[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/base/plasma/engines
From: Michael Olbrich <michael.olbrich () gmx ! net>
Date: 2007-09-16 16:37:05
Message-ID: 1189960625.787145.2772.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 713203 by molbrich:
change engines to use new timing api
M +10 -18 cia.vc/ciavc.cpp
M +1 -7 cia.vc/ciavc.h
M +15 -22 ebn/ebnengine.cpp
M +1 -7 ebn/ebnengine.h
M +0 -2 rss/rss.h
M +7 -23 sensors/sensorsengine.cpp
M +1 -4 sensors/sensorsengine.h
M +3 -11 timetracker/ktimetrackerengine.cpp
M +1 -6 timetracker/ktimetrackerengine.h
M +16 -25 twitter-engine/twitterengine.cpp
M +1 -5 twitter-engine/twitterengine.h
--- trunk/playground/base/plasma/engines/cia.vc/ciavc.cpp #713202:713203
@@ -32,9 +32,8 @@
Q_UNUSED(args)
setSourceLimit(10);
- m_timer = new QTimer(this);
- m_timer->setSingleShot(false);
- connect(m_timer, SIGNAL(timeout()), this, SLOT(updateCiaVc()));
+ setMinimumUpdateInterval(10000);
+ setUpdateInterval(60000);
}
CiaVcEngine::~CiaVcEngine()
@@ -45,27 +44,20 @@
{
}
-void CiaVcEngine::updateCiaVc()
+bool CiaVcEngine::updateSource(const QString &project)
{
- foreach (const QString& project, m_projects) {
- Syndication::Loader * loader = Syndication::Loader::create();
- connect(loader, SIGNAL(loadingComplete(Syndication::Loader*, \
Syndication::FeedPtr, Syndication::ErrorCode)),
- this, SLOT(processProject(Syndication::Loader*, \
Syndication::FeedPtr, Syndication::ErrorCode)));
- loader->loadFrom(QString("http://cia.vc/stats/project/%1/.rss").arg(project));
- }
+ Syndication::Loader * loader = Syndication::Loader::create();
+ connect(loader, SIGNAL(loadingComplete(Syndication::Loader*, \
Syndication::FeedPtr, Syndication::ErrorCode)), + this, \
SLOT(processProject(Syndication::Loader*, Syndication::FeedPtr, \
Syndication::ErrorCode))); + \
loader->loadFrom(QString("http://cia.vc/stats/project/%1/.rss").arg(project)); +
+ return false;
}
bool CiaVcEngine::sourceRequested(const QString &name)
{
- //TODO: projects should be configurable
- m_projects << name;
- updateCiaVc();
+ updateSource(name);
- if (!m_timer->isActive()) {
- //TODO: this should be configurable
- m_timer->start(60000);
- }
-
return true;
}
--- trunk/playground/base/plasma/engines/cia.vc/ciavc.h #713202:713203
@@ -25,8 +25,6 @@
#include "plasma/dataengine.h"
-class QTimer;
-
/**
* This class evaluates the basic expressions given in the interface.
*/
@@ -43,14 +41,10 @@
bool sourceRequested(const QString &name);
protected slots:
- void updateCiaVc();
+ bool updateSource(const QString &project);
void processProject(Syndication::Loader* loader,
Syndication::FeedPtr feed,
Syndication::ErrorCode error);
-
- private:
- QTimer* m_timer;
- QStringList m_projects;
};
K_EXPORT_PLASMA_DATAENGINE(ciavc, CiaVcEngine)
--- trunk/playground/base/plasma/engines/ebn/ebnengine.cpp #713202:713203
@@ -31,9 +31,8 @@
{
Q_UNUSED(args)
- m_timer = new QTimer(this);
- m_timer->setSingleShot(false);
- connect(m_timer, SIGNAL(timeout()), this, SLOT(updateEbn()));
+ setMinimumUpdateInterval(60 * 1000);
+ setUpdateInterval(60 * 60 * 1000);
}
EbnEngine::~EbnEngine()
@@ -44,34 +43,28 @@
{
}
-void EbnEngine::updateEbn()
+bool EbnEngine::updateSource(const QString &name)
{
- foreach (QString url, m_urls) {
- // efficiency: questionable. But Loader forces us to use it like this.
- Syndication::Loader* loader = Syndication::Loader::create();
- connect(loader, \
SIGNAL(loadingComplete(Syndication::Loader*,Syndication::FeedPtr,Syndication::ErrorCode)),
- this, \
SLOT(processFeed(Syndication::Loader*,Syndication::FeedPtr,Syndication::ErrorCode)));
- loader->loadFrom(url);
- }
-}
-
-bool EbnEngine::sourceRequested(const QString &name)
-{
QString section = name.section('/', 0, 0, QString::SectionSkipEmpty);
QString component = name.section('/', 1, 1, QString::SectionSkipEmpty);
QString module = name.section('/', 2, 2, QString::SectionSkipEmpty);
QString url = QString("http://www.englishbreakfastnetwork.org/"
"%1/rssfeed.php?component=%2&module=%3"
).arg(section).arg(component).arg(module);
- m_urls << url;
- // is it worth avoiding re-loading _all_ the feeds when a new one is added?
- updateEbn();
- if (!m_timer->isActive()) {
- //TODO: this should be configurable
- m_timer->start(60 * 60 * 1000);
- }
+ // efficiency: questionable. But Loader forces us to use it like this.
+ Syndication::Loader* loader = Syndication::Loader::create();
+ connect(loader, \
SIGNAL(loadingComplete(Syndication::Loader*,Syndication::FeedPtr,Syndication::ErrorCode)),
+ this, SLOT(processFeed(Syndication::Loader*,Syndication::FeedPtr,Syndication::ErrorCode)));
+ loader->loadFrom(url);
+ return false;
+}
+
+bool EbnEngine::sourceRequested(const QString &name)
+{
+ updateSource(name);
+
return true;
}
--- trunk/playground/base/plasma/engines/ebn/ebnengine.h #713202:713203
@@ -26,8 +26,6 @@
#include "plasma/dataengine.h"
-class QTimer;
-
/**
* Processes feeds from the English Breakfast Network
*
@@ -59,14 +57,10 @@
bool sourceRequested(const QString &name);
protected slots:
- void updateEbn();
+ bool updateSource(const QString &name);
void processFeed(Syndication::Loader* loader,
Syndication::FeedPtr feed,
Syndication::ErrorCode error);
-
- private:
- QTimer* m_timer;
- QStringList m_urls;
};
K_EXPORT_PLASMA_DATAENGINE(ebn, EbnEngine)
--- trunk/playground/base/plasma/engines/rss/rss.h #713202:713203
@@ -26,8 +26,6 @@
#include "plasma/dataengine.h"
-class QTimer;
-
/**
* This class evaluates the basic expressions given in the interface.
*/
--- trunk/playground/base/plasma/engines/sensors/sensorsengine.cpp #713202:713203
@@ -59,15 +59,12 @@
m_sensors[device.dirName()+ "/" + sensor] = data;
}
}
-
- m_timer = new QTimer(this);
- m_timer->setSingleShot(false);
- connect(m_timer, SIGNAL(timeout()), this, SLOT(timeout()));
+ setMinimumUpdateInterval(0);
+ setUpdateInterval(1000);
}
SensorsEngine::~SensorsEngine()
{
- delete m_timer;
}
QStringList SensorsEngine::sources() const
@@ -105,19 +102,16 @@
setData(name, param, content);
}
}
- if (!m_timer->isActive()) {
- m_timer->start(1000);
- }
return true;
}
-void SensorsEngine::update(Plasma::DataContainer* source)
+bool SensorsEngine::updateSource(const QString& source)
{
- SensorData &s = m_sensors[source->objectName()];
+ SensorData &s = m_sensors[source];
QFile file(s.path + QDir::separator()
+ s.name + "_input");
if (!file.open(QIODevice::ReadOnly)) {
- return;
+ return false;
}
QString content = file.readAll();
file.close();
@@ -129,18 +123,8 @@
} else {
data = content;
}
- if (source->data()["input"] != data) {
- source->setData("input", data);
- }
+ setData(source, I18N_NOOP("input"), data);
+ return true;
}
-void SensorsEngine::timeout()
-{
- SourceDict dict = sourceDict();
- for (SourceDict::ConstIterator it = dict.begin(); it != dict.end(); ++it) {
- update(*it);
- }
- checkForUpdates();
-}
-
#include "sensorsengine.moc"
--- trunk/playground/base/plasma/engines/sensors/sensorsengine.h #713202:713203
@@ -23,7 +23,6 @@
#include <QtCore/QMap>
class Plasma::DataContainer;
-class QTimer;
class SensorsEngine : public Plasma::DataEngine
{
@@ -38,8 +37,7 @@
bool sourceRequested(const QString &name);
protected Q_SLOTS:
- void update(Plasma::DataContainer* source);
- void timeout();
+ bool updateSource(const QString& source);
private:
struct SensorData
@@ -54,7 +52,6 @@
bool m_state;
SensorMap m_sensors;
- QTimer *m_timer;
};
K_EXPORT_PLASMA_DATAENGINE(sensors, SensorsEngine)
--- trunk/playground/base/plasma/engines/timetracker/ktimetrackerengine.cpp \
#713202:713203 @@ -29,10 +29,6 @@
KTimetrackerEngine::KTimetrackerEngine( QObject* parent, const QVariantList& args )
{
Q_UNUSED( args );
- m_timer = new QTimer( this );
- m_timer->setSingleShot( false );
- connect( m_timer, SIGNAL( timeout() ),
- this, SLOT( updateData() ) );
}
bool KTimetrackerEngine::sourceRequested( const QString &name )
@@ -40,17 +36,13 @@
if ( name != "timetracker" ) {
return false;
} else {
- updateData();
+ updateSource(name);
- if ( !m_timer->isActive() ) {
- m_timer->start();
- }
-
return true;
}
}
-void KTimetrackerEngine::updateData()
+bool KTimetrackerEngine::updateSource( const QString &name )
{
QDBusInterface iface( "org.kde.karm", "/Karm", "org.kde.karm.Karm", \
QDBusConnection::sessionBus() ); QDBusReply<QStringList> reply;
@@ -66,7 +58,7 @@
}
setData( "timetracker", "ktimetracker-running", valid );
- checkForUpdates();
+ return true;
}
#include "ktimetrackerengine.moc"
--- trunk/playground/base/plasma/engines/timetracker/ktimetrackerengine.h \
#713202:713203 @@ -21,8 +21,6 @@
#include <plasma/dataengine.h>
-class QTimer;
-
class KTimetrackerEngine : public Plasma::DataEngine
{
Q_OBJECT
@@ -34,11 +32,8 @@
protected:
bool sourceRequested( const QString &name );
-private:
- QTimer *m_timer;
-
private Q_SLOTS:
- void updateData();
+ bool updateSource( const QString &name );
};
K_EXPORT_PLASMA_DATAENGINE(ktimetracker, KTimetrackerEngine)
--- trunk/playground/base/plasma/engines/twitter-engine/twitterengine.cpp \
#713202:713203 @@ -37,11 +37,8 @@
m_http = new QHttp("twitter.com");
connect(m_http,SIGNAL(requestFinished(int,bool)), this, \
SLOT(requestFinished(int,bool)));
- m_timer = new QTimer(this);
- m_timer->setSingleShot(false);
- connect(m_timer, SIGNAL(timeout()), this, SLOT(refresh()));
- m_timer->start(60 * 1000);
- refresh();
+ setMinimumUpdateInterval(10 * 1000);
+ setUpdateInterval(60 * 1000);
}
TwitterEngine::~TwitterEngine()
@@ -79,7 +76,7 @@
{
kDebug() ;
m_activeSources.append( name );
- refresh();
+ updateSource(name);
return true;
}
@@ -118,27 +115,21 @@
}
}
-void TwitterEngine::forceRefresh()
+bool TwitterEngine::updateSource(const QString &source)
{
- refresh();
-}
-
-void TwitterEngine::refresh()
-{
- foreach( QString source, m_activeSources ) {
- if (source=="Timeline") {
- updateTimeline();
- }
- QStringList tokens = source.split(':');
- if (tokens.at(0)=="Update")
- getTweet(tokens.at(1).toInt());
- if (tokens.at(0)=="Timeline") {
- updateUser(tokens.at(1));
- }
- if (tokens.at(0)=="TimelineWithFriends") {
- updateUserWithFriends(tokens.at(1));
- }
+ if (source=="Timeline") {
+ updateTimeline();
}
+ QStringList tokens = source.split(':');
+ if (tokens.at(0)=="Update")
+ getTweet(tokens.at(1).toInt());
+ if (tokens.at(0)=="Timeline") {
+ updateUser(tokens.at(1));
+ }
+ if (tokens.at(0)=="TimelineWithFriends") {
+ updateUserWithFriends(tokens.at(1));
+ }
+ return false;
}
void TwitterEngine::updateTimeline()
--- trunk/playground/base/plasma/engines/twitter-engine/twitterengine.h \
#713202:713203 @@ -27,7 +27,6 @@
class QDomNodeList;
class QHttp;
-class QTimer;
class TwitterEngine : public Plasma::DataEngine
{
@@ -47,8 +46,6 @@
//QStringList sources() const;
enum UpdateType { Timeline=1, Status, UserTimeline, UserTimelineWithFriends, \
UserImage };
- void forceRefresh();
-
protected:
bool sourceRequested(const QString &name);
@@ -59,14 +56,13 @@
void getTweet(const int &ID);
void getUserImage( const QString &who, const KUrl& url );
void requestFinished(int id, bool error);
- void refresh();
+ bool updateSource(const QString &source);
private:
QList<QVariant> parseStatuses(QDomNodeList items);
QString m_username;
QString m_password;
- QTimer* m_timer;
QHttp* m_http;
QMap<int,UpdateType> m_updates;
QMap<int,QString> m_timelines;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic