Commit 553a13cd authored by Sebastian Kügler's avatar Sebastian Kügler Committed by Daniel Vrátil
Browse files

Addressing Kai's review, part 1

parent db206472
......@@ -242,8 +242,6 @@ void KScreenDaemon::showOsd(const QString &icon, const QString &text)
);
msg << icon << text;
QDBusConnection::sessionBus().asyncCall(msg);
}
void KScreenDaemon::showOutputIdentifier()
......@@ -283,15 +281,15 @@ void KScreenDaemon::applyGenericConfig()
m_iteration = Generator::DisplaySwitchAction(static_cast<int>(m_iteration) + 1);
qCDebug(KSCREEN_KDED) << "displayButton: " << m_iteration;
QHash<Generator::DisplaySwitchAction, QString> actionMessages({
static QHash<Generator::DisplaySwitchAction, QString> actionMessages({
{Generator::DisplaySwitchAction::None, i18nc("osd when displaybutton is pressed", "No Action")},
{Generator::DisplaySwitchAction::Clone, i18nc("osd when displaybutton is pressed", "Cloned Display")},
{Generator::DisplaySwitchAction::ExtendToLeft, i18nc("osd when displaybutton is pressed", "Extend Left")},
{Generator::DisplaySwitchAction::TurnOffEmbedded, i18nc("osd when displaybutton is pressed", "Embedded Off")},
{Generator::DisplaySwitchAction::TurnOffExternal, i18nc("osd when displaybutton is pressed", "External Off")},
{Generator::DisplaySwitchAction::TurnOffEmbedded, i18nc("osd when displaybutton is pressed", "External Only")},
{Generator::DisplaySwitchAction::TurnOffExternal, i18nc("osd when displaybutton is pressed", "Internal Only")},
{Generator::DisplaySwitchAction::ExtendToRight, i18nc("osd when displaybutton is pressed", "Extended Right")}
});
QString message = actionMessages.value(m_iteration);
const QString &message = actionMessages.value(m_iteration);
// We delay the OSD for two seconds and hope that X and hardware are done setting everything up.
QTimer::singleShot(2000,
......
......@@ -29,32 +29,30 @@
#include <KDeclarative/QmlObject>
namespace KScreen {
using namespace KScreen;
Osd::Osd(const KScreen::OutputPtr output, QObject *parent)
: QObject(parent)
, m_output(output)
, m_osdPath(QStandardPaths::locate(QStandardPaths::QStandardPaths::GenericDataLocation, QStringLiteral("kded_kscreen/qml/Osd.qml")))
, m_osdObject(new KDeclarative::QmlObject(this))
{
if (m_osdPath.isEmpty()) {
qCWarning(KSCREEN_KDED) << "Failed to find OSD QML file" << m_osdPath;
const QString &osdPath = QStandardPaths::locate(QStandardPaths::QStandardPaths::GenericDataLocation, QStringLiteral("kded_kscreen/qml/Osd.qml"));
if (osdPath.isEmpty()) {
qCWarning(KSCREEN_KDED) << "Failed to find OSD QML file" << osdPath;
}
m_osdObject->setSource(QUrl::fromLocalFile(m_osdPath));
m_osdObject->setSource(QUrl::fromLocalFile(osdPath));
if (m_osdObject->status() != QQmlComponent::Ready) {
qCWarning(KSCREEN_KDED) << "Failed to load OSD QML file" << m_osdPath;
qCWarning(KSCREEN_KDED) << "Failed to load OSD QML file" << osdPath;
return;
}
m_timeout = m_osdObject->rootObject()->property("timeout").toInt();
if (!m_osdTimer) {
m_osdTimer = new QTimer(this);
m_osdTimer->setSingleShot(true);
connect(m_osdTimer, &QTimer::timeout, this, &Osd::hideOsd);
}
m_osdTimer = new QTimer(this);
m_osdTimer->setSingleShot(true);
connect(m_osdTimer, &QTimer::timeout, this, &Osd::hideOsd);
}
Osd::~Osd()
......@@ -78,11 +76,9 @@ void Osd::showOutputIdentifier(const KScreen::OutputPtr output)
auto *rootObject = m_osdObject->rootObject();
auto mode = output->currentMode();
QSize realSize;
if (output->isHorizontal()) {
realSize = mode->size();
} else {
realSize = QSize(mode->size().height(), mode->size().width());
QSize realSize = mode->size();
if (!output->isHorizontal()) {
realSize.transpose();
}
rootObject->setProperty("itemSource", QStringLiteral("OutputIdentifier.qml"));
rootObject->setProperty("modeName", Utils::sizeToString(realSize));
......@@ -117,7 +113,7 @@ void Osd::showOsd()
// only animate on X11, wayland plugin doesn't support this and
// pukes loads of warnings into our logs
if (qGuiApp->platformName() == QStringLiteral("xcb")) {
if (qGuiApp->platformName() == QLatin1String("xcb")) {
rootObject->setProperty("animateOpacity", false);
rootObject->setProperty("opacity", 1);
rootObject->setProperty("visible", true);
......@@ -139,4 +135,3 @@ void Osd::hideOsd()
rootObject->setProperty("visible", false);
}
} // ns
......@@ -45,16 +45,12 @@ public:
void showGenericOsd(const QString &icon, const QString &text);
void showOutputIdentifier(const KScreen::OutputPtr output);
private Q_SLOTS:
void hideOsd();
private:
void hideOsd();
void showOsd();
void updatePosition();
KScreen::OutputPtr m_output;
QString m_osdPath;
QRect m_outputGeometry;
KDeclarative::QmlObject *m_osdObject = nullptr;
QTimer *m_osdTimer = nullptr;
......
......@@ -28,7 +28,7 @@
namespace KScreen {
OsdManager* OsdManager::m_instance = 0;
OsdManager* OsdManager::s_instance = nullptr;
OsdManager::OsdManager(QObject *parent)
: QObject(parent)
......@@ -38,12 +38,12 @@ OsdManager::OsdManager(QObject *parent)
m_cleanupTimer->setInterval(60000);
m_cleanupTimer->setSingleShot(true);
connect(m_cleanupTimer, &QTimer::timeout, this, [this]() {
qDeleteAll(m_osds.begin(), m_osds.end());
qDeleteAll(m_osds);
m_osds.clear();
});
QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.kscreen.osdService"));
if (!QDBusConnection::sessionBus().registerObject(QStringLiteral("/org/kde/kscreen/osdService"), this, QDBusConnection::ExportAllSlots | QDBusConnection::ExportAllSignals)) {
qDebug() << "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Failed to registerObject";
if (!QDBusConnection::sessionBus().registerObject(QStringLiteral("/org/kde/kscreen/osdService"), this, QDBusConnection::ExportAllSlots)) {
qCWarning(KSCREEN_KDED) << "Failed to registerObject";
}
}
......@@ -53,10 +53,10 @@ OsdManager::~OsdManager()
OsdManager* OsdManager::self()
{
if (!OsdManager::m_instance) {
m_instance = new OsdManager();
if (!OsdManager::s_instance) {
s_instance = new OsdManager();
}
return m_instance;
return s_instance;
}
void OsdManager::showOutputIdentifiers()
......
......@@ -49,7 +49,7 @@ private:
void slotIdentifyOutputs(KScreen::ConfigOperation *op);
QMap<QString, KScreen::Osd*> m_osds;
static OsdManager* m_instance;
static OsdManager* s_instance;
QTimer* m_cleanupTimer;
};
......
Supports Markdown
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