-rw-r--r-- | microkde/kresources/managerimpl.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/microkde/kresources/managerimpl.cpp b/microkde/kresources/managerimpl.cpp index 5bd9eb7..566b8f4 100644 --- a/microkde/kresources/managerimpl.cpp +++ b/microkde/kresources/managerimpl.cpp | |||
@@ -32,269 +32,269 @@ $Id$ | |||
32 | 32 | ||
33 | #include <kapplication.h> | 33 | #include <kapplication.h> |
34 | #include <kdebug.h> | 34 | #include <kdebug.h> |
35 | #include <kconfig.h> | 35 | #include <kconfig.h> |
36 | #include <kstandarddirs.h> | 36 | #include <kstandarddirs.h> |
37 | #include <qfile.h> | 37 | #include <qfile.h> |
38 | 38 | ||
39 | #include "resource.h" | 39 | #include "resource.h" |
40 | #include "factory.h" | 40 | #include "factory.h" |
41 | #include "managerimpl.h" | 41 | #include "managerimpl.h" |
42 | 42 | ||
43 | using namespace KRES; | 43 | using namespace KRES; |
44 | 44 | ||
45 | ManagerImpl::ManagerImpl( const QString &family ) | 45 | ManagerImpl::ManagerImpl( const QString &family ) |
46 | : mFamily( family ), mConfig( 0 ), mStdConfig( 0 ), mStandard( 0 ), | 46 | : mFamily( family ), mConfig( 0 ), mStdConfig( 0 ), mStandard( 0 ), |
47 | mFactory( 0 ) | 47 | mFactory( 0 ) |
48 | 48 | ||
49 | { | 49 | { |
50 | kdDebug(5650) << "ManagerImpl::ManagerImpl()" << endl; | 50 | kdDebug(5650) << "ManagerImpl::ManagerImpl()" << endl; |
51 | 51 | ||
52 | 52 | ||
53 | } | 53 | } |
54 | 54 | ||
55 | ManagerImpl::~ManagerImpl() | 55 | ManagerImpl::~ManagerImpl() |
56 | { | 56 | { |
57 | kdDebug(5650) << "ManagerImpl::~ManagerImpl()" << endl; | 57 | kdDebug(5650) << "ManagerImpl::~ManagerImpl()" << endl; |
58 | 58 | ||
59 | Resource::List::ConstIterator it; | 59 | Resource::List::ConstIterator it; |
60 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { | 60 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { |
61 | delete *it; | 61 | delete *it; |
62 | } | 62 | } |
63 | 63 | ||
64 | delete mStdConfig; | 64 | delete mStdConfig; |
65 | } | 65 | } |
66 | 66 | ||
67 | void ManagerImpl::createStandardConfig() | 67 | void ManagerImpl::createStandardConfig() |
68 | { | 68 | { |
69 | if ( !mStdConfig ) { | 69 | if ( !mStdConfig ) { |
70 | QString file = locateLocal( "data", KGlobal::getAppName() | 70 | QString file = locateLocal( "data", KGlobal::getAppName() |
71 | + "/kresources/" + mFamily + "rc" ); | 71 | + "/kresources/" + mFamily + "rc" ); |
72 | if ( mFamily == "tmpcontact" ) { | 72 | if ( mFamily == "tmpcontact" ) { |
73 | if (QFile::exists ( file ) ){ | 73 | if (QFile::exists ( file ) ){ |
74 | QFile::remove ( file ); | 74 | QFile::remove ( file ); |
75 | qDebug("removed tmp rc file: %s ", file.latin1()); | 75 | qDebug("removed tmp rc file: %s ", file.latin1()); |
76 | } | 76 | } |
77 | } | 77 | } |
78 | mStdConfig = new KConfig( file ); | 78 | mStdConfig = new KConfig( file ); |
79 | } | 79 | } |
80 | 80 | ||
81 | mConfig = mStdConfig; | 81 | mConfig = mStdConfig; |
82 | } | 82 | } |
83 | 83 | ||
84 | void ManagerImpl::readConfig( KConfig *cfg ) | 84 | void ManagerImpl::readConfig( KConfig *cfg ) |
85 | { | 85 | { |
86 | kdDebug(5650) << "ManagerImpl::readConfig()" << endl; | 86 | kdDebug(5650) << "ManagerImpl::readConfig()" << endl; |
87 | 87 | ||
88 | delete mFactory; | 88 | delete mFactory; |
89 | mFactory = Factory::self( mFamily ); | 89 | mFactory = Factory::self( mFamily ); |
90 | 90 | ||
91 | if ( !cfg ) { | 91 | if ( !cfg ) { |
92 | createStandardConfig(); | 92 | createStandardConfig(); |
93 | } else { | 93 | } else { |
94 | mConfig = cfg; | 94 | mConfig = cfg; |
95 | } | 95 | } |
96 | 96 | ||
97 | mStandard = 0; | 97 | mStandard = 0; |
98 | 98 | ||
99 | mConfig->setGroup( "General" ); | 99 | mConfig->setGroup( "General" ); |
100 | 100 | ||
101 | QStringList keys = mConfig->readListEntry( "ResourceKeys" ); | 101 | QStringList keys = mConfig->readListEntry( "ResourceKeys" ); |
102 | keys += mConfig->readListEntry( "PassiveResourceKeys" ); | 102 | keys += mConfig->readListEntry( "PassiveResourceKeys" ); |
103 | 103 | ||
104 | QString standardKey = mConfig->readEntry( "Standard" ); | 104 | QString standardKey = mConfig->readEntry( "Standard" ); |
105 | 105 | ||
106 | for ( QStringList::Iterator it = keys.begin(); it != keys.end(); ++it ) { | 106 | for ( QStringList::Iterator it = keys.begin(); it != keys.end(); ++it ) { |
107 | readResourceConfig( *it, false ); | 107 | readResourceConfig( *it, false ); |
108 | } | 108 | } |
109 | 109 | ||
110 | } | 110 | } |
111 | 111 | ||
112 | void ManagerImpl::writeConfig( KConfig *cfg ) | 112 | void ManagerImpl::writeConfig( KConfig *cfg ) |
113 | { | 113 | { |
114 | //USqDebug("ManagerImpl::writeConfig begin this= %ul cfg=%ul", this, cfg); | 114 | //USqDebug("ManagerImpl::writeConfig begin this= %ul cfg=%ul", this, cfg); |
115 | 115 | ||
116 | 116 | ||
117 | kdDebug(5650) << "ManagerImpl::writeConfig()" << endl; | 117 | kdDebug(5650) << "ManagerImpl::writeConfig()" << endl; |
118 | 118 | ||
119 | if ( !cfg ) { | 119 | if ( !cfg ) { |
120 | createStandardConfig(); | 120 | createStandardConfig(); |
121 | } else { | 121 | } else { |
122 | mConfig = cfg; | 122 | mConfig = cfg; |
123 | } | 123 | } |
124 | 124 | ||
125 | QStringList activeKeys; | 125 | QStringList activeKeys; |
126 | QStringList passiveKeys; | 126 | QStringList passiveKeys; |
127 | 127 | ||
128 | // First write all keys, collect active and passive keys on the way | 128 | // First write all keys, collect active and passive keys on the way |
129 | Resource::List::Iterator it; | 129 | Resource::List::Iterator it; |
130 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { | 130 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { |
131 | writeResourceConfig( *it, false ); | 131 | writeResourceConfig( *it, false ); |
132 | 132 | ||
133 | QString key = (*it)->identifier(); | 133 | QString key = (*it)->identifier(); |
134 | if( (*it)->isActive() ) | 134 | if( (*it)->isActive() ) |
135 | activeKeys.append( key ); | 135 | activeKeys.append( key ); |
136 | else | 136 | else |
137 | passiveKeys.append( key ); | 137 | passiveKeys.append( key ); |
138 | } | 138 | } |
139 | 139 | ||
140 | // And then the general group | 140 | // And then the general group |
141 | 141 | ||
142 | kdDebug(5650) << "Saving general info" << endl; | 142 | kdDebug(5650) << "Saving general info" << endl; |
143 | mConfig->setGroup( "General" ); | 143 | mConfig->setGroup( "General" ); |
144 | mConfig->writeEntry( "ResourceKeys", activeKeys ); | 144 | mConfig->writeEntry( "ResourceKeys", activeKeys ); |
145 | mConfig->writeEntry( "PassiveResourceKeys", passiveKeys ); | 145 | mConfig->writeEntry( "PassiveResourceKeys", passiveKeys ); |
146 | if ( mStandard ) | 146 | if ( mStandard ) |
147 | mConfig->writeEntry( "Standard", mStandard->identifier() ); | 147 | mConfig->writeEntry( "Standard", mStandard->identifier() ); |
148 | else | 148 | else |
149 | mConfig->writeEntry( "Standard", "" ); | 149 | mConfig->writeEntry( "Standard", "" ); |
150 | 150 | ||
151 | mConfig->sync(); | 151 | mConfig->sync(); |
152 | kdDebug(5650) << "ManagerImpl::save() finished" << endl; | 152 | kdDebug(5650) << "ManagerImpl::save() finished" << endl; |
153 | 153 | ||
154 | //US qDebug("ManagerImpl::writeConfig end this= %ul cfg=%ul", this, cfg); | 154 | //US qDebug("ManagerImpl::writeConfig end this= %ul cfg=%ul", this, cfg); |
155 | 155 | ||
156 | } | 156 | } |
157 | 157 | ||
158 | void ManagerImpl::add( Resource *resource, bool useDCOP ) | 158 | void ManagerImpl::add( Resource *resource, bool useDCOP ) |
159 | { | 159 | { |
160 | qDebug("ManagerImpl::add begin this= %ul resource=%ul", this, resource); | 160 | //qDebug("ManagerImpl::add begin this= %ul resource=%ul", this, resource); |
161 | 161 | ||
162 | resource->setActive( true ); | 162 | resource->setActive( true ); |
163 | 163 | ||
164 | if ( mResources.isEmpty() ) { | 164 | if ( mResources.isEmpty() ) { |
165 | mStandard = resource; | 165 | mStandard = resource; |
166 | } | 166 | } |
167 | 167 | ||
168 | mResources.append( resource ); | 168 | mResources.append( resource ); |
169 | 169 | ||
170 | writeResourceConfig( resource, true ); | 170 | writeResourceConfig( resource, true ); |
171 | 171 | ||
172 | qDebug("ManagerImpl::add end this= %ul resource=%ul", this, resource); | 172 | //qDebug("ManagerImpl::add end this= %ul resource=%ul", this, resource); |
173 | 173 | ||
174 | } | 174 | } |
175 | 175 | ||
176 | void ManagerImpl::remove( Resource *resource, bool useDCOP ) | 176 | void ManagerImpl::remove( Resource *resource, bool useDCOP ) |
177 | { | 177 | { |
178 | if ( mStandard == resource ) mStandard = 0; | 178 | if ( mStandard == resource ) mStandard = 0; |
179 | removeResource( resource ); | 179 | removeResource( resource ); |
180 | 180 | ||
181 | mResources.remove( resource ); | 181 | mResources.remove( resource ); |
182 | 182 | ||
183 | delete resource; | 183 | delete resource; |
184 | 184 | ||
185 | kdDebug(5650) << "Finished ManagerImpl::remove()" << endl; | 185 | kdDebug(5650) << "Finished ManagerImpl::remove()" << endl; |
186 | } | 186 | } |
187 | 187 | ||
188 | void ManagerImpl::setActive( Resource *resource, bool active ) | 188 | void ManagerImpl::setActive( Resource *resource, bool active ) |
189 | { | 189 | { |
190 | if ( resource && resource->isActive() != active ) { | 190 | if ( resource && resource->isActive() != active ) { |
191 | resource->setActive( active ); | 191 | resource->setActive( active ); |
192 | } | 192 | } |
193 | } | 193 | } |
194 | 194 | ||
195 | Resource *ManagerImpl::standardResource() | 195 | Resource *ManagerImpl::standardResource() |
196 | { | 196 | { |
197 | return mStandard; | 197 | return mStandard; |
198 | } | 198 | } |
199 | 199 | ||
200 | void ManagerImpl::setStandardResource( Resource *resource ) | 200 | void ManagerImpl::setStandardResource( Resource *resource ) |
201 | { | 201 | { |
202 | mStandard = resource; | 202 | mStandard = resource; |
203 | } | 203 | } |
204 | 204 | ||
205 | void ManagerImpl::resourceChanged( Resource *resource ) | 205 | void ManagerImpl::resourceChanged( Resource *resource ) |
206 | { | 206 | { |
207 | writeResourceConfig( resource, true ); | 207 | writeResourceConfig( resource, true ); |
208 | 208 | ||
209 | 209 | ||
210 | // ManagerIface_stub allManagers( "*", "ManagerIface_" + mFamily.utf8() ); | 210 | // ManagerIface_stub allManagers( "*", "ManagerIface_" + mFamily.utf8() ); |
211 | // allManagers.dcopResourceModified( resource->identifier() ); | 211 | // allManagers.dcopResourceModified( resource->identifier() ); |
212 | } | 212 | } |
213 | 213 | ||
214 | // DCOP asynchronous functions | 214 | // DCOP asynchronous functions |
215 | //US since we work from inside the application, we call the methods directly. | 215 | //US since we work from inside the application, we call the methods directly. |
216 | 216 | ||
217 | QStringList ManagerImpl::resourceNames() | 217 | QStringList ManagerImpl::resourceNames() |
218 | { | 218 | { |
219 | QStringList result; | 219 | QStringList result; |
220 | 220 | ||
221 | Resource::List::ConstIterator it; | 221 | Resource::List::ConstIterator it; |
222 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { | 222 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { |
223 | result.append( (*it)->resourceName() ); | 223 | result.append( (*it)->resourceName() ); |
224 | } | 224 | } |
225 | return result; | 225 | return result; |
226 | } | 226 | } |
227 | 227 | ||
228 | Resource::List *ManagerImpl::resourceList() | 228 | Resource::List *ManagerImpl::resourceList() |
229 | { | 229 | { |
230 | return &mResources; | 230 | return &mResources; |
231 | } | 231 | } |
232 | 232 | ||
233 | QPtrList<Resource> ManagerImpl::resources() | 233 | QPtrList<Resource> ManagerImpl::resources() |
234 | { | 234 | { |
235 | QPtrList<Resource> result; | 235 | QPtrList<Resource> result; |
236 | 236 | ||
237 | Resource::List::ConstIterator it; | 237 | Resource::List::ConstIterator it; |
238 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { | 238 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { |
239 | result.append( *it ); | 239 | result.append( *it ); |
240 | } | 240 | } |
241 | return result; | 241 | return result; |
242 | } | 242 | } |
243 | 243 | ||
244 | QPtrList<Resource> ManagerImpl::resources( bool active ) | 244 | QPtrList<Resource> ManagerImpl::resources( bool active ) |
245 | { | 245 | { |
246 | QPtrList<Resource> result; | 246 | QPtrList<Resource> result; |
247 | 247 | ||
248 | Resource::List::ConstIterator it; | 248 | Resource::List::ConstIterator it; |
249 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { | 249 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { |
250 | if ( (*it)->isActive() == active ) { | 250 | if ( (*it)->isActive() == active ) { |
251 | result.append( *it ); | 251 | result.append( *it ); |
252 | } | 252 | } |
253 | } | 253 | } |
254 | return result; | 254 | return result; |
255 | } | 255 | } |
256 | 256 | ||
257 | void ManagerImpl::setListener( ManagerImplListener *listener ) | 257 | void ManagerImpl::setListener( ManagerImplListener *listener ) |
258 | { | 258 | { |
259 | mListener = listener; | 259 | mListener = listener; |
260 | } | 260 | } |
261 | 261 | ||
262 | Resource* ManagerImpl::readResourceConfig( const QString& identifier, | 262 | Resource* ManagerImpl::readResourceConfig( const QString& identifier, |
263 | bool checkActive ) | 263 | bool checkActive ) |
264 | { | 264 | { |
265 | kdDebug() << "ManagerImpl::readResourceConfig() " << identifier << endl; | 265 | kdDebug() << "ManagerImpl::readResourceConfig() " << identifier << endl; |
266 | 266 | ||
267 | // qDebug("ManagerImpl::readResourceConfig() %s", identifier.latin1()); | 267 | // qDebug("ManagerImpl::readResourceConfig() %s", identifier.latin1()); |
268 | 268 | ||
269 | mConfig->setGroup( "Resource_" + identifier ); | 269 | mConfig->setGroup( "Resource_" + identifier ); |
270 | #ifdef _WIN32_ | 270 | #ifdef _WIN32_ |
271 | // we use plugins on win32. the group is stored in a static variable | 271 | // we use plugins on win32. the group is stored in a static variable |
272 | // such that gourp info not avail on win32 plugins | 272 | // such that gourp info not avail on win32 plugins |
273 | // to fix that, it would be a looooot of work | 273 | // to fix that, it would be a looooot of work |
274 | mConfig->setTempGroup( "Resource_" + identifier ); | 274 | mConfig->setTempGroup( "Resource_" + identifier ); |
275 | #endif | 275 | #endif |
276 | QString type = mConfig->readEntry( "ResourceType" ); | 276 | QString type = mConfig->readEntry( "ResourceType" ); |
277 | QString name = mConfig->readEntry( "ResourceName" ); | 277 | QString name = mConfig->readEntry( "ResourceName" ); |
278 | Resource *resource = mFactory->resource( type, mConfig ); | 278 | Resource *resource = mFactory->resource( type, mConfig ); |
279 | if ( !resource ) { | 279 | if ( !resource ) { |
280 | qDebug("Failed to create resource with id %s ",identifier.latin1() ); | 280 | qDebug("Failed to create resource with id %s ",identifier.latin1() ); |
281 | return 0; | 281 | return 0; |
282 | } | 282 | } |
283 | 283 | ||
284 | if ( resource->identifier().isEmpty() ) | 284 | if ( resource->identifier().isEmpty() ) |
285 | resource->setIdentifier( identifier ); | 285 | resource->setIdentifier( identifier ); |
286 | 286 | ||
287 | mConfig->setGroup( "General" ); | 287 | mConfig->setGroup( "General" ); |
288 | 288 | ||
289 | QString standardKey = mConfig->readEntry( "Standard" ); | 289 | QString standardKey = mConfig->readEntry( "Standard" ); |
290 | if ( standardKey == identifier ) { | 290 | if ( standardKey == identifier ) { |
291 | mStandard = resource; | 291 | mStandard = resource; |
292 | } | 292 | } |
293 | 293 | ||
294 | if ( checkActive ) { | 294 | if ( checkActive ) { |
295 | QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" ); | 295 | QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" ); |
296 | resource->setActive( activeKeys.contains( identifier ) ); | 296 | resource->setActive( activeKeys.contains( identifier ) ); |
297 | } | 297 | } |
298 | mResources.append( resource ); | 298 | mResources.append( resource ); |
299 | 299 | ||
300 | return resource; | 300 | return resource; |