File: main.cpp

package info (click to toggle)
tipp10 3.3.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,984 kB
  • sloc: cpp: 8,343; xml: 70; ansic: 60; makefile: 11
file content (126 lines) | stat: -rw-r--r-- 3,754 bytes parent folder | download | duplicates (2)
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
115
116
117
118
119
120
121
122
123
124
125
126
/*
Copyright (c) 2006-2011, Tom Thielicke IT Solutions

SPDX-License-Identifier: GPL-2.0-only
*/

/****************************************************************
**
** File name: main.cpp
**
****************************************************************/

#include <QApplication>
#include <QCoreApplication>
#include <QLibraryInfo>
#include <QSettings>
#include <QString>
#include <QTranslator>

#include "def/defines.h"
#include "sql/connection.h"
#include "widget/illustrationdialog.h"
#include "widget/mainwindow.h"

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

    QApplication app(argc, argv);

    // Set application name and domain
    // (this saves having to repeat the information
    // each time a QSettings object is created)
    QApplication::setOrganizationName(t10::app_name_intern);
    QApplication::setOrganizationDomain(t10::app_url);
    QApplication::setApplicationName(t10::app_name_intern);
    QApplication::setDesktopFileName("com.gitlab.tipp10.tipp10");
    QApplication::setWindowIcon(QIcon(":/img/icon.svg"));

    // Translation
    // Common qt widgets
    QTranslator translatorQt;
    bool loaded = translatorQt.load("qt_" + QLocale::system().name(),
        QLibraryInfo::path(QLibraryInfo::TranslationsPath));
    if (loaded)
        QApplication::installTranslator(&translatorQt);

    // Content (own translation files)
    QString trFile = "tipp10_" + QLocale::system().name();
    QString trPath = t10::getDataDir() + "translations";
    QTranslator translatorContent;
    if (translatorContent.load(trFile, trPath))
        QApplication::installTranslator(&translatorContent);

// Settings to get and set general settings
#if APP_PORTABLE
    QSettings settings(
        QCoreApplication::applicationDirPath() + "/portable/settings.ini",
        QSettings::IniFormat);
#else
    QSettings settings;

    // move settings to new location
    QSettings oldSettings("Tom Thielicke IT Solutions", t10::app_name_intern);
    QFile oldconfig(oldSettings.fileName());
    if (oldconfig.exists()) {
        QDir oldDir = QFileInfo(oldconfig).dir();

        QFile newconfig(settings.fileName());
        QDir dir = QFileInfo(newconfig).dir();
        dir.mkpath(dir.path());

        oldconfig.rename(settings.fileName());
        oldDir.rmdir(oldDir.path());
        settings.sync();
    }
#endif

    // Read/write language, license key and show illustration flag
    settings.beginGroup("main");
    QString languageLayout = settings.value("language_layout", "").toString();

    QString languageLesson = settings.value("language_lesson", "").toString();

    bool showIllustration = settings.value("check_illustration", true).toBool();
    settings.endGroup();

    if (languageLayout == "") {
        if (QObject::tr("en") == "de") {
            languageLesson = "de_de_qwertz";
            languageLayout = "de_qwertz";
        } else {
            languageLesson = "en_us_qwerty";
            languageLayout = "us_qwerty";
        }
#ifdef APP_MAC
        languageLayout.append("_mac");
#else
        languageLayout.append("_win");
#endif
    }

    settings.beginGroup("main");
    settings.setValue("language_layout", languageLayout);
    settings.setValue("language_lesson", languageLesson);
    settings.endGroup();

    // Create database connection
    if (!createConnection()) {
        // Cannot find or open database
        // -> exit program
        return 1;
    }

    // Show illustration widget at the beginning if not disabled by the user
    if (showIllustration) {
        IllustrationDialog illustrationDialog(nullptr);
        illustrationDialog.exec();
    }

    // Create main window object
    MainWindow window;
    window.show();

    // Start the event loop
    return QApplication::exec();
}