From 5120fc0f2ceedbf6b314fe45f43410f9c77fb66a Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Fri, 12 Jun 2015 22:12:12 +0000 Subject: [PATCH] Unify/prettify Qt client headers style --- qt/AboutDialog.h | 7 +- qt/AddData.h | 29 +++--- qt/Application.cc | 5 + qt/Application.h | 40 ++++---- qt/ColumnResizer.h | 1 + qt/CustomVariantType.h | 1 - qt/DBusAdaptor.h | 16 ++-- qt/DetailsDialog.cc | 9 -- qt/DetailsDialog.h | 81 ++++++++-------- qt/FaviconCache.h | 23 ++--- qt/FileTreeDelegate.h | 7 +- qt/FileTreeItem.h | 48 +++++----- qt/FileTreeModel.cc | 4 +- qt/FileTreeModel.h | 55 +++++------ qt/FileTreeView.h | 16 ++-- qt/FilterBar.cc | 3 +- qt/FilterBar.h | 31 +++--- qt/FilterBarComboBox.h | 5 +- qt/FilterBarComboBoxDelegate.h | 6 +- qt/FilterBarLineEdit.h | 3 +- qt/Filters.h | 72 ++++++++++---- qt/Formatter.h | 35 ++++--- qt/FreeSpaceLabel.h | 12 +-- qt/IconToolButton.h | 1 + qt/LicenseDialog.h | 4 +- qt/MainWindow.cc | 6 +- qt/MainWindow.h | 167 +++++++++++++++------------------ qt/MakeDialog.h | 25 ++--- qt/OptionsDialog.h | 14 +-- qt/PathButton.h | 10 +- qt/Prefs.cc | 1 + qt/Prefs.h | 57 +++++------ qt/PrefsDialog.cc | 4 +- qt/PrefsDialog.h | 59 +++++------- qt/RelocateDialog.h | 11 ++- qt/Session.cc | 6 +- qt/Session.h | 58 +++++------- qt/SessionDialog.h | 6 +- qt/Speed.h | 13 +-- qt/SqueezeLabel.h | 7 +- qt/StatsDialog.h | 19 ++-- qt/Torrent.cc | 10 +- qt/Torrent.h | 134 +++++++++++++------------- qt/TorrentDelegate.cc | 8 +- qt/TorrentDelegate.h | 45 ++++----- qt/TorrentDelegateMin.h | 18 ++-- qt/TorrentFilter.h | 21 +++-- qt/TorrentModel.cc | 2 + qt/TorrentModel.h | 60 ++++++------ qt/TrackerDelegate.h | 19 ++-- qt/TrackerModel.cc | 1 + qt/TrackerModel.h | 31 +++--- qt/TrackerModelFilter.h | 8 +- qt/Utils.cc | 1 + qt/Utils.h | 15 +-- qt/WatchDir.h | 20 ++-- 56 files changed, 711 insertions(+), 659 deletions(-) diff --git a/qt/AboutDialog.h b/qt/AboutDialog.h index 453a9e1b0..248220034 100644 --- a/qt/AboutDialog.h +++ b/qt/AboutDialog.h @@ -19,15 +19,16 @@ class AboutDialog: public QDialog Q_OBJECT public: - AboutDialog (QWidget * parent = 0); - ~AboutDialog () {} + AboutDialog (QWidget * parent = nullptr); + virtual ~AboutDialog () {} public slots: void showCredits (); private: - QDialog * myLicenseDialog; Ui::AboutDialog ui; + + QDialog * myLicenseDialog; }; #endif // QTR_ABOUT_DIALOG_H diff --git a/qt/AddData.h b/qt/AddData.h index 1dcc60bfb..0c573e6af 100644 --- a/qt/AddData.h +++ b/qt/AddData.h @@ -17,27 +17,32 @@ class AddData { public: - - enum { NONE, MAGNET, URL, FILENAME, METAINFO }; - int type; - - QByteArray metainfo; - QString filename; - QString magnet; - QUrl url; + enum + { + NONE, + MAGNET, + URL, + FILENAME, + METAINFO + }; public: + AddData (): type (NONE) {} + AddData (const QString& str) { set (str); } int set (const QString&); - AddData (const QString& str) { set(str); } - AddData (): type(NONE) {} QByteArray toBase64 () const; QString readableName () const; - public: + static bool isSupported (const QString& str) { return AddData (str).type != NONE; } - static bool isSupported (const QString& str) { return AddData(str).type != NONE; } + public: + int type; + QByteArray metainfo; + QString filename; + QString magnet; + QUrl url; }; #endif // QTR_ADD_DATA_H diff --git a/qt/Application.cc b/qt/Application.cc index 53aa76969..d554b7a10 100644 --- a/qt/Application.cc +++ b/qt/Application.cc @@ -569,6 +569,11 @@ Application::notifyApp (const QString& title, const QString& body) const return (replyMsg.type () == QDBusMessage::ReplyMessage) && !replyMsg.arguments ().isEmpty (); } +FaviconCache& Application::faviconCache () +{ + return myFavicons; +} + /*** **** ***/ diff --git a/qt/Application.h b/qt/Application.h index 40268153a..2995a67a9 100644 --- a/qt/Application.h +++ b/qt/Application.h @@ -32,25 +32,18 @@ class Application: public QApplication Application (int& argc, char ** argv); virtual ~Application (); - public: void raise (); bool notifyApp (const QString& title, const QString& body) const; - public: - FaviconCache favicons; + FaviconCache& faviconCache (); + + public slots: + void addTorrent (const QString&); + void addTorrent (const AddData&); private: - Prefs * myPrefs; - Session * mySession; - TorrentModel * myModel; - MainWindow * myWindow; - WatchDir * myWatchDir; - QTimer myModelTimer; - QTimer myStatsTimer; - QTimer mySessionTimer; - time_t myLastFullUpdateTime; - QTranslator qtTranslator; - QTranslator appTranslator; + void maybeUpdateBlocklist (); + void quitLater (); private slots: void consentGiven (int result); @@ -61,14 +54,19 @@ class Application: public QApplication void onTorrentCompleted (int); void onNewTorrentChanged (int); - public slots: - void addTorrent (const QString&); - void addTorrent (const AddData&); - private: - void maybeUpdateBlocklist (); - - void quitLater (); + Prefs * myPrefs; + Session * mySession; + TorrentModel * myModel; + MainWindow * myWindow; + WatchDir * myWatchDir; + QTimer myModelTimer; + QTimer myStatsTimer; + QTimer mySessionTimer; + time_t myLastFullUpdateTime; + QTranslator qtTranslator; + QTranslator appTranslator; + FaviconCache myFavicons; }; #undef qApp diff --git a/qt/ColumnResizer.h b/qt/ColumnResizer.h index d84041648..2dce3e412 100644 --- a/qt/ColumnResizer.h +++ b/qt/ColumnResizer.h @@ -25,6 +25,7 @@ class ColumnResizer: public QObject void addLayout (QGridLayout * layout); + // QObject virtual bool eventFilter (QObject * object, QEvent * event); public slots: diff --git a/qt/CustomVariantType.h b/qt/CustomVariantType.h index b70f15288..88027e7b1 100644 --- a/qt/CustomVariantType.h +++ b/qt/CustomVariantType.h @@ -15,7 +15,6 @@ class CustomVariantType { public: - enum { TrackerStatsList = QVariant::UserType, diff --git a/qt/DBusAdaptor.h b/qt/DBusAdaptor.h index dfdab9ed9..f09df97ea 100644 --- a/qt/DBusAdaptor.h +++ b/qt/DBusAdaptor.h @@ -17,18 +17,18 @@ class Application; class DBusAdaptor: public QDBusAbstractAdaptor { Q_OBJECT - Q_CLASSINFO( "D-Bus Interface", "com.transmissionbt.Transmission" ) - - private: - Application * myApp; + Q_CLASSINFO ("D-Bus Interface", "com.transmissionbt.Transmission") public: - DBusAdaptor( Application* ); - virtual ~DBusAdaptor() {} + DBusAdaptor (Application *); + virtual ~DBusAdaptor () {} public slots: - bool PresentWindow(); - bool AddMetainfo( const QString& ); + bool PresentWindow (); + bool AddMetainfo (const QString&); + + private: + Application * myApp; }; #endif // QTR_DBUS_ADAPTOR_H diff --git a/qt/DetailsDialog.cc b/qt/DetailsDialog.cc index d070fa5fe..323898e92 100644 --- a/qt/DetailsDialog.cc +++ b/qt/DetailsDialog.cc @@ -285,15 +285,6 @@ DetailsDialog::refreshPref (int key) **** ***/ -QString -DetailsDialog::timeToStringRounded (int seconds) -{ - if (seconds > 60) - seconds -= (seconds % 60); - - return Formatter::timeToString (seconds); -} - void DetailsDialog::onTimer () { diff --git a/qt/DetailsDialog.h b/qt/DetailsDialog.h index 8d0f60a3b..dc15c3226 100644 --- a/qt/DetailsDialog.h +++ b/qt/DetailsDialog.h @@ -16,11 +16,11 @@ #include #include -#include "Prefs.h" - #include "ui_DetailsDialog.h" class QTreeWidgetItem; + +class Prefs; class Session; class Torrent; class TorrentModel; @@ -32,17 +32,13 @@ class DetailsDialog: public QDialog { Q_OBJECT - private: - void getNewData (); - - private slots: - void onTorrentChanged (); - void onTimer (); - public: - DetailsDialog (Session&, Prefs&, const TorrentModel&, QWidget * parent = 0); - ~DetailsDialog (); + DetailsDialog (Session&, Prefs&, const TorrentModel&, QWidget * parent = nullptr); + virtual ~DetailsDialog (); + void setIds (const QSet& ids); + + // QWidget virtual QSize sizeHint () const { return QSize (440, 460); } private: @@ -52,35 +48,33 @@ class DetailsDialog: public QDialog void initFilesTab (); void initOptionsTab (); - private: - QIcon getStockIcon (const QString& freedesktop_name, int fallback); - QString timeToStringRounded (int seconds); - QString trimToDesiredWidth (const QString& str); + void getNewData (); - private: - Session& mySession; - Prefs& myPrefs; - const TorrentModel& myModel; - QSet myIds; - QTimer myTimer; - bool myChangedTorrents; - bool myHavePendingRefresh; + QIcon getStockIcon (const QString& freedesktop_name, int fallback); - Ui::DetailsDialog ui; + private slots: + void refresh (); + void refreshPref (int key); - TrackerModel * myTrackerModel; - TrackerModelFilter * myTrackerFilter; - TrackerDelegate * myTrackerDelegate; + void onTorrentChanged (); + void onTimer (); - QMap myPeers; + // Tracker tab + void onTrackerSelectionChanged (); + void onAddTrackerClicked (); + void onEditTrackerClicked (); + void onRemoveTrackerClicked (); + void onShowTrackerScrapesToggled (bool); + void onShowBackupTrackersToggled (bool); - private slots: - void refreshPref (int key); - void onBandwidthPriorityChanged (int); + // Files tab void onFilePriorityChanged (const QSet& fileIndices, int); void onFileWantedChanged (const QSet& fileIndices, bool); void onPathEdited (const QString& oldpath, const QString& newname); void onOpenRequested (const QString& path); + + // Options tab + void onBandwidthPriorityChanged (int); void onHonorsSessionLimitsToggled (bool); void onDownloadLimitedToggled (bool); void onSpinBoxEditingFinished (); @@ -88,13 +82,24 @@ class DetailsDialog: public QDialog void onRatioModeChanged (int); void onIdleModeChanged (int); void onIdleLimitChanged (); - void onShowTrackerScrapesToggled (bool); - void onShowBackupTrackersToggled (bool); - void onTrackerSelectionChanged (); - void onAddTrackerClicked (); - void onEditTrackerClicked (); - void onRemoveTrackerClicked (); - void refresh (); + + private: + Session& mySession; + Prefs& myPrefs; + const TorrentModel& myModel; + + Ui::DetailsDialog ui; + + QSet myIds; + QTimer myTimer; + bool myChangedTorrents; + bool myHavePendingRefresh; + + TrackerModel * myTrackerModel; + TrackerModelFilter * myTrackerFilter; + TrackerDelegate * myTrackerDelegate; + + QMap myPeers; }; #endif // QTR_DETAILS_DIALOG_H diff --git a/qt/FaviconCache.h b/qt/FaviconCache.h index 06eaeb430..74b7af7d5 100644 --- a/qt/FaviconCache.h +++ b/qt/FaviconCache.h @@ -24,14 +24,8 @@ class FaviconCache: public QObject Q_OBJECT public: - - static QString getHost( const QUrl& url ); - static QSize getIconSize (); - - public: - - FaviconCache(); - virtual ~FaviconCache(); + FaviconCache (); + virtual ~FaviconCache (); // returns a cached pixmap, or a NULL pixmap if there's no match in the cache QPixmap find (const QUrl& url); @@ -42,21 +36,22 @@ class FaviconCache: public QObject // this will emit a signal when (if) the icon becomes ready void add (const QUrl& url); - signals: + static QString getHost (const QUrl& url); + static QSize getIconSize (); + signals: void pixmapReady (const QString& host); private: - - QNetworkAccessManager * myNAM; - QMap myPixmaps; - QString getCacheDir (); void ensureCacheDirHasBeenScanned (); private slots: - void onRequestFinished (QNetworkReply * reply); + + private: + QNetworkAccessManager * myNAM; + QMap myPixmaps; }; #endif // QTR_FAVICON_CACHE_H diff --git a/qt/FileTreeDelegate.h b/qt/FileTreeDelegate.h index 29d81ad86..cd3f8e59e 100644 --- a/qt/FileTreeDelegate.h +++ b/qt/FileTreeDelegate.h @@ -17,12 +17,13 @@ class FileTreeDelegate: public QItemDelegate Q_OBJECT public: - FileTreeDelegate (QObject * parent=0): QItemDelegate(parent) {} - virtual ~FileTreeDelegate() {} + FileTreeDelegate (QObject * parent = nullptr): QItemDelegate (parent) {} + virtual ~FileTreeDelegate () {} public: + // QAbstractItemDelegate virtual QSize sizeHint (const QStyleOptionViewItem&, const QModelIndex&) const; - virtual void paint (QPainter*, const QStyleOptionViewItem&, const QModelIndex&) const; + virtual void paint (QPainter *, const QStyleOptionViewItem&, const QModelIndex&) const; }; #endif // QTR_FILE_TREE_DELEGATE_H diff --git a/qt/FileTreeItem.h b/qt/FileTreeItem.h index 74114e079..079debc04 100644 --- a/qt/FileTreeItem.h +++ b/qt/FileTreeItem.h @@ -12,44 +12,40 @@ #include -#include -#include +#include #include +#include #include #include #include -class FileTreeItem: public QObject +class FileTreeItem { - Q_OBJECT - - enum { LOW=(1<<0), NORMAL=(1<<1), HIGH=(1<<2) }; + Q_DECLARE_TR_FUNCTIONS (FileTreeItem) public: - - virtual ~FileTreeItem(); - - FileTreeItem (const QString& name=QString (), int fileIndex=-1, uint64_t size=0): - myFileIndex (fileIndex), - myParent (0), + FileTreeItem (const QString& name = QString (), int fileIndex = -1, uint64_t size = 0): myName (name), + myFileIndex (fileIndex), + myTotalSize (size), + myParent (nullptr), myPriority (0), - myIsWanted (0), + myIsWanted (false), myHaveSize (0), - myTotalSize (size), myFirstUnhashedRow (0) {} + ~FileTreeItem(); public: - void appendChild (FileTreeItem *child); + void appendChild (FileTreeItem * child); FileTreeItem * child (const QString& filename); - FileTreeItem * child (int row) { return myChildren.at(row); } - int childCount () const { return myChildren.size(); } + FileTreeItem * child (int row) { return myChildren.at (row); } + int childCount () const { return myChildren.size (); } FileTreeItem * parent () { return myParent; } const FileTreeItem * parent () const { return myParent; } int row () const; const QString& name () const { return myName; } QVariant data (int column, int role) const; - std::pair update (const QString& name, bool want, int priority, uint64_t have, bool updateFields); + std::pair update (const QString& name, bool want, int priority, uint64_t have, bool updateFields); void twiddleWanted (QSet& fileIds, bool&); void twiddlePriority (QSet& fileIds, int&); int fileIndex () const { return myFileIndex; } @@ -57,6 +53,14 @@ class FileTreeItem: public QObject QString path () const; bool isComplete () const; + private: + enum + { + LOW = (1 << 0), + NORMAL = (1 << 1), + HIGH = (1 << 2) + }; + private: void setSubtreePriority (int priority, QSet& fileIds); void setSubtreeWanted (bool, QSet& fileIds); @@ -66,17 +70,19 @@ class FileTreeItem: public QObject double progress () const; int priority () const; int isSubtreeWanted () const; + const QHash& getMyChildRows(); + private: + QString myName; const int myFileIndex; + const uint64_t myTotalSize; + FileTreeItem * myParent; QList myChildren; QHash myChildRows; - const QHash& getMyChildRows(); - QString myName; int myPriority; bool myIsWanted; uint64_t myHaveSize; - const uint64_t myTotalSize; size_t myFirstUnhashedRow; }; diff --git a/qt/FileTreeModel.cc b/qt/FileTreeModel.cc index 2807d7491..140ceff92 100644 --- a/qt/FileTreeModel.cc +++ b/qt/FileTreeModel.cc @@ -16,9 +16,9 @@ FileTreeModel::FileTreeModel (QObject * parent, bool isEditable): QAbstractItemModel(parent), + myIsEditable (isEditable), myRootItem (new FileTreeItem), - myIndexCache (), - myIsEditable (isEditable) + myIndexCache () { } diff --git a/qt/FileTreeModel.h b/qt/FileTreeModel.h index ec5b8e382..90b8d436b 100644 --- a/qt/FileTreeModel.h +++ b/qt/FileTreeModel.h @@ -39,21 +39,33 @@ class FileTreeModel: public QAbstractItemModel }; public: - FileTreeModel (QObject *parent = 0, bool isEditable = true); - ~FileTreeModel (); + FileTreeModel (QObject * parent = nullptr, bool isEditable = true); + virtual ~FileTreeModel (); void setEditable (bool editable); - public: - QVariant data (const QModelIndex &index, int role = Qt::DisplayRole) const; - Qt::ItemFlags flags (const QModelIndex& index) const; - QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; - QModelIndex index (int row, int column, const QModelIndex& parent = QModelIndex()) const; - QModelIndex parent (const QModelIndex& child) const; + void clear (); + void addFile (int index, const QString& filename, + bool wanted, int priority, + uint64_t size, uint64_t have, + QList& rowsAdded, + bool torrentChanged); + QModelIndex parent (const QModelIndex& child, int column) const; - int rowCount (const QModelIndex& parent = QModelIndex()) const; - int columnCount (const QModelIndex &parent = QModelIndex()) const; - virtual bool setData (const QModelIndex & index, const QVariant & value, int role = Qt::EditRole); + + // QAbstractItemModel + virtual QVariant data (const QModelIndex& index, int role = Qt::DisplayRole) const; + virtual Qt::ItemFlags flags (const QModelIndex& index) const; + virtual QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; + virtual QModelIndex index (int row, int column, const QModelIndex& parent = QModelIndex ()) const; + virtual QModelIndex parent (const QModelIndex& child) const; + virtual int rowCount (const QModelIndex& parent = QModelIndex ()) const; + virtual int columnCount (const QModelIndex& parent = QModelIndex ()) const; + virtual bool setData (const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); + + public slots: + void clicked (const QModelIndex& index); + void doubleClicked (const QModelIndex& index); signals: void priorityChanged (const QSet& fileIndices, int); @@ -61,30 +73,19 @@ class FileTreeModel: public QAbstractItemModel void pathEdited (const QString& oldpath, const QString& newname); void openRequested (const QString& path); - public: - void clear (); - void addFile (int index, const QString& filename, - bool wanted, int priority, - uint64_t size, uint64_t have, - QList& rowsAdded, - bool torrentChanged); - private: - void clearSubtree (const QModelIndex &); + void clearSubtree (const QModelIndex&); QModelIndex indexOf (FileTreeItem *, int column) const; - void parentsChanged (const QModelIndex &, int firstColumn, int lastColumn); - void subtreeChanged (const QModelIndex &, int firstColumn, int lastColumn); + void parentsChanged (const QModelIndex&, int firstColumn, int lastColumn); + void subtreeChanged (const QModelIndex&, int firstColumn, int lastColumn); FileTreeItem * findItemForFileIndex (int fileIndex) const; FileTreeItem * itemFromIndex (const QModelIndex&) const; private: - FileTreeItem * myRootItem; - QMap myIndexCache; bool myIsEditable; - public slots: - void clicked (const QModelIndex & index); - void doubleClicked (const QModelIndex & index); + FileTreeItem * myRootItem; + QMap myIndexCache; }; #endif // QTR_FILE_TREE_MODEL_H diff --git a/qt/FileTreeView.h b/qt/FileTreeView.h index aadd7041b..ee559a002 100644 --- a/qt/FileTreeView.h +++ b/qt/FileTreeView.h @@ -25,12 +25,18 @@ class FileTreeView: public QTreeView Q_OBJECT public: - FileTreeView (QWidget * parent=0, bool editable=true); + FileTreeView (QWidget * parent = nullptr, bool editable = true); + void clear (); - void update (const FileList& files, bool updateProperties=true); + void update (const FileList& files, bool updateProperties = true); void setEditable (bool editable); + public slots: + void onClicked (const QModelIndex& index); + void onDoubleClicked (const QModelIndex& index); + void onOpenRequested (const QString& path); + signals: void priorityChanged (const QSet& fileIndices, int priority); void wantedChanged (const QSet& fileIndices, bool wanted); @@ -38,17 +44,13 @@ class FileTreeView: public QTreeView void openRequested (const QString& path); protected: + // QObject bool eventFilter (QObject *, QEvent *); private: FileTreeModel * myModel; QSortFilterProxyModel * myProxy; FileTreeDelegate * myDelegate; - - public slots: - void onClicked (const QModelIndex& index); - void onDoubleClicked (const QModelIndex& index); - void onOpenRequested (const QString& path); }; #endif // QTR_FILE_TREE_VIEW_H diff --git a/qt/FilterBar.cc b/qt/FilterBar.cc index b420c8595..52215c4b9 100644 --- a/qt/FilterBar.cc +++ b/qt/FilterBar.cc @@ -19,6 +19,7 @@ #include "FilterBarComboBoxDelegate.h" #include "FilterBarLineEdit.h" #include "Prefs.h" +#include "Torrent.h" #include "TorrentFilter.h" #include "TorrentModel.h" @@ -103,7 +104,7 @@ FilterBar::createActivityCombo () void FilterBar::refreshTrackers () { - FaviconCache& favicons = qApp->favicons; + FaviconCache& favicons = qApp->faviconCache (); const int firstTrackerRow = 2; // skip over the "All" and separator... // pull info from the tracker model... diff --git a/qt/FilterBar.h b/qt/FilterBar.h index 3d623ebaf..6c094a0bf 100644 --- a/qt/FilterBar.h +++ b/qt/FilterBar.h @@ -27,28 +27,16 @@ class FilterBar: public QWidget Q_OBJECT public: - FilterBar (Prefs& prefs, const TorrentModel& torrents, const TorrentFilter& filter, QWidget * parent = 0); - ~FilterBar (); + FilterBar (Prefs& prefs, const TorrentModel& torrents, const TorrentFilter& filter, QWidget * parent = nullptr); + virtual ~FilterBar (); private: - FilterBarComboBox * createTrackerCombo (QStandardItemModel * ); + FilterBarComboBox * createTrackerCombo (QStandardItemModel *); FilterBarComboBox * createActivityCombo (); void recountSoon (); void refreshTrackers (); QString getCountString (int n) const; - private: - Prefs& myPrefs; - const TorrentModel& myTorrents; - const TorrentFilter& myFilter; - FilterBarComboBox * myActivityCombo; - FilterBarComboBox * myTrackerCombo; - QLabel * myCountLabel; - QStandardItemModel * myTrackerModel; - QTimer * myRecountTimer; - bool myIsBootstrapping; - FilterBarLineEdit * myLineEdit; - private slots: void recount (); void refreshPref (int key); @@ -60,6 +48,19 @@ class FilterBar: public QWidget void onTorrentModelRowsRemoved (const QModelIndex&, int, int); void onTorrentModelDataChanged (const QModelIndex&, const QModelIndex&); void onTextChanged (const QString&); + + private: + Prefs& myPrefs; + const TorrentModel& myTorrents; + const TorrentFilter& myFilter; + + FilterBarComboBox * myActivityCombo; + FilterBarComboBox * myTrackerCombo; + QLabel * myCountLabel; + QStandardItemModel * myTrackerModel; + QTimer * myRecountTimer; + bool myIsBootstrapping; + FilterBarLineEdit * myLineEdit; }; #endif // QTR_FILTER_BAR_H diff --git a/qt/FilterBarComboBox.h b/qt/FilterBarComboBox.h index 56dc52ee7..9e698022e 100644 --- a/qt/FilterBarComboBox.h +++ b/qt/FilterBarComboBox.h @@ -25,13 +25,16 @@ class FilterBarComboBox: public QComboBox }; public: - FilterBarComboBox (QWidget * parent = 0); + FilterBarComboBox (QWidget * parent = nullptr); + int currentCount () const; + // QWidget virtual QSize minimumSizeHint () const; virtual QSize sizeHint () const; protected: + // QWidget virtual void paintEvent (QPaintEvent * e); private: diff --git a/qt/FilterBarComboBoxDelegate.h b/qt/FilterBarComboBoxDelegate.h index 1e34f6816..1a5c98aeb 100644 --- a/qt/FilterBarComboBoxDelegate.h +++ b/qt/FilterBarComboBoxDelegate.h @@ -22,16 +22,16 @@ class FilterBarComboBoxDelegate: public QItemDelegate public: FilterBarComboBoxDelegate (QObject * parent, QComboBox * combo); - public: static bool isSeparator (const QModelIndex &index); static void setSeparator (QAbstractItemModel * model, const QModelIndex& index); protected: - virtual void paint (QPainter*, const QStyleOptionViewItem&, const QModelIndex&) const; + // QAbstractItemDelegate + virtual void paint (QPainter *, const QStyleOptionViewItem&, const QModelIndex&) const; virtual QSize sizeHint (const QStyleOptionViewItem&, const QModelIndex&) const; private: - QComboBox * myCombo; + QComboBox * const myCombo; }; #endif // QTR_FILTER_BAR_COMBO_BOX_DELEGATE_H diff --git a/qt/FilterBarLineEdit.h b/qt/FilterBarLineEdit.h index 52e2b68a3..6db67dbe6 100644 --- a/qt/FilterBarLineEdit.h +++ b/qt/FilterBarLineEdit.h @@ -19,9 +19,10 @@ class FilterBarLineEdit: public QLineEdit Q_OBJECT public: - FilterBarLineEdit (QWidget * parent = 0); + FilterBarLineEdit (QWidget * parent = nullptr); protected: + // QWidget virtual void resizeEvent (QResizeEvent * event); private slots: diff --git a/qt/Filters.h b/qt/Filters.h index cd75ae104..1776a73e9 100644 --- a/qt/Filters.h +++ b/qt/Filters.h @@ -16,40 +16,72 @@ class FilterMode { + public: + enum + { + SHOW_ALL, + SHOW_ACTIVE, + SHOW_DOWNLOADING, + SHOW_SEEDING, + SHOW_PAUSED, + SHOW_FINISHED, + SHOW_VERIFYING, + SHOW_ERROR, + NUM_MODES + }; + + public: + FilterMode (int mode = SHOW_ALL): myMode (mode) {} + FilterMode (const QString& name): myMode (modeFromName (name)) {} + + int mode () const { return myMode; } + const QString& name () const { return names[myMode]; } + + static int modeFromName (const QString& name); + static const QString& nameFromMode(int mode) { return names[mode]; } + private: int myMode; - public: - FilterMode( int mode=SHOW_ALL ): myMode(mode) {} - FilterMode( const QString& name ): myMode(modeFromName(name)) {} static const QString names[]; - enum { SHOW_ALL, SHOW_ACTIVE, SHOW_DOWNLOADING, SHOW_SEEDING, SHOW_PAUSED, - SHOW_FINISHED, SHOW_VERIFYING, SHOW_ERROR, NUM_MODES }; - static int modeFromName( const QString& name ); - static const QString& nameFromMode( int mode ) { return names[mode]; } - int mode() const { return myMode; } - const QString& name() const { return names[myMode]; } }; +Q_DECLARE_METATYPE(FilterMode) + class SortMode { + public: + enum + { + SORT_BY_ACTIVITY, + SORT_BY_AGE, + SORT_BY_ETA, + SORT_BY_NAME, + SORT_BY_PROGRESS, + SORT_BY_QUEUE, + SORT_BY_RATIO, + SORT_BY_SIZE, + SORT_BY_STATE, + SORT_BY_ID, + NUM_MODES + }; + + public: + SortMode (int mode = SORT_BY_ID): myMode (mode) {} + SortMode (const QString& name): myMode (modeFromName (name)) {} + + int mode () const { return myMode; } + const QString& name () const { return names[myMode]; } + + static int modeFromName (const QString& name); + static const QString& nameFromMode (int mode); + private: int myMode; - public: - SortMode( int mode=SORT_BY_ID ): myMode(mode) {} - SortMode( const QString& name ): myMode(modeFromName(name)) {} static const QString names[]; - enum { SORT_BY_ACTIVITY, SORT_BY_AGE, SORT_BY_ETA, SORT_BY_NAME, - SORT_BY_PROGRESS, SORT_BY_QUEUE, SORT_BY_RATIO, SORT_BY_SIZE, - SORT_BY_STATE, SORT_BY_ID, NUM_MODES }; - static int modeFromName( const QString& name ); - static const QString& nameFromMode( int mode ); - int mode() const { return myMode; } - const QString& name() const { return names[myMode]; } }; -Q_DECLARE_METATYPE(FilterMode) Q_DECLARE_METATYPE(SortMode) #endif // QTR_FILTERS_H diff --git a/qt/Formatter.h b/qt/Formatter.h index 970d61e8e..a5e9d357e 100644 --- a/qt/Formatter.h +++ b/qt/Formatter.h @@ -12,41 +12,46 @@ #include // int64_t +#include #include -#include -#include class Speed; -class Formatter: public QObject +class Formatter { - Q_OBJECT + Q_DECLARE_TR_FUNCTIONS (Formatter) public: - - Formatter() {} - virtual ~Formatter() {} + enum Size + { + B, + KB, + MB, + GB, + TB + }; + + enum Type + { + SPEED, + SIZE, + MEM + }; public: - static QString memToString (int64_t bytes); static QString sizeToString (int64_t bytes); static QString speedToString (const Speed& speed); static QString percentToString (double x); static QString ratioToString (double ratio); static QString timeToString (int seconds); - static QString uploadSpeedToString(const Speed& up); - static QString downloadSpeedToString(const Speed& down); + static QString uploadSpeedToString (const Speed& up); + static QString downloadSpeedToString (const Speed& down); - public: - - typedef enum { B, KB, MB, GB, TB } Size; - typedef enum { SPEED, SIZE, MEM } Type; static QString unitStr (Type t, Size s) { return unitStrings[t][s]; } static void initUnits (); private: - static QString unitStrings[3][5]; }; diff --git a/qt/FreeSpaceLabel.h b/qt/FreeSpaceLabel.h index 4438685e3..7c633ec9b 100644 --- a/qt/FreeSpaceLabel.h +++ b/qt/FreeSpaceLabel.h @@ -12,9 +12,9 @@ #include +#include #include #include -#include class Session; @@ -28,21 +28,21 @@ class FreeSpaceLabel: public QLabel Q_OBJECT public: - FreeSpaceLabel (QWidget * parent = 0); + FreeSpaceLabel (QWidget * parent = nullptr); virtual ~FreeSpaceLabel () {} void setSession (Session& session); void setPath (const QString& folder); + private slots: + void onSessionExecuted (int64_t tag, const QString& result, tr_variant * arguments); + void onTimer (); + private: Session * mySession; int64_t myTag; QString myPath; QTimer myTimer; - - private slots: - void onSessionExecuted (int64_t tag, const QString& result, tr_variant * arguments); - void onTimer (); }; #endif // QTR_FREE_SPACE_LABEL_H diff --git a/qt/IconToolButton.h b/qt/IconToolButton.h index 40a360845..91906ffbe 100644 --- a/qt/IconToolButton.h +++ b/qt/IconToolButton.h @@ -20,6 +20,7 @@ class IconToolButton: public QToolButton IconToolButton (QWidget * parent = nullptr); protected: + // QWidget virtual void paintEvent (QPaintEvent * event); }; diff --git a/qt/LicenseDialog.h b/qt/LicenseDialog.h index 921e3edfd..53888e135 100644 --- a/qt/LicenseDialog.h +++ b/qt/LicenseDialog.h @@ -17,8 +17,8 @@ class LicenseDialog: public QDialog Q_OBJECT public: - LicenseDialog (QWidget * parent = 0); - ~LicenseDialog () {} + LicenseDialog (QWidget * parent = nullptr); + virtual ~LicenseDialog () {} }; #endif // QTR_LICENSE_DIALOG_H diff --git a/qt/MainWindow.cc b/qt/MainWindow.cc index a47a4f183..614ec59e1 100644 --- a/qt/MainWindow.cc +++ b/qt/MainWindow.cc @@ -79,6 +79,9 @@ MainWindow::getStockIcon (const QString& name, int fallback) } MainWindow::MainWindow (Session& session, Prefs& prefs, TorrentModel& model, bool minimized): + mySession (session), + myPrefs (prefs), + myModel (model), myLastFullUpdateTime (0), mySessionDialog (new SessionDialog (session, prefs, this)), myPrefsDialog (), @@ -88,9 +91,6 @@ MainWindow::MainWindow (Session& session, Prefs& prefs, TorrentModel& model, boo myFilterModel (prefs), myTorrentDelegate (new TorrentDelegate (this)), myTorrentDelegateMin (new TorrentDelegateMin (this)), - mySession (session), - myPrefs (prefs), - myModel (model), myLastSendTime (0), myLastReadTime (0), myNetworkTimer (this), diff --git a/qt/MainWindow.h b/qt/MainWindow.h index 33c1d40f8..dfc3bef9a 100644 --- a/qt/MainWindow.h +++ b/qt/MainWindow.h @@ -11,36 +11,30 @@ #define QTR_MAIN_WINDOW_H #include -#include -#include + #include -#include +#include #include -#include #include #include #include #include -#include #include "Filters.h" #include "TorrentFilter.h" #include "ui_MainWindow.h" +class QAction; +class QIcon; +class QMenu; + class AddData; -class ActionDelegator; class Prefs; class DetailsDialog; class Session; class TorrentDelegate; class TorrentDelegateMin; class TorrentModel; -class QAction; -class QLabel; -class QMenu; -class QModelIndex; -class QSortFilterProxyModel; -class Filterbar; extern "C" { @@ -51,45 +45,56 @@ class MainWindow: public QMainWindow { Q_OBJECT - private: - virtual void hideEvent (QHideEvent * event); - virtual void showEvent (QShowEvent * event); + public: + MainWindow (Session&, Prefs&, TorrentModel&, bool minized); + virtual ~MainWindow (); - private: - time_t myLastFullUpdateTime; - QDialog * mySessionDialog; - QPointer myPrefsDialog; - QDialog * myAboutDialog; - QDialog * myStatsDialog; - DetailsDialog * myDetailsDialog; - QSystemTrayIcon myTrayIcon; - TorrentFilter myFilterModel; - TorrentDelegate * myTorrentDelegate; - TorrentDelegateMin * myTorrentDelegateMin; - Session& mySession; - Prefs& myPrefs; - TorrentModel& myModel; - Ui_MainWindow ui; - time_t myLastSendTime; - time_t myLastReadTime; - QTimer myNetworkTimer; - bool myNetworkError; - QTimer myRefreshTrayIconTimer; - QTimer myRefreshActionSensitivityTimer; - QAction * myDlimitOffAction; - QAction * myDlimitOnAction; - QAction * myUlimitOffAction; - QAction * myUlimitOnAction; - QAction * myRatioOffAction; - QAction * myRatioOnAction; + public slots: + void startAll (); + void startSelected (); + void startSelectedNow (); + void pauseAll (); + void pauseSelected (); + void removeSelected (); + void deleteSelected (); + void verifySelected (); + void queueMoveTop (); + void queueMoveUp (); + void queueMoveDown (); + void queueMoveBottom (); + void reannounceSelected (); + void onNetworkTimer (); - private: - QIcon getStockIcon (const QString&, int fallback=-1); + void setToolbarVisible (bool); + void setFilterbarVisible (bool); + void setStatusbarVisible (bool); + void setCompactView (bool); + void refreshActionSensitivity (); + void refreshActionSensitivitySoon (); + void wrongAuthentication (); + + protected: + // QWidget + virtual void contextMenuEvent (QContextMenuEvent *); + virtual void dragEnterEvent (QDragEnterEvent *); + virtual void dropEvent (QDropEvent *); private: + QIcon getStockIcon (const QString&, int fallback = -1); + QSet getSelectedTorrents () const; void updateNetworkIcon (); - QWidgetList myHidden; + + QMenu * createOptionsMenu (); + QMenu * createStatsModeMenu (); + void initStatusBar (); + + void clearSelection (); + void addTorrent (const AddData& addMe, bool showOptions); + + // QWidget + virtual void hideEvent (QHideEvent * event); + virtual void showEvent (QShowEvent * event); private slots: void openPreferences (); @@ -126,7 +131,6 @@ class MainWindow: public QMainWindow void onSessionSourceChanged (); void onModelReset (); - private slots: void setSortPref (int); void setSortAscendingPref (bool); void onSortByActivityToggled (bool); @@ -140,53 +144,38 @@ class MainWindow: public QMainWindow void onSortByStateToggled (bool); private: - QWidget * myFilterBar; + Session& mySession; + Prefs& myPrefs; + TorrentModel& myModel; - private: - QMenu * createOptionsMenu (); - QMenu * createStatsModeMenu (); - void initStatusBar (); + Ui_MainWindow ui; + time_t myLastFullUpdateTime; + QDialog * mySessionDialog; + QPointer myPrefsDialog; + QDialog * myAboutDialog; + QDialog * myStatsDialog; + DetailsDialog * myDetailsDialog; + QSystemTrayIcon myTrayIcon; + TorrentFilter myFilterModel; + TorrentDelegate * myTorrentDelegate; + TorrentDelegateMin * myTorrentDelegateMin; + time_t myLastSendTime; + time_t myLastReadTime; + QTimer myNetworkTimer; + bool myNetworkError; + QTimer myRefreshTrayIconTimer; + QTimer myRefreshActionSensitivityTimer; + QAction * myDlimitOffAction; + QAction * myDlimitOnAction; + QAction * myUlimitOffAction; + QAction * myUlimitOnAction; + QAction * myRatioOffAction; + QAction * myRatioOnAction; + QWidgetList myHidden; + QWidget * myFilterBar; QAction * myAltSpeedAction; QString myErrorMessage; - - public slots: - void startAll (); - void startSelected (); - void startSelectedNow (); - void pauseAll (); - void pauseSelected (); - void removeSelected (); - void deleteSelected (); - void verifySelected (); - void queueMoveTop (); - void queueMoveUp (); - void queueMoveDown (); - void queueMoveBottom (); - void reannounceSelected (); - void onNetworkTimer (); - - private: - void clearSelection (); - void addTorrent (const AddData& addMe, bool showOptions); - - public slots: - void setToolbarVisible (bool); - void setFilterbarVisible (bool); - void setStatusbarVisible (bool); - void setCompactView (bool); - void refreshActionSensitivity (); - void refreshActionSensitivitySoon (); - void wrongAuthentication (); - - public: - MainWindow (Session&, Prefs&, TorrentModel&, bool minized); - virtual ~MainWindow (); - - protected: - virtual void contextMenuEvent (QContextMenuEvent *); - virtual void dragEnterEvent (QDragEnterEvent *); - virtual void dropEvent (QDropEvent *); }; #endif // QTR_MAIN_WINDOW_H diff --git a/qt/MakeDialog.h b/qt/MakeDialog.h index 5737f88ee..254f1d0ad 100644 --- a/qt/MakeDialog.h +++ b/qt/MakeDialog.h @@ -29,25 +29,28 @@ class MakeDialog: public QDialog { Q_OBJECT - private slots: - void onSourceChanged (); - void makeTorrent (); + public: + MakeDialog (Session&, QWidget * parent = nullptr); + virtual ~MakeDialog (); + + protected: + // QWidget + virtual void dragEnterEvent (QDragEnterEvent *); + virtual void dropEvent (QDropEvent *); private: QString getSource () const; + private slots: + void onSourceChanged (); + void makeTorrent (); + private: Session& mySession; - Ui::MakeDialog ui; - std::unique_ptr myBuilder; - protected: - virtual void dragEnterEvent (QDragEnterEvent *); - virtual void dropEvent (QDropEvent *); + Ui::MakeDialog ui; - public: - MakeDialog (Session&, QWidget * parent = 0); - virtual ~MakeDialog (); + std::unique_ptr myBuilder; }; #endif // QTR_MAKE_DIALOG_H diff --git a/qt/OptionsDialog.h b/qt/OptionsDialog.h index 03529e4e0..1b49f1ca3 100644 --- a/qt/OptionsDialog.h +++ b/qt/OptionsDialog.h @@ -16,7 +16,6 @@ #include #include #include -#include #include #include @@ -38,8 +37,11 @@ class OptionsDialog: public QDialog Q_OBJECT public: - OptionsDialog (Session& session, const Prefs& prefs, const AddData& addme, QWidget * parent = 0); - ~OptionsDialog (); + OptionsDialog (Session& session, const Prefs& prefs, const AddData& addme, QWidget * parent = nullptr); + virtual ~OptionsDialog (); + + private: + typedef QMap mybins_t; private: void reload (); @@ -59,16 +61,17 @@ class OptionsDialog: public QDialog private: Session& mySession; AddData myAdd; + + Ui::OptionsDialog ui; + QDir myLocalDestination; bool myHaveInfo; tr_info myInfo; - Ui::OptionsDialog ui; QPushButton * myVerifyButton; QVector myPriorities; QVector myWanted; FileList myFiles; - private: QTimer myVerifyTimer; char myVerifyBuf[2048 * 4]; QFile myVerifyFile; @@ -78,7 +81,6 @@ class OptionsDialog: public QDialog uint32_t myVerifyPiecePos; QVector myVerifyFlags; QCryptographicHash myVerifyHash; - typedef QMap mybins_t; mybins_t myVerifyBins; QTimer myEditTimer; }; diff --git a/qt/PathButton.h b/qt/PathButton.h index 2f84d387e..9738dc0ee 100644 --- a/qt/PathButton.h +++ b/qt/PathButton.h @@ -33,24 +33,26 @@ class PathButton: public QToolButton void setPath (const QString& path); const QString& path () const; + // QWidget virtual QSize sizeHint () const; signals: void pathChanged (const QString& path); protected: + // QWidget virtual void paintEvent (QPaintEvent * event); - private slots: - void onClicked (); - void onFileSelected (const QString& path); - private: void updateAppearance (); bool isDirMode () const; QString effectiveTitle () const; + private slots: + void onClicked (); + void onFileSelected (const QString& path); + private: Mode myMode; QString myTitle; diff --git a/qt/Prefs.cc b/qt/Prefs.cc index 70d8fb29f..32fc21a62 100644 --- a/qt/Prefs.cc +++ b/qt/Prefs.cc @@ -12,6 +12,7 @@ #include #include +#include #include #include diff --git a/qt/Prefs.h b/qt/Prefs.h index c3291228b..110967584 100644 --- a/qt/Prefs.h +++ b/qt/Prefs.h @@ -10,7 +10,6 @@ #ifndef QTR_PREFS_H #define QTR_PREFS_H -#include #include #include #include @@ -20,6 +19,8 @@ #include "Filters.h" +class QDateTime; + extern "C" { struct tr_variant; @@ -30,7 +31,6 @@ class Prefs: public QObject Q_OBJECT public: - enum { /* client prefs */ @@ -131,36 +131,17 @@ class Prefs: public QObject PREFS_COUNT }; - private: - - struct PrefItem - { - int id; - tr_quark key; - int type; - }; - - static PrefItem myItems[]; - - private: - QSet myTemporaryPrefs; - QString const myConfigDir; - mutable QVariant myValues[PREFS_COUNT]; - void initDefaults (tr_variant *); - - void set (int key, const char * value); - public: - bool isCore (int key) const { return FIRST_CORE_PREF<=key && key<=LAST_CORE_PREF; } + Prefs (const QString& configDir); + virtual ~Prefs (); + + bool isCore (int key) const { return FIRST_CORE_PREF <= key && key <= LAST_CORE_PREF; } bool isClient (int key) const { return !isCore (key); } const char * keyStr (int i) const { return tr_quark_get_string (myItems[i].key,NULL); } - tr_quark getKey (int i) const { return myItems[i].key; } + tr_quark getKey (int i) const { return myItems[i].key; } int type (int i) const { return myItems[i].type; } const QVariant& variant (int i) const { return myValues[i]; } - Prefs (const QString& configDir); - ~Prefs (); - int getInt (int key) const; bool getBool (int key) const; QString getString (int key) const; @@ -173,7 +154,7 @@ class Prefs: public QObject { QVariant& v (myValues[key]); const QVariant tmp = QVariant::fromValue (value); - if (v.isNull() || (v!=tmp)) + if (v.isNull() || v != tmp) { v = tmp; emit changed (key); @@ -184,6 +165,28 @@ class Prefs: public QObject signals: void changed (int key); + + private: + struct PrefItem + { + int id; + tr_quark key; + int type; + }; + + private: + void initDefaults (tr_variant *); + + // Intentionally not implemented + void set (int key, const char * value); + + private: + const QString myConfigDir; + + QSet myTemporaryPrefs; + mutable QVariant myValues[PREFS_COUNT]; + + static PrefItem myItems[]; }; #endif // QTR_PREFS_H diff --git a/qt/PrefsDialog.cc b/qt/PrefsDialog.cc index e9d286e75..68b42bec0 100644 --- a/qt/PrefsDialog.cc +++ b/qt/PrefsDialog.cc @@ -532,9 +532,9 @@ PrefsDialog::initDownloadingTab () PrefsDialog::PrefsDialog (Session& session, Prefs& prefs, QWidget * parent): QDialog (parent), - myIsServer (session.isServer ()), mySession (session), - myPrefs (prefs) + myPrefs (prefs), + myIsServer (session.isServer ()) { ui.setupUi (this); diff --git a/qt/PrefsDialog.h b/qt/PrefsDialog.h index 8f6be8726..78b2e2781 100644 --- a/qt/PrefsDialog.h +++ b/qt/PrefsDialog.h @@ -17,22 +17,10 @@ #include "Prefs.h" #include "ui_PrefsDialog.h" -class QAbstractButton; -class QCheckBox; -class QDoubleSpinBox; class QHttp; -class QLabel; -class QLineEdit; class QMessageBox; -class QPushButton; -class QSpinBox; class QString; -class QTime; -class QTimeEdit; -class QVBoxLayout; -class QWidget; -class FreeSpaceLabel; class Prefs; class Session; @@ -40,6 +28,28 @@ class PrefsDialog: public QDialog { Q_OBJECT + public: + PrefsDialog (Session&, Prefs&, QWidget * parent = nullptr); + virtual ~PrefsDialog (); + + private: + typedef QMap key2widget_t; + + private: + bool updateWidgetValue (QWidget * widget, int prefKey); + void linkWidgetToPref (QWidget * widget, int prefKey); + void updateBlocklistLabel (); + + void setPref (int key, const QVariant& v); + + void initDownloadingTab (); + void initSeedingTab (); + void initSpeedTab (); + void initPrivacyTab (); + void initNetworkTab (); + void initDesktopTab (); + void initRemoteTab (); + private slots: void checkBoxToggled (bool checked); void spinBoxEditingFinished (); @@ -61,31 +71,13 @@ class PrefsDialog: public QDialog void onBlocklistUpdated (int n); private: - bool updateWidgetValue (QWidget * widget, int prefKey); - void linkWidgetToPref (QWidget * widget, int prefKey); - void updateBlocklistLabel (); - - public: - PrefsDialog (Session&, Prefs&, QWidget * parent = 0); - ~PrefsDialog (); - - private: - void setPref (int key, const QVariant& v); + Session& mySession; + Prefs& myPrefs; - void initDownloadingTab (); - void initSeedingTab (); - void initSpeedTab (); - void initPrivacyTab (); - void initNetworkTab (); - void initDesktopTab (); - void initRemoteTab (); + Ui::PrefsDialog ui; - private: - typedef QMap key2widget_t; key2widget_t myWidgets; const bool myIsServer; - Session& mySession; - Prefs& myPrefs; QWidgetList myWebWidgets; QWidgetList myWebAuthWidgets; QWidgetList myWebWhitelistWidgets; @@ -94,7 +86,6 @@ class PrefsDialog: public QDialog QWidgetList mySchedWidgets; QWidgetList myBlockWidgets; QWidgetList myUnsupportedWhenRemote; - Ui::PrefsDialog ui; int myBlocklistHttpTag; QHttp * myBlocklistHttp; diff --git a/qt/RelocateDialog.h b/qt/RelocateDialog.h index 0f5701340..9d31ac614 100644 --- a/qt/RelocateDialog.h +++ b/qt/RelocateDialog.h @@ -23,19 +23,20 @@ class RelocateDialog: public QDialog Q_OBJECT public: - RelocateDialog (Session&, const TorrentModel&, const QSet& ids, QWidget * parent = 0); - ~RelocateDialog () {} + RelocateDialog (Session&, const TorrentModel&, const QSet& ids, QWidget * parent = nullptr); + virtual ~RelocateDialog () {} + + private: + QString newLocation () const; private slots: void onSetLocation (); void onMoveToggled (bool); - private: - QString newLocation () const; - private: Session& mySession; const QSet myIds; + Ui::RelocateDialog ui; static bool myMoveFlag; diff --git a/qt/Session.cc b/qt/Session.cc index 1e6e3cb60..a002c693f 100644 --- a/qt/Session.cc +++ b/qt/Session.cc @@ -275,11 +275,11 @@ Session::updatePref (int key) ***/ Session::Session (const QString& configDir, Prefs& prefs): + myConfigDir (configDir), + myPrefs (prefs), nextUniqueTag (FIRST_UNIQUE_TAG), myBlocklistSize (-1), - myPrefs (prefs), - mySession (0), - myConfigDir (configDir) + mySession (0) { myStats.ratio = TR_RATIO_NA; myStats.uploadedBytes = 0; diff --git a/qt/Session.h b/qt/Session.h index 9a29736b6..a372411e3 100644 --- a/qt/Session.h +++ b/qt/Session.h @@ -34,7 +34,8 @@ class FileAdded: public QObject public: FileAdded (int64_t tag, const QString& name): myTag (tag), myName (name) {} - ~FileAdded () {} + virtual ~FileAdded () {} + void setFileToDelete (const QString& file) { myDelFile = file; } public slots: @@ -43,6 +44,7 @@ class FileAdded: public QObject private: const int64_t myTag; const QString myName; + QString myDelFile; }; @@ -52,55 +54,33 @@ class Session: public QObject public: Session (const QString& configDir, Prefs& prefs); - ~Session (); + virtual ~Session (); - public: void stop (); void restart (); - private: - void start (); - - public: const QUrl& getRemoteUrl () const { return myRpc.url (); } const tr_session_stats& getStats () const { return myStats; } const tr_session_stats& getCumulativeStats () const { return myCumulativeStats; } const QString& sessionVersion () const { return mySessionVersion; } - public: int64_t blocklistSize () const { return myBlocklistSize; } void setBlocklistSize (int64_t i); void updateBlocklist (); void portTest (); void copyMagnetLinkToClipboard (int torrentId); - public: - /** returns true if the transmission session is being run inside this client */ bool isServer () const; /** returns true if isServer () is true or if the remote address is the localhost */ bool isLocal () const; - private: - void updateStats (tr_variant * args); - void updateInfo (tr_variant * args); - - public: void exec (tr_quark method, tr_variant * args, int64_t tag = -1); - void exec (const char* method, tr_variant * args, int64_t tag = -1); + void exec (const char * method, tr_variant * args, int64_t tag = -1); - public: int64_t getUniqueTag () { return nextUniqueTag++; } - private: - void sessionSet (const tr_quark key, const QVariant& variant); - void pumpRequests (); - void sendTorrentRequest (const char * request, const QSet& torrentIds); - static void updateStats (tr_variant * d, tr_session_stats * stats); - void refreshTorrents (const QSet& torrentIds); - - public: void torrentSet (const QSet& ids, const tr_quark key, bool val); void torrentSet (const QSet& ids, const tr_quark key, int val); void torrentSet (const QSet& ids, const tr_quark key, double val); @@ -126,18 +106,15 @@ class Session: public QObject void initTorrents (const QSet& ids = QSet ()); void addNewlyCreatedTorrent (const QString& filename, const QString& localPath); void addTorrent (const AddData& addme); - void removeTorrents (const QSet& torrentIds, bool deleteFiles=false); + void removeTorrents (const QSet& torrentIds, bool deleteFiles = false); void verifyTorrents (const QSet& torrentIds); void reannounceTorrents (const QSet& torrentIds); void launchWebInterface (); void updatePref (int key); - + /** request a refresh for statistics, including the ones only used by the properties dialog, for a specific torrent */ void refreshExtraStats (const QSet& ids); - private slots: - void responseReceived (int64_t tag, const QString& result, tr_variant * args); - signals: void executed (int64_t tag, const QString& result, tr_variant * arguments); void sourceChanged (); @@ -154,11 +131,28 @@ class Session: public QObject void httpAuthenticationRequired (); private: + void start (); + + void updateStats (tr_variant * args); + void updateInfo (tr_variant * args); + + void sessionSet (const tr_quark key, const QVariant& variant); + void pumpRequests (); + void sendTorrentRequest (const char * request, const QSet& torrentIds); + void refreshTorrents (const QSet& torrentIds); + + static void updateStats (tr_variant * d, tr_session_stats * stats); + + private slots: + void responseReceived (int64_t tag, const QString& result, tr_variant * args); + + private: + QString const myConfigDir; + Prefs& myPrefs; + int64_t nextUniqueTag; int64_t myBlocklistSize; - Prefs& myPrefs; tr_session * mySession; - QString const myConfigDir; QStringList myIdleJSON; tr_session_stats myStats; tr_session_stats myCumulativeStats; diff --git a/qt/SessionDialog.h b/qt/SessionDialog.h index b1e805032..fc9537a31 100644 --- a/qt/SessionDialog.h +++ b/qt/SessionDialog.h @@ -23,8 +23,8 @@ class SessionDialog: public QDialog Q_OBJECT public: - SessionDialog (Session& session, Prefs& prefs, QWidget * parent = 0); - ~SessionDialog () {} + SessionDialog (Session& session, Prefs& prefs, QWidget * parent = nullptr); + virtual ~SessionDialog () {} private slots: void onAccepted (); @@ -33,7 +33,9 @@ class SessionDialog: public QDialog private: Session& mySession; Prefs& myPrefs; + Ui::SessionDialog ui; + QWidgetList myRemoteWidgets; QWidgetList myAuthWidgets; }; diff --git a/qt/Speed.h b/qt/Speed.h index 7c7ae33b0..0f4775c5a 100644 --- a/qt/Speed.h +++ b/qt/Speed.h @@ -10,16 +10,11 @@ #ifndef QTR_SPEED_H #define QTR_SPEED_H -#include "Formatter.h" - class Speed { - private: - int _Bps; - Speed (int Bps): _Bps (Bps) {} - public: Speed (): _Bps (0) {} + double KBps () const; int Bps () const { return _Bps; } bool isZero () const { return _Bps == 0; } @@ -29,6 +24,12 @@ class Speed Speed& operator+= (const Speed& that) { _Bps += that._Bps; return *this; } Speed operator+ (const Speed& that) const { return Speed (_Bps + that._Bps); } bool operator< (const Speed& that) const { return _Bps < that._Bps; } + + private: + Speed (int Bps): _Bps (Bps) {} + + private: + int _Bps; }; #endif // QTR_SPEED_H diff --git a/qt/SqueezeLabel.h b/qt/SqueezeLabel.h index 5d5834e7f..3f3c35d60 100644 --- a/qt/SqueezeLabel.h +++ b/qt/SqueezeLabel.h @@ -49,11 +49,12 @@ class SqueezeLabel: public QLabel Q_OBJECT public: - SqueezeLabel (QWidget *parent=0); - SqueezeLabel (const QString& text, QWidget *parent=0); + SqueezeLabel (QWidget * parent = nullptr); + SqueezeLabel (const QString& text, QWidget * parent = nullptr); protected: - void paintEvent (QPaintEvent* paintEvent); + // QWidget + virtual void paintEvent (QPaintEvent * paintEvent); }; #endif // QTR_SQUEEZE_LABEL_H diff --git a/qt/StatsDialog.h b/qt/StatsDialog.h index 9032e4624..4b3fea841 100644 --- a/qt/StatsDialog.h +++ b/qt/StatsDialog.h @@ -14,25 +14,30 @@ #include "ui_StatsDialog.h" -class Session; class QTimer; +class Session; + class StatsDialog: public QDialog { Q_OBJECT - private slots: - void updateStats (); - public: - StatsDialog (Session&, QWidget * parent = 0); + StatsDialog (Session&, QWidget * parent = nullptr); ~StatsDialog (); + + // QWidget virtual void setVisible (bool visible); + private slots: + void updateStats (); + private: - Session & mySession; - QTimer * myTimer; + Session& mySession; + Ui::StatsDialog ui; + + QTimer * myTimer; }; #endif // QTR_STATS_DIALOG_H diff --git a/qt/Torrent.cc b/qt/Torrent.cc index b838b5b78..17e01b5dc 100644 --- a/qt/Torrent.cc +++ b/qt/Torrent.cc @@ -29,8 +29,8 @@ #include "Utils.h" Torrent::Torrent (const Prefs& prefs, int id): - magnetTorrent (false), - myPrefs (prefs) + myPrefs (prefs), + magnetTorrent (false) { #ifndef NDEBUG for (int i=0; ifavicons.add (QUrl(QString::fromUtf8(str))); + qApp->faviconCache ().add (QUrl(QString::fromUtf8(str))); list.append (QString::fromUtf8 (str, len)); } } @@ -644,7 +644,7 @@ Torrent::update (tr_variant * d) if (tr_variantDictFindStr(child, TR_KEY_announce, &str, &len)) { trackerStat.announce = QString::fromUtf8 (str, len); - qApp->favicons.add (QUrl (trackerStat.announce)); + qApp->faviconCache ().add (QUrl (trackerStat.announce)); } if (tr_variantDictFindInt (child, TR_KEY_announceState, &i)) @@ -800,6 +800,6 @@ Torrent::getError () const QPixmap TrackerStat::getFavicon () const { - return qApp->favicons.find (QUrl (announce)); + return qApp->faviconCache ().find (QUrl (announce)); } diff --git a/qt/Torrent.h b/qt/Torrent.h index f7707594c..815d0e07e 100644 --- a/qt/Torrent.h +++ b/qt/Torrent.h @@ -17,7 +17,6 @@ #include #include #include -#include #include #include @@ -30,9 +29,9 @@ #undef ERROR #endif -class Prefs; class QPixmap; -class QStyle; + +class Prefs; extern "C" { @@ -58,12 +57,15 @@ struct Peer double progress; }; -typedef QList PeerList; Q_DECLARE_METATYPE(Peer) + +typedef QList PeerList; Q_DECLARE_METATYPE(PeerList) struct TrackerStat { + QPixmap getFavicon () const; + bool hasAnnounced; bool hasScraped; bool isBackup; @@ -89,16 +91,16 @@ struct TrackerStat QString host; QString lastAnnounceResult; QString lastScrapeResult; - QPixmap getFavicon () const; }; -typedef QList TrackerStatsList; Q_DECLARE_METATYPE(TrackerStat) + +typedef QList TrackerStatsList; Q_DECLARE_METATYPE(TrackerStatsList) struct TorrentFile { - TorrentFile(): wanted(true), index(-1), priority(0), size(0), have(0) {} + TorrentFile(): wanted (true), index (-1), priority (0), size (0), have (0) {} bool wanted; int index; @@ -108,17 +110,16 @@ struct TorrentFile uint64_t have; }; -typedef QList FileList; Q_DECLARE_METATYPE(TorrentFile) -Q_DECLARE_METATYPE(FileList) +typedef QList FileList; +Q_DECLARE_METATYPE(FileList) class Torrent: public QObject { Q_OBJECT public: - enum { ID, @@ -181,66 +182,11 @@ class Torrent: public QObject PROPERTY_COUNT }; - public: - Torrent (const Prefs&, int id); - virtual ~Torrent (); - - signals: - void torrentChanged (int id); - void torrentCompleted (int id); - - private: - - enum Group - { - INFO, // info fields that only need to be loaded once - STAT, // commonly-used stats that should be refreshed often - STAT_EXTRA, // rarely used; only refresh if details dialog is open - DERIVED // doesn't come from RPC - }; - - struct Property - { - int id; - tr_quark key; - int type; - int group; - }; - - static Property myProperties[]; - - bool magnetTorrent; - - public: typedef QList KeyList; - static const KeyList& getInfoKeys (); - static const KeyList& getStatKeys (); - static const KeyList& getExtraStatKeys (); - - private: - static KeyList buildKeyList (Group group); - - private: - QVariant myValues[PROPERTY_COUNT]; - - int getInt (int key) const; - bool getBool (int key) const; - QTime getTime (int key) const; - QIcon getIcon (int key) const; - double getDouble (int key) const; - qulonglong getSize (int key) const; - QString getString (int key) const; - QDateTime getDateTime (int key) const; - - bool setInt (int key, int value); - bool setBool (int key, bool value); - bool setIcon (int key, const QIcon&); - bool setDouble (int key, double); - bool setString (int key, const char *); - bool setSize (int key, qulonglong); - bool setDateTime (int key, const QDateTime&); public: + Torrent (const Prefs&, int id); + virtual ~Torrent (); int getBandwidthPriority () const { return getInt (BANDWIDTH_PRIORITY); } int id () const { return getInt (ID); } @@ -314,7 +260,6 @@ class Torrent: public QObject int queuePosition () const { return getInt (QUEUE_POSITION); } bool isStalled () const { return getBool (IS_STALLED); } - public: QString activityString () const; tr_torrent_activity getActivity () const { return static_cast (getInt (ACTIVITY)); } bool isFinished () const { return getBool (IS_FINISHED); } @@ -329,20 +274,67 @@ class Torrent: public QObject bool isQueued () const { return isWaitingToDownload() || isWaitingToSeed(); } void notifyComplete () const; - public: void update (tr_variant * dict); void setMagnet (bool magnet) { magnetTorrent = magnet; } + QIcon getMimeTypeIcon () const { return getIcon (MIME_ICON); } + + static const KeyList& getInfoKeys (); + static const KeyList& getStatKeys (); + static const KeyList& getExtraStatKeys (); + + signals: + void torrentChanged (int id); + void torrentCompleted (int id); + private: + enum Group + { + INFO, // info fields that only need to be loaded once + STAT, // commonly-used stats that should be refreshed often + STAT_EXTRA, // rarely used; only refresh if details dialog is open + DERIVED // doesn't come from RPC + }; + + struct Property + { + int id; + tr_quark key; + int type; + int group; + }; + + private: + int getInt (int key) const; + bool getBool (int key) const; + QTime getTime (int key) const; + QIcon getIcon (int key) const; + double getDouble (int key) const; + qulonglong getSize (int key) const; + QString getString (int key) const; + QDateTime getDateTime (int key) const; + + bool setInt (int key, int value); + bool setBool (int key, bool value); + bool setIcon (int key, const QIcon&); + bool setDouble (int key, double); + bool setString (int key, const char *); + bool setSize (int key, qulonglong); + bool setDateTime (int key, const QDateTime&); + const char * getMimeTypeString () const; void updateMimeIcon (); - public: - QIcon getMimeTypeIcon () const { return getIcon (MIME_ICON); } + static KeyList buildKeyList (Group group); private: const Prefs& myPrefs; + + QVariant myValues[PROPERTY_COUNT]; + bool magnetTorrent; FileList myFiles; + + static Property myProperties[]; }; Q_DECLARE_METATYPE(const Torrent*) diff --git a/qt/TorrentDelegate.cc b/qt/TorrentDelegate.cc index fd8010cb6..5b8ff8e6d 100644 --- a/qt/TorrentDelegate.cc +++ b/qt/TorrentDelegate.cc @@ -157,7 +157,7 @@ TorrentDelegate::margin (const QStyle& style) const } QString -TorrentDelegate::progressString (const Torrent& tor) const +TorrentDelegate::progressString (const Torrent& tor) { const bool isMagnet (!tor.hasMetadata()); const bool isDone (tor.isDone ()); @@ -266,7 +266,7 @@ TorrentDelegate::progressString (const Torrent& tor) const } QString -TorrentDelegate::shortTransferString (const Torrent& tor) const +TorrentDelegate::shortTransferString (const Torrent& tor) { QString str; const bool haveMeta (tor.hasMetadata()); @@ -285,7 +285,7 @@ TorrentDelegate::shortTransferString (const Torrent& tor) const } QString -TorrentDelegate::shortStatusString (const Torrent& tor) const +TorrentDelegate::shortStatusString (const Torrent& tor) { QString str; static const QChar ratioSymbol (0x262F); @@ -312,7 +312,7 @@ TorrentDelegate::shortStatusString (const Torrent& tor) const } QString -TorrentDelegate::statusString (const Torrent& tor) const +TorrentDelegate::statusString (const Torrent& tor) { QString str; diff --git a/qt/TorrentDelegate.h b/qt/TorrentDelegate.h index fd1525796..77cc3f004 100644 --- a/qt/TorrentDelegate.h +++ b/qt/TorrentDelegate.h @@ -11,12 +11,10 @@ #define QTR_TORRENT_DELEGATE_H #include -#include -class QStyleOptionProgressBar; -class QStyleOptionViewItem; class QStyle; -class Session; +class QStyleOptionProgressBar; + class Torrent; class TorrentDelegate: public QStyledItemDelegate @@ -24,30 +22,35 @@ class TorrentDelegate: public QStyledItemDelegate Q_OBJECT public: - static QColor blueBrush, greenBrush, silverBrush; - static QColor blueBack, greenBack, silverBack; - - protected: - QStyleOptionProgressBar * myProgressBarStyle; + explicit TorrentDelegate (QObject * parent = nullptr); + virtual ~TorrentDelegate (); - protected: - QString statusString (const Torrent& tor) const; - QString progressString (const Torrent& tor) const; - QString shortStatusString (const Torrent& tor) const; - QString shortTransferString (const Torrent& tor) const; + // QAbstractItemDelegate + virtual QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const; + virtual void paint(QPainter * painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; protected: QSize margin (const QStyle& style) const; + void setProgressBarPercentDone (const QStyleOptionViewItem& option, const Torrent&) const; + + // Our own overridables virtual QSize sizeHint (const QStyleOptionViewItem&, const Torrent&) const; - virtual void setProgressBarPercentDone (const QStyleOptionViewItem& option, const Torrent&) const; - virtual void drawTorrent (QPainter* painter, const QStyleOptionViewItem& option, const Torrent&) const; + virtual void drawTorrent (QPainter * painter, const QStyleOptionViewItem& option, const Torrent&) const; - public: - explicit TorrentDelegate (QObject * parent=0); - virtual ~TorrentDelegate (); + static QString statusString (const Torrent& tor); + static QString progressString (const Torrent& tor); + static QString shortStatusString (const Torrent& tor); + static QString shortTransferString (const Torrent& tor); + + protected: + QStyleOptionProgressBar * myProgressBarStyle; - QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const; - void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; + static QColor blueBrush; + static QColor greenBrush; + static QColor silverBrush; + static QColor blueBack; + static QColor greenBack; + static QColor silverBack; }; #endif // QTR_TORRENT_DELEGATE_H diff --git a/qt/TorrentDelegateMin.h b/qt/TorrentDelegateMin.h index 7f3d247fd..6b184ff95 100644 --- a/qt/TorrentDelegateMin.h +++ b/qt/TorrentDelegateMin.h @@ -10,26 +10,20 @@ #ifndef QTR_TORRENT_DELEGATE_MIN_H #define QTR_TORRENT_DELEGATE_MIN_H -#include - #include "TorrentDelegate.h" -class QStyleOptionViewItem; -class QStyle; -class Session; -class Torrent; - class TorrentDelegateMin: public TorrentDelegate { Q_OBJECT - protected: - virtual QSize sizeHint (const QStyleOptionViewItem&, const Torrent&) const; - void drawTorrent (QPainter* painter, const QStyleOptionViewItem& option, const Torrent&) const; - public: - explicit TorrentDelegateMin (QObject * parent=0): TorrentDelegate(parent) {} + explicit TorrentDelegateMin (QObject * parent = nullptr): TorrentDelegate (parent) {} virtual ~TorrentDelegateMin () {} + + protected: + // TorrentDelegate + virtual QSize sizeHint (const QStyleOptionViewItem&, const Torrent&) const; + virtual void drawTorrent (QPainter * painter, const QStyleOptionViewItem& option, const Torrent&) const; }; #endif // QTR_TORRENT_DELEGATE_MIN_H diff --git a/qt/TorrentFilter.h b/qt/TorrentFilter.h index 7b29d85fd..4ad056b07 100644 --- a/qt/TorrentFilter.h +++ b/qt/TorrentFilter.h @@ -11,11 +11,8 @@ #define QTR_TORRENT_FILTER_H #include -#include -#include class QString; -class QWidget; class FilterMode; class Prefs; @@ -25,18 +22,24 @@ class TorrentFilter: public QSortFilterProxyModel { Q_OBJECT + public: + enum TextMode + { + FILTER_BY_NAME, + FILTER_BY_FILES, + FILTER_BY_TRACKER + }; + public: TorrentFilter (const Prefs& prefs); virtual ~TorrentFilter (); - public: - enum TextMode { FILTER_BY_NAME, FILTER_BY_FILES, FILTER_BY_TRACKER }; int hiddenRowCount () const; - private slots: - void refreshPref (int key); + void countTorrentsPerMode (int * setmeCounts) const; protected: + // QSortFilterProxyModel virtual bool filterAcceptsRow (int, const QModelIndex&) const; virtual bool lessThan (const QModelIndex&, const QModelIndex&) const; @@ -44,8 +47,8 @@ class TorrentFilter: public QSortFilterProxyModel bool activityFilterAcceptsTorrent (const Torrent * tor, const FilterMode& mode) const; bool trackerFilterAcceptsTorrent (const Torrent * tor, const QString& tracker) const; - public: - void countTorrentsPerMode (int * setmeCounts) const; + private slots: + void refreshPref (int key); private: const Prefs& myPrefs; diff --git a/qt/TorrentModel.cc b/qt/TorrentModel.cc index f679ec654..197a0ad89 100644 --- a/qt/TorrentModel.cc +++ b/qt/TorrentModel.cc @@ -13,6 +13,8 @@ #include #include +#include "Speed.h" +#include "Torrent.h" #include "TorrentDelegate.h" #include "TorrentModel.h" diff --git a/qt/TorrentModel.h b/qt/TorrentModel.h index 32493adf5..a383ef4eb 100644 --- a/qt/TorrentModel.h +++ b/qt/TorrentModel.h @@ -15,10 +15,9 @@ #include #include -#include "Speed.h" -#include "Torrent.h" - class Prefs; +class Speed; +class Torrent; extern "C" { @@ -29,35 +28,28 @@ class TorrentModel: public QAbstractListModel { Q_OBJECT - private: - typedef QMap id_to_row_t; - typedef QMap id_to_torrent_t; - typedef QVector torrents_t; - id_to_row_t myIdToRow; - id_to_torrent_t myIdToTorrent; - torrents_t myTorrents; - const Prefs& myPrefs; + public: + enum Role + { + TorrentRole = Qt::UserRole + }; public: + TorrentModel (const Prefs& prefs); + virtual ~TorrentModel (); + void clear (); bool hasTorrent (const QString& hashString) const; - virtual int rowCount (const QModelIndex& parent = QModelIndex()) const; - virtual QVariant data (const QModelIndex& index, int role = Qt::DisplayRole) const; - enum Role { TorrentRole = Qt::UserRole }; - public: - Torrent* getTorrentFromId (int id); - const Torrent* getTorrentFromId (int id) const; + Torrent * getTorrentFromId (int id); + const Torrent * getTorrentFromId (int id) const; - private: - void addTorrent (Torrent *); - QSet getIds () const; + void getTransferSpeed (Speed& uploadSpeed, size_t& uploadPeerCount, + Speed& downloadSpeed, size_t& downloadPeerCount); - public: - void getTransferSpeed (Speed & uploadSpeed, - size_t & uploadPeerCount, - Speed & downloadSpeed, - size_t & downloadPeerCount); + // QAbstractItemModel + virtual int rowCount (const QModelIndex& parent = QModelIndex ()) const; + virtual QVariant data (const QModelIndex& index, int role = Qt::DisplayRole) const; signals: void torrentsAdded (QSet); @@ -67,12 +59,24 @@ class TorrentModel: public QAbstractListModel void removeTorrents (tr_variant * torrentList); void removeTorrent (int id); + private: + typedef QMap id_to_row_t; + typedef QMap id_to_torrent_t; + typedef QVector torrents_t; + + private: + void addTorrent (Torrent *); + QSet getIds () const; + private slots: void onTorrentChanged (int propertyId); - public: - TorrentModel (const Prefs& prefs); - virtual ~TorrentModel (); + private: + const Prefs& myPrefs; + + id_to_row_t myIdToRow; + id_to_torrent_t myIdToTorrent; + torrents_t myTorrents; }; #endif // QTR_TORRENT_MODEL_H diff --git a/qt/TrackerDelegate.h b/qt/TrackerDelegate.h index 7c0c4693d..7bef5464d 100644 --- a/qt/TrackerDelegate.h +++ b/qt/TrackerDelegate.h @@ -11,10 +11,7 @@ #define QTR_TRACKER_DELEGATE_H #include -#include -class QPainter; -class QStyleOptionViewItem; class QStyle; class Session; @@ -25,21 +22,21 @@ class TrackerDelegate: public QItemDelegate Q_OBJECT public: - TrackerDelegate (QObject * parent=0): QItemDelegate(parent), myShowMore(false) {} + TrackerDelegate (QObject * parent = nullptr): QItemDelegate (parent), myShowMore (false) {} virtual ~TrackerDelegate () {} - public: - QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const; - void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; - - public: void setShowMore (bool b); + // QAbstractItemDelegate + virtual QSize sizeHint (const QStyleOptionViewItem& option, const QModelIndex& index) const; + virtual void paint (QPainter * painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; + protected: QString getText (const TrackerInfo&) const; QSize margin (const QStyle& style) const; - virtual QSize sizeHint (const QStyleOptionViewItem&, const TrackerInfo&) const; - void drawTracker (QPainter*, const QStyleOptionViewItem&, const TrackerInfo&) const; + + QSize sizeHint (const QStyleOptionViewItem&, const TrackerInfo&) const; + void drawTracker (QPainter *, const QStyleOptionViewItem&, const TrackerInfo&) const; private: bool myShowMore; diff --git a/qt/TrackerModel.cc b/qt/TrackerModel.cc index 7d5c918d8..43486b537 100644 --- a/qt/TrackerModel.cc +++ b/qt/TrackerModel.cc @@ -12,6 +12,7 @@ #include #include "Application.h" // Application +#include "TorrentModel.h" #include "TrackerModel.h" int diff --git a/qt/TrackerModel.h b/qt/TrackerModel.h index 3be6bee24..f69fddbee 100644 --- a/qt/TrackerModel.h +++ b/qt/TrackerModel.h @@ -15,34 +15,43 @@ #include #include "Torrent.h" -#include "TorrentModel.h" + +class TorrentModel; struct TrackerInfo { - TrackerStat st; - int torrentId; + TrackerStat st; + int torrentId; }; + Q_DECLARE_METATYPE(TrackerInfo) class TrackerModel: public QAbstractListModel { Q_OBJECT - typedef QVector rows_t; - rows_t myRows; + public: + enum Role + { + TrackerRole = Qt::UserRole + }; public: + TrackerModel () {} + virtual ~TrackerModel () {} + void refresh (const TorrentModel&, const QSet& ids); int find (int torrentId, const QString& url) const; - public: - virtual int rowCount (const QModelIndex& parent = QModelIndex()) const; + // QAbstractItemModel + virtual int rowCount (const QModelIndex& parent = QModelIndex ()) const; virtual QVariant data (const QModelIndex& index, int role = Qt::DisplayRole) const; - enum Role { TrackerRole = Qt::UserRole }; - public: - TrackerModel () {} - virtual ~TrackerModel () {} + private: + typedef QVector rows_t; + + private: + rows_t myRows; }; #endif // QTR_TRACKER_MODEL_H diff --git a/qt/TrackerModelFilter.h b/qt/TrackerModelFilter.h index 0821062fd..fe94550d9 100644 --- a/qt/TrackerModelFilter.h +++ b/qt/TrackerModelFilter.h @@ -12,19 +12,19 @@ #include -class TrackerModelFilter : public QSortFilterProxyModel +class TrackerModelFilter: public QSortFilterProxyModel { Q_OBJECT public: - TrackerModelFilter (QObject *parent = 0); + TrackerModelFilter (QObject * parent = nullptr); - public: void setShowBackupTrackers (bool); bool showBackupTrackers () const { return myShowBackups; } protected: - bool filterAcceptsRow (int sourceRow, const QModelIndex&sourceParent) const; + // QSortFilterProxyModel + virtual bool filterAcceptsRow (int sourceRow, const QModelIndex& sourceParent) const; private: bool myShowBackups; diff --git a/qt/Utils.cc b/qt/Utils.cc index 582e80e74..504fa2121 100644 --- a/qt/Utils.cc +++ b/qt/Utils.cc @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include diff --git a/qt/Utils.h b/qt/Utils.h index ce2c63c97..754db1101 100644 --- a/qt/Utils.h +++ b/qt/Utils.h @@ -12,27 +12,18 @@ #include // isxdigit() -#include -#include #include #include -#include "Speed.h" - class QColor; +class QIcon; -class Utils: public QObject +class Utils { - Q_OBJECT - - public: - Utils () {} - virtual ~Utils () {} - public: static QIcon guessMimeIcon (const QString& filename); // Test if string is UTF-8 or not - static bool isValidUtf8 (const char *s); + static bool isValidUtf8 (const char * s); static QString removeTrailingDirSeparator (const QString& path); diff --git a/qt/WatchDir.h b/qt/WatchDir.h index d94ce30cc..722f9b27e 100644 --- a/qt/WatchDir.h +++ b/qt/WatchDir.h @@ -24,27 +24,33 @@ class WatchDir: public QObject public: WatchDir (const TorrentModel&); - ~WatchDir (); + virtual ~WatchDir (); - public: void setPath (const QString& path, bool isEnabled); + signals: + void torrentFileAdded (const QString& filename); + private: - enum { OK, DUPLICATE, ERROR }; - int metainfoTest (const QString& filename) const; + enum + { + OK, + DUPLICATE, + ERROR + }; - signals: - void torrentFileAdded (QString filename); + private: + int metainfoTest (const QString& filename) const; private slots: void watcherActivated (const QString& path); void onTimeout (); - private slots: void rescanAllWatchedDirectories (); private: const TorrentModel& myModel; + QSet myWatchDirFiles; QFileSystemWatcher * myWatcher; }; -- 2.49.0