From 0200224ba3af86aa202e64edf168fb382a53f5a4 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Mon, 13 Jun 2022 19:11:17 +0300 Subject: [PATCH] kded: attach the hostname watcher to the Kded object Signed-off-by: Ivailo Monev --- kded/kded.cpp | 20 ++++++++++++-------- kded/kded.h | 45 +++++++++++++++++++++++++-------------------- 2 files changed, 37 insertions(+), 28 deletions(-) diff --git a/kded/kded.cpp b/kded/kded.cpp index 47577f15..9b937ef6 100644 --- a/kded/kded.cpp +++ b/kded/kded.cpp @@ -56,7 +56,7 @@ Kded *Kded::_self = 0; -static int HostnamePollInterval = 5000; +static int iHostnamePollInterval = 5000; static bool bCheckStamps = true; static bool bCheckSycoca = true; static bool bCheckHostname = true; @@ -88,6 +88,7 @@ Kded::Kded(QObject *parent) : QObject(parent), m_pDirWatch(nullptr), m_pTimer(nullptr), + m_pHostnameD(nullptr), m_serviceWatcher(nullptr) { _self = this; @@ -115,6 +116,11 @@ Kded::Kded(QObject *parent) m_pTimer = new QTimer(this); m_pTimer->setSingleShot(true); connect(m_pTimer, SIGNAL(timeout()), this, SLOT(recreate())); + + if (bCheckHostname) { + // Watch for hostname changes + m_pHostnameD = new KHostnameD(this); + } } Kded::~Kded() @@ -130,6 +136,8 @@ Kded::~Kded() delete m_pTimer; delete m_pDirWatch; + delete m_pHostnameD; + QHashIterator it(m_modules); while (it.hasNext()) { it.next(); @@ -518,10 +526,10 @@ void Kded::unregisterWindowId(qlonglong windowId, const QString &sender) } } -KHostnameD::KHostnameD(QObject *parent, int pollInterval) +KHostnameD::KHostnameD(QObject *parent) : QObject(parent) { - m_Timer.start(pollInterval); // repetitive timer (not single-shot) + m_Timer.start(iHostnamePollInterval); // repetitive timer (not single-shot) connect(&m_Timer, SIGNAL(timeout()), this, SLOT(checkHostname())); checkHostname(); } @@ -590,7 +598,7 @@ int main(int argc, char *argv[]) } KConfigGroup cg(config, "General"); - HostnamePollInterval = cg.readEntry("HostnamePollInterval", 5000); + iHostnamePollInterval = cg.readEntry("HostnamePollInterval", 5000); bCheckSycoca = cg.readEntry("CheckSycoca", true); bCheckHostname = cg.readEntry("CheckHostname", true); bCheckStamps = cg.readEntry("CheckFileStamps", true); @@ -608,10 +616,6 @@ int main(int argc, char *argv[]) XSendEvent(QX11Info::display(), QX11Info::appRootWindow(), False, SubstructureNotifyMask, &e); #endif - if (bCheckHostname) { - (void)new KHostnameD(&app, HostnamePollInterval); // Watch for hostname changes - } - return app.exec(); // keep running } diff --git a/kded/kded.h b/kded/kded.h index 4f56aed8..6336eaf5 100644 --- a/kded/kded.h +++ b/kded/kded.h @@ -35,9 +35,27 @@ #include #include + class KDirWatch; -// No need for this in libkio - apps only get readonly access +class KHostnameD : public QObject +{ + Q_OBJECT +public: + KHostnameD(QObject *parent); + +public Q_SLOTS: + void checkHostname(); + +private: + /** + * Timer for interval hostname checking. + */ + QTimer m_Timer; + QByteArray m_hostname; +}; + +// Apps get read-only access class Kded : public QObject { Q_OBJECT @@ -162,7 +180,6 @@ private: /** * Pointer to the dirwatch class which tells us, when some directories * changed. - * Slower polling for remote file systems is now done in KDirWatch (JW). */ KDirWatch* m_pDirWatch; @@ -173,6 +190,12 @@ private: */ QTimer* m_pTimer; + /** + * Pointer to the hostname class which updates X11 authorization when + * hostname changes. + */ + KHostnameD* m_pHostnameD; + QHash m_modules; //QHash m_libs; QHash m_dontLoad; @@ -198,22 +221,4 @@ public Q_SLOTS: void recreate(); }; - -class KHostnameD : public QObject -{ - Q_OBJECT -public: - KHostnameD(QObject *parent, int pollInterval); - -public Q_SLOTS: - void checkHostname(); - -private: - /** - * Timer for interval hostname checking. - */ - QTimer m_Timer; - QByteArray m_hostname; -}; - #endif