1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-27 05:37:25 +00:00

[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.
This commit is contained in:
Marc Bouvier 2013-09-03 01:44:21 -05:00
parent 2e8b0cf502
commit 51332b86a1
4 changed files with 25 additions and 1 deletions

View File

@ -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})

View File

@ -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();

View File

@ -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;
};
}

View File

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