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