2010-07-11 17:37:40 +02:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-07-11 17:37:40 +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 "playlist.h"
|
2010-07-11 18:17:38 +02:00
|
|
|
#include "playlistdelegates.h"
|
2010-07-11 17:37:40 +02:00
|
|
|
#include "playlistmanager.h"
|
|
|
|
#include "queue.h"
|
|
|
|
#include "queuemanager.h"
|
|
|
|
#include "ui_queuemanager.h"
|
2010-07-11 18:58:22 +02:00
|
|
|
#include "ui/iconloader.h"
|
2010-07-11 17:37:40 +02:00
|
|
|
|
2010-12-14 18:43:03 +01:00
|
|
|
#include <QKeySequence>
|
|
|
|
#include <QShortcut>
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
QueueManager::QueueManager(QWidget* parent)
|
|
|
|
: QDialog(parent),
|
|
|
|
ui_(new Ui_QueueManager),
|
|
|
|
playlists_(nullptr),
|
|
|
|
current_playlist_(nullptr) {
|
2010-07-11 17:37:40 +02:00
|
|
|
ui_->setupUi(this);
|
2010-07-11 23:27:36 +02:00
|
|
|
ui_->list->setItemDelegate(new QueuedItemDelegate(this, 0));
|
2010-07-11 18:58:22 +02:00
|
|
|
|
|
|
|
// Set icons on buttons
|
|
|
|
ui_->move_down->setIcon(IconLoader::Load("go-down"));
|
|
|
|
ui_->move_up->setIcon(IconLoader::Load("go-up"));
|
2011-03-30 20:41:34 +02:00
|
|
|
ui_->remove->setIcon(IconLoader::Load("edit-delete"));
|
2010-07-11 18:58:22 +02:00
|
|
|
ui_->clear->setIcon(IconLoader::Load("edit-clear-list"));
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
// Set a standard shortcut
|
2011-03-30 20:41:34 +02:00
|
|
|
ui_->remove->setShortcut(QKeySequence::Delete);
|
|
|
|
|
2010-07-11 18:58:22 +02:00
|
|
|
// Button connections
|
|
|
|
connect(ui_->move_down, SIGNAL(clicked()), SLOT(MoveDown()));
|
|
|
|
connect(ui_->move_up, SIGNAL(clicked()), SLOT(MoveUp()));
|
2011-03-30 20:41:34 +02:00
|
|
|
connect(ui_->remove, SIGNAL(clicked()), SLOT(Remove()));
|
2010-07-11 18:58:22 +02:00
|
|
|
connect(ui_->clear, SIGNAL(clicked()), SLOT(Clear()));
|
2010-12-14 18:43:03 +01:00
|
|
|
|
2010-12-14 18:55:08 +01:00
|
|
|
QShortcut* close = new QShortcut(QKeySequence::Close, this);
|
2010-12-14 18:43:03 +01:00
|
|
|
connect(close, SIGNAL(activated()), SLOT(close()));
|
2010-07-11 17:37:40 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
QueueManager::~QueueManager() { delete ui_; }
|
2010-07-11 17:37:40 +02:00
|
|
|
|
|
|
|
void QueueManager::SetPlaylistManager(PlaylistManager* manager) {
|
|
|
|
playlists_ = manager;
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
connect(playlists_, SIGNAL(CurrentChanged(Playlist*)),
|
|
|
|
SLOT(CurrentPlaylistChanged(Playlist*)));
|
2010-08-28 21:17:39 +02:00
|
|
|
CurrentPlaylistChanged(playlists_->current());
|
2010-07-11 17:37:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QueueManager::CurrentPlaylistChanged(Playlist* playlist) {
|
2010-07-11 18:58:22 +02:00
|
|
|
if (current_playlist_) {
|
2014-02-07 16:34:20 +01:00
|
|
|
disconnect(current_playlist_->queue(),
|
|
|
|
SIGNAL(rowsInserted(QModelIndex, int, int)), this,
|
|
|
|
SLOT(UpdateButtonState()));
|
|
|
|
disconnect(current_playlist_->queue(),
|
|
|
|
SIGNAL(rowsRemoved(QModelIndex, int, int)), this,
|
|
|
|
SLOT(UpdateButtonState()));
|
|
|
|
disconnect(current_playlist_->queue(), SIGNAL(layoutChanged()), this,
|
|
|
|
SLOT(UpdateButtonState()));
|
|
|
|
disconnect(current_playlist_, SIGNAL(destroyed()), this,
|
|
|
|
SLOT(PlaylistDestroyed()));
|
2010-07-11 18:58:22 +02:00
|
|
|
}
|
|
|
|
|
2010-07-11 17:37:40 +02:00
|
|
|
current_playlist_ = playlist;
|
2010-07-11 18:58:22 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
connect(current_playlist_->queue(),
|
|
|
|
SIGNAL(rowsInserted(QModelIndex, int, int)), this,
|
|
|
|
SLOT(UpdateButtonState()));
|
|
|
|
connect(current_playlist_->queue(),
|
|
|
|
SIGNAL(rowsRemoved(QModelIndex, int, int)), this,
|
|
|
|
SLOT(UpdateButtonState()));
|
|
|
|
connect(current_playlist_->queue(), SIGNAL(layoutChanged()), this,
|
|
|
|
SLOT(UpdateButtonState()));
|
|
|
|
connect(current_playlist_, SIGNAL(destroyed()), this,
|
|
|
|
SLOT(PlaylistDestroyed()));
|
2010-07-11 18:58:22 +02:00
|
|
|
|
2010-07-11 17:37:40 +02:00
|
|
|
ui_->list->setModel(current_playlist_->queue());
|
2010-07-11 18:58:22 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
connect(ui_->list->selectionModel(),
|
|
|
|
SIGNAL(currentChanged(QModelIndex, QModelIndex)),
|
2010-07-11 18:58:22 +02:00
|
|
|
SLOT(UpdateButtonState()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void QueueManager::MoveUp() {
|
2010-07-11 19:39:11 +02:00
|
|
|
QModelIndexList indexes = ui_->list->selectionModel()->selectedRows();
|
|
|
|
qStableSort(indexes);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
if (indexes.isEmpty() || indexes.first().row() == 0) return;
|
2010-07-11 18:58:22 +02:00
|
|
|
|
2014-02-10 14:29:07 +01:00
|
|
|
for (const QModelIndex& index : indexes) {
|
2010-07-11 19:39:11 +02:00
|
|
|
current_playlist_->queue()->MoveUp(index.row());
|
|
|
|
}
|
2010-07-11 18:58:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QueueManager::MoveDown() {
|
2010-07-11 19:39:11 +02:00
|
|
|
QModelIndexList indexes = ui_->list->selectionModel()->selectedRows();
|
|
|
|
qStableSort(indexes);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
if (indexes.isEmpty() ||
|
|
|
|
indexes.last().row() == current_playlist_->queue()->rowCount() - 1)
|
2010-07-11 19:39:11 +02:00
|
|
|
return;
|
2010-07-11 18:58:22 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
for (int i = indexes.count() - 1; i >= 0; --i) {
|
2010-07-11 19:39:11 +02:00
|
|
|
current_playlist_->queue()->MoveDown(indexes[i].row());
|
|
|
|
}
|
2010-07-11 18:58:22 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void QueueManager::Clear() { current_playlist_->queue()->Clear(); }
|
2010-07-11 18:58:22 +02:00
|
|
|
|
2011-03-30 20:41:34 +02:00
|
|
|
void QueueManager::Remove() {
|
2014-02-07 16:34:20 +01:00
|
|
|
// collect the rows to be removed
|
2011-03-30 20:41:34 +02:00
|
|
|
QList<int> row_list;
|
2014-02-10 14:29:07 +01:00
|
|
|
for (const QModelIndex& index : ui_->list->selectionModel()->selectedRows()) {
|
2014-02-07 16:34:20 +01:00
|
|
|
if (index.isValid()) row_list << index.row();
|
2011-03-30 20:41:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
current_playlist_->queue()->Remove(row_list);
|
|
|
|
}
|
|
|
|
|
2010-07-11 18:58:22 +02:00
|
|
|
void QueueManager::UpdateButtonState() {
|
|
|
|
const QModelIndex current = ui_->list->selectionModel()->currentIndex();
|
|
|
|
|
|
|
|
if (current.isValid()) {
|
|
|
|
ui_->move_up->setEnabled(current.row() != 0);
|
2014-02-07 16:34:20 +01:00
|
|
|
ui_->move_down->setEnabled(current.row() !=
|
|
|
|
current_playlist_->queue()->rowCount() - 1);
|
2011-03-30 20:41:34 +02:00
|
|
|
ui_->remove->setEnabled(true);
|
2010-07-11 18:58:22 +02:00
|
|
|
} else {
|
|
|
|
ui_->move_up->setEnabled(false);
|
|
|
|
ui_->move_down->setEnabled(false);
|
2011-03-30 20:41:34 +02:00
|
|
|
ui_->remove->setEnabled(false);
|
2010-07-11 18:58:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ui_->clear->setEnabled(!current_playlist_->queue()->is_empty());
|
2010-07-11 17:37:40 +02:00
|
|
|
}
|
2010-07-11 22:23:34 +02:00
|
|
|
|
|
|
|
void QueueManager::PlaylistDestroyed() {
|
2014-02-06 16:49:49 +01:00
|
|
|
current_playlist_ = nullptr;
|
2010-07-11 22:23:34 +02:00
|
|
|
// We'll get another CurrentPlaylistChanged() soon
|
|
|
|
}
|