1 /* This file is part of the KDE project
2 Copyright (C) 2006-2007 Kevin Ottens <ervin@kde.org>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
20 #include "managerbase_p.h"
22 #include <kservicetypetrader.h>
24 #include <klibloader.h>
29 static QMap
<QString
, QObject
*> _k_preloadedBackends
;
31 Solid::Control::ManagerBasePrivate::ManagerBasePrivate()
36 Solid::Control::ManagerBasePrivate::~ManagerBasePrivate()
40 void Solid::Control::ManagerBasePrivate::loadBackend(const QString
&description
, const char *serviceName
,
41 const char *backendClassName
)
43 if (_k_preloadedBackends
.contains(backendClassName
)) {
44 m_backend
= _k_preloadedBackends
[backendClassName
];
48 QStringList error_msg
;
50 KService::List offers
= KServiceTypeTrader::self()->query(serviceName
, "(Type == 'Service')");
52 foreach (const KService::Ptr
&ptr
, offers
)
55 m_backend
= ptr
->createInstance
<QObject
>(0, QVariantList(), &error_string
);
58 if (m_backend
->inherits(backendClassName
)) {
59 kDebug() << "Backend loaded: " << ptr
->name();
62 QString error_string
= i18n("Backend loaded but wrong type obtained, expected %1",
65 kDebug() << "Error loading '" << ptr
->name() << "': " << error_string
;
66 error_msg
.append(error_string
);
72 kDebug() << "Error loading '" << ptr
->name() << "', KService said: " << error_string
;
73 error_msg
.append(error_string
);
78 if (offers
.size() == 0)
80 m_errorText
= i18n("No %1 Backend found", description
);
85 m_errorText
+= i18n("Unable to use any of the %1 Backends", description
);
86 m_errorText
+= "<table>";
88 QString line
= "<tr><td><b>%1</b></td><td>%2</td></tr>";
90 for (int i
= 0; i
< offers
.size(); i
++)
92 m_errorText
+= line
.arg(offers
[i
]->name()).arg(error_msg
[i
]);
95 m_errorText
+= "</table></qt>";
100 QString
Solid::Control::ManagerBasePrivate::errorText() const
105 QObject
*Solid::Control::ManagerBasePrivate::managerBackend() const
110 void Solid::Control::ManagerBasePrivate::_k_forcePreloadedBackend(const char *backendClassName
, QObject
*backend
)
112 _k_preloadedBackends
[backendClassName
] = backend
;