summaryrefslogtreecommitdiff
path: root/library/config.cpp
Unidiff
Diffstat (limited to 'library/config.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/config.cpp13
1 files changed, 5 insertions, 8 deletions
diff --git a/library/config.cpp b/library/config.cpp
index 9634571..e07eecb 100644
--- a/library/config.cpp
+++ b/library/config.cpp
@@ -12,49 +12,51 @@
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include <qdir.h> 21#include <qdir.h>
22#include <qfile.h> 22#include <qfile.h>
23#include <qfileinfo.h> 23#include <qfileinfo.h>
24#include <qmessagebox.h> 24#include <qmessagebox.h>
25#if QT_VERSION <= 230 && defined(QT_NO_CODECS) 25#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
26#include <qtextcodec.h> 26#include <qtextcodec.h>
27#endif 27#endif
28#include <qtextstream.h> 28#include <qtextstream.h>
29 29
30#include <sys/stat.h> 30#include <sys/stat.h>
31#include <sys/types.h> 31#include <sys/types.h>
32#include <fcntl.h> 32#include <fcntl.h>
33#include <stdlib.h> 33#include <stdlib.h>
34#include <unistd.h> 34#include <unistd.h>
35 35
36#define QTOPIA_INTERNAL_LANGLIST
36#include "config.h" 37#include "config.h"
38#include "global.h"
37 39
38 40
39/*! 41/*!
40 \internal 42 \internal
41*/ 43*/
42QString Config::configFilename(const QString& name, Domain d) 44QString Config::configFilename(const QString& name, Domain d)
43{ 45{
44 switch (d) { 46 switch (d) {
45 case File: 47 case File:
46 return name; 48 return name;
47 case User: { 49 case User: {
48 QDir dir = (QString(getenv("HOME")) + "/Settings"); 50 QDir dir = (QString(getenv("HOME")) + "/Settings");
49 if ( !dir.exists() ) 51 if ( !dir.exists() )
50 mkdir(dir.path().local8Bit(),0700); 52 mkdir(dir.path().local8Bit(),0700);
51 return dir.path() + "/" + name + ".conf"; 53 return dir.path() + "/" + name + ".conf";
52 } 54 }
53 } 55 }
54 return name; 56 return name;
55} 57}
56 58
57/*! 59/*!
58 \class Config config.h 60 \class Config config.h
59 \brief The Config class provides for saving application cofniguration state. 61 \brief The Config class provides for saving application cofniguration state.
60 62
@@ -74,56 +76,51 @@ QString Config::configFilename(const QString& name, Domain d)
74 \value File 76 \value File
75 \value User 77 \value User
76 78
77 See Config for details. 79 See Config for details.
78*/ 80*/
79 81
80/*! 82/*!
81 Constructs a config that will load or create a configuration with the 83 Constructs a config that will load or create a configuration with the
82 given \a name in the given \a domain. 84 given \a name in the given \a domain.
83 85
84 You must call setGroup() before doing much else with the Config. 86 You must call setGroup() before doing much else with the Config.
85 87
86 In the default Domain, \e User, 88 In the default Domain, \e User,
87 the configuration is user-specific. \a name should not contain "/" in 89 the configuration is user-specific. \a name should not contain "/" in
88 this case, and in general should be the name of the C++ class that is 90 this case, and in general should be the name of the C++ class that is
89 primarily responsible for maintaining the configuration. 91 primarily responsible for maintaining the configuration.
90 92
91 In the File Domain, \a name is an absolute filename. 93 In the File Domain, \a name is an absolute filename.
92*/ 94*/
93Config::Config( const QString &name, Domain domain ) 95Config::Config( const QString &name, Domain domain )
94 : filename( configFilename(name,domain) ) 96 : filename( configFilename(name,domain) )
95{ 97{
96 git = groups.end(); 98 git = groups.end();
97 read(); 99 read();
98 100 QStringList l = Global::languageList();
99 lang = getenv("LANG"); 101 lang = l[0];
100 int i = lang.find("."); 102 glang = l[1];
101 if ( i > 0 )
102 lang = lang.left( i );
103 i = lang.find( "_" );
104 if ( i > 0 )
105 glang = lang.left(i);
106} 103}
107 104
108/*! 105/*!
109 Writes any changes to disk and destroys the in-memory object. 106 Writes any changes to disk and destroys the in-memory object.
110*/ 107*/
111Config::~Config() 108Config::~Config()
112{ 109{
113 if ( changed ) 110 if ( changed )
114 write(); 111 write();
115} 112}
116 113
117/*! 114/*!
118 Returns whether the current group has an entry called \a key. 115 Returns whether the current group has an entry called \a key.
119*/ 116*/
120bool Config::hasKey( const QString &key ) const 117bool Config::hasKey( const QString &key ) const
121{ 118{
122 if ( groups.end() == git ) 119 if ( groups.end() == git )
123 return FALSE; 120 return FALSE;
124 ConfigGroup::ConstIterator it = ( *git ).find( key ); 121 ConfigGroup::ConstIterator it = ( *git ).find( key );
125 return it != ( *git ).end(); 122 return it != ( *git ).end();
126} 123}
127 124
128/*! 125/*!
129 Sets the current group for subsequent reading and writing of 126 Sets the current group for subsequent reading and writing of