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

List:       kde-panel-devel
Subject:    [Panel-devel] patch: dataengines and timing
From:       Michael Olbrich <michael-olbrich () web ! de>
Date:       2007-08-06 22:57:57
Message-ID: 20070806225757.GA4138 () creature ! apm ! etc ! tu-bs ! de
[Download RAW message or body]

[Attachment #2 (multipart/signed)]

[Attachment #4 (multipart/mixed)]


Hi,

it's been a while since I brought up this topic. I have looked at the
growing list of dataengines and this time I actually came up with some
code.

The attached patch adresses two issues I have seen in data engines.

1. Many engines create a timer with a more or less random timeout.
   Always the same code. The timer is created in the constructor,
   started when the first source is requested, but unfortunately never
   stoped.
   With this patch the engine specifies a default timeout and a slot
   that is called when necessary.

2. As I said in a previous thread different applets may require
   different timeouts.
   The patch adds an optional parameter to DataEngine::connectSource
   with it an applet can request a custom timeout.

I have also added patches for the time engine/clock applet and the
networkapplet that make use of this functionality.
As far as I can tell the patch is source compatible and should not break
any other functionality.

I'm not quite satisfied with this. I've been playing whith the code for
a while now and I couldn't come up with anything better. Maybe someone
else has some ideas to improve it.

Should anyone wonder why I created a separate class: I've been toying
with the idea to use the same mechanism to share timers between
dataengines. Sofar I don't have enough data to support an argument for
the added complexity.

michael


["libplasma.patch" (text/x-diff)]

Index: dataengine.cpp
===================================================================
--- dataengine.cpp	(revision 697137)
+++ dataengine.cpp	(working copy)
@@ -36,7 +36,8 @@
         Private(DataEngine* e)
             : engine(e),
               limit(0),
-              valid(true)
+              valid(true),
+              defaultInterval(0)
         {
             updateTimer = new QTimer(engine);
             updateTimer->setSingleShot(true);
@@ -70,6 +71,7 @@
                      << ", creating" << endl;*/
             DataContainer* s = new DataContainer(engine);
             s->setObjectName(sourceName);
+            s->setDefaultInterval(engine->defaultInterval());
             sources.insert(sourceName, s);
 
             if (limit > 0) {
@@ -110,6 +112,7 @@
         QString icon;
         uint limit;
         bool valid;
+        int defaultInterval;
 };
 
 
@@ -134,7 +137,7 @@
     return d->sources.keys();
 }
 
-void DataEngine::connectSource(const QString& source, QObject* visualization) const
+void DataEngine::connectSource(const QString& source, QObject* visualization, int \
updateInterval) const  {
     DataContainer* s = d->source(source, false);
 
@@ -146,6 +149,8 @@
                 // now we have a source; since it was created on demand, assume
                 // it should be removed when not used
                 connect(s, SIGNAL(unused(QString)), this, \
SLOT(removeSource(QString))); +                connect(s, \
SIGNAL(update(Plasma::DataContainer*)), +                        this, \
SLOT(update(Plasma::DataContainer*)));  }
         }
     }
@@ -154,14 +159,17 @@
         return;
     }
 
-    connect(s, SIGNAL(updated(QString,Plasma::DataEngine::Data)),
-            visualization, SLOT(updated(QString,Plasma::DataEngine::Data)));
+    if (updateInterval < 0) {
+            updateInterval = s->defaultInterval();
+    }
+    s->connect(updateInterval, visualization,
+               SLOT(updated(QString,Plasma::DataEngine::Data)));
     QMetaObject::invokeMethod(visualization, "updated",
                               Q_ARG(QString, s->objectName()),
                               Q_ARG(Plasma::DataEngine::Data, s->data()));
 }
 
-void DataEngine::disconnectSource(const QString& source, QObject* visualization) \
const +void DataEngine::disconnectSource(const QString& source, QObject* \
visualization, int updateInterval) const  {
     DataContainer* s = d->source(source, false);
 
@@ -169,8 +177,11 @@
         return;
     }
 
-    disconnect(s, SIGNAL(updated(QString,Plasma::DataEngine::Data)),
-               visualization, SLOT(updated(QString,Plasma::DataEngine::Data)));
+    if (updateInterval < 0) {
+            updateInterval = s->defaultInterval();
+    }
+    s->disconnect(updateInterval, visualization,
+               SLOT(updated(QString,Plasma::DataEngine::Data)));
 }
 
 void DataEngine::connectAllSources(QObject* visualization) const
@@ -213,6 +224,11 @@
     return false;
 }
 
+DataContainer *DataEngine::source(const QString &name)
+{
+    return d->source(name);
+}
+
 void DataEngine::setData(const QString& source, const QVariant& value)
 {
     setData(source, source, value);
@@ -333,6 +349,16 @@
     return d->sources;
 }
 
+int DataEngine::defaultInterval()
+{
+    return d->defaultInterval;
+}
+
+void DataEngine::setDefaultInterval(int interval)
+{
+    d->defaultInterval = interval;
+}
+
 void DataEngine::setIcon(const QString& icon)
 {
     d->icon = icon;
Index: signalmanager.cpp
===================================================================
--- signalmanager.cpp	(revision 0)
+++ signalmanager.cpp	(revision 0)
@@ -0,0 +1,149 @@
+/*
+ *   Copyright (C) 2007 Michael Olbrich <michael-olbrich@web.de>
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU Library General Public License version 2 as
+ *   published by the Free Software Foundation
+ *
+ *   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 "signalmanager.h"
+
+#include <QtCore/QObject>
+#include <QtCore/QMap>
+
+namespace Plasma
+{
+
+class SignalObject::Private
+{
+    public:
+        Private(const char *s)
+            : signal(QMetaObject::normalizedSignature(s))
+        {}
+
+        QByteArray signal;
+        QAtomic connectCount;
+};
+
+SignalObject::SignalObject(const char *s)
+    : d(new Private(s))
+{
+}
+
+SignalObject::~SignalObject()
+{
+    delete d;
+}
+
+void SignalObject::connectNotify(const char *signal)
+{
+    if (QLatin1String(signal) == d->signal.constData()) {
+        d->connectCount.ref();
+    }
+}
+
+void SignalObject::disconnectNotify(const char *signal)
+{
+    if (QLatin1String(signal) == d->signal.constData()) {
+        if (d->connectCount > 0) {
+            d->connectCount.deref();
+        }
+        if (d->connectCount < 1) {
+            // DO NOT CALL ANYTHING AFTER THIS LINE AS IT MAY GET DELETED!
+            emit unused(this);
+        }
+    }
+}
+
+const char *SignalObject::signal()
+{
+    return  d->signal.constData();
+}
+
+class SignalManager::Private : public QObject
+{
+    Q_OBJECT
+
+    public:
+        typedef QMap<int, SignalObject*> SignalObjectMap;
+
+        Private(SignalManager *manager)
+            : m(manager)
+        {}
+
+    public Q_SLOTS:
+        void removeObject(SignalObject *o)
+        {
+            for (SignalObjectMap::Iterator it = data.begin(); it != data.end(); \
++it) { +                if ((*it) == o) {
+                    delete *it;
+                    data.erase(it);
+                    if (data.empty()) {
+                        emit m->unused(m->objectName());
+                    }
+                    break;
+                }
+            }
+        }
+
+    public:
+        SignalManager *m;
+        SignalObjectMap data;
+
+};
+
+SignalManager::SignalManager(QObject* parent)
+    : QObject(parent),
+      d(new Private(this))
+{
+}
+
+SignalManager::~SignalManager()
+{
+    delete d;
+}
+
+bool SignalManager::connect(int key, const QObject* receiver, const char* method)
+{
+    SignalObject* object = d->data[key];
+    if (!object) {
+        object = createObject(key);
+        d->data[key] = object;
+        QObject::connect(object, SIGNAL(unused(SignalObject*)), d, \
SLOT(removeObject(SignalObject*))); +    }
+    return QObject::connect(object, object->signal(), receiver, method);
+}
+
+bool SignalManager::disconnect(int key, const QObject* receiver, const char* method)
+{
+    Private::SignalObjectMap::ConstIterator it = d->data.find(key);
+    if (it == d->data.end()) {
+        return false;
+    }
+    return QObject::disconnect((*it), (*it)->signal(), receiver, method);
+}
+
+SignalObject *SignalManager::object(int key) const
+{
+    Private::SignalObjectMap::ConstIterator it = d->data.find(key);
+    if (it != d->data.end()) {
+        return *it;
+    } else {
+        return 0;
+    }
+}
+
+}
+
+#include "signalmanager.moc"
+#include "moc_signalmanager.cpp"
Index: datacontainer.h
===================================================================
--- datacontainer.h	(revision 697137)
+++ datacontainer.h	(working copy)
@@ -24,6 +24,7 @@
 
 #include <plasma/plasma_export.h>
 #include <plasma/dataengine.h>
+#include <plasma/signalmanager.h>
 
 namespace Plasma
 {
@@ -38,10 +39,12 @@
  * easy and flexible retrieval of the information associated with this object
  * without writing DataContainer or DataEngine specific code in visualizations.
  **/
-class PLASMA_EXPORT DataContainer : public QObject
+class PLASMA_EXPORT DataContainer : public SignalManager
 {
+    friend class DataSignalObject;
     Q_OBJECT
 
+    Q_PROPERTY(int defaultInterval READ defaultInterval WRITE setDefaultInterval)
     public:
         //typedef QHash<QString, DataEngine::SourceDict> Grouping;
 
@@ -80,22 +83,18 @@
          **/
         void checkForUpdate();
 
+        int defaultInterval() const;
+        void setDefaultInterval(int interval);
+
+    protected:
+        SignalObject *createObject(int key);
+
     Q_SIGNALS:
         /**
-         * Emitted when the data has been updated, allowing visualization to
-         * reflect the new data.
+         * Emmited when the data should be updated.
          **/
-        void updated(const QString& source, const Plasma::DataEngine::Data& data);
+        void update(Plasma::DataContainer *container);
 
-        /**
-         * Emitted when this source becomes unused
-         **/
-        void unused(const QString& source);
-
-    protected:
-        void connectNotify(const char *signal);
-        void disconnectNotify(const char *signal);
-
     private:
         class Private;
         Private* const d;
Index: includes/SignalManager
===================================================================
--- includes/SignalManager	(revision 0)
+++ includes/SignalManager	(revision 0)
@@ -0,0 +1 @@
+#include "../../plasma/signalmanager.h"
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt	(revision 697137)
+++ CMakeLists.txt	(working copy)
@@ -26,6 +26,7 @@
     phase.cpp
     plasma.cpp
     plasma_export.h
+    signalmanager.cpp
     scriptengine.cpp
     shadowitem.cpp
     svg.cpp
@@ -84,6 +85,7 @@
     phase.h
     plasma.h
     plasma_export.h
+    signalmanager.h
     scriptengine.cpp
     shadowitem_p.h
     svg.h
@@ -125,6 +127,7 @@
     includes/Package
     includes/Packager
     includes/PackageStructure
+    includes/SignalManager
     includes/Theme
     includes/DataContainer
     includes/DataEngine
Index: dataengine.h
===================================================================
--- dataengine.h	(revision 697137)
+++ dataengine.h	(working copy)
@@ -55,6 +55,7 @@
     Q_PROPERTY( bool valid READ isValid )
     Q_PROPERTY( QString icon READ icon WRITE setIcon )
 
+    Q_PROPERTY(int defaultInterval READ defaultInterval WRITE setDefaultInterval)
     public:
         typedef QHash<QString, DataEngine*> Dict;
         typedef QHash<QString, QVariant> Data;
@@ -88,8 +89,10 @@
          *
          * @param source the name of the data source
          * @param visualization the object to connect the data source to
+         * @param updateInterval how often the source should update its data.
+         *        This is used by sources that rely on polling.
          **/
-        Q_INVOKABLE void connectSource(const QString& source, QObject* \
visualization) const; +        Q_INVOKABLE void connectSource(const QString& source, \
QObject* visualization, int updateInterval = -1) const;  
         /**
          * Disconnects a source to an object that was receiving data updates.
@@ -97,7 +100,7 @@
          * @param source the name of the data source
          * @param visualization the object to connect the data source to
          **/
-        Q_INVOKABLE void disconnectSource(const QString& source, QObject* \
visualization) const; +        Q_INVOKABLE void disconnectSource(const QString& \
source, QObject* visualization, int updateInterval = -1) const;  
         /**
          * Connects all sources to an object for data updates. The object must
@@ -196,6 +199,14 @@
         virtual bool sourceRequested(const QString &name);
 
         /**
+         * Get a data source. If the sourcedoesn't exist then it is created.
+         *
+         * @param source the name of the data source
+         * @return the requested data source
+         **/
+        DataContainer *source(const QString &name);
+
+        /**
          * Sets a value for a data source. If the source
          * doesn't exist then it is created.
          *
@@ -277,6 +288,9 @@
          */
         SourceDict sourceDict() const;
 
+        int defaultInterval();
+        void setDefaultInterval(int interval);
+
     protected Q_SLOTS:
         /**
          * Call this method when you call setData directly on a DataContainer \
                instead
Index: datacontainer.cpp
===================================================================
--- datacontainer.cpp	(revision 697137)
+++ datacontainer.cpp	(working copy)
@@ -26,20 +26,51 @@
 namespace Plasma
 {
 
+class DataSignalObject : public SignalObject
+{
+    friend class DataContainer;
+    Q_OBJECT
+
+    public:
+        explicit DataSignalObject(DataContainer *c, int interval)
+            : SignalObject(SIGNAL(updated(QString, Plasma::DataEngine::Data))),
+              container(c)
+        {
+            if (interval > 0) {
+                startTimer(interval);
+            }
+        }
+
+    protected:
+        void timerEvent(QTimerEvent* event)
+        {
+            Q_UNUSED(event)
+            emit container->update(container);
+            emit updated(container->objectName(), container->data());
+        }
+
+    Q_SIGNALS:
+        void updated(const QString& source, const Plasma::DataEngine::Data& data);
+
+    private:
+        DataContainer *container;
+};
+
 class DataContainer::Private
 {
     public:
         Private()
-            : dirty(false)
+            : dirty(false),
+              defaultInterval(0)
         {}
 
         DataEngine::Data data;
-        QAtomic connectCount;
         bool dirty : 1;
+        int defaultInterval;
 };
 
 DataContainer::DataContainer(QObject* parent)
-    : QObject(parent),
+    : SignalManager(parent),
       d(new Private())
 {
 }
@@ -83,33 +114,32 @@
 void DataContainer::checkForUpdate()
 {
     if (d->dirty) {
-        emit updated(objectName(), d->data);
+        DataSignalObject *o = \
qobject_cast<DataSignalObject*>(object(defaultInterval())); +        if (o) {
+            emit o->updated(objectName(), d->data);
+        }
         d->dirty = false;
     }
 }
 
-void DataContainer::connectNotify(const char *signal)
+int DataContainer::defaultInterval() const
 {
-    if (QLatin1String(signal) == \
QMetaObject::normalizedSignature(SIGNAL(updated(QString, \
                Plasma::DataEngine::Data))).constData()) {
-        d->connectCount.ref();
-    }
+    return d->defaultInterval;
 }
 
-void DataContainer::disconnectNotify(const char *signal)
+void DataContainer::setDefaultInterval(int interval)
 {
-    if (QLatin1String(signal) == \
QMetaObject::normalizedSignature(SIGNAL(updated(QString, \
                Plasma::DataEngine::Data))).constData()) {
-        if (d->connectCount > 0) {
-            d->connectCount.deref();
-        }
+    d->defaultInterval = interval;
+}
 
-        if (d->connectCount < 1) {
-            // DO NOT CALL ANYTHING AFTER THIS LINE AS IT MAY GET DELETED!
-            emit unused(objectName());
-        }
-    }
+SignalObject *DataContainer::createObject(int key)
+{
+    return new DataSignalObject(this, key);
 }
 
+
 } // Plasma namespace
 
+#include "moc_datacontainer.cpp"
 #include "datacontainer.moc"
 
Index: signalmanager.h
===================================================================
--- signalmanager.h	(revision 0)
+++ signalmanager.h	(revision 0)
@@ -0,0 +1,123 @@
+/*
+ *   Copyright (C) 2007 Michael Olbrich <michael-olbrich@web.de>
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU Library General Public License version 2 as
+ *   published by the Free Software Foundation
+ *
+ *   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_SIGNALMANAGER_H
+#define PLASMA_SIGNALMANAGER_H
+
+#include <plasma/plasma_export.h>
+
+#include <QtCore/QObject>
+#include <QtCore/QMap>
+
+namespace Plasma
+{
+
+/**
+ * SignalObject is expected to be subclassed.
+ * Any subclass needs one signal. The signature of this signal must be passed
+ * to the constructor. It is used to connect to the signal and to keep track of
+ * of all connections.
+ **/
+class SignalObject : public QObject
+{
+    Q_OBJECT
+
+    public:
+        /**
+         * Create a SignalObject.
+         * @param signal the signature of the signal provided by the subclass
+         *        as provided by the SIGNAL() macro
+         **/
+        explicit SignalObject(const char* signal);
+        virtual ~SignalObject();
+
+        /**
+         *
+         * @return the signal signature as provided during construction
+         **/
+        const char *signal();
+
+    protected:
+        void connectNotify(const char *signal);
+        void disconnectNotify(const char *signal);
+
+    Q_SIGNALS:
+        /**
+         * Emitted when the last slot is disconnected
+         * @param o this object
+         **/
+        void unused(SignalObject *o);
+
+    private:
+        class Private;
+        Private* const d;
+};
+
+class PLASMA_EXPORT SignalManager : public QObject
+{
+    Q_OBJECT
+
+    public:
+        explicit SignalManager(QObject* parent);
+        virtual ~SignalManager();
+
+        /**
+         * Connect to the SignalObject associated with key
+         * @param key the key to identify the SignalObject
+         * @param receiver the receiver for QObject::connect
+         * @param method the receiver method for QObject::connect
+         **/
+        bool connect(int key, const QObject* receiver, const char* method);
+
+        /**
+         * Disconnect from the SignalObject associated with key
+         * @param key the key to identify the SignalObject
+         * @param receiver the receiver for QObject::disconnect
+         * @param method the receiver method for QObject::disconnect
+         **/
+        bool disconnect(int key, const QObject* receiver, const char* method);
+
+    Q_SIGNALS:
+        /**
+         * Emitted when the last SignalObject is removed
+         **/
+        void unused(const QString& source);
+
+    protected:
+        /**
+         * Must be implemented to return a subclass of SignalObject
+         **/
+        virtual SignalObject *createObject(int key) = 0;
+
+        /**
+         * Access the SignalObject associated with key
+         * @param key the key to identify the SignalObject
+         * @return the requested SignalObject or NULL if no SignalObject
+         *         for 'key' exists
+         **/
+        SignalObject *object(int key) const;
+
+    private:
+        class Private;
+        Private* const d;
+};
+
+} // Plasma namespace
+
+#endif // multiple inclusion guard
+


["clock.patch" (text/x-diff)]

Index: applets/clock/clock.cpp
===================================================================
--- applets/clock/clock.cpp	(revision 697137)
+++ applets/clock/clock.cpp	(working copy)
@@ -62,8 +62,11 @@
     m_theme->resize(m_pixelSize, m_pixelSize);
 
     Plasma::DataEngine* timeEngine = dataEngine("time");
-    timeEngine->connectSource(m_timezone, this);
-    timeEngine->setProperty("reportSeconds", m_showSecondHand);
+    if (m_showSecondHand) {
+        timeEngine->connectSource(m_timezone, this, 500);
+    } else {
+        timeEngine->connectSource(m_timezone, this);
+    }
     updated(m_timezone, timeEngine->query(m_timezone));
     constraintsUpdated();
 }
@@ -132,11 +135,20 @@
 void Clock::configAccepted()
 {
     KConfigGroup cg = config();
+    bool oldShowSecondHand = m_showSecondHand;
     m_showTimeString = ui.showTimeStringCheckBox->checkState() == Qt::Checked;
     m_showSecondHand = ui.showSecondHandCheckBox->checkState() == Qt::Checked;
     cg.writeEntry("showTimeString", m_showTimeString);
     cg.writeEntry("showSecondHand", m_showSecondHand);
-    dataEngine("time")->setProperty("reportSeconds", m_showSecondHand);
+    if (oldShowSecondHand != m_showSecondHand) {
+        if (oldShowSecondHand) {
+            dataEngine("time")->disconnectSource(m_timezone, this, 500);
+            dataEngine("time")->connectSource(m_timezone, this);
+        } else {
+            dataEngine("time")->disconnectSource(m_timezone, this);
+            dataEngine("time")->connectSource(m_timezone, this, 500);
+        }
+    }
     QGraphicsItem::update();
     cg.writeEntry("size", ui.spinSize->value());
     m_size = QSize(ui.spinSize->value(), ui.spinSize->value());
Index: engines/time/timeengine.cpp
===================================================================
--- engines/time/timeengine.cpp	(revision 697137)
+++ engines/time/timeengine.cpp	(working copy)
@@ -43,28 +43,6 @@
 {
 }
 
-bool TimeEngine::reportSeconds()
-{
-    return m_seconds;
-}
-
-void TimeEngine::setReportSeconds(bool seconds)
-{
-    //kDebug() << "only report seconds? " << seconds;
-    if (m_seconds == seconds) {
-        return;
-    }
-
-    m_seconds = seconds;
-    if (seconds) {
-        m_timer->setInterval(500);
-        disconnect(m_timer, SIGNAL(timeout()), this, SLOT(setTimerTo60()));
-    } else {
-        connect(m_timer, SIGNAL(timeout()), this, SLOT(setTimerTo60()));
-        m_timer->setInterval(((60 - QTime::currentTime().second()) * 1000) + 500);
-    }
-}
-
 void TimeEngine::setTimerTo60()
 {
     disconnect(m_timer, SIGNAL(timeout()), this, SLOT(setTimerTo60()));
@@ -115,13 +93,11 @@
     DataEngine::SourceDict::iterator it = sources.begin();
     QString localName = I18N_NOOP("Local");
 
-    if (!m_seconds) {
-        int seconds = dt.time().second();
-        if (seconds > 2) {
-            // we've drifted more than 2s off the minute, let's reset this
-            connect(m_timer, SIGNAL(timeout()), this, SLOT(setTimerTo60()));
-            m_timer->setInterval(((60 - seconds) * 1000) + 500);
-        }
+    int seconds = dt.time().second();
+    if (seconds > 2) {
+        // we've drifted more than 2s off the minute, let's reset this
+        connect(m_timer, SIGNAL(timeout()), this, SLOT(setTimerTo60()));
+        m_timer->setInterval(((60 - seconds) * 1000) + 500);
     }
 
     while (it != sources.end()) {
@@ -141,4 +117,21 @@
     checkForUpdates();
 }
 
+void TimeEngine::update(Plasma::DataContainer* source)
+{
+    QDateTime dt = QDateTime::currentDateTime();
+    QString localName = I18N_NOOP("Local");
+    QString tz = source->objectName();
+    if (tz == localName) {
+        source->setData(I18N_NOOP("Time"), dt.time());
+        source->setData(I18N_NOOP("Date"), dt.date());
+    } else {
+        KTimeZone local = KSystemTimeZones::local();
+        KTimeZone newTz = KSystemTimeZones::zone(tz);
+        QDateTime localizeDt = local.convert(newTz, dt);
+        source->setData(I18N_NOOP("Time"), localizeDt.time());
+        source->setData(I18N_NOOP("Date"), localizeDt.date());
+    }
+}
+
 #include "timeengine.moc"
Index: engines/time/timeengine.h
===================================================================
--- engines/time/timeengine.h	(revision 697137)
+++ engines/time/timeengine.h	(working copy)
@@ -30,15 +30,11 @@
 class TimeEngine : public Plasma::DataEngine
 {
     Q_OBJECT
-    Q_PROPERTY(bool reportSeconds READ reportSeconds WRITE setReportSeconds)
 
     public:
         TimeEngine( QObject* parent, const QStringList& args );
         ~TimeEngine();
 
-        bool reportSeconds();
-        void setReportSeconds(bool seconds);
-
     protected:
         bool sourceRequested(const QString &name);
         void init();
@@ -46,10 +42,10 @@
     protected slots:
         void updateTime();
         void setTimerTo60();
+        void update(Plasma::DataContainer* source);
 
     private:
         QTimer* m_timer;
-        bool m_seconds;
 };
 
 K_EXPORT_PLASMA_DATAENGINE(time, TimeEngine)

["network.patch" (text/x-diff)]

Index: networkengine.cpp
===================================================================
--- networkengine.cpp	(revision 697137)
+++ networkengine.cpp	(working copy)
@@ -54,9 +54,7 @@
       m_secondsSinceLastUpdate( 0 )
 {
     Q_UNUSED(args)
-    m_timer = new QTimer(this);
-    m_timer->setSingleShot(false);
-    connect(m_timer, SIGNAL(timeout()), this, SLOT(updateNetworkData()));
+    setDefaultInterval(1000);
 }
 
 NetworkEngine::~NetworkEngine()
@@ -70,28 +68,19 @@
     {
         return false;
     }
-
-    if ( !m_timer->isActive() )
-    {
-        m_timer->start(1000);
-    }
+    update(source(name));
     return true;
 }
 
-void NetworkEngine::updateNetworkData()
+void NetworkEngine::update(Plasma::DataContainer* source)
 {
-    DataEngine::SourceDict sources = sourceDict();
-    DataEngine::SourceDict::iterator it = sources.begin();
-    while ( it != sources.end() )
-    {
-        QString ifName = it.key();
-        Plasma::DataContainer* source = it.value();
+        QString ifName = source->objectName();
         QDir interfaceDir( SYSPATH + ifName );
         if ( !interfaceDir.exists() )
         {
             // remove the source as the interface is no longer available
             removeSource( ifName );
-            continue;
+            return;
         }
 
         // Check if it is a wireless interface.
@@ -139,10 +128,6 @@
                 updateWirelessData( ifName, source );
             }
         }
-        ++it;
-    }
-
-    checkForUpdates();
 }
 
 bool NetworkEngine::readNumberFromFile( const QString &fileName, unsigned int &value )
Index: networkengine.h
===================================================================
--- networkengine.h	(revision 697137)
+++ networkengine.h	(working copy)
@@ -21,7 +21,6 @@
 
 #include "plasma/dataengine.h"
 
-class QTimer;
 class Plasma::DataContainer;
 
 class NetworkEngine : public Plasma::DataEngine
@@ -36,7 +35,7 @@
     bool sourceRequested(const QString &name);
 
 protected slots:
-    void updateNetworkData();
+    void update(Plasma::DataContainer* source);
 
 private:
     bool readNumberFromFile( const QString &fileName, unsigned int &value );
@@ -45,7 +44,6 @@
     void updateInterfaceData( const QString &ifName, Plasma::DataContainer *container );
 
     int m_secondsSinceLastUpdate;
-    QTimer* m_timer;
 };
 
 K_EXPORT_PLASMA_DATAENGINE(network, NetworkEngine)

["signature.asc" (application/pgp-signature)]

_______________________________________________
Panel-devel mailing list
Panel-devel@kde.org
https://mail.kde.org/mailman/listinfo/panel-devel


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

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