source: ogBrowser-Git/src/main.cpp @ 21e8f4c

jenkinsmain
Last change on this file since 21e8f4c was 476581b, checked in by Vadim Troshchinskiy Shmelev <vtroshchinskiy@…>, 16 months ago

Add desktop file parser

  • Property mode set to 100644
File size: 2.6 KB
Line 
1#include <QApplication>
2#include <QTranslator>
3#include <QDebug>
4#include <QCommandLineParser>
5
6#include "mainwindow.h"
7#include "ogcommandlne.h"
8#include "desktopparser.h"
9
10
11
12int main(int argc, char *argv[])
13{
14    QApplication a(argc, argv);
15    QCoreApplication::setApplicationName("OGBrowser");
16    QCoreApplication::setOrganizationName("OpenGnsys");
17    QCoreApplication::setOrganizationDomain("opengnsys.es");
18
19    QTranslator translator;
20    QStringList translationDirs{QCoreApplication::applicationDirPath(), "", "."};
21
22    bool translationsOk = false;
23
24    for(const QString &dir : translationDirs) {
25        qDebug() << "Trying to find translations in" << dir;
26        if (translator.load(QLocale(), "OGBrowser_", "", dir)) {
27            qDebug() << "Translations loaded";
28            QCoreApplication::installTranslator(&translator);
29            translationsOk = true;
30            break;
31        }
32    }
33
34    if (!translationsOk) {
35        qWarning() << "Failed to load translations. Tried looking in:" << translationDirs;
36    }
37
38
39    auto &desktopParser = DesktopParser::getInstance();
40    desktopParser.loadSchemes();
41
42
43    QCommandLineParser parser;
44    QCommandLineOption openInNewTabOption("openInNewTab", "Create a new tab when opening a new page");
45    parser.addOption(openInNewTabOption);
46
47    QCommandLineOption replacePageOption("replacePage", "When trying to open a new page/tab, replace the current page instead");
48    parser.addOption(replacePageOption);
49
50    QCommandLineOption ignoreNewPageOption("ignoreNewPage", "Ignore attempts to open documents in a new page/tab");
51    parser.addOption(ignoreNewPageOption);
52
53    QCommandLineOption disableWebSecurityOption("disable-web-security", "Disable web security and allow custom URL schemes");
54    parser.addOption(disableWebSecurityOption);
55
56    QCommandLineOption helpOption  = parser.addHelpOption();
57
58    OGCommandLineOptions &options = OGCommandLineOptions::getInstance();
59
60
61    parser.process(a);
62
63    if (parser.isSet(helpOption)) {
64        return 0;
65    }
66
67    if (parser.isSet(openInNewTabOption)) {
68        options.setNewTabBehavior(OGCommandLineOptions::NewTabBehavior::NewTab);
69    }
70
71    if (parser.isSet(replacePageOption)) {
72        options.setNewTabBehavior(OGCommandLineOptions::NewTabBehavior::ReplacePage);
73    }
74
75    if (parser.isSet(ignoreNewPageOption)) {
76        options.setNewTabBehavior(OGCommandLineOptions::NewTabBehavior::Ignore);
77    }
78
79    QStringList positional = parser.positionalArguments();
80    if ( positional.length() > 0) {
81        options.setUrl( positional[0 ] );
82    }
83
84    MainWindow w;
85    w.show();
86    return a.exec();
87}
Note: See TracBrowser for help on using the repository browser.