author | zautrix <zautrix> | 2004-10-20 21:49:51 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-20 21:49:51 (UTC) |
commit | bb235c5a639b914574e1e247d2de6e479517585f (patch) (unidiff) | |
tree | 0f074ec87d93b6f5fb81b6893f0174cabc52c1df /microkde | |
parent | 8e00329a4a5f0b66d26d20f067ab6aefca17f17a (diff) | |
download | kdepimpi-bb235c5a639b914574e1e247d2de6e479517585f.zip kdepimpi-bb235c5a639b914574e1e247d2de6e479517585f.tar.gz kdepimpi-bb235c5a639b914574e1e247d2de6e479517585f.tar.bz2 |
qtopia resource fixes
-rw-r--r-- | microkde/kresources/managerimpl.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/microkde/kresources/managerimpl.cpp b/microkde/kresources/managerimpl.cpp index 81bbbec..5bd9eb7 100644 --- a/microkde/kresources/managerimpl.cpp +++ b/microkde/kresources/managerimpl.cpp | |||
@@ -1,262 +1,269 @@ | |||
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 | 38 | ||
38 | #include "resource.h" | 39 | #include "resource.h" |
39 | #include "factory.h" | 40 | #include "factory.h" |
40 | #include "managerimpl.h" | 41 | #include "managerimpl.h" |
41 | 42 | ||
42 | using namespace KRES; | 43 | using namespace KRES; |
43 | 44 | ||
44 | ManagerImpl::ManagerImpl( const QString &family ) | 45 | ManagerImpl::ManagerImpl( const QString &family ) |
45 | : mFamily( family ), mConfig( 0 ), mStdConfig( 0 ), mStandard( 0 ), | 46 | : mFamily( family ), mConfig( 0 ), mStdConfig( 0 ), mStandard( 0 ), |
46 | mFactory( 0 ) | 47 | mFactory( 0 ) |
47 | 48 | ||
48 | { | 49 | { |
49 | kdDebug(5650) << "ManagerImpl::ManagerImpl()" << endl; | 50 | kdDebug(5650) << "ManagerImpl::ManagerImpl()" << endl; |
50 | 51 | ||
51 | 52 | ||
52 | } | 53 | } |
53 | 54 | ||
54 | ManagerImpl::~ManagerImpl() | 55 | ManagerImpl::~ManagerImpl() |
55 | { | 56 | { |
56 | kdDebug(5650) << "ManagerImpl::~ManagerImpl()" << endl; | 57 | kdDebug(5650) << "ManagerImpl::~ManagerImpl()" << endl; |
57 | 58 | ||
58 | Resource::List::ConstIterator it; | 59 | Resource::List::ConstIterator it; |
59 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { | 60 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { |
60 | delete *it; | 61 | delete *it; |
61 | } | 62 | } |
62 | 63 | ||
63 | delete mStdConfig; | 64 | delete mStdConfig; |
64 | } | 65 | } |
65 | 66 | ||
66 | void ManagerImpl::createStandardConfig() | 67 | void ManagerImpl::createStandardConfig() |
67 | { | 68 | { |
68 | if ( !mStdConfig ) { | 69 | if ( !mStdConfig ) { |
69 | QString file = locateLocal( "data", KGlobal::getAppName() | 70 | QString file = locateLocal( "data", KGlobal::getAppName() |
70 | + "/kresources/" + mFamily + "rc" ); | 71 | + "/kresources/" + mFamily + "rc" ); |
72 | if ( mFamily == "tmpcontact" ) { | ||
73 | if (QFile::exists ( file ) ){ | ||
74 | QFile::remove ( file ); | ||
75 | qDebug("removed tmp rc file: %s ", file.latin1()); | ||
76 | } | ||
77 | } | ||
71 | mStdConfig = new KConfig( file ); | 78 | mStdConfig = new KConfig( file ); |
72 | } | 79 | } |
73 | 80 | ||
74 | mConfig = mStdConfig; | 81 | mConfig = mStdConfig; |
75 | } | 82 | } |
76 | 83 | ||
77 | void ManagerImpl::readConfig( KConfig *cfg ) | 84 | void ManagerImpl::readConfig( KConfig *cfg ) |
78 | { | 85 | { |
79 | kdDebug(5650) << "ManagerImpl::readConfig()" << endl; | 86 | kdDebug(5650) << "ManagerImpl::readConfig()" << endl; |
80 | 87 | ||
81 | delete mFactory; | 88 | delete mFactory; |
82 | mFactory = Factory::self( mFamily ); | 89 | mFactory = Factory::self( mFamily ); |
83 | 90 | ||
84 | if ( !cfg ) { | 91 | if ( !cfg ) { |
85 | createStandardConfig(); | 92 | createStandardConfig(); |
86 | } else { | 93 | } else { |
87 | mConfig = cfg; | 94 | mConfig = cfg; |
88 | } | 95 | } |
89 | 96 | ||
90 | mStandard = 0; | 97 | mStandard = 0; |
91 | 98 | ||
92 | mConfig->setGroup( "General" ); | 99 | mConfig->setGroup( "General" ); |
93 | 100 | ||
94 | QStringList keys = mConfig->readListEntry( "ResourceKeys" ); | 101 | QStringList keys = mConfig->readListEntry( "ResourceKeys" ); |
95 | keys += mConfig->readListEntry( "PassiveResourceKeys" ); | 102 | keys += mConfig->readListEntry( "PassiveResourceKeys" ); |
96 | 103 | ||
97 | QString standardKey = mConfig->readEntry( "Standard" ); | 104 | QString standardKey = mConfig->readEntry( "Standard" ); |
98 | 105 | ||
99 | for ( QStringList::Iterator it = keys.begin(); it != keys.end(); ++it ) { | 106 | for ( QStringList::Iterator it = keys.begin(); it != keys.end(); ++it ) { |
100 | readResourceConfig( *it, false ); | 107 | readResourceConfig( *it, false ); |
101 | } | 108 | } |
102 | 109 | ||
103 | } | 110 | } |
104 | 111 | ||
105 | void ManagerImpl::writeConfig( KConfig *cfg ) | 112 | void ManagerImpl::writeConfig( KConfig *cfg ) |
106 | { | 113 | { |
107 | //USqDebug("ManagerImpl::writeConfig begin this= %ul cfg=%ul", this, cfg); | 114 | //USqDebug("ManagerImpl::writeConfig begin this= %ul cfg=%ul", this, cfg); |
108 | 115 | ||
109 | 116 | ||
110 | kdDebug(5650) << "ManagerImpl::writeConfig()" << endl; | 117 | kdDebug(5650) << "ManagerImpl::writeConfig()" << endl; |
111 | 118 | ||
112 | if ( !cfg ) { | 119 | if ( !cfg ) { |
113 | createStandardConfig(); | 120 | createStandardConfig(); |
114 | } else { | 121 | } else { |
115 | mConfig = cfg; | 122 | mConfig = cfg; |
116 | } | 123 | } |
117 | 124 | ||
118 | QStringList activeKeys; | 125 | QStringList activeKeys; |
119 | QStringList passiveKeys; | 126 | QStringList passiveKeys; |
120 | 127 | ||
121 | // 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 |
122 | Resource::List::Iterator it; | 129 | Resource::List::Iterator it; |
123 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { | 130 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { |
124 | writeResourceConfig( *it, false ); | 131 | writeResourceConfig( *it, false ); |
125 | 132 | ||
126 | QString key = (*it)->identifier(); | 133 | QString key = (*it)->identifier(); |
127 | if( (*it)->isActive() ) | 134 | if( (*it)->isActive() ) |
128 | activeKeys.append( key ); | 135 | activeKeys.append( key ); |
129 | else | 136 | else |
130 | passiveKeys.append( key ); | 137 | passiveKeys.append( key ); |
131 | } | 138 | } |
132 | 139 | ||
133 | // And then the general group | 140 | // And then the general group |
134 | 141 | ||
135 | kdDebug(5650) << "Saving general info" << endl; | 142 | kdDebug(5650) << "Saving general info" << endl; |
136 | mConfig->setGroup( "General" ); | 143 | mConfig->setGroup( "General" ); |
137 | mConfig->writeEntry( "ResourceKeys", activeKeys ); | 144 | mConfig->writeEntry( "ResourceKeys", activeKeys ); |
138 | mConfig->writeEntry( "PassiveResourceKeys", passiveKeys ); | 145 | mConfig->writeEntry( "PassiveResourceKeys", passiveKeys ); |
139 | if ( mStandard ) | 146 | if ( mStandard ) |
140 | mConfig->writeEntry( "Standard", mStandard->identifier() ); | 147 | mConfig->writeEntry( "Standard", mStandard->identifier() ); |
141 | else | 148 | else |
142 | mConfig->writeEntry( "Standard", "" ); | 149 | mConfig->writeEntry( "Standard", "" ); |
143 | 150 | ||
144 | mConfig->sync(); | 151 | mConfig->sync(); |
145 | kdDebug(5650) << "ManagerImpl::save() finished" << endl; | 152 | kdDebug(5650) << "ManagerImpl::save() finished" << endl; |
146 | 153 | ||
147 | //US qDebug("ManagerImpl::writeConfig end this= %ul cfg=%ul", this, cfg); | 154 | //US qDebug("ManagerImpl::writeConfig end this= %ul cfg=%ul", this, cfg); |
148 | 155 | ||
149 | } | 156 | } |
150 | 157 | ||
151 | void ManagerImpl::add( Resource *resource, bool useDCOP ) | 158 | void ManagerImpl::add( Resource *resource, bool useDCOP ) |
152 | { | 159 | { |
153 | qDebug("ManagerImpl::add begin this= %ul resource=%ul", this, resource); | 160 | qDebug("ManagerImpl::add begin this= %ul resource=%ul", this, resource); |
154 | 161 | ||
155 | resource->setActive( true ); | 162 | resource->setActive( true ); |
156 | 163 | ||
157 | if ( mResources.isEmpty() ) { | 164 | if ( mResources.isEmpty() ) { |
158 | mStandard = resource; | 165 | mStandard = resource; |
159 | } | 166 | } |
160 | 167 | ||
161 | mResources.append( resource ); | 168 | mResources.append( resource ); |
162 | 169 | ||
163 | writeResourceConfig( resource, true ); | 170 | writeResourceConfig( resource, true ); |
164 | 171 | ||
165 | qDebug("ManagerImpl::add end this= %ul resource=%ul", this, resource); | 172 | qDebug("ManagerImpl::add end this= %ul resource=%ul", this, resource); |
166 | 173 | ||
167 | } | 174 | } |
168 | 175 | ||
169 | void ManagerImpl::remove( Resource *resource, bool useDCOP ) | 176 | void ManagerImpl::remove( Resource *resource, bool useDCOP ) |
170 | { | 177 | { |
171 | if ( mStandard == resource ) mStandard = 0; | 178 | if ( mStandard == resource ) mStandard = 0; |
172 | removeResource( resource ); | 179 | removeResource( resource ); |
173 | 180 | ||
174 | mResources.remove( resource ); | 181 | mResources.remove( resource ); |
175 | 182 | ||
176 | delete resource; | 183 | delete resource; |
177 | 184 | ||
178 | kdDebug(5650) << "Finished ManagerImpl::remove()" << endl; | 185 | kdDebug(5650) << "Finished ManagerImpl::remove()" << endl; |
179 | } | 186 | } |
180 | 187 | ||
181 | void ManagerImpl::setActive( Resource *resource, bool active ) | 188 | void ManagerImpl::setActive( Resource *resource, bool active ) |
182 | { | 189 | { |
183 | if ( resource && resource->isActive() != active ) { | 190 | if ( resource && resource->isActive() != active ) { |
184 | resource->setActive( active ); | 191 | resource->setActive( active ); |
185 | } | 192 | } |
186 | } | 193 | } |
187 | 194 | ||
188 | Resource *ManagerImpl::standardResource() | 195 | Resource *ManagerImpl::standardResource() |
189 | { | 196 | { |
190 | return mStandard; | 197 | return mStandard; |
191 | } | 198 | } |
192 | 199 | ||
193 | void ManagerImpl::setStandardResource( Resource *resource ) | 200 | void ManagerImpl::setStandardResource( Resource *resource ) |
194 | { | 201 | { |
195 | mStandard = resource; | 202 | mStandard = resource; |
196 | } | 203 | } |
197 | 204 | ||
198 | void ManagerImpl::resourceChanged( Resource *resource ) | 205 | void ManagerImpl::resourceChanged( Resource *resource ) |
199 | { | 206 | { |
200 | writeResourceConfig( resource, true ); | 207 | writeResourceConfig( resource, true ); |
201 | 208 | ||
202 | 209 | ||
203 | // ManagerIface_stub allManagers( "*", "ManagerIface_" + mFamily.utf8() ); | 210 | // ManagerIface_stub allManagers( "*", "ManagerIface_" + mFamily.utf8() ); |
204 | // allManagers.dcopResourceModified( resource->identifier() ); | 211 | // allManagers.dcopResourceModified( resource->identifier() ); |
205 | } | 212 | } |
206 | 213 | ||
207 | // DCOP asynchronous functions | 214 | // DCOP asynchronous functions |
208 | //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. |
209 | 216 | ||
210 | QStringList ManagerImpl::resourceNames() | 217 | QStringList ManagerImpl::resourceNames() |
211 | { | 218 | { |
212 | QStringList result; | 219 | QStringList result; |
213 | 220 | ||
214 | Resource::List::ConstIterator it; | 221 | Resource::List::ConstIterator it; |
215 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { | 222 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { |
216 | result.append( (*it)->resourceName() ); | 223 | result.append( (*it)->resourceName() ); |
217 | } | 224 | } |
218 | return result; | 225 | return result; |
219 | } | 226 | } |
220 | 227 | ||
221 | Resource::List *ManagerImpl::resourceList() | 228 | Resource::List *ManagerImpl::resourceList() |
222 | { | 229 | { |
223 | return &mResources; | 230 | return &mResources; |
224 | } | 231 | } |
225 | 232 | ||
226 | QPtrList<Resource> ManagerImpl::resources() | 233 | QPtrList<Resource> ManagerImpl::resources() |
227 | { | 234 | { |
228 | QPtrList<Resource> result; | 235 | QPtrList<Resource> result; |
229 | 236 | ||
230 | Resource::List::ConstIterator it; | 237 | Resource::List::ConstIterator it; |
231 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { | 238 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { |
232 | result.append( *it ); | 239 | result.append( *it ); |
233 | } | 240 | } |
234 | return result; | 241 | return result; |
235 | } | 242 | } |
236 | 243 | ||
237 | QPtrList<Resource> ManagerImpl::resources( bool active ) | 244 | QPtrList<Resource> ManagerImpl::resources( bool active ) |
238 | { | 245 | { |
239 | QPtrList<Resource> result; | 246 | QPtrList<Resource> result; |
240 | 247 | ||
241 | Resource::List::ConstIterator it; | 248 | Resource::List::ConstIterator it; |
242 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { | 249 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { |
243 | if ( (*it)->isActive() == active ) { | 250 | if ( (*it)->isActive() == active ) { |
244 | result.append( *it ); | 251 | result.append( *it ); |
245 | } | 252 | } |
246 | } | 253 | } |
247 | return result; | 254 | return result; |
248 | } | 255 | } |
249 | 256 | ||
250 | void ManagerImpl::setListener( ManagerImplListener *listener ) | 257 | void ManagerImpl::setListener( ManagerImplListener *listener ) |
251 | { | 258 | { |
252 | mListener = listener; | 259 | mListener = listener; |
253 | } | 260 | } |
254 | 261 | ||
255 | Resource* ManagerImpl::readResourceConfig( const QString& identifier, | 262 | Resource* ManagerImpl::readResourceConfig( const QString& identifier, |
256 | bool checkActive ) | 263 | bool checkActive ) |
257 | { | 264 | { |
258 | kdDebug() << "ManagerImpl::readResourceConfig() " << identifier << endl; | 265 | kdDebug() << "ManagerImpl::readResourceConfig() " << identifier << endl; |
259 | 266 | ||
260 | // qDebug("ManagerImpl::readResourceConfig() %s", identifier.latin1()); | 267 | // qDebug("ManagerImpl::readResourceConfig() %s", identifier.latin1()); |
261 | 268 | ||
262 | mConfig->setGroup( "Resource_" + identifier ); | 269 | mConfig->setGroup( "Resource_" + identifier ); |