File indexing completed on 2023-10-01 04:11:43
0001 /* 0002 SPDX-FileCopyrightText: 2007 Aaron Seigo <aseigo@kde.org> 0003 SPDX-FileCopyrightText: 2007 Matt Broadstone <mbroadst@gmail.com> 0004 SPDX-FileCopyrightText: 2012 Marco Martin <mart@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #ifndef PLASMA_CORONA_H 0010 #define PLASMA_CORONA_H 0011 0012 #include <plasma/containment.h> 0013 #include <plasma/plasma.h> 0014 #include <plasma/plasma_export.h> 0015 0016 class QAction; 0017 0018 namespace Plasma 0019 { 0020 class CoronaPrivate; 0021 0022 /** 0023 * @class Corona plasma/Corona.h <Plasma/Corona> 0024 * 0025 * @short A bookkeeping Scene for Plasma::Applets 0026 */ 0027 class PLASMA_EXPORT Corona : public QObject 0028 { 0029 Q_OBJECT 0030 Q_PROPERTY(bool isStartupCompleted READ isStartupCompleted NOTIFY startupCompleted) 0031 Q_PROPERTY(bool editMode READ isEditMode WRITE setEditMode NOTIFY editModeChanged) 0032 #if PLASMA_ENABLE_DEPRECATED_SINCE(5, 83) 0033 Q_PROPERTY(Package package READ package NOTIFY packageChanged) 0034 #endif 0035 Q_PROPERTY(KPackage::Package kPackage READ kPackage NOTIFY kPackageChanged) 0036 0037 public: 0038 explicit Corona(QObject *parent = nullptr); 0039 ~Corona() override; 0040 0041 #if PLASMA_ENABLE_DEPRECATED_SINCE(5, 6) 0042 /** 0043 * Accessor for the associated Package object if any. 0044 * A Corona package defines how Containments are laid out in a View, 0045 * ToolBoxes, default layout, error messages 0046 * and in general all the furniture specific of a particular 0047 * device form factor. 0048 * 0049 * @return the Package object, or an invalid one if none 0050 * @since 5.0 0051 * @deprecated Since 5.6, use kPackage instead 0052 **/ 0053 PLASMA_DEPRECATED_VERSION(5, 6, "Use Corona::kPackage()") 0054 Plasma::Package package() const; 0055 #endif 0056 0057 #if PLASMA_ENABLE_DEPRECATED_SINCE(5, 6) 0058 /** 0059 * Setting the package name 0060 * @deprecated Since 5.6, use setKPackage instead 0061 */ 0062 PLASMA_DEPRECATED_VERSION(5, 6, "Use Corona::setKPackage(const KPackage::Package &)") 0063 void setPackage(const Plasma::Package &package); 0064 #endif 0065 0066 /** 0067 * Accessor for the associated Package object if any. 0068 * A Corona package defines how Containments are laid out in a View, 0069 * ToolBoxes, default layout, error messages 0070 * and in genelal all the furniture specific of a particular 0071 * device form factor. 0072 * 0073 * @return the Package object, or an invalid one if none 0074 * @since 5.5 0075 **/ 0076 KPackage::Package kPackage() const; 0077 0078 /** 0079 * Setting the package for the corona 0080 * @since 5.5 0081 */ 0082 void setKPackage(const KPackage::Package &package); 0083 0084 /** 0085 * @return all containments on this Corona 0086 */ 0087 QList<Containment *> containments() const; 0088 0089 /** 0090 * @returns true when the startup is over, and 0091 * all the ui graphics has been instantiated 0092 */ 0093 bool isStartupCompleted() const; 0094 0095 /** 0096 * Returns the config file used to store the configuration for this Corona 0097 */ 0098 KSharedConfig::Ptr config() const; 0099 0100 /** 0101 * Adds a Containment to the Corona 0102 * 0103 * @param name the plugin name for the containment, as given by 0104 * KPluginInfo::pluginName(). If an empty string is passed in, the default 0105 * containment plugin will be used (usually DesktopContainment). If the 0106 * string literal "null" is passed in, then no plugin will be loaded and 0107 * a simple Containment object will be created instead. 0108 * @param args argument list to pass to the containment 0109 * 0110 * @return a pointer to the containment on success, or 0 on failure. Failure can be 0111 * caused by too restrictive of an Immutability type, as containments cannot be added 0112 * when widgets are locked. 0113 * If the requested containment plugin can not be located or successfully loaded, the Containment will have an invalid pluginInfo(). 0114 */ 0115 Containment *createContainment(const QString &name, const QVariantList &args = QVariantList()); 0116 0117 /** 0118 * Returns the Containment for a given physical screen and desktop, creating one 0119 * if none exists 0120 * 0121 * @param screen number of the physical screen to locate 0122 * @param activity the activity id of the containment we want, 0123 * and empty string if the activity is not important 0124 * @param defaultPluginIfNonExistent the plugin to load by default; "null" won't 0125 * create it and "default" creates the default plugin 0126 * @param defaultArgs optional arguments to pass in when creating a Containment if needed 0127 * @since 5.45 0128 */ 0129 Containment * 0130 containmentForScreen(int screen, const QString &activity, const QString &defaultPluginIfNonExistent, const QVariantList &defaultArgs = QVariantList()); 0131 0132 // TODO KF6: add activity here, can't be done now as the overload would get confused 0133 #if PLASMA_ENABLE_DEPRECATED_SINCE(5, 46) 0134 /** 0135 * Returns the Containment, if any, for a given physical screen 0136 * 0137 * @param screen number of the physical screen to locate 0138 * @deprecated Since 5.46, use containmentForScreen(int, const QString &, const QString &, const QVariantList &) 0139 */ 0140 PLASMA_DEPRECATED_VERSION(5, 46, "Use Corona::containmentForScreen(int, const QString &, const QString &, const QVariantList &)") 0141 Containment *containmentForScreen(int screen) const; 0142 #endif 0143 0144 #if PLASMA_ENABLE_DEPRECATED_SINCE(5, 46) 0145 /** 0146 * Returns the Containment for a given physical screen and desktop, creating one 0147 * if none exists 0148 * 0149 * @param screen number of the physical screen to locate 0150 * @param defaultPluginIfNonExistent the plugin to load by default; "null" is an empty 0151 * Containment and "default" creates the default plugin 0152 * @param defaultArgs optional arguments to pass in when creating a Containment if needed 0153 * @deprecated Since 5.46, use containmentForScreen(int, const QString &, const QString &, const QVariantList &) 0154 */ 0155 PLASMA_DEPRECATED_VERSION(5, 46, "Use Corona::containmentForScreen(int, const QString &, const QString &, const QVariantList &)") 0156 Containment *containmentForScreen(int screen, const QString &defaultPluginIfNonExistent, const QVariantList &defaultArgs = QVariantList()); 0157 #endif 0158 0159 /** 0160 * Returns all containments which match a particular activity, for any screen 0161 * @param activity the activity id we want 0162 * @returns the list of matching containments if any, empty if activity is an empty string 0163 * @since 5.45 0164 */ 0165 QList<Containment *> containmentsForActivity(const QString &activity); 0166 0167 /** 0168 * Returns all containments which match a particular screen, for any activity 0169 * @param screen the screen number we want 0170 * @returns the list of matching containments if any, empty if screen is < 0 0171 * @since 5.45 0172 */ 0173 QList<Containment *> containmentsForScreen(int screen); 0174 0175 /** 0176 * Returns the number of screens available to plasma. 0177 * Subclasses should override this method as the default 0178 * implementation returns a meaningless value. 0179 */ 0180 virtual int numScreens() const; 0181 0182 /** 0183 * Returns the geometry of a given screen. 0184 * Valid screen ids are 0 to numScreen()-1, or -1 for the full desktop geometry. 0185 * Subclasses should override this method as the default 0186 * implementation returns a meaningless value. 0187 */ 0188 virtual QRect screenGeometry(int id) const = 0; 0189 0190 /** 0191 * Returns the available region for a given screen. 0192 * The available region excludes panels and similar windows. 0193 * Valid screen ids are 0 to numScreens()-1. 0194 * By default this method returns a rectangular region 0195 * equal to screenGeometry(id); subclasses that need another 0196 * behavior should override this method. 0197 */ 0198 virtual QRegion availableScreenRegion(int id) const; 0199 0200 /** 0201 * Returns the available rect for a given screen. 0202 * The difference between this and availableScreenRegion() 0203 * is that this method returns only a rectangular 0204 * available space (it doesn't care if your panel is not 100% width). 0205 * The available rect excludes panels and similar windows. 0206 * Valid screen ids are 0 to numScreens()-1. 0207 * By default this method returns a rectangular region 0208 * equal to screenGeometry(id); subclasses that need another 0209 * behavior should override this method. 0210 */ 0211 virtual QRect availableScreenRect(int id) const; 0212 0213 /** 0214 * This method is useful in order to retrieve the list of available 0215 * screen edges for panel type containments. 0216 * @param screen the id of the screen to look for free edges. 0217 * @returns a list of free edges not filled with panel type containments. 0218 */ 0219 QList<Plasma::Types::Location> freeEdges(int screen) const; 0220 0221 /** 0222 * The actions associated with this Corona 0223 */ 0224 KActionCollection *actions() const; 0225 0226 /** 0227 * Imports an applet layout from a config file. The results will be added to the 0228 * current set of Containments. 0229 * 0230 * @param config the name of the config file to load from, 0231 * or the default config file if QString() 0232 * @return the list of containments that were loaded 0233 * @since 4.6 0234 */ 0235 QList<Plasma::Containment *> importLayout(const KConfigGroup &config); 0236 0237 /** 0238 * Exports a set of containments to a config file. 0239 * 0240 * @param config the config group to save to 0241 * @param containments the list of containments to save 0242 * @since 4.6 0243 */ 0244 void exportLayout(KConfigGroup &config, QList<Containment *> containments); 0245 0246 /** 0247 * @returns the id of the screen which is showing @p containment 0248 * -1 is returned if the containment is not associated with a screen. 0249 */ 0250 virtual int screenForContainment(const Containment *containment) const; 0251 0252 /** 0253 * @return The type of immutability of this Corona 0254 */ 0255 Types::ImmutabilityType immutability() const; 0256 0257 /** 0258 * Set the Corona globally into "edit mode" 0259 * Only when the corona is of mutable type can be set of edit mode. 0260 * This indicates the UI to make easy for the user to manipulate applets. 0261 * @param edit 0262 * @since 5.63 0263 */ 0264 void setEditMode(bool edit); 0265 0266 /** 0267 * @returns true if the corona is in edit mode 0268 * @since 5.63 0269 */ 0270 bool isEditMode() const; 0271 0272 public Q_SLOTS: 0273 /** 0274 * Load applet layout from a config file. The results will be added to the 0275 * current set of Containments. 0276 * 0277 * @param config the name of the config file to load from, 0278 * or the default config file if QString() 0279 */ 0280 void loadLayout(const QString &config = QString()); 0281 0282 /** 0283 * Save applets layout to file 0284 * @param config the file to save to, or the default config file if QString() 0285 */ 0286 void saveLayout(const QString &config = QString()) const; 0287 0288 /** 0289 * Sets the immutability type for this Corona (not immutable, 0290 * user immutable or system immutable) 0291 * @param immutable the new immutability type of this applet 0292 */ 0293 void setImmutability(const Types::ImmutabilityType immutable); 0294 0295 /** 0296 * Schedules a flush-to-disk synchronization of the configuration state 0297 * at the next convenient moment. 0298 */ 0299 void requestConfigSync(); 0300 0301 /** 0302 * Schedules a time sensitive flush-to-disk synchronization of the 0303 * configuration state. Since this method does not provide any sort of 0304 * event compression, it should only be used when an *immediate* disk 0305 * sync is *absolutely* required. Otherwise, use @see requestConfigSync() 0306 * which does do event compression. 0307 */ 0308 void requireConfigSync(); 0309 0310 Q_SIGNALS: 0311 /** 0312 * This signal indicates a new containment has been added to 0313 * the Corona: it may occur after creation or restore from config 0314 */ 0315 void containmentAdded(Plasma::Containment *containment); 0316 0317 /** 0318 * This signal indicates a new containment has been created 0319 * in the Corona. Compared to containmentAdded it can only happen 0320 * after the creation of a new containment. 0321 * 0322 * @see containmentAdded 0323 * @since 5.16 0324 */ 0325 void containmentCreated(Plasma::Containment *containment); 0326 0327 /** 0328 * This signal indicates that a containment has been newly 0329 * associated (or dissociated) with a physical screen. 0330 * 0331 * @param isScreen the screen it is now associated with 0332 */ 0333 void screenOwnerChanged(int isScreen); 0334 0335 /** 0336 * This signal indicates that the configuration file was flushed to disk. 0337 */ 0338 void configSynced(); 0339 0340 /** 0341 * This signal indicates that a change in available screen geometry occurred. 0342 */ 0343 void availableScreenRegionChanged(); 0344 0345 /** 0346 * This signal indicates that a change in available screen geometry occurred. 0347 */ 0348 void availableScreenRectChanged(); 0349 0350 /** 0351 * This signal indicates that a change in geometry for the screen occurred. 0352 */ 0353 void screenGeometryChanged(int id); 0354 0355 /** 0356 * emitted when immutability changes. 0357 * this is for use by things that don't get constraints events, like plasmaapp. 0358 * it's NOT for containments or applets or any of the other stuff on the scene. 0359 * if your code's not in shells/ it probably shouldn't be using it. 0360 */ 0361 void immutabilityChanged(Plasma::Types::ImmutabilityType immutability); 0362 0363 /** This signal indicates the screen with the specified id was removed. 0364 * @since 5.40 0365 */ 0366 void screenRemoved(int id); 0367 0368 /** This signal indicates a new screen with the specified id was added. 0369 * @since 5.40 0370 */ 0371 void screenAdded(int id); 0372 0373 /** 0374 * emitted when the editMode state changes 0375 * @see isEditMode() 0376 * @since 5.63 0377 */ 0378 void editModeChanged(bool edit); 0379 0380 #if PLASMA_ENABLE_DEPRECATED_SINCE(5, 6) 0381 /** 0382 * Emitted when the package for this corona has been changed. 0383 * Shells must support changing the shell package on the fly (for instance due to device form factor changing) 0384 * 0385 * @param package the new package that defines the Corona furniture and behavior 0386 * @deprecated Since 5.6, use kPackageChanged instead 0387 */ 0388 PLASMA_DEPRECATED_VERSION(5, 6, "Use Corona::kPackageChanged(const KPackage::Package &)") 0389 void packageChanged(const Plasma::Package &package); 0390 #endif 0391 0392 /** 0393 * Emitted when the package for this corona has been changed. 0394 * Shells must support changing the shell package on the fly (for instance due to device form factor changing) 0395 * 0396 * @param package the new package that defines the Corona furniture and behavior 0397 */ 0398 void kPackageChanged(const KPackage::Package &package); 0399 0400 /** 0401 * Emitted when the startup phase has been completed 0402 */ 0403 void startupCompleted(); 0404 0405 protected: 0406 /** 0407 * Loads the default (system wide) layout for this user 0408 **/ 0409 virtual void loadDefaultLayout(); 0410 0411 /** 0412 * Loads a containment with delayed initialization, primarily useful 0413 * for implementations of loadDefaultLayout. The caller is responsible 0414 * for all initialization, saving and notification of a new containment. 0415 * 0416 * @param name the plugin name for the containment, as given by 0417 * KPluginInfo::pluginName(). If an empty string is passed in, the default 0418 * containment plugin will be used (usually DesktopContainment). If the 0419 * string literal "null" is passed in, then no plugin will be loaded and 0420 * a simple Containment object will be created instead. 0421 * @param args argument list to pass to the containment 0422 * 0423 * @return a pointer to the containment on success, or 0 on failure. Failure can 0424 * be caused by the Immutability type being too restrictive, as containments can't be added 0425 * when widgets are locked, or if the requested containment plugin can not be located 0426 * or successfully loaded. 0427 * @see addContainment 0428 **/ 0429 Containment *createContainmentDelayed(const QString &name, const QVariantList &args = QVariantList()); 0430 0431 private: 0432 CoronaPrivate *const d; 0433 0434 Q_PRIVATE_SLOT(d, void containmentDestroyed(QObject *)) 0435 Q_PRIVATE_SLOT(d, void syncConfig()) 0436 Q_PRIVATE_SLOT(d, void toggleImmutability()) 0437 Q_PRIVATE_SLOT(d, void containmentReady(bool)) 0438 0439 friend class CoronaPrivate; 0440 friend class View; 0441 }; 0442 0443 } // namespace Plasma 0444 0445 #endif