-rw-r--r-- | library/config.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/library/config.cpp b/library/config.cpp index 1121cd4..b47c620 100644 --- a/library/config.cpp +++ b/library/config.cpp | |||
@@ -57,96 +57,108 @@ QString Config::configFilename(const QString& name, Domain d) | |||
57 | } | 57 | } |
58 | 58 | ||
59 | /*! | 59 | /*! |
60 | \class Config config.h | 60 | \class Config config.h |
61 | \brief The Config class provides for saving application cofniguration state. | 61 | \brief The Config class provides for saving application cofniguration state. |
62 | 62 | ||
63 | 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 |
64 | 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 |
65 | may be in the future. | 65 | may be in the future. |
66 | */ | 66 | */ |
67 | 67 | ||
68 | /*! | 68 | /*! |
69 | \enum Config::ConfigGroup | 69 | \enum Config::ConfigGroup |
70 | \internal | 70 | \internal |
71 | */ | 71 | */ |
72 | 72 | ||
73 | /*! | 73 | /*! |
74 | \enum Config::Domain | 74 | \enum Config::Domain |
75 | 75 | ||
76 | \value File | 76 | \value File |
77 | \value User | 77 | \value User |
78 | 78 | ||
79 | See Config for details. | 79 | See Config for details. |
80 | */ | 80 | */ |
81 | 81 | ||
82 | /*! | 82 | /*! |
83 | 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 |
84 | given \a name in the given \a domain. | 84 | given \a name in the given \a domain. |
85 | 85 | ||
86 | You must call setGroup() before doing much else with the Config. | 86 | You must call setGroup() before doing much else with the Config. |
87 | 87 | ||
88 | In the default Domain, \e User, | 88 | In the default Domain, \e User, |
89 | the configuration is user-specific. \a name should not contain "/" in | 89 | the configuration is user-specific. \a name should not contain "/" in |
90 | 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 |
91 | primarily responsible for maintaining the configuration. | 91 | primarily responsible for maintaining the configuration. |
92 | 92 | ||
93 | In the File Domain, \a name is an absolute filename. | 93 | In the File Domain, \a name is an absolute filename. |
94 | */ | 94 | */ |
95 | Config::Config( const QString &name, Domain domain ) | 95 | Config::Config( const QString &name, Domain domain ) |
96 | : filename( configFilename(name,domain) ) | 96 | : filename( configFilename(name,domain) ) |
97 | { | 97 | { |
98 | git = groups.end(); | 98 | git = groups.end(); |
99 | read(); | 99 | read(); |
100 | QStringList l = Global::languageList(); | 100 | QStringList l = Global::languageList(); |
101 | lang = l[0]; | 101 | lang = l[0]; |
102 | glang = l[1]; | 102 | glang = l[1]; |
103 | } | 103 | } |
104 | 104 | ||
105 | |||
106 | // Sharp ROM compatibility | ||
107 | Config::Config ( const QString &name, bool what ) | ||
108 | : filename( configFilename(name,what ? User : File) ) | ||
109 | { | ||
110 | git = groups.end(); | ||
111 | read(); | ||
112 | QStringList l = Global::languageList(); | ||
113 | lang = l[0]; | ||
114 | glang = l[1]; | ||
115 | } | ||
116 | |||
105 | /*! | 117 | /*! |
106 | Writes any changes to disk and destroys the in-memory object. | 118 | Writes any changes to disk and destroys the in-memory object. |
107 | */ | 119 | */ |
108 | Config::~Config() | 120 | Config::~Config() |
109 | { | 121 | { |
110 | if ( changed ) | 122 | if ( changed ) |
111 | write(); | 123 | write(); |
112 | } | 124 | } |
113 | 125 | ||
114 | /*! | 126 | /*! |
115 | Returns whether the current group has an entry called \a key. | 127 | Returns whether the current group has an entry called \a key. |
116 | */ | 128 | */ |
117 | bool Config::hasKey( const QString &key ) const | 129 | bool Config::hasKey( const QString &key ) const |
118 | { | 130 | { |
119 | if ( groups.end() == git ) | 131 | if ( groups.end() == git ) |
120 | return FALSE; | 132 | return FALSE; |
121 | ConfigGroup::ConstIterator it = ( *git ).find( key ); | 133 | ConfigGroup::ConstIterator it = ( *git ).find( key ); |
122 | return it != ( *git ).end(); | 134 | return it != ( *git ).end(); |
123 | } | 135 | } |
124 | 136 | ||
125 | /*! | 137 | /*! |
126 | Sets the current group for subsequent reading and writing of | 138 | Sets the current group for subsequent reading and writing of |
127 | entries to \a gname. Grouping allows the application to partition the namespace. | 139 | entries to \a gname. Grouping allows the application to partition the namespace. |
128 | 140 | ||
129 | This function must be called prior to any reading or writing | 141 | This function must be called prior to any reading or writing |
130 | of entries. | 142 | of entries. |
131 | 143 | ||
132 | The \a gname must not be empty. | 144 | The \a gname must not be empty. |
133 | */ | 145 | */ |
134 | void Config::setGroup( const QString &gname ) | 146 | void Config::setGroup( const QString &gname ) |
135 | { | 147 | { |
136 | QMap< QString, ConfigGroup>::Iterator it = groups.find( gname ); | 148 | QMap< QString, ConfigGroup>::Iterator it = groups.find( gname ); |
137 | if ( it == groups.end() ) { | 149 | if ( it == groups.end() ) { |
138 | git = groups.insert( gname, ConfigGroup() ); | 150 | git = groups.insert( gname, ConfigGroup() ); |
139 | changed = TRUE; | 151 | changed = TRUE; |
140 | return; | 152 | return; |
141 | } | 153 | } |
142 | git = it; | 154 | git = it; |
143 | } | 155 | } |
144 | 156 | ||
145 | /*! | 157 | /*! |
146 | Writes a (\a key, \a value) entry to the current group. | 158 | Writes a (\a key, \a value) entry to the current group. |
147 | 159 | ||
148 | \sa readEntry() | 160 | \sa readEntry() |
149 | */ | 161 | */ |
150 | void Config::writeEntry( const QString &key, const char* value ) | 162 | void Config::writeEntry( const QString &key, const char* value ) |
151 | { | 163 | { |
152 | writeEntry(key,QString(value)); | 164 | writeEntry(key,QString(value)); |