Remove incorrect assertions
[qBittorrent.git] / src / gui / mainwindow.h
blob65d1088c8bf3b09feaf069848458428705c798c8
1 /*
2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2022 Vladimir Golovnev <glassez@yandex.ru>
4 * Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * In addition, as a special exception, the copyright holders give permission to
21 * link this program with the OpenSSL project's "OpenSSL" library (or with
22 * modified versions of it that use the same license as the "OpenSSL" library),
23 * and distribute the linked executables. You must obey the GNU General Public
24 * License in all respects for all of the code used other than "OpenSSL". If you
25 * modify file(s), you may extend this exception to your version of the file(s),
26 * but you are not obligated to do so. If you do not wish to do so, delete this
27 * exception statement from your version.
30 #pragma once
32 #include <QMainWindow>
33 #include <QPointer>
35 #include "base/bittorrent/torrent.h"
36 #include "base/logger.h"
37 #include "base/settingvalue.h"
38 #include "guiapplicationcomponent.h"
39 #include "windowstate.h"
41 class QCloseEvent;
42 class QComboBox;
43 class QFileSystemWatcher;
44 class QSplitter;
45 class QTabWidget;
46 class QTimer;
48 class AboutDialog;
49 class DownloadFromURLDialog;
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;
60 class TorrentCreatorDialog;
61 class TransferListFiltersWidget;
62 class TransferListWidget;
64 #ifdef Q_OS_MACOS
65 namespace MacUtils
67 class Badger;
69 #endif
71 namespace Net
73 struct DownloadResult;
76 namespace Ui
78 class MainWindow;
81 class MainWindow final : public GUIApplicationComponent<QMainWindow>
83 Q_OBJECT
84 Q_DISABLE_COPY_MOVE(MainWindow)
86 public:
87 explicit MainWindow(IGUIApplication *app, WindowState initialState = WindowState::Normal);
88 ~MainWindow() override;
90 QWidget *currentTabWidget() const;
91 TransferListWidget *transferListWidget() const;
92 PropertiesWidget *propertiesWidget() const;
94 // ExecutionLog properties
95 bool isExecutionLogEnabled() const;
96 void setExecutionLogEnabled(bool value);
97 Log::MsgTypes executionLogMsgTypes() const;
98 void setExecutionLogMsgTypes(Log::MsgTypes value);
100 // Notifications properties
102 // Misc properties
103 bool isDownloadTrackerFavicon() const;
104 void setDownloadTrackerFavicon(bool value);
106 void activate();
107 void cleanup();
109 private slots:
110 void showFilterContextMenu();
111 void desktopNotificationClicked();
112 void saveSettings() const;
113 void loadSettings();
114 void saveSplitterSettings() const;
115 void tabChanged(int newTab);
116 bool defineUILockPassword();
117 void clearUILockPassword();
118 bool unlockUI();
119 void notifyOfUpdate(const QString &);
120 void showConnectionSettings();
121 void minimizeWindow();
122 // Keyboard shortcuts
123 void createKeyboardShortcuts();
124 void displayTransferTab() const;
125 void displaySearchTab();
126 void displayRSSTab();
127 void displayExecutionLogTab();
128 void focusSearchFilter();
129 void reloadSessionStats();
130 void reloadTorrentStats(const QVector<BitTorrent::Torrent *> &torrents);
131 void loadPreferences();
132 void optionsSaved();
133 void toggleAlternativeSpeeds();
135 #ifdef Q_OS_WIN
136 void pythonDownloadFinished(const Net::DownloadResult &result);
137 #endif
138 void addToolbarContextMenu();
139 void manageCookies();
141 void downloadFromURLList(const QStringList &urlList);
142 void updateAltSpeedsBtn(bool alternative);
143 void updateNbTorrents();
144 void handleRSSUnreadCountUpdated(int count);
146 void on_actionSearchWidget_triggered();
147 void on_actionRSSReader_triggered();
148 void on_actionSpeedInTitleBar_triggered();
149 void on_actionTopToolBar_triggered();
150 void on_actionShowStatusbar_triggered();
151 void on_actionShowFiltersSidebar_triggered(bool checked);
152 void on_actionDonateMoney_triggered();
153 void on_actionExecutionLogs_triggered(bool checked);
154 void on_actionNormalMessages_triggered(bool checked);
155 void on_actionInformationMessages_triggered(bool checked);
156 void on_actionWarningMessages_triggered(bool checked);
157 void on_actionCriticalMessages_triggered(bool checked);
158 void on_actionAutoExit_toggled(bool);
159 void on_actionAutoSuspend_toggled(bool);
160 void on_actionAutoHibernate_toggled(bool);
161 void on_actionAutoShutdown_toggled(bool);
162 void on_actionAbout_triggered();
163 void on_actionStatistics_triggered();
164 void on_actionCreateTorrent_triggered();
165 void on_actionOptions_triggered();
166 void on_actionSetGlobalSpeedLimits_triggered();
167 void on_actionDocumentation_triggered() const;
168 void on_actionOpen_triggered();
169 void on_actionDownloadFromURL_triggered();
170 void on_actionExit_triggered();
171 void on_actionLock_triggered();
172 // Check for unpaused downloading or seeding torrents and prevent system suspend/sleep according to preferences
173 void updatePowerManagementState() const;
175 void toolbarMenuRequested();
176 void toolbarIconsOnly();
177 void toolbarTextOnly();
178 void toolbarTextBeside();
179 void toolbarTextUnder();
180 void toolbarFollowSystem();
181 #ifdef Q_OS_MACOS
182 void on_actionCloseWindow_triggered();
183 #else
184 void toggleVisibility();
185 #endif
187 private:
188 QMenu *createDesktopIntegrationMenu();
189 #ifdef Q_OS_WIN
190 void installPython();
191 #endif
193 void dropEvent(QDropEvent *event) override;
194 void dragEnterEvent(QDragEnterEvent *event) override;
195 void closeEvent(QCloseEvent *) override;
196 void showEvent(QShowEvent *) override;
197 void keyPressEvent(QKeyEvent *event) override;
198 bool event(QEvent *e) override;
199 void displayRSSTab(bool enable);
200 void displaySearchTab(bool enable);
201 void createTorrentTriggered(const Path &path);
202 void showStatusBar(bool show);
203 void showFiltersSidebar(bool show);
204 void applyTransferListFilter();
206 Ui::MainWindow *m_ui = nullptr;
208 QFileSystemWatcher *m_executableWatcher = nullptr;
209 // GUI related
210 bool m_posInitialized = false;
211 bool m_neverShown = true;
212 QPointer<QTabWidget> m_tabs;
213 QPointer<StatusBar> m_statusBar;
214 QPointer<OptionsDialog> m_options;
215 QPointer<AboutDialog> m_aboutDlg;
216 QPointer<StatsDialog> m_statsDlg;
217 QPointer<TorrentCreatorDialog> m_createTorrentDlg;
218 QPointer<DownloadFromURLDialog> m_downloadFromURLDialog;
220 QPointer<QMenu> m_trayIconMenu;
222 TransferListWidget *m_transferListWidget = nullptr;
223 TransferListFiltersWidget *m_transferListFiltersWidget = nullptr;
224 PropertiesWidget *m_propertiesWidget = nullptr;
225 bool m_displaySpeedInTitle = false;
226 bool m_forceExit = false;
227 bool m_uiLocked = false;
228 bool m_unlockDlgShowing = false;
229 QWidget *m_columnFilterWidget = nullptr;
230 LineEdit *m_columnFilterEdit = nullptr;
231 QAction *m_columnFilterAction = nullptr;
232 QComboBox *m_columnFilterComboBox = nullptr;
233 // Widgets
234 QAction *m_queueSeparator = nullptr;
235 QAction *m_queueSeparatorMenu = nullptr;
236 QSplitter *m_splitter = nullptr;
237 QPointer<SearchWidget> m_searchWidget;
238 QPointer<RSSWidget> m_rssWidget;
239 QPointer<ExecutionLogWidget> m_executionLog;
240 // Power Management
241 PowerManagement *m_pwr = nullptr;
242 QTimer *m_preventTimer = nullptr;
243 QMenu *m_toolbarMenu = nullptr;
245 SettingValue<bool> m_storeExecutionLogEnabled;
246 SettingValue<bool> m_storeDownloadTrackerFavicon;
247 CachedSettingValue<Log::MsgTypes> m_storeExecutionLogTypes;
249 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
250 void checkProgramUpdate(bool invokedByUser);
251 void handleUpdateCheckFinished(ProgramUpdater *updater, bool invokedByUser);
253 QTimer *m_programUpdateTimer = nullptr;
254 #endif
255 #ifdef Q_OS_MACOS
256 std::unique_ptr<MacUtils::Badger> m_badger;
257 #endif