~mateo-salta/nitroshare/nitroshare

« back to all changes in this revision

Viewing changes to src/main/main.cpp

  • Committer: Nathan Osman
  • Date: 2012-07-04 23:45:28 UTC
  • Revision ID: admin@quickmediasolutions.com-20120704234528-1ycx8e04a2swv53s
Added dependency on XML-RPC library and implemented code to make sure that only one instance of the application is running at a time.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
#include <QApplication>
18
18
#include <QDebug>
19
19
#include <QLocale>
 
20
#include <QMessageBox>
20
21
#include <QTranslator>
21
22
 
22
23
#include <dialogs/CFirstStartWizard.h>
23
24
#include <main/CTrayIcon.h>
 
25
#include <rpc/CRPCServer.h>
24
26
#include <util/defaults.h>
25
27
#include <util/settings.h>
26
28
 
27
 
int main(int argc, char *argv[])
 
29
void InitLocale()
28
30
{
29
 
    QApplication a(argc, argv);
30
 
    a.setQuitOnLastWindowClosed(false);
31
 
 
32
 
    /* Set information about the application. */
33
 
    a.setApplicationName("NitroShare");
34
 
    a.setOrganizationName("Nathan Osman");
35
 
    a.setOrganizationDomain("quickmediasolutions.com");
36
 
 
37
31
    /* Determine what the user's default locale is set to
38
32
       and attempt to load the appropriate translation. */
39
33
    QString locale = QLocale::system().name();
44
38
        qDebug() << "Unable to load translation" << QString("translations/%1.qm").arg(locale);
45
39
    else
46
40
        QApplication::installTranslator(&translator);
 
41
}
 
42
 
 
43
int main(int argc, char *argv[])
 
44
{
 
45
    QApplication a(argc, argv);
 
46
    a.setQuitOnLastWindowClosed(false);
 
47
 
 
48
    /* Set information about the application. */
 
49
    a.setApplicationName("NitroShare");
 
50
    a.setOrganizationName("Nathan Osman");
 
51
    a.setOrganizationDomain("quickmediasolutions.com");
47
52
 
48
53
    /* Load the application defaults. */
49
54
    Defaults::Init();
50
55
 
 
56
    /* Determine if NitroShare is already running. */
 
57
    CRPCServer server;
 
58
    if(!server.Init())
 
59
    {
 
60
        // TODO: we need to ask the user if they want to start the application anyway
 
61
        // in case something is using the port.
 
62
 
 
63
        qDebug() << "Unable to initialize RPC server. Assuming the application is already running.";
 
64
 
 
65
        QMessageBox::critical(NULL, QObject::tr("Error:"), QObject::tr("NitroShare is already running. Please close the current instance before launching the application again."));
 
66
        return 1;
 
67
    }
 
68
 
51
69
    /* If this is the first time the application is started, display
52
70
       the initial setup and configuration wizard. */
53
71
    if(!Settings::Get("Internal/FirstStart").toBool())