kded: attach the hostname watcher to the Kded object

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-06-13 19:11:17 +03:00
parent b0a5d8b2bf
commit 0200224ba3
2 changed files with 37 additions and 28 deletions

View file

@ -56,7 +56,7 @@
Kded *Kded::_self = 0; Kded *Kded::_self = 0;
static int HostnamePollInterval = 5000; static int iHostnamePollInterval = 5000;
static bool bCheckStamps = true; static bool bCheckStamps = true;
static bool bCheckSycoca = true; static bool bCheckSycoca = true;
static bool bCheckHostname = true; static bool bCheckHostname = true;
@ -88,6 +88,7 @@ Kded::Kded(QObject *parent)
: QObject(parent), : QObject(parent),
m_pDirWatch(nullptr), m_pDirWatch(nullptr),
m_pTimer(nullptr), m_pTimer(nullptr),
m_pHostnameD(nullptr),
m_serviceWatcher(nullptr) m_serviceWatcher(nullptr)
{ {
_self = this; _self = this;
@ -115,6 +116,11 @@ Kded::Kded(QObject *parent)
m_pTimer = new QTimer(this); m_pTimer = new QTimer(this);
m_pTimer->setSingleShot(true); m_pTimer->setSingleShot(true);
connect(m_pTimer, SIGNAL(timeout()), this, SLOT(recreate())); connect(m_pTimer, SIGNAL(timeout()), this, SLOT(recreate()));
if (bCheckHostname) {
// Watch for hostname changes
m_pHostnameD = new KHostnameD(this);
}
} }
Kded::~Kded() Kded::~Kded()
@ -130,6 +136,8 @@ Kded::~Kded()
delete m_pTimer; delete m_pTimer;
delete m_pDirWatch; delete m_pDirWatch;
delete m_pHostnameD;
QHashIterator<QString,KDEDModule*> it(m_modules); QHashIterator<QString,KDEDModule*> it(m_modules);
while (it.hasNext()) { while (it.hasNext()) {
it.next(); 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) : 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())); connect(&m_Timer, SIGNAL(timeout()), this, SLOT(checkHostname()));
checkHostname(); checkHostname();
} }
@ -590,7 +598,7 @@ int main(int argc, char *argv[])
} }
KConfigGroup cg(config, "General"); KConfigGroup cg(config, "General");
HostnamePollInterval = cg.readEntry("HostnamePollInterval", 5000); iHostnamePollInterval = cg.readEntry("HostnamePollInterval", 5000);
bCheckSycoca = cg.readEntry("CheckSycoca", true); bCheckSycoca = cg.readEntry("CheckSycoca", true);
bCheckHostname = cg.readEntry("CheckHostname", true); bCheckHostname = cg.readEntry("CheckHostname", true);
bCheckStamps = cg.readEntry("CheckFileStamps", true); bCheckStamps = cg.readEntry("CheckFileStamps", true);
@ -608,10 +616,6 @@ int main(int argc, char *argv[])
XSendEvent(QX11Info::display(), QX11Info::appRootWindow(), False, SubstructureNotifyMask, &e); XSendEvent(QX11Info::display(), QX11Info::appRootWindow(), False, SubstructureNotifyMask, &e);
#endif #endif
if (bCheckHostname) {
(void)new KHostnameD(&app, HostnamePollInterval); // Watch for hostname changes
}
return app.exec(); // keep running return app.exec(); // keep running
} }

View file

@ -35,9 +35,27 @@
#include <kservice.h> #include <kservice.h>
#include <QDBusServiceWatcher> #include <QDBusServiceWatcher>
class KDirWatch; 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 class Kded : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -162,7 +180,6 @@ private:
/** /**
* Pointer to the dirwatch class which tells us, when some directories * Pointer to the dirwatch class which tells us, when some directories
* changed. * changed.
* Slower polling for remote file systems is now done in KDirWatch (JW).
*/ */
KDirWatch* m_pDirWatch; KDirWatch* m_pDirWatch;
@ -173,6 +190,12 @@ private:
*/ */
QTimer* m_pTimer; QTimer* m_pTimer;
/**
* Pointer to the hostname class which updates X11 authorization when
* hostname changes.
*/
KHostnameD* m_pHostnameD;
QHash<QString,KDEDModule *> m_modules; QHash<QString,KDEDModule *> m_modules;
//QHash<QString,QLibrary *> m_libs; //QHash<QString,QLibrary *> m_libs;
QHash<QString,QObject *> m_dontLoad; QHash<QString,QObject *> m_dontLoad;
@ -198,22 +221,4 @@ public Q_SLOTS:
void recreate(); 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 #endif