mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-24 01:39:42 +01:00
Update to newer kdsingleappguard
This commit is contained in:
parent
7326212671
commit
b052486e2e
@ -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();
|
||||
}
|
||||
|
@ -31,9 +31,9 @@ void * KDLockedSharedMemoryPointerBase::get() {
|
||||
const void * KDLockedSharedMemoryPointerBase::get() const {
|
||||
return mem ? mem->data() : 0 ;
|
||||
}
|
||||
|
||||
|
||||
size_t KDLockedSharedMemoryPointerBase::byteSize() const {
|
||||
return mem->size();
|
||||
return mem ? mem->size() : 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -137,7 +137,7 @@ size_t KDLockedSharedMemoryPointerBase::byteSize() const {
|
||||
|
||||
(The exception safety of this class has not been evaluated yet.)
|
||||
|
||||
KDLockedSharedMemoryArray is a smart immutable pointer, which gives convenient and safe access to array data stored in a QSharedMemory
|
||||
KDLockedSharedMemoryArray is a smart immutable pointer, which gives convenient and safe access to array data stored in a QSharedMemory
|
||||
data segment.
|
||||
The content of a KDLockedSharedMemoryArray cannot be changed during it's lifetime.
|
||||
|
||||
@ -248,7 +248,7 @@ size_t KDLockedSharedMemoryPointerBase::byteSize() const {
|
||||
|
||||
/*!
|
||||
\fn KDLockedSharedMemoryArray::size_type KDLockedSharedMemoryArray::size() const
|
||||
Returns the size of this array. The size is calculated from the storage size of T and
|
||||
Returns the size of this array. The size is calculated from the storage size of T and
|
||||
the size of the shared memory segment.
|
||||
\since_f 2.2
|
||||
*/
|
||||
@ -461,7 +461,7 @@ KDAB_UNITTEST_SIMPLE( KDLockedSharedMemoryPointer, "kdcoretools" ) {
|
||||
assertEqual( a[ i ].n, i );
|
||||
assertEqual( a.front().n, 0u );
|
||||
assertEqual( a.back().n, a.size() - 1 );
|
||||
|
||||
|
||||
std::copy( v.begin(), v.end(), a.rbegin() );
|
||||
for( uint i = 0; i < a.size(); ++i )
|
||||
assertEqual( a[ i ].n, a.size() - 1 - i );
|
||||
|
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() )
|
||||
|
Loading…
x
Reference in New Issue
Block a user