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"
class FilesystemMusicStorage : public MusicStorage {
class FilesystemMusicStorage : public virtual MusicStorage {
public:
FilesystemMusicStorage(const QString& root);

View File

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

View File

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

View File

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

View File

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

View File

@ -17,6 +17,8 @@
#ifndef CONNECTEDDEVICE_H
#define CONNECTEDDEVICE_H
#include "core/musicstorage.h"
#include <QObject>
#include <QStringList>
#include <QUrl>
@ -26,9 +28,8 @@ class DeviceLister;
class DeviceManager;
class LibraryBackend;
class LibraryModel;
class MusicStorage;
class ConnectedDevice : public QObject {
class ConnectedDevice : public QObject, public virtual MusicStorage {
Q_OBJECT
public:
@ -42,7 +43,7 @@ public:
LibraryModel* model() const { return model_; }
QUrl url() const { return url_; }
virtual MusicStorage* storage() = 0;
void Eject();
signals:
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());
if (!info.device_)
return QVariant();
return QVariant::fromValue(info.device_->storage());
return QVariant::fromValue<MusicStorage*>(info.device_.get());
case Role_MountPath:
if (!info.device_)

View File

@ -27,8 +27,8 @@ FilesystemDevice::FilesystemDevice(
const QUrl& url, DeviceLister* lister,
const QString& unique_id, DeviceManager* manager,
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))
{
// Create the library watcher

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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