~ubuntu-branches/ubuntu/trusty/tomahawk/trusty-proposed

« back to all changes in this revision

Viewing changes to src/libtomahawk/thirdparty/kdsingleapplicationguard/kdsingleapplicationguard.h

  • Committer: Package Import Robot
  • Author(s): Harald Sitter
  • Date: 2013-03-07 21:50:13 UTC
  • Revision ID: package-import@ubuntu.com-20130307215013-6gdjkdds7i9uenvs
Tags: upstream-0.6.0+dfsg
ImportĀ upstreamĀ versionĀ 0.6.0+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef __KDTOOLSCORE_KDSINGLEAPPLICATIONGUARD_H__
 
2
#define __KDTOOLSCORE_KDSINGLEAPPLICATIONGUARD_H__
 
3
 
 
4
#include <QtCore/QObject>
 
5
 
 
6
#ifndef QT_NO_SHAREDMEMORY
 
7
 
 
8
#include <QtCore/QStringList>
 
9
#include <QtCore/QMetaType>
 
10
 
 
11
#include "pimpl_ptr.h"
 
12
#include "DllMacro.h"
 
13
 
 
14
#include <algorithm>
 
15
 
 
16
template <typename T> class QVector;
 
17
class QCoreApplication;
 
18
 
 
19
class DLLEXPORT KDSingleApplicationGuard : public QObject
 
20
{
 
21
    Q_OBJECT
 
22
    Q_ENUMS( Policy )
 
23
    Q_PROPERTY( bool operational READ isOperational )
 
24
    Q_PROPERTY( bool exitRequested READ isExitRequested )
 
25
    Q_PROPERTY( bool primaryInstance READ isPrimaryInstance NOTIFY becamePrimaryInstance )
 
26
    Q_PROPERTY( Policy policy READ policy WRITE setPolicy NOTIFY policyChanged )
 
27
public:
 
28
    enum Policy
 
29
    {
 
30
        NoPolicy = 0,
 
31
        AutoKillOtherInstances = 1
 
32
    };
 
33
 
 
34
    explicit KDSingleApplicationGuard( QObject * parent=0 );
 
35
    explicit KDSingleApplicationGuard( Policy policy, QObject * parent=0 );
 
36
    explicit KDSingleApplicationGuard( const QStringList & arguments, QObject * parent=0 );
 
37
    explicit KDSingleApplicationGuard( const QStringList & arguments, Policy policy, QObject * parent=0 );
 
38
    ~KDSingleApplicationGuard();
 
39
 
 
40
    bool isOperational() const;
 
41
 
 
42
    bool isExitRequested() const;
 
43
 
 
44
    bool isPrimaryInstance() const;
 
45
 
 
46
    Policy policy() const;
 
47
    void setPolicy( Policy policy );
 
48
 
 
49
    class Instance;
 
50
 
 
51
    QVector<Instance> instances() const;
 
52
 
 
53
Q_SIGNALS:
 
54
    void instanceStarted( const KDSingleApplicationGuard::Instance & instance );
 
55
    void instanceExited( const KDSingleApplicationGuard::Instance & instance );
 
56
    void exitRequested();
 
57
    void raiseRequested();
 
58
    void becamePrimaryInstance();
 
59
    void becameSecondaryInstance();
 
60
    void policyChanged( KDSingleApplicationGuard::Policy policy );
 
61
 
 
62
public Q_SLOTS:
 
63
    void shutdownOtherInstances();
 
64
    void killOtherInstances();
 
65
 
 
66
protected:
 
67
    /*! \reimp */ bool event( QEvent * event );
 
68
 
 
69
private:
 
70
#ifndef Q_WS_WIN
 
71
    static void SIGINT_handler( int );
 
72
#endif
 
73
 
 
74
private:
 
75
    friend struct ProcessInfo;
 
76
 
 
77
    class Private;
 
78
    kdtools::pimpl_ptr< Private > d;
 
79
};
 
80
 
 
81
class DLLEXPORT KDSingleApplicationGuard::Instance {
 
82
    friend class ::KDSingleApplicationGuard;
 
83
    friend class ::KDSingleApplicationGuard::Private;
 
84
    Instance( const QStringList &, bool, qint64 );
 
85
public:
 
86
    Instance();
 
87
    Instance( const Instance & other );
 
88
    ~Instance();
 
89
 
 
90
    void swap( Instance & other ) {
 
91
        std::swap( d, other.d );
 
92
    }
 
93
 
 
94
    Instance & operator=( Instance other ) {
 
95
        swap( other );
 
96
        return *this;
 
97
    }
 
98
 
 
99
    bool isNull() const { return !d; }
 
100
    bool isValid() const;
 
101
 
 
102
    bool areArgumentsTruncated() const;
 
103
 
 
104
    const QStringList & arguments() const;
 
105
    qint64 pid() const;
 
106
 
 
107
    void shutdown();
 
108
    void kill();
 
109
    void raise();
 
110
 
 
111
private:
 
112
    class Private;
 
113
    Private * d;
 
114
};
 
115
 
 
116
namespace std {
 
117
    template <>
 
118
    inline void swap( KDSingleApplicationGuard::Instance & lhs,
 
119
                      KDSingleApplicationGuard::Instance & rhs )
 
120
    {
 
121
        lhs.swap( rhs );
 
122
    }
 
123
} // namespace std
 
124
 
 
125
QT_BEGIN_NAMESPACE
 
126
 
 
127
template <>
 
128
inline void qSwap( KDSingleApplicationGuard::Instance & lhs,
 
129
                   KDSingleApplicationGuard::Instance & rhs )
 
130
{
 
131
    lhs.swap( rhs );
 
132
}
 
133
Q_DECLARE_METATYPE( KDSingleApplicationGuard::Instance )
 
134
Q_DECLARE_TYPEINFO( KDSingleApplicationGuard::Instance, Q_MOVABLE_TYPE );
 
135
 
 
136
QT_END_NAMESPACE
 
137
 
 
138
 
 
139
#endif // QT_NO_SHAREDMEMORY
 
140
 
 
141
#endif /* __KDTOOLSCORE_KDSINGLEAPPLICATIONGUARD_H__ */