[Feature #811] Only 1 Instance of OpenCS is Allowed

If another instance of OpenCS is started, then it will terminate. This
is done by creating a QLocalServer with a unique ID. If another
QLocalServer with the same ID attempts to be opened, then the creation
of the QLocalServer will fail and the application will terminate.
actorid
Marc Bouvier 11 years ago
parent 2e8b0cf502
commit 51332b86a1

@ -127,7 +127,7 @@ if(WIN32)
set(QT_USE_QTMAIN TRUE)
endif(WIN32)
find_package(Qt4 COMPONENTS QtCore QtGui QtXml QtXmlPatterns REQUIRED)
find_package(Qt4 COMPONENTS QtCore QtGui QtNetwork QtXml QtXmlPatterns REQUIRED)
include(${QT_USE_FILE})
qt4_wrap_ui(OPENCS_UI_HDR ${OPENCS_UI})

@ -2,6 +2,8 @@
#include "editor.hpp"
#include <QApplication>
#include <QLocalServer>
#include <QLocalSocket>
#include "model/doc/document.hpp"
#include "model/world/data.hpp"
@ -114,6 +116,15 @@ void CS::Editor::createNewFile()
mFileDialog.hide();
}
bool CS::Editor::makeIPCServer()
{
server = new QLocalServer(this);
if(server->listen("IPCServer"))
return true;
server->close();
return false;
}
int CS::Editor::run()
{
mStartup.show();

@ -1,6 +1,8 @@
#ifndef CS_EDITOR_H
#define CS_EDITOR_H
#include <QLocalServer>
#include <QObject>
#ifndef Q_MOC_RUN
#include <components/files/configurationmanager.hpp>
@ -35,6 +37,8 @@ namespace CS
Editor();
bool makeIPCServer();
int run();
///< \return error status
@ -45,6 +49,10 @@ namespace CS
void loadDocument();
void openFiles();
void createNewFile();
private:
QLocalServer *server;
};
}

@ -39,5 +39,10 @@ int main(int argc, char *argv[])
CS::Editor editor;
if(!editor.makeIPCServer())
{
return 0;
}
return editor.run();
}

Loading…
Cancel
Save