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.
35 #include <QCoreApplication>
37 #include <QStringList>
38 #include <QTranslator>
41 #include <QApplication>
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"
52 #include "gui/interfaces/iguiapplication.h"
55 class ApplicationInstanceManager
;
70 class QProgressDialog
;
72 class DesktopIntegration
;
75 using BaseApplication
= QApplication
;
76 using BaseIApplication
= IGUIApplication
;
79 class QSessionManager
;
82 using BaseApplication
= QCoreApplication
;
83 using BaseIApplication
= IApplication
;
90 class Application final
: public BaseApplication
, public BaseIApplication
93 Q_DISABLE_COPY_MOVE(Application
)
96 Application(int &argc
, char **argv
);
97 ~Application() override
;
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
;
125 MemoryPriority
processMemoryPriority() const override
;
126 void setProcessMemoryPriority(MemoryPriority priority
) override
;
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
;
141 void processMessage(const QString
&message
);
142 void torrentAdded(const BitTorrent::Torrent
*torrent
) const;
143 void torrentFinished(const BitTorrent::Torrent
*torrent
);
144 void allTorrentsFinished();
147 #if (!defined(DISABLE_GUI) && defined(Q_OS_WIN))
148 void shutdownCleanup(QSessionManager
&manager
);
152 #ifndef DISABLE_WEBUI
153 WebUI
*webUI() const override
;
156 void initializeTranslation();
157 void processParams(const QBtCommandLineParameters
¶ms
);
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;
166 void applyMemoryPriority() const;
167 void adjustThreadPriority() const;
171 void createStartupProgressDialog();
173 bool event(QEvent
*) override
;
177 ApplicationInstanceManager
*m_instanceManager
= nullptr;
178 QAtomicInt m_isCleanupRun
;
179 bool m_isProcessingParamsAllowed
= false;
180 ShutdownDialogAction m_shutdownAct
= ShutdownDialogAction::Exit
;
181 QBtCommandLineParameters m_commandLineArgs
;
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
;
201 SettingValue
<MemoryPriority
> m_processMemoryPriority
;
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;
213 #ifndef DISABLE_WEBUI
214 WebUI
*m_webui
= nullptr;