File indexing completed on 2024-04-21 04:58:10

0001 /* This file is part of the KDE project
0002     SPDX-FileCopyrightText: 2001, 2002 Joseph Wenninger <jowenn@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef _konqsidebarplugin_h_
0008 #define _konqsidebarplugin_h_
0009 
0010 #include <kconfiggroup.h>
0011 #include <QWidget>
0012 
0013 #include <kparts/part.h>
0014 
0015 //We don't use kf5compat.h to avoid linking with libkonq
0016 //TODO KF6: when removing compatibility with KF5, remove #if
0017 #include <QtGlobal>
0018 #if QT_VERSION_MAJOR < 6
0019 #include <KParts/BrowserExtension>
0020 namespace KParts {
0021   typedef BrowserExtension NavigationExtension;
0022 }
0023 #else
0024 #include <KParts/NavigationExtension>
0025 #endif
0026 #include <kio/job.h>
0027 #include <kfileitem.h>
0028 
0029 #include "browserarguments.h"
0030 #include "windowargs.h"
0031 
0032 #ifndef KONQSIDEBARPLUGIN_EXPORT
0033 # if defined(MAKE_KONQSIDEBARPLUGIN_LIB)
0034 /* We are building this library */
0035 #  define KONQSIDEBARPLUGIN_EXPORT Q_DECL_EXPORT
0036 # else
0037 /* We are using this library */
0038 #  define KONQSIDEBARPLUGIN_EXPORT Q_DECL_IMPORT
0039 # endif
0040 #endif
0041 
0042 class KonqSidebarModulePrivate;
0043 
0044 /**
0045  * Base class for modules, implemented in plugins.
0046  * This class is exported, make sure you keep BINARY COMPATIBILITY!
0047  * (Alternatively, add a Version key to the plugins desktop file...)
0048  *
0049  * A plugin can instantiate multiple modules, for various configurations.
0050  * Example: the dirtree plugin can create a module for "/", a module for $HOME, etc.
0051  */
0052 class KONQSIDEBARPLUGIN_EXPORT KonqSidebarModule : public QObject
0053 {
0054     Q_OBJECT
0055 public:
0056     KonqSidebarModule(QObject *parent,
0057                       const KConfigGroup &configGroup);
0058     ~KonqSidebarModule() override;
0059 
0060     virtual QWidget *getWidget() = 0;
0061     KConfigGroup configGroup();
0062 
0063     /**
0064      * Enable/disable a standard konqueror action (cut, copy, paste, print)
0065      * See KParts::NavigationExtension::enableAction
0066      */
0067     void enableCopy(bool enabled);
0068     void enableCut(bool enabled);
0069     void enablePaste(bool enabled);
0070     bool isCopyEnabled() const;
0071     bool isCutEnabled() const;
0072     bool isPasteEnabled() const;
0073 
0074     void showPopupMenu(const QPoint &global, const KFileItemList &items,
0075                        const KParts::OpenUrlArguments &args = KParts::OpenUrlArguments(),
0076                        const BrowserArguments &browserArgs = BrowserArguments(),
0077                        KParts::NavigationExtension::PopupFlags flags = KParts::NavigationExtension::DefaultPopupItems,
0078                        const KParts::NavigationExtension::ActionGroupMap &actionGroups = KParts::NavigationExtension::ActionGroupMap());
0079 
0080 protected:
0081     /**
0082      * Called by the sidebar's openUrl. Reimplement this in order to
0083      * follow the navigation happening in konqueror's current view.
0084      */
0085     virtual void handleURL(const QUrl &url)
0086     {
0087         Q_UNUSED(url);
0088     }
0089     virtual void handlePreview(const KFileItemList &items);
0090     virtual void handlePreviewOnMouseOver(const KFileItem &items); //not used yet
0091 
0092 public Q_SLOTS:
0093     void openUrl(const QUrl &url);
0094 
0095     void openPreview(const KFileItemList &items);
0096 
0097     void openPreviewOnMouseOver(const KFileItem &item); // not used yet
0098 
0099     virtual void slotCurViewUrlChanged(const QUrl &url){Q_UNUSED(url);}
0100 
0101 Q_SIGNALS:
0102     void started(KIO::Job *);
0103     void completed();
0104     void setIcon(const QString &icon);
0105     void setCaption(const QString &caption);
0106 
0107     /**
0108      * Ask konqueror to open @p url.
0109      */
0110     void openUrlRequest(const QUrl &url, const KParts::OpenUrlArguments &args = KParts::OpenUrlArguments(),
0111                         const BrowserArguments &browserArgs = BrowserArguments());
0112     /**
0113      * Ask konqueror to create a new window (or tab, see BrowserArguments) for @p url.
0114      */
0115     void createNewWindow(const QUrl &url, const KParts::OpenUrlArguments &args = KParts::OpenUrlArguments(),
0116                          const BrowserArguments &browserArgs = BrowserArguments(),
0117                          const WindowArgs & = WindowArgs());
0118 
0119     /**
0120      * Ask konqueror to show the standard popup menu for the given @p items.
0121      */
0122     void popupMenu(KonqSidebarModule *module,
0123                    const QPoint &global, const KFileItemList &items,
0124                    const KParts::OpenUrlArguments &args = KParts::OpenUrlArguments(),
0125                    const BrowserArguments &browserArgs = BrowserArguments(),
0126                    KParts::NavigationExtension::PopupFlags flags = KParts::NavigationExtension::DefaultPopupItems,
0127                    const KParts::NavigationExtension::ActionGroupMap &actionGroups = KParts::NavigationExtension::ActionGroupMap());
0128 
0129     // TODO
0130     void submitFormRequest(const char *, const QString &, const QByteArray &, const QString &, const QString &, const QString &);
0131 
0132     void enableAction(KonqSidebarModule *module, const char *name, bool enabled);
0133 
0134 private:
0135     KConfigGroup m_configGroup;
0136     KonqSidebarModulePrivate *const d;
0137 
0138 };
0139 
0140 /**
0141  * The plugin class is the "factory" for sidebar modules.
0142  * It can create a module (based on a given configuration),
0143  * it can also provide QActions for letting the user create new modules interactively.
0144  */
0145 class KONQSIDEBARPLUGIN_EXPORT KonqSidebarPlugin : public QObject
0146 {
0147     Q_OBJECT
0148 public:
0149     KonqSidebarPlugin(QObject *parent, const QVariantList &args)
0150         : QObject(parent)
0151     {
0152         Q_UNUSED(args);
0153     }
0154     ~KonqSidebarPlugin() override {}
0155 
0156     /**
0157      * Create new module for the sidebar.
0158      * @param parent parent widget, for the plugin's widget
0159      * @param configGroup desktop group from the plugin's desktop file
0160      * @param desktopName filename of the plugin's desktop file - for compatibility only
0161      * @param unused for future extensions
0162      */
0163     virtual KonqSidebarModule *createModule(QWidget *parent,
0164                                             const KConfigGroup &configGroup,
0165                                             const QString &desktopname,
0166                                             const QVariant &unused) = 0;
0167 
0168     /**
0169      * Creates QActions for the "Add new" menu.
0170      * @param parent parent object for the actions
0171      * @param existingModules list of existing modules, to avoid creating "unique"
0172      * modules multiple times
0173      * @param unused for future extensions
0174      */
0175     virtual QList<QAction *> addNewActions(QObject *parent,
0176                                            const QList<KConfigGroup> &existingModules,
0177                                            const QVariant &unused)
0178     {
0179         Q_UNUSED(parent); Q_UNUSED(existingModules); Q_UNUSED(unused);
0180         return QList<QAction *>();
0181     }
0182 
0183     /**
0184      * Returns the template of the filename to used for new modules.
0185      * @param actionData data given to the QAction (for modules who provide
0186      * multiple "new" actions)
0187      * @param unused for future extensions
0188      */
0189     virtual QString templateNameForNewModule(const QVariant &actionData,
0190             const QVariant &unused) const
0191     {
0192         Q_UNUSED(actionData); Q_UNUSED(unused);
0193         return QString();
0194     }
0195 
0196     /**
0197      * Finally create a new module, added by the user.
0198      * @param actionData data given to the QAction (for modules who provide
0199      * multiple "new" actions)
0200      * @param configGroup desktop group of the new desktop file. The desktop file
0201      * is deleted if the method returns false (e.g. cancelled by user).
0202      * @param parentWidget in case the plugin shows dialogs in this method
0203      * @param unused for future extensions
0204      */
0205     virtual bool createNewModule(const QVariant &actionData, KConfigGroup &configGroup,
0206                                  QWidget *parentWidget,
0207                                  const QVariant &unused)
0208     {
0209         Q_UNUSED(actionData); Q_UNUSED(configGroup);
0210         Q_UNUSED(parentWidget); Q_UNUSED(unused);
0211         return false;
0212     }
0213 };
0214 
0215 #endif