• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

KDECore

BackendsManager.cpp

Go to the documentation of this file.
00001 /*
00002 *   Copyright (C) 2009 Dario Freddi <drf@kde.org>
00003 *
00004 *   This program is free software; you can redistribute it and/or modify
00005 *   it under the terms of the GNU Lesser General Public License as published by
00006 *   the Free Software Foundation; either version 2.1 of the License, or
00007 *   (at your option) any later version.
00008 *
00009 *   This program 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
00012 *   GNU General Public License for more details.
00013 *
00014 *   You should have received a copy of the GNU Lesser General Public License
00015 *   along with this program; if not, write to the
00016 *   Free Software Foundation, Inc.,
00017 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .
00018 */
00019 
00020 #include "BackendsManager.h"
00021 
00022 #include "BackendsConfig.h"
00023 
00024 // Include fake backends
00025 #include "backends/fake/FakeBackend.h"
00026 #include "backends/fakehelper/FakeHelperProxy.h"
00027 
00028 #include <QPluginLoader>
00029 #include <QDir>
00030 
00031 #include <kdebug.h>
00032 
00033 namespace KAuth
00034 {
00035 
00036 AuthBackend *BackendsManager::auth = 0;
00037 HelperProxy *BackendsManager::helper = 0;
00038 
00039 BackendsManager::BackendsManager()
00040 {
00041 }
00042 
00043 QList< QObject* > BackendsManager::retrieveInstancesIn(const QString& path)
00044 {
00045     QDir pluginPath(path);
00046 
00047     if (!pluginPath.exists()) {
00048         return QList< QObject* >();
00049     }
00050 
00051     const QFileInfoList entryList = pluginPath.entryInfoList(QDir::NoDotAndDotDot | QDir::Files);
00052 
00053     if (entryList.isEmpty()) {
00054         return QList< QObject* >();
00055     }
00056 
00057     QList< QObject* > retlist;
00058 
00059     foreach(const QFileInfo &fi, entryList) {
00060         QString filePath = fi.filePath(); // file name with path
00061         QString fileName = fi.fileName(); // just file name
00062 
00063         if(!QLibrary::isLibrary(filePath)) {
00064             continue;
00065         }
00066 
00067         QString errstr;
00068         QPluginLoader loader(filePath);
00069         QObject *instance = loader.instance();
00070         if (instance) {
00071             retlist.append(instance);
00072         }
00073     }
00074 
00075     return retlist;
00076 }
00077 
00078 void BackendsManager::init()
00079 {
00080     // Backend plugin
00081     const QList< QObject* > backends = retrieveInstancesIn(QFile::decodeName(KAUTH_BACKEND_PLUGIN_DIR));
00082 
00083     foreach (QObject *instance, backends) {
00084         auth = qobject_cast< KAuth::AuthBackend* >(instance);
00085         if (auth) {
00086             break;
00087         }
00088     }
00089 
00090     // Helper plugin
00091     const QList< QObject* > helpers = retrieveInstancesIn(QFile::decodeName(KAUTH_HELPER_PLUGIN_DIR));
00092 
00093     foreach (QObject *instance, helpers) {
00094         helper = qobject_cast< KAuth::HelperProxy* >(instance);
00095         if (helper) {
00096             break;
00097         }
00098     }
00099 
00100     if (!auth) {
00101         // Load the fake auth backend then
00102         auth = new FakeBackend;
00103 #ifndef KAUTH_COMPILING_FAKE_BACKEND
00104         // Spit a fat warning
00105         kWarning() << "WARNING: KAuth was compiled with a working backend, but was unable to load it! Check your installation!";
00106 #endif
00107     }
00108 
00109     if (!helper) {
00110         // Load the fake helper backend then
00111         helper = new FakeHelperProxy;
00112 #ifndef KAUTH_COMPILING_FAKE_BACKEND
00113         // Spit a fat warning
00114         kWarning() << "WARNING: KAuth was compiled with a working helper backend, but was unable to load it! "
00115                       "Check your installation!";
00116 #endif
00117     }
00118 }
00119 
00120 AuthBackend *BackendsManager::authBackend()
00121 {
00122     if (!auth) {
00123         init();
00124     }
00125 
00126     return auth;
00127 }
00128 
00129 HelperProxy *BackendsManager::helperProxy()
00130 {
00131     if (!helper) {
00132         init();
00133     }
00134 
00135     return helper;
00136 }
00137 
00138 } // namespace Auth

KDECore

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
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