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
00172 template <class T>
00173 static T *createInstanceFromQuery(const QString &serviceType,
00174 QWidget *parentWidget, QObject *parent, const QString &constraint = QString(),
00175 const QVariantList &args = QVariantList(), QString *error = 0)
00176 {
00177 const KService::List offers = self()->query(serviceType, constraint);
00178 Q_FOREACH (const KService::Ptr &ptr, offers) {
00179 T *component = ptr->template createInstance<T>(parentWidget, parent, args, error);
00180 if (component) {
00181 if (error)
00182 error->clear();
00183 return component;
00184 }
00185 }
00186 if (error)
00187 *error = i18n("No service matching the requirements was found");
00188 return 0;
00189 }
00190
00191 template <class T>
00192 static KDE_DEPRECATED T *createInstanceFromQuery(const QString &serviceType, const QString &constraint,
00193 QObject *parent, const QStringList &args, int *error = 0)
00194 {
00195 const KService::List offers = KServiceTypeTrader::self()->query(serviceType, constraint);
00196 if (offers.isEmpty()) {
00197 if (error) {
00198 *error = KLibLoader::ErrNoServiceFound;
00199 }
00200 return 0;
00201 }
00202
00203 return KService::createInstance<T>(offers.begin(), offers.end(), parent, args, error);
00204 }
00205
00206
00210 static void applyConstraints( KService::List& lst,
00211 const QString& constraint );
00212
00213 private:
00217 KServiceTypeTrader();
00218
00219
00220 KServiceTypeTrader( const KServiceTypeTrader& other );
00221 KServiceTypeTrader& operator=( const KServiceTypeTrader& rhs );
00222
00223 class Private;
00224 Private * const d;
00225 };
00226
00227 #endif