File indexing completed on 2023-10-01 04:11:42
0001 /* 0002 SPDX-FileCopyrightText: 2007 Aaron Seigo <aseigo@kde.org> 0003 SPDX-FileCopyrightText: 2008 Ménard Alexis <darktears31@gmail.com> 0004 SPDX-FileCopyrightText: 2009 Chani Armitage <chani@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #ifndef PLASMA_CONTAINMENT_H 0010 #define PLASMA_CONTAINMENT_H 0011 0012 #include <KPluginFactory> 0013 #include <KSharedConfig> 0014 #include <plasma/applet.h> 0015 0016 namespace Plasma 0017 { 0018 class DataEngine; 0019 class Package; 0020 class Corona; 0021 class ContainmentActions; 0022 class ContainmentPrivate; 0023 0024 /** 0025 * @class Containment plasma/containment.h <Plasma/Containment> 0026 * 0027 * @short The base class for plugins that provide backgrounds and applet grouping containers 0028 * 0029 * Containment objects provide the means to group applets into functional sets. 0030 * They also provide the following: 0031 * 0032 * creation of focusing event 0033 * - drawing of the background image (which can be interactive) 0034 * - form factors (e.g. panel, desktop, full screen, etc) 0035 * - applet layout management 0036 * 0037 * Since containment is actually just a Plasma::Applet, all the techniques used 0038 * for writing the visual presentation of Applets is applicable to Containtments. 0039 * Containments are differentiated from Applets by being marked with the ServiceType 0040 * of Plasma/Containment. Plugins registered with both the Applet and the Containment 0041 * ServiceTypes can be loaded for us in either situation. 0042 * 0043 * See techbase.kde.org for a tutorial on writing Containments using this class. 0044 */ 0045 class PLASMA_EXPORT Containment : public Applet 0046 { 0047 Q_OBJECT 0048 Q_PROPERTY(QString wallpaper READ wallpaper WRITE setWallpaper NOTIFY wallpaperChanged) 0049 Q_PROPERTY(bool isUiReady READ isUiReady NOTIFY uiReadyChanged) 0050 0051 public: 0052 /** 0053 * This constructor can be used with the KCoreAddons plugin loading system. 0054 * The argument list is expected to have contain the KPackage of the applet, 0055 * the meta data file path (for compatibility) and an applet ID which must be a base 10 number. 0056 * 0057 * @param parent a QObject parent; you probably want to pass in 0 0058 * @param data, KPluginMetaData used to create this plugin 0059 * @param args a list of strings containing the applet id 0060 * @since 5.86 0061 */ 0062 explicit Containment(QObject *parentObject, const KPluginMetaData &data, const QVariantList &args); 0063 0064 #if PLASMA_ENABLE_DEPRECATED_SINCE(5, 86) 0065 /** 0066 * @param parent the QObject this applet is parented to 0067 * @param serviceId the name of the .desktop file containing the 0068 * information about the widget 0069 * @param containmentId a unique id used to differentiate between multiple 0070 * instances of the same Applet type 0071 * @deprecated Since 5.86, use Containment(QObject *, KPluginMetaData, QVariantList) instead 0072 */ 0073 PLASMA_DEPRECATED_VERSION(5, 86, "use Containment(QObject *, KPluginMetaData, QVariantList) instead") 0074 explicit Containment(QObject *parent = nullptr, const QString &serviceId = QString(), uint containmentId = 0); 0075 #endif 0076 0077 #if PLASMA_ENABLE_DEPRECATED_SINCE(5, 86) 0078 /** 0079 * This constructor is to be used with the plugin loading systems 0080 * found in KPluginInfo and KService. The argument list is expected 0081 * to have two elements: the KService service ID for the desktop entry 0082 * and an applet ID which must be a base 10 number. 0083 * 0084 * @param parent a QObject parent; you probably want to pass in 0 0085 * @param args a list of strings containing two entries: the service id 0086 * and the applet id 0087 * @deprecated Since 5.86, use Containment(QObject *, KPluginMetaData, QVariantList) instead 0088 */ 0089 PLASMA_DEPRECATED_VERSION(5, 86, "use Containment(QObject *, KPluginMetaData, QVariantList) instead") 0090 Containment(QObject *parent, const QVariantList &args); 0091 #endif 0092 0093 ~Containment() override; 0094 0095 /** 0096 * Reimplemented from Applet 0097 */ 0098 void init() override; 0099 0100 /** 0101 * Returns the type of containment 0102 */ 0103 Plasma::Types::ContainmentType containmentType() const; 0104 0105 /** 0106 * Returns the Corona (if any) that this Containment is hosted by 0107 */ 0108 Corona *corona() const; 0109 0110 /** 0111 * Adds an applet to this Containment 0112 * 0113 * @param name the plugin name for the applet, as given by 0114 * KPluginInfo::pluginName() 0115 * @param args argument list to pass to the plasmoid 0116 * @param geometry where to place the applet, or to auto-place it if an invalid 0117 * is provided 0118 * 0119 * @return a pointer to the applet on success, or 0 on failure 0120 */ 0121 Applet *createApplet(const QString &name, const QVariantList &args = QVariantList()); 0122 0123 /** 0124 * Add an existing applet to this Containment 0125 * 0126 * @param applet the applet that should be added 0127 * @param pos the containment-relative position 0128 */ 0129 void addApplet(Applet *applet); 0130 0131 /** 0132 * @return the applets currently in this Containment 0133 */ 0134 QList<Applet *> applets() const; 0135 0136 /** 0137 * @return the screen number this containment is serving as the desktop for 0138 * or -1 if none 0139 */ 0140 int screen() const; 0141 0142 /** 0143 * @return the last screen number this containment had 0144 * only returns -1 if it's never ever been on a screen 0145 * @since 4.5 0146 */ 0147 int lastScreen() const; 0148 0149 /** 0150 * @reimp 0151 * @sa Applet::save(KConfigGroup &) 0152 */ 0153 void save(KConfigGroup &group) const override; 0154 0155 /** 0156 * @reimp 0157 * @sa Applet::restore(KConfigGroup &) 0158 */ 0159 void restore(KConfigGroup &group) override; 0160 0161 /** 0162 * Sets wallpaper plugin. 0163 * 0164 * @param pluginName the name of the wallpaper to attempt to load 0165 */ 0166 void setWallpaper(const QString &pluginName); 0167 0168 /** 0169 * Return wallpaper plugin. 0170 */ 0171 QString wallpaper() const; 0172 0173 /** 0174 * Sets the current activity by id 0175 * 0176 * @param activity the id of the activity 0177 */ 0178 void setActivity(const QString &activityId); 0179 0180 /** 0181 * @return the current activity id associated with this containment 0182 */ 0183 QString activity() const; 0184 0185 /** 0186 * Sets a containmentactions plugin. 0187 * 0188 * @param trigger the mouse button (and optional modifier) to associate the plugin with 0189 * @param pluginName the name of the plugin to attempt to load. blank = set no plugin. 0190 * @since 4.4 0191 */ 0192 void setContainmentActions(const QString &trigger, const QString &pluginName); 0193 0194 /** 0195 * @return All the loaded containment action plugins, indexed by trigger name 0196 * @since 5.0 0197 */ 0198 QHash<QString, ContainmentActions *> &containmentActions(); 0199 0200 /** 0201 * @returns true when the ui of this containment is fully loaded, as well the ui of every applet in it 0202 */ 0203 bool isUiReady() const; 0204 0205 Q_SIGNALS: 0206 /** 0207 * This signal is emitted when a new applet is added in the containment 0208 * It may happen in the following situations: 0209 * * The user created the applet 0210 * * The applet was moved in from another containment 0211 * * The applet got restored at startup 0212 */ 0213 void appletAdded(Plasma::Applet *applet); 0214 0215 /** 0216 * This signal is emitted when an applet is destroyed 0217 */ 0218 void appletRemoved(Plasma::Applet *applet); 0219 0220 /** 0221 * This signal is emitted when a new applet is created by the containment. 0222 * Compared to appletAdded, this gets emitted only when the user explicitly 0223 * creates a new applet, either via the widget explorer or the scripting 0224 * environment. 0225 * @see appletAdded 0226 * @since 5.16 0227 */ 0228 void appletCreated(Plasma::Applet *applet); 0229 0230 /** 0231 * Emitted when the activity id has changed 0232 */ 0233 void activityChanged(const QString &activity); 0234 0235 /** 0236 * Emitted when the containment requests an add widgets dialog is shown. 0237 * Usually only used for desktop containments. 0238 * 0239 * @param pos where in the containment this request was made from, or 0240 * an invalid position (QPointF()) is not location specific 0241 */ 0242 void showAddWidgetsInterface(const QPointF &pos); 0243 0244 /** 0245 * This signal indicates that a containment has been 0246 * associated (or dissociated) with a physical screen. 0247 * 0248 * @param newScreen the screen it is now associated with 0249 */ 0250 void screenChanged(int newScreen); 0251 0252 /** 0253 * Emitted when the user wants to configure/change the containment, or an applet inside it. 0254 */ 0255 void configureRequested(Plasma::Applet *applet); 0256 0257 /** 0258 * Emitted when the user wants to chose an alternative for this applet or containment. 0259 */ 0260 void appletAlternativesRequested(Plasma::Applet *applet); 0261 0262 /** 0263 * Emitted when the wallpaper plugin is changed 0264 */ 0265 void wallpaperChanged(); 0266 0267 /** 0268 * Emitted when the location has changed 0269 * @since 5.0 0270 */ 0271 void locationChanged(Plasma::Types::Location location); 0272 0273 /** 0274 * Emitted when the formFactor has changed 0275 * @since 5.0 0276 */ 0277 void formFactorChanged(Plasma::Types::FormFactor formFactor); 0278 0279 /** 0280 * Emitted when the ui has been fully loaded and is fully working 0281 * @param uiReady true when the ui of the containment is ready, as well the ui of each applet in it 0282 */ 0283 void uiReadyChanged(bool uiReady); 0284 0285 /** 0286 * emitted when the containment type changed 0287 */ 0288 void containmentTypeChanged(); 0289 0290 public Q_SLOTS: 0291 /** 0292 * Informs the Corona as to what position it is in. This is informational 0293 * only, as the Corona doesn't change its actual location. This is, 0294 * however, passed on to Applets that may be managed by this Corona. 0295 * 0296 * @param location the new location of this Corona 0297 */ 0298 void setLocation(Plasma::Types::Location location); 0299 0300 /** 0301 * Sets the form factor for this Containment. This may cause changes in both 0302 * the arrangement of Applets as well as the display choices of individual 0303 * Applets. 0304 */ 0305 void setFormFactor(Plasma::Types::FormFactor formFactor); 0306 0307 /** 0308 * Set Display hints that come from the containment that suggest the applet how to look and behave. 0309 * 0310 * @param hints the new hints, as bitwise OR 0311 * @since 5.77 0312 */ 0313 void setContainmentDisplayHints(Plasma::Types::ContainmentDisplayHints hints); 0314 0315 /** 0316 * Sets the type of this containment. 0317 */ 0318 void setContainmentType(Plasma::Types::ContainmentType type); 0319 0320 void reactToScreenChange(); 0321 0322 protected: 0323 /** 0324 * Called when the contents of the containment should be saved. By default this saves 0325 * all loaded Applets 0326 * 0327 * @param group the KConfigGroup to save settings under 0328 */ 0329 virtual void saveContents(KConfigGroup &group) const; 0330 0331 /** 0332 * Called when the contents of the containment should be loaded. By default this loads 0333 * all previously saved Applets 0334 * 0335 * @param group the KConfigGroup to save settings under 0336 */ 0337 virtual void restoreContents(KConfigGroup &group); 0338 0339 private: 0340 /** 0341 * @internal This constructor is to be used with the Package loading system. 0342 * 0343 * @param parent a QObject parent; you probably want to pass in 0 0344 * @since 4.3 0345 */ 0346 Containment(const KPluginMetaData &md, uint appletId); 0347 0348 Q_PRIVATE_SLOT(d, void appletDeleted(Plasma::Applet *)) 0349 Q_PRIVATE_SLOT(d, void triggerShowAddWidgets()) 0350 Q_PRIVATE_SLOT(d, void checkStatus(Plasma::Types::ItemStatus)) 0351 0352 friend class Applet; 0353 friend class AppletPrivate; 0354 friend class CoronaPrivate; 0355 friend class ContainmentPrivate; 0356 friend class ContainmentActions; 0357 ContainmentPrivate *const d; 0358 }; 0359 0360 } // Plasma namespace 0361 0362 #endif // multiple inclusion guard