mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-10 23:07:59 +00:00
Merge pull request #16820 from Chocobo1/comparisons
Move comparison operator out of class
This commit is contained in:
commit
e42fa0e027
@ -111,12 +111,6 @@ namespace
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const QString &arg) const
|
|
||||||
{
|
|
||||||
return (hasShortcut() && ((arg.size() == 2) && (arg == shortcutParameter())))
|
|
||||||
|| (arg == fullParameter());
|
|
||||||
}
|
|
||||||
|
|
||||||
bool value(const QProcessEnvironment &env) const
|
bool value(const QProcessEnvironment &env) const
|
||||||
{
|
{
|
||||||
QString val = env.value(envVarName());
|
QString val = env.value(envVarName());
|
||||||
@ -132,11 +126,17 @@ namespace
|
|||||||
res += fullParameter();
|
res += fullParameter();
|
||||||
return padUsageText(res);
|
return padUsageText(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
friend bool operator==(const BoolOption &option, const QString &arg)
|
||||||
|
{
|
||||||
|
return (option.hasShortcut() && ((arg.size() == 2) && (option.shortcutParameter() == arg)))
|
||||||
|
|| (option.fullParameter() == arg);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
bool operator==(const QString &s, const BoolOption &o)
|
bool operator==(const QString &arg, const BoolOption &option)
|
||||||
{
|
{
|
||||||
return o == s;
|
return (option == arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Option with string value. May not have a shortcut
|
// Option with string value. May not have a shortcut
|
||||||
@ -148,11 +148,6 @@ namespace
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const QString &arg) const
|
|
||||||
{
|
|
||||||
return arg.startsWith(parameterAssignment());
|
|
||||||
}
|
|
||||||
|
|
||||||
QString value(const QString &arg) const
|
QString value(const QString &arg) const
|
||||||
{
|
{
|
||||||
QStringList parts = arg.split(u'=');
|
QStringList parts = arg.split(u'=');
|
||||||
@ -174,6 +169,11 @@ namespace
|
|||||||
return padUsageText(parameterAssignment() + u'<' + valueName + u'>');
|
return padUsageText(parameterAssignment() + u'<' + valueName + u'>');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
friend bool operator==(const StringOption &option, const QString &arg)
|
||||||
|
{
|
||||||
|
return arg.startsWith(option.parameterAssignment());
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString parameterAssignment() const
|
QString parameterAssignment() const
|
||||||
{
|
{
|
||||||
@ -181,9 +181,9 @@ namespace
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
bool operator==(const QString &s, const StringOption &o)
|
bool operator==(const QString &arg, const StringOption &option)
|
||||||
{
|
{
|
||||||
return o == s;
|
return (option == arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Option with integer value. May not have a shortcut
|
// Option with integer value. May not have a shortcut
|
||||||
@ -195,7 +195,6 @@ namespace
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
using StringOption::operator==;
|
|
||||||
using StringOption::usage;
|
using StringOption::usage;
|
||||||
|
|
||||||
int value(const QString &arg) const
|
int value(const QString &arg) const
|
||||||
@ -225,11 +224,16 @@ namespace
|
|||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
friend bool operator==(const IntOption &option, const QString &arg)
|
||||||
|
{
|
||||||
|
return (static_cast<StringOption>(option) == arg);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
bool operator==(const QString &s, const IntOption &o)
|
bool operator==(const QString &arg, const IntOption &option)
|
||||||
{
|
{
|
||||||
return o == s;
|
return (option == arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Option that is explicitly set to true or false, and whose value is undefined when unspecified.
|
// Option that is explicitly set to true or false, and whose value is undefined when unspecified.
|
||||||
@ -243,12 +247,6 @@ namespace
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const QString &arg) const
|
|
||||||
{
|
|
||||||
QStringList parts = arg.split(u'=');
|
|
||||||
return parts[0] == fullParameter();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString usage() const
|
QString usage() const
|
||||||
{
|
{
|
||||||
return padUsageText(fullParameter() + u"=<true|false>");
|
return padUsageText(fullParameter() + u"=<true|false>");
|
||||||
@ -308,12 +306,17 @@ namespace
|
|||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
friend bool operator==(const TriStateBoolOption &option, const QString &arg)
|
||||||
|
{
|
||||||
|
return arg.section(u'=', 0, 0) == option.fullParameter();
|
||||||
|
}
|
||||||
|
|
||||||
bool m_defaultValue;
|
bool m_defaultValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool operator==(const QString &s, const TriStateBoolOption &o)
|
bool operator==(const QString &arg, const TriStateBoolOption &option)
|
||||||
{
|
{
|
||||||
return o == s;
|
return (option == arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr const BoolOption SHOW_HELP_OPTION {"help", 'h'};
|
constexpr const BoolOption SHOW_HELP_OPTION {"help", 'h'};
|
||||||
|
@ -101,14 +101,15 @@ public:
|
|||||||
return iter;
|
return iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool operator==(const Iterator &other) const
|
// comparing iterators from different containers is undefined behavior in C++ standard library
|
||||||
|
friend constexpr bool operator==(const Iterator &left, const Iterator &right)
|
||||||
{
|
{
|
||||||
return (*(*this) == *other);
|
return (*left == *right);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool operator!=(const Iterator &other) const
|
friend constexpr bool operator!=(const Iterator &left, const Iterator &right)
|
||||||
{
|
{
|
||||||
return !(*this == other);
|
return !(left == right);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -144,24 +144,35 @@ namespace RSS
|
|||||||
mutable QStringList lastComputedEpisodes;
|
mutable QStringList lastComputedEpisodes;
|
||||||
mutable QHash<QString, QRegularExpression> cachedRegexes;
|
mutable QHash<QString, QRegularExpression> cachedRegexes;
|
||||||
|
|
||||||
bool operator==(const AutoDownloadRuleData &other) const
|
friend bool operator==(const AutoDownloadRuleData &left, const AutoDownloadRuleData &right)
|
||||||
{
|
{
|
||||||
return (name == other.name)
|
return (left.name == right.name)
|
||||||
&& (enabled == other.enabled)
|
&& (left.enabled == right.enabled)
|
||||||
&& (mustContain == other.mustContain)
|
&& (left.mustContain == right.mustContain)
|
||||||
&& (mustNotContain == other.mustNotContain)
|
&& (left.mustNotContain == right.mustNotContain)
|
||||||
&& (episodeFilter == other.episodeFilter)
|
&& (left.episodeFilter == right.episodeFilter)
|
||||||
&& (feedURLs == other.feedURLs)
|
&& (left.feedURLs == right.feedURLs)
|
||||||
&& (useRegex == other.useRegex)
|
&& (left.useRegex == right.useRegex)
|
||||||
&& (ignoreDays == other.ignoreDays)
|
&& (left.ignoreDays == right.ignoreDays)
|
||||||
&& (lastMatch == other.lastMatch)
|
&& (left.lastMatch == right.lastMatch)
|
||||||
&& (savePath == other.savePath)
|
&& (left.savePath == right.savePath)
|
||||||
&& (category == other.category)
|
&& (left.category == right.category)
|
||||||
&& (addPaused == other.addPaused)
|
&& (left.addPaused == right.addPaused)
|
||||||
&& (contentLayout == other.contentLayout)
|
&& (left.contentLayout == right.contentLayout)
|
||||||
&& (smartFilter == other.smartFilter);
|
&& (left.smartFilter == right.smartFilter);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool operator==(const AutoDownloadRule &left, const AutoDownloadRule &right)
|
||||||
|
{
|
||||||
|
return (left.m_dataPtr == right.m_dataPtr) // optimization
|
||||||
|
|| (*(left.m_dataPtr) == *(right.m_dataPtr));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const AutoDownloadRule &left, const AutoDownloadRule &right)
|
||||||
|
{
|
||||||
|
return !(left == right);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
using namespace RSS;
|
using namespace RSS;
|
||||||
@ -448,17 +459,6 @@ AutoDownloadRule &AutoDownloadRule::operator=(const AutoDownloadRule &other)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AutoDownloadRule::operator==(const AutoDownloadRule &other) const
|
|
||||||
{
|
|
||||||
return (m_dataPtr == other.m_dataPtr) // optimization
|
|
||||||
|| (*m_dataPtr == *other.m_dataPtr);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AutoDownloadRule::operator!=(const AutoDownloadRule &other) const
|
|
||||||
{
|
|
||||||
return !operator==(other);
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonObject AutoDownloadRule::toJsonObject() const
|
QJsonObject AutoDownloadRule::toJsonObject() const
|
||||||
{
|
{
|
||||||
return {{Str_Enabled, isEnabled()}
|
return {{Str_Enabled, isEnabled()}
|
||||||
|
@ -53,6 +53,8 @@ namespace RSS
|
|||||||
AutoDownloadRule(const AutoDownloadRule &other);
|
AutoDownloadRule(const AutoDownloadRule &other);
|
||||||
~AutoDownloadRule();
|
~AutoDownloadRule();
|
||||||
|
|
||||||
|
AutoDownloadRule &operator=(const AutoDownloadRule &other);
|
||||||
|
|
||||||
QString name() const;
|
QString name() const;
|
||||||
void setName(const QString &name);
|
void setName(const QString &name);
|
||||||
|
|
||||||
@ -91,9 +93,7 @@ namespace RSS
|
|||||||
bool matches(const QVariantHash &articleData) const;
|
bool matches(const QVariantHash &articleData) const;
|
||||||
bool accepts(const QVariantHash &articleData);
|
bool accepts(const QVariantHash &articleData);
|
||||||
|
|
||||||
AutoDownloadRule &operator=(const AutoDownloadRule &other);
|
friend bool operator==(const AutoDownloadRule &left, const AutoDownloadRule &right);
|
||||||
bool operator==(const AutoDownloadRule &other) const;
|
|
||||||
bool operator!=(const AutoDownloadRule &other) const;
|
|
||||||
|
|
||||||
QJsonObject toJsonObject() const;
|
QJsonObject toJsonObject() const;
|
||||||
static AutoDownloadRule fromJsonObject(const QJsonObject &jsonObj, const QString &name = u""_qs);
|
static AutoDownloadRule fromJsonObject(const QJsonObject &jsonObj, const QString &name = u""_qs);
|
||||||
@ -111,4 +111,6 @@ namespace RSS
|
|||||||
|
|
||||||
QSharedDataPointer<AutoDownloadRuleData> m_dataPtr;
|
QSharedDataPointer<AutoDownloadRuleData> m_dataPtr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool operator!=(const AutoDownloadRule &left, const AutoDownloadRule &right);
|
||||||
}
|
}
|
||||||
|
@ -142,10 +142,10 @@ QPoint Utils::Gui::screenCenter(const QWidget *w)
|
|||||||
void Utils::Gui::openPath(const Path &path)
|
void Utils::Gui::openPath(const Path &path)
|
||||||
{
|
{
|
||||||
// Hack to access samba shares with QDesktopServices::openUrl
|
// Hack to access samba shares with QDesktopServices::openUrl
|
||||||
if (path.data().startsWith(u"//"))
|
const QUrl url = path.data().startsWith(u"//")
|
||||||
QDesktopServices::openUrl(QUrl(u"file:" + path.toString()));
|
? QUrl(u"file:" + path.data())
|
||||||
else
|
: QUrl::fromLocalFile(path.data());
|
||||||
QDesktopServices::openUrl(QUrl::fromLocalFile(path.data()));
|
QDesktopServices::openUrl(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open the parent directory of the given path with a file manager and select
|
// Open the parent directory of the given path with a file manager and select
|
||||||
|
@ -717,7 +717,8 @@ void TorrentsController::addAction()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto it = data().constBegin(); it != data().constEnd(); ++it)
|
const DataMap torrents = data();
|
||||||
|
for (auto it = torrents.constBegin(); it != torrents.constEnd(); ++it)
|
||||||
{
|
{
|
||||||
const nonstd::expected<BitTorrent::TorrentInfo, QString> result = BitTorrent::TorrentInfo::load(it.value());
|
const nonstd::expected<BitTorrent::TorrentInfo, QString> result = BitTorrent::TorrentInfo::load(it.value());
|
||||||
if (!result)
|
if (!result)
|
||||||
|
Loading…
Reference in New Issue
Block a user