summaryrefslogtreecommitdiffstats
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp55
1 files changed, 48 insertions, 7 deletions
diff --git a/src/main.cpp b/src/main.cpp
index b828d60..208a635 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -3,6 +3,7 @@
#include <QApplication>
#include <QKeyEvent>
#include <QCommandLineParser>
+#include <QTextStream>
class KeyHandler : public QObject
{
@@ -18,6 +19,8 @@ public:
}
};
+QStringList loadUrlList(const QString &file);
+
/**
* MAIN
*/
@@ -26,23 +29,61 @@ int main(int argc, char** argv)
QApplication app(argc, argv);
QCommandLineParser parser;
parser.addHelpOption();
- parser.addPositionalArgument("url", "URL to load");
- QCommandLineOption ignoreSsl("insecure", "Ignore SSL errors");
- QCommandLineOption fullscreen("fullscreen", "Run browser in full screen");
- QCommandLineOption reloadInterval("reload-interval", "Reload displayed page every X seconds", "seconds");
+ parser.addPositionalArgument("url", "URL to load.");
+ QCommandLineOption ignoreSsl("insecure", "Ignore SSL errors.");
+ QCommandLineOption fullscreen("fullscreen", "Run browser in full screen.");
+ QCommandLineOption reloadInterval("reload-interval", "Reload displayed page every X seconds.", "seconds");
+ QCommandLineOption whitelist("whitelist", "Path to a file of allowed URLs. Mutually exclusive with blacklist.", "file");
+ QCommandLineOption blacklist("blacklist", "Path to a file of disallowed URLs. Mutually exclusive with whitelist.", "file");
parser.addOption(ignoreSsl);
parser.addOption(fullscreen);
parser.addOption(reloadInterval);
+ parser.addOption(whitelist);
+ parser.addOption(blacklist);
parser.process(app);
QStringList list(parser.positionalArguments());
if (list.empty()) {
- QMessageBox::critical(NULL, "Error", "Need one argument: file name");
+ QMessageBox::critical(nullptr, "Error", "Need one argument: file name");
return 1;
}
- QString url(list[0]);
- SLXbrowser main(url, parser.isSet(fullscreen), parser.isSet(ignoreSsl), parser.value(reloadInterval).toInt());
+ if (parser.isSet(whitelist) && parser.isSet(blacklist)) {
+ QMessageBox::critical(nullptr, "Error", "Need either blacklist or whitelist, not both");
+ return 2;
+ }
+ BrowserSettings settings;
+ settings.url = list[0];
+ settings.fullscreen = parser.isSet(fullscreen);
+ settings.ignoreSslErrors = parser.isSet(ignoreSsl);
+ settings.reloadInterval = parser.value(reloadInterval).toInt();
+ if (parser.isSet(whitelist)) {
+ settings.urlList = loadUrlList(parser.value(whitelist));
+ } else if (parser.isSet(blacklist)) {
+ settings.urlList = loadUrlList(parser.value(blacklist));
+ }
+ settings.isWhitelist = parser.isSet(whitelist);
+ SLXbrowser main(settings);
main.show();
app.installEventFilter(new KeyHandler());
app.exec();
return 0;
}
+
+QStringList loadUrlList(const QString &file)
+{
+ QStringList stringList;
+ QFile textFile(file);
+ if (!textFile.open(QFile::ReadOnly)) {
+ QTextStream(stdout) << "Cannot open URL list\n";
+ return QStringList();
+ }
+ QTextStream textStream(&textFile);
+ while (true)
+ {
+ QString line = textStream.readLine();
+ if (line.isNull())
+ break;
+ else
+ stringList.append(line);
+ }
+ return stringList;
+}