diff --git a/apps/opencs/editor.cpp b/apps/opencs/editor.cpp index c339d8769..79dc368b4 100644 --- a/apps/opencs/editor.cpp +++ b/apps/opencs/editor.cpp @@ -10,6 +10,8 @@ CS::Editor::Editor() : mViewManager (mDocumentManager) { + ipcServerName = "IPCServer"; + connect (&mViewManager, SIGNAL (newDocumentRequest ()), this, SLOT (createDocument ())); connect (&mViewManager, SIGNAL (loadDocumentRequest ()), this, SLOT (loadDocument ())); @@ -116,15 +118,35 @@ void CS::Editor::createNewFile() mFileDialog.hide(); } +void CS::Editor::showStartup() +{ + if(mStartup.isHidden()) + mStartup.show(); + mStartup.raise(); + mStartup.activateWindow(); +} + bool CS::Editor::makeIPCServer() { server = new QLocalServer(this); - if(server->listen("IPCServer")) + + if(server->listen(ipcServerName)) + { + connect(server, SIGNAL(newConnection()), this, SLOT(showStartup())); return true; + } + server->close(); return false; } +void CS::Editor::connectToIPCServer() +{ + clientToServerSocket = new QLocalSocket(this); + clientToServerSocket->connectToServer(ipcServerName); + clientToServerSocket->close(); +} + int CS::Editor::run() { mStartup.show(); diff --git a/apps/opencs/editor.hpp b/apps/opencs/editor.hpp index 2d50b68fe..258d5b18a 100644 --- a/apps/opencs/editor.hpp +++ b/apps/opencs/editor.hpp @@ -1,9 +1,11 @@ #ifndef CS_EDITOR_H #define CS_EDITOR_H +#include +#include #include +#include -#include #ifndef Q_MOC_RUN #include #endif @@ -38,6 +40,7 @@ namespace CS Editor(); bool makeIPCServer(); + void connectToIPCServer(); int run(); ///< \return error status @@ -50,9 +53,13 @@ namespace CS void openFiles(); void createNewFile(); + void showStartup(); + private: + QString ipcServerName; QLocalServer *server; + QLocalSocket *clientToServerSocket; }; } diff --git a/apps/opencs/main.cpp b/apps/opencs/main.cpp index 3e40ee8cc..eddeb1983 100644 --- a/apps/opencs/main.cpp +++ b/apps/opencs/main.cpp @@ -41,6 +41,7 @@ int main(int argc, char *argv[]) if(!editor.makeIPCServer()) { + editor.connectToIPCServer(); return 0; }