From b91185f41e3dbde404118f9d584560a8ea1781c3 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Sun, 9 Apr 2017 19:09:16 +0200 Subject: [PATCH] Added option for creating "pretty" file names to clean_file_name_make_pretty() function. --- docs/d0/d8a/class_m_utils_1_1_update_checker.html | 19 ++++++-- .../class_m_utils_1_1_update_checker-members.html | 43 ++++++++-------- docs/d2/dad/_hash_8h_source.html | 2 +- docs/d3/da6/namespace_m_utils.html | 50 +++++++++++++------ docs/d4/d85/_job_object_8h_source.html | 2 +- docs/d5/d3b/_global_8h.html | 12 ++--- docs/d5/d3b/_global_8h_source.html | 6 +-- docs/d6/d83/_update_checker_8h_source.html | 2 +- docs/da/d5d/_g_u_i_8h_source.html | 2 +- docs/namespacemembers.html | 4 +- docs/namespacemembers_func.html | 4 +- docs/search/all_3.js | 4 +- docs/search/functions_1.js | 4 +- include/MUtils/Global.h | 12 +++-- src/Global.cpp | 57 +++++++++++++++++++--- 15 files changed, 153 insertions(+), 70 deletions(-) diff --git a/docs/d0/d8a/class_m_utils_1_1_update_checker.html b/docs/d0/d8a/class_m_utils_1_1_update_checker.html index c2c9734..0153c64 100644 --- a/docs/d0/d8a/class_m_utils_1_1_update_checker.html +++ b/docs/d0/d8a/class_m_utils_1_1_update_checker.html @@ -65,6 +65,7 @@ $(function() {
Public Types | +Public Slots | Signals | Public Member Functions | Public Attributes | @@ -96,11 +97,18 @@ Public Types UpdateStatus_ErrorNoConnection = 6, UpdateStatus_ErrorConnectionTestFailed = 7,
-  UpdateStatus_ErrorFetchUpdateInfo = 8 +  UpdateStatus_ErrorFetchUpdateInfo = 8, +UpdateStatus_CancelledByUser = 9
}   + + + +

+Public Slots

+void start (Priority=InheritPriority)
 

Signals

@@ -115,9 +123,9 @@ void messageLogged (co
- - + + @@ -133,6 +141,9 @@ const int  + +

Public Member Functions

UpdateChecker (const QString &binWGet, const QString &binNC, const QString &binGnuPG, const QString &binKeys, const QString &applicationId, const quint32 &installedBuildNo, const bool betaUpdates, const bool testMode=false)
 
UpdateChecker (const QString &binWGet, const QString &binMCat, const QString &binGnuPG, const QString &binKeys, const QString &applicationId, const quint32 &installedBuildNo, const bool betaUpdates, const bool testMode=false)
 
const int getUpdateStatus (void) const
 
getCurrentProgre
const UpdateCheckerInfogetUpdateInfo (void) const
 
+void cancel (void)
 
diff --git a/docs/d2/d7d/class_m_utils_1_1_update_checker-members.html b/docs/d2/d7d/class_m_utils_1_1_update_checker-members.html index b9bf2fa..2a308e4 100644 --- a/docs/d2/d7d/class_m_utils_1_1_update_checker-members.html +++ b/docs/d2/d7d/class_m_utils_1_1_update_checker-members.html @@ -70,29 +70,32 @@ $(function() {

This is the complete list of members for MUtils::UpdateChecker, including all inherited members.

Public Attributes

- - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + +
checkForUpdates(void) (defined in MUtils::UpdateChecker)MUtils::UpdateCheckerprotected
getCurrentProgress(void) const (defined in MUtils::UpdateChecker)MUtils::UpdateCheckerinline
getMaximumProgress(void) const (defined in MUtils::UpdateChecker)MUtils::UpdateCheckerinline
getSuccess(void) const (defined in MUtils::UpdateChecker)MUtils::UpdateCheckerinline
getUpdateInfo(void) const (defined in MUtils::UpdateChecker)MUtils::UpdateCheckerinline
getUpdateStatus(void) const (defined in MUtils::UpdateChecker)MUtils::UpdateCheckerinline
messageLogged(const QString &text) (defined in MUtils::UpdateChecker)MUtils::UpdateCheckersignal
progressChanged(const int progress) (defined in MUtils::UpdateChecker)MUtils::UpdateCheckersignal
run(void) (defined in MUtils::UpdateChecker)MUtils::UpdateCheckerprotected
cancel(void) (defined in MUtils::UpdateChecker)MUtils::UpdateCheckerinline
checkForUpdates(void) (defined in MUtils::UpdateChecker)MUtils::UpdateCheckerprotected
getCurrentProgress(void) const (defined in MUtils::UpdateChecker)MUtils::UpdateCheckerinline
getMaximumProgress(void) const (defined in MUtils::UpdateChecker)MUtils::UpdateCheckerinline
getSuccess(void) const (defined in MUtils::UpdateChecker)MUtils::UpdateCheckerinline
getUpdateInfo(void) const (defined in MUtils::UpdateChecker)MUtils::UpdateCheckerinline
getUpdateStatus(void) const (defined in MUtils::UpdateChecker)MUtils::UpdateCheckerinline
messageLogged(const QString &text) (defined in MUtils::UpdateChecker)MUtils::UpdateCheckersignal
progressChanged(const int progress) (defined in MUtils::UpdateChecker)MUtils::UpdateCheckersignal
run(void) (defined in MUtils::UpdateChecker)MUtils::UpdateCheckerprotected
start(Priority=InheritPriority) (defined in MUtils::UpdateChecker)MUtils::UpdateCheckerslot
statusChanged(const int status) (defined in MUtils::UpdateChecker)MUtils::UpdateCheckersignal
testKnownHosts(void) (defined in MUtils::UpdateChecker)MUtils::UpdateCheckerprotected
update_status_t (defined in MUtils::UpdateChecker)MUtils::UpdateChecker
UpdateChecker(const QString &binWGet, const QString &binNC, const QString &binGnuPG, const QString &binKeys, const QString &applicationId, const quint32 &installedBuildNo, const bool betaUpdates, const bool testMode=false) (defined in MUtils::UpdateChecker)MUtils::UpdateChecker
UpdateStatus_CheckingConnection enum value (defined in MUtils::UpdateChecker)MUtils::UpdateChecker
UpdateStatus_CompletedNewVersionOlder enum value (defined in MUtils::UpdateChecker)MUtils::UpdateChecker
UpdateStatus_CompletedNoUpdates enum value (defined in MUtils::UpdateChecker)MUtils::UpdateChecker
UpdateStatus_CompletedUpdateAvailable enum value (defined in MUtils::UpdateChecker)MUtils::UpdateChecker
UpdateStatus_ErrorConnectionTestFailed enum value (defined in MUtils::UpdateChecker)MUtils::UpdateChecker
UpdateStatus_ErrorFetchUpdateInfo enum value (defined in MUtils::UpdateChecker)MUtils::UpdateChecker
UpdateStatus_ErrorNoConnection enum value (defined in MUtils::UpdateChecker)MUtils::UpdateChecker
UpdateStatus_FetchingUpdates enum value (defined in MUtils::UpdateChecker)MUtils::UpdateChecker
UpdateStatus_NotStartedYet enum value (defined in MUtils::UpdateChecker)MUtils::UpdateChecker
~UpdateChecker(void) (defined in MUtils::UpdateChecker)MUtils::UpdateChecker
UpdateChecker(const QString &binWGet, const QString &binMCat, const QString &binGnuPG, const QString &binKeys, const QString &applicationId, const quint32 &installedBuildNo, const bool betaUpdates, const bool testMode=false) (defined in MUtils::UpdateChecker)MUtils::UpdateChecker
UpdateStatus_CancelledByUser enum value (defined in MUtils::UpdateChecker)MUtils::UpdateChecker
UpdateStatus_CheckingConnection enum value (defined in MUtils::UpdateChecker)MUtils::UpdateChecker
UpdateStatus_CompletedNewVersionOlder enum value (defined in MUtils::UpdateChecker)MUtils::UpdateChecker
UpdateStatus_CompletedNoUpdates enum value (defined in MUtils::UpdateChecker)MUtils::UpdateChecker
UpdateStatus_CompletedUpdateAvailable enum value (defined in MUtils::UpdateChecker)MUtils::UpdateChecker
UpdateStatus_ErrorConnectionTestFailed enum value (defined in MUtils::UpdateChecker)MUtils::UpdateChecker
UpdateStatus_ErrorFetchUpdateInfo enum value (defined in MUtils::UpdateChecker)MUtils::UpdateChecker
UpdateStatus_ErrorNoConnection enum value (defined in MUtils::UpdateChecker)MUtils::UpdateChecker
UpdateStatus_FetchingUpdates enum value (defined in MUtils::UpdateChecker)MUtils::UpdateChecker
UpdateStatus_NotStartedYet enum value (defined in MUtils::UpdateChecker)MUtils::UpdateChecker
~UpdateChecker(void) (defined in MUtils::UpdateChecker)MUtils::UpdateChecker
- -

§ clean_file_name()

+ +

§ clean_file_name()

@@ -211,8 +211,18 @@ class MUTILS_API Taskbar7_ MUTILS_API QString MUtils::clean_file_name ( const QString &  - name) + name, + + + + const bool &  + pretty  + + + + ) +
@@ -221,7 +231,8 @@ class MUTILS_API Taskbar7_

This function ensures that the given string is a valid file (or directory) name. It does so by replacing any illegal characters, i.e. any characters not allowed in file names (which explicitly includes directory separators). Furthermore, the function will trim/remove specific characters that are not allowed directly at the beginning or end of a file name. Finally, the function takes care of special "reserved" file names that are forbidden by the file system. You can use this function to convert user inputs into a valid file name.

Parameters
- + +
listA read-only reference to the QString holding the original, potentially invalid file name.
nameA read-only reference to the QString holding the original, potentially invalid file name.
prettyIf set to true, the function tries to generate a "pretty" file name from the given file name. Otherwise, the function simply replaces each forbidden file name character by an underscore character.
@@ -229,8 +240,8 @@ class MUTILS_API Taskbar7_
- -

§ clean_file_path()

+ +

§ clean_file_path()

@@ -239,8 +250,18 @@ class MUTILS_API Taskbar7_ MUTILS_API QString MUtils::clean_file_path ( const QString &  - path) + path, + + + + const bool &  + pretty  + + + + ) +
@@ -249,7 +270,8 @@ class MUTILS_API Taskbar7_

This function ensures that the given string is a valid file (or directory) path. It does so by replacing any illegal characters, i.e. any characters not allowed in file paths. Directory separators are preserved, but they will be "canonicalized". Furthermore, in each path component, the function will trim/remove specific characters that are not allowed directly at the beginning or end of a path component. Finally, the function takes care of special "reserved" file names that are forbidden by the file system. You can use this function to convert user inputs into a valid file path.

Parameters
- + +
listA read-only reference to the QString holding the original, potentially invalid file path.
pathA read-only reference to the QString holding the original, potentially invalid file path.
prettyIf set to true, the function tries to generate "pretty" file names from the given file names. Otherwise, the function simply replaces each forbidden file name character by an underscore character.
diff --git a/docs/d4/d85/_job_object_8h_source.html b/docs/d4/d85/_job_object_8h_source.html index 680e9bf..254f51e 100644 --- a/docs/d4/d85/_job_object_8h_source.html +++ b/docs/d4/d85/_job_object_8h_source.html @@ -70,7 +70,7 @@ $(function() { Go to the documentation of this file.
1 // MuldeR's Utilities for Qt
3 // Copyright (C) 2004-2017 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //
19 // http://www.gnu.org/licenses/lgpl-2.1.txt
21 
31 #pragma once
32 
33 #include <MUtils/Global.h>
34 
35 class QProcess;
36 
37 namespace MUtils
38 {
46  class MUTILS_API JobObject
47  {
48  public:
54  JobObject(void);
55 
61  ~JobObject(void);
62 
70  bool isObjectCreated(void);
71 
81  bool addProcessToJob(const QProcess *const process);
82 
92  bool terminateJob(const quint32 &exitCode);
93 
94  private:
95  uintptr_t m_jobPtr;
97  };
98 }
This file contains miscellaneous functions that are generally useful for Qt-based applications...
This class represents a job object.
Definition: JobObject.h:46
Global MUtils namespace.
Definition: CPUFeatures.h:37
-
#define MUTILS_NO_COPY(CLASS)
Disables copy constructor and assignment operator in the specified class. This macro should be used i...
Definition: Global.h:362
+
#define MUTILS_NO_COPY(CLASS)
Disables copy constructor and assignment operator in the specified class. This macro should be used i...
Definition: Global.h:366
-Go to the documentation of this file.
1 // MuldeR's Utilities for Qt
3 // Copyright (C) 2004-2017 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //
19 // http://www.gnu.org/licenses/lgpl-2.1.txt
21 
27 #pragma once
28 
29 #include <QString>
30 
31 //Forward Declarations
32 class QProcess;
33 
35 
39 //MUtils API
40 #ifdef _MSC_VER
41 # ifdef MUTILS_DLL_EXPORT
42 # define MUTILS_API __declspec(dllexport)
43 # else
44 # ifndef MUTILS_STATIC_LIB
45 # define MUTILS_API __declspec(dllimport)
46 # else
47 # define MUTILS_API /*static lib*/
48 # endif
49 # endif
50 #else
51 # define MUTILS_API
52 #endif
53 
54 #define MUTILS_MAKE_STRING_HELPER(X) #X
55 #define MUTILS_MAKE_STRING(X) MUTILS_MAKE_STRING_HELPER(X)
56 #define MUTILS_COMPILER_WARNING(TXT) __pragma(message(__FILE__ "(" MUTILS_MAKE_STRING(__LINE__) ") : warning: " TXT))
57 
58 //Check Debug Flags
59 #if defined(_DEBUG) || defined(DEBUG) || (!defined(NDEBUG))
60 # define MUTILS_DEBUG (1)
61 # if defined(NDEBUG) || defined(QT_NO_DEBUG) || (!defined(QT_DEBUG))
62 # error Inconsistent DEBUG flags have been detected!
63 # endif
64 #else
65 # define MUTILS_DEBUG (0)
66 # if (!defined(NDEBUG)) || (!defined(QT_NO_DEBUG)) || defined(QT_DEBUG)
67 # error Inconsistent DEBUG flags have been detected!
68 # endif
69 #endif
70 
71 //Check CPU options
72 #if defined(_MSC_VER) && (!defined(__INTELLISENSE__)) && (!defined(_M_X64)) && defined(_M_IX86_FP)
73  #if (_M_IX86_FP != 0)
74  #error We should not enabled SSE or SSE2 in release builds!
75  #endif
76 #endif
77 
81 
86 namespace MUtils
87 {
95  MUTILS_API const QString& temp_folder(void);
96 
110  MUTILS_API void init_process(QProcess &process, const QString &wokringDir, const bool bReplaceTempDir = true, const QStringList *const extraPaths = NULL);
111 
119  MUTILS_API quint32 next_rand_u32(void);
120 
128  MUTILS_API quint64 next_rand_u64(void);
129 
139  MUTILS_API QString next_rand_str(const bool &bLong = false);
140 
154  MUTILS_API QString make_temp_file(const QString &basePath, const QString &extension, const bool placeholder = false);
155 
171  MUTILS_API QString make_unique_file(const QString &basePath, const QString &baseName, const QString &extension, const bool fancy = false);
172 
180  MUTILS_API bool parity(quint32 value);
181 
191  MUTILS_API bool remove_file(const QString &fileName);
192 
204  MUTILS_API bool remove_directory(const QString &folderPath, const bool &recursive);
205 
215  MUTILS_API QString& trim_right(QString &str);
216 
226  MUTILS_API QString& trim_left(QString &str);
227 
237  MUTILS_API QString trim_right(const QString &str);
238 
248  MUTILS_API QString trim_left(const QString &str);
249 
259  MUTILS_API void natural_string_sort(QStringList &list, const bool bIgnoreCase);
260 
270  MUTILS_API QString clean_file_name(const QString &name);
271 
281  MUTILS_API QString clean_file_path(const QString &path);
282 
294  MUTILS_API bool regexp_parse_uint32(const QRegExp &regexp, quint32 &value);
295 
309  MUTILS_API bool regexp_parse_uint32(const QRegExp &regexp, quint32 *values, const size_t &count);
310 
320  MUTILS_API QStringList available_codepages(const bool &noAliases = true);
321 
322  //Internal
323  namespace Internal
324  {
325  MUTILS_API int selfTest(const char *const buildKey, const bool debug);
326  static const int s_selfTest = selfTest(__DATE__ "@" __TIME__, MUTILS_DEBUG);
327  }
328 }
329 
331 
334 #define MUTILS_DELETE(PTR) do { if((PTR)) { delete (PTR); (PTR) = NULL; } } while(0)
335 
338 #define MUTILS_DELETE_ARRAY(PTR) do { if((PTR)) { delete [] (PTR); (PTR) = NULL; } } while(0)
339 
342 #define MUTILS_ZERO_MEMORY(PTR) memset(&(PTR), 0, sizeof((PTR)))
343 
346 #define MUTILS_WCHR(STR) (reinterpret_cast<const wchar_t*>((STR).utf16()))
347 
350 #define MUTILS_UTF8(STR) ((STR).toUtf8().constData())
351 
354 #define MUTILS_QSTR(STR) (QString::fromUtf16(reinterpret_cast<const unsigned short*>((STR))))
355 
358 #define MUTILS_BOOL2STR(X) ((X) ? "1" : "0")
359 
362 #define MUTILS_NO_COPY(CLASS) \
363  CLASS(const CLASS &) { throw "Copy constructor is disabled!"; } \
364  CLASS &operator=(const CLASS &) { throw "Assignment operator is disabled!"; }
MUTILS_API QStringList available_codepages(const bool &noAliases=true)
Retrieve a list of all available codepages.
+Go to the documentation of this file.
1 // MuldeR's Utilities for Qt
3 // Copyright (C) 2004-2017 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //
19 // http://www.gnu.org/licenses/lgpl-2.1.txt
21 
27 #pragma once
28 
29 #include <QString>
30 
31 //Forward Declarations
32 class QProcess;
33 
35 
39 //MUtils API
40 #ifdef _MSC_VER
41 # ifdef MUTILS_DLL_EXPORT
42 # define MUTILS_API __declspec(dllexport)
43 # else
44 # ifndef MUTILS_STATIC_LIB
45 # define MUTILS_API __declspec(dllimport)
46 # else
47 # define MUTILS_API /*static lib*/
48 # endif
49 # endif
50 #else
51 # define MUTILS_API
52 #endif
53 
54 #define MUTILS_MAKE_STRING_HELPER(X) #X
55 #define MUTILS_MAKE_STRING(X) MUTILS_MAKE_STRING_HELPER(X)
56 #define MUTILS_COMPILER_WARNING(TXT) __pragma(message(__FILE__ "(" MUTILS_MAKE_STRING(__LINE__) ") : warning: " TXT))
57 
58 //Check Debug Flags
59 #if defined(_DEBUG) || defined(DEBUG) || (!defined(NDEBUG))
60 # define MUTILS_DEBUG (1)
61 # if defined(NDEBUG) || defined(QT_NO_DEBUG) || (!defined(QT_DEBUG))
62 # error Inconsistent DEBUG flags have been detected!
63 # endif
64 #else
65 # define MUTILS_DEBUG (0)
66 # if (!defined(NDEBUG)) || (!defined(QT_NO_DEBUG)) || defined(QT_DEBUG)
67 # error Inconsistent DEBUG flags have been detected!
68 # endif
69 #endif
70 
71 //Check CPU options
72 #if defined(_MSC_VER) && (!defined(__INTELLISENSE__)) && (!defined(_M_X64)) && defined(_M_IX86_FP)
73  #if (_M_IX86_FP != 0)
74  #error We should not enabled SSE or SSE2 in release builds!
75  #endif
76 #endif
77 
81 
86 namespace MUtils
87 {
95  MUTILS_API const QString& temp_folder(void);
96 
110  MUTILS_API void init_process(QProcess &process, const QString &wokringDir, const bool bReplaceTempDir = true, const QStringList *const extraPaths = NULL);
111 
119  MUTILS_API quint32 next_rand_u32(void);
120 
128  MUTILS_API quint64 next_rand_u64(void);
129 
139  MUTILS_API QString next_rand_str(const bool &bLong = false);
140 
154  MUTILS_API QString make_temp_file(const QString &basePath, const QString &extension, const bool placeholder = false);
155 
171  MUTILS_API QString make_unique_file(const QString &basePath, const QString &baseName, const QString &extension, const bool fancy = false);
172 
180  MUTILS_API bool parity(quint32 value);
181 
191  MUTILS_API bool remove_file(const QString &fileName);
192 
204  MUTILS_API bool remove_directory(const QString &folderPath, const bool &recursive);
205 
215  MUTILS_API QString& trim_right(QString &str);
216 
226  MUTILS_API QString& trim_left(QString &str);
227 
237  MUTILS_API QString trim_right(const QString &str);
238 
248  MUTILS_API QString trim_left(const QString &str);
249 
259  MUTILS_API void natural_string_sort(QStringList &list, const bool bIgnoreCase);
260 
272  MUTILS_API QString clean_file_name(const QString &name, const bool &pretty);
273 
285  MUTILS_API QString clean_file_path(const QString &path, const bool &pretty);
286 
298  MUTILS_API bool regexp_parse_uint32(const QRegExp &regexp, quint32 &value);
299 
313  MUTILS_API bool regexp_parse_uint32(const QRegExp &regexp, quint32 *values, const size_t &count);
314 
324  MUTILS_API QStringList available_codepages(const bool &noAliases = true);
325 
326  //Internal
327  namespace Internal
328  {
329  MUTILS_API int selfTest(const char *const buildKey, const bool debug);
330  static const int s_selfTest = selfTest(__DATE__ "@" __TIME__, MUTILS_DEBUG);
331  }
332 }
333 
335 
338 #define MUTILS_DELETE(PTR) do { if((PTR)) { delete (PTR); (PTR) = NULL; } } while(0)
339 
342 #define MUTILS_DELETE_ARRAY(PTR) do { if((PTR)) { delete [] (PTR); (PTR) = NULL; } } while(0)
343 
346 #define MUTILS_ZERO_MEMORY(PTR) memset(&(PTR), 0, sizeof((PTR)))
347 
350 #define MUTILS_WCHR(STR) (reinterpret_cast<const wchar_t*>((STR).utf16()))
351 
354 #define MUTILS_UTF8(STR) ((STR).toUtf8().constData())
355 
358 #define MUTILS_QSTR(STR) (QString::fromUtf16(reinterpret_cast<const unsigned short*>((STR))))
359 
362 #define MUTILS_BOOL2STR(X) ((X) ? "1" : "0")
363 
366 #define MUTILS_NO_COPY(CLASS) \
367  CLASS(const CLASS &) { throw "Copy constructor is disabled!"; } \
368  CLASS &operator=(const CLASS &) { throw "Assignment operator is disabled!"; }
MUTILS_API QStringList available_codepages(const bool &noAliases=true)
Retrieve a list of all available codepages.
MUTILS_API QString next_rand_str(const bool &bLong=false)
Generates a random string.
MUTILS_API bool remove_file(const QString &fileName)
Deletes the specified file.
+
MUTILS_API QString clean_file_path(const QString &path, const bool &pretty)
Clean up a file path string.
MUTILS_API void natural_string_sort(QStringList &list, const bool bIgnoreCase)
Sort a list of strings using "natural ordering" algorithm.
MUTILS_API bool regexp_parse_uint32(const QRegExp &regexp, quint32 &value)
Parse regular expression results.
-
MUTILS_API QString clean_file_name(const QString &name)
Clean up a file name string.
MUTILS_API bool parity(quint32 value)
Computes the parity of the given unsigned 32-Bit value.
MUTILS_API quint64 next_rand_u64(void)
Generates a random unsigned 64-Bit value.
MUTILS_API void init_process(QProcess &process, const QString &wokringDir, const bool bReplaceTempDir=true, const QStringList *const extraPaths=NULL)
Initialize a given QProcess object.
MUTILS_API QString & trim_right(QString &str)
Remove trailing white-space characters.
MUTILS_API const QString & temp_folder(void)
Rerieves the full path of the application&#39;s Temp folder.
Global MUtils namespace.
Definition: CPUFeatures.h:37
+
MUTILS_API QString clean_file_name(const QString &name, const bool &pretty)
Clean up a file name string.
MUTILS_API quint32 next_rand_u32(void)
Generates a random unsigned 32-Bit value.
MUTILS_API QString make_unique_file(const QString &basePath, const QString &baseName, const QString &extension, const bool fancy=false)
Generates a unique file name.
MUTILS_API bool remove_directory(const QString &folderPath, const bool &recursive)
Recursively deletes the specified directory.
MUTILS_API QString make_temp_file(const QString &basePath, const QString &extension, const bool placeholder=false)
Generates a temporary file name.
MUTILS_API QString & trim_left(QString &str)
Remove leading white-space characters.
-
MUTILS_API QString clean_file_path(const QString &path)
Clean up a file path string.
-
1 // MuldeR's Utilities for Qt
3 // Copyright (C) 2004-2017 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //
19 // http://www.gnu.org/licenses/lgpl-2.1.txt
21 
22 #pragma once
23 
24 //MUtils
25 #include <MUtils/Global.h>
26 
27 //Qt
28 #include <QThread>
29 #include <QDate>
30 
32 
33 namespace MUtils
34 {
35  class MUTILS_API UpdateCheckerInfo
36  {
37  friend class UpdateChecker;
38 
39  public:
40  UpdateCheckerInfo(void);
41  void resetInfo(void);
42  bool isComplete(void);
43 
44  const quint32 &getBuildNo(void) const { return m_buildNo; }
45  const QDate &getBuildDate(void) const { return m_buildDate; }
46  const QString &getDownloadSite(void) const { return m_downloadSite; }
47  const QString &getDownloadAddress(void) const { return m_downloadAddress; }
48  const QString &getDownloadFilename(void) const { return m_downloadFilename; }
49  const QString &getDownloadFilecode(void) const { return m_downloadFilecode; }
50  const QString &getDownloadChecksum(void) const { return m_downloadChecksum; }
51 
52  private:
53  quint32 m_buildNo;
54  QDate m_buildDate;
55  QString m_downloadSite;
56  QString m_downloadAddress;
57  QString m_downloadFilename;
58  QString m_downloadFilecode;
59  QString m_downloadChecksum;
60  };
61 
62  // ----------------------------------------------------------------
63 
64  class MUTILS_API UpdateChecker : public QThread
65  {
66  Q_OBJECT
67 
68  public:
69  enum
70  {
71  UpdateStatus_NotStartedYet = 0,
72  UpdateStatus_CheckingConnection = 1,
73  UpdateStatus_FetchingUpdates = 2,
74  UpdateStatus_CompletedUpdateAvailable = 3,
75  UpdateStatus_CompletedNoUpdates = 4,
76  UpdateStatus_CompletedNewVersionOlder = 5,
77  UpdateStatus_ErrorNoConnection = 6,
78  UpdateStatus_ErrorConnectionTestFailed = 7,
79  UpdateStatus_ErrorFetchUpdateInfo = 8
80  }
81  update_status_t;
82 
83  UpdateChecker(const QString &binWGet, const QString &binNC, const QString &binGnuPG, const QString &binKeys, const QString &applicationId, const quint32 &installedBuildNo, const bool betaUpdates, const bool testMode = false);
84  ~UpdateChecker(void);
85 
86  const int getUpdateStatus(void) const { return m_status; }
87  const bool getSuccess(void) const { return m_success; };
88  const int getMaximumProgress(void) const { return m_maxProgress; };
89  const int getCurrentProgress(void) const { return m_progress; };
90  const UpdateCheckerInfo *getUpdateInfo(void) const { return m_updateInfo.data(); }
91 
92  protected:
93  void run(void);
94  void checkForUpdates(void);
95  void testKnownHosts(void);
96 
97  signals:
98  void statusChanged(const int status);
99  void progressChanged(const int progress);
100  void messageLogged(const QString &text);
101 
102  private:
103  const int m_maxProgress;
104  QScopedPointer<UpdateCheckerInfo> m_updateInfo;
105 
106  const bool m_betaUpdates;
107  const bool m_testMode;
108 
109  const QString m_applicationId;
110  const quint32 m_installedBuildNo;
111 
112  const QString m_binaryWGet;
113  const QString m_binaryNC;
114  const QString m_binaryGnuPG;
115  const QString m_binaryKeys;
116 
117  volatile bool m_success;
118 
119  int m_status;
120  int m_progress;
121 
122  inline void setStatus(const int status);
123  inline void setProgress(const int progress);
124  inline void log(const QString &str1, const QString &str2 = QString(), const QString &str3 = QString(), const QString &str4 = QString());
125 
126  bool getUpdateInfo(const QString &url, const QString &outFileVers, const QString &outFileSign);
127  bool tryContactHost(const QString &hostname);
128  bool parseVersionInfo(const QString &file, UpdateCheckerInfo *updateInfo);
129 
130  bool getFile(const QString &url, const QString &outFile, const unsigned int maxRedir = 5U, bool *httpOk = NULL);
131  bool getFile(const QString &url, const bool forceIp4, const QString &outFile, const unsigned int maxRedir = 5U, bool *httpOk = NULL);
132  bool checkSignature(const QString &file, const QString &signature);
133  bool tryUpdateMirror(UpdateCheckerInfo *updateInfo, const QString &url);
134  };
135 }
This file contains miscellaneous functions that are generally useful for Qt-based applications...
+
1 // MuldeR's Utilities for Qt
3 // Copyright (C) 2004-2017 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //
19 // http://www.gnu.org/licenses/lgpl-2.1.txt
21 
22 #pragma once
23 
24 //MUtils
25 #include <MUtils/Global.h>
26 
27 //Qt
28 #include <QThread>
29 #include <QDate>
30 
32 
33 namespace MUtils
34 {
35  class MUTILS_API UpdateCheckerInfo
36  {
37  friend class UpdateChecker;
38 
39  public:
40  UpdateCheckerInfo(void);
41  void resetInfo(void);
42  bool isComplete(void);
43 
44  const quint32 &getBuildNo(void) const { return m_buildNo; }
45  const QDate &getBuildDate(void) const { return m_buildDate; }
46  const QString &getDownloadSite(void) const { return m_downloadSite; }
47  const QString &getDownloadAddress(void) const { return m_downloadAddress; }
48  const QString &getDownloadFilename(void) const { return m_downloadFilename; }
49  const QString &getDownloadFilecode(void) const { return m_downloadFilecode; }
50  const QString &getDownloadChecksum(void) const { return m_downloadChecksum; }
51 
52  private:
53  quint32 m_buildNo;
54  QDate m_buildDate;
55  QString m_downloadSite;
56  QString m_downloadAddress;
57  QString m_downloadFilename;
58  QString m_downloadFilecode;
59  QString m_downloadChecksum;
60  };
61 
62  // ----------------------------------------------------------------
63 
64  class MUTILS_API UpdateChecker : public QThread
65  {
66  Q_OBJECT
67 
68  public:
69  enum
70  {
71  UpdateStatus_NotStartedYet = 0,
72  UpdateStatus_CheckingConnection = 1,
73  UpdateStatus_FetchingUpdates = 2,
74  UpdateStatus_CompletedUpdateAvailable = 3,
75  UpdateStatus_CompletedNoUpdates = 4,
76  UpdateStatus_CompletedNewVersionOlder = 5,
77  UpdateStatus_ErrorNoConnection = 6,
78  UpdateStatus_ErrorConnectionTestFailed = 7,
79  UpdateStatus_ErrorFetchUpdateInfo = 8,
80  UpdateStatus_CancelledByUser = 9
81  }
82  update_status_t;
83 
84  UpdateChecker(const QString &binWGet, const QString &binMCat, const QString &binGnuPG, const QString &binKeys, const QString &applicationId, const quint32 &installedBuildNo, const bool betaUpdates, const bool testMode = false);
85  ~UpdateChecker(void);
86 
87  const int getUpdateStatus(void) const { return m_status; }
88  const bool getSuccess(void) const { return m_success; };
89  const int getMaximumProgress(void) const { return m_maxProgress; };
90  const int getCurrentProgress(void) const { return m_progress; };
91  const UpdateCheckerInfo *getUpdateInfo(void) const { return m_updateInfo.data(); }
92 
93  void cancel(void) { m_cancelled = true; }
94 
95  public slots:
96  void start(Priority = InheritPriority);
97 
98  protected:
99  void run(void);
100  void checkForUpdates(void);
101  void testKnownHosts(void);
102 
103  signals:
104  void statusChanged(const int status);
105  void progressChanged(const int progress);
106  void messageLogged(const QString &text);
107 
108  private:
109  const int m_maxProgress;
110  QScopedPointer<UpdateCheckerInfo> m_updateInfo;
111 
112  const bool m_betaUpdates;
113  const bool m_testMode;
114 
115  const QString m_applicationId;
116  const quint32 m_installedBuildNo;
117 
118  const QString m_binaryWGet;
119  const QString m_binaryMCat;
120  const QString m_binaryGnuPG;
121  const QString m_binaryKeys;
122 
123  volatile bool m_success;
124  volatile bool m_cancelled;
125 
126  int m_status;
127  int m_progress;
128 
129  inline void setStatus(const int status);
130  inline void setProgress(const int progress);
131  inline void log(const QString &str1, const QString &str2 = QString(), const QString &str3 = QString(), const QString &str4 = QString());
132 
133  bool getUpdateInfo(const QString &url, const QString &outFileVers, const QString &outFileSign);
134  bool tryContactHost(const QString &hostname, const int &timeoutMsec);
135  bool parseVersionInfo(const QString &file, UpdateCheckerInfo *updateInfo);
136 
137  bool getFile(const QString &url, const QString &outFile, const unsigned int maxRedir = 5U);
138  bool getFile(const QString &url, const bool forceIp4, const QString &outFile, const unsigned int maxRedir = 5U);
139  bool checkSignature(const QString &file, const QString &signature);
140  bool tryUpdateMirror(UpdateCheckerInfo *updateInfo, const QString &url, const bool &quick);
141  };
142 }
This file contains miscellaneous functions that are generally useful for Qt-based applications...
Definition: UpdateChecker.h:35
Global MUtils namespace.
Definition: CPUFeatures.h:37
Definition: UpdateChecker.h:64
diff --git a/docs/da/d5d/_g_u_i_8h_source.html b/docs/da/d5d/_g_u_i_8h_source.html index 03640ae..f26d62b 100644 --- a/docs/da/d5d/_g_u_i_8h_source.html +++ b/docs/da/d5d/_g_u_i_8h_source.html @@ -67,7 +67,7 @@ $(function() {
GUI.h
-
1 // MuldeR's Utilities for Qt
3 // Copyright (C) 2004-2017 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //
19 // http://www.gnu.org/licenses/lgpl-2.1.txt
21 
22 #pragma once
23 
24 //MUtils
25 #include <MUtils/Global.h>
26 
27 //Qt
28 #include <QColor>
29 
30 //Forward Declaration
31 class QIcon;
32 class QWidget;
33 
35 
36 namespace MUtils
37 {
38  namespace GUI
39  {
40  typedef enum
41  {
42  USER_EVENT = 1000, /*QEvent::User*/
43  USER_EVENT_QUERYENDSESSION = USER_EVENT + 666,
44  USER_EVENT_ENDSESSION = USER_EVENT + 667
45  }
46  user_events_t;
47 
48  typedef enum
49  {
50  SYSCOLOR_TEXT = 1,
51  SYSCOLOR_BACKGROUND = 2,
52  SYSCOLOR_CAPTION = 3
53  }
54  system_color_t;
55 
56  //Broadcast message
57  MUTILS_API bool broadcast(int eventType, const bool &onlyToVisible);
58 
59  //Window icon
60  MUTILS_API bool set_window_icon(QWidget *const window, const QIcon &icon, const bool bIsBigIcon);
61 
62  //Theme support
63  MUTILS_API bool themes_enabled(void);
64 
65  //System menu
66  MUTILS_API bool sysmenu_append(const QWidget *const win, const unsigned int identifier, const QString &text);
67  MUTILS_API bool sysmenu_update(const QWidget *const win, const unsigned int identifier, const QString &text);
68  MUTILS_API bool sysmenu_check_msg(void *const message, const unsigned int &identifier);
69 
70  //Close button
71  MUTILS_API bool enable_close_button(const QWidget *const win, const bool &bEnable);
72 
73  //Bring to front
74  MUTILS_API bool bring_to_front(const QWidget *const window);
75  MUTILS_API bool bring_to_front(const unsigned long pid);
76 
77  //Sheet of glass
78  MUTILS_API bool sheet_of_glass(QWidget *const window);
79  MUTILS_API bool sheet_of_glass_update(QWidget *const window);
80 
81  //System colors
82  MUTILS_API QColor system_color(const int &color_id);
83 
84  //Blink window
85  MUTILS_API void blink_window(QWidget *const poWindow, const unsigned int &count = 10, const unsigned int &delay = 150);
86 
87  //Force quit application
88  MUTILS_API void force_quit(void);
89  }
90 }
91 
This file contains miscellaneous functions that are generally useful for Qt-based applications...
+
1 // MuldeR's Utilities for Qt
3 // Copyright (C) 2004-2017 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //
19 // http://www.gnu.org/licenses/lgpl-2.1.txt
21 
22 #pragma once
23 
24 //MUtils
25 #include <MUtils/Global.h>
26 
27 //Qt
28 #include <QColor>
29 
30 //Forward Declaration
31 class QIcon;
32 class QWidget;
33 
35 
36 namespace MUtils
37 {
38  namespace GUI
39  {
40  typedef enum
41  {
42  USER_EVENT = 1000, /*QEvent::User*/
43  USER_EVENT_QUERYENDSESSION = USER_EVENT + 666,
44  USER_EVENT_ENDSESSION = USER_EVENT + 667
45  }
46  user_events_t;
47 
48  typedef enum
49  {
50  SYSCOLOR_TEXT = 1,
51  SYSCOLOR_BACKGROUND = 2,
52  SYSCOLOR_CAPTION = 3
53  }
54  system_color_t;
55 
56  //Broadcast message
57  MUTILS_API bool broadcast(int eventType, const bool &onlyToVisible);
58 
59  //Window icon
60  MUTILS_API bool set_window_icon(QWidget *const window, const QIcon &icon, const bool bIsBigIcon);
61 
62  //Theme support
63  MUTILS_API bool themes_enabled(void);
64 
65  //DPI information
66  MUTILS_API double dpi_scale(void);
67  MUTILS_API bool scale_widget(QWidget *const widget, const bool recenter = true);
68  MUTILS_API bool center_widget(QWidget *const widget);
69 
70  //System menu
71  MUTILS_API bool sysmenu_append(const QWidget *const win, const unsigned int identifier, const QString &text);
72  MUTILS_API bool sysmenu_update(const QWidget *const win, const unsigned int identifier, const QString &text);
73  MUTILS_API bool sysmenu_check_msg(void *const message, const unsigned int &identifier);
74 
75  //Close button
76  MUTILS_API bool enable_close_button(const QWidget *const win, const bool &bEnable);
77 
78  //Bring to front
79  MUTILS_API bool bring_to_front(const QWidget *const window);
80  MUTILS_API bool bring_to_front(const unsigned long pid);
81 
82  //Sheet of glass
83  MUTILS_API bool sheet_of_glass(QWidget *const window);
84  MUTILS_API bool sheet_of_glass_update(QWidget *const window);
85 
86  //System colors
87  MUTILS_API QColor system_color(const int &color_id);
88 
89  //Blink window
90  MUTILS_API void blink_window(QWidget *const poWindow, const unsigned int &count = 10, const unsigned int &delay = 150);
91 
92  //Force quit application
93  MUTILS_API void force_quit(void);
94  }
95 }
96 
This file contains miscellaneous functions that are generally useful for Qt-based applications...
Global MUtils namespace.
Definition: CPUFeatures.h:37
diff --git a/docs/namespacemembers.html b/docs/namespacemembers.html index 3b6989e..a03b3db 100644 --- a/docs/namespacemembers.html +++ b/docs/namespacemembers.html @@ -70,10 +70,10 @@ $(function() {

- c -

  • clean_file_name() -: MUtils +: MUtils
  • clean_file_path() -: MUtils +: MUtils
  • cpu_info_t : MUtils::CPUFetaures diff --git a/docs/namespacemembers_func.html b/docs/namespacemembers_func.html index adcad69..5a644a3 100644 --- a/docs/namespacemembers_func.html +++ b/docs/namespacemembers_func.html @@ -64,10 +64,10 @@ $(function() { : MUtils
  • clean_file_name() -: MUtils +: MUtils
  • clean_file_path() -: MUtils +: MUtils
  • detect() : MUtils::CPUFetaures diff --git a/docs/search/all_3.js b/docs/search/all_3.js index 53083cf..428ac0e 100644 --- a/docs/search/all_3.js +++ b/docs/search/all_3.js @@ -1,7 +1,7 @@ var searchData= [ - ['clean_5ffile_5fname',['clean_file_name',['../d3/da6/namespace_m_utils.html#afd8eb699de88edd73e47fe2e41873385',1,'MUtils']]], - ['clean_5ffile_5fpath',['clean_file_path',['../d3/da6/namespace_m_utils.html#ad801fab93087c31d764ad15295fe3a88',1,'MUtils']]], + ['clean_5ffile_5fname',['clean_file_name',['../d3/da6/namespace_m_utils.html#aeb7783b8ecbe163501ce60dce8b6709f',1,'MUtils']]], + ['clean_5ffile_5fpath',['clean_file_path',['../d3/da6/namespace_m_utils.html#adb5da6435b27e10443060dd2550784f3',1,'MUtils']]], ['count',['count',['../dd/de2/struct_m_utils_1_1_c_p_u_fetaures_1_1__cpu__info__t.html#a7861529c47568141daa37810ebb499ea',1,'MUtils::CPUFetaures::_cpu_info_t']]], ['cpu_5finfo_5ft',['cpu_info_t',['../d3/d02/namespace_m_utils_1_1_c_p_u_fetaures.html#a8b80fb34713dbc70a63ae5cd48b0630e',1,'MUtils::CPUFetaures']]], ['cpufeatures_2eh',['CPUFeatures.h',['../d2/db5/_c_p_u_features_8h.html',1,'']]], diff --git a/docs/search/functions_1.js b/docs/search/functions_1.js index 625c19d..e8c9edd 100644 --- a/docs/search/functions_1.js +++ b/docs/search/functions_1.js @@ -1,6 +1,6 @@ var searchData= [ - ['clean_5ffile_5fname',['clean_file_name',['../d3/da6/namespace_m_utils.html#afd8eb699de88edd73e47fe2e41873385',1,'MUtils']]], - ['clean_5ffile_5fpath',['clean_file_path',['../d3/da6/namespace_m_utils.html#ad801fab93087c31d764ad15295fe3a88',1,'MUtils']]], + ['clean_5ffile_5fname',['clean_file_name',['../d3/da6/namespace_m_utils.html#aeb7783b8ecbe163501ce60dce8b6709f',1,'MUtils']]], + ['clean_5ffile_5fpath',['clean_file_path',['../d3/da6/namespace_m_utils.html#adb5da6435b27e10443060dd2550784f3',1,'MUtils']]], ['create',['create',['../d2/dad/_hash_8h.html#a330b73d6927d6cd95892712f9396f40e',1,'MUtils::Hash']]] ]; diff --git a/include/MUtils/Global.h b/include/MUtils/Global.h index b84d9a8..3acb912 100644 --- a/include/MUtils/Global.h +++ b/include/MUtils/Global.h @@ -263,22 +263,26 @@ namespace MUtils * * This function ensures that the given string is a valid file (or directory) name. It does so by replacing any illegal characters, i.e. any characters *not* allowed in file names (which explicitly *includes* directory separators). Furthermore, the function will trim/remove specific characters that are *not* allowed directly at the beginning or end of a file name. Finally, the function takes care of special "reserved" file names that are forbidden by the file system. You can use this function to convert user inputs into a valid file name. * - * \param list A read-only reference to the QString holding the original, potentially invalid file name. + * \param name A read-only reference to the QString holding the original, potentially invalid file name. + * + * \param pretty If set to `true`, the function tries to generate a "pretty" file name from the given file name. Otherwise, the function simply replaces each forbidden file name character by an underscore character. * * \return The function returns a QString holding a valid file name. If, however, the input string was empty or contained only white-space characters, the returned sting can be empty. */ - MUTILS_API QString clean_file_name(const QString &name); + MUTILS_API QString clean_file_name(const QString &name, const bool &pretty); /** * \brief Clean up a file path string * * This function ensures that the given string is a valid file (or directory) path. It does so by replacing any illegal characters, i.e. any characters *not* allowed in file paths. Directory separators are preserved, but they will be "canonicalized". Furthermore, in each path component, the function will trim/remove specific characters that are *not* allowed directly at the beginning or end of a path component. Finally, the function takes care of special "reserved" file names that are forbidden by the file system. You can use this function to convert user inputs into a valid file path. * - * \param list A read-only reference to the QString holding the original, potentially invalid file path. + * \param path A read-only reference to the QString holding the original, potentially invalid file path. + * + * \param pretty If set to `true`, the function tries to generate "pretty" file names from the given file names. Otherwise, the function simply replaces each forbidden file name character by an underscore character. * * \return The function returns a QString holding a valid file path. If, however, the input string was empty or contained only white-space characters, the returned sting can be empty. */ - MUTILS_API QString clean_file_path(const QString &path); + MUTILS_API QString clean_file_path(const QString &path, const bool &pretty); /** * \brief Parse regular expression results diff --git a/src/Global.cpp b/src/Global.cpp index dc48e84..248309a 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -561,7 +561,52 @@ void MUtils::natural_string_sort(QStringList &list, const bool bIgnoreCase) // CLEAN FILE PATH /////////////////////////////////////////////////////////////////////////////// -QString MUtils::clean_file_name(const QString &name) +static QMutex g_clean_file_name_mutex; +static QScopedPointer>> g_clean_file_name_regex; + +static void clean_file_name_make_pretty(QString &str) +{ + static const struct { const char *p; const char *r; } PATTERN[] = + { + { "^\\s*\"([^\"]*)\"\\s*$", "\\1" }, //Remove straight double quotes around the whole string + { "\"([^\"]*)\"", "\xE2\x80\x9C\\1\xE2\x80\x9D" }, //Replace remaining pairs of straight double quotes with opening/closing double quote + { "^[\\\\/:]+([^\\\\/:]+.*)$", "\\1" }, //Remove leading slash, backslash and colon characters + { "^(.*[^\\\\/:]+)[\\\\/:]+$", "\\1" }, //Remove trailing slash, backslash and colon characters + { "(\\s*[\\\\/:]\\s*)+", " - " }, //Replace any slash, backslash or colon character that appears in the middle + { NULL, NULL } + }; + + QMutexLocker locker(&g_clean_file_name_mutex); + + if (g_clean_file_name_regex.isNull()) + { + QScopedPointer>> list(new QList>()); + for (size_t i = 0; PATTERN[i].p; ++i) + { + list->append(qMakePair(QRegExp(QString::fromUtf8(PATTERN[i].p), Qt::CaseInsensitive), PATTERN[i].r ? QString::fromUtf8(PATTERN[i].r) : QString())); + } + g_clean_file_name_regex.reset(list.take()); + } + + bool keepOnGoing = !str.isEmpty(); + while(keepOnGoing) + { + const QString prev = str; + keepOnGoing = false; + for (QList>::ConstIterator iter = g_clean_file_name_regex->constBegin(); iter != g_clean_file_name_regex->constEnd(); ++iter) + { + str.replace(iter->first, iter->second); + if (str.compare(prev)) + { + keepOnGoing = !str.isEmpty(); + break; + } + } + str = str.simplified(); + } +} + +QString MUtils::clean_file_name(const QString &name, const bool &pretty) { static const QLatin1Char REPLACEMENT_CHAR('_'); static const char FILENAME_ILLEGAL_CHARS[] = "<>:\"/\\|?*"; @@ -573,11 +618,9 @@ QString MUtils::clean_file_name(const QString &name) }; QString result(name); - if (result.contains(QLatin1Char('"'))) + if (pretty) { - QRegExp quoted("\"(.+)\""); - quoted.setMinimal(true); - result.replace(quoted, "``\\1ยดยด"); + clean_file_name_make_pretty(result); } for(QString::Iterator iter = result.begin(); iter != result.end(); iter++) @@ -630,7 +673,7 @@ static QPair clean_file_path_get_prefix(const QString path) return qMakePair(QString(), posixPath); } -QString MUtils::clean_file_path(const QString &path) +QString MUtils::clean_file_path(const QString &path, const bool &pretty) { const QPair prefix = clean_file_path_get_prefix(path); @@ -641,7 +684,7 @@ QString MUtils::clean_file_path(const QString &path) { continue; //handle case "c:\" } - parts[i] = MUtils::clean_file_name(parts[i]); + parts[i] = MUtils::clean_file_name(parts[i], pretty); } const QString cleanPath = parts.join(QLatin1String("/")); -- 2.11.0