Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 4be57b20 authored by Roman Gilg's avatar Roman Gilg

Add output and connected outputs config API

Summary:
In order to support writing and retrieving config data by API consumers
introduce two API exposed functions for calculating hash values of
individual outputs and configs dependent on the currently connected
outputs.

This allows to move the similar code path out of kscreen.

Test Plan: Compiles.

Reviewers: #plasma, davidedmundson

Reviewed By: #plasma, davidedmundson

Subscribers: apol, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D16843
parent d1c1ad87
......@@ -25,6 +25,8 @@
#include <QDebug>
#include <QRect>
#include <QStringList>
#include <QCryptographicHash>
using namespace KScreen;
......@@ -219,6 +221,19 @@ ConfigPtr Config::clone() const
return newConfig;
}
QString Config::connectedOutputsHash() const
{
QStringList hashedOutputs;
const auto outputs = connectedOutputs();
for (const OutputPtr &output : outputs) {
hashedOutputs << output->hash();
}
std::sort(hashedOutputs.begin(), hashedOutputs.end());
const auto hash = QCryptographicHash::hash(hashedOutputs.join(QString()).toLatin1(),
QCryptographicHash::Md5);
return QString::fromLatin1(hash.toHex());
}
ScreenPtr Config::screen() const
{
......
......@@ -115,6 +115,18 @@ class KSCREEN_EXPORT Config : public QObject
*/
ConfigPtr clone() const;
/**
* Returns an identifying hash for this config in regards to its
* connected outputs.
*
* The hash is calculated with a sorted combination of all
* connected output hashes.
*
* @return sorted hash combination of all connected outputs
* @since 5.15
*/
QString connectedOutputsHash() const;
ScreenPtr screen() const;
void setScreen(const ScreenPtr &screen);
......
......@@ -210,6 +210,14 @@ void Output::setName(const QString& name)
Q_EMIT outputChanged();
}
QString Output::hash() const
{
if (edid() && edid()->isValid()) {
return edid()->hash();
}
return name();
}
Output::Type Output::type() const
{
return d->type;
......
......@@ -98,6 +98,17 @@ class KSCREEN_EXPORT Output : public QObject
QString name() const;
void setName(const QString& name);
/**
* Returns an identifying hash for this output.
*
* The hash is calculated either via the edid hash or if no
* edid is available by the output name.
*
* @return identifying hash of this output
* @since 5.15
*/
QString hash() const;
Type type() const;
void setType(Type type);
......
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