Add a menu option to forget a device, and add some helpful information dialogs

This commit is contained in:
David Sansome 2010-07-04 12:56:49 +00:00
parent 4a8bff5f4e
commit a892489de7
32 changed files with 420 additions and 3 deletions

View File

@ -100,8 +100,10 @@ void DeviceDatabaseBackend::RemoveDevice(int id) {
if (db_->CheckErrors(q.lastError())) return;
// Remove the songs tables for the device
db.exec(QString("DROP TABLE device_%1").arg(id));
db.exec(QString("DROP TABLE device_%1_songs").arg(id));
db.exec(QString("DROP TABLE device_%1_fts").arg(id));
db.exec(QString("DROP TABLE device_%1_directories").arg(id));
db.exec(QString("DROP TABLE device_%1_subdirectories").arg(id));
t.Commit();
}

View File

@ -260,6 +260,10 @@ boost::shared_ptr<ConnectedDevice> DeviceManager::GetConnectedDevice(int row) co
return devices_[row].device_;
}
int DeviceManager::GetDatabaseId(int row) const {
return devices_[row].database_id_;
}
void DeviceManager::Disconnect(int row) {
DeviceInfo& info = devices_[row];
if (!info.device_) // Already disconnected
@ -268,3 +272,24 @@ void DeviceManager::Disconnect(int row) {
info.device_.reset();
emit DeviceDisconnected(row);
}
void DeviceManager::Forget(int row) {
DeviceInfo& info = devices_[row];
if (info.database_id_ == -1)
return;
if (info.device_)
Disconnect(row);
backend_->RemoveDevice(info.database_id_);
info.database_id_ = -1;
if (!info.lister_) {
// It's not attached any more so remove it from the list
beginRemoveRows(QModelIndex(), row, row);
devices_.removeAt(row);
endRemoveRows();
} else {
dataChanged(index(row, 0), index(row, 0));
}
}

View File

@ -57,10 +57,12 @@ public:
BackgroundThread<Database>* database() const { return database_; }
TaskManager* task_manager() const { return task_manager_; }
boost::shared_ptr<ConnectedDevice> Connect(int row);
boost::shared_ptr<ConnectedDevice> GetConnectedDevice(int row) const;
int GetDatabaseId(int row) const;
boost::shared_ptr<ConnectedDevice> Connect(int row);
void Disconnect(int row);
void Forget(int row);
// QAbstractListModel
int rowCount(const QModelIndex &parent) const;

View File

@ -23,7 +23,9 @@
#include <QContextMenuEvent>
#include <QMenu>
#include <QMessageBox>
#include <QPainter>
#include <QPushButton>
#include <QSortFilterProxyModel>
#include <boost/shared_ptr.hpp>
@ -108,6 +110,8 @@ DeviceView::DeviceView(QWidget* parent)
IconLoader::Load("list-add"), tr("Connect device"), this, SLOT(Connect()));
disconnect_action_ = menu_->addAction(
IconLoader::Load("list-remove"), tr("Disconnect device"), this, SLOT(Disconnect()));
forget_action_ = menu_->addAction(
IconLoader::Load("list-remove"), tr("Forget device"), this, SLOT(Forget()));
setItemDelegate(new DeviceItemDelegate(this));
SetExpandOnReset(false);
@ -139,11 +143,13 @@ void DeviceView::contextMenuEvent(QContextMenuEvent* e) {
QModelIndex device_index = MapToDevice(menu_index_);
bool is_device = device_index.isValid();
bool is_connected = is_device && manager_->GetConnectedDevice(device_index.row());
bool is_remembered = is_device && manager_->GetDatabaseId(device_index.row()) != -1;
connect_action_->setEnabled(is_device);
disconnect_action_->setEnabled(is_device);
connect_action_->setVisible(!is_connected);
disconnect_action_->setVisible(is_connected);
forget_action_->setEnabled(is_remembered);
menu_->popup(e->globalPos());
}
@ -159,6 +165,20 @@ QModelIndex DeviceView::MapToDevice(const QModelIndex& merged_model_index) const
void DeviceView::Connect() {
QModelIndex device_idx = MapToDevice(menu_index_);
QModelIndex sort_idx = sort_model_->mapFromSource(device_idx);
bool first_time = manager_->GetDatabaseId(device_idx.row()) == -1;
if (first_time) {
boost::scoped_ptr<QMessageBox> dialog(new QMessageBox(
QMessageBox::Information, tr("Connect device"),
tr("This is the first time you have connected this device. Clementine will now scan the device to find music files - this may take some time."),
QMessageBox::Cancel, this));
QPushButton* connect =
dialog->addButton(tr("Connect device"), QMessageBox::AcceptRole);
dialog->exec();
if (dialog->clickedButton() != connect)
return;
}
boost::shared_ptr<ConnectedDevice> device = manager_->Connect(device_idx.row());
if (!device)
@ -176,10 +196,25 @@ void DeviceView::Connect() {
void DeviceView::Disconnect() {
QModelIndex device_idx = MapToDevice(menu_index_);
manager_->Disconnect(device_idx.row());
}
void DeviceView::DeviceDisconnected(int row) {
merged_model_->RemoveSubModel(sort_model_->mapFromSource(manager_->index(row)));
}
void DeviceView::Forget() {
boost::scoped_ptr<QMessageBox> dialog(new QMessageBox(
QMessageBox::Question, tr("Forget device"),
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."),
QMessageBox::Cancel, this));
QPushButton* forget =
dialog->addButton(tr("Forget device"), QMessageBox::DestructiveRole);
dialog->exec();
if (dialog->clickedButton() != forget)
return;
QModelIndex device_idx = MapToDevice(menu_index_);
manager_->Forget(device_idx.row());
}

View File

@ -51,6 +51,7 @@ protected:
private slots:
void Connect();
void Disconnect();
void Forget();
void DeviceDisconnected(int row);
@ -65,6 +66,7 @@ private:
QMenu* menu_;
QAction* connect_action_;
QAction* disconnect_action_;
QAction* forget_action_;
QModelIndex menu_index_;
};

View File

@ -643,6 +643,14 @@ msgstr ""
msgid "First level"
msgstr "المستوى الأول"
msgid "Forget device"
msgstr ""
msgid ""
"Forgetting a device will remove it from this list and Clementine will have "
"to rescan all the songs again next time you connect it."
msgstr ""
msgid "Form"
msgstr "النموذج"
@ -1430,6 +1438,11 @@ msgstr "المستوى الثالث"
msgid "This album is not available in the requested format"
msgstr ""
msgid ""
"This is the first time you have connected this device. Clementine will now "
"scan the device to find music files - this may take some time."
msgstr ""
msgid "This stream is for paid subscribers only"
msgstr ""

View File

@ -646,6 +646,14 @@ msgstr ""
msgid "First level"
msgstr "První úroveň"
msgid "Forget device"
msgstr ""
msgid ""
"Forgetting a device will remove it from this list and Clementine will have "
"to rescan all the songs again next time you connect it."
msgstr ""
msgid "Form"
msgstr "Formulář"
@ -1434,6 +1442,11 @@ msgstr "Třetí úroveň"
msgid "This album is not available in the requested format"
msgstr ""
msgid ""
"This is the first time you have connected this device. Clementine will now "
"scan the device to find music files - this may take some time."
msgstr ""
msgid "This stream is for paid subscribers only"
msgstr "Tento proud je pouze pro předplatitele"

View File

@ -646,6 +646,14 @@ msgstr ""
msgid "First level"
msgstr "Første niveau"
msgid "Forget device"
msgstr ""
msgid ""
"Forgetting a device will remove it from this list and Clementine will have "
"to rescan all the songs again next time you connect it."
msgstr ""
msgid "Form"
msgstr "Formular"
@ -1437,6 +1445,11 @@ msgstr "Tredje niveau"
msgid "This album is not available in the requested format"
msgstr ""
msgid ""
"This is the first time you have connected this device. Clementine will now "
"scan the device to find music files - this may take some time."
msgstr ""
msgid "This stream is for paid subscribers only"
msgstr "Denne stream er kun for betalende abonnenter"

View File

@ -647,6 +647,14 @@ msgstr "Zu konvertierende Dateien"
msgid "First level"
msgstr "Erste Stufe"
msgid "Forget device"
msgstr ""
msgid ""
"Forgetting a device will remove it from this list and Clementine will have "
"to rescan all the songs again next time you connect it."
msgstr ""
msgid "Form"
msgstr "Formular"
@ -1438,6 +1446,11 @@ msgstr "Dritte Stufe"
msgid "This album is not available in the requested format"
msgstr "Das Album ist im gewünschten Format nicht verfügbar"
msgid ""
"This is the first time you have connected this device. Clementine will now "
"scan the device to find music files - this may take some time."
msgstr ""
msgid "This stream is for paid subscribers only"
msgstr "Nur für zahlende Kunden"

View File

@ -655,6 +655,14 @@ msgstr "Αρχεία για επανακωδικοποίηση"
msgid "First level"
msgstr "Πρώτο επίπεδο"
msgid "Forget device"
msgstr ""
msgid ""
"Forgetting a device will remove it from this list and Clementine will have "
"to rescan all the songs again next time you connect it."
msgstr ""
msgid "Form"
msgstr "Μορφή"
@ -1446,6 +1454,11 @@ msgstr "Τρίτο επίπεδο"
msgid "This album is not available in the requested format"
msgstr "Αυτό το άλμπουμ δεν είναι διαθέσιμο στην ζητούμενη μορφή"
msgid ""
"This is the first time you have connected this device. Clementine will now "
"scan the device to find music files - this may take some time."
msgstr ""
msgid "This stream is for paid subscribers only"
msgstr "Η ροή (stream) αυτή είναι μόνο για συνδρομητές"

View File

@ -646,6 +646,14 @@ msgstr "Files to transcode"
msgid "First level"
msgstr "First level"
msgid "Forget device"
msgstr ""
msgid ""
"Forgetting a device will remove it from this list and Clementine will have "
"to rescan all the songs again next time you connect it."
msgstr ""
msgid "Form"
msgstr "Form"
@ -1435,6 +1443,11 @@ msgstr "Third level"
msgid "This album is not available in the requested format"
msgstr ""
msgid ""
"This is the first time you have connected this device. Clementine will now "
"scan the device to find music files - this may take some time."
msgstr ""
msgid "This stream is for paid subscribers only"
msgstr "This stream is for paid subscribers only"

View File

@ -644,6 +644,14 @@ msgstr ""
msgid "First level"
msgstr "First level"
msgid "Forget device"
msgstr ""
msgid ""
"Forgetting a device will remove it from this list and Clementine will have "
"to rescan all the songs again next time you connect it."
msgstr ""
msgid "Form"
msgstr "Form"
@ -1432,6 +1440,11 @@ msgstr "Third level"
msgid "This album is not available in the requested format"
msgstr ""
msgid ""
"This is the first time you have connected this device. Clementine will now "
"scan the device to find music files - this may take some time."
msgstr ""
msgid "This stream is for paid subscribers only"
msgstr "This stream is for paid subscribers only"

View File

@ -650,6 +650,14 @@ msgstr "Archivos para convertir"
msgid "First level"
msgstr "Primer nivel"
msgid "Forget device"
msgstr ""
msgid ""
"Forgetting a device will remove it from this list and Clementine will have "
"to rescan all the songs again next time you connect it."
msgstr ""
msgid "Form"
msgstr "Formulario"
@ -1444,6 +1452,11 @@ msgstr "Tercer nivel"
msgid "This album is not available in the requested format"
msgstr ""
msgid ""
"This is the first time you have connected this device. Clementine will now "
"scan the device to find music files - this may take some time."
msgstr ""
msgid "This stream is for paid subscribers only"
msgstr "Este flujo es solo para Suscriptores de Paga"

View File

@ -643,6 +643,14 @@ msgstr ""
msgid "First level"
msgstr ""
msgid "Forget device"
msgstr ""
msgid ""
"Forgetting a device will remove it from this list and Clementine will have "
"to rescan all the songs again next time you connect it."
msgstr ""
msgid "Form"
msgstr ""
@ -1432,6 +1440,11 @@ msgstr ""
msgid "This album is not available in the requested format"
msgstr ""
msgid ""
"This is the first time you have connected this device. Clementine will now "
"scan the device to find music files - this may take some time."
msgstr ""
msgid "This stream is for paid subscribers only"
msgstr ""

View File

@ -646,6 +646,14 @@ msgstr ""
msgid "First level"
msgstr "Premier niveau"
msgid "Forget device"
msgstr ""
msgid ""
"Forgetting a device will remove it from this list and Clementine will have "
"to rescan all the songs again next time you connect it."
msgstr ""
msgid "Form"
msgstr "Form"
@ -1440,6 +1448,11 @@ msgstr "Troisième niveau"
msgid "This album is not available in the requested format"
msgstr ""
msgid ""
"This is the first time you have connected this device. Clementine will now "
"scan the device to find music files - this may take some time."
msgstr ""
msgid "This stream is for paid subscribers only"
msgstr "Ce flux n'est accessible qu'aux abonnés ayant payé"

View File

@ -643,6 +643,14 @@ msgstr ""
msgid "First level"
msgstr ""
msgid "Forget device"
msgstr ""
msgid ""
"Forgetting a device will remove it from this list and Clementine will have "
"to rescan all the songs again next time you connect it."
msgstr ""
msgid "Form"
msgstr ""
@ -1432,6 +1440,11 @@ msgstr ""
msgid "This album is not available in the requested format"
msgstr ""
msgid ""
"This is the first time you have connected this device. Clementine will now "
"scan the device to find music files - this may take some time."
msgstr ""
msgid "This stream is for paid subscribers only"
msgstr "Esta stream é só para asinantes"

View File

@ -648,6 +648,14 @@ msgstr "File da transcodificare"
msgid "First level"
msgstr "Primo livello"
msgid "Forget device"
msgstr ""
msgid ""
"Forgetting a device will remove it from this list and Clementine will have "
"to rescan all the songs again next time you connect it."
msgstr ""
msgid "Form"
msgstr "Modulo"
@ -1445,6 +1453,11 @@ msgstr "Terzo livello"
msgid "This album is not available in the requested format"
msgstr "L'album non è disponibile nel formato richiesto"
msgid ""
"This is the first time you have connected this device. Clementine will now "
"scan the device to find music files - this may take some time."
msgstr ""
msgid "This stream is for paid subscribers only"
msgstr "Questo flusso è riservato ai soli abbonati"

View File

@ -643,6 +643,14 @@ msgstr ""
msgid "First level"
msgstr ""
msgid "Forget device"
msgstr ""
msgid ""
"Forgetting a device will remove it from this list and Clementine will have "
"to rescan all the songs again next time you connect it."
msgstr ""
msgid "Form"
msgstr ""
@ -1432,6 +1440,11 @@ msgstr ""
msgid "This album is not available in the requested format"
msgstr ""
msgid ""
"This is the first time you have connected this device. Clementine will now "
"scan the device to find music files - this may take some time."
msgstr ""
msgid "This stream is for paid subscribers only"
msgstr ""

View File

@ -644,6 +644,14 @@ msgstr ""
msgid "First level"
msgstr "Første nivå"
msgid "Forget device"
msgstr ""
msgid ""
"Forgetting a device will remove it from this list and Clementine will have "
"to rescan all the songs again next time you connect it."
msgstr ""
msgid "Form"
msgstr "Skjema"
@ -1434,6 +1442,11 @@ msgstr "Tredje nivå"
msgid "This album is not available in the requested format"
msgstr ""
msgid ""
"This is the first time you have connected this device. Clementine will now "
"scan the device to find music files - this may take some time."
msgstr ""
msgid "This stream is for paid subscribers only"
msgstr "Denne tjenesten er kun for betalende kunder"

View File

@ -643,6 +643,14 @@ msgstr ""
msgid "First level"
msgstr "Primièr nivèl"
msgid "Forget device"
msgstr ""
msgid ""
"Forgetting a device will remove it from this list and Clementine will have "
"to rescan all the songs again next time you connect it."
msgstr ""
msgid "Form"
msgstr "Formulari"
@ -1430,6 +1438,11 @@ msgstr ""
msgid "This album is not available in the requested format"
msgstr ""
msgid ""
"This is the first time you have connected this device. Clementine will now "
"scan the device to find music files - this may take some time."
msgstr ""
msgid "This stream is for paid subscribers only"
msgstr ""

View File

@ -644,6 +644,14 @@ msgstr ""
msgid "First level"
msgstr "Pierwszy poziom"
msgid "Forget device"
msgstr ""
msgid ""
"Forgetting a device will remove it from this list and Clementine will have "
"to rescan all the songs again next time you connect it."
msgstr ""
msgid "Form"
msgstr "Forma"
@ -1432,6 +1440,11 @@ msgstr "Trzeci poziom"
msgid "This album is not available in the requested format"
msgstr ""
msgid ""
"This is the first time you have connected this device. Clementine will now "
"scan the device to find music files - this may take some time."
msgstr ""
msgid "This stream is for paid subscribers only"
msgstr "Strumień wyłacznie dla płatnych subskrybentów"

View File

@ -651,6 +651,14 @@ msgstr "Ficheiros a converter"
msgid "First level"
msgstr "Primeiro Nível"
msgid "Forget device"
msgstr ""
msgid ""
"Forgetting a device will remove it from this list and Clementine will have "
"to rescan all the songs again next time you connect it."
msgstr ""
msgid "Form"
msgstr "Formulário"
@ -1442,6 +1450,11 @@ msgstr "Terceiro nível"
msgid "This album is not available in the requested format"
msgstr "Este álbum não está disponível no formato solicitado"
msgid ""
"This is the first time you have connected this device. Clementine will now "
"scan the device to find music files - this may take some time."
msgstr ""
msgid "This stream is for paid subscribers only"
msgstr "Esta emissão é apenas para assinantes"

View File

@ -650,6 +650,14 @@ msgstr "Arquivos a transcodificar"
msgid "First level"
msgstr "Primeiro nível"
msgid "Forget device"
msgstr ""
msgid ""
"Forgetting a device will remove it from this list and Clementine will have "
"to rescan all the songs again next time you connect it."
msgstr ""
msgid "Form"
msgstr "Formulário"
@ -1443,6 +1451,11 @@ msgstr "Terceiro nível"
msgid "This album is not available in the requested format"
msgstr "Este álbum não encontra-se disponível no formato requerido"
msgid ""
"This is the first time you have connected this device. Clementine will now "
"scan the device to find music files - this may take some time."
msgstr ""
msgid "This stream is for paid subscribers only"
msgstr "Este canal é apenas para assinantes"

View File

@ -643,6 +643,14 @@ msgstr ""
msgid "First level"
msgstr "Primul nivel"
msgid "Forget device"
msgstr ""
msgid ""
"Forgetting a device will remove it from this list and Clementine will have "
"to rescan all the songs again next time you connect it."
msgstr ""
msgid "Form"
msgstr ""
@ -1431,6 +1439,11 @@ msgstr "Al treilea nivel"
msgid "This album is not available in the requested format"
msgstr ""
msgid ""
"This is the first time you have connected this device. Clementine will now "
"scan the device to find music files - this may take some time."
msgstr ""
msgid "This stream is for paid subscribers only"
msgstr ""

View File

@ -644,6 +644,14 @@ msgstr "Файлы для перекодирования"
msgid "First level"
msgstr "Первый уровень"
msgid "Forget device"
msgstr ""
msgid ""
"Forgetting a device will remove it from this list and Clementine will have "
"to rescan all the songs again next time you connect it."
msgstr ""
msgid "Form"
msgstr "Форма"
@ -1437,6 +1445,11 @@ msgstr "Третий уровень"
msgid "This album is not available in the requested format"
msgstr ""
msgid ""
"This is the first time you have connected this device. Clementine will now "
"scan the device to find music files - this may take some time."
msgstr ""
msgid "This stream is for paid subscribers only"
msgstr "Этот поток только для платных подписчиков"

View File

@ -652,6 +652,14 @@ msgstr "Súbory na transkódovanie"
msgid "First level"
msgstr "Prvá úroveň"
msgid "Forget device"
msgstr ""
msgid ""
"Forgetting a device will remove it from this list and Clementine will have "
"to rescan all the songs again next time you connect it."
msgstr ""
msgid "Form"
msgstr "Forma"
@ -1441,6 +1449,11 @@ msgstr "Tretia úroveň"
msgid "This album is not available in the requested format"
msgstr "Tento album nieje dostupný v požadovanom formáte"
msgid ""
"This is the first time you have connected this device. Clementine will now "
"scan the device to find music files - this may take some time."
msgstr ""
msgid "This stream is for paid subscribers only"
msgstr "Tento stream je len pre platiacich odoberateľov"

View File

@ -647,6 +647,14 @@ msgstr "Filer som skall omkodas"
msgid "First level"
msgstr "Första nivån"
msgid "Forget device"
msgstr ""
msgid ""
"Forgetting a device will remove it from this list and Clementine will have "
"to rescan all the songs again next time you connect it."
msgstr ""
msgid "Form"
msgstr "Formulär"
@ -1437,6 +1445,11 @@ msgstr "Tredje nivån"
msgid "This album is not available in the requested format"
msgstr ""
msgid ""
"This is the first time you have connected this device. Clementine will now "
"scan the device to find music files - this may take some time."
msgstr ""
msgid "This stream is for paid subscribers only"
msgstr "Den här strömmen är endast för betalande abonnenter"

View File

@ -643,6 +643,14 @@ msgstr ""
msgid "First level"
msgstr ""
msgid "Forget device"
msgstr ""
msgid ""
"Forgetting a device will remove it from this list and Clementine will have "
"to rescan all the songs again next time you connect it."
msgstr ""
msgid "Form"
msgstr "Biçim"
@ -1432,6 +1440,11 @@ msgstr ""
msgid "This album is not available in the requested format"
msgstr ""
msgid ""
"This is the first time you have connected this device. Clementine will now "
"scan the device to find music files - this may take some time."
msgstr ""
msgid "This stream is for paid subscribers only"
msgstr ""

View File

@ -634,6 +634,14 @@ msgstr ""
msgid "First level"
msgstr ""
msgid "Forget device"
msgstr ""
msgid ""
"Forgetting a device will remove it from this list and Clementine will have "
"to rescan all the songs again next time you connect it."
msgstr ""
msgid "Form"
msgstr ""
@ -1421,6 +1429,11 @@ msgstr ""
msgid "This album is not available in the requested format"
msgstr ""
msgid ""
"This is the first time you have connected this device. Clementine will now "
"scan the device to find music files - this may take some time."
msgstr ""
msgid "This stream is for paid subscribers only"
msgstr ""

View File

@ -650,6 +650,14 @@ msgstr "Файли для перекодування"
msgid "First level"
msgstr "Перший рівень"
msgid "Forget device"
msgstr ""
msgid ""
"Forgetting a device will remove it from this list and Clementine will have "
"to rescan all the songs again next time you connect it."
msgstr ""
msgid "Form"
msgstr "Форма"
@ -1441,6 +1449,11 @@ msgstr "Третій рівень"
msgid "This album is not available in the requested format"
msgstr "Цей альбом не доступний в запитуваному форматі"
msgid ""
"This is the first time you have connected this device. Clementine will now "
"scan the device to find music files - this may take some time."
msgstr ""
msgid "This stream is for paid subscribers only"
msgstr "Цей потік лише для платних передплатників"

View File

@ -643,6 +643,14 @@ msgstr ""
msgid "First level"
msgstr ""
msgid "Forget device"
msgstr ""
msgid ""
"Forgetting a device will remove it from this list and Clementine will have "
"to rescan all the songs again next time you connect it."
msgstr ""
msgid "Form"
msgstr ""
@ -1430,6 +1438,11 @@ msgstr ""
msgid "This album is not available in the requested format"
msgstr ""
msgid ""
"This is the first time you have connected this device. Clementine will now "
"scan the device to find music files - this may take some time."
msgstr ""
msgid "This stream is for paid subscribers only"
msgstr ""

View File

@ -643,6 +643,14 @@ msgstr ""
msgid "First level"
msgstr ""
msgid "Forget device"
msgstr ""
msgid ""
"Forgetting a device will remove it from this list and Clementine will have "
"to rescan all the songs again next time you connect it."
msgstr ""
msgid "Form"
msgstr ""
@ -1430,6 +1438,11 @@ msgstr ""
msgid "This album is not available in the requested format"
msgstr ""
msgid ""
"This is the first time you have connected this device. Clementine will now "
"scan the device to find music files - this may take some time."
msgstr ""
msgid "This stream is for paid subscribers only"
msgstr ""