KDECore
kservicetypetrader.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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 template <class T>
00202 static KDE_DEPRECATED T *createInstanceFromQuery(const QString &serviceType, const QString &constraint,
00203 QObject *parent, const QStringList &args, int *error = 0)
00204 {
00205 const KService::List offers = KServiceTypeTrader::self()->query(serviceType, constraint);
00206 if (offers.isEmpty()) {
00207 if (error) {
00208 *error = KLibLoader::ErrNoServiceFound;
00209 }
00210 return 0;
00211 }
00212
00213 return KService::createInstance<T>(offers.begin(), offers.end(), parent, args, error);
00214 }
00215
00216
00220 static void applyConstraints( KService::List& lst,
00221 const QString& constraint );
00222
00223 private:
00227 KServiceTypeTrader();
00228
00229
00230 KServiceTypeTrader( const KServiceTypeTrader& other );
00231 KServiceTypeTrader& operator=( const KServiceTypeTrader& rhs );
00232
00233 class Private;
00234 Private * const d;
00235 };
00236
00237 #endif