From 302a470d3b815d52c65d82774cf9b147ecf660f4 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Sat, 20 Apr 2024 15:45:36 +0300 Subject: [PATCH] kded: drop unused window registration feature no point in passing around windows to kded4 or its modules, job UI delegate windows are different thing tho Signed-off-by: Ivailo Monev --- kdecore/util/kdedmodule.h | 74 +++++++++++++++------------------------ kded/kded.cpp | 73 ++------------------------------------ kded/kded.h | 41 ++++------------------ kded/kdedadaptor.cpp | 11 +----- kded/kdedadaptor.h | 5 +-- kio/kio/jobuidelegate.cpp | 22 ++++-------- kio/kio/jobuidelegate.h | 7 ---- kio/kio/scheduler.cpp | 74 --------------------------------------- kio/kio/scheduler.h | 16 --------- 9 files changed, 47 insertions(+), 276 deletions(-) diff --git a/kdecore/util/kdedmodule.h b/kdecore/util/kdedmodule.h index 37219ee5..f0c4ca64 100644 --- a/kdecore/util/kdedmodule.h +++ b/kdecore/util/kdedmodule.h @@ -19,19 +19,18 @@ Boston, MA 02110-1301, USA. */ -#ifndef __KDEDMODULE_H__ -#define __KDEDMODULE_H__ +#ifndef KDEDMODULE_H +#define KDEDMODULE_H #include -#include -#include +#include +#include +#include class KDEDModulePrivate; class Kded; -#include - /** * \class KDEDModule kdedmodule.h * @@ -46,53 +45,38 @@ class Kded; */ class KDECORE_EXPORT KDEDModule: public QObject { - Q_OBJECT - Q_CLASSINFO("D-Bus Interface", "org.kde.KDEDModule") + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.kde.KDEDModule") - friend class Kded; + friend class Kded; public: + explicit KDEDModule(QObject *parent = nullptr); + virtual ~KDEDModule(); - /** - * Constructor - */ - explicit KDEDModule(QObject* parent = 0); + /** + * @internal called by kded after loading a module + * The module name is set from the path of the desktop file, and is + * used to register the module to D-Bus. + */ + void setModuleName(const QString &name); - virtual ~KDEDModule(); - - /** - * @internal called by kded after loading a module - * The module name is set from the path of the desktop file, and is - * used to register the module to D-Bus. - */ - void setModuleName( const QString& name ); - - QString moduleName() const; + QString moduleName() const; Q_SIGNALS: - /** - * Emitted when the module is being deleted. - */ - void moduleDeleted(KDEDModule *); + /** + * Emitted when the module is being deleted. + */ + void moduleDeleted(KDEDModule *); - /** - * Emitted when a mainwindow registers itself. - */ - void windowRegistered(qlonglong windowId); - - /** - * Emitted when a mainwindow unregisters itself. - */ - void windowUnregistered(qlonglong windowId); - - /** - * Emitted after the module is registered successfully with D-Bus - * - * @since 4.2 - */ - void moduleRegistered(const QDBusObjectPath &path); + /** + * Emitted after the module is registered successfully with D-Bus + * + * @since 4.2 + */ + void moduleRegistered(const QDBusObjectPath &path); private: - KDEDModulePrivate* const d; + KDEDModulePrivate* const d; }; -#endif +#endif // KDEDMODULE_H diff --git a/kded/kded.cpp b/kded/kded.cpp index a7c6a64b..8bb1c309 100644 --- a/kded/kded.cpp +++ b/kded/kded.cpp @@ -88,17 +88,10 @@ Kded::Kded(QObject *parent) : QObject(parent), m_pDirWatch(nullptr), m_pTimer(nullptr), - m_hTimer(nullptr), - m_serviceWatcher(nullptr) + m_hTimer(nullptr) { _self = this; - m_serviceWatcher = new QDBusServiceWatcher(this); - m_serviceWatcher->setConnection(QDBusConnection::sessionBus()); - m_serviceWatcher->setWatchMode(QDBusServiceWatcher::WatchForUnregistration); - connect(m_serviceWatcher, SIGNAL(serviceUnregistered(QString)), - this, SLOT(slotApplicationRemoved(QString))); - new KBuildsycocaAdaptor(this); new KdedAdaptor(this); @@ -442,24 +435,6 @@ void Kded::slotKDEDModuleRemoved(KDEDModule *module) // } } -void Kded::slotApplicationRemoved(const QString &name) -{ -#if 0 // see kdedmodule.cpp (KDED_OBJECTS) - foreach (KDEDModule* module, m_modules) { - module->removeAll(appId); - } -#endif - m_serviceWatcher->removeWatchedService(name); - const QList windowIds = m_windowIdList.value(name); - foreach(const qlonglong windowId, windowIds) { - m_globalWindowIdList.remove(windowId); - foreach(KDEDModule* module, m_modules) { - emit module->windowUnregistered(windowId); - } - } - m_windowIdList.remove(name); -} - void Kded::updateDirWatch() { if (!bCheckSycoca) { @@ -524,52 +499,8 @@ void Kded::checkHostname() m_hostname = newHostname; } -#if 0 -bool Kded::isWindowRegistered(long windowId) const -{ - return m_globalWindowIdList.contains(windowId); -} -#endif - -void Kded::registerWindowId(qlonglong windowId, const QString &sender) -{ - if (!m_windowIdList.contains(sender)) { - m_serviceWatcher->addWatchedService(sender); - } - - m_globalWindowIdList.insert(windowId); - QList windowIds = m_windowIdList.value(sender); - windowIds.append(windowId); - m_windowIdList.insert(sender, windowIds); - - foreach (KDEDModule* module, m_modules) { - // kDebug() << module->moduleName(); - emit module->windowRegistered(windowId); - } -} - -void Kded::unregisterWindowId(qlonglong windowId, const QString &sender) -{ - m_globalWindowIdList.remove(windowId); - QList windowIds = m_windowIdList.value(sender); - if (!windowIds.isEmpty()) { - windowIds.removeAll(windowId); - if (windowIds.isEmpty()) { - m_serviceWatcher->removeWatchedService(sender); - m_windowIdList.remove(sender); - } else { - m_windowIdList.insert(sender, windowIds); - } - } - - foreach (KDEDModule* module, m_modules) { - // kDebug() << module->moduleName(); - emit module->windowUnregistered(windowId); - } -} - KBuildsycocaAdaptor::KBuildsycocaAdaptor(QObject *parent) - : QDBusAbstractAdaptor(parent) + : QDBusAbstractAdaptor(parent) { } diff --git a/kded/kded.h b/kded/kded.h index 07ca9005..0a509d62 100644 --- a/kded/kded.h +++ b/kded/kded.h @@ -20,22 +20,18 @@ #ifndef KDED_H #define KDED_H -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #include #include #include -#include - class KDirWatch; // Apps get read-only access @@ -55,20 +51,7 @@ public: KDEDModule *loadModule(const KService::Ptr& service, bool onDemand); QStringList loadedModules(); bool unloadModule(const QString &obj); - //bool isWindowRegistered(qlonglong windowId) const; - /** - * Applications can register/unregister their windows with kded modules. - */ - //@{ - /** - * Register a window with KDED - */ - void registerWindowId(qlonglong windowId, const QString &sender); - /** - * Unregister a window previously registered with KDED - */ - void unregisterWindowId(qlonglong windowId, const QString &sender); - //@} + void loadSecondPhase(); //@{ @@ -142,11 +125,6 @@ public Q_SLOTS: */ void updateResourceList(); - /** - * An application unregistered itself from DBus - */ - void slotApplicationRemoved(const QString&); - /** * A KDEDModule is about to get destroyed. */ @@ -191,11 +169,6 @@ private: //QHash m_libs; QHash m_dontLoad; - //window id tracking, with a QDBusServiceWatcher to remove them as needed - QDBusServiceWatcher *m_serviceWatcher; - QHash > m_windowIdList; - QSet m_globalWindowIdList; - QStringList m_allResourceDirs; static Kded *_self; diff --git a/kded/kdedadaptor.cpp b/kded/kdedadaptor.cpp index ac2e5bfc..ca4cbd04 100644 --- a/kded/kdedadaptor.cpp +++ b/kded/kdedadaptor.cpp @@ -49,18 +49,9 @@ bool KdedAdaptor::unloadModule(const QString &module) return Kded::self()->unloadModule(module); } -void KdedAdaptor::registerWindowId(qlonglong windowId, const QDBusMessage &msg) -{ - Kded::self()->registerWindowId(windowId, msg.service()); -} - void KdedAdaptor::setModuleAutoloading(const QString &module, bool autoload) { - return Kded::self()->setModuleAutoloading(module, autoload); -} -void KdedAdaptor::unregisterWindowId(qlonglong windowId, const QDBusMessage &msg) -{ - Kded::self()->unregisterWindowId(windowId, msg.service()); + return Kded::self()->setModuleAutoloading(module, autoload); } QStringList KdedAdaptor::loadedModules() diff --git a/kded/kdedadaptor.h b/kded/kdedadaptor.h index f18b4687..a1f1ccd3 100644 --- a/kded/kdedadaptor.h +++ b/kded/kdedadaptor.h @@ -35,9 +35,6 @@ public Q_SLOTS: bool loadModule(const QString &obj); QStringList loadedModules(); bool unloadModule(const QString &obj); - //bool isWindowRegistered(qlonglong windowId) const; - void registerWindowId(qlonglong windowId, const QDBusMessage&); - void unregisterWindowId(qlonglong windowId, const QDBusMessage&); void reconfigure(); void loadSecondPhase(); void quit(); @@ -58,4 +55,4 @@ public Q_SLOTS: void setModuleAutoloading(const QString &module, bool autoload); }; -#endif +#endif // KDED_KDEDADAPTOR_H diff --git a/kio/kio/jobuidelegate.cpp b/kio/kio/jobuidelegate.cpp index 4e9c8000..ed1cdbd0 100644 --- a/kio/kio/jobuidelegate.cpp +++ b/kio/kio/jobuidelegate.cpp @@ -21,25 +21,17 @@ */ #include "jobuidelegate.h" - -#include -#include -#include -#include -#include -#include +#include "kio/job.h" +#include "kjob.h" +#include "klocale.h" +#include "kmessagebox.h" +#include "ksharedconfig.h" +#include "kmessage.h" +#include "kdebug.h" #include #include -#include "kio/scheduler.h" - -void KIO::JobUiDelegate::setWindow(QWidget *window) -{ - KDialogJobUiDelegate::setWindow(window); - KIO::Scheduler::registerWindow(window); -} - KIO::RenameDialog_Result KIO::JobUiDelegate::askFileRename(KJob * job, const QString & caption, const QString& src, diff --git a/kio/kio/jobuidelegate.h b/kio/kio/jobuidelegate.h index 06207c46..8581affe 100644 --- a/kio/kio/jobuidelegate.h +++ b/kio/kio/jobuidelegate.h @@ -41,13 +41,6 @@ class KIO_EXPORT JobUiDelegate : public KDialogJobUiDelegate Q_OBJECT public: - /** - * Associate this job with a window given by @p window. - * @param window the window to associate to - * @see window() - */ - virtual void setWindow(QWidget *window); - /** * \relates KIO::RenameDialog * Construct a modal, parent-less "rename" dialog, and return diff --git a/kio/kio/scheduler.cpp b/kio/kio/scheduler.cpp index 73f26778..b9bf8a65 100644 --- a/kio/kio/scheduler.cpp +++ b/kio/kio/scheduler.cpp @@ -560,13 +560,11 @@ public: bool m_ignoreConfigReparse; SessionData sessionData; - QMap m_windowList; void doJob(SimpleJob *job); void setJobPriority(SimpleJob *job, int priority); void cancelJob(SimpleJob *job); void jobFinished(KIO::SimpleJob *job, KIO::SlaveInterface *slave); - void registerWindow(QWidget *wid); void setupSlave(KIO::SlaveInterface *slave, const KUrl &url, const QString &protocol, bool newSlave); @@ -574,8 +572,6 @@ public: void slotReparseSlaveConfiguration(const QString &, const QDBusMessage&); - void slotUnregisterWindow(QObject *); - ProtoQueue *protoQ(const QString& protocol, const QString& host) { ProtoQueue *pq = m_protocols.value(protocol, 0); @@ -661,16 +657,6 @@ void Scheduler::jobFinished(KIO::SimpleJob *job, KIO::SlaveInterface *slave) schedulerPrivate->jobFinished(job, slave); } -void Scheduler::registerWindow(QWidget *wid) -{ - schedulerPrivate->registerWindow(wid); -} - -void Scheduler::unregisterWindow(QObject *wid) -{ - schedulerPrivate->slotUnregisterWindow(wid); -} - void Scheduler::emitReparseSlaveConfiguration() { // Do it immediately in this process, otherwise we might send a request before reparsing @@ -816,65 +802,5 @@ void SchedulerPrivate::slotSlaveDied(KIO::SlaveInterface *slave) slave->deref(); // Delete slave } -/* - Returns the top most window associated with widget. - - Unlike QWidget::window(), this function does its best to find and return the - main application window associated with the given widget. - - If widget itself is a dialog or its parent is a dialog, and that dialog has a - parent widget then this function will iterate through all those widgets to - find the top most window, which most of the time is the main window of the - application. By contrast, QWidget::window() would simply return the first - file dialog it encountered since it is the "next ancestor widget that has (or - could have) a window-system frame". -*/ -static QWidget* topLevelWindow(QWidget* widget) -{ - QWidget* w = widget; - while (w && w->parentWidget()) { - w = w->parentWidget(); - } - return (w ? w->window() : 0); -} - -void SchedulerPrivate::registerWindow(QWidget *wid) -{ - if (!wid) - return; - - QWidget* window = topLevelWindow(wid); - QObject *obj = static_cast(window); - - if (!m_windowList.contains(obj)) - { - // We must store the window Id because by the time - // the destroyed signal is emitted we can no longer - // access QWidget::winId() (already destructed) - WId windowId = window->winId(); - m_windowList.insert(obj, windowId); - q->connect(window, SIGNAL(destroyed(QObject*)), - SLOT(slotUnregisterWindow(QObject*))); - QDBusInterface("org.kde.kded", "/kded", "org.kde.kded"). - call(QDBus::NoBlock, "registerWindowId", qlonglong(windowId)); - } -} - -void SchedulerPrivate::slotUnregisterWindow(QObject *obj) -{ - if (!obj) - return; - - QMap::Iterator it = m_windowList.find(obj); - if (it == m_windowList.end()) - return; - WId windowId = it.value(); - q->disconnect(it.key(), SIGNAL(destroyed(QObject*)), - q, SLOT(slotUnregisterWindow(QObject*))); - m_windowList.erase( it ); - QDBusInterface("org.kde.kded", "/kded", "org.kde.kded"). - call(QDBus::NoBlock, "unregisterWindowId", qlonglong(windowId)); -} - #include "moc_scheduler.cpp" #include "moc_scheduler_p.cpp" diff --git a/kio/kio/scheduler.h b/kio/kio/scheduler.h index a39eaa17..2512ae76 100644 --- a/kio/kio/scheduler.h +++ b/kio/kio/scheduler.h @@ -120,20 +120,6 @@ namespace KIO { */ static void jobFinished(KIO::SimpleJob *job, KIO::SlaveInterface *slave); - /** - * Register the mainwindow @p wid with the KIO subsystem - * Do not call this, it is called automatically from - * void KIO::Job::setWindow(QWidget*). - * @param wid the window to register - */ - static void registerWindow(QWidget *wid); - - /** - * @internal - * Unregisters the window registered by registerWindow(). - */ - static void unregisterWindow(QObject *wid); - static void emitReparseSlaveConfiguration(); static Scheduler *self(); @@ -151,8 +137,6 @@ namespace KIO { // connected to D-Bus signal: Q_PRIVATE_SLOT(d_func(), void slotReparseSlaveConfiguration(const QString &, const QDBusMessage&)) - - Q_PRIVATE_SLOT(d_func(), void slotUnregisterWindow(QObject *)) private: friend class SchedulerPrivate; SchedulerPrivate *d_func();