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
@@ -1,153 +1,150 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
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
61 You should keep a Config in existence only while you do not want others 63 You should keep a Config in existence only while you do not want others
62 to be able to change the state. There is no locking currently, but there 64 to be able to change the state. There is no locking currently, but there
63 may be in the future. 65 may be in the future.
64*/ 66*/
65 67
66/*! 68/*!
67 \enum Config::ConfigGroup 69 \enum Config::ConfigGroup
68 \internal 70 \internal
69*/ 71*/
70 72
71/*! 73/*!
72 \enum Config::Domain 74 \enum Config::Domain
73 75
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
130 entries to \a gname. Grouping allows the application to partition the namespace. 127 entries to \a gname. Grouping allows the application to partition the namespace.
131 128
132 This function must be called prior to any reading or writing 129 This function must be called prior to any reading or writing
133 of entries. 130 of entries.
134 131
135 The \a gname must not be empty. 132 The \a gname must not be empty.
136*/ 133*/
137void Config::setGroup( const QString &gname ) 134void Config::setGroup( const QString &gname )
138{ 135{
139 QMap< QString, ConfigGroup>::Iterator it = groups.find( gname ); 136 QMap< QString, ConfigGroup>::Iterator it = groups.find( gname );
140 if ( it == groups.end() ) { 137 if ( it == groups.end() ) {
141 git = groups.insert( gname, ConfigGroup() ); 138 git = groups.insert( gname, ConfigGroup() );
142 changed = TRUE; 139 changed = TRUE;
143 return; 140 return;
144 } 141 }
145 git = it; 142 git = it;
146} 143}
147 144
148/*! 145/*!
149 Writes a (\a key, \a value) entry to the current group. 146 Writes a (\a key, \a value) entry to the current group.
150 147
151 \sa readEntry() 148 \sa readEntry()
152*/ 149*/
153void Config::writeEntry( const QString &key, const char* value ) 150void Config::writeEntry( const QString &key, const char* value )