diff --git a/declarativeimports/plasmaextracomponents/CMakeLists.txt b/declarativeimports/plasmaextracomponents/CMakeLists.txt index 7be6a9432..b6d5b7837 100644 --- a/declarativeimports/plasmaextracomponents/CMakeLists.txt +++ b/declarativeimports/plasmaextracomponents/CMakeLists.txt @@ -9,6 +9,7 @@ set(plasmaextracomponents_SRCS appbackgroundprovider.cpp resourceinstance.cpp plasmaextracomponentsplugin.cpp + fallbackcomponent.cpp ) include_directories( @@ -19,7 +20,8 @@ qt4_automoc(${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) diff --git a/declarativeimports/plasmaextracomponents/fallbackcomponent.cpp b/declarativeimports/plasmaextracomponents/fallbackcomponent.cpp new file mode 100644 index 000000000..10fb0a6ef --- /dev/null +++ b/declarativeimports/plasmaextracomponents/fallbackcomponent.cpp @@ -0,0 +1,60 @@ +/* + * Copyright 2011 Marco Martin + * + * 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 + + +#include +#include + + +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" diff --git a/declarativeimports/plasmaextracomponents/fallbackcomponent.h b/declarativeimports/plasmaextracomponents/fallbackcomponent.h new file mode 100644 index 000000000..b5a13fa7e --- /dev/null +++ b/declarativeimports/plasmaextracomponents/fallbackcomponent.h @@ -0,0 +1,41 @@ +/* + * Copyright 2011 Marco Martin + * + * 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 +#include + + +class FallbackComponent : public QObject +{ + Q_OBJECT + +public: + FallbackComponent(QObject *parent = 0); + + Q_INVOKABLE QString resolvePath(const QString &component, const QStringList &paths); + +private: + QCache m_paths; +}; + +#endif diff --git a/declarativeimports/plasmaextracomponents/plasmaextracomponentsplugin.cpp b/declarativeimports/plasmaextracomponents/plasmaextracomponentsplugin.cpp index fe54051ce..aa01f163c 100644 --- a/declarativeimports/plasmaextracomponents/plasmaextracomponentsplugin.cpp +++ b/declarativeimports/plasmaextracomponents/plasmaextracomponentsplugin.cpp @@ -21,6 +21,7 @@ #include "appbackgroundprovider_p.h" #include "resourceinstance.h" +#include "fallbackcomponent.h" #include #include @@ -48,8 +49,7 @@ void PlasmaExtraComponentsPlugin::registerTypes(const char *uri) */ // Register additional types here... qmlRegisterType(uri, 0, 1, "ResourceInstance"); - - + qmlRegisterType(uri, 0, 1, "FallbackComponent"); }