Add the fallback component from the plasma-mobile repository

This commit is contained in:
Giorgos Tsiapaliokas 2012-09-24 21:51:39 +03:00
parent d86b233464
commit dde5cc7d6c
4 changed files with 106 additions and 3 deletions

View File

@ -9,6 +9,7 @@ set(plasmaextracomponents_SRCS
appbackgroundprovider.cpp appbackgroundprovider.cpp
resourceinstance.cpp resourceinstance.cpp
plasmaextracomponentsplugin.cpp plasmaextracomponentsplugin.cpp
fallbackcomponent.cpp
) )
include_directories( include_directories(
@ -19,7 +20,8 @@ qt4_automoc(${plasmaextracomponents_SRCS})
add_library(plasmaextracomponentsplugin SHARED ${plasmaextracomponents_SRCS}) add_library(plasmaextracomponentsplugin SHARED ${plasmaextracomponents_SRCS})
target_link_libraries(plasmaextracomponentsplugin ${QT_QTCORE_LIBRARY} ${QT_QTDECLARATIVE_LIBRARY} ${QT_QTGUI_LIBRARY} ${KDE4_PLASMA_LIBS} ${KACTIVITIES_LIBRARY} ) target_link_libraries(plasmaextracomponentsplugin ${QT_QTCORE_LIBRARY} ${QT_QTDECLARATIVE_LIBRARY}
${QT_QTGUI_LIBRARY} ${KDE4_PLASMA_LIBS} ${KACTIVITIES_LIBRARY} )
install(TARGETS plasmaextracomponentsplugin DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/plasma/extras) install(TARGETS plasmaextracomponentsplugin DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/plasma/extras)

View File

@ -0,0 +1,60 @@
/*
* Copyright 2011 Marco Martin <mart@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "fallbackcomponent.h"
#include <QFile>
#include <KStandardDirs>
#include <KDebug>
FallbackComponent::FallbackComponent(QObject *parent)
: QObject(parent)
{
}
QString FallbackComponent::resolvePath(const QString &component, const QStringList &paths)
{
QString resolved;
foreach (const QString &path, paths) {
//kDebug() << "Searching for" << path;
const QString key = component + '/' + path;
if (m_paths.contains(key)) {
resolved = *m_paths.object(key);
if (!resolved.isEmpty()) {
break;
} else {
continue;
}
}
resolved = KStandardDirs::locate("data", "plasma/" + key);
m_paths.insert(key, new QString(resolved));
if (!resolved.isEmpty()) {
break;
}
}
return resolved;
}
#include "fallbackcomponent.moc"

View File

@ -0,0 +1,41 @@
/*
* Copyright 2011 Marco Martin <mart@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef FALLBACKCOMPONENT_H
#define FALLBACKCOMPONENT_H
#include <QObject>
#include <QCache>
class FallbackComponent : public QObject
{
Q_OBJECT
public:
FallbackComponent(QObject *parent = 0);
Q_INVOKABLE QString resolvePath(const QString &component, const QStringList &paths);
private:
QCache<QString, QString> m_paths;
};
#endif

View File

@ -21,6 +21,7 @@
#include "appbackgroundprovider_p.h" #include "appbackgroundprovider_p.h"
#include "resourceinstance.h" #include "resourceinstance.h"
#include "fallbackcomponent.h"
#include <QtDeclarative/qdeclarative.h> #include <QtDeclarative/qdeclarative.h>
#include <QtDeclarative/QDeclarativeEngine> #include <QtDeclarative/QDeclarativeEngine>
@ -48,8 +49,7 @@ void PlasmaExtraComponentsPlugin::registerTypes(const char *uri)
*/ */
// Register additional types here... // Register additional types here...
qmlRegisterType<ResourceInstance>(uri, 0, 1, "ResourceInstance"); qmlRegisterType<ResourceInstance>(uri, 0, 1, "ResourceInstance");
qmlRegisterType<FallbackComponent>(uri, 0, 1, "FallbackComponent");
} }