Add an option to disable directory watchers

This commit is contained in:
David Sansome 2010-07-10 17:03:28 +00:00
parent b12db6357e
commit d620779696
34 changed files with 225 additions and 10 deletions

View File

@ -105,3 +105,10 @@ void Library::ResumeWatcher() {
watcher_->Worker()->SetRescanPausedAsync(false);
}
void Library::ReloadSettings() {
if (!watcher_->Worker())
return;
watcher_->Worker()->ReloadSettingsAsync();
}

View File

@ -51,6 +51,8 @@ class Library : public QObject {
LibraryModel* model() const { return model_; }
public slots:
void ReloadSettings();
void PauseWatcher();
void ResumeWatcher();

View File

@ -91,6 +91,7 @@ void LibraryConfig::Save() {
s.beginGroup(LibraryWatcher::kSettingsGroup);
s.setValue("startup_scan", ui_->startup_scan->isChecked());
s.setValue("monitor", ui_->monitor->isChecked());
s.endGroup();
}
@ -107,5 +108,6 @@ void LibraryConfig::Load() {
s.beginGroup(LibraryWatcher::kSettingsGroup);
ui_->startup_scan->setChecked(s.value("startup_scan", true).toBool());
ui_->monitor->setChecked(s.value("monitor", true).toBool());
s.endGroup();
}

View File

@ -70,13 +70,26 @@
</layout>
</item>
<item>
<widget class="QCheckBox" name="startup_scan">
<property name="text">
<string>Update the library when Clementine starts</string>
</property>
<property name="checked">
<bool>true</bool>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Automatic updating</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QCheckBox" name="startup_scan">
<property name="text">
<string>Update the library when Clementine starts</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="monitor">
<property name="text">
<string>Monitor the library for changes</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>

View File

@ -40,6 +40,7 @@ LibraryWatcher::LibraryWatcher(QObject* parent)
task_manager_(NULL),
stop_requested_(false),
scan_on_startup_(true),
monitor_(true),
rescan_timer_(new QTimer(this)),
rescan_paused_(false),
total_watches_(0)
@ -98,9 +99,11 @@ LibraryWatcher::ScanTransaction::~ScanTransaction() {
watcher_->task_manager_->SetTaskFinished(task_id_);
// Watch the new subdirectories
foreach (const Subdirectory& subdir, new_subdirs) {
watcher_->AddWatch(watcher_->watched_dirs_[dir_].watcher, subdir.path);
if (watcher_->monitor_) {
// Watch the new subdirectories
foreach (const Subdirectory& subdir, new_subdirs) {
watcher_->AddWatch(watcher_->watched_dirs_[dir_].watcher, subdir.path);
}
}
}
@ -192,7 +195,8 @@ void LibraryWatcher::AddDirectory(const Directory& dir, const SubdirectoryList&
if (scan_on_startup_)
ScanSubdirectory(subdir.path, subdir, &transaction);
AddWatch(data.watcher, subdir.path);
if (monitor_)
AddWatch(data.watcher, subdir.path);
}
}
@ -460,10 +464,32 @@ QString LibraryWatcher::ImageForSong(const QString& path, QMap<QString, QStringL
return QString();
}
void LibraryWatcher::ReloadSettingsAsync() {
QMetaObject::invokeMethod(this, "ReloadSettings", Qt::QueuedConnection);
}
void LibraryWatcher::ReloadSettings() {
const bool was_monitoring_before = monitor_;
QSettings s;
s.beginGroup(kSettingsGroup);
scan_on_startup_ = s.value("startup_scan", true).toBool();
monitor_ = s.value("monitor", true).toBool();
if (!monitor_ && was_monitoring_before) {
// Remove all directories from all QFileSystemWatchers
foreach (const DirData& data, watched_dirs_.values()) {
data.watcher->removePaths(data.watcher->directories());
}
} else if (monitor_ && !was_monitoring_before) {
// Add all directories to all QFileSystemWatchers again
foreach (const DirData& data, watched_dirs_.values()) {
SubdirectoryList subdirs = backend_->SubdirsInDirectory(data.dir.id);
foreach (const Subdirectory& subdir, subdirs) {
AddWatch(data.watcher, subdir.path);
}
}
}
}
void LibraryWatcher::SetRescanPausedAsync(bool pause) {

View File

@ -44,6 +44,7 @@ class LibraryWatcher : public QObject {
void IncrementalScanAsync();
void SetRescanPausedAsync(bool pause);
void ReloadSettingsAsync();
void Stop() { stop_requested_ = true; }
@ -142,6 +143,7 @@ class LibraryWatcher : public QObject {
QString device_name_;
bool stop_requested_;
bool scan_on_startup_;
bool monitor_;
QMap<int, DirData> watched_dirs_;
QTimer* rescan_timer_;

View File

@ -237,6 +237,9 @@ msgstr ""
msgid "Authors"
msgstr ""
msgid "Automatic updating"
msgstr ""
msgid "Automatically open single categories in the library tree"
msgstr ""
@ -943,6 +946,9 @@ msgstr ""
msgid "Model"
msgstr ""
msgid "Monitor the library for changes"
msgstr ""
msgid "Mount points"
msgstr ""

View File

@ -238,6 +238,9 @@ msgstr "Ověření selhalo"
msgid "Authors"
msgstr "Autoři"
msgid "Automatic updating"
msgstr ""
msgid "Automatically open single categories in the library tree"
msgstr "Automaticky otevře jednostlivé kategorie ve stromu knihovny"
@ -947,6 +950,9 @@ msgstr ""
msgid "Model"
msgstr ""
msgid "Monitor the library for changes"
msgstr ""
msgid "Mount points"
msgstr ""

View File

@ -238,6 +238,9 @@ msgstr "Autentificering mislykkedes"
msgid "Authors"
msgstr "Ophavsmænd"
msgid "Automatic updating"
msgstr ""
msgid "Automatically open single categories in the library tree"
msgstr "Åbn automatisk enkelte kategorier i bibliotekstræet"
@ -948,6 +951,9 @@ msgstr ""
msgid "Model"
msgstr ""
msgid "Monitor the library for changes"
msgstr ""
msgid "Mount points"
msgstr ""

View File

@ -237,6 +237,9 @@ msgstr "Authentifizierung fehlgeschlagen"
msgid "Authors"
msgstr "Autoren"
msgid "Automatic updating"
msgstr ""
msgid "Automatically open single categories in the library tree"
msgstr "Kategorien in der Musiksammlung automatisch öffnen"
@ -950,6 +953,9 @@ msgstr "Art der Mitgliedschaft"
msgid "Model"
msgstr ""
msgid "Monitor the library for changes"
msgstr ""
msgid "Mount points"
msgstr ""

View File

@ -244,6 +244,9 @@ msgstr "Η πιστοποίηση απέτυχε"
msgid "Authors"
msgstr "Δημιουργοί"
msgid "Automatic updating"
msgstr ""
msgid "Automatically open single categories in the library tree"
msgstr "Άνοιξε αυτόμα τις μόνες κατηγορίες του δέντρου της βιβλιοθήκης"
@ -956,6 +959,9 @@ msgstr "Τύπος συνδρομής"
msgid "Model"
msgstr ""
msgid "Monitor the library for changes"
msgstr ""
msgid "Mount points"
msgstr ""

View File

@ -237,6 +237,9 @@ msgstr "Authentication failed"
msgid "Authors"
msgstr "Authors"
msgid "Automatic updating"
msgstr ""
msgid "Automatically open single categories in the library tree"
msgstr "Automatically open single categories in the library tree"
@ -947,6 +950,9 @@ msgstr ""
msgid "Model"
msgstr ""
msgid "Monitor the library for changes"
msgstr ""
msgid "Mount points"
msgstr ""

View File

@ -237,6 +237,9 @@ msgstr "Authentication failed"
msgid "Authors"
msgstr "Authors"
msgid "Automatic updating"
msgstr ""
msgid "Automatically open single categories in the library tree"
msgstr "Automatically open single categories in the library tree"
@ -945,6 +948,9 @@ msgstr ""
msgid "Model"
msgstr ""
msgid "Monitor the library for changes"
msgstr ""
msgid "Mount points"
msgstr ""

View File

@ -238,6 +238,9 @@ msgstr "Falló la autenticación"
msgid "Authors"
msgstr "Autores"
msgid "Automatic updating"
msgstr ""
msgid "Automatically open single categories in the library tree"
msgstr ""
"Expandir automáticamente las categorías únicas en el árbol de la colección"
@ -954,6 +957,9 @@ msgstr ""
msgid "Model"
msgstr ""
msgid "Monitor the library for changes"
msgstr ""
msgid "Mount points"
msgstr ""

View File

@ -237,6 +237,9 @@ msgstr ""
msgid "Authors"
msgstr ""
msgid "Automatic updating"
msgstr ""
msgid "Automatically open single categories in the library tree"
msgstr ""
@ -944,6 +947,9 @@ msgstr ""
msgid "Model"
msgstr ""
msgid "Monitor the library for changes"
msgstr ""
msgid "Mount points"
msgstr ""

View File

@ -238,6 +238,9 @@ msgstr "Échec de l'authentification"
msgid "Authors"
msgstr "Auteurs"
msgid "Automatic updating"
msgstr ""
msgid "Automatically open single categories in the library tree"
msgstr ""
@ -951,6 +954,9 @@ msgstr ""
msgid "Model"
msgstr ""
msgid "Monitor the library for changes"
msgstr ""
msgid "Mount points"
msgstr ""

View File

@ -237,6 +237,9 @@ msgstr "Autenticazón fallida"
msgid "Authors"
msgstr "Autores/as"
msgid "Automatic updating"
msgstr ""
msgid "Automatically open single categories in the library tree"
msgstr ""
@ -945,6 +948,9 @@ msgstr ""
msgid "Model"
msgstr ""
msgid "Monitor the library for changes"
msgstr ""
msgid "Mount points"
msgstr ""

View File

@ -238,6 +238,9 @@ msgstr "Autenticazione non riuscita"
msgid "Authors"
msgstr "Autori"
msgid "Automatic updating"
msgstr ""
msgid "Automatically open single categories in the library tree"
msgstr "Apri automaticamente categorie singole nell'albero della raccolta"
@ -952,6 +955,9 @@ msgstr "Tipo d'iscrizione"
msgid "Model"
msgstr ""
msgid "Monitor the library for changes"
msgstr ""
msgid "Mount points"
msgstr ""

View File

@ -237,6 +237,9 @@ msgstr ""
msgid "Authors"
msgstr "Авторлары"
msgid "Automatic updating"
msgstr ""
msgid "Automatically open single categories in the library tree"
msgstr ""
@ -945,6 +948,9 @@ msgstr ""
msgid "Model"
msgstr ""
msgid "Monitor the library for changes"
msgstr ""
msgid "Mount points"
msgstr ""

View File

@ -237,6 +237,9 @@ msgstr "Autentiseringen feilet"
msgid "Authors"
msgstr "Forfattere"
msgid "Automatic updating"
msgstr ""
msgid "Automatically open single categories in the library tree"
msgstr "Automatisk åpne enkeltkategorier i bibliotektreet"
@ -946,6 +949,9 @@ msgstr ""
msgid "Model"
msgstr ""
msgid "Monitor the library for changes"
msgstr ""
msgid "Mount points"
msgstr ""

View File

@ -237,6 +237,9 @@ msgstr "L'autentificacion a fracassat"
msgid "Authors"
msgstr "Autors"
msgid "Automatic updating"
msgstr ""
msgid "Automatically open single categories in the library tree"
msgstr ""
@ -943,6 +946,9 @@ msgstr ""
msgid "Model"
msgstr ""
msgid "Monitor the library for changes"
msgstr ""
msgid "Mount points"
msgstr ""

View File

@ -238,6 +238,9 @@ msgstr "Błąd uwierzytelniania"
msgid "Authors"
msgstr "Autorzy"
msgid "Automatic updating"
msgstr ""
msgid "Automatically open single categories in the library tree"
msgstr "Automatycznie otwieraj pojedyńcze kategorie w drzewie Biblioteki"
@ -945,6 +948,9 @@ msgstr ""
msgid "Model"
msgstr ""
msgid "Monitor the library for changes"
msgstr ""
msgid "Mount points"
msgstr ""

View File

@ -241,6 +241,9 @@ msgstr "Falha ao autenticar"
msgid "Authors"
msgstr "Autores"
msgid "Automatic updating"
msgstr ""
msgid "Automatically open single categories in the library tree"
msgstr ""
"Na biblioteca em árvore, abrir automaticamente as categorias individuais"
@ -953,6 +956,9 @@ msgstr "Tipo de adesão"
msgid "Model"
msgstr ""
msgid "Monitor the library for changes"
msgstr ""
msgid "Mount points"
msgstr ""

View File

@ -240,6 +240,9 @@ msgstr "Autenticação falhou"
msgid "Authors"
msgstr "Autores"
msgid "Automatic updating"
msgstr ""
msgid "Automatically open single categories in the library tree"
msgstr "Abrir categorias únicas na árvore da biblioteca automaticamente"
@ -953,6 +956,9 @@ msgstr "Tipo de membro"
msgid "Model"
msgstr ""
msgid "Monitor the library for changes"
msgstr ""
msgid "Mount points"
msgstr ""

View File

@ -237,6 +237,9 @@ msgstr "Autentificarea a eșuat"
msgid "Authors"
msgstr "Autori"
msgid "Automatic updating"
msgstr ""
msgid "Automatically open single categories in the library tree"
msgstr ""
@ -944,6 +947,9 @@ msgstr ""
msgid "Model"
msgstr ""
msgid "Monitor the library for changes"
msgstr ""
msgid "Mount points"
msgstr ""

View File

@ -236,6 +236,9 @@ msgstr "Ошибка аутентификации"
msgid "Authors"
msgstr "Авторы"
msgid "Automatic updating"
msgstr ""
msgid "Automatically open single categories in the library tree"
msgstr "Автоматически открывать одиночные категории в дереве коллекции"
@ -947,6 +950,9 @@ msgstr ""
msgid "Model"
msgstr ""
msgid "Monitor the library for changes"
msgstr ""
msgid "Mount points"
msgstr ""

View File

@ -242,6 +242,9 @@ msgstr "Autentifikácia zlyhala"
msgid "Authors"
msgstr "Autori"
msgid "Automatic updating"
msgstr ""
msgid "Automatically open single categories in the library tree"
msgstr "Automaticky otvoriť jednotlivé kategórie v strome zbierky"
@ -953,6 +956,9 @@ msgstr "Typ členstva"
msgid "Model"
msgstr ""
msgid "Monitor the library for changes"
msgstr ""
msgid "Mount points"
msgstr ""

View File

@ -237,6 +237,9 @@ msgstr "Behörighetskontroll misslyckades"
msgid "Authors"
msgstr "Upphovsmän"
msgid "Automatic updating"
msgstr ""
msgid "Automatically open single categories in the library tree"
msgstr "Öppna enkla kategorier i biblioteksträdet automatiskt"
@ -948,6 +951,9 @@ msgstr ""
msgid "Model"
msgstr ""
msgid "Monitor the library for changes"
msgstr ""
msgid "Mount points"
msgstr ""

View File

@ -237,6 +237,9 @@ msgstr "Kimlik doğrulama başarısız"
msgid "Authors"
msgstr "Yazarlar"
msgid "Automatic updating"
msgstr ""
msgid "Automatically open single categories in the library tree"
msgstr ""
@ -943,6 +946,9 @@ msgstr ""
msgid "Model"
msgstr ""
msgid "Monitor the library for changes"
msgstr ""
msgid "Mount points"
msgstr ""

View File

@ -228,6 +228,9 @@ msgstr ""
msgid "Authors"
msgstr ""
msgid "Automatic updating"
msgstr ""
msgid "Automatically open single categories in the library tree"
msgstr ""
@ -934,6 +937,9 @@ msgstr ""
msgid "Model"
msgstr ""
msgid "Monitor the library for changes"
msgstr ""
msgid "Mount points"
msgstr ""

View File

@ -241,6 +241,9 @@ msgstr "Помилка автентификації"
msgid "Authors"
msgstr "Автори"
msgid "Automatic updating"
msgstr ""
msgid "Automatically open single categories in the library tree"
msgstr "Автоматично відкривати одиночні категорії в дереві фонотеки"
@ -952,6 +955,9 @@ msgstr "Тип членства"
msgid "Model"
msgstr ""
msgid "Monitor the library for changes"
msgstr ""
msgid "Mount points"
msgstr ""

View File

@ -237,6 +237,9 @@ msgstr ""
msgid "Authors"
msgstr ""
msgid "Automatic updating"
msgstr ""
msgid "Automatically open single categories in the library tree"
msgstr ""
@ -943,6 +946,9 @@ msgstr ""
msgid "Model"
msgstr ""
msgid "Monitor the library for changes"
msgstr ""
msgid "Mount points"
msgstr ""

View File

@ -237,6 +237,9 @@ msgstr ""
msgid "Authors"
msgstr ""
msgid "Automatic updating"
msgstr ""
msgid "Automatically open single categories in the library tree"
msgstr ""
@ -943,6 +946,9 @@ msgstr ""
msgid "Model"
msgstr ""
msgid "Monitor the library for changes"
msgstr ""
msgid "Mount points"
msgstr ""

View File

@ -457,6 +457,7 @@ MainWindow::MainWindow(NetworkAccessManager* network, Engine::Type engine, QWidg
// Settings
connect(settings_dialog_.get(), SIGNAL(accepted()), SLOT(ReloadSettings()));
connect(settings_dialog_.get(), SIGNAL(accepted()), library_, SLOT(ReloadSettings()));
connect(settings_dialog_.get(), SIGNAL(accepted()), player_, SLOT(ReloadSettings()));
connect(settings_dialog_.get(), SIGNAL(accepted()), osd_, SLOT(ReloadSettings()));
connect(settings_dialog_.get(), SIGNAL(accepted()), ui_->library_view, SLOT(ReloadSettings()));