File: main.cpp

package info (click to toggle)
cb2bib 1.9.2-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,368 kB
  • sloc: cpp: 24,179; sh: 481; makefile: 16
file content (114 lines) | stat: -rw-r--r-- 3,576 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/***************************************************************************
 *   Copyright (C) 2004-2015 by Pere Constans
 *   constans@molspaces.com
 *   cb2Bib version 1.9.2. Licensed under the GNU GPL version 3.
 *   See the LICENSE file that comes with this distribution.
 ***************************************************************************/
#include "qtsingleapplication/src/qtsingleapplication.h"
#include "qtsingleapplication/src/qtsinglecoreapplication.h"

#include "c2bConfigure.h"
#include "c2bConsole.h"
#include "c2bSettings.h"
#include "cb2Bib.h"

#ifdef C2B_USE_WEBKIT
#include "c2bAnnote.h"
#ifdef C2B_STATIC_LINKING
#include <QtPlugin>
Q_IMPORT_PLUGIN(qjpeg)
Q_IMPORT_PLUGIN(qgif)
#endif
#endif


int main(int argc, char* argv[])
{
    Q_INIT_RESOURCE(cb2bib);
    Q_INIT_RESOURCE(c2blib);

    c2bSettings* c2b_settings; // Delete before app, this avoids QVariant::save: unable to save type 67/64
    int code(0);

    if (c2bSettings::isConsoleMode(argc, argv))
    {
        // Cannot use QCoreApplication, QTextDocument is required by c2bUtils::fromHtmlString
#ifdef Q_OS_WIN
        // Needs also workaround c2bSettings::decodeFilename()
        QApplication app(argc, argv);
#else
        QApplication app(argc, argv);
#endif
        app.setOrganizationName(C2B_ORGANIZATION);
        app.setApplicationName(C2B_APPLICATION);
        c2b_settings = c2bSettings::initSettings();
        if (c2b_settings->loaded())
        {
            c2bConsole c2B;
            c2B.load();
            code = app.exec();
        }
        delete c2b_settings;
    }
    else if (c2bSettings::isSingleApplicationMode(argc, argv))
    {
        // Avoid connecting to the graphic server. On Windows it would create a void window.
        QtSingleCoreApplication* capp = new QtSingleCoreApplication(argc, argv);
        const bool is_running = capp->sendMessage(QString());
        delete capp;
        if (is_running)
            return code;
        QtSingleApplication app(argc, argv);
        if (app.isRunning()) // Activate local peer
            return code;
        app.setQuitOnLastWindowClosed(false);
        app.setOrganizationName(C2B_ORGANIZATION);
        app.setApplicationName(C2B_APPLICATION);
        c2b_settings = c2bSettings::initSettings();
        if (c2b_settings->loaded())
        {
            cb2Bib c2B;
            c2B.show();
            QObject::connect(&app, SIGNAL(messageReceived(const QString&)), &c2B, SLOT(show()));
            code = app.exec();
        }
        delete c2b_settings;
    }
    else
    {
        QApplication app(argc, argv);
        app.setOrganizationName(C2B_ORGANIZATION);
        app.setApplicationName(C2B_APPLICATION);
        c2b_settings = c2bSettings::initSettings();
        if (c2b_settings->loaded())
        {
            if (c2b_settings->cl_cb2bib_import_mode)
                code = app.exec();
            else if (c2b_settings->cl_configure)
            {
                c2bConfigure c2B;
                c2B.show();
                code = app.exec();
            }
            else if (c2b_settings->cl_view_annote)
            {
#ifdef C2B_USE_WEBKIT
                c2bAnnote c2B;
                if (c2B.show())
                    code = app.exec();
#else
                fprintf(stdout, "The cb2Bib Annote is disabled. Recompile using WebKit library.\n");
#endif
            }
            else
            {
                cb2Bib c2B;
                c2B.show();
                code = app.exec();
            }
        }
        delete c2b_settings;
    }

    return code;
}