1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-11 07:18:08 +00:00

Merge pull request #9015 from thalieht/style

Fix coding style
This commit is contained in:
Vladimir Golovnev 2018-06-03 14:48:04 +03:00 committed by GitHub
commit e61c882fee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 195 additions and 223 deletions

View File

@ -31,10 +31,6 @@
#include <algorithm> #include <algorithm>
#ifdef Q_OS_WIN
#include <memory>
#endif
#include <QAtomicInt> #include <QAtomicInt>
#include <QDebug> #include <QDebug>
#include <QFileInfo> #include <QFileInfo>
@ -43,6 +39,29 @@
#include <QProcess> #include <QProcess>
#include <QSysInfo> #include <QSysInfo>
#ifdef Q_OS_WIN
#include <memory>
#include <Shellapi.h>
#endif
#ifndef DISABLE_GUI
#ifdef Q_OS_WIN
#include <QSessionManager>
#include <QSharedMemory>
#endif // Q_OS_WIN
#ifdef Q_OS_MAC
#include <QFileOpenEvent>
#include <QFont>
#include <QUrl>
#endif // Q_OS_MAC
#include "addnewtorrentdialog.h"
#include "gui/guiiconprovider.h"
#include "mainwindow.h"
#include "shutdownconfirmdlg.h"
#else // DISABLE_GUI
#include <cstdio>
#endif // DISABLE_GUI
#include "base/bittorrent/session.h" #include "base/bittorrent/session.h"
#include "base/bittorrent/torrenthandle.h" #include "base/bittorrent/torrenthandle.h"
#include "base/iconprovider.h" #include "base/iconprovider.h"
@ -62,28 +81,6 @@
#include "base/utils/string.h" #include "base/utils/string.h"
#include "filelogger.h" #include "filelogger.h"
#ifndef DISABLE_GUI
#ifdef Q_OS_WIN
#include <QSessionManager>
#include <QSharedMemory>
#endif // Q_OS_WIN
#ifdef Q_OS_MAC
#include <QFileOpenEvent>
#include <QFont>
#include <QUrl>
#endif // Q_OS_MAC
#include "addnewtorrentdialog.h"
#include "gui/guiiconprovider.h"
#include "mainwindow.h"
#include "shutdownconfirmdlg.h"
#else // DISABLE_GUI
#include <cstdio>
#endif // DISABLE_GUI
#ifdef Q_OS_WIN
#include <Shellapi.h>
#endif
#ifndef DISABLE_WEBUI #ifndef DISABLE_WEBUI
#include "webui/webui.h" #include "webui/webui.h"
#endif #endif
@ -102,7 +99,7 @@ namespace
const QString KEY_FILELOGGER_AGE = FILELOGGER_SETTINGS_KEY("Age"); const QString KEY_FILELOGGER_AGE = FILELOGGER_SETTINGS_KEY("Age");
const QString KEY_FILELOGGER_AGETYPE = FILELOGGER_SETTINGS_KEY("AgeType"); const QString KEY_FILELOGGER_AGETYPE = FILELOGGER_SETTINGS_KEY("AgeType");
//just a shortcut // just a shortcut
inline SettingsStorage *settings() { return SettingsStorage::instance(); } inline SettingsStorage *settings() { return SettingsStorage::instance(); }
const QString LOG_FOLDER("logs"); const QString LOG_FOLDER("logs");
@ -261,12 +258,12 @@ void Application::setFileLoggerAge(const int value)
int Application::fileLoggerAgeType() const int Application::fileLoggerAgeType() const
{ {
int val = settings()->loadValue(KEY_FILELOGGER_AGETYPE, 1).toInt(); int val = settings()->loadValue(KEY_FILELOGGER_AGETYPE, 1).toInt();
return (val < 0 || val > 2) ? 1 : val; return ((val < 0) || (val > 2)) ? 1 : val;
} }
void Application::setFileLoggerAgeType(const int value) void Application::setFileLoggerAgeType(const int value)
{ {
settings()->storeValue(KEY_FILELOGGER_AGETYPE, (value < 0 || value > 2) ? 1 : value); settings()->storeValue(KEY_FILELOGGER_AGETYPE, ((value < 0) || (value > 2)) ? 1 : value);
} }
void Application::processMessage(const QString &message) void Application::processMessage(const QString &message)
@ -338,12 +335,12 @@ void Application::runExternalProgram(const BitTorrent::TorrentHandle *torrent) c
void Application::sendNotificationEmail(const BitTorrent::TorrentHandle *torrent) void Application::sendNotificationEmail(const BitTorrent::TorrentHandle *torrent)
{ {
// Prepare mail content // Prepare mail content
const QString content = tr("Torrent name: %1").arg(torrent->name()) + "\n" const QString content = tr("Torrent name: %1").arg(torrent->name()) + '\n'
+ tr("Torrent size: %1").arg(Utils::Misc::friendlyUnit(torrent->wantedSize())) + "\n" + tr("Torrent size: %1").arg(Utils::Misc::friendlyUnit(torrent->wantedSize())) + '\n'
+ tr("Save path: %1").arg(torrent->savePath()) + "\n\n" + tr("Save path: %1").arg(torrent->savePath()) + "\n\n"
+ tr("The torrent was downloaded in %1.", "The torrent was downloaded in 1 hour and 20 seconds") + tr("The torrent was downloaded in %1.", "The torrent was downloaded in 1 hour and 20 seconds")
.arg(Utils::Misc::userFriendlyDuration(torrent->activeTime())) + "\n\n\n" .arg(Utils::Misc::userFriendlyDuration(torrent->activeTime())) + "\n\n\n"
+ tr("Thank you for using qBittorrent.") + "\n"; + tr("Thank you for using qBittorrent.") + '\n';
// Send the notification email // Send the notification email
const Preferences *pref = Preferences::instance(); const Preferences *pref = Preferences::instance();
@ -523,7 +520,7 @@ int Application::exec(const QStringList &params)
#ifdef DISABLE_GUI #ifdef DISABLE_GUI
#ifndef DISABLE_WEBUI #ifndef DISABLE_WEBUI
Preferences* const pref = Preferences::instance(); Preferences *const pref = Preferences::instance();
// Display some information to the user // Display some information to the user
const QString mesg = QString("\n******** %1 ********\n").arg(tr("Information")) const QString mesg = QString("\n******** %1 ********\n").arg(tr("Information"))
+ tr("To control qBittorrent, access the Web UI at %1") + tr("To control qBittorrent, access the Web UI at %1")
@ -619,7 +616,7 @@ bool Application::notify(QObject *receiver, QEvent *event)
void Application::initializeTranslation() void Application::initializeTranslation()
{ {
Preferences* const pref = Preferences::instance(); Preferences *const pref = Preferences::instance();
// Load translation // Load translation
QString localeStr = pref->getLocale(); QString localeStr = pref->getLocale();
@ -685,7 +682,7 @@ void Application::cleanup()
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
if (m_window) { if (m_window) {
// Hide the window and not leave it on screen as // Hide the window and don't leave it on screen as
// unresponsive. Also for Windows take the WinId // unresponsive. Also for Windows take the WinId
// after it's hidden, because hide() may cause a // after it's hidden, because hide() may cause a
// WinId change. // WinId change.

View File

@ -40,15 +40,13 @@ typedef QtSingleApplication BaseApplication;
class MainWindow; class MainWindow;
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
QT_BEGIN_NAMESPACE
class QSessionManager; class QSessionManager;
QT_END_NAMESPACE
#endif // Q_OS_WIN #endif // Q_OS_WIN
#else #else
#include "qtsinglecoreapplication.h" #include "qtsinglecoreapplication.h"
typedef QtSingleCoreApplication BaseApplication; typedef QtSingleCoreApplication BaseApplication;
#endif #endif // DISABLE_GUI
#include "base/utils/misc.h" #include "base/utils/misc.h"
#include "cmdoptions.h" #include "cmdoptions.h"
@ -112,7 +110,7 @@ protected:
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
bool event(QEvent *) override; bool event(QEvent *) override;
#endif #endif
bool notify(QObject* receiver, QEvent* event) override; bool notify(QObject *receiver, QEvent *event) override;
#endif #endif
private slots: private slots:

View File

@ -2,7 +2,7 @@
* Bittorrent Client using Qt and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2016 Eugene Shalygin <eugene.shalygin@gmail.com> * Copyright (C) 2016 Eugene Shalygin <eugene.shalygin@gmail.com>
* Copyright (C) 2014 Vladimir Golovnev <glassez@yandex.ru> * Copyright (C) 2014 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2006 Christophe Dumez * Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -26,8 +26,6 @@
* modify file(s), you may extend this exception to your version of the file(s), * modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */
#include "cmdoptions.h" #include "cmdoptions.h"
@ -100,7 +98,7 @@ namespace
}; };
// Boolean option. // Boolean option.
class BoolOption: protected Option class BoolOption : protected Option
{ {
public: public:
constexpr BoolOption(const char *name, char shortcut = 0) constexpr BoolOption(const char *name, char shortcut = 0)
@ -118,7 +116,7 @@ namespace
{ {
QString val = env.value(envVarName()); QString val = env.value(envVarName());
// we accept "1" and "true" (upper or lower cased) as boolean 'true' values // we accept "1" and "true" (upper or lower cased) as boolean 'true' values
return (val == QLatin1String("1") || val.toUpper() == QLatin1String("TRUE")); return ((val == QLatin1String("1")) || (val.toUpper() == QLatin1String("TRUE")));
} }
QString usage() const QString usage() const
@ -137,7 +135,7 @@ namespace
} }
// Option with string value. May not have a shortcut // Option with string value. May not have a shortcut
struct StringOption: protected Option struct StringOption : protected Option
{ {
public: public:
constexpr StringOption(const char *name) constexpr StringOption(const char *name)
@ -184,7 +182,7 @@ namespace
} }
// Option with integer value. May not have a shortcut // Option with integer value. May not have a shortcut
class IntOption: protected StringOption class IntOption : protected StringOption
{ {
public: public:
constexpr IntOption(const char *name) constexpr IntOption(const char *name)
@ -230,7 +228,7 @@ namespace
// 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.
// May not have a shortcut. // May not have a shortcut.
class TriStateBoolOption: protected Option class TriStateBoolOption : protected Option
{ {
public: public:
constexpr TriStateBoolOption(const char *name, bool defaultValue) constexpr TriStateBoolOption(const char *name, bool defaultValue)
@ -260,10 +258,10 @@ namespace
else if (parts.size() == 2) { else if (parts.size() == 2) {
QString val = parts[1]; QString val = parts[1];
if (val.toUpper() == QLatin1String("TRUE") || val == QLatin1String("1")) { if ((val.toUpper() == QLatin1String("TRUE")) || (val == QLatin1String("1"))) {
return TriStateBool::True; return TriStateBool::True;
} }
else if (val.toUpper() == QLatin1String("FALSE") || val == QLatin1String("0")) { else if ((val.toUpper() == QLatin1String("FALSE")) || (val == QLatin1String("0"))) {
return TriStateBool::False; return TriStateBool::False;
} }
} }
@ -285,10 +283,10 @@ namespace
else if (val == QLatin1String("-1")) { else if (val == QLatin1String("-1")) {
return TriStateBool::Undefined; return TriStateBool::Undefined;
} }
else if (val.toUpper() == QLatin1String("TRUE") || val == QLatin1String("1")) { else if ((val.toUpper() == QLatin1String("TRUE")) || (val == QLatin1String("1"))) {
return TriStateBool::True; return TriStateBool::True;
} }
else if (val.toUpper() == QLatin1String("FALSE") || val == QLatin1String("0")) { else if ((val.toUpper() == QLatin1String("FALSE")) || (val == QLatin1String("0"))) {
return TriStateBool::False; return TriStateBool::False;
} }
else { else {
@ -360,7 +358,7 @@ QStringList QBtCommandLineParameters::paramList() const
// the user has specified. Here we place special strings that are // the user has specified. Here we place special strings that are
// almost certainly not going to collide with a file path or URL // almost certainly not going to collide with a file path or URL
// specified by the user, and placing them at the beginning of the // specified by the user, and placing them at the beginning of the
// string listr so that they will be processed before the list of // string list so that they will be processed before the list of
// torrent paths or URLs. // torrent paths or URLs.
if (!savePath.isEmpty()) if (!savePath.isEmpty())
@ -406,7 +404,7 @@ QBtCommandLineParameters parseCommandLine(const QStringList &args)
if ((arg.startsWith("--") && !arg.endsWith(".torrent")) if ((arg.startsWith("--") && !arg.endsWith(".torrent"))
|| (arg.startsWith("-") && (arg.size() == 2))) { || (arg.startsWith("-") && (arg.size() == 2))) {
// Parse known parameters // Parse known parameters
if ((arg == SHOW_HELP_OPTION)) { if (arg == SHOW_HELP_OPTION) {
result.showHelp = true; result.showHelp = true;
} }
#ifndef Q_OS_WIN #ifndef Q_OS_WIN
@ -509,7 +507,7 @@ QString wrapText(const QString &text, int initialIndentation = USAGE_TEXT_COLUMN
} }
} }
return lines.join("\n"); return lines.join('\n');
} }
QString makeUsage(const QString &prgName) QString makeUsage(const QString &prgName)

View File

@ -2,7 +2,7 @@
* Bittorrent Client using Qt and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2016 Eugene Shalygin <eugene.shalygin@gmail.com> * Copyright (C) 2016 Eugene Shalygin <eugene.shalygin@gmail.com>
* Copyright (C) 2014 Vladimir Golovnev <glassez@yandex.ru> * Copyright (C) 2014 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2006 Christophe Dumez * Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -26,8 +26,6 @@
* modify file(s), you may extend this exception to your version of the file(s), * modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */
#ifndef APP_OPTIONS_H #ifndef APP_OPTIONS_H
@ -62,11 +60,11 @@ struct QBtCommandLineParameters
QStringList paramList() const; QStringList paramList() const;
}; };
class CommandLineParameterError: public std::runtime_error class CommandLineParameterError : public std::runtime_error
{ {
public: public:
CommandLineParameterError(const QString &messageForUser); CommandLineParameterError(const QString &messageForUser);
const QString& messageForUser() const; const QString &messageForUser() const;
private: private:
const QString m_messageForUser; const QString m_messageForUser;

View File

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2016 sledgehammer999 <hammered999@gmail.com> * Copyright (C) 2016 sledgehammer999 <sledgehammer999@qbittorrent.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -26,11 +26,13 @@
* exception statement from your version. * exception statement from your version.
*/ */
#include "filelogger.h"
#include <QDateTime> #include <QDateTime>
#include <QDir> #include <QDir>
#include <QFile> #include <QFile>
#include <QTextStream> #include <QTextStream>
#include "filelogger.h"
#include "base/logger.h" #include "base/logger.h"
#include "base/utils/fs.h" #include "base/utils/fs.h"
@ -47,8 +49,8 @@ FileLogger::FileLogger(const QString &path, const bool backup, const int maxSize
if (deleteOld) if (deleteOld)
this->deleteOld(age, ageType); this->deleteOld(age, ageType);
const Logger* const logger = Logger::instance(); const Logger *const logger = Logger::instance();
foreach (const Log::Msg& msg, logger->getMessages()) foreach (const Log::Msg &msg, logger->getMessages())
addLogMessage(msg); addLogMessage(msg);
connect(logger, &Logger::newLogMessage, this, &FileLogger::addLogMessage); connect(logger, &Logger::newLogMessage, this, &FileLogger::addLogMessage);
@ -61,7 +63,7 @@ FileLogger::~FileLogger()
delete m_logFile; delete m_logFile;
} }
void FileLogger::changePath(const QString& newPath) void FileLogger::changePath(const QString &newPath)
{ {
QString tmpPath = Utils::Fs::fromNativePath(newPath); QString tmpPath = Utils::Fs::fromNativePath(newPath);
QDir dir(tmpPath); QDir dir(tmpPath);

View File

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2016 sledgehammer999 <hammered999@gmail.com> * Copyright (C) 2016 sledgehammer999 <sledgehammer999@qbittorrent.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -76,4 +76,3 @@ private:
}; };
#endif // FILELOGGER_H #endif // FILELOGGER_H

View File

@ -1,7 +1,7 @@
/* /*
* Bittorrent Client using Qt and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2014 Vladimir Golovnev <glassez@yandex.ru> * Copyright (C) 2014 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2006 Christophe Dumez * Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -25,8 +25,6 @@
* modify file(s), you may extend this exception to your version of the file(s), * modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */
#include <cstdlib> #include <cstdlib>
@ -67,10 +65,10 @@ Q_IMPORT_PLUGIN(QICOPlugin)
#endif // Q_OS_UNIX #endif // Q_OS_UNIX
#endif //STACKTRACE #endif //STACKTRACE
#include "application.h" #include "base/preferences.h"
#include "base/profile.h" #include "base/profile.h"
#include "base/utils/misc.h" #include "base/utils/misc.h"
#include "base/preferences.h" #include "application.h"
#include "cmdoptions.h" #include "cmdoptions.h"
#include "upgrade.h" #include "upgrade.h"
@ -95,7 +93,7 @@ const char *sysSigName[] = {
}; };
#if !defined Q_OS_WIN && !defined Q_OS_HAIKU #if !defined Q_OS_WIN && !defined Q_OS_HAIKU
void reportToUser(const char* str); void reportToUser(const char *str);
#endif #endif
void displayVersion(); void displayVersion();
@ -269,7 +267,7 @@ int main(int argc, char *argv[])
} }
#if !defined Q_OS_WIN && !defined Q_OS_HAIKU #if !defined Q_OS_WIN && !defined Q_OS_HAIKU
void reportToUser(const char* str) void reportToUser(const char *str)
{ {
const size_t strLen = strlen(str); const size_t strLen = strlen(str);
if (write(STDERR_FILENO, str, strLen) < static_cast<ssize_t>(strLen)) { if (write(STDERR_FILENO, str, strLen) < static_cast<ssize_t>(strLen)) {
@ -347,7 +345,7 @@ void displayVersion()
printf("%s %s\n", qUtf8Printable(qApp->applicationName()), QBT_VERSION); printf("%s %s\n", qUtf8Printable(qApp->applicationName()), QBT_VERSION);
} }
void displayBadArgMessage(const QString& message) void displayBadArgMessage(const QString &message)
{ {
QString help = QObject::tr("Run application with -h option to read about command line parameters."); QString help = QObject::tr("Run application with -h option to read about command line parameters.");
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
@ -366,7 +364,7 @@ void displayBadArgMessage(const QString& message)
bool userAgreesWithLegalNotice() bool userAgreesWithLegalNotice()
{ {
Preferences* const pref = Preferences::instance(); Preferences *const pref = Preferences::instance();
if (pref->getAcceptedLegal()) // Already accepted once if (pref->getAcceptedLegal()) // Already accepted once
return true; return true;
@ -397,7 +395,7 @@ bool userAgreesWithLegalNotice()
pref->setAcceptedLegal(true); pref->setAcceptedLegal(true);
return true; return true;
} }
#endif #endif // DISABLE_GUI
return false; return false;
} }

View File

@ -299,6 +299,6 @@ void migrateRSS()
qBTRSSLegacy->remove("old_items"); qBTRSSLegacy->remove("old_items");
} }
} }
#endif #endif // DISABLE_GUI
#endif // UPGRADE_H #endif // UPGRADE_H

View File

@ -1,5 +1,5 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2011 Vladimir Golovnev <glassez@yandex.ru> * Copyright (C) 2011 Vladimir Golovnev <glassez@yandex.ru>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -24,16 +24,15 @@
* modify file(s), you may extend this exception to your version of the file(s), * modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */
#include "powermanagement.h"
#include <QtGlobal> #include <QtGlobal>
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) && defined(QT_DBUS_LIB) #if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) && defined(QT_DBUS_LIB)
#include "powermanagement_x11.h" #include "powermanagement_x11.h"
#endif #endif
#include "powermanagement.h"
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
#include <IOKit/pwr_mgt/IOPMLib.h> #include <IOKit/pwr_mgt/IOPMLib.h>
@ -43,7 +42,9 @@
#include <windows.h> #include <windows.h>
#endif #endif
PowerManagement::PowerManagement(QObject *parent) : QObject(parent), m_busy(false) PowerManagement::PowerManagement(QObject *parent)
: QObject(parent)
, m_busy(false)
{ {
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) && defined(QT_DBUS_LIB) #if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) && defined(QT_DBUS_LIB)
m_inhibitor = new PowerManagementInhibitor(this); m_inhibitor = new PowerManagementInhibitor(this);
@ -56,8 +57,10 @@ PowerManagement::~PowerManagement()
void PowerManagement::setActivityState(bool busy) void PowerManagement::setActivityState(bool busy)
{ {
if (busy) setBusy(); if (busy)
else setIdle(); setBusy();
else
setIdle();
} }
void PowerManagement::setBusy() void PowerManagement::setBusy()
@ -68,10 +71,11 @@ void PowerManagement::setBusy()
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED); SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED);
#elif (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) && defined(QT_DBUS_LIB) #elif (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) && defined(QT_DBUS_LIB)
m_inhibitor->RequestBusy(); m_inhibitor->requestBusy();
#elif defined(Q_OS_MAC) #elif defined(Q_OS_MAC)
IOReturn success = IOPMAssertionCreate(kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, &m_assertionID); IOReturn success = IOPMAssertionCreate(kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, &m_assertionID);
if (success != kIOReturnSuccess) m_busy = false; if (success != kIOReturnSuccess)
m_busy = false;
#endif #endif
} }
@ -83,7 +87,7 @@ void PowerManagement::setIdle()
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
SetThreadExecutionState(ES_CONTINUOUS); SetThreadExecutionState(ES_CONTINUOUS);
#elif (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) && defined(QT_DBUS_LIB) #elif (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) && defined(QT_DBUS_LIB)
m_inhibitor->RequestIdle(); m_inhibitor->requestIdle();
#elif defined(Q_OS_MAC) #elif defined(Q_OS_MAC)
IOPMAssertionRelease(m_assertionID); IOPMAssertionRelease(m_assertionID);
#endif #endif

View File

@ -1,5 +1,5 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2011 Vladimir Golovnev <glassez@yandex.ru> * Copyright (C) 2011 Vladimir Golovnev <glassez@yandex.ru>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -24,8 +24,6 @@
* modify file(s), you may extend this exception to your version of the file(s), * modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */
#ifndef POWERMANAGEMENT_H #ifndef POWERMANAGEMENT_H

View File

@ -1,5 +1,5 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2011 Vladimir Golovnev <glassez@yandex.ru> * Copyright (C) 2011 Vladimir Golovnev <glassez@yandex.ru>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -24,48 +24,45 @@
* modify file(s), you may extend this exception to your version of the file(s), * modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */
#include "powermanagement_x11.h"
#include <QDBusConnection> #include <QDBusConnection>
#include <QDBusMessage> #include <QDBusMessage>
#include <QDBusPendingCall> #include <QDBusPendingCall>
#include <QDBusPendingReply> #include <QDBusPendingReply>
#include "powermanagement_x11.h" PowerManagementInhibitor::PowerManagementInhibitor(QObject *parent)
: QObject(parent)
PowerManagementInhibitor::PowerManagementInhibitor(QObject *parent) : QObject(parent)
{ {
if (!QDBusConnection::sessionBus().isConnected()) if (!QDBusConnection::sessionBus().isConnected()) {
{
qDebug("D-Bus: Could not connect to session bus"); qDebug("D-Bus: Could not connect to session bus");
m_state = error; m_state = Error;
} }
else else {
{ m_state = Idle;
m_state = idle;
} }
m_intended_state = idle; m_intendedState = Idle;
m_cookie = 0; m_cookie = 0;
m_use_gsm = false; m_useGSM = false;
} }
PowerManagementInhibitor::~PowerManagementInhibitor() PowerManagementInhibitor::~PowerManagementInhibitor()
{ {
} }
void PowerManagementInhibitor::RequestIdle() void PowerManagementInhibitor::requestIdle()
{ {
m_intended_state = idle; m_intendedState = Idle;
if (m_state == error || m_state == idle || m_state == request_idle || m_state == request_busy) if ((m_state == Error) || (m_state == Idle) || (m_state == RequestIdle) || (m_state == RequestBusy))
return; return;
qDebug("D-Bus: PowerManagementInhibitor: Requesting idle"); qDebug("D-Bus: PowerManagementInhibitor: Requesting idle");
QDBusMessage call; QDBusMessage call;
if (!m_use_gsm) if (!m_useGSM)
call = QDBusMessage::createMethodCall( call = QDBusMessage::createMethodCall(
"org.freedesktop.PowerManagement", "org.freedesktop.PowerManagement",
"/org/freedesktop/PowerManagement/Inhibit", "/org/freedesktop/PowerManagement/Inhibit",
@ -78,7 +75,7 @@ void PowerManagementInhibitor::RequestIdle()
"org.gnome.SessionManager", "org.gnome.SessionManager",
"Uninhibit"); "Uninhibit");
m_state = request_idle; m_state = RequestIdle;
QList<QVariant> args; QList<QVariant> args;
args << m_cookie; args << m_cookie;
@ -86,20 +83,20 @@ void PowerManagementInhibitor::RequestIdle()
QDBusPendingCall pcall = QDBusConnection::sessionBus().asyncCall(call, 1000); QDBusPendingCall pcall = QDBusConnection::sessionBus().asyncCall(call, 1000);
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, &PowerManagementInhibitor::OnAsyncReply); connect(watcher, &QDBusPendingCallWatcher::finished, this, &PowerManagementInhibitor::onAsyncReply);
} }
void PowerManagementInhibitor::RequestBusy() void PowerManagementInhibitor::requestBusy()
{ {
m_intended_state = busy; m_intendedState = Busy;
if (m_state == error || m_state == busy || m_state == request_busy || m_state == request_idle) if ((m_state == Error) || (m_state == Busy) || (m_state == RequestBusy) || (m_state == RequestIdle))
return; return;
qDebug("D-Bus: PowerManagementInhibitor: Requesting busy"); qDebug("D-Bus: PowerManagementInhibitor: Requesting busy");
QDBusMessage call; QDBusMessage call;
if (!m_use_gsm) if (!m_useGSM)
call = QDBusMessage::createMethodCall( call = QDBusMessage::createMethodCall(
"org.freedesktop.PowerManagement", "org.freedesktop.PowerManagement",
"/org/freedesktop/PowerManagement/Inhibit", "/org/freedesktop/PowerManagement/Inhibit",
@ -112,71 +109,64 @@ void PowerManagementInhibitor::RequestBusy()
"org.gnome.SessionManager", "org.gnome.SessionManager",
"Inhibit"); "Inhibit");
m_state = request_busy; m_state = RequestBusy;
QList<QVariant> args; QList<QVariant> args;
args << "qBittorrent"; args << "qBittorrent";
if (m_use_gsm) args << 0u; if (m_useGSM) args << 0u;
args << "Active torrents are presented"; args << "Active torrents are presented";
if (m_use_gsm) args << 8u; if (m_useGSM) args << 8u;
call.setArguments(args); call.setArguments(args);
QDBusPendingCall pcall = QDBusConnection::sessionBus().asyncCall(call, 1000); QDBusPendingCall pcall = QDBusConnection::sessionBus().asyncCall(call, 1000);
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, &PowerManagementInhibitor::OnAsyncReply); connect(watcher, &QDBusPendingCallWatcher::finished, this, &PowerManagementInhibitor::onAsyncReply);
} }
void PowerManagementInhibitor::OnAsyncReply(QDBusPendingCallWatcher *call) void PowerManagementInhibitor::onAsyncReply(QDBusPendingCallWatcher *call)
{ {
if (m_state == request_idle) if (m_state == RequestIdle) {
{
QDBusPendingReply<> reply = *call; QDBusPendingReply<> reply = *call;
if (reply.isError()) if (reply.isError()) {
{
qDebug("D-Bus: Reply: Error: %s", qUtf8Printable(reply.error().message())); qDebug("D-Bus: Reply: Error: %s", qUtf8Printable(reply.error().message()));
m_state = error; m_state = Error;
} }
else else {
{ m_state = Idle;
m_state = idle;
qDebug("D-Bus: PowerManagementInhibitor: Request successful"); qDebug("D-Bus: PowerManagementInhibitor: Request successful");
if (m_intended_state == busy) RequestBusy(); if (m_intendedState == Busy)
requestBusy();
} }
} }
else if (m_state == request_busy) else if (m_state == RequestBusy) {
{
QDBusPendingReply<uint> reply = *call; QDBusPendingReply<uint> reply = *call;
if (reply.isError()) if (reply.isError()) {
{
qDebug("D-Bus: Reply: Error: %s", qUtf8Printable(reply.error().message())); qDebug("D-Bus: Reply: Error: %s", qUtf8Printable(reply.error().message()));
if (!m_use_gsm) if (!m_useGSM) {
{
qDebug("D-Bus: Falling back to org.gnome.SessionManager"); qDebug("D-Bus: Falling back to org.gnome.SessionManager");
m_use_gsm = true; m_useGSM = true;
m_state = idle; m_state = Idle;
if (m_intended_state == busy) if (m_intendedState == Busy)
RequestBusy(); requestBusy();
} }
else else {
{ m_state = Error;
m_state = error;
} }
} }
else else {
{ m_state = Busy;
m_state = busy;
m_cookie = reply.value(); m_cookie = reply.value();
qDebug("D-Bus: PowerManagementInhibitor: Request successful, cookie is %d", m_cookie); qDebug("D-Bus: PowerManagementInhibitor: Request successful, cookie is %d", m_cookie);
if (m_intended_state == idle) RequestIdle(); if (m_intendedState == Idle)
requestIdle();
} }
} }
else else {
{
qDebug("D-Bus: Unexpected reply in state %d", m_state); qDebug("D-Bus: Unexpected reply in state %d", m_state);
m_state = error; m_state = Error;
} }
call->deleteLater(); call->deleteLater();

View File

@ -1,5 +1,5 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2011 Vladimir Golovnev <glassez@yandex.ru> * Copyright (C) 2011 Vladimir Golovnev <glassez@yandex.ru>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -24,8 +24,6 @@
* modify file(s), you may extend this exception to your version of the file(s), * modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */
#ifndef POWERMANAGEMENTINHIBITOR_H #ifndef POWERMANAGEMENTINHIBITOR_H
@ -33,9 +31,7 @@
#include <QObject> #include <QObject>
QT_BEGIN_NAMESPACE
class QDBusPendingCallWatcher; class QDBusPendingCallWatcher;
QT_END_NAMESPACE
class PowerManagementInhibitor : public QObject class PowerManagementInhibitor : public QObject
{ {
@ -45,27 +41,27 @@ public:
PowerManagementInhibitor(QObject *parent = nullptr); PowerManagementInhibitor(QObject *parent = nullptr);
virtual ~PowerManagementInhibitor(); virtual ~PowerManagementInhibitor();
void RequestIdle(); void requestIdle();
void RequestBusy(); void requestBusy();
private slots: private slots:
void OnAsyncReply(QDBusPendingCallWatcher *call); void onAsyncReply(QDBusPendingCallWatcher *call);
private: private:
enum _state enum State
{ {
error, Error,
idle, Idle,
request_busy, RequestBusy,
busy, Busy,
request_idle RequestIdle
}; };
enum _state m_state; enum State m_state;
enum _state m_intended_state; enum State m_intendedState;
unsigned int m_cookie; unsigned int m_cookie;
bool m_use_gsm; bool m_useGSM;
}; };
#endif // POWERMANAGEMENTINHIBITOR_H #endif // POWERMANAGEMENTINHIBITOR_H

View File

@ -38,7 +38,7 @@ namespace RSS
class Item; class Item;
} }
class ArticleListWidget: public QListWidget class ArticleListWidget : public QListWidget
{ {
Q_OBJECT Q_OBJECT

View File

@ -50,8 +50,8 @@
#include "base/rss/rss_session.h" #include "base/rss/rss_session.h"
#include "base/utils/fs.h" #include "base/utils/fs.h"
#include "base/utils/string.h" #include "base/utils/string.h"
#include "guiiconprovider.h"
#include "autoexpandabledialog.h" #include "autoexpandabledialog.h"
#include "guiiconprovider.h"
#include "ui_automatedrssdownloader.h" #include "ui_automatedrssdownloader.h"
#include "utils.h" #include "utils.h"
@ -579,7 +579,7 @@ void AutomatedRssDownloader::updateMatchingArticles()
: RSS::AutoDownloader::instance()->ruleByName(ruleItem->text())); : RSS::AutoDownloader::instance()->ruleByName(ruleItem->text()));
foreach (const QString &feedURL, rule.feedURLs()) { foreach (const QString &feedURL, rule.feedURLs()) {
auto feed = RSS::Session::instance()->feedByURL(feedURL); auto feed = RSS::Session::instance()->feedByURL(feedURL);
if (!feed) continue; // feed doesn't exists if (!feed) continue; // feed doesn't exist
QStringList matchingArticles; QStringList matchingArticles;
foreach (auto article, feed->articles()) foreach (auto article, feed->articles())

View File

@ -51,7 +51,7 @@ namespace RSS
class Feed; class Feed;
} }
class AutomatedRssDownloader: public QDialog class AutomatedRssDownloader : public QDialog
{ {
Q_OBJECT Q_OBJECT

View File

@ -41,7 +41,7 @@ namespace RSS
class Item; class Item;
} }
class FeedListWidget: public QTreeWidget class FeedListWidget : public QTreeWidget
{ {
Q_OBJECT Q_OBJECT

View File

@ -308,7 +308,7 @@ void RSSWidget::loadFoldersOpenState()
const QStringList openedFolders = Preferences::instance()->getRssOpenFolders(); const QStringList openedFolders = Preferences::instance()->getRssOpenFolders();
foreach (const QString &varPath, openedFolders) { foreach (const QString &varPath, openedFolders) {
QTreeWidgetItem *parent = nullptr; QTreeWidgetItem *parent = nullptr;
foreach (const QString &name, varPath.split("\\")) { foreach (const QString &name, varPath.split('\\')) {
int nbChildren = (parent ? parent->childCount() : m_feedListWidget->topLevelItemCount()); int nbChildren = (parent ? parent->childCount() : m_feedListWidget->topLevelItemCount());
for (int i = 0; i < nbChildren; ++i) { for (int i = 0; i < nbChildren; ++i) {
QTreeWidgetItem *child = (parent ? parent->child(i) : m_feedListWidget->topLevelItem(i)); QTreeWidgetItem *child = (parent ? parent->child(i) : m_feedListWidget->topLevelItem(i));
@ -414,7 +414,7 @@ void RSSWidget::copySelectedFeedsURL()
if (auto feed = qobject_cast<RSS::Feed *>(m_feedListWidget->getRSSItem(item))) if (auto feed = qobject_cast<RSS::Feed *>(m_feedListWidget->getRSSItem(item)))
URLs << feed->url(); URLs << feed->url();
} }
qApp->clipboard()->setText(URLs.join("\n")); qApp->clipboard()->setText(URLs.join('\n'));
} }
void RSSWidget::handleCurrentFeedItemChanged(QTreeWidgetItem *currentItem) void RSSWidget::handleCurrentFeedItemChanged(QTreeWidgetItem *currentItem)

View File

@ -44,7 +44,7 @@ namespace Ui
class RSSWidget; class RSSWidget;
} }
class RSSWidget: public QWidget class RSSWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT

View File

@ -25,8 +25,6 @@
* modify file(s), you may extend this exception to your version of the file(s), * modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */
#include "pluginselectdlg.h" #include "pluginselectdlg.h"
@ -41,11 +39,11 @@
#include <QMimeData> #include <QMimeData>
#include <QTableView> #include <QTableView>
#include "autoexpandabledialog.h"
#include "base/net/downloadhandler.h" #include "base/net/downloadhandler.h"
#include "base/net/downloadmanager.h" #include "base/net/downloadmanager.h"
#include "base/utils/fs.h" #include "base/utils/fs.h"
#include "base/utils/misc.h" #include "base/utils/misc.h"
#include "autoexpandabledialog.h"
#include "guiiconprovider.h" #include "guiiconprovider.h"
#include "pluginsourcedlg.h" #include "pluginsourcedlg.h"
#include "searchwidget.h" #include "searchwidget.h"
@ -252,7 +250,7 @@ QList<QTreeWidgetItem*> PluginSelectDlg::findItemsWithUrl(QString url)
return res; return res;
} }
QTreeWidgetItem* PluginSelectDlg::findItemWithID(QString id) QTreeWidgetItem *PluginSelectDlg::findItemWithID(QString id)
{ {
for (int i = 0; i < m_ui->pluginsTree->topLevelItemCount(); ++i) { for (int i = 0; i < m_ui->pluginsTree->topLevelItemCount(); ++i) {
QTreeWidgetItem *item = m_ui->pluginsTree->topLevelItem(i); QTreeWidgetItem *item = m_ui->pluginsTree->topLevelItem(i);

View File

@ -25,8 +25,6 @@
* modify file(s), you may extend this exception to your version of the file(s), * modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */
#ifndef PLUGINSELECTDLG_H #ifndef PLUGINSELECTDLG_H
@ -45,7 +43,7 @@ namespace Ui
class PluginSelectDlg; class PluginSelectDlg;
} }
class PluginSelectDlg: public QDialog class PluginSelectDlg : public QDialog
{ {
Q_OBJECT Q_OBJECT
@ -54,7 +52,7 @@ public:
~PluginSelectDlg(); ~PluginSelectDlg();
QList<QTreeWidgetItem*> findItemsWithUrl(QString url); QList<QTreeWidgetItem*> findItemsWithUrl(QString url);
QTreeWidgetItem* findItemWithID(QString id); QTreeWidgetItem *findItemWithID(QString id);
protected: protected:
void dropEvent(QDropEvent *event); void dropEvent(QDropEvent *event);
@ -67,7 +65,7 @@ private slots:
void on_closeButton_clicked(); void on_closeButton_clicked();
void togglePluginState(QTreeWidgetItem*, int); void togglePluginState(QTreeWidgetItem*, int);
void setRowColor(int row, QString color); void setRowColor(int row, QString color);
void displayContextMenu(const QPoint& pos); void displayContextMenu(const QPoint &pos);
void enableSelection(bool enable); void enableSelection(bool enable);
void askForLocalPlugin(); void askForLocalPlugin();
void askForPluginUrl(); void askForPluginUrl();

View File

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2006 Christophe Dumez * Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -24,8 +24,6 @@
* modify file(s), you may extend this exception to your version of the file(s), * modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */
#include "pluginsourcedlg.h" #include "pluginsourcedlg.h"

View File

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2006 Christophe Dumez * Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -24,8 +24,6 @@
* modify file(s), you may extend this exception to your version of the file(s), * modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */
#ifndef PLUGINSOURCEDLG_H #ifndef PLUGINSOURCEDLG_H
@ -38,7 +36,7 @@ namespace Ui
class PluginSourceDlg; class PluginSourceDlg;
} }
class PluginSourceDlg: public QDialog class PluginSourceDlg : public QDialog
{ {
Q_OBJECT Q_OBJECT

View File

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2006 Christophe Dumez * Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -24,8 +24,6 @@
* modify file(s), you may extend this exception to your version of the file(s), * modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */
#ifndef SEARCHLISTDELEGATE_H #ifndef SEARCHLISTDELEGATE_H
@ -33,7 +31,7 @@
#include <QItemDelegate> #include <QItemDelegate>
class SearchListDelegate: public QItemDelegate class SearchListDelegate : public QItemDelegate
{ {
public: public:
explicit SearchListDelegate(QObject *parent); explicit SearchListDelegate(QObject *parent);
@ -42,4 +40,4 @@ public:
QWidget *createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const override; QWidget *createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const override;
}; };
#endif #endif // SEARCHLISTDELEGATE_H

View File

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2013 sledgehammer999 <hammered999@gmail.com> * Copyright (C) 2013 sledgehammer999 <sledgehammer999@qbittorrent.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -123,10 +123,10 @@ bool SearchSortModel::lessThan(const QModelIndex &left, const QModelIndex &right
bool SearchSortModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const bool SearchSortModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{ {
const QAbstractItemModel* const sourceModel = this->sourceModel(); const QAbstractItemModel *const sourceModel = this->sourceModel();
if (m_isNameFilterEnabled && !m_searchTerm.isEmpty()) { if (m_isNameFilterEnabled && !m_searchTerm.isEmpty()) {
QString name = sourceModel->data(sourceModel->index(sourceRow, NAME, sourceParent)).toString(); QString name = sourceModel->data(sourceModel->index(sourceRow, NAME, sourceParent)).toString();
for (const QString& word: m_searchTermWords) { for (const QString &word: m_searchTermWords) {
int i = name.indexOf(word, 0, Qt::CaseInsensitive); int i = name.indexOf(word, 0, Qt::CaseInsensitive);
if (i == -1) { if (i == -1) {
return false; return false;
@ -134,26 +134,26 @@ bool SearchSortModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceP
} }
} }
if (m_minSize > 0 || m_maxSize >= 0) { if ((m_minSize > 0) || (m_maxSize >= 0)) {
qlonglong size = sourceModel->data(sourceModel->index(sourceRow, SIZE, sourceParent)).toLongLong(); qlonglong size = sourceModel->data(sourceModel->index(sourceRow, SIZE, sourceParent)).toLongLong();
if ((m_minSize > 0 && size < m_minSize) if (((m_minSize > 0) && (size < m_minSize))
|| (m_maxSize > 0 && size > m_maxSize)) { || ((m_maxSize > 0) && (size > m_maxSize))) {
return false; return false;
} }
} }
if (m_minSeeds > 0 || m_maxSeeds >= 0) { if ((m_minSeeds > 0) || (m_maxSeeds >= 0)) {
int seeds = sourceModel->data(sourceModel->index(sourceRow, SEEDS, sourceParent)).toInt(); int seeds = sourceModel->data(sourceModel->index(sourceRow, SEEDS, sourceParent)).toInt();
if ((m_minSeeds > 0 && seeds < m_minSeeds) if (((m_minSeeds > 0) && (seeds < m_minSeeds))
|| (m_maxSeeds > 0 && seeds > m_maxSeeds)) { || ((m_maxSeeds > 0) && (seeds > m_maxSeeds))) {
return false; return false;
} }
} }
if (m_minLeeches > 0 || m_maxLeeches >= 0) { if ((m_minLeeches > 0) || (m_maxLeeches >= 0)) {
int leeches = sourceModel->data(sourceModel->index(sourceRow, LEECHES, sourceParent)).toInt(); int leeches = sourceModel->data(sourceModel->index(sourceRow, LEECHES, sourceParent)).toInt();
if ((m_minLeeches > 0 && leeches < m_minLeeches) if (((m_minLeeches > 0) && (leeches < m_minLeeches))
|| (m_maxLeeches > 0 && leeches > m_maxLeeches)) { || ((m_maxLeeches > 0) && (leeches > m_maxLeeches))) {
return false; return false;
} }
} }

View File

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2013 sledgehammer999 <hammered999@gmail.com> * Copyright (C) 2013 sledgehammer999 <sledgehammer999@qbittorrent.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -33,7 +33,7 @@
#include <QStringList> #include <QStringList>
#include "base/utils/string.h" #include "base/utils/string.h"
class SearchSortModel: public QSortFilterProxyModel class SearchSortModel : public QSortFilterProxyModel
{ {
using base = QSortFilterProxyModel; using base = QSortFilterProxyModel;
@ -53,7 +53,7 @@ public:
explicit SearchSortModel(QObject *parent = nullptr); explicit SearchSortModel(QObject *parent = nullptr);
void enableNameFilter(bool enabled); void enableNameFilter(bool enabled);
void setNameFilter(const QString& searchTerm = QString()); void setNameFilter(const QString &searchTerm = QString());
//! \brief Sets parameters for filtering by size //! \brief Sets parameters for filtering by size
//! \param minSize minimal size in bytes //! \param minSize minimal size in bytes

View File

@ -102,7 +102,7 @@ SearchTab::SearchTab(SearchHandler *searchHandler, QWidget *parent)
m_ui->resultsBrowser->setAllColumnsShowFocus(true); m_ui->resultsBrowser->setAllColumnsShowFocus(true);
m_ui->resultsBrowser->setSortingEnabled(true); m_ui->resultsBrowser->setSortingEnabled(true);
//Ensure that at least one column is visible at all times // Ensure that at least one column is visible at all times
bool atLeastOne = false; bool atLeastOne = false;
for (unsigned int i = 0; i < SearchSortModel::DL_LINK; i++) { for (unsigned int i = 0; i < SearchSortModel::DL_LINK; i++) {
if (!m_ui->resultsBrowser->isColumnHidden(i)) { if (!m_ui->resultsBrowser->isColumnHidden(i)) {
@ -112,9 +112,9 @@ SearchTab::SearchTab(SearchHandler *searchHandler, QWidget *parent)
} }
if (!atLeastOne) if (!atLeastOne)
m_ui->resultsBrowser->setColumnHidden(SearchSortModel::NAME, false); m_ui->resultsBrowser->setColumnHidden(SearchSortModel::NAME, false);
//To also mitigate the above issue, we have to resize each column when // To also mitigate the above issue, we have to resize each column when
//its size is 0, because explicitly 'showing' the column isn't enough // its size is 0, because explicitly 'showing' the column isn't enough
//in the above scenario. // in the above scenario.
for (unsigned int i = 0; i < SearchSortModel::DL_LINK; i++) for (unsigned int i = 0; i < SearchSortModel::DL_LINK; i++)
if ((m_ui->resultsBrowser->columnWidth(i) <= 0) && !m_ui->resultsBrowser->isColumnHidden(i)) if ((m_ui->resultsBrowser->columnWidth(i) <= 0) && !m_ui->resultsBrowser->isColumnHidden(i))
m_ui->resultsBrowser->resizeColumnToContents(i); m_ui->resultsBrowser->resizeColumnToContents(i);
@ -229,7 +229,7 @@ void SearchTab::copyTorrentURLs()
if (!urls.empty()) { if (!urls.empty()) {
QClipboard *clipboard = QApplication::clipboard(); QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(urls.join("\n")); clipboard->setText(urls.join('\n'));
} }
} }
@ -327,7 +327,7 @@ void SearchTab::fillFilterComboBoxes()
QVariant selectedMode = static_cast<int>(nameFilteringModeSetting().value()); QVariant selectedMode = static_cast<int>(nameFilteringModeSetting().value());
int index = m_ui->filterMode->findData(selectedMode); int index = m_ui->filterMode->findData(selectedMode);
m_ui->filterMode->setCurrentIndex(index == -1 ? 0 : index); m_ui->filterMode->setCurrentIndex((index == -1) ? 0 : index);
} }
QString SearchTab::statusText(SearchTab::Status st) QString SearchTab::statusText(SearchTab::Status st)

View File

@ -34,9 +34,9 @@
#define ENGINE_URL_COLUMN 4 #define ENGINE_URL_COLUMN 4
#define URL_COLUMN 5 #define URL_COLUMN 5
class QHeaderView;
class QLabel; class QLabel;
class QModelIndex; class QModelIndex;
class QHeaderView;
class QStandardItem; class QStandardItem;
class QStandardItemModel; class QStandardItemModel;
class QVBoxLayout; class QVBoxLayout;
@ -44,8 +44,8 @@ class QVBoxLayout;
template <typename T> class CachedSettingValue; template <typename T> class CachedSettingValue;
class SearchHandler; class SearchHandler;
class SearchSortModel;
class SearchListDelegate; class SearchListDelegate;
class SearchSortModel;
struct SearchResult; struct SearchResult;
namespace Ui namespace Ui
@ -110,7 +110,7 @@ private:
void setRowColor(int row, const QColor &color); void setRowColor(int row, const QColor &color);
static QString statusText(Status st); static QString statusText(Status st);
static CachedSettingValue<NameFilteringMode>& nameFilteringModeSetting(); static CachedSettingValue<NameFilteringMode> &nameFilteringModeSetting();
Ui::SearchTab *m_ui; Ui::SearchTab *m_ui;
SearchHandler *m_searchHandler; SearchHandler *m_searchHandler;

View File

@ -254,7 +254,7 @@ void SearchWidget::tabChanged(int index)
{ {
// when we switch from a tab that is not empty to another that is empty // when we switch from a tab that is not empty to another that is empty
// the download button doesn't have to be available // the download button doesn't have to be available
m_currentSearchTab = (index < 0 ? nullptr : m_allTabs.at(m_ui->tabWidget->currentIndex())); m_currentSearchTab = ((index < 0) ? nullptr : m_allTabs.at(m_ui->tabWidget->currentIndex()));
updateButtons(); updateButtons();
} }
@ -308,10 +308,14 @@ void SearchWidget::on_searchButton_clicked()
} }
QStringList plugins; QStringList plugins;
if (selectedPlugin() == "all") plugins = SearchPluginManager::instance()->allPlugins(); if (selectedPlugin() == "all")
else if (selectedPlugin() == "enabled") plugins = SearchPluginManager::instance()->enabledPlugins(); plugins = SearchPluginManager::instance()->allPlugins();
else if (selectedPlugin() == "multi") plugins = SearchPluginManager::instance()->enabledPlugins(); else if (selectedPlugin() == "enabled")
else plugins << selectedPlugin(); plugins = SearchPluginManager::instance()->enabledPlugins();
else if (selectedPlugin() == "multi")
plugins = SearchPluginManager::instance()->enabledPlugins();
else
plugins << selectedPlugin();
qDebug("Search with category: %s", qUtf8Printable(selectedCategory())); qDebug("Search with category: %s", qUtf8Printable(selectedCategory()));