From 60403202df6c8dbd46b8addc1978dc0daf635348 Mon Sep 17 00:00:00 2001 From: Martchus Date: Mon, 19 Dec 2016 23:38:32 +0100 Subject: [PATCH] Add function to convert QString to native filename --- CMakeLists.txt | 5 +++-- misc/conversion.h | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 misc/conversion.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 96e4e0b..02e3329 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,7 @@ set(HEADER_FILES misc/adoptlocker.h misc/dialogutils.h misc/desktoputils.h + misc/conversion.h models/checklistmodel.h resources/qtconfigarguments.h resources/resources.h @@ -113,7 +114,7 @@ set(META_APP_AUTHOR "Martchus") set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}") set(META_APP_DESCRIPTION "Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models") set(META_VERSION_MAJOR 5) -set(META_VERSION_MINOR 2) +set(META_VERSION_MINOR 3) set(META_VERSION_PATCH 0) set(META_APP_VERSION ${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}) @@ -146,7 +147,7 @@ if(DBUS_NOTIFICATIONS) list(APPEND DBUS_FILES dbus/org.freedesktop.Notifications.xml ) - list(APPEND META_PUBLIC_COMPILE_DEFINITIONS QT_UTILITIES_SUPPORT_DBUS_NOTIFICATIONS) + list(APPEND META_PUBLIC_COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_SUPPORT_DBUS_NOTIFICATIONS) message(STATUS "D-Bus notifications enabled") else() list(APPEND DOC_ONLY_FILES diff --git a/misc/conversion.h b/misc/conversion.h new file mode 100644 index 0000000..53b74dc --- /dev/null +++ b/misc/conversion.h @@ -0,0 +1,41 @@ +#ifndef CONVERSION_H +#define CONVERSION_H + +#include "../global.h" + +#include + +#include + +namespace ConversionUtilities { + +inline QByteArray toNativeFileName(const QString &fileName) +{ +#if !defined(PLATFORM_MINGW) || !defined(CPP_UTILITIES_USE_NATIVE_FILE_BUFFER) + return fileName.toLocal8Bit(); +#else + return fileName.toUtf8(); +#endif +} + +inline QString fromNativeFileName(const char *nativeFileName, int size = -1) +{ +#if !defined(PLATFORM_MINGW) || !defined(CPP_UTILITIES_USE_NATIVE_FILE_BUFFER) + return QString::fromLocal8Bit(nativeFileName, size); +#else + return QString::fromUtf8(nativeFileName, size); +#endif +} + +inline QString fromNativeFileName(const std::string &nativeFileName) +{ +#if !defined(PLATFORM_MINGW) || !defined(CPP_UTILITIES_USE_NATIVE_FILE_BUFFER) + return QString::fromLocal8Bit(nativeFileName.data(), static_cast(nativeFileName.size())); +#else + return QString::fromUtf8(nativeFileName.data(), static_cast(nativeFileName.size())); +#endif +} + +} // namespace Dialogs + +#endif // CONVERSION_H