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
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
return (replyMsg.type () == QDBusMessage::ReplyMessage) && !replyMsg.arguments ().isEmpty ();
}
+FaviconCache& Application::faviconCache ()
+{
+ return myFavicons;
+}
+
/***
****
***/
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);
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
void addLayout (QGridLayout * layout);
+ // QObject
virtual bool eventFilter (QObject * object, QEvent * event);
public slots:
class CustomVariantType
{
public:
-
enum
{
TrackerStatsList = QVariant::UserType,
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
****
***/
-QString
-DetailsDialog::timeToStringRounded (int seconds)
-{
- if (seconds > 60)
- seconds -= (seconds % 60);
-
- return Formatter::timeToString (seconds);
-}
-
void
DetailsDialog::onTimer ()
{
#include <QSet>
#include <QTimer>
-#include "Prefs.h"
-
#include "ui_DetailsDialog.h"
class QTreeWidgetItem;
+
+class Prefs;
class Session;
class Torrent;
class TorrentModel;
{
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<int>& ids);
+
+ // QWidget
virtual QSize sizeHint () const { return QSize (440, 460); }
private:
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<int> 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<QString,QTreeWidgetItem*> 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<int>& fileIndices, int);
void onFileWantedChanged (const QSet<int>& 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 ();
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<int> myIds;
+ QTimer myTimer;
+ bool myChangedTorrents;
+ bool myHavePendingRefresh;
+
+ TrackerModel * myTrackerModel;
+ TrackerModelFilter * myTrackerFilter;
+ TrackerDelegate * myTrackerDelegate;
+
+ QMap<QString, QTreeWidgetItem*> myPeers;
};
#endif // QTR_DETAILS_DIALOG_H
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);
// 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<QString,QPixmap> myPixmaps;
-
QString getCacheDir ();
void ensureCacheDirHasBeenScanned ();
private slots:
-
void onRequestFinished (QNetworkReply * reply);
+
+ private:
+ QNetworkAccessManager * myNAM;
+ QMap<QString, QPixmap> myPixmaps;
};
#endif // QTR_FAVICON_CACHE_H
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
#include <stdint.h>
-#include <QObject>
-#include <QList>
+#include <QCoreApplication>
#include <QHash>
+#include <QList>
#include <QSet>
#include <QString>
#include <QVariant>
-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<int,int> update (const QString& name, bool want, int priority, uint64_t have, bool updateFields);
+ std::pair<int, int> update (const QString& name, bool want, int priority, uint64_t have, bool updateFields);
void twiddleWanted (QSet<int>& fileIds, bool&);
void twiddlePriority (QSet<int>& fileIds, int&);
int fileIndex () const { return myFileIndex; }
QString path () const;
bool isComplete () const;
+ private:
+ enum
+ {
+ LOW = (1 << 0),
+ NORMAL = (1 << 1),
+ HIGH = (1 << 2)
+ };
+
private:
void setSubtreePriority (int priority, QSet<int>& fileIds);
void setSubtreeWanted (bool, QSet<int>& fileIds);
double progress () const;
int priority () const;
int isSubtreeWanted () const;
+ const QHash<QString,int>& getMyChildRows();
+ private:
+ QString myName;
const int myFileIndex;
+ const uint64_t myTotalSize;
+
FileTreeItem * myParent;
QList<FileTreeItem*> myChildren;
QHash<QString,int> myChildRows;
- const QHash<QString,int>& getMyChildRows();
- QString myName;
int myPriority;
bool myIsWanted;
uint64_t myHaveSize;
- const uint64_t myTotalSize;
size_t myFirstUnhashedRow;
};
FileTreeModel::FileTreeModel (QObject * parent, bool isEditable):
QAbstractItemModel(parent),
+ myIsEditable (isEditable),
myRootItem (new FileTreeItem),
- myIndexCache (),
- myIsEditable (isEditable)
+ myIndexCache ()
{
}
};
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<QModelIndex>& 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<int>& fileIndices, int);
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<QModelIndex>& 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<int, FileTreeItem *> myIndexCache;
bool myIsEditable;
- public slots:
- void clicked (const QModelIndex & index);
- void doubleClicked (const QModelIndex & index);
+ FileTreeItem * myRootItem;
+ QMap<int, FileTreeItem *> myIndexCache;
};
#endif // QTR_FILE_TREE_MODEL_H
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<int>& fileIndices, int priority);
void wantedChanged (const QSet<int>& fileIndices, bool wanted);
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
#include "FilterBarComboBoxDelegate.h"
#include "FilterBarLineEdit.h"
#include "Prefs.h"
+#include "Torrent.h"
#include "TorrentFilter.h"
#include "TorrentModel.h"
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...
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);
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
};
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:
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
Q_OBJECT
public:
- FilterBarLineEdit (QWidget * parent = 0);
+ FilterBarLineEdit (QWidget * parent = nullptr);
protected:
+ // QWidget
virtual void resizeEvent (QResizeEvent * event);
private slots:
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
#include <stdint.h> // int64_t
+#include <QCoreApplication>
#include <QString>
-#include <QObject>
-#include <QIcon>
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];
};
#include <stdint.h>
+#include <QLabel>
#include <QString>
#include <QTimer>
-#include <QLabel>
class Session;
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
IconToolButton (QWidget * parent = nullptr);
protected:
+ // QWidget
virtual void paintEvent (QPaintEvent * event);
};
Q_OBJECT
public:
- LicenseDialog (QWidget * parent = 0);
- ~LicenseDialog () {}
+ LicenseDialog (QWidget * parent = nullptr);
+ virtual ~LicenseDialog () {}
};
#endif // QTR_LICENSE_DIALOG_H
}
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 (),
myFilterModel (prefs),
myTorrentDelegate (new TorrentDelegate (this)),
myTorrentDelegateMin (new TorrentDelegateMin (this)),
- mySession (session),
- myPrefs (prefs),
- myModel (model),
myLastSendTime (0),
myLastReadTime (0),
myNetworkTimer (this),
#define QTR_MAIN_WINDOW_H
#include <ctime>
-#include <QLineEdit>
-#include <QIcon>
+
#include <QMainWindow>
-#include <QMap>
+#include <QNetworkReply>
#include <QPointer>
-#include <QPushButton>
#include <QSet>
#include <QSystemTrayIcon>
#include <QTimer>
#include <QWidgetList>
-#include <QNetworkReply>
#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"
{
{
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<QDialog> 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<int> 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 ();
void onSessionSourceChanged ();
void onModelReset ();
- private slots:
void setSortPref (int);
void setSortAscendingPref (bool);
void onSortByActivityToggled (bool);
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<QDialog> 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
{
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<tr_metainfo_builder, void(*)(tr_metainfo_builder*)> myBuilder;
- protected:
- virtual void dragEnterEvent (QDragEnterEvent *);
- virtual void dropEvent (QDropEvent *);
+ Ui::MakeDialog ui;
- public:
- MakeDialog (Session&, QWidget * parent = 0);
- virtual ~MakeDialog ();
+ std::unique_ptr<tr_metainfo_builder, void(*)(tr_metainfo_builder*)> myBuilder;
};
#endif // QTR_MAKE_DIALOG_H
#include <QFile>
#include <QMap>
#include <QString>
-#include <QString>
#include <QTimer>
#include <QVector>
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<uint32_t, int32_t> mybins_t;
private:
void reload ();
private:
Session& mySession;
AddData myAdd;
+
+ Ui::OptionsDialog ui;
+
QDir myLocalDestination;
bool myHaveInfo;
tr_info myInfo;
- Ui::OptionsDialog ui;
QPushButton * myVerifyButton;
QVector<int> myPriorities;
QVector<bool> myWanted;
FileList myFiles;
- private:
QTimer myVerifyTimer;
char myVerifyBuf[2048 * 4];
QFile myVerifyFile;
uint32_t myVerifyPiecePos;
QVector<bool> myVerifyFlags;
QCryptographicHash myVerifyHash;
- typedef QMap<uint32_t, int32_t> mybins_t;
mybins_t myVerifyBins;
QTimer myEditTimer;
};
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;
#include <cassert>
#include <iostream>
+#include <QDateTime>
#include <QDir>
#include <QFile>
#ifndef QTR_PREFS_H
#define QTR_PREFS_H
-#include <QDateTime>
#include <QObject>
#include <QSet>
#include <QString>
#include "Filters.h"
+class QDateTime;
+
extern "C"
{
struct tr_variant;
Q_OBJECT
public:
-
enum
{
/* client prefs */
PREFS_COUNT
};
- private:
-
- struct PrefItem
- {
- int id;
- tr_quark key;
- int type;
- };
-
- static PrefItem myItems[];
-
- private:
- QSet<int> 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;
{
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);
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<int> myTemporaryPrefs;
+ mutable QVariant myValues[PREFS_COUNT];
+
+ static PrefItem myItems[];
};
#endif // QTR_PREFS_H
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);
#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;
{
Q_OBJECT
+ public:
+ PrefsDialog (Session&, Prefs&, QWidget * parent = nullptr);
+ virtual ~PrefsDialog ();
+
+ private:
+ typedef QMap<int, QWidget*> 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 ();
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<int,QWidget*> key2widget_t;
key2widget_t myWidgets;
const bool myIsServer;
- Session& mySession;
- Prefs& myPrefs;
QWidgetList myWebWidgets;
QWidgetList myWebAuthWidgets;
QWidgetList myWebWhitelistWidgets;
QWidgetList mySchedWidgets;
QWidgetList myBlockWidgets;
QWidgetList myUnsupportedWhenRemote;
- Ui::PrefsDialog ui;
int myBlocklistHttpTag;
QHttp * myBlocklistHttp;
Q_OBJECT
public:
- RelocateDialog (Session&, const TorrentModel&, const QSet<int>& ids, QWidget * parent = 0);
- ~RelocateDialog () {}
+ RelocateDialog (Session&, const TorrentModel&, const QSet<int>& 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<int> myIds;
+
Ui::RelocateDialog ui;
static bool myMoveFlag;
***/
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;
public:
FileAdded (int64_t tag, const QString& name): myTag (tag), myName (name) {}
- ~FileAdded () {}
+ virtual ~FileAdded () {}
+
void setFileToDelete (const QString& file) { myDelFile = file; }
public slots:
private:
const int64_t myTag;
const QString myName;
+
QString myDelFile;
};
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<int>& torrentIds);
- static void updateStats (tr_variant * d, tr_session_stats * stats);
- void refreshTorrents (const QSet<int>& torrentIds);
-
- public:
void torrentSet (const QSet<int>& ids, const tr_quark key, bool val);
void torrentSet (const QSet<int>& ids, const tr_quark key, int val);
void torrentSet (const QSet<int>& ids, const tr_quark key, double val);
void initTorrents (const QSet<int>& ids = QSet<int> ());
void addNewlyCreatedTorrent (const QString& filename, const QString& localPath);
void addTorrent (const AddData& addme);
- void removeTorrents (const QSet<int>& torrentIds, bool deleteFiles=false);
+ void removeTorrents (const QSet<int>& torrentIds, bool deleteFiles = false);
void verifyTorrents (const QSet<int>& torrentIds);
void reannounceTorrents (const QSet<int>& 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<int>& 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 ();
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<int>& torrentIds);
+ void refreshTorrents (const QSet<int>& 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;
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 ();
private:
Session& mySession;
Prefs& myPrefs;
+
Ui::SessionDialog ui;
+
QWidgetList myRemoteWidgets;
QWidgetList myAuthWidgets;
};
#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; }
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
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
#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
#include "Utils.h"
Torrent::Torrent (const Prefs& prefs, int id):
- magnetTorrent (false),
- myPrefs (prefs)
+ myPrefs (prefs),
+ magnetTorrent (false)
{
#ifndef NDEBUG
for (int i=0; i<PROPERTY_COUNT; ++i)
{
if (tr_variantDictFindStr(child, TR_KEY_announce, &str, &len))
{
- qApp->favicons.add (QUrl(QString::fromUtf8(str)));
+ qApp->faviconCache ().add (QUrl(QString::fromUtf8(str)));
list.append (QString::fromUtf8 (str, len));
}
}
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))
QPixmap
TrackerStat::getFavicon () const
{
- return qApp->favicons.find (QUrl (announce));
+ return qApp->faviconCache ().find (QUrl (announce));
}
#include <QString>
#include <QStringList>
#include <QList>
-#include <QTemporaryFile>
#include <QVariant>
#include <libtransmission/transmission.h>
#undef ERROR
#endif
-class Prefs;
class QPixmap;
-class QStyle;
+
+class Prefs;
extern "C"
{
double progress;
};
-typedef QList<Peer> PeerList;
Q_DECLARE_METATYPE(Peer)
+
+typedef QList<Peer> PeerList;
Q_DECLARE_METATYPE(PeerList)
struct TrackerStat
{
+ QPixmap getFavicon () const;
+
bool hasAnnounced;
bool hasScraped;
bool isBackup;
QString host;
QString lastAnnounceResult;
QString lastScrapeResult;
- QPixmap getFavicon () const;
};
-typedef QList<TrackerStat> TrackerStatsList;
Q_DECLARE_METATYPE(TrackerStat)
+
+typedef QList<TrackerStat> 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;
uint64_t have;
};
-typedef QList<TorrentFile> FileList;
Q_DECLARE_METATYPE(TorrentFile)
-Q_DECLARE_METATYPE(FileList)
+typedef QList<TorrentFile> FileList;
+Q_DECLARE_METATYPE(FileList)
class Torrent: public QObject
{
Q_OBJECT
public:
-
enum
{
ID,
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<tr_quark> 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); }
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<tr_torrent_activity> (getInt (ACTIVITY)); }
bool isFinished () const { return getBool (IS_FINISHED); }
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*)
}
QString
-TorrentDelegate::progressString (const Torrent& tor) const
+TorrentDelegate::progressString (const Torrent& tor)
{
const bool isMagnet (!tor.hasMetadata());
const bool isDone (tor.isDone ());
}
QString
-TorrentDelegate::shortTransferString (const Torrent& tor) const
+TorrentDelegate::shortTransferString (const Torrent& tor)
{
QString str;
const bool haveMeta (tor.hasMetadata());
}
QString
-TorrentDelegate::shortStatusString (const Torrent& tor) const
+TorrentDelegate::shortStatusString (const Torrent& tor)
{
QString str;
static const QChar ratioSymbol (0x262F);
}
QString
-TorrentDelegate::statusString (const Torrent& tor) const
+TorrentDelegate::statusString (const Torrent& tor)
{
QString str;
#define QTR_TORRENT_DELEGATE_H
#include <QStyledItemDelegate>
-#include <QSize>
-class QStyleOptionProgressBar;
-class QStyleOptionViewItem;
class QStyle;
-class Session;
+class QStyleOptionProgressBar;
+
class Torrent;
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
#ifndef QTR_TORRENT_DELEGATE_MIN_H
#define QTR_TORRENT_DELEGATE_MIN_H
-#include <QSize>
-
#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
#define QTR_TORRENT_FILTER_H
#include <QSortFilterProxyModel>
-#include <QMetaType>
-#include <QVariant>
class QString;
-class QWidget;
class FilterMode;
class Prefs;
{
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;
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;
#include <libtransmission/transmission.h>
#include <libtransmission/variant.h>
+#include "Speed.h"
+#include "Torrent.h"
#include "TorrentDelegate.h"
#include "TorrentModel.h"
#include <QSet>
#include <QVector>
-#include "Speed.h"
-#include "Torrent.h"
-
class Prefs;
+class Speed;
+class Torrent;
extern "C"
{
{
Q_OBJECT
- private:
- typedef QMap<int,int> id_to_row_t;
- typedef QMap<int,Torrent*> id_to_torrent_t;
- typedef QVector<Torrent*> 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<int> 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<int>);
void removeTorrents (tr_variant * torrentList);
void removeTorrent (int id);
+ private:
+ typedef QMap<int, int> id_to_row_t;
+ typedef QMap<int, Torrent*> id_to_torrent_t;
+ typedef QVector<Torrent*> torrents_t;
+
+ private:
+ void addTorrent (Torrent *);
+ QSet<int> 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
#define QTR_TRACKER_DELEGATE_H
#include <QItemDelegate>
-#include <QSize>
-class QPainter;
-class QStyleOptionViewItem;
class QStyle;
class Session;
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;
#include <QUrl>
#include "Application.h" // Application
+#include "TorrentModel.h"
#include "TrackerModel.h"
int
#include <QVector>
#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<TrackerInfo> rows_t;
- rows_t myRows;
+ public:
+ enum Role
+ {
+ TrackerRole = Qt::UserRole
+ };
public:
+ TrackerModel () {}
+ virtual ~TrackerModel () {}
+
void refresh (const TorrentModel&, const QSet<int>& 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<TrackerInfo> rows_t;
+
+ private:
+ rows_t myRows;
};
#endif // QTR_TRACKER_MODEL_H
#include <QSortFilterProxyModel>
-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;
#include <QFile>
#include <QFileDialog>
#include <QFileInfo>
+#include <QIcon>
#include <QInputDialog>
#include <QObject>
#include <QPixmapCache>
#include <cctype> // isxdigit()
-#include <QIcon>
-#include <QObject>
#include <QRect>
#include <QString>
-#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);
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<QString> myWatchDirFiles;
QFileSystemWatcher * myWatcher;
};