File indexing completed on 2023-10-01 04:11:43
0001 /* 0002 SPDX-FileCopyrightText: 2009 Chani Armitage <chani@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef PLASMA_CONTAINMENTACTIONS_H 0008 #define PLASMA_CONTAINMENTACTIONS_H 0009 0010 #include <QList> 0011 0012 #include <plasma/plasma_export.h> 0013 #if PLASMA_ENABLE_DEPRECATED_SINCE(5, 94) 0014 #include <KPluginInfo> 0015 #endif 0016 0017 #include <plasma/plasma.h> 0018 0019 class QAction; 0020 class KPluginMetaData; 0021 class KConfigGroup; 0022 0023 namespace Plasma 0024 { 0025 class DataEngine; 0026 class Containment; 0027 class ContainmentActionsPrivate; 0028 0029 /** 0030 * @class ContainmentActions plasma/containmentactions.h <Plasma/ContainmentActions> 0031 * 0032 * @short The base ContainmentActions class 0033 * 0034 * "ContainmentActions" are components that provide actions (usually displaying a contextmenu) in 0035 * response to an event with a position (usually a mouse event). 0036 * 0037 * ContainmentActions plugins are registered using .desktop files. These files should be 0038 * named using the following naming scheme: 0039 * 0040 * plasma-containmentactions-\<pluginname\>.desktop 0041 * 0042 */ 0043 0044 class PLASMA_EXPORT ContainmentActions : public QObject 0045 { 0046 Q_OBJECT 0047 0048 public: 0049 /** 0050 * Default constructor for an empty or null containmentactions 0051 */ 0052 explicit ContainmentActions(QObject *parent = nullptr); 0053 0054 ~ContainmentActions() override; 0055 0056 #if PLASMA_ENABLE_DEPRECATED_SINCE(5, 67) 0057 /** 0058 * @return the plugin info for this ContainmentActions instance, 0059 * including name, pluginName and icon 0060 * @since 5.0 0061 * 0062 * @deprecated since 5.67, use metadata 0063 */ 0064 PLASMA_DEPRECATED_VERSION(5, 67, "use metadata()") 0065 KPluginInfo pluginInfo() const; 0066 #endif 0067 0068 /** 0069 * @return metadata for this ContainmentActions instance 0070 * including name, pluginName and icon 0071 * @since 5.67 0072 */ 0073 KPluginMetaData metadata() const; 0074 0075 /** 0076 * This method should be called once the plugin is loaded or settings are changed. 0077 * @param config Config group to load settings 0078 * @see init 0079 **/ 0080 virtual void restore(const KConfigGroup &config); 0081 0082 /** 0083 * This method is called when settings need to be saved. 0084 * @param config Config group to save settings 0085 **/ 0086 virtual void save(KConfigGroup &config); 0087 0088 /** 0089 * Returns the widget used in the configuration dialog. 0090 * Add the configuration interface of the containmentactions to this widget. 0091 */ 0092 virtual QWidget *createConfigurationInterface(QWidget *parent); 0093 0094 /** 0095 * This method is called when the user's configuration changes are accepted 0096 */ 0097 virtual void configurationAccepted(); 0098 0099 /** 0100 * Called when a "next" action is triggered (e.g. by mouse wheel scroll). This 0101 * can be used to scroll through a list of items this plugin manages such as 0102 * windows, virtual desktops, activities, etc. 0103 * @see performPrevious 0104 */ 0105 virtual void performNextAction(); 0106 0107 /** 0108 * Called when a "previous" action is triggered (e.g. by mouse wheel scroll). This 0109 * can be used to scroll through a list of items this plugin manages such as 0110 * windows, virtual desktops, activities, etc. 0111 * @see performNext 0112 */ 0113 virtual void performPreviousAction(); 0114 0115 /** 0116 * Implement this to provide a list of actions that can be added to another menu 0117 * for example, when right-clicking an applet, the "Activity Options" submenu is populated 0118 * with this. 0119 */ 0120 virtual QList<QAction *> contextualActions(); 0121 0122 /** 0123 * Turns a mouse or wheel event into a string suitable for a ContainmentActions 0124 * @return the string representation of the event 0125 */ 0126 static QString eventToString(QEvent *event); 0127 0128 /** 0129 * @p newContainment the containment the plugin should be associated with. 0130 * @since 4.6 0131 */ 0132 void setContainment(Containment *newContainment); 0133 0134 /** 0135 * @return the containment the plugin is associated with. 0136 */ 0137 Containment *containment(); 0138 0139 protected: 0140 /** 0141 * This constructor is to be used with the plugin loading systems 0142 * found in KPluginInfo and KService. The argument list is expected 0143 * to have one element: the KService service ID for the desktop entry. 0144 * 0145 * @param parent a QObject parent; you probably want to pass in 0 0146 * @param args a list of strings containing one entry: the service id 0147 */ 0148 ContainmentActions(QObject *parent, const QVariantList &args); 0149 0150 private: 0151 ContainmentActionsPrivate *const d; 0152 }; 0153 0154 } // Plasma namespace 0155 0156 #if PLASMA_ENABLE_DEPRECATED_SINCE(5, 88) 0157 /** 0158 * Register a containmentactions when it is contained in a loadable module 0159 * @deprecated Since 5.88, use K_PLUGIN_CLASS_WITH_JSON instead 0160 */ 0161 /* clang-format off */ 0162 #define K_EXPORT_PLASMA_CONTAINMENTACTIONS_WITH_JSON(libname, classname, jsonFile) \ 0163 K_PLUGIN_FACTORY_WITH_JSON(factory, jsonFile, registerPlugin<classname>();) 0164 /* clang-format on */ 0165 #endif 0166 0167 #endif // PLASMA_CONTAINMENTACTIONS_H