Skip to content

Commit

Permalink
Follow project coding style. Issue qbittorrent#2192.
Browse files Browse the repository at this point in the history
--HG--
branch : magao-dev
  • Loading branch information
magao committed Feb 5, 2017
1 parent f78bf27 commit adee0ee
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 44 deletions.
25 changes: 16 additions & 9 deletions src/base/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@
#include "logger.h"
#include "preferences.h"

Preferences* Preferences::m_instance = 0;
Preferences *Preferences::m_instance = 0;

Preferences::Preferences() {}
Preferences::Preferences()
{
}

Preferences *Preferences::instance()
{
Expand Down Expand Up @@ -250,6 +252,7 @@ void Preferences::setWinStartup(bool b)
settings.remove("qBittorrent");
}
}

#endif

// Downloads
Expand Down Expand Up @@ -712,6 +715,7 @@ void Preferences::useSystemIconTheme(bool enabled)
{
setValue("Preferences/Advanced/useSystemIconTheme", enabled);
}

#endif

bool Preferences::recursiveDownloadDisabled() const
Expand All @@ -725,7 +729,8 @@ void Preferences::disableRecursiveDownload(bool disable)
}

#ifdef Q_OS_WIN
namespace {
namespace
{
enum REG_SEARCH_TYPE
{
USER,
Expand Down Expand Up @@ -814,7 +819,7 @@ namespace {
versions.sort();

bool found = false;
while(!found && !versions.empty()) {
while (!found && !versions.empty()) {
const QString version = versions.takeLast() + "\\InstallPath";
LPWSTR lpSubkey = new WCHAR[version.size() + 1];
version.toWCharArray(lpSubkey);
Expand Down Expand Up @@ -844,7 +849,6 @@ namespace {

return path;
}

}

QString Preferences::getPythonPath()
Expand Down Expand Up @@ -950,6 +954,7 @@ void Preferences::setMagnetLinkAssoc(bool set)

SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0);
}

#endif

#ifdef Q_OS_MAC
Expand Down Expand Up @@ -1006,6 +1011,7 @@ void Preferences::setMagnetLinkAssoc()
CFStringRef myBundleId = CFBundleGetIdentifier(CFBundleGetMainBundle());
LSSetDefaultHandlerForURLScheme(magnetUrlScheme, myBundleId);
}

#endif

int Preferences::getTrackerPort() const
Expand All @@ -1028,6 +1034,7 @@ void Preferences::setUpdateCheckEnabled(bool enabled)
{
setValue("Preferences/Advanced/updateCheck", enabled);
}

#endif

bool Preferences::confirmTorrentDeletion() const
Expand Down Expand Up @@ -1132,7 +1139,7 @@ void Preferences::setMainLastDir(const QString &path)
}

#ifndef DISABLE_GUI
QSize Preferences::getPrefSize(const QSize& defaultSize) const
QSize Preferences::getPrefSize(const QSize &defaultSize) const
{
return value("Preferences/State/size", defaultSize).toSize();
}
Expand All @@ -1141,6 +1148,7 @@ void Preferences::setPrefSize(const QSize &size)
{
setValue("Preferences/State/size", size);
}

#endif

QPoint Preferences::getPrefPos() const
Expand Down Expand Up @@ -1477,7 +1485,7 @@ void Preferences::setTransHeaderState(const QByteArray &state)
#endif
}

//From old RssSettings class
// From old RssSettings class
bool Preferences::isRSSEnabled() const
{
return value("Preferences/RSS/RSSEnabled", false).toBool();
Expand Down Expand Up @@ -1611,10 +1619,9 @@ void Preferences::upgrade()
QStringList labels = value("TransferListFilters/customLabels").toStringList();
if (!labels.isEmpty()) {
QVariantMap categories = value("BitTorrent/Session/Categories").toMap();
foreach (const QString &label, labels) {
foreach (const QString &label, labels)
if (!categories.contains(label))
categories[label] = "";
}
setValue("BitTorrent/Session/Categories", categories);
SettingsStorage::instance()->removeValue("TransferListFilters/customLabels");
}
Expand Down
6 changes: 3 additions & 3 deletions src/base/preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ class Preferences: public QObject
const QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const;
void setValue(const QString &key, const QVariant &value);

static Preferences* m_instance;
static Preferences *m_instance;

signals:
void changed();

public:
static void initInstance();
static void freeInstance();
static Preferences* instance();
static Preferences *instance();

// General options
QString getLocale() const;
Expand Down Expand Up @@ -332,7 +332,7 @@ class Preferences: public QObject
int getToolbarTextPosition() const;
void setToolbarTextPosition(const int position);

//From old RssSettings class
// From old RssSettings class
bool isRSSEnabled() const;
void setRSSEnabled(const bool enabled);
uint getRSSRefreshInterval() const;
Expand Down
6 changes: 4 additions & 2 deletions src/gui/guiiconprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ GuiIconProvider::GuiIconProvider(QObject *parent)
connect(Preferences::instance(), SIGNAL(changed()), SLOT(configure()));
}

GuiIconProvider::~GuiIconProvider() {}
GuiIconProvider::~GuiIconProvider()
{
}

void GuiIconProvider::initInstance()
{
Expand Down Expand Up @@ -117,6 +119,7 @@ QIcon GuiIconProvider::generateDifferentSizes(const QIcon &icon)

return newIcon;
}

#endif

QString GuiIconProvider::getIconPath(const QString &iconId)
Expand All @@ -138,7 +141,6 @@ QString GuiIconProvider::getIconPath(const QString &iconId)
return IconProvider::getIconPath(iconId);
}


void GuiIconProvider::configure()
{
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
Expand Down
2 changes: 1 addition & 1 deletion src/gui/guiiconprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

class QIcon;

class GuiIconProvider : public IconProvider
class GuiIconProvider: public IconProvider
{
Q_DISABLE_COPY(GuiIconProvider)
Q_OBJECT
Expand Down
2 changes: 1 addition & 1 deletion src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ void MainWindow::createKeyboardShortcuts()
m_ui->actionDocumentation->setShortcut(QKeySequence::HelpContents);
m_ui->actionOptions->setShortcut(Qt::ALT + Qt::Key_O);
m_ui->actionStart->setShortcut(Qt::CTRL + Qt::Key_S);
m_ui->actionStartAll->setShortcut(Qt::CTRL + Qt::SHIFT +Qt::Key_S);
m_ui->actionStartAll->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_S);
m_ui->actionPause->setShortcut(Qt::CTRL + Qt::Key_P);
m_ui->actionPauseAll->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_P);
m_ui->actionBottomPriority->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_Minus);
Expand Down
6 changes: 3 additions & 3 deletions src/gui/torrentmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace BitTorrent
class TorrentHandle;
}

class TorrentModel : public QAbstractListModel
class TorrentModel: public QAbstractListModel
{
Q_OBJECT
Q_DISABLE_COPY(TorrentModel)
Expand Down Expand Up @@ -84,8 +84,8 @@ class TorrentModel : public QAbstractListModel

explicit TorrentModel(QObject *parent = 0);

int rowCount(const QModelIndex& index = QModelIndex()) const;
int columnCount(const QModelIndex &parent=QModelIndex()) const;
int rowCount(const QModelIndex &index = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::DisplayRole);
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
Expand Down
53 changes: 28 additions & 25 deletions src/gui/transferlistfilterswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ FiltersBase::FiltersBase(QWidget *parent, TransferListWidget *transferList)
connect(this, SIGNAL(customContextMenuRequested(QPoint)), SLOT(showMenu(QPoint)));
connect(this, SIGNAL(currentRowChanged(int)), SLOT(applyFilter(int)));

connect(BitTorrent::Session::instance(), SIGNAL(torrentAdded(BitTorrent::TorrentHandle *const)), SLOT(handleNewTorrent(BitTorrent::TorrentHandle *const)));
connect(BitTorrent::Session::instance(), SIGNAL(torrentAboutToBeRemoved(BitTorrent::TorrentHandle *const)), SLOT(torrentAboutToBeDeleted(BitTorrent::TorrentHandle *const)));
connect(BitTorrent::Session::instance(), SIGNAL(torrentAdded(BitTorrent::TorrentHandle * const)), SLOT(handleNewTorrent(BitTorrent::TorrentHandle * const)));
connect(BitTorrent::Session::instance(), SIGNAL(torrentAboutToBeRemoved(BitTorrent::TorrentHandle * const)), SLOT(torrentAboutToBeDeleted(BitTorrent::TorrentHandle * const)));
}

QSize FiltersBase::sizeHint() const
Expand Down Expand Up @@ -142,7 +142,7 @@ StatusFiltersWidget::StatusFiltersWidget(QWidget *parent, TransferListWidget *tr
errored->setData(Qt::DisplayRole, QVariant(tr("Errored (0)")));
errored->setData(Qt::DecorationRole, QIcon(":/icons/skin/error.png"));

const Preferences* const pref = Preferences::instance();
const Preferences *const pref = Preferences::instance();
setCurrentRow(pref->getTransSelFilter(), QItemSelectionModel::SelectCurrent);
toggleFilter(pref->getStatusFilterState());
}
Expand All @@ -167,16 +167,22 @@ void StatusFiltersWidget::updateTorrentNumbers()
item(TorrentFilter::Errored)->setData(Qt::DisplayRole, QVariant(tr("Errored (%1)").arg(report.nbErrored)));
}

void StatusFiltersWidget::showMenu(QPoint) {}
void StatusFiltersWidget::showMenu(QPoint)
{
}

void StatusFiltersWidget::applyFilter(int row)
{
transferList->applyStatusFilter(row);
}

void StatusFiltersWidget::handleNewTorrent(BitTorrent::TorrentHandle *const) {}
void StatusFiltersWidget::handleNewTorrent(BitTorrent::TorrentHandle *const)
{
}

void StatusFiltersWidget::torrentAboutToBeDeleted(BitTorrent::TorrentHandle *const) {}
void StatusFiltersWidget::torrentAboutToBeDeleted(BitTorrent::TorrentHandle *const)
{
}

TrackerFiltersList::TrackerFiltersList(QWidget *parent, TransferListWidget *transferList)
: FiltersBase(parent, transferList)
Expand Down Expand Up @@ -219,12 +225,10 @@ void TrackerFiltersList::addItem(const QString &tracker, const QString &hash)
if (tmp.contains(hash))
return;

if (host != "") {
if (host != "")
trackerItem = item(rowFromTracker(host));
}
else {
else
trackerItem = item(1);
}
}
else {
trackerItem = new QListWidgetItem();
Expand Down Expand Up @@ -314,10 +318,9 @@ void TrackerFiltersList::setDownloadTrackerFavicon(bool value)
m_downloadTrackerFavicon = value;

if (m_downloadTrackerFavicon) {
foreach (const QString &tracker, m_trackers.keys()) {
foreach (const QString &tracker, m_trackers.keys())
if (!tracker.isEmpty())
downloadFavicon(QString("http://%1/favicon.ico").arg(tracker));
}
}
}

Expand Down Expand Up @@ -383,15 +386,15 @@ void TrackerFiltersList::trackerWarning(const QString &hash, const QString &trac
applyFilter(3);
}

void TrackerFiltersList::downloadFavicon(const QString& url)
void TrackerFiltersList::downloadFavicon(const QString &url)
{
if (!m_downloadTrackerFavicon) return;
Net::DownloadHandler *h = Net::DownloadManager::instance()->downloadUrl(url, true);
connect(h, SIGNAL(downloadFinished(QString, QString)), this, SLOT(handleFavicoDownload(QString, QString)));
connect(h, SIGNAL(downloadFailed(QString, QString)), this, SLOT(handleFavicoFailure(QString, QString)));
connect(h, SIGNAL(downloadFinished(QString,QString)), this, SLOT(handleFavicoDownload(QString,QString)));
connect(h, SIGNAL(downloadFailed(QString,QString)), this, SLOT(handleFavicoFailure(QString,QString)));
}

void TrackerFiltersList::handleFavicoDownload(const QString& url, const QString& filePath)
void TrackerFiltersList::handleFavicoDownload(const QString &url, const QString &filePath)
{
QString host = getHost(url);
if (!m_trackers.contains(host)) {
Expand All @@ -403,7 +406,7 @@ void TrackerFiltersList::handleFavicoDownload(const QString& url, const QString&
if (!trackerItem) return;

QIcon icon(filePath);
//Detect a non-decodable icon
// Detect a non-decodable icon
QList<QSize> sizes = icon.availableSizes();
bool invalid = (sizes.isEmpty() || icon.pixmap(sizes.first()).isNull());
if (invalid) {
Expand All @@ -417,7 +420,7 @@ void TrackerFiltersList::handleFavicoDownload(const QString& url, const QString&
}
}

void TrackerFiltersList::handleFavicoFailure(const QString& url, const QString& error)
void TrackerFiltersList::handleFavicoFailure(const QString &url, const QString &error)
{
Q_UNUSED(error)
if (url.endsWith(".ico", Qt::CaseInsensitive))
Expand Down Expand Up @@ -459,7 +462,7 @@ void TrackerFiltersList::handleNewTorrent(BitTorrent::TorrentHandle *const torre
foreach (const BitTorrent::TrackerEntry &tracker, trackers)
addItem(tracker.url(), hash);

//Check for trackerless torrent
// Check for trackerless torrent
if (trackers.size() == 0)
addItem("", hash);

Expand All @@ -473,7 +476,7 @@ void TrackerFiltersList::torrentAboutToBeDeleted(BitTorrent::TorrentHandle *cons
foreach (const BitTorrent::TrackerEntry &tracker, trackers)
removeItem(tracker.url(), hash);

//Check for trackerless torrent
// Check for trackerless torrent
if (trackers.size() == 0)
removeItem("", hash);

Expand Down Expand Up @@ -531,7 +534,7 @@ TransferListFiltersWidget::TransferListFiltersWidget(QWidget *parent, TransferLi
, m_transferList(transferList)
, m_trackerFilters(0)
{
Preferences* const pref = Preferences::instance();
Preferences *const pref = Preferences::instance();

// Construct lists
QVBoxLayout *vLayout = new QVBoxLayout(this);
Expand All @@ -557,7 +560,7 @@ TransferListFiltersWidget::TransferListFiltersWidget(QWidget *parent, TransferLi
vLayout->addWidget(scroll);
setLayout(vLayout);

QCheckBox * statusLabel = new QCheckBox(tr("Status"), this);
QCheckBox *statusLabel = new QCheckBox(tr("Status"), this);
statusLabel->setChecked(pref->getStatusFilterState());
statusLabel->setFont(font);
frameLayout->addWidget(statusLabel);
Expand Down Expand Up @@ -595,9 +598,9 @@ TransferListFiltersWidget::TransferListFiltersWidget(QWidget *parent, TransferLi
connect(statusLabel, SIGNAL(toggled(bool)), pref, SLOT(setStatusFilterState(const bool)));
connect(trackerLabel, SIGNAL(toggled(bool)), m_trackerFilters, SLOT(toggleFilter(bool)));
connect(trackerLabel, SIGNAL(toggled(bool)), pref, SLOT(setTrackerFilterState(const bool)));
connect(this, SIGNAL(trackerSuccess(const QString &, const QString &)), m_trackerFilters, SLOT(trackerSuccess(const QString &, const QString &)));
connect(this, SIGNAL(trackerError(const QString &, const QString &)), m_trackerFilters, SLOT(trackerError(const QString &, const QString &)));
connect(this, SIGNAL(trackerWarning(const QString &, const QString &)), m_trackerFilters, SLOT(trackerWarning(const QString &, const QString &)));
connect(this, SIGNAL(trackerSuccess(const QString&,const QString&)), m_trackerFilters, SLOT(trackerSuccess(const QString&,const QString&)));
connect(this, SIGNAL(trackerError(const QString&,const QString&)), m_trackerFilters, SLOT(trackerError(const QString&,const QString&)));
connect(this, SIGNAL(trackerWarning(const QString&,const QString&)), m_trackerFilters, SLOT(trackerWarning(const QString&,const QString&)));
}

void TransferListFiltersWidget::setDownloadTrackerFavicon(bool value)
Expand Down

0 comments on commit adee0ee

Please sign in to comment.