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

List:       kde-commits
Subject:    KDE/kdebase/workspace/plasma/applets/systemtray
From:       Aaron J. Seigo <aseigo () kde ! org>
Date:       2009-09-01 22:01:06
Message-ID: 1251842466.403018.25192.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1018588 by aseigo:

when the items aren't being shown, don't update them.


 M  +2 -4      core/job.cpp  
 M  +15 -0     ui/applet.cpp  
 M  +1 -0      ui/applet.h  
 M  +65 -31    ui/jobwidget.cpp  
 M  +4 -0      ui/jobwidget.h  


--- trunk/KDE/kdebase/workspace/plasma/applets/systemtray/core/job.cpp \
#1018587:1018588 @@ -194,10 +194,8 @@
 
 void Job::setTotalAmounts(QMap<QString, qlonglong> amounts)
 {
-    if (d->totalAmounts != amounts) {
-        d->totalAmounts = amounts;
-        scheduleChangedSignal();
-    }
+    d->totalAmounts = amounts;
+    scheduleChangedSignal();
 }
 
 QMap<QString, qlonglong> Job::processedAmounts() const
--- trunk/KDE/kdebase/workspace/plasma/applets/systemtray/ui/applet.cpp \
#1018587:1018588 @@ -781,6 +781,21 @@
     }
 }
 
+void Applet::popupEvent(bool show)
+{
+    Plasma::ExtenderGroup * jobGroup = extender()->group("jobGroup");
+    if (!jobGroup) {
+        return;
+    }
+
+    foreach (Plasma::ExtenderItem *item, jobGroup->items()) {
+        JobWidget *job = dynamic_cast<JobWidget *>(item->widget());
+        if (job) {
+            job->poppedUp(show);
+        }
+    }
+}
+
 void Applet::clearAllCompletedJobs()
 {
     Plasma::ExtenderGroup *completedJobsGroup = \
                extender()->group("completedJobsGroup");
--- trunk/KDE/kdebase/workspace/plasma/applets/systemtray/ui/applet.h \
#1018587:1018588 @@ -58,6 +58,7 @@
     void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); }
 
     void timerEvent(QTimerEvent *event);
+    void popupEvent(bool show);
 
 private slots:
     void configAccepted();
--- trunk/KDE/kdebase/workspace/plasma/applets/systemtray/ui/jobwidget.cpp \
#1018587:1018588 @@ -26,14 +26,15 @@
 #include <QGraphicsGridLayout>
 #include <QLabel>
 
-#include <plasma/widgets/meter.h>
 #include <Plasma/DataEngine>
-#include <Plasma/Service>
+#include <Plasma/Extender>
 #include <Plasma/ExtenderItem>
-#include <Plasma/Theme>
 #include <Plasma/Label>
 #include <Plasma/Meter>
+#include <Plasma/PopupApplet>
 #include <Plasma/PushButton>
+#include <Plasma/Service>
+#include <Plasma/Theme>
 
 static const int UPDATE_INTERVAL = 200;
 
@@ -97,11 +98,9 @@
     if (m_job) {
         m_details->setText(i18n("More"));
 
-        connect(m_job, SIGNAL(changed(SystemTray::Job*)), this, \
                SLOT(scheduleUpdateJob()));
         connect(m_job, SIGNAL(stateChanged(SystemTray::Job*)), this, \
                SLOT(updateJobState()));
         connect(m_job, SIGNAL(destroyed(SystemTray::Job*)), this, \
                SLOT(destroyExtenderItem()));
-        connect(m_details, SIGNAL(clicked()),
-                this, SLOT(detailsClicked()));
+        connect(m_details, SIGNAL(clicked()), this, SLOT(detailsClicked()));
 
         //the suspend action
         QAction *suspendAction = new QAction(m_extenderItem);
@@ -110,8 +109,7 @@
         suspendAction->setVisible(false);
         suspendAction->setToolTip(i18n("Pause job"));
         m_extenderItem->addAction("suspend", suspendAction);
-        connect(suspendAction, SIGNAL(triggered()), m_job,
-                SLOT(suspend()));
+        connect(suspendAction, SIGNAL(triggered()), m_job, SLOT(suspend()));
 
         //the resume action
         QAction *resumeAction = new QAction(m_extenderItem);
@@ -120,8 +118,7 @@
         resumeAction->setVisible(false);
         resumeAction->setToolTip(i18n("Resume job"));
         m_extenderItem->addAction("resume", resumeAction);
-        connect(resumeAction, SIGNAL(triggered()), m_job,
-                SLOT(resume()));
+        connect(resumeAction, SIGNAL(triggered()), m_job, SLOT(resume()));
 
         //the friendly stop action
         QAction *stopAction = new QAction(m_extenderItem);
@@ -130,8 +127,7 @@
         stopAction->setVisible(true);
         stopAction->setToolTip(i18n("Cancel job"));
         m_extenderItem->addAction("stop", stopAction);
-        connect(stopAction, SIGNAL(triggered()), m_job,
-                SLOT(stop()));
+        connect(stopAction, SIGNAL(triggered()), m_job, SLOT(stop()));
 
         updateJob();
     } else {
@@ -169,7 +165,7 @@
 
 void JobWidget::updateJobState()
 {
-    if (m_extenderItemDestroyed) {
+    if (m_extenderItemDestroyed && m_job) {
         return;
     }
 
@@ -194,34 +190,34 @@
             i18nc("%1 is the name of the job, can be things like Copying, deleting, \
moving",  "%1 [Finished]", m_job->message()));
         m_extenderItem->showCloseButton();
-        m_details->hide();
     }
 }
 
 void JobWidget::updateJob()
 {
-    if (m_extenderItemDestroyed) {
+    if (m_extenderItemDestroyed && m_job) {
         return;
     }
 
+
     m_meter->setValue(m_job->percentage());
 
-    if (m_job) {
-        if (m_job->labels().count() > 0) {
-            labelName0 = m_job->labels().value(0).first;
-            label0 = m_job->labels().value(0).second;
-        }
-        if (m_job->labels().count() > 1) {
-            labelName1 = m_job->labels().value(1).first;
-            label1 = m_job->labels().value(1).second;
-        }
-        KConfigGroup cg = m_extenderItem->config();
-        cg.writeEntry("labelName0", labelName0);
-        cg.writeEntry("label0", label0);
-        cg.writeEntry("labelName1", labelName1);
-        cg.writeEntry("label1", label1);
+    if (m_job->labels().count() > 0) {
+        labelName0 = m_job->labels().value(0).first;
+        label0 = m_job->labels().value(0).second;
     }
+    if (m_job->labels().count() > 1) {
+        labelName1 = m_job->labels().value(1).first;
+        label1 = m_job->labels().value(1).second;
+    }
 
+    //TODO: can we write this at some later point?
+    KConfigGroup cg = m_extenderItem->config();
+    cg.writeEntry("labelName0", labelName0);
+    cg.writeEntry("label0", label0);
+    cg.writeEntry("labelName1", labelName1);
+    cg.writeEntry("label1", label1);
+
     updateLabels();
 
     //set the correct actions to visible.
@@ -253,11 +249,10 @@
         m_fileCountLabel->setText(i18np("%2 / 1 file", "%2 / %1 files", files, \
processed["files"]));  }
 
-    qlonglong done = processed["bytes"];
     qlonglong total = totals["bytes"];
     if (total > 0) {
         QString processedString = \
                KGlobal::locale()->formatByteSize(processed["bytes"]);
-        QString totalsString = KGlobal::locale()->formatByteSize(totals["bytes"]);
+        QString totalsString = KGlobal::locale()->formatByteSize(total);
         m_totalBytesLabel->setText(QString("%1 / %2").arg(processedString, \
totalsString));  } else {
         m_details->hide();
@@ -267,6 +262,45 @@
     m_extenderItem->setIcon(m_job->applicationIconName());
 }
 
+void JobWidget::showEvent(QShowEvent *)
+{
+    if (!m_job) {
+        return;
+    }
+
+    Plasma::PopupApplet *applet = qobject_cast<Plasma::PopupApplet \
*>(m_extenderItem->extender()->applet()); +    if (applet && \
!applet->isPopupShowing()) { +        updateJob();
+        disconnect(m_job, SIGNAL(changed(SystemTray::Job*)), this, \
SLOT(scheduleUpdateJob())); +        connect(m_job, \
SIGNAL(changed(SystemTray::Job*)), this, SLOT(scheduleUpdateJob())); +        return;
+    }
+}
+
+void JobWidget::hideEvent(QHideEvent *)
+{
+    if (!m_job) {
+        return;
+    }
+
+    disconnect(m_job, SIGNAL(changed(SystemTray::Job*)), this, \
SLOT(scheduleUpdateJob())); +}
+
+void JobWidget::poppedUp(bool shown)
+{
+    if (!m_job) {
+        return;
+    }
+
+    disconnect(m_job, SIGNAL(changed(SystemTray::Job*)), this, \
SLOT(scheduleUpdateJob())); +
+    if (shown && isVisible()) {
+        updateJob();
+        connect(m_job, SIGNAL(changed(SystemTray::Job*)), this, \
SLOT(scheduleUpdateJob())); +        return;
+    }
+}
+
 void JobWidget::resizeEvent(QGraphicsSceneResizeEvent *event)
 {
     Q_UNUSED(event)
--- trunk/KDE/kdebase/workspace/plasma/applets/systemtray/ui/jobwidget.h \
#1018587:1018588 @@ -52,9 +52,13 @@
         explicit JobWidget(SystemTray::Job *job, Plasma::ExtenderItem *parent);
         ~JobWidget();
 
+        void poppedUp(bool shown);
+
     protected:
         void resizeEvent(QGraphicsSceneResizeEvent *event);
         void timerEvent(QTimerEvent *event);
+        void showEvent(QShowEvent *event);
+        void hideEvent(QHideEvent *event);
 
     private Q_SLOTS:
         void detailsClicked();


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

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