From 79848c36c0fcd0454a86b4265262a63be76a67a5 Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Thu, 11 Dec 2014 22:21:24 +0000 Subject: [PATCH] #5841: Fix initial watchdir scan in Qt client Run the initial scan after application has finished initializing and session has been created. Otherwise, adding torrents is a no-op. --- qt/watchdir.cc | 12 +++++++++++- qt/watchdir.h | 3 +++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/qt/watchdir.cc b/qt/watchdir.cc index a6f6884fe..cadcda937 100644 --- a/qt/watchdir.cc +++ b/qt/watchdir.cc @@ -92,7 +92,7 @@ WatchDir :: setPath (const QString& path, bool isEnabled) connect (myWatcher, SIGNAL(directoryChanged(const QString&)), this, SLOT(watcherActivated(const QString&))); //std::cerr << "watching " << qPrintable(path) << " for new .torrent files" << std::endl; - watcherActivated (path); // trigger the watchdir for .torrent files in there already + QTimer::singleShot (0, this, SLOT (rescanAllWatchedDirectories ())); // trigger the watchdir for .torrent files in there already } } @@ -140,3 +140,13 @@ WatchDir :: watcherActivated (const QString& path) // for comparison the next time around myWatchDirFiles = files; } + +void +WatchDir :: rescanAllWatchedDirectories () +{ + if (myWatcher == nullptr) + return; + + foreach (const QString& path, myWatcher->directories ()) + watcherActivated (path); +} diff --git a/qt/watchdir.h b/qt/watchdir.h index a123c7879..81dcc8afb 100644 --- a/qt/watchdir.h +++ b/qt/watchdir.h @@ -39,6 +39,9 @@ class WatchDir: public QObject void watcherActivated (const QString& path); void onTimeout (); + private slots: + void rescanAllWatchedDirectories (); + private: const TorrentModel& myModel; QSet myWatchDirFiles;