Add a menu item for copying songs to devices. Only filesystem devices supported so far

This commit is contained in:
David Sansome 2010-07-19 21:16:22 +00:00
parent 62616304d8
commit 9f2d610e9d
33 changed files with 134 additions and 15 deletions

View File

@ -21,6 +21,7 @@
#include "filesystemdevice.h" #include "filesystemdevice.h"
#include "giolister.h" #include "giolister.h"
#include "gpoddevice.h" #include "gpoddevice.h"
#include "core/musicstorage.h"
#include "core/taskmanager.h" #include "core/taskmanager.h"
#include "core/utilities.h" #include "core/utilities.h"
#include "ui/iconloader.h" #include "ui/iconloader.h"
@ -38,6 +39,7 @@ DeviceStateFilterModel::DeviceStateFilterModel(QObject *parent,
: QSortFilterProxyModel(parent), : QSortFilterProxyModel(parent),
state_(state) state_(state)
{ {
setDynamicSortFilter(true);
} }
bool DeviceStateFilterModel::filterAcceptsRow(int row, const QModelIndex&) const { bool DeviceStateFilterModel::filterAcceptsRow(int row, const QModelIndex&) const {
@ -235,6 +237,11 @@ QVariant DeviceManager::data(const QModelIndex& index, int role) const {
return QVariant(); return QVariant();
return info.task_percentage_; return info.task_percentage_;
case MusicStorage::kStorageRole:
if (info.device_)
return QVariant::fromValue(info.device_->storage());
return QVariant();
default: default:
return QVariant(); return QVariant();
} }
@ -428,6 +435,7 @@ boost::shared_ptr<ConnectedDevice> DeviceManager::Connect(int row) {
qWarning() << "Could not create device for" << url.toString(); qWarning() << "Could not create device for" << url.toString();
} else { } else {
info.device_ = ret; info.device_ = ret;
emit dataChanged(index(row), index(row));
connect(info.device_.get(), SIGNAL(TaskStarted(int)), SLOT(DeviceTaskStarted(int))); connect(info.device_.get(), SIGNAL(TaskStarted(int)), SLOT(DeviceTaskStarted(int)));
connect(info.device_.get(), SIGNAL(Error(QString)), SIGNAL(Error(QString))); connect(info.device_.get(), SIGNAL(Error(QString)), SIGNAL(Error(QString)));
} }
@ -453,6 +461,7 @@ void DeviceManager::Disconnect(int row) {
return; return;
info.device_.reset(); info.device_.reset();
emit dataChanged(index(row), index(row));
emit DeviceDisconnected(row); emit DeviceDisconnected(row);
} }

View File

@ -19,6 +19,7 @@
#include "libraryview.h" #include "libraryview.h"
#include "libraryitem.h" #include "libraryitem.h"
#include "librarybackend.h" #include "librarybackend.h"
#include "devices/devicemanager.h"
#include "ui/iconloader.h" #include "ui/iconloader.h"
#include "ui/organisedialog.h" #include "ui/organisedialog.h"
@ -93,6 +94,8 @@ LibraryView::LibraryView(QWidget* parent)
context_menu_->addSeparator(); context_menu_->addSeparator();
organise_ = context_menu_->addAction(IconLoader::Load("edit-copy"), organise_ = context_menu_->addAction(IconLoader::Load("edit-copy"),
tr("Organise files..."), this, SLOT(Organise())); 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"), delete_ = context_menu_->addAction(IconLoader::Load("edit-delete"),
tr("Delete from disk..."), this, SLOT(Delete())); tr("Delete from disk..."), this, SLOT(Delete()));
context_menu_->addSeparator(); context_menu_->addSeparator();
@ -118,13 +121,16 @@ void LibraryView::ReloadSettings() {
void LibraryView::SetTaskManager(TaskManager *task_manager) { void LibraryView::SetTaskManager(TaskManager *task_manager) {
organise_dialog_.reset(new OrganiseDialog(task_manager)); organise_dialog_.reset(new OrganiseDialog(task_manager));
organise_dialog_->SetDestinationModel(library_->directory_model());
} }
void LibraryView::SetLibrary(LibraryModel *library) { void LibraryView::SetLibrary(LibraryModel *library) {
library_ = library; library_ = library;
} }
void LibraryView::SetDeviceManager(DeviceManager *device_manager) {
devices_ = device_manager;
}
void LibraryView::TotalSongCountUpdated(int count) { void LibraryView::TotalSongCountUpdated(int count) {
bool old = total_song_count_; bool old = total_song_count_;
total_song_count_ = count; total_song_count_ = count;
@ -240,22 +246,34 @@ void LibraryView::scrollTo(const QModelIndex &index, ScrollHint hint) {
QTreeView::scrollTo(index, hint); QTreeView::scrollTo(index, hint);
} }
void LibraryView::Organise() { QStringList LibraryView::GetSelectedFilenames() const {
QModelIndexList selected_indexes = QModelIndexList selected_indexes =
qobject_cast<QSortFilterProxyModel*>(model())->mapSelectionToSource( qobject_cast<QSortFilterProxyModel*>(model())->mapSelectionToSource(
selectionModel()->selection()).indexes(); selectionModel()->selection()).indexes();
SongList songs = library_->GetChildSongs(selected_indexes); SongList songs = library_->GetChildSongs(selected_indexes);
QStringList filenames; QStringList ret;
foreach (const Song& song, songs) { foreach (const Song& song, songs) {
filenames << song.filename(); ret << song.filename();
} }
return ret;
}
void LibraryView::Organise() {
organise_dialog_->SetDestinationModel(library_->directory_model());
organise_dialog_->SetCopy(false); organise_dialog_->SetCopy(false);
organise_dialog_->SetFilenames(filenames); organise_dialog_->SetFilenames(GetSelectedFilenames());
organise_dialog_->show(); organise_dialog_->show();
} }
void LibraryView::Delete() { void LibraryView::Delete() {
} }
void LibraryView::CopyToDevice() {
organise_dialog_->SetDestinationModel(devices_->connected_devices_model());
organise_dialog_->SetCopy(true);
organise_dialog_->SetFilenames(GetSelectedFilenames());
organise_dialog_->show();
}

View File

@ -23,6 +23,7 @@
#include <boost/scoped_ptr.hpp> #include <boost/scoped_ptr.hpp>
class DeviceManager;
class LibraryModel; class LibraryModel;
class OrganiseDialog; class OrganiseDialog;
class TaskManager; class TaskManager;
@ -44,6 +45,7 @@ class LibraryView : public AutoExpandingTreeView {
void SetTaskManager(TaskManager* task_manager); void SetTaskManager(TaskManager* task_manager);
void SetLibrary(LibraryModel* library); void SetLibrary(LibraryModel* library);
void SetDeviceManager(DeviceManager* device_manager);
// QTreeView // QTreeView
void keyboardSearch(const QString &search); void keyboardSearch(const QString &search);
@ -68,6 +70,7 @@ class LibraryView : public AutoExpandingTreeView {
void Load(); void Load();
void AddToPlaylist(); void AddToPlaylist();
void Organise(); void Organise();
void CopyToDevice();
void Delete(); void Delete();
void ShowInVarious(); void ShowInVarious();
void NoShowInVarious(); void NoShowInVarious();
@ -75,9 +78,12 @@ class LibraryView : public AutoExpandingTreeView {
private: private:
void RecheckIsEmpty(); void RecheckIsEmpty();
void ShowInVarious(bool on); void ShowInVarious(bool on);
QStringList GetSelectedFilenames() const;
private: private:
LibraryModel* library_; LibraryModel* library_;
DeviceManager* devices_;
int total_song_count_; int total_song_count_;
QPixmap nomusic_; QPixmap nomusic_;
@ -87,6 +93,7 @@ class LibraryView : public AutoExpandingTreeView {
QAction* load_; QAction* load_;
QAction* add_to_playlist_; QAction* add_to_playlist_;
QAction* organise_; QAction* organise_;
QAction* copy_to_device_;
QAction* delete_; QAction* delete_;
QAction* show_in_various_; QAction* show_in_various_;
QAction* no_show_in_various_; QAction* no_show_in_various_;

View File

@ -375,6 +375,9 @@ msgstr ""
msgid "Connected" msgid "Connected"
msgstr "" msgstr ""
msgid "Copy to device..."
msgstr ""
msgid "Copy to library..." msgid "Copy to library..."
msgstr "" msgstr ""

View File

@ -376,6 +376,9 @@ msgstr ""
msgid "Connected" msgid "Connected"
msgstr "" msgstr ""
msgid "Copy to device..."
msgstr ""
msgid "Copy to library..." msgid "Copy to library..."
msgstr "Zkopírovat do knihovny..." msgstr "Zkopírovat do knihovny..."

View File

@ -376,6 +376,9 @@ msgstr ""
msgid "Connected" msgid "Connected"
msgstr "" msgstr ""
msgid "Copy to device..."
msgstr ""
msgid "Copy to library..." msgid "Copy to library..."
msgstr "Kopiér til bibliotek..." msgstr "Kopiér til bibliotek..."

View File

@ -375,6 +375,9 @@ msgstr ""
msgid "Connected" msgid "Connected"
msgstr "" msgstr ""
msgid "Copy to device..."
msgstr ""
msgid "Copy to library..." msgid "Copy to library..."
msgstr "In die Musiksammlung kopieren..." msgstr "In die Musiksammlung kopieren..."

View File

@ -383,6 +383,9 @@ msgstr ""
msgid "Connected" msgid "Connected"
msgstr "" msgstr ""
msgid "Copy to device..."
msgstr ""
msgid "Copy to library..." msgid "Copy to library..."
msgstr "Αντιγραφή στην βιβλιοθήκη..." msgstr "Αντιγραφή στην βιβλιοθήκη..."

View File

@ -375,6 +375,9 @@ msgstr ""
msgid "Connected" msgid "Connected"
msgstr "" msgstr ""
msgid "Copy to device..."
msgstr ""
msgid "Copy to library..." msgid "Copy to library..."
msgstr "Copy to library..." msgstr "Copy to library..."

View File

@ -375,6 +375,9 @@ msgstr ""
msgid "Connected" msgid "Connected"
msgstr "" msgstr ""
msgid "Copy to device..."
msgstr ""
msgid "Copy to library..." msgid "Copy to library..."
msgstr "Copy to library..." msgstr "Copy to library..."

View File

@ -377,6 +377,9 @@ msgstr ""
msgid "Connected" msgid "Connected"
msgstr "" msgstr ""
msgid "Copy to device..."
msgstr ""
msgid "Copy to library..." msgid "Copy to library..."
msgstr "Copiar a la colección..." msgstr "Copiar a la colección..."

View File

@ -375,6 +375,9 @@ msgstr ""
msgid "Connected" msgid "Connected"
msgstr "" msgstr ""
msgid "Copy to device..."
msgstr ""
msgid "Copy to library..." msgid "Copy to library..."
msgstr "Kopioi kirjastoon" msgstr "Kopioi kirjastoon"

View File

@ -376,6 +376,9 @@ msgstr ""
msgid "Connected" msgid "Connected"
msgstr "" msgstr ""
msgid "Copy to device..."
msgstr ""
msgid "Copy to library..." msgid "Copy to library..."
msgstr "Copier dans la bilbiothèque..." msgstr "Copier dans la bilbiothèque..."

View File

@ -375,6 +375,9 @@ msgstr ""
msgid "Connected" msgid "Connected"
msgstr "" msgstr ""
msgid "Copy to device..."
msgstr ""
msgid "Copy to library..." msgid "Copy to library..."
msgstr "Copiar para a biblioteca" msgstr "Copiar para a biblioteca"

View File

@ -376,6 +376,9 @@ msgstr ""
msgid "Connected" msgid "Connected"
msgstr "" msgstr ""
msgid "Copy to device..."
msgstr ""
msgid "Copy to library..." msgid "Copy to library..."
msgstr "Copia nella raccolta..." msgstr "Copia nella raccolta..."

View File

@ -375,6 +375,9 @@ msgstr ""
msgid "Connected" msgid "Connected"
msgstr "" msgstr ""
msgid "Copy to device..."
msgstr ""
msgid "Copy to library..." msgid "Copy to library..."
msgstr "" msgstr ""

View File

@ -375,6 +375,9 @@ msgstr ""
msgid "Connected" msgid "Connected"
msgstr "" msgstr ""
msgid "Copy to device..."
msgstr ""
msgid "Copy to library..." msgid "Copy to library..."
msgstr "Kopier til bibliotek..." msgstr "Kopier til bibliotek..."

View File

@ -375,6 +375,9 @@ msgstr ""
msgid "Connected" msgid "Connected"
msgstr "" msgstr ""
msgid "Copy to device..."
msgstr ""
msgid "Copy to library..." msgid "Copy to library..."
msgstr "" msgstr ""

View File

@ -376,6 +376,9 @@ msgstr ""
msgid "Connected" msgid "Connected"
msgstr "" msgstr ""
msgid "Copy to device..."
msgstr ""
msgid "Copy to library..." msgid "Copy to library..."
msgstr "Skopiuj do biblioteki..." msgstr "Skopiuj do biblioteki..."

View File

@ -380,6 +380,9 @@ msgstr ""
msgid "Connected" msgid "Connected"
msgstr "" msgstr ""
msgid "Copy to device..."
msgstr ""
msgid "Copy to library..." msgid "Copy to library..."
msgstr "Copiar para a biblioteca..." msgstr "Copiar para a biblioteca..."

View File

@ -378,6 +378,9 @@ msgstr ""
msgid "Connected" msgid "Connected"
msgstr "" msgstr ""
msgid "Copy to device..."
msgstr ""
msgid "Copy to library..." msgid "Copy to library..."
msgstr "Copiar para biblioteca..." msgstr "Copiar para biblioteca..."

View File

@ -375,6 +375,9 @@ msgstr ""
msgid "Connected" msgid "Connected"
msgstr "" msgstr ""
msgid "Copy to device..."
msgstr ""
msgid "Copy to library..." msgid "Copy to library..."
msgstr "Copiază în bibliotecă..." msgstr "Copiază în bibliotecă..."

View File

@ -374,6 +374,9 @@ msgstr ""
msgid "Connected" msgid "Connected"
msgstr "" msgstr ""
msgid "Copy to device..."
msgstr ""
msgid "Copy to library..." msgid "Copy to library..."
msgstr "Копировать в коллекцию..." msgstr "Копировать в коллекцию..."

View File

@ -380,6 +380,9 @@ msgstr ""
msgid "Connected" msgid "Connected"
msgstr "" msgstr ""
msgid "Copy to device..."
msgstr ""
msgid "Copy to library..." msgid "Copy to library..."
msgstr "Skopírovať do zbierky..." msgstr "Skopírovať do zbierky..."

View File

@ -375,6 +375,9 @@ msgstr ""
msgid "Connected" msgid "Connected"
msgstr "" msgstr ""
msgid "Copy to device..."
msgstr ""
msgid "Copy to library..." msgid "Copy to library..."
msgstr "Kopiera till bibliotek..." msgstr "Kopiera till bibliotek..."

View File

@ -375,6 +375,9 @@ msgstr ""
msgid "Connected" msgid "Connected"
msgstr "" msgstr ""
msgid "Copy to device..."
msgstr ""
msgid "Copy to library..." msgid "Copy to library..."
msgstr "" msgstr ""

View File

@ -365,6 +365,9 @@ msgstr ""
msgid "Connected" msgid "Connected"
msgstr "" msgstr ""
msgid "Copy to device..."
msgstr ""
msgid "Copy to library..." msgid "Copy to library..."
msgstr "" msgstr ""

View File

@ -379,6 +379,9 @@ msgstr ""
msgid "Connected" msgid "Connected"
msgstr "" msgstr ""
msgid "Copy to device..."
msgstr ""
msgid "Copy to library..." msgid "Copy to library..."
msgstr "Скопіювати до фонотеки..." msgstr "Скопіювати до фонотеки..."

View File

@ -375,6 +375,9 @@ msgstr ""
msgid "Connected" msgid "Connected"
msgstr "" msgstr ""
msgid "Copy to device..."
msgstr ""
msgid "Copy to library..." msgid "Copy to library..."
msgstr "" msgstr ""

View File

@ -375,6 +375,9 @@ msgstr ""
msgid "Connected" msgid "Connected"
msgstr "" msgstr ""
msgid "Copy to device..."
msgstr ""
msgid "Copy to library..." msgid "Copy to library..."
msgstr "" msgstr ""

View File

@ -196,6 +196,7 @@ MainWindow::MainWindow(NetworkAccessManager* network, Engine::Type engine, QWidg
ui_->library_view->setModel(library_sort_model_); ui_->library_view->setModel(library_sort_model_);
ui_->library_view->SetLibrary(library_->model()); ui_->library_view->SetLibrary(library_->model());
ui_->library_view->SetTaskManager(task_manager_); ui_->library_view->SetTaskManager(task_manager_);
ui_->library_view->SetDeviceManager(devices_);
settings_dialog_->SetLibraryDirectoryModel(library_->model()->directory_model()); settings_dialog_->SetLibraryDirectoryModel(library_->model()->directory_model());
ui_->radio_view->SetModel(radio_model_); ui_->radio_view->SetModel(radio_model_);

View File

@ -149,12 +149,13 @@ void OrganiseDialog::InsertTag(const QString &tag) {
void OrganiseDialog::UpdatePreviews() { void OrganiseDialog::UpdatePreviews() {
const QModelIndex destination = ui_->destination->model()->index( const QModelIndex destination = ui_->destination->model()->index(
ui_->destination->currentIndex(), 0); ui_->destination->currentIndex(), 0);
if (!destination.isValid()) MusicStorage* storage = NULL;
return; bool has_local_destination = false;
const MusicStorage* storage =
destination.data(MusicStorage::kStorageRole).value<MusicStorage*>();
const bool has_local_destination = !storage->LocalPath().isEmpty(); if (destination.isValid()) {
storage = destination.data(MusicStorage::kStorageRole).value<MusicStorage*>();
has_local_destination = !storage->LocalPath().isEmpty();
}
// Update the format object // Update the format object
format_.set_format(ui_->naming->toPlainText()); format_.set_format(ui_->naming->toPlainText());
@ -163,13 +164,13 @@ void OrganiseDialog::UpdatePreviews() {
format_.set_replace_the(ui_->replace_the->isChecked()); format_.set_replace_the(ui_->replace_the->isChecked());
const bool format_valid = format_.IsValid(); const bool format_valid = format_.IsValid();
ui_->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(format_valid); ui_->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(format_valid && storage);
if (!format_valid) if (!format_valid)
return; return;
// Update the previews // Update the previews
ui_->preview->clear(); ui_->preview->clear();
ui_->preview->setVisible(has_local_destination); ui_->preview_group->setVisible(has_local_destination);
if (has_local_destination) { if (has_local_destination) {
foreach (const Song& song, preview_songs_) { foreach (const Song& song, preview_songs_) {
QString filename = storage->LocalPath() + "/" + QString filename = storage->LocalPath() + "/" +

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>639</width> <width>639</width>
<height>436</height> <height>492</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -114,7 +114,7 @@
</widget> </widget>
</item> </item>
<item row="3" column="0" colspan="2"> <item row="3" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox_2"> <widget class="QGroupBox" name="preview_group">
<property name="title"> <property name="title">
<string>Preview</string> <string>Preview</string>
</property> </property>
@ -146,7 +146,9 @@
<header>widgets/linetextedit.h</header> <header>widgets/linetextedit.h</header>
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<resources/> <resources>
<include location="../../data/data.qrc"/>
</resources>
<connections> <connections>
<connection> <connection>
<sender>buttonBox</sender> <sender>buttonBox</sender>