summaryrefslogtreecommitdiffstats
path: root/kweather/weatherbar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'kweather/weatherbar.cpp')
-rw-r--r--kweather/weatherbar.cpp128
1 files changed, 99 insertions, 29 deletions
diff --git a/kweather/weatherbar.cpp b/kweather/weatherbar.cpp
index dcc5d37..b06bbd8 100644
--- a/kweather/weatherbar.cpp
+++ b/kweather/weatherbar.cpp
@@ -23,6 +23,7 @@
#include "dockwidget.h"
#include "sidebarwidget.h"
+#include <tdeapplication.h>
#include <tqlabel.h>
#include <tqfont.h>
#include <tqlayout.h>
@@ -32,7 +33,9 @@
#include <kdebug.h>
#include <tdeconfig.h>
#include <kstandarddirs.h>
+#include <tdeglobalsettings.h>
#include <tdemessagebox.h>
+#include <dcopclient.h>
#include <dcopref.h>
@@ -50,32 +53,17 @@ KonqSidebarWeather::KonqSidebarWeather(TDEInstance* inst, TQObject* parent,
kdDebug() << "Get weatherstation list... " << endl;
- if (!connectDCOPSignal(0,0,
- "fileUpdate(TQString)",
- "refresh(TQString)",false))
+ if (!(
+ connectDCOPSignal(0, 0, "fileUpdate(TQString)", "refresh(TQString)", false) &&
+ connectDCOPSignal(0, 0, "stationAdded(TQString)", "updateWidgets()", false) &&
+ connectDCOPSignal(0, 0, "stationRemoved(TQString)", "updateWidgets()", false)
+ ))
kdDebug() << "Could not attach signal..." << endl;
else
kdDebug() << "attached dcop signals..." << endl;
- DCOPRef dcopCall( "KWeatherService", "WeatherService" );
- DCOPReply reply = dcopCall.call("listStations()", true );
- if ( reply.isValid() ) {
- TQStringList replyList = reply;
- for(int i = 0; i < replyList.size(); i++)
- {
- dockwidget *d = new dockwidget(m_container->viewport(), replyList[i].latin1());
- m_container->addWidget(d, replyList[i].latin1());
- d->resizeView(80,48);
- d->show();
- m_widgets.insert(replyList[i], d);
- dcopCall.send("update(TQString)", replyList[i]);
- }
- }
-
timeOut = new TQTimer(this, "timeOut" );
- timeOut->changeInterval(15*60000);
- connect(timeOut, TQT_SIGNAL(timeout()), this, TQT_SLOT(update()));
- // m_widgets.append(new dockwidget(widgetParent));
+ updateWidgets(true);
}
@@ -102,15 +90,16 @@ void KonqSidebarWeather::refresh(TQString stationID)
kdDebug() << "refresh " << stationID << endl;
if(m_widgets.find(stationID))
{
+ /* These updates are seemingly now handled by dockwidget itself
DCOPRef dcopCall( "KWeatherService", "WeatherService" );
m_widgets[stationID]->setWeatherIcon(dcopCall.call("currentIcon(TQString)", stationID ,true ));
m_widgets[stationID]->setTemperature(dcopCall.call("temperature(TQString)", stationID,true ));
m_widgets[stationID]->setPressure(dcopCall.call("pressure(TQString)", stationID,true ));
m_widgets[stationID]->setWind(dcopCall.call("wind(TQString)", stationID,true ));
+ */
+
m_widgets[stationID]->showWeather();
}
- else
- update();
}
void KonqSidebarWeather::handleURL(const KURL& url)
@@ -125,26 +114,107 @@ void KonqSidebarWeather::handlePreviewOnMouseOver(const KFileItem& item)
{
}
-void KonqSidebarWeather::update()
+void KonqSidebarWeather::updateWidgets( bool firstTime )
{
+ kdDebug() << "updating station widgets" << endl;
timeOut->stop();
DCOPRef dcopCall( "KWeatherService", "WeatherService" );
DCOPReply reply = dcopCall.call("listStations()", true );
+
+ // KWeatherService might not be active at this point
+ if( !reply.isValid() ) {
+ kdDebug() << "Starting KWeatherService" << endl;
+ if( !startWeatherService() ) {
+ KMessageBox::sorry(0, i18n("Could not start the weather service!"));
+ return;
+ }
+
+ reply = dcopCall.call("listStations()", true );
+ }
+
if ( reply.isValid() ) {
TQStringList replyList = reply;
+
+ // Check for new cities
for(int i = 0; i < replyList.size(); i++)
{
if(!m_widgets.find(replyList[i]))
{
- dockwidget *d = new dockwidget(m_container->viewport(), replyList[i].latin1());
- m_container->addWidget(d, replyList[i].latin1());
+ TQLabel *city = new TQLabel(
+ dcopCall.call("stationName(TQString)", replyList[i], true),
+ m_container->viewport()
+ );
+ city->setPaletteBackgroundColor(TDEGlobalSettings::highlightColor());
+ city->setPaletteForegroundColor(TDEGlobalSettings::highlightedTextColor());
+ dockwidget *d = new dockwidget(replyList[i], m_container->viewport());
+ d->resizeView(TQSize(d->width(), 48));
+ city->show();
d->show();
+ m_labels.insert(replyList[i], city);
m_widgets.insert(replyList[i], d);
}
dcopCall.send("update(TQString)", replyList[i]);
}
+
+ // Check for removed cities
+ TQDictIterator<dockwidget> it(m_widgets);
+ for(; it.current(); ++it)
+ {
+ TQString current(it.currentKey());
+ if(!replyList.contains(current))
+ {
+ m_widgets[current]->~dockwidget();
+ m_labels[current]->~TQLabel();
+ m_widgets.remove(current);
+ m_labels.remove(current);
+ }
+ }
+ } else {
+ KMessageBox::sorry(0, i18n("The weather service is unreachable!"));
+ }
+
+ if( firstTime )
+ timeOut->start(15*60000);
+ else
+ {
+ timeOut->changeInterval(15*60000);
+ connect(timeOut, TQT_SIGNAL(timeout()), this, TQT_SLOT(updateWidgets()));
}
- timeOut->start(15*60000);
+}
+
+bool KonqSidebarWeather::startWeatherService()
+{
+ TQByteArray data, replyData;
+ TQCString replyType;
+ TQDataStream arg(data, IO_WriteOnly);
+ arg << TQString("KWeatherService") << TQStringList();
+
+ if ( !kapp->dcopClient()->call(
+ "tdelauncher", "tdelauncher",
+ "start_service_by_name(TQString,TQStringList)",
+ data, replyType, replyData) ) {
+ kdDebug() << "Cannot start weather service: tdelauncher call failed." << endl;
+ return false;
+ }
+
+ TQDataStream reply(replyData, IO_ReadOnly);
+ if ( replyType != "serviceResult" )
+ {
+ kdDebug() << "Cannot start weather service: unknown reply type by tdelauncher." << endl;
+ return false;
+ }
+
+ int result;
+ TQCString dcopName;
+ TQString error;
+ reply >> result >> dcopName >> error;
+ if (result != 0)
+ {
+ kdDebug() << "Cannot start weather service: " << error.local8Bit().data() << endl;
+ return false;
+ }
+
+ return true;
}
extern "C"
@@ -159,8 +229,8 @@ extern "C"
TQMap<TQString, TQString>* map)
{
map->insert("Type","Link");
- map->insert("Icon","weather_sidebar");
- map->insert("Name",i18n("Sidebar Weather Report"));
+ map->insert("Icon","kweather");
+ map->insert("Name",i18n("Weather"));
map->insert("Open","false");
map->insert("X-TDE-KonqSidebarModule","weather_sidebar");
fn->setLatin1("weatherbar%1.desktop");