2009-04-09 18:55:47 +00:00
|
|
|
/*
|
2016-04-19 20:41:59 +00:00
|
|
|
* This file Copyright (C) 2009-2016 Mnemosyne LLC
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
2014-01-21 03:10:30 +00:00
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
2014-01-19 01:09:44 +00:00
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-03-29 16:37:21 +00:00
|
|
|
#pragma once
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
#include <ctime>
|
2015-06-12 22:12:12 +00:00
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <QMainWindow>
|
2015-06-12 22:12:12 +00:00
|
|
|
#include <QNetworkReply>
|
2015-01-25 15:47:03 +00:00
|
|
|
#include <QPointer>
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <QSystemTrayIcon>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QWidgetList>
|
|
|
|
|
2015-06-10 21:27:11 +00:00
|
|
|
#include "Filters.h"
|
2019-11-12 01:37:05 +00:00
|
|
|
#include "Speed.h"
|
2015-06-10 21:27:11 +00:00
|
|
|
#include "TorrentFilter.h"
|
2019-11-12 01:37:05 +00:00
|
|
|
#include "Typedefs.h"
|
|
|
|
|
2015-06-10 21:27:11 +00:00
|
|
|
#include "ui_MainWindow.h"
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2015-06-12 22:12:12 +00:00
|
|
|
class QAction;
|
|
|
|
class QIcon;
|
|
|
|
class QMenu;
|
2017-02-18 18:22:34 +00:00
|
|
|
class QStringList;
|
2015-06-12 22:12:12 +00:00
|
|
|
|
2015-07-30 06:18:02 +00:00
|
|
|
class AboutDialog;
|
2013-02-09 23:11:17 +00:00
|
|
|
class AddData;
|
2015-06-10 21:27:11 +00:00
|
|
|
class DetailsDialog;
|
2015-07-30 06:18:02 +00:00
|
|
|
class Prefs;
|
|
|
|
class PrefsDialog;
|
2009-04-09 18:55:47 +00:00
|
|
|
class Session;
|
2015-07-30 06:18:02 +00:00
|
|
|
class SessionDialog;
|
|
|
|
class StatsDialog;
|
2009-04-09 18:55:47 +00:00
|
|
|
class TorrentDelegate;
|
|
|
|
class TorrentDelegateMin;
|
|
|
|
class TorrentModel;
|
|
|
|
|
2015-06-10 21:27:11 +00:00
|
|
|
extern "C"
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
struct tr_variant;
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
class MainWindow : public QMainWindow
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-01-27 18:09:49 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
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 wrongAuthentication();
|
|
|
|
|
|
|
|
void openSession();
|
|
|
|
|
|
|
|
protected:
|
2015-06-12 22:12:12 +00:00
|
|
|
// QWidget
|
2019-11-12 01:37:05 +00:00
|
|
|
void contextMenuEvent(QContextMenuEvent*) override;
|
|
|
|
void dragEnterEvent(QDragEnterEvent*) override;
|
|
|
|
void dropEvent(QDropEvent*) override;
|
2013-01-27 18:09:49 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
private:
|
2017-04-20 16:02:19 +00:00
|
|
|
QIcon getStockIcon(QString const&, int fallback = -1);
|
2019-11-06 21:09:04 +00:00
|
|
|
QIcon addEmblem(QIcon icon, QStringList const& emblemNames);
|
2015-06-12 22:12:12 +00:00
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
torrent_ids_t getSelectedTorrents(bool withMetadataOnly = false) const;
|
2017-04-19 12:04:45 +00:00
|
|
|
void updateNetworkIcon();
|
2015-06-12 22:12:12 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
QMenu* createOptionsMenu();
|
|
|
|
QMenu* createStatsModeMenu();
|
|
|
|
void initStatusBar();
|
2015-06-12 22:12:12 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void clearSelection();
|
2017-04-20 16:02:19 +00:00
|
|
|
void addTorrent(AddData const& addMe, bool showOptions);
|
2015-06-12 22:12:12 +00:00
|
|
|
|
|
|
|
// QWidget
|
2019-11-12 01:37:05 +00:00
|
|
|
void hideEvent(QHideEvent* event) override;
|
|
|
|
void showEvent(QShowEvent* event) override;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
private slots:
|
2017-04-20 16:02:19 +00:00
|
|
|
void addTorrents(QStringList const& filenames);
|
2017-04-19 12:04:45 +00:00
|
|
|
void copyMagnetLinkToClipboard();
|
|
|
|
void dataReadProgress();
|
|
|
|
void dataSendProgress();
|
2019-11-09 14:44:40 +00:00
|
|
|
void newTorrent();
|
2017-04-20 16:02:19 +00:00
|
|
|
void onNetworkResponse(QNetworkReply::NetworkError code, QString const& message);
|
2019-11-09 14:44:40 +00:00
|
|
|
void onRefreshTimer();
|
|
|
|
void onSessionSourceChanged();
|
2017-04-19 12:04:45 +00:00
|
|
|
void onSetPrefs();
|
|
|
|
void onSetPrefs(bool);
|
|
|
|
void onSortModeChanged(QAction* action);
|
2019-11-09 14:44:40 +00:00
|
|
|
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 removeTorrents(bool const deleteFiles);
|
|
|
|
void setLocation();
|
|
|
|
void setSortAscendingPref(bool);
|
|
|
|
void toggleSpeedMode();
|
|
|
|
void toggleWindows(bool doShow);
|
|
|
|
void trayActivated(QSystemTrayIcon::ActivationReason);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
private:
|
2015-06-12 22:12:12 +00:00
|
|
|
Session& mySession;
|
|
|
|
Prefs& myPrefs;
|
|
|
|
TorrentModel& myModel;
|
2013-01-27 18:09:49 +00:00
|
|
|
|
2019-11-06 21:09:04 +00:00
|
|
|
QPixmap myPixmapNetworkError;
|
|
|
|
QPixmap myPixmapNetworkIdle;
|
|
|
|
QPixmap myPixmapNetworkReceive;
|
|
|
|
QPixmap myPixmapNetworkTransmit;
|
|
|
|
QPixmap myPixmapNetworkTransmitReceive;
|
|
|
|
|
2015-06-12 22:12:12 +00:00
|
|
|
Ui_MainWindow ui;
|
2014-12-18 01:30:50 +00:00
|
|
|
|
2015-06-12 22:12:12 +00:00
|
|
|
time_t myLastFullUpdateTime;
|
2015-07-30 06:18:02 +00:00
|
|
|
QPointer<SessionDialog> mySessionDialog;
|
|
|
|
QPointer<PrefsDialog> myPrefsDialog;
|
|
|
|
QPointer<AboutDialog> myAboutDialog;
|
|
|
|
QPointer<StatsDialog> myStatsDialog;
|
|
|
|
QPointer<DetailsDialog> myDetailsDialog;
|
2015-06-12 22:12:12 +00:00
|
|
|
QSystemTrayIcon myTrayIcon;
|
|
|
|
TorrentFilter myFilterModel;
|
2017-04-19 12:04:45 +00:00
|
|
|
TorrentDelegate* myTorrentDelegate;
|
|
|
|
TorrentDelegateMin* myTorrentDelegateMin;
|
2015-06-12 22:12:12 +00:00
|
|
|
time_t myLastSendTime;
|
|
|
|
time_t myLastReadTime;
|
|
|
|
QTimer myNetworkTimer;
|
|
|
|
bool myNetworkError;
|
2017-04-19 12:04:45 +00:00
|
|
|
QAction* myDlimitOffAction;
|
|
|
|
QAction* myDlimitOnAction;
|
|
|
|
QAction* myUlimitOffAction;
|
|
|
|
QAction* myUlimitOnAction;
|
|
|
|
QAction* myRatioOffAction;
|
|
|
|
QAction* myRatioOnAction;
|
2015-06-12 22:12:12 +00:00
|
|
|
QWidgetList myHidden;
|
2017-04-19 12:04:45 +00:00
|
|
|
QWidget* myFilterBar;
|
|
|
|
QAction* myAltSpeedAction;
|
2013-10-20 19:57:48 +00:00
|
|
|
QString myErrorMessage;
|
2019-11-09 14:44:40 +00:00
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
struct TransferStats
|
|
|
|
{
|
|
|
|
Speed speedUp;
|
|
|
|
Speed speedDown;
|
|
|
|
size_t peersSending = 0;
|
|
|
|
size_t peersReceiving = 0;
|
|
|
|
};
|
|
|
|
TransferStats getTransferStats() const;
|
|
|
|
|
2019-11-09 14:44:40 +00:00
|
|
|
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;
|
2020-05-02 04:23:47 +00:00
|
|
|
void refreshActionSensitivity();
|
2019-11-12 01:37:05 +00:00
|
|
|
void refreshStatusBar(TransferStats const&);
|
2020-05-02 04:23:47 +00:00
|
|
|
void refreshTitle();
|
2019-11-09 14:44:40 +00:00
|
|
|
void refreshTorrentViewHeader();
|
2020-05-02 04:23:47 +00:00
|
|
|
void refreshTrayIcon(TransferStats const&);
|
2009-04-09 18:55:47 +00:00
|
|
|
};
|