From: Linus Torvalds <[email protected]> Date: Sun, 8 Feb 2015 11:35:50 -0800 Subject: [PATCH 2/5] Add 'system_default_directory()' helper function
This is just a extern "C" wrapper around QStandardPaths::AppDataLocation, while also making sure the entry exists. Signed-off-by: Linus Torvalds <[email protected]> --- pref.h | 2 ++ qthelper.cpp | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/pref.h b/pref.h index 8804ce2600f5..c33b554384c5 100644 --- a/pref.h +++ b/pref.h @@ -94,6 +94,8 @@ extern struct preferences prefs, default_prefs; extern const char *system_divelist_default_font; extern double system_divelist_default_font_size; + +extern const char *system_default_directory(void); extern const char *system_default_filename(); extern bool subsurface_ignore_font(const char *font); extern void subsurface_OS_pref_setup(); diff --git a/qthelper.cpp b/qthelper.cpp index acb1e103ab1a..db090b19411c 100644 --- a/qthelper.cpp +++ b/qthelper.cpp @@ -8,6 +8,7 @@ #include <QDir> #include <QDebug> #include <QSettings> +#include <QStandardPaths> #include <libxslt/documents.h> #define translate(_context, arg) trGettext(arg) @@ -283,6 +284,20 @@ picture_load_exit: return; } +extern "C" const char *system_default_directory(void) +{ + static char filename[PATH_MAX]; + + if (!*filename) { + QString name = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation).first(); + QDir dir(name); + dir.mkpath(name); + // Why no "dir.encodeName()"? Crazy Qt + strncpy(filename, QFile::encodeName(name), PATH_MAX-1); + } + return filename; +} + extern "C" char *get_file_name(const char *fileName) { QFileInfo fileInfo(fileName); -- 2.3.0.rc2.2.g0d1c285 _______________________________________________ subsurface mailing list [email protected] http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface
