mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-13 16:53:08 -07:00
Put all application logic into Application class.
Application process message and split it into params list itself (this prevents code duplication). Application store params unless other components ready to process them. Application incapsulate all QMacApplication and SessionApplication logic (this is too small to have separate classes).
This commit is contained in:
parent
8b95bb233d
commit
0c50a8b98b
11 changed files with 210 additions and 486 deletions
|
@ -39,8 +39,6 @@
|
|||
#include <QPen>
|
||||
#include <QPushButton>
|
||||
#include <QSplashScreen>
|
||||
#include <QStyle>
|
||||
#include <QStyleFactory>
|
||||
#ifdef QBT_STATIC_QT
|
||||
#include <QtPlugin>
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
|
||||
|
@ -49,12 +47,9 @@ Q_IMPORT_PLUGIN(QICOPlugin)
|
|||
Q_IMPORT_PLUGIN(qico)
|
||||
#endif
|
||||
#endif // QBT_STATIC_QT
|
||||
#include "mainwindow.h"
|
||||
#include "ico.h"
|
||||
#else // DISABLE_GUI
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include "headlessloader.h"
|
||||
#endif // DISABLE_GUI
|
||||
|
||||
#include "application.h"
|
||||
|
@ -71,25 +66,11 @@ Q_IMPORT_PLUGIN(qico)
|
|||
#include "stacktrace_win_dlg.h"
|
||||
#endif //STACKTRACE_WIN
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <cstdlib>
|
||||
#include "misc.h"
|
||||
#include "preferences.h"
|
||||
#include "logger.h"
|
||||
|
||||
class MessagesCollector : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public slots:
|
||||
void collectMessage(const QString& message)
|
||||
{
|
||||
messages.append(message.split("|", QString::SkipEmptyParts));
|
||||
}
|
||||
public:
|
||||
QStringList messages;
|
||||
};
|
||||
|
||||
#include "main.moc"
|
||||
|
||||
// Signal handlers
|
||||
#if defined(Q_OS_UNIX) || defined(STACKTRACE_WIN)
|
||||
void sigintHandler(int);
|
||||
|
@ -149,10 +130,6 @@ int main(int argc, char *argv[])
|
|||
QString appId = QLatin1String("qBittorrent-") + misc::getUserIDString();
|
||||
QScopedPointer<Application> app(new Application(appId, argc, argv));
|
||||
|
||||
MessagesCollector* messagesCollector = new MessagesCollector();
|
||||
QObject::connect(app.data(), SIGNAL(messageReceived(const QString &)),
|
||||
messagesCollector, SLOT(collectMessage(const QString &)));
|
||||
|
||||
const QBtCommandLineParameters params = parseCommandLine();
|
||||
|
||||
if (!params.unknownParameter.isEmpty()) {
|
||||
|
@ -216,15 +193,7 @@ int main(int argc, char *argv[])
|
|||
qDebug("qBittorrent is already running for this user.");
|
||||
|
||||
misc::msleep(300);
|
||||
if (!params.torrents.isEmpty()) {
|
||||
QString message = params.torrents.join("|");
|
||||
qDebug("Passing program parameters to running instance...");
|
||||
qDebug("Message: %s", qPrintable(message));
|
||||
app->sendMessage(message);
|
||||
}
|
||||
else { // Raise main window
|
||||
app->sendMessage("qbt://show");
|
||||
}
|
||||
app->sendParams(params.torrents);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
@ -257,32 +226,7 @@ int main(int argc, char *argv[])
|
|||
signal(SIGSEGV, sigsegvHandler);
|
||||
#endif
|
||||
|
||||
#ifndef DISABLE_GUI
|
||||
MainWindow window(0, params.torrents);
|
||||
QObject::connect(app.data(), SIGNAL(messageReceived(const QString &)),
|
||||
&window, SLOT(processParams(const QString &)));
|
||||
QObject::disconnect(app.data(), SIGNAL(messageReceived(const QString &)),
|
||||
messagesCollector, SLOT(collectMessage(const QString &)));
|
||||
window.processParams(messagesCollector->messages);
|
||||
delete messagesCollector;
|
||||
app->setActivationWindow(&window);
|
||||
#ifdef Q_OS_MAC
|
||||
app->setReadyToProcessEvents();
|
||||
#endif // Q_OS_MAC
|
||||
#else
|
||||
// Load Headless class
|
||||
HeadlessLoader loader(params.torrents);
|
||||
QObject::connect(app.data(), SIGNAL(messageReceived(const QString &)),
|
||||
&loader, SLOT(processParams(const QString &)));
|
||||
QObject::disconnect(app.data(), SIGNAL(messageReceived(const QString &)),
|
||||
messagesCollector, SLOT(collectMessage(const QString &)));
|
||||
loader.processParams(messagesCollector->messages);
|
||||
delete messagesCollector;
|
||||
#endif
|
||||
|
||||
int ret = app->exec();
|
||||
qDebug("Application has exited");
|
||||
return ret;
|
||||
return app->exec(params.torrents);
|
||||
}
|
||||
|
||||
QBtCommandLineParameters parseCommandLine()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue