1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-29 02:56:11 +00:00
transmission/qt/MainWindow.h
Charles Kerr d857a5821a
refractor: simplify torrent model signal emissions (#1044)
refractor: simplify torrent model signal emissions

The Torrent->Application signal connections make up for about 5% of the
app's memory use. Move this to the TorrentModel so that there are only a
handful of signal connections.

Moving signals to TorrentModel means batch change signals can be emitted
instead of per-change-per-torrent emissions and can be handled that way.
2019-11-09 08:44:40 -06:00

192 lines
4.7 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.
*
*/
#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 QStringList;
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 wrongAuthentication();
void openSession();
protected:
// QWidget
virtual void contextMenuEvent(QContextMenuEvent*);
virtual void dragEnterEvent(QDragEnterEvent*);
virtual void dropEvent(QDropEvent*);
private:
QIcon getStockIcon(QString const&, int fallback = -1);
QIcon addEmblem(QIcon icon, QStringList const& emblemNames);
QSet<int> getSelectedTorrents(bool withMetadataOnly = false) const;
void updateNetworkIcon();
QMenu* createOptionsMenu();
QMenu* createStatsModeMenu();
void initStatusBar();
void clearSelection();
void addTorrent(AddData const& addMe, bool showOptions);
// QWidget
virtual void hideEvent(QHideEvent* event);
virtual void showEvent(QShowEvent* event);
private slots:
void addTorrents(QStringList const& filenames);
void copyMagnetLinkToClipboard();
void dataReadProgress();
void dataSendProgress();
void newTorrent();
void onNetworkResponse(QNetworkReply::NetworkError code, QString const& message);
void onRefreshTimer();
void onSessionSourceChanged();
void onSetPrefs();
void onSetPrefs(bool);
void onSortModeChanged(QAction* action);
void onStatsModeChanged(QAction* action);
void openAbout();
void openDonate();
void openFolder();
void openHelp();
void openPreferences();
void openProperties();
void openStats();
void openTorrent();
void openURL();
void refreshPref(int key);
void refreshSoon(int fields = ~0);
void refreshStatusBar();
void removeTorrents(bool const deleteFiles);
void setLocation();
void setSortAscendingPref(bool);
void toggleSpeedMode();
void toggleWindows(bool doShow);
void trayActivated(QSystemTrayIcon::ActivationReason);
private:
Session& mySession;
Prefs& myPrefs;
TorrentModel& myModel;
QPixmap myPixmapNetworkError;
QPixmap myPixmapNetworkIdle;
QPixmap myPixmapNetworkReceive;
QPixmap myPixmapNetworkTransmit;
QPixmap myPixmapNetworkTransmitReceive;
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;
QAction* myDlimitOffAction;
QAction* myDlimitOnAction;
QAction* myUlimitOffAction;
QAction* myUlimitOnAction;
QAction* myRatioOffAction;
QAction* myRatioOnAction;
QWidgetList myHidden;
QWidget* myFilterBar;
QAction* myAltSpeedAction;
QString myErrorMessage;
enum
{
REFRESH_TITLE = (1 << 0),
REFRESH_STATUS_BAR = (1 << 1),
REFRESH_TRAY_ICON = (1 << 2),
REFRESH_TORRENT_VIEW_HEADER = (1 << 3),
REFRESH_ACTION_SENSITIVITY = (1 << 4)
};
int myRefreshFields = 0;
QTimer myRefreshTimer;
void refreshTitle();
void refreshTrayIcon();
void refreshTorrentViewHeader();
};