KDECore
kservicetypetrader.h
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2000 Torben Weis <weis@kde.org> 00003 Copyright (C) 2006 David Faure <faure@kde.org> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License version 2 as published by the Free Software Foundation. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 00018 */ 00019 #ifndef __kservicetypetrader_h__ 00020 #define __kservicetypetrader_h__ 00021 00022 #include "kservice.h" 00023 00070 class KDECORE_EXPORT KServiceTypeTrader 00071 { 00072 public: 00076 ~KServiceTypeTrader(); 00077 00104 KService::List query( const QString& servicetype, 00105 const QString& constraint = QString() ) const; 00106 00113 KService::List defaultOffers( const QString& serviceType, 00114 const QString& constraint = QString() ) const; 00121 KService::Ptr preferredService( const QString & serviceType ) const; 00122 00131 static KServiceTypeTrader* self(); 00132 00152 template <class T> 00153 static T *createInstanceFromQuery(const QString &serviceType, 00154 const QString &constraint = QString(), QObject *parent = 0, 00155 const QVariantList &args = QVariantList(), QString *error = 0) 00156 { 00157 return createInstanceFromQuery<T>(serviceType, 0, parent, constraint, args, error); 00158 } 00159 00177 template <class T> 00178 static T *createInstanceFromQuery(const QString &serviceType, 00179 QWidget *parentWidget, QObject *parent, const QString &constraint = QString(), 00180 const QVariantList &args = QVariantList(), QString *error = 0) 00181 { 00182 const KService::List offers = self()->query(serviceType, constraint); 00183 Q_FOREACH (const KService::Ptr &ptr, offers) { 00184 T *component = ptr->template createInstance<T>(parentWidget, parent, args, error); 00185 if (component) { 00186 if (error) 00187 error->clear(); 00188 return component; 00189 } 00190 } 00191 if (error) 00192 *error = i18n("No service matching the requirements was found"); 00193 return 0; 00194 } 00195 00201 #ifndef KDE_NO_DEPRECATED 00202 template <class T> 00203 static KDE_DEPRECATED T *createInstanceFromQuery(const QString &serviceType, const QString &constraint, 00204 QObject *parent, const QStringList &args, int *error = 0) 00205 { 00206 const KService::List offers = KServiceTypeTrader::self()->query(serviceType, constraint); 00207 if (offers.isEmpty()) { 00208 if (error) { 00209 *error = KLibLoader::ErrNoServiceFound; 00210 } 00211 return 0; 00212 } 00213 00214 return KService::createInstance<T>(offers.begin(), offers.end(), parent, args, error); 00215 } 00216 #endif 00217 00218 00222 static void applyConstraints( KService::List& lst, 00223 const QString& constraint ); 00224 00225 private: 00229 KServiceTypeTrader(); 00230 00231 // dissalow copy ctor and assignment operator 00232 KServiceTypeTrader( const KServiceTypeTrader& other ); 00233 KServiceTypeTrader& operator=( const KServiceTypeTrader& rhs ); 00234 00235 class Private; 00236 Private * const d; 00237 }; 00238 00239 #endif
KDE 4.6 API Reference