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 58f5bb62 authored by Frederik Gladhorn's avatar Frederik Gladhorn

Turn OsdManager into a regular class

Summary:
The OsdManager was trying to be a singleton while used from only one
place. Simplify it.

Reviewers: #plasma, davidedmundson

Reviewed By: #plasma, davidedmundson

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D14166
parent 97f7b9cf
......@@ -95,7 +95,7 @@ void KScreenDaemon::init()
new KScreenAdaptor(this);
// Initialize OSD manager to register its dbus interface
KScreen::OsdManager::self();
m_osdManager = new KScreen::OsdManager(this);
m_saveTimer->setInterval(300);
m_saveTimer->setSingleShot(true);
......@@ -213,11 +213,11 @@ void KScreenDaemon::applyIdealConfig()
{
if (m_monitoredConfig->connectedOutputs().count() < 2) {
KScreen::OsdManager::self()->hideOsd();
m_osdManager->hideOsd();
doApplyConfig(Generator::self()->idealConfig(m_monitoredConfig));
} else {
qCDebug(KSCREEN_KDED) << "Getting ideal config from user via OSD...";
auto action = KScreen::OsdManager::self()->showActionSelector();
auto action = m_osdManager->showActionSelector();
connect(action, &KScreen::OsdAction::selected,
this, &KScreenDaemon::applyOsdAction);
}
......@@ -282,14 +282,14 @@ void KScreenDaemon::showOsd(const QString &icon, const QString &text)
void KScreenDaemon::showOutputIdentifier()
{
KScreen::OsdManager::self()->showOutputIdentifiers();
m_osdManager->showOutputIdentifiers();
}
void KScreenDaemon::displayButton()
{
qCDebug(KSCREEN_KDED) << "displayBtn triggered";
auto action = KScreen::OsdManager::self()->showActionSelector();
auto action = m_osdManager->showActionSelector();
connect(action, &KScreen::OsdAction::selected,
this, &KScreenDaemon::applyOsdAction);
}
......
......@@ -79,6 +79,7 @@ class Q_DECL_EXPORT KScreenDaemon : public KDEDModule
QTimer* m_changeCompressor;
QTimer* m_saveTimer;
QTimer* m_lidClosedTimer;
KScreen::OsdManager *m_osdManager;
};
#endif /*KSCREEN_DAEMON_H*/
......@@ -30,8 +30,6 @@
namespace KScreen {
OsdManager* OsdManager::s_instance = nullptr;
OsdAction::OsdAction(QObject *parent)
: QObject(parent)
{
......@@ -82,14 +80,6 @@ OsdManager::~OsdManager()
{
}
OsdManager* OsdManager::self()
{
if (!OsdManager::s_instance) {
s_instance = new OsdManager();
}
return s_instance;
}
void OsdManager::showOutputIdentifiers()
{
connect(new KScreen::GetConfigOperation(), &KScreen::GetConfigOperation::finished,
......
......@@ -59,8 +59,8 @@ class OsdManager : public QObject {
Q_CLASSINFO("D-Bus Interface", "org.kde.kscreen.osdService")
public:
OsdManager(QObject *parent = nullptr);
~OsdManager() override;
static OsdManager* self();
public Q_SLOTS:
void showOutputIdentifiers();
......@@ -69,11 +69,8 @@ public Q_SLOTS:
OsdAction *showActionSelector();
private:
OsdManager(QObject *parent = nullptr);
void slotIdentifyOutputs(KScreen::ConfigOperation *op);
QMap<QString, KScreen::Osd*> m_osds;
static OsdManager* s_instance;
QTimer* m_cleanupTimer;
};
......
......@@ -37,11 +37,19 @@ OsdTest::~OsdTest()
{
}
OsdManager *OsdTest::getOsdManager()
{
if (m_osdManager)
return m_osdManager;
m_osdManager = new OsdManager(this);
return m_osdManager;
}
void OsdTest::showOutputIdentifiers()
{
if (!m_useDBus) {
QTimer::singleShot(5500, qApp, &QCoreApplication::quit);
KScreen::OsdManager::self()->showOutputIdentifiers();
getOsdManager()->showOutputIdentifiers();
} else {
QDBusMessage msg = QDBusMessage::createMethodCall(
QLatin1Literal("org.kde.kscreen.osdService"),
......@@ -67,7 +75,7 @@ void OsdTest::showGenericOsd(const QString& icon, const QString& message)
{
if (!m_useDBus) {
QTimer::singleShot(5500, qApp, &QCoreApplication::quit);
KScreen::OsdManager::self()->showOsd(!icon.isEmpty() ? icon : QStringLiteral("preferences-desktop-display-randr"),
getOsdManager()->showOsd(!icon.isEmpty() ? icon : QStringLiteral("preferences-desktop-display-randr"),
!message.isEmpty() ? message : QStringLiteral("On-Screen-Display"));
} else {
qCWarning(KSCREEN_KDED) << "Implement me.";
......@@ -78,7 +86,7 @@ void OsdTest::showGenericOsd(const QString& icon, const QString& message)
void OsdTest::showActionSelector()
{
if (!m_useDBus) {
auto action = KScreen::OsdManager::self()->showActionSelector();
auto action = getOsdManager()->showActionSelector();
connect(action, &KScreen::OsdAction::selected,
[](KScreen::OsdAction::Action action) {
qCDebug(KSCREEN_KDED) << "Selected action:" << action;
......
......@@ -24,6 +24,7 @@
namespace KScreen
{
class OsdManager;
class OsdTest : public QObject
{
......@@ -40,6 +41,8 @@ public:
void showActionSelector();
private:
OsdManager *getOsdManager();
OsdManager *m_osdManager = nullptr;
bool m_useDBus = false;
};
......
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