WebUI: Show 'Rename...' context menu item only when one torrent is selected
[qBittorrent.git] / src / app / application.h
blobca683fbff495c6859f8ae872fbfe49376970493e
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 hasAnotherInstance() const;
105 bool callMainInstance();
106 const QBtCommandLineParameters &commandLineArgs() const;
108 QString instanceName() const override;
109 void setInstanceName(const QString &name) override;
111 // FileLogger properties
112 bool isFileLoggerEnabled() const override;
113 void setFileLoggerEnabled(bool value) override;
114 Path fileLoggerPath() const override;
115 void setFileLoggerPath(const Path &path) override;
116 bool isFileLoggerBackup() const override;
117 void setFileLoggerBackup(bool value) override;
118 bool isFileLoggerDeleteOld() const override;
119 void setFileLoggerDeleteOld(bool value) override;
120 int fileLoggerMaxSize() const override;
121 void setFileLoggerMaxSize(int bytes) override;
122 int fileLoggerAge() const override;
123 void setFileLoggerAge(int value) override;
124 int fileLoggerAgeType() const override;
125 void setFileLoggerAgeType(int value) override;
127 int memoryWorkingSetLimit() const override;
128 void setMemoryWorkingSetLimit(int size) override;
130 void sendTestEmail() const override;
132 #ifdef Q_OS_WIN
133 MemoryPriority processMemoryPriority() const override;
134 void setProcessMemoryPriority(MemoryPriority priority) override;
135 #endif
137 #ifndef DISABLE_GUI
138 DesktopIntegration *desktopIntegration() override;
139 MainWindow *mainWindow() override;
141 WindowState startUpWindowState() const override;
142 void setStartUpWindowState(WindowState windowState) override;
144 bool isTorrentAddedNotificationsEnabled() const override;
145 void setTorrentAddedNotificationsEnabled(bool value) override;
146 #endif
148 private slots:
149 void processMessage(const QString &message);
150 void torrentAdded(const BitTorrent::Torrent *torrent) const;
151 void torrentFinished(const BitTorrent::Torrent *torrent);
152 void allTorrentsFinished();
153 void cleanup();
155 #if (!defined(DISABLE_GUI) && defined(Q_OS_WIN))
156 void shutdownCleanup(QSessionManager &manager);
157 #endif
159 private:
160 AddTorrentManagerImpl *addTorrentManager() const override;
161 #ifndef DISABLE_WEBUI
162 WebUI *webUI() const override;
163 #endif
165 void initializeTranslation();
166 void processParams(const QBtCommandLineParameters &params);
167 void runExternalProgram(const QString &programTemplate, const BitTorrent::Torrent *torrent) const;
168 void sendNotificationEmail(const BitTorrent::Torrent *torrent);
170 #if defined(QBT_USES_LIBTORRENT2) && !defined(Q_OS_MACOS)
171 void applyMemoryWorkingSetLimit() const;
172 #endif
174 #ifdef Q_OS_WIN
175 void applyMemoryPriority() const;
176 void adjustThreadPriority() const;
177 #endif
179 #ifndef DISABLE_GUI
180 void createStartupProgressDialog();
181 #ifdef Q_OS_MACOS
182 bool event(QEvent *) override;
183 #endif
184 void askRecursiveTorrentDownloadConfirmation(const BitTorrent::Torrent *torrent);
185 void recursiveTorrentDownload(const BitTorrent::TorrentID &torrentID);
186 #endif
188 ApplicationInstanceManager *m_instanceManager = nullptr;
189 std::atomic_bool m_isCleanupRun;
190 bool m_isProcessingParamsAllowed = false;
191 ShutdownDialogAction m_shutdownAct = ShutdownDialogAction::Exit;
192 QBtCommandLineParameters m_commandLineArgs;
194 // FileLog
195 QPointer<FileLogger> m_fileLogger;
197 QTranslator m_qtTranslator;
198 QTranslator m_translator;
200 QList<QBtCommandLineParameters> m_paramsQueue;
202 SettingValue<QString> m_storeInstanceName;
203 SettingValue<bool> m_storeFileLoggerEnabled;
204 SettingValue<bool> m_storeFileLoggerBackup;
205 SettingValue<bool> m_storeFileLoggerDeleteOld;
206 SettingValue<int> m_storeFileLoggerMaxSize;
207 SettingValue<int> m_storeFileLoggerAge;
208 SettingValue<int> m_storeFileLoggerAgeType;
209 SettingValue<Path> m_storeFileLoggerPath;
210 SettingValue<int> m_storeMemoryWorkingSetLimit;
212 #ifdef Q_OS_WIN
213 SettingValue<MemoryPriority> m_processMemoryPriority;
214 #endif
216 AddTorrentManagerImpl *m_addTorrentManager = nullptr;
218 #ifndef DISABLE_GUI
219 SettingValue<WindowState> m_startUpWindowState;
220 SettingValue<bool> m_storeNotificationTorrentAdded;
222 DesktopIntegration *m_desktopIntegration = nullptr;
223 MainWindow *m_window = nullptr;
224 QProgressDialog *m_startupProgressDialog = nullptr;
225 #endif
227 #ifndef DISABLE_WEBUI
228 WebUI *m_webui = nullptr;
229 #endif