source: ogBrowser-Git/src/main.cpp

jenkins
Last change on this file was 068539c, checked in by Vadim Troshchinskiy Shmelev <vtroshchinskiy@…>, 2 months ago

Add ability to ignore SSL errors

  • Property mode set to 100644
File size: 2.9 KB
Line 
1#include <QApplication>
2#include <QTranslator>
3#include <QDebug>
4#include <QCommandLineParser>
5
6#include "mainwindow.h"
7#include "ogcommandline.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 noSandboxOption("no-sandbox", "Disable Chromium sandbox to allow running as root");
57    parser.addOption(noSandboxOption);
58
59    QCommandLineOption ignoreSslErrors("ignore-ssl-errors", "Ignore SSL certificate errors");
60    parser.addOption(ignoreSslErrors);
61
62    QCommandLineOption helpOption  = parser.addHelpOption();
63
64    OGCommandLineOptions &options = OGCommandLineOptions::getInstance();
65
66
67    parser.process(a);
68
69    if (parser.isSet(helpOption)) {
70        return 0;
71    }
72
73    if (parser.isSet(openInNewTabOption)) {
74        options.setNewTabBehavior(OGCommandLineOptions::NewTabBehavior::NewTab);
75    }
76
77    if (parser.isSet(replacePageOption)) {
78        options.setNewTabBehavior(OGCommandLineOptions::NewTabBehavior::ReplacePage);
79    }
80
81    if (parser.isSet(ignoreNewPageOption)) {
82        options.setNewTabBehavior(OGCommandLineOptions::NewTabBehavior::Ignore);
83    }
84
85    if (parser.isSet(ignoreSslErrors)) {
86        options.setIgnoreSslErrors(true);
87    }
88
89    QStringList positional = parser.positionalArguments();
90    if ( positional.length() > 0) {
91        options.setUrl( positional[0 ] );
92    }
93
94    MainWindow w;
95    w.show();
96    return a.exec();
97}
Note: See TracBrowser for help on using the repository browser.