diff --git a/src/plasma/corona.cpp b/src/plasma/corona.cpp index f97fa3b63..b8d26784c 100644 --- a/src/plasma/corona.cpp +++ b/src/plasma/corona.cpp @@ -1,698 +1,736 @@ /* * Copyright 2007 Matt Broadstone * Copyright 2007-2011 Aaron Seigo * Copyright 2007 Riccardo Iaconelli * Copyright (c) 2009 Chani Armitage * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "corona.h" #include "private/corona_p.h" #include #include #include #include #include #include #include #include #include #include "containment.h" #include "pluginloader.h" #include "packagestructure.h" #include "private/applet_p.h" #include "private/containment_p.h" #include "private/package_p.h" #include "private/timetracker.h" #include "debug_p.h" using namespace Plasma; namespace Plasma { Corona::Corona(QObject *parent) : QObject(parent), d(new CoronaPrivate(this)) { #ifndef NDEBUG // qCDebug(LOG_PLASMA) << "!!{} STARTUP TIME" << QTime().msecsTo(QTime::currentTime()) << "Corona ctor start"; #endif d->init(); #ifndef NDEBUG if (qEnvironmentVariableIsSet("PLASMA_TRACK_STARTUP")) { new TimeTracker(this); } #endif } Corona::~Corona() { KConfigGroup trans(KSharedConfig::openConfig(), "PlasmaTransientsConfig"); trans.deleteGroup(); delete d; } Plasma::Package Corona::package() const { return Package(d->package); } void Corona::setPackage(const Plasma::Package &package) { setKPackage(*package.d->internalPackage); emit packageChanged(package); } KPackage::Package Corona::kPackage() const { return d->package; } void Corona::setKPackage(const KPackage::Package &package) { d->package = package; emit kPackageChanged(package); } void Corona::saveLayout(const QString &configName) const { KSharedConfigPtr c; if (configName.isEmpty() || configName == d->configName) { c = config(); } else { c = KSharedConfig::openConfig(configName, KConfig::SimpleConfig); } d->saveLayout(c); } void Corona::exportLayout(KConfigGroup &config, QList containments) { foreach (const QString &group, config.groupList()) { KConfigGroup cg(&config, group); cg.deleteGroup(); } //temporarily unlock so that removal works Types::ImmutabilityType oldImm = immutability(); d->immutability = Types::Mutable; KConfigGroup dest(&config, "Containments"); KConfigGroup dummy; foreach (Plasma::Containment *c, containments) { c->save(dummy); c->config().reparent(&dest); //ensure the containment is unlocked //this is done directly because we have to bypass any Types::SystemImmutable checks c->Applet::d->immutability = Types::Mutable; foreach (Applet *a, c->applets()) { a->d->immutability = Types::Mutable; } c->destroy(); } //restore immutability d->immutability = oldImm; config.sync(); } void Corona::requestConfigSync() { // constant controlling how long between requesting a configuration sync // and one happening should occur. currently 10 seconds static const int CONFIG_SYNC_TIMEOUT = 10000; // TODO: should we check into our immutability before doing this? //NOTE: this is a pretty simplistic model: we simply save no more than CONFIG_SYNC_TIMEOUT // after the first time this is called. not much of a heuristic for save points, but // it should at least compress these activities a bit and provide a way for applet // authors to ween themselves from the sync() disease. A more interesting/dynamic // algorithm for determining when to actually sync() to disk might be better, though. if (!d->configSyncTimer->isActive()) { d->configSyncTimer->start(CONFIG_SYNC_TIMEOUT); } } void Corona::requireConfigSync() { d->syncConfig(); } void Corona::loadLayout(const QString &configName) { if (!configName.isEmpty() && configName != d->configName) { // if we have a new config name passed in, then use that as the config file for this Corona d->config = nullptr; d->configName = configName; } KConfigGroup conf(config(), QString()); if (!config()->groupList().isEmpty()) { d->importLayout(conf, false); } else { loadDefaultLayout(); d->notifyContainmentsReady(); } KConfigGroup cg(config(), "General"); setImmutability((Plasma::Types::ImmutabilityType)cg.readEntry("immutability", (int)Plasma::Types::Mutable)); } QList Corona::importLayout(const KConfigGroup &conf) { return d->importLayout(conf, true); } Containment *Corona::containmentForScreen(int screen) const { foreach (Containment *containment, d->containments) { if (containment->screen() == screen && (containment->containmentType() == Plasma::Types::DesktopContainment || containment->containmentType() == Plasma::Types::CustomContainment)) { return containment; } } return nullptr; } Containment *Corona::containmentForScreen(int screen, const QString &defaultPluginIfNonExistent, const QVariantList &defaultArgs) { return containmentForScreen(screen, QString(), defaultPluginIfNonExistent, defaultArgs); } Containment *Corona::containmentForScreen(int screen, const QString &activity, const QString &defaultPluginIfNonExistent, const QVariantList &defaultArgs) { Containment *containment = nullptr; foreach (Containment *cont, d->containments) { if (cont->lastScreen() == screen && (cont->activity().isEmpty() || cont->activity() == activity) && (cont->containmentType() == Plasma::Types::DesktopContainment || cont->containmentType() == Plasma::Types::CustomContainment)) { containment = cont; } } if (!containment && !defaultPluginIfNonExistent.isEmpty()) { // screen requests are allowed to bypass immutability if (screen >= 0) { Plasma::Types::ImmutabilityType imm = d->immutability; d->immutability = Types::Mutable; containment = d->addContainment(defaultPluginIfNonExistent, defaultArgs, 0, screen, false); d->immutability = imm; } } if (containment) { containment->setActivity(activity); } return containment; } QList Corona::containmentsForActivity(const QString &activity) { QList conts; if (activity.isEmpty()) { return conts; } std::copy_if(d->containments.begin(), d->containments.end(), std::back_inserter(conts), [activity](Containment *cont) { return cont->activity() == activity && (cont->containmentType() == Plasma::Types::DesktopContainment || cont->containmentType() == Plasma::Types::CustomContainment);} ); return conts; } QList Corona::containmentsForScreen(int screen) { QList conts; if (screen < 0) { return conts; } std::copy_if(d->containments.begin(), d->containments.end(), std::back_inserter(conts), [screen](Containment *cont) { return cont->lastScreen() == screen && (cont->containmentType() == Plasma::Types::DesktopContainment || cont->containmentType() == Plasma::Types::CustomContainment);} ); return conts; } QList Corona::containments() const { return d->containments; } bool Corona::isStartupCompleted() const { return d->containmentsStarting <= 0; } KSharedConfigPtr Corona::config() const { if (!d->config) { d->config = KSharedConfig::openConfig(d->configName, KConfig::SimpleConfig); } return d->config; } Containment *Corona::createContainment(const QString &name, const QVariantList &args) { if (d->immutability == Types::Mutable || args.contains(QVariant::fromValue(QStringLiteral("org.kde.plasma:force-create")))) { return d->addContainment(name, args, 0, -1, false); } return nullptr; } Containment *Corona::createContainmentDelayed(const QString &name, const QVariantList &args) { if (d->immutability == Types::Mutable) { return d->addContainment(name, args, 0, -1, true); } return nullptr; } int Corona::screenForContainment(const Containment *) const { return -1; } int Corona::numScreens() const { return 1; } QRegion Corona::availableScreenRegion(int id) const { return QRegion(screenGeometry(id)); } QRect Corona::availableScreenRect(int id) const { return screenGeometry(id); } void Corona::loadDefaultLayout() { //Default implementation does nothing } Types::ImmutabilityType Corona::immutability() const { return d->immutability; } void Corona::setImmutability(const Types::ImmutabilityType immutable) { if (d->immutability == immutable || d->immutability == Types::SystemImmutable) { return; } #ifndef NDEBUG // qCDebug(LOG_PLASMA) << "setting immutability to" << immutable; #endif d->immutability = immutable; d->updateContainmentImmutability(); //tell non-containments that might care (like plasmaapp or a custom corona) emit immutabilityChanged(immutable); //update our actions QAction *action = d->actions.action(QStringLiteral("lock widgets")); if (action) { if (d->immutability == Types::SystemImmutable) { action->setEnabled(false); action->setVisible(false); } else { bool unlocked = d->immutability == Types::Mutable; action->setText(unlocked ? i18n("Lock Widgets") : i18n("Unlock Widgets")); action->setIcon(QIcon::fromTheme(unlocked ? QStringLiteral("object-locked") : QStringLiteral("object-unlocked"))); action->setEnabled(true); action->setVisible(true); } } + action = d->actions.action(QStringLiteral("edit mode")); + if (action) { + switch (d->immutability) { + case Types::UserImmutable: + action->setEnabled(false); + action->setVisible(true); + break; + case Types::SystemImmutable: + action->setEnabled(false); + action->setVisible(false); + break; + case Types::Mutable: + default: + action->setEnabled(true); + action->setVisible(true); + break; + } + } + if (d->immutability != Types::SystemImmutable) { KConfigGroup cg(config(), "General"); // we call the dptr member directly for locked since isImmutable() // also checks kiosk and parent containers cg.writeEntry("immutability", (int)d->immutability); requestConfigSync(); } if (d->immutability != Types::Mutable) { - d->editMode = false; - emit editModeChanged(); + setEditMode(false); } } void Corona::setEditMode(bool edit) { - if (d->immutability != Plasma::Types::Mutable || edit == d->editMode) { + if (edit == d->editMode || (edit && d->immutability != Plasma::Types::Mutable)) { return; } + QAction *editAction = d->actions.action(QStringLiteral("edit mode")); + if (editAction) { + if (edit) { + editAction->setText(i18n("Finish Customizing Layout")); + } else { + editAction->setText(i18n("Customize Layout...")); + } + } + d->editMode = edit; - emit editModeChanged(); + emit editModeChanged(edit); } bool Corona::isEditMode() const { return d->editMode; } QList Corona::freeEdges(int screen) const { QList freeEdges; freeEdges << Plasma::Types::TopEdge << Plasma::Types::BottomEdge << Plasma::Types::LeftEdge << Plasma::Types::RightEdge; foreach (Containment *containment, containments()) { if (containment->screen() == screen && freeEdges.contains(containment->location())) { freeEdges.removeAll(containment->location()); } } return freeEdges; } KActionCollection *Corona::actions() const { return &d->actions; } CoronaPrivate::CoronaPrivate(Corona *corona) : q(corona), immutability(Types::Mutable), config(nullptr), configSyncTimer(new QTimer(corona)), actions(corona), containmentsStarting(0) { //TODO: make Package path configurable if (QCoreApplication::instance()) { configName = QCoreApplication::instance()->applicationName() + QStringLiteral("-appletsrc"); } else { configName = QStringLiteral("plasma-appletsrc"); } } CoronaPrivate::~CoronaPrivate() { qDeleteAll(containments); } void CoronaPrivate::init() { desktopDefaultsConfig = KConfigGroup(KSharedConfig::openConfig(package.filePath("defaults")), "Desktop"); configSyncTimer->setSingleShot(true); QObject::connect(configSyncTimer, SIGNAL(timeout()), q, SLOT(syncConfig())); //some common actions actions.setConfigGroup(QStringLiteral("Shortcuts")); QAction *lockAction = actions.add(QStringLiteral("lock widgets")); QObject::connect(lockAction, SIGNAL(triggered(bool)), q, SLOT(toggleImmutability())); lockAction->setText(i18n("Lock Widgets")); lockAction->setAutoRepeat(true); lockAction->setIcon(QIcon::fromTheme(QStringLiteral("object-locked"))); lockAction->setData(Plasma::Types::ControlAction); lockAction->setShortcut(QKeySequence(QStringLiteral("alt+d, l"))); lockAction->setShortcutContext(Qt::ApplicationShortcut); //fake containment/applet actions KActionCollection *containmentActions = AppletPrivate::defaultActions(q); //containment has to start with applet stuff ContainmentPrivate::addDefaultActions(containmentActions); //now it's really containment + + QAction *editAction = actions.add(QStringLiteral("edit mode")); + QObject::connect(editAction, &QAction::triggered, q, [this] () { + q->setEditMode(!q->isEditMode()); + }); + editAction->setText(i18n("Customize Layout...")); + editAction->setAutoRepeat(true); + editAction->setIcon(QIcon::fromTheme(QStringLiteral("document-edit"))); + editAction->setData(Plasma::Types::ControlAction); + editAction->setShortcut(QKeySequence(QStringLiteral("alt+d, e"))); + editAction->setShortcutContext(Qt::ApplicationShortcut); } void CoronaPrivate::toggleImmutability() { if (immutability == Types::Mutable) { q->setImmutability(Types::UserImmutable); } else { q->setImmutability(Types::Mutable); } } void CoronaPrivate::saveLayout(KSharedConfigPtr cg) const { KConfigGroup containmentsGroup(cg, "Containments"); foreach (const Containment *containment, containments) { QString cid = QString::number(containment->id()); KConfigGroup containmentConfig(&containmentsGroup, cid); containment->save(containmentConfig); } } void CoronaPrivate::updateContainmentImmutability() { foreach (Containment *c, containments) { // we need to tell each containment that immutability has been altered c->updateConstraints(Types::ImmutableConstraint); } } void CoronaPrivate::containmentDestroyed(QObject *obj) { // we do a static_cast here since it really isn't an Containment by this // point anymore since we are in the qobject dtor. we don't actually // try and do anything with it, we just need the value of the pointer // so this unsafe looking code is actually just fine. Containment *containment = static_cast(obj); int index = containments.indexOf(containment); if (index > -1) { containments.removeAt(index); q->requestConfigSync(); } } void CoronaPrivate::syncConfig() { q->config()->sync(); emit q->configSynced(); } Containment *CoronaPrivate::addContainment(const QString &name, const QVariantList &args, uint id, int lastScreen, bool delayedInit) { QString pluginName = name; Containment *containment = nullptr; Applet *applet = nullptr; // qCDebug(LOG_PLASMA) << "Loading" << name << args << id; if (pluginName.isEmpty() || pluginName == QLatin1String("default")) { // default to the desktop containment pluginName = desktopDefaultsConfig.readEntry("Containment", "org.kde.desktopcontainment"); } bool loadingNull = pluginName == QLatin1String("null"); if (!loadingNull) { applet = PluginLoader::self()->loadApplet(pluginName, id, args); containment = dynamic_cast(applet); if (containment) { containment->setParent(q); } } if (!containment) { if (!loadingNull) { #ifndef NDEBUG // qCDebug(LOG_PLASMA) << "loading of containment" << name << "failed."; #endif } // in case we got a non-Containment from Applet::loadApplet or // a null containment was requested if (applet) { // the applet probably doesn't know what's hit it, so let's pretend it can be // initialized to make assumptions in the applet's dtor safer applet->init(); delete applet; } applet = containment = new Containment(q, {}, id); if (lastScreen >= 0) { containment->d->lastScreen = lastScreen; } //if it's a dummy containment, just say its ui is ready, not blocking the corona applet->updateConstraints(Plasma::Types::UiReadyConstraint); // we want to provide something and don't care about the failure to launch containment->setFormFactor(Plasma::Types::Planar); } // if this is a new containment, we need to ensure that there are no stale // configuration data around if (id == 0) { KConfigGroup conf(q->config(), "Containments"); conf = KConfigGroup(&conf, QString::number(containment->id())); conf.deleteGroup(); } //make sure the containments are sorted by id auto position = std::lower_bound(containments.begin(), containments.end(), containment, [](Plasma::Containment *c1, Plasma::Containment *c2) { return c1->id() < c2->id(); }); containments.insert(position, containment); QObject::connect(containment, SIGNAL(destroyed(QObject*)), q, SLOT(containmentDestroyed(QObject*))); QObject::connect(containment, &Applet::configNeedsSaving, q, &Corona::requestConfigSync); QObject::connect(containment, &Containment::screenChanged, q, &Corona::screenOwnerChanged); if (!delayedInit) { containment->init(); KConfigGroup cg = containment->config(); containment->restore(cg); containment->updateConstraints(Plasma::Types::StartupCompletedConstraint); containment->save(cg); q->requestConfigSync(); containment->flushPendingConstraintsEvents(); emit q->containmentAdded(containment); //if id = 0 a new containment has been created, not restored if (id == 0) { emit q->containmentCreated(containment); } } return containment; } QList CoronaPrivate::importLayout(const KConfigGroup &conf, bool mergeConfig) { if (!conf.isValid()) { return QList(); } QList newContainments; QSet containmentsIds; foreach (Containment *containment, containments) { containmentsIds.insert(containment->id()); } KConfigGroup containmentsGroup(&conf, "Containments"); QStringList groups = containmentsGroup.groupList(); std::sort(groups.begin(), groups.end()); foreach (const QString &group, groups) { KConfigGroup containmentConfig(&containmentsGroup, group); if (containmentConfig.entryMap().isEmpty()) { continue; } uint cid = group.toUInt(); if (containmentsIds.contains(cid)) { cid = ++AppletPrivate::s_maxAppletId; } else if (cid > AppletPrivate::s_maxAppletId) { AppletPrivate::s_maxAppletId = cid; } if (mergeConfig) { KConfigGroup realConf(q->config(), "Containments"); realConf = KConfigGroup(&realConf, QString::number(cid)); // in case something was there before us realConf.deleteGroup(); containmentConfig.copyTo(&realConf); } //qCDebug(LOG_PLASMA) << "got a containment in the config, trying to make a" << containmentConfig.readEntry("plugin", QString()) << "from" << group; #ifndef NDEBUG // qCDebug(LOG_PLASMA) << "!!{} STARTUP TIME" << QTime().msecsTo(QTime::currentTime()) << "Adding Containment" << containmentConfig.readEntry("plugin", QString()); #endif Containment *c = addContainment(containmentConfig.readEntry("plugin", QString()), QVariantList(), cid, -1); if (!c) { continue; } newContainments.append(c); containmentsIds.insert(c->id()); #ifndef NDEBUG // qCDebug(LOG_PLASMA) << "!!{} STARTUP TIME" << QTime().msecsTo(QTime::currentTime()) << "Restored Containment" << c->pluginName(); #endif } if (!mergeConfig) { notifyContainmentsReady(); } return newContainments; } void CoronaPrivate::notifyContainmentsReady() { containmentsStarting = 0; foreach (Containment *containment, containments) { if (!containment->isUiReady() && containment->screen() >= 0) { ++containmentsStarting; QObject::connect(containment, &Plasma::Containment::uiReadyChanged, q, [this](bool ready) { containmentReady(ready); } ); } } if (containmentsStarting <= 0) { emit q->startupCompleted(); } } void CoronaPrivate::containmentReady(bool ready) { if (!ready) { return; } --containmentsStarting; if (containmentsStarting <= 0) { emit q->startupCompleted(); } } } // namespace Plasma #include "moc_corona.cpp" diff --git a/src/plasma/corona.h b/src/plasma/corona.h index 5a655a48d..a6e0df541 100644 --- a/src/plasma/corona.h +++ b/src/plasma/corona.h @@ -1,461 +1,462 @@ /* * Copyright 2007 Aaron Seigo * Copyright 2007 Matt Broadstone * Copyright 2012 Marco MArtin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef PLASMA_CORONA_H #define PLASMA_CORONA_H #include #include #include class QAction; namespace Plasma { class CoronaPrivate; /** * @class Corona plasma/Corona.h * * @short A bookkeeping Scene for Plasma::Applets */ class PLASMA_EXPORT Corona : public QObject { Q_OBJECT Q_PROPERTY(bool isStartupCompleted READ isStartupCompleted NOTIFY startupCompleted) + Q_PROPERTY(bool editMode READ isEditMode WRITE setEditMode NOTIFY editModeChanged) Q_PROPERTY(Package package READ package NOTIFY packageChanged) Q_PROPERTY(KPackage::Package kPackage READ kPackage NOTIFY kPackageChanged) public: explicit Corona(QObject *parent = nullptr); ~Corona(); #if PLASMA_ENABLE_DEPRECATED_SINCE(5, 6) /** * Accessor for the associated Package object if any. * A Corona package defines how Containments are laid out in a View, * ToolBoxes, default layout, error messages * and in genelal all the furniture specific of a particular * device form factor. * * @return the Package object, or an invalid one if none * @since 5.0 * @deprecated Since 5.6, use kPackage instead **/ PLASMA_DEPRECATED_VERSION(5, 6, "Use Corona::kPackage()") Plasma::Package package() const; #endif #if PLASMA_ENABLE_DEPRECATED_SINCE(5, 6) /** * Setting the package name * @deprecated Since 5.6, use setKPackage instead */ PLASMA_DEPRECATED_VERSION(5, 6, "Use Corona::setKPackage(const KPackage::Package &)") void setPackage(const Plasma::Package &package); #endif /** * Accessor for the associated Package object if any. * A Corona package defines how Containments are laid out in a View, * ToolBoxes, default layout, error messages * and in genelal all the furniture specific of a particular * device form factor. * * @return the Package object, or an invalid one if none * @since 5.5 **/ KPackage::Package kPackage() const; /** * Setting the package for the corona * @since 5.5 */ void setKPackage(const KPackage::Package &package); /** * @return all containments on this Corona */ QList containments() const; /** * @returns true when the startup is over, and * all the ui graphics has been instantiated */ bool isStartupCompleted() const; /** * Returns the config file used to store the configuration for this Corona */ KSharedConfig::Ptr config() const; /** * Adds a Containment to the Corona * * @param name the plugin name for the containment, as given by * KPluginInfo::pluginName(). If an empty string is passed in, the default * containment plugin will be used (usually DesktopContainment). If the * string literal "null" is passed in, then no plugin will be loaded and * a simple Containment object will be created instead. * @param args argument list to pass to the containment * * @return a pointer to the containment on success, or 0 on failure. Failure can be * caused by too restrictive of an Immutability type, as containments cannot be added * when widgets are locked. * If the requested containment plugin can not be located or successfully loaded, the Containment will have an invalid pluginInfo(). */ Containment *createContainment(const QString &name, const QVariantList &args = QVariantList()); /** * Returns the Containment for a given physical screen and desktop, creating one * if none exists * * @param screen number of the physical screen to locate * @param activity the activity id of the containment we want, * and empty string if the activity is not important * @param defaultPluginIfNonExistent the plugin to load by default; "null" won't * create it and "default" creates the default plugin * @param defaultArgs optional arguments to pass in when creating a Containment if needed * @since 5.45 */ Containment *containmentForScreen(int screen, const QString &activity, const QString &defaultPluginIfNonExistent, const QVariantList &defaultArgs = QVariantList()); //TODO KF6: add activity here, can't be done now as the overload would get confused #if PLASMA_ENABLE_DEPRECATED_SINCE(5, 46) /** * Returns the Containment, if any, for a given physical screen * * @param screen number of the physical screen to locate * @deprecated Since 5.46, use containmentForScreen(int, const QString &, const QString &, const QVariantList &) */ PLASMA_DEPRECATED_VERSION(5, 46, "Use Corona::containmentForScreen(int, const QString &, const QString &, const QVariantList &)") Containment *containmentForScreen(int screen) const; #endif #if PLASMA_ENABLE_DEPRECATED_SINCE(5, 46) /** * Returns the Containment for a given physical screen and desktop, creating one * if none exists * * @param screen number of the physical screen to locate * @param defaultPluginIfNonExistent the plugin to load by default; "null" is an empty * Containment and "default" creates the default plugin * @param defaultArgs optional arguments to pass in when creating a Containment if needed * @deprecated Since 5.46, use containmentForScreen(int, const QString &, const QString &, const QVariantList &) */ PLASMA_DEPRECATED_VERSION(5, 46, "Use Corona::containmentForScreen(int, const QString &, const QString &, const QVariantList &)") Containment *containmentForScreen(int screen, const QString &defaultPluginIfNonExistent, const QVariantList &defaultArgs = QVariantList()); #endif /** * Returns all containments which match a particular activity, for any screen * @param activity the activity id we want * @returns the list of matching containments if any, empty if activity is an empty string * @since 5.45 */ QList containmentsForActivity(const QString &activity); /** * Returns all containments which match a particular screen, for any activity * @param screen the screen number we want * @returns the list of matching containments if any, empty if screen is < 0 * @since 5.45 */ QList containmentsForScreen(int screen); /** * Returns the number of screens available to plasma. * Subclasses should override this method as the default * implementation returns a meaningless value. */ virtual int numScreens() const; /** * Returns the geometry of a given screen. * Valid screen ids are 0 to numScreen()-1, or -1 for the full desktop geometry. * Subclasses should override this method as the default * implementation returns a meaningless value. */ virtual QRect screenGeometry(int id) const = 0; /** * Returns the available region for a given screen. * The available region excludes panels and similar windows. * Valid screen ids are 0 to numScreens()-1. * By default this method returns a rectangular region * equal to screenGeometry(id); subclasses that need another * behavior should override this method. */ virtual QRegion availableScreenRegion(int id) const; /** * Returns the available rect for a given screen. * The difference between this and availableScreenRegion() * is that this method returns only a rectangular * available space (it doesn't care if your panel is not 100% width). * The available rect excludes panels and similar windows. * Valid screen ids are 0 to numScreens()-1. * By default this method returns a rectangular region * equal to screenGeometry(id); subclasses that need another * behavior should override this method. */ virtual QRect availableScreenRect(int id) const; /** * This method is useful in order to retrieve the list of available * screen edges for panel type containments. * @param screen the id of the screen to look for free edges. * @returns a list of free edges not filled with panel type containments. */ QList freeEdges(int screen) const; /** * The actions associated with this Corona */ KActionCollection *actions() const; /** * Imports an applet layout from a config file. The results will be added to the * current set of Containments. * * @param config the name of the config file to load from, * or the default config file if QString() * @return the list of containments that were loaded * @since 4.6 */ QList importLayout(const KConfigGroup &config); /** * Exports a set of containments to a config file. * * @param config the config group to save to * @param containments the list of containments to save * @since 4.6 */ void exportLayout(KConfigGroup &config, QList containments); /** * @returns the id of the screen which is showing @p containment * -1 is returned if the containment is not associated with a screen. */ virtual int screenForContainment(const Containment *containment) const; /** * @return The type of immutability of this Corona */ Types::ImmutabilityType immutability() const; /** * Set the Corona globally into "edit mode" * Only when the corona is of mutable type can be set of edit mode. * This indicates the UI to make easy for the user to manipulate applets. * @param edit * @since 5.63 */ void setEditMode(bool edit); /** * @returns true if the corona is in edit mode * @since 5.63 */ bool isEditMode() const; public Q_SLOTS: /** * Load applet layout from a config file. The results will be added to the * current set of Containments. * * @param config the name of the config file to load from, * or the default config file if QString() */ void loadLayout(const QString &config = QString()); /** * Save applets layout to file * @param config the file to save to, or the default config file if QString() */ void saveLayout(const QString &config = QString()) const; /** * Sets the immutability type for this Corona (not immutable, * user immutable or system immutable) * @param immutable the new immutability type of this applet */ void setImmutability(const Types::ImmutabilityType immutable); /** * Schedules a flush-to-disk synchronization of the configuration state * at the next convenient moment. */ void requestConfigSync(); /** * Schedules a time sensitive flush-to-disk synchronization of the * configuration state. Since this method does not provide any sort of * event compression, it should only be used when an *immediate* disk * sync is *absolutely* required. Otherwise, use @see requestConfigSync() * which does do event compression. */ void requireConfigSync(); Q_SIGNALS: /** * This signal indicates a new containment has been added to * the Corona: it may occur after creation or restore from config */ void containmentAdded(Plasma::Containment *containment); /** * This signal indicates a new containment has been created * in the Corona. Compared to containmentAdded it can only happen * after the creation of a new containment. * * @see containmentAdded * @since 5.16 */ void containmentCreated(Plasma::Containment *containment); /** * This signal indicates that a containment has been newly * associated (or dissociated) with a physical screen. * * @param isScreen the screen it is now associated with */ void screenOwnerChanged(int isScreen); /** * This signal indicates that the configuration file was flushed to disk. */ void configSynced(); /** * This signal indicates that a change in available screen geometry occurred. */ void availableScreenRegionChanged(); /** * This signal indicates that a change in available screen geometry occurred. */ void availableScreenRectChanged(); /** * This signal indicates that a change in geometry for the screen occurred. */ void screenGeometryChanged(int id); /** * emitted when immutability changes. * this is for use by things that don't get constraints events, like plasmaapp. * it's NOT for containments or applets or any of the other stuff on the scene. * if your code's not in shells/ it probably shouldn't be using it. */ void immutabilityChanged(Plasma::Types::ImmutabilityType immutability); /** This signal indicates the screen with the specified id was removed. * @since 5.40 */ void screenRemoved(int id); /** This signal indicates a new screen with the specified id was added. * @since 5.40 */ void screenAdded(int id); /** * emitted when the editMode state changes * @see isEditMode() * @since 5.63 */ - void editModeChanged(); + void editModeChanged(bool edit); #if PLASMA_ENABLE_DEPRECATED_SINCE(5, 6) /** * Emitted when the package for this corona has been changed. * Shells must support changing the shell package on the fly (for instance due to device form factor changing) * * @param package the new package that defines the Corona furniture and behavior * @deprecated Since 5.6, use kPackageChanged instead */ PLASMA_DEPRECATED_VERSION(5, 6, "Use Corona::kPackageChanged(const KPackage::Package &)") void packageChanged(const Plasma::Package &package); #endif /** * Emitted when the package for this corona has been changed. * Shells must support changing the shell package on the fly (for instance due to device form factor changing) * * @param package the new package that defines the Corona furniture and behavior */ void kPackageChanged(const KPackage::Package &package); /** * Emitted when the startup phase has been completed */ void startupCompleted(); protected: /** * Loads the default (system wide) layout for this user **/ virtual void loadDefaultLayout(); /** * Loads a containment with delayed initialization, primarily useful * for implementations of loadDefaultLayout. The caller is responsible * for all initialization, saving and notification of a new containment. * * @param name the plugin name for the containment, as given by * KPluginInfo::pluginName(). If an empty string is passed in, the default * containment plugin will be used (usually DesktopContainment). If the * string literal "null" is passed in, then no plugin will be loaded and * a simple Containment object will be created instead. * @param args argument list to pass to the containment * * @return a pointer to the containment on success, or 0 on failure. Failure can * be caused by the Immutability type being too restrictive, as containments can't be added * when widgets are locked, or if the requested containment plugin can not be located * or successfully loaded. * @see addContainment **/ Containment *createContainmentDelayed(const QString &name, const QVariantList &args = QVariantList()); private: CoronaPrivate *const d; Q_PRIVATE_SLOT(d, void containmentDestroyed(QObject *)) Q_PRIVATE_SLOT(d, void syncConfig()) Q_PRIVATE_SLOT(d, void toggleImmutability()) Q_PRIVATE_SLOT(d, void containmentReady(bool)) friend class CoronaPrivate; friend class View; }; } // namespace Plasma #endif