[kcmkwin/deco] Bring back KNewStuff support

KNewStuff is no longer hard-coded to Aurorae themes. Instead the
availability of KNewStuff is derived from the available plugin
metadata. If the section org.kde.kdecoration2 contains a key
"KNewStuff" it's value is interpreted as the knsrc config file name.
If there is at least one plugin with such a key KNS gets enabled.

If there are multiple plugins providing KNS support the download
button is turned into a button with a connected menu and each menu
entry points to one of the available resources. Of course this is
not optimal, but KNS doesn't allow the combining of multiple config
files.
This commit is contained in:
Martin Gräßlin 2014-12-05 10:15:41 +01:00
parent f8d1a0868a
commit 2034e7e875
6 changed files with 101 additions and 9 deletions

View file

@ -10,6 +10,7 @@
"blur": true,
"themes": true,
"defaultTheme": "kwin4_decoration_qml_plastik",
"themeListKeyword": "themes"
"themeListKeyword": "themes",
"KNewStuff": "aurorae.knsrc"
}
}

View file

@ -97,9 +97,19 @@ static QString themeListKeyword(const QVariantMap &decoSettingsMap)
return it.value().toString();
}
static QString findKNewStuff(const QVariantMap &decoSettingsMap)
{
auto it = decoSettingsMap.find(QStringLiteral("KNewStuff"));
if (it == decoSettingsMap.end()) {
return QString();
}
return it.value().toString();
}
void DecorationsModel::init()
{
beginResetModel();
m_plugins.clear();
const auto plugins = KPluginTrader::self()->query(s_pluginName, s_pluginName);
for (const auto &info : plugins) {
KPluginLoader loader(info.libraryPath());
@ -110,6 +120,10 @@ void DecorationsModel::init()
auto metadata = loader.metaData().value(QStringLiteral("MetaData")).toObject().value(s_pluginName);
if (!metadata.isUndefined()) {
const auto decoSettingsMap = metadata.toObject().toVariantMap();
const QString &kns = findKNewStuff(decoSettingsMap);
if (!kns.isEmpty()) {
m_knsProvides.insert(kns, info.name().isEmpty() ? info.pluginName() : info.name());
}
if (isThemeEngine(decoSettingsMap)) {
const QString keyword = themeListKeyword(decoSettingsMap);
if (keyword.isNull()) {

View file

@ -41,6 +41,10 @@ public:
QModelIndex findDecoration(const QString &pluginName, const QString &themeName = QString()) const;
QMap<QString, QString> knsProviders() const {
return m_knsProvides;
}
public Q_SLOTS:
void init();
@ -51,6 +55,7 @@ private:
QString visibleName;
};
std::vector<Data> m_plugins;
QMap<QString, QString> m_knsProvides;
};
}

View file

@ -25,9 +25,11 @@
#include <KPluginFactory>
#include <KSharedConfig>
#include <KDecoration2/DecorationButton>
#include <KNewStuff3/KNS3/DownloadDialog>
// Qt
#include <QDBusConnection>
#include <QDBusMessage>
#include <QMenu>
#include <QQmlContext>
#include <QQmlEngine>
#include <QQuickItem>
@ -49,6 +51,7 @@ namespace Configuration
static const QString s_pluginName = QStringLiteral("org.kde.kdecoration2");
static const QString s_defaultPlugin = QStringLiteral("org.kde.breeze");
static const QString s_borderSizeNormal = QStringLiteral("Normal");
static const QString s_ghnsIcon = QStringLiteral("get-hot-new-stuff");
ConfigurationForm::ConfigurationForm(QWidget *parent)
: QWidget(parent)
@ -91,6 +94,7 @@ ConfigurationModule::ConfigurationModule(QWidget *parent, const QVariantList &ar
m_ui->borderSizesCombo->setItemData(6, QVariant::fromValue(BorderSize::Huge));
m_ui->borderSizesCombo->setItemData(7, QVariant::fromValue(BorderSize::VeryHuge));
m_ui->borderSizesCombo->setItemData(8, QVariant::fromValue(BorderSize::Oversized));
m_ui->knsButton->setIcon(QIcon::fromTheme(s_ghnsIcon));
connect(m_ui->closeWindowsDoubleClick, &QCheckBox::stateChanged, this,
static_cast<void (ConfigurationModule::*)()>(&ConfigurationModule::changed));
@ -111,6 +115,33 @@ ConfigurationModule::ConfigurationModule(QWidget *parent, const QVariantList &ar
changed();
}
);
connect(m_model, &QAbstractItemModel::modelReset, this,
[this] {
const auto &kns = m_model->knsProviders();
m_ui->knsButton->setEnabled(!kns.isEmpty());
if (kns.isEmpty()) {
return;
}
if (kns.count() > 1) {
QMenu *menu = new QMenu(m_ui->knsButton);
for (auto it = kns.begin(); it != kns.end(); ++it) {
QAction *action = menu->addAction(QIcon::fromTheme(s_ghnsIcon), it.value());
action->setData(it.key());
connect(action, &QAction::triggered, this, [this, action] { showKNS(action->data().toString());});
}
m_ui->knsButton->setMenu(menu);
}
}
);
connect(m_ui->knsButton, &QPushButton::clicked, this,
[this] {
const auto &kns = m_model->knsProviders();
if (kns.isEmpty()) {
return;
}
showKNS(kns.firstKey());
}
);
QVBoxLayout *l = new QVBoxLayout(this);
l->addWidget(m_ui);
@ -208,6 +239,32 @@ void ConfigurationModule::defaults()
KCModule::defaults();
}
void ConfigurationModule::showKNS(const QString &config)
{
QPointer<KNS3::DownloadDialog> downloadDialog = new KNS3::DownloadDialog(config, this);
if (downloadDialog->exec() == QDialog::Accepted && !downloadDialog->changedEntries().isEmpty()) {
auto listView = m_ui->view->rootObject()->findChild<QQuickItem*>("listView");
QString selectedPluginName;
QString selectedThemeName;
if (listView) {
const QModelIndex index = m_proxyModel->index(listView->property("currentIndex").toInt(), 0);
if (index.isValid()) {
selectedPluginName = index.data(Qt::UserRole + 4).toString();
selectedThemeName = index.data(Qt::UserRole + 5).toString();
}
}
m_model->init();
if (!selectedPluginName.isEmpty()) {
const QModelIndex index = m_model->findDecoration(selectedPluginName, selectedThemeName);
const QModelIndex proxyIndex = m_proxyModel->mapFromSource(index);
if (listView) {
listView->setProperty("currentIndex", proxyIndex.isValid() ? proxyIndex.row() : -1);
}
}
}
delete downloadDialog;
}
}
}

View file

@ -57,6 +57,7 @@ protected:
void showEvent(QShowEvent *ev) override;
private:
void showKNS(const QString &config);
DecorationsModel *m_model;
QSortFilterProxyModel *m_proxyModel;
ConfigurationForm *m_ui;

View file

@ -18,14 +18,28 @@
<widget class="KMessageWidget" name="doubleClickMessage"/>
</item>
<item>
<widget class="QLineEdit" name="filter">
<property name="placeholderText">
<string>Search</string>
</property>
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="filter">
<property name="placeholderText">
<string>Search</string>
</property>
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="knsButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Get New Decorations...</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QQuickWidget" name="view">