mirror of
https://github.com/transmission/transmission
synced 2024-12-29 02:56:11 +00:00
2b917de65b
This refactoring is driven by the need to be able to do true queued RPC calls (where each successive call uses the result of the previous). Currently, such queueing of requests is done by assigning them special "magic" tag numbers, which are then intercepted in one big switch() statement and acted upon. This (aside from making code greatly unclear) effectively makes each such queue a singleton, because state passing is restricted to global variables. We refactor RpcClient to assign an unique tag to each remote call, and then abstract all the call<->response matching with Qt's future/promise mechanism. Finally, we introduce a "RPC request queue" class (RpcQueue) which is built on top of QFutureWatcher and C++11's <functional> library. This class maintains a queue of functions, where each function receives an RPC response, does necessary processing, performs another call and finally returns its future.
177 lines
4.3 KiB
C++
177 lines
4.3 KiB
C++
/*
|
|
* This file Copyright (C) 2009-2016 Mnemosyne LLC
|
|
*
|
|
* It may be used under the GNU GPL versions 2 or 3
|
|
* or any future license endorsed by Mnemosyne LLC.
|
|
*
|
|
* $Id$
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <ctime>
|
|
|
|
#include <QMainWindow>
|
|
#include <QNetworkReply>
|
|
#include <QPointer>
|
|
#include <QSet>
|
|
#include <QSystemTrayIcon>
|
|
#include <QTimer>
|
|
#include <QWidgetList>
|
|
|
|
#include "Filters.h"
|
|
#include "TorrentFilter.h"
|
|
#include "ui_MainWindow.h"
|
|
|
|
class QAction;
|
|
class QIcon;
|
|
class QMenu;
|
|
|
|
class AboutDialog;
|
|
class AddData;
|
|
class DetailsDialog;
|
|
class Prefs;
|
|
class PrefsDialog;
|
|
class Session;
|
|
class SessionDialog;
|
|
class StatsDialog;
|
|
class TorrentDelegate;
|
|
class TorrentDelegateMin;
|
|
class TorrentModel;
|
|
|
|
extern "C"
|
|
{
|
|
struct tr_variant;
|
|
}
|
|
|
|
class MainWindow: public QMainWindow
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
MainWindow (Session&, Prefs&, TorrentModel&, bool minized);
|
|
virtual ~MainWindow ();
|
|
|
|
QSystemTrayIcon& trayIcon () { return myTrayIcon; }
|
|
|
|
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 ();
|
|
|
|
void setToolbarVisible (bool);
|
|
void setFilterbarVisible (bool);
|
|
void setStatusbarVisible (bool);
|
|
void setCompactView (bool);
|
|
void refreshActionSensitivity ();
|
|
void refreshActionSensitivitySoon ();
|
|
void wrongAuthentication ();
|
|
|
|
void openSession ();
|
|
|
|
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 (bool withMetadataOnly = false) const;
|
|
void updateNetworkIcon ();
|
|
|
|
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 refreshTitle ();
|
|
void refreshStatusBar ();
|
|
void refreshTrayIcon ();
|
|
void refreshTrayIconSoon ();
|
|
void refreshTorrentViewHeader ();
|
|
void openTorrent ();
|
|
void openURL ();
|
|
void newTorrent ();
|
|
void trayActivated (QSystemTrayIcon::ActivationReason);
|
|
void refreshPref (int key);
|
|
void addTorrents (const QStringList& filenames);
|
|
void removeTorrents (const bool deleteFiles);
|
|
void openStats ();
|
|
void openDonate ();
|
|
void openAbout ();
|
|
void openHelp ();
|
|
void openFolder ();
|
|
void copyMagnetLinkToClipboard ();
|
|
void setLocation ();
|
|
void openProperties ();
|
|
void toggleSpeedMode ();
|
|
void dataReadProgress ();
|
|
void dataSendProgress ();
|
|
void onNetworkResponse (QNetworkReply::NetworkError code, const QString& message);
|
|
void toggleWindows (bool doShow);
|
|
void onSetPrefs ();
|
|
void onSetPrefs (bool);
|
|
void onSessionSourceChanged ();
|
|
void onModelReset ();
|
|
|
|
void setSortAscendingPref (bool);
|
|
|
|
void onStatsModeChanged (QAction * action);
|
|
void onSortModeChanged (QAction * action);
|
|
|
|
private:
|
|
Session& mySession;
|
|
Prefs& myPrefs;
|
|
TorrentModel& myModel;
|
|
|
|
Ui_MainWindow ui;
|
|
|
|
time_t myLastFullUpdateTime;
|
|
QPointer<SessionDialog> mySessionDialog;
|
|
QPointer<PrefsDialog> myPrefsDialog;
|
|
QPointer<AboutDialog> myAboutDialog;
|
|
QPointer<StatsDialog> myStatsDialog;
|
|
QPointer<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;
|
|
};
|
|
|