Don't initialize Properties widget size until window is shown
[qBittorrent.git] / src / gui / mainwindow.h
blob0566c70500d12b85b51f78beb17b47ec2282fc50
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 namespace Net
66 struct DownloadResult;
69 namespace Ui
71 class MainWindow;
74 class MainWindow final : public QMainWindow, public GUIApplicationComponent
76 Q_OBJECT
77 Q_DISABLE_COPY_MOVE(MainWindow)
79 public:
80 explicit MainWindow(IGUIApplication *app, WindowState initialState = WindowState::Normal);
81 ~MainWindow() override;
83 QWidget *currentTabWidget() const;
84 TransferListWidget *transferListWidget() const;
85 PropertiesWidget *propertiesWidget() const;
87 // ExecutionLog properties
88 bool isExecutionLogEnabled() const;
89 void setExecutionLogEnabled(bool value);
90 Log::MsgTypes executionLogMsgTypes() const;
91 void setExecutionLogMsgTypes(Log::MsgTypes value);
93 // Notifications properties
95 // Misc properties
96 bool isDownloadTrackerFavicon() const;
97 void setDownloadTrackerFavicon(bool value);
99 void activate();
100 void cleanup();
102 private slots:
103 void showFilterContextMenu();
104 void desktopNotificationClicked();
105 void saveSettings() const;
106 void loadSettings();
107 void saveSplitterSettings() const;
108 void tabChanged(int newTab);
109 bool defineUILockPassword();
110 void clearUILockPassword();
111 bool unlockUI();
112 void notifyOfUpdate(const QString &);
113 void showConnectionSettings();
114 void minimizeWindow();
115 // Keyboard shortcuts
116 void createKeyboardShortcuts();
117 void displayTransferTab() const;
118 void displaySearchTab();
119 void displayRSSTab();
120 void displayExecutionLogTab();
121 void focusSearchFilter();
122 void reloadSessionStats();
123 void reloadTorrentStats(const QVector<BitTorrent::Torrent *> &torrents);
124 void loadPreferences();
125 void askRecursiveTorrentDownloadConfirmation(const BitTorrent::Torrent *torrent);
126 void optionsSaved();
127 void toggleAlternativeSpeeds();
129 #ifdef Q_OS_WIN
130 void pythonDownloadFinished(const Net::DownloadResult &result);
131 #endif
132 void addToolbarContextMenu();
133 void manageCookies();
135 void downloadFromURLList(const QStringList &urlList);
136 void updateAltSpeedsBtn(bool alternative);
137 void updateNbTorrents();
138 void handleRSSUnreadCountUpdated(int count);
140 void on_actionSearchWidget_triggered();
141 void on_actionRSSReader_triggered();
142 void on_actionSpeedInTitleBar_triggered();
143 void on_actionTopToolBar_triggered();
144 void on_actionShowStatusbar_triggered();
145 void on_actionShowFiltersSidebar_triggered(bool checked);
146 void on_actionDonateMoney_triggered();
147 void on_actionExecutionLogs_triggered(bool checked);
148 void on_actionNormalMessages_triggered(bool checked);
149 void on_actionInformationMessages_triggered(bool checked);
150 void on_actionWarningMessages_triggered(bool checked);
151 void on_actionCriticalMessages_triggered(bool checked);
152 void on_actionAutoExit_toggled(bool);
153 void on_actionAutoSuspend_toggled(bool);
154 void on_actionAutoHibernate_toggled(bool);
155 void on_actionAutoShutdown_toggled(bool);
156 void on_actionAbout_triggered();
157 void on_actionStatistics_triggered();
158 void on_actionCreateTorrent_triggered();
159 void on_actionOptions_triggered();
160 void on_actionSetGlobalSpeedLimits_triggered();
161 void on_actionDocumentation_triggered() const;
162 void on_actionOpen_triggered();
163 void on_actionDownloadFromURL_triggered();
164 void on_actionExit_triggered();
165 void on_actionLock_triggered();
166 // Check for unpaused downloading or seeding torrents and prevent system suspend/sleep according to preferences
167 void updatePowerManagementState();
169 void toolbarMenuRequested();
170 void toolbarIconsOnly();
171 void toolbarTextOnly();
172 void toolbarTextBeside();
173 void toolbarTextUnder();
174 void toolbarFollowSystem();
175 #ifdef Q_OS_MACOS
176 void on_actionCloseWindow_triggered();
177 #else
178 void toggleVisibility();
179 #endif
181 private:
182 QMenu *createDesktopIntegrationMenu();
183 #ifdef Q_OS_WIN
184 void installPython();
185 #endif
187 void dropEvent(QDropEvent *event) override;
188 void dragEnterEvent(QDragEnterEvent *event) override;
189 void closeEvent(QCloseEvent *) override;
190 void showEvent(QShowEvent *) override;
191 void keyPressEvent(QKeyEvent *event) override;
192 bool event(QEvent *e) override;
193 void displayRSSTab(bool enable);
194 void displaySearchTab(bool enable);
195 void createTorrentTriggered(const Path &path);
196 void showStatusBar(bool show);
197 void showFiltersSidebar(bool show);
198 void applyTransferListFilter();
200 Ui::MainWindow *m_ui = nullptr;
202 QFileSystemWatcher *m_executableWatcher = nullptr;
203 // GUI related
204 bool m_posInitialized = false;
205 bool m_neverShown = true;
206 QPointer<QTabWidget> m_tabs;
207 QPointer<StatusBar> m_statusBar;
208 QPointer<OptionsDialog> m_options;
209 QPointer<AboutDialog> m_aboutDlg;
210 QPointer<StatsDialog> m_statsDlg;
211 QPointer<TorrentCreatorDialog> m_createTorrentDlg;
212 QPointer<DownloadFromURLDialog> m_downloadFromURLDialog;
214 QPointer<QMenu> m_trayIconMenu;
216 TransferListWidget *m_transferListWidget = nullptr;
217 TransferListFiltersWidget *m_transferListFiltersWidget = nullptr;
218 PropertiesWidget *m_propertiesWidget = nullptr;
219 bool m_displaySpeedInTitle = false;
220 bool m_forceExit = false;
221 bool m_uiLocked = false;
222 bool m_unlockDlgShowing = false;
223 QWidget *m_columnFilterWidget = nullptr;
224 LineEdit *m_columnFilterEdit = nullptr;
225 QAction *m_columnFilterAction = nullptr;
226 QComboBox *m_columnFilterComboBox = nullptr;
227 // Widgets
228 QAction *m_queueSeparator = nullptr;
229 QAction *m_queueSeparatorMenu = nullptr;
230 QSplitter *m_splitter = nullptr;
231 QPointer<SearchWidget> m_searchWidget;
232 QPointer<RSSWidget> m_rssWidget;
233 QPointer<ExecutionLogWidget> m_executionLog;
234 // Power Management
235 PowerManagement *m_pwr = nullptr;
236 QTimer *m_preventTimer = nullptr;
237 bool m_hasPython = false;
238 QMenu *m_toolbarMenu = nullptr;
240 SettingValue<bool> m_storeExecutionLogEnabled;
241 SettingValue<bool> m_storeDownloadTrackerFavicon;
242 CachedSettingValue<Log::MsgTypes> m_storeExecutionLogTypes;
244 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
245 void checkProgramUpdate(bool invokedByUser);
246 void handleUpdateCheckFinished(ProgramUpdater *updater, bool invokedByUser);
248 QTimer *m_programUpdateTimer = nullptr;
249 #endif