File indexing completed on 2024-04-28 04:38:34

0001 /*
0002     SPDX-FileCopyrightText: 1999-2001 John Birch <jbb@kdevelop.org>
0003     SPDX-FileCopyrightText: 2001 Bernd Gehrmann <bernd@kdevelop.org>
0004     SPDX-FileCopyrightText: 2007 Hamish Rodda <rodda@kde.org>
0005     SPDX-FileCopyrightText: 2016 Aetf <aetf@unlimitedcodeworks.xyz>
0006 
0007     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0008 */
0009 
0010 #ifndef MIDEBUGGERPLUGIN_H
0011 #define MIDEBUGGERPLUGIN_H
0012 
0013 #include <config-kdevelop.h>
0014 
0015 #include <interfaces/iplugin.h>
0016 #include <interfaces/istatus.h>
0017 #include <interfaces/iuicontroller.h>
0018 #include <sublime/view.h>
0019 
0020 #include <QHash>
0021 
0022 class QDBusServiceWatcher;
0023 class QUrl;
0024 
0025 namespace KDevelop {
0026 class Context;
0027 }
0028 
0029 namespace KDevMI {
0030 class MIAttachProcessJob;
0031 class MIDebugSession;
0032 class DBusProxy;
0033 class MIDebuggerPlugin : public KDevelop::IPlugin, public KDevelop::IStatus
0034 {
0035     Q_OBJECT
0036     Q_INTERFACES(KDevelop::IStatus)
0037 
0038 public:
0039     MIDebuggerPlugin(const QString& componentName, const QString& displayName, QObject *parent);
0040     ~MIDebuggerPlugin() override;
0041 
0042     void unload() override;
0043     KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context* context, QWidget* parent) override;
0044 
0045     virtual MIDebugSession *createSession() = 0;
0046 
0047     virtual void setupToolViews() = 0;
0048     /**
0049      * The implementation should be sure it's safe to call
0050      * even when tool views are already unloaded.
0051      */
0052     virtual void unloadToolViews() = 0;
0053 
0054 //BEGIN IStatus
0055 public:
0056     QString statusName() const override;
0057 
0058 Q_SIGNALS:
0059     void clearMessage(KDevelop::IStatus*) override;
0060     void showMessage(KDevelop::IStatus*, const QString & message, int timeout = 0) override;
0061     void hideProgress(KDevelop::IStatus*) override;
0062     void showProgress(KDevelop::IStatus*, int minimum, int maximum, int value) override;
0063     void showErrorMessage(const QString&, int) override;
0064 //END IStatus
0065 
0066 Q_SIGNALS:
0067     void reset();
0068     void addWatchVariable(const QString& var);
0069     void evaluateExpression(const QString& expr);
0070     void raiseDebuggerConsoleViews();
0071 
0072 protected Q_SLOTS:
0073 
0074     void slotDebugExternalProcess(DBusProxy* proxy);
0075     void slotExamineCore();
0076 
0077 #if HAVE_KSYSGUARD
0078     void slotAttachProcess();
0079 #endif
0080 
0081 protected:
0082     void setupActions();
0083     void setupDBus();
0084 
0085     MIAttachProcessJob* attachProcess(int pid);
0086     void showStatusMessage(const QString& msg, int timeout);
0087 
0088 private:
0089     QHash<QString, DBusProxy*> m_drkonqis;
0090     const QString m_displayName;
0091     QDBusServiceWatcher* m_watcher = nullptr;
0092 };
0093 
0094 template<class T, class Plugin = MIDebuggerPlugin>
0095 class DebuggerToolFactory : public KDevelop::IToolViewFactory
0096 {
0097 public:
0098     DebuggerToolFactory(Plugin * plugin, const QString &id, Qt::DockWidgetArea defaultArea)
0099     : m_plugin(plugin), m_id(id), m_defaultArea(defaultArea)
0100     {}
0101 
0102     QWidget* create(QWidget *parent = nullptr) override
0103     {
0104         return new T(m_plugin, parent);
0105     }
0106 
0107     QString id() const override
0108     {
0109         return m_id;
0110     }
0111 
0112     Qt::DockWidgetArea defaultPosition() const override
0113     {
0114         return m_defaultArea;
0115     }
0116 
0117     void viewCreated(Sublime::View* view) override
0118     {
0119         if (view->widget()->metaObject()->indexOfSignal(QMetaObject::normalizedSignature("requestRaise()").constData()) != -1)
0120             QObject::connect(view->widget(), SIGNAL(requestRaise()), view, SLOT(requestRaise()));
0121     }
0122 
0123 private:
0124     Plugin * m_plugin;
0125     QString m_id;
0126     Qt::DockWidgetArea m_defaultArea;
0127 };
0128 
0129 } // end of namespace KDevMI
0130 
0131 #endif // MIDEBUGGERPLUGIN_H