Browse Source

Fix coding style

adaptive-webui-19844
thalieht 7 years ago
parent
commit
4022799881
  1. 14
      src/app/main.cpp
  2. 3
      src/base/bittorrent/private/resumedatasavingmanager.cpp
  3. 2
      src/base/bittorrent/torrenthandle.cpp
  4. 2
      src/base/scanfoldersmodel.cpp
  5. 15
      src/gui/about_imp.h
  6. 8
      src/gui/addnewtorrentdialog.cpp
  7. 18
      src/gui/advancedsettings.cpp
  8. 2
      src/gui/advancedsettings.h
  9. 4
      src/gui/autoexpandabledialog.h
  10. 2
      src/gui/categoryfiltermodel.cpp
  11. 2
      src/gui/categoryfiltermodel.h
  12. 2
      src/gui/categoryfilterproxymodel.h
  13. 2
      src/gui/categoryfilterwidget.h
  14. 85
      src/gui/deletionconfirmationdlg.h
  15. 2
      src/gui/downloadfromurldialog.h
  16. 38
      src/gui/executionlog.cpp
  17. 16
      src/gui/executionlog.h
  18. 8
      src/gui/fspathedit.h
  19. 6
      src/gui/fspathedit_p.h
  20. 8
      src/gui/hidabletabwidget.h
  21. 4
      src/gui/loglistwidget.cpp
  22. 13
      src/gui/loglistwidget.h
  23. 36
      src/gui/mainwindow.cpp
  24. 10
      src/gui/mainwindow.h
  25. 48
      src/gui/messageboxraised.cpp
  26. 29
      src/gui/messageboxraised.h
  27. 39
      src/gui/optionsdlg.cpp
  28. 12
      src/gui/optionsdlg.h
  29. 5
      src/gui/previewlistdelegate.h
  30. 2
      src/gui/programupdater.cpp
  31. 8
      src/gui/programupdater.h
  32. 2
      src/gui/properties/downloadedpiecesbar.cpp
  33. 2
      src/gui/properties/peerlistsortmodel.h
  34. 10
      src/gui/properties/peerlistwidget.cpp
  35. 10
      src/gui/properties/peersadditiondlg.cpp
  36. 2
      src/gui/properties/pieceavailabilitybar.cpp
  37. 2
      src/gui/properties/piecesbar.cpp
  38. 16
      src/gui/properties/propertieswidget.cpp
  39. 4
      src/gui/properties/speedplotview.cpp
  40. 2
      src/gui/properties/speedwidget.h
  41. 2
      src/gui/properties/trackerlist.cpp
  42. 10
      src/gui/properties/trackersadditiondlg.cpp
  43. 18
      src/gui/scanfoldersdelegate.cpp
  44. 19
      src/gui/scanfoldersdelegate.h
  45. 4
      src/gui/shutdownconfirmdlg.cpp
  46. 20
      src/gui/speedlimitdlg.cpp
  47. 4
      src/gui/speedlimitdlg.h
  48. 2
      src/gui/statsdialog.h
  49. 2
      src/gui/statusbar.h
  50. 4
      src/gui/tagfiltermodel.cpp
  51. 2
      src/gui/tagfiltermodel.h
  52. 2
      src/gui/tagfilterproxymodel.h
  53. 2
      src/gui/tagfilterwidget.h
  54. 8
      src/gui/torrentcontentfiltermodel.h
  55. 65
      src/gui/torrentcontentmodel.cpp
  56. 24
      src/gui/torrentcontentmodel.h
  57. 6
      src/gui/torrentcontentmodelfile.cpp
  58. 8
      src/gui/torrentcontentmodelfile.h
  59. 8
      src/gui/torrentcontentmodelfolder.cpp
  60. 20
      src/gui/torrentcontentmodelfolder.h
  61. 13
      src/gui/torrentcontentmodelitem.cpp
  62. 6
      src/gui/torrentcontentmodelitem.h
  63. 4
      src/gui/torrentcontenttreeview.h
  64. 4
      src/gui/torrentcreatordlg.h
  65. 9
      src/gui/torrentmodel.cpp
  66. 14
      src/gui/torrentmodel.h
  67. 6
      src/gui/trackerlogin.cpp
  68. 8
      src/gui/trackerlogin.h
  69. 195
      src/gui/transferlistdelegate.cpp
  70. 18
      src/gui/transferlistdelegate.h
  71. 22
      src/gui/transferlistfilterswidget.cpp
  72. 41
      src/gui/transferlistfilterswidget.h
  73. 180
      src/gui/transferlistsortmodel.cpp
  74. 12
      src/gui/transferlistsortmodel.h
  75. 196
      src/gui/transferlistwidget.cpp
  76. 22
      src/gui/transferlistwidget.h
  77. 2
      src/gui/updownratiodlg.h
  78. 2
      src/gui/utils.cpp
  79. 2
      src/webui/api/torrentscontroller.cpp

14
src/app/main.cpp

@ -234,7 +234,7 @@ int main(int argc, char *argv[])
#ifdef DISABLE_GUI #ifdef DISABLE_GUI
if (params.shouldDaemonize) { if (params.shouldDaemonize) {
app.reset(); // Destroy current application app.reset(); // Destroy current application
if ((daemon(1, 0) == 0)) { if (daemon(1, 0) == 0) {
app.reset(new Application(appId, argc, argv)); app.reset(new Application(appId, argc, argv));
if (app->isRunning()) { if (app->isRunning()) {
// Another instance had time to start. // Another instance had time to start.
@ -319,13 +319,13 @@ void sigAbnormalHandler(int signum)
#if !defined(DISABLE_GUI) #if !defined(DISABLE_GUI)
void showSplashScreen() void showSplashScreen()
{ {
QPixmap splash_img(":/icons/skin/splash.png"); QPixmap splashImg(":/icons/skin/splash.png");
QPainter painter(&splash_img); QPainter painter(&splashImg);
QString version = QBT_VERSION; QString version = QBT_VERSION;
painter.setPen(QPen(Qt::white)); painter.setPen(QPen(Qt::white));
painter.setFont(QFont("Arial", 22, QFont::Black)); painter.setFont(QFont("Arial", 22, QFont::Black));
painter.drawText(224 - painter.fontMetrics().width(version), 270, version); painter.drawText(224 - painter.fontMetrics().width(version), 270, version);
QSplashScreen *splash = new QSplashScreen(splash_img); QSplashScreen *splash = new QSplashScreen(splashImg);
splash->show(); splash->show();
QTimer::singleShot(1500, splash, &QObject::deleteLater); QTimer::singleShot(1500, splash, &QObject::deleteLater);
qApp->processEvents(); qApp->processEvents();
@ -376,7 +376,7 @@ bool userAgreesWithLegalNotice()
printf("%s", qUtf8Printable(eula)); printf("%s", qUtf8Printable(eula));
char ret = getchar(); // Read pressed key char ret = getchar(); // Read pressed key
if (ret == 'y' || ret == 'Y') { if ((ret == 'y') || (ret == 'Y')) {
// Save the answer // Save the answer
pref->setAcceptedLegal(true); pref->setAcceptedLegal(true);
return true; return true;
@ -386,11 +386,11 @@ bool userAgreesWithLegalNotice()
msgBox.setText(QObject::tr("qBittorrent is a file sharing program. When you run a torrent, its data will be made available to others by means of upload. Any content you share is your sole responsibility.\n\nNo further notices will be issued.")); msgBox.setText(QObject::tr("qBittorrent is a file sharing program. When you run a torrent, its data will be made available to others by means of upload. Any content you share is your sole responsibility.\n\nNo further notices will be issued."));
msgBox.setWindowTitle(QObject::tr("Legal notice")); msgBox.setWindowTitle(QObject::tr("Legal notice"));
msgBox.addButton(QObject::tr("Cancel"), QMessageBox::RejectRole); msgBox.addButton(QObject::tr("Cancel"), QMessageBox::RejectRole);
QAbstractButton *agree_button = msgBox.addButton(QObject::tr("I Agree"), QMessageBox::AcceptRole); QAbstractButton *agreeButton = msgBox.addButton(QObject::tr("I Agree"), QMessageBox::AcceptRole);
msgBox.show(); // Need to be shown or to moveToCenter does not work msgBox.show(); // Need to be shown or to moveToCenter does not work
msgBox.move(Utils::Misc::screenCenter(&msgBox)); msgBox.move(Utils::Misc::screenCenter(&msgBox));
msgBox.exec(); msgBox.exec();
if (msgBox.clickedButton() == agree_button) { if (msgBox.clickedButton() == agreeButton) {
// Save the answer // Save the answer
pref->setAcceptedLegal(true); pref->setAcceptedLegal(true);
return true; return true;

3
src/base/bittorrent/private/resumedatasavingmanager.cpp

@ -26,12 +26,13 @@
* exception statement from your version. * exception statement from your version.
*/ */
#include "resumedatasavingmanager.h"
#include <QDebug> #include <QDebug>
#include <QSaveFile> #include <QSaveFile>
#include "base/logger.h" #include "base/logger.h"
#include "base/utils/fs.h" #include "base/utils/fs.h"
#include "resumedatasavingmanager.h"
ResumeDataSavingManager::ResumeDataSavingManager(const QString &resumeFolderPath) ResumeDataSavingManager::ResumeDataSavingManager(const QString &resumeFolderPath)
: m_resumeDataDir(resumeFolderPath) : m_resumeDataDir(resumeFolderPath)

2
src/base/bittorrent/torrenthandle.cpp

@ -1831,7 +1831,7 @@ void TorrentHandle::manageIncompleteFiles()
{ {
const bool isAppendExtensionEnabled = m_session->isAppendExtensionEnabled(); const bool isAppendExtensionEnabled = m_session->isAppendExtensionEnabled();
QVector<qreal> fp = filesProgress(); QVector<qreal> fp = filesProgress();
if( fp.size() != filesCount() ) { if (fp.size() != filesCount()) {
qDebug() << "skip manageIncompleteFiles because of invalid torrent meta-data or empty file-progress"; qDebug() << "skip manageIncompleteFiles because of invalid torrent meta-data or empty file-progress";
return; return;
} }

2
src/base/scanfoldersmodel.cpp

@ -388,7 +388,7 @@ void ScanFoldersModel::addTorrentsToSession(const QStringList &pathList)
QString ScanFoldersModel::pathTypeDisplayName(const PathType type) QString ScanFoldersModel::pathTypeDisplayName(const PathType type)
{ {
switch(type) { switch (type) {
case DOWNLOAD_IN_WATCH_FOLDER: case DOWNLOAD_IN_WATCH_FOLDER:
return tr("Monitored folder"); return tr("Monitored folder");
case DEFAULT_LOCATION: case DEFAULT_LOCATION:

15
src/gui/about_imp.h

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 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 ABOUT_H #ifndef ABOUT_H
@ -33,17 +31,18 @@
#include <QFile> #include <QFile>
#include "base/utils/misc.h"
#include "base/unicodestrings.h" #include "base/unicodestrings.h"
#include "base/utils/misc.h"
#include "ui_about.h" #include "ui_about.h"
#include "utils.h" #include "utils.h"
class about: public QDialog, private Ui::AboutDlg class AboutDialog : public QDialog, private Ui::AboutDlg
{ {
Q_OBJECT Q_OBJECT
public: public:
about(QWidget *parent) : QDialog(parent) AboutDialog(QWidget *parent)
: QDialog(parent)
{ {
setupUi(this); setupUi(this);
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
@ -108,4 +107,4 @@ public:
} }
}; };
#endif #endif // ABOUT_H

8
src/gui/addnewtorrentdialog.cpp

@ -536,15 +536,15 @@ void AddNewTorrentDialog::renameSelectedFile()
pathItems.prepend(parent.data().toString()); pathItems.prepend(parent.data().toString());
parent = m_contentModel->parent(parent); parent = m_contentModel->parent(parent);
} }
const QString oldPath = pathItems.join("/"); const QString oldPath = pathItems.join('/');
pathItems.removeLast(); pathItems.removeLast();
pathItems << newName; pathItems << newName;
QString newPath = pathItems.join("/"); QString newPath = pathItems.join('/');
if (Utils::Fs::sameFileNames(oldPath, newPath)) { if (Utils::Fs::sameFileNames(oldPath, newPath)) {
qDebug("Name did not change"); qDebug("Name did not change");
return; return;
} }
if (!newPath.endsWith("/")) newPath += "/"; if (!newPath.endsWith('/')) newPath += '/';
// Check for overwriting // Check for overwriting
for (int i = 0; i < m_torrentInfo.filesCount(); ++i) { for (int i = 0; i < m_torrentInfo.filesCount(); ++i) {
const QString &currentName = m_torrentInfo.filePath(i); const QString &currentName = m_torrentInfo.filePath(i);
@ -813,7 +813,7 @@ void AddNewTorrentDialog::setCommentText(const QString &str) const
// workaround for the additional space introduced by QScrollArea // workaround for the additional space introduced by QScrollArea
int lineHeight = m_ui->commentLabel->fontMetrics().lineSpacing(); int lineHeight = m_ui->commentLabel->fontMetrics().lineSpacing();
int lines = 1 + str.count("\n"); int lines = 1 + str.count('\n');
int height = lineHeight * lines; int height = lineHeight * lines;
m_ui->scrollArea->setMaximumHeight(height); m_ui->scrollArea->setMaximumHeight(height);
} }

18
src/gui/advancedsettings.cpp

@ -33,10 +33,10 @@
#include <QHostAddress> #include <QHostAddress>
#include <QNetworkInterface> #include <QNetworkInterface>
#include "app/application.h"
#include "base/bittorrent/session.h" #include "base/bittorrent/session.h"
#include "base/preferences.h" #include "base/preferences.h"
#include "base/unicodestrings.h" #include "base/unicodestrings.h"
#include "app/application.h"
#include "gui/addnewtorrentdialog.h" #include "gui/addnewtorrentdialog.h"
#include "gui/mainwindow.h" #include "gui/mainwindow.h"
@ -137,7 +137,7 @@ AdvancedSettings::AdvancedSettings(QWidget *parent)
void AdvancedSettings::saveAdvancedSettings() void AdvancedSettings::saveAdvancedSettings()
{ {
Preferences* const pref = Preferences::instance(); Preferences *const pref = Preferences::instance();
BitTorrent::Session *const session = BitTorrent::Session::instance(); BitTorrent::Session *const session = BitTorrent::Session::instance();
// Disk write cache // Disk write cache
@ -201,7 +201,7 @@ void AdvancedSettings::saveAdvancedSettings()
session->setAnnounceIP(addr.isNull() ? "" : addr.toString()); session->setAnnounceIP(addr.isNull() ? "" : addr.toString());
// Program notification // Program notification
MainWindow * const mainWindow = static_cast<Application*>(QCoreApplication::instance())->mainWindow(); MainWindow *const mainWindow = static_cast<Application*>(QCoreApplication::instance())->mainWindow();
mainWindow->setNotificationsEnabled(cb_program_notifications.isChecked()); mainWindow->setNotificationsEnabled(cb_program_notifications.isChecked());
mainWindow->setTorrentAddedNotificationsEnabled(cb_torrent_added_notifications.isChecked()); mainWindow->setTorrentAddedNotificationsEnabled(cb_torrent_added_notifications.isChecked());
// Misc GUI properties // Misc GUI properties
@ -247,16 +247,16 @@ void AdvancedSettings::updateInterfaceAddressCombo()
const QString ifaceName = combo_iface.itemData(combo_iface.currentIndex()).toString(); // Empty string for the first element const QString ifaceName = combo_iface.itemData(combo_iface.currentIndex()).toString(); // Empty string for the first element
const QString currentAddress = BitTorrent::Session::instance()->networkInterfaceAddress(); const QString currentAddress = BitTorrent::Session::instance()->networkInterfaceAddress();
//Clear all items and reinsert them, default to all // Clear all items and reinsert them, default to all
combo_iface_address.clear(); combo_iface_address.clear();
combo_iface_address.addItem(tr("All addresses")); combo_iface_address.addItem(tr("All addresses"));
combo_iface_address.setCurrentIndex(0); combo_iface_address.setCurrentIndex(0);
auto populateCombo = [this, &currentAddress](const QString &ip, const QAbstractSocket::NetworkLayerProtocol &protocol) auto populateCombo = [this, &currentAddress](const QString &ip, const QAbstractSocket::NetworkLayerProtocol &protocol)
{ {
Q_ASSERT(protocol == QAbstractSocket::IPv4Protocol || protocol == QAbstractSocket::IPv6Protocol); Q_ASSERT((protocol == QAbstractSocket::IPv4Protocol) || (protocol == QAbstractSocket::IPv6Protocol));
//Only take ipv4 for now? // Only take ipv4 for now?
if (protocol != QAbstractSocket::IPv4Protocol && protocol != QAbstractSocket::IPv6Protocol) if ((protocol != QAbstractSocket::IPv4Protocol) && (protocol != QAbstractSocket::IPv6Protocol))
return; return;
combo_iface_address.addItem(ip); combo_iface_address.addItem(ip);
//Try to select the last added one //Try to select the last added one
@ -280,7 +280,7 @@ void AdvancedSettings::updateInterfaceAddressCombo()
void AdvancedSettings::loadAdvancedSettings() void AdvancedSettings::loadAdvancedSettings()
{ {
const Preferences* const pref = Preferences::instance(); const Preferences *const pref = Preferences::instance();
const BitTorrent::Session *const session = BitTorrent::Session::instance(); const BitTorrent::Session *const session = BitTorrent::Session::instance();
// add section headers // add section headers
@ -483,7 +483,7 @@ void AdvancedSettings::loadAdvancedSettings()
} }
template <typename T> template <typename T>
void AdvancedSettings::addRow(int row, const QString &rowText, T* widget) void AdvancedSettings::addRow(int row, const QString &rowText, T *widget)
{ {
setItem(row, PROPERTY, new QTableWidgetItem(rowText)); setItem(row, PROPERTY, new QTableWidgetItem(rowText));
setCellWidget(row, VALUE, widget); setCellWidget(row, VALUE, widget);

2
src/gui/advancedsettings.h

@ -36,7 +36,7 @@
#include <QSpinBox> #include <QSpinBox>
#include <QTableWidget> #include <QTableWidget>
class AdvancedSettings: public QTableWidget class AdvancedSettings : public QTableWidget
{ {
Q_OBJECT Q_OBJECT

4
src/gui/autoexpandabledialog.h

@ -38,7 +38,7 @@ namespace Ui
class AutoExpandableDialog; class AutoExpandableDialog;
} }
class AutoExpandableDialog: public QDialog class AutoExpandableDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
@ -51,7 +51,7 @@ public:
bool *ok = nullptr, Qt::InputMethodHints inputMethodHints = Qt::ImhNone); bool *ok = nullptr, Qt::InputMethodHints inputMethodHints = Qt::ImhNone);
protected: protected:
void showEvent(QShowEvent *e); void showEvent(QShowEvent *e) override;
private: private:
Ui::AutoExpandableDialog *m_ui; Ui::AutoExpandableDialog *m_ui;

2
src/gui/categoryfiltermodel.cpp

@ -31,8 +31,8 @@
#include <QHash> #include <QHash>
#include <QIcon> #include <QIcon>
#include "base/bittorrent/torrenthandle.h"
#include "base/bittorrent/session.h" #include "base/bittorrent/session.h"
#include "base/bittorrent/torrenthandle.h"
#include "guiiconprovider.h" #include "guiiconprovider.h"
class CategoryModelItem class CategoryModelItem

2
src/gui/categoryfiltermodel.h

@ -40,7 +40,7 @@ namespace BitTorrent
class CategoryModelItem; class CategoryModelItem;
class CategoryFilterModel: public QAbstractItemModel class CategoryFilterModel : public QAbstractItemModel
{ {
Q_OBJECT Q_OBJECT

2
src/gui/categoryfilterproxymodel.h

@ -32,7 +32,7 @@
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include <QString> #include <QString>
class CategoryFilterProxyModel: public QSortFilterProxyModel class CategoryFilterProxyModel : public QSortFilterProxyModel
{ {
public: public:
explicit CategoryFilterProxyModel(QObject *parent = nullptr); explicit CategoryFilterProxyModel(QObject *parent = nullptr);

2
src/gui/categoryfilterwidget.h

@ -28,7 +28,7 @@
#include <QTreeView> #include <QTreeView>
class CategoryFilterWidget: public QTreeView class CategoryFilterWidget : public QTreeView
{ {
Q_OBJECT Q_OBJECT
Q_DISABLE_COPY(CategoryFilterWidget) Q_DISABLE_COPY(CategoryFilterWidget)

85
src/gui/deletionconfirmationdlg.h

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt4 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 DELETIONCONFIRMATIONDLG_H #ifndef DELETIONCONFIRMATIONDLG_H
@ -41,52 +39,59 @@
#include "ui_confirmdeletiondlg.h" #include "ui_confirmdeletiondlg.h"
#include "utils.h" #include "utils.h"
class DeletionConfirmationDlg : public QDialog, private Ui::confirmDeletionDlg { class DeletionConfirmationDlg : public QDialog, private Ui::confirmDeletionDlg
Q_OBJECT {
Q_OBJECT
public: public:
DeletionConfirmationDlg(QWidget *parent, const int &size, const QString &name, bool defaultDeleteFiles): QDialog(parent) { DeletionConfirmationDlg(QWidget *parent, const int &size, const QString &name, bool defaultDeleteFiles)
setupUi(this); : QDialog(parent)
if (size == 1) {
label->setText(tr("Are you sure you want to delete '%1' from the transfer list?", "Are you sure you want to delete 'ubuntu-linux-iso' from the transfer list?").arg(name.toHtmlEscaped())); setupUi(this);
else if (size == 1)
label->setText(tr("Are you sure you want to delete these %1 torrents from the transfer list?", "Are you sure you want to delete these 5 torrents from the transfer list?").arg(QString::number(size))); label->setText(tr("Are you sure you want to delete '%1' from the transfer list?", "Are you sure you want to delete 'ubuntu-linux-iso' from the transfer list?").arg(name.toHtmlEscaped()));
// Icons else
const QSize iconSize = Utils::Gui::largeIconSize(); label->setText(tr("Are you sure you want to delete these %1 torrents from the transfer list?", "Are you sure you want to delete these 5 torrents from the transfer list?").arg(QString::number(size)));
lbl_warn->setPixmap(GuiIconProvider::instance()->getIcon("dialog-warning").pixmap(iconSize)); // Icons
lbl_warn->setFixedWidth(iconSize.width()); const QSize iconSize = Utils::Gui::largeIconSize();
rememberBtn->setIcon(GuiIconProvider::instance()->getIcon("object-locked")); lbl_warn->setPixmap(GuiIconProvider::instance()->getIcon("dialog-warning").pixmap(iconSize));
rememberBtn->setIconSize(Utils::Gui::mediumIconSize()); lbl_warn->setFixedWidth(iconSize.width());
rememberBtn->setIcon(GuiIconProvider::instance()->getIcon("object-locked"));
rememberBtn->setIconSize(Utils::Gui::mediumIconSize());
checkPermDelete->setChecked(defaultDeleteFiles || Preferences::instance()->deleteTorrentFilesAsDefault()); checkPermDelete->setChecked(defaultDeleteFiles || Preferences::instance()->deleteTorrentFilesAsDefault());
connect(checkPermDelete, &QCheckBox::clicked, this, &DeletionConfirmationDlg::updateRememberButtonState); connect(checkPermDelete, &QCheckBox::clicked, this, &DeletionConfirmationDlg::updateRememberButtonState);
buttonBox->button(QDialogButtonBox::Cancel)->setFocus(); buttonBox->button(QDialogButtonBox::Cancel)->setFocus();
Utils::Gui::resize(this); Utils::Gui::resize(this);
} }
bool shouldDeleteLocalFiles() const { bool shouldDeleteLocalFiles() const
return checkPermDelete->isChecked(); {
} return checkPermDelete->isChecked();
}
static bool askForDeletionConfirmation(QWidget *parent, bool& deleteLocalFiles, const int& size, const QString& name) { static bool askForDeletionConfirmation(QWidget *parent, bool &deleteLocalFiles, const int &size, const QString &name)
DeletionConfirmationDlg dlg(parent, size, name, deleteLocalFiles); {
if (dlg.exec() == QDialog::Accepted) { DeletionConfirmationDlg dlg(parent, size, name, deleteLocalFiles);
deleteLocalFiles = dlg.shouldDeleteLocalFiles(); if (dlg.exec() == QDialog::Accepted) {
return true; deleteLocalFiles = dlg.shouldDeleteLocalFiles();
return true;
}
return false;
} }
return false;
}
private slots: private slots:
void updateRememberButtonState() { void updateRememberButtonState()
rememberBtn->setEnabled(checkPermDelete->isChecked() != Preferences::instance()->deleteTorrentFilesAsDefault()); {
} rememberBtn->setEnabled(checkPermDelete->isChecked() != Preferences::instance()->deleteTorrentFilesAsDefault());
}
void on_rememberBtn_clicked() { void on_rememberBtn_clicked()
Preferences::instance()->setDeleteTorrentFilesAsDefault(checkPermDelete->isChecked()); {
rememberBtn->setEnabled(false); Preferences::instance()->setDeleteTorrentFilesAsDefault(checkPermDelete->isChecked());
} rememberBtn->setEnabled(false);
}
}; };
#endif // DELETIONCONFIRMATIONDLG_H #endif // DELETIONCONFIRMATIONDLG_H

2
src/gui/downloadfromurldialog.h

@ -55,4 +55,4 @@ private:
Ui::DownloadFromURLDialog *m_ui; Ui::DownloadFromURLDialog *m_ui;
}; };
#endif #endif // DOWNLOADFROMURL_H

38
src/gui/executionlog.cpp

@ -1,5 +1,5 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2011 Christophe Dumez * Copyright (C) 2011 Christophe Dumez
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -24,40 +24,40 @@
* 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 <QListWidgetItem> #include "executionlog.h"
#include <QLabel>
#include <QDateTime>
#include <QColor> #include <QColor>
#include <QDateTime>
#include <QLabel>
#include <QListWidgetItem>
#include <QPalette> #include <QPalette>
#include "executionlog.h"
#include "ui_executionlog.h"
#include "guiiconprovider.h" #include "guiiconprovider.h"
#include "loglistwidget.h" #include "loglistwidget.h"
#include "ui_executionlog.h"
ExecutionLog::ExecutionLog(QWidget *parent, const Log::MsgTypes &types) ExecutionLog::ExecutionLog(QWidget *parent, const Log::MsgTypes &types)
: QWidget(parent) : QWidget(parent)
, ui(new Ui::ExecutionLog) , m_ui(new Ui::ExecutionLog)
, m_peerList(new LogListWidget(MAX_LOG_MESSAGES)) , m_peerList(new LogListWidget(MAX_LOG_MESSAGES))
{ {
ui->setupUi(this); m_ui->setupUi(this);
m_msgList = new LogListWidget(MAX_LOG_MESSAGES, Log::MsgTypes(types)); m_msgList = new LogListWidget(MAX_LOG_MESSAGES, Log::MsgTypes(types));
#ifndef Q_OS_MAC #ifndef Q_OS_MAC
ui->tabConsole->setTabIcon(0, GuiIconProvider::instance()->getIcon("view-calendar-journal")); m_ui->tabConsole->setTabIcon(0, GuiIconProvider::instance()->getIcon("view-calendar-journal"));
ui->tabConsole->setTabIcon(1, GuiIconProvider::instance()->getIcon("view-filter")); m_ui->tabConsole->setTabIcon(1, GuiIconProvider::instance()->getIcon("view-filter"));
#endif #endif
ui->tabGeneral->layout()->addWidget(m_msgList); m_ui->tabGeneral->layout()->addWidget(m_msgList);
ui->tabBan->layout()->addWidget(m_peerList); m_ui->tabBan->layout()->addWidget(m_peerList);
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);
foreach (const Log::Peer& peer, logger->getPeers()) foreach (const Log::Peer &peer, logger->getPeers())
addPeerMessage(peer); addPeerMessage(peer);
connect(logger, &Logger::newLogMessage, this, &ExecutionLog::addLogMessage); connect(logger, &Logger::newLogMessage, this, &ExecutionLog::addLogMessage);
connect(logger, &Logger::newLogPeer, this, &ExecutionLog::addPeerMessage); connect(logger, &Logger::newLogPeer, this, &ExecutionLog::addPeerMessage);
@ -67,7 +67,7 @@ ExecutionLog::~ExecutionLog()
{ {
delete m_msgList; delete m_msgList;
delete m_peerList; delete m_peerList;
delete ui; delete m_ui;
} }
void ExecutionLog::showMsgTypes(const Log::MsgTypes &types) void ExecutionLog::showMsgTypes(const Log::MsgTypes &types)
@ -99,7 +99,7 @@ void ExecutionLog::addLogMessage(const Log::Msg &msg)
m_msgList->appendLine(text, msg.type); m_msgList->appendLine(text, msg.type);
} }
void ExecutionLog::addPeerMessage(const Log::Peer& peer) void ExecutionLog::addPeerMessage(const Log::Peer &peer)
{ {
QString text; QString text;
QDateTime time = QDateTime::fromMSecsSinceEpoch(peer.timestamp); QDateTime time = QDateTime::fromMSecsSinceEpoch(peer.timestamp);

16
src/gui/executionlog.h

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2011 Christophe Dumez * Copyright (C) 2011 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 EXECUTIONLOG_H #ifndef EXECUTIONLOG_H
@ -34,14 +32,14 @@
#include <QWidget> #include <QWidget>
#include "base/logger.h" #include "base/logger.h"
QT_BEGIN_NAMESPACE
namespace Ui { namespace Ui
{
class ExecutionLog; class ExecutionLog;
} }
QT_END_NAMESPACE
class LogListWidget; class LogListWidget;
class ExecutionLog: public QWidget class ExecutionLog : public QWidget
{ {
Q_OBJECT Q_OBJECT
@ -55,7 +53,7 @@ private slots:
void addPeerMessage(const Log::Peer &peer); void addPeerMessage(const Log::Peer &peer);
private: private:
Ui::ExecutionLog *ui; Ui::ExecutionLog *m_ui;
LogListWidget *m_msgList; LogListWidget *m_msgList;
LogListWidget *m_peerList; LogListWidget *m_peerList;

8
src/gui/fspathedit.h

@ -34,16 +34,16 @@
namespace Private namespace Private
{ {
class FileComboEdit;
class FileEditorWithCompletion; class FileEditorWithCompletion;
class FileLineEdit; class FileLineEdit;
class FileComboEdit;
} }
/*! /*!
* \brief * \brief
* Widget for editing strings which are paths in filesystem * Widget for editing strings which are paths in filesystem
*/ */
class FileSystemPathEdit: public QWidget class FileSystemPathEdit : public QWidget
{ {
Q_OBJECT Q_OBJECT
Q_ENUMS(Mode) Q_ENUMS(Mode)
@ -109,7 +109,7 @@ private:
}; };
/// Widget which uses QLineEdit for path editing /// Widget which uses QLineEdit for path editing
class FileSystemPathLineEdit: public FileSystemPathEdit class FileSystemPathLineEdit : public FileSystemPathEdit
{ {
using base = FileSystemPathEdit; using base = FileSystemPathEdit;
using WidgetType = Private::FileLineEdit; using WidgetType = Private::FileLineEdit;
@ -125,7 +125,7 @@ private:
}; };
/// Widget which uses QComboBox for path editing /// Widget which uses QComboBox for path editing
class FileSystemPathComboEdit: public FileSystemPathEdit class FileSystemPathComboEdit : public FileSystemPathEdit
{ {
using base = FileSystemPathEdit; using base = FileSystemPathEdit;
using WidgetType = Private::FileComboEdit; using WidgetType = Private::FileComboEdit;

6
src/gui/fspathedit_p.h

@ -47,7 +47,7 @@ class QStringList;
namespace Private namespace Private
{ {
class FileSystemPathValidator: public QValidator class FileSystemPathValidator : public QValidator
{ {
Q_OBJECT Q_OBJECT
@ -113,7 +113,7 @@ namespace Private
virtual QWidget *widget() = 0; virtual QWidget *widget() = 0;
}; };
class FileLineEdit: public QLineEdit, public FileEditorWithCompletion class FileLineEdit : public QLineEdit, public FileEditorWithCompletion
{ {
Q_OBJECT Q_OBJECT
Q_DISABLE_COPY(FileLineEdit) Q_DISABLE_COPY(FileLineEdit)
@ -143,7 +143,7 @@ namespace Private
QAction *m_warningAction; QAction *m_warningAction;
}; };
class FileComboEdit: public QComboBox, public FileEditorWithCompletion class FileComboEdit : public QComboBox, public FileEditorWithCompletion
{ {
Q_OBJECT Q_OBJECT

8
src/gui/hidabletabwidget.h

@ -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,15 +24,13 @@
* 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 HIDABLETABWIDGET_H #ifndef HIDABLETABWIDGET_H
#define HIDABLETABWIDGET_H #define HIDABLETABWIDGET_H
#include <QTabWidget>
#include <QTabBar> #include <QTabBar>
#include <QTabWidget>
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
#include <QStyle> #include <QStyle>
@ -48,7 +46,7 @@ public:
protected: protected:
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
void paintEvent(QPaintEvent* event) override void paintEvent(QPaintEvent *event) override
{ {
// Hide the pane for macintosh style // Hide the pane for macintosh style
if (!style()->inherits("QMacStyle")) if (!style()->inherits("QMacStyle"))

4
src/gui/loglistwidget.cpp

@ -1,5 +1,5 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2011 Christophe Dumez <chris@qbittorrent.org> * Copyright (C) 2011 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
@ -100,5 +100,5 @@ void LogListWidget::copySelection()
foreach (QListWidgetItem* it, selectedItems()) foreach (QListWidgetItem* it, selectedItems())
strings << static_cast<QLabel*>(itemWidget(it))->text().remove(htmlTag); strings << static_cast<QLabel*>(itemWidget(it))->text().remove(htmlTag);
QApplication::clipboard()->setText(strings.join("\n")); QApplication::clipboard()->setText(strings.join('\n'));
} }

13
src/gui/loglistwidget.h

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2011 Christophe Dumez * Copyright (C) 2011 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,20 +24,17 @@
* 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 LOGLISTWIDGET_H #ifndef LOGLISTWIDGET_H
#define LOGLISTWIDGET_H #define LOGLISTWIDGET_H
#include <QListWidget> #include <QListWidget>
#include "base/logger.h" #include "base/logger.h"
QT_BEGIN_NAMESPACE
class QKeyEvent; class QKeyEvent;
QT_END_NAMESPACE
class LogListWidget: public QListWidget class LogListWidget : public QListWidget
{ {
Q_OBJECT Q_OBJECT
@ -53,7 +50,7 @@ protected slots:
void copySelection(); void copySelection();
protected: protected:
void keyPressEvent(QKeyEvent *event); void keyPressEvent(QKeyEvent *event) override;
private: private:
int m_maxLines; int m_maxLines;

36
src/gui/mainwindow.cpp

@ -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 "mainwindow.h" #include "mainwindow.h"
@ -59,10 +57,6 @@
#include "notifications.h" #include "notifications.h"
#endif #endif
#include "about_imp.h"
#include "addnewtorrentdialog.h"
#include "application.h"
#include "autoexpandabledialog.h"
#include "base/bittorrent/session.h" #include "base/bittorrent/session.h"
#include "base/bittorrent/sessionstatus.h" #include "base/bittorrent/sessionstatus.h"
#include "base/bittorrent/torrenthandle.h" #include "base/bittorrent/torrenthandle.h"
@ -74,6 +68,10 @@
#include "base/settingsstorage.h" #include "base/settingsstorage.h"
#include "base/utils/fs.h" #include "base/utils/fs.h"
#include "base/utils/misc.h" #include "base/utils/misc.h"
#include "about_imp.h"
#include "addnewtorrentdialog.h"
#include "application.h"
#include "autoexpandabledialog.h"
#include "cookiesdialog.h" #include "cookiesdialog.h"
#include "downloadfromurldialog.h" #include "downloadfromurldialog.h"
#include "executionlog.h" #include "executionlog.h"
@ -267,7 +265,7 @@ MainWindow::MainWindow(QWidget *parent)
connect(BitTorrent::Session::instance(), &BitTorrent::Session::trackersRemoved, m_transferListFiltersWidget, &TransferListFiltersWidget::removeTrackers); connect(BitTorrent::Session::instance(), &BitTorrent::Session::trackersRemoved, m_transferListFiltersWidget, &TransferListFiltersWidget::removeTrackers);
connect(BitTorrent::Session::instance(), &BitTorrent::Session::trackerlessStateChanged, m_transferListFiltersWidget, &TransferListFiltersWidget::changeTrackerless); connect(BitTorrent::Session::instance(), &BitTorrent::Session::trackerlessStateChanged, m_transferListFiltersWidget, &TransferListFiltersWidget::changeTrackerless);
using Func = void (TransferListFiltersWidget::*)(BitTorrent::TorrentHandle * const, const QString &); using Func = void (TransferListFiltersWidget::*)(BitTorrent::TorrentHandle *const, const QString &);
connect(BitTorrent::Session::instance(), &BitTorrent::Session::trackerSuccess, m_transferListFiltersWidget, static_cast<Func>(&TransferListFiltersWidget::trackerSuccess)); connect(BitTorrent::Session::instance(), &BitTorrent::Session::trackerSuccess, m_transferListFiltersWidget, static_cast<Func>(&TransferListFiltersWidget::trackerSuccess));
connect(BitTorrent::Session::instance(), &BitTorrent::Session::trackerError, m_transferListFiltersWidget, static_cast<Func>(&TransferListFiltersWidget::trackerError)); connect(BitTorrent::Session::instance(), &BitTorrent::Session::trackerError, m_transferListFiltersWidget, static_cast<Func>(&TransferListFiltersWidget::trackerError));
connect(BitTorrent::Session::instance(), &BitTorrent::Session::trackerWarning, m_transferListFiltersWidget, static_cast<Func>(&TransferListFiltersWidget::trackerWarning)); connect(BitTorrent::Session::instance(), &BitTorrent::Session::trackerWarning, m_transferListFiltersWidget, static_cast<Func>(&TransferListFiltersWidget::trackerWarning));
@ -1059,7 +1057,7 @@ void MainWindow::notifyOfUpdate(QString)
void MainWindow::toggleVisibility(const QSystemTrayIcon::ActivationReason reason) void MainWindow::toggleVisibility(const QSystemTrayIcon::ActivationReason reason)
{ {
switch (reason) { switch (reason) {
case QSystemTrayIcon::Trigger: { case QSystemTrayIcon::Trigger:
if (isHidden()) { if (isHidden()) {
if (m_uiLocked && !unlockUI()) // Ask for UI lock password if (m_uiLocked && !unlockUI()) // Ask for UI lock password
return; return;
@ -1075,9 +1073,7 @@ void MainWindow::toggleVisibility(const QSystemTrayIcon::ActivationReason reason
else { else {
hide(); hide();
} }
break; break;
}
default: default:
break; break;
@ -1092,7 +1088,7 @@ void MainWindow::on_actionAbout_triggered()
if (m_aboutDlg) if (m_aboutDlg)
m_aboutDlg->activateWindow(); m_aboutDlg->activateWindow();
else else
m_aboutDlg = new about(this); m_aboutDlg = new AboutDialog(this);
} }
void MainWindow::on_actionStatistics_triggered() void MainWindow::on_actionStatistics_triggered()
@ -1136,7 +1132,7 @@ void MainWindow::closeEvent(QCloseEvent *e)
e->accept(); e->accept();
return; return;
} }
#endif #endif // Q_OS_MAC
if (pref->confirmOnExit() && BitTorrent::Session::instance()->hasActiveTorrents()) { if (pref->confirmOnExit() && BitTorrent::Session::instance()->hasActiveTorrents()) {
if (e->spontaneous() || m_forceExit) { if (e->spontaneous() || m_forceExit) {
@ -1144,7 +1140,7 @@ void MainWindow::closeEvent(QCloseEvent *e)
show(); show();
QMessageBox confirmBox(QMessageBox::Question, tr("Exiting qBittorrent"), QMessageBox confirmBox(QMessageBox::Question, tr("Exiting qBittorrent"),
// Split it because the last sentence is used in the Web UI // Split it because the last sentence is used in the Web UI
tr("Some files are currently transferring.") + "\n" + tr("Are you sure you want to quit qBittorrent?"), tr("Some files are currently transferring.") + '\n' + tr("Are you sure you want to quit qBittorrent?"),
QMessageBox::NoButton, this); QMessageBox::NoButton, this);
QPushButton *noBtn = confirmBox.addButton(tr("&No"), QMessageBox::NoRole); QPushButton *noBtn = confirmBox.addButton(tr("&No"), QMessageBox::NoRole);
confirmBox.addButton(tr("&Yes"), QMessageBox::YesRole); confirmBox.addButton(tr("&Yes"), QMessageBox::YesRole);
@ -1355,9 +1351,9 @@ void MainWindow::on_actionOpen_triggered()
} }
// Save last dir to remember it // Save last dir to remember it
QStringList topDir = Utils::Fs::fromNativePath(pathsList.at(0)).split("/"); QStringList topDir = Utils::Fs::fromNativePath(pathsList.at(0)).split('/');
topDir.removeLast(); topDir.removeLast();
pref->setMainLastDir(Utils::Fs::fromNativePath(topDir.join("/"))); pref->setMainLastDir(Utils::Fs::fromNativePath(topDir.join('/')));
} }
} }
@ -1538,7 +1534,7 @@ void MainWindow::updateGUI()
#else #else
// OSes such as Windows do not support html here // OSes such as Windows do not support html here
QString html = tr("DL speed: %1", "e.g: Download speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate, true)); QString html = tr("DL speed: %1", "e.g: Download speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate, true));
html += "\n"; html += '\n';
html += tr("UP speed: %1", "e.g: Upload speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadUploadRate, true)); html += tr("UP speed: %1", "e.g: Upload speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadUploadRate, true));
#endif // Q_OS_UNIX #endif // Q_OS_UNIX
m_systrayIcon->setToolTip(html); // tray icon m_systrayIcon->setToolTip(html); // tray icon
@ -1660,7 +1656,7 @@ void MainWindow::createTrayIcon()
connect(m_systrayIcon.data(), &QSystemTrayIcon::activated, this, &MainWindow::toggleVisibility); connect(m_systrayIcon.data(), &QSystemTrayIcon::activated, this, &MainWindow::toggleVisibility);
m_systrayIcon->show(); m_systrayIcon->show();
} }
#endif #endif // Q_OS_MAC
QMenu *MainWindow::trayIconMenu() QMenu *MainWindow::trayIconMenu()
{ {
@ -2006,7 +2002,7 @@ QIcon MainWindow::getSystrayIcon() const
// As a failsafe in case the enum is invalid // As a failsafe in case the enum is invalid
return QIcon(QLatin1String(":/icons/skin/qbittorrent-tray.svg")); return QIcon(QLatin1String(":/icons/skin/qbittorrent-tray.svg"));
} }
#endif #endif // Q_OS_MAC
#if defined(Q_OS_WIN) || defined(Q_OS_MAC) #if defined(Q_OS_WIN) || defined(Q_OS_MAC)
void MainWindow::checkProgramUpdate() void MainWindow::checkProgramUpdate()
@ -2102,4 +2098,4 @@ void MainWindow::pythonDownloadFailure(const QString &url, const QString &error)
QMessageBox::warning(this, tr("Download error"), tr("Python setup could not be downloaded, reason: %1.\nPlease install it manually.").arg(error)); QMessageBox::warning(this, tr("Download error"), tr("Python setup could not be downloaded, reason: %1.\nPlease install it manually.").arg(error));
} }
#endif #endif // Q_OS_WIN

10
src/gui/mainwindow.h

@ -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 MAINWINDOW_H #ifndef MAINWINDOW_H
@ -48,7 +46,7 @@ class QTimer;
class DownloadFromURLDialog; class DownloadFromURLDialog;
class SearchWidget; class SearchWidget;
class RSSWidget; class RSSWidget;
class about; class AboutDialog;
class OptionsDialog; class OptionsDialog;
class TransferListWidget; class TransferListWidget;
class TransferListFiltersWidget; class TransferListFiltersWidget;
@ -70,7 +68,7 @@ namespace Ui
class MainWindow; class MainWindow;
} }
class MainWindow: public QMainWindow class MainWindow : public QMainWindow
{ {
Q_OBJECT Q_OBJECT
@ -227,7 +225,7 @@ private:
QPointer<QTabWidget> m_tabs; QPointer<QTabWidget> m_tabs;
QPointer<StatusBar> m_statusBar; QPointer<StatusBar> m_statusBar;
QPointer<OptionsDialog> m_options; QPointer<OptionsDialog> m_options;
QPointer<about> m_aboutDlg; QPointer<AboutDialog> m_aboutDlg;
QPointer<StatsDialog> m_statsDlg; QPointer<StatsDialog> m_statsDlg;
QPointer<TorrentCreatorDlg> m_createTorrentDlg; QPointer<TorrentCreatorDlg> m_createTorrentDlg;
QPointer<DownloadFromURLDialog> m_downloadFromURLDialog; QPointer<DownloadFromURLDialog> m_downloadFromURLDialog;

48
src/gui/messageboxraised.cpp

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2014 sledgehammer999 * Copyright (C) 2014 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
@ -24,40 +24,46 @@
* 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 : hammered999@gmail.com
*/ */
#include "messageboxraised.h" #include "messageboxraised.h"
MessageBoxRaised::MessageBoxRaised(QMessageBox::Icon icon, const QString &title, const QString &text, MessageBoxRaised::MessageBoxRaised(QMessageBox::Icon icon, const QString &title, const QString &text,
QMessageBox::StandardButtons buttons, QWidget *parent, Qt::WindowFlags f) QMessageBox::StandardButtons buttons, QWidget *parent, Qt::WindowFlags f)
: QMessageBox(icon, title, text, buttons, parent, f) {} : QMessageBox(icon, title, text, buttons, parent, f)
{
}
QMessageBox::StandardButton MessageBoxRaised::impl(const QMessageBox::Icon &icon, QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) { QMessageBox::StandardButton MessageBoxRaised::impl(const QMessageBox::Icon &icon, QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
MessageBoxRaised dlg(icon, title, text, buttons, parent); {
dlg.setDefaultButton(defaultButton); MessageBoxRaised dlg(icon, title, text, buttons, parent);
return static_cast<QMessageBox::StandardButton>(dlg.exec()); dlg.setDefaultButton(defaultButton);
return static_cast<QMessageBox::StandardButton>(dlg.exec());
} }
QMessageBox::StandardButton MessageBoxRaised::critical(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) { QMessageBox::StandardButton MessageBoxRaised::critical(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
return impl(Critical, parent, title, text, buttons, defaultButton); {
return impl(Critical, parent, title, text, buttons, defaultButton);
} }
QMessageBox::StandardButton MessageBoxRaised::information(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) { QMessageBox::StandardButton MessageBoxRaised::information(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
return impl(Information, parent, title, text, buttons, defaultButton); {
return impl(Information, parent, title, text, buttons, defaultButton);
} }
QMessageBox::StandardButton MessageBoxRaised::question(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) { QMessageBox::StandardButton MessageBoxRaised::question(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
return impl(Question, parent, title, text, buttons, defaultButton); {
return impl(Question, parent, title, text, buttons, defaultButton);
} }
QMessageBox::StandardButton MessageBoxRaised::warning(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) { QMessageBox::StandardButton MessageBoxRaised::warning(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
return impl(Warning, parent, title, text, buttons, defaultButton); {
return impl(Warning, parent, title, text, buttons, defaultButton);
} }
void MessageBoxRaised::showEvent(QShowEvent *event) { void MessageBoxRaised::showEvent(QShowEvent *event)
QMessageBox::showEvent(event); {
activateWindow(); QMessageBox::showEvent(event);
raise(); activateWindow();
raise();
} }

29
src/gui/messageboxraised.h

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2014 sledgehammer999 * Copyright (C) 2014 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
@ -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 : hammered999@gmail.com
*/ */
#ifndef MESSAGEBOXRAISED_H #ifndef MESSAGEBOXRAISED_H
@ -37,23 +35,22 @@ class MessageBoxRaised : public QMessageBox
{ {
Q_OBJECT Q_OBJECT
private:
MessageBoxRaised(QMessageBox::Icon icon, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = NoButton, QWidget *parent = nullptr, Qt::WindowFlags f = Qt::Dialog|Qt::MSWindowsFixedSizeDialogHint);
MessageBoxRaised();
MessageBoxRaised(MessageBoxRaised const&);
void operator=(MessageBoxRaised const&);
public: public:
static QMessageBox::StandardButton critical(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = QMessageBox::Ok, QMessageBox::StandardButton defaultButton = QMessageBox::NoButton); static QMessageBox::StandardButton critical(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = QMessageBox::Ok, QMessageBox::StandardButton defaultButton = QMessageBox::NoButton);
static QMessageBox::StandardButton information(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = QMessageBox::Ok, QMessageBox::StandardButton defaultButton = QMessageBox::NoButton); static QMessageBox::StandardButton information(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = QMessageBox::Ok, QMessageBox::StandardButton defaultButton = QMessageBox::NoButton);
static QMessageBox::StandardButton question(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = QMessageBox::Ok, QMessageBox::StandardButton defaultButton = QMessageBox::NoButton); static QMessageBox::StandardButton question(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = QMessageBox::Ok, QMessageBox::StandardButton defaultButton = QMessageBox::NoButton);
static QMessageBox::StandardButton warning(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = QMessageBox::Ok, QMessageBox::StandardButton defaultButton = QMessageBox::NoButton); static QMessageBox::StandardButton warning(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = QMessageBox::Ok, QMessageBox::StandardButton defaultButton = QMessageBox::NoButton);
protected: protected:
void showEvent(QShowEvent *event); void showEvent(QShowEvent *event) override;
private: private:
static QMessageBox::StandardButton impl(const QMessageBox::Icon &icon, QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = QMessageBox::Ok, QMessageBox::StandardButton defaultButton = QMessageBox::NoButton); MessageBoxRaised(QMessageBox::Icon icon, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = NoButton, QWidget *parent = nullptr, Qt::WindowFlags f = Qt::Dialog|Qt::MSWindowsFixedSizeDialogHint);
MessageBoxRaised();
MessageBoxRaised(MessageBoxRaised const&);
void operator=(MessageBoxRaised const&);
static QMessageBox::StandardButton impl(const QMessageBox::Icon &icon, QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = QMessageBox::Ok, QMessageBox::StandardButton defaultButton = QMessageBox::NoButton);
}; };
#endif // MESSAGEBOXRAISED_H #endif // MESSAGEBOXRAISED_H

39
src/gui/optionsdlg.cpp

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 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 "optionsdlg.h" #include "optionsdlg.h"
@ -49,7 +47,6 @@
#include <QSslKey> #include <QSslKey>
#endif #endif
#include "app/application.h"
#include "base/bittorrent/session.h" #include "base/bittorrent/session.h"
#include "base/global.h" #include "base/global.h"
#include "base/net/dnsupdater.h" #include "base/net/dnsupdater.h"
@ -65,10 +62,11 @@
#include "base/utils/random.h" #include "base/utils/random.h"
#include "addnewtorrentdialog.h" #include "addnewtorrentdialog.h"
#include "advancedsettings.h" #include "advancedsettings.h"
#include "rss/automatedrssdownloader.h" #include "app/application.h"
#include "banlistoptions.h" #include "banlistoptions.h"
#include "ipsubnetwhitelistoptionsdialog.h" #include "ipsubnetwhitelistoptionsdialog.h"
#include "guiiconprovider.h" #include "guiiconprovider.h"
#include "rss/automatedrssdownloader.h"
#include "scanfoldersdelegate.h" #include "scanfoldersdelegate.h"
#include "utils.h" #include "utils.h"
@ -401,7 +399,7 @@ OptionsDialog::OptionsDialog(QWidget *parent)
connect(m_ui->DNSPasswordTxt, &QLineEdit::textChanged, this, &ThisType::enableApplyButton); connect(m_ui->DNSPasswordTxt, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
connect(m_ui->groupAltWebUI, &QGroupBox::toggled, this, &ThisType::enableApplyButton); connect(m_ui->groupAltWebUI, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->textWebUIRootFolder, &FileSystemPathLineEdit::selectedPathChanged, this, &ThisType::enableApplyButton); connect(m_ui->textWebUIRootFolder, &FileSystemPathLineEdit::selectedPathChanged, this, &ThisType::enableApplyButton);
#endif #endif // DISABLE_WEBUI
// RSS tab // RSS tab
connect(m_ui->checkRSSEnable, &QCheckBox::toggled, this, &OptionsDialog::enableApplyButton); connect(m_ui->checkRSSEnable, &QCheckBox::toggled, this, &OptionsDialog::enableApplyButton);
@ -514,7 +512,7 @@ void OptionsDialog::loadSplitterState()
void OptionsDialog::saveWindowState() const void OptionsDialog::saveWindowState() const
{ {
Preferences* const pref = Preferences::instance(); Preferences *const pref = Preferences::instance();
// window size // window size
pref->setPrefSize(size()); pref->setPrefSize(size());
@ -529,7 +527,7 @@ void OptionsDialog::saveWindowState() const
void OptionsDialog::saveOptions() void OptionsDialog::saveOptions()
{ {
applyButton->setEnabled(false); applyButton->setEnabled(false);
Preferences* const pref = Preferences::instance(); Preferences *const pref = Preferences::instance();
// Load the translation // Load the translation
QString locale = getLocale(); QString locale = getLocale();
if (pref->getLocale() != locale) { if (pref->getLocale() != locale) {
@ -576,7 +574,7 @@ void OptionsDialog::saveOptions()
m_ui->checkAssociateMagnetLinks->setEnabled(!m_ui->checkAssociateMagnetLinks->isChecked()); m_ui->checkAssociateMagnetLinks->setEnabled(!m_ui->checkAssociateMagnetLinks->isChecked());
} }
#endif #endif
Application * const app = static_cast<Application*>(QCoreApplication::instance()); Application *const app = static_cast<Application*>(QCoreApplication::instance());
app->setFileLoggerPath(m_ui->textFileLogPath->selectedPath()); app->setFileLoggerPath(m_ui->textFileLogPath->selectedPath());
app->setFileLoggerBackup(m_ui->checkFileLogBackup->isChecked()); app->setFileLoggerBackup(m_ui->checkFileLogBackup->isChecked());
app->setFileLoggerMaxSize(m_ui->spinFileLogSize->value() * 1024); app->setFileLoggerMaxSize(m_ui->spinFileLogSize->value() * 1024);
@ -652,7 +650,7 @@ void OptionsDialog::saveOptions()
pref->setSchedulerDays(static_cast<SchedulerDays>(m_ui->schedule_days->currentIndex())); pref->setSchedulerDays(static_cast<SchedulerDays>(m_ui->schedule_days->currentIndex()));
session->setBandwidthSchedulerEnabled(m_ui->check_schedule->isChecked()); session->setBandwidthSchedulerEnabled(m_ui->check_schedule->isChecked());
auto proxyConfigManager = Net::ProxyConfigurationManager::instance(); auto proxyConfigManager = Net::ProxyConfigurationManager::instance();
Net::ProxyConfiguration proxyConf; Net::ProxyConfiguration proxyConf;
proxyConf.type = getProxyType(); proxyConf.type = getProxyType();
proxyConf.ip = getProxyIp(); proxyConf.ip = getProxyIp();
@ -769,7 +767,7 @@ void OptionsDialog::loadOptions()
QString strValue; QString strValue;
bool fileLogBackup = true; bool fileLogBackup = true;
bool fileLogDelete = true; bool fileLogDelete = true;
const Preferences* const pref = Preferences::instance(); const Preferences *const pref = Preferences::instance();
// General preferences // General preferences
setLocale(pref->getLocale()); setLocale(pref->getLocale());
@ -807,7 +805,7 @@ void OptionsDialog::loadOptions()
m_ui->checkAssociateMagnetLinks->setEnabled(!m_ui->checkAssociateMagnetLinks->isChecked()); m_ui->checkAssociateMagnetLinks->setEnabled(!m_ui->checkAssociateMagnetLinks->isChecked());
#endif #endif
const Application * const app = static_cast<Application*>(QCoreApplication::instance()); const Application *const app = static_cast<Application*>(QCoreApplication::instance());
m_ui->checkFileLog->setChecked(app->isFileLoggerEnabled()); m_ui->checkFileLog->setChecked(app->isFileLoggerEnabled());
m_ui->textFileLogPath->setSelectedPath(app->fileLoggerPath()); m_ui->textFileLogPath->setSelectedPath(app->fileLoggerPath());
fileLogBackup = app->isFileLoggerBackup(); fileLogBackup = app->isFileLoggerBackup();
@ -1237,7 +1235,7 @@ bool OptionsDialog::closeToTray() const
if (!m_ui->checkShowSystray->isChecked()) return false; if (!m_ui->checkShowSystray->isChecked()) return false;
return m_ui->checkCloseToSystray->isChecked(); return m_ui->checkCloseToSystray->isChecked();
} }
#endif #endif // Q_OS_MAC
// Return Share ratio // Return Share ratio
qreal OptionsDialog::getMaxRatio() const qreal OptionsDialog::getMaxRatio() const
@ -1307,7 +1305,7 @@ void OptionsDialog::on_buttonBox_accepted()
accept(); accept();
} }
void OptionsDialog::applySettings(QAbstractButton* button) void OptionsDialog::applySettings(QAbstractButton *button)
{ {
if (button == applyButton) { if (button == applyButton) {
if (!schedTimesOk()) { if (!schedTimesOk()) {
@ -1524,7 +1522,7 @@ int OptionsDialog::getActionOnDblClOnTorrentFn() const
void OptionsDialog::on_addScanFolderButton_clicked() void OptionsDialog::on_addScanFolderButton_clicked()
{ {
Preferences* const pref = Preferences::instance(); Preferences *const pref = Preferences::instance();
const QString dir = QFileDialog::getExistingDirectory(this, tr("Select folder to monitor"), const QString dir = QFileDialog::getExistingDirectory(this, tr("Select folder to monitor"),
Utils::Fs::toNativePath(Utils::Fs::folderName(pref->getScanDirsLastPath()))); Utils::Fs::toNativePath(Utils::Fs::folderName(pref->getScanDirsLastPath())));
if (!dir.isEmpty()) { if (!dir.isEmpty()) {
@ -1572,7 +1570,7 @@ void OptionsDialog::handleScanFolderViewSelectionChanged()
m_ui->removeScanFolderButton->setEnabled(!m_ui->scanFoldersView->selectionModel()->selectedIndexes().isEmpty()); m_ui->removeScanFolderButton->setEnabled(!m_ui->scanFoldersView->selectionModel()->selectedIndexes().isEmpty());
} }
QString OptionsDialog::askForExportDir(const QString& currentExportPath) QString OptionsDialog::askForExportDir(const QString &currentExportPath)
{ {
QDir currentExportDir(Utils::Fs::expandPathAbs(currentExportPath)); QDir currentExportDir(Utils::Fs::expandPathAbs(currentExportPath));
QString dir; QString dir;
@ -1733,15 +1731,14 @@ QString OptionsDialog::languageToLocalizedString(const QLocale &locale)
return QString::fromUtf8(C_LOCALE_CHINESE_TRADITIONAL_HK); return QString::fromUtf8(C_LOCALE_CHINESE_TRADITIONAL_HK);
default: default:
return QString::fromUtf8(C_LOCALE_CHINESE_TRADITIONAL_TW); return QString::fromUtf8(C_LOCALE_CHINESE_TRADITIONAL_TW);
} }
} }
case QLocale::Korean: return QString::fromUtf8(C_LOCALE_KOREAN); case QLocale::Korean: return QString::fromUtf8(C_LOCALE_KOREAN);
default: { default: {
// Fallback to English // Fallback to English
const QString eng_lang = QLocale::languageToString(locale.language()); const QString engLang = QLocale::languageToString(locale.language());
qWarning() << "Unrecognized language name: " << eng_lang; qWarning() << "Unrecognized language name: " << engLang;
return eng_lang; return engLang;
} }
} }
} }

12
src/gui/optionsdlg.h

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 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 OPTIONSDLG_H #ifndef OPTIONSDLG_H
@ -57,7 +55,7 @@ namespace Ui
class OptionsDialog; class OptionsDialog;
} }
class OptionsDialog: public QDialog class OptionsDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
using ThisType = OptionsDialog; using ThisType = OptionsDialog;
@ -87,7 +85,7 @@ private slots:
void enableForceProxy(bool enable); void enableForceProxy(bool enable);
void enableProxy(int index); void enableProxy(int index);
void on_buttonBox_accepted(); void on_buttonBox_accepted();
void closeEvent(QCloseEvent *e); void closeEvent(QCloseEvent *e) override;
void on_buttonBox_rejected(); void on_buttonBox_rejected();
void applySettings(QAbstractButton *button); void applySettings(QAbstractButton *button);
void enableApplyButton(); void enableApplyButton();
@ -188,4 +186,4 @@ private:
QList<QString> removedScanDirs; QList<QString> removedScanDirs;
}; };
#endif #endif // OPTIONSDLG_H

5
src/gui/previewlistdelegate.h

@ -33,11 +33,12 @@
#include <QItemDelegate> #include <QItemDelegate>
#include <QModelIndex> #include <QModelIndex>
#include <QPainter> #include <QPainter>
#include <QStyleOptionProgressBar>
#include <QStyleOptionViewItem>
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#include <QProxyStyle> #include <QProxyStyle>
#endif #endif
#include <QStyleOptionProgressBar>
#include <QStyleOptionViewItem>
#include "base/utils/misc.h" #include "base/utils/misc.h"
#include "base/utils/string.h" #include "base/utils/string.h"

2
src/gui/programupdater.cpp

@ -1,5 +1,5 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2010 Christophe Dumez <chris@qbittorrent.org> * Copyright (C) 2010 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

8
src/gui/programupdater.h

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2010 Christophe Dumez * Copyright (C) 2010 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 PROGRAMUPDATER_H #ifndef PROGRAMUPDATER_H
@ -34,7 +32,7 @@
#include <QObject> #include <QObject>
#include <QUrl> #include <QUrl>
class ProgramUpdater: public QObject class ProgramUpdater : public QObject
{ {
Q_OBJECT Q_OBJECT

2
src/gui/properties/downloadedpiecesbar.cpp

@ -101,7 +101,7 @@ QVector<float> DownloadedPiecesBar::bitfieldToFloatVector(const QBitArray &vecin
// normalization <0, 1> // normalization <0, 1>
value /= ratio; value /= ratio;
// float precision sometimes gives > 1, because in not possible to store irrational numbers // float precision sometimes gives > 1, because it's not possible to store irrational numbers
value = qMin(value, 1.0f); value = qMin(value, 1.0f);
result[x] = value; result[x] = value;

2
src/gui/properties/peerlistsortmodel.h

@ -54,7 +54,7 @@ protected:
const QString strR = right.data().toString(); const QString strR = right.data().toString();
const int result = Utils::String::naturalCompare(strL, strR, Qt::CaseInsensitive); const int result = Utils::String::naturalCompare(strL, strR, Qt::CaseInsensitive);
return (result < 0); return (result < 0);
} }
break; break;
default: default:
return QSortFilterProxyModel::lessThan(left, right); return QSortFilterProxyModel::lessThan(left, right);

10
src/gui/properties/peerlistwidget.cpp

@ -303,12 +303,12 @@ void PeerListWidget::copySelectedPeers()
int row = m_proxyModel->mapToSource(index).row(); int row = m_proxyModel->mapToSource(index).row();
QString ip = m_listModel->data(m_listModel->index(row, PeerListDelegate::IP_HIDDEN)).toString(); QString ip = m_listModel->data(m_listModel->index(row, PeerListDelegate::IP_HIDDEN)).toString();
QString myport = m_listModel->data(m_listModel->index(row, PeerListDelegate::PORT)).toString(); QString myport = m_listModel->data(m_listModel->index(row, PeerListDelegate::PORT)).toString();
if (ip.indexOf(".") == -1) // IPv6 if (ip.indexOf('.') == -1) // IPv6
selectedPeers << "[" + ip + "]:" + myport; selectedPeers << "[" + ip + "]:" + myport;
else // IPv4 else // IPv4
selectedPeers << ip + ":" + myport; selectedPeers << ip + ":" + myport;
} }
QApplication::clipboard()->setText(selectedPeers.join("\n")); QApplication::clipboard()->setText(selectedPeers.join('\n'));
} }
void PeerListWidget::clear() void PeerListWidget::clear()
@ -339,7 +339,7 @@ void PeerListWidget::loadPeers(BitTorrent::TorrentHandle *const torrent, bool fo
if (!torrent) return; if (!torrent) return;
QList<BitTorrent::PeerInfo> peers = torrent->peers(); QList<BitTorrent::PeerInfo> peers = torrent->peers();
QSet<QString> oldeersSet = m_peerItems.keys().toSet(); QSet<QString> oldPeersSet = m_peerItems.keys().toSet();
foreach (const BitTorrent::PeerInfo &peer, peers) { foreach (const BitTorrent::PeerInfo &peer, peers) {
BitTorrent::PeerAddress addr = peer.address(); BitTorrent::PeerAddress addr = peer.address();
@ -349,7 +349,7 @@ void PeerListWidget::loadPeers(BitTorrent::TorrentHandle *const torrent, bool fo
if (m_peerItems.contains(peerIp)) { if (m_peerItems.contains(peerIp)) {
// Update existing peer // Update existing peer
updatePeer(peerIp, torrent, peer); updatePeer(peerIp, torrent, peer);
oldeersSet.remove(peerIp); oldPeersSet.remove(peerIp);
if (forceHostnameResolution && m_resolver) if (forceHostnameResolution && m_resolver)
m_resolver->resolve(peerIp); m_resolver->resolve(peerIp);
} }
@ -363,7 +363,7 @@ void PeerListWidget::loadPeers(BitTorrent::TorrentHandle *const torrent, bool fo
} }
} }
// Delete peers that are gone // Delete peers that are gone
QSetIterator<QString> it(oldeersSet); QSetIterator<QString> it(oldPeersSet);
while (it.hasNext()) { while (it.hasNext()) {
const QString &ip = it.next(); const QString &ip = it.next();
m_missingFlags.remove(ip); m_missingFlags.remove(ip);

10
src/gui/properties/peersadditiondlg.cpp

@ -61,7 +61,7 @@ void PeersAdditionDlg::validateInput()
QMessageBox::Ok); QMessageBox::Ok);
return; return;
} }
foreach (const QString &peer, m_ui->peers_txt->toPlainText().trimmed().split("\n")) { foreach (const QString &peer, m_ui->peers_txt->toPlainText().trimmed().split('\n')) {
BitTorrent::PeerAddress addr = parsePeer(peer); BitTorrent::PeerAddress addr = parsePeer(peer);
if (!addr.ip.isNull()) { if (!addr.ip.isNull()) {
m_peersList.append(addr); m_peersList.append(addr);
@ -82,10 +82,10 @@ BitTorrent::PeerAddress PeersAdditionDlg::parsePeer(QString peer)
BitTorrent::PeerAddress addr; BitTorrent::PeerAddress addr;
QStringList ipPort; QStringList ipPort;
if (peer[0] == '[' && peer.indexOf("]:") != -1) // IPv6 if ((peer[0] == '[') && (peer.indexOf("]:") != -1)) // IPv6
ipPort = peer.remove(QChar('[')).split("]:"); ipPort = peer.remove(QChar('[')).split("]:");
else if (peer.indexOf(":") != -1) // IPv4 else if (peer.indexOf(':') != -1) // IPv4
ipPort = peer.split(":"); ipPort = peer.split(':');
else else
return addr; return addr;
@ -95,7 +95,7 @@ BitTorrent::PeerAddress PeersAdditionDlg::parsePeer(QString peer)
bool ok; bool ok;
int port = ipPort[1].toInt(&ok); int port = ipPort[1].toInt(&ok);
if (!ok || port < 1 || port > 65535) if (!ok || (port < 1) || (port > 65535))
return addr; return addr;
addr.ip = ip; addr.ip = ip;

2
src/gui/properties/pieceavailabilitybar.cpp

@ -109,7 +109,7 @@ QVector<float> PieceAvailabilityBar::intToFloatVector(const QVector<int> &vecin,
// normalization <0, 1> // normalization <0, 1>
value /= ratio * maxElement; value /= ratio * maxElement;
// float precision sometimes gives > 1, because in not possible to store irrational numbers // float precision sometimes gives > 1, because it's not possible to store irrational numbers
value = qMin(value, 1.0f); value = qMin(value, 1.0f);
result[x] = value; result[x] = value;

2
src/gui/properties/piecesbar.cpp

@ -50,7 +50,7 @@ namespace
{ {
public: public:
PieceIndexToImagePos(const BitTorrent::TorrentInfo &torrentInfo, const QImage &image) PieceIndexToImagePos(const BitTorrent::TorrentInfo &torrentInfo, const QImage &image)
: m_bytesPerPixel {(image.width() > 0 && torrentInfo.totalSize() >= image.width()) : m_bytesPerPixel {((image.width() > 0) && (torrentInfo.totalSize() >= image.width()))
? torrentInfo.totalSize() / image.width() : -1} ? torrentInfo.totalSize() / image.width() : -1}
, m_torrentInfo {torrentInfo} , m_torrentInfo {torrentInfo}
{ {

16
src/gui/properties/propertieswidget.cpp

@ -357,7 +357,7 @@ void PropertiesWidget::readSettings()
{ {
const Preferences *const pref = Preferences::instance(); const Preferences *const pref = Preferences::instance();
// Restore splitter sizes // Restore splitter sizes
QStringList sizesStr = pref->getPropSplitterSizes().split(","); QStringList sizesStr = pref->getPropSplitterSizes().split(',');
if (sizesStr.size() == 2) { if (sizesStr.size() == 2) {
m_slideSizes << sizesStr.first().toInt(); m_slideSizes << sizesStr.first().toInt();
m_slideSizes << sizesStr.last().toInt(); m_slideSizes << sizesStr.last().toInt();
@ -561,7 +561,7 @@ void PropertiesWidget::openFolder(const QModelIndex &index, bool containingFolde
if (pathItems.isEmpty()) if (pathItems.isEmpty())
return; return;
const QDir saveDir(m_torrent->savePath(true)); const QDir saveDir(m_torrent->savePath(true));
const QString relativePath = pathItems.join("/"); const QString relativePath = pathItems.join('/');
absolutePath = Utils::Fs::expandPath(saveDir.absoluteFilePath(relativePath)); absolutePath = Utils::Fs::expandPath(saveDir.absoluteFilePath(relativePath));
} }
else { else {
@ -743,15 +743,15 @@ void PropertiesWidget::renameSelectedFile()
pathItems.prepend(parent.data().toString()); pathItems.prepend(parent.data().toString());
parent = m_propListModel->parent(parent); parent = m_propListModel->parent(parent);
} }
const QString oldPath = pathItems.join("/"); const QString oldPath = pathItems.join('/');
pathItems.removeLast(); pathItems.removeLast();
pathItems << newName; pathItems << newName;
QString newPath = pathItems.join("/"); QString newPath = pathItems.join('/');
if (Utils::Fs::sameFileNames(oldPath, newPath)) { if (Utils::Fs::sameFileNames(oldPath, newPath)) {
qDebug("Name did not change"); qDebug("Name did not change");
return; return;
} }
if (!newPath.endsWith("/")) newPath += "/"; if (!newPath.endsWith('/')) newPath += '/';
// Check for overwriting // Check for overwriting
for (int i = 0; i < m_torrent->filesCount(); ++i) { for (int i = 0; i < m_torrent->filesCount(); ++i) {
const QString &currentName = m_torrent->filePath(i); const QString &currentName = m_torrent->filePath(i);
@ -785,9 +785,9 @@ void PropertiesWidget::renameSelectedFile()
// Rename folder in torrent files model too // Rename folder in torrent files model too
m_propListModel->setData(modelIndex, newName); m_propListModel->setData(modelIndex, newName);
// Remove old folder // Remove old folder
const QDir oldFolder(m_torrent->savePath(true) + "/" + oldPath); const QDir oldFolder(m_torrent->savePath(true) + '/' + oldPath);
int timeout = 10; int timeout = 10;
while (!QDir().rmpath(oldFolder.absolutePath()) && timeout > 0) { while (!QDir().rmpath(oldFolder.absolutePath()) && (timeout > 0)) {
// FIXME: We should not sleep here (freezes the UI for 1 second) // FIXME: We should not sleep here (freezes the UI for 1 second)
QThread::msleep(100); QThread::msleep(100);
--timeout; --timeout;
@ -847,7 +847,7 @@ void PropertiesWidget::copySelectedWebSeedsToClipboard() const
foreach (QListWidgetItem *item, selectedItems) foreach (QListWidgetItem *item, selectedItems)
urlsToCopy << item->text(); urlsToCopy << item->text();
QApplication::clipboard()->setText(urlsToCopy.join("\n")); QApplication::clipboard()->setText(urlsToCopy.join('\n'));
} }
void PropertiesWidget::editWebSeed() void PropertiesWidget::editWebSeed()

4
src/gui/properties/speedplotview.cpp

@ -161,7 +161,7 @@ int SpeedPlotView::maxYValue()
if (!m_properties[static_cast<GraphID>(id)].enable) if (!m_properties[static_cast<GraphID>(id)].enable)
continue; continue;
for (int i = int(queue.size()) - 1, j = 0; i >= 0 && j <= m_viewablePointsCount; --i, ++j) for (int i = static_cast<int>(queue.size()) - 1, j = 0; (i >= 0) && (j <= m_viewablePointsCount); --i, ++j)
if (queue[i].y[id] > maxYValue) if (queue[i].y[id] > maxYValue)
maxYValue = queue[i].y[id]; maxYValue = queue[i].y[id];
} }
@ -241,7 +241,7 @@ void SpeedPlotView::paintEvent(QPaintEvent *)
continue; continue;
QVector<QPoint> points; QVector<QPoint> points;
for (int i = int(queue.size()) - 1, j = 0; i >= 0 && j <= m_viewablePointsCount; --i, ++j) { for (int i = static_cast<int>(queue.size()) - 1, j = 0; (i >= 0) && (j <= m_viewablePointsCount); --i, ++j) {
int newX = rect.right() - j * xTickSize; int newX = rect.right() - j * xTickSize;
int newY = rect.bottom() - queue[i].y[id] * yMultiplier; int newY = rect.bottom() - queue[i].y[id] * yMultiplier;

2
src/gui/properties/speedwidget.h

@ -47,7 +47,7 @@ class ComboBoxMenuButton : public QComboBox
public: public:
ComboBoxMenuButton(QWidget *parent, QMenu *menu); ComboBoxMenuButton(QWidget *parent, QMenu *menu);
virtual void showPopup(); void showPopup() override;
private: private:
QMenu *m_menu; QMenu *m_menu;

2
src/gui/properties/trackerlist.cpp

@ -411,7 +411,7 @@ void TrackerList::copyTrackerUrl()
qDebug() << QString("Copy: ") + trackerURL; qDebug() << QString("Copy: ") + trackerURL;
urlsToCopy << trackerURL; urlsToCopy << trackerURL;
} }
QApplication::clipboard()->setText(urlsToCopy.join("\n")); QApplication::clipboard()->setText(urlsToCopy.join('\n'));
} }

10
src/gui/properties/trackersadditiondlg.cpp

@ -59,7 +59,7 @@ TrackersAdditionDlg::~TrackersAdditionDlg()
QStringList TrackersAdditionDlg::newTrackers() const QStringList TrackersAdditionDlg::newTrackers() const
{ {
QStringList cleanTrackers; QStringList cleanTrackers;
foreach (QString url, m_ui->trackers_list->toPlainText().split("\n")) { foreach (QString url, m_ui->trackers_list->toPlainText().split('\n')) {
url = url.trimmed(); url = url.trimmed();
if (!url.isEmpty()) if (!url.isEmpty())
cleanTrackers << url; cleanTrackers << url;
@ -92,7 +92,7 @@ void TrackersAdditionDlg::parseUTorrentList(const QString &, const QString &path
// Load from torrent handle // Load from torrent handle
QList<BitTorrent::TrackerEntry> existingTrackers = m_torrent->trackers(); QList<BitTorrent::TrackerEntry> existingTrackers = m_torrent->trackers();
// Load from current user list // Load from current user list
QStringList tmp = m_ui->trackers_list->toPlainText().split("\n"); QStringList tmp = m_ui->trackers_list->toPlainText().split('\n');
foreach (const QString &userURL, tmp) { foreach (const QString &userURL, tmp) {
BitTorrent::TrackerEntry userTracker(userURL); BitTorrent::TrackerEntry userTracker(userURL);
if (!existingTrackers.contains(userTracker)) if (!existingTrackers.contains(userTracker))
@ -100,7 +100,7 @@ void TrackersAdditionDlg::parseUTorrentList(const QString &, const QString &path
} }
// Add new trackers to the list // Add new trackers to the list
if (!m_ui->trackers_list->toPlainText().isEmpty() && !m_ui->trackers_list->toPlainText().endsWith("\n")) if (!m_ui->trackers_list->toPlainText().isEmpty() && !m_ui->trackers_list->toPlainText().endsWith('\n'))
m_ui->trackers_list->insertPlainText("\n"); m_ui->trackers_list->insertPlainText("\n");
int nb = 0; int nb = 0;
while (!listFile.atEnd()) { while (!listFile.atEnd()) {
@ -108,7 +108,7 @@ void TrackersAdditionDlg::parseUTorrentList(const QString &, const QString &path
if (line.isEmpty()) continue; if (line.isEmpty()) continue;
BitTorrent::TrackerEntry newTracker(line); BitTorrent::TrackerEntry newTracker(line);
if (!existingTrackers.contains(newTracker)) { if (!existingTrackers.contains(newTracker)) {
m_ui->trackers_list->insertPlainText(line + "\n"); m_ui->trackers_list->insertPlainText(line + '\n');
++nb; ++nb;
} }
} }
@ -125,7 +125,7 @@ void TrackersAdditionDlg::parseUTorrentList(const QString &, const QString &path
void TrackersAdditionDlg::getTrackerError(const QString &, const QString &error) void TrackersAdditionDlg::getTrackerError(const QString &, const QString &error)
{ {
//To restore the cursor ... // To restore the cursor ...
setCursor(Qt::ArrowCursor); setCursor(Qt::ArrowCursor);
m_ui->uTorrentListButton->setEnabled(true); m_ui->uTorrentListButton->setEnabled(true);
QMessageBox::warning(this, tr("Download error"), tr("The trackers list could not be downloaded, reason: %1").arg(error), QMessageBox::Ok); QMessageBox::warning(this, tr("Download error"), tr("The trackers list could not be downloaded, reason: %1").arg(error), QMessageBox::Ok);

18
src/gui/scanfoldersdelegate.cpp

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2015 sledgehammer999 * Copyright (C) 2015 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
@ -24,21 +24,19 @@
* 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 : hammered999@gmail.com
*/ */
#include <QDebug> #include "scanfoldersdelegate.h"
#include <QPainter>
#include <QComboBox> #include <QComboBox>
#include <QDebug>
#include <QFileDialog> #include <QFileDialog>
#include <QTreeView>
#include <QItemSelectionModel> #include <QItemSelectionModel>
#include <QPainter>
#include <QTreeView>
#include "base/scanfoldersmodel.h"
#include "base/bittorrent/session.h" #include "base/bittorrent/session.h"
#include "scanfoldersdelegate.h" #include "base/scanfoldersmodel.h"
ScanFoldersDelegate::ScanFoldersDelegate(QObject *parent, QTreeView *foldersView) ScanFoldersDelegate::ScanFoldersDelegate(QObject *parent, QTreeView *foldersView)
: QItemDelegate(parent) : QItemDelegate(parent)
@ -60,7 +58,7 @@ QWidget *ScanFoldersDelegate::createEditor(QWidget *parent, const QStyleOptionVi
{ {
if (index.column() != ScanFoldersModel::DOWNLOAD) return 0; if (index.column() != ScanFoldersModel::DOWNLOAD) return 0;
QComboBox* editor = new QComboBox(parent); QComboBox *editor = new QComboBox(parent);
editor->setFocusPolicy(Qt::StrongFocus); editor->setFocusPolicy(Qt::StrongFocus);
editor->addItem(ScanFoldersModel::pathTypeDisplayName(ScanFoldersModel::DOWNLOAD_IN_WATCH_FOLDER)); editor->addItem(ScanFoldersModel::pathTypeDisplayName(ScanFoldersModel::DOWNLOAD_IN_WATCH_FOLDER));

19
src/gui/scanfoldersdelegate.h

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2015 sledgehammer999 * Copyright (C) 2015 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
@ -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 : hammered999@gmail.com
*/ */
#ifndef SCANFOLDERSDELEGATE_H #ifndef SCANFOLDERSDELEGATE_H
@ -33,12 +31,12 @@
#include <QItemDelegate> #include <QItemDelegate>
class QPainter; class QAbstractItemModel;
class QModelIndex; class QModelIndex;
class QPainter;
class QStyleOptionViewItem; class QStyleOptionViewItem;
class QAbstractItemModel;
class PropertiesWidget;
class QTreeView; class QTreeView;
class PropertiesWidget;
class ScanFoldersDelegate : public QItemDelegate class ScanFoldersDelegate : public QItemDelegate
{ {
@ -51,13 +49,12 @@ private slots:
void comboboxIndexChanged(int index); void comboboxIndexChanged(int index);
private: private:
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const; void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const; void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const override;
void setEditorData(QWidget *editor, const QModelIndex &index) const; void setEditorData(QWidget *editor, const QModelIndex &index) const override;
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const; QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const override;
QTreeView *m_folderView; QTreeView *m_folderView;
}; };
#endif // SCANFOLDERSDELEGATE_H #endif // SCANFOLDERSDELEGATE_H

4
src/gui/shutdownconfirmdlg.cpp

@ -131,12 +131,12 @@ void ShutdownConfirmDlg::initText()
break; break;
} }
m_msg += "\n"; m_msg += '\n';
updateText(); updateText();
} }
void ShutdownConfirmDlg::updateText() void ShutdownConfirmDlg::updateText()
{ {
QString t = tr("You can cancel the action within %1 seconds.").arg(QString::number(m_timeout)) + "\n"; QString t = tr("You can cancel the action within %1 seconds.").arg(QString::number(m_timeout)) + '\n';
m_ui->shutdownText->setText(m_msg + t); m_ui->shutdownText->setText(m_msg + t);
} }

20
src/gui/speedlimitdlg.cpp

@ -54,17 +54,17 @@ SpeedLimitDialog::~SpeedLimitDialog()
} }
// -2: if cancel // -2: if cancel
long SpeedLimitDialog::askSpeedLimit(QWidget *parent, bool *ok, QString title, long default_value, long max_value) long SpeedLimitDialog::askSpeedLimit(QWidget *parent, bool *ok, QString title, long defaultVal, long maxVal)
{ {
SpeedLimitDialog dlg(parent); SpeedLimitDialog dlg(parent);
dlg.setWindowTitle(title); dlg.setWindowTitle(title);
dlg.setupDialog(max_value / 1024., default_value / 1024.); dlg.setupDialog(maxVal / 1024., defaultVal / 1024.);
if (dlg.exec() == QDialog::Accepted) { if (dlg.exec() == QDialog::Accepted) {
*ok = true; *ok = true;
int val = dlg.getSpeedLimit(); int val = dlg.getSpeedLimit();
if (val <= 0) if (val <= 0)
return 0; return 0;
return val * 1024; return (val * 1024);
} }
else { else {
*ok = false; *ok = false;
@ -82,7 +82,7 @@ void SpeedLimitDialog::updateSpinValue(int val) const
} }
else { else {
m_ui->spinBandwidth->setValue(val); m_ui->spinBandwidth->setValue(val);
m_ui->spinBandwidth->setSuffix(" " + tr("KiB/s")); m_ui->spinBandwidth->setSuffix(' ' + tr("KiB/s"));
} }
} }
@ -106,17 +106,17 @@ long SpeedLimitDialog::getSpeedLimit() const
return -1; return -1;
} }
void SpeedLimitDialog::setupDialog(long max_slider, long val) const void SpeedLimitDialog::setupDialog(long maxSlider, long val) const
{ {
if (val < 0) if (val < 0)
val = 0; val = 0;
if (max_slider <= 0) if (maxSlider <= 0)
max_slider = 10000; maxSlider = 10000;
// This can happen for example if global rate limit is lower // This can happen for example if global rate limit is lower
// than torrent rate limit. // than torrent rate limit.
if (val > max_slider) if (val > maxSlider)
max_slider = val; maxSlider = val;
m_ui->bandwidthSlider->setMaximum(max_slider); m_ui->bandwidthSlider->setMaximum(maxSlider);
m_ui->bandwidthSlider->setValue(val); m_ui->bandwidthSlider->setValue(val);
updateSpinValue(val); updateSpinValue(val);
} }

4
src/gui/speedlimitdlg.h

@ -47,12 +47,12 @@ class SpeedLimitDialog : public QDialog
public: public:
explicit SpeedLimitDialog(QWidget *parent); explicit SpeedLimitDialog(QWidget *parent);
~SpeedLimitDialog(); ~SpeedLimitDialog();
static long askSpeedLimit(QWidget *parent, bool *ok, QString title, long default_value, long max_value=10240000); static long askSpeedLimit(QWidget *parent, bool *ok, QString title, long defaultVal, long maxVal=10240000);
protected slots: protected slots:
void updateSpinValue(int val) const; void updateSpinValue(int val) const;
void updateSliderValue(int val) const; void updateSliderValue(int val) const;
void setupDialog(long max_slider, long val) const; void setupDialog(long maxSlider, long val) const;
private: private:
long getSpeedLimit() const; long getSpeedLimit() const;

2
src/gui/statsdialog.h

@ -36,7 +36,7 @@ namespace Ui
class StatsDialog; class StatsDialog;
} }
class StatsDialog: public QDialog class StatsDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT

2
src/gui/statusbar.h

@ -39,7 +39,7 @@ namespace BitTorrent
struct SessionStatus; struct SessionStatus;
} }
class StatusBar: public QStatusBar class StatusBar : public QStatusBar
{ {
Q_OBJECT Q_OBJECT
Q_DISABLE_COPY(StatusBar) Q_DISABLE_COPY(StatusBar)

4
src/gui/tagfiltermodel.cpp

@ -113,7 +113,7 @@ bool TagFilterModel::isSpecialItem(const QModelIndex &index)
QVariant TagFilterModel::data(const QModelIndex &index, int role) const QVariant TagFilterModel::data(const QModelIndex &index, int role) const
{ {
if (!index.isValid() || index.column() != 0) if (!index.isValid() || (index.column() != 0))
return QVariant(); return QVariant();
const int row = index.internalId(); const int row = index.internalId();
@ -214,7 +214,7 @@ void TagFilterModel::torrentTagAdded(BitTorrent::TorrentHandle *const torrent, c
emit dataChanged(i, i); emit dataChanged(i, i);
} }
void TagFilterModel::torrentTagRemoved(BitTorrent::TorrentHandle* const torrent, const QString &tag) void TagFilterModel::torrentTagRemoved(BitTorrent::TorrentHandle *const torrent, const QString &tag)
{ {
Q_ASSERT(torrent->tags().count() >= 0); Q_ASSERT(torrent->tags().count() >= 0);
if (torrent->tags().count() == 0) if (torrent->tags().count() == 0)

2
src/gui/tagfiltermodel.h

@ -42,7 +42,7 @@ namespace BitTorrent
class TagModelItem; class TagModelItem;
class TagFilterModel: public QAbstractListModel class TagFilterModel : public QAbstractListModel
{ {
Q_OBJECT Q_OBJECT

2
src/gui/tagfilterproxymodel.h

@ -32,7 +32,7 @@
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include <QString> #include <QString>
class TagFilterProxyModel: public QSortFilterProxyModel class TagFilterProxyModel : public QSortFilterProxyModel
{ {
public: public:
explicit TagFilterProxyModel(QObject *parent = nullptr); explicit TagFilterProxyModel(QObject *parent = nullptr);

2
src/gui/tagfilterwidget.h

@ -31,7 +31,7 @@
#include <QTreeView> #include <QTreeView>
class TagFilterWidget: public QTreeView class TagFilterWidget : public QTreeView
{ {
Q_OBJECT Q_OBJECT

8
src/gui/torrentcontentfiltermodel.h

@ -35,7 +35,7 @@
class TorrentContentModel; class TorrentContentModel;
class TorrentContentFilterModel: public QSortFilterProxyModel class TorrentContentFilterModel : public QSortFilterProxyModel
{ {
Q_OBJECT Q_OBJECT
@ -46,7 +46,7 @@ public:
TorrentContentModel *model() const; TorrentContentModel *model() const;
TorrentContentModelItem::ItemType itemType(const QModelIndex &index) const; TorrentContentModelItem::ItemType itemType(const QModelIndex &index) const;
int getFileIndex(const QModelIndex &index) const; int getFileIndex(const QModelIndex &index) const;
virtual QModelIndex parent(const QModelIndex &child) const; QModelIndex parent(const QModelIndex &child) const override;
public slots: public slots:
void selectAll(); void selectAll();
@ -56,8 +56,8 @@ signals:
void filteredFilesChanged(); void filteredFilesChanged();
protected: protected:
virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const; bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
private: private:
TorrentContentModel *m_model; TorrentContentModel *m_model;

65
src/gui/torrentcontentmodel.cpp

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2006-2012 Christophe Dumez * Copyright (C) 2006-2012 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 <QDir> #include <QDir>
@ -48,13 +46,14 @@
#include <QPixmapCache> #include <QPixmapCache>
#endif #endif
#include "guiiconprovider.h"
#include "base/utils/misc.h" #include "base/utils/misc.h"
#include "base/utils/fs.h" #include "base/utils/fs.h"
#include "guiiconprovider.h"
#include "torrentcontentmodel.h" #include "torrentcontentmodel.h"
#include "torrentcontentmodelitem.h"
#include "torrentcontentmodelfolder.h"
#include "torrentcontentmodelfile.h" #include "torrentcontentmodelfile.h"
#include "torrentcontentmodelfolder.h"
#include "torrentcontentmodelitem.h"
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
#include "macutilities.h" #include "macutilities.h"
#endif #endif
@ -67,7 +66,7 @@ namespace
return cached; return cached;
} }
class UnifiedFileIconProvider: public QFileIconProvider class UnifiedFileIconProvider : public QFileIconProvider
{ {
public: public:
using QFileIconProvider::icon; using QFileIconProvider::icon;
@ -99,7 +98,7 @@ namespace
PixmapCacheSetup pixmapCacheSetup; PixmapCacheSetup pixmapCacheSetup;
class CachingFileIconProvider: public UnifiedFileIconProvider class CachingFileIconProvider : public UnifiedFileIconProvider
{ {
public: public:
using QFileIconProvider::icon; using QFileIconProvider::icon;
@ -123,11 +122,11 @@ namespace
protected: protected:
virtual QPixmap pixmapForExtension(const QString &ext) const = 0; virtual QPixmap pixmapForExtension(const QString &ext) const = 0;
}; };
#endif #endif // QBT_PIXMAP_CACHE_FOR_FILE_ICONS
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
// See QTBUG-25319 for explanation why this is required // See QTBUG-25319 for explanation why this is required
class WinShellFileIconProvider final: public CachingFileIconProvider class WinShellFileIconProvider final : public CachingFileIconProvider
{ {
QPixmap pixmapForExtension(const QString &ext) const override QPixmap pixmapForExtension(const QString &ext) const override
{ {
@ -174,7 +173,7 @@ namespace
return (!testIcon1.isNull() || !testIcon2.isNull()); return (!testIcon1.isNull() || !testIcon2.isNull());
} }
class MimeFileIconProvider: public UnifiedFileIconProvider class MimeFileIconProvider : public UnifiedFileIconProvider
{ {
using QFileIconProvider::icon; using QFileIconProvider::icon;
@ -197,7 +196,7 @@ namespace
private: private:
QMimeDatabase m_db; QMimeDatabase m_db;
}; };
#endif #endif // Q_OS_WIN
} }
TorrentContentModel::TorrentContentModel(QObject *parent) TorrentContentModel::TorrentContentModel(QObject *parent)
@ -266,20 +265,20 @@ QVector<int> TorrentContentModel::getFilePriorities() const
{ {
QVector<int> prio; QVector<int> prio;
prio.reserve(m_filesIndex.size()); prio.reserve(m_filesIndex.size());
foreach (const TorrentContentModelFile* file, m_filesIndex) foreach (const TorrentContentModelFile *file, m_filesIndex)
prio.push_back(file->priority()); prio.push_back(file->priority());
return prio; return prio;
} }
bool TorrentContentModel::allFiltered() const bool TorrentContentModel::allFiltered() const
{ {
foreach (const TorrentContentModelFile* fileItem, m_filesIndex) foreach (const TorrentContentModelFile *fileItem, m_filesIndex)
if (fileItem->priority() != prio::IGNORED) if (fileItem->priority() != prio::IGNORED)
return false; return false;
return true; return true;
} }
int TorrentContentModel::columnCount(const QModelIndex& parent) const int TorrentContentModel::columnCount(const QModelIndex &parent) const
{ {
if (parent.isValid()) if (parent.isValid())
return static_cast<TorrentContentModelItem*>(parent.internalPointer())->columnCount(); return static_cast<TorrentContentModelItem*>(parent.internalPointer())->columnCount();
@ -287,7 +286,7 @@ int TorrentContentModel::columnCount(const QModelIndex& parent) const
return m_rootItem->columnCount(); return m_rootItem->columnCount();
} }
bool TorrentContentModel::setData(const QModelIndex& index, const QVariant& value, int role) bool TorrentContentModel::setData(const QModelIndex &index, const QVariant &value, int role)
{ {
if (!index.isValid()) if (!index.isValid())
return false; return false;
@ -313,7 +312,7 @@ bool TorrentContentModel::setData(const QModelIndex& index, const QVariant& valu
if (role == Qt::EditRole) { if (role == Qt::EditRole) {
Q_ASSERT(index.isValid()); Q_ASSERT(index.isValid());
TorrentContentModelItem* item = static_cast<TorrentContentModelItem*>(index.internalPointer()); TorrentContentModelItem *item = static_cast<TorrentContentModelItem*>(index.internalPointer());
switch (index.column()) { switch (index.column()) {
case TorrentContentModelItem::COL_NAME: case TorrentContentModelItem::COL_NAME:
item->setName(value.toString()); item->setName(value.toString());
@ -331,12 +330,12 @@ bool TorrentContentModel::setData(const QModelIndex& index, const QVariant& valu
return false; return false;
} }
TorrentContentModelItem::ItemType TorrentContentModel::itemType(const QModelIndex& index) const TorrentContentModelItem::ItemType TorrentContentModel::itemType(const QModelIndex &index) const
{ {
return static_cast<const TorrentContentModelItem*>(index.internalPointer())->itemType(); return static_cast<const TorrentContentModelItem*>(index.internalPointer())->itemType();
} }
int TorrentContentModel::getFileIndex(const QModelIndex& index) int TorrentContentModel::getFileIndex(const QModelIndex &index)
{ {
TorrentContentModelItem *item = static_cast<TorrentContentModelItem*>(index.internalPointer()); TorrentContentModelItem *item = static_cast<TorrentContentModelItem*>(index.internalPointer());
if (item->itemType() == TorrentContentModelItem::FileType) if (item->itemType() == TorrentContentModelItem::FileType)
@ -351,7 +350,7 @@ QVariant TorrentContentModel::data(const QModelIndex& index, int role) const
if (!index.isValid()) if (!index.isValid())
return QVariant(); return QVariant();
TorrentContentModelItem* item = static_cast<TorrentContentModelItem*>(index.internalPointer()); TorrentContentModelItem *item = static_cast<TorrentContentModelItem*>(index.internalPointer());
if ((index.column() == TorrentContentModelItem::COL_NAME) && (role == Qt::DecorationRole)) { if ((index.column() == TorrentContentModelItem::COL_NAME) && (role == Qt::DecorationRole)) {
if (item->itemType() == TorrentContentModelItem::FolderType) if (item->itemType() == TorrentContentModelItem::FolderType)
@ -374,7 +373,7 @@ QVariant TorrentContentModel::data(const QModelIndex& index, int role) const
return QVariant(); return QVariant();
} }
Qt::ItemFlags TorrentContentModel::flags(const QModelIndex& index) const Qt::ItemFlags TorrentContentModel::flags(const QModelIndex &index) const
{ {
if (!index.isValid()) if (!index.isValid())
return 0; return 0;
@ -393,7 +392,7 @@ QVariant TorrentContentModel::headerData(int section, Qt::Orientation orientatio
return QVariant(); return QVariant();
} }
QModelIndex TorrentContentModel::index(int row, int column, const QModelIndex& parent) const QModelIndex TorrentContentModel::index(int row, int column, const QModelIndex &parent) const
{ {
if (parent.isValid() && (parent.column() != 0)) if (parent.isValid() && (parent.column() != 0))
return QModelIndex(); return QModelIndex();
@ -401,7 +400,7 @@ QModelIndex TorrentContentModel::index(int row, int column, const QModelIndex& p
if (column >= TorrentContentModelItem::NB_COL) if (column >= TorrentContentModelItem::NB_COL)
return QModelIndex(); return QModelIndex();
TorrentContentModelFolder* parentItem; TorrentContentModelFolder *parentItem;
if (!parent.isValid()) if (!parent.isValid())
parentItem = m_rootItem; parentItem = m_rootItem;
else else
@ -411,18 +410,18 @@ QModelIndex TorrentContentModel::index(int row, int column, const QModelIndex& p
if (row >= parentItem->childCount()) if (row >= parentItem->childCount())
return QModelIndex(); return QModelIndex();
TorrentContentModelItem* childItem = parentItem->child(row); TorrentContentModelItem *childItem = parentItem->child(row);
if (childItem) if (childItem)
return createIndex(row, column, childItem); return createIndex(row, column, childItem);
return QModelIndex(); return QModelIndex();
} }
QModelIndex TorrentContentModel::parent(const QModelIndex& index) const QModelIndex TorrentContentModel::parent(const QModelIndex &index) const
{ {
if (!index.isValid()) if (!index.isValid())
return QModelIndex(); return QModelIndex();
TorrentContentModelItem* childItem = static_cast<TorrentContentModelItem*>(index.internalPointer()); TorrentContentModelItem *childItem = static_cast<TorrentContentModelItem*>(index.internalPointer());
if (!childItem) if (!childItem)
return QModelIndex(); return QModelIndex();
@ -433,12 +432,12 @@ QModelIndex TorrentContentModel::parent(const QModelIndex& index) const
return createIndex(parentItem->row(), 0, parentItem); return createIndex(parentItem->row(), 0, parentItem);
} }
int TorrentContentModel::rowCount(const QModelIndex& parent) const int TorrentContentModel::rowCount(const QModelIndex &parent) const
{ {
if (parent.column() > 0) if (parent.column() > 0)
return 0; return 0;
TorrentContentModelFolder* parentItem; TorrentContentModelFolder *parentItem;
if (!parent.isValid()) if (!parent.isValid())
parentItem = m_rootItem; parentItem = m_rootItem;
else else
@ -468,15 +467,15 @@ void TorrentContentModel::setupModelData(const BitTorrent::TorrentInfo &info)
qDebug("Torrent contains %d files", filesCount); qDebug("Torrent contains %d files", filesCount);
m_filesIndex.reserve(filesCount); m_filesIndex.reserve(filesCount);
TorrentContentModelFolder* currentParent; TorrentContentModelFolder *currentParent;
// Iterate over files // Iterate over files
for (int i = 0; i < filesCount; ++i) { for (int i = 0; i < filesCount; ++i) {
currentParent = m_rootItem; currentParent = m_rootItem;
QString path = Utils::Fs::fromNativePath(info.filePath(i)); QString path = Utils::Fs::fromNativePath(info.filePath(i));
// Iterate of parts of the path to create necessary folders // Iterate of parts of the path to create necessary folders
QStringList pathFolders = path.split("/", QString::SkipEmptyParts); QStringList pathFolders = path.split('/', QString::SkipEmptyParts);
pathFolders.removeLast(); pathFolders.removeLast();
foreach (const QString& pathPart, pathFolders) { foreach (const QString &pathPart, pathFolders) {
if (pathPart == ".unwanted") if (pathPart == ".unwanted")
continue; continue;
TorrentContentModelFolder* newParent = currentParent->childFolderWithName(pathPart); TorrentContentModelFolder* newParent = currentParent->childFolderWithName(pathPart);
@ -487,7 +486,7 @@ void TorrentContentModel::setupModelData(const BitTorrent::TorrentInfo &info)
currentParent = newParent; currentParent = newParent;
} }
// Actually create the file // Actually create the file
TorrentContentModelFile* fileItem = new TorrentContentModelFile(info.fileName(i), info.fileSize(i), currentParent, i); TorrentContentModelFile *fileItem = new TorrentContentModelFile(info.fileName(i), info.fileSize(i), currentParent, i);
currentParent->appendChild(fileItem); currentParent->appendChild(fileItem);
m_filesIndex.push_back(fileItem); m_filesIndex.push_back(fileItem);
} }

24
src/gui/torrentcontentmodel.h

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2006-2012 Christophe Dumez * Copyright (C) 2006-2012 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 TORRENTCONTENTMODEL_H #ifndef TORRENTCONTENTMODEL_H
@ -33,8 +31,8 @@
#include <QAbstractItemModel> #include <QAbstractItemModel>
#include <QModelIndex> #include <QModelIndex>
#include <QVector>
#include <QVariant> #include <QVariant>
#include <QVector>
#include "base/bittorrent/torrentinfo.h" #include "base/bittorrent/torrentinfo.h"
#include "torrentcontentmodelitem.h" #include "torrentcontentmodelitem.h"
@ -42,7 +40,7 @@
class QFileIconProvider; class QFileIconProvider;
class TorrentContentModelFile; class TorrentContentModelFile;
class TorrentContentModel: public QAbstractItemModel class TorrentContentModel : public QAbstractItemModel
{ {
Q_OBJECT Q_OBJECT
@ -56,15 +54,15 @@ public:
QVector<int> getFilePriorities() const; QVector<int> getFilePriorities() const;
bool allFiltered() const; bool allFiltered() const;
int columnCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override;
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override; bool setData(const QModelIndex &index, const QVariant& value, int role = Qt::EditRole) override;
TorrentContentModelItem::ItemType itemType(const QModelIndex& index) const; TorrentContentModelItem::ItemType itemType(const QModelIndex &index) const;
int getFileIndex(const QModelIndex& index); int getFileIndex(const QModelIndex &index);
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
Qt::ItemFlags flags(const QModelIndex& index) const override; Qt::ItemFlags flags(const QModelIndex &index) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override; QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override; QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
QModelIndex parent(const QModelIndex& index) const override; QModelIndex parent(const QModelIndex &index) const override;
int rowCount(const QModelIndex& parent = QModelIndex()) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
void clear(); void clear();
void setupModelData(const BitTorrent::TorrentInfo &info); void setupModelData(const BitTorrent::TorrentInfo &info);

6
src/gui/torrentcontentmodelfile.cpp

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2006-2012 Christophe Dumez * Copyright (C) 2006-2012 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 "torrentcontentmodelfile.h" #include "torrentcontentmodelfile.h"

8
src/gui/torrentcontentmodelfile.h

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2006-2012 Christophe Dumez * Copyright (C) 2006-2012 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 TORRENTCONTENTMODELFILE_H #ifndef TORRENTCONTENTMODELFILE_H
@ -33,7 +31,7 @@
#include "torrentcontentmodelitem.h" #include "torrentcontentmodelitem.h"
class TorrentContentModelFile: public TorrentContentModelItem class TorrentContentModelFile : public TorrentContentModelItem
{ {
public: public:
TorrentContentModelFile(const QString &fileName, qulonglong fileSize, TorrentContentModelFile(const QString &fileName, qulonglong fileSize,

8
src/gui/torrentcontentmodelfolder.cpp

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2006-2012 Christophe Dumez * Copyright (C) 2006-2012 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 "torrentcontentmodelfolder.h" #include "torrentcontentmodelfolder.h"
@ -165,7 +163,7 @@ void TorrentContentModelFolder::recalculateAvailability()
qreal tAvailability = 0; qreal tAvailability = 0;
qulonglong tSize = 0; qulonglong tSize = 0;
bool foundAnyData = false; bool foundAnyData = false;
foreach (TorrentContentModelItem* child, m_childItems) { foreach (TorrentContentModelItem *child, m_childItems) {
if (child->priority() == prio::IGNORED) if (child->priority() == prio::IGNORED)
continue; continue;

20
src/gui/torrentcontentmodelfolder.h

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2006-2012 Christophe Dumez * Copyright (C) 2006-2012 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 TORRENTCONTENTMODELFOLDER_H #ifndef TORRENTCONTENTMODELFOLDER_H
@ -33,14 +31,14 @@
#include "torrentcontentmodelitem.h" #include "torrentcontentmodelitem.h"
class TorrentContentModelFolder: public TorrentContentModelItem class TorrentContentModelFolder : public TorrentContentModelItem
{ {
public: public:
// Folder constructor // Folder constructor
TorrentContentModelFolder(const QString& name, TorrentContentModelFolder* parent); TorrentContentModelFolder(const QString &name, TorrentContentModelFolder *parent);
// Invisible root item constructor // Invisible root item constructor
TorrentContentModelFolder(const QList<QVariant>& data); TorrentContentModelFolder(const QList<QVariant> &data);
~TorrentContentModelFolder(); ~TorrentContentModelFolder();
@ -54,10 +52,10 @@ public:
void setPriority(int newPriority, bool updateParent = true) override; void setPriority(int newPriority, bool updateParent = true) override;
void deleteAllChildren(); void deleteAllChildren();
const QList<TorrentContentModelItem*>& children() const; const QList<TorrentContentModelItem*> &children() const;
void appendChild(TorrentContentModelItem* item); void appendChild(TorrentContentModelItem *item);
TorrentContentModelItem* child(int row) const; TorrentContentModelItem *child(int row) const;
TorrentContentModelFolder* childFolderWithName(const QString& name) const; TorrentContentModelFolder *childFolderWithName(const QString &name) const;
int childCount() const; int childCount() const;
private: private:

13
src/gui/torrentcontentmodelitem.cpp

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2006-2012 Christophe Dumez * Copyright (C) 2006-2012 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,15 +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 "torrentcontentmodelitem.h"
#include <QDebug>
#include "base/utils/misc.h" #include "base/utils/misc.h"
#include "base/utils/fs.h" #include "base/utils/fs.h"
#include "torrentcontentmodelitem.h"
#include "torrentcontentmodelfolder.h" #include "torrentcontentmodelfolder.h"
#include <QDebug>
TorrentContentModelItem::TorrentContentModelItem(TorrentContentModelFolder *parent) TorrentContentModelItem::TorrentContentModelItem(TorrentContentModelFolder *parent)
: m_parentItem(parent) : m_parentItem(parent)
@ -138,4 +138,3 @@ TorrentContentModelFolder *TorrentContentModelItem::parent() const
{ {
return m_parentItem; return m_parentItem;
} }

6
src/gui/torrentcontentmodelitem.h

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2006-2012 Christophe Dumez * Copyright (C) 2006-2012 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 TORRENTCONTENTMODELITEM_H #ifndef TORRENTCONTENTMODELITEM_H

4
src/gui/torrentcontenttreeview.h

@ -31,13 +31,13 @@
#include <QTreeView> #include <QTreeView>
class TorrentContentTreeView: public QTreeView class TorrentContentTreeView : public QTreeView
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit TorrentContentTreeView(QWidget *parent = nullptr); explicit TorrentContentTreeView(QWidget *parent = nullptr);
void keyPressEvent(QKeyEvent *event); void keyPressEvent(QKeyEvent *event) override;
private: private:
QModelIndex currentNameCell(); QModelIndex currentNameCell();

4
src/gui/torrentcreatordlg.h

@ -44,7 +44,7 @@ namespace BitTorrent
class TorrentCreatorThread; class TorrentCreatorThread;
} }
class TorrentCreatorDlg: public QDialog class TorrentCreatorDlg : public QDialog
{ {
Q_OBJECT Q_OBJECT
@ -89,4 +89,4 @@ private:
CachedSettingValue<QString> m_storeSource; CachedSettingValue<QString> m_storeSource;
}; };
#endif #endif // TORRENTCREATORDLG_H

9
src/gui/torrentmodel.cpp

@ -25,20 +25,19 @@
* 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 <QDebug> #include "torrentmodel.h"
#include <QApplication> #include <QApplication>
#include <QPalette> #include <QDebug>
#include <QIcon> #include <QIcon>
#include <QPalette>
#include "base/bittorrent/session.h" #include "base/bittorrent/session.h"
#include "base/bittorrent/torrenthandle.h" #include "base/bittorrent/torrenthandle.h"
#include "base/torrentfilter.h" #include "base/torrentfilter.h"
#include "base/utils/fs.h" #include "base/utils/fs.h"
#include "torrentmodel.h"
static QIcon getIconByState(BitTorrent::TorrentState state); static QIcon getIconByState(BitTorrent::TorrentState state);
static QColor getColorByState(BitTorrent::TorrentState state); static QColor getColorByState(BitTorrent::TorrentState state);

14
src/gui/torrentmodel.h

@ -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 TORRENTMODEL_H #ifndef TORRENTMODEL_H
@ -85,12 +83,12 @@ public:
explicit TorrentModel(QObject *parent = nullptr); explicit TorrentModel(QObject *parent = nullptr);
int rowCount(const QModelIndex& index = QModelIndex()) const; int rowCount(const QModelIndex& index = QModelIndex()) const override;
int columnCount(const QModelIndex &parent=QModelIndex()) const; int columnCount(const QModelIndex &parent=QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::DisplayRole); bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::DisplayRole) override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
Qt::ItemFlags flags(const QModelIndex &index) const; Qt::ItemFlags flags(const QModelIndex &index) const override;
BitTorrent::TorrentHandle *torrentHandle(const QModelIndex &index) const; BitTorrent::TorrentHandle *torrentHandle(const QModelIndex &index) const;

6
src/gui/trackerlogin.cpp

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 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 "trackerlogin.h" #include "trackerlogin.h"

8
src/gui/trackerlogin.h

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 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 TRACKERLOGIN_H #ifndef TRACKERLOGIN_H
@ -58,4 +56,4 @@ class trackerLogin : public QDialog, private Ui::authentication{
void cancelButtonClicked(); void cancelButtonClicked();
}; };
#endif #endif // TRACKERLOGIN_H

195
src/gui/transferlistdelegate.cpp

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 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,35 +24,34 @@
* 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 "transferlistdelegate.h" #include "transferlistdelegate.h"
#include <QModelIndex>
#include <QStyleOptionViewItem>
#include <QApplication> #include <QApplication>
#include <QModelIndex>
#include <QPainter> #include <QPainter>
#include "base/utils/misc.h" #include <QStyleOptionViewItem>
#include "base/utils/string.h"
#include "torrentmodel.h"
#include "base/bittorrent/session.h"
#include "base/bittorrent/torrenthandle.h"
#include "base/types.h"
#include "base/preferences.h"
#include "base/unicodestrings.h"
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#include <QProxyStyle> #include <QProxyStyle>
#endif #endif
#include "base/bittorrent/session.h"
#include "base/bittorrent/torrenthandle.h"
#include "base/preferences.h"
#include "base/types.h"
#include "base/unicodestrings.h"
#include "base/utils/misc.h"
#include "base/utils/string.h"
#include "torrentmodel.h"
TransferListDelegate::TransferListDelegate(QObject *parent) TransferListDelegate::TransferListDelegate(QObject *parent)
: QItemDelegate(parent) : QItemDelegate(parent)
{ {
} }
void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const void TransferListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{ {
painter->save(); painter->save();
bool isHideState = true; bool isHideState = true;
@ -74,13 +73,13 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem
case TorrentModel::TR_COMPLETED: case TorrentModel::TR_COMPLETED:
case TorrentModel::TR_SIZE: case TorrentModel::TR_SIZE:
case TorrentModel::TR_TOTAL_SIZE: { case TorrentModel::TR_TOTAL_SIZE: {
qlonglong size = index.data().toLongLong(); qlonglong size = index.data().toLongLong();
if (hideValues && !size) if (hideValues && !size)
break; break;
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; opt.displayAlignment = (Qt::AlignRight | Qt::AlignVCenter);
QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(size)); QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(size));
}
break; break;
}
case TorrentModel::TR_ETA: { case TorrentModel::TR_ETA: {
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::userFriendlyDuration(index.data().toLongLong())); QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::userFriendlyDuration(index.data().toLongLong()));
@ -88,124 +87,124 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem
} }
case TorrentModel::TR_SEEDS: case TorrentModel::TR_SEEDS:
case TorrentModel::TR_PEERS: { case TorrentModel::TR_PEERS: {
qlonglong value = index.data().toLongLong(); qlonglong value = index.data().toLongLong();
qlonglong total = index.data(Qt::UserRole).toLongLong(); qlonglong total = index.data(Qt::UserRole).toLongLong();
if (hideValues && (!value && !total)) if (hideValues && (!value && !total))
break; break;
QString display = QString::number(value) + " (" + QString::number(total) + ")"; QString display = QString::number(value) + " (" + QString::number(total) + ")";
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
QItemDelegate::drawDisplay(painter, opt, opt.rect, display); QItemDelegate::drawDisplay(painter, opt, opt.rect, display);
}
break; break;
}
case TorrentModel::TR_STATUS: { case TorrentModel::TR_STATUS: {
const auto state = index.data().value<BitTorrent::TorrentState>(); const auto state = index.data().value<BitTorrent::TorrentState>();
QString display = getStatusString(state); QString display = getStatusString(state);
QItemDelegate::drawDisplay(painter, opt, opt.rect, display); QItemDelegate::drawDisplay(painter, opt, opt.rect, display);
}
break; break;
}
case TorrentModel::TR_UPSPEED: case TorrentModel::TR_UPSPEED:
case TorrentModel::TR_DLSPEED: { case TorrentModel::TR_DLSPEED: {
const qulonglong speed = index.data().toULongLong(); const qulonglong speed = index.data().toULongLong();
if (hideValues && !speed) if (hideValues && !speed)
break; break;
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::Misc::friendlyUnit(speed, true)); QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::Misc::friendlyUnit(speed, true));
}
break; break;
}
case TorrentModel::TR_UPLIMIT: case TorrentModel::TR_UPLIMIT:
case TorrentModel::TR_DLLIMIT: { case TorrentModel::TR_DLLIMIT: {
const qlonglong limit = index.data().toLongLong(); const qlonglong limit = index.data().toLongLong();
if (hideValues && !limit) if (hideValues && !limit)
break; break;
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
QItemDelegate::drawDisplay(painter, opt, opt.rect, limit > 0 ? Utils::Misc::friendlyUnit(limit, true) : QString::fromUtf8(C_INFINITY)); QItemDelegate::drawDisplay(painter, opt, opt.rect, limit > 0 ? Utils::Misc::friendlyUnit(limit, true) : QString::fromUtf8(C_INFINITY));
}
break; break;
}
case TorrentModel::TR_TIME_ELAPSED: { case TorrentModel::TR_TIME_ELAPSED: {
const int elapsedTime = index.data().toInt(); const int elapsedTime = index.data().toInt();
const int seedingTime = index.data(Qt::UserRole).toInt(); const int seedingTime = index.data(Qt::UserRole).toInt();
const QString txt = (seedingTime > 0) const QString txt = (seedingTime > 0)
? tr("%1 (seeded for %2)", "e.g. 4m39s (seeded for 3m10s)") ? tr("%1 (seeded for %2)", "e.g. 4m39s (seeded for 3m10s)")
.arg(Utils::Misc::userFriendlyDuration(elapsedTime) .arg(Utils::Misc::userFriendlyDuration(elapsedTime)
, Utils::Misc::userFriendlyDuration(seedingTime)) , Utils::Misc::userFriendlyDuration(seedingTime))
: Utils::Misc::userFriendlyDuration(elapsedTime); : Utils::Misc::userFriendlyDuration(elapsedTime);
QItemDelegate::drawDisplay(painter, opt, opt.rect, txt); QItemDelegate::drawDisplay(painter, opt, opt.rect, txt);
}
break; break;
}
case TorrentModel::TR_ADD_DATE: case TorrentModel::TR_ADD_DATE:
case TorrentModel::TR_SEED_DATE: case TorrentModel::TR_SEED_DATE:
QItemDelegate::drawDisplay(painter, opt, opt.rect, index.data().toDateTime().toLocalTime().toString(Qt::DefaultLocaleShortDate)); QItemDelegate::drawDisplay(painter, opt, opt.rect, index.data().toDateTime().toLocalTime().toString(Qt::DefaultLocaleShortDate));
break; break;
case TorrentModel::TR_RATIO_LIMIT: case TorrentModel::TR_RATIO_LIMIT:
case TorrentModel::TR_RATIO: { case TorrentModel::TR_RATIO: {
const qreal ratio = index.data().toDouble(); const qreal ratio = index.data().toDouble();
if (hideValues && (ratio <= 0)) if (hideValues && (ratio <= 0))
break; break;
QString str = ((ratio == -1) || (ratio > BitTorrent::TorrentHandle::MAX_RATIO)) ? QString::fromUtf8(C_INFINITY) : Utils::String::fromDouble(ratio, 2); QString str = ((ratio == -1) || (ratio > BitTorrent::TorrentHandle::MAX_RATIO)) ? QString::fromUtf8(C_INFINITY) : Utils::String::fromDouble(ratio, 2);
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
QItemDelegate::drawDisplay(painter, opt, opt.rect, str); QItemDelegate::drawDisplay(painter, opt, opt.rect, str);
}
break; break;
}
case TorrentModel::TR_PRIORITY: { case TorrentModel::TR_PRIORITY: {
const int priority = index.data().toInt(); const int priority = index.data().toInt();
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
if (priority > 0) { if (priority > 0) {
QItemDelegate::paint(painter, opt, index); QItemDelegate::paint(painter, opt, index);
} }
else { else {
QItemDelegate::drawDisplay(painter, opt, opt.rect, "*"); QItemDelegate::drawDisplay(painter, opt, opt.rect, "*");
}
} }
break; break;
}
case TorrentModel::TR_PROGRESS: { case TorrentModel::TR_PROGRESS: {
QStyleOptionProgressBar newopt; QStyleOptionProgressBar newopt;
qreal progress = index.data().toDouble() * 100.; qreal progress = index.data().toDouble() * 100.;
newopt.rect = opt.rect; newopt.rect = opt.rect;
newopt.text = ((progress == 100.0) ? QString("100%") : Utils::String::fromDouble(progress, 1) + "%"); newopt.text = ((progress == 100.0) ? QString("100%") : Utils::String::fromDouble(progress, 1) + "%");
newopt.progress = static_cast<int>(progress); newopt.progress = static_cast<int>(progress);
newopt.maximum = 100; newopt.maximum = 100;
newopt.minimum = 0; newopt.minimum = 0;
newopt.state |= QStyle::State_Enabled; newopt.state |= QStyle::State_Enabled;
newopt.textVisible = true; newopt.textVisible = true;
#ifndef Q_OS_WIN #ifndef Q_OS_WIN
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter); QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter);
#else #else
// XXX: To avoid having the progress text on the right of the bar // XXX: To avoid having the progress text on the right of the bar
QProxyStyle st("fusion"); QProxyStyle st("fusion");
st.drawControl(QStyle::CE_ProgressBar, &newopt, painter, 0); st.drawControl(QStyle::CE_ProgressBar, &newopt, painter, 0);
#endif #endif
}
break; break;
}
case TorrentModel::TR_LAST_ACTIVITY: { case TorrentModel::TR_LAST_ACTIVITY: {
qlonglong elapsed = index.data().toLongLong(); qlonglong elapsed = index.data().toLongLong();
if (hideValues && ((elapsed < 0) || (elapsed >= MAX_ETA))) if (hideValues && ((elapsed < 0) || (elapsed >= MAX_ETA)))
break; break;
// Show '< 1m ago' when elapsed time is 0 // Show '< 1m ago' when elapsed time is 0
if (elapsed == 0) if (elapsed == 0)
elapsed = 1; elapsed = 1;
QString elapsedString = (elapsed >= 0) QString elapsedString = (elapsed >= 0)
? tr("%1 ago", "e.g.: 1h 20m ago").arg(Utils::Misc::userFriendlyDuration(elapsed)) ? tr("%1 ago", "e.g.: 1h 20m ago").arg(Utils::Misc::userFriendlyDuration(elapsed))
: Utils::Misc::userFriendlyDuration(elapsed); : Utils::Misc::userFriendlyDuration(elapsed);
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
QItemDelegate::drawDisplay(painter, opt, option.rect, elapsedString); QItemDelegate::drawDisplay(painter, opt, option.rect, elapsedString);
}
break; break;
}
default: default:
QItemDelegate::paint(painter, option, index); QItemDelegate::paint(painter, option, index);
} }
painter->restore(); painter->restore();
} }
QWidget* TransferListDelegate::createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const QWidget *TransferListDelegate::createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const
{ {
// No editor here // No editor here
return 0; return nullptr;
} }
QSize TransferListDelegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const QSize TransferListDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{ {
// Reimplementing sizeHint() because the 'name' column contains text+icon. // Reimplementing sizeHint() because the 'name' column contains text+icon.
// When that WHOLE column goes out of view(eg user scrolls horizontally) // When that WHOLE column goes out of view(eg user scrolls horizontally)

18
src/gui/transferlistdelegate.h

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 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 TRANSFERLISTDELEGATE_H #ifndef TRANSFERLISTDELEGATE_H
@ -33,11 +31,9 @@
#include <QItemDelegate> #include <QItemDelegate>
QT_BEGIN_NAMESPACE class QModelIndex;
class QPainter; class QPainter;
class QStyleOptionViewItem; class QStyleOptionViewItem;
class QModelIndex;
QT_END_NAMESPACE
namespace BitTorrent namespace BitTorrent
{ {
@ -45,15 +41,15 @@ namespace BitTorrent
} }
// Defines for download list list columns // Defines for download list list columns
class TransferListDelegate: public QItemDelegate class TransferListDelegate : public QItemDelegate
{ {
Q_OBJECT Q_OBJECT
public: public:
TransferListDelegate(QObject *parent); TransferListDelegate(QObject *parent);
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const; void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
QWidget* createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const; QWidget *createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const override;
QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const; QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
private: private:
QString getStatusString(const BitTorrent::TorrentState state) const; QString getStatusString(const BitTorrent::TorrentState state) const;

22
src/gui/transferlistfilterswidget.cpp

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 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 "transferlistfilterswidget.h" #include "transferlistfilterswidget.h"
@ -37,15 +35,15 @@
#include <QMenu> #include <QMenu>
#include <QMessageBox> #include <QMessageBox>
#include <QScrollArea> #include <QScrollArea>
#include <QVBoxLayout>
#include <QUrl> #include <QUrl>
#include <QVBoxLayout>
#include "base/bittorrent/session.h" #include "base/bittorrent/session.h"
#include "base/bittorrent/torrenthandle.h" #include "base/bittorrent/torrenthandle.h"
#include "base/bittorrent/trackerentry.h" #include "base/bittorrent/trackerentry.h"
#include "base/logger.h" #include "base/logger.h"
#include "base/net/downloadmanager.h"
#include "base/net/downloadhandler.h" #include "base/net/downloadhandler.h"
#include "base/net/downloadmanager.h"
#include "base/preferences.h" #include "base/preferences.h"
#include "base/torrentfilter.h" #include "base/torrentfilter.h"
#include "base/utils/fs.h" #include "base/utils/fs.h"
@ -161,7 +159,7 @@ StatusFiltersWidget::StatusFiltersWidget(QWidget *parent, TransferListWidget *tr
errored->setData(Qt::DisplayRole, QVariant(tr("Errored (0)"))); errored->setData(Qt::DisplayRole, QVariant(tr("Errored (0)")));
errored->setData(Qt::DecorationRole, QIcon(":/icons/skin/error.png")); 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); setCurrentRow(pref->getTransSelFilter(), QItemSelectionModel::SelectCurrent);
toggleFilter(pref->getStatusFilterState()); toggleFilter(pref->getStatusFilterState());
} }
@ -443,7 +441,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) Q_UNUSED(error)
if (url.endsWith(".ico", Qt::CaseInsensitive)) { if (url.endsWith(".ico", Qt::CaseInsensitive)) {
@ -514,10 +512,10 @@ QString TrackerFiltersList::trackerFromRow(int row) const
{ {
Q_ASSERT(row > 1); Q_ASSERT(row > 1);
const QString &tracker = item(row)->text(); const QString &tracker = item(row)->text();
QStringList parts = tracker.split(" "); QStringList parts = tracker.split(' ');
Q_ASSERT(parts.size() >= 2); Q_ASSERT(parts.size() >= 2);
parts.removeLast(); // Remove trailing number parts.removeLast(); // Remove trailing number
return parts.join(" "); return parts.join(' ');
} }
int TrackerFiltersList::rowFromTracker(const QString &tracker) const int TrackerFiltersList::rowFromTracker(const QString &tracker) const
@ -561,7 +559,7 @@ TransferListFiltersWidget::TransferListFiltersWidget(QWidget *parent, TransferLi
, m_transferList(transferList) , m_transferList(transferList)
, m_trackerFilters(nullptr) , m_trackerFilters(nullptr)
{ {
Preferences* const pref = Preferences::instance(); Preferences *const pref = Preferences::instance();
// Construct lists // Construct lists
QVBoxLayout *vLayout = new QVBoxLayout(this); QVBoxLayout *vLayout = new QVBoxLayout(this);
@ -587,7 +585,7 @@ TransferListFiltersWidget::TransferListFiltersWidget(QWidget *parent, TransferLi
vLayout->addWidget(scroll); vLayout->addWidget(scroll);
setLayout(vLayout); setLayout(vLayout);
QCheckBox * statusLabel = new QCheckBox(tr("Status"), this); QCheckBox *statusLabel = new QCheckBox(tr("Status"), this);
statusLabel->setChecked(pref->getStatusFilterState()); statusLabel->setChecked(pref->getStatusFilterState());
statusLabel->setFont(font); statusLabel->setFont(font);
frameLayout->addWidget(statusLabel); frameLayout->addWidget(statusLabel);

41
src/gui/transferlistfilterswidget.h

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 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,21 +24,16 @@
* 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 TRANSFERLISTFILTERSWIDGET_H #ifndef TRANSFERLISTFILTERSWIDGET_H
#define TRANSFERLISTFILTERSWIDGET_H #define TRANSFERLISTFILTERSWIDGET_H
#include <QListWidget>
#include <QFrame> #include <QFrame>
#include <QListWidget>
QT_BEGIN_NAMESPACE
class QResizeEvent;
class QCheckBox; class QCheckBox;
QT_END_NAMESPACE class QResizeEvent;
class TransferListWidget; class TransferListWidget;
namespace BitTorrent namespace BitTorrent
@ -47,15 +42,15 @@ namespace BitTorrent
class TrackerEntry; class TrackerEntry;
} }
class FiltersBase: public QListWidget class FiltersBase : public QListWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
FiltersBase(QWidget *parent, TransferListWidget *transferList); FiltersBase(QWidget *parent, TransferListWidget *transferList);
virtual QSize sizeHint() const; QSize sizeHint() const override;
virtual QSize minimumSizeHint() const; QSize minimumSizeHint() const override;
public slots: public slots:
void toggleFilter(bool checked); void toggleFilter(bool checked);
@ -70,7 +65,7 @@ private slots:
virtual void torrentAboutToBeDeleted(BitTorrent::TorrentHandle *const) = 0; virtual void torrentAboutToBeDeleted(BitTorrent::TorrentHandle *const) = 0;
}; };
class StatusFiltersWidget: public FiltersBase class StatusFiltersWidget : public FiltersBase
{ {
Q_OBJECT Q_OBJECT
@ -84,13 +79,13 @@ private slots:
private: private:
// These 4 methods are virtual slots in the base class. // These 4 methods are virtual slots in the base class.
// No need to redeclare them here as slots. // No need to redeclare them here as slots.
virtual void showMenu(QPoint); void showMenu(QPoint) override;
virtual void applyFilter(int row); void applyFilter(int row) override;
virtual void handleNewTorrent(BitTorrent::TorrentHandle *const); void handleNewTorrent(BitTorrent::TorrentHandle *const) override;
virtual void torrentAboutToBeDeleted(BitTorrent::TorrentHandle *const); void torrentAboutToBeDeleted(BitTorrent::TorrentHandle *const) override;
}; };
class TrackerFiltersList: public FiltersBase class TrackerFiltersList : public FiltersBase
{ {
Q_OBJECT Q_OBJECT
@ -116,10 +111,10 @@ private slots:
private: private:
// These 4 methods are virtual slots in the base class. // These 4 methods are virtual slots in the base class.
// No need to redeclare them here as slots. // No need to redeclare them here as slots.
virtual void showMenu(QPoint); void showMenu(QPoint) override;
virtual void applyFilter(int row); void applyFilter(int row) override;
virtual void handleNewTorrent(BitTorrent::TorrentHandle *const torrent); void handleNewTorrent(BitTorrent::TorrentHandle *const torrent) override;
virtual void torrentAboutToBeDeleted(BitTorrent::TorrentHandle *const torrent); void torrentAboutToBeDeleted(BitTorrent::TorrentHandle *const torrent) override;
QString trackerFromRow(int row) const; QString trackerFromRow(int row) const;
int rowFromTracker(const QString &tracker) const; int rowFromTracker(const QString &tracker) const;
QString getHost(const QString &tracker) const; QString getHost(const QString &tracker) const;
@ -138,7 +133,7 @@ private:
class CategoryFilterWidget; class CategoryFilterWidget;
class TagFilterWidget; class TagFilterWidget;
class TransferListFiltersWidget: public QFrame class TransferListFiltersWidget : public QFrame
{ {
Q_OBJECT Q_OBJECT

180
src/gui/transferlistsortmodel.cpp

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2013 Nick Tiskov * Copyright (C) 2013 Nick Tiskov <daymansmail@gmail.com>
* *
* 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,17 +24,17 @@
* 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 : daymansmail@gmail.com
*/ */
#include "transferlistsortmodel.h"
#include <QStringList> #include <QStringList>
#include "base/bittorrent/torrenthandle.h"
#include "base/types.h" #include "base/types.h"
#include "base/utils/string.h" #include "base/utils/string.h"
#include "base/bittorrent/torrenthandle.h"
#include "torrentmodel.h" #include "torrentmodel.h"
#include "transferlistsortmodel.h"
TransferListSortModel::TransferListSortModel(QObject *parent) TransferListSortModel::TransferListSortModel(QObject *parent)
: QSortFilterProxyModel(parent) : QSortFilterProxyModel(parent)
@ -89,125 +89,125 @@ bool TransferListSortModel::lessThan(const QModelIndex &left, const QModelIndex
case TorrentModel::TR_CATEGORY: case TorrentModel::TR_CATEGORY:
case TorrentModel::TR_TAGS: case TorrentModel::TR_TAGS:
case TorrentModel::TR_NAME: { case TorrentModel::TR_NAME: {
const QVariant vL = left.data(); const QVariant vL = left.data();
const QVariant vR = right.data(); const QVariant vR = right.data();
if (!vL.isValid() || !vR.isValid() || (vL == vR)) if (!vL.isValid() || !vR.isValid() || (vL == vR))
return lowerPositionThan(left, right); return lowerPositionThan(left, right);
const int result = Utils::String::naturalCompare(vL.toString(), vR.toString(), Qt::CaseInsensitive); const int result = Utils::String::naturalCompare(vL.toString(), vR.toString(), Qt::CaseInsensitive);
return (result < 0); return (result < 0);
} }
case TorrentModel::TR_STATUS: { case TorrentModel::TR_STATUS: {
// QSortFilterProxyModel::lessThan() uses the < operator only for specific QVariant types // QSortFilterProxyModel::lessThan() uses the < operator only for specific QVariant types
// so our custom type is outside that list. // so our custom type is outside that list.
// In this case QSortFilterProxyModel::lessThan() converts other types to QString and // In this case QSortFilterProxyModel::lessThan() converts other types to QString and
// sorts them. // sorts them.
// Thus we can't use the code in the default label. // Thus we can't use the code in the default label.
const BitTorrent::TorrentState leftValue = left.data().value<BitTorrent::TorrentState>(); const BitTorrent::TorrentState leftValue = left.data().value<BitTorrent::TorrentState>();
const BitTorrent::TorrentState rightValue = right.data().value<BitTorrent::TorrentState>(); const BitTorrent::TorrentState rightValue = right.data().value<BitTorrent::TorrentState>();
if (leftValue != rightValue) if (leftValue != rightValue)
return leftValue < rightValue; return leftValue < rightValue;
return lowerPositionThan(left, right); return lowerPositionThan(left, right);
} }
case TorrentModel::TR_ADD_DATE: case TorrentModel::TR_ADD_DATE:
case TorrentModel::TR_SEED_DATE: case TorrentModel::TR_SEED_DATE:
case TorrentModel::TR_SEEN_COMPLETE_DATE: { case TorrentModel::TR_SEEN_COMPLETE_DATE: {
return dateLessThan(sortColumn(), left, right, true); return dateLessThan(sortColumn(), left, right, true);
} }
case TorrentModel::TR_PRIORITY: { case TorrentModel::TR_PRIORITY: {
return lowerPositionThan(left, right); return lowerPositionThan(left, right);
} }
case TorrentModel::TR_SEEDS: case TorrentModel::TR_SEEDS:
case TorrentModel::TR_PEERS: { case TorrentModel::TR_PEERS: {
const int leftActive = left.data().toInt(); const int leftActive = left.data().toInt();
const int leftTotal = left.data(Qt::UserRole).toInt(); const int leftTotal = left.data(Qt::UserRole).toInt();
const int rightActive = right.data().toInt(); const int rightActive = right.data().toInt();
const int rightTotal = right.data(Qt::UserRole).toInt(); const int rightTotal = right.data(Qt::UserRole).toInt();
// Active peers/seeds take precedence over total peers/seeds.
if (leftActive != rightActive)
return (leftActive < rightActive);
if (leftTotal != rightTotal) // Active peers/seeds take precedence over total peers/seeds.
return (leftTotal < rightTotal); if (leftActive != rightActive)
return (leftActive < rightActive);
return lowerPositionThan(left, right); if (leftTotal != rightTotal)
} return (leftTotal < rightTotal);
case TorrentModel::TR_ETA: { return lowerPositionThan(left, right);
const TorrentModel *model = qobject_cast<TorrentModel *>(sourceModel());
// Sorting rules prioritized.
// 1. Active torrents at the top
// 2. Seeding torrents at the bottom
// 3. Torrents with invalid ETAs at the bottom
const bool isActiveL = TorrentFilter::ActiveTorrent.match(model->torrentHandle(model->index(left.row())));
const bool isActiveR = TorrentFilter::ActiveTorrent.match(model->torrentHandle(model->index(right.row())));
if (isActiveL != isActiveR)
return isActiveL;
const int prioL = model->data(model->index(left.row(), TorrentModel::TR_PRIORITY)).toInt();
const int prioR = model->data(model->index(right.row(), TorrentModel::TR_PRIORITY)).toInt();
const bool isSeedingL = (prioL < 0);
const bool isSeedingR = (prioR < 0);
if (isSeedingL != isSeedingR) {
const bool isAscendingOrder = (sortOrder() == Qt::AscendingOrder);
if (isSeedingL)
return !isAscendingOrder;
else
return isAscendingOrder;
} }
const qlonglong etaL = left.data().toLongLong(); case TorrentModel::TR_ETA: {
const qlonglong etaR = right.data().toLongLong(); const TorrentModel *model = qobject_cast<TorrentModel *>(sourceModel());
const bool isInvalidL = ((etaL < 0) || (etaL >= MAX_ETA));
const bool isInvalidR = ((etaR < 0) || (etaR >= MAX_ETA)); // Sorting rules prioritized.
if (isInvalidL && isInvalidR) { // 1. Active torrents at the top
if (isSeedingL) // Both seeding // 2. Seeding torrents at the bottom
return dateLessThan(TorrentModel::TR_SEED_DATE, left, right, true); // 3. Torrents with invalid ETAs at the bottom
else
return (prioL < prioR); const bool isActiveL = TorrentFilter::ActiveTorrent.match(model->torrentHandle(model->index(left.row())));
} const bool isActiveR = TorrentFilter::ActiveTorrent.match(model->torrentHandle(model->index(right.row())));
else if (!isInvalidL && !isInvalidR) { if (isActiveL != isActiveR)
return (etaL < etaR); return isActiveL;
}
else { const int prioL = model->data(model->index(left.row(), TorrentModel::TR_PRIORITY)).toInt();
return !isInvalidL; const int prioR = model->data(model->index(right.row(), TorrentModel::TR_PRIORITY)).toInt();
const bool isSeedingL = (prioL < 0);
const bool isSeedingR = (prioR < 0);
if (isSeedingL != isSeedingR) {
const bool isAscendingOrder = (sortOrder() == Qt::AscendingOrder);
if (isSeedingL)
return !isAscendingOrder;
else
return isAscendingOrder;
}
const qlonglong etaL = left.data().toLongLong();
const qlonglong etaR = right.data().toLongLong();
const bool isInvalidL = ((etaL < 0) || (etaL >= MAX_ETA));
const bool isInvalidR = ((etaR < 0) || (etaR >= MAX_ETA));
if (isInvalidL && isInvalidR) {
if (isSeedingL) // Both seeding
return dateLessThan(TorrentModel::TR_SEED_DATE, left, right, true);
else
return (prioL < prioR);
}
else if (!isInvalidL && !isInvalidR) {
return (etaL < etaR);
}
else {
return !isInvalidL;
}
} }
}
case TorrentModel::TR_LAST_ACTIVITY: { case TorrentModel::TR_LAST_ACTIVITY: {
const qlonglong vL = left.data().toLongLong(); const qlonglong vL = left.data().toLongLong();
const qlonglong vR = right.data().toLongLong(); const qlonglong vR = right.data().toLongLong();
if (vL == -1) return false; if (vL == -1) return false;
if (vR == -1) return true; if (vR == -1) return true;
return vL < vR; return vL < vR;
} }
case TorrentModel::TR_RATIO_LIMIT: { case TorrentModel::TR_RATIO_LIMIT: {
const qreal vL = left.data().toDouble(); const qreal vL = left.data().toDouble();
const qreal vR = right.data().toDouble(); const qreal vR = right.data().toDouble();
if (vL == -1) return false; if (vL == -1) return false;
if (vR == -1) return true; if (vR == -1) return true;
return vL < vR; return vL < vR;
} }
default: { default: {
if (left.data() != right.data()) if (left.data() != right.data())
return QSortFilterProxyModel::lessThan(left, right); return QSortFilterProxyModel::lessThan(left, right);
return lowerPositionThan(left, right); return lowerPositionThan(left, right);
} }
} }
} }

12
src/gui/transferlistsortmodel.h

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2013 Nick Tiskov * Copyright (C) 2013 Nick Tiskov <daymansmail@gmail.com>
* *
* 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 : daymansmail@gmail.com
*/ */
#ifndef TRANSFERLISTSORTMODEL_H #ifndef TRANSFERLISTSORTMODEL_H
@ -36,7 +34,7 @@
class QStringList; class QStringList;
class TransferListSortModel: public QSortFilterProxyModel class TransferListSortModel : public QSortFilterProxyModel
{ {
Q_OBJECT Q_OBJECT
@ -52,10 +50,10 @@ public:
void disableTrackerFilter(); void disableTrackerFilter();
private: private:
bool lessThan(const QModelIndex &left, const QModelIndex &right) const; bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
bool lowerPositionThan(const QModelIndex &left, const QModelIndex &right) const; bool lowerPositionThan(const QModelIndex &left, const QModelIndex &right) const;
bool dateLessThan(const int dateColumn, const QModelIndex &left, const QModelIndex &right, bool sortInvalidInBottom) const; bool dateLessThan(const int dateColumn, const QModelIndex &left, const QModelIndex &right, bool sortInvalidInBottom) const;
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
bool matchFilter(int sourceRow, const QModelIndex &sourceParent) const; bool matchFilter(int sourceRow, const QModelIndex &sourceParent) const;
private: private:

196
src/gui/transferlistwidget.cpp

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

22
src/gui/transferlistwidget.h

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 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 TRANSFERLISTWIDGET_H #ifndef TRANSFERLISTWIDGET_H
@ -39,25 +37,23 @@ namespace BitTorrent
class TorrentHandle; class TorrentHandle;
} }
class QShortcut;
class QSortFilterProxyModel;
class QStandardItemModel;
class MainWindow; class MainWindow;
class TransferListDelegate; class TransferListDelegate;
class TransferListSortModel; class TransferListSortModel;
class TorrentModel; class TorrentModel;
QT_BEGIN_NAMESPACE class TransferListWidget : public QTreeView
class QShortcut;
class QSortFilterProxyModel;
class QStandardItemModel;
QT_END_NAMESPACE
class TransferListWidget: public QTreeView
{ {
Q_OBJECT Q_OBJECT
public: public:
TransferListWidget(QWidget *parent, MainWindow *mainWindow); TransferListWidget(QWidget *parent, MainWindow *mainWindow);
~TransferListWidget(); ~TransferListWidget();
TorrentModel* getSourceModel() const; TorrentModel *getSourceModel() const;
public slots: public slots:
void setSelectionCategory(QString category); void setSelectionCategory(QString category);
@ -92,7 +88,7 @@ public slots:
void previewSelectedTorrents(); void previewSelectedTorrents();
void hidePriorityColumn(bool hide); void hidePriorityColumn(bool hide);
void displayDLHoSMenu(const QPoint&); void displayDLHoSMenu(const QPoint&);
void applyNameFilter(const QString& name); void applyNameFilter(const QString &name);
void applyStatusFilter(int f); void applyStatusFilter(int f);
void applyCategoryFilter(QString category); void applyCategoryFilter(QString category);
void applyTagFilter(const QString &tag); void applyTagFilter(const QString &tag);

2
src/gui/updownratiodlg.h

@ -51,7 +51,7 @@ public:
int seedingTime() const; int seedingTime() const;
public slots: public slots:
void accept(); void accept() override;
private slots: private slots:
void handleRatioTypeChanged(); void handleRatioTypeChanged();

2
src/gui/utils.cpp

@ -60,7 +60,7 @@ qreal Utils::Gui::screenScalingFactor(const QWidget *widget)
#else #else
return widget->devicePixelRatio(); return widget->devicePixelRatio();
#endif #endif
#endif #endif // Q_OS_WIN
} }
QPixmap Utils::Gui::scaledPixmap(const QString &path, const QWidget *widget, const int height) QPixmap Utils::Gui::scaledPixmap(const QString &path, const QWidget *widget, const int height)

2
src/webui/api/torrentscontroller.cpp

@ -49,8 +49,8 @@
#include "base/torrentfilter.h" #include "base/torrentfilter.h"
#include "base/utils/fs.h" #include "base/utils/fs.h"
#include "base/utils/string.h" #include "base/utils/string.h"
#include "serialize/serialize_torrent.h"
#include "apierror.h" #include "apierror.h"
#include "serialize/serialize_torrent.h"
// Tracker keys // Tracker keys
const char KEY_TRACKER_URL[] = "url"; const char KEY_TRACKER_URL[] = "url";

Loading…
Cancel
Save