diff --git a/kcm/src/profilesmodel.h b/kcm/src/profilesmodel.h deleted file mode 100644 --- a/kcm/src/profilesmodel.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 2013 Daniel Vrátil - * - * 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 - -#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 mProfilesCache; -}; - -#endif // PROFILESMODEL_H diff --git a/kcm/src/profilesmodel.cpp b/kcm/src/profilesmodel.cpp deleted file mode 100644 --- a/kcm/src/profilesmodel.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (C) 2013 Daniel Vrátil - * - * 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 -#include -#include -#include - -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 profiles = mInterface->listCurrentProfiles(); - - clear(); - mProfilesCache.clear(); - - QMapIterator 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(); - arg >> outputs; - - for (int i = 0; i < outputs.count(); i++) { - QDBusArgument arg = outputs.at(i).value(); - QVariantMap output; - arg >> output; - - QVariantMap metadata; - arg = output[QLatin1String("metadata")].value(); - arg >> metadata; - output[QLatin1String("metadata")] = metadata; - - QVariantMap pos; - arg = output[QLatin1String("pos")].value(); - arg >> pos; - output[QLatin1String("pos")] = pos; - - if (output.contains(QLatin1String("mode"))) { - QVariantMap mode; - arg = output[QLatin1String("mode")].value(); - arg >> mode; - - QVariantMap size; - arg = mode[QLatin1String("size")].value(); - arg >> size; - mode[QLatin1String("size")] = size; - output[QLatin1String("mode")] = mode; - } - - outputs.replace(i, output); - } - - return outputs; -} diff --git a/kcm/src/widget.h b/kcm/src/widget.h --- a/kcm/src/widget.h +++ b/kcm/src/widget.h @@ -25,7 +25,6 @@ #include -class ProfilesModel; class QLabel; class QMLOutput; class QMLScreen; @@ -72,10 +71,6 @@ 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 @@ ControlPanel *mControlPanel = nullptr; - ProfilesModel *mProfilesModel = nullptr; - QComboBox *mProfilesCombo = nullptr; - QPushButton *mSaveProfileButton = nullptr; - QList mOutputIdentifiers; QTimer *mOutputTimer = nullptr; }; diff --git a/kcm/src/widget.cpp b/kcm/src/widget.cpp --- a/kcm/src/widget.cpp +++ b/kcm/src/widget.cpp @@ -19,9 +19,6 @@ #include "widget.h" #include "controlpanel.h" -#ifdef WITH_PROFILES -#include "profilesmodel.h" -#endif #include #include @@ -64,18 +61,6 @@ connect(ui->primaryCombo, QOverload::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 @@ 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 @@ 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();