Add an option to eject a device after copying files to it. Now with bonus multiple virtual inheritance.

This commit is contained in:
David Sansome 2010-07-25 09:52:29 +00:00
parent 4ffc118468
commit b2aba2bac2
45 changed files with 150 additions and 24 deletions

View File

@ -19,7 +19,7 @@
#include "musicstorage.h" #include "musicstorage.h"
class FilesystemMusicStorage : public MusicStorage { class FilesystemMusicStorage : public virtual MusicStorage {
public: public:
FilesystemMusicStorage(const QString& root); FilesystemMusicStorage(const QString& root);

View File

@ -35,6 +35,7 @@ public:
const Song& metadata, bool overwrite, const Song& metadata, bool overwrite,
bool remove_original) = 0; bool remove_original) = 0;
virtual void FinishCopy() {} virtual void FinishCopy() {}
virtual void Eject() {}
}; };
Q_DECLARE_METATYPE(MusicStorage*); Q_DECLARE_METATYPE(MusicStorage*);

View File

@ -27,7 +27,7 @@ const int Organise::kBatchSize = 10;
Organise::Organise(TaskManager* task_manager, MusicStorage* destination, Organise::Organise(TaskManager* task_manager, MusicStorage* destination,
const OrganiseFormat &format, bool copy, bool overwrite, const OrganiseFormat &format, bool copy, bool overwrite,
const QStringList& files) const QStringList& files, bool eject_after)
: thread_(NULL), : thread_(NULL),
task_manager_(task_manager), task_manager_(task_manager),
destination_(destination), destination_(destination),
@ -35,6 +35,7 @@ Organise::Organise(TaskManager* task_manager, MusicStorage* destination,
copy_(copy), copy_(copy),
overwrite_(overwrite), overwrite_(overwrite),
files_(files), files_(files),
eject_after_(eject_after),
started_(false), started_(false),
task_id_(0), task_id_(0),
progress_(0) progress_(0)
@ -65,7 +66,10 @@ void Organise::ProcessSomeFiles() {
// None left? // None left?
if (progress_ >= files_.count()) { if (progress_ >= files_.count()) {
task_manager_->SetTaskProgress(task_id_, progress_, files_.count()); task_manager_->SetTaskProgress(task_id_, progress_, files_.count());
destination_->FinishCopy(); destination_->FinishCopy();
if (eject_after_)
destination_->Eject();
task_manager_->SetTaskFinished(task_id_); task_manager_->SetTaskFinished(task_id_);

View File

@ -30,7 +30,7 @@ class Organise : public QObject {
public: public:
Organise(TaskManager* task_manager, MusicStorage* destination, Organise(TaskManager* task_manager, MusicStorage* destination,
const OrganiseFormat& format, bool copy, bool overwrite, const OrganiseFormat& format, bool copy, bool overwrite,
const QStringList& files); const QStringList& files, bool eject_after);
static const int kBatchSize; static const int kBatchSize;
@ -49,6 +49,7 @@ private:
const bool copy_; const bool copy_;
const bool overwrite_; const bool overwrite_;
QStringList files_; QStringList files_;
const bool eject_after_;
bool started_; bool started_;

View File

@ -76,3 +76,7 @@ void ConnectedDevice::InitBackendDirectory(const QString& mount_point, bool firs
backend_->LoadDirectoriesAsync(); backend_->LoadDirectoriesAsync();
} }
} }
void ConnectedDevice::Eject() {
manager_->Unmount(manager_->FindDeviceById(unique_id_));
}

View File

@ -17,6 +17,8 @@
#ifndef CONNECTEDDEVICE_H #ifndef CONNECTEDDEVICE_H
#define CONNECTEDDEVICE_H #define CONNECTEDDEVICE_H
#include "core/musicstorage.h"
#include <QObject> #include <QObject>
#include <QStringList> #include <QStringList>
#include <QUrl> #include <QUrl>
@ -26,9 +28,8 @@ class DeviceLister;
class DeviceManager; class DeviceManager;
class LibraryBackend; class LibraryBackend;
class LibraryModel; class LibraryModel;
class MusicStorage;
class ConnectedDevice : public QObject { class ConnectedDevice : public QObject, public virtual MusicStorage {
Q_OBJECT Q_OBJECT
public: public:
@ -42,7 +43,7 @@ public:
LibraryModel* model() const { return model_; } LibraryModel* model() const { return model_; }
QUrl url() const { return url_; } QUrl url() const { return url_; }
virtual MusicStorage* storage() = 0; void Eject();
signals: signals:
void TaskStarted(int id); void TaskStarted(int id);

View File

@ -241,7 +241,7 @@ QVariant DeviceManager::data(const QModelIndex& index, int role) const {
const_cast<DeviceManager*>(this)->Connect(index.row()); const_cast<DeviceManager*>(this)->Connect(index.row());
if (!info.device_) if (!info.device_)
return QVariant(); return QVariant();
return QVariant::fromValue(info.device_->storage()); return QVariant::fromValue<MusicStorage*>(info.device_.get());
case Role_MountPath: case Role_MountPath:
if (!info.device_) if (!info.device_)

View File

@ -27,8 +27,8 @@ FilesystemDevice::FilesystemDevice(
const QUrl& url, DeviceLister* lister, const QUrl& url, DeviceLister* lister,
const QString& unique_id, DeviceManager* manager, const QString& unique_id, DeviceManager* manager,
int database_id, bool first_time) int database_id, bool first_time)
: ConnectedDevice(url, lister, unique_id, manager, database_id, first_time), : FilesystemMusicStorage(url.toLocalFile()),
FilesystemMusicStorage(url.toLocalFile()), ConnectedDevice(url, lister, unique_id, manager, database_id, first_time),
watcher_(new BackgroundThreadImplementation<LibraryWatcher, LibraryWatcher>(this)) watcher_(new BackgroundThreadImplementation<LibraryWatcher, LibraryWatcher>(this))
{ {
// Create the library watcher // Create the library watcher

View File

@ -24,7 +24,7 @@
class DeviceManager; class DeviceManager;
class LibraryWatcher; class LibraryWatcher;
class FilesystemDevice : public ConnectedDevice, public FilesystemMusicStorage { class FilesystemDevice : public ConnectedDevice, public virtual FilesystemMusicStorage {
Q_OBJECT Q_OBJECT
public: public:
@ -36,8 +36,6 @@ public:
static QStringList url_schemes() { return QStringList() << "file"; } static QStringList url_schemes() { return QStringList() << "file"; }
MusicStorage* storage() { return this; }
private: private:
BackgroundThread<LibraryWatcher>* watcher_; BackgroundThread<LibraryWatcher>* watcher_;
}; };

View File

@ -27,7 +27,7 @@
class GPodLoader; class GPodLoader;
class GPodDevice : public ConnectedDevice, public MusicStorage { class GPodDevice : public ConnectedDevice, public virtual MusicStorage {
Q_OBJECT Q_OBJECT
public: public:
@ -39,8 +39,6 @@ public:
static QStringList url_schemes() { return QStringList() << "ipod"; } static QStringList url_schemes() { return QStringList() << "ipod"; }
MusicStorage* storage() { return this; }
void StartCopy(); void StartCopy();
bool CopyToStorage(const QString &source, const QString &destination, bool CopyToStorage(const QString &source, const QString &destination,
const Song &metadata, bool overwrite, bool remove_original); const Song &metadata, bool overwrite, bool remove_original);

View File

@ -276,7 +276,7 @@ void LibraryView::Delete() {
} }
void LibraryView::CopyToDevice() { void LibraryView::CopyToDevice() {
organise_dialog_->SetDestinationModel(devices_->connected_devices_model()); organise_dialog_->SetDestinationModel(devices_->connected_devices_model(), true);
organise_dialog_->SetCopy(true); organise_dialog_->SetCopy(true);
organise_dialog_->SetFilenames(GetSelectedFilenames()); organise_dialog_->SetFilenames(GetSelectedFilenames());
organise_dialog_->show(); organise_dialog_->show();

View File

@ -1299,6 +1299,9 @@ msgstr ""
msgid "Safely remove device" msgid "Safely remove device"
msgstr "" msgstr ""
msgid "Safely remove the device after copying"
msgstr ""
msgid "Sample rate" msgid "Sample rate"
msgstr "" msgstr ""

View File

@ -1299,6 +1299,9 @@ msgstr ""
msgid "Safely remove device" msgid "Safely remove device"
msgstr "" msgstr ""
msgid "Safely remove the device after copying"
msgstr ""
msgid "Sample rate" msgid "Sample rate"
msgstr "" msgstr ""

View File

@ -1303,6 +1303,9 @@ msgstr "Rock"
msgid "Safely remove device" msgid "Safely remove device"
msgstr "" msgstr ""
msgid "Safely remove the device after copying"
msgstr ""
msgid "Sample rate" msgid "Sample rate"
msgstr "Vzorkovací frekvence" msgstr "Vzorkovací frekvence"

View File

@ -1304,6 +1304,9 @@ msgstr "Rock"
msgid "Safely remove device" msgid "Safely remove device"
msgstr "" msgstr ""
msgid "Safely remove the device after copying"
msgstr ""
msgid "Sample rate" msgid "Sample rate"
msgstr "Samplingsrate" msgstr "Samplingsrate"

View File

@ -1318,6 +1318,9 @@ msgstr "Rock"
msgid "Safely remove device" msgid "Safely remove device"
msgstr "" msgstr ""
msgid "Safely remove the device after copying"
msgstr ""
msgid "Sample rate" msgid "Sample rate"
msgstr "Abtastrate" msgstr "Abtastrate"

View File

@ -1320,6 +1320,9 @@ msgstr "Rock"
msgid "Safely remove device" msgid "Safely remove device"
msgstr "" msgstr ""
msgid "Safely remove the device after copying"
msgstr ""
msgid "Sample rate" msgid "Sample rate"
msgstr "Ρυθμός δειγματοληψίας" msgstr "Ρυθμός δειγματοληψίας"

View File

@ -1304,6 +1304,9 @@ msgstr "Rock"
msgid "Safely remove device" msgid "Safely remove device"
msgstr "" msgstr ""
msgid "Safely remove the device after copying"
msgstr ""
msgid "Sample rate" msgid "Sample rate"
msgstr "Sample rate" msgstr "Sample rate"

View File

@ -1301,6 +1301,9 @@ msgstr "Rock"
msgid "Safely remove device" msgid "Safely remove device"
msgstr "" msgstr ""
msgid "Safely remove the device after copying"
msgstr ""
msgid "Sample rate" msgid "Sample rate"
msgstr "Sample rate" msgstr "Sample rate"

View File

@ -1324,6 +1324,9 @@ msgstr "Rock"
msgid "Safely remove device" msgid "Safely remove device"
msgstr "" msgstr ""
msgid "Safely remove the device after copying"
msgstr ""
msgid "Sample rate" msgid "Sample rate"
msgstr "Tasa de muestreo" msgstr "Tasa de muestreo"

View File

@ -1301,6 +1301,9 @@ msgstr "Rock"
msgid "Safely remove device" msgid "Safely remove device"
msgstr "" msgstr ""
msgid "Safely remove the device after copying"
msgstr ""
msgid "Sample rate" msgid "Sample rate"
msgstr "" msgstr ""

View File

@ -1311,6 +1311,9 @@ msgstr "Rock"
msgid "Safely remove device" msgid "Safely remove device"
msgstr "" msgstr ""
msgid "Safely remove the device after copying"
msgstr ""
msgid "Sample rate" msgid "Sample rate"
msgstr "Échantillonnage" msgstr "Échantillonnage"

View File

@ -1301,6 +1301,9 @@ msgstr "Rock"
msgid "Safely remove device" msgid "Safely remove device"
msgstr "" msgstr ""
msgid "Safely remove the device after copying"
msgstr ""
msgid "Sample rate" msgid "Sample rate"
msgstr "Taxa de mostra" msgstr "Taxa de mostra"

View File

@ -1323,6 +1323,9 @@ msgstr "Rock"
msgid "Safely remove device" msgid "Safely remove device"
msgstr "" msgstr ""
msgid "Safely remove the device after copying"
msgstr ""
msgid "Sample rate" msgid "Sample rate"
msgstr "Campionamento" msgstr "Campionamento"

View File

@ -1301,6 +1301,9 @@ msgstr "Рок"
msgid "Safely remove device" msgid "Safely remove device"
msgstr "" msgstr ""
msgid "Safely remove the device after copying"
msgstr ""
msgid "Sample rate" msgid "Sample rate"
msgstr "" msgstr ""

View File

@ -1299,6 +1299,9 @@ msgstr ""
msgid "Safely remove device" msgid "Safely remove device"
msgstr "" msgstr ""
msgid "Safely remove the device after copying"
msgstr ""
msgid "Sample rate" msgid "Sample rate"
msgstr "" msgstr ""

View File

@ -1302,6 +1302,9 @@ msgstr "Rock"
msgid "Safely remove device" msgid "Safely remove device"
msgstr "" msgstr ""
msgid "Safely remove the device after copying"
msgstr ""
msgid "Sample rate" msgid "Sample rate"
msgstr "Samplingsrate" msgstr "Samplingsrate"

View File

@ -1318,6 +1318,9 @@ msgstr "Rock"
msgid "Safely remove device" msgid "Safely remove device"
msgstr "" msgstr ""
msgid "Safely remove the device after copying"
msgstr ""
msgid "Sample rate" msgid "Sample rate"
msgstr "Samplerate" msgstr "Samplerate"

View File

@ -1299,6 +1299,9 @@ msgstr "Rock"
msgid "Safely remove device" msgid "Safely remove device"
msgstr "" msgstr ""
msgid "Safely remove the device after copying"
msgstr ""
msgid "Sample rate" msgid "Sample rate"
msgstr "" msgstr ""

View File

@ -1310,6 +1310,9 @@ msgstr ""
msgid "Safely remove device" msgid "Safely remove device"
msgstr "" msgstr ""
msgid "Safely remove the device after copying"
msgstr ""
msgid "Sample rate" msgid "Sample rate"
msgstr "" msgstr ""

View File

@ -1315,6 +1315,9 @@ msgstr "Rock"
msgid "Safely remove device" msgid "Safely remove device"
msgstr "" msgstr ""
msgid "Safely remove the device after copying"
msgstr ""
msgid "Sample rate" msgid "Sample rate"
msgstr "Taxa de amostragem" msgstr "Taxa de amostragem"

View File

@ -1311,6 +1311,9 @@ msgstr "Rock"
msgid "Safely remove device" msgid "Safely remove device"
msgstr "" msgstr ""
msgid "Safely remove the device after copying"
msgstr ""
msgid "Sample rate" msgid "Sample rate"
msgstr "Taxa de amostragem" msgstr "Taxa de amostragem"

View File

@ -1300,6 +1300,9 @@ msgstr "Rock"
msgid "Safely remove device" msgid "Safely remove device"
msgstr "" msgstr ""
msgid "Safely remove the device after copying"
msgstr ""
msgid "Sample rate" msgid "Sample rate"
msgstr "Rată de eșantionare" msgstr "Rată de eșantionare"

View File

@ -1313,6 +1313,9 @@ msgstr "Rock"
msgid "Safely remove device" msgid "Safely remove device"
msgstr "" msgstr ""
msgid "Safely remove the device after copying"
msgstr ""
msgid "Sample rate" msgid "Sample rate"
msgstr "Частота" msgstr "Частота"

View File

@ -1314,6 +1314,9 @@ msgstr "Rock"
msgid "Safely remove device" msgid "Safely remove device"
msgstr "" msgstr ""
msgid "Safely remove the device after copying"
msgstr ""
msgid "Sample rate" msgid "Sample rate"
msgstr "Rýchlosť vzorkovania" msgstr "Rýchlosť vzorkovania"

View File

@ -1304,6 +1304,9 @@ msgstr "Рок"
msgid "Safely remove device" msgid "Safely remove device"
msgstr "" msgstr ""
msgid "Safely remove the device after copying"
msgstr ""
msgid "Sample rate" msgid "Sample rate"
msgstr "узорковање" msgstr "узорковање"

View File

@ -1304,6 +1304,9 @@ msgstr "Rock"
msgid "Safely remove device" msgid "Safely remove device"
msgstr "" msgstr ""
msgid "Safely remove the device after copying"
msgstr ""
msgid "Sample rate" msgid "Sample rate"
msgstr "Samplingsfrekvens" msgstr "Samplingsfrekvens"

View File

@ -1305,6 +1305,9 @@ msgstr "Rock"
msgid "Safely remove device" msgid "Safely remove device"
msgstr "" msgstr ""
msgid "Safely remove the device after copying"
msgstr ""
msgid "Sample rate" msgid "Sample rate"
msgstr "Örneklem oranı" msgstr "Örneklem oranı"

View File

@ -1289,6 +1289,9 @@ msgstr ""
msgid "Safely remove device" msgid "Safely remove device"
msgstr "" msgstr ""
msgid "Safely remove the device after copying"
msgstr ""
msgid "Sample rate" msgid "Sample rate"
msgstr "" msgstr ""

View File

@ -1314,6 +1314,9 @@ msgstr "Рок"
msgid "Safely remove device" msgid "Safely remove device"
msgstr "" msgstr ""
msgid "Safely remove the device after copying"
msgstr ""
msgid "Sample rate" msgid "Sample rate"
msgstr "Частота вибірки" msgstr "Частота вибірки"

View File

@ -1299,6 +1299,9 @@ msgstr ""
msgid "Safely remove device" msgid "Safely remove device"
msgstr "" msgstr ""
msgid "Safely remove the device after copying"
msgstr ""
msgid "Sample rate" msgid "Sample rate"
msgstr "采样率" msgstr "采样率"

View File

@ -1304,6 +1304,9 @@ msgstr "搖滾"
msgid "Safely remove device" msgid "Safely remove device"
msgstr "" msgstr ""
msgid "Safely remove the device after copying"
msgstr ""
msgid "Sample rate" msgid "Sample rate"
msgstr "取樣頻率" msgstr "取樣頻率"

View File

@ -91,8 +91,10 @@ OrganiseDialog::~OrganiseDialog() {
delete ui_; delete ui_;
} }
void OrganiseDialog::SetDestinationModel(QAbstractItemModel *model) { void OrganiseDialog::SetDestinationModel(QAbstractItemModel *model, bool devices) {
ui_->destination->setModel(model); ui_->destination->setModel(model);
ui_->eject_after->setVisible(devices);
} }
void OrganiseDialog::SetUrls(const QList<QUrl> &urls) { void OrganiseDialog::SetUrls(const QList<QUrl> &urls) {
@ -196,6 +198,7 @@ void OrganiseDialog::Reset() {
ui_->replace_spaces->setChecked(false); ui_->replace_spaces->setChecked(false);
ui_->replace_the->setChecked(false); ui_->replace_the->setChecked(false);
ui_->overwrite->setChecked(true); ui_->overwrite->setChecked(true);
ui_->eject_after->setChecked(false);
} }
void OrganiseDialog::showEvent(QShowEvent *) { void OrganiseDialog::showEvent(QShowEvent *) {
@ -206,6 +209,7 @@ void OrganiseDialog::showEvent(QShowEvent *) {
ui_->replace_spaces->setChecked(s.value("replace_spaces", false).toBool()); ui_->replace_spaces->setChecked(s.value("replace_spaces", false).toBool());
ui_->replace_the->setChecked(s.value("replace_the", false).toBool()); ui_->replace_the->setChecked(s.value("replace_the", false).toBool());
ui_->overwrite->setChecked(s.value("overwrite", true).toBool()); ui_->overwrite->setChecked(s.value("overwrite", true).toBool());
ui_->eject_after->setChecked(s.value("eject_after", false).toBool());
QString destination = s.value("destination").toString(); QString destination = s.value("destination").toString();
int index = ui_->destination->findText(destination); int index = ui_->destination->findText(destination);
@ -223,6 +227,7 @@ void OrganiseDialog::accept() {
s.setValue("replace_the", ui_->replace_the->isChecked()); s.setValue("replace_the", ui_->replace_the->isChecked());
s.setValue("overwrite", ui_->overwrite->isChecked()); s.setValue("overwrite", ui_->overwrite->isChecked());
s.setValue("destination", ui_->destination->currentText()); s.setValue("destination", ui_->destination->currentText());
s.setValue("eject_after", ui_->eject_after->isChecked());
const QModelIndex destination = ui_->destination->model()->index( const QModelIndex destination = ui_->destination->model()->index(
ui_->destination->currentIndex(), 0); ui_->destination->currentIndex(), 0);
@ -232,7 +237,8 @@ void OrganiseDialog::accept() {
// It deletes itself when it's finished. // It deletes itself when it's finished.
const bool copy = ui_->aftercopying->currentIndex() == 0; const bool copy = ui_->aftercopying->currentIndex() == 0;
Organise* organise = new Organise( Organise* organise = new Organise(
task_manager_, storage, format_, copy, ui_->overwrite->isChecked(), filenames_); task_manager_, storage, format_, copy, ui_->overwrite->isChecked(),
filenames_, ui_->eject_after->isChecked());
organise->Start(); organise->Start();
QDialog::accept(); QDialog::accept();

View File

@ -45,7 +45,7 @@ public:
QSize sizeHint() const; QSize sizeHint() const;
void SetDestinationModel(QAbstractItemModel* model); void SetDestinationModel(QAbstractItemModel* model, bool devices = false);
void SetUrls(const QList<QUrl>& urls); void SetUrls(const QList<QUrl>& urls);
void SetFilenames(const QStringList& filenames); void SetFilenames(const QStringList& filenames);

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>588</width> <width>588</width>
<height>475</height> <height>497</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -53,6 +53,13 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<widget class="QCheckBox" name="eject_after">
<property name="text">
<string>Safely remove the device after copying</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QGroupBox" name="naming_group"> <widget class="QGroupBox" name="naming_group">
<property name="title"> <property name="title">
@ -150,6 +157,19 @@
<header>widgets/linetextedit.h</header> <header>widgets/linetextedit.h</header>
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<tabstops>
<tabstop>destination</tabstop>
<tabstop>aftercopying</tabstop>
<tabstop>eject_after</tabstop>
<tabstop>naming</tabstop>
<tabstop>insert</tabstop>
<tabstop>replace_the</tabstop>
<tabstop>replace_spaces</tabstop>
<tabstop>replace_ascii</tabstop>
<tabstop>overwrite</tabstop>
<tabstop>preview</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources> <resources>
<include location="../../data/data.qrc"/> <include location="../../data/data.qrc"/>
</resources> </resources>
@ -161,8 +181,8 @@
<slot>accept()</slot> <slot>accept()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>248</x> <x>257</x>
<y>254</y> <y>487</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>157</x> <x>157</x>
@ -177,8 +197,8 @@
<slot>reject()</slot> <slot>reject()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>316</x> <x>325</x>
<y>260</y> <y>487</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>286</x> <x>286</x>