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

KDECore

  • sources
  • kde-4.14
  • kdelibs
  • kdecore
  • auth
BackendsManager.cpp
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2009 Dario Freddi <drf@kde.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA .
18 */
19 
20 #include "BackendsManager.h"
21 
22 #include "BackendsConfig.h"
23 
24 // Include fake backends
25 #include "backends/fake/FakeBackend.h"
26 #include "backends/fakehelper/FakeHelperProxy.h"
27 
28 #include <QPluginLoader>
29 #include <QDir>
30 
31 #include <kdebug.h>
32 
33 namespace KAuth
34 {
35 
36 AuthBackend *BackendsManager::auth = 0;
37 HelperProxy *BackendsManager::helper = 0;
38 
39 BackendsManager::BackendsManager()
40 {
41 }
42 
43 QList< QObject* > BackendsManager::retrieveInstancesIn(const QString& path)
44 {
45  QDir pluginPath(path);
46 
47  if (!pluginPath.exists()) {
48  return QList< QObject* >();
49  }
50 
51  const QFileInfoList entryList = pluginPath.entryInfoList(QDir::NoDotAndDotDot | QDir::Files);
52 
53  if (entryList.isEmpty()) {
54  return QList< QObject* >();
55  }
56 
57  QList< QObject* > retlist;
58 
59  foreach(const QFileInfo &fi, entryList) {
60  QString filePath = fi.filePath(); // file name with path
61  QString fileName = fi.fileName(); // just file name
62 
63  if(!QLibrary::isLibrary(filePath)) {
64  continue;
65  }
66 
67  QString errstr;
68  QPluginLoader loader(filePath);
69  QObject *instance = loader.instance();
70  if (instance) {
71  retlist.append(instance);
72  }
73  }
74 
75  return retlist;
76 }
77 
78 void BackendsManager::init()
79 {
80  // Backend plugin
81  const QList< QObject* > backends = retrieveInstancesIn(QFile::decodeName(KAUTH_BACKEND_PLUGIN_DIR));
82 
83  foreach (QObject *instance, backends) {
84  auth = qobject_cast< KAuth::AuthBackend* >(instance);
85  if (auth) {
86  break;
87  }
88  }
89 
90  // Helper plugin
91  const QList< QObject* > helpers = retrieveInstancesIn(QFile::decodeName(KAUTH_HELPER_PLUGIN_DIR));
92 
93  foreach (QObject *instance, helpers) {
94  helper = qobject_cast< KAuth::HelperProxy* >(instance);
95  if (helper) {
96  break;
97  }
98  }
99 
100  if (!auth) {
101  // Load the fake auth backend then
102  auth = new FakeBackend;
103 #ifndef KAUTH_COMPILING_FAKE_BACKEND
104  // Spit a fat warning
105  kWarning() << "WARNING: KAuth was compiled with a working backend, but was unable to load it! Check your installation!";
106 #endif
107  }
108 
109  if (!helper) {
110  // Load the fake helper backend then
111  helper = new FakeHelperProxy;
112 #ifndef KAUTH_COMPILING_FAKE_BACKEND
113  // Spit a fat warning
114  kWarning() << "WARNING: KAuth was compiled with a working helper backend, but was unable to load it! "
115  "Check your installation!";
116 #endif
117  }
118 }
119 
120 AuthBackend *BackendsManager::authBackend()
121 {
122  if (!auth) {
123  init();
124  }
125 
126  return auth;
127 }
128 
129 HelperProxy *BackendsManager::helperProxy()
130 {
131  if (!helper) {
132  init();
133  }
134 
135  return helper;
136 }
137 
138 } // namespace Auth
FakeBackend.h
KAuth::HelperProxy
Definition: HelperProxy.h:35
kdebug.h
KAuth::BackendsManager::authBackend
static AuthBackend * authBackend()
Definition: BackendsManager.cpp:120
QFileInfo::filePath
QString filePath() const
QList::append
void append(const T &value)
KAuth::BackendsManager::helperProxy
static HelperProxy * helperProxy()
Definition: BackendsManager.cpp:129
QFileInfo::fileName
QString fileName() const
QObject
QString
QList
Definition: kaboutdata.h:33
QFileInfo
kWarning
#define kWarning
Definition: kdebug.h:322
QDir
KAuth::AuthBackend
Definition: AuthBackend.h:31
QPluginLoader
FakeHelperProxy.h
BackendsManager.h
QFile::decodeName
QString decodeName(const QByteArray &localFileName)
QLibrary::isLibrary
bool isLibrary(const QString &fileName)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:22:10 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • 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

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal