|
|
@ -17,11 +17,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#include "control.h"
|
|
|
|
#include "control.h"
|
|
|
|
#include "globals.h"
|
|
|
|
#include "globals.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include <QStringBuilder>
|
|
|
|
#include <KDirWatch>
|
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QFileSystemWatcher>
|
|
|
|
|
|
|
|
#include <QJsonDocument>
|
|
|
|
#include <QJsonDocument>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QStringBuilder>
|
|
|
|
|
|
|
|
|
|
|
|
#include <kscreen/config.h>
|
|
|
|
#include <kscreen/config.h>
|
|
|
|
#include <kscreen/output.h>
|
|
|
|
#include <kscreen/output.h>
|
|
|
@ -38,14 +38,15 @@ void Control::activateWatcher()
|
|
|
|
if (m_watcher) {
|
|
|
|
if (m_watcher) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_watcher = new QFileSystemWatcher({filePath()}, this);
|
|
|
|
m_watcher = new KDirWatch(this);
|
|
|
|
connect(m_watcher, &QFileSystemWatcher::fileChanged, this, [this]() {
|
|
|
|
m_watcher->addFile(filePath());
|
|
|
|
|
|
|
|
connect(m_watcher, &KDirWatch::dirty, this, [this]() {
|
|
|
|
readFile();
|
|
|
|
readFile();
|
|
|
|
Q_EMIT changed();
|
|
|
|
Q_EMIT changed();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QFileSystemWatcher* Control::watcher() const
|
|
|
|
KDirWatch *Control::watcher() const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return m_watcher;
|
|
|
|
return m_watcher;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -61,19 +62,15 @@ bool Control::writeFile()
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!QDir().mkpath(dirPath())) {
|
|
|
|
if (!QDir().mkpath(dirPath())) {
|
|
|
|
// TODO: error message
|
|
|
|
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// write updated data to file
|
|
|
|
// write updated data to file
|
|
|
|
QFile file(path);
|
|
|
|
QFile file(path);
|
|
|
|
if (!file.open(QIODevice::WriteOnly)) {
|
|
|
|
if (!file.open(QIODevice::WriteOnly)) {
|
|
|
|
// TODO: logging category?
|
|
|
|
|
|
|
|
// qCWarning(KSCREEN_COMMON) << "Failed to open config control file for writing! " << file.errorString();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
file.write(QJsonDocument::fromVariant(infoMap).toJson());
|
|
|
|
file.write(QJsonDocument::fromVariant(infoMap).toJson());
|
|
|
|
// qCDebug(KSCREEN_COMMON) << "Control saved on: " << file.fileName();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -98,12 +95,12 @@ QString Control::filePathFromHash(const QString &hash) const
|
|
|
|
return dirPath() % hash;
|
|
|
|
return dirPath() % hash;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QVariantMap& Control::info()
|
|
|
|
QVariantMap &Control::info()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return m_info;
|
|
|
|
return m_info;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const QVariantMap& Control::constInfo() const
|
|
|
|
const QVariantMap &Control::constInfo() const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return m_info;
|
|
|
|
return m_info;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -126,7 +123,7 @@ ControlConfig::ControlConfig(KScreen::ConfigPtr config, QObject *parent)
|
|
|
|
: Control(parent)
|
|
|
|
: Control(parent)
|
|
|
|
, m_config(config)
|
|
|
|
, m_config(config)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// qDebug() << "Looking for control file:" << config->connectedOutputsHash();
|
|
|
|
// qDebug() << "Looking for control file:" << config->connectedOutputsHash();
|
|
|
|
readFile();
|
|
|
|
readFile();
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: use a file watcher in case of changes to the control file while
|
|
|
|
// TODO: use a file watcher in case of changes to the control file while
|
|
|
@ -184,8 +181,7 @@ bool ControlConfig::writeFile()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bool success = true;
|
|
|
|
bool success = true;
|
|
|
|
for (auto *outputControl : m_outputsControls) {
|
|
|
|
for (auto *outputControl : m_outputsControls) {
|
|
|
|
if (getOutputRetention(outputControl->id(), outputControl->name())
|
|
|
|
if (getOutputRetention(outputControl->id(), outputControl->name()) == OutputRetention::Individual) {
|
|
|
|
== OutputRetention::Individual) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
success &= outputControl->writeFile();
|
|
|
|
success &= outputControl->writeFile();
|
|
|
@ -304,7 +300,7 @@ qreal ControlConfig::getScale(const QString &outputId, const QString &outputName
|
|
|
|
|
|
|
|
|
|
|
|
// Info for output not found.
|
|
|
|
// Info for output not found.
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ControlConfig::setScale(const KScreen::OutputPtr &output, qreal value)
|
|
|
|
void ControlConfig::setScale(const KScreen::OutputPtr &output, qreal value)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -321,7 +317,6 @@ void ControlConfig::setScale(const QString &outputId, const QString &outputName,
|
|
|
|
if (auto *control = getOutputControl(outputId, outputName)) {
|
|
|
|
if (auto *control = getOutputControl(outputId, outputName)) {
|
|
|
|
control->setScale(value);
|
|
|
|
control->setScale(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
for (it = outputsInfo.begin(); it != outputsInfo.end(); ++it) {
|
|
|
|
for (it = outputsInfo.begin(); it != outputsInfo.end(); ++it) {
|
|
|
@ -387,7 +382,6 @@ void ControlConfig::setAutoRotate(const QString &outputId, const QString &output
|
|
|
|
if (auto *control = getOutputControl(outputId, outputName)) {
|
|
|
|
if (auto *control = getOutputControl(outputId, outputName)) {
|
|
|
|
control->setAutoRotate(value);
|
|
|
|
control->setAutoRotate(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
for (it = outputsInfo.begin(); it != outputsInfo.end(); ++it) {
|
|
|
|
for (it = outputsInfo.begin(); it != outputsInfo.end(); ++it) {
|
|
|
@ -415,8 +409,7 @@ bool ControlConfig::getAutoRotateOnlyInTabletMode(const KScreen::OutputPtr &outp
|
|
|
|
return getAutoRotateOnlyInTabletMode(output->hashMd5(), output->name());
|
|
|
|
return getAutoRotateOnlyInTabletMode(output->hashMd5(), output->name());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ControlConfig::getAutoRotateOnlyInTabletMode(const QString &outputId,
|
|
|
|
bool ControlConfig::getAutoRotateOnlyInTabletMode(const QString &outputId, const QString &outputName) const
|
|
|
|
const QString &outputName) const
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const auto retention = getOutputRetention(outputId, outputName);
|
|
|
|
const auto retention = getOutputRetention(outputId, outputName);
|
|
|
|
if (retention == OutputRetention::Individual) {
|
|
|
|
if (retention == OutputRetention::Individual) {
|
|
|
@ -445,8 +438,7 @@ void ControlConfig::setAutoRotateOnlyInTabletMode(const KScreen::OutputPtr &outp
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: combine methods (templated functions)
|
|
|
|
// TODO: combine methods (templated functions)
|
|
|
|
void ControlConfig::setAutoRotateOnlyInTabletMode(const QString &outputId,
|
|
|
|
void ControlConfig::setAutoRotateOnlyInTabletMode(const QString &outputId, const QString &outputName, bool value)
|
|
|
|
const QString &outputName, bool value)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QList<QVariant>::iterator it;
|
|
|
|
QList<QVariant>::iterator it;
|
|
|
|
QVariantList outputsInfo = getOutputs();
|
|
|
|
QVariantList outputsInfo = getOutputs();
|
|
|
@ -477,14 +469,12 @@ void ControlConfig::setAutoRotateOnlyInTabletMode(const QString &outputId,
|
|
|
|
setOutputAutoRotateOnlyInTabletMode();
|
|
|
|
setOutputAutoRotateOnlyInTabletMode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
KScreen::OutputPtr ControlConfig::getReplicationSource(const KScreen::OutputPtr &output) const
|
|
|
|
KScreen::OutputPtr ControlConfig::getReplicationSource(const KScreen::OutputPtr &output) const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return getReplicationSource(output->hashMd5(), output->name());
|
|
|
|
return getReplicationSource(output->hashMd5(), output->name());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
KScreen::OutputPtr ControlConfig::getReplicationSource(const QString &outputId,
|
|
|
|
KScreen::OutputPtr ControlConfig::getReplicationSource(const QString &outputId, const QString &outputName) const
|
|
|
|
const QString &outputName) const
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const QVariantList outputsInfo = getOutputs();
|
|
|
|
const QVariantList outputsInfo = getOutputs();
|
|
|
|
for (const auto &variantInfo : outputsInfo) {
|
|
|
|
for (const auto &variantInfo : outputsInfo) {
|
|
|
@ -512,14 +502,12 @@ KScreen::OutputPtr ControlConfig::getReplicationSource(const QString &outputId,
|
|
|
|
return nullptr;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ControlConfig::setReplicationSource(const KScreen::OutputPtr &output,
|
|
|
|
void ControlConfig::setReplicationSource(const KScreen::OutputPtr &output, const KScreen::OutputPtr &source)
|
|
|
|
const KScreen::OutputPtr &source)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
setReplicationSource(output->hashMd5(), output->name(), source);
|
|
|
|
setReplicationSource(output->hashMd5(), output->name(), source);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ControlConfig::setReplicationSource(const QString &outputId, const QString &outputName,
|
|
|
|
void ControlConfig::setReplicationSource(const QString &outputId, const QString &outputName, const KScreen::OutputPtr &source)
|
|
|
|
const KScreen::OutputPtr &source)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QList<QVariant>::iterator it;
|
|
|
|
QList<QVariant>::iterator it;
|
|
|
|
QVariantList outputsInfo = getOutputs();
|
|
|
|
QVariantList outputsInfo = getOutputs();
|
|
|
@ -558,8 +546,7 @@ void ControlConfig::setOutputs(QVariantList outputsInfo)
|
|
|
|
auto &infoMap = info();
|
|
|
|
auto &infoMap = info();
|
|
|
|
infoMap[QStringLiteral("outputs")] = outputsInfo;
|
|
|
|
infoMap[QStringLiteral("outputs")] = outputsInfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ControlOutput* ControlConfig::getOutputControl(const QString &outputId,
|
|
|
|
ControlOutput *ControlConfig::getOutputControl(const QString &outputId, const QString &outputName) const
|
|
|
|
const QString &outputName) const
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for (auto *control : m_outputsControls) {
|
|
|
|
for (auto *control : m_outputsControls) {
|
|
|
|
if (control->id() == outputId && control->name() == outputName) {
|
|
|
|
if (control->id() == outputId && control->name() == outputName) {
|
|
|
|