mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-27 05:10:26 +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:
parent
2e8b0cf502
commit
51332b86a1
4 changed files with 25 additions and 1 deletions
|
@ -127,7 +127,7 @@ if(WIN32)
|
||||||
set(QT_USE_QTMAIN TRUE)
|
set(QT_USE_QTMAIN TRUE)
|
||||||
endif(WIN32)
|
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})
|
include(${QT_USE_FILE})
|
||||||
|
|
||||||
qt4_wrap_ui(OPENCS_UI_HDR ${OPENCS_UI})
|
qt4_wrap_ui(OPENCS_UI_HDR ${OPENCS_UI})
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
#include "editor.hpp"
|
#include "editor.hpp"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QLocalServer>
|
||||||
|
#include <QLocalSocket>
|
||||||
|
|
||||||
#include "model/doc/document.hpp"
|
#include "model/doc/document.hpp"
|
||||||
#include "model/world/data.hpp"
|
#include "model/world/data.hpp"
|
||||||
|
@ -114,6 +116,15 @@ void CS::Editor::createNewFile()
|
||||||
mFileDialog.hide();
|
mFileDialog.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CS::Editor::makeIPCServer()
|
||||||
|
{
|
||||||
|
server = new QLocalServer(this);
|
||||||
|
if(server->listen("IPCServer"))
|
||||||
|
return true;
|
||||||
|
server->close();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int CS::Editor::run()
|
int CS::Editor::run()
|
||||||
{
|
{
|
||||||
mStartup.show();
|
mStartup.show();
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#ifndef CS_EDITOR_H
|
#ifndef CS_EDITOR_H
|
||||||
#define CS_EDITOR_H
|
#define CS_EDITOR_H
|
||||||
|
|
||||||
|
#include <QLocalServer>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#ifndef Q_MOC_RUN
|
#ifndef Q_MOC_RUN
|
||||||
#include <components/files/configurationmanager.hpp>
|
#include <components/files/configurationmanager.hpp>
|
||||||
|
@ -35,6 +37,8 @@ namespace CS
|
||||||
|
|
||||||
Editor();
|
Editor();
|
||||||
|
|
||||||
|
bool makeIPCServer();
|
||||||
|
|
||||||
int run();
|
int run();
|
||||||
///< \return error status
|
///< \return error status
|
||||||
|
|
||||||
|
@ -45,6 +49,10 @@ namespace CS
|
||||||
void loadDocument();
|
void loadDocument();
|
||||||
void openFiles();
|
void openFiles();
|
||||||
void createNewFile();
|
void createNewFile();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
QLocalServer *server;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,5 +39,10 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
CS::Editor editor;
|
CS::Editor editor;
|
||||||
|
|
||||||
|
if(!editor.makeIPCServer())
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return editor.run();
|
return editor.run();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue