Skip to content

Commit

Permalink
Merge pull request #14882 from glassez/fswatcher
Browse files Browse the repository at this point in the history
Improve "Watched folders" feature
  • Loading branch information
glassez authored May 22, 2021
2 parents 365b1c6 + 2993fdb commit 015780f
Show file tree
Hide file tree
Showing 40 changed files with 1,681 additions and 1,073 deletions.
8 changes: 4 additions & 4 deletions src/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@
#include "base/profile.h"
#include "base/rss/rss_autodownloader.h"
#include "base/rss/rss_session.h"
#include "base/scanfoldersmodel.h"
#include "base/search/searchpluginmanager.h"
#include "base/settingsstorage.h"
#include "base/torrentfileswatcher.h"
#include "base/utils/compare.h"
#include "base/utils/fs.h"
#include "base/utils/misc.h"
Expand Down Expand Up @@ -621,7 +621,7 @@ int Application::exec(const QStringList &params)
connect(BitTorrent::Session::instance(), &BitTorrent::Session::allTorrentsFinished, this, &Application::allTorrentsFinished, Qt::QueuedConnection);

Net::GeoIPManager::initInstance();
ScanFoldersModel::initInstance();
TorrentFilesWatcher::initInstance();

#ifndef DISABLE_WEBUI
m_webui = new WebUI;
Expand All @@ -638,7 +638,7 @@ int Application::exec(const QStringList &params)
catch (const RuntimeError &err)
{
#ifdef DISABLE_GUI
fprintf(stderr, "%s", err.what());
fprintf(stderr, "%s", qPrintable(err.message()));
#else
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Critical);
Expand Down Expand Up @@ -817,7 +817,7 @@ void Application::cleanup()
delete RSS::AutoDownloader::instance();
delete RSS::Session::instance();

ScanFoldersModel::freeInstance();
TorrentFilesWatcher::freeInstance();
BitTorrent::Session::freeInstance();
Net::GeoIPManager::freeInstance();
Net::DownloadManager::freeInstance();
Expand Down
11 changes: 0 additions & 11 deletions src/app/cmdoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,17 +498,6 @@ QBtCommandLineParameters parseCommandLine(const QStringList &args)
return result;
}

CommandLineParameterError::CommandLineParameterError(const QString &messageForUser)
: std::runtime_error(messageForUser.toLocal8Bit().data())
, m_messageForUser(messageForUser)
{
}

const QString &CommandLineParameterError::messageForUser() const
{
return m_messageForUser;
}

QString wrapText(const QString &text, int initialIndentation = USAGE_TEXT_COLUMN, int wrapAtColumn = WRAP_AT_COLUMN)
{
QStringList words = text.split(' ');
Expand Down
11 changes: 4 additions & 7 deletions src/app/cmdoptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@
#pragma once

#include <optional>
#include <stdexcept>

#include <QString>
#include <QStringList>

#include "base/exceptions.h"

class QProcessEnvironment;

struct QBtCommandLineParameters
Expand Down Expand Up @@ -67,14 +68,10 @@ struct QBtCommandLineParameters
QStringList paramList() const;
};

class CommandLineParameterError : public std::runtime_error
class CommandLineParameterError : public RuntimeError
{
public:
explicit CommandLineParameterError(const QString &messageForUser);
const QString &messageForUser() const;

private:
const QString m_messageForUser;
using RuntimeError::RuntimeError;
};

QBtCommandLineParameters parseCommandLine(const QStringList &args);
Expand Down
2 changes: 1 addition & 1 deletion src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ int main(int argc, char *argv[])
}
catch (const CommandLineParameterError &er)
{
displayBadArgMessage(er.messageForUser());
displayBadArgMessage(er.message());
return EXIT_FAILURE;
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ add_library(qbt_base STATIC
bittorrent/trackerentry.h
digest32.h
exceptions.h
filesystemwatcher.h
global.h
http/connection.h
http/httperror.h
Expand Down Expand Up @@ -71,13 +70,13 @@ add_library(qbt_base STATIC
rss/rss_item.h
rss/rss_parser.h
rss/rss_session.h
scanfoldersmodel.h
search/searchdownloadhandler.h
search/searchhandler.h
search/searchpluginmanager.h
settingsstorage.h
tagset.h
torrentfileguard.h
torrentfileswatcher.h
torrentfilter.h
types.h
unicodestrings.h
Expand Down Expand Up @@ -122,7 +121,6 @@ add_library(qbt_base STATIC
bittorrent/tracker.cpp
bittorrent/trackerentry.cpp
exceptions.cpp
filesystemwatcher.cpp
http/connection.cpp
http/httperror.cpp
http/requestparser.cpp
Expand Down Expand Up @@ -151,13 +149,13 @@ add_library(qbt_base STATIC
rss/rss_item.cpp
rss/rss_parser.cpp
rss/rss_session.cpp
scanfoldersmodel.cpp
search/searchdownloadhandler.cpp
search/searchhandler.cpp
search/searchpluginmanager.cpp
settingsstorage.cpp
tagset.cpp
torrentfileguard.cpp
torrentfileswatcher.cpp
torrentfilter.cpp
utils/bytearray.cpp
utils/compare.cpp
Expand Down
6 changes: 2 additions & 4 deletions src/base/base.pri
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ HEADERS += \
$$PWD/bittorrent/trackerentry.h \
$$PWD/digest32.h \
$$PWD/exceptions.h \
$$PWD/filesystemwatcher.h \
$$PWD/global.h \
$$PWD/http/connection.h \
$$PWD/http/httperror.h \
Expand Down Expand Up @@ -70,14 +69,14 @@ HEADERS += \
$$PWD/rss/rss_item.h \
$$PWD/rss/rss_parser.h \
$$PWD/rss/rss_session.h \
$$PWD/scanfoldersmodel.h \
$$PWD/search/searchdownloadhandler.h \
$$PWD/search/searchhandler.h \
$$PWD/search/searchpluginmanager.h \
$$PWD/settingsstorage.h \
$$PWD/settingvalue.h \
$$PWD/tagset.h \
$$PWD/torrentfileguard.h \
$$PWD/torrentfileswatcher.h \
$$PWD/torrentfilter.h \
$$PWD/types.h \
$$PWD/unicodestrings.h \
Expand Down Expand Up @@ -122,7 +121,6 @@ SOURCES += \
$$PWD/bittorrent/tracker.cpp \
$$PWD/bittorrent/trackerentry.cpp \
$$PWD/exceptions.cpp \
$$PWD/filesystemwatcher.cpp \
$$PWD/http/connection.cpp \
$$PWD/http/httperror.cpp \
$$PWD/http/requestparser.cpp \
Expand Down Expand Up @@ -151,13 +149,13 @@ SOURCES += \
$$PWD/rss/rss_item.cpp \
$$PWD/rss/rss_parser.cpp \
$$PWD/rss/rss_session.cpp \
$$PWD/scanfoldersmodel.cpp \
$$PWD/search/searchdownloadhandler.cpp \
$$PWD/search/searchhandler.cpp \
$$PWD/search/searchpluginmanager.cpp \
$$PWD/settingsstorage.cpp \
$$PWD/tagset.cpp \
$$PWD/torrentfileguard.cpp \
$$PWD/torrentfileswatcher.cpp \
$$PWD/torrentfilter.cpp \
$$PWD/utils/bytearray.cpp \
$$PWD/utils/compare.cpp \
Expand Down
3 changes: 3 additions & 0 deletions src/base/bittorrent/addtorrentparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include <optional>

#include <QMetaType>
#include <QString>
#include <QVector>

Expand Down Expand Up @@ -62,3 +63,5 @@ namespace BitTorrent
qreal ratioLimit = Torrent::USE_GLOBAL_RATIO;
};
}

Q_DECLARE_METATYPE(BitTorrent::AddTorrentParams)
3 changes: 2 additions & 1 deletion src/base/bittorrent/magneturi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include <libtorrent/sha1_hash.hpp>

#include <QRegularExpression>
#include <QUrl>

#include "infohash.h"

Expand All @@ -59,6 +58,8 @@ namespace

using namespace BitTorrent;

const int magnetUriId = qRegisterMetaType<MagnetUri>();

MagnetUri::MagnetUri(const QString &source)
: m_valid(false)
, m_url(source)
Expand Down
5 changes: 3 additions & 2 deletions src/base/bittorrent/magneturi.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@
#include <libtorrent/add_torrent_params.hpp>

#include <QString>
#include <QUrl>
#include <QVector>

#include "infohash.h"
#include "trackerentry.h"

class QUrl;

namespace BitTorrent
{
class MagnetUri
Expand All @@ -64,3 +63,5 @@ namespace BitTorrent
lt::add_torrent_params m_addTorrentParams;
};
}

Q_DECLARE_METATYPE(BitTorrent::MagnetUri)
6 changes: 5 additions & 1 deletion src/base/bittorrent/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ namespace
#endif
}

const int addTorrentParamsId = qRegisterMetaType<AddTorrentParams>();

// Session

Session *Session::m_instance = nullptr;
Expand Down Expand Up @@ -2062,8 +2064,10 @@ LoadTorrentParams Session::initLoadTorrentParams(const AddTorrentParams &addTorr
const bool useAutoTMM = addTorrentParams.useAutoTMM.value_or(!isAutoTMMDisabledByDefault());
if (useAutoTMM)
loadTorrentParams.savePath = "";
else if (addTorrentParams.savePath.trimmed().isEmpty())
else if (addTorrentParams.savePath.isEmpty())
loadTorrentParams.savePath = defaultSavePath();
else if (QDir(addTorrentParams.savePath).isRelative())
loadTorrentParams.savePath = QDir(defaultSavePath()).absoluteFilePath(addTorrentParams.savePath);
else
loadTorrentParams.savePath = normalizePath(addTorrentParams.savePath);

Expand Down
2 changes: 2 additions & 0 deletions src/base/bittorrent/torrentinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ namespace
}
}

const int torrentInfoId = qRegisterMetaType<TorrentInfo>();

TorrentInfo::TorrentInfo(std::shared_ptr<const lt::torrent_info> nativeInfo)
{
m_nativeInfo = std::const_pointer_cast<lt::torrent_info>(nativeInfo);
Expand Down
2 changes: 2 additions & 0 deletions src/base/bittorrent/torrentinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,5 @@ namespace BitTorrent
std::shared_ptr<lt::torrent_info> m_nativeInfo;
};
}

Q_DECLARE_METATYPE(BitTorrent::TorrentInfo)
2 changes: 1 addition & 1 deletion src/base/bittorrent/tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ Http::Response Tracker::processRequest(const Http::Request &request, const Http:

const lt::entry::dictionary_type bencodedEntry =
{
{ANNOUNCE_RESPONSE_FAILURE_REASON, {error.what()}}
{ANNOUNCE_RESPONSE_FAILURE_REASON, {error.message().toStdString()}}
};
QByteArray reply;
lt::bencode(std::back_inserter(reply), bencodedEntry);
Expand Down
8 changes: 4 additions & 4 deletions src/base/exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@

#include "exceptions.h"

RuntimeError::RuntimeError(const QString &message)
: std::runtime_error {message.toUtf8().data()}
Exception::Exception(const QString &message) noexcept
: m_message {message}
{
}

QString RuntimeError::message() const
QString Exception::message() const noexcept
{
return what();
return m_message;
}
24 changes: 19 additions & 5 deletions src/base/exceptions.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2018 Vladimir Golovnev <[email protected]>
* Copyright (C) 2018, 2021 Vladimir Golovnev <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -28,12 +28,26 @@

#pragma once

#include <stdexcept>
#include <QString>

class RuntimeError : public std::runtime_error
class Exception
{
public:
explicit RuntimeError(const QString &message = {});
QString message() const;
explicit Exception(const QString &message = {}) noexcept;
[[nodiscard]] QString message() const noexcept;

private:
QString m_message;
};

class RuntimeError : public Exception
{
public:
using Exception::Exception;
};

class InvalidArgument : public Exception
{
public:
using Exception::Exception;
};
Loading

0 comments on commit 015780f

Please sign in to comment.