diff --git a/kcms/desktoptheme/CMakeLists.txt b/kcms/desktoptheme/CMakeLists.txt --- a/kcms/desktoptheme/CMakeLists.txt +++ b/kcms/desktoptheme/CMakeLists.txt @@ -1,24 +1,26 @@ # KI18N Translation Domain for this library -add_definitions(-DTRANSLATION_DOMAIN=\"kcm_desktopthemedetails\") +add_definitions(-DTRANSLATION_DOMAIN=\"kcm_desktoptheme\") -set(kcmdesktoptheme_SRCS kcmdesktoptheme.cpp thememodel.cpp) -ki18n_wrap_ui(kcmdesktoptheme_SRCS DesktopTheme.ui) - -add_library(kcm_desktoptheme MODULE ${kcmdesktoptheme_SRCS}) -target_link_libraries(kcm_desktoptheme ${X11_LIBRARIES} - KF5::Archive - KF5::KCMUtils - KF5::I18n - KF5::Parts - KF5::Plasma - KF5::NewStuff +set(kcm_desktoptheme_SRCS + kcm.cpp ) -kcoreaddons_desktop_to_json(kcm_desktoptheme desktoptheme.desktop) +add_library(kcm_desktoptheme MODULE ${kcm_desktoptheme_SRCS}) + +target_link_libraries(kcm_desktoptheme + KF5::CoreAddons + KF5::KCMUtils + KF5::I18n + KF5::Plasma + KF5::Declarative + KF5::QuickAddons + KF5::NewStuff +) -install(TARGETS kcm_desktoptheme DESTINATION ${PLUGIN_INSTALL_DIR} ) -install( FILES plasma-themes.knsrc DESTINATION ${CONFIG_INSTALL_DIR} ) +kcoreaddons_desktop_to_json(kcm_desktoptheme "kcm_desktoptheme.desktop") -########### install files ############### -install( FILES desktoptheme.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) +#this desktop file is installed only for retrocompatibility with sycoca +install(FILES kcm_desktoptheme.desktop DESTINATION ${SERVICES_INSTALL_DIR}) +install(TARGETS kcm_desktoptheme DESTINATION ${PLUGIN_INSTALL_DIR}/kcms) +kpackage_install_package(package kcm_desktoptheme kcms) diff --git a/kcms/desktoptheme/DesktopTheme.ui b/kcms/desktoptheme/DesktopTheme.ui deleted file mode 100644 --- a/kcms/desktoptheme/DesktopTheme.ui +++ /dev/null @@ -1,74 +0,0 @@ - - - DesktopTheme - - - - 0 - 0 - 669 - 460 - - - - - - - - - - - - Qt::Horizontal - - - - 462 - 20 - - - - - - - - Insta&ll from File - - - - .. - - - - - - - true - - - Get New Themes... - - - - .. - - - - - - - - - - - - - KMessageWidget - QWidget -
KMessageWidget
- 1 -
-
- - -
diff --git a/kcms/desktoptheme/Messages.sh b/kcms/desktoptheme/Messages.sh --- a/kcms/desktoptheme/Messages.sh +++ b/kcms/desktoptheme/Messages.sh @@ -1,4 +1,4 @@ -#! /bin/sh -$EXTRACTRC *.ui >> rc.cpp -$XGETTEXT *.cpp -o $podir/kcm_desktopthemedetails.pot +#! /usr/bin/env bash +$EXTRACTRC `find . -name "*.ui"` >> rc.cpp || exit 11 +$XGETTEXT `find . -name "*.cpp" -o -name "*.qml"` -o $podir/kcm_desktoptheme.pot rm -f rc.cpp diff --git a/kcms/desktoptheme/desktoptheme.desktop b/kcms/desktoptheme/desktoptheme.desktop deleted file mode 100644 --- a/kcms/desktoptheme/desktoptheme.desktop +++ /dev/null @@ -1,176 +0,0 @@ -[Desktop Entry] -Exec=kcmshell5 desktoptheme -Icon=preferences-desktop -Type=Service - -X-KDE-ServiceTypes=KCModule -X-KDE-Library=kcm_desktoptheme -X-KDE-ParentApp=kcontrol -X-KDE-System-Settings-Parent-Category=workspacetheme -X-DocPath=kcontrol/desktopthemedetails/index.html -X-KDE-Weight=40 - -Name=Desktop Theme -Name[ar]=سمة سطح المكتب -Name[ast]=Tema d'escritoriu -Name[bg]=Тема за работния плот -Name[bn]=ডেস্কটপ থীম -Name[bs]=Tema površi -Name[ca]=Tema d'escriptori -Name[ca@valencia]=Tema d'escriptori -Name[cs]=Motiv plochy -Name[da]=Skrivebordstema -Name[de]=Arbeitsflächen-Design -Name[el]=Θέμα επιφάνειας εργασίας -Name[en_GB]=Desktop Theme -Name[es]=Tema de escritorio -Name[et]=Töölauateema -Name[eu]=Mahaigaineko gaia -Name[fi]=Työpöytäteema -Name[fr]=Thème de bureau -Name[ga]=Téama Deisce -Name[gl]=Tema do escritorio -Name[gu]=ડેસ્કટોપ થીમ -Name[he]=ערכת־הנושא לשולחן־העבודה -Name[hi]=डेस्कटॉप प्रसंग -Name[hr]=Tema radne površine -Name[hu]=Asztali téma -Name[ia]=Thema de scriptorio -Name[id]=Tema Desktop -Name[is]=Skjáborðsþema -Name[it]=Tema del desktop -Name[ja]=デスクトップテーマ -Name[kk]=Үстел нақышы -Name[km]=ស្បែក​ផ្ទៃតុ -Name[kn]=ಗಣಕತೆರೆ ಪರಿಸರವಿನ್ಯಾಸ -Name[ko]=데스크톱 테마 -Name[lt]=Darbalaukio apipavidalinimas -Name[lv]=Darbvirsmas tēma -Name[mr]=डेस्कटॉप शैली -Name[nb]=Skrivebordstema -Name[nds]=Schriefdischmuster -Name[nl]=Bureaubladthema -Name[nn]=Skrivebordstema -Name[pa]=ਡੈਸਕਟਾਪ ਥੀਮ -Name[pl]=Wystrój pulpitu -Name[pt]=Tema do Ambiente de Trabalho -Name[pt_BR]=Tema da área de trabalho -Name[ro]=Tematica de birou -Name[ru]=Тема рабочего стола -Name[si]=වැඩතල තේමාව -Name[sk]=Téma plochy -Name[sl]=Namizna tema -Name[sr]=Тема површи -Name[sr@ijekavian]=Тема површи -Name[sr@ijekavianlatin]=Tema površi -Name[sr@latin]=Tema površi -Name[sv]=Skrivbordstema -Name[tg]=Мавзӯъи мизи корӣ -Name[th]=ชุดตกแต่งพื้นที่ทำงาน -Name[tr]=Masaüstü Teması -Name[ug]=ئۈستەلئۈستى ئۆرنىكى -Name[uk]=Тема стільниці -Name[vi]=Sắc thái màn hình -Name[wa]=Tinme do scribanne -Name[x-test]=xxDesktop Themexx -Name[zh_CN]=桌面主题 -Name[zh_TW]=桌面主題 -Comment=Desktop Theme -Comment[ar]=سمة سطح المكتب -Comment[ast]=Tema d'escritoriu -Comment[bs]=Tema radne površine -Comment[ca]=Tema d'escriptori -Comment[ca@valencia]=Tema d'escriptori -Comment[cs]=Motiv plochy -Comment[da]=Skrivebordstema -Comment[de]=Arbeitsflächen-Design -Comment[el]=Θέμα επιφάνειας εργασίας -Comment[en_GB]=Desktop Theme -Comment[es]=Tema de escritorio -Comment[et]=Töölauateema -Comment[fi]=Työpöytäteema -Comment[fr]=Thème de bureau -Comment[gl]=Tema do escritorio -Comment[hu]=Asztali téma -Comment[id]=Tema Desktop -Comment[is]=Skjáborðsþema -Comment[it]=Tema del desktop -Comment[ja]=デスクトップテーマ -Comment[ko]=데스크톱 테마 -Comment[lt]=Darbalaukio apipavidalinimas -Comment[mr]=डेस्कटॉप शैली -Comment[nb]=Skrivebordstema -Comment[nds]=Schriefdischmuster -Comment[nl]=Bureaubladthema -Comment[nn]=Skrivebordstema -Comment[pa]=ਡੈਸਕਟਾਪ ਥੀਮ -Comment[pl]=Wystrój pulpitu -Comment[pt]=Tema do Ambiente de Trabalho -Comment[pt_BR]=Tema da área de trabalho -Comment[ru]=Тема рабочего стола -Comment[sk]=Téma plochy -Comment[sl]=Namizna tema -Comment[sr]=Тема површи -Comment[sr@ijekavian]=Тема површи -Comment[sr@ijekavianlatin]=Tema površi -Comment[sr@latin]=Tema površi -Comment[sv]=Skrivbordstema -Comment[tr]=Masaüstü Teması -Comment[uk]=Тема стільниці -Comment[x-test]=xxDesktop Themexx -Comment[zh_CN]=桌面主题 -Comment[zh_TW]=桌面主題 -X-KDE-Keywords=Desktop Theme -X-KDE-Keywords[ar]=سمة سطح المكتب -X-KDE-Keywords[ast]=Tema d'escritoriu -X-KDE-Keywords[bs]=Tema površi -X-KDE-Keywords[ca]=Tema d'escriptori -X-KDE-Keywords[ca@valencia]=Tema d'escriptori -X-KDE-Keywords[cs]=Motiv plochy -X-KDE-Keywords[da]=Skrivebordstema -X-KDE-Keywords[de]=Arbeitsflächen-Design -X-KDE-Keywords[el]=Θέμα επιφάνειας εργασίας -X-KDE-Keywords[en_GB]=Desktop Theme -X-KDE-Keywords[es]=Tema de escritorio -X-KDE-Keywords[et]=Töölauateema -X-KDE-Keywords[eu]=Mahaigaineko gaia -X-KDE-Keywords[fi]=Työpöytäteema -X-KDE-Keywords[fr]=Thème du bureau -X-KDE-Keywords[ga]=Téama Deisce -X-KDE-Keywords[gl]=Tema do escritorio -X-KDE-Keywords[he]=ערכת־הנושא -X-KDE-Keywords[hu]=Asztali téma -X-KDE-Keywords[ia]=Thema de scriptorio -X-KDE-Keywords[id]=Tema Desktop -X-KDE-Keywords[is]=Skjáborðsþema -X-KDE-Keywords[it]=Tema del desktop -X-KDE-Keywords[ja]=デスクトップテーマ -X-KDE-Keywords[kk]=Desktop Theme,Үстел нақышы -X-KDE-Keywords[km]=រូបរាង​ផ្ទៃតុ -X-KDE-Keywords[ko]=데스크톱 테마 -X-KDE-Keywords[lt]=Darbalaukio apipavidalinimas -X-KDE-Keywords[mr]=डेस्कटॉप शैली -X-KDE-Keywords[nb]=Skrivebordstema -X-KDE-Keywords[nds]=Schriefdischmuster -X-KDE-Keywords[nl]=Bureaubladthema -X-KDE-Keywords[nn]=Skrivebordstema -X-KDE-Keywords[pa]=ਡੈਸਕਟਾਪ ਥੀਮ -X-KDE-Keywords[pl]=Wystrój pulpitu -X-KDE-Keywords[pt]=Tema do Ambiente de Trabalho -X-KDE-Keywords[pt_BR]=Tema da área de trabalho -X-KDE-Keywords[ro]=Tematica de birou -X-KDE-Keywords[ru]=Тема рабочего стола -X-KDE-Keywords[sk]=Téma plochy -X-KDE-Keywords[sl]=Namizna tema -X-KDE-Keywords[sr]=Desktop Theme,тема површи -X-KDE-Keywords[sr@ijekavian]=Desktop Theme,тема површи -X-KDE-Keywords[sr@ijekavianlatin]=Desktop Theme,tema površi -X-KDE-Keywords[sr@latin]=Desktop Theme,tema površi -X-KDE-Keywords[sv]=Skrivbordstema -X-KDE-Keywords[tr]=Masaüstü Teması -X-KDE-Keywords[ug]=ئۈستەلئۈستى ئۆرنىكى -X-KDE-Keywords[uk]=тема,стільниця -X-KDE-Keywords[vi]=Sắc thái màn hình -X-KDE-Keywords[x-test]=xxDesktop Themexx -X-KDE-Keywords[zh_CN]=Desktop Theme,桌面主题 -X-KDE-Keywords[zh_TW]=Desktop Theme diff --git a/kcms/desktoptheme/kcm.h b/kcms/desktoptheme/kcm.h new file mode 100644 --- /dev/null +++ b/kcms/desktoptheme/kcm.h @@ -0,0 +1,83 @@ +/* + Copyright (c) 2014 Marco Martin + Copyright (c) 2014 Vishesh Handa + Copyright (c) 2016 David Rosca + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef _KCM_DESKTOPTHEME_H +#define _KCM_DESKTOPTHEME_H + +#include + +namespace Plasma { + class Svg; + class Theme; +} + +class QStandardItemModel; + +class KCMDesktopTheme : public KQuickAddons::ConfigModule +{ + Q_OBJECT + Q_PROPERTY(QStandardItemModel *desktopThemeModel READ desktopThemeModel CONSTANT) + Q_PROPERTY(QString selectedPlugin READ selectedPlugin WRITE setSelectedPlugin NOTIFY selectedPluginChanged) + +public: + enum Roles { + PluginNameRole = Qt::UserRole + 1, + ThemeNameRole, + IsLocalRole + }; + Q_ENUM(Roles) + + KCMDesktopTheme(QObject *parent, const QVariantList &args); + ~KCMDesktopTheme(); + + QStandardItemModel *desktopThemeModel() const; + + QString selectedPlugin() const; + void setSelectedPlugin(const QString &plugin); + + Q_INVOKABLE void getNewThemes(); + Q_INVOKABLE void installThemeFromFile(const QUrl &file); + Q_INVOKABLE void removeTheme(const QString &name); + + Q_INVOKABLE void applyPlasmaTheme(QQuickItem *item, const QString &themeName); + +Q_SIGNALS: + void selectedPluginChanged(const QString &plugin); + void showInfoMessage(const QString &infoMessage); + +public Q_SLOTS: + void load(); + void save(); + void defaults(); + +private: + void removeThemes(); + void updateNeedsSave(); + + QStandardItemModel *m_model; + QString m_selectedPlugin; + QStringList m_pendingRemoval; + Plasma::Theme *m_defaultTheme; + QHash m_themes; +}; + +Q_DECLARE_LOGGING_CATEGORY(KCM_DESKTOP_THEME) + +#endif // _KCM_DESKTOPTHEME_H diff --git a/kcms/desktoptheme/kcm.cpp b/kcms/desktoptheme/kcm.cpp new file mode 100644 --- /dev/null +++ b/kcms/desktoptheme/kcm.cpp @@ -0,0 +1,273 @@ +/* This file is part of the KDE Project + Copyright (c) 2014 Marco Martin + Copyright (c) 2014 Vishesh Handa + Copyright (c) 2016 David Rosca + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kcm.h" + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include + +Q_LOGGING_CATEGORY(KCM_DESKTOP_THEME, "kcm_desktoptheme") + +K_PLUGIN_FACTORY_WITH_JSON(KCMDesktopThemeFactory, "kcm_desktoptheme.json", registerPlugin();) + +KCMDesktopTheme::KCMDesktopTheme(QObject *parent, const QVariantList &args) + : KQuickAddons::ConfigModule(parent, args) + , m_defaultTheme(new Plasma::Theme(this)) +{ + //This flag seems to be needed in order for QQuickWidget to work + //see https://bugreports.qt-project.org/browse/QTBUG-40765 + //also, it seems to work only if set in the kcm, not in the systemsettings' main + qApp->setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); + qmlRegisterType(); + + KAboutData* about = new KAboutData(QStringLiteral("kcm_desktoptheme"), i18n("Configure Desktop Theme"), + QStringLiteral("0.1"), QString(), KAboutLicense::LGPL); + about->addAuthor(i18n("David Rosca"), QString(), QStringLiteral("nowrep@gmail.com")); + setAboutData(about); + setButtons(Apply | Default); + + m_model = new QStandardItemModel(this); + QHash roles = m_model->roleNames(); + roles[PluginNameRole] = QByteArrayLiteral("pluginName"); + roles[ThemeNameRole] = QByteArrayLiteral("themeName"); + roles[IsLocalRole] = QByteArrayLiteral("isLocal"); + m_model->setItemRoleNames(roles); +} + +KCMDesktopTheme::~KCMDesktopTheme() +{ + delete m_defaultTheme; +} + +QStandardItemModel *KCMDesktopTheme::desktopThemeModel() const +{ + return m_model; +} + +QString KCMDesktopTheme::selectedPlugin() const +{ + return m_selectedPlugin; +} + +void KCMDesktopTheme::setSelectedPlugin(const QString &plugin) +{ + if (m_selectedPlugin == plugin) { + return; + } + m_selectedPlugin = plugin; + Q_EMIT selectedPluginChanged(m_selectedPlugin); + updateNeedsSave(); +} + +void KCMDesktopTheme::getNewThemes() +{ + KNS3::DownloadDialog *dialog = new KNS3::DownloadDialog(QStringLiteral("plasma-themes.knsrc")); + dialog->open(); + + connect(dialog, &QDialog::done, this, [this, dialog]() { + if (!dialog->changedEntries().isEmpty()) { + load(); + } + }); +} + +void KCMDesktopTheme::installThemeFromFile(const QUrl &file) +{ + qCDebug(KCM_DESKTOP_THEME) << "Installing ... " << file; + + QString program = QStringLiteral("plasmapkg2"); + QStringList arguments; + arguments << QStringLiteral("-t") << QStringLiteral("theme") << QStringLiteral("-i") << file.toLocalFile(); + + qCDebug(KCM_DESKTOP_THEME) << program << arguments.join(QStringLiteral(" ")); + QProcess *myProcess = new QProcess(this); + connect(myProcess, static_cast(&QProcess::finished), + this, [this](int exitCode, QProcess::ExitStatus exitStatus) { + Q_UNUSED(exitStatus); + if (exitCode == 0) { + qCDebug(KCM_DESKTOP_THEME) << "Theme installed successfully :)"; + load(); + Q_EMIT showInfoMessage(i18n("Theme installed successfully.")); + } else { + qCWarning(KCM_DESKTOP_THEME) << "Theme installation failed." << exitCode; + Q_EMIT showInfoMessage(i18n("Theme installation failed.")); + } + }); + + connect(myProcess, static_cast(&QProcess::error), + this, [this](QProcess::ProcessError e) { + qCWarning(KCM_DESKTOP_THEME) << "Theme installation failed: " << e; + Q_EMIT showInfoMessage(i18n("Theme installation failed.")); + }); + + myProcess->start(program, arguments); +} + +void KCMDesktopTheme::removeTheme(const QString &name) +{ + Q_ASSERT(!m_pendingRemoval.contains(name)); + Q_ASSERT(!m_model->findItems(name).isEmpty()); + + m_pendingRemoval.append(name); + m_model->removeRow(m_model->findItems(name).at(0)->row()); + + updateNeedsSave(); +} + +void KCMDesktopTheme::applyPlasmaTheme(QQuickItem *item, const QString &themeName) +{ + if (!item) { + return; + } + + Plasma::Theme *theme = m_themes[themeName]; + if (!theme) { + theme = new Plasma::Theme(themeName, this); + m_themes[themeName] = theme; + } + + Q_FOREACH (Plasma::Svg *svg, item->findChildren()) { + svg->setTheme(theme); + svg->setUsingRenderingCache(false); + } +} + +void KCMDesktopTheme::load() +{ + m_pendingRemoval.clear(); + + // Get all desktop themes + QStringList themes; + const QStringList &packs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("plasma/desktoptheme"), QStandardPaths::LocateDirectory); + Q_FOREACH (const QString &ppath, packs) { + const QDir cd(ppath); + const QStringList &entries = cd.entryList(QDir::Dirs | QDir::Hidden | QDir::NoDotAndDotDot); + Q_FOREACH (const QString &pack, entries) { + const QString _metadata = ppath + QLatin1Char('/') + pack + QStringLiteral("/metadata.desktop"); + if (QFile::exists(_metadata)) { + themes << _metadata; + } + } + } + + m_model->clear(); + + Q_FOREACH (const QString &theme, themes) { + int themeSepIndex = theme.lastIndexOf('/', -1); + const QString themeRoot = theme.left(themeSepIndex); + int themeNameSepIndex = themeRoot.lastIndexOf('/', -1); + const QString packageName = themeRoot.right(themeRoot.length() - themeNameSepIndex - 1); + + KDesktopFile df(theme); + + if (df.noDisplay()) { + continue; + } + + QString name = df.readName(); + if (name.isEmpty()) { + name = packageName; + } + const bool isLocal = QFileInfo(theme).isWritable(); + + if (m_model->findItems(packageName).isEmpty()) { + QStandardItem *item = new QStandardItem; + item->setText(packageName); + item->setData(packageName, PluginNameRole); + item->setData(name, ThemeNameRole); + item->setData(isLocal, IsLocalRole); + m_model->appendRow(item); + } + } + + KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("plasmarc")), "Theme"); + setSelectedPlugin(cg.readEntry("name", m_defaultTheme->themeName())); + + updateNeedsSave(); +} + +void KCMDesktopTheme::save() +{ + if (m_defaultTheme->themeName() == m_selectedPlugin) { + return; + } + + m_defaultTheme->setThemeName(m_selectedPlugin); + removeThemes(); + updateNeedsSave(); +} + +void KCMDesktopTheme::defaults() +{ + setSelectedPlugin(QStringLiteral("default")); +} + +void KCMDesktopTheme::updateNeedsSave() +{ + setNeedsSave(!m_pendingRemoval.isEmpty() || m_selectedPlugin != m_defaultTheme->themeName()); +} + +void KCMDesktopTheme::removeThemes() +{ + const QString program = QStringLiteral("plasmapkg2"); + + Q_FOREACH (const QString &name, m_pendingRemoval) { + const QStringList arguments = {QStringLiteral("-t"), QStringLiteral("theme"), QStringLiteral("-r"), name}; + qCDebug(KCM_DESKTOP_THEME) << program << arguments.join(QStringLiteral(" ")); + QProcess *process = new QProcess(this); + connect(process, static_cast(&QProcess::finished), + this, [this, process](int exitCode, QProcess::ExitStatus exitStatus) { + Q_UNUSED(exitStatus); + if (exitCode == 0) { + qCDebug(KCM_DESKTOP_THEME) << "Theme removed successfully :)"; + load(); + } else { + qCWarning(KCM_DESKTOP_THEME) << "Theme removal failed." << exitCode; + Q_EMIT showInfoMessage(i18n("Theme removal failed.")); + } + process->deleteLater(); + }); + + connect(process, static_cast(&QProcess::error), + this, [this, process](QProcess::ProcessError e) { + qCWarning(KCM_DESKTOP_THEME) << "Theme removal failed: " << e; + Q_EMIT showInfoMessage(i18n("Theme removal failed.")); + process->deleteLater(); + }); + + process->start(program, arguments); + } +} + +#include "kcm.moc" diff --git a/kcms/desktoptheme/kcm_desktoptheme.desktop b/kcms/desktoptheme/kcm_desktoptheme.desktop new file mode 100644 --- /dev/null +++ b/kcms/desktoptheme/kcm_desktoptheme.desktop @@ -0,0 +1,14 @@ +[Desktop Entry] +Icon=preferences-desktop +Exec=kcmshell5 kcm_desktoptheme + +Type=Service +X-KDE-ServiceTypes=KCModule +X-KDE-Library=kcm_desktoptheme +X-KDE-ParentApp=kcontrol +X-KDE-System-Settings-Parent-Category=workspacetheme +X-KDE-Weight=40 + +Name=Desktop Theme +Comment=Desktop Theme +X-KDE-Keywords=Desktop Theme diff --git a/kcms/desktoptheme/kcmdesktoptheme.h b/kcms/desktoptheme/kcmdesktoptheme.h deleted file mode 100644 --- a/kcms/desktoptheme/kcmdesktoptheme.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - * KCMDesktopTheme - * Copyright (C) 2002 Karol Szwed - * Copyright (C) 2002 Daniel Molkentin - * Copyright (C) 2007 Urs Wolfer - * - * Portions Copyright (C) TrollTech AS. - * - * Based on kcmstyle which is based on kcmdisplay - * Copyright (C) 1997-2002 kcmdisplay Authors. - * (see Help -> About Style Settings) - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License version 2 as published by the Free Software Foundation. - * - * 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 - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef KCMDESKTOPTHEME_H -#define KCMDESKTOPTHEME_H - -#include - -#include "ui_DesktopTheme.h" - -#include -#include - -Q_DECLARE_LOGGING_CATEGORY(KCM_DESKTOP_THEME_LOG) - -class QFileDialog; -class ThemeModel; - - -namespace Plasma -{ - class Theme; -} - -class KCMDesktopTheme : public KCModule, public Ui::DesktopTheme -{ - Q_OBJECT - -public: - KCMDesktopTheme( QWidget* parent, const QVariantList& ); - ~KCMDesktopTheme(); - - virtual void load(); - virtual void save(); - virtual void defaults(); - -protected Q_SLOTS: - void loadDesktopTheme(); - - void setDesktopThemeDirty(); - - void getNewThemes(); - - void installFinished(int exitCode, QProcess::ExitStatus exitStatus); - void installError(QProcess::ProcessError e); - -private: - static QString toolbarButtonText(int index); - static int toolbarButtonIndex(const QString &text); - - bool m_bDesktopThemeDirty; - - void showFileDialog(); - QFileDialog *m_dialog; - void installTheme(const QString &file); - void fileBrowserCompleted(); - - ThemeModel* m_themeModel; - Plasma::Theme *m_defaultTheme; -}; - -#endif // KCMDESKTOPTHEME_H - -// vim: set noet ts=4: diff --git a/kcms/desktoptheme/kcmdesktoptheme.cpp b/kcms/desktoptheme/kcmdesktoptheme.cpp deleted file mode 100644 --- a/kcms/desktoptheme/kcmdesktoptheme.cpp +++ /dev/null @@ -1,234 +0,0 @@ -/* - * KCMDesktopTheme - * Copyright (C) 2002 Karol Szwed - * Copyright (C) 2002 Daniel Molkentin - * Copyright (C) 2007 Urs Wolfer - * Copyright (C) 2009 by Davide Bettio - - * Portions Copyright (C) 2007 Paolo Capriotti - * Portions Copyright (C) 2007 Ivan Cukic - * Portions Copyright (C) 2008 by Petri Damsten - * Portions Copyright (C) 2000 TrollTech AS. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License version 2 as published by the Free Software Foundation. - * - * 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 - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "kcmdesktoptheme.h" - -#include "thememodel.h" - -#include - -#include -#include - -#include - -/**** DLL Interface for kcontrol ****/ - -#include - -Q_LOGGING_CATEGORY(KCM_DESKTOP_THEME_LOG, "log_kcm_desktoptheme") - -K_PLUGIN_FACTORY_WITH_JSON(KCMDesktopThemeFactory, "desktoptheme.json", registerPlugin();) - -KCMDesktopTheme::KCMDesktopTheme( QWidget* parent, const QVariantList& ) - : KCModule( parent ) - , m_dialog(0) - , m_defaultTheme(new Plasma::Theme(this)) -{ - setQuickHelp( i18n("

Desktop Theme

" - "This module allows you to modify the visual appearance " - "of the desktop.")); - - setupUi(this); - - m_bDesktopThemeDirty = false; - - KAboutData *about = - new KAboutData( QStringLiteral("KCMDesktopTheme"), i18n("KDE Desktop Theme Module"), - QStringLiteral("1.0"), QString(), KAboutLicense::GPL, - i18n("(c) 2002 Karol Szwed, Daniel Molkentin")); - - about->addAuthor(QStringLiteral("Karol Szwed"), QString(), QStringLiteral("gallium@kde.org")); - about->addAuthor(QStringLiteral("Daniel Molkentin"), QString(), QStringLiteral("molkentin@kde.org")); - about->addAuthor(QStringLiteral("Ralf Nolden"), QString(), QStringLiteral("nolden@kde.org")); - setAboutData( about ); - - m_messageWidget->hide(); - - m_newThemeButton->setIcon(QIcon::fromTheme(QStringLiteral("get-hot-new-stuff"))); - - m_themeModel = new ThemeModel(this); - m_theme->setModel(m_themeModel); - m_theme->setItemDelegate(new ThemeDelegate(m_theme)); - m_theme->setVerticalScrollMode(QAbstractItemView::ScrollPerItem); - - connect(m_theme->selectionModel(), &QItemSelectionModel::currentChanged, - this, &KCMDesktopTheme::setDesktopThemeDirty); - connect(m_newThemeButton, &QAbstractButton::clicked, this, &KCMDesktopTheme::getNewThemes); - connect(m_fileInstallButton, &QPushButton::clicked, this, &KCMDesktopTheme::showFileDialog); -} - -KCMDesktopTheme::~KCMDesktopTheme() -{ - delete m_dialog; -} - -void KCMDesktopTheme::load() -{ - loadDesktopTheme(); - - m_bDesktopThemeDirty = false; - - emit changed( false ); -} - -void KCMDesktopTheme::save() -{ - qCDebug(KCM_DESKTOP_THEME_LOG) << "Save!"; - // Don't do anything if we don't need to. - if (!m_bDesktopThemeDirty) { - return; - } - - //Desktop theme - if ( m_bDesktopThemeDirty ) - { - QString theme = m_themeModel->data(m_theme->currentIndex(), ThemeModel::PackageNameRole).toString(); - qCDebug(KCM_DESKTOP_THEME_LOG) << "theme changed to " << theme; - qCDebug(KCM_DESKTOP_THEME_LOG) << "m-defaultTheme" << theme; - m_defaultTheme->setThemeName(theme); - - } - - // Clean up - m_bDesktopThemeDirty = false; - emit changed( false ); - qCDebug(KCM_DESKTOP_THEME_LOG) << "saved."; -} - -void KCMDesktopTheme::defaults() -{ - m_theme->setCurrentIndex(m_themeModel->indexOf(QStringLiteral("default"))); - setDesktopThemeDirty(); -} - -void KCMDesktopTheme::setDesktopThemeDirty() -{ - m_bDesktopThemeDirty = true; - emit changed(true); -} - -void KCMDesktopTheme::getNewThemes() -{ - KNS3::DownloadDialog dialog(QStringLiteral("plasma-themes.knsrc"), this); - dialog.exec(); - KNS3::Entry::List entries = dialog.changedEntries(); - - if (!entries.isEmpty()) { - loadDesktopTheme(); - } -} - -void KCMDesktopTheme::loadDesktopTheme() -{ - QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); - m_themeModel->reload(); - QString themeName; - KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("plasmarc")), "Theme"); - themeName = cg.readEntry("name", m_defaultTheme->themeName()); - - m_theme->setCurrentIndex(m_themeModel->indexOf(themeName)); - QApplication::restoreOverrideCursor(); -} - -void KCMDesktopTheme::showFileDialog() -{ - if (!m_dialog) { - m_dialog = new QFileDialog(m_fileInstallButton, i18n("Open Theme"), - QDir::homePath(), - i18n("Theme Files (*.zip *.tar.gz *.tar.bz2)")); - m_dialog->setFileMode(QFileDialog::ExistingFile); - connect(m_dialog, &QDialog::accepted, this, &KCMDesktopTheme::fileBrowserCompleted); - } - - m_dialog->exec(); - m_dialog->raise(); - m_dialog->activateWindow(); -} - -void KCMDesktopTheme::fileBrowserCompleted() -{ - if (m_dialog && m_dialog->selectedFiles().count() > 0) { - foreach (const QString &file, m_dialog->selectedFiles()) { - qCDebug(KCM_DESKTOP_THEME_LOG) << "INSTALL Theme file: " << file; - m_newThemeButton->setEnabled(false); - installTheme(file); - } - } -} - -void KCMDesktopTheme::installTheme(const QString &file) -{ - qCDebug(KCM_DESKTOP_THEME_LOG) << "Installing ... " << file; - - QString program = QStringLiteral("plasmapkg2"); - QStringList arguments; - arguments << QStringLiteral("-t") << QStringLiteral("theme") << QStringLiteral("-i") << file; - - qCDebug(KCM_DESKTOP_THEME_LOG) << program << arguments.join(QStringLiteral(" ")); - QProcess *myProcess = new QProcess(this); - connect(myProcess, static_cast(&QProcess::finished), this, &KCMDesktopTheme::installFinished); - connect(myProcess, static_cast(&QProcess::error), this, &KCMDesktopTheme::installError); - - myProcess->start(program, arguments); -} - -void KCMDesktopTheme::installFinished(int exitCode, QProcess::ExitStatus exitStatus) -{ - Q_UNUSED(exitStatus) - - if (exitCode == 0) { - qCDebug(KCM_DESKTOP_THEME_LOG) << "Theme installed successfully :)"; - m_themeModel->reload(); - - m_messageWidget->setMessageType(KMessageWidget::Positive); - m_messageWidget->setText(i18n("Theme installed successfully.")); - } else { - qCWarning(KCM_DESKTOP_THEME_LOG) << "Theme installation failed."; - m_messageWidget->setMessageType(KMessageWidget::Error); - m_messageWidget->setText(i18n("Theme installation failed. (%1)", exitCode)); - } - - m_messageWidget->animatedShow(); - - m_newThemeButton->setEnabled(true); -} - -void KCMDesktopTheme::installError(QProcess::ProcessError e) -{ - qCWarning(KCM_DESKTOP_THEME_LOG) << "Theme installation failed: " << e; - m_messageWidget->setMessageType(KMessageWidget::Error); - m_messageWidget->setText(i18n("Theme installation failed.")); - m_messageWidget->animatedShow(); - - m_newThemeButton->setEnabled(true); -} - - -#include "kcmdesktoptheme.moc" - -// vim: set noet ts=4: diff --git a/kcms/desktoptheme/package/contents/ui/Hand.qml b/kcms/desktoptheme/package/contents/ui/Hand.qml new file mode 100644 --- /dev/null +++ b/kcms/desktoptheme/package/contents/ui/Hand.qml @@ -0,0 +1,58 @@ +/* + * Copyright 2012 Viranch Mehta + * Copyright 2012 Marco Martin + * Copyright 2013 David Edmundson + * + * 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. + */ + +import QtQuick 2.0 + +import org.kde.plasma.core 2.0 as PlasmaCore + +PlasmaCore.SvgItem { + id: secondHand + + property alias rotation: rotation.angle + property double svgScale + + width: Math.round(naturalSize.width * svgScale) + Math.round(naturalSize.width * svgScale) % 2 + height: Math.round(naturalSize.height * svgScale) + width % 2 + anchors { + top: clock.verticalCenter + topMargin: -width / 2 + horizontalCenter: clock.horizontalCenter + } + svg: clockSvg + smooth: !anim.running + transform: Rotation { + id: rotation + angle: 0 + origin { + x: width / 2 + y: width / 2 + } + Behavior on angle { + RotationAnimation { + id: anim + duration: 200 + direction: RotationAnimation.Clockwise + easing.type: Easing.OutElastic + easing.overshoot: 0.5 + } + } + } +} diff --git a/kcms/desktoptheme/package/contents/ui/ThemePreview.qml b/kcms/desktoptheme/package/contents/ui/ThemePreview.qml new file mode 100644 --- /dev/null +++ b/kcms/desktoptheme/package/contents/ui/ThemePreview.qml @@ -0,0 +1,131 @@ +/* + Copyright (c) 2016 David Rosca + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +import QtQuick 2.4 +import QtQuick.Layouts 1.1 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.components 2.0 as PlasmaComponents + +Item { + id: root + property string themeName + + PlasmaCore.FrameSvgItem { + id: background + anchors.fill: parent + // Air theme have huge transparent margins in widgets/background svg, so use + // widgets/panel-backroung untill Plasma::FrameSvg exposes the transparent margins + imagePath: themeName == "air" ? "widgets/panel-background" : "widgets/background" + } + + RowLayout { + id: contents + anchors { + fill: parent + topMargin: root.height / 8 + bottomMargin: root.height / 8 + leftMargin: root.width / 10 + rightMargin: root.width / 10 + } + + // Icons + ColumnLayout { + id: icons + Layout.fillHeight: true + + PlasmaCore.IconItem { + id: computerIcon + Layout.fillHeight: true + source: "computer" + } + + PlasmaCore.IconItem { + id: applicationsIcon + Layout.fillHeight: true + source: "applications-other" + } + + PlasmaCore.IconItem { + id: logoutIcon + Layout.fillHeight: true + source: "system-log-out" + } + } + + Item { + Layout.fillWidth: true + } + + // Analog clock + Item { + id: clock + Layout.fillHeight: true + Layout.preferredWidth: height + + property int hours: 9 + property int minutes: 5 + + PlasmaCore.Svg { + id: clockSvg + imagePath: "widgets/clock" + } + + PlasmaCore.SvgItem { + id: face + anchors.centerIn: parent + width: Math.min(parent.width, parent.height) + height: Math.min(parent.width, parent.height) + svg: clockSvg + elementId: "ClockFace" + } + + Hand { + elementId: "HourHand" + rotation: 180 + clock.hours * 30 + (clock.minutes/2) + svgScale: face.width / face.naturalSize.width + } + + Hand { + elementId: "MinuteHand" + rotation: 180 + clock.minutes * 6 + svgScale: face.width / face.naturalSize.width + } + + PlasmaCore.SvgItem { + id: center + width: naturalSize.width * face.width / face.naturalSize.width + height: naturalSize.height * face.width / face.naturalSize.width + anchors.centerIn: clock + svg: clockSvg + elementId: "HandCenterScrew" + z: 1000 + } + + PlasmaCore.SvgItem { + anchors.fill: face + svg: clockSvg + elementId: "Glass" + width: naturalSize.width * face.width / face.naturalSize.width + height: naturalSize.height * face.width / face.naturalSize.width + } + } + } + + Component.onCompleted: { + kcm.applyPlasmaTheme(root, themeName); + } +} diff --git a/kcms/desktoptheme/package/contents/ui/main.qml b/kcms/desktoptheme/package/contents/ui/main.qml new file mode 100644 --- /dev/null +++ b/kcms/desktoptheme/package/contents/ui/main.qml @@ -0,0 +1,211 @@ +/* + Copyright (c) 2014 Marco Martin + Copyright (c) 2016 David Rosca + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +import QtQuick 2.1 +import QtQuick.Layouts 1.1 +import QtQuick.Dialogs 1.0 +import QtQuick.Controls.Private 1.0 +import QtQuick.Controls 1.0 as QtControls + +import org.kde.kcm 1.0 +import org.kde.plasma.core 2.0 // for units + +Item { + implicitWidth: units.gridUnit * 20 + implicitHeight: units.gridUnit * 20 + + ConfigModule.quickHelp: i18n("This module lets you configure the desktop theme.") + + SystemPalette { + id: syspal + } + + ColumnLayout { + anchors.fill: parent + QtControls.ScrollView { + Layout.fillWidth: true + Layout.fillHeight: true + verticalScrollBarPolicy: Qt.ScrollBarAlwaysOn + GridView { + id: grid + model: kcm.desktopThemeModel + cellWidth: Math.floor(grid.width / Math.max(Math.floor(grid.width / (units.gridUnit * 12)), 3)) + cellHeight: cellWidth / 1.6 + + delegate: Item { + property bool isLocal : model.isLocal + property string pluginName : model.pluginName + width: grid.cellWidth + height: grid.cellHeight + Rectangle { + anchors { + fill: parent + margins: units.smallSpacing + } + Connections { + target: kcm + onSelectedPluginChanged: { + if (kcm.selectedPlugin == model.pluginName) { + makeCurrentTimer.pendingIndex = index + } + } + } + Component.onCompleted: { + if (kcm.selectedPlugin == model.pluginName) { + makeCurrentTimer.pendingIndex = index + } + } + + Item { + anchors { + fill: parent + margins: units.smallSpacing * 2 + } + ThemePreview { + id: preview + anchors { + top: parent.top + left: parent.left + right: parent.right + bottom: label.top + } + themeName: model.pluginName + } + QtControls.Label { + id: label + anchors { + bottom: parent.bottom + horizontalCenter: parent.horizontalCenter + leftMargin: units.smallSpacing * 2 + rightMargin: units.smallSpacing * 2 + } + height: paintedHeight + width: parent.width + color: "black" + text: model.themeName + elide: Text.ElideRight + horizontalAlignment: Text.AlignHCenter + } + } + + Rectangle { + opacity: grid.currentIndex == index ? 1.0 : 0 + anchors.fill: parent + border.width: units.smallSpacing * 2 + border.color: syspal.highlight + color: "transparent" + Behavior on opacity { + PropertyAnimation { + duration: units.longDuration + easing.type: Easing.OutQuad + } + } + } + MouseArea { + anchors.fill: parent + hoverEnabled: true + onClicked: { + grid.currentIndex = index + kcm.selectedPlugin = model.pluginName + } + Timer { + interval: 1000 + running: parent.containsMouse && !parent.pressedButtons + onTriggered: { + Tooltip.showText(parent, Qt.point(parent.mouseX, parent.mouseY), model.themeName); + } + } + } + } + } + Timer { + id: makeCurrentTimer + interval: 100 + repeat: false + property int pendingIndex + onPendingIndexChanged: makeCurrentTimer.restart() + onTriggered: { + grid.currentIndex = pendingIndex + } + } + } + } + RowLayout { + QtControls.Button { + text: i18n("Get new Theme") + iconName: "get-hot-new-stuff" + onClicked: kcm.getNewThemes() + } + + QtControls.Button { + text: i18n("Install from File") + iconName: "document-import" + onClicked: fileDialog.open() + } + + QtControls.Button { + text: i18n("Remove Theme") + iconName: "edit-delete" + enabled: grid.currentItem && grid.currentItem.isLocal + onClicked: { + kcm.removeTheme(grid.currentItem.pluginName); + updateSelectedPluginTimer.restart(); + } + } + + Item { + Layout.fillWidth: true + } + + QtControls.Label { + id: infoLabel + } + } + } + + Connections { + target: kcm + onShowInfoMessage: { + infoLabel.text = infoMessage; + hideInfoMessageTimer.restart(); + } + } + + Timer { + id: updateSelectedPluginTimer + interval: 100 + onTriggered: kcm.selectedPlugin = grid.currentItem.pluginName + } + + Timer { + id: hideInfoMessageTimer + interval: 20 * 1000 + onTriggered: { + infoLabel.text = "" + } + } + + FileDialog { + id: fileDialog + title: i18n("Open Theme") + folder: shortcuts.home + nameFilters: [ i18n("Theme Files (*.zip *.tar.gz *.tar.bz2)") ] + onAccepted: kcm.installThemeFromFile(fileUrls[0]) + } +} diff --git a/kcms/desktoptheme/package/metadata.desktop b/kcms/desktoptheme/package/metadata.desktop new file mode 100644 --- /dev/null +++ b/kcms/desktoptheme/package/metadata.desktop @@ -0,0 +1,17 @@ +[Desktop Entry] +Name=Desktop Theme +Comment=Desktop Theme +Icon=preferences-desktop-theme +Keywords= +Type=Service +X-KDE-ParentApp= +X-KDE-PluginInfo-Author=David Rosca +X-KDE-PluginInfo-Email=nowrep@gmail.com +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-Name=kcm_desktoptheme +X-KDE-PluginInfo-Version= +X-KDE-PluginInfo-Website= +X-KDE-ServiceTypes=Plasma/Generic +X-Plasma-API=declarativeappletscript + +X-Plasma-MainScript=ui/main.qml diff --git a/kcms/desktoptheme/plasma-themes.knsrc b/kcms/desktoptheme/plasma-themes.knsrc deleted file mode 100644 --- a/kcms/desktoptheme/plasma-themes.knsrc +++ /dev/null @@ -1,6 +0,0 @@ -[KNewStuff3] -ProvidersUrl=http://download.kde.org/ocs/providers.xml -Categories=Plasma Theme -StandardResource=tmp -InstallationCommand=plasmapkg2 -t theme -i %f -UninstallCommand=plasmapkg2 -t theme -r %f diff --git a/kcms/desktoptheme/thememodel.h b/kcms/desktoptheme/thememodel.h deleted file mode 100644 --- a/kcms/desktoptheme/thememodel.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * ThemeModel - * Copyright (C) 2002 Karol Szwed - * Copyright (C) 2002 Daniel Molkentin - * Copyright (C) 2007 Urs Wolfer - * Copyright (C) 2009 by Davide Bettio - - * Portions Copyright (C) 2007 Paolo Capriotti - * Portions Copyright (C) 2007 Ivan Cukic - * Portions Copyright (C) 2008 by Petri Damsten - * Portions Copyright (C) 2000 TrollTech AS. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License version 2 as published by the Free Software Foundation. - * - * 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 - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef THEMEMODEL_H -#define THEMEMODEL_H - -#include - -namespace Plasma -{ - class FrameSvg; -} - -//Theme selector code by Andre Duffeck (modified to add package description) -class ThemeInfo -{ -public: - QString package; - Plasma::FrameSvg *svg; - QString description; - QString author; - QString version; - QString themeRoot; -}; - -class ThemeModel : public QAbstractListModel -{ -public: - enum { PackageNameRole = Qt::UserRole, - SvgRole = Qt::UserRole + 1, - PackageDescriptionRole = Qt::UserRole + 2, - PackageAuthorRole = Qt::UserRole + 3, - PackageVersionRole = Qt::UserRole + 4 - }; - - ThemeModel(QObject *parent = 0); - virtual ~ThemeModel(); - - virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; - virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - QModelIndex indexOf(const QString &path) const; - void reload(); - void clearThemeList(); -private: - QMap m_themes; -}; - -class ThemeDelegate : public QAbstractItemDelegate -{ -public: - ThemeDelegate(QObject * parent = 0); - - virtual void paint(QPainter *painter, - const QStyleOptionViewItem &option, - const QModelIndex &index) const; - virtual QSize sizeHint(const QStyleOptionViewItem &option, - const QModelIndex &index) const; -private: - static const int MARGIN = 10; -}; - - -#endif diff --git a/kcms/desktoptheme/thememodel.cpp b/kcms/desktoptheme/thememodel.cpp deleted file mode 100644 --- a/kcms/desktoptheme/thememodel.cpp +++ /dev/null @@ -1,218 +0,0 @@ -/* - * ThemeModel - * Copyright (C) 2002 Karol Szwed - * Copyright (C) 2002 Daniel Molkentin - * Copyright (C) 2007 Urs Wolfer - * Copyright (C) 2009 by Davide Bettio - - * Portions Copyright (C) 2007 Paolo Capriotti - * Portions Copyright (C) 2007 Ivan Cukic - * Portions Copyright (C) 2008 by Petri Damsten - * Portions Copyright (C) 2000 TrollTech AS. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License version 2 as published by the Free Software Foundation. - * - * 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 - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "thememodel.h" - -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include - -ThemeModel::ThemeModel( QObject *parent ) -: QAbstractListModel( parent ) -{ - reload(); -} - -ThemeModel::~ThemeModel() -{ - clearThemeList(); -} - -void ThemeModel::clearThemeList() -{ - foreach (const ThemeInfo& themeInfo, m_themes) { - delete themeInfo.svg; - } - m_themes.clear(); -} - -void ThemeModel::reload() -{ - beginResetModel(); - clearThemeList(); - - // get all desktop themes - QStringList themes; - const QStringList &packs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("plasma/desktoptheme"), QStandardPaths::LocateDirectory); - foreach (const QString &ppath, packs) { - const QDir cd(ppath); - const QStringList &entries = cd.entryList(QDir::Dirs | QDir::Hidden); - foreach (const QString pack, entries) { - const QString _metadata = ppath+QLatin1Char('/')+pack+QStringLiteral("/metadata.desktop"); - if ((pack != QLatin1String(".") && pack != QLatin1String("..")) && - (QFile::exists(_metadata))) { - themes << _metadata; - } - } - } - - foreach (const QString &theme, themes) { - int themeSepIndex = theme.lastIndexOf('/', -1); - QString themeRoot = theme.left(themeSepIndex); - int themeNameSepIndex = themeRoot.lastIndexOf('/', -1); - QString packageName = themeRoot.right(themeRoot.length() - themeNameSepIndex - 1); - - KDesktopFile df(theme); - - if (df.noDisplay()) { - continue; - } - - QString name = df.readName(); - if (name.isEmpty()) { - name = packageName; - } - const QString comment = df.readComment(); - const QString author = df.desktopGroup().readEntry("X-KDE-PluginInfo-Author",QString()); - const QString version = df.desktopGroup().readEntry("X-KDE-PluginInfo-Version",QString()); - - - Plasma::FrameSvg *svg = new Plasma::FrameSvg(this); - Plasma::Theme *t = new Plasma::Theme(packageName, svg); - svg->setTheme(t); - svg->setImagePath(QStringLiteral("widgets/background")); - - svg->setEnabledBorders(Plasma::FrameSvg::AllBorders); - ThemeInfo info; - info.package = packageName; - info.description = comment; - info.author = author; - info.version = version; - info.svg = svg; - info.themeRoot = themeRoot; - m_themes[name] = info; - } - endResetModel(); -} - -int ThemeModel::rowCount(const QModelIndex &) const -{ - return m_themes.size(); -} - -QVariant ThemeModel::data(const QModelIndex &index, int role) const -{ - if (!index.isValid()) { - return QVariant(); - } - - if (index.row() >= m_themes.size()) { - return QVariant(); - } - - QMap::const_iterator it = m_themes.constBegin(); - for (int i = 0; i < index.row(); ++i) { - ++it; - } - - switch (role) { - case Qt::DisplayRole: - return it.key(); - case PackageNameRole: - return (*it).package; - case SvgRole: - return qVariantFromValue((void*)(*it).svg); - case PackageDescriptionRole: - return (*it).description; - case PackageAuthorRole: - return (*it).author; - case PackageVersionRole: - return (*it).version; - default: - return QVariant(); - } -} - -QModelIndex ThemeModel::indexOf(const QString &name) const -{ - QMapIterator it(m_themes); - int i = -1; - while (it.hasNext()) { - ++i; - if (it.next().value().package == name) { - return index(i, 0); - } - } - - return QModelIndex(); -} - -ThemeDelegate::ThemeDelegate(QObject* parent) -: QAbstractItemDelegate(parent) -{ -} - -void ThemeDelegate::paint(QPainter *painter, - const QStyleOptionViewItem &option, - const QModelIndex &index) const -{ - QString title = index.model()->data(index, Qt::DisplayRole).toString(); - QString package = index.model()->data(index, ThemeModel::PackageNameRole).toString(); - - QStyleOptionViewItemV4 opt(option); - QStyle *style = opt.widget ? opt.widget->style() : QApplication::style(); - style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget); - - // draw image - Plasma::FrameSvg *svg = static_cast( - index.model()->data(index, ThemeModel::SvgRole).value()); - svg->resizeFrame(QSize(option.rect.width() - (2 * MARGIN), 100 - (2 * MARGIN))); - QRect imgRect = QRect(option.rect.topLeft(), - QSize(option.rect.width() - (2 * MARGIN), 100 - (2 * MARGIN))) - .translated(MARGIN, MARGIN); - svg->paintFrame(painter, QPoint(option.rect.left() + MARGIN, option.rect.top() + MARGIN)); - - // draw text - painter->save(); - QFont font = painter->font(); - //font.setWeight(QFont::Bold); - const QString colorFile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "plasma/desktoptheme/" + package + "/colors"); - if (!colorFile.isEmpty()) { - KSharedConfigPtr colors = KSharedConfig::openConfig(colorFile); - KColorScheme colorScheme(QPalette::Active, KColorScheme::Window, colors); - painter->setPen(colorScheme.foreground(KColorScheme::NormalText).color()); - } - painter->setFont(font); - painter->drawText(option.rect, Qt::AlignCenter | Qt::TextWordWrap, title); - painter->restore(); -} - -QSize ThemeDelegate::sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const -{ - return QSize(152, 100); -} - -