ogbrowser/src/main.cpp

98 lines
2.9 KiB
C++

#include <QApplication>
#include <QTranslator>
#include <QDebug>
#include <QCommandLineParser>
#include "mainwindow.h"
#include "ogcommandline.h"
#include "desktopparser.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QCoreApplication::setApplicationName("OGBrowser");
QCoreApplication::setOrganizationName("OpenGnsys");
QCoreApplication::setOrganizationDomain("opengnsys.es");
QTranslator translator;
QStringList translationDirs{QCoreApplication::applicationDirPath(), "", "."};
bool translationsOk = false;
for(const QString &dir : translationDirs) {
qDebug() << "Trying to find translations in" << dir;
if (translator.load(QLocale(), "OGBrowser_", "", dir)) {
qDebug() << "Translations loaded";
QCoreApplication::installTranslator(&translator);
translationsOk = true;
break;
}
}
if (!translationsOk) {
qWarning() << "Failed to load translations. Tried looking in:" << translationDirs;
}
auto &desktopParser = DesktopParser::getInstance();
desktopParser.loadSchemes();
QCommandLineParser parser;
QCommandLineOption openInNewTabOption("openInNewTab", "Create a new tab when opening a new page");
parser.addOption(openInNewTabOption);
QCommandLineOption replacePageOption("replacePage", "When trying to open a new page/tab, replace the current page instead");
parser.addOption(replacePageOption);
QCommandLineOption ignoreNewPageOption("ignoreNewPage", "Ignore attempts to open documents in a new page/tab");
parser.addOption(ignoreNewPageOption);
QCommandLineOption disableWebSecurityOption("disable-web-security", "Disable web security and allow custom URL schemes");
parser.addOption(disableWebSecurityOption);
QCommandLineOption noSandboxOption("no-sandbox", "Disable Chromium sandbox to allow running as root");
parser.addOption(noSandboxOption);
QCommandLineOption ignoreSslErrors("ignore-ssl-errors", "Ignore SSL certificate errors");
parser.addOption(ignoreSslErrors);
QCommandLineOption helpOption = parser.addHelpOption();
OGCommandLineOptions &options = OGCommandLineOptions::getInstance();
parser.process(a);
if (parser.isSet(helpOption)) {
return 0;
}
if (parser.isSet(openInNewTabOption)) {
options.setNewTabBehavior(OGCommandLineOptions::NewTabBehavior::NewTab);
}
if (parser.isSet(replacePageOption)) {
options.setNewTabBehavior(OGCommandLineOptions::NewTabBehavior::ReplacePage);
}
if (parser.isSet(ignoreNewPageOption)) {
options.setNewTabBehavior(OGCommandLineOptions::NewTabBehavior::Ignore);
}
if (parser.isSet(ignoreSslErrors)) {
options.setIgnoreSslErrors(true);
}
QStringList positional = parser.positionalArguments();
if ( positional.length() > 0) {
options.setUrl( positional[0 ] );
}
MainWindow w;
w.show();
return a.exec();
}