Browse Source

Better Mac integration

adaptive-webui-19844
Christophe Dumez 15 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 @@ @@ -65,6 +65,9 @@
#include "transferlistfilterswidget.h"
#include "propertieswidget.h"
#include "statusbar.h"
#ifdef Q_WS_MAC
#include "qmacapplication.h"
#endif
#ifdef Q_WS_WIN
#include <windows.h>
@ -129,6 +132,9 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis @@ -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(alternativeSpeedsModeChanged(bool)), this, SLOT(updateAltSpeedsBtn(bool)));
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");
tabs = new QTabWidget();
@ -149,7 +155,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis @@ -149,7 +155,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
vSplitter->setCollapsible(0, true);
vSplitter->setCollapsible(1, false);
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);
// Transfer list slots

111
src/main.cpp

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

56
src/qmacapplication.cpp

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