Fix coding style

This commit is contained in:
thalieht 2018-06-06 16:48:17 +03:00 committed by sledgehammer999
parent b107b745f2
commit ac6426eab1
No known key found for this signature in database
GPG key ID: 6E4A2D025B7CC9A2
79 changed files with 717 additions and 772 deletions

View file

@ -1,5 +1,5 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
*
* This program is free software; you can redistribute it and/or
@ -79,7 +79,7 @@ namespace
}
// Helper for setting style parameters when painting check box primitives.
class CheckBoxIconHelper: public QCheckBox
class CheckBoxIconHelper : public QCheckBox
{
public:
explicit CheckBoxIconHelper(QWidget *parent);
@ -108,7 +108,7 @@ namespace
}
// Tristate checkbox styled for use in menus.
class MenuCheckBox: public QWidget
class MenuCheckBox : public QWidget
{
public:
MenuCheckBox(const QString &text, const ToggleFn &onToggle, Qt::CheckState initialState);
@ -188,7 +188,7 @@ namespace
m_checkBox->click();
}
class CheckBoxMenuItem: public QWidgetAction
class CheckBoxMenuItem : public QWidgetAction
{
public:
CheckBoxMenuItem(const QString &text, const ToggleFn &onToggle, Qt::CheckState initialState, QObject *parent)
@ -206,7 +206,7 @@ TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *mainWindow)
setUniformRowHeights(true);
// Load settings
bool column_loaded = loadSettings();
bool columnLoaded = loadSettings();
// Create and apply delegate
m_listDelegate = new TransferListDelegate(this);
@ -238,7 +238,7 @@ TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *mainWindow)
header()->setStretchLastSection(false);
// Default hidden columns
if (!column_loaded) {
if (!columnLoaded) {
setColumnHidden(TorrentModel::TR_ADD_DATE, true);
setColumnHidden(TorrentModel::TR_SEED_DATE, true);
setColumnHidden(TorrentModel::TR_UPLIMIT, true);
@ -318,7 +318,7 @@ TransferListWidget::~TransferListWidget()
qDebug() << Q_FUNC_INFO << "EXIT";
}
TorrentModel* TransferListWidget::getSourceModel() const
TorrentModel *TransferListWidget::getSourceModel() const
{
return m_listModel;
}
@ -358,7 +358,7 @@ void TransferListWidget::torrentDoubleClicked()
else
action = Preferences::instance()->getActionOnDblClOnTorrentDl();
switch(action) {
switch (action) {
case TOGGLE_PAUSE:
if (torrent->isPaused())
torrent->resume();
@ -531,7 +531,7 @@ void TransferListWidget::copySelectedMagnetURIs() const
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents())
magnet_uris << torrent->toMagnetUri();
qApp->clipboard()->setText(magnet_uris.join("\n"));
qApp->clipboard()->setText(magnet_uris.join('\n'));
}
void TransferListWidget::copySelectedNames() const
@ -540,7 +540,7 @@ void TransferListWidget::copySelectedNames() const
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents())
torrent_names << torrent->name();
qApp->clipboard()->setText(torrent_names.join("\n"));
qApp->clipboard()->setText(torrent_names.join('\n'));
}
void TransferListWidget::copySelectedHashes() const
@ -703,8 +703,8 @@ void TransferListWidget::displayDLHoSMenu(const QPoint&)
hideshowColumn.setTitle(tr("Column visibility"));
QList<QAction*> actions;
for (int i = 0; i < m_listModel->columnCount(); ++i) {
if (!BitTorrent::Session::instance()->isQueueingSystemEnabled() && i == TorrentModel::TR_PRIORITY) {
actions.append(0);
if (!BitTorrent::Session::instance()->isQueueingSystemEnabled() && (i == TorrentModel::TR_PRIORITY)) {
actions.append(nullptr);
continue;
}
QAction *myAct = hideshowColumn.addAction(m_listModel->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString());
@ -872,16 +872,16 @@ void TransferListWidget::displayListMenu(const QPoint&)
connect(&actionForceStart, &QAction::triggered, this, &TransferListWidget::forceStartSelectedTorrents);
QAction actionDelete(GuiIconProvider::instance()->getIcon("edit-delete"), tr("Delete", "Delete the torrent"), nullptr);
connect(&actionDelete, &QAction::triggered, this, &TransferListWidget::softDeleteSelectedTorrents);
QAction actionPreview_file(GuiIconProvider::instance()->getIcon("view-preview"), tr("Preview file..."), nullptr);
connect(&actionPreview_file, &QAction::triggered, this, &TransferListWidget::previewSelectedTorrents);
QAction actionSet_max_ratio(QIcon(QLatin1String(":/icons/skin/ratio.png")), tr("Limit share ratio..."), nullptr);
connect(&actionSet_max_ratio, &QAction::triggered, this, &TransferListWidget::setMaxRatioSelectedTorrents);
QAction actionSet_upload_limit(GuiIconProvider::instance()->getIcon("kt-set-max-upload-speed"), tr("Limit upload rate..."), nullptr);
connect(&actionSet_upload_limit, &QAction::triggered, this, &TransferListWidget::setUpLimitSelectedTorrents);
QAction actionSet_download_limit(GuiIconProvider::instance()->getIcon("kt-set-max-download-speed"), tr("Limit download rate..."), nullptr);
connect(&actionSet_download_limit, &QAction::triggered, this, &TransferListWidget::setDlLimitSelectedTorrents);
QAction actionOpen_destination_folder(GuiIconProvider::instance()->getIcon("inode-directory"), tr("Open destination folder"), nullptr);
connect(&actionOpen_destination_folder, &QAction::triggered, this, &TransferListWidget::openSelectedTorrentsFolder);
QAction actionPreviewFile(GuiIconProvider::instance()->getIcon("view-preview"), tr("Preview file..."), nullptr);
connect(&actionPreviewFile, &QAction::triggered, this, &TransferListWidget::previewSelectedTorrents);
QAction actionSetMaxRatio(QIcon(QLatin1String(":/icons/skin/ratio.png")), tr("Limit share ratio..."), nullptr);
connect(&actionSetMaxRatio, &QAction::triggered, this, &TransferListWidget::setMaxRatioSelectedTorrents);
QAction actionSetUploadLimit(GuiIconProvider::instance()->getIcon("kt-set-max-upload-speed"), tr("Limit upload rate..."), nullptr);
connect(&actionSetUploadLimit, &QAction::triggered, this, &TransferListWidget::setUpLimitSelectedTorrents);
QAction actionSetDownloadLimit(GuiIconProvider::instance()->getIcon("kt-set-max-download-speed"), tr("Limit download rate..."), nullptr);
connect(&actionSetDownloadLimit, &QAction::triggered, this, &TransferListWidget::setDlLimitSelectedTorrents);
QAction actionOpenDestinationFolder(GuiIconProvider::instance()->getIcon("inode-directory"), tr("Open destination folder"), nullptr);
connect(&actionOpenDestinationFolder, &QAction::triggered, this, &TransferListWidget::openSelectedTorrentsFolder);
QAction actionIncreasePriority(GuiIconProvider::instance()->getIcon("go-up"), tr("Move up", "i.e. move up in the queue"), nullptr);
connect(&actionIncreasePriority, &QAction::triggered, this, &TransferListWidget::increasePrioSelectedTorrents);
QAction actionDecreasePriority(GuiIconProvider::instance()->getIcon("go-down"), tr("Move down", "i.e. Move down in the queue"), nullptr);
@ -892,27 +892,27 @@ void TransferListWidget::displayListMenu(const QPoint&)
connect(&actionBottomPriority, &QAction::triggered, this, &TransferListWidget::bottomPrioSelectedTorrents);
QAction actionSetTorrentPath(GuiIconProvider::instance()->getIcon("inode-directory"), tr("Set location..."), nullptr);
connect(&actionSetTorrentPath, &QAction::triggered, this, &TransferListWidget::setSelectedTorrentsLocation);
QAction actionForce_recheck(GuiIconProvider::instance()->getIcon("document-edit-verify"), tr("Force recheck"), nullptr);
connect(&actionForce_recheck, &QAction::triggered, this, &TransferListWidget::recheckSelectedTorrents);
QAction actionForce_reannounce(GuiIconProvider::instance()->getIcon("document-edit-verify"), tr("Force reannounce"), nullptr);
connect(&actionForce_reannounce, &QAction::triggered, this, &TransferListWidget::reannounceSelectedTorrents);
QAction actionCopy_magnet_link(GuiIconProvider::instance()->getIcon("kt-magnet"), tr("Copy magnet link"), nullptr);
connect(&actionCopy_magnet_link, &QAction::triggered, this, &TransferListWidget::copySelectedMagnetURIs);
QAction actionCopy_name(GuiIconProvider::instance()->getIcon("edit-copy"), tr("Copy name"), nullptr);
connect(&actionCopy_name, &QAction::triggered, this, &TransferListWidget::copySelectedNames);
QAction actionForceRecheck(GuiIconProvider::instance()->getIcon("document-edit-verify"), tr("Force recheck"), nullptr);
connect(&actionForceRecheck, &QAction::triggered, this, &TransferListWidget::recheckSelectedTorrents);
QAction actionForceReannounce(GuiIconProvider::instance()->getIcon("document-edit-verify"), tr("Force reannounce"), nullptr);
connect(&actionForceReannounce, &QAction::triggered, this, &TransferListWidget::reannounceSelectedTorrents);
QAction actionCopyMagnetLink(GuiIconProvider::instance()->getIcon("kt-magnet"), tr("Copy magnet link"), nullptr);
connect(&actionCopyMagnetLink, &QAction::triggered, this, &TransferListWidget::copySelectedMagnetURIs);
QAction actionCopyName(GuiIconProvider::instance()->getIcon("edit-copy"), tr("Copy name"), nullptr);
connect(&actionCopyName, &QAction::triggered, this, &TransferListWidget::copySelectedNames);
QAction actionCopyHash(GuiIconProvider::instance()->getIcon("edit-copy"), tr("Copy hash"), nullptr);
connect(&actionCopyHash, &QAction::triggered, this, &TransferListWidget::copySelectedHashes);
QAction actionSuper_seeding_mode(tr("Super seeding mode"), nullptr);
actionSuper_seeding_mode.setCheckable(true);
connect(&actionSuper_seeding_mode, &QAction::triggered, this, &TransferListWidget::toggleSelectedTorrentsSuperSeeding);
QAction actionSuperSeedingMode(tr("Super seeding mode"), nullptr);
actionSuperSeedingMode.setCheckable(true);
connect(&actionSuperSeedingMode, &QAction::triggered, this, &TransferListWidget::toggleSelectedTorrentsSuperSeeding);
QAction actionRename(GuiIconProvider::instance()->getIcon("edit-rename"), tr("Rename..."), nullptr);
connect(&actionRename, &QAction::triggered, this, &TransferListWidget::renameSelectedTorrent);
QAction actionSequential_download(tr("Download in sequential order"), nullptr);
actionSequential_download.setCheckable(true);
connect(&actionSequential_download, &QAction::triggered, this, &TransferListWidget::toggleSelectedTorrentsSequentialDownload);
QAction actionFirstLastPiece_prio(tr("Download first and last pieces first"), nullptr);
actionFirstLastPiece_prio.setCheckable(true);
connect(&actionFirstLastPiece_prio, &QAction::triggered, this, &TransferListWidget::toggleSelectedFirstLastPiecePrio);
QAction actionSequentialDownload(tr("Download in sequential order"), nullptr);
actionSequentialDownload.setCheckable(true);
connect(&actionSequentialDownload, &QAction::triggered, this, &TransferListWidget::toggleSelectedTorrentsSequentialDownload);
QAction actionFirstLastPiecePrio(tr("Download first and last pieces first"), nullptr);
actionFirstLastPiecePrio.setCheckable(true);
connect(&actionFirstLastPiecePrio, &QAction::triggered, this, &TransferListWidget::toggleSelectedFirstLastPiecePrio);
QAction actionAutoTMM(tr("Automatic Torrent Management"), nullptr);
actionAutoTMM.setCheckable(true);
actionAutoTMM.setToolTip(tr("Automatic mode means that various torrent properties(eg save path) will be decided by the associated category"));
@ -920,12 +920,12 @@ void TransferListWidget::displayListMenu(const QPoint&)
// End of actions
// Enable/disable pause/start action given the DL state
bool needs_pause = false, needs_start = false, needs_force = false, needs_preview = false;
bool all_same_super_seeding = true;
bool super_seeding_mode = false;
bool all_same_sequential_download_mode = true, all_same_prio_firstlast = true;
bool sequential_download_mode = false, prioritize_first_last = false;
bool one_has_metadata = false, one_not_seed = false;
bool needsPause = false, needsStart = false, needsForce = false, needsPreview = false;
bool allSameSuperSeeding = true;
bool superSeedingMode = false;
bool allSameSequentialDownloadMode = true, allSamePrioFirstlast = true;
bool sequentialDownloadMode = false, prioritizeFirstLast = false;
bool oneHasMetadata = false, oneNotSeed = false;
bool allSameCategory = true;
bool allSameAutoTMM = true;
bool firstAutoTMM = false;
@ -960,57 +960,57 @@ void TransferListWidget::displayListMenu(const QPoint&)
allSameAutoTMM = false;
if (torrent->hasMetadata())
one_has_metadata = true;
oneHasMetadata = true;
if (!torrent->isSeed()) {
one_not_seed = true;
oneNotSeed = true;
if (torrent->hasMetadata()) {
if (first) {
sequential_download_mode = torrent->isSequentialDownload();
prioritize_first_last = torrent->hasFirstLastPiecePriority();
sequentialDownloadMode = torrent->isSequentialDownload();
prioritizeFirstLast = torrent->hasFirstLastPiecePriority();
}
else {
if (sequential_download_mode != torrent->isSequentialDownload())
all_same_sequential_download_mode = false;
if (prioritize_first_last != torrent->hasFirstLastPiecePriority())
all_same_prio_firstlast = false;
if (sequentialDownloadMode != torrent->isSequentialDownload())
allSameSequentialDownloadMode = false;
if (prioritizeFirstLast != torrent->hasFirstLastPiecePriority())
allSamePrioFirstlast = false;
}
}
}
else {
if (!one_not_seed && all_same_super_seeding && torrent->hasMetadata()) {
if (!oneNotSeed && allSameSuperSeeding && torrent->hasMetadata()) {
if (first) {
super_seeding_mode = torrent->superSeeding();
superSeedingMode = torrent->superSeeding();
}
else if (super_seeding_mode != torrent->superSeeding())
all_same_super_seeding = false;
else if (superSeedingMode != torrent->superSeeding())
allSameSuperSeeding = false;
}
}
if (!torrent->isForced())
needs_force = true;
needsForce = true;
else
needs_start = true;
needsStart = true;
if (torrent->isPaused())
needs_start = true;
needsStart = true;
else
needs_pause = true;
needsPause = true;
if (torrent->hasMetadata())
needs_preview = true;
needsPreview = true;
first = false;
if (one_has_metadata && one_not_seed && !all_same_sequential_download_mode
&& !all_same_prio_firstlast && !all_same_super_seeding && !allSameCategory
&& needs_start && needs_force && needs_pause && needs_preview && !allSameAutoTMM) {
if (oneHasMetadata && oneNotSeed && !allSameSequentialDownloadMode
&& !allSamePrioFirstlast && !allSameSuperSeeding && !allSameCategory
&& needsStart && needsForce && needsPause && needsPreview && !allSameAutoTMM) {
break;
}
}
QMenu listMenu(this);
if (needs_start)
if (needsStart)
listMenu.addAction(&actionStart);
if (needs_pause)
if (needsPause)
listMenu.addAction(&actionPause);
if (needs_force)
if (needsForce)
listMenu.addAction(&actionForceStart);
listMenu.addSeparator();
listMenu.addAction(&actionDelete);
@ -1068,42 +1068,42 @@ void TransferListWidget::displayListMenu(const QPoint&)
}
listMenu.addSeparator();
if (one_not_seed)
listMenu.addAction(&actionSet_download_limit);
listMenu.addAction(&actionSet_upload_limit);
listMenu.addAction(&actionSet_max_ratio);
if (!one_not_seed && all_same_super_seeding && one_has_metadata) {
actionSuper_seeding_mode.setChecked(super_seeding_mode);
listMenu.addAction(&actionSuper_seeding_mode);
if (oneNotSeed)
listMenu.addAction(&actionSetDownloadLimit);
listMenu.addAction(&actionSetUploadLimit);
listMenu.addAction(&actionSetMaxRatio);
if (!oneNotSeed && allSameSuperSeeding && oneHasMetadata) {
actionSuperSeedingMode.setChecked(superSeedingMode);
listMenu.addAction(&actionSuperSeedingMode);
}
listMenu.addSeparator();
bool added_preview_action = false;
if (needs_preview) {
listMenu.addAction(&actionPreview_file);
added_preview_action = true;
bool addedPreviewAction = false;
if (needsPreview) {
listMenu.addAction(&actionPreviewFile);
addedPreviewAction = true;
}
if (one_not_seed && one_has_metadata) {
if (all_same_sequential_download_mode) {
actionSequential_download.setChecked(sequential_download_mode);
listMenu.addAction(&actionSequential_download);
added_preview_action = true;
if (oneNotSeed && oneHasMetadata) {
if (allSameSequentialDownloadMode) {
actionSequentialDownload.setChecked(sequentialDownloadMode);
listMenu.addAction(&actionSequentialDownload);
addedPreviewAction = true;
}
if (all_same_prio_firstlast) {
actionFirstLastPiece_prio.setChecked(prioritize_first_last);
listMenu.addAction(&actionFirstLastPiece_prio);
added_preview_action = true;
if (allSamePrioFirstlast) {
actionFirstLastPiecePrio.setChecked(prioritizeFirstLast);
listMenu.addAction(&actionFirstLastPiecePrio);
addedPreviewAction = true;
}
}
if (added_preview_action)
if (addedPreviewAction)
listMenu.addSeparator();
if (one_has_metadata) {
listMenu.addAction(&actionForce_recheck);
listMenu.addAction(&actionForce_reannounce);
if (oneHasMetadata) {
listMenu.addAction(&actionForceRecheck);
listMenu.addAction(&actionForceReannounce);
listMenu.addSeparator();
}
listMenu.addAction(&actionOpen_destination_folder);
if (BitTorrent::Session::instance()->isQueueingSystemEnabled() && one_not_seed) {
listMenu.addAction(&actionOpenDestinationFolder);
if (BitTorrent::Session::instance()->isQueueingSystemEnabled() && oneNotSeed) {
listMenu.addSeparator();
QMenu *prioMenu = listMenu.addMenu(tr("Priority"));
prioMenu->addAction(&actionTopPriority);
@ -1112,9 +1112,9 @@ void TransferListWidget::displayListMenu(const QPoint&)
prioMenu->addAction(&actionBottomPriority);
}
listMenu.addSeparator();
listMenu.addAction(&actionCopy_name);
listMenu.addAction(&actionCopyName);
listMenu.addAction(&actionCopyHash);
listMenu.addAction(&actionCopy_magnet_link);
listMenu.addAction(&actionCopyMagnetLink);
// Call menu
QAction *act = nullptr;
act = listMenu.exec(QCursor::pos());
@ -1186,7 +1186,7 @@ void TransferListWidget::applyTrackerFilter(const QStringList &hashes)
m_sortFilterModel->setTrackerFilter(hashes);
}
void TransferListWidget::applyNameFilter(const QString& name)
void TransferListWidget::applyNameFilter(const QString &name)
{
m_sortFilterModel->setFilterRegExp(QRegExp(name, Qt::CaseInsensitive, QRegExp::WildcardUnix));
}
@ -1195,7 +1195,7 @@ void TransferListWidget::applyStatusFilter(int f)
{
m_sortFilterModel->setStatusFilter(static_cast<TorrentFilter::Type>(f));
// Select first item if nothing is selected
if (selectionModel()->selectedRows(0).empty() && m_sortFilterModel->rowCount() > 0) {
if (selectionModel()->selectedRows(0).empty() && (m_sortFilterModel->rowCount() > 0)) {
qDebug("Nothing is selected, selecting first row: %s", qUtf8Printable(m_sortFilterModel->index(0, TorrentModel::TR_NAME).data().toString()));
selectionModel()->setCurrentIndex(m_sortFilterModel->index(0, TorrentModel::TR_NAME), QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
}