diff --git a/shell/CMakeLists.txt b/shell/CMakeLists.txt --- a/shell/CMakeLists.txt +++ b/shell/CMakeLists.txt @@ -45,7 +45,6 @@ DEFAULT_SEVERITY Info) set (plasma_shell_SRCS - activity.cpp alternativeshelper.cpp main.cpp containmentconfigview.cpp diff --git a/shell/activity.h b/shell/activity.h deleted file mode 100644 --- a/shell/activity.h +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright 2010 Chani Armitage - * Copyright 2016 Ivan Cukic - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU 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 ACTIVITY_H -#define ACTIVITY_H - -#include -#include - -#include -#include - -#include - -class QSize; -class QString; -class QPixmap; -class KConfig; - -namespace KActivities -{ - class Controller; -} // namespace KActivities - - -namespace Plasma -{ - class Corona; -} // namespace Plasma - -/** - * This class represents one activity. - * an activity has an ID and a name, from nepomuk. - * it also is associated with one or more containments. - * - * do NOT construct these yourself; use DesktopCorona::activity() - */ -class Activity : public QObject -{ - Q_OBJECT -public: - Activity(const QString &id, Plasma::Corona *parent = 0); - ~Activity() override; - - QString id() const; - QString name() const; - QPixmap pixmap(const QSize &size) const; //FIXME do we want diff. sizes? updates? - - /** - * whether this is the currently active activity - */ - bool isCurrent() const; - - /** - * state of the activity - */ - KActivities::Info::State state() const; - - /** - * set the plugin to use when creating new containments - */ - void setDefaultPlugin(const QString &plugin); - - /** - * The plugin to use when creating new containments - */ - QString defaultPlugin() const; - - /** - * @returns the info object for this activity - */ - const KActivities::Info * info() const; - - KConfigGroup config() const; - -Q_SIGNALS: - void infoChanged(); - void stateChanged(); - void currentStatusChanged(); - - void removed(); - void opened(); - void closed(); - -public Q_SLOTS: - void setName(const QString &name); - void setIcon(const QString &icon); - - /** - * delete the activity forever - */ - void remove(); - - /** - * make this activity the current activity - */ - void activate(); - - /** - * save and remove all our containments - */ - void close(); - - /** - * load the saved containment(s) for this activity - */ - void open(); - -private Q_SLOTS: - void cleanupActivity(); - -private: - KActivities::Info m_info; - QString m_plugin; - std::shared_ptr m_activityController; - -}; - -#endif diff --git a/shell/activity.cpp b/shell/activity.cpp deleted file mode 100644 --- a/shell/activity.cpp +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright 2010 Chani Armitage - * Copyright 2016 Ivan Cukic - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU 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 "shellcorona.h" -#include "kidenticongenerator.h" - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include - -#include - -#include "activity.h" - -#include -// #include - -namespace { - std::shared_ptr activitiesControllerInstance() - { - static std::weak_ptr s_instance; - - // TODO: If it turns out we need these in multiple threads, - // all hell will break loose (well, not really) - // static std::mutex sharedSingleton; - // std::lock_guard sharedSingletonLock(sharedSingleton); - - auto result = s_instance.lock(); - - if (s_instance.expired()) { - result.reset(new KActivities::Controller()); - s_instance = result; - } - - return result; - } - -} - -Activity::Activity(const QString &id, Plasma::Corona *parent) - : QObject(parent), - m_info(id), - m_plugin(QStringLiteral("org.kde.desktopcontainment")),//FIXME ask the corona - m_activityController(activitiesControllerInstance()) -{ - connect(&m_info, &KActivities::Info::stateChanged, this, &Activity::stateChanged); - connect(&m_info, &KActivities::Info::started, this, &Activity::opened); - connect(&m_info, &KActivities::Info::stopped, this, &Activity::closed); - connect(&m_info, &KActivities::Info::removed, this, &Activity::removed); - connect(&m_info, &KActivities::Info::removed, this, &Activity::cleanupActivity); -} - -Activity::~Activity() -{ -} - -QString Activity::id() const -{ - return m_info.id(); -} - -QString Activity::name() const -{ - return m_info.name(); -} - -QPixmap Activity::pixmap(const QSize &size) const -{ - if (m_info.isValid() && !m_info.icon().isEmpty()) { - return QIcon::fromTheme(m_info.icon()).pixmap(size); - } else { - return QIcon().pixmap(size); - } -} - -bool Activity::isCurrent() const -{ - return m_info.isCurrent(); -} - -KActivities::Info::State Activity::state() const -{ - return m_info.state(); -} - -void Activity::remove() -{ - m_activityController->removeActivity(m_info.id()); -} - -void Activity::cleanupActivity() -{ - const QString name = "activities/" + m_info.id(); - QFile::remove(QStandardPaths::writableLocation(QStandardPaths::DataLocation)+QChar('/')+name); -} - -void Activity::activate() -{ - m_activityController->setCurrentActivity(m_info.id()); -} - -void Activity::setName(const QString &name) -{ - m_activityController->setActivityName(m_info.id(), name); -} - -void Activity::setIcon(const QString &icon) -{ - m_activityController->setActivityIcon(m_info.id(), icon); -} - -void Activity::close() -{ - m_activityController->stopActivity(m_info.id()); -} - -KConfigGroup Activity::config() const -{ - const QString name = "activities/" + m_info.id(); - KConfig external(name, KConfig::SimpleConfig, QStandardPaths::GenericDataLocation); - - //passing an empty string for the group name turns a kconfig into a kconfiggroup - return external.group(QString()); -} - -void Activity::open() -{ - m_activityController->startActivity(m_info.id()); -} - -void Activity::setDefaultPlugin(const QString &plugin) -{ - m_plugin = plugin; - //FIXME save&restore this setting -} - -QString Activity::defaultPlugin() const -{ - return m_plugin; -} - -const KActivities::Info * Activity::info() const -{ - return &m_info; -} - - - -// vim: sw=4 sts=4 et tw=100 diff --git a/shell/scripting/scriptengine.cpp b/shell/scripting/scriptengine.cpp --- a/shell/scripting/scriptengine.cpp +++ b/shell/scripting/scriptengine.cpp @@ -49,7 +49,6 @@ #include "i18n.h" #include "panel.h" #include "widget.h" -#include "../activity.h" #include "../shellcorona.h" #include "../standaloneappcorona.h" @@ -171,7 +170,7 @@ } const QString name = context->argument(0).toString(); - const QString plugin = context->argument(1).toString(); + QString plugin = context->argument(1).toString(); ScriptEngine *env = envFor(engine); @@ -189,23 +188,19 @@ loop.exec(); QString id = futureId.result(); - Activity *a = new Activity(id, env->m_corona); - qDebug() << "Setting default Containment plugin:" << plugin; if (plugin.isEmpty() || plugin == QLatin1String("undefined")) { KConfigGroup shellCfg = KConfigGroup(KSharedConfig::openConfig(env->m_corona->package().filePath("defaults")), "Desktop"); - a->setDefaultPlugin(shellCfg.readEntry("Containment", "org.kde.desktopcontainment")); - } else { - a->setDefaultPlugin(plugin); + plugin = shellCfg.readEntry("Containment", "org.kde.desktopcontainment"); } ShellCorona *sc = qobject_cast(env->m_corona); StandaloneAppCorona *ac = qobject_cast(env->m_corona); if (sc) { - sc->insertActivity(id, a); + sc->insertActivity(id, plugin); } else if (ac) { - ac->insertActivity(id, a); + ac->insertActivity(id, plugin); } return QScriptValue(id); diff --git a/shell/shellcorona.h b/shell/shellcorona.h --- a/shell/shellcorona.h +++ b/shell/shellcorona.h @@ -32,7 +32,6 @@ #include -class Activity; class DesktopView; class PanelView; class QMenu; @@ -94,8 +93,7 @@ KActivities::Controller *activityController(); //Those two are a bit of an hack but are just for desktop scripting - Activity *activity(const QString &id); - void insertActivity(const QString &id, Activity *activity); + void insertActivity(const QString &id, const QString &plugin); Plasma::Containment *setContainmentTypeForScreen(int screen, const QString &plugin); @@ -218,7 +216,7 @@ QHash m_panelViews; KConfigGroup m_desktopDefaultsConfig; QList m_waitingPanels; - QHash m_activities; + QHash m_activityContainmentPlugins; QHash > m_desktopContainments; QAction *m_addPanelAction; QMenu *m_addPanelsMenu; diff --git a/shell/shellcorona.cpp b/shell/shellcorona.cpp --- a/shell/shellcorona.cpp +++ b/shell/shellcorona.cpp @@ -53,7 +53,6 @@ #include "config-ktexteditor.h" // HAVE_KTEXTEDITOR #include "alternativeshelper.h" -#include "activity.h" #include "desktopview.h" #include "panelview.h" #include "scripting/scriptengine.h" @@ -910,11 +909,8 @@ return *it; } - QString plugin; - Activity* a = m_activities.value(activity); - if (a && !a->defaultPlugin().isEmpty()) { - plugin = a->defaultPlugin(); - } else { + QString plugin = m_activityContainmentPlugins.value(activity); + if (plugin.isEmpty()) { plugin = m_desktopDefaultsConfig.readEntry("Containment", "org.kde.desktopcontainment"); } @@ -1213,30 +1209,23 @@ void ShellCorona::activityAdded(const QString &id) { //TODO more sanity checks - if (m_activities.contains(id)) { + if (m_activityContainmentPlugins.contains(id)) { qWarning() << "Activity added twice" << id; return; } - Activity *a = new Activity(id, this); - a->setDefaultPlugin(m_desktopDefaultsConfig.readEntry("Containment", "org.kde.desktopcontainment")); - m_activities.insert(id, a); + const QString plugin = m_desktopDefaultsConfig.readEntry("Containment", "org.kde.desktopcontainment"); + m_activityContainmentPlugins.insert(id, plugin); } void ShellCorona::activityRemoved(const QString &id) { - Activity *a = m_activities.take(id); - a->deleteLater(); -} - -Activity *ShellCorona::activity(const QString &id) -{ - return m_activities.value(id); + m_activityContainmentPlugins.remove(id); } -void ShellCorona::insertActivity(const QString &id, Activity *activity) +void ShellCorona::insertActivity(const QString &id, const QString &plugin) { - m_activities.insert(id, activity); + m_activityContainmentPlugins.insert(id, plugin); for (int i = 0; i < m_views.count(); ++i) { Plasma::Containment *c = createContainmentForActivity(id, i); if (c) { diff --git a/shell/standaloneappcorona.h b/shell/standaloneappcorona.h --- a/shell/standaloneappcorona.h +++ b/shell/standaloneappcorona.h @@ -25,8 +25,6 @@ #include #include "desktopview.h" -class Activity; - namespace KActivities { class Consumer; } @@ -45,7 +43,7 @@ Plasma::Containment *createContainmentForActivity(const QString& activity, int screenNum); - void insertActivity(const QString &id, Activity *activity); + void insertActivity(const QString &id, const QString &plugin); Plasma::Containment *addPanel(const QString &plugin); public Q_SLOTS: @@ -64,7 +62,7 @@ KActivities::Consumer *m_activityConsumer; KConfigGroup m_desktopDefaultsConfig; DesktopView *m_view; - QHash m_activities; + QHash m_activityContainmentPlugins; }; #endif diff --git a/shell/standaloneappcorona.cpp b/shell/standaloneappcorona.cpp --- a/shell/standaloneappcorona.cpp +++ b/shell/standaloneappcorona.cpp @@ -21,7 +21,6 @@ #include "standaloneappcorona.h" #include "desktopview.h" -#include "activity.h" #include #include @@ -162,19 +161,17 @@ void StandaloneAppCorona::activityAdded(const QString &id) { //TODO more sanity checks - if (m_activities.contains(id)) { + if (m_activityContainmentPlugins.contains(id)) { qWarning() << "Activity added twice" << id; return; } - Activity *a = new Activity(id, this); - m_activities.insert(id, a); + m_activityContainmentPlugins.insert(id, QString()); } void StandaloneAppCorona::activityRemoved(const QString &id) { - Activity *a = m_activities.take(id); - a->deleteLater(); + m_activityContainmentPlugins.remove(id); } void StandaloneAppCorona::currentActivityChanged(const QString &newActivity) @@ -205,9 +202,9 @@ return; } -void StandaloneAppCorona::insertActivity(const QString &id, Activity *activity) +void StandaloneAppCorona::insertActivity(const QString &id, const QString &plugin) { - m_activities.insert(id, activity); + m_activityContainmentPlugins.insert(id, plugin); Plasma::Containment *c = createContainmentForActivity(id, 0); if (c) { c->config().writeEntry("lastScreen", 0); @@ -217,7 +214,7 @@ Plasma::Containment *StandaloneAppCorona::addPanel(const QString &plugin) { //this creates a panel that wwill be used for nothing - //it's needed by the scriptengine to create + //it's needed by the scriptengine to create //a corona useful also when launched in fullshell Plasma::Containment *panel = createContainment(plugin); if (!panel) {