Skip to content

Commit 015780f

Browse files
authored
Merge pull request #14882 from glassez/fswatcher
Improve "Watched folders" feature
2 parents 365b1c6 + 2993fdb commit 015780f

40 files changed

Lines changed: 1681 additions & 1073 deletions

src/app/application.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@
7575
#include "base/profile.h"
7676
#include "base/rss/rss_autodownloader.h"
7777
#include "base/rss/rss_session.h"
78-
#include "base/scanfoldersmodel.h"
7978
#include "base/search/searchpluginmanager.h"
8079
#include "base/settingsstorage.h"
80+
#include "base/torrentfileswatcher.h"
8181
#include "base/utils/compare.h"
8282
#include "base/utils/fs.h"
8383
#include "base/utils/misc.h"
@@ -621,7 +621,7 @@ int Application::exec(const QStringList &params)
621621
connect(BitTorrent::Session::instance(), &BitTorrent::Session::allTorrentsFinished, this, &Application::allTorrentsFinished, Qt::QueuedConnection);
622622

623623
Net::GeoIPManager::initInstance();
624-
ScanFoldersModel::initInstance();
624+
TorrentFilesWatcher::initInstance();
625625

626626
#ifndef DISABLE_WEBUI
627627
m_webui = new WebUI;
@@ -638,7 +638,7 @@ int Application::exec(const QStringList &params)
638638
catch (const RuntimeError &err)
639639
{
640640
#ifdef DISABLE_GUI
641-
fprintf(stderr, "%s", err.what());
641+
fprintf(stderr, "%s", qPrintable(err.message()));
642642
#else
643643
QMessageBox msgBox;
644644
msgBox.setIcon(QMessageBox::Critical);
@@ -817,7 +817,7 @@ void Application::cleanup()
817817
delete RSS::AutoDownloader::instance();
818818
delete RSS::Session::instance();
819819

820-
ScanFoldersModel::freeInstance();
820+
TorrentFilesWatcher::freeInstance();
821821
BitTorrent::Session::freeInstance();
822822
Net::GeoIPManager::freeInstance();
823823
Net::DownloadManager::freeInstance();

src/app/cmdoptions.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -498,17 +498,6 @@ QBtCommandLineParameters parseCommandLine(const QStringList &args)
498498
return result;
499499
}
500500

501-
CommandLineParameterError::CommandLineParameterError(const QString &messageForUser)
502-
: std::runtime_error(messageForUser.toLocal8Bit().data())
503-
, m_messageForUser(messageForUser)
504-
{
505-
}
506-
507-
const QString &CommandLineParameterError::messageForUser() const
508-
{
509-
return m_messageForUser;
510-
}
511-
512501
QString wrapText(const QString &text, int initialIndentation = USAGE_TEXT_COLUMN, int wrapAtColumn = WRAP_AT_COLUMN)
513502
{
514503
QStringList words = text.split(' ');

src/app/cmdoptions.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@
3131
#pragma once
3232

3333
#include <optional>
34-
#include <stdexcept>
3534

3635
#include <QString>
3736
#include <QStringList>
3837

38+
#include "base/exceptions.h"
39+
3940
class QProcessEnvironment;
4041

4142
struct QBtCommandLineParameters
@@ -67,14 +68,10 @@ struct QBtCommandLineParameters
6768
QStringList paramList() const;
6869
};
6970

70-
class CommandLineParameterError : public std::runtime_error
71+
class CommandLineParameterError : public RuntimeError
7172
{
7273
public:
73-
explicit CommandLineParameterError(const QString &messageForUser);
74-
const QString &messageForUser() const;
75-
76-
private:
77-
const QString m_messageForUser;
74+
using RuntimeError::RuntimeError;
7875
};
7976

8077
QBtCommandLineParameters parseCommandLine(const QStringList &args);

src/app/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ int main(int argc, char *argv[])
311311
}
312312
catch (const CommandLineParameterError &er)
313313
{
314-
displayBadArgMessage(er.messageForUser());
314+
displayBadArgMessage(er.message());
315315
return EXIT_FAILURE;
316316
}
317317
}

src/base/CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ add_library(qbt_base STATIC
3737
bittorrent/trackerentry.h
3838
digest32.h
3939
exceptions.h
40-
filesystemwatcher.h
4140
global.h
4241
http/connection.h
4342
http/httperror.h
@@ -71,13 +70,13 @@ add_library(qbt_base STATIC
7170
rss/rss_item.h
7271
rss/rss_parser.h
7372
rss/rss_session.h
74-
scanfoldersmodel.h
7573
search/searchdownloadhandler.h
7674
search/searchhandler.h
7775
search/searchpluginmanager.h
7876
settingsstorage.h
7977
tagset.h
8078
torrentfileguard.h
79+
torrentfileswatcher.h
8180
torrentfilter.h
8281
types.h
8382
unicodestrings.h
@@ -122,7 +121,6 @@ add_library(qbt_base STATIC
122121
bittorrent/tracker.cpp
123122
bittorrent/trackerentry.cpp
124123
exceptions.cpp
125-
filesystemwatcher.cpp
126124
http/connection.cpp
127125
http/httperror.cpp
128126
http/requestparser.cpp
@@ -151,13 +149,13 @@ add_library(qbt_base STATIC
151149
rss/rss_item.cpp
152150
rss/rss_parser.cpp
153151
rss/rss_session.cpp
154-
scanfoldersmodel.cpp
155152
search/searchdownloadhandler.cpp
156153
search/searchhandler.cpp
157154
search/searchpluginmanager.cpp
158155
settingsstorage.cpp
159156
tagset.cpp
160157
torrentfileguard.cpp
158+
torrentfileswatcher.cpp
161159
torrentfilter.cpp
162160
utils/bytearray.cpp
163161
utils/compare.cpp

src/base/base.pri

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ HEADERS += \
3636
$$PWD/bittorrent/trackerentry.h \
3737
$$PWD/digest32.h \
3838
$$PWD/exceptions.h \
39-
$$PWD/filesystemwatcher.h \
4039
$$PWD/global.h \
4140
$$PWD/http/connection.h \
4241
$$PWD/http/httperror.h \
@@ -70,14 +69,14 @@ HEADERS += \
7069
$$PWD/rss/rss_item.h \
7170
$$PWD/rss/rss_parser.h \
7271
$$PWD/rss/rss_session.h \
73-
$$PWD/scanfoldersmodel.h \
7472
$$PWD/search/searchdownloadhandler.h \
7573
$$PWD/search/searchhandler.h \
7674
$$PWD/search/searchpluginmanager.h \
7775
$$PWD/settingsstorage.h \
7876
$$PWD/settingvalue.h \
7977
$$PWD/tagset.h \
8078
$$PWD/torrentfileguard.h \
79+
$$PWD/torrentfileswatcher.h \
8180
$$PWD/torrentfilter.h \
8281
$$PWD/types.h \
8382
$$PWD/unicodestrings.h \
@@ -122,7 +121,6 @@ SOURCES += \
122121
$$PWD/bittorrent/tracker.cpp \
123122
$$PWD/bittorrent/trackerentry.cpp \
124123
$$PWD/exceptions.cpp \
125-
$$PWD/filesystemwatcher.cpp \
126124
$$PWD/http/connection.cpp \
127125
$$PWD/http/httperror.cpp \
128126
$$PWD/http/requestparser.cpp \
@@ -151,13 +149,13 @@ SOURCES += \
151149
$$PWD/rss/rss_item.cpp \
152150
$$PWD/rss/rss_parser.cpp \
153151
$$PWD/rss/rss_session.cpp \
154-
$$PWD/scanfoldersmodel.cpp \
155152
$$PWD/search/searchdownloadhandler.cpp \
156153
$$PWD/search/searchhandler.cpp \
157154
$$PWD/search/searchpluginmanager.cpp \
158155
$$PWD/settingsstorage.cpp \
159156
$$PWD/tagset.cpp \
160157
$$PWD/torrentfileguard.cpp \
158+
$$PWD/torrentfileswatcher.cpp \
161159
$$PWD/torrentfilter.cpp \
162160
$$PWD/utils/bytearray.cpp \
163161
$$PWD/utils/compare.cpp \

src/base/bittorrent/addtorrentparams.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include <optional>
3232

33+
#include <QMetaType>
3334
#include <QString>
3435
#include <QVector>
3536

@@ -62,3 +63,5 @@ namespace BitTorrent
6263
qreal ratioLimit = Torrent::USE_GLOBAL_RATIO;
6364
};
6465
}
66+
67+
Q_DECLARE_METATYPE(BitTorrent::AddTorrentParams)

src/base/bittorrent/magneturi.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include <libtorrent/sha1_hash.hpp>
3535

3636
#include <QRegularExpression>
37-
#include <QUrl>
3837

3938
#include "infohash.h"
4039

@@ -59,6 +58,8 @@ namespace
5958

6059
using namespace BitTorrent;
6160

61+
const int magnetUriId = qRegisterMetaType<MagnetUri>();
62+
6263
MagnetUri::MagnetUri(const QString &source)
6364
: m_valid(false)
6465
, m_url(source)

src/base/bittorrent/magneturi.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,12 @@
3131
#include <libtorrent/add_torrent_params.hpp>
3232

3333
#include <QString>
34+
#include <QUrl>
3435
#include <QVector>
3536

3637
#include "infohash.h"
3738
#include "trackerentry.h"
3839

39-
class QUrl;
40-
4140
namespace BitTorrent
4241
{
4342
class MagnetUri
@@ -64,3 +63,5 @@ namespace BitTorrent
6463
lt::add_torrent_params m_addTorrentParams;
6564
};
6665
}
66+
67+
Q_DECLARE_METATYPE(BitTorrent::MagnetUri)

src/base/bittorrent/session.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,8 @@ namespace
318318
#endif
319319
}
320320

321+
const int addTorrentParamsId = qRegisterMetaType<AddTorrentParams>();
322+
321323
// Session
322324

323325
Session *Session::m_instance = nullptr;
@@ -2062,8 +2064,10 @@ LoadTorrentParams Session::initLoadTorrentParams(const AddTorrentParams &addTorr
20622064
const bool useAutoTMM = addTorrentParams.useAutoTMM.value_or(!isAutoTMMDisabledByDefault());
20632065
if (useAutoTMM)
20642066
loadTorrentParams.savePath = "";
2065-
else if (addTorrentParams.savePath.trimmed().isEmpty())
2067+
else if (addTorrentParams.savePath.isEmpty())
20662068
loadTorrentParams.savePath = defaultSavePath();
2069+
else if (QDir(addTorrentParams.savePath).isRelative())
2070+
loadTorrentParams.savePath = QDir(defaultSavePath()).absoluteFilePath(addTorrentParams.savePath);
20672071
else
20682072
loadTorrentParams.savePath = normalizePath(addTorrentParams.savePath);
20692073

0 commit comments

Comments
 (0)