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