Browse Source

Better Mac integration

adaptive-webui-19844
Christophe Dumez 14 years ago
parent
commit
0d4b55ca32
  1. 8
      src/GUI.cpp
  2. 111
      src/main.cpp
  3. 56
      src/qmacapplication.cpp
  4. 55
      src/qmacapplication.h
  5. 289
      src/src.pro

8
src/GUI.cpp

@ -65,6 +65,9 @@
#include "transferlistfilterswidget.h" #include "transferlistfilterswidget.h"
#include "propertieswidget.h" #include "propertieswidget.h"
#include "statusbar.h" #include "statusbar.h"
#ifdef Q_WS_MAC
#include "qmacapplication.h"
#endif
#ifdef Q_WS_WIN #ifdef Q_WS_WIN
#include <windows.h> #include <windows.h>
@ -129,6 +132,9 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
connect(BTSession, SIGNAL(downloadFromUrlFailure(QString, QString)), this, SLOT(handleDownloadFromUrlFailure(QString, QString))); connect(BTSession, SIGNAL(downloadFromUrlFailure(QString, QString)), this, SLOT(handleDownloadFromUrlFailure(QString, QString)));
connect(BTSession, SIGNAL(alternativeSpeedsModeChanged(bool)), this, SLOT(updateAltSpeedsBtn(bool))); connect(BTSession, SIGNAL(alternativeSpeedsModeChanged(bool)), this, SLOT(updateAltSpeedsBtn(bool)));
connect(BTSession, SIGNAL(recursiveTorrentDownloadPossible(QTorrentHandle&)), this, SLOT(askRecursiveTorrentDownloadConfirmation(QTorrentHandle&))); connect(BTSession, SIGNAL(recursiveTorrentDownloadPossible(QTorrentHandle&)), this, SLOT(askRecursiveTorrentDownloadConfirmation(QTorrentHandle&)));
#ifdef Q_WS_MAC
connect(static_cast<QMacApplication*>(qApp), SIGNAL(newFileOpenMacEvent(QStringList)), this, SLOT(processParams(QStringList)));
#endif
qDebug("create tabWidget"); qDebug("create tabWidget");
tabs = new QTabWidget(); tabs = new QTabWidget();
@ -149,7 +155,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
vSplitter->setCollapsible(0, true); vSplitter->setCollapsible(0, true);
vSplitter->setCollapsible(1, false); vSplitter->setCollapsible(1, false);
tabs->addTab(vSplitter, QIcon(QString::fromUtf8(":/Icons/oxygen/folder-remote.png")), tr("Transfers")); tabs->addTab(vSplitter, QIcon(QString::fromUtf8(":/Icons/oxygen/folder-remote.png")), tr("Transfers"));
connect(transferList, SIGNAL(torrentStatusUpdate(uint,uint,uint,uint,uint)), this, SLOT(updateNbTorrents(uint,uint,uint,uint,uint))); connect(transferList, SIGNAL(torrentStatusUpdate(uint,uint,uint,uint,uint)), this, SLOT(updateNbTorrents(uint,uint,uint,uint,uint)));
vboxLayout->addWidget(tabs); vboxLayout->addWidget(tabs);
// Transfer list slots // Transfer list slots

111
src/main.cpp

@ -39,6 +39,9 @@
#include <QStyle> #include <QStyle>
#include <QSplashScreen> #include <QSplashScreen>
#include <QPushButton> #include <QPushButton>
#ifdef Q_WS_MAC
#include "qmacapplication.h"
#endif
#include "GUI.h" #include "GUI.h"
#include "ico.h" #include "ico.h"
#else #else
@ -70,7 +73,11 @@ const int UNLEN = 256;
#ifdef DISABLE_GUI #ifdef DISABLE_GUI
QCoreApplication *app; QCoreApplication *app;
#else #else
#ifndef Q_WS_MAC
QApplication *app; QApplication *app;
#else
QMacApplication *app;
#endif
#endif #endif
class UsageDisplay: public QObject { class UsageDisplay: public QObject {
@ -170,11 +177,15 @@ void useStyle(QApplication *app, QString style){
// Main // Main
int main(int argc, char *argv[]){ int main(int argc, char *argv[]){
// Create Application // Create Application
#ifdef DISABLE_GUI #ifdef DISABLE_GUI
app = new QCoreApplication(argc, argv); app = new QCoreApplication(argc, argv);
#else #else
app = new QApplication(argc, argv); #ifndef Q_WS_MAC
#endif app = new QApplication(argc, argv);
#else
app = new QMacApplication(argc, argv);
#endif
#endif
QString locale; QString locale;
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
@ -191,7 +202,7 @@ int main(int argc, char *argv[]){
if (!GetUserNameA(buffer, &buffer_len)) if (!GetUserNameA(buffer, &buffer_len))
uid = QString(buffer); uid = QString(buffer);
#else #else
uid = QString::number(getuid()); uid = QString::number(getuid());
#endif #endif
localSocket.connectToServer("qBittorrent-"+uid, QIODevice::WriteOnly); localSocket.connectToServer("qBittorrent-"+uid, QIODevice::WriteOnly);
if (localSocket.waitForConnected(1000)){ if (localSocket.waitForConnected(1000)){
@ -287,72 +298,72 @@ int main(int argc, char *argv[]){
#if defined(Q_WS_WIN) && !defined(MINGW) #if defined(Q_WS_WIN) && !defined(MINGW)
if(SetEnvironmentVariableA("QBITTORRENT", VERSION)) { if(SetEnvironmentVariableA("QBITTORRENT", VERSION)) {
#else #else
if(putenv((char*)"QBITTORRENT="VERSION)) { if(putenv((char*)"QBITTORRENT="VERSION)) {
#endif #endif
std::cerr << "Couldn't set environment variable...\n"; std::cerr << "Couldn't set environment variable...\n";
} }
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
useStyle(app, settings.value("Preferences/General/Style", "").toString()); useStyle(app, settings.value("Preferences/General/Style", "").toString());
app->setStyleSheet("QStatusBar::item { border-width: 0; }"); app->setStyleSheet("QStatusBar::item { border-width: 0; }");
QSplashScreen *splash = 0; QSplashScreen *splash = 0;
if(!no_splash) { if(!no_splash) {
splash = new QSplashScreen(QPixmap(QString::fromUtf8(":/Icons/skin/splash.png"))); splash = new QSplashScreen(QPixmap(QString::fromUtf8(":/Icons/skin/splash.png")));
splash->show(); splash->show();
} }
#endif #endif
if(!LegalNotice::userAgreesWithNotice()) { if(!LegalNotice::userAgreesWithNotice()) {
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
delete splash; delete splash;
#endif #endif
delete app; delete app;
return 0; return 0;
} }
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
app->setQuitOnLastWindowClosed(false); app->setQuitOnLastWindowClosed(false);
#endif #endif
#if defined(Q_WS_X11) || defined(Q_WS_MAC) #if defined(Q_WS_X11) || defined(Q_WS_MAC)
signal(SIGABRT, sigabrtHandler); signal(SIGABRT, sigabrtHandler);
signal(SIGTERM, sigtermHandler); signal(SIGTERM, sigtermHandler);
signal(SIGINT, sigintHandler); signal(SIGINT, sigintHandler);
signal(SIGSEGV, sigsegvHandler); signal(SIGSEGV, sigsegvHandler);
#endif #endif
// Read torrents given on command line // Read torrents given on command line
QStringList torrentCmdLine = app->arguments(); QStringList torrentCmdLine = app->arguments();
// Remove first argument (program name) // Remove first argument (program name)
torrentCmdLine.removeFirst(); torrentCmdLine.removeFirst();
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
GUI *window = new GUI(0, torrentCmdLine); GUI *window = new GUI(0, torrentCmdLine);
if(!no_splash) { if(!no_splash) {
splash->finish(window); splash->finish(window);
delete splash; delete splash;
} }
#else #else
// Load Headless class // Load Headless class
HeadlessLoader *loader = new HeadlessLoader(torrentCmdLine); HeadlessLoader *loader = new HeadlessLoader(torrentCmdLine);
#endif #endif
int ret = app->exec(); int ret = app->exec();
#if defined(Q_WS_X11) || defined(Q_WS_MAC) #if defined(Q_WS_X11) || defined(Q_WS_MAC)
// Application has exited, stop catching SIGINT and SIGTERM // Application has exited, stop catching SIGINT and SIGTERM
signal(SIGINT, 0); signal(SIGINT, 0);
signal(SIGTERM, 0); signal(SIGTERM, 0);
#endif #endif
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
delete window; delete window;
qDebug("GUI was deleted!"); qDebug("GUI was deleted!");
#else #else
delete loader; delete loader;
#endif #endif
qDebug("Deleting app..."); qDebug("Deleting app...");
#ifndef Q_WS_WIN #ifndef Q_WS_WIN
// XXX: Why does it crash on Windows!? // XXX: Why does it crash on Windows!?
delete app; delete app;
#endif #endif
qDebug("App was deleted! All good."); qDebug("App was deleted! All good.");
return ret; return ret;
} }

56
src/qmacapplication.cpp

@ -0,0 +1,56 @@
/*
* 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
*/
#ifdef Q_WS_MAC
#include <QFileOpenEvent>
#include "qmacapplication.h"
QMacApplication::QMacApplication(int &argc, char** argv) :
QApplication(argc, argv)
{
}
bool QMacApplication::event(QEvent * event) {
switch (event->type()) {
case QEvent::FileOpen:
{
QStringList paths;
paths << static_cast<QFileOpenEvent *>(event)->file();
emit newFileOpenMacEvent(paths);
return true;
}
default:
return QApplication::event(event);
}
}
#endif

55
src/qmacapplication.h

@ -0,0 +1,55 @@
/*
* 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
#ifdef Q_WS_MAC
#include <QApplication>
#include <QStringList>
class QMacApplication : public QApplication
{
Q_OBJECT
public:
explicit QMacApplication(int &argc, char** argv);
signals:
void newFileOpenMacEvent(QStringList paths);
protected:
bool event(QEvent *);
};
#endif
#endif // QMACAPPLICATION_H

289
src/src.pro

@ -200,9 +200,9 @@ os2:LIBS += -ltorrent-rasterbar \
# Resource files # Resource files
RESOURCES = icons.qrc \ RESOURCES = icons.qrc \
lang.qrc \ lang.qrc \
search.qrc \ search.qrc \
webui.qrc webui.qrc
# Add GeoIP resource file if the GeoIP database # Add GeoIP resource file if the GeoIP database
# should be embedded in qBittorrent executable # should be embedded in qBittorrent executable
@ -221,145 +221,158 @@ else:message("GeoIP database will not be embedded in qBittorrent executable.")
# Translations # Translations
TRANSLATIONS = $$LANG_PATH/qbittorrent_fr.ts \ TRANSLATIONS = $$LANG_PATH/qbittorrent_fr.ts \
$$LANG_PATH/qbittorrent_zh.ts \ $$LANG_PATH/qbittorrent_zh.ts \
$$LANG_PATH/qbittorrent_zh_TW.ts \ $$LANG_PATH/qbittorrent_zh_TW.ts \
$$LANG_PATH/qbittorrent_en.ts \ $$LANG_PATH/qbittorrent_en.ts \
$$LANG_PATH/qbittorrent_ca.ts \ $$LANG_PATH/qbittorrent_ca.ts \
$$LANG_PATH/qbittorrent_es.ts \ $$LANG_PATH/qbittorrent_es.ts \
$$LANG_PATH/qbittorrent_pl.ts \ $$LANG_PATH/qbittorrent_pl.ts \
$$LANG_PATH/qbittorrent_ko.ts \ $$LANG_PATH/qbittorrent_ko.ts \
$$LANG_PATH/qbittorrent_de.ts \ $$LANG_PATH/qbittorrent_de.ts \
$$LANG_PATH/qbittorrent_nl.ts \ $$LANG_PATH/qbittorrent_nl.ts \
$$LANG_PATH/qbittorrent_tr.ts \ $$LANG_PATH/qbittorrent_tr.ts \
$$LANG_PATH/qbittorrent_sv.ts \ $$LANG_PATH/qbittorrent_sv.ts \
$$LANG_PATH/qbittorrent_el.ts \ $$LANG_PATH/qbittorrent_el.ts \
$$LANG_PATH/qbittorrent_ru.ts \ $$LANG_PATH/qbittorrent_ru.ts \
$$LANG_PATH/qbittorrent_uk.ts \ $$LANG_PATH/qbittorrent_uk.ts \
$$LANG_PATH/qbittorrent_bg.ts \ $$LANG_PATH/qbittorrent_bg.ts \
$$LANG_PATH/qbittorrent_it.ts \ $$LANG_PATH/qbittorrent_it.ts \
$$LANG_PATH/qbittorrent_sk.ts \ $$LANG_PATH/qbittorrent_sk.ts \
$$LANG_PATH/qbittorrent_ro.ts \ $$LANG_PATH/qbittorrent_ro.ts \
$$LANG_PATH/qbittorrent_pt.ts \ $$LANG_PATH/qbittorrent_pt.ts \
$$LANG_PATH/qbittorrent_nb.ts \ $$LANG_PATH/qbittorrent_nb.ts \
$$LANG_PATH/qbittorrent_fi.ts \ $$LANG_PATH/qbittorrent_fi.ts \
$$LANG_PATH/qbittorrent_da.ts \ $$LANG_PATH/qbittorrent_da.ts \
$$LANG_PATH/qbittorrent_ja.ts \ $$LANG_PATH/qbittorrent_ja.ts \
$$LANG_PATH/qbittorrent_hu.ts \ $$LANG_PATH/qbittorrent_hu.ts \
$$LANG_PATH/qbittorrent_pt_BR.ts \ $$LANG_PATH/qbittorrent_pt_BR.ts \
$$LANG_PATH/qbittorrent_cs.ts \ $$LANG_PATH/qbittorrent_cs.ts \
$$LANG_PATH/qbittorrent_sr.ts \ $$LANG_PATH/qbittorrent_sr.ts \
$$LANG_PATH/qbittorrent_ar.ts \ $$LANG_PATH/qbittorrent_ar.ts \
$$LANG_PATH/qbittorrent_hr.ts $$LANG_PATH/qbittorrent_hr.ts
# Source code # Source code
HEADERS += misc.h \ HEADERS += misc.h \
downloadthread.h \ downloadthread.h \
bittorrent.h \ bittorrent.h \
qtorrenthandle.h \ qtorrenthandle.h \
httpserver.h \ httpserver.h \
httpconnection.h \ httpconnection.h \
httprequestparser.h \ httprequestparser.h \
httpresponsegenerator.h \ httpresponsegenerator.h \
json.h \ json.h \
eventmanager.h \ eventmanager.h \
filterparserthread.h \ filterparserthread.h \
stacktrace.h \ stacktrace.h \
torrentpersistentdata.h \ torrentpersistentdata.h \
filesystemwatcher.h \ filesystemwatcher.h \
preferences.h \ preferences.h \
bandwidthscheduler.h \ bandwidthscheduler.h \
scannedfoldersmodel.h scannedfoldersmodel.h
contains(DEFINES, DISABLE_GUI):HEADERS += headlessloader.h contains(DEFINES, DISABLE_GUI) {
else:HEADERS += GUI.h \ HEADERS += headlessloader.h
feedList.h \ } else {
supportedengines.h \ HEADERS += GUI.h \
transferlistwidget.h \ feedList.h \
transferlistdelegate.h \ supportedengines.h \
transferlistfilterswidget.h \ transferlistwidget.h \
propertieswidget.h \ transferlistdelegate.h \
torrentfilesmodel.h \ transferlistfilterswidget.h \
geoip.h \ propertieswidget.h \
peeraddition.h \ torrentfilesmodel.h \
deletionconfirmationdlg.h \ geoip.h \
statusbar.h \ peeraddition.h \
trackerlist.h \ deletionconfirmationdlg.h \
downloadedpiecesbar.h \ statusbar.h \
peerlistwidget.h \ trackerlist.h \
peerlistdelegate.h \ downloadedpiecesbar.h \
reverseresolution.h \ peerlistwidget.h \
feeddownloader.h \ peerlistdelegate.h \
trackersadditiondlg.h \ reverseresolution.h \
searchtab.h \ feeddownloader.h \
console_imp.h \ trackersadditiondlg.h \
ico.h \ searchtab.h \
engineselectdlg.h \ console_imp.h \
pluginsource.h \ ico.h \
searchEngine.h \ engineselectdlg.h \
rss.h \ pluginsource.h \
rss_imp.h \ searchEngine.h \
speedlimitdlg.h \ rss.h \
options_imp.h \ rss_imp.h \
about_imp.h \ speedlimitdlg.h \
createtorrent_imp.h \ options_imp.h \
searchlistdelegate.h \ about_imp.h \
proplistdelegate.h \ createtorrent_imp.h \
previewselect.h \ searchlistdelegate.h \
previewlistdelegate.h \ proplistdelegate.h \
downloadfromurldlg.h \ previewselect.h \
torrentadditiondlg.h \ previewlistdelegate.h \
trackerlogin.h \ downloadfromurldlg.h \
pieceavailabilitybar.h \ torrentadditiondlg.h \
advancedsettings.h \ trackerlogin.h \
cookiesdlg.h pieceavailabilitybar.h \
advancedsettings.h \
!contains(DEFINES, DISABLE_GUI):FORMS += ui/mainwindow.ui \ cookiesdlg.h
ui/options.ui \ macx {
ui/about.ui \ HEADERS += qmacapplication.h
ui/createtorrent.ui \ }
ui/preview.ui \ }
ui/login.ui \
ui/downloadfromurldlg.ui \ !contains(DEFINES, DISABLE_GUI) {
ui/torrentadditiondlg.ui \ FORMS += ui/mainwindow.ui \
ui/search.ui \ ui/options.ui \
ui/rss.ui \ ui/about.ui \
ui/bandwidth_limit.ui \ ui/createtorrent.ui \
ui/engineselect.ui \ ui/preview.ui \
ui/pluginsource.ui \ ui/login.ui \
ui/trackersadditiondlg.ui \ ui/downloadfromurldlg.ui \
ui/console.ui \ ui/torrentadditiondlg.ui \
ui/feeddownloader.ui \ ui/search.ui \
ui/propertieswidget.ui \ ui/rss.ui \
ui/peer.ui \ ui/bandwidth_limit.ui \
ui/confirmdeletiondlg.ui \ ui/engineselect.ui \
ui/cookiesdlg.ui ui/pluginsource.ui \
ui/trackersadditiondlg.ui \
ui/console.ui \
ui/feeddownloader.ui \
ui/propertieswidget.ui \
ui/peer.ui \
ui/confirmdeletiondlg.ui \
ui/cookiesdlg.ui
}
SOURCES += main.cpp \ SOURCES += main.cpp \
bittorrent.cpp \ bittorrent.cpp \
qtorrenthandle.cpp \ qtorrenthandle.cpp \
downloadthread.cpp \ downloadthread.cpp \
httpserver.cpp \ httpserver.cpp \
httpconnection.cpp \ httpconnection.cpp \
httprequestparser.cpp \ httprequestparser.cpp \
httpresponsegenerator.cpp \ httpresponsegenerator.cpp \
eventmanager.cpp \ eventmanager.cpp \
scannedfoldersmodel.cpp \ scannedfoldersmodel.cpp \
misc.cpp misc.cpp
!contains(DEFINES, DISABLE_GUI):SOURCES += GUI.cpp \
options_imp.cpp \
createtorrent_imp.cpp \
searchengine.cpp \
rss_imp.cpp \
engineselectdlg.cpp \
searchtab.cpp \
ico.cpp \
rss.cpp \
transferlistwidget.cpp \
propertieswidget.cpp \
peerlistwidget.cpp \
cookiesdlg.cpp \
trackerlist.cpp
DESTDIR = . !contains(DEFINES, DISABLE_GUI) {
SOURCES += GUI.cpp \
options_imp.cpp \
createtorrent_imp.cpp \
searchengine.cpp \
rss_imp.cpp \
engineselectdlg.cpp \
searchtab.cpp \
ico.cpp \
rss.cpp \
transferlistwidget.cpp \
propertieswidget.cpp \
peerlistwidget.cpp \
cookiesdlg.cpp \
trackerlist.cpp
macx {
HEADERS += qmacapplication.cpp
}
}
DESTDIR = .

Loading…
Cancel
Save