diff options
| author | Felix (xq) Queißner <git@mq32.de> | 2020-06-28 13:11:00 +0200 |
|---|---|---|
| committer | Felix (xq) Queißner <git@mq32.de> | 2020-06-28 13:11:00 +0200 |
| commit | 0b524b7c2d0890809cc1dc835037fa1ea6674051 (patch) | |
| tree | a45ec977ccdb36bfb46bfaea45d3f71247336178 /src/main.cpp | |
| parent | 96754c53b4ff0d54f4d6c95a7c25186c58886a78 (diff) | |
| download | kristall-0b524b7c2d0890809cc1dc835037fa1ea6674051.tar.gz | |
Fixes #25 and #23, starts to implement new config/cache directory system.
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 47 |
1 files changed, 46 insertions, 1 deletions
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); |
