Browse Source

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).
adaptive-webui-19844
Vladimir Golovnev (Glassez) 10 years ago
parent
commit
0c50a8b98b
  1. 11
      src/app/app.pri
  2. 169
      src/app/application.cpp
  3. 31
      src/app/application.h
  4. 117
      src/app/headlessloader.h
  5. 64
      src/app/main.cpp
  6. 72
      src/app/qmacapplication.cpp
  7. 54
      src/app/qmacapplication.h
  8. 50
      src/app/sessionapplication.cpp
  9. 60
      src/app/sessionapplication.h
  10. 57
      src/gui/mainwindow.cpp
  11. 5
      src/gui/mainwindow.h

11
src/app/app.pri

@ -14,20 +14,9 @@ usesystemqtsingleapplication { @@ -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

169
src/app/application.cpp

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2014 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2015 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2006 Christophe Dumez
*
* This program is free software; you can redistribute it and/or
@ -32,10 +32,20 @@ @@ -32,10 +32,20 @@
#include <QLocale>
#include <QLibraryInfo>
#include <QSysInfo>
#ifndef DISABLE_GUI
#ifdef Q_OS_WIN
#include <Windows.h>
#include <QSharedMemory>
#endif
#endif // Q_OS_WIN
#ifdef Q_OS_MAC
#include <QFileOpenEvent>
#include <QUrl>
#endif // Q_OS_MAC
#include "mainwindow.h"
#include "addnewtorrentdialog.h"
#else // DISABLE_GUI
#include <iostream>
#endif // DISABLE_GUI
#if (!defined(DISABLE_GUI) && defined(Q_OS_MAC))
#include <QFont>
@ -43,9 +53,17 @@ @@ -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) @@ -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 &params)
{
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 &params)
{
#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 &params)
{
// 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() @@ -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<QFileOpenEvent *>(ev)->file();
if (path.isEmpty())
// Get the url instead
path = static_cast<QFileOpenEvent *>(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()
{

31
src/app/application.h

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2014 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2015 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2006 Christophe Dumez
*
* This program is free software; you can redistribute it and/or
@ -34,8 +34,9 @@ @@ -34,8 +34,9 @@
#include <QTranslator>
#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; @@ -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 &params);
bool sendParams(const QStringList &params);
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 &params);
};
#endif // APPLICATION_H

117
src/app/headlessloader.h

@ -1,117 +0,0 @@ @@ -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 <QObject>
#include <QCoreApplication>
#include <QDebug>
#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

64
src/app/main.cpp

@ -39,8 +39,6 @@ @@ -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) @@ -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) @@ -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[]) @@ -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[]) @@ -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[]) @@ -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()

72
src/app/qmacapplication.cpp

@ -1,72 +0,0 @@ @@ -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 <QEvent>
#include <QFileOpenEvent>
#include <QUrl>
#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<QFileOpenEvent *>(ev)->file();
if (path.isEmpty()) {
// Get the url instead
path = static_cast<QFileOpenEvent *>(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);
}
}

54
src/app/qmacapplication.h

@ -1,54 +0,0 @@ @@ -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 <QStringList>
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

50
src/app/sessionapplication.cpp

@ -1,50 +0,0 @@ @@ -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 <QDebug>
#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;
}

60
src/app/sessionapplication.h

@ -1,60 +0,0 @@ @@ -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 <QtCore/QtGlobal>
#ifdef Q_OS_MAC
#include "qmacapplication.h"
#else
#include "qtsingleapplication.h"
#endif
#include <QSessionManager>
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

57
src/gui/mainwindow.cpp

@ -77,11 +77,10 @@ @@ -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; @@ -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 @@ -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<QMacApplication*>(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 @@ -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() @@ -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;
if (!ui_locked || unlockUI()) {
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);
}
}
}
}

5
src/gui/mainwindow.h

@ -72,7 +72,7 @@ class MainWindow: public QMainWindow, private Ui::MainWindow @@ -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: @@ -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: @@ -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<QTorrentHandle,QString> &tracker);
void processDownloadedFiles(QString path, QString url);

Loading…
Cancel
Save