2010-07-03 23:05:55 +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-03 23:05:55 +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/>.
|
|
|
|
*/
|
|
|
|
|
2014-02-06 14:48:00 +01:00
|
|
|
#include "deviceview.h"
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QContextMenuEvent>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QSortFilterProxyModel>
|
|
|
|
|
2010-07-04 01:00:07 +02:00
|
|
|
#include "connecteddevice.h"
|
2011-08-11 00:59:34 +02:00
|
|
|
#include "devicelister.h"
|
2010-07-04 01:00:07 +02:00
|
|
|
#include "devicemanager.h"
|
2010-07-04 17:01:24 +02:00
|
|
|
#include "deviceproperties.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"
|
2010-07-04 01:00:07 +02:00
|
|
|
#include "core/mergedproxymodel.h"
|
2011-01-10 23:26:13 +01:00
|
|
|
#include "core/mimedata.h"
|
2010-07-18 19:13:43 +02:00
|
|
|
#include "library/librarydirectorymodel.h"
|
2010-07-04 01:00:07 +02:00
|
|
|
#include "library/librarymodel.h"
|
2011-02-14 18:00:13 +01:00
|
|
|
#include "library/libraryview.h"
|
2010-07-04 01:00:07 +02:00
|
|
|
#include "ui/iconloader.h"
|
2010-07-18 19:13:43 +02:00
|
|
|
#include "ui/organisedialog.h"
|
2010-08-14 13:51:50 +02:00
|
|
|
#include "ui/organiseerrordialog.h"
|
2010-07-03 23:05:55 +02:00
|
|
|
|
2010-07-04 13:34:25 +02:00
|
|
|
const int DeviceItemDelegate::kIconPadding = 6;
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
DeviceItemDelegate::DeviceItemDelegate(QObject* parent)
|
|
|
|
: LibraryItemDelegate(parent) {}
|
2010-07-04 13:34:25 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void DeviceItemDelegate::paint(QPainter* p, const QStyleOptionViewItem& opt,
|
|
|
|
const QModelIndex& index) const {
|
2010-07-04 13:34:25 +02:00
|
|
|
// Is it a device or a library item?
|
|
|
|
if (index.data(DeviceManager::Role_State).isNull()) {
|
|
|
|
LibraryItemDelegate::paint(p, opt, index);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw the background
|
2014-02-07 16:34:20 +01:00
|
|
|
const QStyleOptionViewItemV3* vopt =
|
|
|
|
qstyleoption_cast<const QStyleOptionViewItemV3*>(&opt);
|
2010-09-10 21:59:29 +02:00
|
|
|
const QWidget* widget = vopt->widget;
|
|
|
|
QStyle* style = widget->style() ? widget->style() : QApplication::style();
|
|
|
|
style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, p, widget);
|
2010-07-04 13:34:25 +02:00
|
|
|
|
|
|
|
p->save();
|
|
|
|
|
|
|
|
// Font for the status line
|
|
|
|
QFont status_font(opt.font);
|
2010-08-30 16:47:30 +02:00
|
|
|
|
|
|
|
#ifdef Q_OS_WIN32
|
2010-08-28 20:43:01 +02:00
|
|
|
status_font.setPointSize(status_font.pointSize() - 1);
|
2010-08-30 16:47:30 +02:00
|
|
|
#else
|
|
|
|
status_font.setPointSize(status_font.pointSize() - 2);
|
|
|
|
#endif
|
2010-07-04 13:34:25 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
const int text_height =
|
|
|
|
QFontMetrics(opt.font).height() + QFontMetrics(status_font).height();
|
2010-07-04 13:34:25 +02:00
|
|
|
|
|
|
|
QRect line1(opt.rect);
|
|
|
|
QRect line2(opt.rect);
|
|
|
|
line1.setTop(line1.top() + (opt.rect.height() - text_height) / 2);
|
|
|
|
line2.setTop(line1.top() + QFontMetrics(opt.font).height());
|
|
|
|
line1.setLeft(line1.left() + DeviceManager::kDeviceIconSize + kIconPadding);
|
|
|
|
line2.setLeft(line2.left() + DeviceManager::kDeviceIconSize + kIconPadding);
|
|
|
|
|
|
|
|
// Change the color for selected items
|
|
|
|
if (opt.state & QStyle::State_Selected) {
|
|
|
|
p->setPen(opt.palette.color(QPalette::HighlightedText));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw the icon
|
2014-02-07 16:34:20 +01:00
|
|
|
p->drawPixmap(opt.rect.topLeft(),
|
|
|
|
index.data(Qt::DecorationRole).value<QPixmap>());
|
2010-07-04 13:34:25 +02:00
|
|
|
|
|
|
|
// Draw the first line (device name)
|
|
|
|
p->drawText(line1, Qt::AlignLeft | Qt::AlignTop, index.data().toString());
|
|
|
|
|
|
|
|
// Draw the second line (status)
|
2014-02-07 16:34:20 +01:00
|
|
|
DeviceManager::State state = static_cast<DeviceManager::State>(
|
|
|
|
index.data(DeviceManager::Role_State).toInt());
|
2010-07-04 17:56:08 +02:00
|
|
|
QVariant progress = index.data(DeviceManager::Role_UpdatingPercentage);
|
|
|
|
QString status_text;
|
|
|
|
|
|
|
|
if (progress.isValid()) {
|
|
|
|
status_text = tr("Updating %1%...").arg(progress.toInt());
|
|
|
|
} else {
|
|
|
|
switch (state) {
|
|
|
|
case DeviceManager::State_Remembered:
|
|
|
|
status_text = tr("Not connected");
|
|
|
|
break;
|
|
|
|
|
2010-09-11 14:29:44 +02:00
|
|
|
case DeviceManager::State_NotMounted:
|
|
|
|
status_text = tr("Not mounted - double click to mount");
|
|
|
|
break;
|
|
|
|
|
2010-07-04 17:56:08 +02:00
|
|
|
case DeviceManager::State_NotConnected:
|
|
|
|
status_text = tr("Double click to open");
|
|
|
|
break;
|
|
|
|
|
2010-08-30 16:45:27 +02:00
|
|
|
case DeviceManager::State_Connected: {
|
|
|
|
QVariant song_count = index.data(DeviceManager::Role_SongCount);
|
|
|
|
if (song_count.isValid()) {
|
|
|
|
int count = song_count.toInt();
|
2014-02-07 16:34:20 +01:00
|
|
|
if (count == 1) // TODO: Fix this properly
|
2010-08-30 16:45:27 +02:00
|
|
|
status_text = tr("%1 song").arg(count);
|
|
|
|
else
|
|
|
|
status_text = tr("%1 songs").arg(count);
|
|
|
|
} else {
|
|
|
|
status_text = index.data(DeviceManager::Role_MountPath).toString();
|
|
|
|
}
|
2010-07-04 17:56:08 +02:00
|
|
|
break;
|
2010-08-30 16:45:27 +02:00
|
|
|
}
|
2010-07-04 17:56:08 +02:00
|
|
|
}
|
2010-07-04 13:34:25 +02:00
|
|
|
}
|
|
|
|
|
2010-08-28 20:43:01 +02:00
|
|
|
if (opt.state & QStyle::State_Selected)
|
|
|
|
p->setPen(opt.palette.color(QPalette::HighlightedText));
|
|
|
|
else
|
|
|
|
p->setPen(opt.palette.color(QPalette::Dark));
|
|
|
|
p->setFont(status_font);
|
2010-07-04 17:56:08 +02:00
|
|
|
p->drawText(line2, Qt::AlignLeft | Qt::AlignTop, status_text);
|
|
|
|
|
2010-07-04 13:34:25 +02:00
|
|
|
p->restore();
|
|
|
|
}
|
|
|
|
|
2010-07-03 23:05:55 +02:00
|
|
|
DeviceView::DeviceView(QWidget* parent)
|
2014-02-07 16:34:20 +01:00
|
|
|
: AutoExpandingTreeView(parent),
|
|
|
|
app_(nullptr),
|
|
|
|
merged_model_(nullptr),
|
|
|
|
sort_model_(nullptr),
|
|
|
|
properties_dialog_(new DeviceProperties),
|
|
|
|
device_menu_(nullptr),
|
|
|
|
library_menu_(nullptr) {
|
2010-07-04 13:34:25 +02:00
|
|
|
setItemDelegate(new DeviceItemDelegate(this));
|
2010-07-04 02:37:41 +02:00
|
|
|
SetExpandOnReset(false);
|
2010-08-26 14:34:03 +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-07-04 01:00:07 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
DeviceView::~DeviceView() {}
|
2010-07-04 17:01:24 +02:00
|
|
|
|
2012-02-12 14:41:50 +01:00
|
|
|
void DeviceView::SetApplication(Application* app) {
|
2014-02-06 16:49:49 +01:00
|
|
|
Q_ASSERT(app_ == nullptr);
|
2012-02-12 14:41:50 +01:00
|
|
|
app_ = app;
|
2010-07-04 01:00:07 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
connect(app_->device_manager(), SIGNAL(DeviceConnected(int)),
|
|
|
|
SLOT(DeviceConnected(int)));
|
|
|
|
connect(app_->device_manager(), SIGNAL(DeviceDisconnected(int)),
|
|
|
|
SLOT(DeviceDisconnected(int)));
|
2010-07-04 01:00:07 +02:00
|
|
|
|
2010-07-04 02:58:01 +02:00
|
|
|
sort_model_ = new QSortFilterProxyModel(this);
|
2012-02-12 14:41:50 +01:00
|
|
|
sort_model_->setSourceModel(app_->device_manager());
|
2010-07-04 02:58:01 +02:00
|
|
|
sort_model_->setDynamicSortFilter(true);
|
2010-08-14 14:30:51 +02:00
|
|
|
sort_model_->setSortCaseSensitivity(Qt::CaseInsensitive);
|
2010-07-04 02:58:01 +02:00
|
|
|
sort_model_->sort(0);
|
|
|
|
|
2010-07-04 01:00:07 +02:00
|
|
|
merged_model_ = new MergedProxyModel(this);
|
2010-07-04 02:58:01 +02:00
|
|
|
merged_model_->setSourceModel(sort_model_);
|
2010-07-04 01:00:07 +02:00
|
|
|
|
2010-07-04 02:37:41 +02:00
|
|
|
connect(merged_model_,
|
2014-02-07 16:34:20 +01:00
|
|
|
SIGNAL(SubModelReset(QModelIndex, QAbstractItemModel*)),
|
2010-07-04 02:37:41 +02:00
|
|
|
SLOT(RecursivelyExpand(QModelIndex)));
|
|
|
|
|
2010-07-04 02:58:01 +02:00
|
|
|
setModel(merged_model_);
|
2012-02-12 14:41:50 +01:00
|
|
|
properties_dialog_->SetDeviceManager(app_->device_manager());
|
2010-07-18 19:13:43 +02:00
|
|
|
|
2012-02-12 14:41:50 +01:00
|
|
|
organise_dialog_.reset(new OrganiseDialog(app_->task_manager()));
|
2014-02-07 16:34:20 +01:00
|
|
|
organise_dialog_->SetDestinationModel(
|
|
|
|
app_->library_model()->directory_model());
|
2010-07-18 19:13:43 +02:00
|
|
|
}
|
|
|
|
|
2010-07-04 01:00:07 +02:00
|
|
|
void DeviceView::contextMenuEvent(QContextMenuEvent* e) {
|
2010-08-27 18:15:54 +02:00
|
|
|
if (!device_menu_) {
|
|
|
|
device_menu_ = new QMenu(this);
|
|
|
|
library_menu_ = new QMenu(this);
|
|
|
|
|
|
|
|
// Device menu
|
2014-02-07 16:34:20 +01:00
|
|
|
eject_action_ = device_menu_->addAction(IconLoader::Load("media-eject"),
|
|
|
|
tr("Safely remove device"), this,
|
|
|
|
SLOT(Unmount()));
|
|
|
|
forget_action_ =
|
|
|
|
device_menu_->addAction(IconLoader::Load("list-remove"),
|
|
|
|
tr("Forget device"), this, SLOT(Forget()));
|
2010-08-27 18:15:54 +02:00
|
|
|
device_menu_->addSeparator();
|
2014-02-07 16:34:20 +01:00
|
|
|
properties_action_ = device_menu_->addAction(IconLoader::Load("configure"),
|
|
|
|
tr("Device properties..."),
|
|
|
|
this, SLOT(Properties()));
|
2010-08-27 18:15:54 +02:00
|
|
|
|
|
|
|
// Library menu
|
2014-02-07 16:34:20 +01:00
|
|
|
add_to_playlist_action_ = library_menu_->addAction(
|
|
|
|
IconLoader::Load("media-playback-start"),
|
2011-02-08 23:42:09 +01:00
|
|
|
tr("Append to current playlist"), this, SLOT(AddToPlaylist()));
|
2014-02-07 16:34:20 +01:00
|
|
|
load_action_ = library_menu_->addAction(
|
|
|
|
IconLoader::Load("media-playback-start"),
|
2011-02-08 23:42:09 +01:00
|
|
|
tr("Replace current playlist"), this, SLOT(Load()));
|
2014-02-07 16:34:20 +01:00
|
|
|
open_in_new_playlist_ = library_menu_->addAction(
|
|
|
|
IconLoader::Load("document-new"), tr("Open in new playlist"), this,
|
|
|
|
SLOT(OpenInNewPlaylist()));
|
2010-08-27 18:15:54 +02:00
|
|
|
library_menu_->addSeparator();
|
|
|
|
organise_action_ = library_menu_->addAction(IconLoader::Load("edit-copy"),
|
2014-02-07 16:34:20 +01:00
|
|
|
tr("Copy to library..."), this,
|
|
|
|
SLOT(Organise()));
|
2010-08-27 18:15:54 +02:00
|
|
|
delete_action_ = library_menu_->addAction(IconLoader::Load("edit-delete"),
|
2014-02-07 16:34:20 +01:00
|
|
|
tr("Delete from device..."), this,
|
|
|
|
SLOT(Delete()));
|
2010-08-27 18:15:54 +02:00
|
|
|
}
|
|
|
|
|
2010-07-04 01:00:07 +02:00
|
|
|
menu_index_ = currentIndex();
|
|
|
|
|
2010-07-18 00:53:27 +02:00
|
|
|
const QModelIndex device_index = MapToDevice(menu_index_);
|
|
|
|
const QModelIndex library_index = MapToLibrary(menu_index_);
|
|
|
|
|
|
|
|
if (device_index.isValid()) {
|
2014-02-07 16:34:20 +01:00
|
|
|
const bool is_plugged_in =
|
|
|
|
app_->device_manager()->GetLister(device_index.row());
|
|
|
|
const bool is_remembered =
|
|
|
|
app_->device_manager()->GetDatabaseId(device_index.row()) != -1;
|
2010-07-18 00:53:27 +02:00
|
|
|
|
|
|
|
forget_action_->setEnabled(is_remembered);
|
2010-07-25 03:07:51 +02:00
|
|
|
eject_action_->setEnabled(is_plugged_in);
|
2010-07-04 02:33:34 +02:00
|
|
|
|
2010-07-18 00:53:27 +02:00
|
|
|
device_menu_->popup(e->globalPos());
|
|
|
|
} else if (library_index.isValid()) {
|
2010-09-04 13:27:59 +02:00
|
|
|
const QModelIndex parent_device_index = FindParentDevice(menu_index_);
|
|
|
|
|
|
|
|
bool is_filesystem_device = false;
|
|
|
|
if (parent_device_index.isValid()) {
|
2014-02-06 14:48:00 +01:00
|
|
|
std::shared_ptr<ConnectedDevice> device =
|
|
|
|
app_->device_manager()->GetConnectedDevice(parent_device_index.row());
|
2014-02-07 16:34:20 +01:00
|
|
|
if (device && !device->LocalPath().isEmpty()) is_filesystem_device = true;
|
2010-09-04 13:27:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
organise_action_->setEnabled(is_filesystem_device);
|
|
|
|
|
2010-07-18 00:53:27 +02:00
|
|
|
library_menu_->popup(e->globalPos());
|
|
|
|
}
|
2010-07-04 01:00:07 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
QModelIndex DeviceView::MapToDevice(const QModelIndex& merged_model_index)
|
|
|
|
const {
|
2010-07-04 02:58:01 +02:00
|
|
|
QModelIndex sort_model_index = merged_model_->mapToSource(merged_model_index);
|
2014-02-07 16:34:20 +01:00
|
|
|
if (sort_model_index.model() != sort_model_) return QModelIndex();
|
2010-07-04 01:00:07 +02:00
|
|
|
|
2010-07-04 02:58:01 +02:00
|
|
|
return sort_model_->mapToSource(sort_model_index);
|
2010-07-04 01:00:07 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
QModelIndex DeviceView::FindParentDevice(const QModelIndex& merged_model_index)
|
|
|
|
const {
|
2010-07-31 18:12:16 +02:00
|
|
|
QModelIndex index = merged_model_->FindSourceParent(merged_model_index);
|
2014-02-07 16:34:20 +01:00
|
|
|
if (index.model() != sort_model_) return QModelIndex();
|
2010-07-31 18:12:16 +02:00
|
|
|
|
|
|
|
return sort_model_->mapToSource(index);
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
QModelIndex DeviceView::MapToLibrary(const QModelIndex& merged_model_index)
|
|
|
|
const {
|
2010-07-18 00:53:27 +02:00
|
|
|
QModelIndex sort_model_index = merged_model_->mapToSource(merged_model_index);
|
|
|
|
if (const QSortFilterProxyModel* sort_model =
|
2014-02-07 16:34:20 +01:00
|
|
|
qobject_cast<const QSortFilterProxyModel*>(
|
|
|
|
sort_model_index.model())) {
|
2010-07-18 00:53:27 +02:00
|
|
|
return sort_model->mapToSource(sort_model_index);
|
|
|
|
}
|
|
|
|
|
|
|
|
return QModelIndex();
|
|
|
|
}
|
|
|
|
|
2010-07-04 01:00:07 +02:00
|
|
|
void DeviceView::Connect() {
|
|
|
|
QModelIndex device_idx = MapToDevice(menu_index_);
|
2014-02-07 16:34:20 +01:00
|
|
|
app_->device_manager()->data(device_idx,
|
|
|
|
MusicStorage::Role_StorageForceConnect);
|
2010-07-25 11:27:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void DeviceView::DeviceConnected(int row) {
|
2014-02-06 14:48:00 +01:00
|
|
|
std::shared_ptr<ConnectedDevice> device =
|
|
|
|
app_->device_manager()->GetConnectedDevice(row);
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!device) return;
|
2010-07-04 02:58:01 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
QModelIndex sort_idx =
|
|
|
|
sort_model_->mapFromSource(app_->device_manager()->index(row));
|
2010-07-25 11:27:41 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
QSortFilterProxyModel* sort_model =
|
|
|
|
new QSortFilterProxyModel(device->model());
|
2010-07-04 02:58:01 +02:00
|
|
|
sort_model->setSourceModel(device->model());
|
|
|
|
sort_model->setSortRole(LibraryModel::Role_SortText);
|
|
|
|
sort_model->setDynamicSortFilter(true);
|
|
|
|
sort_model->sort(0);
|
|
|
|
merged_model_->AddSubModel(sort_idx, sort_model);
|
2010-07-04 02:37:41 +02:00
|
|
|
|
|
|
|
expand(menu_index_);
|
2010-07-03 23:05:55 +02:00
|
|
|
}
|
2010-07-04 02:33:34 +02:00
|
|
|
|
|
|
|
void DeviceView::DeviceDisconnected(int row) {
|
2014-02-07 16:34:20 +01:00
|
|
|
merged_model_->RemoveSubModel(
|
|
|
|
sort_model_->mapFromSource(app_->device_manager()->index(row)));
|
2010-07-04 02:33:34 +02:00
|
|
|
}
|
2010-07-04 14:56:49 +02:00
|
|
|
|
|
|
|
void DeviceView::Forget() {
|
|
|
|
QModelIndex device_idx = MapToDevice(menu_index_);
|
2014-02-07 16:34:20 +01:00
|
|
|
QString unique_id = app_->device_manager()
|
|
|
|
->data(device_idx, DeviceManager::Role_UniqueId)
|
|
|
|
.toString();
|
2012-02-12 14:41:50 +01:00
|
|
|
if (app_->device_manager()->GetLister(device_idx.row()) &&
|
2014-02-07 16:34:20 +01:00
|
|
|
app_->device_manager()->GetLister(device_idx.row())->AskForScan(
|
|
|
|
unique_id)) {
|
2014-02-06 14:48:00 +01:00
|
|
|
std::unique_ptr<QMessageBox> dialog(new QMessageBox(
|
2011-08-11 00:59:34 +02:00
|
|
|
QMessageBox::Question, tr("Forget device"),
|
2014-02-07 16:34:20 +01:00
|
|
|
tr("Forgetting a device will remove it from this list and Clementine "
|
|
|
|
"will have to rescan all the songs again next time you connect it."),
|
2011-08-11 00:59:34 +02:00
|
|
|
QMessageBox::Cancel, this));
|
|
|
|
QPushButton* forget =
|
|
|
|
dialog->addButton(tr("Forget device"), QMessageBox::DestructiveRole);
|
|
|
|
dialog->exec();
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
if (dialog->clickedButton() != forget) return;
|
2011-08-11 00:59:34 +02:00
|
|
|
}
|
|
|
|
|
2012-02-12 14:41:50 +01:00
|
|
|
app_->device_manager()->Forget(device_idx.row());
|
2010-07-04 14:56:49 +02:00
|
|
|
}
|
2010-07-04 17:01:24 +02:00
|
|
|
|
|
|
|
void DeviceView::Properties() {
|
|
|
|
properties_dialog_->ShowDevice(MapToDevice(menu_index_).row());
|
|
|
|
}
|
2010-07-04 17:25:11 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void DeviceView::mouseDoubleClickEvent(QMouseEvent* event) {
|
2010-07-04 17:25:11 +02:00
|
|
|
AutoExpandingTreeView::mouseDoubleClickEvent(event);
|
|
|
|
|
|
|
|
QModelIndex merged_index = indexAt(event->pos());
|
|
|
|
QModelIndex device_index = MapToDevice(merged_index);
|
2010-07-18 00:53:27 +02:00
|
|
|
if (device_index.isValid()) {
|
2012-02-12 14:41:50 +01:00
|
|
|
if (!app_->device_manager()->GetConnectedDevice(device_index.row())) {
|
2010-07-18 00:53:27 +02:00
|
|
|
menu_index_ = merged_index;
|
|
|
|
Connect();
|
|
|
|
}
|
2010-07-04 17:25:11 +02:00
|
|
|
}
|
|
|
|
}
|
2010-07-18 00:53:27 +02:00
|
|
|
|
|
|
|
SongList DeviceView::GetSelectedSongs() const {
|
|
|
|
QModelIndexList selected_merged_indexes = selectionModel()->selectedRows();
|
|
|
|
SongList songs;
|
2014-02-10 14:29:07 +01:00
|
|
|
for (const QModelIndex& merged_index : selected_merged_indexes) {
|
2010-07-18 00:53:27 +02:00
|
|
|
QModelIndex library_index = MapToLibrary(merged_index);
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!library_index.isValid()) continue;
|
2010-07-18 00:53:27 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
const LibraryModel* library =
|
|
|
|
qobject_cast<const LibraryModel*>(library_index.model());
|
|
|
|
if (!library) continue;
|
2010-07-18 00:53:27 +02:00
|
|
|
|
|
|
|
songs << library->GetChildSongs(library_index);
|
|
|
|
}
|
|
|
|
return songs;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeviceView::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-07-18 00:53:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void DeviceView::AddToPlaylist() {
|
2011-01-10 23:26:13 +01:00
|
|
|
emit AddToPlaylistSignal(model()->mimeData(selectedIndexes()));
|
2010-07-18 00:53:27 +02:00
|
|
|
}
|
|
|
|
|
2011-02-09 18:51:59 +01:00
|
|
|
void DeviceView::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-07-18 00:53:27 +02:00
|
|
|
void DeviceView::Delete() {
|
2014-02-07 16:34:20 +01:00
|
|
|
if (selectedIndexes().isEmpty()) return;
|
2010-07-31 18:12:16 +02:00
|
|
|
|
|
|
|
// Take the device of the first selected item
|
|
|
|
QModelIndex device_index = FindParentDevice(selectedIndexes()[0]);
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!device_index.isValid()) return;
|
2010-07-31 18:12:16 +02:00
|
|
|
|
|
|
|
if (QMessageBox::question(this, tr("Delete files"),
|
2014-02-07 16:34:20 +01:00
|
|
|
tr("These files will be deleted from the device, "
|
|
|
|
"are you sure you want to continue?"),
|
|
|
|
QMessageBox::Yes,
|
|
|
|
QMessageBox::Cancel) != QMessageBox::Yes)
|
2010-07-31 18:12:16 +02:00
|
|
|
return;
|
|
|
|
|
2014-02-06 14:48:00 +01:00
|
|
|
std::shared_ptr<MusicStorage> storage =
|
2014-02-07 16:34:20 +01:00
|
|
|
device_index.data(MusicStorage::Role_Storage)
|
|
|
|
.value<std::shared_ptr<MusicStorage>>();
|
2010-07-18 00:53:27 +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-07-31 18:12:16 +02:00
|
|
|
delete_files->Start(GetSelectedSongs());
|
2010-07-18 00:53:27 +02:00
|
|
|
}
|
2010-07-18 19:13:43 +02:00
|
|
|
|
|
|
|
void DeviceView::Organise() {
|
|
|
|
SongList songs = GetSelectedSongs();
|
|
|
|
QStringList filenames;
|
2014-02-10 14:29:07 +01:00
|
|
|
for (const Song& song : songs) {
|
|
|
|
filenames << song.url().toLocalFile();
|
|
|
|
}
|
2010-07-18 19:13:43 +02:00
|
|
|
|
|
|
|
organise_dialog_->SetCopy(true);
|
|
|
|
organise_dialog_->SetFilenames(filenames);
|
|
|
|
organise_dialog_->show();
|
|
|
|
}
|
2010-07-25 03:07:51 +02:00
|
|
|
|
|
|
|
void DeviceView::Unmount() {
|
|
|
|
QModelIndex device_idx = MapToDevice(menu_index_);
|
2012-02-12 14:41:50 +01:00
|
|
|
app_->device_manager()->Unmount(device_idx.row());
|
2010-07-25 03:07:51 +02:00
|
|
|
}
|
2010-08-14 13:51:50 +02:00
|
|
|
|
|
|
|
void DeviceView::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-09-18 16:29:43 +02:00
|
|
|
|
|
|
|
bool DeviceView::CanRecursivelyExpand(const QModelIndex& index) const {
|
|
|
|
// Never expand devices
|
|
|
|
return index.parent().isValid();
|
|
|
|
}
|