mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 11:20:22 +02:00
Update to newer kdsingleappguard
This commit is contained in:
@@ -680,28 +680,29 @@ TomahawkApp::loadUrl( const QString& url )
|
||||
void
|
||||
TomahawkApp::instanceStarted( KDSingleApplicationGuard::Instance instance )
|
||||
{
|
||||
tDebug( LOGINFO ) << "Instance started!" << instance.pid << instance.arguments;
|
||||
tDebug( LOGINFO ) << "Instance started!" << instance.pid() << instance.arguments();
|
||||
const QStringList arguments = instance.arguments();
|
||||
|
||||
if ( instance.arguments.size() < 2 )
|
||||
if ( arguments.size() < 2 )
|
||||
return;
|
||||
|
||||
QString arg1 = instance.arguments[ 1 ];
|
||||
QString arg1 = arguments[ 1 ];
|
||||
if ( loadUrl( arg1 ) )
|
||||
{
|
||||
activate();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( instance.arguments.contains( "--next" ) )
|
||||
if ( arguments.contains( "--next" ) )
|
||||
AudioEngine::instance()->next();
|
||||
else if ( instance.arguments.contains( "--prev" ) )
|
||||
else if ( arguments.contains( "--prev" ) )
|
||||
AudioEngine::instance()->previous();
|
||||
else if ( instance.arguments.contains( "--playpause" ) )
|
||||
else if ( arguments.contains( "--playpause" ) )
|
||||
AudioEngine::instance()->playPause();
|
||||
else if ( instance.arguments.contains( "--play" ) )
|
||||
else if ( arguments.contains( "--play" ) )
|
||||
AudioEngine::instance()->play();
|
||||
else if ( instance.arguments.contains( "--pause" ) )
|
||||
else if ( arguments.contains( "--pause" ) )
|
||||
AudioEngine::instance()->pause();
|
||||
else if ( instance.arguments.contains( "--stop" ) )
|
||||
else if ( arguments.contains( "--stop" ) )
|
||||
AudioEngine::instance()->stop();
|
||||
}
|
||||
|
@@ -33,7 +33,7 @@ const void * KDLockedSharedMemoryPointerBase::get() const {
|
||||
}
|
||||
|
||||
size_t KDLockedSharedMemoryPointerBase::byteSize() const {
|
||||
return mem->size();
|
||||
return mem ? mem->size() : 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -2,24 +2,29 @@
|
||||
#define __KDTOOLSCORE_KDSINGLEAPPLICATIONGUARD_H__
|
||||
|
||||
#include <QtCore/QObject>
|
||||
|
||||
#if QT_VERSION >= 0x040400 || defined(DOXYGEN_RUN)
|
||||
#ifndef QT_NO_SHAREDMEMORY
|
||||
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QMetaType>
|
||||
|
||||
#include "pimpl_ptr.h"
|
||||
#include "DllMacro.h"
|
||||
|
||||
class QCoreApplication;
|
||||
#include <algorithm>
|
||||
|
||||
#ifndef Q_WS_WIN
|
||||
void SIGINT_handler( int sig );
|
||||
#endif
|
||||
template <typename T> class QVector;
|
||||
class QCoreApplication;
|
||||
|
||||
class DLLEXPORT KDSingleApplicationGuard : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
#ifndef Q_WS_WIN
|
||||
friend void ::SIGINT_handler( int );
|
||||
#endif
|
||||
|
||||
Q_ENUMS( Policy )
|
||||
Q_PROPERTY( bool operational READ isOperational )
|
||||
Q_PROPERTY( bool exitRequested READ isExitRequested )
|
||||
Q_PROPERTY( bool primaryInstance READ isPrimaryInstance NOTIFY becamePrimaryInstance )
|
||||
Q_PROPERTY( Policy policy READ policy WRITE setPolicy NOTIFY policyChanged )
|
||||
public:
|
||||
enum Policy
|
||||
{
|
||||
@@ -27,49 +32,112 @@ public:
|
||||
AutoKillOtherInstances = 1
|
||||
};
|
||||
|
||||
Q_PROPERTY( bool primaryInstance READ isPrimaryInstance NOTIFY becamePrimaryInstance )
|
||||
Q_PROPERTY( Policy policy READ policy WRITE setPolicy NOTIFY policyChanged )
|
||||
|
||||
explicit KDSingleApplicationGuard( QCoreApplication* parent, Policy policy = AutoKillOtherInstances );
|
||||
explicit KDSingleApplicationGuard( QObject * parent=0 );
|
||||
explicit KDSingleApplicationGuard( Policy policy, QObject * parent=0 );
|
||||
explicit KDSingleApplicationGuard( const QStringList & arguments, QObject * parent=0 );
|
||||
explicit KDSingleApplicationGuard( const QStringList & arguments, Policy policy, QObject * parent=0 );
|
||||
~KDSingleApplicationGuard();
|
||||
|
||||
bool isOperational() const;
|
||||
|
||||
bool isExitRequested() const;
|
||||
|
||||
bool isPrimaryInstance() const;
|
||||
|
||||
Policy policy() const;
|
||||
void setPolicy( Policy policy );
|
||||
|
||||
struct Instance
|
||||
{
|
||||
Instance( const QStringList& arguments = QStringList(), qint64 pid = -1 );
|
||||
class Instance;
|
||||
|
||||
QStringList arguments;
|
||||
qint64 pid;
|
||||
};
|
||||
|
||||
QList< Instance > instances() const;
|
||||
QVector<Instance> instances() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void instanceStarted( KDSingleApplicationGuard::Instance instance );
|
||||
void instanceExited( KDSingleApplicationGuard::Instance instance );
|
||||
void instanceStarted( const KDSingleApplicationGuard::Instance & instance );
|
||||
void instanceExited( const KDSingleApplicationGuard::Instance & instance );
|
||||
void exitRequested();
|
||||
void raiseRequested();
|
||||
void becamePrimaryInstance();
|
||||
void policyChanged();
|
||||
void becameSecondaryInstance();
|
||||
void policyChanged( KDSingleApplicationGuard::Policy policy );
|
||||
|
||||
public Q_SLOTS:
|
||||
void shutdownOtherInstances();
|
||||
void killOtherInstances();
|
||||
|
||||
protected:
|
||||
void timerEvent( QTimerEvent* event );
|
||||
/*! \reimp */ bool event( QEvent * event );
|
||||
|
||||
private:
|
||||
#ifndef Q_WS_WIN
|
||||
static void SIGINT_handler( int );
|
||||
#endif
|
||||
|
||||
private:
|
||||
friend struct ProcessInfo;
|
||||
|
||||
class Private;
|
||||
kdtools::pimpl_ptr< Private > d;
|
||||
};
|
||||
|
||||
#if QT_VERSION < 0x040400
|
||||
#ifdef Q_CC_GNU
|
||||
#warning "Can't use KDSingleApplicationGuard with Qt versions prior to 4.4"
|
||||
#endif
|
||||
#endif
|
||||
class DLLEXPORT KDSingleApplicationGuard::Instance {
|
||||
friend class ::KDSingleApplicationGuard;
|
||||
friend class ::KDSingleApplicationGuard::Private;
|
||||
Instance( const QStringList &, bool, qint64 );
|
||||
public:
|
||||
Instance();
|
||||
Instance( const Instance & other );
|
||||
~Instance();
|
||||
|
||||
#endif
|
||||
void swap( Instance & other ) {
|
||||
std::swap( d, other.d );
|
||||
}
|
||||
|
||||
Instance & operator=( Instance other ) {
|
||||
swap( other );
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool isNull() const { return !d; }
|
||||
bool isValid() const;
|
||||
|
||||
bool areArgumentsTruncated() const;
|
||||
|
||||
const QStringList & arguments() const;
|
||||
qint64 pid() const;
|
||||
|
||||
void shutdown();
|
||||
void kill();
|
||||
void raise();
|
||||
|
||||
private:
|
||||
class Private;
|
||||
Private * d;
|
||||
};
|
||||
|
||||
namespace std {
|
||||
template <>
|
||||
inline void swap( KDSingleApplicationGuard::Instance & lhs,
|
||||
KDSingleApplicationGuard::Instance & rhs )
|
||||
{
|
||||
lhs.swap( rhs );
|
||||
}
|
||||
} // namespace std
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
template <>
|
||||
inline void qSwap( KDSingleApplicationGuard::Instance & lhs,
|
||||
KDSingleApplicationGuard::Instance & rhs )
|
||||
{
|
||||
lhs.swap( rhs );
|
||||
}
|
||||
Q_DECLARE_METATYPE( KDSingleApplicationGuard::Instance )
|
||||
Q_DECLARE_TYPEINFO( KDSingleApplicationGuard::Instance, Q_MOVABLE_TYPE );
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
|
||||
#endif // QT_NO_SHAREDMEMORY
|
||||
#endif // QT_VERSION >= 0x040400 || defined(DOXYGEN_RUN)
|
||||
|
||||
#endif /* __KDTOOLSCORE_KDSINGLEAPPLICATIONGUARD_H__ */
|
||||
|
@@ -152,7 +152,7 @@ main( int argc, char *argv[] )
|
||||
#endif
|
||||
#endif
|
||||
|
||||
KDSingleApplicationGuard guard( &a, KDSingleApplicationGuard::AutoKillOtherInstances );
|
||||
KDSingleApplicationGuard guard( KDSingleApplicationGuard::AutoKillOtherInstances );
|
||||
QObject::connect( &guard, SIGNAL( instanceStarted( KDSingleApplicationGuard::Instance ) ), &a, SLOT( instanceStarted( KDSingleApplicationGuard::Instance ) ) );
|
||||
|
||||
if ( guard.isPrimaryInstance() )
|
||||
|
Reference in New Issue
Block a user