2010-04-19 20:44:35 +02:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-04-19 20:44:35 +02:00
|
|
|
|
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "playlistundocommands.h"
|
|
|
|
#include "playlist.h"
|
|
|
|
|
|
|
|
namespace PlaylistUndoCommands {
|
|
|
|
|
|
|
|
Base::Base(Playlist *playlist)
|
|
|
|
: QUndoCommand(0),
|
|
|
|
playlist_(playlist)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-29 16:08:43 +01:00
|
|
|
InsertItems::InsertItems(Playlist *playlist, const PlaylistItemList& items,
|
|
|
|
int pos, bool enqueue)
|
2010-04-19 20:44:35 +02:00
|
|
|
: Base(playlist),
|
|
|
|
items_(items),
|
2010-12-29 16:08:43 +01:00
|
|
|
pos_(pos),
|
|
|
|
enqueue_(enqueue)
|
2010-04-19 20:44:35 +02:00
|
|
|
{
|
|
|
|
setText(tr("add %n songs", "", items_.count()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void InsertItems::redo() {
|
2010-12-29 16:08:43 +01:00
|
|
|
playlist_->InsertItemsWithoutUndo(items_, pos_, enqueue_);
|
2010-04-19 20:44:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void InsertItems::undo() {
|
|
|
|
const int start = pos_ == -1 ?
|
|
|
|
playlist_->rowCount() - items_.count() : pos_;
|
|
|
|
playlist_->RemoveItemsWithoutUndo(start, items_.count());
|
|
|
|
}
|
|
|
|
|
2011-04-16 16:04:15 +02:00
|
|
|
bool InsertItems::UpdateItem(const PlaylistItemPtr& updated_item) {
|
|
|
|
for (int i=0; i<items_.size(); i++) {
|
|
|
|
PlaylistItemPtr item = items_[i];
|
2011-04-28 14:27:53 +02:00
|
|
|
if (item->Metadata().url() == updated_item->Metadata().url()) {
|
2011-04-16 16:04:15 +02:00
|
|
|
items_[i] = updated_item;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-04-19 20:44:35 +02:00
|
|
|
|
|
|
|
RemoveItems::RemoveItems(Playlist *playlist, int pos, int count)
|
2010-04-30 01:58:31 +02:00
|
|
|
: Base(playlist)
|
2010-04-19 20:44:35 +02:00
|
|
|
{
|
2010-04-30 01:58:31 +02:00
|
|
|
setText(tr("remove %n songs", "", count));
|
|
|
|
|
|
|
|
ranges_ << Range(pos, count);
|
2010-04-19 20:44:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveItems::redo() {
|
2010-04-30 01:58:31 +02:00
|
|
|
for (int i=0 ; i<ranges_.count() ; ++i)
|
|
|
|
ranges_[i].items_ = playlist_->RemoveItemsWithoutUndo(
|
|
|
|
ranges_[i].pos_, ranges_[i].count_);
|
2010-04-19 20:44:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveItems::undo() {
|
2010-04-30 01:58:31 +02:00
|
|
|
for (int i=ranges_.count()-1 ; i>=0 ; --i)
|
|
|
|
playlist_->InsertItemsWithoutUndo(ranges_[i].items_, ranges_[i].pos_);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RemoveItems::mergeWith(const QUndoCommand *other) {
|
|
|
|
const RemoveItems* remove_command = static_cast<const RemoveItems*>(other);
|
|
|
|
ranges_.append(remove_command->ranges_);
|
|
|
|
|
|
|
|
int sum = 0;
|
|
|
|
foreach (const Range& range, ranges_)
|
|
|
|
sum += range.count_;
|
|
|
|
setText(tr("remove %n songs", "", sum));
|
|
|
|
|
|
|
|
return true;
|
2010-04-19 20:44:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MoveItems::MoveItems(Playlist *playlist, const QList<int> &source_rows, int pos)
|
|
|
|
: Base(playlist),
|
|
|
|
source_rows_(source_rows),
|
|
|
|
pos_(pos)
|
|
|
|
{
|
|
|
|
setText(tr("move songs", "", source_rows.count()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MoveItems::redo() {
|
|
|
|
playlist_->MoveItemsWithoutUndo(source_rows_, pos_);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MoveItems::undo() {
|
|
|
|
playlist_->MoveItemsWithoutUndo(pos_, source_rows_);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|