[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdebase/workspace/plasma/desktop/shell
From:       Chani Armitage <chanika () gmail ! com>
Date:       2010-11-09 19:54:43
Message-ID: 20101109195443.26541AC8A2 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1194756 by chani:

hook up the session stuff to the UI :) :)

 M  +44 -23    activity.cpp  
 M  +13 -10    activity.h  
 M  +14 -6     activitymanager/activityicon.cpp  
 M  +2 -22     activitymanager/activitylist.cpp  
 M  +0 -2      activitymanager/activitylist.h  
 M  +1 -1      desktopcorona.cpp  


--- trunk/KDE/kdebase/workspace/plasma/desktop/shell/activity.cpp #1194755:1194756
@@ -20,7 +20,6 @@
 #include "desktopcorona.h"
 #include "plasma-shell-desktop.h"
 #include "kactivitycontroller.h"
-#include "kactivityinfo.h"
 #include "activitymanager/kidenticongenerator.h"
 
 #include <QPixmap>
@@ -48,13 +47,19 @@
       m_info(new KActivityInfo(id, this))
 {
     connect(m_info, SIGNAL(infoChanged()), this, SLOT(activityChanged()));
+    connect(m_info, SIGNAL(stateChanged(KActivityInfo::State)), this, \
SLOT(activityStateChanged(KActivityInfo::State))); +    connect(m_info, \
SIGNAL(started()), this, SLOT(opened())); +    connect(m_info, SIGNAL(stopped()), \
this, SLOT(closed())); +    connect(m_info, SIGNAL(removed()), this, \
SLOT(removed()));  
     if (m_info) {
         m_name = m_info->name();
         m_icon = m_info->icon();
+        m_state = m_info->state();
     } else {
         m_name = m_id;
         m_icon = QString();
+        m_state = KActivityInfo::Invalid;
     }
 
     m_corona = qobject_cast<DesktopCorona*>(PlasmaApp::self()->corona());
@@ -68,7 +73,7 @@
         }
     }
 
-    kDebug() << m_containments.size();
+    //kDebug() << m_containments.size();
 }
 
 Activity::~Activity()
@@ -81,6 +86,12 @@
     setIcon(m_info->icon());
 }
 
+void Activity::activityStateChanged(KActivityInfo::State state)
+{
+    m_state = state;
+    emit stateChanged();
+}
+
 QString Activity::id()
 {
     return m_id;
@@ -100,24 +111,32 @@
     }
 }
 
-bool Activity::isActive()
+bool Activity::isCurrent()
 {
     KActivityConsumer c;
     return m_id == c.currentActivity();
     //TODO maybe plasmaapp should cache the current activity to reduce dbus calls?
 }
 
-bool Activity::isRunning()
+KActivityInfo::State Activity::state()
 {
-    return !m_containments.isEmpty();
+    return m_state;
 }
 
-void Activity::destroy()
+void Activity::remove()
 {
     KActivityController().removeActivity(m_id);
+}
+
+void Activity::removed()
+{
+    if (! m_containments.isEmpty()) {
+        //FIXME only m_corona has authority to remove properly
+        kDebug() << "!!!!! if your widgets are locked you've hit a BUG now";
     foreach (Plasma::Containment *c, m_containments) {
         c->destroy(false);
     }
+    }
 
     const QString name = "activities/" + m_id;
     QFile::remove(KStandardDirs::locateLocal("appdata", name));
@@ -178,7 +197,7 @@
 void Activity::ensureActive()
 {
     if (m_containments.isEmpty()) {
-        open();
+        opened();
     }
 
     //ensure there's a containment for every screen & desktop.
@@ -257,6 +276,11 @@
 
 void Activity::close()
 {
+    KActivityController().stopActivity(m_id);
+}
+
+void Activity::closed()
+{
     const QString name = "activities/" + m_id;
     KConfig external(name, KConfig::SimpleConfig, "appdata");
 
@@ -264,22 +288,12 @@
     KConfigGroup group = external.group(QString());
     m_corona->exportLayout(group, m_containments.values());
 
+    //hrm, shouldn't the containments' deleted signals have done this for us?
+    if (! m_containments.isEmpty()) {
+        kDebug() << "isn't close supposed to *remove* containments??";
     m_containments.clear();
-    emit closed();
-    //TODO save a thumbnail to a file too
-
-    KActivityController controller;
-    if (controller.currentActivity() == m_id) {
-        //activate someone else
-        //TODO we could use a better strategy here
-        QStringList list = controller.listActivities();
-        QString next = list.first();
-        if (next == m_id && list.count() > 1) {
-            next = list.at(1);
         }
-        controller.setCurrentActivity(next);
     }
-}
 
 void Activity::replaceContainment(Plasma::Containment* containment)
 {
@@ -294,7 +308,7 @@
     //desktop -1 and 0 should share the same containment (for when PVD is changed)
     if (desktop == -1) {
         desktop = 0;
-        kDebug() << "desktop was -1";
+        //kDebug() << "desktop was -1";
     }
 
     kDebug() << screen << desktop;
@@ -345,11 +359,19 @@
 
 void Activity::open()
 {
+    KActivityController().startActivity(m_id);
+}
+
+void Activity::opened()
+{
+    if (! m_containments.isEmpty()) {
+        kDebug() << "already open!";
+        return;
+    }
     QString fileName = "activities/";
     fileName += m_id;
     KConfig external(fileName, KConfig::SimpleConfig, "appdata");
 
-    //TODO only load existing screens
     foreach (Plasma::Containment *newContainment, \
m_corona->importLayout(external.group(QByteArray()))) {  \
                insertContainment(newContainment);
         //ensure it's hooked up (if something odd happened we don't want orphan \
containments) @@ -369,7 +391,6 @@
 
     m_corona->requireConfigSync();
     external.sync();
-    emit opened();
 }
 
 void Activity::setDefaultPlugin(const QString &plugin)
--- trunk/KDE/kdebase/workspace/plasma/desktop/shell/activity.h #1194755:1194756
@@ -23,10 +23,11 @@
 #include <QObject>
 #include <QHash>
 
+#include "kactivityinfo.h"
+
 class QSize;
 class QString;
 class QPixmap;
-class KActivityInfo;
 class KConfig;
 class DesktopCorona;
 namespace Plasma
@@ -56,11 +57,11 @@
     /**
      * whether this is the currently active activity
      */
-    bool isActive();
+    bool isCurrent();
     /**
-     * whether this is one of the activities currently loaded
+     * state of the activity
      */
-    bool isRunning();
+    KActivityInfo::State state();
 
     /**
      * save (copy) the activity out to an @p external config
@@ -90,12 +91,8 @@
 
 signals:
     void infoChanged();
+    void stateChanged();
 
-    void opened();
-    void closed();
-
-//TODO signals for other changes
-
 public slots:
     void setName(const QString &name);
     void setIcon(const QString &icon);
@@ -103,7 +100,7 @@
     /**
      * delete the activity forever
      */
-    void destroy();
+    void remove();
 
     /**
      * make this activity the current activity
@@ -129,7 +126,12 @@
     void updateActivityName(Plasma::Context *context);
     void containmentDestroyed(QObject *object);
     void activityChanged();
+    void activityStateChanged(KActivityInfo::State);
 
+    void removed();
+    void opened();
+    void closed();
+
 private:
     void activateContainment(int screen, int desktop);
     void insertContainment(Plasma::Containment* cont, bool force=false);
@@ -140,6 +142,7 @@
     QString m_name;
     QString m_icon;
     QString m_plugin;
+    KActivityInfo::State m_state;
     QHash<QPair<int,int>, Plasma::Containment*> m_containments;
     KActivityInfo *m_info;
     DesktopCorona *m_corona;
--- trunk/KDE/kdebase/workspace/plasma/desktop/shell/activitymanager/activityicon.cpp \
#1194755:1194756 @@ -96,8 +96,7 @@
     DesktopCorona *c = qobject_cast<DesktopCorona*>(PlasmaApp::self()->corona());
     m_activity = c->activity(id);
     connect(this, SIGNAL(clicked(Plasma::AbstractIcon*)), m_activity, \
                SLOT(activate()));
-    connect(m_activity, SIGNAL(opened()), this, SLOT(updateButtons()));
-    connect(m_activity, SIGNAL(closed()), this, SLOT(updateButtons()));
+    connect(m_activity, SIGNAL(stateChanged()), this, SLOT(updateButtons()));
     connect(m_activity, SIGNAL(infoChanged()), this, SLOT(updateContents()));
     setName(m_activity->name());
 
@@ -178,7 +177,7 @@
 {
     ActivityControls * w = new ActivityRemovalConfirmation(this);
 
-    connect(w, SIGNAL(removalConfirmed()), m_activity, SLOT(destroy()));
+    connect(w, SIGNAL(removalConfirmed()), m_activity, SLOT(remove()));
 
     showInlineWidget(w);
 }
@@ -312,7 +311,8 @@
         A = 0;                             \
     }
 
-    if (m_activity->isRunning()) {
+    switch (m_activity->state()) {
+    case KActivityInfo::Running:
         DESTROY_ACTIVITY_ACTION_WIDIGET(m_buttonStart);
         DESTROY_ACTIVITY_ACTION_WIDIGET(m_buttonRemove);
 
@@ -323,8 +323,9 @@
         } else {
             DESTROY_ACTIVITY_ACTION_WIDIGET(m_buttonStop);
         }
+        break;
 
-    } else {
+    case KActivityInfo::Stopped:
         DESTROY_ACTIVITY_ACTION_WIDIGET(m_buttonStop);
 
         if (!m_buttonRemove) {
@@ -334,7 +335,13 @@
         if (!m_buttonStart) {
             m_buttonStart = new ActivityActionWidget(this, "startActivity", \
START_ICON, i18n("Stop activity"), QSize(32, 32));  }
+        break;
 
+    default: //transitioning or invalid: don't let the user mess with it
+        DESTROY_ACTIVITY_ACTION_WIDIGET(m_buttonStart);
+        DESTROY_ACTIVITY_ACTION_WIDIGET(m_buttonRemove);
+        DESTROY_ACTIVITY_ACTION_WIDIGET(m_buttonStop);
+        DESTROY_ACTIVITY_ACTION_WIDIGET(m_buttonConfigure);
     }
 
 #undef DESTROY_ACTIVITY_ACTION_WIDIGET
@@ -367,7 +374,8 @@
         return;
     }
 
-    setSelected(m_activity->isActive());
+    //a dbus call during paint; this can be optimized :)
+    setSelected(m_activity->isCurrent());
 
     AbstractIcon::paint(painter, option, widget);
 }
--- trunk/KDE/kdebase/workspace/plasma/desktop/shell/activitymanager/activitylist.cpp \
#1194755:1194756 @@ -64,8 +64,7 @@
     ActivityIcon *icon = new ActivityIcon(id);
     addIcon(icon);
     m_allAppletsHash.insert(id, icon);
-    connect(icon->activity(), SIGNAL(opened()), this, SLOT(activityOpened()));
-    connect(icon->activity(), SIGNAL(closed()), this, SLOT(activityClosed()));
+    connect(icon->activity(), SIGNAL(stateChanged()), this, SLOT(updateClosable()));
 }
 /*
 void AppletsListWidget::appletIconDoubleClicked(AbstractIcon *icon)
@@ -118,11 +117,6 @@
     updateList();
 }
 
-void ActivityList::activityClosed()
-{
-    updateClosable();
-}
-
 void ActivityList::updateClosable()
 {
     ActivityIcon * running = 0;
@@ -131,7 +125,7 @@
     foreach (Plasma::AbstractIcon *i, m_allAppletsHash) {
         ActivityIcon *icon = qobject_cast<ActivityIcon*>(i);
 
-        if (icon && icon->activity()->isRunning()) {
+        if (icon && icon->activity()->state() == KActivityInfo::Running) {
             if (running) {
                 //found two, no worries
                 twoRunning = true;
@@ -151,17 +145,3 @@
         running->setClosable(false);
     }
 }
-
-void ActivityList::activityOpened()
-{
-    updateClosable();
-
-//    foreach (Plasma::AbstractIcon *i, m_allAppletsHash) {
-//        ActivityIcon *icon = qobject_cast<ActivityIcon*>(i);
-//        if (icon && icon->activity()->isRunning()) {
-//            icon->setClosable(true);
-//        }
-//    }
-}
-
-
--- trunk/KDE/kdebase/workspace/plasma/desktop/shell/activitymanager/activitylist.h \
#1194755:1194756 @@ -46,8 +46,6 @@
 private Q_SLOTS:
     void activityAdded(const QString &id);
     void activityRemoved(const QString &id);
-    void activityOpened();
-    void activityClosed();
 
     void updateClosable();
 
--- trunk/KDE/kdebase/workspace/plasma/desktop/shell/desktopcorona.cpp \
#1194755:1194756 @@ -636,7 +636,7 @@
     }
 
     Activity *a = new Activity(id, this);
-    if (a->isActive()) {
+    if (a->isCurrent()) {
         a->ensureActive();
     }
     m_activities.insert(id, a);


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic