summaryrefslogtreecommitdiffabout
path: root/microkde
Unidiff
Diffstat (limited to 'microkde') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kresources/factory.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/microkde/kresources/factory.cpp b/microkde/kresources/factory.cpp
index 5fbfa68..4843ce0 100644
--- a/microkde/kresources/factory.cpp
+++ b/microkde/kresources/factory.cpp
@@ -1,282 +1,295 @@
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 37#ifdef STATIC_RESOURCES
38#include <file/resourcefile.h> 38#include <file/resourcefile.h>
39#include <dir/resourcedir.h> 39#include <dir/resourcedir.h>
40#include <qtopia/resourceqtopia.h> 40#include <qtopia/resourceqtopia.h>
41#endif 41#endif
42using namespace KRES; 42using namespace KRES;
43 43
44QDict<Factory> *Factory::mSelves = 0; 44QDict<Factory> *Factory::mSelves = 0;
45static KStaticDeleter< QDict<Factory> > staticDeleter; 45static KStaticDeleter< QDict<Factory> > staticDeleter;
46 46
47Factory *Factory::self( const QString& resourceFamily) 47Factory *Factory::self( const QString& resourceFamily)
48{ 48{
49 49
50 50
51 Factory *factory = 0; 51 Factory *factory = 0;
52 if ( !mSelves ) 52 if ( !mSelves )
53 { 53 {
54 mSelves = staticDeleter.setObject( new QDict<Factory> ); 54 mSelves = staticDeleter.setObject( new QDict<Factory> );
55 } 55 }
56 56
57 factory = mSelves->find( resourceFamily ); 57 factory = mSelves->find( resourceFamily );
58 58
59 if ( !factory ) { 59 if ( !factory ) {
60 factory = new Factory( resourceFamily); 60 factory = new Factory( resourceFamily);
61 mSelves->insert( resourceFamily, factory ); 61 mSelves->insert( resourceFamily, factory );
62 } 62 }
63 63
64 return factory; 64 return factory;
65} 65}
66 66
67Factory::Factory( const QString& resourceFamily) : 67Factory::Factory( const QString& resourceFamily) :
68 mResourceFamily( resourceFamily ) 68 mResourceFamily( resourceFamily )
69{ 69{
70//US so far we have three types available for resourceFamily "contact" 70//US so far we have three types available for resourceFamily "contact"
71// and that are "file", "dir", "ldap" 71// and that are "file", "dir", "ldap"
72/*US 72/*US
73 73
74 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'" )
75 .arg( resourceFamily ) ); 75 .arg( resourceFamily ) );
76 KTrader::OfferList::ConstIterator it; 76 KTrader::OfferList::ConstIterator it;
77 for ( it = plugins.begin(); it != plugins.end(); ++it ) { 77 for ( it = plugins.begin(); it != plugins.end(); ++it ) {
78 QVariant type = (*it)->property( "X-KDE-ResourceType" ); 78 QVariant type = (*it)->property( "X-KDE-ResourceType" );
79 if ( !type.toString().isEmpty() ) 79 if ( !type.toString().isEmpty() )
80 mTypeMap.insert( type.toString(), *it ); 80 mTypeMap.insert( type.toString(), *it );
81 } 81 }
82*/ 82*/
83 83
84//US new 84//US new
85 PluginInfo* info = new PluginInfo; 85 PluginInfo* info = new PluginInfo;
86 info->library = "microkabc_file"; 86 info->library = "microkabc_file";
87 info->nameLabel = i18n( "file" ); 87 info->nameLabel = i18n( "file" );
88 info->descriptionLabel = i18n( "One file" ); 88 info->descriptionLabel = i18n( "One file" );
89 mTypeMap.insert( "file", info ); 89 mTypeMap.insert( "file", info );
90 90
91 info = new PluginInfo; 91 info = new PluginInfo;
92 info->library = "microkabc_dir"; 92 info->library = "microkabc_dir";
93 info->nameLabel = i18n( "dir" ); 93 info->nameLabel = i18n( "dir" );
94 info->descriptionLabel = i18n( "A directory with many files" ); 94 info->descriptionLabel = i18n( "A directory with many files" );
95 mTypeMap.insert( "dir", info ); 95 mTypeMap.insert( "dir", info );
96 96
97 info = new PluginInfo; 97 info = new PluginInfo;
98 info->library = "microkabc_ldap"; 98 info->library = "microkabc_ldap";
99 info->nameLabel = i18n( "ldap" ); 99 info->nameLabel = i18n( "ldap" );
100 info->descriptionLabel = i18n( "Connect to a directory server" ); 100 info->descriptionLabel = i18n( "Connect to a directory server" );
101 mTypeMap.insert( "ldap", info ); 101 mTypeMap.insert( "ldap", info );
102 102
103 //US add opie plugin only, if the library exists. 103 //US add opie plugin only, if the library exists.
104 /*US 104 /*US
105 QString libname = "microkabc_opie"; 105 QString libname = "microkabc_opie";
106 QString path = KLibLoader::findLibrary( QFile::encodeName( libname ) ); 106 QString path = KLibLoader::findLibrary( QFile::encodeName( libname ) );
107 if ( !path.isEmpty() ) 107 if ( !path.isEmpty() )
108 { 108 {
109 info = new PluginInfo; 109 info = new PluginInfo;
110 info->library = libname; 110 info->library = libname;
111 info->nameLabel = i18n( "opie" ); 111 info->nameLabel = i18n( "opie" );
112 info->descriptionLabel = i18n( "Opie PIM Addressbook." ); 112 info->descriptionLabel = i18n( "Opie PIM Addressbook." );
113 mTypeMap.insert( "opie", info ); 113 mTypeMap.insert( "opie", info );
114 } 114 }
115 */ 115 */
116 //US add qtopia plugin only, if the library exists. 116 //US add qtopia plugin only, if the library exists.
117 QString libname = "microkabc_qtopia"; 117 QString libname = "microkabc_qtopia";
118 QString path = KLibLoader::findLibrary( QFile::encodeName( libname ) ); 118 QString path = KLibLoader::findLibrary( QFile::encodeName( libname ) );
119 if ( !path.isEmpty() ) 119 if ( !path.isEmpty() )
120 { 120 {
121 info = new PluginInfo; 121 info = new PluginInfo;
122 info->library = libname; 122 info->library = libname;
123 info->nameLabel = i18n( "qtopia" ); 123 info->nameLabel = i18n( "qtopia" );
124 info->descriptionLabel = i18n( "Qtopia PIM Addressbook." ); 124 info->descriptionLabel = i18n( "Qtopia PIM Addressbook." );
125 mTypeMap.insert( "qtopia", info ); 125 mTypeMap.insert( "qtopia", info );
126 } 126 }
127 127
128 //US add sharp plugin only, if the library exists. 128 //US add sharp plugin only, if the library exists.
129 libname = "microkabc_sharpdtm"; 129 libname = "microkabc_sharpdtm";
130 path = KLibLoader::findLibrary( QFile::encodeName( libname ) ); 130 path = KLibLoader::findLibrary( QFile::encodeName( libname ) );
131 if ( !path.isEmpty() ) 131 if ( !path.isEmpty() )
132 { 132 {
133 info = new PluginInfo; 133 info = new PluginInfo;
134 info->library = libname; 134 info->library = libname;
135 info->nameLabel = i18n( "sharp" ); 135 info->nameLabel = i18n( "sharp" );
136 info->descriptionLabel = i18n( "Sharp DTM Addressbook." ); 136 info->descriptionLabel = i18n( "Sharp DTM Addressbook." );
137 mTypeMap.insert( "sharp", info ); 137 mTypeMap.insert( "sharp", info );
138 } 138 }
139 139
140 140
141 //LR add ol plugin only, if the library exists.
142 libname = "microkabc_olaccess";
143 path = KLibLoader::findLibrary( QFile::encodeName( libname ) );
144 if ( !path.isEmpty() )
145 {
146 info = new PluginInfo;
147 info->library = libname;
148 info->nameLabel = i18n( "sharp" );
149 info->descriptionLabel = i18n( "Outlook Addressbook." );
150 mTypeMap.insert( "olaccess", info );
151 }
152
153
141} 154}
142 155
143Factory::~Factory() 156Factory::~Factory()
144{ 157{
145} 158}
146 159
147QStringList Factory::typeNames() const 160QStringList Factory::typeNames() const
148{ 161{
149//US method QMap::keys() not available yet. SO collect the data manually 162//US method QMap::keys() not available yet. SO collect the data manually
150//US return mTypeMap.keys(); 163//US return mTypeMap.keys();
151 164
152 QStringList result; 165 QStringList result;
153 166
154 QMap<QString, PluginInfo*>::ConstIterator it; 167 QMap<QString, PluginInfo*>::ConstIterator it;
155 for( it = mTypeMap.begin(); it != mTypeMap.end(); ++it ) { 168 for( it = mTypeMap.begin(); it != mTypeMap.end(); ++it ) {
156 result << it.key().latin1(); 169 result << it.key().latin1();
157// qDebug("Factory::typeNames() : %s ", it.key().latin1()); 170// qDebug("Factory::typeNames() : %s ", it.key().latin1());
158 171
159 } 172 }
160 return result; 173 return result;
161} 174}
162 175
163ConfigWidget *Factory::configWidget( const QString& type, QWidget *parent ) 176ConfigWidget *Factory::configWidget( const QString& type, QWidget *parent )
164{ 177{
165 if ( type.isEmpty() || !mTypeMap.contains( type ) ) 178 if ( type.isEmpty() || !mTypeMap.contains( type ) )
166 return 0; 179 return 0;
167 180
168//US KService::Ptr ptr = mTypeMap[ type ]; 181//US KService::Ptr ptr = mTypeMap[ type ];
169//US KLibFactory *factory = KLibLoader::self()->factory( ptr->library().latin1() ); 182//US KLibFactory *factory = KLibLoader::self()->factory( ptr->library().latin1() );
170 PluginInfo* pi = mTypeMap[ type ]; 183 PluginInfo* pi = mTypeMap[ type ];
171 KLibFactory *factory = (KLibFactory *)KLibLoader::self()->factory( pi->library.latin1() ); 184 KLibFactory *factory = (KLibFactory *)KLibLoader::self()->factory( pi->library.latin1() );
172 if ( !factory ) { 185 if ( !factory ) {
173 qDebug("KRES::Factory::configWidget(): Factory creation failed for library %s", pi->library.latin1()); 186 qDebug("KRES::Factory::configWidget(): Factory creation failed for library %s", pi->library.latin1());
174 kdDebug() << "KRES::Factory::configWidget(): Factory creation failed" << endl; 187 kdDebug() << "KRES::Factory::configWidget(): Factory creation failed" << endl;
175 return 0; 188 return 0;
176 } 189 }
177 190
178 PluginFactoryBase *pluginFactory = static_cast<PluginFactoryBase *>( factory ); 191 PluginFactoryBase *pluginFactory = static_cast<PluginFactoryBase *>( factory );
179 192
180 if ( !pluginFactory ) { 193 if ( !pluginFactory ) {
181 qDebug("KRES::Factory::configWidget(): no plugin factory for library %s", pi->library.latin1()); 194 qDebug("KRES::Factory::configWidget(): no plugin factory for library %s", pi->library.latin1());
182 kdDebug() << "KRES::Factory::configWidget(): no plugin factory." << endl; 195 kdDebug() << "KRES::Factory::configWidget(): no plugin factory." << endl;
183 return 0; 196 return 0;
184 } 197 }
185 198
186 ConfigWidget *wdg = pluginFactory->configWidget( parent ); 199 ConfigWidget *wdg = pluginFactory->configWidget( parent );
187 if ( !wdg ) { 200 if ( !wdg ) {
188//US kdDebug() << "'" << ptr->library() << "' is not a " + mResourceFamily + " plugin." << endl; 201//US kdDebug() << "'" << ptr->library() << "' is not a " + mResourceFamily + " plugin." << endl;
189 qDebug("%s is not a %s plugin.", pi->library.latin1(), mResourceFamily.latin1()); 202 qDebug("%s is not a %s plugin.", pi->library.latin1(), mResourceFamily.latin1());
190 return 0; 203 return 0;
191 } 204 }
192 return wdg; 205 return wdg;
193 206
194} 207}
195 208
196QString Factory::typeName( const QString &type ) const 209QString Factory::typeName( const QString &type ) const
197{ 210{
198 if ( type.isEmpty() || !mTypeMap.contains( type ) ) 211 if ( type.isEmpty() || !mTypeMap.contains( type ) )
199 return QString(); 212 return QString();
200 213
201 214
202//US KService::Ptr ptr = mTypeMap[ type ]; 215//US KService::Ptr ptr = mTypeMap[ type ];
203//US return ptr->name(); 216//US return ptr->name();
204 PluginInfo* pi = mTypeMap[ type ]; 217 PluginInfo* pi = mTypeMap[ type ];
205 return pi->nameLabel; 218 return pi->nameLabel;
206 219
207} 220}
208 221
209QString Factory::typeDescription( const QString &type ) const 222QString Factory::typeDescription( const QString &type ) const
210{ 223{
211 if ( type.isEmpty() || !mTypeMap.contains( type ) ) 224 if ( type.isEmpty() || !mTypeMap.contains( type ) )
212 return QString(); 225 return QString();
213 226
214//US KService::Ptr ptr = mTypeMap[ type ]; 227//US KService::Ptr ptr = mTypeMap[ type ];
215//US return ptr->comment(); 228//US return ptr->comment();
216 PluginInfo* pi = mTypeMap[ type ]; 229 PluginInfo* pi = mTypeMap[ type ];
217 return pi->descriptionLabel; 230 return pi->descriptionLabel;
218} 231}
219 232
220Resource *Factory::resource( const QString& type, const KConfig *config ) 233Resource *Factory::resource( const QString& type, const KConfig *config )
221{ 234{
222 235
223 236
224 if ( type.isEmpty() || !mTypeMap.contains( type ) ) 237 if ( type.isEmpty() || !mTypeMap.contains( type ) )
225 return 0; 238 return 0;
226 239
227#ifdef STATIC_RESOURCES 240#ifdef STATIC_RESOURCES
228 qDebug("NEW STATIC RESOURCE %s", type.latin1()); 241 qDebug("NEW STATIC RESOURCE %s", type.latin1());
229 Resource *resource = 0; 242 Resource *resource = 0;
230 if ( type == "file" ) { 243 if ( type == "file" ) {
231 resource = (Resource *) new KABC::ResourceFile( config ); 244 resource = (Resource *) new KABC::ResourceFile( config );
232 } else if ( type == "dir" ) { 245 } else if ( type == "dir" ) {
233 resource = new KABC::ResourceDir( config ); 246 resource = new KABC::ResourceDir( config );
234 } else if ( type == "qtopia" ) { 247 } else if ( type == "qtopia" ) {
235 resource = new KABC::ResourceQtopia( config ); 248 resource = new KABC::ResourceQtopia( config );
236 } 249 }
237 if ( !resource) 250 if ( !resource)
238 qDebug("Factory::resource:: resources are statically linked. resource type %s is not supported ",type.latin1() ); 251 qDebug("Factory::resource:: resources are statically linked. resource type %s is not supported ",type.latin1() );
239 else 252 else
240 resource->setType( type ); 253 resource->setType( type );
241 return resource; 254 return resource;
242#else 255#else
243 256
244 257
245 258
246/*US load the lib not dynamicly. !! 259/*US load the lib not dynamicly. !!
247 KService::Ptr ptr = mTypeMap[ type ]; 260 KService::Ptr ptr = mTypeMap[ type ];
248 KLibFactory *factory = KLibLoader::self()->factory( ptr->library().latin1() ); 261 KLibFactory *factory = KLibLoader::self()->factory( ptr->library().latin1() );
249 if ( !factory ) { 262 if ( !factory ) {
250 kdDebug() << "KRES::Factory::resource(): Factory creation failed" << endl; 263 kdDebug() << "KRES::Factory::resource(): Factory creation failed" << endl;
251 return 0; 264 return 0;
252 } 265 }
253*/ 266*/
254 PluginInfo* pi = mTypeMap[ type ]; 267 PluginInfo* pi = mTypeMap[ type ];
255 KLibFactory *factory = (KLibFactory *)KLibLoader::self()->factory( pi->library.latin1() ); 268 KLibFactory *factory = (KLibFactory *)KLibLoader::self()->factory( pi->library.latin1() );
256 if ( !factory ) { 269 if ( !factory ) {
257 qDebug("KRES::Factory::resource(): Factory creation failed for library %s", pi->library.latin1()); 270 qDebug("KRES::Factory::resource(): Factory creation failed for library %s", pi->library.latin1());
258 kdDebug() << "KRES::Factory::resource(): Factory creation failed" << endl; 271 kdDebug() << "KRES::Factory::resource(): Factory creation failed" << endl;
259 return 0; 272 return 0;
260 } 273 }
261 274
262 PluginFactoryBase *pluginFactory = static_cast<PluginFactoryBase *>( factory ); 275 PluginFactoryBase *pluginFactory = static_cast<PluginFactoryBase *>( factory );
263 276
264 if ( !pluginFactory ) { 277 if ( !pluginFactory ) {
265 qDebug("KRES::Factory::resource(): no plugin factory for library %s", pi->library.latin1()); 278 qDebug("KRES::Factory::resource(): no plugin factory for library %s", pi->library.latin1());
266 kdDebug() << "KRES::Factory::resource(): no plugin factory." << endl; 279 kdDebug() << "KRES::Factory::resource(): no plugin factory." << endl;
267 return 0; 280 return 0;
268 } 281 }
269 282
270 Resource *resource = pluginFactory->resource( config ); 283 Resource *resource = pluginFactory->resource( config );
271 if ( !resource ) { 284 if ( !resource ) {
272//US kdDebug() << "'" << ptr->library() << "' is not a " + mResourceFamily + " plugin." << endl; 285//US kdDebug() << "'" << ptr->library() << "' is not a " + mResourceFamily + " plugin." << endl;
273 qDebug("%s is not a %s plugin.", pi->library.latin1(), mResourceFamily.latin1()); 286 qDebug("%s is not a %s plugin.", pi->library.latin1(), mResourceFamily.latin1());
274 return 0; 287 return 0;
275 } 288 }
276 289
277 resource->setType( type ); 290 resource->setType( type );
278 291
279 return resource; 292 return resource;
280 293
281#endif 294#endif
282} 295}