1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-09 23:57:34 +02:00

* Fixed TomahawkApp CTOR for secondary instances.

This commit is contained in:
Christian Muehlhaeuser
2011-04-07 04:47:31 +02:00
parent f6d4e0c63a
commit 87c554c6f0
3 changed files with 66 additions and 55 deletions

View File

@@ -78,6 +78,7 @@ public:
TomahawkApp( int& argc, char *argv[] ); TomahawkApp( int& argc, char *argv[] );
virtual ~TomahawkApp(); virtual ~TomahawkApp();
void init();
static TomahawkApp* instance(); static TomahawkApp* instance();
SipHandler* sipHandler() { return m_sipHandler; } SipHandler* sipHandler() { return m_sipHandler; }

View File

@@ -18,15 +18,15 @@
#include "tomahawk/tomahawkapp.h" #include "tomahawk/tomahawkapp.h"
#include "kdsingleapplicationguard/kdsingleapplicationguard.h"
#ifdef Q_WS_MAC #ifdef Q_WS_MAC
#include "tomahawkapp_mac.h" #include "tomahawkapp_mac.h"
#include </System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/AE.framework/Versions/A/Headers/AppleEvents.h> #include </System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/AE.framework/Versions/A/Headers/AppleEvents.h>
static pascal OSErr appleEventHandler( const AppleEvent*, AppleEvent*, long ); static pascal OSErr appleEventHandler( const AppleEvent*, AppleEvent*, long );
#endif #endif
#include <exception>
#include "kdsingleapplicationguard/kdsingleapplicationguard.h"
int int
main( int argc, char *argv[] ) main( int argc, char *argv[] )
{ {
@@ -42,11 +42,15 @@ main( int argc, char *argv[] )
TomahawkApp a( argc, argv ); TomahawkApp a( argc, argv );
KDSingleApplicationGuard guard( &a, KDSingleApplicationGuard::AutoKillOtherInstances ); KDSingleApplicationGuard guard( &a, KDSingleApplicationGuard::AutoKillOtherInstances );
QObject::connect( &guard, SIGNAL( instanceStarted( KDSingleApplicationGuard::Instance ) ), &a, SLOT( instanceStarted( KDSingleApplicationGuard::Instance ) ) ); QObject::connect( &guard, SIGNAL( instanceStarted( KDSingleApplicationGuard::Instance ) ), &a, SLOT( instanceStarted( KDSingleApplicationGuard::Instance ) ) );
if ( guard.isPrimaryInstance() )
a.init();
return a.exec(); return a.exec();
} }
#ifdef Q_WS_MAC #ifdef Q_WS_MAC
static pascal OSErr static pascal OSErr
appleEventHandler( const AppleEvent* e, AppleEvent*, long ) appleEventHandler( const AppleEvent* e, AppleEvent*, long )

View File

@@ -152,23 +152,45 @@ TomahawkApp::TomahawkApp( int& argc, char *argv[] )
, m_mainwindow( 0 ) , m_mainwindow( 0 )
, m_infoSystem( 0 ) , m_infoSystem( 0 )
{ {
qsrand( QTime( 0, 0, 0 ).secsTo( QTime::currentTime() ) );
#ifdef TOMAHAWK_HEADLESS
m_headless = true;
#else
m_mainwindow = 0;
m_headless = arguments().contains( "--headless" );
setWindowIcon( QIcon( RESPATH "icons/tomahawk-icon-128x128.png" ) );
#endif
qDebug() << "TomahawkApp thread:" << this->thread(); qDebug() << "TomahawkApp thread:" << this->thread();
setOrganizationName( QLatin1String( ORGANIZATION_NAME ) ); setOrganizationName( QLatin1String( ORGANIZATION_NAME ) );
setOrganizationDomain( QLatin1String( ORGANIZATION_DOMAIN ) ); setOrganizationDomain( QLatin1String( ORGANIZATION_DOMAIN ) );
setApplicationName( QLatin1String( APPLICATION_NAME ) ); setApplicationName( QLatin1String( APPLICATION_NAME ) );
setApplicationVersion( QLatin1String( VERSION ) ); setApplicationVersion( QLatin1String( VERSION ) );
registerMetaTypes();
setupLogfile(); setupLogfile();
}
TomahawkApp::~TomahawkApp()
{
qDebug() << Q_FUNC_INFO;
delete m_sipHandler;
delete m_servent;
#ifndef TOMAHAWK_HEADLESS
delete m_mainwindow;
delete m_audioEngine;
#endif
delete m_database;
}
void
TomahawkApp::init()
{
qsrand( QTime( 0, 0, 0 ).secsTo( QTime::currentTime() ) );
#ifdef TOMAHAWK_HEADLESS
m_headless = true;
#else
m_mainwindow = 0;
m_headless = arguments().contains( "--headless" );
setWindowIcon( QIcon( RESPATH "icons/tomahawk-icon-128x128.png" ) );
#endif
registerMetaTypes();
Echonest::Config::instance()->setAPIKey( "JRIHWEP6GPOER2QQ6" ); Echonest::Config::instance()->setAPIKey( "JRIHWEP6GPOER2QQ6" );
@@ -188,12 +210,12 @@ TomahawkApp::TomahawkApp( int& argc, char *argv[] )
m_scrubFriendlyName = arguments().contains( "--demo" ); m_scrubFriendlyName = arguments().contains( "--demo" );
// Register shortcut handler for this platform // Register shortcut handler for this platform
#ifdef Q_WS_MAC #ifdef Q_WS_MAC
m_shortcutHandler = new MacShortcutHandler( this ); m_shortcutHandler = new MacShortcutHandler( this );
Tomahawk::setShortcutHandler( static_cast<MacShortcutHandler*>( m_shortcutHandler) ); Tomahawk::setShortcutHandler( static_cast<MacShortcutHandler*>( m_shortcutHandler) );
Tomahawk::setApplicationHandler( this ); Tomahawk::setApplicationHandler( this );
#endif #endif
// Connect up shortcuts // Connect up shortcuts
if ( m_shortcutHandler ) if ( m_shortcutHandler )
@@ -208,7 +230,7 @@ TomahawkApp::TomahawkApp( int& argc, char *argv[] )
connect( m_shortcutHandler, SIGNAL( mute() ), m_audioEngine, SLOT( mute() ) ); connect( m_shortcutHandler, SIGNAL( mute() ), m_audioEngine, SLOT( mute() ) );
} }
#ifdef LIBLASTFM_FOUND #ifdef LIBLASTFM_FOUND
qDebug() << "Init Scrobbler."; qDebug() << "Init Scrobbler.";
m_scrobbler = new Scrobbler( this ); m_scrobbler = new Scrobbler( this );
qDebug() << "Setting NAM."; qDebug() << "Setting NAM.";
@@ -225,10 +247,10 @@ TomahawkApp::TomahawkApp( int& argc, char *argv[] )
connect( m_audioEngine, SIGNAL( stopped() ), connect( m_audioEngine, SIGNAL( stopped() ),
m_scrobbler, SLOT( trackStopped() ), Qt::QueuedConnection ); m_scrobbler, SLOT( trackStopped() ), Qt::QueuedConnection );
#else #else
qDebug() << "Setting NAM."; qDebug() << "Setting NAM.";
TomahawkUtils::setNam( new QNetworkAccessManager ); TomahawkUtils::setNam( new QNetworkAccessManager );
#endif #endif
// Set up proxy // Set up proxy
if( TomahawkSettings::instance()->proxyType() != QNetworkProxy::NoProxy && if( TomahawkSettings::instance()->proxyType() != QNetworkProxy::NoProxy &&
@@ -258,7 +280,7 @@ TomahawkApp::TomahawkApp( int& argc, char *argv[] )
m_mainwindow->setWindowTitle( "Tomahawk" ); m_mainwindow->setWindowTitle( "Tomahawk" );
m_mainwindow->show(); m_mainwindow->show();
} }
#endif #endif
qDebug() << "Init Local Collection."; qDebug() << "Init Local Collection.";
initLocalCollection(); initLocalCollection();
@@ -273,28 +295,12 @@ TomahawkApp::TomahawkApp( int& argc, char *argv[] )
startHTTP(); startHTTP();
} }
#ifndef TOMAHAWK_HEADLESS #ifndef TOMAHAWK_HEADLESS
if ( !TomahawkSettings::instance()->hasScannerPath() ) if ( !TomahawkSettings::instance()->hasScannerPath() )
{ {
m_mainwindow->showSettingsDialog(); m_mainwindow->showSettingsDialog();
} }
#endif #endif
}
TomahawkApp::~TomahawkApp()
{
qDebug() << Q_FUNC_INFO;
delete m_sipHandler;
delete m_servent;
#ifndef TOMAHAWK_HEADLESS
delete m_mainwindow;
delete m_audioEngine;
#endif
delete m_database;
} }