Commit 7283fb56 authored by Roman Gilg's avatar Roman Gilg

[kcm] Remove profiles code

Summary:
This code seems to be unused for a long time or was never used at all.
Introduced in 2013 there were no substantial commits to it afterwards,
nor is the functionality exposed to the Ui.

Test Plan: Compiles.

Reviewers: #plasma, apol, davidedmundson

Reviewed By: #plasma, apol, davidedmundson

Subscribers: davidedmundson, afiestas, apol, dvratil, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D16898
parent a98fa6fc
/*
* Copyright (C) 2013 Daniel Vrátil <dvratil@redhat.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 "profilesmodel.h"
#include <QTimer>
#include <QDBusConnection>
#include <QDBusMetaType>
#include <QDBusReply>
ProfilesModel::ProfilesModel(QObject *parent):
QStandardItemModel(parent)
{
mInterface = new org::kde::KScreen(QLatin1String("org.kde.KScreen"),
QLatin1String("/modules/kscreen"),
QDBusConnection::sessionBus(),
this);
connect(mInterface, SIGNAL(profilesChanged()),
this, SLOT(reloadProfiles()));
QTimer::singleShot(0, this, SLOT(reloadProfiles()));
}
ProfilesModel::~ProfilesModel()
{
}
void ProfilesModel::reloadProfiles()
{
Q_EMIT aboutToUpdateModel();
const QMap<QString,QString> profiles = mInterface->listCurrentProfiles();
clear();
mProfilesCache.clear();
QMapIterator<QString, QString> iter(profiles);
while (iter.hasNext()) {
iter.next();
QStandardItem *item = new QStandardItem(iter.value());
item->setData(iter.key(), ProfileIDRole);
appendRow(item);
}
Q_EMIT modelUpdated();
}
QVariant ProfilesModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid()) {
return QVariant();
}
if (role == ProfileRole) {
const QString profileId = QStandardItemModel::data(index, ProfileIDRole).toString();
if (!mProfilesCache.contains(profileId)) {
QVariantMap profile = mInterface->getProfile(profileId);
profile["outputs"] = parseOutputs(profile[QLatin1String("outputs")]);
mProfilesCache.insert(profileId, profile);
return profile;
}
return mProfilesCache.value(profileId);
}
return QStandardItemModel::data(index, role);
}
int ProfilesModel::activeProfileIndex() const
{
const QString activeProfile = mInterface->activeProfile();
for (int i = 0; i < rowCount(); i++) {
const QModelIndex rowIndex = index(i, 0);
if (activeProfile.isEmpty()) {
const QVariantMap map = data(rowIndex, ProfileRole).toMap();
if (map[QLatin1String("preferred")].toBool()) {
return i;
}
} else {
if (data(rowIndex, ProfileIDRole).toString() == activeProfile) {
return i;
}
}
}
return -1;
}
// FIXME: Yeah, if someone could explain me why this cannot happen
// automatically, that would be great.
QVariant ProfilesModel::parseOutputs(const QVariant &variant) const
{
QVariantList outputs;
QDBusArgument arg = variant.value<QDBusArgument>();
arg >> outputs;
for (int i = 0; i < outputs.count(); i++) {
QDBusArgument arg = outputs.at(i).value<QDBusArgument>();
QVariantMap output;
arg >> output;
QVariantMap metadata;
arg = output[QLatin1String("metadata")].value<QDBusArgument>();
arg >> metadata;
output[QLatin1String("metadata")] = metadata;
QVariantMap pos;
arg = output[QLatin1String("pos")].value<QDBusArgument>();
arg >> pos;
output[QLatin1String("pos")] = pos;
if (output.contains(QLatin1String("mode"))) {
QVariantMap mode;
arg = output[QLatin1String("mode")].value<QDBusArgument>();
arg >> mode;
QVariantMap size;
arg = mode[QLatin1String("size")].value<QDBusArgument>();
arg >> size;
mode[QLatin1String("size")] = size;
output[QLatin1String("mode")] = mode;
}
outputs.replace(i, output);
}
return outputs;
}
/*
* Copyright (C) 2013 Daniel Vrátil <dvratil@redhat.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 PROFILESMODEL_H
#define PROFILESMODEL_H
#include <QStandardItemModel>
#include "kscreeninterface.h"
class ProfilesModel : public QStandardItemModel
{
Q_OBJECT
public:
enum {
ProfileIDRole = Qt::UserRole + 1,
ProfileRole
};
explicit ProfilesModel(QObject *parent = 0);
virtual ~ProfilesModel();
int activeProfileIndex() const;
int profileIndex(const QString &profileId);
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
public Q_SLOTS:
void reloadProfiles();
Q_SIGNALS:
void aboutToUpdateModel();
void modelUpdated();
private:
QVariant parseOutputs(const QVariant &variant) const;
org::kde::KScreen *mInterface;
mutable QMap<QString, QVariant> mProfilesCache;
};
#endif // PROFILESMODEL_H
......@@ -19,9 +19,6 @@
#include "widget.h"
#include "controlpanel.h"
#ifdef WITH_PROFILES
#include "profilesmodel.h"
#endif
#include <QVBoxLayout>
#include <QSplitter>
......@@ -64,18 +61,6 @@ Widget::Widget(QWidget *parent)
connect(ui->primaryCombo, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &Widget::primaryOutputSelected);
#ifdef WITH_PROFILES
mProfilesModel = new ProfilesModel(this);
connect(mProfilesModel, &ProfilesModel::modelUpdated()),
this, &Widget::slotProfilesUpdated);
mProfilesCombo = new QComboBox(this);
mProfilesCombo->setModel(mProfilesModel);
mProfilesCombo->setSizeAdjustPolicy(QComboBox::AdjustToContents);
hbox->addWidget(new QLabel(i18n("Active profile")));
hbox->addWidget(mProfilesCombo);
#endif
mControlPanel = new ControlPanel(this);
connect(mControlPanel, &ControlPanel::changed,
this, &Widget::changed);
......@@ -323,40 +308,6 @@ void Widget::slotUnifyOutputs()
Q_EMIT changed();
}
void Widget::slotProfileChanged(int index)
{
#ifdef WITH_PROFILES
const QVariantMap profile = mProfilesCombo->itemData(index, ProfilesModel::ProfileRole).toMap();
const QVariantList outputs = profile[QLatin1String("outputs")].toList();
// FIXME: Copy-pasted from KDED's Serializer::config()
KScreen::Config *config = KScreen::Config::current();
KScreen::OutputList outputList = config->outputs();
for (KScreen::Output: output, outputList) {
if (!output->isConnected() && output->isEnabled()) {
output->setEnabled(false);
}
}
KScreen::Config *outputsConfig = config->clone();
Q_FOREACH(const QVariant & info, outputs) {
KScreen::Output *output = findOutput(outputsConfig, info.toMap());
if (!output) {
continue;
}
delete outputList.take(output->id());
outputList.insert(output->id(), output);
}
config->setOutputs(outputList);
setConfig(config);
#else
Q_UNUSED(index)
#endif
}
// FIXME: Copy-pasted from KDED's Serializer::findOutput()
KScreen::OutputPtr Widget::findOutput(const KScreen::ConfigPtr &config, const QVariantMap &info)
{
......@@ -400,26 +351,6 @@ KScreen::OutputPtr Widget::findOutput(const KScreen::ConfigPtr &config, const QV
return KScreen::OutputPtr();
}
void Widget::slotProfilesAboutToUpdate()
{
#ifdef WITH_PROFILES
disconnect(mProfilesCombo, &QComboBox::currentIndexChanged,
this, &Widget::slotProfileChanged);
#endif
}
void Widget::slotProfilesUpdated()
{
#ifdef WITH_PROFILES
connect(mProfilesCombo, &QComboBox::currentIndexChanged,
this, &Widget::slotProfileChanged);
const int index = mProfilesModel->activeProfileIndex();
mProfilesCombo->setCurrentIndex(index);
#endif
}
void Widget::clearOutputIdentifiers()
{
mOutputTimer->stop();
......
......@@ -25,7 +25,6 @@
#include <kscreen/config.h>
class ProfilesModel;
class QLabel;
class QMLOutput;
class QMLScreen;
......@@ -72,10 +71,6 @@ class Widget : public QWidget
void slotOutputConnectedChanged();
void slotUnifyOutputs();
void slotProfileChanged(int index);
void slotProfilesAboutToUpdate();
void slotProfilesUpdated();
void slotIdentifyButtonClicked(bool checked = true);
void slotIdentifyOutputs(KScreen::ConfigOperation *op);
......@@ -101,10 +96,6 @@ class Widget : public QWidget
ControlPanel *mControlPanel = nullptr;
ProfilesModel *mProfilesModel = nullptr;
QComboBox *mProfilesCombo = nullptr;
QPushButton *mSaveProfileButton = nullptr;
QList<QQuickView*> mOutputIdentifiers;
QTimer *mOutputTimer = nullptr;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment