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/>.
|
|
|
|
*/
|
|
|
|
|
2014-02-06 14:48:00 +01:00
|
|
|
#include "libraryview.h"
|
|
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QContextMenuEvent>
|
|
|
|
#include <QHelpEvent>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QSet>
|
|
|
|
#include <QSettings>
|
|
|
|
#include <QSortFilterProxyModel>
|
|
|
|
#include <QToolTip>
|
|
|
|
#include <QWhatsThis>
|
|
|
|
|
2010-06-25 00:45:30 +02:00
|
|
|
#include "librarydirectorymodel.h"
|
2011-11-05 20:09:02 +01:00
|
|
|
#include "libraryfilterwidget.h"
|
2010-05-09 02:10:26 +02:00
|
|
|
#include "librarymodel.h"
|
2009-12-24 20:16:07 +01:00
|
|
|
#include "libraryitem.h"
|
2010-05-09 02:10:26 +02:00
|
|
|
#include "librarybackend.h"
|
2012-02-12 14:41:50 +01:00
|
|
|
#include "core/application.h"
|
2010-07-31 18:12:16 +02:00
|
|
|
#include "core/deletefiles.h"
|
2012-02-19 14:38:24 +01:00
|
|
|
#include "core/logging.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"
|
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
|
|
|
|
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
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
LibraryItemDelegate::LibraryItemDelegate(QObject* parent)
|
|
|
|
: QStyledItemDelegate(parent) {}
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
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
|
|
|
|
2012-06-04 19:18:37 +02:00
|
|
|
QRect text_rect(opt.rect);
|
|
|
|
|
|
|
|
// Does this item have an icon?
|
|
|
|
QPixmap pixmap;
|
|
|
|
QVariant decoration = index.data(Qt::DecorationRole);
|
|
|
|
if (!decoration.isNull()) {
|
|
|
|
if (decoration.canConvert<QPixmap>()) {
|
|
|
|
pixmap = decoration.value<QPixmap>();
|
|
|
|
} else if (decoration.canConvert<QIcon>()) {
|
|
|
|
pixmap = decoration.value<QIcon>().pixmap(opt.decorationSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw the icon at the left of the text rectangle
|
|
|
|
if (!pixmap.isNull()) {
|
|
|
|
QRect icon_rect(text_rect.topLeft(), opt.decorationSize);
|
|
|
|
const int padding = (text_rect.height() - icon_rect.height()) / 2;
|
|
|
|
icon_rect.adjust(padding, padding, padding, padding);
|
|
|
|
text_rect.moveLeft(icon_rect.right() + padding + 6);
|
|
|
|
|
|
|
|
if (pixmap.size() != opt.decorationSize) {
|
|
|
|
pixmap = pixmap.scaled(opt.decorationSize, Qt::KeepAspectRatio);
|
|
|
|
}
|
|
|
|
|
|
|
|
painter->drawPixmap(icon_rect, pixmap);
|
|
|
|
} else {
|
2015-09-21 00:23:30 +02:00
|
|
|
text_rect.setLeft(text_rect.left() + 30);
|
2015-08-31 06:52:01 +02:00
|
|
|
}
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2015-08-31 06:52:01 +02:00
|
|
|
// Draw the text
|
2015-09-21 00:23:30 +02:00
|
|
|
QFont bold_font(opt.font);
|
|
|
|
bold_font.setBold(true);
|
|
|
|
|
|
|
|
painter->setPen(opt.palette.color(QPalette::Text));
|
|
|
|
painter->setFont(bold_font);
|
|
|
|
painter->drawText(text_rect, text);
|
|
|
|
|
|
|
|
// Draw the line under the item
|
2015-09-21 22:15:44 +02:00
|
|
|
QColor line_color = opt.palette.color(QPalette::Text);
|
2015-11-24 18:48:16 +01:00
|
|
|
QLinearGradient grad_color(opt.rect.bottomLeft(), opt.rect.bottomRight());
|
2017-08-09 15:12:36 +02:00
|
|
|
const double fade_start_end = (opt.rect.width() / 3.0) / opt.rect.width();
|
2015-11-24 18:48:16 +01:00
|
|
|
line_color.setAlphaF(0.0);
|
|
|
|
grad_color.setColorAt(0, line_color);
|
|
|
|
line_color.setAlphaF(0.5);
|
|
|
|
grad_color.setColorAt(fade_start_end, line_color);
|
|
|
|
grad_color.setColorAt(1.0 - fade_start_end, line_color);
|
|
|
|
line_color.setAlphaF(0.0);
|
|
|
|
grad_color.setColorAt(1, line_color);
|
|
|
|
painter->setPen(QPen(grad_color, 1));
|
2015-09-21 00:23:30 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
bool LibraryItemDelegate::helpEvent(QHelpEvent* event, QAbstractItemView* view,
|
|
|
|
const QStyleOptionViewItem& option,
|
|
|
|
const QModelIndex& index) {
|
2011-02-08 22:55:32 +01:00
|
|
|
Q_UNUSED(option);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!event || !view) return false;
|
2011-02-08 22:55:32 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
QHelpEvent* he = static_cast<QHelpEvent*>(event);
|
2011-02-08 22:55:32 +01:00
|
|
|
QString text = displayText(index.data(), QLocale::system());
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
if (text.isEmpty() || !he) return false;
|
2011-02-08 22:55:32 +01:00
|
|
|
|
|
|
|
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();
|
2012-06-27 00:57:31 +02:00
|
|
|
|
|
|
|
if (is_elided) {
|
2011-02-08 22:55:32 +01:00
|
|
|
QToolTip::showText(he->globalPos(), text, view);
|
2012-06-27 00:57:31 +02:00
|
|
|
} else if (index.data(Qt::ToolTipRole).isValid()) {
|
|
|
|
// If the item has a tooltip text, display it
|
|
|
|
QString tooltip_text = index.data(Qt::ToolTipRole).toString();
|
|
|
|
QToolTip::showText(he->globalPos(), tooltip_text, view);
|
|
|
|
} else {
|
|
|
|
// in case that another text was previously displayed
|
2011-02-08 22:55:32 +01:00
|
|
|
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)
|
2014-02-07 16:34:20 +01:00
|
|
|
: AutoExpandingTreeView(parent),
|
|
|
|
app_(nullptr),
|
|
|
|
filter_(nullptr),
|
|
|
|
total_song_count_(-1),
|
|
|
|
context_menu_(nullptr),
|
|
|
|
is_in_keyboard_search_(false) {
|
2018-11-11 17:17:19 +01:00
|
|
|
QIcon nomusic = IconLoader::Load("nomusic", IconLoader::Other);
|
|
|
|
nomusic_ = nomusic.pixmap(nomusic.availableSizes().last());
|
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
|
|
|
|
2011-01-02 15:51:01 +01:00
|
|
|
setStyleSheet("QTreeView::item{padding-top:1px;}");
|
2010-04-01 02:12:25 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
LibraryView::~LibraryView() {}
|
2010-06-25 00:45:30 +02:00
|
|
|
|
2012-08-26 14:36:44 +02:00
|
|
|
void LibraryView::SaveFocus() {
|
|
|
|
QModelIndex current = currentIndex();
|
|
|
|
QVariant type = model()->data(current, LibraryModel::Role_Type);
|
2017-08-09 15:12:36 +02:00
|
|
|
if (!type.isValid() ||
|
|
|
|
!(type.toInt() == LibraryItem::Type_Song ||
|
|
|
|
type.toInt() == LibraryItem::Type_Container ||
|
|
|
|
type.toInt() == LibraryItem::Type_Divider)) {
|
2012-08-26 14:36:44 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
last_selected_path_.clear();
|
|
|
|
last_selected_song_ = Song();
|
|
|
|
last_selected_container_ = QString();
|
2017-08-09 15:12:36 +02:00
|
|
|
last_selected_text_ = QString();
|
2012-08-26 14:36:44 +02:00
|
|
|
|
|
|
|
switch (type.toInt()) {
|
|
|
|
case LibraryItem::Type_Song: {
|
2014-02-07 16:34:20 +01:00
|
|
|
QModelIndex index =
|
|
|
|
qobject_cast<QSortFilterProxyModel*>(model())->mapToSource(current);
|
2012-08-26 14:36:44 +02:00
|
|
|
SongList songs = app_->library_model()->GetChildSongs(index);
|
|
|
|
if (!songs.isEmpty()) {
|
|
|
|
last_selected_song_ = songs.last();
|
2017-08-09 15:12:36 +02:00
|
|
|
last_selected_text_ = songs.last().title();
|
2012-08-26 14:36:44 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LibraryItem::Type_Container:
|
|
|
|
case LibraryItem::Type_Divider: {
|
2014-02-07 16:34:20 +01:00
|
|
|
QString text =
|
2017-08-09 15:12:36 +02:00
|
|
|
model()->data(current, LibraryModel::Role_Key).toString();
|
2012-08-26 14:36:44 +02:00
|
|
|
last_selected_container_ = text;
|
2017-08-09 15:12:36 +02:00
|
|
|
last_selected_text_ = model()->data(current, LibraryModel::Role_DisplayText).toString();
|
2012-08-26 14:36:44 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SaveContainerPath(current);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LibraryView::SaveContainerPath(const QModelIndex& child) {
|
|
|
|
QModelIndex current = model()->parent(child);
|
|
|
|
QVariant type = model()->data(current, LibraryModel::Role_Type);
|
2017-08-09 15:12:36 +02:00
|
|
|
if (!type.isValid() ||
|
|
|
|
!(type.toInt() == LibraryItem::Type_Container ||
|
|
|
|
type.toInt() == LibraryItem::Type_Divider)) {
|
2012-08-26 14:36:44 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString text = model()->data(current, LibraryModel::Role_SortText).toString();
|
|
|
|
last_selected_path_ << text;
|
|
|
|
SaveContainerPath(current);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LibraryView::RestoreFocus() {
|
2014-02-07 16:34:20 +01:00
|
|
|
if (last_selected_container_.isEmpty() &&
|
|
|
|
last_selected_song_.url().isEmpty()) {
|
2012-08-26 14:36:44 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
RestoreLevelFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LibraryView::RestoreLevelFocus(const QModelIndex& parent) {
|
|
|
|
if (model()->canFetchMore(parent)) {
|
|
|
|
model()->fetchMore(parent);
|
|
|
|
}
|
|
|
|
int rows = model()->rowCount(parent);
|
|
|
|
for (int i = 0; i < rows; i++) {
|
|
|
|
QModelIndex current = model()->index(i, 0, parent);
|
|
|
|
QVariant type = model()->data(current, LibraryModel::Role_Type);
|
|
|
|
switch (type.toInt()) {
|
|
|
|
case LibraryItem::Type_Song:
|
|
|
|
if (!last_selected_song_.url().isEmpty()) {
|
|
|
|
QModelIndex index = qobject_cast<QSortFilterProxyModel*>(model())
|
2014-02-07 16:34:20 +01:00
|
|
|
->mapToSource(current);
|
2012-08-26 14:36:44 +02:00
|
|
|
SongList songs = app_->library_model()->GetChildSongs(index);
|
2014-02-10 14:29:07 +01:00
|
|
|
for (const Song& song : songs) {
|
2012-08-26 14:36:44 +02:00
|
|
|
if (song == last_selected_song_) {
|
|
|
|
setCurrentIndex(current);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LibraryItem::Type_Container:
|
|
|
|
case LibraryItem::Type_Divider: {
|
2014-02-07 16:34:20 +01:00
|
|
|
QString text =
|
2017-08-09 15:12:36 +02:00
|
|
|
model()->data(current, LibraryModel::Role_Key).toString();
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!last_selected_container_.isEmpty() &&
|
|
|
|
last_selected_container_ == text) {
|
2012-08-26 14:36:44 +02:00
|
|
|
emit expand(current);
|
|
|
|
setCurrentIndex(current);
|
|
|
|
return true;
|
|
|
|
} else if (last_selected_path_.contains(text)) {
|
|
|
|
emit expand(current);
|
2014-02-07 16:34:20 +01:00
|
|
|
// If a selected container or song were not found, we've got into a
|
|
|
|
// wrong subtree
|
2012-08-26 14:36:44 +02:00
|
|
|
// (happens with "unknown" all the time)
|
|
|
|
if (!RestoreLevelFocus(current)) {
|
|
|
|
emit collapse(current);
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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());
|
2014-02-06 16:49:49 +01:00
|
|
|
if (app_ != nullptr) {
|
2014-02-07 16:34:20 +01:00
|
|
|
app_->library_model()->set_pretty_covers(
|
|
|
|
s.value("pretty_covers", true).toBool());
|
|
|
|
app_->library_model()->set_show_dividers(
|
|
|
|
s.value("show_dividers", true).toBool());
|
2011-03-05 16:20:27 +01:00
|
|
|
}
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
2012-02-12 14:41:50 +01:00
|
|
|
void LibraryView::SetApplication(Application* app) {
|
|
|
|
app_ = app;
|
2011-03-05 16:20:27 +01:00
|
|
|
ReloadSettings();
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void LibraryView::SetFilter(LibraryFilterWidget* filter) { filter_ = filter; }
|
2011-11-05 20:09:02 +01:00
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
void LibraryView::TotalSongCountUpdated(int count) {
|
2019-11-13 19:20:17 +01:00
|
|
|
int old = total_song_count_;
|
2009-12-24 20:16:07 +01:00
|
|
|
total_song_count_ = count;
|
2014-02-07 16:34:20 +01:00
|
|
|
if (old != total_song_count_) update();
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void LibraryView::contextMenuEvent(QContextMenuEvent* e) {
|
|
|
|
if (!context_menu_) {
|
2011-01-18 18:12:05 +01:00
|
|
|
context_menu_ = new QMenu(this);
|
2014-02-07 16:34:20 +01:00
|
|
|
add_to_playlist_ = context_menu_->addAction(
|
2015-10-14 03:01:08 +02:00
|
|
|
IconLoader::Load("media-playback-start", IconLoader::Base),
|
2011-02-08 23:42:09 +01:00
|
|
|
tr("Append to current playlist"), this, SLOT(AddToPlaylist()));
|
2015-10-14 03:01:08 +02:00
|
|
|
load_ = context_menu_->addAction(
|
|
|
|
IconLoader::Load("media-playback-start", IconLoader::Base),
|
|
|
|
tr("Replace current playlist"), this, SLOT(Load()));
|
2014-02-07 16:34:20 +01:00
|
|
|
open_in_new_playlist_ = context_menu_->addAction(
|
2017-07-22 19:57:33 +02:00
|
|
|
IconLoader::Load("document-new", IconLoader::Base),
|
2015-10-14 03:01:08 +02:00
|
|
|
tr("Open in new playlist"), this, SLOT(OpenInNewPlaylist()));
|
2011-02-08 23:42:09 +01:00
|
|
|
|
|
|
|
context_menu_->addSeparator();
|
2017-08-09 15:12:36 +02:00
|
|
|
add_to_playlist_enqueue_ = context_menu_->addAction(
|
|
|
|
IconLoader::Load("go-next", IconLoader::Base), tr("Queue track"), this,
|
|
|
|
SLOT(AddToPlaylistEnqueue()));
|
2018-03-19 03:44:00 +01:00
|
|
|
add_to_playlist_enqueue_next_ = context_menu_->addAction(
|
|
|
|
IconLoader::Load("go-next", IconLoader::Base), tr("Play next"), this,
|
2018-04-14 22:57:06 +02:00
|
|
|
SLOT(AddToPlaylistEnqueueNext()));
|
2017-08-09 15:12:36 +02:00
|
|
|
context_menu_->addSeparator();
|
|
|
|
search_for_this_ = context_menu_->addAction(
|
|
|
|
IconLoader::Load("system-search", IconLoader::Base),
|
|
|
|
tr("Search for this"), this, SLOT(SearchForThis()));
|
2011-01-18 18:12:05 +01:00
|
|
|
context_menu_->addSeparator();
|
2014-02-07 16:34:20 +01:00
|
|
|
new_smart_playlist_ = context_menu_->addAction(
|
2017-07-22 19:57:33 +02:00
|
|
|
IconLoader::Load("document-new", IconLoader::Base),
|
2015-10-14 03:01:08 +02:00
|
|
|
tr("New smart playlist..."), this, SLOT(NewSmartPlaylist()));
|
2014-02-07 16:34:20 +01:00
|
|
|
edit_smart_playlist_ = context_menu_->addAction(
|
2017-07-22 19:57:33 +02:00
|
|
|
IconLoader::Load("edit-rename", IconLoader::Base),
|
2015-10-14 03:01:08 +02:00
|
|
|
tr("Edit smart playlist..."), this, SLOT(EditSmartPlaylist()));
|
2014-02-07 16:34:20 +01:00
|
|
|
delete_smart_playlist_ = context_menu_->addAction(
|
2017-07-22 19:57:33 +02:00
|
|
|
IconLoader::Load("edit-delete", IconLoader::Base),
|
2015-10-14 03:01:08 +02:00
|
|
|
tr("Delete smart playlist"), this, SLOT(DeleteSmartPlaylist()));
|
2011-01-18 18:12:05 +01:00
|
|
|
|
|
|
|
context_menu_->addSeparator();
|
2017-08-09 15:12:36 +02:00
|
|
|
organise_ = context_menu_->addAction(
|
|
|
|
IconLoader::Load("edit-copy", IconLoader::Base),
|
|
|
|
tr("Organise files..."), this, SLOT(Organise()));
|
2014-02-07 16:34:20 +01:00
|
|
|
copy_to_device_ = context_menu_->addAction(
|
2015-10-14 03:01:08 +02:00
|
|
|
IconLoader::Load("multimedia-player-ipod-mini-blue", IconLoader::Base),
|
2011-01-18 18:12:05 +01:00
|
|
|
tr("Copy to device..."), this, SLOT(CopyToDevice()));
|
2017-08-09 15:12:36 +02:00
|
|
|
delete_ = context_menu_->addAction(
|
|
|
|
IconLoader::Load("edit-delete", IconLoader::Base),
|
|
|
|
tr("Delete from disk..."), this, SLOT(Delete()));
|
2011-01-18 18:12:05 +01:00
|
|
|
|
|
|
|
context_menu_->addSeparator();
|
2017-08-09 15:12:36 +02:00
|
|
|
edit_track_ = context_menu_->addAction(
|
|
|
|
IconLoader::Load("edit-rename", IconLoader::Base),
|
|
|
|
tr("Edit track information..."), this, SLOT(EditTracks()));
|
|
|
|
edit_tracks_ = context_menu_->addAction(
|
|
|
|
IconLoader::Load("edit-rename", IconLoader::Base),
|
|
|
|
tr("Edit tracks information..."), this, SLOT(EditTracks()));
|
2014-02-07 16:34:20 +01:00
|
|
|
show_in_browser_ = context_menu_->addAction(
|
2017-07-22 19:57:33 +02:00
|
|
|
IconLoader::Load("document-open-folder", IconLoader::Base),
|
2015-10-14 03:01:08 +02:00
|
|
|
tr("Show in file browser..."), this, SLOT(ShowInBrowser()));
|
2011-01-18 18:12:05 +01:00
|
|
|
|
|
|
|
context_menu_->addSeparator();
|
2014-02-07 16:34:20 +01:00
|
|
|
show_in_various_ = context_menu_->addAction(tr("Show in various artists"),
|
|
|
|
this, SLOT(ShowInVarious()));
|
2011-01-18 18:12:05 +01:00
|
|
|
no_show_in_various_ = context_menu_->addAction(
|
|
|
|
tr("Don't show in various artists"), this, SLOT(NoShowInVarious()));
|
|
|
|
|
|
|
|
context_menu_->addSeparator();
|
|
|
|
|
2011-11-05 20:09:02 +01:00
|
|
|
context_menu_->addMenu(filter_->menu());
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
copy_to_device_->setDisabled(
|
|
|
|
app_->device_manager()->connected_devices_model()->rowCount() == 0);
|
|
|
|
connect(app_->device_manager()->connected_devices_model(),
|
|
|
|
SIGNAL(IsEmptyChanged(bool)), copy_to_device_,
|
|
|
|
SLOT(setDisabled(bool)));
|
2011-01-18 18:12:05 +01:00
|
|
|
}
|
|
|
|
|
2010-03-21 00:59:39 +01:00
|
|
|
context_menu_index_ = indexAt(e->pos());
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!context_menu_index_.isValid()) return;
|
2010-03-21 00:59:39 +01:00
|
|
|
|
|
|
|
context_menu_index_ = qobject_cast<QSortFilterProxyModel*>(model())
|
2014-02-07 16:34:20 +01:00
|
|
|
->mapToSource(context_menu_index_);
|
2010-03-21 00:59:39 +01:00
|
|
|
|
2011-02-21 21:06:44 +01:00
|
|
|
QModelIndexList selected_indexes =
|
2014-02-07 16:34:20 +01:00
|
|
|
qobject_cast<QSortFilterProxyModel*>(model())
|
|
|
|
->mapSelectionToSource(selectionModel()->selection())
|
|
|
|
.indexes();
|
2011-02-21 21:06:44 +01:00
|
|
|
|
|
|
|
// 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;
|
2017-08-09 15:12:36 +02:00
|
|
|
// number of container elements selected
|
|
|
|
int container_elements = 0;
|
2011-02-21 21:06:44 +01:00
|
|
|
|
2014-02-10 14:29:07 +01:00
|
|
|
for (const QModelIndex& index : selected_indexes) {
|
2014-02-07 16:34:20 +01:00
|
|
|
int type =
|
|
|
|
app_->library_model()->data(index, LibraryModel::Role_Type).toInt();
|
2011-02-21 21:06:44 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
if (type == LibraryItem::Type_SmartPlaylist) {
|
2011-02-21 21:06:44 +01:00
|
|
|
smart_playlists++;
|
2014-02-07 16:34:20 +01:00
|
|
|
} else if (type == LibraryItem::Type_PlaylistContainer) {
|
2011-02-21 21:06:44 +01:00
|
|
|
smart_playlists_header++;
|
2017-08-09 15:12:36 +02:00
|
|
|
} else if (type == LibraryItem::Type_Container) {
|
|
|
|
container_elements++;
|
|
|
|
// To preserve expected behavior, since a container is "regular"
|
|
|
|
regular_elements++;
|
2011-02-21 21:06:44 +01:00
|
|
|
} else {
|
|
|
|
regular_elements++;
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
if (app_->library_model()
|
|
|
|
->data(index, LibraryModel::Role_Editable)
|
|
|
|
.toBool()) {
|
2011-02-21 21:06:44 +01:00
|
|
|
regular_editable++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-18 17:34:43 +01:00
|
|
|
// TODO: check if custom plugin actions should be enabled / visible
|
2014-02-07 16:34:20 +01:00
|
|
|
const int songs_selected =
|
|
|
|
smart_playlists + smart_playlists_header + regular_elements;
|
|
|
|
const bool regular_elements_only =
|
|
|
|
songs_selected == regular_elements && regular_elements > 0;
|
|
|
|
const bool smart_playlists_only =
|
|
|
|
songs_selected == smart_playlists + smart_playlists_header;
|
|
|
|
const bool only_smart_playlist_selected =
|
|
|
|
smart_playlists == 1 && songs_selected == 1;
|
2017-08-09 15:12:36 +02:00
|
|
|
const bool one_regular_song_only =
|
|
|
|
regular_elements_only && container_elements == 0 && regular_elements == 1;
|
|
|
|
const bool one_container_only =
|
|
|
|
container_elements == 1 && songs_selected == 1;
|
2011-02-21 21:06:44 +01:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
2017-08-09 15:12:36 +02:00
|
|
|
// only when a single container or one song is selected exclusively
|
|
|
|
search_for_this_->setVisible(one_container_only || one_regular_song_only);
|
|
|
|
|
2011-02-21 21:06:44 +01:00
|
|
|
// 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());
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void LibraryView::ShowInVarious() { ShowInVarious(true); }
|
2010-03-21 00:59:39 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void LibraryView::NoShowInVarious() { ShowInVarious(false); }
|
2010-03-21 00:59:39 +01:00
|
|
|
|
|
|
|
void LibraryView::ShowInVarious(bool on) {
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!context_menu_index_.isValid()) return;
|
|
|
|
|
|
|
|
// Map is from album name -> all artists sharing that album name, built from
|
|
|
|
// each selected
|
|
|
|
// song. We put through "Various Artists" changes one album at a time, to make
|
|
|
|
// sure the old album
|
|
|
|
// node gets removed (due to all children removed), before the new one gets
|
|
|
|
// added
|
2011-11-28 07:11:46 +01:00
|
|
|
QMultiMap<QString, QString> albums;
|
2014-02-10 14:29:07 +01:00
|
|
|
for (const Song& song : GetSelectedSongs()) {
|
2011-11-28 07:11:46 +01:00
|
|
|
if (albums.find(song.album(), song.artist()) == albums.end())
|
2014-02-07 16:34:20 +01:00
|
|
|
albums.insert(song.album(), song.artist());
|
2010-12-11 15:17:07 +01:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
// If we have only one album and we are putting it into Various Artists, check
|
|
|
|
// to see
|
|
|
|
// if there are other Artists in this album and prompt the user if they'd like
|
|
|
|
// them moved, too
|
|
|
|
if (on && albums.keys().count() == 1) {
|
2012-02-19 14:38:24 +01:00
|
|
|
const QString album = albums.keys().first();
|
2012-02-13 21:44:04 +01:00
|
|
|
QList<Song> all_of_album = app_->library_backend()->GetSongsByAlbum(album);
|
2012-02-19 14:38:24 +01:00
|
|
|
QSet<QString> other_artists;
|
2014-02-10 14:29:07 +01:00
|
|
|
for (const Song& s : all_of_album) {
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!albums.contains(album, s.artist()) &&
|
|
|
|
!other_artists.contains(s.artist())) {
|
2012-02-19 14:38:24 +01:00
|
|
|
other_artists.insert(s.artist());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (other_artists.count() > 0) {
|
2014-02-07 16:34:20 +01:00
|
|
|
if (QMessageBox::question(this, tr("There are other songs in this album"),
|
|
|
|
tr("Would you like to move the other songs in "
|
|
|
|
"this album to Various Artists as well?"),
|
|
|
|
QMessageBox::Yes | QMessageBox::No,
|
|
|
|
QMessageBox::Yes) == QMessageBox::Yes) {
|
2014-02-10 14:29:07 +01:00
|
|
|
for (const QString& s : other_artists) {
|
|
|
|
albums.insert(album, s);
|
|
|
|
}
|
2012-02-19 14:38:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 14:29:07 +01:00
|
|
|
for (const QString& album : QSet<QString>::fromList(albums.keys())) {
|
2012-02-12 14:41:50 +01:00
|
|
|
app_->library_backend()->ForceCompilation(album, albums.values(album), on);
|
2010-12-11 15:17:07 +01:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2018-03-19 03:44:00 +01:00
|
|
|
void LibraryView::AddToPlaylistEnqueueNext() {
|
2018-04-14 22:57:06 +02:00
|
|
|
QMimeData* data = model()->mimeData(selectedIndexes());
|
|
|
|
if (MimeData* mime_data = qobject_cast<MimeData*>(data)) {
|
|
|
|
mime_data->enqueue_next_now_ = true;
|
|
|
|
}
|
|
|
|
emit AddToPlaylistSignal(data);
|
2018-03-19 03:44:00 +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
|
|
|
|
2017-11-21 11:02:36 +01:00
|
|
|
// get selected songs
|
2010-08-30 17:28:55 +02:00
|
|
|
SongList LibraryView::GetSelectedSongs() const {
|
2010-06-25 00:45:30 +02:00
|
|
|
QModelIndexList selected_indexes =
|
2014-02-07 16:34:20 +01:00
|
|
|
qobject_cast<QSortFilterProxyModel*>(model())
|
|
|
|
->mapSelectionToSource(selectionModel()->selection())
|
|
|
|
.indexes();
|
2012-02-12 14:41:50 +01:00
|
|
|
return app_->library_model()->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_)
|
2017-07-22 19:57:33 +02:00
|
|
|
organise_dialog_.reset(new OrganiseDialog(app_->task_manager(),
|
|
|
|
app_->library_backend()));
|
2010-08-27 18:15:54 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
organise_dialog_->SetDestinationModel(
|
|
|
|
app_->library_model()->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 {
|
2014-02-07 16:34:20 +01:00
|
|
|
QMessageBox::warning(
|
|
|
|
this, tr("Error"),
|
2010-09-15 22:00:17 +02:00
|
|
|
tr("None of the selected songs were suitable for copying to a device"));
|
|
|
|
}
|
2010-06-25 00:45:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void LibraryView::Delete() {
|
2013-02-23 22:02:51 +01:00
|
|
|
if (QMessageBox::warning(this, tr("Delete files"),
|
2014-02-07 16:34:20 +01:00
|
|
|
tr("These files will be permanently deleted from "
|
|
|
|
"disk, are you sure you want to continue?"),
|
|
|
|
QMessageBox::Yes,
|
|
|
|
QMessageBox::Cancel) != QMessageBox::Yes)
|
2010-07-31 18:12:16 +02:00
|
|
|
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.
|
2014-02-06 14:48:00 +01:00
|
|
|
std::shared_ptr<MusicStorage> storage =
|
2014-02-07 16:34:20 +01:00
|
|
|
app_->library_model()
|
|
|
|
->directory_model()
|
|
|
|
->index(0, 0)
|
|
|
|
.data(MusicStorage::Role_Storage)
|
|
|
|
.value<std::shared_ptr<MusicStorage>>();
|
2010-08-09 23:50:46 +02:00
|
|
|
|
2012-02-12 14:41:50 +01:00
|
|
|
DeleteFiles* delete_files = new DeleteFiles(app_->task_manager(), storage);
|
2014-02-07 16:34:20 +01: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() {
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!edit_tag_dialog_) {
|
2012-02-12 14:41:50 +01:00
|
|
|
edit_tag_dialog_.reset(new EditTagDialog(app_, this));
|
2010-12-06 22:16:04 +01:00
|
|
|
}
|
|
|
|
edit_tag_dialog_->SetSongs(GetSelectedSongs());
|
|
|
|
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_)
|
2017-07-22 19:57:33 +02:00
|
|
|
// Don't notify song has been replaced if copying to device, so
|
|
|
|
// don't associate the organise dialog with the library backend.
|
|
|
|
// Could improve this behavior if the device has a separate set of saved
|
|
|
|
// playlists that are somehow in sync with the library.
|
2012-02-12 14:41:50 +01:00
|
|
|
organise_dialog_.reset(new OrganiseDialog(app_->task_manager()));
|
2010-08-27 18:15:54 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
organise_dialog_->SetDestinationModel(
|
|
|
|
app_->device_manager()->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) {
|
2014-02-07 16:34:20 +01:00
|
|
|
if (songs_with_errors.isEmpty()) return;
|
2010-08-14 13:51:50 +02:00
|
|
|
|
|
|
|
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
|
2014-02-07 16:34:20 +01:00
|
|
|
for (int row = 0; row < model()->rowCount(); ++row) {
|
2010-08-29 14:15:30 +02:00
|
|
|
QModelIndex idx(model()->index(row, 0));
|
|
|
|
if (idx.data(LibraryModel::Role_Type) != LibraryItem::Type_Divider) {
|
|
|
|
setCurrentIndex(idx);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!currentIndex().isValid()) return;
|
2010-08-29 14:15:30 +02:00
|
|
|
|
|
|
|
emit doubleClicked(currentIndex());
|
|
|
|
}
|
2010-11-18 20:34:04 +01:00
|
|
|
|
2017-08-09 15:12:36 +02:00
|
|
|
void LibraryView::SearchForThis() {
|
|
|
|
SaveFocus();
|
|
|
|
if (!last_selected_text_.isEmpty()) {
|
|
|
|
filter_->ShowInLibrary(last_selected_text_.simplified());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-18 20:34:04 +01:00
|
|
|
void LibraryView::NewSmartPlaylist() {
|
2012-05-30 12:06:25 +02:00
|
|
|
Wizard* wizard = new Wizard(app_, app_->library_backend(), this);
|
2010-11-19 00:08:37 +01:00
|
|
|
wizard->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
connect(wizard, SIGNAL(accepted()), SLOT(NewSmartPlaylistFinished()));
|
|
|
|
|
|
|
|
wizard->show();
|
2010-11-18 20:34:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LibraryView::EditSmartPlaylist() {
|
2012-05-30 12:06:25 +02:00
|
|
|
Wizard* wizard = new Wizard(app_, app_->library_backend(), this);
|
2010-11-19 00:08:37 +01:00
|
|
|
wizard->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
connect(wizard, SIGNAL(accepted()), SLOT(EditSmartPlaylistFinished()));
|
|
|
|
|
|
|
|
wizard->show();
|
2014-02-07 16:34:20 +01:00
|
|
|
wizard->SetGenerator(
|
|
|
|
app_->library_model()->CreateGenerator(context_menu_index_));
|
2010-11-18 20:34:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LibraryView::DeleteSmartPlaylist() {
|
2012-02-12 14:41:50 +01:00
|
|
|
app_->library_model()->DeleteGenerator(context_menu_index_);
|
2010-11-19 00:08:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LibraryView::NewSmartPlaylistFinished() {
|
|
|
|
const Wizard* wizard = qobject_cast<Wizard*>(sender());
|
2012-02-12 14:41:50 +01:00
|
|
|
app_->library_model()->AddGenerator(wizard->CreateGenerator());
|
2010-11-19 00:08:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LibraryView::EditSmartPlaylistFinished() {
|
|
|
|
const Wizard* wizard = qobject_cast<Wizard*>(sender());
|
2014-02-07 16:34:20 +01:00
|
|
|
app_->library_model()->UpdateGenerator(context_menu_index_,
|
|
|
|
wizard->CreateGenerator());
|
2010-11-18 20:34:04 +01:00
|
|
|
}
|
2011-02-14 18:00:13 +01:00
|
|
|
|
2011-03-17 20:52:21 +01:00
|
|
|
void LibraryView::ShowInBrowser() {
|
2011-10-26 14:54:24 +02:00
|
|
|
QList<QUrl> urls;
|
2014-02-10 14:29:07 +01:00
|
|
|
for (const Song& song : GetSelectedSongs()) {
|
|
|
|
urls << song.url();
|
|
|
|
}
|
2011-03-17 20:52:21 +01:00
|
|
|
|
2011-10-26 14:54:24 +02:00
|
|
|
Utilities::OpenInFileBrowser(urls);
|
2011-03-17 20:52:21 +01:00
|
|
|
}
|