author | zautrix <zautrix> | 2005-04-03 21:03:06 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-04-03 21:03:06 (UTC) |
commit | f3707f1dcc3d42d43c9e6b649a9a68b2e706051e (patch) (unidiff) | |
tree | cad8019b110d59bd76a2901494259f2971c160b7 /microkde/kresources | |
parent | 2d83daf3568bb829db2530baa917db5a4cbf0768 (diff) | |
download | kdepimpi-f3707f1dcc3d42d43c9e6b649a9a68b2e706051e.zip kdepimpi-f3707f1dcc3d42d43c9e6b649a9a68b2e706051e.tar.gz kdepimpi-f3707f1dcc3d42d43c9e6b649a9a68b2e706051e.tar.bz2 |
static fix
-rw-r--r-- | microkde/kresources/factory.cpp | 26 | ||||
-rw-r--r-- | microkde/kresources/managerimpl.cpp | 2 |
2 files changed, 28 insertions, 0 deletions
diff --git a/microkde/kresources/factory.cpp b/microkde/kresources/factory.cpp index a3b7fff..5fbfa68 100644 --- a/microkde/kresources/factory.cpp +++ b/microkde/kresources/factory.cpp | |||
@@ -1,256 +1,282 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkresources. | 2 | This file is part of libkresources. |
3 | 3 | ||
4 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> | 4 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> |
5 | Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org> | 5 | Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org> |
6 | Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> | 6 | Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> |
7 | 7 | ||
8 | This library is free software; you can redistribute it and/or | 8 | This library is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU Library General Public | 9 | modify it under the terms of the GNU Library General Public |
10 | License as published by the Free Software Foundation; either | 10 | License as published by the Free Software Foundation; either |
11 | version 2 of the License, or (at your option) any later version. | 11 | version 2 of the License, or (at your option) any later version. |
12 | 12 | ||
13 | This library is distributed in the hope that it will be useful, | 13 | This library is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | Library General Public License for more details. | 16 | Library General Public License for more details. |
17 | 17 | ||
18 | You should have received a copy of the GNU Library General Public License | 18 | You should have received a copy of the GNU Library General Public License |
19 | along with this library; see the file COPYING.LIB. If not, write to | 19 | along with this library; see the file COPYING.LIB. If not, write to |
20 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 20 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
21 | Boston, MA 02111-1307, USA. | 21 | Boston, MA 02111-1307, USA. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <kdebug.h> | 24 | #include <kdebug.h> |
25 | #include <klocale.h> | 25 | #include <klocale.h> |
26 | #include <ksimpleconfig.h> | 26 | #include <ksimpleconfig.h> |
27 | #include <kstandarddirs.h> | 27 | #include <kstandarddirs.h> |
28 | #include <kstaticdeleter.h> | 28 | #include <kstaticdeleter.h> |
29 | //#ifndef DESKTOP_VERSION | 29 | //#ifndef DESKTOP_VERSION |
30 | #include <klibloader.h> | 30 | #include <klibloader.h> |
31 | //#endif | 31 | //#endif |
32 | #include <qfile.h> | 32 | #include <qfile.h> |
33 | 33 | ||
34 | #include "resource.h" | 34 | #include "resource.h" |
35 | #include "factory.h" | 35 | #include "factory.h" |
36 | 36 | ||
37 | #ifdef STATIC_RESOURCES | ||
38 | #include <file/resourcefile.h> | ||
39 | #include <dir/resourcedir.h> | ||
40 | #include <qtopia/resourceqtopia.h> | ||
41 | #endif | ||
37 | using namespace KRES; | 42 | using namespace KRES; |
38 | 43 | ||
39 | QDict<Factory> *Factory::mSelves = 0; | 44 | QDict<Factory> *Factory::mSelves = 0; |
40 | static KStaticDeleter< QDict<Factory> > staticDeleter; | 45 | static KStaticDeleter< QDict<Factory> > staticDeleter; |
41 | 46 | ||
42 | Factory *Factory::self( const QString& resourceFamily) | 47 | Factory *Factory::self( const QString& resourceFamily) |
43 | { | 48 | { |
44 | 49 | ||
45 | 50 | ||
46 | Factory *factory = 0; | 51 | Factory *factory = 0; |
47 | if ( !mSelves ) | 52 | if ( !mSelves ) |
48 | { | 53 | { |
49 | mSelves = staticDeleter.setObject( new QDict<Factory> ); | 54 | mSelves = staticDeleter.setObject( new QDict<Factory> ); |
50 | } | 55 | } |
51 | 56 | ||
52 | factory = mSelves->find( resourceFamily ); | 57 | factory = mSelves->find( resourceFamily ); |
53 | 58 | ||
54 | if ( !factory ) { | 59 | if ( !factory ) { |
55 | factory = new Factory( resourceFamily); | 60 | factory = new Factory( resourceFamily); |
56 | mSelves->insert( resourceFamily, factory ); | 61 | mSelves->insert( resourceFamily, factory ); |
57 | } | 62 | } |
58 | 63 | ||
59 | return factory; | 64 | return factory; |
60 | } | 65 | } |
61 | 66 | ||
62 | Factory::Factory( const QString& resourceFamily) : | 67 | Factory::Factory( const QString& resourceFamily) : |
63 | mResourceFamily( resourceFamily ) | 68 | mResourceFamily( resourceFamily ) |
64 | { | 69 | { |
65 | //US so far we have three types available for resourceFamily "contact" | 70 | //US so far we have three types available for resourceFamily "contact" |
66 | // and that are "file", "dir", "ldap" | 71 | // and that are "file", "dir", "ldap" |
67 | /*US | 72 | /*US |
68 | 73 | ||
69 | KTrader::OfferList plugins = KTrader::self()->query( "KResources/Plugin", QString( "[X-KDE-ResourceFamily] == '%1'" ) | 74 | KTrader::OfferList plugins = KTrader::self()->query( "KResources/Plugin", QString( "[X-KDE-ResourceFamily] == '%1'" ) |
70 | .arg( resourceFamily ) ); | 75 | .arg( resourceFamily ) ); |
71 | KTrader::OfferList::ConstIterator it; | 76 | KTrader::OfferList::ConstIterator it; |
72 | for ( it = plugins.begin(); it != plugins.end(); ++it ) { | 77 | for ( it = plugins.begin(); it != plugins.end(); ++it ) { |
73 | QVariant type = (*it)->property( "X-KDE-ResourceType" ); | 78 | QVariant type = (*it)->property( "X-KDE-ResourceType" ); |
74 | if ( !type.toString().isEmpty() ) | 79 | if ( !type.toString().isEmpty() ) |
75 | mTypeMap.insert( type.toString(), *it ); | 80 | mTypeMap.insert( type.toString(), *it ); |
76 | } | 81 | } |
77 | */ | 82 | */ |
78 | 83 | ||
79 | //US new | 84 | //US new |
80 | PluginInfo* info = new PluginInfo; | 85 | PluginInfo* info = new PluginInfo; |
81 | info->library = "microkabc_file"; | 86 | info->library = "microkabc_file"; |
82 | info->nameLabel = i18n( "file" ); | 87 | info->nameLabel = i18n( "file" ); |
83 | info->descriptionLabel = i18n( "One file" ); | 88 | info->descriptionLabel = i18n( "One file" ); |
84 | mTypeMap.insert( "file", info ); | 89 | mTypeMap.insert( "file", info ); |
85 | 90 | ||
86 | info = new PluginInfo; | 91 | info = new PluginInfo; |
87 | info->library = "microkabc_dir"; | 92 | info->library = "microkabc_dir"; |
88 | info->nameLabel = i18n( "dir" ); | 93 | info->nameLabel = i18n( "dir" ); |
89 | info->descriptionLabel = i18n( "A directory with many files" ); | 94 | info->descriptionLabel = i18n( "A directory with many files" ); |
90 | mTypeMap.insert( "dir", info ); | 95 | mTypeMap.insert( "dir", info ); |
91 | 96 | ||
92 | info = new PluginInfo; | 97 | info = new PluginInfo; |
93 | info->library = "microkabc_ldap"; | 98 | info->library = "microkabc_ldap"; |
94 | info->nameLabel = i18n( "ldap" ); | 99 | info->nameLabel = i18n( "ldap" ); |
95 | info->descriptionLabel = i18n( "Connect to a directory server" ); | 100 | info->descriptionLabel = i18n( "Connect to a directory server" ); |
96 | mTypeMap.insert( "ldap", info ); | 101 | mTypeMap.insert( "ldap", info ); |
97 | 102 | ||
98 | //US add opie plugin only, if the library exists. | 103 | //US add opie plugin only, if the library exists. |
99 | /*US | 104 | /*US |
100 | QString libname = "microkabc_opie"; | 105 | QString libname = "microkabc_opie"; |
101 | QString path = KLibLoader::findLibrary( QFile::encodeName( libname ) ); | 106 | QString path = KLibLoader::findLibrary( QFile::encodeName( libname ) ); |
102 | if ( !path.isEmpty() ) | 107 | if ( !path.isEmpty() ) |
103 | { | 108 | { |
104 | info = new PluginInfo; | 109 | info = new PluginInfo; |
105 | info->library = libname; | 110 | info->library = libname; |
106 | info->nameLabel = i18n( "opie" ); | 111 | info->nameLabel = i18n( "opie" ); |
107 | info->descriptionLabel = i18n( "Opie PIM Addressbook." ); | 112 | info->descriptionLabel = i18n( "Opie PIM Addressbook." ); |
108 | mTypeMap.insert( "opie", info ); | 113 | mTypeMap.insert( "opie", info ); |
109 | } | 114 | } |
110 | */ | 115 | */ |
111 | //US add qtopia plugin only, if the library exists. | 116 | //US add qtopia plugin only, if the library exists. |
112 | QString libname = "microkabc_qtopia"; | 117 | QString libname = "microkabc_qtopia"; |
113 | QString path = KLibLoader::findLibrary( QFile::encodeName( libname ) ); | 118 | QString path = KLibLoader::findLibrary( QFile::encodeName( libname ) ); |
114 | if ( !path.isEmpty() ) | 119 | if ( !path.isEmpty() ) |
115 | { | 120 | { |
116 | info = new PluginInfo; | 121 | info = new PluginInfo; |
117 | info->library = libname; | 122 | info->library = libname; |
118 | info->nameLabel = i18n( "qtopia" ); | 123 | info->nameLabel = i18n( "qtopia" ); |
119 | info->descriptionLabel = i18n( "Qtopia PIM Addressbook." ); | 124 | info->descriptionLabel = i18n( "Qtopia PIM Addressbook." ); |
120 | mTypeMap.insert( "qtopia", info ); | 125 | mTypeMap.insert( "qtopia", info ); |
121 | } | 126 | } |
122 | 127 | ||
123 | //US add sharp plugin only, if the library exists. | 128 | //US add sharp plugin only, if the library exists. |
124 | libname = "microkabc_sharpdtm"; | 129 | libname = "microkabc_sharpdtm"; |
125 | path = KLibLoader::findLibrary( QFile::encodeName( libname ) ); | 130 | path = KLibLoader::findLibrary( QFile::encodeName( libname ) ); |
126 | if ( !path.isEmpty() ) | 131 | if ( !path.isEmpty() ) |
127 | { | 132 | { |
128 | info = new PluginInfo; | 133 | info = new PluginInfo; |
129 | info->library = libname; | 134 | info->library = libname; |
130 | info->nameLabel = i18n( "sharp" ); | 135 | info->nameLabel = i18n( "sharp" ); |
131 | info->descriptionLabel = i18n( "Sharp DTM Addressbook." ); | 136 | info->descriptionLabel = i18n( "Sharp DTM Addressbook." ); |
132 | mTypeMap.insert( "sharp", info ); | 137 | mTypeMap.insert( "sharp", info ); |
133 | } | 138 | } |
134 | 139 | ||
135 | 140 | ||
136 | } | 141 | } |
137 | 142 | ||
138 | Factory::~Factory() | 143 | Factory::~Factory() |
139 | { | 144 | { |
140 | } | 145 | } |
141 | 146 | ||
142 | QStringList Factory::typeNames() const | 147 | QStringList Factory::typeNames() const |
143 | { | 148 | { |
144 | //US method QMap::keys() not available yet. SO collect the data manually | 149 | //US method QMap::keys() not available yet. SO collect the data manually |
145 | //US return mTypeMap.keys(); | 150 | //US return mTypeMap.keys(); |
146 | 151 | ||
147 | QStringList result; | 152 | QStringList result; |
148 | 153 | ||
149 | QMap<QString, PluginInfo*>::ConstIterator it; | 154 | QMap<QString, PluginInfo*>::ConstIterator it; |
150 | for( it = mTypeMap.begin(); it != mTypeMap.end(); ++it ) { | 155 | for( it = mTypeMap.begin(); it != mTypeMap.end(); ++it ) { |
151 | result << it.key().latin1(); | 156 | result << it.key().latin1(); |
152 | // qDebug("Factory::typeNames() : %s ", it.key().latin1()); | 157 | // qDebug("Factory::typeNames() : %s ", it.key().latin1()); |
153 | 158 | ||
154 | } | 159 | } |
155 | return result; | 160 | return result; |
156 | } | 161 | } |
157 | 162 | ||
158 | ConfigWidget *Factory::configWidget( const QString& type, QWidget *parent ) | 163 | ConfigWidget *Factory::configWidget( const QString& type, QWidget *parent ) |
159 | { | 164 | { |
160 | if ( type.isEmpty() || !mTypeMap.contains( type ) ) | 165 | if ( type.isEmpty() || !mTypeMap.contains( type ) ) |
161 | return 0; | 166 | return 0; |
162 | 167 | ||
163 | //US KService::Ptr ptr = mTypeMap[ type ]; | 168 | //US KService::Ptr ptr = mTypeMap[ type ]; |
164 | //US KLibFactory *factory = KLibLoader::self()->factory( ptr->library().latin1() ); | 169 | //US KLibFactory *factory = KLibLoader::self()->factory( ptr->library().latin1() ); |
165 | PluginInfo* pi = mTypeMap[ type ]; | 170 | PluginInfo* pi = mTypeMap[ type ]; |
166 | KLibFactory *factory = (KLibFactory *)KLibLoader::self()->factory( pi->library.latin1() ); | 171 | KLibFactory *factory = (KLibFactory *)KLibLoader::self()->factory( pi->library.latin1() ); |
167 | if ( !factory ) { | 172 | if ( !factory ) { |
168 | qDebug("KRES::Factory::configWidget(): Factory creation failed for library %s", pi->library.latin1()); | 173 | qDebug("KRES::Factory::configWidget(): Factory creation failed for library %s", pi->library.latin1()); |
169 | kdDebug() << "KRES::Factory::configWidget(): Factory creation failed" << endl; | 174 | kdDebug() << "KRES::Factory::configWidget(): Factory creation failed" << endl; |
170 | return 0; | 175 | return 0; |
171 | } | 176 | } |
172 | 177 | ||
173 | PluginFactoryBase *pluginFactory = static_cast<PluginFactoryBase *>( factory ); | 178 | PluginFactoryBase *pluginFactory = static_cast<PluginFactoryBase *>( factory ); |
174 | 179 | ||
175 | if ( !pluginFactory ) { | 180 | if ( !pluginFactory ) { |
176 | qDebug("KRES::Factory::configWidget(): no plugin factory for library %s", pi->library.latin1()); | 181 | qDebug("KRES::Factory::configWidget(): no plugin factory for library %s", pi->library.latin1()); |
177 | kdDebug() << "KRES::Factory::configWidget(): no plugin factory." << endl; | 182 | kdDebug() << "KRES::Factory::configWidget(): no plugin factory." << endl; |
178 | return 0; | 183 | return 0; |
179 | } | 184 | } |
180 | 185 | ||
181 | ConfigWidget *wdg = pluginFactory->configWidget( parent ); | 186 | ConfigWidget *wdg = pluginFactory->configWidget( parent ); |
182 | if ( !wdg ) { | 187 | if ( !wdg ) { |
183 | //US kdDebug() << "'" << ptr->library() << "' is not a " + mResourceFamily + " plugin." << endl; | 188 | //US kdDebug() << "'" << ptr->library() << "' is not a " + mResourceFamily + " plugin." << endl; |
184 | qDebug("%s is not a %s plugin.", pi->library.latin1(), mResourceFamily.latin1()); | 189 | qDebug("%s is not a %s plugin.", pi->library.latin1(), mResourceFamily.latin1()); |
185 | return 0; | 190 | return 0; |
186 | } | 191 | } |
187 | return wdg; | 192 | return wdg; |
188 | 193 | ||
189 | } | 194 | } |
190 | 195 | ||
191 | QString Factory::typeName( const QString &type ) const | 196 | QString Factory::typeName( const QString &type ) const |
192 | { | 197 | { |
193 | if ( type.isEmpty() || !mTypeMap.contains( type ) ) | 198 | if ( type.isEmpty() || !mTypeMap.contains( type ) ) |
194 | return QString(); | 199 | return QString(); |
195 | 200 | ||
196 | 201 | ||
197 | //US KService::Ptr ptr = mTypeMap[ type ]; | 202 | //US KService::Ptr ptr = mTypeMap[ type ]; |
198 | //US return ptr->name(); | 203 | //US return ptr->name(); |
199 | PluginInfo* pi = mTypeMap[ type ]; | 204 | PluginInfo* pi = mTypeMap[ type ]; |
200 | return pi->nameLabel; | 205 | return pi->nameLabel; |
201 | 206 | ||
202 | } | 207 | } |
203 | 208 | ||
204 | QString Factory::typeDescription( const QString &type ) const | 209 | QString Factory::typeDescription( const QString &type ) const |
205 | { | 210 | { |
206 | if ( type.isEmpty() || !mTypeMap.contains( type ) ) | 211 | if ( type.isEmpty() || !mTypeMap.contains( type ) ) |
207 | return QString(); | 212 | return QString(); |
208 | 213 | ||
209 | //US KService::Ptr ptr = mTypeMap[ type ]; | 214 | //US KService::Ptr ptr = mTypeMap[ type ]; |
210 | //US return ptr->comment(); | 215 | //US return ptr->comment(); |
211 | PluginInfo* pi = mTypeMap[ type ]; | 216 | PluginInfo* pi = mTypeMap[ type ]; |
212 | return pi->descriptionLabel; | 217 | return pi->descriptionLabel; |
213 | } | 218 | } |
214 | 219 | ||
215 | Resource *Factory::resource( const QString& type, const KConfig *config ) | 220 | Resource *Factory::resource( const QString& type, const KConfig *config ) |
216 | { | 221 | { |
217 | 222 | ||
218 | 223 | ||
219 | if ( type.isEmpty() || !mTypeMap.contains( type ) ) | 224 | if ( type.isEmpty() || !mTypeMap.contains( type ) ) |
220 | return 0; | 225 | return 0; |
221 | 226 | ||
227 | #ifdef STATIC_RESOURCES | ||
228 | qDebug("NEW STATIC RESOURCE %s", type.latin1()); | ||
229 | Resource *resource = 0; | ||
230 | if ( type == "file" ) { | ||
231 | resource = (Resource *) new KABC::ResourceFile( config ); | ||
232 | } else if ( type == "dir" ) { | ||
233 | resource = new KABC::ResourceDir( config ); | ||
234 | } else if ( type == "qtopia" ) { | ||
235 | resource = new KABC::ResourceQtopia( config ); | ||
236 | } | ||
237 | if ( !resource) | ||
238 | qDebug("Factory::resource:: resources are statically linked. resource type %s is not supported ",type.latin1() ); | ||
239 | else | ||
240 | resource->setType( type ); | ||
241 | return resource; | ||
242 | #else | ||
243 | |||
244 | |||
245 | |||
222 | /*US load the lib not dynamicly. !! | 246 | /*US load the lib not dynamicly. !! |
223 | KService::Ptr ptr = mTypeMap[ type ]; | 247 | KService::Ptr ptr = mTypeMap[ type ]; |
224 | KLibFactory *factory = KLibLoader::self()->factory( ptr->library().latin1() ); | 248 | KLibFactory *factory = KLibLoader::self()->factory( ptr->library().latin1() ); |
225 | if ( !factory ) { | 249 | if ( !factory ) { |
226 | kdDebug() << "KRES::Factory::resource(): Factory creation failed" << endl; | 250 | kdDebug() << "KRES::Factory::resource(): Factory creation failed" << endl; |
227 | return 0; | 251 | return 0; |
228 | } | 252 | } |
229 | */ | 253 | */ |
230 | PluginInfo* pi = mTypeMap[ type ]; | 254 | PluginInfo* pi = mTypeMap[ type ]; |
231 | KLibFactory *factory = (KLibFactory *)KLibLoader::self()->factory( pi->library.latin1() ); | 255 | KLibFactory *factory = (KLibFactory *)KLibLoader::self()->factory( pi->library.latin1() ); |
232 | if ( !factory ) { | 256 | if ( !factory ) { |
233 | qDebug("KRES::Factory::resource(): Factory creation failed for library %s", pi->library.latin1()); | 257 | qDebug("KRES::Factory::resource(): Factory creation failed for library %s", pi->library.latin1()); |
234 | kdDebug() << "KRES::Factory::resource(): Factory creation failed" << endl; | 258 | kdDebug() << "KRES::Factory::resource(): Factory creation failed" << endl; |
235 | return 0; | 259 | return 0; |
236 | } | 260 | } |
237 | 261 | ||
238 | PluginFactoryBase *pluginFactory = static_cast<PluginFactoryBase *>( factory ); | 262 | PluginFactoryBase *pluginFactory = static_cast<PluginFactoryBase *>( factory ); |
239 | 263 | ||
240 | if ( !pluginFactory ) { | 264 | if ( !pluginFactory ) { |
241 | qDebug("KRES::Factory::resource(): no plugin factory for library %s", pi->library.latin1()); | 265 | qDebug("KRES::Factory::resource(): no plugin factory for library %s", pi->library.latin1()); |
242 | kdDebug() << "KRES::Factory::resource(): no plugin factory." << endl; | 266 | kdDebug() << "KRES::Factory::resource(): no plugin factory." << endl; |
243 | return 0; | 267 | return 0; |
244 | } | 268 | } |
245 | 269 | ||
246 | Resource *resource = pluginFactory->resource( config ); | 270 | Resource *resource = pluginFactory->resource( config ); |
247 | if ( !resource ) { | 271 | if ( !resource ) { |
248 | //US kdDebug() << "'" << ptr->library() << "' is not a " + mResourceFamily + " plugin." << endl; | 272 | //US kdDebug() << "'" << ptr->library() << "' is not a " + mResourceFamily + " plugin." << endl; |
249 | qDebug("%s is not a %s plugin.", pi->library.latin1(), mResourceFamily.latin1()); | 273 | qDebug("%s is not a %s plugin.", pi->library.latin1(), mResourceFamily.latin1()); |
250 | return 0; | 274 | return 0; |
251 | } | 275 | } |
252 | 276 | ||
253 | resource->setType( type ); | 277 | resource->setType( type ); |
254 | 278 | ||
255 | return resource; | 279 | return resource; |
280 | |||
281 | #endif | ||
256 | } | 282 | } |
diff --git a/microkde/kresources/managerimpl.cpp b/microkde/kresources/managerimpl.cpp index 566b8f4..a6d2007 100644 --- a/microkde/kresources/managerimpl.cpp +++ b/microkde/kresources/managerimpl.cpp | |||
@@ -1,374 +1,376 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkresources. | 2 | This file is part of libkresources. |
3 | 3 | ||
4 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> | 4 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> |
5 | Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org> | 5 | Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org> |
6 | Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> | 6 | Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> |
7 | 7 | ||
8 | This library is free software; you can redistribute it and/or | 8 | This library is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU Library General Public | 9 | modify it under the terms of the GNU Library General Public |
10 | License as published by the Free Software Foundation; either | 10 | License as published by the Free Software Foundation; either |
11 | version 2 of the License, or (at your option) any later version. | 11 | version 2 of the License, or (at your option) any later version. |
12 | 12 | ||
13 | This library is distributed in the hope that it will be useful, | 13 | This library is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | Library General Public License for more details. | 16 | Library General Public License for more details. |
17 | 17 | ||
18 | You should have received a copy of the GNU Library General Public License | 18 | You should have received a copy of the GNU Library General Public License |
19 | along with this library; see the file COPYING.LIB. If not, write to | 19 | along with this library; see the file COPYING.LIB. If not, write to |
20 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 20 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
21 | Boston, MA 02111-1307, USA. | 21 | Boston, MA 02111-1307, USA. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | /* | 24 | /* |
25 | Enhanced Version of the file for platform independent KDE tools. | 25 | Enhanced Version of the file for platform independent KDE tools. |
26 | Copyright (c) 2004 Ulf Schenk | 26 | Copyright (c) 2004 Ulf Schenk |
27 | 27 | ||
28 | $Id$ | 28 | $Id$ |
29 | */ | 29 | */ |
30 | 30 | ||
31 | #include <kglobal.h> | 31 | #include <kglobal.h> |
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 | |||
44 | |||
43 | using namespace KRES; | 45 | using namespace KRES; |
44 | 46 | ||
45 | ManagerImpl::ManagerImpl( const QString &family ) | 47 | ManagerImpl::ManagerImpl( const QString &family ) |
46 | : mFamily( family ), mConfig( 0 ), mStdConfig( 0 ), mStandard( 0 ), | 48 | : mFamily( family ), mConfig( 0 ), mStdConfig( 0 ), mStandard( 0 ), |
47 | mFactory( 0 ) | 49 | mFactory( 0 ) |
48 | 50 | ||
49 | { | 51 | { |
50 | kdDebug(5650) << "ManagerImpl::ManagerImpl()" << endl; | 52 | kdDebug(5650) << "ManagerImpl::ManagerImpl()" << endl; |
51 | 53 | ||
52 | 54 | ||
53 | } | 55 | } |
54 | 56 | ||
55 | ManagerImpl::~ManagerImpl() | 57 | ManagerImpl::~ManagerImpl() |
56 | { | 58 | { |
57 | kdDebug(5650) << "ManagerImpl::~ManagerImpl()" << endl; | 59 | kdDebug(5650) << "ManagerImpl::~ManagerImpl()" << endl; |
58 | 60 | ||
59 | Resource::List::ConstIterator it; | 61 | Resource::List::ConstIterator it; |
60 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { | 62 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { |
61 | delete *it; | 63 | delete *it; |
62 | } | 64 | } |
63 | 65 | ||
64 | delete mStdConfig; | 66 | delete mStdConfig; |
65 | } | 67 | } |
66 | 68 | ||
67 | void ManagerImpl::createStandardConfig() | 69 | void ManagerImpl::createStandardConfig() |
68 | { | 70 | { |
69 | if ( !mStdConfig ) { | 71 | if ( !mStdConfig ) { |
70 | QString file = locateLocal( "data", KGlobal::getAppName() | 72 | QString file = locateLocal( "data", KGlobal::getAppName() |
71 | + "/kresources/" + mFamily + "rc" ); | 73 | + "/kresources/" + mFamily + "rc" ); |
72 | if ( mFamily == "tmpcontact" ) { | 74 | if ( mFamily == "tmpcontact" ) { |
73 | if (QFile::exists ( file ) ){ | 75 | if (QFile::exists ( file ) ){ |
74 | QFile::remove ( file ); | 76 | QFile::remove ( file ); |
75 | qDebug("removed tmp rc file: %s ", file.latin1()); | 77 | qDebug("removed tmp rc file: %s ", file.latin1()); |
76 | } | 78 | } |
77 | } | 79 | } |
78 | mStdConfig = new KConfig( file ); | 80 | mStdConfig = new KConfig( file ); |
79 | } | 81 | } |
80 | 82 | ||
81 | mConfig = mStdConfig; | 83 | mConfig = mStdConfig; |
82 | } | 84 | } |
83 | 85 | ||
84 | void ManagerImpl::readConfig( KConfig *cfg ) | 86 | void ManagerImpl::readConfig( KConfig *cfg ) |
85 | { | 87 | { |
86 | kdDebug(5650) << "ManagerImpl::readConfig()" << endl; | 88 | kdDebug(5650) << "ManagerImpl::readConfig()" << endl; |
87 | 89 | ||
88 | delete mFactory; | 90 | delete mFactory; |
89 | mFactory = Factory::self( mFamily ); | 91 | mFactory = Factory::self( mFamily ); |
90 | 92 | ||
91 | if ( !cfg ) { | 93 | if ( !cfg ) { |
92 | createStandardConfig(); | 94 | createStandardConfig(); |
93 | } else { | 95 | } else { |
94 | mConfig = cfg; | 96 | mConfig = cfg; |
95 | } | 97 | } |
96 | 98 | ||
97 | mStandard = 0; | 99 | mStandard = 0; |
98 | 100 | ||
99 | mConfig->setGroup( "General" ); | 101 | mConfig->setGroup( "General" ); |
100 | 102 | ||
101 | QStringList keys = mConfig->readListEntry( "ResourceKeys" ); | 103 | QStringList keys = mConfig->readListEntry( "ResourceKeys" ); |
102 | keys += mConfig->readListEntry( "PassiveResourceKeys" ); | 104 | keys += mConfig->readListEntry( "PassiveResourceKeys" ); |
103 | 105 | ||
104 | QString standardKey = mConfig->readEntry( "Standard" ); | 106 | QString standardKey = mConfig->readEntry( "Standard" ); |
105 | 107 | ||
106 | for ( QStringList::Iterator it = keys.begin(); it != keys.end(); ++it ) { | 108 | for ( QStringList::Iterator it = keys.begin(); it != keys.end(); ++it ) { |
107 | readResourceConfig( *it, false ); | 109 | readResourceConfig( *it, false ); |
108 | } | 110 | } |
109 | 111 | ||
110 | } | 112 | } |
111 | 113 | ||
112 | void ManagerImpl::writeConfig( KConfig *cfg ) | 114 | void ManagerImpl::writeConfig( KConfig *cfg ) |
113 | { | 115 | { |
114 | //USqDebug("ManagerImpl::writeConfig begin this= %ul cfg=%ul", this, cfg); | 116 | //USqDebug("ManagerImpl::writeConfig begin this= %ul cfg=%ul", this, cfg); |
115 | 117 | ||
116 | 118 | ||
117 | kdDebug(5650) << "ManagerImpl::writeConfig()" << endl; | 119 | kdDebug(5650) << "ManagerImpl::writeConfig()" << endl; |
118 | 120 | ||
119 | if ( !cfg ) { | 121 | if ( !cfg ) { |
120 | createStandardConfig(); | 122 | createStandardConfig(); |
121 | } else { | 123 | } else { |
122 | mConfig = cfg; | 124 | mConfig = cfg; |
123 | } | 125 | } |
124 | 126 | ||
125 | QStringList activeKeys; | 127 | QStringList activeKeys; |
126 | QStringList passiveKeys; | 128 | QStringList passiveKeys; |
127 | 129 | ||
128 | // First write all keys, collect active and passive keys on the way | 130 | // First write all keys, collect active and passive keys on the way |
129 | Resource::List::Iterator it; | 131 | Resource::List::Iterator it; |
130 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { | 132 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { |
131 | writeResourceConfig( *it, false ); | 133 | writeResourceConfig( *it, false ); |
132 | 134 | ||
133 | QString key = (*it)->identifier(); | 135 | QString key = (*it)->identifier(); |
134 | if( (*it)->isActive() ) | 136 | if( (*it)->isActive() ) |
135 | activeKeys.append( key ); | 137 | activeKeys.append( key ); |
136 | else | 138 | else |
137 | passiveKeys.append( key ); | 139 | passiveKeys.append( key ); |
138 | } | 140 | } |
139 | 141 | ||
140 | // And then the general group | 142 | // And then the general group |
141 | 143 | ||
142 | kdDebug(5650) << "Saving general info" << endl; | 144 | kdDebug(5650) << "Saving general info" << endl; |
143 | mConfig->setGroup( "General" ); | 145 | mConfig->setGroup( "General" ); |
144 | mConfig->writeEntry( "ResourceKeys", activeKeys ); | 146 | mConfig->writeEntry( "ResourceKeys", activeKeys ); |
145 | mConfig->writeEntry( "PassiveResourceKeys", passiveKeys ); | 147 | mConfig->writeEntry( "PassiveResourceKeys", passiveKeys ); |
146 | if ( mStandard ) | 148 | if ( mStandard ) |
147 | mConfig->writeEntry( "Standard", mStandard->identifier() ); | 149 | mConfig->writeEntry( "Standard", mStandard->identifier() ); |
148 | else | 150 | else |
149 | mConfig->writeEntry( "Standard", "" ); | 151 | mConfig->writeEntry( "Standard", "" ); |
150 | 152 | ||
151 | mConfig->sync(); | 153 | mConfig->sync(); |
152 | kdDebug(5650) << "ManagerImpl::save() finished" << endl; | 154 | kdDebug(5650) << "ManagerImpl::save() finished" << endl; |
153 | 155 | ||
154 | //US qDebug("ManagerImpl::writeConfig end this= %ul cfg=%ul", this, cfg); | 156 | //US qDebug("ManagerImpl::writeConfig end this= %ul cfg=%ul", this, cfg); |
155 | 157 | ||
156 | } | 158 | } |
157 | 159 | ||
158 | void ManagerImpl::add( Resource *resource, bool useDCOP ) | 160 | void ManagerImpl::add( Resource *resource, bool useDCOP ) |
159 | { | 161 | { |
160 | //qDebug("ManagerImpl::add begin this= %ul resource=%ul", this, resource); | 162 | //qDebug("ManagerImpl::add begin this= %ul resource=%ul", this, resource); |
161 | 163 | ||
162 | resource->setActive( true ); | 164 | resource->setActive( true ); |
163 | 165 | ||
164 | if ( mResources.isEmpty() ) { | 166 | if ( mResources.isEmpty() ) { |
165 | mStandard = resource; | 167 | mStandard = resource; |
166 | } | 168 | } |
167 | 169 | ||
168 | mResources.append( resource ); | 170 | mResources.append( resource ); |
169 | 171 | ||
170 | writeResourceConfig( resource, true ); | 172 | writeResourceConfig( resource, true ); |
171 | 173 | ||
172 | //qDebug("ManagerImpl::add end this= %ul resource=%ul", this, resource); | 174 | //qDebug("ManagerImpl::add end this= %ul resource=%ul", this, resource); |
173 | 175 | ||
174 | } | 176 | } |
175 | 177 | ||
176 | void ManagerImpl::remove( Resource *resource, bool useDCOP ) | 178 | void ManagerImpl::remove( Resource *resource, bool useDCOP ) |
177 | { | 179 | { |
178 | if ( mStandard == resource ) mStandard = 0; | 180 | if ( mStandard == resource ) mStandard = 0; |
179 | removeResource( resource ); | 181 | removeResource( resource ); |
180 | 182 | ||
181 | mResources.remove( resource ); | 183 | mResources.remove( resource ); |
182 | 184 | ||
183 | delete resource; | 185 | delete resource; |
184 | 186 | ||
185 | kdDebug(5650) << "Finished ManagerImpl::remove()" << endl; | 187 | kdDebug(5650) << "Finished ManagerImpl::remove()" << endl; |
186 | } | 188 | } |
187 | 189 | ||
188 | void ManagerImpl::setActive( Resource *resource, bool active ) | 190 | void ManagerImpl::setActive( Resource *resource, bool active ) |
189 | { | 191 | { |
190 | if ( resource && resource->isActive() != active ) { | 192 | if ( resource && resource->isActive() != active ) { |
191 | resource->setActive( active ); | 193 | resource->setActive( active ); |
192 | } | 194 | } |
193 | } | 195 | } |
194 | 196 | ||
195 | Resource *ManagerImpl::standardResource() | 197 | Resource *ManagerImpl::standardResource() |
196 | { | 198 | { |
197 | return mStandard; | 199 | return mStandard; |
198 | } | 200 | } |
199 | 201 | ||
200 | void ManagerImpl::setStandardResource( Resource *resource ) | 202 | void ManagerImpl::setStandardResource( Resource *resource ) |
201 | { | 203 | { |
202 | mStandard = resource; | 204 | mStandard = resource; |
203 | } | 205 | } |
204 | 206 | ||
205 | void ManagerImpl::resourceChanged( Resource *resource ) | 207 | void ManagerImpl::resourceChanged( Resource *resource ) |
206 | { | 208 | { |
207 | writeResourceConfig( resource, true ); | 209 | writeResourceConfig( resource, true ); |
208 | 210 | ||
209 | 211 | ||
210 | // ManagerIface_stub allManagers( "*", "ManagerIface_" + mFamily.utf8() ); | 212 | // ManagerIface_stub allManagers( "*", "ManagerIface_" + mFamily.utf8() ); |
211 | // allManagers.dcopResourceModified( resource->identifier() ); | 213 | // allManagers.dcopResourceModified( resource->identifier() ); |
212 | } | 214 | } |
213 | 215 | ||
214 | // DCOP asynchronous functions | 216 | // DCOP asynchronous functions |
215 | //US since we work from inside the application, we call the methods directly. | 217 | //US since we work from inside the application, we call the methods directly. |
216 | 218 | ||
217 | QStringList ManagerImpl::resourceNames() | 219 | QStringList ManagerImpl::resourceNames() |
218 | { | 220 | { |
219 | QStringList result; | 221 | QStringList result; |
220 | 222 | ||
221 | Resource::List::ConstIterator it; | 223 | Resource::List::ConstIterator it; |
222 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { | 224 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { |
223 | result.append( (*it)->resourceName() ); | 225 | result.append( (*it)->resourceName() ); |
224 | } | 226 | } |
225 | return result; | 227 | return result; |
226 | } | 228 | } |
227 | 229 | ||
228 | Resource::List *ManagerImpl::resourceList() | 230 | Resource::List *ManagerImpl::resourceList() |
229 | { | 231 | { |
230 | return &mResources; | 232 | return &mResources; |
231 | } | 233 | } |
232 | 234 | ||
233 | QPtrList<Resource> ManagerImpl::resources() | 235 | QPtrList<Resource> ManagerImpl::resources() |
234 | { | 236 | { |
235 | QPtrList<Resource> result; | 237 | QPtrList<Resource> result; |
236 | 238 | ||
237 | Resource::List::ConstIterator it; | 239 | Resource::List::ConstIterator it; |
238 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { | 240 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { |
239 | result.append( *it ); | 241 | result.append( *it ); |
240 | } | 242 | } |
241 | return result; | 243 | return result; |
242 | } | 244 | } |
243 | 245 | ||
244 | QPtrList<Resource> ManagerImpl::resources( bool active ) | 246 | QPtrList<Resource> ManagerImpl::resources( bool active ) |
245 | { | 247 | { |
246 | QPtrList<Resource> result; | 248 | QPtrList<Resource> result; |
247 | 249 | ||
248 | Resource::List::ConstIterator it; | 250 | Resource::List::ConstIterator it; |
249 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { | 251 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { |
250 | if ( (*it)->isActive() == active ) { | 252 | if ( (*it)->isActive() == active ) { |
251 | result.append( *it ); | 253 | result.append( *it ); |
252 | } | 254 | } |
253 | } | 255 | } |
254 | return result; | 256 | return result; |
255 | } | 257 | } |
256 | 258 | ||
257 | void ManagerImpl::setListener( ManagerImplListener *listener ) | 259 | void ManagerImpl::setListener( ManagerImplListener *listener ) |
258 | { | 260 | { |
259 | mListener = listener; | 261 | mListener = listener; |
260 | } | 262 | } |
261 | 263 | ||
262 | Resource* ManagerImpl::readResourceConfig( const QString& identifier, | 264 | Resource* ManagerImpl::readResourceConfig( const QString& identifier, |
263 | bool checkActive ) | 265 | bool checkActive ) |
264 | { | 266 | { |
265 | kdDebug() << "ManagerImpl::readResourceConfig() " << identifier << endl; | 267 | kdDebug() << "ManagerImpl::readResourceConfig() " << identifier << endl; |
266 | 268 | ||
267 | // qDebug("ManagerImpl::readResourceConfig() %s", identifier.latin1()); | 269 | // qDebug("ManagerImpl::readResourceConfig() %s", identifier.latin1()); |
268 | 270 | ||
269 | mConfig->setGroup( "Resource_" + identifier ); | 271 | mConfig->setGroup( "Resource_" + identifier ); |
270 | #ifdef _WIN32_ | 272 | #ifdef _WIN32_ |
271 | // we use plugins on win32. the group is stored in a static variable | 273 | // we use plugins on win32. the group is stored in a static variable |
272 | // such that gourp info not avail on win32 plugins | 274 | // such that gourp info not avail on win32 plugins |
273 | // to fix that, it would be a looooot of work | 275 | // to fix that, it would be a looooot of work |
274 | mConfig->setTempGroup( "Resource_" + identifier ); | 276 | mConfig->setTempGroup( "Resource_" + identifier ); |
275 | #endif | 277 | #endif |
276 | QString type = mConfig->readEntry( "ResourceType" ); | 278 | QString type = mConfig->readEntry( "ResourceType" ); |
277 | QString name = mConfig->readEntry( "ResourceName" ); | 279 | QString name = mConfig->readEntry( "ResourceName" ); |
278 | Resource *resource = mFactory->resource( type, mConfig ); | 280 | Resource *resource = mFactory->resource( type, mConfig ); |
279 | if ( !resource ) { | 281 | if ( !resource ) { |
280 | qDebug("Failed to create resource with id %s ",identifier.latin1() ); | 282 | qDebug("Failed to create resource with id %s ",identifier.latin1() ); |
281 | return 0; | 283 | return 0; |
282 | } | 284 | } |
283 | 285 | ||
284 | if ( resource->identifier().isEmpty() ) | 286 | if ( resource->identifier().isEmpty() ) |
285 | resource->setIdentifier( identifier ); | 287 | resource->setIdentifier( identifier ); |
286 | 288 | ||
287 | mConfig->setGroup( "General" ); | 289 | mConfig->setGroup( "General" ); |
288 | 290 | ||
289 | QString standardKey = mConfig->readEntry( "Standard" ); | 291 | QString standardKey = mConfig->readEntry( "Standard" ); |
290 | if ( standardKey == identifier ) { | 292 | if ( standardKey == identifier ) { |
291 | mStandard = resource; | 293 | mStandard = resource; |
292 | } | 294 | } |
293 | 295 | ||
294 | if ( checkActive ) { | 296 | if ( checkActive ) { |
295 | QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" ); | 297 | QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" ); |
296 | resource->setActive( activeKeys.contains( identifier ) ); | 298 | resource->setActive( activeKeys.contains( identifier ) ); |
297 | } | 299 | } |
298 | mResources.append( resource ); | 300 | mResources.append( resource ); |
299 | 301 | ||
300 | return resource; | 302 | return resource; |
301 | } | 303 | } |
302 | 304 | ||
303 | void ManagerImpl::writeResourceConfig( Resource *resource, | 305 | void ManagerImpl::writeResourceConfig( Resource *resource, |
304 | bool checkActive ) | 306 | bool checkActive ) |
305 | { | 307 | { |
306 | QString key = resource->identifier(); | 308 | QString key = resource->identifier(); |
307 | 309 | ||
308 | kdDebug(5650) << "Saving resource " << key << endl; | 310 | kdDebug(5650) << "Saving resource " << key << endl; |
309 | 311 | ||
310 | if ( !mConfig ) createStandardConfig(); | 312 | if ( !mConfig ) createStandardConfig(); |
311 | 313 | ||
312 | mConfig->setGroup( "Resource_" + key ); | 314 | mConfig->setGroup( "Resource_" + key ); |
313 | resource->writeConfig( mConfig ); | 315 | resource->writeConfig( mConfig ); |
314 | 316 | ||
315 | mConfig->setGroup( "General" ); | 317 | mConfig->setGroup( "General" ); |
316 | QString standardKey = mConfig->readEntry( "Standard" ); | 318 | QString standardKey = mConfig->readEntry( "Standard" ); |
317 | 319 | ||
318 | if ( resource == mStandard && standardKey != key ) | 320 | if ( resource == mStandard && standardKey != key ) |
319 | mConfig->writeEntry( "Standard", resource->identifier() ); | 321 | mConfig->writeEntry( "Standard", resource->identifier() ); |
320 | else if ( resource != mStandard && standardKey == key ) | 322 | else if ( resource != mStandard && standardKey == key ) |
321 | mConfig->writeEntry( "Standard", "" ); | 323 | mConfig->writeEntry( "Standard", "" ); |
322 | 324 | ||
323 | if ( checkActive ) { | 325 | if ( checkActive ) { |
324 | QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" ); | 326 | QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" ); |
325 | if ( resource->isActive() && !activeKeys.contains( key ) ) { | 327 | if ( resource->isActive() && !activeKeys.contains( key ) ) { |
326 | activeKeys.append( resource->identifier() ); | 328 | activeKeys.append( resource->identifier() ); |
327 | mConfig->writeEntry( "ResourceKeys", activeKeys ); | 329 | mConfig->writeEntry( "ResourceKeys", activeKeys ); |
328 | } else if ( !resource->isActive() && activeKeys.contains( key ) ) { | 330 | } else if ( !resource->isActive() && activeKeys.contains( key ) ) { |
329 | activeKeys.remove( key ); | 331 | activeKeys.remove( key ); |
330 | mConfig->writeEntry( "ResourceKeys", activeKeys ); | 332 | mConfig->writeEntry( "ResourceKeys", activeKeys ); |
331 | } | 333 | } |
332 | } | 334 | } |
333 | 335 | ||
334 | mConfig->sync(); | 336 | mConfig->sync(); |
335 | } | 337 | } |
336 | 338 | ||
337 | void ManagerImpl::removeResource( Resource *resource ) | 339 | void ManagerImpl::removeResource( Resource *resource ) |
338 | { | 340 | { |
339 | QString key = resource->identifier(); | 341 | QString key = resource->identifier(); |
340 | 342 | ||
341 | if ( !mConfig ) createStandardConfig(); | 343 | if ( !mConfig ) createStandardConfig(); |
342 | 344 | ||
343 | mConfig->setGroup( "General" ); | 345 | mConfig->setGroup( "General" ); |
344 | QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" ); | 346 | QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" ); |
345 | if ( activeKeys.contains( key ) ) { | 347 | if ( activeKeys.contains( key ) ) { |
346 | activeKeys.remove( key ); | 348 | activeKeys.remove( key ); |
347 | mConfig->writeEntry( "ResourceKeys", activeKeys ); | 349 | mConfig->writeEntry( "ResourceKeys", activeKeys ); |
348 | } else { | 350 | } else { |
349 | QStringList passiveKeys = mConfig->readListEntry( "PassiveResourceKeys" ); | 351 | QStringList passiveKeys = mConfig->readListEntry( "PassiveResourceKeys" ); |
350 | passiveKeys.remove( key ); | 352 | passiveKeys.remove( key ); |
351 | mConfig->writeEntry( "PassiveResourceKeys", passiveKeys ); | 353 | mConfig->writeEntry( "PassiveResourceKeys", passiveKeys ); |
352 | } | 354 | } |
353 | 355 | ||
354 | QString standardKey = mConfig->readEntry( "Standard" ); | 356 | QString standardKey = mConfig->readEntry( "Standard" ); |
355 | if ( standardKey == key ) { | 357 | if ( standardKey == key ) { |
356 | mConfig->writeEntry( "Standard", "" ); | 358 | mConfig->writeEntry( "Standard", "" ); |
357 | } | 359 | } |
358 | 360 | ||
359 | mConfig->deleteGroup( "Resource_" + resource->identifier() ); | 361 | mConfig->deleteGroup( "Resource_" + resource->identifier() ); |
360 | 362 | ||
361 | mConfig->sync(); | 363 | mConfig->sync(); |
362 | } | 364 | } |
363 | 365 | ||
364 | Resource* ManagerImpl::getResource( const QString& identifier ) | 366 | Resource* ManagerImpl::getResource( const QString& identifier ) |
365 | { | 367 | { |
366 | Resource::List::ConstIterator it; | 368 | Resource::List::ConstIterator it; |
367 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { | 369 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { |
368 | if ( (*it)->identifier() == identifier ) | 370 | if ( (*it)->identifier() == identifier ) |
369 | return *it; | 371 | return *it; |
370 | } | 372 | } |
371 | return 0; | 373 | return 0; |
372 | } | 374 | } |
373 | 375 | ||
374 | 376 | ||