2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-03-24 00:11:46 +01: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/>.
|
|
|
|
*/
|
|
|
|
|
2010-06-25 00:45:30 +02:00
|
|
|
#include "librarydirectorymodel.h"
|
2010-05-09 02:10:26 +02:00
|
|
|
#include "librarymodel.h"
|
2009-12-24 20:16:07 +01:00
|
|
|
#include "libraryview.h"
|
|
|
|
#include "libraryitem.h"
|
2010-05-09 02:10:26 +02:00
|
|
|
#include "librarybackend.h"
|
2010-07-31 18:12:16 +02:00
|
|
|
#include "core/deletefiles.h"
|
2011-01-10 23:26:13 +01:00
|
|
|
#include "core/mimedata.h"
|
2010-07-31 18:12:16 +02:00
|
|
|
#include "core/musicstorage.h"
|
2011-03-17 20:52:21 +01:00
|
|
|
#include "core/utilities.h"
|
2010-07-19 23:16:22 +02:00
|
|
|
#include "devices/devicemanager.h"
|
2010-07-24 20:31:05 +02:00
|
|
|
#include "devices/devicestatefiltermodel.h"
|
2011-01-18 18:12:05 +01:00
|
|
|
#include "scripting/scriptmanager.h"
|
|
|
|
#include "scripting/uiinterface.h"
|
2010-11-18 21:19:33 +01:00
|
|
|
#include "smartplaylists/wizard.h"
|
2010-05-19 17:45:29 +02:00
|
|
|
#include "ui/iconloader.h"
|
2010-06-25 00:45:30 +02:00
|
|
|
#include "ui/organisedialog.h"
|
2010-08-14 13:51:50 +02:00
|
|
|
#include "ui/organiseerrordialog.h"
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
#include <QPainter>
|
2010-03-21 00:59:39 +01:00
|
|
|
#include <QContextMenuEvent>
|
2011-02-08 22:55:32 +01:00
|
|
|
#include <QHelpEvent>
|
2010-03-21 00:59:39 +01:00
|
|
|
#include <QMenu>
|
2010-07-31 18:12:16 +02:00
|
|
|
#include <QMessageBox>
|
2011-02-14 18:00:13 +01:00
|
|
|
#include <QSet>
|
2010-04-01 02:12:25 +02:00
|
|
|
#include <QSettings>
|
2011-02-14 18:00:13 +01:00
|
|
|
#include <QSortFilterProxyModel>
|
2011-02-08 22:55:32 +01:00
|
|
|
#include <QToolTip>
|
|
|
|
#include <QWhatsThis>
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-11-18 21:19:33 +01:00
|
|
|
using smart_playlists::Wizard;
|
|
|
|
|
2010-04-01 02:12:25 +02:00
|
|
|
const char* LibraryView::kSettingsGroup = "LibraryView";
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
LibraryItemDelegate::LibraryItemDelegate(QObject *parent)
|
|
|
|
: QStyledItemDelegate(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void LibraryItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opt, const QModelIndex &index) const {
|
2010-11-24 22:34:54 +01:00
|
|
|
const bool is_divider = index.data(LibraryModel::Role_IsDivider).toBool();
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-11-24 22:34:54 +01:00
|
|
|
if (is_divider) {
|
|
|
|
QString text(index.data().toString());
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-11-24 22:34:54 +01:00
|
|
|
painter->save();
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-11-24 22:34:54 +01:00
|
|
|
// Draw the text
|
|
|
|
QFont bold_font(opt.font);
|
|
|
|
bold_font.setBold(true);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-11-24 22:34:54 +01:00
|
|
|
QRect text_rect(opt.rect);
|
|
|
|
text_rect.setLeft(text_rect.left() + 30);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-11-24 22:34:54 +01:00
|
|
|
painter->setPen(opt.palette.color(QPalette::Text));
|
|
|
|
painter->setFont(bold_font);
|
|
|
|
painter->drawText(text_rect, text);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-11-24 22:34:54 +01:00
|
|
|
// Draw the line under the item
|
|
|
|
QPen line_pen(opt.palette.color(QPalette::Dark));
|
|
|
|
line_pen.setWidth(2);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-11-24 22:34:54 +01:00
|
|
|
painter->setPen(line_pen);
|
|
|
|
painter->drawLine(opt.rect.bottomLeft(), opt.rect.bottomRight());
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-11-24 22:34:54 +01:00
|
|
|
painter->restore();
|
|
|
|
} else {
|
|
|
|
QStyledItemDelegate::paint(painter, opt, index);
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-08 22:55:32 +01:00
|
|
|
bool LibraryItemDelegate::helpEvent(QHelpEvent *event, QAbstractItemView *view,
|
|
|
|
const QStyleOptionViewItem &option,
|
|
|
|
const QModelIndex &index) {
|
|
|
|
Q_UNUSED(option);
|
|
|
|
|
|
|
|
if (!event || !view)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
QHelpEvent *he = static_cast<QHelpEvent*>(event);
|
|
|
|
QString text = displayText(index.data(), QLocale::system());
|
|
|
|
|
|
|
|
if (text.isEmpty() || !he)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
switch (event->type()) {
|
|
|
|
case QEvent::ToolTip: {
|
|
|
|
QRect displayed_text;
|
|
|
|
QSize real_text;
|
|
|
|
bool is_elided = false;
|
|
|
|
|
|
|
|
real_text = sizeHint(option, index);
|
|
|
|
displayed_text = view->visualRect(index);
|
|
|
|
is_elided = displayed_text.width() < real_text.width();
|
|
|
|
if(is_elided) {
|
|
|
|
QToolTip::showText(he->globalPos(), text, view);
|
|
|
|
} else { // in case that another text was previously displayed
|
|
|
|
QToolTip::hideText();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case QEvent::QueryWhatsThis:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case QEvent::WhatsThis:
|
|
|
|
QWhatsThis::showText(he->globalPos(), text, view);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
LibraryView::LibraryView(QWidget* parent)
|
2010-05-17 01:44:33 +02:00
|
|
|
: AutoExpandingTreeView(parent),
|
2011-01-18 18:20:42 +01:00
|
|
|
scripts_(NULL),
|
2009-12-24 20:16:07 +01:00
|
|
|
library_(NULL),
|
|
|
|
total_song_count_(-1),
|
2010-03-21 00:59:39 +01:00
|
|
|
nomusic_(":nomusic.png"),
|
2010-08-30 16:03:32 +02:00
|
|
|
context_menu_(NULL),
|
|
|
|
is_in_keyboard_search_(false)
|
2009-12-24 20:16:07 +01:00
|
|
|
{
|
|
|
|
setItemDelegate(new LibraryItemDelegate(this));
|
2010-08-26 14:22:13 +02:00
|
|
|
setAttribute(Qt::WA_MacShowFocusRect, false);
|
2010-10-01 21:27:01 +02:00
|
|
|
setHeaderHidden(true);
|
|
|
|
setAllColumnsShowFocus(true);
|
|
|
|
setDragEnabled(true);
|
|
|
|
setDragDropMode(QAbstractItemView::DragOnly);
|
|
|
|
setSelectionMode(QAbstractItemView::ExtendedSelection);
|
2010-08-26 14:22:13 +02:00
|
|
|
|
2010-04-01 02:12:25 +02:00
|
|
|
ReloadSettings();
|
2011-01-02 15:51:01 +01:00
|
|
|
setStyleSheet("QTreeView::item{padding-top:1px;}");
|
2010-04-01 02:12:25 +02:00
|
|
|
}
|
|
|
|
|
2010-06-25 00:45:30 +02:00
|
|
|
LibraryView::~LibraryView() {
|
|
|
|
}
|
|
|
|
|
2010-04-01 02:12:25 +02:00
|
|
|
void LibraryView::ReloadSettings() {
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(kSettingsGroup);
|
|
|
|
|
2010-05-17 01:44:33 +02:00
|
|
|
SetAutoOpen(s.value("auto_open", true).toBool());
|
2011-03-05 16:20:27 +01:00
|
|
|
if (library_ != NULL) {
|
2011-01-02 15:51:01 +01:00
|
|
|
library_->set_pretty_covers(s.value("pretty_covers", true).toBool());
|
2011-03-05 16:20:27 +01:00
|
|
|
library_->set_show_dividers(s.value("show_dividers", true).toBool());
|
|
|
|
}
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
2010-06-25 00:45:30 +02:00
|
|
|
void LibraryView::SetTaskManager(TaskManager *task_manager) {
|
2010-07-31 18:12:16 +02:00
|
|
|
task_manager_ = task_manager;
|
2010-06-25 00:45:30 +02:00
|
|
|
}
|
|
|
|
|
2011-01-18 18:12:05 +01:00
|
|
|
void LibraryView::SetLibrary(LibraryModel* library) {
|
2009-12-24 20:16:07 +01:00
|
|
|
library_ = library;
|
2011-03-05 16:20:27 +01:00
|
|
|
ReloadSettings();
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
2011-01-18 18:12:05 +01:00
|
|
|
void LibraryView::SetDeviceManager(DeviceManager* device_manager) {
|
2010-07-19 23:16:22 +02:00
|
|
|
devices_ = device_manager;
|
2011-01-18 18:12:05 +01:00
|
|
|
}
|
2011-01-18 17:34:43 +01:00
|
|
|
|
2011-01-18 18:12:05 +01:00
|
|
|
void LibraryView::SetScriptManager(ScriptManager* scripts) {
|
|
|
|
scripts_ = scripts;
|
2010-07-19 23:16:22 +02:00
|
|
|
}
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
void LibraryView::TotalSongCountUpdated(int count) {
|
|
|
|
bool old = total_song_count_;
|
|
|
|
total_song_count_ = count;
|
|
|
|
if (old != total_song_count_)
|
|
|
|
update();
|
|
|
|
|
|
|
|
if (total_song_count_ == 0)
|
|
|
|
setCursor(Qt::PointingHandCursor);
|
|
|
|
else
|
|
|
|
unsetCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LibraryView::paintEvent(QPaintEvent* event) {
|
|
|
|
if (total_song_count_ == 0) {
|
2010-11-20 15:59:11 +01:00
|
|
|
QPainter p(viewport());
|
|
|
|
QRect rect(viewport()->rect());
|
|
|
|
|
2010-01-08 17:21:22 +01:00
|
|
|
// Draw the confused clementine
|
2009-12-24 20:16:07 +01:00
|
|
|
QRect image_rect((rect.width() - nomusic_.width()) / 2, 50,
|
|
|
|
nomusic_.width(), nomusic_.height());
|
|
|
|
p.drawPixmap(image_rect, nomusic_);
|
|
|
|
|
|
|
|
// Draw the title text
|
|
|
|
QFont bold_font;
|
|
|
|
bold_font.setBold(true);
|
|
|
|
p.setFont(bold_font);
|
|
|
|
|
|
|
|
QFontMetrics metrics(bold_font);
|
|
|
|
|
|
|
|
QRect title_rect(0, image_rect.bottom() + 20, rect.width(), metrics.height());
|
2010-02-23 19:33:09 +01:00
|
|
|
p.drawText(title_rect, Qt::AlignHCenter, tr("Your library is empty!"));
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
// Draw the other text
|
|
|
|
p.setFont(QFont());
|
|
|
|
|
|
|
|
QRect text_rect(0, title_rect.bottom() + 5, rect.width(), metrics.height());
|
2010-02-23 19:33:09 +01:00
|
|
|
p.drawText(text_rect, Qt::AlignHCenter, tr("Click here to add some music"));
|
2010-11-20 15:59:11 +01:00
|
|
|
} else {
|
|
|
|
QTreeView::paintEvent(event);
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LibraryView::mouseReleaseEvent(QMouseEvent* e) {
|
|
|
|
QTreeView::mouseReleaseEvent(e);
|
|
|
|
|
|
|
|
if (total_song_count_ == 0) {
|
|
|
|
emit ShowConfigDialog();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-21 00:59:39 +01:00
|
|
|
void LibraryView::contextMenuEvent(QContextMenuEvent *e) {
|
2011-01-18 18:12:05 +01:00
|
|
|
if(!context_menu_) {
|
|
|
|
context_menu_ = new QMenu(this);
|
|
|
|
add_to_playlist_ = context_menu_->addAction(IconLoader::Load("media-playback-start"),
|
2011-02-08 23:42:09 +01:00
|
|
|
tr("Append to current playlist"), this, SLOT(AddToPlaylist()));
|
|
|
|
load_ = context_menu_->addAction(IconLoader::Load("media-playback-start"),
|
|
|
|
tr("Replace current playlist"), this, SLOT(Load()));
|
2011-02-09 18:51:59 +01:00
|
|
|
open_in_new_playlist_ = context_menu_->addAction(IconLoader::Load("document-new"),
|
|
|
|
tr("Open in new playlist"), this, SLOT(OpenInNewPlaylist()));
|
2011-02-08 23:42:09 +01:00
|
|
|
|
|
|
|
context_menu_->addSeparator();
|
|
|
|
add_to_playlist_enqueue_ = context_menu_->addAction(IconLoader::Load("go-next"),
|
2011-02-20 17:23:30 +01:00
|
|
|
tr("Queue track"), this, SLOT(AddToPlaylistEnqueue()));
|
2011-01-18 18:12:05 +01:00
|
|
|
|
|
|
|
context_menu_->addSeparator();
|
|
|
|
new_smart_playlist_ = context_menu_->addAction(IconLoader::Load("document-new"),
|
|
|
|
tr("New smart playlist..."), this, SLOT(NewSmartPlaylist()));
|
|
|
|
edit_smart_playlist_ = context_menu_->addAction(IconLoader::Load("edit-rename"),
|
|
|
|
tr("Edit smart playlist..."), this, SLOT(EditSmartPlaylist()));
|
|
|
|
delete_smart_playlist_ = context_menu_->addAction(IconLoader::Load("edit-delete"),
|
|
|
|
tr("Delete smart playlist"), this, SLOT(DeleteSmartPlaylist()));
|
|
|
|
|
|
|
|
context_menu_->addSeparator();
|
|
|
|
organise_ = context_menu_->addAction(IconLoader::Load("edit-copy"),
|
|
|
|
tr("Organise files..."), this, SLOT(Organise()));
|
|
|
|
copy_to_device_ = context_menu_->addAction(IconLoader::Load("multimedia-player-ipod-mini-blue"),
|
|
|
|
tr("Copy to device..."), this, SLOT(CopyToDevice()));
|
|
|
|
delete_ = context_menu_->addAction(IconLoader::Load("edit-delete"),
|
|
|
|
tr("Delete from disk..."), this, SLOT(Delete()));
|
|
|
|
|
|
|
|
context_menu_->addSeparator();
|
|
|
|
edit_track_ = context_menu_->addAction(IconLoader::Load("edit-rename"),
|
|
|
|
tr("Edit track information..."), this, SLOT(EditTracks()));
|
|
|
|
edit_tracks_ = context_menu_->addAction(IconLoader::Load("edit-rename"),
|
|
|
|
tr("Edit tracks information..."), this, SLOT(EditTracks()));
|
2011-03-17 20:52:21 +01:00
|
|
|
show_in_browser_ = context_menu_->addAction(IconLoader::Load("document-open-folder"),
|
|
|
|
tr("Show in file browser..."), this, SLOT(ShowInBrowser()));
|
2011-01-18 18:12:05 +01:00
|
|
|
|
|
|
|
context_menu_->addSeparator();
|
|
|
|
show_in_various_ = context_menu_->addAction(
|
|
|
|
tr("Show in various artists"), this, SLOT(ShowInVarious()));
|
|
|
|
no_show_in_various_ = context_menu_->addAction(
|
|
|
|
tr("Don't show in various artists"), this, SLOT(NoShowInVarious()));
|
|
|
|
|
|
|
|
context_menu_->addSeparator();
|
|
|
|
|
|
|
|
copy_to_device_->setDisabled(devices_->connected_devices_model()->rowCount() == 0);
|
|
|
|
connect(devices_->connected_devices_model(), SIGNAL(IsEmptyChanged(bool)),
|
|
|
|
copy_to_device_, SLOT(setDisabled(bool)));
|
|
|
|
|
|
|
|
if(scripts_) {
|
|
|
|
scripts_->ui()->RegisterActionLocation("library_context_menu", context_menu_, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-21 00:59:39 +01:00
|
|
|
context_menu_index_ = indexAt(e->pos());
|
|
|
|
if (!context_menu_index_.isValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
context_menu_index_ = qobject_cast<QSortFilterProxyModel*>(model())
|
|
|
|
->mapToSource(context_menu_index_);
|
|
|
|
|
2011-02-21 21:06:44 +01:00
|
|
|
QModelIndexList selected_indexes =
|
|
|
|
qobject_cast<QSortFilterProxyModel*>(model())->mapSelectionToSource(
|
|
|
|
selectionModel()->selection()).indexes();
|
|
|
|
|
|
|
|
// number of smart playlists selected
|
|
|
|
int smart_playlists = 0;
|
|
|
|
// is the smart playlists header selected?
|
|
|
|
int smart_playlists_header = 0;
|
|
|
|
// number of non smart playlists selected
|
|
|
|
int regular_elements = 0;
|
|
|
|
// number of editable non smart playlists selected
|
|
|
|
int regular_editable = 0;
|
|
|
|
|
|
|
|
foreach(const QModelIndex& index, selected_indexes) {
|
|
|
|
int type = library_->data(index, LibraryModel::Role_Type).toInt();
|
|
|
|
|
|
|
|
if(type == LibraryItem::Type_SmartPlaylist) {
|
|
|
|
smart_playlists++;
|
|
|
|
} else if(type == LibraryItem::Type_PlaylistContainer) {
|
|
|
|
smart_playlists_header++;
|
|
|
|
} else {
|
|
|
|
regular_elements++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(library_->data(index, LibraryModel::Role_Editable).toBool()) {
|
|
|
|
regular_editable++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-18 17:34:43 +01:00
|
|
|
// TODO: check if custom plugin actions should be enabled / visible
|
2011-02-21 21:06:44 +01:00
|
|
|
const int songs_selected = smart_playlists + smart_playlists_header + regular_elements;
|
2011-03-20 13:43:10 +01:00
|
|
|
const bool regular_elements_only = songs_selected == regular_elements && regular_elements > 0;
|
2011-02-21 21:06:44 +01:00
|
|
|
const bool smart_playlists_only = songs_selected == smart_playlists + smart_playlists_header;
|
|
|
|
const bool only_smart_playlist_selected = smart_playlists == 1 && songs_selected == 1;
|
|
|
|
|
|
|
|
// in all modes
|
|
|
|
load_->setEnabled(songs_selected);
|
|
|
|
add_to_playlist_->setEnabled(songs_selected);
|
|
|
|
open_in_new_playlist_->setEnabled(songs_selected);
|
|
|
|
add_to_playlist_enqueue_->setEnabled(songs_selected);
|
|
|
|
|
|
|
|
// allow mixed smart playlists / regular elements selected
|
2011-03-20 13:43:10 +01:00
|
|
|
show_in_browser_->setVisible(!smart_playlists_only);
|
2011-02-21 21:06:44 +01:00
|
|
|
edit_tracks_->setVisible(!smart_playlists_only && regular_editable > 1);
|
|
|
|
// if neither edit_track not edit_tracks are available, we show disabled
|
|
|
|
// edit_track element
|
|
|
|
edit_track_->setVisible(!smart_playlists_only && (regular_editable <= 1));
|
|
|
|
edit_track_->setEnabled(regular_editable == 1);
|
|
|
|
|
|
|
|
// only when no smart playlists selected
|
|
|
|
organise_->setVisible(regular_elements_only);
|
|
|
|
copy_to_device_->setVisible(regular_elements_only);
|
|
|
|
delete_->setVisible(regular_elements_only);
|
|
|
|
show_in_various_->setVisible(regular_elements_only);
|
|
|
|
no_show_in_various_->setVisible(regular_elements_only);
|
|
|
|
|
|
|
|
// only when all selected items are editable
|
|
|
|
organise_->setEnabled(regular_elements == regular_editable);
|
|
|
|
copy_to_device_->setEnabled(regular_elements == regular_editable);
|
|
|
|
delete_->setEnabled(regular_elements == regular_editable);
|
|
|
|
|
|
|
|
// only when no regular elements selected
|
|
|
|
new_smart_playlist_->setVisible(smart_playlists_only);
|
|
|
|
edit_smart_playlist_->setVisible(smart_playlists_only);
|
|
|
|
delete_smart_playlist_->setVisible(smart_playlists_only);
|
|
|
|
|
|
|
|
edit_smart_playlist_->setEnabled(only_smart_playlist_selected);
|
|
|
|
delete_smart_playlist_->setEnabled(only_smart_playlist_selected);
|
2010-11-18 20:34:04 +01:00
|
|
|
|
2010-03-21 00:59:39 +01:00
|
|
|
context_menu_->popup(e->globalPos());
|
|
|
|
}
|
|
|
|
|
|
|
|
void LibraryView::ShowInVarious() {
|
|
|
|
ShowInVarious(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LibraryView::NoShowInVarious() {
|
|
|
|
ShowInVarious(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LibraryView::ShowInVarious(bool on) {
|
|
|
|
if (!context_menu_index_.isValid())
|
|
|
|
return;
|
|
|
|
|
2010-12-11 15:17:07 +01:00
|
|
|
// Build a list of the selected unique album/artist combos
|
|
|
|
typedef QPair<QString, QString> AlbumArtist;
|
|
|
|
QSet<AlbumArtist> selected;
|
|
|
|
foreach (const Song& song, GetSelectedSongs()) {
|
|
|
|
selected << AlbumArtist(song.album(), song.artist());
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (const AlbumArtist& albumartist, selected.values()) {
|
|
|
|
library_->backend()->ForceCompilation(
|
|
|
|
albumartist.second, albumartist.first, on);
|
|
|
|
}
|
2010-03-21 00:59:39 +01:00
|
|
|
}
|
2010-04-04 15:31:21 +02:00
|
|
|
|
2010-05-15 19:45:04 +02:00
|
|
|
void LibraryView::Load() {
|
2011-01-10 23:26:13 +01:00
|
|
|
QMimeData* data = model()->mimeData(selectedIndexes());
|
|
|
|
if (MimeData* mime_data = qobject_cast<MimeData*>(data)) {
|
|
|
|
mime_data->clear_first_ = true;
|
|
|
|
}
|
|
|
|
emit AddToPlaylistSignal(data);
|
2010-05-15 19:45:04 +02:00
|
|
|
}
|
|
|
|
|
2010-04-04 15:31:21 +02:00
|
|
|
void LibraryView::AddToPlaylist() {
|
2011-01-10 23:26:13 +01:00
|
|
|
emit AddToPlaylistSignal(model()->mimeData(selectedIndexes()));
|
2010-04-04 15:31:21 +02:00
|
|
|
}
|
2010-05-28 14:52:22 +02:00
|
|
|
|
2010-12-29 16:08:43 +01:00
|
|
|
void LibraryView::AddToPlaylistEnqueue() {
|
2011-01-10 23:26:13 +01:00
|
|
|
QMimeData* data = model()->mimeData(selectedIndexes());
|
|
|
|
if (MimeData* mime_data = qobject_cast<MimeData*>(data)) {
|
|
|
|
mime_data->enqueue_now_ = true;
|
|
|
|
}
|
|
|
|
emit AddToPlaylistSignal(data);
|
2010-12-29 16:08:43 +01:00
|
|
|
}
|
|
|
|
|
2011-02-09 18:51:59 +01:00
|
|
|
void LibraryView::OpenInNewPlaylist() {
|
|
|
|
QMimeData* data = model()->mimeData(selectedIndexes());
|
|
|
|
if (MimeData* mime_data = qobject_cast<MimeData*>(data)) {
|
2011-02-16 19:29:35 +01:00
|
|
|
mime_data->open_in_new_playlist_ = true;
|
2011-02-09 18:51:59 +01:00
|
|
|
}
|
|
|
|
emit AddToPlaylistSignal(data);
|
|
|
|
}
|
|
|
|
|
2010-08-29 14:15:30 +02:00
|
|
|
void LibraryView::keyboardSearch(const QString& search) {
|
2010-08-30 12:31:44 +02:00
|
|
|
is_in_keyboard_search_ = true;
|
|
|
|
QTreeView::keyboardSearch(search);
|
|
|
|
is_in_keyboard_search_ = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LibraryView::scrollTo(const QModelIndex& index, ScrollHint hint) {
|
|
|
|
if (is_in_keyboard_search_)
|
|
|
|
QTreeView::scrollTo(index, QAbstractItemView::PositionAtTop);
|
|
|
|
else
|
|
|
|
QTreeView::scrollTo(index, hint);
|
2010-05-28 14:52:22 +02:00
|
|
|
}
|
2010-06-25 00:45:30 +02:00
|
|
|
|
2010-08-30 17:28:55 +02:00
|
|
|
SongList LibraryView::GetSelectedSongs() const {
|
2010-06-25 00:45:30 +02:00
|
|
|
QModelIndexList selected_indexes =
|
|
|
|
qobject_cast<QSortFilterProxyModel*>(model())->mapSelectionToSource(
|
|
|
|
selectionModel()->selection()).indexes();
|
2010-08-30 17:28:55 +02:00
|
|
|
return library_->GetChildSongs(selected_indexes);
|
2010-07-19 23:16:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void LibraryView::Organise() {
|
2010-08-27 18:15:54 +02:00
|
|
|
if (!organise_dialog_)
|
|
|
|
organise_dialog_.reset(new OrganiseDialog(task_manager_));
|
|
|
|
|
2010-07-19 23:16:22 +02:00
|
|
|
organise_dialog_->SetDestinationModel(library_->directory_model());
|
2010-06-25 00:45:30 +02:00
|
|
|
organise_dialog_->SetCopy(false);
|
2010-09-15 22:00:17 +02:00
|
|
|
if (organise_dialog_->SetSongs(GetSelectedSongs()))
|
|
|
|
organise_dialog_->show();
|
|
|
|
else {
|
|
|
|
QMessageBox::warning(this, tr("Error"),
|
|
|
|
tr("None of the selected songs were suitable for copying to a device"));
|
|
|
|
}
|
2010-06-25 00:45:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void LibraryView::Delete() {
|
2010-07-31 18:12:16 +02:00
|
|
|
if (QMessageBox::question(this, tr("Delete files"),
|
|
|
|
tr("These files will be deleted from disk, are you sure you want to continue?"),
|
|
|
|
QMessageBox::Yes, QMessageBox::Cancel) != QMessageBox::Yes)
|
|
|
|
return;
|
2010-06-25 00:45:30 +02:00
|
|
|
|
2010-07-31 18:12:16 +02:00
|
|
|
// We can cheat and always take the storage of the first directory, since
|
|
|
|
// they'll all be FilesystemMusicStorage in a library and deleting doesn't
|
|
|
|
// check the actual directory.
|
2010-08-09 23:50:46 +02:00
|
|
|
boost::shared_ptr<MusicStorage> storage =
|
|
|
|
library_->directory_model()->index(0, 0).data(MusicStorage::Role_Storage)
|
|
|
|
.value<boost::shared_ptr<MusicStorage> >();
|
|
|
|
|
2010-07-31 18:12:16 +02:00
|
|
|
DeleteFiles* delete_files = new DeleteFiles(task_manager_, storage);
|
2010-08-14 13:51:50 +02:00
|
|
|
connect(delete_files, SIGNAL(Finished(SongList)), SLOT(DeleteFinished(SongList)));
|
2010-08-30 17:28:55 +02:00
|
|
|
delete_files->Start(GetSelectedSongs());
|
2010-06-25 00:45:30 +02:00
|
|
|
}
|
2010-07-19 23:16:22 +02:00
|
|
|
|
2010-12-06 22:16:04 +01:00
|
|
|
void LibraryView::EditTracks() {
|
|
|
|
if(!edit_tag_dialog_) {
|
|
|
|
edit_tag_dialog_.reset(new EditTagDialog(this));
|
|
|
|
}
|
|
|
|
edit_tag_dialog_->SetSongs(GetSelectedSongs());
|
|
|
|
edit_tag_dialog_->SetTagCompleter(library_->backend());
|
|
|
|
edit_tag_dialog_->show();
|
|
|
|
}
|
|
|
|
|
2010-07-19 23:16:22 +02:00
|
|
|
void LibraryView::CopyToDevice() {
|
2010-08-27 18:15:54 +02:00
|
|
|
if (!organise_dialog_)
|
|
|
|
organise_dialog_.reset(new OrganiseDialog(task_manager_));
|
|
|
|
|
2010-07-25 11:52:29 +02:00
|
|
|
organise_dialog_->SetDestinationModel(devices_->connected_devices_model(), true);
|
2010-07-19 23:16:22 +02:00
|
|
|
organise_dialog_->SetCopy(true);
|
2010-08-30 17:28:55 +02:00
|
|
|
organise_dialog_->SetSongs(GetSelectedSongs());
|
2010-07-19 23:16:22 +02:00
|
|
|
organise_dialog_->show();
|
|
|
|
}
|
2010-07-31 19:29:52 +02:00
|
|
|
|
2010-08-14 13:51:50 +02:00
|
|
|
void LibraryView::DeleteFinished(const SongList& songs_with_errors) {
|
|
|
|
if (songs_with_errors.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
OrganiseErrorDialog* dialog = new OrganiseErrorDialog(this);
|
|
|
|
dialog->Show(OrganiseErrorDialog::Type_Delete, songs_with_errors);
|
|
|
|
// It deletes itself when the user closes it
|
|
|
|
}
|
2010-08-29 14:15:30 +02:00
|
|
|
|
|
|
|
void LibraryView::FilterReturnPressed() {
|
|
|
|
if (!currentIndex().isValid()) {
|
|
|
|
// Pick the first thing that isn't a divider
|
|
|
|
for (int row=0 ; row<model()->rowCount() ; ++row) {
|
|
|
|
QModelIndex idx(model()->index(row, 0));
|
|
|
|
if (idx.data(LibraryModel::Role_Type) != LibraryItem::Type_Divider) {
|
|
|
|
setCurrentIndex(idx);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!currentIndex().isValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
emit doubleClicked(currentIndex());
|
|
|
|
}
|
2010-11-18 20:34:04 +01:00
|
|
|
|
|
|
|
void LibraryView::NewSmartPlaylist() {
|
2010-11-19 00:08:37 +01:00
|
|
|
Wizard* wizard = new Wizard(library_->backend(), this);
|
|
|
|
wizard->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
connect(wizard, SIGNAL(accepted()), SLOT(NewSmartPlaylistFinished()));
|
|
|
|
|
|
|
|
wizard->show();
|
2010-11-18 20:34:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LibraryView::EditSmartPlaylist() {
|
2010-11-19 00:08:37 +01:00
|
|
|
Wizard* wizard = new Wizard(library_->backend(), this);
|
|
|
|
wizard->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
connect(wizard, SIGNAL(accepted()), SLOT(EditSmartPlaylistFinished()));
|
|
|
|
|
|
|
|
wizard->show();
|
|
|
|
wizard->SetGenerator(library_->CreateGenerator(context_menu_index_));
|
2010-11-18 20:34:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LibraryView::DeleteSmartPlaylist() {
|
2010-11-19 00:08:37 +01:00
|
|
|
library_->DeleteGenerator(context_menu_index_);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LibraryView::NewSmartPlaylistFinished() {
|
|
|
|
const Wizard* wizard = qobject_cast<Wizard*>(sender());
|
|
|
|
library_->AddGenerator(wizard->CreateGenerator());
|
|
|
|
}
|
|
|
|
|
|
|
|
void LibraryView::EditSmartPlaylistFinished() {
|
|
|
|
const Wizard* wizard = qobject_cast<Wizard*>(sender());
|
|
|
|
library_->UpdateGenerator(context_menu_index_, wizard->CreateGenerator());
|
2010-11-18 20:34:04 +01:00
|
|
|
}
|
2011-02-14 18:00:13 +01:00
|
|
|
|
|
|
|
QString LibraryView::GetNameForNewPlaylist(const SongList& songs) {
|
2011-02-26 15:27:57 +01:00
|
|
|
if (songs.isEmpty()) {
|
|
|
|
return tr("Playlist");
|
|
|
|
}
|
|
|
|
|
2011-02-14 18:00:13 +01:00
|
|
|
QSet<QString> artists;
|
|
|
|
QSet<QString> albums;
|
|
|
|
|
|
|
|
foreach(const Song& song, songs) {
|
|
|
|
artists << (song.artist().isEmpty()
|
|
|
|
? tr("Unknown")
|
|
|
|
: song.artist());
|
|
|
|
albums << (song.album().isEmpty()
|
|
|
|
? tr("Unknown")
|
|
|
|
: song.album());
|
|
|
|
|
|
|
|
if(artists.size() > 1) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool various_artists = artists.size() > 1;
|
|
|
|
|
|
|
|
QString result;
|
|
|
|
if(various_artists) {
|
|
|
|
result = tr("Various artists");
|
|
|
|
} else {
|
2011-02-20 16:05:05 +01:00
|
|
|
result = artists.values().first();
|
2011-02-14 18:00:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!various_artists && albums.size() == 1) {
|
2011-02-20 16:05:05 +01:00
|
|
|
result += " - " + albums.toList().first();
|
2011-02-14 18:00:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2011-03-17 20:52:21 +01:00
|
|
|
|
|
|
|
void LibraryView::ShowInBrowser() {
|
|
|
|
QStringList filenames;
|
|
|
|
foreach (const Song& song, GetSelectedSongs()) {
|
|
|
|
filenames << song.filename();
|
|
|
|
}
|
|
|
|
|
|
|
|
Utilities::OpenInFileBrowser(filenames);
|
|
|
|
}
|