• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

libsolidcontrol

managerbase.cpp

Go to the documentation of this file.
00001 /*  This file is part of the KDE project
00002     Copyright (C) 2006-2007 Kevin Ottens <ervin@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License version 2 as published by the Free Software Foundation.
00007 
00008     This library is distributed in the hope that it will be useful,
00009     but WITHOUT ANY WARRANTY; without even the implied warranty of
00010     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011     Library General Public License for more details.
00012 
00013     You should have received a copy of the GNU Library General Public License
00014     along with this library; see the file COPYING.LIB.  If not, write to
00015     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016     Boston, MA 02110-1301, USA.
00017 
00018 */
00019 
00020 #include "managerbase_p.h"
00021 
00022 #include <kservicetypetrader.h>
00023 #include <kservice.h>
00024 #include <klibloader.h>
00025 
00026 #include <klocale.h>
00027 #include <kdebug.h>
00028 
00029 static QMap<QString, QObject *> _k_preloadedBackends;
00030 
00031 Solid::Control::ManagerBasePrivate::ManagerBasePrivate()
00032     : m_backend(0)
00033 {
00034 }
00035 
00036 Solid::Control::ManagerBasePrivate::~ManagerBasePrivate()
00037 {
00038 }
00039 
00040 void Solid::Control::ManagerBasePrivate::loadBackend(const QString &description, const char *serviceName,
00041                                             const char *backendClassName)
00042 {
00043     if (_k_preloadedBackends.contains(backendClassName)) {
00044         m_backend = _k_preloadedBackends[backendClassName];
00045         return;
00046     }
00047 
00048     QStringList error_msg;
00049 
00050     KService::List offers = KServiceTypeTrader::self()->query(serviceName, "(Type == 'Service')");
00051 
00052     foreach (const KService::Ptr &ptr, offers)
00053     {
00054         QString error_string;
00055         m_backend = ptr->createInstance<QObject>(0, QVariantList(), &error_string);
00056 
00057         if(m_backend!=0) {
00058             if (m_backend->inherits(backendClassName)) {
00059                 kDebug() << "Backend loaded: " << ptr->name();
00060                 break;
00061             } else {
00062                 QString error_string = i18n("Backend loaded but wrong type obtained, expected %1",
00063                                              backendClassName);
00064 
00065                 kDebug() << "Error loading '" << ptr->name() << "': " << error_string;
00066                 error_msg.append(error_string);
00067 
00068                 delete m_backend;
00069                 m_backend = 0;
00070             }
00071         } else {
00072             kDebug() << "Error loading '" << ptr->name() << "', KService said: " << error_string;
00073             error_msg.append(error_string);
00074         }
00075     }
00076 
00077     if (m_backend==0) {
00078         if (offers.size() == 0)
00079         {
00080             m_errorText = i18n("No %1 Backend found", description);
00081         }
00082         else
00083         {
00084             m_errorText = "<qt>";
00085             m_errorText+= i18n("Unable to use any of the %1 Backends", description);
00086             m_errorText+= "<table>";
00087 
00088             QString line = "<tr><td><b>%1</b></td><td>%2</td></tr>";
00089 
00090             for (int i = 0; i< offers.size(); i++)
00091             {
00092                 m_errorText+= line.arg(offers[i]->name()).arg(error_msg[i]);
00093             }
00094 
00095             m_errorText+= "</table></qt>";
00096         }
00097     }
00098 }
00099 
00100 QString Solid::Control::ManagerBasePrivate::errorText() const
00101 {
00102     return m_errorText;
00103 }
00104 
00105 QObject *Solid::Control::ManagerBasePrivate::managerBackend() const
00106 {
00107     return m_backend;
00108 }
00109 
00110 void Solid::Control::ManagerBasePrivate::_k_forcePreloadedBackend(const char *backendClassName, QObject *backend)
00111 {
00112     _k_preloadedBackends[backendClassName] = backend;
00113 }
00114 
00115 

libsolidcontrol

Skip menu "libsolidcontrol"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libplasma
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal