annotate src/SettingsPaths.cpp @ 674:06450e6542ee

Avoiding a memory leak in the SettingsPaths class. git-svn-id: svn://svn.code.sf.net/p/universalindent/code/trunk@940 59b1889a-e5ac-428c-b0c7-476e01d41282
author thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
date Sun, 15 Feb 2009 12:58:42 +0000
parents b964e594c0a4
children b4aee13bc733
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
674
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
1 /***************************************************************************
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
2 * Copyright (C) 2006-2009 by Thomas Schweitzer *
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
3 * thomas-schweitzer(at)arcor.de *
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
4 * *
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
5 * This program is free software; you can redistribute it and/or modify *
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
6 * it under the terms of the GNU General Public License version 2.0 as *
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
7 * published by the Free Software Foundation. *
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
8 * *
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
9 * This program is distributed in the hope that it will be useful, *
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
12 * GNU General Public License for more details. *
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
13 * *
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
14 * You should have received a copy of the GNU General Public License *
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
15 * along with this program in the file LICENSE.GPL; if not, write to the *
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
16 * Free Software Foundation, Inc., *
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
18 ***************************************************************************/
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
19
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
20
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
21 #include <stdlib.h>
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
22 #include <QDirIterator>
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
23 #include <QStack>
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
24 #include <QtDebug>
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
25
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
26 #include "SettingsPaths.h"
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
27
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
28
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
29 //! \defgroup grp_Settings All concerning applications settings.
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
30
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
31 /*!
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
32 \class SettingsPaths
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
33 \ingroup grp_Settings
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
34 \brief SettingsPaths is a pure static functions class from which info about the
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
35 paths needed for settings can be retrieved.
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
36 */
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
37
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
38 bool SettingsPaths::alreadyInitialized = false;
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
39 QString SettingsPaths::applicationBinaryPath = "";
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
40 QString SettingsPaths::settingsPath = "";
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
41 QString SettingsPaths::globalFilesPath = "";
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
42 QString SettingsPaths::indenterPath = "";
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
43 QString SettingsPaths::tempPath = "";
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
44 bool SettingsPaths::portableMode = false;
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
45
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
46
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
47 /*!
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
48 \brief Initializes all available information about the paths.
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
49
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
50 Mainly during this init it is detected whether to start in portable mode or not. This is
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
51 done by testing whether the directory "config" is in the same directory as this
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
52 applications executable file.
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
53 In portable mode all data is ONLY written to subdirectories of the applications executable file.
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
54 Means also that the directory "indenters" has to be there.
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
55 In not portable mode (multiuser mode) only users home directory is used for writing config data.
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
56 */
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
57 void SettingsPaths::init() {
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
58 // Get the applications binary path, with respect to MacOSXs use of the .app folder.
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
59 applicationBinaryPath = QCoreApplication::applicationDirPath();
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
60 // Remove any trailing slashes
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
61 while ( applicationBinaryPath.right(1) == "/" ) {
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
62 applicationBinaryPath.chop(1);
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
63 }
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
64
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
65 #ifdef UNIVERSALINDENTGUI_NPP_EXPORTS
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
66 applicationBinaryPath += "/plugins/uigui";
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
67 #endif
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
68
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
69 #ifdef Q_OS_MAC
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
70 // Because on Mac universal binaries are used, the binary path is not equal
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
71 // to the applications (.app) path. So get the .apps path here.
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
72 int indexOfDotApp = applicationBinaryPath.indexOf(".app");
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
73 if ( indexOfDotApp != -1 ) {
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
74 // Cut off after the dot of ".app".
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
75 applicationBinaryPath = applicationBinaryPath.left( indexOfDotApp-1 );
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
76 // Cut off after the first slash that was in front of ".app" (normally this is the word "UniversalIndentGUI")
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
77 applicationBinaryPath = applicationBinaryPath.left( applicationBinaryPath.lastIndexOf("/") );
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
78 }
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
79 #endif
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
80
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
81 // If the "config" directory is a subdir of the applications binary path, use this one (portable mode)
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
82 settingsPath = applicationBinaryPath + "/config";
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
83 if ( QFile::exists( settingsPath ) ) {
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
84 portableMode = true;
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
85 QDir dirCreator;
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
86 globalFilesPath = applicationBinaryPath;
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
87 indenterPath = applicationBinaryPath + "/indenters";
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
88 dirCreator.mkpath( settingsPath );
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
89 tempPath = applicationBinaryPath + "/temp";
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
90 //TODO: If the portable drive has write protection, use local temp path and clean it up on exit.
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
91 dirCreator.mkpath( tempPath );
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
92 }
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
93 // ... otherwise use the system specific global application data path.
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
94 else {
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
95 portableMode = false;
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
96 QDir dirCreator;
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
97 #ifdef Q_OS_WIN
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
98 // Get the local users application settings directory.
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
99 // Remove any trailing slashes.
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
100 settingsPath = QDir::fromNativeSeparators( qgetenv("APPDATA") );
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
101 while ( settingsPath.right(1) == "/" ) {
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
102 settingsPath.chop(1);
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
103 }
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
104 settingsPath = settingsPath + "/UniversalIndentGUI";
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
105
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
106 // On windows systems the directories "indenters", "translations" are subdirs of the applicationBinaryPath.
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
107 globalFilesPath = applicationBinaryPath;
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
108 #else
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
109 // Remove any trailing slashes.
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
110 settingsPath = QDir::homePath();
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
111 while ( settingsPath.right(1) == "/" ) {
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
112 settingsPath.chop(1);
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
113 }
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
114 settingsPath = settingsPath + "/.universalindentgui";
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
115 globalFilesPath = "/usr/share/universalindentgui";
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
116 #endif
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
117 dirCreator.mkpath( settingsPath );
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
118 // If a highlighter config file does not exist in the users home config dir
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
119 // copy the default config file over there.
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
120 if ( !QFile::exists(settingsPath+"/UiGuiSyntaxHighlightConfig.ini") ) {
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
121 QFile::copy( globalFilesPath+"/config/UiGuiSyntaxHighlightConfig.ini", settingsPath+"/UiGuiSyntaxHighlightConfig.ini" );
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
122 }
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
123 indenterPath = globalFilesPath + "/indenters";
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
124
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
125 // On different systems it may be that "QDir::tempPath()" ends with a "/" or not. So check this.
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
126 // Remove any trailing slashes.
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
127 tempPath = QDir::tempPath();
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
128 while ( tempPath.right(1) == "/" ) {
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
129 tempPath.chop(1);
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
130 }
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
131 tempPath = tempPath + "/UniversalIndentGUI";
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
132
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
133 #if defined(Q_OS_WIN32)
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
134 dirCreator.mkpath( tempPath );
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
135 #else
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
136 // On Unix based systems create a random temporary directory for security
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
137 // reasons. Otherwise an evil human being could create a symbolic link
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
138 // to an important existing file which gets overwritten when UiGUI writes
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
139 // into this normally temporary but linked file.
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
140 char *pathTemplate = new char[tempPath.length()+8];
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
141 QByteArray pathTemplateQBA = QString(tempPath + "-XXXXXX").toAscii();
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
142 delete pathTemplate;
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
143 pathTemplate = pathTemplateQBA.data();
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
144 pathTemplate = mkdtemp( pathTemplate );
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
145 tempPath = pathTemplate;
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
146 #endif
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
147 }
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
148
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
149 alreadyInitialized = true;
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
150 }
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
151
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
152
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
153 /*!
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
154 \brief Returns the path of the applications executable.
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
155 */
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
156 const QString SettingsPaths::getApplicationBinaryPath() {
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
157 if ( !alreadyInitialized ) {
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
158 SettingsPaths::init();
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
159 }
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
160 return applicationBinaryPath;
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
161 }
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
162
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
163
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
164 /*!
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
165 \brief Returns the path where all settings are being/should be written to.
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
166 */
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
167 const QString SettingsPaths::getSettingsPath() {
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
168 if ( !alreadyInitialized ) {
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
169 SettingsPaths::init();
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
170 }
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
171 return settingsPath;
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
172 }
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
173
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
174
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
175 /*!
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
176 \brief Returns the path where the files concerning all users reside. For example translations.
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
177 */
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
178 const QString SettingsPaths::getGlobalFilesPath() {
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
179 if ( !alreadyInitialized ) {
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
180 SettingsPaths::init();
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
181 }
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
182 return globalFilesPath;
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
183 }
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
184
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
185
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
186 /*!
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
187 \brief Returns the path where the indenter executables reside.
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
188 */
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
189 const QString SettingsPaths::getIndenterPath() {
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
190 if ( !alreadyInitialized ) {
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
191 SettingsPaths::init();
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
192 }
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
193 return indenterPath;
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
194 }
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
195
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
196
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
197 /*!
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
198 \brief Returns the path where the where all temporary data should be written to.
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
199 */
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
200 const QString SettingsPaths::getTempPath() {
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
201 if ( !alreadyInitialized ) {
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
202 SettingsPaths::init();
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
203 }
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
204 return tempPath;
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
205 }
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
206
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
207
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
208 /*!
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
209 \brief Returns true if portable mode shall be used.
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
210 */
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
211 bool SettingsPaths::getPortableMode() {
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
212 if ( !alreadyInitialized ) {
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
213 SettingsPaths::init();
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
214 }
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
215 return portableMode;
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
216 }
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
217
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
218
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
219 /*!
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
220 \brief Returns true if portable mode shall be used.
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
221 */
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
222 void SettingsPaths::cleanAndRemoveTempDir() {
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
223 QDirIterator dirIterator(tempPath, QDirIterator::Subdirectories);
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
224 QStack<QString> directoryStack;
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
225 bool noErrorsOccurred = true;
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
226
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
227 while ( dirIterator.hasNext() ) {
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
228 QString currentDirOrFile = dirIterator.next();
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
229 // If this dummy call isn't done here, calling "dirIterator.fileInfo().isDir()" later somehow fails.
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
230 dirIterator.fileInfo();
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
231
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
232 if ( !currentDirOrFile.isEmpty() && dirIterator.fileName() != "." && dirIterator.fileName() != ".." ) {
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
233 // There is a path on the stack but the current path doesn't start with that path.
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
234 // So we changed into another parent directory and the one on the stack can be deleted
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
235 // since it must be empty.
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
236 if ( !directoryStack.isEmpty() && !currentDirOrFile.startsWith(directoryStack.top()) ) {
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
237 QString dirToBeRemoved = directoryStack.pop();
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
238 noErrorsOccurred &= QDir(dirToBeRemoved).rmdir(dirToBeRemoved);
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
239 //qDebug() << "Removing Dir " << directoryStack.pop();
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
240 }
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
241
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
242 // If the iterator currently points to a directory push it onto the stack.
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
243 if ( dirIterator.fileInfo().isDir() ) {
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
244 directoryStack.push( currentDirOrFile );
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
245 //qDebug() << "Pushing onto Stack " << currentDirOrFile;
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
246 }
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
247 // otherwise it must be a file, so delete it.
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
248 else {
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
249 noErrorsOccurred &= QFile::remove( currentDirOrFile );
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
250 //qDebug() << "Removing File " << currentDirOrFile;
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
251 }
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
252 }
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
253 }
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
254 noErrorsOccurred &= QDir(tempPath).rmdir(tempPath);
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
255 //qDebug() << "Removing tempPath " << tempPath;
06450e6542ee Avoiding a memory leak in the SettingsPaths class.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
256 }