diff --git a/import/CMakeLists.txt b/import/CMakeLists.txt --- a/import/CMakeLists.txt +++ b/import/CMakeLists.txt @@ -1,6 +1,7 @@ project(settings) set(settings_SRCS + package.cpp settingsplugin.cpp settingsmodule.cpp settingsmodulesmodel.cpp diff --git a/import/SettingsItem.qml b/import/SettingsItem.qml --- a/import/SettingsItem.qml +++ b/import/SettingsItem.qml @@ -66,7 +66,7 @@ } } - MobileComponents.Package { + ActiveSettings.Package { id: switcherPackage } } diff --git a/import/package.h b/import/package.h new file mode 100644 --- /dev/null +++ b/import/package.h @@ -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 of the License, 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 PACKAGE_H +#define PACKAGE_H + +#include +#include +#include + +namespace Plasma { + class Package; +} + + +class QTimer; + +class Package : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) + Q_PROPERTY(QString visibleName READ visibleName NOTIFY visibleNameChanged) + +public: + Package(QObject *parent = 0); + ~Package(); + + QString name() const; + void setName(const QString &name); + + Q_INVOKABLE QString filePath(const QString &fileType, const QString &filename) const; + Q_INVOKABLE QString filePath(const QString &fileType) const; + + QString visibleName() const; + +Q_SIGNALS: + void nameChanged(const QString &); + void visibleNameChanged(); + +private: + QString m_name; + Plasma::Package m_package; +}; + +#endif diff --git a/import/package.cpp b/import/package.cpp new file mode 100644 --- /dev/null +++ b/import/package.cpp @@ -0,0 +1,94 @@ +/*************************************************************************** + * 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 of the License, 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 "package.h" + +#include + +#include +#include +#include +#include +#include + +Package::Package(QObject *parent) + : QObject(parent) +{ +} + +Package::~Package() +{ +} + + +QString Package::name() const +{ + return m_name; +} + +void Package::setName(const QString &name) +{ + if (m_name == name) { + return; + } + + m_name = name; + + m_package = Plasma::PluginLoader::self()->loadPackage(QStringLiteral("Plasma/Generic")); + m_package.setPath(name); + QString domain = QStringLiteral("plasma_package_") + name; + KLocalizedString::setApplicationDomain(domain.toLocal8Bit().data()); + + emit nameChanged(name); + emit visibleNameChanged(); +} + +QString Package::visibleName() const +{ + if (!m_package.isValid()) { + return QString(); + } + + return m_package.metadata().name(); +} + +QString Package::filePath(const QString &fileType, const QString &fileName) const +{ + if (!m_package.isValid()) { + return QString(); + } + + if (fileName.isEmpty()) { + return m_package.filePath(fileType.toLatin1()); + } else { + return m_package.filePath(fileType.toLatin1(), fileName); + } +} + +QString Package::filePath(const QString &fileType) const +{ + if (!m_package.isValid()) { + return QString(); + } + + return m_package.filePath(fileType.toLatin1()); +} + +#include "package.moc" + diff --git a/import/settingsplugin.cpp b/import/settingsplugin.cpp --- a/import/settingsplugin.cpp +++ b/import/settingsplugin.cpp @@ -27,6 +27,7 @@ #include "settingsmodulesmodel.h" #include "settingscomponent.h" #include "configgroup.h" +#include "package.h" void SettingsPlugin::registerTypes(const char *uri) { @@ -36,6 +37,7 @@ qmlRegisterType(uri, major, minor, "SettingsModulesModel"); qmlRegisterType(uri, major, minor, "SettingsModule"); qmlRegisterType(uri, major, minor, "SettingsComponent"); + qmlRegisterType(uri, major, minor, "Package"); qmlRegisterType(uri, major, minor, "ConfigGroup"); }