From 0c50a8b98b55dceb0c918072e5d034122738e639 Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Thu, 22 Jan 2015 15:56:16 +0300 Subject: [PATCH] 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). --- src/app/app.pri | 11 --- src/app/application.cpp | 169 ++++++++++++++++++++++++++++++++- src/app/application.h | 31 +++++- src/app/headlessloader.h | 117 ----------------------- src/app/main.cpp | 64 +------------ src/app/qmacapplication.cpp | 72 -------------- src/app/qmacapplication.h | 54 ----------- src/app/sessionapplication.cpp | 50 ---------- src/app/sessionapplication.h | 60 ------------ src/gui/mainwindow.cpp | 63 +++--------- src/gui/mainwindow.h | 5 +- 11 files changed, 210 insertions(+), 486 deletions(-) delete mode 100644 src/app/headlessloader.h delete mode 100644 src/app/qmacapplication.cpp delete mode 100644 src/app/qmacapplication.h delete mode 100644 src/app/sessionapplication.cpp delete mode 100644 src/app/sessionapplication.h diff --git a/src/app/app.pri b/src/app/app.pri index 6ffe7be19..22a4d859e 100644 --- a/src/app/app.pri +++ b/src/app/app.pri @@ -14,20 +14,9 @@ usesystemqtsingleapplication { } } -!nogui { - macx { - HEADERS += $$PWD/qmacapplication.h - SOURCES += $$PWD/qmacapplication.cpp - } - HEADERS += $$PWD/sessionapplication.h - SOURCES += $$PWD/sessionapplication.cpp -} - HEADERS += $$PWD/application.h SOURCES += $$PWD/application.cpp -nogui: HEADERS += $$PWD/headlessloader.h - unix: HEADERS += $$PWD/stacktrace.h strace_win { HEADERS += $$PWD/stacktrace_win.h diff --git a/src/app/application.cpp b/src/app/application.cpp index 2d2e776c5..4052c69a9 100644 --- a/src/app/application.cpp +++ b/src/app/application.cpp @@ -1,6 +1,6 @@ /* * Bittorrent Client using Qt and libtorrent. - * Copyright (C) 2014 Vladimir Golovnev + * Copyright (C) 2015 Vladimir Golovnev * Copyright (C) 2006 Christophe Dumez * * This program is free software; you can redistribute it and/or @@ -32,10 +32,20 @@ #include #include #include +#ifndef DISABLE_GUI #ifdef Q_OS_WIN #include #include -#endif +#endif // Q_OS_WIN +#ifdef Q_OS_MAC +#include +#include +#endif // Q_OS_MAC +#include "mainwindow.h" +#include "addnewtorrentdialog.h" +#else // DISABLE_GUI +#include +#endif // DISABLE_GUI #if (!defined(DISABLE_GUI) && defined(Q_OS_MAC)) #include @@ -43,9 +53,17 @@ #include "application.h" #include "preferences.h" +#include "qbtsession.h" +#include "logger.h" + +static const char PARAMS_SEPARATOR[] = "|"; Application::Application(const QString &id, int &argc, char **argv) : BaseApplication(id, argc, argv) +#ifndef DISABLE_GUI + , m_window(0) +#endif + , m_running(false) { #if defined(Q_OS_MACX) && !defined(DISABLE_GUI) if (QSysInfo::MacintoshVersion > QSysInfo::MV_10_8) { @@ -60,8 +78,118 @@ Application::Application(const QString &id, int &argc, char **argv) setStyleSheet("QStatusBar::item { border-width: 0; }"); setQuitOnLastWindowClosed(false); #endif + + connect(this, SIGNAL(messageReceived(const QString &)), SLOT(processMessage(const QString &))); +} + +Application::~Application() +{ + qDebug() << Q_FUNC_INFO; + QBtSession::drop(); + Preferences::drop(); + Logger::drop(); +} + +void Application::processMessage(const QString &message) +{ + QStringList params = message.split(QLatin1String(PARAMS_SEPARATOR), QString::SkipEmptyParts); + // If Application is not running (i.e., other + // components are not ready) store params + if (m_running) + processParams(params); + else + m_paramsQueue.append(params); +} + +bool Application::sendParams(const QStringList ¶ms) +{ + return sendMessage(params.join(QLatin1String(PARAMS_SEPARATOR))); +} + +// As program parameters, we can get paths or urls. +// This function parse the parameters and call +// the right addTorrent function, considering +// the parameter type. +void Application::processParams(const QStringList ¶ms) +{ +#ifndef DISABLE_GUI + if (params.isEmpty()) { + m_window->activate(); // show UI + return; + } + + const bool useTorrentAdditionDialog = Preferences::instance()->useAdditionDialog(); +#endif + + foreach (QString param, params) { + param = param.trimmed(); + if (misc::isUrl(param)) { + QBtSession::instance()->downloadFromUrl(param); + } + else { + if (param.startsWith("bc://bt/", Qt::CaseInsensitive)) { + qDebug("Converting bc link to magnet link"); + param = misc::bcLinkToMagnet(param); + } + + if (param.startsWith("magnet:", Qt::CaseInsensitive)) { +#ifndef DISABLE_GUI + if (useTorrentAdditionDialog) + AddNewTorrentDialog::showMagnet(param, m_window); + else +#endif + QBtSession::instance()->addMagnetUri(param); + } + else { +#ifndef DISABLE_GUI + if (useTorrentAdditionDialog) + AddNewTorrentDialog::showTorrent(param, QString(), m_window); + else +#endif + QBtSession::instance()->addTorrent(param); + } + } + } +} + +int Application::exec(const QStringList ¶ms) +{ + // Resume unfinished torrents + QBtSession::instance()->startUpTorrents(); + +#ifdef DISABLE_GUI + Preferences* const pref = Preferences::instance(); + if (pref->isWebUiEnabled()) { + // Display some information to the user + std::cout << std::endl << "******** " << qPrintable(tr("Information")) << " ********" << std::endl; + std::cout << qPrintable(tr("To control qBittorrent, access the Web UI at http://localhost:%1").arg(QString::number(pref->getWebUiPort()))) << std::endl; + std::cout << qPrintable(tr("The Web UI administrator user name is: %1").arg(pref->getWebUiUsername())) << std::endl; + qDebug() << "Password:" << pref->getWebUiPassword(); + if (pref->getWebUiPassword() == "f6fdffe48c908deb0f4c3bd36c032e72") { + std::cout << qPrintable(tr("The Web UI administrator password is still the default one: %1").arg("adminadmin")) << std::endl; + std::cout << qPrintable(tr("This is a security risk, please consider changing your password from program preferences.")) << std::endl; + } + } +#else + m_window = new MainWindow; +#endif + + m_running = true; + m_paramsQueue = params + m_paramsQueue; + if (!m_paramsQueue.isEmpty()) { + processParams(m_paramsQueue); + m_paramsQueue.clear(); + } + + int res = BaseApplication::exec(); +#ifndef DISABLE_GUI + delete m_window; +#endif + qDebug("Application has exited"); + return res; } +#ifndef DISABLE_GUI #ifdef Q_OS_WIN bool Application::isRunning() { @@ -87,7 +215,42 @@ bool Application::isRunning() return running; } -#endif +#endif // Q_OS_WIN + +#ifdef Q_OS_MAC +bool Application::event(QEvent *ev) +{ + if (ev->type() == QEvent::FileOpen) { + QString path = static_cast(ev)->file(); + if (path.isEmpty()) + // Get the url instead + path = static_cast(ev)->url().toString(); + qDebug("Received a mac file open event: %s", qPrintable(path)); + if (running_) + processParams(QStringList(path)); + else + paramsQueue_.append(path); + return true; + } + else { + return BaseApplication::event(ev); + } +} +#endif // Q_OS_MAC + +bool Application::notify(QObject *receiver, QEvent *event) +{ + try { + return QApplication::notify(receiver, event); + } + catch (const std::exception &e) { + qCritical() << "Exception thrown:" << e.what() << ", receiver: " << receiver->objectName(); + receiver->dumpObjectInfo(); + } + + return false; +} +#endif // DISABLE_GUI void Application::initializeTranslation() { diff --git a/src/app/application.h b/src/app/application.h index 1a98dc256..783817302 100644 --- a/src/app/application.h +++ b/src/app/application.h @@ -1,6 +1,6 @@ /* * Bittorrent Client using Qt and libtorrent. - * Copyright (C) 2014 Vladimir Golovnev + * Copyright (C) 2015 Vladimir Golovnev * Copyright (C) 2006 Christophe Dumez * * This program is free software; you can redistribute it and/or @@ -34,8 +34,9 @@ #include #ifndef DISABLE_GUI -#include "sessionapplication.h" -typedef SessionApplication BaseApplication; +#include "qtsingleapplication.h" +typedef QtSingleApplication BaseApplication; +class MainWindow; #else #include "qtsinglecoreapplication.h" typedef QtSingleCoreApplication BaseApplication; @@ -43,18 +44,40 @@ typedef QtSingleCoreApplication BaseApplication; class Application : public BaseApplication { + Q_OBJECT + public: Application(const QString &id, int &argc, char **argv); + ~Application(); -#ifdef Q_OS_WIN + #if (defined(Q_OS_WIN) && !defined(DISABLE_GUI)) bool isRunning(); #endif + int exec(const QStringList ¶ms); + bool sendParams(const QStringList ¶ms); + +protected: +#ifndef DISABLE_GUI +#ifdef Q_OS_MAC + bool event(QEvent *); +#endif + bool notify(QObject* receiver, QEvent* event); +#endif + +private slots: + void processMessage(const QString &message); private: + bool m_running; +#ifndef DISABLE_GUI + MainWindow *m_window; +#endif QTranslator m_qtTranslator; QTranslator m_translator; + QStringList m_paramsQueue; void initializeTranslation(); + void processParams(const QStringList ¶ms); }; #endif // APPLICATION_H diff --git a/src/app/headlessloader.h b/src/app/headlessloader.h deleted file mode 100644 index 5bbc2c3c2..000000000 --- a/src/app/headlessloader.h +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Bittorrent Client using Qt4 and libtorrent. - * Copyright (C) 2006 Christophe Dumez, Frédéric Lassabe - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * In addition, as a special exception, the copyright holders give permission to - * link this program with the OpenSSL project's "OpenSSL" library (or with - * modified versions of it that use the same license as the "OpenSSL" library), - * and distribute the linked executables. You must obey the GNU General Public - * License in all respects for all of the code used other than "OpenSSL". If you - * modify file(s), you may extend this exception to your version of the file(s), - * but you are not obligated to do so. If you do not wish to do so, delete this - * exception statement from your version. - * - * Contact : chris@qbittorrent.org - */ - -#ifndef HEADLESSLOADER_H -#define HEADLESSLOADER_H - -#include -#include -#include -#include "preferences.h" -#include "qbtsession.h" -#include "fs_utils.h" -#include "misc.h" -#include "logger.h" -#include "torrentpersistentdata.h" - -class HeadlessLoader: public QObject { - Q_OBJECT - -public: - HeadlessLoader(const QStringList &torrentCmdLine) { - connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(shutdownCleanUp()), Qt::DirectConnection); - Preferences* const pref = Preferences::instance(); - // Enable Web UI - pref->setWebUiEnabled(true); - // Instanciate Bittorrent Object - connect(QBtSession::instance(), SIGNAL(newConsoleMessage(QString)), this, SLOT(displayConsoleMessage(QString))); - // Resume unfinished torrents - QBtSession::instance()->startUpTorrents(); - // Process command line parameters - processParams(torrentCmdLine); - // Display some information to the user - std::cout << std::endl << "******** " << qPrintable(tr("Information")) << " ********" << std::endl; - std::cout << qPrintable(tr("To control qBittorrent, access the Web UI at http://localhost:%1").arg(QString::number(pref->getWebUiPort()))) << std::endl; - std::cout << qPrintable(tr("The Web UI administrator user name is: %1").arg(pref->getWebUiUsername())) << std::endl; - qDebug() << "Password:" << pref->getWebUiPassword(); - if (pref->getWebUiPassword() == "f6fdffe48c908deb0f4c3bd36c032e72") { - std::cout << qPrintable(tr("The Web UI administrator password is still the default one: %1").arg("adminadmin")) << std::endl; - std::cout << qPrintable(tr("This is a security risk, please consider changing your password from program preferences.")) << std::endl; - } - } - -public slots: - void shutdownCleanUp() { - QBtSession::drop(); - TorrentPersistentData::drop(); - Preferences::drop(); - Logger::drop(); - } - - // Call this function to exit qBittorrent headless loader - // and return to prompt (object will be deleted by main) - void exit() { - qApp->quit(); - } - - void displayConsoleMessage(const QString &msg) { - std::cout << qPrintable(msg) << std::endl; - } - - void processParams(const QString& params_str) { - processParams(params_str.split(" ", QString::SkipEmptyParts)); - } - - // As program parameters, we can get paths or urls. - // This function parse the parameters and call - // the right addTorrent function, considering - // the parameter type. - void processParams(const QStringList& params) { - foreach (QString param, params) { - param = fsutils::fromNativePath(param).trimmed(); - if (param.startsWith(QString::fromUtf8("http://"), Qt::CaseInsensitive) || param.startsWith(QString::fromUtf8("ftp://"), Qt::CaseInsensitive) || param.startsWith(QString::fromUtf8("https://"), Qt::CaseInsensitive)) { - QBtSession::instance()->downloadFromUrl(param); - }else{ - if (param.startsWith("bc://bt/", Qt::CaseInsensitive)) { - qDebug("Converting bc link to magnet link"); - param = misc::bcLinkToMagnet(param); - } - if (param.startsWith("magnet:", Qt::CaseInsensitive)) { - QBtSession::instance()->addMagnetUri(param); - } else { - QBtSession::instance()->addTorrent(param); - } - } - } - } - -}; - -#endif diff --git a/src/app/main.cpp b/src/app/main.cpp index 518ede3ee..90a4fe739 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -39,8 +39,6 @@ #include #include #include -#include -#include #ifdef QBT_STATIC_QT #include #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 #include -#include -#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 +#include #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 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() diff --git a/src/app/qmacapplication.cpp b/src/app/qmacapplication.cpp deleted file mode 100644 index 1361db949..000000000 --- a/src/app/qmacapplication.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Bittorrent Client using Qt4 and libtorrent. - * Copyright (C) 2010 Christophe Dumez - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * In addition, as a special exception, the copyright holders give permission to - * link this program with the OpenSSL project's "OpenSSL" library (or with - * modified versions of it that use the same license as the "OpenSSL" library), - * and distribute the linked executables. You must obey the GNU General Public - * License in all respects for all of the code used other than "OpenSSL". If you - * modify file(s), you may extend this exception to your version of the file(s), - * but you are not obligated to do so. If you do not wish to do so, delete this - * exception statement from your version. - * - * Contact : chris@qbittorrent.org - */ - -#include -#include -#include -#include "qmacapplication.h" - -QMacApplication::QMacApplication(QString appid, int &argc, char** argv) : - QtSingleApplication(appid, argc, argv), - m_readyToProcessEvents(false) -{ - qDebug("Constructing a QMacApplication to receive file open events"); -} - -void QMacApplication::setReadyToProcessEvents() -{ - m_readyToProcessEvents = true; - if (!m_torrentsQueue.isEmpty()) { - emit newFileOpenMacEvent(m_torrentsQueue.join("|")); - m_torrentsQueue.clear(); - } -} - -bool QMacApplication::event(QEvent * ev) { - switch (ev->type()) { - case QEvent::FileOpen: - { - QString path = static_cast(ev)->file(); - if (path.isEmpty()) { - // Get the url instead - path = static_cast(ev)->url().toString(); - } - qDebug("Received a mac file open event: %s", qPrintable(path)); - if (m_readyToProcessEvents) - emit newFileOpenMacEvent(path); - else - m_torrentsQueue.append(path); - return true; - } - default: - return QtSingleApplication::event(ev); - } -} - diff --git a/src/app/qmacapplication.h b/src/app/qmacapplication.h deleted file mode 100644 index 8148a4e13..000000000 --- a/src/app/qmacapplication.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Bittorrent Client using Qt4 and libtorrent. - * Copyright (C) 2010 Christophe Dumez - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * In addition, as a special exception, the copyright holders give permission to - * link this program with the OpenSSL project's "OpenSSL" library (or with - * modified versions of it that use the same license as the "OpenSSL" library), - * and distribute the linked executables. You must obey the GNU General Public - * License in all respects for all of the code used other than "OpenSSL". If you - * modify file(s), you may extend this exception to your version of the file(s), - * but you are not obligated to do so. If you do not wish to do so, delete this - * exception statement from your version. - * - * Contact : chris@qbittorrent.org - */ -#ifndef QMACAPPLICATION_H -#define QMACAPPLICATION_H - -#include "qtsingleapplication.h" -#include - -class QMacApplication : public QtSingleApplication -{ - Q_OBJECT -public: - explicit QMacApplication(QString appid, int &argc, char** argv); - void setReadyToProcessEvents(); - -signals: - void newFileOpenMacEvent(const QString &path); - -protected: - bool event(QEvent *); - -private: - bool m_readyToProcessEvents; - QStringList m_torrentsQueue; -}; - -#endif // QMACAPPLICATION_H diff --git a/src/app/sessionapplication.cpp b/src/app/sessionapplication.cpp deleted file mode 100644 index fb834cece..000000000 --- a/src/app/sessionapplication.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Bittorrent Client using Qt4 and libtorrent. - * Copyright (C) 2010 Christophe Dumez - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * In addition, as a special exception, the copyright holders give permission to - * link this program with the OpenSSL project's "OpenSSL" library (or with - * modified versions of it that use the same license as the "OpenSSL" library), - * and distribute the linked executables. You must obey the GNU General Public - * License in all respects for all of the code used other than "OpenSSL". If you - * modify file(s), you may extend this exception to your version of the file(s), - * but you are not obligated to do so. If you do not wish to do so, delete this - * exception statement from your version. - * - * Contact : chris@qbittorrent.org - */ - -#include -#include "sessionapplication.h" - -SessionApplication::SessionApplication(const QString &id, int &argc, char **argv) : -#ifdef Q_OS_MAC -QMacApplication(id, argc, argv) -#else -QtSingleApplication(id, argc, argv) -#endif -{} - -bool SessionApplication::notify(QObject* receiver, QEvent* event) { - try { - return QApplication::notify(receiver, event); - } catch(const std::exception& e) { - qCritical() << "Exception thrown:" << e.what() << ", receiver: " << receiver->objectName(); - receiver->dumpObjectInfo(); - } - return false; -} diff --git a/src/app/sessionapplication.h b/src/app/sessionapplication.h deleted file mode 100644 index 3ad8d4e93..000000000 --- a/src/app/sessionapplication.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Bittorrent Client using Qt4 and libtorrent. - * Copyright (C) 2010 Christophe Dumez - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * In addition, as a special exception, the copyright holders give permission to - * link this program with the OpenSSL project's "OpenSSL" library (or with - * modified versions of it that use the same license as the "OpenSSL" library), - * and distribute the linked executables. You must obey the GNU General Public - * License in all respects for all of the code used other than "OpenSSL". If you - * modify file(s), you may extend this exception to your version of the file(s), - * but you are not obligated to do so. If you do not wish to do so, delete this - * exception statement from your version. - * - * Contact : chris@qbittorrent.org - */ - -#ifndef SESSIONAPPLICATION_H -#define SESSIONAPPLICATION_H - -#include - -#ifdef Q_OS_MAC -#include "qmacapplication.h" -#else -#include "qtsingleapplication.h" -#endif - -#include - -class SessionApplication : -#ifdef Q_OS_MAC - public QMacApplication -#else - public QtSingleApplication -#endif -{ - Q_OBJECT - -public: - SessionApplication(const QString &id, int &argc, char **argv); - -protected: - virtual bool notify(QObject* receiver, QEvent* event); -}; - -#endif // SESSIONAPPLICATION_H diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 40aa3bedd..b724968b7 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -77,11 +77,10 @@ #include "autoexpandabledialog.h" #endif #ifdef Q_OS_MAC -#include "qmacapplication.h" void qt_mac_set_dock_menu(QMenu *menu); #endif #include "lineedit.h" -#include "sessionapplication.h" +#include "application.h" #if defined(Q_OS_WIN) || defined(Q_OS_MAC) #include "programupdater.h" #endif @@ -104,7 +103,11 @@ using namespace libtorrent; *****************************************************/ // Constructor -MainWindow::MainWindow(QWidget *parent, const QStringList& torrentCmdLine): QMainWindow(parent), m_posInitialized(false), force_exit(false), unlockDlgShowing(false) +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) + , m_posInitialized(false) + , force_exit(false) + , unlockDlgShowing(false) #ifdef Q_OS_WIN , has_python(false) #endif @@ -175,9 +178,6 @@ MainWindow::MainWindow(QWidget *parent, const QStringList& torrentCmdLine): QMai connect(QBtSession::instance(), SIGNAL(downloadFromUrlFailure(QString, QString)), this, SLOT(handleDownloadFromUrlFailure(QString, QString))); connect(QBtSession::instance(), SIGNAL(alternativeSpeedsModeChanged(bool)), this, SLOT(updateAltSpeedsBtn(bool))); connect(QBtSession::instance(), SIGNAL(recursiveTorrentDownloadPossible(QTorrentHandle)), this, SLOT(askRecursiveTorrentDownloadConfirmation(QTorrentHandle))); -#ifdef Q_OS_MAC - connect(static_cast(qApp), SIGNAL(newFileOpenMacEvent(QString)), this, SLOT(processParams(QString))); -#endif qDebug("create tabWidget"); tabs = new HidableTabWidget(); @@ -316,8 +316,6 @@ MainWindow::MainWindow(QWidget *parent, const QStringList& torrentCmdLine): QMai // Resume unfinished torrents QBtSession::instance()->startUpTorrents(); - // Add torrent given on command line - processParams(torrentCmdLine); // Populate the transfer list transferList->getSourceModel()->populate(); @@ -1105,51 +1103,12 @@ void MainWindow::on_actionOpen_triggered() } } -// As program parameters, we can get paths or urls. -// This function parse the parameters and call -// the right addTorrent function, considering -// the parameter type. -void MainWindow::processParams(const QString& params_str) -{ - processParams(params_str.split("|", QString::SkipEmptyParts)); -} - -void MainWindow::processParams(const QStringList& params) +void MainWindow::activate() { - Preferences* const pref = Preferences::instance(); - const bool useTorrentAdditionDialog = pref->useAdditionDialog(); - foreach (QString param, params) { - param = param.trimmed(); - if (misc::isUrl(param)) { - QBtSession::instance()->downloadFromUrl(param); - } - else { - if(param.startsWith("qbt://show")) { - if(ui_locked) - if(!unlockUI()) - return; - show(); - activateWindow(); - raise(); - return; // Do not process more params - } - if (param.startsWith("bc://bt/", Qt::CaseInsensitive)) { - qDebug("Converting bc link to magnet link"); - param = misc::bcLinkToMagnet(param); - } - if (param.startsWith("magnet:", Qt::CaseInsensitive)) { - if (useTorrentAdditionDialog) - AddNewTorrentDialog::showMagnet(param, this); - else - QBtSession::instance()->addMagnetUri(param); - } - else { - if (useTorrentAdditionDialog) - AddNewTorrentDialog::showTorrent(param, QString(), this); - else - QBtSession::instance()->addTorrent(param); - } - } + if (!ui_locked || unlockUI()) { + show(); + activateWindow(); + raise(); } } diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index b18559ba1..d28ec7a2c 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -72,7 +72,7 @@ class MainWindow: public QMainWindow, private Ui::MainWindow public: // Construct / Destruct - MainWindow(QWidget *parent = 0, const QStringList& torrentCmdLine = QStringList()); + explicit MainWindow(QWidget *parent = 0); // Methods QWidget* getCurrentTabWidget() const; TransferListWidget* getTransferList() const { return transferList; } @@ -87,7 +87,7 @@ public slots: void updateAltSpeedsBtn(bool alternative); void updateNbTorrents(); void shutdownCleanUp(); - void processParams(const QStringList& params); + void activate(); protected slots: // GUI related slots @@ -128,7 +128,6 @@ protected slots: void on_actionOpen_triggered(); void updateGUI(); void loadPreferences(bool configure_session = true); - void processParams(const QString& params); void addTorrent(QString path); void addUnauthenticatedTracker(const QPair &tracker); void processDownloadedFiles(QString path, QString url);