[Feature #881] Raise OpenCS New Window After Re-execution

The OpenCS startup window of the existing exist is raised when trying to
start a new instance. This is done by the new instance connection to the
existing instance's QLocalServer. Once the connection is established the
existing instance raises the startup window.
pull/51/head
Marc Bouvier 11 years ago
parent 51332b86a1
commit 563bd0b430

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

@ -1,9 +1,11 @@
#ifndef CS_EDITOR_H
#define CS_EDITOR_H
#include <QObject>
#include <QString>
#include <QLocalServer>
#include <QLocalSocket>
#include <QObject>
#ifndef Q_MOC_RUN
#include <components/files/configurationmanager.hpp>
#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;
};
}

@ -41,6 +41,7 @@ int main(int argc, char *argv[])
if(!editor.makeIPCServer())
{
editor.connectToIPCServer();
return 0;
}

Loading…
Cancel
Save