File: main.cpp

package info (click to toggle)
vibes 0.3.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,684 kB
  • sloc: cpp: 6,120; python: 412; makefile: 214; sh: 13
file content (37 lines) | stat: -rw-r--r-- 1,282 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "vibeswindow.h"
#include <QApplication>
#include <QLocalSocket>
#include <QLocalServer>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    // Identifier for running instance checking
    const QString serverName("VIBes_running_instance");
    // Check if another instance is already running
    {
        QLocalSocket socket;
        socket.connectToServer(serverName);
        if (socket.waitForConnected(500))
            return 1; // Exit already a process running
    }
    // Start a local server to signal the application is running
    // parent is set to <a> in order to destroy cleanly the socket at the end.
    QLocalServer * m_localServer = new QLocalServer(&a);
    m_localServer->listen(serverName);

    // Process command line arguments
    bool showFileOpenDlg = a.arguments().contains("--show-open-dlg", Qt::CaseInsensitive);

    // Create application main window
    VibesWindow w(showFileOpenDlg);
    w.show();

    // Trying to launch the app when it is already launched will make it pop
    QObject::connect(m_localServer, SIGNAL(newConnection()), &w, SLOT(showNormal()));
    QObject::connect(m_localServer, &QLocalServer::newConnection, &w, &VibesWindow::activateWindow);

    // Enter main event loop
    return a.exec();
}