← Back to team overview

ayatana-commits team mailing list archive

[Branch ~agateau/plasma-widget-message-indicator/trunk] Rev 113: Use Plasma::setStatus() so that the widget autohides in systemtray

 

------------------------------------------------------------
revno: 113
committer: Aurelien Gateau <aurelien.gateau@xxxxxxxxxxxxx>
branch nick: plasma-widget-message-indicator
timestamp: Mon 2010-02-15 11:09:31 +0100
message:
  Use Plasma::setStatus() so that the widget autohides in systemtray
modified:
  src/message-indicator.cpp
  src/message-indicator.h


--
lp:plasma-widget-message-indicator
https://code.launchpad.net/~agateau/plasma-widget-message-indicator/trunk

Your team ayatana-commits is subscribed to branch lp:plasma-widget-message-indicator.
To unsubscribe from this branch go to https://code.launchpad.net/~agateau/plasma-widget-message-indicator/trunk/+edit-subscription.
=== modified file 'src/message-indicator.cpp'
--- src/message-indicator.cpp	2010-02-12 11:43:16 +0000
+++ src/message-indicator.cpp	2010-02-15 10:09:31 +0000
@@ -68,7 +68,7 @@
     mCurrentWidget = mNoIndicatorLabel;
 
     setWidget(mStack);
-    updateIconState();
+    updateStatus();
 }
 
 MessageIndicator::~MessageIndicator()
@@ -100,8 +100,7 @@
     layout->addItem(mIconWidget);
 
     connect(mIconWidget, SIGNAL(clicked()), SLOT(togglePopup()));
-    updateIcon(false /* no new stuff */);
-    updateIconState();
+    updateStatus();
 }
 
 void MessageIndicator::initSourceModel()
@@ -218,15 +217,9 @@
     hidePopup();
 }
 
-void MessageIndicator::slotRowsChanged(const QModelIndex& parent)
+void MessageIndicator::slotRowsChanged(const QModelIndex& /*parent*/)
 {
-    if (!parent.isValid()) {
-        // A server has been added or removed
-        updateIconState();
-        return;
-    }
-
-    updateIconFromIndicators();
+    updateStatus();
 
     #ifdef DUMP_MODELS
     dumpModels();
@@ -235,33 +228,35 @@
 
 void MessageIndicator::slotDrawAttentionChanged()
 {
-    updateIconFromIndicators();
+    updateStatus();
 
     #ifdef DUMP_MODELS
     dumpModels();
     #endif
 }
 
-void MessageIndicator::updateIcon(bool newStuff)
-{
-    mIconWidget->setIcon(newStuff ? NEW_STUFF_ICON : NO_NEW_STUFF_ICON);
-}
-
-void MessageIndicator::updateIconFromIndicators()
-{
-    // Check if one of the indicators want to draw attention
-    QModelIndexList lst = mSourceModel->match(mSourceModel->index(0, 0),
-                                              ListenerModel::IndicatorDrawAttentionRole,
-                                              QVariant(true),
-                                              1 /* hits */,
-                                              Qt::MatchExactly | Qt::MatchRecursive);
-
-    updateIcon(!lst.isEmpty());
-}
-
-void MessageIndicator::updateIconState()
-{
-    if (!mSourceModel || mSourceModel->rowCount() == 0) {
+void MessageIndicator::updateStatus()
+{
+    Plasma::ItemStatus status;
+    if (mSourceModel && mSourceModel->rowCount() > 0) {
+        // Check if one of the indicators want to draw attention
+        QModelIndexList lst = mSourceModel->match(mSourceModel->index(0, 0),
+                                                  ListenerModel::IndicatorDrawAttentionRole,
+                                                  QVariant(true),
+                                                  1 /* hits */,
+                                                  Qt::MatchExactly | Qt::MatchRecursive);
+        status = lst.isEmpty() ? Plasma::ActiveStatus : Plasma::NeedsAttentionStatus;
+    } else {
+        status = Plasma::PassiveStatus;
+    }
+
+    setStatus(status);
+
+    // Update icon
+    mIconWidget->setIcon(status == Plasma::NeedsAttentionStatus ? NEW_STUFF_ICON : NO_NEW_STUFF_ICON);
+
+    // Update views
+    if (status == Plasma::PassiveStatus) {
         mView->hide();
         mNoIndicatorLabel->show();
         mCurrentWidget = mNoIndicatorLabel;

=== modified file 'src/message-indicator.h'
--- src/message-indicator.h	2010-02-12 10:46:57 +0000
+++ src/message-indicator.h	2010-02-15 10:09:31 +0000
@@ -61,9 +61,7 @@
     void initIcon();
     void initSourceModel();
     void initView();
-    void updateIcon(bool newStuff);
-    void updateIconState();
-    void updateIconFromIndicators();
+    void updateStatus();
     void removeInterestOnServers();
 };