summaryrefslogtreecommitdiffabout
path: root/microkde
Unidiff
Diffstat (limited to 'microkde') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kresources/factory.cpp54
1 files changed, 33 insertions, 21 deletions
diff --git a/microkde/kresources/factory.cpp b/microkde/kresources/factory.cpp
index 2253de4..f82e94c 100644
--- a/microkde/kresources/factory.cpp
+++ b/microkde/kresources/factory.cpp
@@ -1,243 +1,255 @@
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 QString libname = "microkabc_opie"; 99 QString libname = "microkabc_opie";
100 QString path = KLibLoader::findLibrary( QFile::encodeName( libname ) ); 100 QString path = KLibLoader::findLibrary( QFile::encodeName( libname ) );
101 if ( !path.isEmpty() ) 101 if ( !path.isEmpty() )
102 { 102 {
103 info = new PluginInfo; 103 info = new PluginInfo;
104 info->library = libname; 104 info->library = libname;
105 info->nameLabel = i18n( "opie" ); 105 info->nameLabel = i18n( "opie" );
106 info->descriptionLabel = i18n( "Opie PIM Addressbook." ); 106 info->descriptionLabel = i18n( "Opie PIM Addressbook." );
107 mTypeMap.insert( "opie", info ); 107 mTypeMap.insert( "opie", info );
108 } 108 }
109 109
110 //US add qtopia plugin only, if the library exists 110 //US add qtopia plugin only, if the library exists.
111 libname = "microkabc_qtopia"; 111 libname = "microkabc_qtopia";
112 path = KLibLoader::findLibrary( QFile::encodeName( libname ) ); 112 path = KLibLoader::findLibrary( QFile::encodeName( libname ) );
113 if ( !path.isEmpty() ) 113 if ( !path.isEmpty() )
114 { 114 {
115 info = new PluginInfo; 115 info = new PluginInfo;
116 info->library = libname; 116 info->library = libname;
117 info->nameLabel = i18n( "qtopia" ); 117 info->nameLabel = i18n( "qtopia" );
118 info->descriptionLabel = i18n( "Qtopia PIM Addressbook." ); 118 info->descriptionLabel = i18n( "Qtopia PIM Addressbook." );
119 mTypeMap.insert( "qtopia", info ); 119 mTypeMap.insert( "qtopia", info );
120 } 120 }
121 121
122 //US add sharp plugin only, if the library exists.
123 libname = "microkabc_sharpdtm";
124 path = KLibLoader::findLibrary( QFile::encodeName( libname ) );
125 if ( !path.isEmpty() )
126 {
127 info = new PluginInfo;
128 info->library = libname;
129 info->nameLabel = i18n( "sharp" );
130 info->descriptionLabel = i18n( "Sharp DTM Addressbook." );
131 mTypeMap.insert( "sharp", info );
132 }
133
122 134
123} 135}
124 136
125Factory::~Factory() 137Factory::~Factory()
126{ 138{
127} 139}
128 140
129QStringList Factory::typeNames() const 141QStringList Factory::typeNames() const
130{ 142{
131//US method QMap::keys() not available yet. SO collect the data manually 143//US method QMap::keys() not available yet. SO collect the data manually
132//US return mTypeMap.keys(); 144//US return mTypeMap.keys();
133 145
134 QStringList result; 146 QStringList result;
135 147
136 QMap<QString, PluginInfo*>::ConstIterator it; 148 QMap<QString, PluginInfo*>::ConstIterator it;
137 for( it = mTypeMap.begin(); it != mTypeMap.end(); ++it ) { 149 for( it = mTypeMap.begin(); it != mTypeMap.end(); ++it ) {
138 result << it.key().latin1(); 150 result << it.key().latin1();
139// qDebug("Factory::typeNames() : %s ", it.key().latin1()); 151// qDebug("Factory::typeNames() : %s ", it.key().latin1());
140 152
141 } 153 }
142 return result; 154 return result;
143} 155}
144 156
145ConfigWidget *Factory::configWidget( const QString& type, QWidget *parent ) 157ConfigWidget *Factory::configWidget( const QString& type, QWidget *parent )
146{ 158{
147 if ( type.isEmpty() || !mTypeMap.contains( type ) ) 159 if ( type.isEmpty() || !mTypeMap.contains( type ) )
148 return 0; 160 return 0;
149 161
150//US KService::Ptr ptr = mTypeMap[ type ]; 162//US KService::Ptr ptr = mTypeMap[ type ];
151//US KLibFactory *factory = KLibLoader::self()->factory( ptr->library().latin1() ); 163//US KLibFactory *factory = KLibLoader::self()->factory( ptr->library().latin1() );
152 PluginInfo* pi = mTypeMap[ type ]; 164 PluginInfo* pi = mTypeMap[ type ];
153 KLibFactory *factory = (KLibFactory *)KLibLoader::self()->factory( pi->library.latin1() ); 165 KLibFactory *factory = (KLibFactory *)KLibLoader::self()->factory( pi->library.latin1() );
154 if ( !factory ) { 166 if ( !factory ) {
155 qDebug("KRES::Factory::configWidget(): Factory creation failed for library %s", pi->library.latin1()); 167 qDebug("KRES::Factory::configWidget(): Factory creation failed for library %s", pi->library.latin1());
156 kdDebug() << "KRES::Factory::configWidget(): Factory creation failed" << endl; 168 kdDebug() << "KRES::Factory::configWidget(): Factory creation failed" << endl;
157 return 0; 169 return 0;
158 } 170 }
159 171
160 PluginFactoryBase *pluginFactory = static_cast<PluginFactoryBase *>( factory ); 172 PluginFactoryBase *pluginFactory = static_cast<PluginFactoryBase *>( factory );
161 173
162 if ( !pluginFactory ) { 174 if ( !pluginFactory ) {
163 qDebug("KRES::Factory::configWidget(): no plugin factory for library %s", pi->library.latin1()); 175 qDebug("KRES::Factory::configWidget(): no plugin factory for library %s", pi->library.latin1());
164 kdDebug() << "KRES::Factory::configWidget(): no plugin factory." << endl; 176 kdDebug() << "KRES::Factory::configWidget(): no plugin factory." << endl;
165 return 0; 177 return 0;
166 } 178 }
167 179
168 ConfigWidget *wdg = pluginFactory->configWidget( parent ); 180 ConfigWidget *wdg = pluginFactory->configWidget( parent );
169 if ( !wdg ) { 181 if ( !wdg ) {
170//US kdDebug() << "'" << ptr->library() << "' is not a " + mResourceFamily + " plugin." << endl; 182//US kdDebug() << "'" << ptr->library() << "' is not a " + mResourceFamily + " plugin." << endl;
171 qDebug("%s is not a %s plugin.", pi->library.latin1(), mResourceFamily.latin1()); 183 qDebug("%s is not a %s plugin.", pi->library.latin1(), mResourceFamily.latin1());
172 return 0; 184 return 0;
173 } 185 }
174 return wdg; 186 return wdg;
175 187
176} 188}
177 189
178QString Factory::typeName( const QString &type ) const 190QString Factory::typeName( const QString &type ) const
179{ 191{
180 if ( type.isEmpty() || !mTypeMap.contains( type ) ) 192 if ( type.isEmpty() || !mTypeMap.contains( type ) )
181 return QString(); 193 return QString();
182 194
183 195
184//US KService::Ptr ptr = mTypeMap[ type ]; 196//US KService::Ptr ptr = mTypeMap[ type ];
185//US return ptr->name(); 197//US return ptr->name();
186 PluginInfo* pi = mTypeMap[ type ]; 198 PluginInfo* pi = mTypeMap[ type ];
187 return pi->nameLabel; 199 return pi->nameLabel;
188 200
189} 201}
190 202
191QString Factory::typeDescription( const QString &type ) const 203QString Factory::typeDescription( const QString &type ) const
192{ 204{
193 if ( type.isEmpty() || !mTypeMap.contains( type ) ) 205 if ( type.isEmpty() || !mTypeMap.contains( type ) )
194 return QString(); 206 return QString();
195 207
196//US KService::Ptr ptr = mTypeMap[ type ]; 208//US KService::Ptr ptr = mTypeMap[ type ];
197//US return ptr->comment(); 209//US return ptr->comment();
198 PluginInfo* pi = mTypeMap[ type ]; 210 PluginInfo* pi = mTypeMap[ type ];
199 return pi->descriptionLabel; 211 return pi->descriptionLabel;
200} 212}
201 213
202Resource *Factory::resource( const QString& type, const KConfig *config ) 214Resource *Factory::resource( const QString& type, const KConfig *config )
203{ 215{
204 216
205 217
206 if ( type.isEmpty() || !mTypeMap.contains( type ) ) 218 if ( type.isEmpty() || !mTypeMap.contains( type ) )
207 return 0; 219 return 0;
208 220
209/*US load the lib not dynamicly. !! 221/*US load the lib not dynamicly. !!
210 KService::Ptr ptr = mTypeMap[ type ]; 222 KService::Ptr ptr = mTypeMap[ type ];
211 KLibFactory *factory = KLibLoader::self()->factory( ptr->library().latin1() ); 223 KLibFactory *factory = KLibLoader::self()->factory( ptr->library().latin1() );
212 if ( !factory ) { 224 if ( !factory ) {
213 kdDebug() << "KRES::Factory::resource(): Factory creation failed" << endl; 225 kdDebug() << "KRES::Factory::resource(): Factory creation failed" << endl;
214 return 0; 226 return 0;
215 } 227 }
216*/ 228*/
217 PluginInfo* pi = mTypeMap[ type ]; 229 PluginInfo* pi = mTypeMap[ type ];
218 KLibFactory *factory = (KLibFactory *)KLibLoader::self()->factory( pi->library.latin1() ); 230 KLibFactory *factory = (KLibFactory *)KLibLoader::self()->factory( pi->library.latin1() );
219 if ( !factory ) { 231 if ( !factory ) {
220 qDebug("KRES::Factory::resource(): Factory creation failed for library %s", pi->library.latin1()); 232 qDebug("KRES::Factory::resource(): Factory creation failed for library %s", pi->library.latin1());
221 kdDebug() << "KRES::Factory::resource(): Factory creation failed" << endl; 233 kdDebug() << "KRES::Factory::resource(): Factory creation failed" << endl;
222 return 0; 234 return 0;
223 } 235 }
224 236
225 PluginFactoryBase *pluginFactory = static_cast<PluginFactoryBase *>( factory ); 237 PluginFactoryBase *pluginFactory = static_cast<PluginFactoryBase *>( factory );
226 238
227 if ( !pluginFactory ) { 239 if ( !pluginFactory ) {
228 qDebug("KRES::Factory::resource(): no plugin factory for library %s", pi->library.latin1()); 240 qDebug("KRES::Factory::resource(): no plugin factory for library %s", pi->library.latin1());
229 kdDebug() << "KRES::Factory::resource(): no plugin factory." << endl; 241 kdDebug() << "KRES::Factory::resource(): no plugin factory." << endl;
230 return 0; 242 return 0;
231 } 243 }
232 244
233 Resource *resource = pluginFactory->resource( config ); 245 Resource *resource = pluginFactory->resource( config );
234 if ( !resource ) { 246 if ( !resource ) {
235//US kdDebug() << "'" << ptr->library() << "' is not a " + mResourceFamily + " plugin." << endl; 247//US kdDebug() << "'" << ptr->library() << "' is not a " + mResourceFamily + " plugin." << endl;
236 qDebug("%s is not a %s plugin.", pi->library.latin1(), mResourceFamily.latin1()); 248 qDebug("%s is not a %s plugin.", pi->library.latin1(), mResourceFamily.latin1());
237 return 0; 249 return 0;
238 } 250 }
239 251
240 resource->setType( type ); 252 resource->setType( type );
241 253
242 return resource; 254 return resource;
243} 255}