blob: ba342327c334d47578f09db5136730b1522c04f8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
//===========================================
// Lumina-DE source code
// Copyright (c) 2014, Ken Moore
// Available under the 3-clause BSD license
// See the LICENSE file for full details
//===========================================
// This is the general class for a single-instance application
//===========================================
//EXAMPLE USAGE in main.cpp:
//
// LSingleApplication app(argc, argv);
// if( !app.isPrimaryProcess() ){
// return 0;
// }
// QMainWindow w; //or whatever the main window class is
// connect(app, SIGNAL(InputsAvailable(QStringList)), w, SLOT(<some slot>)); //for interactive apps - optional
// app.exec();
//===========================================
#ifndef _LUMINA_LIBRARY_SINGLE_APPLICATION_H
#define _LUMINA_LIBRARY_SINGLE_APPLICATION_H
#include <QString>
#include <QStringList>
#include <QLocalServer>
#include <QLockFile>
#include <LuminaUtils.h>
class LSingleApplication : public QApplication{
Q_OBJECT
public:
LSingleApplication(int &argc, char **argv);
~LSingleApplication();
bool isPrimaryProcess();
QStringList inputlist; //in case the app wants access to modified inputs (relative path fixes and such)
private:
bool isActive;
QLockFile *lockfile;
QLocalServer *lserver;
QString cfile;
void PerformLockChecks();
private slots:
void newInputsAvailable(); //internally used to detect a message from an alternate instance
signals:
void InputsAvailable(QStringList);
};
#endif
|