summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-08-02 18:10:42 (UTC)
committer ulf69 <ulf69>2004-08-02 18:10:42 (UTC)
commit09e8e7e5d4c3cafcf2b05511e5c78717fb5380e7 (patch) (unidiff)
tree4060a8dad4d840c92c62c16f9c51e733da51e33c
parent7520e7cb4f10eb535efd457c539a15a0b7e52137 (diff)
downloadkdepimpi-09e8e7e5d4c3cafcf2b05511e5c78717fb5380e7.zip
kdepimpi-09e8e7e5d4c3cafcf2b05511e5c78717fb5380e7.tar.gz
kdepimpi-09e8e7e5d4c3cafcf2b05511e5c78717fb5380e7.tar.bz2
add changes that resources can be used for syncing as well
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kresources/managerimpl.h19
-rw-r--r--microkde/kresources/resource.cpp5
-rw-r--r--microkde/kresources/resource.h25
3 files changed, 39 insertions, 10 deletions
diff --git a/microkde/kresources/managerimpl.h b/microkde/kresources/managerimpl.h
index a049bcc..0425279 100644
--- a/microkde/kresources/managerimpl.h
+++ b/microkde/kresources/managerimpl.h
@@ -1,113 +1,126 @@
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/*
25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk
27
28$Id$
29*/
30
24#ifndef KRESOURCES_MANAGERIMPL_H 31#ifndef KRESOURCES_MANAGERIMPL_H
25#define KRESOURCES_MANAGERIMPL_H 32#define KRESOURCES_MANAGERIMPL_H
26 33
27#include <qstring.h> 34#include <qstring.h>
28#include <qptrlist.h> 35#include <qptrlist.h>
29#include <qdict.h> 36#include <qdict.h>
30//US 37//US
31#include <qobject.h> 38#include <qobject.h>
32 39
33#include "resource.h" 40#include "resource.h"
34 41
35 42
36class KConfig; 43class KConfig;
37 44
38namespace KRES { 45namespace KRES {
39 46
40class Resource; 47class Resource;
41class Factory; 48class Factory;
42 49
43class ManagerImplListener 50class ManagerImplListener
44{ 51{
45 public: 52 public:
46 virtual void resourceAdded( Resource *resource ) = 0; 53 virtual void resourceAdded( Resource *resource ) = 0;
47 virtual void resourceModified( Resource *resource ) = 0; 54 virtual void resourceModified( Resource *resource ) = 0;
48 virtual void resourceDeleted( Resource *resource ) = 0; 55 virtual void resourceDeleted( Resource *resource ) = 0;
49}; 56};
50 57
51 58
52/** 59/**
53 @internal 60 @internal
54 61
55 Do not use this class directly. Use ResourceManager instead 62 Do not use this class directly. Use ResourceManager instead
56*/ 63*/
57class ManagerImpl : public QObject 64class ManagerImpl : public QObject
58{ 65{
59 Q_OBJECT 66 Q_OBJECT
60 public: 67 public:
61 ManagerImpl( const QString &family ); 68 ManagerImpl( const QString &family, bool syncable);
62 ~ManagerImpl(); 69 ~ManagerImpl();
63 70
64 void readConfig( KConfig * ); 71 void readConfig( KConfig * );
65 void writeConfig( KConfig * ); 72 void writeConfig( KConfig * );
66 73
67 void add( Resource *resource, bool useDCOP = true ); 74 void add( Resource *resource, bool useDCOP = true );
68 void remove( Resource *resource, bool useDCOP = true ); 75 void remove( Resource *resource, bool useDCOP = true );
69 76
70 Resource *standardResource(); 77 Resource *standardResource();
71 void setStandardResource( Resource *resource ); 78 void setStandardResource( Resource *resource );
72 79
73 void setActive( Resource *resource, bool active ); 80 void setActive( Resource *resource, bool active );
74 81
75 Resource::List *resourceList(); 82 Resource::List *resourceList();
76 83
77 QPtrList<Resource> resources(); 84 QPtrList<Resource> resources();
78 85
79 // Get only active or passive resources 86 // Get only active or passive resources
80 QPtrList<Resource> resources( bool active ); 87 QPtrList<Resource> resources( bool active );
81 88
82 QStringList resourceNames(); 89 QStringList resourceNames();
83 90
84 void setListener( ManagerImplListener *listener ); 91 void setListener( ManagerImplListener *listener );
85 92
93 /**
94 Return true, if the manager manages syncable resources.
95 */
96 bool manageSyncable() const;
97
86 public slots: 98 public slots:
87 void resourceChanged( Resource *resource ); 99 void resourceChanged( Resource *resource );
88 100
89 private: 101 private:
90 // dcop calls 102 // dcop calls
91 103
92 private: 104 private:
93 void createStandardConfig(); 105 void createStandardConfig();
94 106
95 Resource *readResourceConfig( const QString& identifier, bool checkActive ); 107 Resource *readResourceConfig( const QString& identifier, bool checkActive );
96 void writeResourceConfig( Resource *resource, bool checkActive ); 108 void writeResourceConfig( Resource *resource, bool checkActive );
97 109
98 void removeResource( Resource *resource ); 110 void removeResource( Resource *resource );
99 Resource *getResource( Resource *resource ); 111 Resource *getResource( Resource *resource );
100 Resource *getResource( const QString& identifier ); 112 Resource *getResource( const QString& identifier );
101 113
102 QString mFamily; 114 QString mFamily;
115 bool mSyncable;
103 KConfig *mConfig; 116 KConfig *mConfig;
104 KConfig *mStdConfig; 117 KConfig *mStdConfig;
105 Resource *mStandard; 118 Resource *mStandard;
106 Factory *mFactory; 119 Factory *mFactory;
107 Resource::List mResources; 120 Resource::List mResources;
108 ManagerImplListener *mListener; 121 ManagerImplListener *mListener;
109}; 122};
110 123
111} 124}
112 125
113#endif 126#endif
diff --git a/microkde/kresources/resource.cpp b/microkde/kresources/resource.cpp
index 991d53d..4f69540 100644
--- a/microkde/kresources/resource.cpp
+++ b/microkde/kresources/resource.cpp
@@ -30,80 +30,80 @@
30using namespace KRES; 30using namespace KRES;
31 31
32class Resource::ResourcePrivate 32class Resource::ResourcePrivate
33{ 33{
34 public: 34 public:
35#ifdef QT_THREAD_SUPPORT 35#ifdef QT_THREAD_SUPPORT
36 QMutex mMutex; 36 QMutex mMutex;
37#endif 37#endif
38 int mOpenCount; 38 int mOpenCount;
39 QString mType; 39 QString mType;
40 QString mIdentifier; 40 QString mIdentifier;
41 bool mReadOnly; 41 bool mReadOnly;
42 QString mName; 42 QString mName;
43 bool mActive; 43 bool mActive;
44 bool mIsOpen; 44 bool mIsOpen;
45}; 45};
46 46
47Resource::Resource( const KConfig* config ) 47Resource::Resource( const KConfig* config )
48 : QObject( 0, "" ), d( new ResourcePrivate ) 48 : QObject( 0, "" ), d( new ResourcePrivate )
49{ 49{
50 d->mOpenCount = 0; 50 d->mOpenCount = 0;
51 d->mIsOpen = false; 51 d->mIsOpen = false;
52 52
53 //US compiler claimed that const discards qualifier 53 //US compiler claimed that const discards qualifier
54 KConfig* cfg = (KConfig*)config; 54 KConfig* cfg = (KConfig*)config;
55 if ( cfg ) { 55 if ( cfg ) {
56#ifdef _WIN32_ 56#ifdef _WIN32_
57 // we use plugins on win32. the group is stored in a static variable 57 // we use plugins on win32. the group is stored in a static variable
58 // such that group info not available on win32 plugins 58 // such that group info not available on win32 plugins
59 // to fix that, it would be a looooot of work 59 // to fix that, it would be a looooot of work
60 if ( !cfg->tempGroup().isEmpty() ) 60 if ( !cfg->tempGroup().isEmpty() )
61 cfg->setGroup( cfg->tempGroup() ); 61 cfg->setGroup( cfg->tempGroup() );
62#endif 62#endif
63 d->mType = cfg->readEntry( "ResourceType" ); 63 d->mType = cfg->readEntry( "ResourceType" );
64 d->mName = cfg->readEntry( "ResourceName" ); 64 d->mName = cfg->readEntry( "ResourceName" );
65 d->mReadOnly = cfg->readBoolEntry( "ResourceIsReadOnly", false ); 65 d->mReadOnly = cfg->readBoolEntry( "ResourceIsReadOnly", false );
66 d->mActive = cfg->readBoolEntry( "ResourceIsActive", true ); 66 d->mActive = cfg->readBoolEntry( "ResourceIsActive", true );
67 d->mIdentifier = cfg->readEntry( "ResourceIdentifier" ); 67 d->mIdentifier = cfg->readEntry( "ResourceIdentifier" );
68 } else { 68 } else {
69 d->mType = "type"; 69 d->mType = "type";
70 d->mName = "resource-name"; 70 d->mName = "resource-name";
71 d->mReadOnly = false; 71 d->mReadOnly = false;
72 d->mActive = true; 72 d->mActive = true;
73 d->mIdentifier = KApplication::randomString( 10 ); 73 d->mIdentifier = KApplication::randomString( 10 );
74 } 74 }
75} 75}
76 76
77Resource::~Resource() 77Resource::~Resource()
78{ 78{
79 delete d; 79 delete d;
80 d = 0; 80 d = 0;
81} 81}
82 82
83void Resource::writeConfig( KConfig* config ) 83void Resource::writeConfig( KConfig* config )
84{ 84{
85 85
86 86
87 config->writeEntry( "ResourceType", d->mType ); 87 config->writeEntry( "ResourceType", d->mType );
88 config->writeEntry( "ResourceName", d->mName ); 88 config->writeEntry( "ResourceName", d->mName );
89 config->writeEntry( "ResourceIsReadOnly", d->mReadOnly ); 89 config->writeEntry( "ResourceIsReadOnly", d->mReadOnly );
90 config->writeEntry( "ResourceIsActive", d->mActive ); 90 config->writeEntry( "ResourceIsActive", d->mActive );
91 config->writeEntry( "ResourceIdentifier", d->mIdentifier ); 91 config->writeEntry( "ResourceIdentifier", d->mIdentifier );
92} 92}
93 93
94bool Resource::open() 94bool Resource::open()
95{ 95{
96 d->mIsOpen = true; 96 d->mIsOpen = true;
97#ifdef QT_THREAD_SUPPORT 97#ifdef QT_THREAD_SUPPORT
98 QMutexLocker guard( &(d->mMutex) ); 98 QMutexLocker guard( &(d->mMutex) );
99#endif 99#endif
100 if ( !d->mOpenCount ) { 100 if ( !d->mOpenCount ) {
101 kdDebug(5650) << "Opening resource " << resourceName() << endl; 101 kdDebug(5650) << "Opening resource " << resourceName() << endl;
102 d->mIsOpen = doOpen(); 102 d->mIsOpen = doOpen();
103 } 103 }
104 d->mOpenCount++; 104 d->mOpenCount++;
105 return d->mIsOpen; 105 return d->mIsOpen;
106} 106}
107 107
108void Resource::close() 108void Resource::close()
109{ 109{
@@ -170,24 +170,25 @@ QString Resource::resourceName() const
170} 170}
171 171
172void Resource::setActive( bool value ) 172void Resource::setActive( bool value )
173{ 173{
174 d->mActive = value; 174 d->mActive = value;
175} 175}
176 176
177bool Resource::isActive() const 177bool Resource::isActive() const
178{ 178{
179 return d->mActive; 179 return d->mActive;
180} 180}
181 181
182void Resource::dump() const 182void Resource::dump() const
183{ 183{
184 qDebug("Resource::dump() "); 184 qDebug("Resource::dump() ");
185 kdDebug(5650) << "Resource:" << endl; 185 kdDebug(5650) << "Resource:" << endl;
186 kdDebug(5650) << " Name: " << d->mName << endl; 186 kdDebug(5650) << " Name: " << d->mName << endl;
187 kdDebug(5650) << " Identifier: " << d->mIdentifier << endl; 187 kdDebug(5650) << " Identifier: " << d->mIdentifier << endl;
188 kdDebug(5650) << " Type: " << d->mType << endl; 188 kdDebug(5650) << " Type: " << d->mType << endl;
189 kdDebug(5650) << " OpenCount: " << d->mOpenCount << endl; 189 kdDebug(5650) << " OpenCount: " << d->mOpenCount << endl;
190 kdDebug(5650) << " ReadOnly: " << ( d->mReadOnly ? "yes" : "no" ) << endl; 190 kdDebug(5650) << " ReadOnly: " << ( d->mReadOnly ? "yes" : "no" ) << endl;
191 kdDebug(5650) << " Active: " << ( d->mActive ? "yes" : "no" ) << endl; 191 kdDebug(5650) << " Active: " << ( d->mActive ? "yes" : "no" ) << endl;
192 kdDebug(5650) << " IsOpen: " << ( d->mIsOpen ? "yes" : "no" ) << endl; 192 kdDebug(5650) << " IsOpen: " << ( d->mIsOpen ? "yes" : "no" ) << endl;
193} 193}
194
diff --git a/microkde/kresources/resource.h b/microkde/kresources/resource.h
index 64e7424..c9202c9 100644
--- a/microkde/kresources/resource.h
+++ b/microkde/kresources/resource.h
@@ -19,48 +19,49 @@
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22 22
23#ifndef KRESOURCES_RESOURCE_H 23#ifndef KRESOURCES_RESOURCE_H
24#define KRESOURCES_RESOURCE_H 24#define KRESOURCES_RESOURCE_H
25 25
26//US 26//US
27#ifdef QT_THREAD_SUPPORT 27#ifdef QT_THREAD_SUPPORT
28#include <qmutex.h> 28#include <qmutex.h>
29#endif //QT_THREAD_SUPPORT 29#endif //QT_THREAD_SUPPORT
30 30
31#include <qvaluelist.h> 31#include <qvaluelist.h>
32#include <qwidget.h> 32#include <qwidget.h>
33 33
34#include <qobject.h> 34#include <qobject.h>
35 35
36#include <klibloader.h> 36#include <klibloader.h>
37 37
38class KConfig; 38class KConfig;
39 39
40namespace KRES { 40namespace KRES {
41 41
42class ConfigWidget; 42class ConfigWidget;
43class SyncWidget;
43 44
44/** 45/**
45 * @internal 46 * @internal
46 * @libdoc The KDE Resource library 47 * @libdoc The KDE Resource library
47 * 48 *
48 * NOTE: this library is NOT (YET?) PUBLIC. Do not publish this 49 * NOTE: this library is NOT (YET?) PUBLIC. Do not publish this
49 * interface, it is in constant flux. 50 * interface, it is in constant flux.
50 * 51 *
51 * The KDE Resource framework can be used to manage resources of 52 * The KDE Resource framework can be used to manage resources of
52 * different types, organized in families. The Resource framework 53 * different types, organized in families. The Resource framework
53 * is currently used for addressbook resources in libkabc and for 54 * is currently used for addressbook resources in libkabc and for
54 * calendar resources in libkcal. 55 * calendar resources in libkcal.
55 * 56 *
56 * When you want to use the framework for a new family, you need to 57 * When you want to use the framework for a new family, you need to
57 * <ul><li>Define a name for your resource family</li> 58 * <ul><li>Define a name for your resource family</li>
58 * <li>subclass Resource and add the fields and method that are needed 59 * <li>subclass Resource and add the fields and method that are needed
59 * in your application</li> 60 * in your application</li>
60 * <li>If needed, override the doOpen() and doClose() methods. 61 * <li>If needed, override the doOpen() and doClose() methods.
61 * <li> Provide a configuration possibility for resources in your 62 * <li> Provide a configuration possibility for resources in your
62 * new family. You can use @ref ResourcesConfigPage to easily create a 63 * new family. You can use @ref ResourcesConfigPage to easily create a
63 * KControl applet</li> 64 * KControl applet</li>
64 * <li>In your application, you can use @ref ResourceManager to keep track 65 * <li>In your application, you can use @ref ResourceManager to keep track
65 * of the resources in your family, and you can use @ref ResourceSelectDialog 66 * of the resources in your family, and you can use @ref ResourceSelectDialog
66 * to let the user select a single resource.</li> 67 * to let the user select a single resource.</li>
@@ -299,103 +300,117 @@ class Resource : public QObject
299 QString type() const; 300 QString type() const;
300 301
301 /** 302 /**
302 * Mark the resource as read-only. You can override this method, 303 * Mark the resource as read-only. You can override this method,
303 * but also remember to call Resource::setReadOnly(). 304 * but also remember to call Resource::setReadOnly().
304 */ 305 */
305 virtual void setReadOnly( bool value ); 306 virtual void setReadOnly( bool value );
306 307
307 /** 308 /**
308 * Returns, if the resource is read-only. 309 * Returns, if the resource is read-only.
309 */ 310 */
310 virtual bool readOnly() const; 311 virtual bool readOnly() const;
311 312
312 /** 313 /**
313 * Set the name of resource.You can override this method, 314 * Set the name of resource.You can override this method,
314 * but also remember to call Resource::setResourceName(). 315 * but also remember to call Resource::setResourceName().
315 */ 316 */
316 virtual void setResourceName( const QString &name ); 317 virtual void setResourceName( const QString &name );
317 318
318 /** 319 /**
319 * Returns the name of resource. 320 * Returns the name of resource.
320 */ 321 */
321 virtual QString resourceName() const; 322 virtual QString resourceName() const;
322 323
324
325
326 virtual bool isSyncable() const = 0;
327
328
323 /** 329 /**
324 Sets, if the resource is active. 330 Sets, if the resource is active.
325 */ 331 */
326 void setActive( bool active ); 332 void setActive( bool active );
327 333
328 /** 334 /**
329 Return true, if the resource is active. 335 Return true, if the resource is active.
330 */ 336 */
331 bool isActive() const; 337 bool isActive() const;
332 338
333 friend class Factory; 339 friend class Factory;
334 friend class ManagerImpl; 340 friend class ManagerImpl;
335 341
336 /** 342 /**
337 Print resource information as debug output. 343 Print resource information as debug output.
338 */ 344 */
339 virtual void dump() const; 345 virtual void dump() const;
340 346
347
341 protected: 348 protected:
342 /** 349 /**
343 * Open this resource. When called, the resource must be in 350 * Open this resource. When called, the resource must be in
344 * a closed state. 351 * a closed state.
345 * 352 *
346 * Returns true if the resource was opened successfully; 353 * Returns true if the resource was opened successfully;
347 * returns false if the resource was not opened successfully. 354 * returns false if the resource was not opened successfully.
348 * 355 *
349 * The result of this call can be accessed later by @ref isOpen() 356 * The result of this call can be accessed later by @ref isOpen()
350 */ 357 */
351 virtual bool doOpen() { return true; } 358 virtual bool doOpen() { return true; }
352 359
353 /** 360 /**
354 * Close this resource. Pre-condition: resource is open. 361 * Close this resource. Pre-condition: resource is open.
355 * Post-condition: resource is closed. 362 * Post-condition: resource is closed.
356 */ 363 */
357 virtual void doClose() {} 364 virtual void doClose() {}
358 365
359 void setIdentifier( const QString& identifier ); 366 void setIdentifier( const QString& identifier );
360 void setType( const QString& type ); 367 void setType( const QString& type );
361 368
362 private: 369 private:
363 class ResourcePrivate; 370 class ResourcePrivate;
364 ResourcePrivate *d; 371 ResourcePrivate *d;
365}; 372};
366 373
367class PluginFactoryBase : public KLibFactory 374class PluginFactoryBase : public KLibFactory
368{ 375{
369 public: 376 public:
370 virtual Resource *resource( const KConfig *config ) = 0; 377 virtual Resource *resource( const KConfig *config, bool syncable ) = 0;
371 378
372 virtual ConfigWidget *configWidget( QWidget *parent ) = 0; 379 virtual ConfigWidget *configWidget( QWidget *parent ) = 0;
373 380
381 virtual SyncWidget *syncWidget( QWidget *parent ) = 0;
382
374 protected: 383 protected:
375 virtual QObject* createObject( QObject*, const char*, const char*, 384 virtual QObject* createObject( QObject*, const char*, const char*,
376 const QStringList & ) 385 const QStringList & )
377 { 386 {
378 return 0; 387 return 0;
379 } 388 }
380}; 389};
381 390
382template<class TR,class TC> 391template<class TR,class TC, class TS>
383class PluginFactory : public PluginFactoryBase 392class PluginFactory : public PluginFactoryBase
384{ 393{
385 public: 394 public:
386 Resource *resource( const KConfig *config ) 395 Resource *resource( const KConfig *config, bool syncable )
387 { 396 {
388 return new TR( config ); 397 return new TR( config, syncable );
389 } 398 }
390 399
391 ConfigWidget *configWidget( QWidget *parent ) 400 ConfigWidget *configWidget( QWidget *parent )
392 { 401 {
393 return new TC( parent ); 402 return new TC( parent );
394 } 403 }
404
405 virtual SyncWidget *syncWidget( QWidget *parent )
406 {
407 return new TS( parent );
408 }
409
395}; 410};
396 411
397 412
398 413
399} 414}
400 415
401#endif 416#endif