2010-05-20 16:12:15 +02:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-05-20 16:12:15 +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 "playlistcontainer.h"
|
2010-05-20 23:21:55 +02:00
|
|
|
#include "playlistmanager.h"
|
2011-04-28 19:50:45 +02:00
|
|
|
#include "specialplaylisttype.h"
|
2010-05-20 16:12:15 +02:00
|
|
|
#include "ui_playlistcontainer.h"
|
2011-04-29 13:24:58 +02:00
|
|
|
#include "core/logging.h"
|
2010-05-22 22:28:11 +02:00
|
|
|
#include "playlistparsers/playlistparser.h"
|
2010-05-20 16:12:15 +02:00
|
|
|
#include "ui/iconloader.h"
|
2011-04-28 22:48:53 +02:00
|
|
|
#include "widgets/didyoumean.h"
|
2010-08-25 22:59:08 +02:00
|
|
|
#include "widgets/maclineedit.h"
|
2010-05-20 16:12:15 +02:00
|
|
|
|
2011-04-29 13:24:58 +02:00
|
|
|
#include <QFileDialog>
|
2010-05-20 23:21:55 +02:00
|
|
|
#include <QInputDialog>
|
2010-05-22 19:03:18 +02:00
|
|
|
#include <QLabel>
|
2010-05-22 22:28:11 +02:00
|
|
|
#include <QMessageBox>
|
2011-04-29 13:24:58 +02:00
|
|
|
#include <QSettings>
|
|
|
|
#include <QSortFilterProxyModel>
|
|
|
|
#include <QTimeLine>
|
|
|
|
#include <QUndoStack>
|
2010-05-21 01:18:55 +02:00
|
|
|
|
|
|
|
const char* PlaylistContainer::kSettingsGroup = "Playlist";
|
2010-05-20 23:21:55 +02:00
|
|
|
|
2010-05-20 16:12:15 +02:00
|
|
|
PlaylistContainer::PlaylistContainer(QWidget *parent)
|
|
|
|
: QWidget(parent),
|
2010-05-20 23:21:55 +02:00
|
|
|
ui_(new Ui_PlaylistContainer),
|
2010-05-22 22:28:11 +02:00
|
|
|
manager_(NULL),
|
2010-05-20 23:21:55 +02:00
|
|
|
undo_(NULL),
|
2010-05-21 01:18:55 +02:00
|
|
|
redo_(NULL),
|
2011-04-29 13:24:58 +02:00
|
|
|
playlist_(NULL),
|
2010-05-21 12:57:40 +02:00
|
|
|
starting_up_(true),
|
|
|
|
tab_bar_visible_(false),
|
2010-05-22 19:03:18 +02:00
|
|
|
tab_bar_animation_(new QTimeLine(500, this)),
|
2011-04-29 13:24:58 +02:00
|
|
|
no_matches_label_(NULL),
|
2011-04-28 22:48:53 +02:00
|
|
|
did_you_mean_(NULL)
|
2010-05-20 16:12:15 +02:00
|
|
|
{
|
|
|
|
ui_->setupUi(this);
|
|
|
|
|
2011-04-29 13:24:58 +02:00
|
|
|
no_matches_label_ = new QLabel(ui_->playlist);
|
2010-05-22 19:03:18 +02:00
|
|
|
no_matches_label_->setAlignment(Qt::AlignTop | Qt::AlignHCenter);
|
|
|
|
no_matches_label_->setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
|
|
no_matches_label_->setWordWrap(true);
|
|
|
|
no_matches_label_->raise();
|
|
|
|
no_matches_label_->hide();
|
|
|
|
|
|
|
|
// Set the colour of the no matches label to the disabled text colour
|
|
|
|
QPalette no_matches_palette = no_matches_label_->palette();
|
2011-04-29 13:24:58 +02:00
|
|
|
const QColor no_matches_color = no_matches_palette.color(QPalette::Disabled, QPalette::Text);
|
|
|
|
no_matches_palette.setColor(QPalette::Normal, QPalette::WindowText, no_matches_color);
|
|
|
|
no_matches_palette.setColor(QPalette::Inactive, QPalette::WindowText, no_matches_color);
|
2010-05-22 19:03:18 +02:00
|
|
|
no_matches_label_->setPalette(no_matches_palette);
|
|
|
|
|
|
|
|
// Make it bold
|
|
|
|
QFont no_matches_font = no_matches_label_->font();
|
|
|
|
no_matches_font.setBold(true);
|
|
|
|
no_matches_label_->setFont(no_matches_font);
|
|
|
|
|
2010-05-21 01:18:55 +02:00
|
|
|
settings_.beginGroup(kSettingsGroup);
|
|
|
|
|
2010-05-20 16:12:15 +02:00
|
|
|
// Tab bar
|
|
|
|
ui_->tab_bar->setExpanding(false);
|
|
|
|
ui_->tab_bar->setMovable(true);
|
|
|
|
|
2010-05-21 12:57:40 +02:00
|
|
|
connect(tab_bar_animation_, SIGNAL(frameChanged(int)), SLOT(SetTabBarHeight(int)));
|
2010-10-01 21:27:01 +02:00
|
|
|
ui_->tab_bar->setMaximumHeight(0);
|
2010-05-21 12:57:40 +02:00
|
|
|
|
2010-05-20 16:12:15 +02:00
|
|
|
// Connections
|
2010-05-21 01:18:55 +02:00
|
|
|
connect(ui_->tab_bar, SIGNAL(currentChanged(int)), SLOT(Save()));
|
2010-05-23 00:20:00 +02:00
|
|
|
connect(ui_->tab_bar, SIGNAL(Save(int)), SLOT(SavePlaylist(int)));
|
2010-08-25 22:59:08 +02:00
|
|
|
|
|
|
|
// Replace playlist search filter with native search box.
|
|
|
|
#ifdef Q_OS_DARWIN
|
|
|
|
delete ui_->filter;
|
|
|
|
MacLineEdit* filter = new MacLineEdit(ui_->toolbar);
|
|
|
|
filter->setObjectName("filter");
|
2010-08-28 21:29:20 +02:00
|
|
|
ui_->horizontalLayout->addWidget(filter);
|
2010-08-25 22:59:08 +02:00
|
|
|
connect(filter, SIGNAL(textChanged(QString)), SLOT(UpdateFilter()));
|
2010-12-20 15:49:47 +01:00
|
|
|
filter->set_hint(tr("Playlist search"));
|
2010-08-25 22:59:08 +02:00
|
|
|
filter_ = filter;
|
|
|
|
#else
|
|
|
|
filter_ = ui_->filter;
|
2010-09-02 21:17:35 +02:00
|
|
|
connect(ui_->filter, SIGNAL(textChanged(QString)), SLOT(UpdateFilter()));
|
2011-02-23 23:21:17 +01:00
|
|
|
connect(ui_->playlist, SIGNAL(FocusOnFilterSignal(QKeyEvent*)), SLOT(FocusOnFilter(QKeyEvent*)));
|
|
|
|
ui_->filter->installEventFilter(this);
|
2010-08-25 22:59:08 +02:00
|
|
|
#endif
|
2011-04-28 22:48:53 +02:00
|
|
|
|
|
|
|
did_you_mean_ = new DidYouMean(filter_->widget(), this);
|
|
|
|
connect(did_you_mean_, SIGNAL(Accepted(QString)), SLOT(DidYouMeanAccepted(QString)));
|
2010-05-20 16:12:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
PlaylistContainer::~PlaylistContainer() {
|
|
|
|
delete ui_;
|
|
|
|
}
|
|
|
|
|
|
|
|
PlaylistView* PlaylistContainer::view() const {
|
|
|
|
return ui_->playlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistContainer::SetActions(
|
2011-04-19 22:11:24 +02:00
|
|
|
QAction* new_playlist, QAction* save_playlist, QAction* load_playlist,
|
|
|
|
QAction* next_playlist, QAction* previous_playlist) {
|
2010-05-20 16:12:15 +02:00
|
|
|
ui_->create_new->setDefaultAction(new_playlist);
|
|
|
|
ui_->save->setDefaultAction(save_playlist);
|
|
|
|
ui_->load->setDefaultAction(load_playlist);
|
|
|
|
|
2010-05-23 00:20:00 +02:00
|
|
|
ui_->tab_bar->SetActions(new_playlist, load_playlist);
|
2010-05-20 23:21:55 +02:00
|
|
|
|
2010-05-21 01:18:55 +02:00
|
|
|
connect(new_playlist, SIGNAL(triggered()), SLOT(NewPlaylist()));
|
|
|
|
connect(save_playlist, SIGNAL(triggered()), SLOT(SavePlaylist()));
|
|
|
|
connect(load_playlist, SIGNAL(triggered()), SLOT(LoadPlaylist()));
|
2011-04-19 22:11:24 +02:00
|
|
|
connect(next_playlist, SIGNAL(triggered()), SLOT(GoToNextPlaylistTab()));
|
|
|
|
connect(previous_playlist, SIGNAL(triggered()), SLOT(GoToPreviousPlaylistTab()));
|
2010-05-20 16:12:15 +02:00
|
|
|
}
|
|
|
|
|
2010-05-20 23:21:55 +02:00
|
|
|
void PlaylistContainer::SetManager(PlaylistManager *manager) {
|
|
|
|
manager_ = manager;
|
2010-07-17 14:47:59 +02:00
|
|
|
ui_->tab_bar->SetManager(manager);
|
2010-05-20 23:21:55 +02:00
|
|
|
|
2010-05-21 12:29:17 +02:00
|
|
|
connect(ui_->tab_bar, SIGNAL(CurrentIdChanged(int)),
|
2010-05-20 23:21:55 +02:00
|
|
|
manager, SLOT(SetCurrentPlaylist(int)));
|
|
|
|
connect(ui_->tab_bar, SIGNAL(Rename(int,QString)),
|
|
|
|
manager, SLOT(Rename(int,QString)));
|
|
|
|
connect(ui_->tab_bar, SIGNAL(Remove(int)),
|
|
|
|
manager, SLOT(Remove(int)));
|
2010-05-21 12:37:24 +02:00
|
|
|
connect(ui_->tab_bar, SIGNAL(PlaylistOrderChanged(QList<int>)),
|
|
|
|
manager, SLOT(ChangePlaylistOrder(QList<int>)));
|
2010-05-20 23:21:55 +02:00
|
|
|
|
|
|
|
connect(manager, SIGNAL(CurrentChanged(Playlist*)),
|
|
|
|
SLOT(SetViewModel(Playlist*)));
|
|
|
|
connect(manager, SIGNAL(PlaylistAdded(int,QString)),
|
|
|
|
SLOT(PlaylistAdded(int,QString)));
|
|
|
|
connect(manager, SIGNAL(PlaylistRemoved(int)),
|
|
|
|
SLOT(PlaylistRemoved(int)));
|
|
|
|
connect(manager, SIGNAL(PlaylistRenamed(int,QString)),
|
|
|
|
SLOT(PlaylistRenamed(int,QString)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistContainer::SetViewModel(Playlist* playlist) {
|
2010-06-13 14:45:05 +02:00
|
|
|
if (view()->selectionModel()) {
|
|
|
|
disconnect(view()->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
|
|
|
|
this, SLOT(SelectionChanged()));
|
|
|
|
}
|
2011-04-29 13:24:58 +02:00
|
|
|
if (playlist_ && playlist_->proxy()) {
|
|
|
|
disconnect(playlist_->proxy(), SIGNAL(modelReset()),
|
|
|
|
this, SLOT(UpdateNoMatchesLabel()));
|
|
|
|
disconnect(playlist_->proxy(), SIGNAL(rowsInserted(QModelIndex,int,int)),
|
|
|
|
this, SLOT(UpdateNoMatchesLabel()));
|
|
|
|
disconnect(playlist_->proxy(), SIGNAL(rowsRemoved(QModelIndex,int,int)),
|
|
|
|
this, SLOT(UpdateNoMatchesLabel()));
|
|
|
|
}
|
|
|
|
if (playlist_) {
|
|
|
|
disconnect(playlist_, SIGNAL(modelReset()),
|
|
|
|
this, SLOT(UpdateNoMatchesLabel()));
|
|
|
|
disconnect(playlist_, SIGNAL(rowsInserted(QModelIndex,int,int)),
|
|
|
|
this, SLOT(UpdateNoMatchesLabel()));
|
|
|
|
disconnect(playlist_, SIGNAL(rowsRemoved(QModelIndex,int,int)),
|
|
|
|
this, SLOT(UpdateNoMatchesLabel()));
|
|
|
|
}
|
|
|
|
|
|
|
|
playlist_ = playlist;
|
2010-06-13 14:45:05 +02:00
|
|
|
|
2010-05-21 01:18:55 +02:00
|
|
|
// Set the view
|
2010-05-20 23:21:55 +02:00
|
|
|
playlist->IgnoreSorting(true);
|
2010-05-22 18:36:13 +02:00
|
|
|
view()->setModel(playlist->proxy());
|
2010-05-20 23:21:55 +02:00
|
|
|
view()->SetItemDelegates(manager_->library_backend());
|
2010-05-22 18:36:13 +02:00
|
|
|
view()->SetPlaylist(playlist);
|
2010-09-25 17:30:47 +02:00
|
|
|
view()->selectionModel()->select(manager_->current_selection(), QItemSelectionModel::ClearAndSelect);
|
2010-05-20 23:21:55 +02:00
|
|
|
playlist->IgnoreSorting(false);
|
|
|
|
|
2010-06-13 14:45:05 +02:00
|
|
|
connect(view()->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
|
|
|
|
this, SLOT(SelectionChanged()));
|
2010-11-28 16:14:48 +01:00
|
|
|
emit ViewSelectionModelChanged();
|
2010-06-13 14:45:05 +02:00
|
|
|
|
2010-05-22 18:36:13 +02:00
|
|
|
// Update filter
|
2010-12-20 00:40:36 +01:00
|
|
|
filter_->set_text(playlist->proxy()->filterRegExp().pattern());
|
2010-05-22 18:36:13 +02:00
|
|
|
|
2011-04-29 13:24:58 +02:00
|
|
|
// Update the no matches label
|
|
|
|
connect(playlist_->proxy(), SIGNAL(modelReset()), SLOT(UpdateNoMatchesLabel()));
|
|
|
|
connect(playlist_->proxy(), SIGNAL(rowsInserted(QModelIndex,int,int)), SLOT(UpdateNoMatchesLabel()));
|
|
|
|
connect(playlist_->proxy(), SIGNAL(rowsRemoved(QModelIndex,int,int)), SLOT(UpdateNoMatchesLabel()));
|
|
|
|
connect(playlist_, SIGNAL(modelReset()), SLOT(UpdateNoMatchesLabel()));
|
|
|
|
connect(playlist_, SIGNAL(rowsInserted(QModelIndex,int,int)), SLOT(UpdateNoMatchesLabel()));
|
|
|
|
connect(playlist_, SIGNAL(rowsRemoved(QModelIndex,int,int)), SLOT(UpdateNoMatchesLabel()));
|
|
|
|
UpdateNoMatchesLabel();
|
|
|
|
|
2010-05-21 11:41:57 +02:00
|
|
|
// Ensure that tab is current
|
2010-05-21 12:29:17 +02:00
|
|
|
if (ui_->tab_bar->current_id() != manager_->current_id())
|
|
|
|
ui_->tab_bar->set_current_id(manager_->current_id());
|
2010-05-21 11:41:57 +02:00
|
|
|
|
2010-05-21 01:18:55 +02:00
|
|
|
// Sort out the undo/redo actions
|
2010-05-20 23:21:55 +02:00
|
|
|
delete undo_;
|
|
|
|
delete redo_;
|
|
|
|
undo_ = playlist->undo_stack()->createUndoAction(this);
|
|
|
|
redo_ = playlist->undo_stack()->createRedoAction(this);
|
|
|
|
undo_->setIcon(IconLoader::Load("edit-undo"));
|
|
|
|
undo_->setShortcut(QKeySequence::Undo);
|
|
|
|
redo_->setIcon(IconLoader::Load("edit-redo"));
|
|
|
|
redo_->setShortcut(QKeySequence::Redo);
|
|
|
|
|
|
|
|
ui_->undo->setDefaultAction(undo_);
|
|
|
|
ui_->redo->setDefaultAction(redo_);
|
|
|
|
|
|
|
|
emit UndoRedoActionsChanged(undo_, redo_);
|
2011-04-28 19:50:45 +02:00
|
|
|
|
2011-04-28 22:48:53 +02:00
|
|
|
did_you_mean()->hide();
|
|
|
|
|
2011-04-28 19:50:45 +02:00
|
|
|
// Implement special playlist behaviour
|
|
|
|
const SpecialPlaylistType* type = manager_->GetPlaylistType(playlist->special_type());
|
2011-04-28 22:19:48 +02:00
|
|
|
filter_->set_hint(type->search_hint_text(playlist));
|
2010-05-20 23:21:55 +02:00
|
|
|
}
|
|
|
|
|
2010-05-21 00:48:11 +02:00
|
|
|
void PlaylistContainer::ActivePlaying() {
|
|
|
|
UpdateActiveIcon(QIcon(":tiny-start.png"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistContainer::ActivePaused() {
|
|
|
|
UpdateActiveIcon(QIcon(":tiny-pause.png"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistContainer::ActiveStopped() {
|
|
|
|
UpdateActiveIcon(QIcon());
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistContainer::UpdateActiveIcon(const QIcon& icon) {
|
|
|
|
// Unset all existing icons
|
|
|
|
for (int i=0 ; i<ui_->tab_bar->count() ; ++i) {
|
2011-04-29 13:24:58 +02:00
|
|
|
// Get the default icon for this tab
|
|
|
|
const int id = ui_->tab_bar->tabData(i).toInt();
|
|
|
|
Playlist* playlist = manager_->playlist(id);
|
|
|
|
const SpecialPlaylistType* type = manager_->GetPlaylistType(playlist->special_type());
|
|
|
|
|
|
|
|
ui_->tab_bar->setTabIcon(i, type->icon(playlist));
|
2010-05-21 00:48:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set our icon
|
|
|
|
if (!icon.isNull())
|
2010-05-21 12:29:17 +02:00
|
|
|
ui_->tab_bar->set_icon_by_id(manager_->active_id(), icon);
|
2010-05-21 00:48:11 +02:00
|
|
|
}
|
|
|
|
|
2010-05-21 12:29:17 +02:00
|
|
|
void PlaylistContainer::PlaylistAdded(int id, const QString &name) {
|
2011-04-28 19:50:45 +02:00
|
|
|
Playlist* playlist = manager_->playlist(id);
|
|
|
|
const SpecialPlaylistType* type = manager_->GetPlaylistType(playlist->special_type());
|
|
|
|
|
|
|
|
const int index = ui_->tab_bar->count();
|
|
|
|
const QIcon icon = type->icon(playlist);
|
|
|
|
ui_->tab_bar->InsertTab(id, index, name, icon);
|
2010-05-21 01:18:55 +02:00
|
|
|
|
|
|
|
// Are we startup up, should we select this tab?
|
2010-05-21 12:57:40 +02:00
|
|
|
if (starting_up_ && settings_.value("current_playlist", 1).toInt() == id) {
|
2010-05-21 01:18:55 +02:00
|
|
|
starting_up_ = false;
|
2010-05-21 12:29:17 +02:00
|
|
|
ui_->tab_bar->set_current_id(id);
|
2010-05-21 01:18:55 +02:00
|
|
|
}
|
2010-05-21 12:57:40 +02:00
|
|
|
|
|
|
|
if (ui_->tab_bar->count() > 1) {
|
|
|
|
// Have to do this here because sizeHint() is only valid when there's a
|
|
|
|
// tab in the bar.
|
|
|
|
tab_bar_animation_->setFrameRange(0, ui_->tab_bar->sizeHint().height());
|
|
|
|
|
|
|
|
if (!isVisible()) {
|
|
|
|
// Skip the animation since the window is hidden (eg. if we're still
|
|
|
|
// loading the UI).
|
|
|
|
tab_bar_visible_ = true;
|
2010-10-01 21:27:01 +02:00
|
|
|
ui_->tab_bar->setMaximumHeight(tab_bar_animation_->endFrame());
|
2010-05-21 12:57:40 +02:00
|
|
|
} else {
|
|
|
|
SetTabBarVisible(true);
|
|
|
|
}
|
|
|
|
}
|
2010-05-20 23:21:55 +02:00
|
|
|
}
|
|
|
|
|
2010-05-21 12:29:17 +02:00
|
|
|
void PlaylistContainer::PlaylistRemoved(int id) {
|
|
|
|
ui_->tab_bar->RemoveTab(id);
|
2010-05-21 12:57:40 +02:00
|
|
|
|
|
|
|
if (ui_->tab_bar->count() <= 1)
|
|
|
|
SetTabBarVisible(false);
|
2010-05-20 23:21:55 +02:00
|
|
|
}
|
|
|
|
|
2010-05-21 12:29:17 +02:00
|
|
|
void PlaylistContainer::PlaylistRenamed(int id, const QString &new_name) {
|
|
|
|
ui_->tab_bar->set_text_by_id(id, new_name);
|
2010-05-20 23:21:55 +02:00
|
|
|
}
|
|
|
|
|
2010-05-21 01:18:55 +02:00
|
|
|
void PlaylistContainer::NewPlaylist() {
|
2011-03-25 20:16:12 +01:00
|
|
|
manager_->New(tr("Playlist"));
|
2010-05-20 23:21:55 +02:00
|
|
|
}
|
|
|
|
|
2010-05-21 01:18:55 +02:00
|
|
|
void PlaylistContainer::LoadPlaylist() {
|
2010-05-22 22:28:11 +02:00
|
|
|
QString filename = settings_.value("last_load_playlist").toString();
|
|
|
|
filename = QFileDialog::getOpenFileName(
|
|
|
|
this, tr("Load playlist"), filename,
|
2010-05-23 00:29:52 +02:00
|
|
|
manager_->parser()->filters());
|
2010-05-21 01:18:55 +02:00
|
|
|
|
2010-05-22 22:28:11 +02:00
|
|
|
if (filename.isNull())
|
|
|
|
return;
|
|
|
|
|
|
|
|
settings_.setValue("last_load_playlist", filename);
|
|
|
|
|
2010-05-23 00:20:00 +02:00
|
|
|
manager_->Load(filename);
|
|
|
|
}
|
2010-05-22 22:28:11 +02:00
|
|
|
|
2010-05-23 00:20:00 +02:00
|
|
|
void PlaylistContainer::SavePlaylist(int id = -1) {
|
|
|
|
QString filename = settings_.value("last_save_playlist").toString();
|
2010-07-31 15:10:08 +02:00
|
|
|
|
|
|
|
// We want to use the playlist tab name as a default filename, but in the
|
|
|
|
// same directory as the last saved file.
|
|
|
|
|
|
|
|
// Strip off filename components until we find something that's a folder
|
|
|
|
forever {
|
|
|
|
QFileInfo fileinfo(filename);
|
|
|
|
if (filename.isEmpty() || fileinfo.isDir())
|
|
|
|
break;
|
|
|
|
|
|
|
|
filename = filename.section('/', 0, -2);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use the home directory as a fallback in case the path is empty.
|
|
|
|
if (filename.isEmpty())
|
|
|
|
filename = QDir::homePath();
|
|
|
|
|
|
|
|
// Add the suggested filename based on the tab name
|
|
|
|
filename += "/" + ui_->tab_bar->tabText(ui_->tab_bar->currentIndex()) +
|
|
|
|
"." + manager_->parser()->default_extension();
|
|
|
|
|
|
|
|
QString default_filter = manager_->parser()->default_filter();
|
|
|
|
|
2010-05-23 00:20:00 +02:00
|
|
|
filename = QFileDialog::getSaveFileName(
|
|
|
|
this, tr("Save playlist"), filename,
|
2010-07-31 15:10:08 +02:00
|
|
|
manager_->parser()->filters(), &default_filter);
|
2010-05-22 22:28:11 +02:00
|
|
|
|
2010-05-23 00:20:00 +02:00
|
|
|
if (filename.isNull())
|
|
|
|
return;
|
2010-05-21 01:18:55 +02:00
|
|
|
|
2010-05-23 00:20:00 +02:00
|
|
|
settings_.setValue("last_save_playlist", filename);
|
2010-05-20 23:21:55 +02:00
|
|
|
|
2010-05-23 00:20:00 +02:00
|
|
|
manager_->Save(id == -1 ? manager_->current_id() : id, filename);
|
2010-05-20 23:21:55 +02:00
|
|
|
}
|
|
|
|
|
2011-04-19 22:11:24 +02:00
|
|
|
void PlaylistContainer::GoToNextPlaylistTab() {
|
|
|
|
// Get the next tab' id
|
|
|
|
int id_next =
|
|
|
|
ui_->tab_bar->id_of((ui_->tab_bar->currentIndex()+1)%ui_->tab_bar->count());
|
|
|
|
// Switch to next tab
|
|
|
|
manager_->SetCurrentPlaylist(id_next);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistContainer::GoToPreviousPlaylistTab() {
|
|
|
|
// Get the next tab' id
|
|
|
|
int id_previous =
|
|
|
|
ui_->tab_bar->id_of((ui_->tab_bar->currentIndex()+ui_->tab_bar->count()-1)
|
|
|
|
% ui_->tab_bar->count());
|
|
|
|
// Switch to next tab
|
|
|
|
manager_->SetCurrentPlaylist(id_previous);
|
|
|
|
}
|
|
|
|
|
2010-05-20 23:21:55 +02:00
|
|
|
void PlaylistContainer::Save() {
|
2010-05-21 01:18:55 +02:00
|
|
|
if (starting_up_)
|
|
|
|
return;
|
2010-05-20 23:21:55 +02:00
|
|
|
|
2010-05-21 12:29:17 +02:00
|
|
|
settings_.setValue("current_playlist", ui_->tab_bar->current_id());
|
2010-05-20 23:21:55 +02:00
|
|
|
}
|
2010-05-21 12:57:40 +02:00
|
|
|
|
|
|
|
void PlaylistContainer::SetTabBarVisible(bool visible) {
|
|
|
|
if (tab_bar_visible_ == visible)
|
|
|
|
return;
|
|
|
|
tab_bar_visible_ = visible;
|
|
|
|
|
|
|
|
tab_bar_animation_->setDirection(visible ? QTimeLine::Forward : QTimeLine::Backward);
|
|
|
|
tab_bar_animation_->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistContainer::SetTabBarHeight(int height) {
|
2010-10-01 21:27:01 +02:00
|
|
|
ui_->tab_bar->setMaximumHeight(height);
|
2010-05-21 12:57:40 +02:00
|
|
|
}
|
2010-05-22 18:36:13 +02:00
|
|
|
|
|
|
|
void PlaylistContainer::UpdateFilter() {
|
2011-04-28 19:50:45 +02:00
|
|
|
Playlist* playlist = manager_->current();
|
|
|
|
SpecialPlaylistType* type = manager_->GetPlaylistType(playlist->special_type());
|
|
|
|
|
2011-04-29 13:24:58 +02:00
|
|
|
did_you_mean()->hide();
|
|
|
|
|
2011-04-28 19:50:45 +02:00
|
|
|
if (type->has_special_search_behaviour(playlist)) {
|
|
|
|
type->Search(filter_->text(), playlist);
|
|
|
|
} else {
|
|
|
|
manager_->current()->proxy()->setFilterFixedString(filter_->text());
|
|
|
|
ui_->playlist->JumpToCurrentlyPlayingTrack();
|
2011-04-29 13:24:58 +02:00
|
|
|
}
|
2010-05-22 19:03:18 +02:00
|
|
|
|
2011-04-29 13:24:58 +02:00
|
|
|
UpdateNoMatchesLabel();
|
|
|
|
}
|
2010-05-22 19:03:18 +02:00
|
|
|
|
2011-04-29 13:24:58 +02:00
|
|
|
void PlaylistContainer::UpdateNoMatchesLabel() {
|
|
|
|
Playlist* playlist = manager_->current();
|
|
|
|
SpecialPlaylistType* type = manager_->GetPlaylistType(playlist->special_type());
|
|
|
|
const QString empty_text = type->empty_playlist_text(playlist);
|
|
|
|
|
|
|
|
const bool has_rows = playlist->rowCount() != 0;
|
|
|
|
const bool has_results = playlist->proxy()->rowCount() != 0;
|
|
|
|
|
|
|
|
QString text;
|
|
|
|
if (!empty_text.isEmpty() && !has_results) {
|
|
|
|
text = empty_text;
|
|
|
|
} else if (has_rows && !has_results) {
|
|
|
|
text = tr("No matches found. Clear the search box to show the whole playlist again.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!text.isEmpty()) {
|
|
|
|
no_matches_label_->setText(text);
|
|
|
|
RepositionNoMatchesLabel(true);
|
|
|
|
no_matches_label_->show();
|
|
|
|
} else {
|
|
|
|
no_matches_label_->hide();
|
2011-04-28 19:50:45 +02:00
|
|
|
}
|
2010-05-22 19:03:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistContainer::resizeEvent(QResizeEvent* e) {
|
|
|
|
QWidget::resizeEvent(e);
|
|
|
|
RepositionNoMatchesLabel();
|
|
|
|
}
|
|
|
|
|
2011-02-23 23:21:17 +01:00
|
|
|
void PlaylistContainer::FocusOnFilter(QKeyEvent *event) {
|
|
|
|
ui_->filter->setFocus(Qt::OtherFocusReason);
|
|
|
|
QApplication::sendEvent(ui_->filter, event);
|
|
|
|
}
|
|
|
|
|
2010-05-22 19:03:18 +02:00
|
|
|
void PlaylistContainer::RepositionNoMatchesLabel(bool force) {
|
|
|
|
if (!force && !no_matches_label_->isVisible())
|
|
|
|
return;
|
|
|
|
|
|
|
|
const int kBorder = 10;
|
|
|
|
|
2011-04-29 13:24:58 +02:00
|
|
|
QPoint pos = ui_->playlist->viewport()->mapTo(ui_->playlist, QPoint(kBorder, kBorder));
|
2010-05-22 19:03:18 +02:00
|
|
|
QSize size = ui_->playlist->viewport()->size();
|
|
|
|
size.setWidth(size.width() - kBorder * 2);
|
|
|
|
size.setHeight(size.height() - kBorder * 2);
|
|
|
|
|
|
|
|
no_matches_label_->move(pos);
|
|
|
|
no_matches_label_->resize(size);
|
2010-05-22 18:36:13 +02:00
|
|
|
}
|
2010-06-13 14:45:05 +02:00
|
|
|
|
|
|
|
void PlaylistContainer::SelectionChanged() {
|
|
|
|
manager_->SelectionChanged(view()->selectionModel()->selection());
|
|
|
|
}
|
2011-02-23 23:21:17 +01:00
|
|
|
|
|
|
|
bool PlaylistContainer::eventFilter(QObject *objectWatched, QEvent *event) {
|
|
|
|
if(objectWatched == ui_->filter) {
|
|
|
|
if (event->type() == QEvent::KeyPress) {
|
|
|
|
QKeyEvent *e = static_cast<QKeyEvent*>(event);
|
|
|
|
switch(e->key()) {
|
|
|
|
case Qt::Key_Up:
|
|
|
|
case Qt::Key_Down:
|
|
|
|
case Qt::Key_PageUp:
|
|
|
|
case Qt::Key_PageDown:
|
|
|
|
case Qt::Key_Return:
|
|
|
|
case Qt::Key_Enter:
|
|
|
|
view()->setFocus(Qt::OtherFocusReason);
|
|
|
|
QApplication::sendEvent(ui_->playlist, event);
|
|
|
|
return true;
|
|
|
|
case Qt::Key_Escape:
|
|
|
|
ui_->filter->LineEditInterface::clear();
|
2011-02-24 01:00:10 +01:00
|
|
|
return true;
|
2011-02-23 23:21:17 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QWidget::eventFilter(objectWatched, event);
|
|
|
|
}
|
2011-04-28 22:48:53 +02:00
|
|
|
|
|
|
|
void PlaylistContainer::DidYouMeanAccepted(const QString& text) {
|
|
|
|
filter_->set_text(text);
|
|
|
|
|
|
|
|
Playlist* playlist = manager_->current();
|
|
|
|
SpecialPlaylistType* type = manager_->GetPlaylistType(playlist->special_type());
|
|
|
|
type->DidYouMeanClicked(text, playlist);
|
|
|
|
}
|