summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kresources/manager.h44
-rw-r--r--microkde/kresources/managerimpl.cpp70
-rw-r--r--microkde/kresources/syncwidget.cpp46
-rw-r--r--microkde/kresources/syncwidget.h62
4 files changed, 180 insertions, 42 deletions
diff --git a/microkde/kresources/manager.h b/microkde/kresources/manager.h
index b5e97fc..7e9e19a 100644
--- a/microkde/kresources/manager.h
+++ b/microkde/kresources/manager.h
@@ -4,6 +4,7 @@
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 Copyright (c) 2004 Ulf Schenk
7 8
8 This library is free software; you can redistribute it and/or 9 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public 10 modify it under the terms of the GNU Library General Public
@@ -21,6 +22,13 @@
21 Boston, MA 02111-1307, USA. 22 Boston, MA 02111-1307, USA.
22*/ 23*/
23 24
25/*
26Enhanced Version of the file for platform independent KDE tools.
27Copyright (c) 2004 Ulf Schenk
28
29$Id$
30*/
31
24#ifndef KRESOURCES_MANAGER_H 32#ifndef KRESOURCES_MANAGER_H
25#define KRESOURCES_MANAGER_H 33#define KRESOURCES_MANAGER_H
26 34
@@ -48,7 +56,7 @@ class ManagerListener
48// to warn applications that resources have been added, 56// to warn applications that resources have been added,
49// removed or modified. 57// removed or modified.
50// 58//
51// The manager should also keep track of which (or at least 59// The manager should also keep track of which (or at least
52// how many) applications hve opened a resource, so that it 60// how many) applications hve opened a resource, so that it
53// is only closed if none of them is using it any more 61// is only closed if none of them is using it any more
54 62
@@ -71,7 +79,7 @@ class Manager : private ManagerImplListener
71 bool operator==( const Iterator &it ) { return mIt == it.mIt; } 79 bool operator==( const Iterator &it ) { return mIt == it.mIt; }
72 bool operator!=( const Iterator &it ) { return mIt != it.mIt; } 80 bool operator!=( const Iterator &it ) { return mIt != it.mIt; }
73 81
74 private: 82 private:
75 Resource::List::Iterator mIt; 83 Resource::List::Iterator mIt;
76 }; 84 };
77 85
@@ -81,7 +89,7 @@ class Manager : private ManagerImplListener
81 it.mIt = mImpl->resourceList()->begin(); 89 it.mIt = mImpl->resourceList()->begin();
82 return it; 90 return it;
83 } 91 }
84 92
85 Iterator end() 93 Iterator end()
86 { 94 {
87 Iterator it; 95 Iterator it;
@@ -159,19 +167,24 @@ class Manager : private ManagerImplListener
159 167
160 bool isEmpty() const { return mImpl->resourceList()->isEmpty(); } 168 bool isEmpty() const { return mImpl->resourceList()->isEmpty(); }
161 169
162 Manager( const QString &family ) 170 /**
171 Return true, if the manager manages syncable resources.
172 */
173 bool manageSyncable() { return mImpl->manageSyncable(); }
174
175 Manager( const QString &family, bool syncable )
163 { 176 {
164 mFactory = Factory::self( family ); 177 mFactory = Factory::self( family );
165 // The managerimpl will use the same Factory object as the manager 178 // The managerimpl will use the same Factory object as the manager
166 // because of the Factory::self() pattern 179 // because of the Factory::self() pattern
167 mImpl = new ManagerImpl( family ); 180 mImpl = new ManagerImpl( family, syncable );
168 mImpl->setListener( this ); 181 mImpl->setListener( this );
169 182
170 mListeners = new QPtrList<ManagerListener<T> >; 183 mListeners = new QPtrList<ManagerListener<T> >;
171 } 184 }
172 185
173 virtual ~Manager() 186 virtual ~Manager()
174 { 187 {
175 mImpl->setListener( 0 ); 188 mImpl->setListener( 0 );
176 delete mListeners; 189 delete mListeners;
177 delete mImpl; 190 delete mImpl;
@@ -239,18 +252,19 @@ class Manager : private ManagerImplListener
239 } 252 }
240 253
241 /** 254 /**
242 Creates a new resource of type @param type, with default 255 Creates a new resource of type @param type, with default
243 settings. The resource is 256 settings. The resource is
244 not added to the manager, the application has to do that. 257 not added to the manager, the application has to do that.
245 Returns a pointer to a resource object or a null pointer 258 Returns a pointer to a resource object or a null pointer
246 if resource type doesn't exist. 259 if resource type doesn't exist.
247 260
248 @param type The type of the resource, one of those returned 261 @param type The type of the resource, one of those returned
249 by @ref resourceTypeNames() 262 by @ref resourceTypeNames()
263 * @param syncable If the resource should support syncing capabilities.
250 */ 264 */
251 T *createResource( const QString& type ) 265 T *createResource( const QString& type )
252 { 266 {
253 return (T *)( mFactory->resource( type, 0 ) ); 267 return (T *)( mFactory->resource( type, 0, mImpl->manageSyncable() ) );
254 } 268 }
255 269
256 /** 270 /**
@@ -278,8 +292,8 @@ class Manager : private ManagerImplListener
278 } 292 }
279 293
280 void resourceChanged( T *resource ) 294 void resourceChanged( T *resource )
281 { 295 {
282 mImpl->resourceChanged( resource ); 296 mImpl->resourceChanged( resource );
283 } 297 }
284 298
285 void addListener( ManagerListener<T> *listener ) 299 void addListener( ManagerListener<T> *listener )
@@ -309,7 +323,7 @@ class Manager : private ManagerImplListener
309 for ( listener = mListeners->first(); listener; listener = mListeners->next() ) 323 for ( listener = mListeners->first(); listener; listener = mListeners->next() )
310 listener->resourceModified( resource ); 324 listener->resourceModified( resource );
311 } 325 }
312 326
313 virtual void resourceDeleted( Resource *res ) 327 virtual void resourceDeleted( Resource *res )
314 { 328 {
315 kdDebug(5650) << "Manager::resourceDeleted " << res->resourceName() << endl; 329 kdDebug(5650) << "Manager::resourceDeleted " << res->resourceName() << endl;
diff --git a/microkde/kresources/managerimpl.cpp b/microkde/kresources/managerimpl.cpp
index 785b6b4..3655f50 100644
--- a/microkde/kresources/managerimpl.cpp
+++ b/microkde/kresources/managerimpl.cpp
@@ -1,6 +1,6 @@
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>
@@ -21,6 +21,13 @@
21 Boston, MA 02111-1307, USA. 21 Boston, MA 02111-1307, USA.
22*/ 22*/
23 23
24/*
25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk
27
28$Id$
29*/
30
24#include <kglobal.h> 31#include <kglobal.h>
25 32
26#include <kapplication.h> 33#include <kapplication.h>
@@ -34,14 +41,14 @@
34 41
35using namespace KRES; 42using namespace KRES;
36 43
37ManagerImpl::ManagerImpl( const QString &family ) 44ManagerImpl::ManagerImpl( const QString &family, bool syncable )
38 : mFamily( family ), mConfig( 0 ), mStdConfig( 0 ), mStandard( 0 ), 45 : mFamily( family ), mSyncable(syncable), mConfig( 0 ), mStdConfig( 0 ), mStandard( 0 ),
39 mFactory( 0 ) 46 mFactory( 0 )
40 47
41{ 48{
42 kdDebug(5650) << "ManagerImpl::ManagerImpl()" << endl; 49 kdDebug(5650) << "ManagerImpl::ManagerImpl()" << endl;
43 50
44 51
45} 52}
46 53
47ManagerImpl::~ManagerImpl() 54ManagerImpl::~ManagerImpl()
@@ -52,18 +59,18 @@ ManagerImpl::~ManagerImpl()
52 for ( it = mResources.begin(); it != mResources.end(); ++it ) { 59 for ( it = mResources.begin(); it != mResources.end(); ++it ) {
53 delete *it; 60 delete *it;
54 } 61 }
55 62
56 delete mStdConfig; 63 delete mStdConfig;
57} 64}
58 65
59void ManagerImpl::createStandardConfig() 66void ManagerImpl::createStandardConfig()
60{ 67{
61 if ( !mStdConfig ) { 68 if ( !mStdConfig ) {
62 QString file = locateLocal( "data", KGlobal::getAppName() 69 QString file = locateLocal( "data", KGlobal::getAppName()
63 + "/kresources/" + mFamily + "rc" ); 70 + "/kresources/" + mFamily + "rc" );
64 mStdConfig = new KConfig( file ); 71 mStdConfig = new KConfig( file );
65 } 72 }
66 73
67 mConfig = mStdConfig; 74 mConfig = mStdConfig;
68} 75}
69 76
@@ -79,7 +86,7 @@ void ManagerImpl::readConfig( KConfig *cfg )
79 } else { 86 } else {
80 mConfig = cfg; 87 mConfig = cfg;
81 } 88 }
82 89
83 mStandard = 0; 90 mStandard = 0;
84 91
85 mConfig->setGroup( "General" ); 92 mConfig->setGroup( "General" );
@@ -92,14 +99,14 @@ void ManagerImpl::readConfig( KConfig *cfg )
92 for ( QStringList::Iterator it = keys.begin(); it != keys.end(); ++it ) { 99 for ( QStringList::Iterator it = keys.begin(); it != keys.end(); ++it ) {
93 readResourceConfig( *it, false ); 100 readResourceConfig( *it, false );
94 } 101 }
95 102
96} 103}
97 104
98void ManagerImpl::writeConfig( KConfig *cfg ) 105void ManagerImpl::writeConfig( KConfig *cfg )
99{ 106{
100//USqDebug("ManagerImpl::writeConfig begin this= %ul cfg=%ul", this, cfg); 107//USqDebug("ManagerImpl::writeConfig begin this= %ul cfg=%ul", this, cfg);
101 108
102 109
103 kdDebug(5650) << "ManagerImpl::writeConfig()" << endl; 110 kdDebug(5650) << "ManagerImpl::writeConfig()" << endl;
104 111
105 if ( !cfg ) { 112 if ( !cfg ) {
@@ -107,7 +114,7 @@ void ManagerImpl::writeConfig( KConfig *cfg )
107 } else { 114 } else {
108 mConfig = cfg; 115 mConfig = cfg;
109 } 116 }
110 117
111 QStringList activeKeys; 118 QStringList activeKeys;
112 QStringList passiveKeys; 119 QStringList passiveKeys;
113 120
@@ -129,22 +136,22 @@ void ManagerImpl::writeConfig( KConfig *cfg )
129 mConfig->setGroup( "General" ); 136 mConfig->setGroup( "General" );
130 mConfig->writeEntry( "ResourceKeys", activeKeys ); 137 mConfig->writeEntry( "ResourceKeys", activeKeys );
131 mConfig->writeEntry( "PassiveResourceKeys", passiveKeys ); 138 mConfig->writeEntry( "PassiveResourceKeys", passiveKeys );
132 if ( mStandard ) 139 if ( mStandard )
133 mConfig->writeEntry( "Standard", mStandard->identifier() ); 140 mConfig->writeEntry( "Standard", mStandard->identifier() );
134 else 141 else
135 mConfig->writeEntry( "Standard", "" ); 142 mConfig->writeEntry( "Standard", "" );
136 143
137 mConfig->sync(); 144 mConfig->sync();
138 kdDebug(5650) << "ManagerImpl::save() finished" << endl; 145 kdDebug(5650) << "ManagerImpl::save() finished" << endl;
139 146
140//US qDebug("ManagerImpl::writeConfig end this= %ul cfg=%ul", this, cfg); 147//US qDebug("ManagerImpl::writeConfig end this= %ul cfg=%ul", this, cfg);
141 148
142} 149}
143 150
144void ManagerImpl::add( Resource *resource, bool useDCOP ) 151void ManagerImpl::add( Resource *resource, bool useDCOP )
145{ 152{
146qDebug("ManagerImpl::add begin this= %ul resource=%ul", this, resource); 153qDebug("ManagerImpl::add begin this= %ul resource=%ul", this, resource);
147 154
148 resource->setActive( true ); 155 resource->setActive( true );
149 156
150 if ( mResources.isEmpty() ) { 157 if ( mResources.isEmpty() ) {
@@ -155,7 +162,7 @@ qDebug("ManagerImpl::add begin this= %ul resource=%ul", this, resource);
155 162
156 writeResourceConfig( resource, true ); 163 writeResourceConfig( resource, true );
157 164
158 qDebug("ManagerImpl::add end this= %ul resource=%ul", this, resource); 165 qDebug("ManagerImpl::add end this= %ul resource=%ul", this, resource);
159 166
160} 167}
161 168
@@ -178,12 +185,12 @@ void ManagerImpl::setActive( Resource *resource, bool active )
178 } 185 }
179} 186}
180 187
181Resource *ManagerImpl::standardResource() 188Resource *ManagerImpl::standardResource()
182{ 189{
183 return mStandard; 190 return mStandard;
184} 191}
185 192
186void ManagerImpl::setStandardResource( Resource *resource ) 193void ManagerImpl::setStandardResource( Resource *resource )
187{ 194{
188 mStandard = resource; 195 mStandard = resource;
189} 196}
@@ -249,7 +256,7 @@ Resource* ManagerImpl::readResourceConfig( const QString& identifier,
249 bool checkActive ) 256 bool checkActive )
250{ 257{
251 kdDebug() << "ManagerImpl::readResourceConfig() " << identifier << endl; 258 kdDebug() << "ManagerImpl::readResourceConfig() " << identifier << endl;
252 259
253// qDebug("ManagerImpl::readResourceConfig() %s", identifier.latin1()); 260// qDebug("ManagerImpl::readResourceConfig() %s", identifier.latin1());
254 261
255 mConfig->setGroup( "Resource_" + identifier ); 262 mConfig->setGroup( "Resource_" + identifier );
@@ -261,7 +268,7 @@ Resource* ManagerImpl::readResourceConfig( const QString& identifier,
261#endif 268#endif
262 QString type = mConfig->readEntry( "ResourceType" ); 269 QString type = mConfig->readEntry( "ResourceType" );
263 QString name = mConfig->readEntry( "ResourceName" ); 270 QString name = mConfig->readEntry( "ResourceName" );
264 Resource *resource = mFactory->resource( type, mConfig ); 271 Resource *resource = mFactory->resource( type, mConfig, mSyncable );
265 if ( !resource ) { 272 if ( !resource ) {
266 qDebug("Failed to create resource with id %s ",identifier.latin1() ); 273 qDebug("Failed to create resource with id %s ",identifier.latin1() );
267 return 0; 274 return 0;
@@ -305,7 +312,7 @@ void ManagerImpl::writeResourceConfig( Resource *resource,
305 mConfig->writeEntry( "Standard", resource->identifier() ); 312 mConfig->writeEntry( "Standard", resource->identifier() );
306 else if ( resource != mStandard && standardKey == key ) 313 else if ( resource != mStandard && standardKey == key )
307 mConfig->writeEntry( "Standard", "" ); 314 mConfig->writeEntry( "Standard", "" );
308 315
309 if ( checkActive ) { 316 if ( checkActive ) {
310 QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" ); 317 QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" );
311 if ( resource->isActive() && !activeKeys.contains( key ) ) { 318 if ( resource->isActive() && !activeKeys.contains( key ) ) {
@@ -325,7 +332,7 @@ void ManagerImpl::removeResource( Resource *resource )
325 QString key = resource->identifier(); 332 QString key = resource->identifier();
326 333
327 if ( !mConfig ) createStandardConfig(); 334 if ( !mConfig ) createStandardConfig();
328 335
329 mConfig->setGroup( "General" ); 336 mConfig->setGroup( "General" );
330 QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" ); 337 QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" );
331 if ( activeKeys.contains( key ) ) { 338 if ( activeKeys.contains( key ) ) {
@@ -356,3 +363,12 @@ Resource* ManagerImpl::getResource( const QString& identifier )
356 } 363 }
357 return 0; 364 return 0;
358} 365}
366
367/**
368 Return true, if the manager manages syncable resources.
369*/
370bool ManagerImpl::manageSyncable() const
371{
372 return mSyncable;
373}
374
diff --git a/microkde/kresources/syncwidget.cpp b/microkde/kresources/syncwidget.cpp
new file mode 100644
index 0000000..9bb0df6
--- a/dev/null
+++ b/microkde/kresources/syncwidget.cpp
@@ -0,0 +1,46 @@
1/*
2 This file is part of libkresources.
3
4 Copyright (c) 2004 Ulf Schenk
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
20*/
21
22// $Id$
23
24#include "syncwidget.h"
25
26using namespace KRES;
27
28
29SyncWidget::SyncWidget( QWidget *parent, const char *name )
30 : QWidget( parent, name )
31{
32}
33
34void SyncWidget::setInEditMode( bool )
35{
36}
37
38void SyncWidget::loadSettings( Resource * )
39{
40}
41
42void SyncWidget::saveSettings( Resource * )
43{
44}
45
46
diff --git a/microkde/kresources/syncwidget.h b/microkde/kresources/syncwidget.h
new file mode 100644
index 0000000..e94252c
--- a/dev/null
+++ b/microkde/kresources/syncwidget.h
@@ -0,0 +1,62 @@
1/*
2 This file is part of libkresources.
3 Copyright (c) 2004 Ulf Schenk
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21// $Id$
22
23#ifndef KRESOURCES_SYNCWIDGET_H
24#define KRESOURCES_SYNCWIDGET_H
25
26#include <qwidget.h>
27
28#include <kconfig.h>
29
30#include "resource.h"
31
32namespace KRES {
33
34class SyncWidget : public QWidget
35{
36 Q_OBJECT
37
38public:
39 SyncWidget( QWidget *parent = 0, const char *name = 0 );
40
41 /**
42 Sets the widget to 'edit' mode. Reimplement this method if you are
43 interested in the mode change (to disable some GUI element for
44 example). By default the widget is in 'create new' mode.
45 */
46 virtual void setInEditMode( bool value );
47
48public slots:
49 virtual void loadSettings( Resource *resource );
50 virtual void saveSettings( Resource *resource );
51
52signals:
53//US void setReadOnly( bool value );
54//US void setPersistentReadOnly( bool value );
55
56
57protected:
58//US Resource* mResource;
59};
60
61}
62#endif