qBittorrent
mainwindow.h
Go to the documentation of this file.
1 /*
2  * Bittorrent Client using Qt and libtorrent.
3  * Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  * In addition, as a special exception, the copyright holders give permission to
20  * link this program with the OpenSSL project's "OpenSSL" library (or with
21  * modified versions of it that use the same license as the "OpenSSL" library),
22  * and distribute the linked executables. You must obey the GNU General Public
23  * License in all respects for all of the code used other than "OpenSSL". If you
24  * modify file(s), you may extend this exception to your version of the file(s),
25  * but you are not obligated to do so. If you do not wish to do so, delete this
26  * exception statement from your version.
27  */
28 
29 #pragma once
30 
31 #include <QMainWindow>
32 #include <QPointer>
33 
34 #ifndef Q_OS_MACOS
35 #include <QSystemTrayIcon>
36 #endif
37 
39 #include "base/logger.h"
40 #include "base/settingvalue.h"
41 
42 class QCloseEvent;
43 class QFileSystemWatcher;
44 class QSplitter;
45 class QTabWidget;
46 class QTimer;
47 
48 class AboutDialog;
50 class ExecutionLogWidget;
51 class LineEdit;
52 class OptionsDialog;
53 class PowerManagement;
54 class ProgramUpdater;
55 class PropertiesWidget;
56 class RSSWidget;
57 class SearchWidget;
58 class StatsDialog;
59 class StatusBar;
62 class TransferListWidget;
63 
64 namespace Net
65 {
66  struct DownloadResult;
67 }
68 
69 namespace Ui
70 {
71  class MainWindow;
72 }
73 
74 class MainWindow final : public QMainWindow
75 {
76  Q_OBJECT
77 
78 public:
79  explicit MainWindow(QWidget *parent = nullptr);
80  ~MainWindow() override;
81 
82  QWidget *currentTabWidget() const;
85 
86  // ExecutionLog properties
87  bool isExecutionLogEnabled() const;
88  void setExecutionLogEnabled(bool value);
89  Log::MsgTypes executionLogMsgTypes() const;
90  void setExecutionLogMsgTypes(Log::MsgTypes value);
91 
92  // Notifications properties
93  bool isNotificationsEnabled() const;
94  void setNotificationsEnabled(bool value);
97 #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB)
98  int getNotificationTimeout() const;
99  void setNotificationTimeout(int value);
100 #endif
101 
102  // Misc properties
103  bool isDownloadTrackerFavicon() const;
104  void setDownloadTrackerFavicon(bool value);
105 
106  void activate();
107  void cleanup();
108 
109  void showNotificationBalloon(const QString &title, const QString &msg) const;
110 
111 signals:
113 
114 private slots:
115  void showFilterContextMenu(const QPoint &);
116  void balloonClicked();
117  void writeSettings();
118  void readSettings();
119  void fullDiskError(BitTorrent::Torrent *const torrent, const QString &msg) const;
120  void handleDownloadFromUrlFailure(const QString &, const QString &) const;
121  void tabChanged(int newTab);
122  bool defineUILockPassword();
123  void clearUILockPassword();
124  bool unlockUI();
125  void notifyOfUpdate(const QString &);
126  void showConnectionSettings();
127  void minimizeWindow();
128  // Keyboard shortcuts
130  void displayTransferTab() const;
131  void displaySearchTab();
132  void displayRSSTab();
133  void displayExecutionLogTab();
134  void focusSearchFilter();
135  void reloadSessionStats();
136  void reloadTorrentStats(const QVector<BitTorrent::Torrent *> &torrents);
137  void loadPreferences();
138  void addTorrentFailed(const QString &error) const;
139  void torrentNew(BitTorrent::Torrent *const torrent) const;
140  void finishedTorrent(BitTorrent::Torrent *const torrent) const;
142  void optionsSaved();
144 
145 #ifdef Q_OS_WIN
146  void pythonDownloadFinished(const Net::DownloadResult &result);
147 #endif
148  void addToolbarContextMenu();
149  void manageCookies();
150 
151  void downloadFromURLList(const QStringList &urlList);
152  void updateAltSpeedsBtn(bool alternative);
153  void updateNbTorrents();
154  void handleRSSUnreadCountUpdated(int count);
155 
162  void on_actionExecutionLogs_triggered(bool checked);
163  void on_actionNormalMessages_triggered(bool checked);
164  void on_actionInformationMessages_triggered(bool checked);
165  void on_actionWarningMessages_triggered(bool checked);
166  void on_actionCriticalMessages_triggered(bool checked);
167  void on_actionAutoExit_toggled(bool);
168  void on_actionAutoSuspend_toggled(bool);
181  // Check for unpaused downloading or seeding torrents and prevent system suspend/sleep according to preferences
183 
184  void toolbarMenuRequested(const QPoint &point);
185  void toolbarIconsOnly();
186  void toolbarTextOnly();
187  void toolbarTextBeside();
188  void toolbarTextUnder();
189  void toolbarFollowSystem();
190 #ifdef Q_OS_MACOS
191  void on_actionCloseWindow_triggered();
192 #else
193  void toggleVisibility(const QSystemTrayIcon::ActivationReason reason = QSystemTrayIcon::Trigger);
194 #endif
195 
196 private:
197  void createTrayIconMenu();
198 #ifdef Q_OS_MACOS
199  void setupDockClickHandler();
200 #else
201  void createTrayIcon(int retries);
202 #endif
203 #ifdef Q_OS_WIN
204  void installPython();
205 #endif
206 
207  void dropEvent(QDropEvent *event) override;
208  void dragEnterEvent(QDragEnterEvent *event) override;
209  void closeEvent(QCloseEvent *) override;
210  void showEvent(QShowEvent *) override;
211  void keyPressEvent(QKeyEvent *event) override;
212  bool event(QEvent *e) override;
213  void displayRSSTab(bool enable);
214  void displaySearchTab(bool enable);
215  void createTorrentTriggered(const QString &path = {});
216  void showStatusBar(bool show);
217 
218  Ui::MainWindow *m_ui;
219 
220  QFileSystemWatcher *m_executableWatcher;
221  // GUI related
222  bool m_posInitialized = false;
223  QPointer<QTabWidget> m_tabs;
224  QPointer<StatusBar> m_statusBar;
225  QPointer<OptionsDialog> m_options;
226  QPointer<AboutDialog> m_aboutDlg;
227  QPointer<StatsDialog> m_statsDlg;
228  QPointer<TorrentCreatorDialog> m_createTorrentDlg;
229  QPointer<DownloadFromURLDialog> m_downloadFromURLDialog;
230 
231 #ifndef Q_OS_MACOS
232  QPointer<QSystemTrayIcon> m_systrayIcon;
233 #endif
234  QPointer<QMenu> m_trayIconMenu;
235 
240  bool m_forceExit = false;
242  bool m_unlockDlgShowing = false;
245  // Widgets
248  QSplitter *m_splitter;
249  QPointer<SearchWidget> m_searchWidget;
250  QPointer<RSSWidget> m_rssWidget;
251  QPointer<ExecutionLogWidget> m_executionLog;
252  // Power Management
254  QTimer *m_preventTimer;
255  bool m_hasPython = false;
257 
263 
264 #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB)
265  SettingValue<int> m_storeNotificationTimeOut;
266 #endif
267 
268 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
269  void checkProgramUpdate(bool invokedByUser);
270  void handleUpdateCheckFinished(ProgramUpdater *updater, bool invokedByUser);
271 
272  QTimer *m_programUpdateTimer = nullptr;
273 #endif
274 };
void handleDownloadFromUrlFailure(const QString &, const QString &) const
Definition: mainwindow.cpp:986
void showStatusBar(bool show)
void downloadFromURLList(const QStringList &urlList)
void readSettings()
Definition: mainwindow.cpp:818
QPointer< AboutDialog > m_aboutDlg
Definition: mainwindow.h:226
void showNotificationBalloon(const QString &title, const QString &msg) const
PropertiesWidget * m_propertiesWidget
Definition: mainwindow.h:238
void toggleAlternativeSpeeds()
TransferListWidget * transferListWidget() const
void minimizeWindow()
SettingValue< bool > m_storeNotificationEnabled
Definition: mainwindow.h:260
void balloonClicked()
Definition: mainwindow.cpp:832
void updateNbTorrents()
Definition: mainwindow.cpp:756
void on_actionOptions_triggered()
void on_actionAutoHibernate_toggled(bool)
SettingValue< bool > m_storeNotificationTorrentAdded
Definition: mainwindow.h:261
void on_actionNormalMessages_triggered(bool checked)
~MainWindow() override
Definition: mainwindow.cpp:480
QPointer< TorrentCreatorDialog > m_createTorrentDlg
Definition: mainwindow.h:228
void askRecursiveTorrentDownloadConfirmation(BitTorrent::Torrent *const torrent)
Definition: mainwindow.cpp:960
void on_actionAutoSuspend_toggled(bool)
void displaySearchTab()
Definition: mainwindow.cpp:925
void fullDiskError(BitTorrent::Torrent *const torrent, const QString &msg) const
Definition: mainwindow.cpp:870
void manageCookies()
Definition: mainwindow.cpp:597
void createKeyboardShortcuts()
Definition: mainwindow.cpp:877
PropertiesWidget * propertiesWidget() const
TransferListWidget * m_transferListWidget
Definition: mainwindow.h:236
void createTrayIconMenu()
void on_actionShowStatusbar_triggered()
void on_actionDonateMoney_triggered()
void finishedTorrent(BitTorrent::Torrent *const torrent) const
Definition: mainwindow.cpp:864
void on_actionOpen_triggered()
void writeSettings()
Definition: mainwindow.cpp:787
void closeEvent(QCloseEvent *) override
void toolbarMenuRequested(const QPoint &point)
Definition: mainwindow.cpp:604
void setExecutionLogEnabled(bool value)
Definition: mainwindow.cpp:490
void on_actionAbout_triggered()
void dragEnterEvent(QDragEnterEvent *event) override
Log::MsgTypes executionLogMsgTypes() const
Definition: mainwindow.cpp:495
void keyPressEvent(QKeyEvent *event) override
void setNotificationsEnabled(bool value)
Definition: mainwindow.cpp:511
bool m_posInitialized
Definition: mainwindow.h:222
void addToolbarContextMenu()
Definition: mainwindow.cpp:549
void on_actionCriticalMessages_triggered(bool checked)
Ui::MainWindow * m_ui
Definition: mainwindow.h:218
void toolbarTextOnly()
Definition: mainwindow.cpp:615
QPointer< StatusBar > m_statusBar
Definition: mainwindow.h:224
void createTorrentTriggered(const QString &path={})
SettingValue< bool > m_storeExecutionLogEnabled
Definition: mainwindow.h:258
void clearUILockPassword()
Definition: mainwindow.cpp:657
void torrentNew(BitTorrent::Torrent *const torrent) const
Definition: mainwindow.cpp:857
SettingValue< bool > m_storeDownloadTrackerFavicon
Definition: mainwindow.h:259
void on_actionAutoExit_toggled(bool)
void on_actionSearchWidget_triggered()
void toolbarIconsOnly()
Definition: mainwindow.cpp:609
bool m_forceExit
Definition: mainwindow.h:240
void on_actionDocumentation_triggered() const
Definition: mainwindow.cpp:761
void toolbarTextBeside()
Definition: mainwindow.cpp:621
void updateAltSpeedsBtn(bool alternative)
QFileSystemWatcher * m_executableWatcher
Definition: mainwindow.h:220
void on_actionTopToolBar_triggered()
void tabChanged(int newTab)
Definition: mainwindow.cpp:766
PowerManagement * m_pwr
Definition: mainwindow.h:253
void setTorrentAddedNotificationsEnabled(bool value)
Definition: mainwindow.cpp:521
bool m_unlockDlgShowing
Definition: mainwindow.h:242
QPointer< ExecutionLogWidget > m_executionLog
Definition: mainwindow.h:251
QPointer< OptionsDialog > m_options
Definition: mainwindow.h:225
QAction * m_queueSeparatorMenu
Definition: mainwindow.h:247
void showFilterContextMenu(const QPoint &)
Definition: mainwindow.cpp:711
void showConnectionSettings()
LineEdit * m_searchFilter
Definition: mainwindow.h:243
CachedSettingValue< Log::MsgTypes > m_storeExecutionLogTypes
Definition: mainwindow.h:262
bool m_displaySpeedInTitle
Definition: mainwindow.h:239
void on_actionInformationMessages_triggered(bool checked)
void updatePowerManagementState()
MainWindow(QWidget *parent=nullptr)
Definition: mainwindow.cpp:123
QPointer< QTabWidget > m_tabs
Definition: mainwindow.h:223
void addTorrentFailed(const QString &error) const
Definition: mainwindow.cpp:851
void displayExecutionLogTab()
Definition: mainwindow.cpp:947
void handleRSSUnreadCountUpdated(int count)
Definition: mainwindow.cpp:683
void reloadSessionStats()
QPointer< StatsDialog > m_statsDlg
Definition: mainwindow.h:227
void setExecutionLogMsgTypes(Log::MsgTypes value)
Definition: mainwindow.cpp:500
void cleanup()
Definition: mainwindow.cpp:796
void on_actionAutoShutdown_toggled(bool)
void toolbarTextUnder()
Definition: mainwindow.cpp:627
bool isTorrentAddedNotificationsEnabled() const
Definition: mainwindow.cpp:516
void loadPreferences()
QPointer< QSystemTrayIcon > m_systrayIcon
Definition: mainwindow.h:232
void on_actionExit_triggered()
void optionsSaved()
void displayRSSTab()
Definition: mainwindow.cpp:936
void toolbarFollowSystem()
Definition: mainwindow.cpp:633
bool m_uiLocked
Definition: mainwindow.h:241
QPointer< DownloadFromURLDialog > m_downloadFromURLDialog
Definition: mainwindow.h:229
QPointer< SearchWidget > m_searchWidget
Definition: mainwindow.h:249
void showEvent(QShowEvent *) override
bool isDownloadTrackerFavicon() const
Definition: mainwindow.cpp:538
void on_actionRSSReader_triggered()
QSplitter * m_splitter
Definition: mainwindow.h:248
QWidget * currentTabWidget() const
bool defineUILockPassword()
Definition: mainwindow.cpp:639
bool m_hasPython
Definition: mainwindow.h:255
void on_actionLock_triggered()
Definition: mainwindow.cpp:665
TransferListFiltersWidget * m_transferListFiltersWidget
Definition: mainwindow.h:237
void on_actionWarningMessages_triggered(bool checked)
void activate()
void toggleVisibility(const QSystemTrayIcon::ActivationReason reason=QSystemTrayIcon::Trigger)
QMenu * m_toolbarMenu
Definition: mainwindow.h:256
void on_actionSetGlobalSpeedLimits_triggered()
Definition: mainwindow.cpp:993
QPointer< RSSWidget > m_rssWidget
Definition: mainwindow.h:250
QAction * m_searchFilterAction
Definition: mainwindow.h:244
void displayTransferTab() const
Definition: mainwindow.cpp:920
void on_actionCreateTorrent_triggered()
QTimer * m_preventTimer
Definition: mainwindow.h:254
QAction * m_queueSeparator
Definition: mainwindow.h:246
void on_actionDownloadFromURL_triggered()
bool isExecutionLogEnabled() const
Definition: mainwindow.cpp:485
void focusSearchFilter()
Definition: mainwindow.cpp:750
void notifyOfUpdate(const QString &)
void on_actionStatistics_triggered()
bool unlockUI()
void setDownloadTrackerFavicon(bool value)
Definition: mainwindow.cpp:543
void on_actionExecutionLogs_triggered(bool checked)
QPointer< QMenu > m_trayIconMenu
Definition: mainwindow.h:234
bool event(QEvent *e) override
void dropEvent(QDropEvent *event) override
void reloadTorrentStats(const QVector< BitTorrent::Torrent * > &torrents)
void createTrayIcon(int retries)
void on_actionSpeedInTitleBar_triggered()
bool isNotificationsEnabled() const
Definition: mainwindow.cpp:506
void systemTrayIconCreated()
Definition: session.h:86
T value(const QString &key, const T &defaultValue={})
Definition: preferences.cpp:64