aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFelix (xq) Queißner <git@mq32.de>2020-06-28 13:11:00 +0200
committerFelix (xq) Queißner <git@mq32.de>2020-06-28 13:11:00 +0200
commit0b524b7c2d0890809cc1dc835037fa1ea6674051 (patch)
treea45ec977ccdb36bfb46bfaea45d3f71247336178 /src
parent96754c53b4ff0d54f4d6c95a7c25186c58886a78 (diff)
downloadkristall-0b524b7c2d0890809cc1dc835037fa1ea6674051.tar.gz
Fixes #25 and #23, starts to implement new config/cache directory system.
Diffstat (limited to 'src')
-rw-r--r--src/kristall.hpp20
-rw-r--r--src/kristall.pro2
-rw-r--r--src/main.cpp47
-rw-r--r--src/mainwindow.cpp4
4 files changed, 71 insertions, 2 deletions
diff --git a/src/kristall.hpp b/src/kristall.hpp
index e5ff24e..cbe2510 100644
--- a/src/kristall.hpp
+++ b/src/kristall.hpp
@@ -1,6 +1,7 @@
#ifndef KRISTALL_HPP
#define KRISTALL_HPP
+#include <QDir>
#include <QSettings>
#include <QClipboard>
#include <QSslCertificate>
@@ -59,4 +60,23 @@ extern SslTrust global_https_trust;
extern FavouriteCollection global_favourites;
extern GenericSettings global_options;
+///
+/// Kristall directory structure:
+/// ~/.cache/kristall/
+/// ./offline-pages/${HOST}/${HASHED_URL}
+/// : Contains "mime/type\r\n${BLOB}"
+/// ~/.config/kristall/
+/// ./themes/${THEME_ID}/theme.qss
+/// ./styles/${STYLE_ID}.ini
+/// ./config.ini
+///
+namespace kristall
+{
+ extern QDir config_root;
+ extern QDir cache_root;
+ extern QDir offline_pages;
+ extern QDir themes;
+ extern QDir styles;
+}
+
#endif // KRISTALL_HPP
diff --git a/src/kristall.pro b/src/kristall.pro
index fc2253f..d860340 100644
--- a/src/kristall.pro
+++ b/src/kristall.pro
@@ -9,6 +9,8 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets network multimedia multimediawid
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
+DEFINES += KRISTALL_VERSION="\"$(shell cd $$PWD; git describe --tags)\""
+
# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
diff --git a/src/main.cpp b/src/main.cpp
index 256ed2b..6e71917 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -7,6 +7,8 @@
#include <QCommandLineParser>
#include <QDebug>
+#include <QStandardPaths>
+
IdentityCollection global_identities;
QSettings global_settings { "xqTechnologies", "Kristall" };
QClipboard * global_clipboard;
@@ -15,19 +17,62 @@ SslTrust global_https_trust;
FavouriteCollection global_favourites;
GenericSettings global_options;
+namespace kristall
+{
+ QDir config_root;
+ QDir cache_root;
+ QDir offline_pages;
+ QDir themes;
+ QDir styles;
+}
+
QString toFingerprintString(QSslCertificate const & certificate)
{
return QCryptographicHash::hash(certificate.toDer(), QCryptographicHash::Sha256).toHex(':');
}
+#define SSTR(X) STR(X)
+#define STR(X) #X
+
+static QDir derive_dir(QDir const & parent, QString subdir)
+{
+ QDir child = parent;
+ if(not child.mkpath(subdir)) {
+ qWarning() << "failed to initialize directory:" << subdir;
+ return QDir { };
+ }
+ if(not child.cd(subdir)) {
+ qWarning() << "failed to setup directory:" << subdir;
+ return QDir { };
+ }
+ return child;
+}
+
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
+ app.setApplicationVersion(SSTR(KRISTALL_VERSION));
global_clipboard = app.clipboard();
QCommandLineParser cli_parser;
- cli_parser.parse(app.arguments());
+ cli_parser.addVersionOption();
+ cli_parser.addHelpOption();
+ cli_parser.addPositionalArgument("urls", app.tr("The urls that should be opened instead of the start page"), "[urls...]");
+
+ cli_parser.process(app);
+
+
+
+ QString cache_root = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
+ QString config_root = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
+
+ kristall::config_root = QDir { config_root };
+ kristall::cache_root = QDir { cache_root };
+
+ kristall::offline_pages = derive_dir(kristall::cache_root, "offline-pages");
+ kristall::themes = derive_dir(kristall::config_root, "themes");
+ kristall::styles = derive_dir(kristall::config_root, "styles");
global_options.load(global_settings);
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 625fc3a..885b5b4 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -112,7 +112,9 @@ BrowserTab * MainWindow::addEmptyTab(bool focus_new, bool load_default)
}
if(load_default) {
- tab->navigateTo(QUrl(global_options.start_page), BrowserTab::DontPush);
+ tab->navigateTo(QUrl(global_options.start_page), BrowserTab::PushImmediate);
+ } else {
+ tab->navigateTo(QUrl("about:blank"), BrowserTab::DontPush);
}
return tab;