source: calamares/trunk/fuentes/src/libcalamares/kdsingleapplicationguard/kdsingleapplicationguard.h @ 7538

Last change on this file since 7538 was 7538, checked in by kbut, 13 months ago

sync with github

File size: 3.4 KB
Line 
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
16template <typename T> class QVector;
17class QCoreApplication;
18
19class 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 )
27public:
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
53Q_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
62public Q_SLOTS:
63    void shutdownOtherInstances();
64    void killOtherInstances();
65
66protected:
67    /*! \reimp */ bool event( QEvent * event );
68
69private:
70#ifndef Q_WS_WIN
71    static void SIGINT_handler( int );
72#endif
73
74private:
75    friend struct ProcessInfo;
76
77    class Private;
78    kdtools::pimpl_ptr< Private > d;
79};
80
81class DLLEXPORT KDSingleApplicationGuard::Instance {
82    friend class ::KDSingleApplicationGuard;
83    friend class ::KDSingleApplicationGuard::Private;
84    Instance( const QStringList &, bool, qint64 );
85public:
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
111private:
112    class Private;
113    Private * d;
114};
115
116namespace std {
117    template <>
118    inline void swap( KDSingleApplicationGuard::Instance & lhs,
119                      KDSingleApplicationGuard::Instance & rhs )
120    {
121        lhs.swap( rhs );
122    }
123} // namespace std
124
125QT_BEGIN_NAMESPACE
126
127template <>
128inline void qSwap( KDSingleApplicationGuard::Instance & lhs,
129                   KDSingleApplicationGuard::Instance & rhs )
130{
131    lhs.swap( rhs );
132}
133Q_DECLARE_METATYPE( KDSingleApplicationGuard::Instance )
134Q_DECLARE_TYPEINFO( KDSingleApplicationGuard::Instance, Q_MOVABLE_TYPE );
135
136QT_END_NAMESPACE
137
138
139#endif // QT_NO_SHAREDMEMORY
140
141#endif /* __KDTOOLSCORE_KDSINGLEAPPLICATIONGUARD_H__ */
Note: See TracBrowser for help on using the repository browser.