GHA CI: don't override cmake default CXXFLAGS
[qBittorrent.git] / src / app / application.h
blobd267a8d9be299ee3ad54f839d228c7c684546611
1 /*
2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2022 Mike Tzou (Chocobo1)
4 * Copyright (C) 2015, 2019 Vladimir Golovnev <glassez@yandex.ru>
5 * Copyright (C) 2006 Christophe Dumez
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * In addition, as a special exception, the copyright holders give permission to
22 * link this program with the OpenSSL project's "OpenSSL" library (or with
23 * modified versions of it that use the same license as the "OpenSSL" library),
24 * and distribute the linked executables. You must obey the GNU General Public
25 * License in all respects for all of the code used other than "OpenSSL". If you
26 * modify file(s), you may extend this exception to your version of the file(s),
27 * but you are not obligated to do so. If you do not wish to do so, delete this
28 * exception statement from your version.
31 #pragma once
33 #include <atomic>
35 #include <QtSystemDetection>
36 #include <QCoreApplication>
37 #include <QPointer>
38 #include <QStringList>
39 #include <QTranslator>
41 #ifndef DISABLE_GUI
42 #include <QApplication>
43 #endif
45 #include "base/bittorrent/addtorrentparams.h"
46 #include "base/interfaces/iapplication.h"
47 #include "base/path.h"
48 #include "base/settingvalue.h"
49 #include "base/types.h"
50 #include "cmdoptions.h"
52 #ifndef DISABLE_GUI
53 #include "gui/interfaces/iguiapplication.h"
54 #endif
56 class ApplicationInstanceManager;
57 class FileLogger;
59 namespace BitTorrent
61 class Torrent;
64 namespace RSS
66 class Session;
67 class AutoDownloader;
70 #ifndef DISABLE_GUI
71 class QProgressDialog;
73 class DesktopIntegration;
74 class MainWindow;
76 using AddTorrentManagerImpl = GUIAddTorrentManager;
77 using BaseApplication = QApplication;
78 using BaseIApplication = IGUIApplication;
80 #ifdef Q_OS_WIN
81 class QSessionManager;
82 #endif
83 #else // DISABLE_GUI
84 using AddTorrentManagerImpl = AddTorrentManager;
85 using BaseApplication = QCoreApplication;
86 using BaseIApplication = IApplication;
87 #endif // DISABLE_GUI
89 #ifndef DISABLE_WEBUI
90 class WebUI;
91 #endif
93 class Application final : public BaseApplication, public BaseIApplication
95 Q_OBJECT
96 Q_DISABLE_COPY_MOVE(Application)
98 public:
99 Application(int &argc, char **argv);
100 ~Application() override;
102 int exec();
104 bool isRunning();
105 bool callMainInstance();
106 const QBtCommandLineParameters &commandLineArgs() const;
108 // FileLogger properties
109 bool isFileLoggerEnabled() const override;
110 void setFileLoggerEnabled(bool value) override;
111 Path fileLoggerPath() const override;
112 void setFileLoggerPath(const Path &path) override;
113 bool isFileLoggerBackup() const override;
114 void setFileLoggerBackup(bool value) override;
115 bool isFileLoggerDeleteOld() const override;
116 void setFileLoggerDeleteOld(bool value) override;
117 int fileLoggerMaxSize() const override;
118 void setFileLoggerMaxSize(int bytes) override;
119 int fileLoggerAge() const override;
120 void setFileLoggerAge(int value) override;
121 int fileLoggerAgeType() const override;
122 void setFileLoggerAgeType(int value) override;
124 int memoryWorkingSetLimit() const override;
125 void setMemoryWorkingSetLimit(int size) override;
127 #ifdef Q_OS_WIN
128 MemoryPriority processMemoryPriority() const override;
129 void setProcessMemoryPriority(MemoryPriority priority) override;
130 #endif
132 #ifndef DISABLE_GUI
133 DesktopIntegration *desktopIntegration() override;
134 MainWindow *mainWindow() override;
136 WindowState startUpWindowState() const override;
137 void setStartUpWindowState(WindowState windowState) override;
139 bool isTorrentAddedNotificationsEnabled() const override;
140 void setTorrentAddedNotificationsEnabled(bool value) override;
141 #endif
143 private slots:
144 void processMessage(const QString &message);
145 void torrentAdded(const BitTorrent::Torrent *torrent) const;
146 void torrentFinished(const BitTorrent::Torrent *torrent);
147 void allTorrentsFinished();
148 void cleanup();
150 #if (!defined(DISABLE_GUI) && defined(Q_OS_WIN))
151 void shutdownCleanup(QSessionManager &manager);
152 #endif
154 private:
155 AddTorrentManagerImpl *addTorrentManager() const override;
157 void initializeTranslation();
158 void processParams(const QBtCommandLineParameters &params);
159 void runExternalProgram(const QString &programTemplate, const BitTorrent::Torrent *torrent) const;
160 void sendNotificationEmail(const BitTorrent::Torrent *torrent);
162 #ifdef QBT_USES_LIBTORRENT2
163 void applyMemoryWorkingSetLimit() const;
164 #endif
166 #ifdef Q_OS_WIN
167 void applyMemoryPriority() const;
168 void adjustThreadPriority() const;
169 #endif
171 #ifndef DISABLE_GUI
172 void createStartupProgressDialog();
173 #ifdef Q_OS_MACOS
174 bool event(QEvent *) override;
175 #endif
176 void askRecursiveTorrentDownloadConfirmation(const BitTorrent::Torrent *torrent);
177 void recursiveTorrentDownload(const BitTorrent::TorrentID &torrentID);
178 #endif
180 ApplicationInstanceManager *m_instanceManager = nullptr;
181 std::atomic_bool m_isCleanupRun;
182 bool m_isProcessingParamsAllowed = false;
183 ShutdownDialogAction m_shutdownAct = ShutdownDialogAction::Exit;
184 QBtCommandLineParameters m_commandLineArgs;
186 // FileLog
187 QPointer<FileLogger> m_fileLogger;
189 QTranslator m_qtTranslator;
190 QTranslator m_translator;
192 QList<QBtCommandLineParameters> m_paramsQueue;
194 SettingValue<bool> m_storeFileLoggerEnabled;
195 SettingValue<bool> m_storeFileLoggerBackup;
196 SettingValue<bool> m_storeFileLoggerDeleteOld;
197 SettingValue<int> m_storeFileLoggerMaxSize;
198 SettingValue<int> m_storeFileLoggerAge;
199 SettingValue<int> m_storeFileLoggerAgeType;
200 SettingValue<Path> m_storeFileLoggerPath;
201 SettingValue<int> m_storeMemoryWorkingSetLimit;
203 #ifdef Q_OS_WIN
204 SettingValue<MemoryPriority> m_processMemoryPriority;
205 #endif
207 AddTorrentManagerImpl *m_addTorrentManager = nullptr;
209 #ifndef DISABLE_GUI
210 SettingValue<WindowState> m_startUpWindowState;
211 SettingValue<bool> m_storeNotificationTorrentAdded;
213 DesktopIntegration *m_desktopIntegration = nullptr;
214 MainWindow *m_window = nullptr;
215 QProgressDialog *m_startupProgressDialog = nullptr;
216 #endif
218 #ifndef DISABLE_WEBUI
219 WebUI *m_webui = nullptr;
220 #endif