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
@@ -1,193 +1,194 @@
1/* 1/*
2 This file is part of libkresources. 2 This file is part of libkresources.
3 3
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001 Cornelius Schumacher <schumacher@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 <kapplication.h> 25#include <kapplication.h>
26#include <kconfig.h> 26#include <kconfig.h>
27 27
28#include "resource.h" 28#include "resource.h"
29 29
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{
110#ifdef QT_THREAD_SUPPORT 110#ifdef QT_THREAD_SUPPORT
111 QMutexLocker guard( &(d->mMutex) ); 111 QMutexLocker guard( &(d->mMutex) );
112#endif 112#endif
113 if ( !d->mOpenCount ) { 113 if ( !d->mOpenCount ) {
114 kdDebug(5650) << "ERROR: Resource " << resourceName() << " closed more times than previously opened" << endl; 114 kdDebug(5650) << "ERROR: Resource " << resourceName() << " closed more times than previously opened" << endl;
115 return; 115 return;
116 } 116 }
117 d->mOpenCount--; 117 d->mOpenCount--;
118 if ( !d->mOpenCount ) { 118 if ( !d->mOpenCount ) {
119 kdDebug(5650) << "Closing resource " << resourceName() << endl; 119 kdDebug(5650) << "Closing resource " << resourceName() << endl;
120 doClose(); 120 doClose();
121 d->mIsOpen = false; 121 d->mIsOpen = false;
122 } else { 122 } else {
123 kdDebug(5650) << "Not yet closing resource " << resourceName() << ", open count = " << d->mOpenCount << endl; 123 kdDebug(5650) << "Not yet closing resource " << resourceName() << ", open count = " << d->mOpenCount << endl;
124 } 124 }
125} 125}
126 126
127bool Resource::isOpen() const 127bool Resource::isOpen() const
128{ 128{
129 return d->mIsOpen; 129 return d->mIsOpen;
130} 130}
131 131
132void Resource::setIdentifier( const QString& identifier ) 132void Resource::setIdentifier( const QString& identifier )
133{ 133{
134 d->mIdentifier = identifier; 134 d->mIdentifier = identifier;
135} 135}
136 136
137QString Resource::identifier() const 137QString Resource::identifier() const
138{ 138{
139 return d->mIdentifier; 139 return d->mIdentifier;
140} 140}
141 141
142void Resource::setType( const QString& type ) 142void Resource::setType( const QString& type )
143{ 143{
144 d->mType = type; 144 d->mType = type;
145} 145}
146 146
147QString Resource::type() const 147QString Resource::type() const
148{ 148{
149 return d->mType; 149 return d->mType;
150} 150}
151 151
152void Resource::setReadOnly( bool value ) 152void Resource::setReadOnly( bool value )
153{ 153{
154 d->mReadOnly = value; 154 d->mReadOnly = value;
155} 155}
156 156
157bool Resource::readOnly() const 157bool Resource::readOnly() const
158{ 158{
159 return d->mReadOnly; 159 return d->mReadOnly;
160} 160}
161 161
162void Resource::setResourceName( const QString &name ) 162void Resource::setResourceName( const QString &name )
163{ 163{
164 d->mName = name; 164 d->mName = name;
165} 165}
166 166
167QString Resource::resourceName() const 167QString Resource::resourceName() const
168{ 168{
169 return d->mName; 169 return d->mName;
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
@@ -1,138 +1,139 @@
1/* 1/*
2 This file is part of libkresources 2 This file is part of libkresources
3 3
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001 Cornelius Schumacher <schumacher@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 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This library is distributed in the hope that it will be useful, 12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details. 15 Library General Public License for more details.
16 16
17 You should have received a copy of the GNU Library General Public License 17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. If not, write to
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>
67 * </ul> 68 * </ul>
68 * 69 *
69 * When you want to add a new resource type to an existing resource family, 70 * When you want to add a new resource type to an existing resource family,
70 * you need to 71 * you need to
71 * <ul><li>Further subclass the family-specific Resource to implement 72 * <ul><li>Further subclass the family-specific Resource to implement
72 * resource type-specific operation</li> 73 * resource type-specific operation</li>
73 * <li>Subclass ResourceConfigWidget to provide a configuration widget 74 * <li>Subclass ResourceConfigWidget to provide a configuration widget
74 * for your new resource type</li> 75 * for your new resource type</li>
75 * <li>Provide a .desktop file so that the new resource type can be found 76 * <li>Provide a .desktop file so that the new resource type can be found
76 * automatically by the ResourceManager</li> 77 * automatically by the ResourceManager</li>
77 * </ul> 78 * </ul>
78 * 79 *
79 * Example: 80 * Example:
80 * 81 *
81<B>resourceexample.h</B>: 82<B>resourceexample.h</B>:
82<pre> 83<pre>
83#include <kconfig.h> 84#include <kconfig.h>
84#include <kresources/resource.h> 85#include <kresources/resource.h>
85 86
86class ResourceExample : public KRES::ResourceExample 87class ResourceExample : public KRES::ResourceExample
87{ 88{
88public: 89public:
89 ResourceExample( const KConfig * ); 90 ResourceExample( const KConfig * );
90 ~ResourceCalendarExchange(); 91 ~ResourceCalendarExchange();
91 void writeConfig( KConfig *config ); 92 void writeConfig( KConfig *config );
92private: 93private:
93 QString mLocation; 94 QString mLocation;
94 QString mPassword; 95 QString mPassword;
95} 96}
96</pre> 97</pre>
97<B>resourceexample.cpp</B>: 98<B>resourceexample.cpp</B>:
98<pre> 99<pre>
99#include <kconfig.h> 100#include <kconfig.h>
100 101
101#include "resourceexample.h" 102#include "resourceexample.h"
102 103
103ResourceExample::ResourceExample( const KConfig *config ) 104ResourceExample::ResourceExample( const KConfig *config )
104 : Resource( config ) 105 : Resource( config )
105{ 106{
106 if ( config ) { 107 if ( config ) {
107 mLocation = config->readEntry( "Location" ); 108 mLocation = config->readEntry( "Location" );
108 mPassword = KStringHandler::obscure( config->readEntry( "Password" ) ); 109 mPassword = KStringHandler::obscure( config->readEntry( "Password" ) );
109 } else { 110 } else {
110 mLocation = ""; // Or some sensible default 111 mLocation = ""; // Or some sensible default
111 mPassword = ""; 112 mPassword = "";
112 } 113 }
113} 114}
114 115
115void ResourceExample::writeConfig( KConfig *config ) 116void ResourceExample::writeConfig( KConfig *config )
116{ 117{
117 KRES::Resource::writeConfig( config ); 118 KRES::Resource::writeConfig( config );
118 config->writeEntry( "Location", mLocation ); 119 config->writeEntry( "Location", mLocation );
119 config->writeEntry( "Password", KStringHandler::obscure( mPassword ) ); 120 config->writeEntry( "Password", KStringHandler::obscure( mPassword ) );
120} 121}
121 122
122extern "C" 123extern "C"
123{ 124{
124 KRES::ResourceExample *config_widget( QWidget *parent ) { 125 KRES::ResourceExample *config_widget( QWidget *parent ) {
125 return new ResourceExampleConfig( parent, "Configure Example Resource" ); 126 return new ResourceExampleConfig( parent, "Configure Example Resource" );
126 } 127 }
127 128
128 KRES::Resource *resource( const KConfig *config ) { 129 KRES::Resource *resource( const KConfig *config ) {
129 return new ResourceExample( config ); 130 return new ResourceExample( config );
130 } 131 }
131} 132}
132</pre> 133</pre>
133* <B>resourceexampleconfig.h</B>: 134* <B>resourceexampleconfig.h</B>:
134<pre> 135<pre>
135#include <klineedit.h> 136#include <klineedit.h>
136#include <kresources/resourceconfigwidget.h> 137#include <kresources/resourceconfigwidget.h>
137 138
138#include "resourceexample.h" 139#include "resourceexample.h"
@@ -227,175 +228,189 @@ link_DATA= resourceexample.desktop
227 * 228 *
228 */ 229 */
229 230
230/** 231/**
231 * A @ref Resource is a ... 232 * A @ref Resource is a ...
232 * 233 *
233 * A subclass should reimplement at least the constructor and the 234 * A subclass should reimplement at least the constructor and the
234 * @ref writeConfig method. 235 * @ref writeConfig method.
235 * 236 *
236 */ 237 */
237class Resource : public QObject 238class Resource : public QObject
238{ 239{
239 Q_OBJECT 240 Q_OBJECT
240 241
241 public: 242 public:
242 typedef QValueList<Resource *> List; 243 typedef QValueList<Resource *> List;
243 244
244 /** 245 /**
245 * Constructor. Construct resource from config. 246 * Constructor. Construct resource from config.
246 * @param config Configuration to read persistence information from. 247 * @param config Configuration to read persistence information from.
247 * If config==0, create object using default settings. 248 * If config==0, create object using default settings.
248 */ 249 */
249 Resource( const KConfig* config ); 250 Resource( const KConfig* config );
250 251
251 /** 252 /**
252 * Destructor. 253 * Destructor.
253 */ 254 */
254 virtual ~Resource(); 255 virtual ~Resource();
255 256
256 /** 257 /**
257 * Write configuration information for this resource to a configuration 258 * Write configuration information for this resource to a configuration
258 * file. If you override this method, remember to call Resource::writeConfig 259 * file. If you override this method, remember to call Resource::writeConfig
259 * or Terrible Things(TM) will happen. 260 * or Terrible Things(TM) will happen.
260 * @param config Configuration to write persistence information to. 261 * @param config Configuration to write persistence information to.
261 */ 262 */
262 virtual void writeConfig( KConfig* config ); 263 virtual void writeConfig( KConfig* config );
263 264
264 /** 265 /**
265 * Open this resource, if it not already open. Increase the open 266 * Open this resource, if it not already open. Increase the open
266 * count of this object, and open the resource by calling @ref doOpen(). 267 * count of this object, and open the resource by calling @ref doOpen().
267 * This method may block while another thread is concurrently opening 268 * This method may block while another thread is concurrently opening
268 * or closing the resource. 269 * or closing the resource.
269 * 270 *
270 * Returns true if the resource was already opened or if it was opened 271 * Returns true if the resource was already opened or if it was opened
271 * successfully; returns false if the resource was not opened successfully. 272 * successfully; returns false if the resource was not opened successfully.
272 */ 273 */
273 bool open(); 274 bool open();
274 275
275 /** 276 /**
276 * Decrease the open count of this object, and if the count reaches 277 * Decrease the open count of this object, and if the count reaches
277 * zero, close this resource by calling @ref doClose(). 278 * zero, close this resource by calling @ref doClose().
278 * This method may block while another thread is concurrently closing 279 * This method may block while another thread is concurrently closing
279 * or opening the resource. 280 * or opening the resource.
280 */ 281 */
281 void close(); 282 void close();
282 283
283 /** 284 /**
284 * Returns whether the resource is open or not. 285 * Returns whether the resource is open or not.
285 */ 286 */
286 bool isOpen() const; 287 bool isOpen() const;
287 288
288 /** 289 /**
289 * Returns a unique identifier. The identifier is unique for this resource. 290 * Returns a unique identifier. The identifier is unique for this resource.
290 * It is created when the resource is first created, and it is retained 291 * It is created when the resource is first created, and it is retained
291 * in the resource family configuration file for this resource. 292 * in the resource family configuration file for this resource.
292 * @return This resource's identifier 293 * @return This resource's identifier
293 */ 294 */
294 QString identifier() const; 295 QString identifier() const;
295 296
296 /** 297 /**
297 * Returns the type of this resource. 298 * Returns the type of this resource.
298 */ 299 */
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