Changeset View
Standalone View
plugins/debuggercommon/midebuggerplugin.cpp
Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | |||||
46 | 46 | | |||
47 | #include <QAction> | 47 | #include <QAction> | ||
48 | #include <QApplication> | 48 | #include <QApplication> | ||
49 | #include <QDBusConnection> | 49 | #include <QDBusConnection> | ||
50 | #include <QDBusConnectionInterface> | 50 | #include <QDBusConnectionInterface> | ||
51 | #include <QDBusInterface> | 51 | #include <QDBusInterface> | ||
52 | #include <QDBusServiceWatcher> | 52 | #include <QDBusServiceWatcher> | ||
53 | #include <QPointer> | 53 | #include <QPointer> | ||
54 | #include <QSignalMapper> | | |||
55 | #include <QTimer> | 54 | #include <QTimer> | ||
56 | 55 | | |||
57 | using namespace KDevelop; | 56 | using namespace KDevelop; | ||
58 | using namespace KDevMI; | 57 | using namespace KDevMI; | ||
59 | 58 | | |||
59 | class KDevMI::DBusProxy : public QObject | ||||
60 | { | ||||
61 | Q_OBJECT | ||||
62 | | ||||
63 | public: | ||||
64 | DBusProxy(const QString & service, const QString & path, QObject* parent) | ||||
mwolff: style: remove space before & | |||||
65 | : QObject(parent), | ||||
66 | dbusinterface(service, path, | ||||
67 | QString(), QDBusConnection::sessionBus(), this) | ||||
68 | {} | ||||
69 | | ||||
70 | QDBusInterface * interface() | ||||
mwolff: dito | |||||
71 | { | ||||
72 | return &dbusinterface; | ||||
73 | } | ||||
74 | | ||||
75 | public Q_SLOTS: | ||||
76 | void slotDBusCall() | ||||
77 | { | ||||
78 | emit signalDBusCall(this); | ||||
79 | } | ||||
80 | | ||||
81 | Q_SIGNALS: | ||||
82 | void signalDBusCall(DBusProxy*); | ||||
83 | | ||||
84 | private: | ||||
85 | QDBusInterface dbusinterface; | ||||
86 | }; | ||||
87 | | ||||
60 | MIDebuggerPlugin::MIDebuggerPlugin(const QString &componentName, const QString& displayName, QObject *parent) | 88 | MIDebuggerPlugin::MIDebuggerPlugin(const QString &componentName, const QString& displayName, QObject *parent) | ||
apol: Shouldn't this line go to the end of the file? | |||||
croick: That's probably more common, thanks. | |||||
61 | : KDevelop::IPlugin(componentName, parent) | 89 | : KDevelop::IPlugin(componentName, parent) | ||
62 | { | 90 | { | ||
63 | core()->debugController()->initializeUi(); | 91 | core()->debugController()->initializeUi(); | ||
64 | 92 | | |||
65 | setupActions(displayName); | 93 | setupActions(displayName); | ||
66 | setupDBus(); | 94 | setupDBus(); | ||
67 | } | 95 | } | ||
68 | 96 | | |||
Show All 21 Lines | 117 | action->setWhatsThis(i18n("<b>Attach to process</b>" | |||
90 | "<p>Attaches the debugger to a running process.</p>")); | 118 | "<p>Attaches the debugger to a running process.</p>")); | ||
91 | connect(action, &QAction::triggered, this, &MIDebuggerPlugin::slotAttachProcess); | 119 | connect(action, &QAction::triggered, this, &MIDebuggerPlugin::slotAttachProcess); | ||
92 | ac->addAction(QStringLiteral("debug_attach"), action); | 120 | ac->addAction(QStringLiteral("debug_attach"), action); | ||
93 | #endif | 121 | #endif | ||
94 | } | 122 | } | ||
95 | 123 | | |||
96 | void MIDebuggerPlugin::setupDBus() | 124 | void MIDebuggerPlugin::setupDBus() | ||
97 | { | 125 | { | ||
98 | m_drkonqiMap = new QSignalMapper(this); | | |||
99 | connect(m_drkonqiMap, static_cast<void(QSignalMapper::*)(QObject*)>(&QSignalMapper::mapped), | | |||
100 | this, &MIDebuggerPlugin::slotDebugExternalProcess); | | |||
101 | | ||||
102 | QDBusConnectionInterface* dbusInterface = QDBusConnection::sessionBus().interface(); | 126 | QDBusConnectionInterface* dbusInterface = QDBusConnection::sessionBus().interface(); | ||
103 | for (const auto &service : dbusInterface->registeredServiceNames().value()) { | 127 | for (const auto &service : dbusInterface->registeredServiceNames().value()) { | ||
104 | slotDBusServiceRegistered(service); | 128 | slotDBusServiceRegistered(service); | ||
105 | } | 129 | } | ||
106 | 130 | | |||
107 | QDBusServiceWatcher* watcher = new QDBusServiceWatcher(this); | 131 | QDBusServiceWatcher* watcher = new QDBusServiceWatcher(this); | ||
108 | connect(watcher, &QDBusServiceWatcher::serviceRegistered, | 132 | connect(watcher, &QDBusServiceWatcher::serviceRegistered, | ||
109 | this, &MIDebuggerPlugin::slotDBusServiceRegistered); | 133 | this, &MIDebuggerPlugin::slotDBusServiceRegistered); | ||
Show All 9 Lines | |||||
119 | MIDebuggerPlugin::~MIDebuggerPlugin() | 143 | MIDebuggerPlugin::~MIDebuggerPlugin() | ||
120 | { | 144 | { | ||
121 | } | 145 | } | ||
122 | 146 | | |||
123 | void MIDebuggerPlugin::slotDBusServiceRegistered(const QString& service) | 147 | void MIDebuggerPlugin::slotDBusServiceRegistered(const QString& service) | ||
124 | { | 148 | { | ||
125 | if (service.startsWith(QLatin1String("org.kde.drkonqi"))) { | 149 | if (service.startsWith(QLatin1String("org.kde.drkonqi"))) { | ||
126 | // New registration | 150 | // New registration | ||
127 | QDBusInterface* drkonqiInterface = new QDBusInterface(service, QStringLiteral("/krashinfo"), | 151 | auto drkonqiProxy = new DBusProxy(service, QStringLiteral("/krashinfo"), this); | ||
the old code was odd here already, but shouldn't you first check whether the service is already known and a proxy exists? also, add a comment here please saying that we use the proxy to map N services to the one slot that takes the proxy. Finally, can't we just use old-style connect + sender() here to simplify the code? Yes, sender() isn't the nicest thing on earth, but it certainly is less code than this here. mwolff: the old code was odd here already, but shouldn't you first check whether the service is already… | |||||
Actually, since I didn't know what the thing is supposed to do, I checked the DrKonqi side of the code: The whole thing is never called, since DrKonqi never starts a service called "org.kde.drkonqi". There is a service foreseen called "org.kde.Krash", but it is not registered to the DBus. croick: Actually, since I didn't know what the thing is supposed to do, I checked the DrKonqi side of… | |||||
128 | QString(), QDBusConnection::sessionBus(), | 152 | m_drkonqis.insert(service, drkonqiProxy); | ||
129 | this); | 153 | connect(drkonqiProxy->interface(), SIGNAL(acceptDebuggingApplication()), | ||
130 | m_drkonqis.insert(service, drkonqiInterface); | 154 | drkonqiProxy, SLOT(slotDBusCall())); | ||
131 | 155 | connect(drkonqiProxy, &DBusProxy::signalDBusCall, | |||
132 | connect(drkonqiInterface, SIGNAL(acceptDebuggingApplication()), m_drkonqiMap, SLOT(map())); | 156 | this, &MIDebuggerPlugin::slotDebugExternalProcess); | ||
133 | m_drkonqiMap->setMapping(drkonqiInterface, drkonqiInterface); | | |||
134 | 157 | | |||
135 | drkonqiInterface->call(QStringLiteral("registerDebuggingApplication"), i18n("KDevelop")); | 158 | drkonqiProxy->interface()->call(QStringLiteral("registerDebuggingApplication"), i18n("KDevelop")); | ||
136 | } | 159 | } | ||
137 | } | 160 | } | ||
138 | 161 | | |||
139 | void MIDebuggerPlugin::slotDBusServiceUnregistered(const QString& service) | 162 | void MIDebuggerPlugin::slotDBusServiceUnregistered(const QString& service) | ||
140 | { | 163 | { | ||
141 | if (service.startsWith(QLatin1String("org.kde.drkonqi"))) { | 164 | if (service.startsWith(QLatin1String("org.kde.drkonqi"))) { | ||
142 | // Deregistration | 165 | // Deregistration | ||
143 | if (m_drkonqis.contains(service)) | 166 | if (m_drkonqis.contains(service)) | ||
144 | delete m_drkonqis.take(service); | 167 | delete m_drkonqis.take(service); | ||
145 | } | 168 | } | ||
146 | } | 169 | } | ||
147 | 170 | | |||
148 | void MIDebuggerPlugin::slotDebugExternalProcess(QObject* interface) | 171 | void MIDebuggerPlugin::slotDebugExternalProcess(DBusProxy* proxy) | ||
149 | { | 172 | { | ||
150 | auto dbusInterface = static_cast<QDBusInterface*>(interface); | 173 | QDBusReply<int> reply = proxy->interface()->call(QStringLiteral("pid")); | ||
151 | | ||||
152 | QDBusReply<int> reply = dbusInterface->call(QStringLiteral("pid")); | | |||
153 | if (reply.isValid()) { | 174 | if (reply.isValid()) { | ||
154 | attachProcess(reply.value()); | 175 | attachProcess(reply.value()); | ||
155 | QTimer::singleShot(500, this, &MIDebuggerPlugin::slotCloseDrKonqi); | 176 | QTimer::singleShot(500, this, &MIDebuggerPlugin::slotCloseDrKonqi); | ||
156 | 177 | | |||
157 | m_drkonqi = m_drkonqis.key(dbusInterface); | 178 | m_drkonqi = m_drkonqis.key(proxy); | ||
158 | } | 179 | } | ||
159 | 180 | | |||
160 | core()->uiController()->activeMainWindow()->raise(); | 181 | core()->uiController()->activeMainWindow()->raise(); | ||
161 | } | 182 | } | ||
162 | 183 | | |||
163 | void MIDebuggerPlugin::slotCloseDrKonqi() | 184 | void MIDebuggerPlugin::slotCloseDrKonqi() | ||
164 | { | 185 | { | ||
165 | if (!m_drkonqi.isEmpty()) { | 186 | if (!m_drkonqi.isEmpty()) { | ||
▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Line(s) | |||||
267 | { | 288 | { | ||
268 | return i18n("Debugger"); | 289 | return i18n("Debugger"); | ||
269 | } | 290 | } | ||
270 | 291 | | |||
271 | void MIDebuggerPlugin::showStatusMessage(const QString& msg, int timeout) | 292 | void MIDebuggerPlugin::showStatusMessage(const QString& msg, int timeout) | ||
272 | { | 293 | { | ||
273 | emit showMessage(this, msg, timeout); | 294 | emit showMessage(this, msg, timeout); | ||
274 | } | 295 | } | ||
296 | | ||||
297 | #include "midebuggerplugin.moc" |
style: remove space before &