File indexing completed on 2023-10-01 04:11:42
0001 /* 0002 SPDX-FileCopyrightText: 2006-2007 Aaron Seigo <aseigo@kde.org> 0003 SPDX-FileCopyrightText: 2007 Riccardo Iaconelli <riccardo@kde.org> 0004 SPDX-FileCopyrightText: 2008 Ménard Alexis <darktears31@gmail.com> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #ifndef PLASMA_APPLET_H 0010 #define PLASMA_APPLET_H 0011 0012 #include <QKeySequence> 0013 #include <QObject> 0014 #include <QUrl> 0015 0016 #include <KConfigGroup> 0017 #include <plasma/plasma_export.h> 0018 #if PLASMA_ENABLE_DEPRECATED_SINCE(5, 94) 0019 #include <KPluginInfo> 0020 #endif 0021 0022 #include <plasma/framesvg.h> 0023 #include <plasma/plasma.h> 0024 0025 #if PLASMA_ENABLE_DEPRECATED_SINCE(5, 100) 0026 #include <KPackage/Package> 0027 #else 0028 namespace KPackage 0029 { 0030 class Package; 0031 } 0032 #endif 0033 namespace PlasmaQuick 0034 { 0035 class AppletQuickItem; 0036 class ConfigViewPrivate; 0037 class ConfigModelPrivate; 0038 class ConfigModel; 0039 }; 0040 class DeclarativeAppletScript; 0041 #include <KPluginFactory> 0042 0043 class KActionCollection; 0044 class KConfigLoader; 0045 0046 namespace Plasma 0047 { 0048 class AppletPrivate; 0049 class Containment; 0050 class DataEngine; 0051 class Package; 0052 0053 /** 0054 * @class Applet plasma/applet.h <Plasma/Applet> 0055 * 0056 * @short The base Applet class 0057 * 0058 * Applet provides several important roles for add-ons widgets in Plasma. 0059 * 0060 * First, it is the base class for the plugin system and therefore is the 0061 * interface to applets for host applications. It also handles the life time 0062 * management of data engines (e.g. all data engines accessed via 0063 * Applet::dataEngine(const QString&) are properly deref'd on Applet 0064 * destruction), background painting (allowing for consistent and complex 0065 * look and feel in just one line of code for applets), loading and starting 0066 * of scripting support for each applet, providing access to the associated 0067 * plasmoid package (if any) and access to configuration data. 0068 * 0069 * See techbase.kde.org for tutorials on writing Applets using this class. 0070 */ 0071 class PLASMA_EXPORT Applet : public QObject 0072 { 0073 Q_OBJECT 0074 Q_PROPERTY(Plasma::Types::ItemStatus status READ status WRITE setStatus NOTIFY statusChanged) 0075 Q_PROPERTY(Plasma::Types::ImmutabilityType immutability READ immutability WRITE setImmutability NOTIFY immutabilityChanged) 0076 Q_PROPERTY(Plasma::Types::FormFactor formFactor READ formFactor NOTIFY formFactorChanged) 0077 Q_PROPERTY(Plasma::Types::Location location READ location NOTIFY locationChanged) 0078 Q_PROPERTY(Plasma::Types::ContainmentDisplayHints containmentDisplayHints READ containmentDisplayHints NOTIFY containmentDisplayHintsChanged) 0079 Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged FINAL) 0080 Q_PROPERTY(QString icon READ icon WRITE setIcon NOTIFY iconChanged FINAL) 0081 Q_PROPERTY(bool busy READ isBusy WRITE setBusy NOTIFY busyChanged FINAL) 0082 0083 /** 0084 * How the applet wants its background to be drawn. The containment may chose to ignore this hint. 0085 */ 0086 Q_PROPERTY(Plasma::Types::BackgroundHints backgroundHints WRITE setBackgroundHints READ backgroundHints NOTIFY backgroundHintsChanged FINAL) 0087 0088 /** 0089 * The containment (and/or the user) may decide to use another kind of background instead (if supported by the applet) 0090 */ 0091 Q_PROPERTY(Plasma::Types::BackgroundHints userBackgroundHints WRITE setUserBackgroundHints READ userBackgroundHints NOTIFY userBackgroundHintsChanged FINAL) 0092 0093 /** 0094 * The effective background hints the applet has, internally decided how to mix with userBackgroundHints 0095 */ 0096 Q_PROPERTY(Plasma::Types::BackgroundHints effectiveBackgroundHints READ effectiveBackgroundHints NOTIFY effectiveBackgroundHintsChanged FINAL) 0097 0098 public: 0099 // CONSTRUCTORS 0100 0101 /** 0102 * This constructor can be used with the KCoreAddons plugin loading system. 0103 * The argument list is expected to have contain the KPackage of the applet, 0104 * the meta data file path (for compatibility) and an applet ID which must be a base 10 number. 0105 * 0106 * @param parent a QObject parent; you probably want to pass in 0 0107 * @param data, KPluginMetaData used to create this plugin 0108 * @param args a list of strings containing the applet id 0109 * @Since 5.86 0110 */ 0111 Applet(QObject *parentObject, const KPluginMetaData &data, const QVariantList &args); 0112 0113 #if PLASMA_ENABLE_DEPRECATED_SINCE(5, 86) 0114 /** 0115 * @param parent the QObject this applet is parented to 0116 * @param serviceId the name of the .desktop file containing the 0117 * information about the widget 0118 * @param appletId a unique id used to differentiate between multiple 0119 * instances of the same Applet type 0120 * @deprecated Since 5.86, use Applet(QObject *, KPluginMetaData, QVariantList) instead 0121 */ 0122 PLASMA_DEPRECATED_VERSION(5, 86, "use Applet(QObject *, KPluginMetaData, QVariantList) instead") 0123 explicit Applet(QObject *parent = nullptr, const QString &serviceId = QString(), uint appletId = 0); 0124 #endif 0125 0126 #if PLASMA_ENABLE_DEPRECATED_SINCE(5, 28) 0127 /** 0128 * @param parent the QObject this applet is parented to 0129 * @param info the plugin information object for this Applet 0130 * @param appletId a unique id used to differentiate between multiple 0131 * instances of the same Applet type 0132 * @since 4.6 0133 * 0134 * @deprecated Since 5.28, prefer using KPluginMetaData 0135 */ 0136 PLASMA_DEPRECATED_VERSION(5, 28, "Use Applet(const KPluginMetaData &, QObject *, uint") 0137 explicit Applet(const KPluginInfo &info, QObject *parent = nullptr, uint appletId = 0); 0138 #endif 0139 0140 #if PLASMA_ENABLE_DEPRECATED_SINCE(5, 86) 0141 /** 0142 * @param parent the QObject this applet is parented to 0143 * @param metadata the plugin information object for this Applet 0144 * @param appletId a unique id used to differentiate between multiple 0145 * instances of the same Applet type 0146 * @since 5.27 0147 * @deprecated Since 5.86, use Applet(QObject *, KPluginMetaData, QVariantList) instead 0148 */ 0149 PLASMA_DEPRECATED_VERSION(5, 86, "use Applet(QObject *, KPluginMetaData, QVariantList) instead") 0150 explicit Applet(const KPluginMetaData &metadata, QObject *parent = nullptr, uint appletId = 0); 0151 #endif 0152 0153 ~Applet() override; 0154 0155 // BOOKKEEPING 0156 /** 0157 * @return the id of this applet 0158 */ 0159 uint id() const; 0160 0161 /** 0162 * @return The type of immutability of this applet 0163 */ 0164 Types::ImmutabilityType immutability() const; 0165 0166 /** 0167 * If for some reason, the applet fails to get up on its feet (the 0168 * library couldn't be loaded, necessary hardware support wasn't found, 0169 * etc..) this method returns the reason why, in an user-readable way. 0170 * @since 5.0 0171 **/ 0172 QString launchErrorMessage() const; 0173 0174 /** 0175 * If for some reason, the applet fails to get up on its feet (the 0176 * library couldn't be loaded, necessary hardware support wasn't found, 0177 * etc..) this method returns true. 0178 **/ 0179 bool failedToLaunch() const; 0180 0181 /** 0182 * @return true if destroy() was called; useful for Applets which should avoid 0183 * certain tasks if they are about to be deleted permanently 0184 */ 0185 bool destroyed() const; 0186 0187 /** 0188 * @return the Containment, if any, this applet belongs to 0189 **/ 0190 Containment *containment() const; 0191 0192 /** 0193 * @return true if this Applet is currently being used as a Containment, false otherwise 0194 */ 0195 bool isContainment() const; 0196 0197 /** 0198 * @return the status of the applet 0199 * @since 4.4 0200 */ 0201 Types::ItemStatus status() const; 0202 0203 /** 0204 * Returns the current form factor the applet is being displayed in. 0205 * 0206 * @see Plasma::FormFactor 0207 */ 0208 Types::FormFactor formFactor() const; 0209 0210 /** 0211 * Returns the location of the scene which is displaying applet. 0212 * 0213 * @see Plasma::Types::Location 0214 */ 0215 Types::Location location() const; 0216 0217 /** 0218 * @return Display hints that come from the containment that suggest the applet how to look and behave. 0219 * @since 5.77 0220 */ 0221 Types::ContainmentDisplayHints containmentDisplayHints() const; 0222 0223 // CONFIGURATION 0224 /** 0225 * Returns the KConfigGroup to access the applets configuration. 0226 * 0227 * This config object will write to an instance 0228 * specific config file named \<appletname\>\<instanceid\>rc 0229 * in the Plasma appdata directory. 0230 **/ 0231 KConfigGroup config() const; 0232 0233 /** 0234 * Returns a KConfigGroup object to be shared by all applets of this 0235 * type. 0236 * 0237 * This config object will write to an applet-specific config object 0238 * named plasma_\<appletname\>rc in the local config directory. 0239 */ 0240 KConfigGroup globalConfig() const; 0241 0242 /** 0243 * Returns the config skeleton object from this applet's package, 0244 * if any. 0245 * 0246 * @return config skeleton object, or 0 if none 0247 **/ 0248 KConfigLoader *configScheme() const; 0249 0250 /** 0251 * Saves state information about this applet that will 0252 * be accessed when next instantiated in the restore(KConfigGroup&) method. 0253 * 0254 * This method does not need to be reimplemented by Applet 0255 * subclasses, but can be useful for Applet specializations 0256 * (such as Containment) to do so. 0257 * 0258 * Applet subclasses may instead want to reimplement saveState(). 0259 **/ 0260 virtual void save(KConfigGroup &group) const; 0261 0262 /** 0263 * Restores state information about this applet saved previously 0264 * in save(KConfigGroup&). 0265 * 0266 * This method does not need to be reimplemented by Applet 0267 * subclasses, but can be useful for Applet specializations 0268 * (such as Containment) to do so. 0269 **/ 0270 virtual void restore(KConfigGroup &group); 0271 0272 /** 0273 * @return true if the applet currently needs to be configured, 0274 * otherwise, false 0275 */ 0276 bool configurationRequired() const; 0277 0278 /** 0279 * @return A translated message for the user explaining that the 0280 * applet needs configuring; this should note what needs 0281 * to be configured 0282 * 0283 * @see setConfigurationRequired 0284 * @since 5.20 0285 */ 0286 QString configurationRequiredReason() const; 0287 0288 /** 0289 * @return true when the configuration interface is being shown 0290 * @since 4.5 0291 */ 0292 bool isUserConfiguring() const; 0293 0294 /** 0295 * Tells the applet the user is configuring 0296 * @param configuring true if the configuration ui is showing 0297 */ 0298 void setUserConfiguring(bool configuring); 0299 0300 // UTILS 0301 #if PLASMA_ENABLE_DEPRECATED_SINCE(5, 6) 0302 /** 0303 * Accessor for the associated Package object if any. 0304 * Generally, only Plasmoids come in a Package. 0305 * 0306 * @return the Package object, or an invalid one if none 0307 * @deprecated Since 5.6, use kPackage() instead 0308 **/ 0309 PLASMA_DEPRECATED_VERSION(5, 6, "Use Applet::kPackage()") 0310 Package package() const; 0311 #endif 0312 0313 #if PLASMA_ENABLE_DEPRECATED_SINCE(5, 100) 0314 /** 0315 * Accessor for the associated Package object if any. 0316 * Generally, only Plasmoids come in a Package. 0317 * 0318 * @return the Package object, or an invalid one if none 0319 * @since 5.6 0320 * @deprecated Since 5.100, accessing an applets KPackage is deprecated. For using the metadata, use @p pluginMetaData instead. 0321 **/ 0322 KPackage::Package kPackage() const; 0323 #endif 0324 0325 /** 0326 * Called when any of the geometry constraints have been updated. 0327 * This method calls constraintsEvent, which may be reimplemented, 0328 * once the Applet has been prepared for updating the constraints. 0329 * 0330 * @param constraints the type of constraints that were updated 0331 */ 0332 void updateConstraints(Plasma::Types::Constraints constraints = Plasma::Types::AllConstraints); 0333 0334 // METADATA 0335 #if PLASMA_ENABLE_DEPRECATED_SINCE(5, 28) 0336 /** 0337 * @return metadata information about this plugin 0338 * @see KPluginInfo, pluginMetaData 0339 * @since 5.0 0340 * @deprecated Since 5.28, use pluginMetaData instead 0341 */ 0342 PLASMA_DEPRECATED_VERSION(5, 28, "Use Applet::pluginMetaData()") 0343 KPluginInfo pluginInfo() const; 0344 #endif 0345 0346 /** 0347 * @return metadata information about this plugin 0348 * 0349 * @since 5.27 0350 */ 0351 KPluginMetaData pluginMetaData() const; 0352 0353 /** 0354 * Returns the user-visible title for the applet, as specified in the 0355 * Name field of the .desktop file. Can be changed with @see setTitle 0356 * 0357 * @since 5.0 0358 * @return the user-visible title for the applet. 0359 **/ 0360 QString title() const; 0361 0362 /** 0363 * Sets a custom title for this instance of the applet. E.g. a clock might 0364 * use the timezone as its name rather than the .desktop file 0365 * 0366 * @since 5.0 0367 * @param title the user-visible title for the applet. 0368 */ 0369 void setTitle(const QString &title); 0370 0371 #if PLASMA_ENABLE_DEPRECATED_SINCE(5, 19) 0372 /** 0373 * Attempts to load an applet from a package 0374 * 0375 * Returns a pointer to the applet if successful. 0376 * The caller takes responsibility for the applet, including 0377 * deleting it when no longer needed. 0378 * If you instance a plasmoid with this deprecated API, the 0379 * automated default setup scripts won't be executed for that plasmoid 0380 * 0381 * @param path the path to the package 0382 * @param appletId unique ID to assign the applet, or zero to have one 0383 * assigned automatically. 0384 * @return a pointer to the loaded applet, or 0 on load failure 0385 * @since 4.3 0386 * 0387 * @deprecated Since 5.19, use Containment::createApplet() instead, you are not 0388 * supposed to have applets without containments 0389 **/ 0390 PLASMA_DEPRECATED_VERSION(5, 19, "Use Containment::createApplet(...)") 0391 static Applet *loadPlasmoid(const QString &path, uint appletId = 0); 0392 #endif 0393 0394 /** 0395 * @returns The icon name related to this applet 0396 * By default is the one in the plasmoid desktop file 0397 **/ 0398 QString icon() const; 0399 0400 /** 0401 * Sets an icon name for this applet 0402 * @param icon Freedesktop compatible icon name 0403 */ 0404 void setIcon(const QString &icon); 0405 0406 /** 0407 * @returns true if the applet should show a busy status, for instance doing 0408 * some network operation 0409 * @since 5.21 0410 */ 0411 bool isBusy() const; 0412 0413 /** 0414 * Sets the Applet to have a busy status hint, for instance the applet doing 0415 * some network operation. 0416 * The graphical representation of the busy status depends completely from 0417 * the visualization. 0418 * @param busy true if the applet is busy 0419 * @since 5.21 0420 */ 0421 void setBusy(bool busy); 0422 0423 /** 0424 * How the applet wants its background to be drawn. The containment may chose to ignore this hint. 0425 * @since 5.65 0426 */ 0427 Plasma::Types::BackgroundHints backgroundHints() const; 0428 0429 /** 0430 * Sets the applet background hints. Only Applet implementations should write this property 0431 * @since 5.65 0432 */ 0433 void setBackgroundHints(Plasma::Types::BackgroundHints hint); 0434 0435 /** 0436 * The containment (and/or the user) may decide to use another kind of background instead if supported by the applet. 0437 * In order for an applet to support user configuration of the 0438 * background, it needs to have the Plasma::Types::ConfigurableBackground flag set in its backgroundHints 0439 * @since 5.65 0440 */ 0441 Plasma::Types::BackgroundHints userBackgroundHints() const; 0442 0443 /** 0444 * Sets the hints the user wished the background style for the applet to be. 0445 * @since 5.65 0446 */ 0447 void setUserBackgroundHints(Plasma::Types::BackgroundHints hint); 0448 0449 /** 0450 * The effective background hints the applet will have: it will follow userBackgroundHints only if backgroundHints has the 0451 * Plasma::Types::ConfigurableBackground flag set 0452 * @since 5.65 0453 */ 0454 Plasma::Types::BackgroundHints effectiveBackgroundHints() const; 0455 0456 // ACTIONS 0457 /** 0458 * Returns a list of context-related QAction instances. 0459 * 0460 * This is used e.g. within the \a DesktopView to display a 0461 * contextmenu. 0462 * 0463 * @return A list of actions. The default implementation returns an 0464 * empty list. 0465 **/ 0466 virtual QList<QAction *> contextualActions(); 0467 0468 /** 0469 * Returns the collection of actions for this Applet 0470 */ 0471 KActionCollection *actions() const; 0472 0473 /** 0474 * Sets the global shortcut to associate with this widget. 0475 */ 0476 void setGlobalShortcut(const QKeySequence &shortcut); 0477 0478 /** 0479 * @return the global shortcut associated with this widget, or 0480 * an empty shortcut if no global shortcut is associated. 0481 */ 0482 QKeySequence globalShortcut() const; 0483 0484 // ASSOCIATED APPLICATION 0485 /** 0486 * Sets an application associated to this applet, that will be 0487 * regarded as a full view of what is represented in the applet 0488 * 0489 * @param string the name of the application. it can be 0490 * \li a name understood by KService::serviceByDesktopName 0491 * (e.g. "konqueror") 0492 * \li a command in $PATH 0493 * \li or an absolute path to an executable 0494 * @since 4.4 0495 */ 0496 void setAssociatedApplication(const QString &string); 0497 0498 /** 0499 * Sets a list of urls associated to this application, 0500 * they will be used as parameters for the associated application 0501 * @see setAssociatedApplication() 0502 * 0503 * @param urls 0504 */ 0505 void setAssociatedApplicationUrls(const QList<QUrl> &urls); 0506 0507 /** 0508 * @return the application associated to this applet 0509 * @since 4.4 0510 */ 0511 QString associatedApplication() const; 0512 0513 /** 0514 * @return the urls associated to this applet 0515 * @since 4.4 0516 */ 0517 QList<QUrl> associatedApplicationUrls() const; 0518 0519 /** 0520 * @return true if the applet has a valid associated application or urls 0521 * @since 4.4 0522 */ 0523 bool hasValidAssociatedApplication() const; 0524 0525 // Completely UI-specific, remove or move to scriptengine 0526 /** 0527 * @return true if this plasmoid provides a GUI configuration 0528 **/ 0529 bool hasConfigurationInterface() const; 0530 0531 Q_SIGNALS: 0532 // BOOKKEEPING 0533 /** 0534 * Emitted when the immutability changes 0535 * @since 4.4 0536 */ 0537 void immutabilityChanged(Plasma::Types::ImmutabilityType immutable); 0538 0539 /** 0540 * Emitted when the applet status changes 0541 * @since 4.4 0542 */ 0543 void statusChanged(Plasma::Types::ItemStatus status); 0544 0545 /** 0546 * Emitted when the applet has been scheduled for destruction 0547 * or the destruction has been undone 0548 * @since 5.4 0549 */ 0550 void destroyedChanged(bool destroyed); 0551 0552 /** 0553 * Emitted when the title has changed 0554 * @since 5.20 0555 */ 0556 void titleChanged(const QString &title); 0557 0558 /** 0559 * Emitted when the icon name for the applet has changed 0560 * @since 5.20 0561 */ 0562 void iconChanged(const QString &icon); 0563 0564 /** 0565 * Emitted when the busy status has changed 0566 * @since 5.21 0567 */ 0568 void busyChanged(bool busy); 0569 0570 /** 0571 * Emitted when the background hints have changed 0572 * @since 5.65 0573 */ 0574 void backgroundHintsChanged(); 0575 0576 /** 0577 * Emitted when the user background hints have changed 0578 * @since 5.65 0579 */ 0580 void userBackgroundHintsChanged(); 0581 0582 /** 0583 * Emitted when the effective background hints have changed 0584 * @since 5.65 0585 */ 0586 void effectiveBackgroundHintsChanged(); 0587 0588 // CONFIGURATION 0589 /** 0590 * Emitted when an applet has changed values in its configuration 0591 * and wishes for them to be saved at the next save point. As this implies 0592 * disk activity, this signal should be used with care. 0593 * 0594 * @note This does not need to be emitted from saveState by individual 0595 * applets. 0596 */ 0597 void configNeedsSaving(); 0598 0599 /** 0600 * emitted when the config ui appears or disappears 0601 */ 0602 void userConfiguringChanged(bool configuring); 0603 0604 // ACTIONS 0605 /** 0606 * Emitted just before the contextual actions are about to show 0607 * For instance just before the context menu containing the actions 0608 * added with setAction() is shown 0609 */ 0610 void contextualActionsAboutToShow(); 0611 0612 /** 0613 * Emitted when activation is requested due to, for example, a global 0614 * keyboard shortcut. By default the widget is given focus. 0615 */ 0616 void activated(); 0617 0618 // TODO: fix usage in containment, port to QObject::destroyed 0619 /** 0620 * Emitted when the applet is deleted 0621 */ 0622 void appletDeleted(Plasma::Applet *applet); 0623 0624 /** 0625 * Emitted when the formfactor changes 0626 */ 0627 void formFactorChanged(Plasma::Types::FormFactor formFactor); 0628 0629 /** 0630 * Emitted when the location changes 0631 */ 0632 void locationChanged(Plasma::Types::Location location); 0633 0634 void containmentDisplayHintsChanged(Plasma::Types::ContainmentDisplayHints hints); 0635 0636 /** 0637 * Emitted when setConfigurationRequired was called 0638 * @see setConfigurationRequired 0639 * @since 5.20 0640 */ 0641 void configurationRequiredChanged(bool needsConfig, const QString &reason); 0642 0643 public Q_SLOTS: 0644 // BOOKKEEPING 0645 /** 0646 * Call this method when the applet fails to launch properly. An 0647 * optional reason can be provided. 0648 * 0649 * Not that all children items will be deleted when this method is 0650 * called. If you have pointers to these items, you will need to 0651 * reset them after calling this method. 0652 * 0653 * @param failed true when the applet failed, false when it succeeded 0654 * @param reason an optional reason to show the user why the applet 0655 * failed to launch 0656 * @since 5.0 0657 **/ 0658 void setLaunchErrorMessage(const QString &reason = QString()); 0659 0660 /** 0661 * Sets the immutability type for this applet (not immutable, 0662 * user immutable or system immutable) 0663 * @param immutable the new immutability type of this applet 0664 */ 0665 void setImmutability(const Types::ImmutabilityType immutable); 0666 0667 /** 0668 * Destroys the applet; it will be removed nicely and deleted. 0669 * Its configuration will also be deleted. 0670 * If you want to remove the Applet configuration, use this, don't just delete the Applet * 0671 */ 0672 void destroy(); 0673 0674 /** 0675 * sets the status for this applet 0676 * @since 4.4 0677 */ 0678 void setStatus(const Types::ItemStatus stat); 0679 0680 // CONFIGURATION 0681 /** 0682 * Called when applet configuration values have changed. 0683 */ 0684 // TODO KF6: make it not a slot anymore and protected 0685 virtual void configChanged(); 0686 0687 // UTILS 0688 /** 0689 * Sends all pending constraints updates to the applet. Will usually 0690 * be called automatically, but can also be called manually if needed. 0691 */ 0692 void flushPendingConstraintsEvents(); 0693 0694 /** 0695 * This method is called once the applet is loaded and added to a Corona. 0696 * If the applet requires a Scene or has an particularly intensive 0697 * set of initialization routines to go through, consider implementing it 0698 * in this method instead of the constructor. 0699 * 0700 * Note: paintInterface may get called before init() depending on initialization 0701 * order. Painting is managed by the canvas (QGraphisScene), and may schedule a 0702 * paint event prior to init() being called. 0703 **/ 0704 virtual void init(); 0705 0706 // ASSOCIATED APPLICATION 0707 /** 0708 * Open the application associated to this applet, if it's not set 0709 * but some urls are, open those urls with the proper application 0710 * for their mimetype 0711 * @see setAssociatedApplication() 0712 * @see setAssociatedApplicationUrls() 0713 * @since 4.4 0714 */ 0715 void runAssociatedApplication(); 0716 0717 protected: 0718 #if PLASMA_ENABLE_DEPRECATED_SINCE(5, 86) 0719 /** 0720 * This constructor is to be used with the plugin loading systems 0721 * found in KPluginInfo and KService. The argument list is expected 0722 * to have two elements: the KService service ID for the desktop entry 0723 * and an applet ID which must be a base 10 number. 0724 * 0725 * @param parent a QObject parent; you probably want to pass in 0 0726 * @param args a list of strings containing two entries: the service id 0727 * and the applet id 0728 * @deprecated Since 5.86, use Applet(QObject *, KPluginMetaData, QVariantList) instead 0729 */ 0730 PLASMA_DEPRECATED_VERSION(5, 86, "use Applet(QObject *, KPluginMetaData, QVariantList) instead") 0731 Applet(QObject *parent, const QVariantList &args); 0732 #endif 0733 0734 // CONFIGURATION 0735 /** 0736 * When called, the Applet should write any information needed as part 0737 * of the Applet's running state to the configuration object in config() 0738 * and/or globalConfig(). 0739 * 0740 * Applets that always sync their settings/state with the config 0741 * objects when these settings/states change do not need to reimplement 0742 * this method. 0743 **/ 0744 virtual void saveState(KConfigGroup &config) const; 0745 0746 /** 0747 * Sets whether or not this applet provides a user interface for 0748 * configuring the applet. 0749 * 0750 * It defaults to false, and if true is passed in you should 0751 * also reimplement createConfigurationInterface() 0752 * 0753 * @param hasInterface whether or not there is a user interface available 0754 **/ 0755 void setHasConfigurationInterface(bool hasInterface); 0756 0757 /** 0758 * When the applet needs to be configured before being usable, this 0759 * method can be called to show a standard interface prompting the user 0760 * to configure the applet 0761 * 0762 * @param needsConfiguring true if the applet needs to be configured, 0763 * or false if it doesn't 0764 * @param reason a translated message for the user explaining that the 0765 * applet needs configuring; this should note what needs 0766 * to be configured 0767 */ 0768 void setConfigurationRequired(bool needsConfiguring, const QString &reason = QString()); 0769 0770 // UTILS 0771 /** 0772 * Called when any of the constraints for the applet have been updated. These constraints 0773 * range from notifying when the applet has officially "started up" to when geometry changes 0774 * to when the form factor changes. 0775 * 0776 * Each constraint that has been changed is passed in the constraints flag. 0777 * All of the constraints and how they work is documented in the @see Plasma::Constraints 0778 * enumeration. 0779 * 0780 * On applet creation, this is always called prior to painting and can be used as an 0781 * opportunity to layout the widget, calculate sizings, etc. 0782 * 0783 * Do not call update() from this method; an update() will be triggered 0784 * at the appropriate time for the applet. 0785 * 0786 * @param constraints the type of constraints that were updated 0787 * @property constraint 0788 */ 0789 virtual void constraintsEvent(Plasma::Types::Constraints constraints); 0790 0791 // TODO: timerEvent should go into AppletPrivate 0792 /** 0793 * Reimplemented from QObject 0794 */ 0795 void timerEvent(QTimerEvent *event) override; 0796 0797 private: 0798 QString filePath(const QByteArray &key, const QString &filename = QString()) const; 0799 #if !PLASMA_ENABLE_DEPRECATED_SINCE(5, 100) 0800 KPackage::Package kPackage() const; 0801 #endif 0802 /** 0803 * @internal This constructor is to be used with the Package loading system. 0804 * 0805 * @param parent a QObject parent; you probably want to pass in 0 0806 * @param args a list of strings containing two entries: the service id 0807 * and the applet id 0808 * @since 4.3 0809 */ 0810 Applet(const QString &packagePath, uint appletId); 0811 0812 Q_PRIVATE_SLOT(d, void cleanUpAndDelete()) 0813 Q_PRIVATE_SLOT(d, void askDestroy()) 0814 Q_PRIVATE_SLOT(d, void updateShortcuts()) 0815 Q_PRIVATE_SLOT(d, void globalShortcutChanged()) 0816 Q_PRIVATE_SLOT(d, void propagateConfigChanged()) 0817 Q_PRIVATE_SLOT(d, void requestConfiguration()) 0818 0819 AppletPrivate *const d; 0820 0821 // Corona needs to access setLaunchErrorMessage and init 0822 friend class Corona; 0823 friend class CoronaPrivate; 0824 friend class Containment; 0825 friend class ContainmentPrivate; 0826 friend class AppletScript; 0827 friend class AppletPrivate; 0828 friend class AccessAppletJobPrivate; 0829 friend class GraphicsViewAppletPrivate; 0830 friend class PluginLoader; 0831 friend class AssociatedApplicationManager; 0832 friend class SvgPrivate; 0833 friend class PlasmaQuick::AppletQuickItem; 0834 friend class PlasmaQuick::ConfigModel; 0835 friend class PlasmaQuick::ConfigModelPrivate; 0836 friend class PlasmaQuick::ConfigViewPrivate; 0837 friend DeclarativeAppletScript; 0838 }; 0839 0840 } // Plasma namespace 0841 0842 #if PLASMA_ENABLE_DEPRECATED_SINCE(5, 88) 0843 0844 /** 0845 * Register an applet when it is contained in a loadable module 0846 * @deprecated Since 5.88, use K_PLUGIN_CLASS_WITH_JSON instead 0847 */ 0848 /* clang-format off */ 0849 #define K_EXPORT_PLASMA_APPLET(libname, classname) \ 0850 K_PLUGIN_FACTORY(factory, registerPlugin<classname>();) 0851 0852 /// @deprecated Since 5.88, use K_PLUGIN_CLASS_WITH_JSON instead 0853 #define K_EXPORT_PLASMA_APPLET_WITH_JSON(libname, classname, jsonFile) \ 0854 K_PLUGIN_FACTORY_WITH_JSON(factory, jsonFile, registerPlugin<classname>();) 0855 /* clang-format on */ 0856 #endif 0857 0858 #endif // multiple inclusion guard