aboutsummaryrefslogtreecommitdiff
path: root/libLumina/LuminaSingleApplication.h
blob: 909241ae52638d64bbe84dba544feb8b1b1d3ff5 (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
57
58
59
//===========================================
//  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>

//NOTE: This application type will automatically load the proper translation file(s)
//  if the application name is set properly
class LSingleApplication : public QApplication{
  Q_OBJECT
public:
	LSingleApplication(int &argc, char **argv, QString appname);
	~LSingleApplication();

	bool isPrimaryProcess();

	QStringList inputlist; //in case the app wants access to modified inputs (relative path fixes and such)

private:
	bool isActive, isBypass;
	QLockFile *lockfile;
	QLocalServer *lserver;
	QString cfile;
	QTranslator *cTrans; //current translation


	void PerformLockChecks();

private slots:
	void newInputsAvailable(); //internally used to detect a message from an alternate instance

signals:
	void InputsAvailable(QStringList);

};

#endif
bgstack15