Merge pull request #18104 from sledgehammer999/remove_dead_code
[qBittorrent.git] / src / gui / mainwindow.h
blobe7af3d2e02d28d75fe7f3f638ee65c41c68334ec
1 /*
2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
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.
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.
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.
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.
29 #pragma once
31 #include <QMainWindow>
32 #include <QPointer>
34 #include "base/bittorrent/torrent.h"
35 #include "base/logger.h"
36 #include "base/settingvalue.h"
37 #include "guiapplicationcomponent.h"
39 class QCloseEvent;
40 class QFileSystemWatcher;
41 class QSplitter;
42 class QTabWidget;
43 class QTimer;
45 class AboutDialog;
46 class DownloadFromURLDialog;
47 class ExecutionLogWidget;
48 class LineEdit;
49 class OptionsDialog;
50 class PowerManagement;
51 class ProgramUpdater;
52 class PropertiesWidget;
53 class RSSWidget;
54 class SearchWidget;
55 class StatsDialog;
56 class StatusBar;
57 class TorrentCreatorDialog;
58 class TransferListFiltersWidget;
59 class TransferListWidget;
61 namespace Net
63 struct DownloadResult;
66 namespace Ui
68 class MainWindow;
71 class MainWindow final : public QMainWindow, public GUIApplicationComponent
73 Q_OBJECT
74 Q_DISABLE_COPY_MOVE(MainWindow)
76 public:
77 enum State
79 Normal,
80 Minimized
83 explicit MainWindow(IGUIApplication *app, State initialState = Normal);
84 ~MainWindow() override;
86 QWidget *currentTabWidget() const;
87 TransferListWidget *transferListWidget() const;
88 PropertiesWidget *propertiesWidget() const;
90 // ExecutionLog properties
91 bool isExecutionLogEnabled() const;
92 void setExecutionLogEnabled(bool value);
93 Log::MsgTypes executionLogMsgTypes() const;
94 void setExecutionLogMsgTypes(Log::MsgTypes value);
96 // Notifications properties
98 // Misc properties
99 bool isDownloadTrackerFavicon() const;
100 void setDownloadTrackerFavicon(bool value);
102 void activate();
103 void cleanup();
105 private slots:
106 void showFilterContextMenu();
107 void desktopNotificationClicked();
108 void saveSettings() const;
109 void loadSettings();
110 void saveSplitterSettings() const;
111 void tabChanged(int newTab);
112 bool defineUILockPassword();
113 void clearUILockPassword();
114 bool unlockUI();
115 void notifyOfUpdate(const QString &);
116 void showConnectionSettings();
117 void minimizeWindow();
118 // Keyboard shortcuts
119 void createKeyboardShortcuts();
120 void displayTransferTab() const;
121 void displaySearchTab();
122 void displayRSSTab();
123 void displayExecutionLogTab();
124 void focusSearchFilter();
125 void reloadSessionStats();
126 void reloadTorrentStats(const QVector<BitTorrent::Torrent *> &torrents);
127 void loadPreferences();
128 void askRecursiveTorrentDownloadConfirmation(const BitTorrent::Torrent *torrent);
129 void optionsSaved();
130 void toggleAlternativeSpeeds();
132 #ifdef Q_OS_WIN
133 void pythonDownloadFinished(const Net::DownloadResult &result);
134 #endif
135 void addToolbarContextMenu();
136 void manageCookies();
138 void downloadFromURLList(const QStringList &urlList);
139 void updateAltSpeedsBtn(bool alternative);
140 void updateNbTorrents();
141 void handleRSSUnreadCountUpdated(int count);
143 void on_actionSearchWidget_triggered();
144 void on_actionRSSReader_triggered();
145 void on_actionSpeedInTitleBar_triggered();
146 void on_actionTopToolBar_triggered();
147 void on_actionShowStatusbar_triggered();
148 void on_actionShowFiltersSidebar_triggered(bool checked);
149 void on_actionDonateMoney_triggered();
150 void on_actionExecutionLogs_triggered(bool checked);
151 void on_actionNormalMessages_triggered(bool checked);
152 void on_actionInformationMessages_triggered(bool checked);
153 void on_actionWarningMessages_triggered(bool checked);
154 void on_actionCriticalMessages_triggered(bool checked);
155 void on_actionAutoExit_toggled(bool);
156 void on_actionAutoSuspend_toggled(bool);
157 void on_actionAutoHibernate_toggled(bool);
158 void on_actionAutoShutdown_toggled(bool);
159 void on_actionAbout_triggered();
160 void on_actionStatistics_triggered();
161 void on_actionCreateTorrent_triggered();
162 void on_actionOptions_triggered();
163 void on_actionSetGlobalSpeedLimits_triggered();
164 void on_actionDocumentation_triggered() const;
165 void on_actionOpen_triggered();
166 void on_actionDownloadFromURL_triggered();
167 void on_actionExit_triggered();
168 void on_actionLock_triggered();
169 // Check for unpaused downloading or seeding torrents and prevent system suspend/sleep according to preferences
170 void updatePowerManagementState();
172 void toolbarMenuRequested();
173 void toolbarIconsOnly();
174 void toolbarTextOnly();
175 void toolbarTextBeside();
176 void toolbarTextUnder();
177 void toolbarFollowSystem();
178 #ifdef Q_OS_MACOS
179 void on_actionCloseWindow_triggered();
180 #else
181 void toggleVisibility();
182 #endif
184 private:
185 QMenu *createDesktopIntegrationMenu();
186 #ifdef Q_OS_WIN
187 void installPython();
188 #endif
190 void dropEvent(QDropEvent *event) override;
191 void dragEnterEvent(QDragEnterEvent *event) override;
192 void closeEvent(QCloseEvent *) override;
193 void showEvent(QShowEvent *) override;
194 void keyPressEvent(QKeyEvent *event) override;
195 bool event(QEvent *e) override;
196 void displayRSSTab(bool enable);
197 void displaySearchTab(bool enable);
198 void createTorrentTriggered(const Path &path);
199 void showStatusBar(bool show);
200 void showFiltersSidebar(bool show);
202 Ui::MainWindow *m_ui = nullptr;
204 QFileSystemWatcher *m_executableWatcher = nullptr;
205 // GUI related
206 bool m_posInitialized = false;
207 QPointer<QTabWidget> m_tabs;
208 QPointer<StatusBar> m_statusBar;
209 QPointer<OptionsDialog> m_options;
210 QPointer<AboutDialog> m_aboutDlg;
211 QPointer<StatsDialog> m_statsDlg;
212 QPointer<TorrentCreatorDialog> m_createTorrentDlg;
213 QPointer<DownloadFromURLDialog> m_downloadFromURLDialog;
215 QPointer<QMenu> m_trayIconMenu;
217 TransferListWidget *m_transferListWidget = nullptr;
218 TransferListFiltersWidget *m_transferListFiltersWidget = nullptr;
219 PropertiesWidget *m_propertiesWidget = nullptr;
220 bool m_displaySpeedInTitle = false;
221 bool m_forceExit = false;
222 bool m_uiLocked = false;
223 bool m_unlockDlgShowing = false;
224 LineEdit *m_searchFilter = nullptr;
225 QAction *m_searchFilterAction = nullptr;
226 // Widgets
227 QAction *m_queueSeparator = nullptr;
228 QAction *m_queueSeparatorMenu = nullptr;
229 QSplitter *m_splitter = nullptr;
230 QPointer<SearchWidget> m_searchWidget;
231 QPointer<RSSWidget> m_rssWidget;
232 QPointer<ExecutionLogWidget> m_executionLog;
233 // Power Management
234 PowerManagement *m_pwr = nullptr;
235 QTimer *m_preventTimer = nullptr;
236 bool m_hasPython = false;
237 QMenu *m_toolbarMenu = nullptr;
239 SettingValue<bool> m_storeExecutionLogEnabled;
240 SettingValue<bool> m_storeDownloadTrackerFavicon;
241 CachedSettingValue<Log::MsgTypes> m_storeExecutionLogTypes;
243 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
244 void checkProgramUpdate(bool invokedByUser);
245 void handleUpdateCheckFinished(ProgramUpdater *updater, bool invokedByUser);
247 QTimer *m_programUpdateTimer = nullptr;
248 #endif