[dae65b7] | 1 | #include <QApplication> |
---|
[8e79a8a] | 2 | #include <QTranslator> |
---|
[0b68674] | 3 | #include <QDebug> |
---|
[476581b] | 4 | #include <QCommandLineParser> |
---|
[8e79a8a] | 5 | |
---|
[3648efe] | 6 | #include "mainwindow.h" |
---|
[bc7a483] | 7 | #include "ogcommandline.h" |
---|
[476581b] | 8 | #include "desktopparser.h" |
---|
| 9 | |
---|
| 10 | |
---|
[050d67a] | 11 | |
---|
| 12 | int main(int argc, char *argv[]) |
---|
| 13 | { |
---|
[8e79a8a] | 14 | QApplication a(argc, argv); |
---|
| 15 | QCoreApplication::setApplicationName("OGBrowser"); |
---|
| 16 | QCoreApplication::setOrganizationName("OpenGnsys"); |
---|
| 17 | QCoreApplication::setOrganizationDomain("opengnsys.es"); |
---|
[1ed6e72] | 18 | |
---|
[8e79a8a] | 19 | QTranslator translator; |
---|
[0b68674] | 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; |
---|
[3648efe] | 36 | } |
---|
[dae65b7] | 37 | |
---|
[476581b] | 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 | |
---|
[068539c] | 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 | |
---|
[476581b] | 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 | |
---|
[068539c] | 85 | if (parser.isSet(ignoreSslErrors)) { |
---|
| 86 | options.setIgnoreSslErrors(true); |
---|
| 87 | } |
---|
| 88 | |
---|
[476581b] | 89 | QStringList positional = parser.positionalArguments(); |
---|
| 90 | if ( positional.length() > 0) { |
---|
| 91 | options.setUrl( positional[0 ] ); |
---|
| 92 | } |
---|
| 93 | |
---|
[3648efe] | 94 | MainWindow w; |
---|
| 95 | w.show(); |
---|
| 96 | return a.exec(); |
---|
[050d67a] | 97 | } |
---|