Sync translations from Transifex and run lupdate
[qBittorrent.git] / src / app / application.h
blob6d73c8c9aec436612ae8e502ed3dcaf434710248
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 <QtGlobal>
34 #include <QAtomicInt>
35 #include <QCoreApplication>
36 #include <QPointer>
37 #include <QStringList>
38 #include <QTranslator>
40 #ifndef DISABLE_GUI
41 #include <QApplication>
42 #endif
44 #include "base/bittorrent/addtorrentparams.h"
45 #include "base/interfaces/iapplication.h"
46 #include "base/path.h"
47 #include "base/settingvalue.h"
48 #include "base/types.h"
49 #include "cmdoptions.h"
51 #ifndef DISABLE_GUI
52 #include "gui/interfaces/iguiapplication.h"
53 #endif
55 class ApplicationInstanceManager;
56 class FileLogger;
58 namespace BitTorrent
60 class Torrent;
63 namespace RSS
65 class Session;
66 class AutoDownloader;
69 #ifndef DISABLE_GUI
70 class QProgressDialog;
72 class DesktopIntegration;
73 class MainWindow;
75 using BaseApplication = QApplication;
76 using BaseIApplication = IGUIApplication;
78 #ifdef Q_OS_WIN
79 class QSessionManager;
80 #endif
81 #else // DISABLE_GUI
82 using BaseApplication = QCoreApplication;
83 using BaseIApplication = IApplication;
84 #endif // DISABLE_GUI
86 #ifndef DISABLE_WEBUI
87 class WebUI;
88 #endif
90 class Application final : public BaseApplication, public BaseIApplication
92 Q_OBJECT
93 Q_DISABLE_COPY_MOVE(Application)
95 public:
96 Application(int &argc, char **argv);
97 ~Application() override;
99 int exec();
101 bool isRunning();
102 bool callMainInstance();
103 const QBtCommandLineParameters &commandLineArgs() const;
105 // FileLogger properties
106 bool isFileLoggerEnabled() const override;
107 void setFileLoggerEnabled(bool value) override;
108 Path fileLoggerPath() const override;
109 void setFileLoggerPath(const Path &path) override;
110 bool isFileLoggerBackup() const override;
111 void setFileLoggerBackup(bool value) override;
112 bool isFileLoggerDeleteOld() const override;
113 void setFileLoggerDeleteOld(bool value) override;
114 int fileLoggerMaxSize() const override;
115 void setFileLoggerMaxSize(int bytes) override;
116 int fileLoggerAge() const override;
117 void setFileLoggerAge(int value) override;
118 int fileLoggerAgeType() const override;
119 void setFileLoggerAgeType(int value) override;
121 int memoryWorkingSetLimit() const override;
122 void setMemoryWorkingSetLimit(int size) override;
124 #ifdef Q_OS_WIN
125 MemoryPriority processMemoryPriority() const override;
126 void setProcessMemoryPriority(MemoryPriority priority) override;
127 #endif
129 #ifndef DISABLE_GUI
130 DesktopIntegration *desktopIntegration() override;
131 MainWindow *mainWindow() override;
133 WindowState startUpWindowState() const override;
134 void setStartUpWindowState(WindowState windowState) override;
136 bool isTorrentAddedNotificationsEnabled() const override;
137 void setTorrentAddedNotificationsEnabled(bool value) override;
138 #endif
140 private slots:
141 void processMessage(const QString &message);
142 void torrentAdded(const BitTorrent::Torrent *torrent) const;
143 void torrentFinished(const BitTorrent::Torrent *torrent);
144 void allTorrentsFinished();
145 void cleanup();
147 #if (!defined(DISABLE_GUI) && defined(Q_OS_WIN))
148 void shutdownCleanup(QSessionManager &manager);
149 #endif
151 private:
152 #ifndef DISABLE_WEBUI
153 WebUI *webUI() const override;
154 #endif
156 void initializeTranslation();
157 void processParams(const QBtCommandLineParameters &params);
158 void runExternalProgram(const QString &programTemplate, const BitTorrent::Torrent *torrent) const;
159 void sendNotificationEmail(const BitTorrent::Torrent *torrent);
161 #if defined(QBT_USES_LIBTORRENT2) && !defined(Q_OS_MACOS)
162 void applyMemoryWorkingSetLimit() const;
163 #endif
165 #ifdef Q_OS_WIN
166 void applyMemoryPriority() const;
167 void adjustThreadPriority() const;
168 #endif
170 #ifndef DISABLE_GUI
171 void createStartupProgressDialog();
172 #ifdef Q_OS_MACOS
173 bool event(QEvent *) override;
174 #endif
175 #endif
177 ApplicationInstanceManager *m_instanceManager = nullptr;
178 QAtomicInt m_isCleanupRun;
179 bool m_isProcessingParamsAllowed = false;
180 ShutdownDialogAction m_shutdownAct = ShutdownDialogAction::Exit;
181 QBtCommandLineParameters m_commandLineArgs;
183 // FileLog
184 QPointer<FileLogger> m_fileLogger;
186 QTranslator m_qtTranslator;
187 QTranslator m_translator;
189 QList<QBtCommandLineParameters> m_paramsQueue;
191 SettingValue<bool> m_storeFileLoggerEnabled;
192 SettingValue<bool> m_storeFileLoggerBackup;
193 SettingValue<bool> m_storeFileLoggerDeleteOld;
194 SettingValue<int> m_storeFileLoggerMaxSize;
195 SettingValue<int> m_storeFileLoggerAge;
196 SettingValue<int> m_storeFileLoggerAgeType;
197 SettingValue<Path> m_storeFileLoggerPath;
198 SettingValue<int> m_storeMemoryWorkingSetLimit;
200 #ifdef Q_OS_WIN
201 SettingValue<MemoryPriority> m_processMemoryPriority;
202 #endif
204 #ifndef DISABLE_GUI
205 SettingValue<WindowState> m_startUpWindowState;
206 SettingValue<bool> m_storeNotificationTorrentAdded;
208 DesktopIntegration *m_desktopIntegration = nullptr;
209 MainWindow *m_window = nullptr;
210 QProgressDialog *m_startupProgressDialog = nullptr;
211 #endif
213 #ifndef DISABLE_WEBUI
214 WebUI *m_webui = nullptr;
215 #endif