Better Mac integration

This commit is contained in:
Christophe Dumez
2010-06-08 15:23:11 +00:00
parent 56e45a11a8
commit 323fd791c5
3 changed files with 81 additions and 54 deletions

View File

@@ -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();

View File

@@ -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;
} }

View File

@@ -270,8 +270,10 @@ HEADERS += misc.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
} else {
HEADERS += GUI.h \
feedList.h \ feedList.h \
supportedengines.h \ supportedengines.h \
transferlistwidget.h \ transferlistwidget.h \
@@ -311,6 +313,10 @@ else:HEADERS += GUI.h \
trackerlogin.h \ trackerlogin.h \
pieceavailabilitybar.h \ pieceavailabilitybar.h \
advancedsettings.h advancedsettings.h
macx {
HEADERS += qmacapplication.h
}
}
!contains(DEFINES, DISABLE_GUI):FORMS += ui/mainwindow.ui \ !contains(DEFINES, DISABLE_GUI):FORMS += ui/mainwindow.ui \
ui/options.ui \ ui/options.ui \
@@ -344,7 +350,8 @@ SOURCES += main.cpp \
scannedfoldersmodel.cpp \ scannedfoldersmodel.cpp \
misc.cpp misc.cpp
!contains(DEFINES, DISABLE_GUI):SOURCES += GUI.cpp \ !contains(DEFINES, DISABLE_GUI) {
SOURCES += GUI.cpp \
options_imp.cpp \ options_imp.cpp \
createtorrent_imp.cpp \ createtorrent_imp.cpp \
searchengine.cpp \ searchengine.cpp \
@@ -357,5 +364,8 @@ SOURCES += main.cpp \
propertieswidget.cpp \ propertieswidget.cpp \
peerlistwidget.cpp \ peerlistwidget.cpp \
trackerlist.cpp trackerlist.cpp
macx {
HEADERS += qmacapplication.cpp
}
}
DESTDIR = . DESTDIR = .