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

KDECore

  • 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
33namespace KAuth
34{
35
36AuthBackend *BackendsManager::auth = 0;
37HelperProxy *BackendsManager::helper = 0;
38
39BackendsManager::BackendsManager()
40{
41}
42
43QList< 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
78void 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
120AuthBackend *BackendsManager::authBackend()
121{
122 if (!auth) {
123 init();
124 }
125
126 return auth;
127}
128
129HelperProxy *BackendsManager::helperProxy()
130{
131 if (!helper) {
132 init();
133 }
134
135 return helper;
136}
137
138} // namespace Auth
BackendsManager.h
FakeBackend.h
FakeHelperProxy.h
KAuth::AuthBackend
Definition: AuthBackend.h:32
KAuth::BackendsManager::authBackend
static AuthBackend * authBackend()
Definition: BackendsManager.cpp:120
KAuth::BackendsManager::helperProxy
static HelperProxy * helperProxy()
Definition: BackendsManager.cpp:129
KAuth::HelperProxy
Definition: HelperProxy.h:36
QList
Definition: kaboutdata.h:33
QObject
QPluginLoader
QString
kWarning
#define kWarning
Definition: kdebug.h:322
kdebug.h
KAuth
Definition: AuthBackend.cpp:24
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 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
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