summaryrefslogtreecommitdiffstats
path: root/kweather
diff options
context:
space:
mode:
Diffstat (limited to 'kweather')
-rw-r--r--kweather/CMakeLists.txt26
-rw-r--r--kweather/dockwidget.cpp2
-rw-r--r--kweather/kweather.cpp28
-rw-r--r--kweather/sidebarwidget.cpp98
-rw-r--r--kweather/sidebarwidget.h27
-rw-r--r--kweather/sidebarwidgetbase.ui112
-rw-r--r--kweather/weatherbar.cpp128
-rw-r--r--kweather/weatherbar.desktop5
-rw-r--r--kweather/weatherbar.h14
-rw-r--r--kweather/weatherbar_add.desktop5
-rw-r--r--kweather/weatherservice.cpp5
-rw-r--r--kweather/weatherservice.h1
12 files changed, 251 insertions, 200 deletions
diff --git a/kweather/CMakeLists.txt b/kweather/CMakeLists.txt
index 5aa6517..dcf4722 100644
--- a/kweather/CMakeLists.txt
+++ b/kweather/CMakeLists.txt
@@ -130,6 +130,18 @@ tde_add_kpart( kcm_weatherservice AUTOMOC
DESTINATION ${PLUGIN_INSTALL_DIR}
)
+##### weather_sidebar (kpart) ####################
+if( BUILD_KONQ_KWEATHER )
+ tde_import( konqueror )
+ tde_add_kpart( weather_sidebar AUTOMOC
+ SOURCES sidebarwidget.cpp dockwidget.cpp
+ weatherbar.cpp weatherbar.skel
+ weatherbutton.cpp weatherservice.stub
+ LINK tdeio-shared konqsidebarplugin-shared tdeutils-shared
+ DESTINATION ${PLUGIN_INSTALL_DIR}
+ )
+endif( )
+
##### icons #####################################
@@ -164,3 +176,17 @@ tde_create_translated_desktop(
DESTINATION ${SERVICES_INSTALL_DIR}
PO_DIR kweather-desktops
)
+
+if( BUILD_KONQ_KWEATHER )
+ tde_create_translated_desktop(
+ SOURCE weatherbar.desktop
+ DESTINATION ${DATA_INSTALL_DIR}/konqsidebartng/entries
+ PO_DIR kweather-desktops
+ )
+
+ tde_create_translated_desktop(
+ SOURCE weatherbar_add.desktop
+ DESTINATION ${DATA_INSTALL_DIR}/konqsidebartng/add
+ PO_DIR kweather-desktops
+ )
+endif( )
diff --git a/kweather/dockwidget.cpp b/kweather/dockwidget.cpp
index 6319ad1..98d00ac 100644
--- a/kweather/dockwidget.cpp
+++ b/kweather/dockwidget.cpp
@@ -179,7 +179,7 @@ void dockwidget::initDock()
m_lblWind->setMargin(0);
m_lblPres->setMargin(0);
- TQBoxLayout *mainLayout = new TQBoxLayout(this, TQBoxLayout::TopToBottom);
+ TQBoxLayout *mainLayout = new TQBoxLayout(this, TQBoxLayout::LeftToRight);
mainLayout->setSpacing(0);
mainLayout->setMargin(0);
mainLayout->addWidget(m_button, 0, TQt::AlignCenter);
diff --git a/kweather/kweather.cpp b/kweather/kweather.cpp
index 71fe647..eb87f98 100644
--- a/kweather/kweather.cpp
+++ b/kweather/kweather.cpp
@@ -58,21 +58,21 @@ kweather::kweather(const TQString& configFile, Type t, int actions,
{
kdDebug(12004) << "Constructor " << endl;
setObjId("weatherIface");
-
+
setBackgroundOrigin( TQWidget::AncestorOrigin );
loadPrefs();
initContextMenu();
initDCOP();
-
+
dockWidget = new dockwidget(reportLocation, this, "dockwidget");
connect(dockWidget, TQT_SIGNAL(buttonClicked()), TQT_SLOT(doReport()));
dockWidget->setViewMode(mViewMode);
setLabelColor();
-
+
timeOut = new TQTimer(this, "timeOut" );
connect(timeOut, TQT_SIGNAL(timeout()), TQT_SLOT(timeout()));
timeOut->start(10*60*1000);
-
+
if(mFirstRun)
preferences();
else
@@ -103,20 +103,20 @@ void kweather::initDCOP()
{
if ( !mClient )
mClient = TDEApplication::dcopClient();
-
+
if(!mClient->isAttached())
mClient->attach();
-
+
if(!attach())
return;
-
+
kdDebug(12004) << "attached to the server..." << endl;
-
+
if ( mWeatherService )
delete mWeatherService;
-
+
mWeatherService = new WeatherService_stub( "KWeatherService", "WeatherService" );
-
+
if (!connectDCOPSignal(0, 0, "fileUpdate(TQString)",
"refresh(TQString)",false))
kdDebug(12004) << "Could not attach dcop signal..." << endl;
@@ -189,10 +189,10 @@ void kweather::doReport()
if ( mReport == 0 )
{
mReport = new reportView(reportLocation);
-
+
connect( mReport, TQT_SIGNAL( finished() ), TQT_SLOT( slotReportFinished() ) );
}
-
+
mReport->show();
mReport->raise();
}
@@ -225,7 +225,7 @@ void kweather::loadPrefs(){
void kweather::savePrefs(){
kdDebug(12004) << "Saving Prefs..." << endl;
TDEConfig *kcConfig = config();
-
+
kcConfig->setGroup("General Options");
kcConfig->writeEntry("logging", logOn);
kcConfig->writeEntry("report_location", reportLocation);
@@ -286,7 +286,7 @@ void kweather::timeout()
{
if ( !mWeatherService )
initDCOP();
-
+
if ( mWeatherService )
{
// isEmtpy is true for null and 0 length strings
diff --git a/kweather/sidebarwidget.cpp b/kweather/sidebarwidget.cpp
index 0a7c080..45a97fd 100644
--- a/kweather/sidebarwidget.cpp
+++ b/kweather/sidebarwidget.cpp
@@ -1,4 +1,4 @@
- /*
+/*
* This file is part of the KDE project
* Copyright (C) 2002 Ian Reinhart Geiser <geiseri@kde.org>
*
@@ -18,32 +18,78 @@
*
* $Id$
*/
-
- #include "sidebarwidget.h"
- #include <tqscrollview.h>
-
- sidebarwidget::sidebarwidget(TQWidget* parent, const char* name) :
- sidebarwidgetbase(parent,name)
- {
- view = new TQVBox(reportGrid->viewport());
- reportGrid->addChild(view);
- reportGrid->setResizePolicy(TQScrollView::AutoOneFit);
- }
-
- sidebarwidget::~sidebarwidget()
- {
-
- }
-
- void sidebarwidget::addWidget(TQWidget *w, const TQString &s)
- {
- w->setFixedWidth(reportGrid->visibleWidth ());
- }
-
- TQWidget *sidebarwidget::viewport()
+
+#include "sidebarwidget.h"
+#include <tqscrollview.h>
+#include <tqlayout.h>
+#include <tqvbox.h>
+#include <ksettings/dialog.h>
+#include <ksettings/dispatcher.h>
+#include <kcmultidialog.h>
+
+#include <kiconloader.h>
+#include <tdetoolbar.h>
+#include <tdeaction.h>
+#include <tdelocale.h>
+#include <dcopref.h>
+
+sidebarwidget::sidebarwidget(TQWidget* parent, const char* name)
+ : TQWidget(parent,name)
+{
+ mainLayout = new TQVBoxLayout(this);
+
+ TDEToolBar *toolbar = new TDEToolBar(this);
+ toolbar->setLabel( i18n("Weather Sidebar") );
+ toolbar->setSizePolicy(TQSizePolicy::Maximum, TQSizePolicy::Minimum);
+
+ TDEAction *refresh = new TDEAction( i18n("Refresh"), SmallIcon("view-refresh"),
+ 0, TQT_TQOBJECT(this), TQT_SLOT(slotRefresh()), this, "refresh" );
+ TDEAction *prefs = new TDEAction( i18n("Settings"), SmallIcon("configure"),
+ 0, TQT_TQOBJECT(this), TQT_SLOT(slotConfigure()), this, "preferences" );
+ refresh->plug(toolbar);
+ prefs->plug(toolbar);
+
+ reportGrid = new TQScrollView(this);
+ reportGrid->setResizePolicy(TQScrollView::AutoOneFit);
+
+ layout = new TQVBoxLayout(reportGrid->viewport());
+ view = new TQVBox(reportGrid->viewport());
+ view->setSpacing(3);
+ layout->addWidget(view);
+ layout->addStretch();
+
+ mainLayout->addWidget(toolbar);
+ mainLayout->addWidget(reportGrid);
+
+ dcopCall = new DCOPRef( "KWeatherService", "WeatherService" );
+}
+
+sidebarwidget::~sidebarwidget()
+{
+}
+
+TQWidget *sidebarwidget::viewport()
+{
+ return view;
+}
+
+void sidebarwidget::slotRefresh()
+{
+ dcopCall->send("updateAll()");
+}
+
+void sidebarwidget::slotConfigure()
+{
+ if ( settingsDialog == 0 )
{
- return view;
+ settingsDialog = new KCMultiDialog(0);
+ connect( settingsDialog, TQT_SIGNAL( configCommitted() ), this, TQT_SLOT( slotRefresh() ) );
+
+ settingsDialog->addModule( "kcmweatherservice.desktop" );
}
+ settingsDialog->show();
+ settingsDialog->raise();
+}
+
#include "sidebarwidget.moc"
-
diff --git a/kweather/sidebarwidget.h b/kweather/sidebarwidget.h
index fea25ea..a45139e 100644
--- a/kweather/sidebarwidget.h
+++ b/kweather/sidebarwidget.h
@@ -22,21 +22,36 @@
#ifndef __SIDEBARWIDGET_H__
#define __SIDEBARWIDGET_H__
+#include <tqwidget.h>
-#include <sidebarwidgetbase.h>
-#include <tqvbox.h>
+class TQVBox;
+class TQVBoxLayout;
+class TQScrollView;
+class KCMultiDialog;
+class DCOPRef;
-class sidebarwidget : public sidebarwidgetbase
+class sidebarwidget : public TQWidget
{
Q_OBJECT
-
-public:
+
+ public:
sidebarwidget(TQWidget* parent, const char* name = 0);
virtual ~sidebarwidget();
- void addWidget(TQWidget *w, const TQString &s);
TQWidget *viewport();
+ TQScrollView *reportGrid;
+ TQVBoxLayout *mainLayout;
+ TQVBoxLayout *layout;
TQVBox *view;
+
+ private slots:
+ void slotRefresh();
+ void slotConfigure();
+
+ private:
+ DCOPRef *dcopCall;
+ KCMultiDialog *settingsDialog = 0;
+
};
#endif
diff --git a/kweather/sidebarwidgetbase.ui b/kweather/sidebarwidgetbase.ui
deleted file mode 100644
index 6f1f50c..0000000
--- a/kweather/sidebarwidgetbase.ui
+++ /dev/null
@@ -1,112 +0,0 @@
-<!DOCTYPE UI><UI version="3.1" stdsetdef="1">
-<class>sidebarwidgetbase</class>
-<author>ian reinhart geiser &lt;geiseri@kde.org&gt;</author>
-<widget class="TQWidget">
- <property name="name">
- <cstring>Form1</cstring>
- </property>
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>338</width>
- <height>480</height>
- </rect>
- </property>
- <grid>
- <property name="name">
- <cstring>unnamed</cstring>
- </property>
- <widget class="TQGroupBox" row="1" column="0">
- <property name="name">
- <cstring>GroupBox2</cstring>
- </property>
- <property name="title">
- <string>Station Manager</string>
- </property>
- <grid>
- <property name="name">
- <cstring>unnamed</cstring>
- </property>
- <widget class="TQLayoutWidget" row="0" column="0">
- <property name="name">
- <cstring>Layout1</cstring>
- </property>
- <hbox>
- <property name="name">
- <cstring>unnamed</cstring>
- </property>
- <widget class="KComboBox">
- <property name="name">
- <cstring>stationList</cstring>
- </property>
- </widget>
- <widget class="KPushButton">
- <property name="name">
- <cstring>addStation</cstring>
- </property>
- <property name="text">
- <string>Add</string>
- </property>
- </widget>
- </hbox>
- </widget>
- <spacer row="0" column="1">
- <property name="name">
- <cstring>Spacer4</cstring>
- </property>
- <property name="orientation">
- <enum>Horizontal</enum>
- </property>
- <property name="sizeType">
- <enum>Expanding</enum>
- </property>
- <property name="sizeHint">
- <size>
- <width>20</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </grid>
- </widget>
- <widget class="TQGroupBox" row="0" column="0">
- <property name="name">
- <cstring>reportGroup</cstring>
- </property>
- <property name="title">
- <string>Weather Report</string>
- </property>
- <grid>
- <property name="name">
- <cstring>unnamed</cstring>
- </property>
- <widget class="TQScrollView" row="0" column="0">
- <property name="name">
- <cstring>reportGrid</cstring>
- </property>
- </widget>
- </grid>
- </widget>
- </grid>
-</widget>
-<customwidgets>
- <customwidget>
- <class>QScrollView</class>
- <header location="global">qscrollview.h</header>
- <sizehint>
- <width>25</width>
- <height>25</height>
- </sizehint>
- <container>1</container>
- <sizepolicy>
- <hordata>3</hordata>
- <verdata>3</verdata>
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- <pixmap>image0</pixmap>
- </customwidget>
-</customwidgets>
-<layoutdefaults spacing="5" margin="5"/>
-</UI>
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");
diff --git a/kweather/weatherbar.desktop b/kweather/weatherbar.desktop
index 0c19789..c911a54 100644
--- a/kweather/weatherbar.desktop
+++ b/kweather/weatherbar.desktop
@@ -1,8 +1,7 @@
[Desktop Entry]
Type=Link
-URL=
-Icon=weather_sidebar
-Name=Sidebar Weather Report
+Icon=kweather
+Name=Weather
Open=false
X-TDE-KonqSidebarModule=weather_sidebar
diff --git a/kweather/weatherbar.h b/kweather/weatherbar.h
index 0bf6075..8607d59 100644
--- a/kweather/weatherbar.h
+++ b/kweather/weatherbar.h
@@ -33,11 +33,12 @@
class dockwidget;
class sidebarwidget;
+class TQLabel;
class KonqSidebarWeather: public KonqSidebarPlugin, virtual public DCOPObject
{
Q_OBJECT
-
+
K_DCOP
public:
KonqSidebarWeather(TDEInstance* inst, TQObject* parent, TQWidget* widgetParent,
@@ -50,16 +51,19 @@ public:
k_dcop:
virtual void refresh(TQString);
-
+
+public slots:
+ virtual void updateWidgets( bool firstTime = false );
+
protected:
virtual void handleURL(const KURL &url);
virtual void handlePreview(const KFileItemList& items);
virtual void handlePreviewOnMouseOver(const KFileItem& item);
-private slots:
- void update();
-
private:
+ bool startWeatherService();
+
+ TQDict <TQLabel> m_labels;
TQDict <dockwidget> m_widgets;
sidebarwidget *m_container;
TQTimer *timeOut;
diff --git a/kweather/weatherbar_add.desktop b/kweather/weatherbar_add.desktop
index f30db1a..5f514f9 100644
--- a/kweather/weatherbar_add.desktop
+++ b/kweather/weatherbar_add.desktop
@@ -1,8 +1,7 @@
[Desktop Entry]
Type=Link
-URL=
-Icon=weather_sidebar
-Name=Sidebar Weather Report
+Icon=kweather
+Name=Weather
Open=false
X-TDE-KonqSidebarAddModule=weather_sidebar
diff --git a/kweather/weatherservice.cpp b/kweather/weatherservice.cpp
index 60ad1b2..9bf3561 100644
--- a/kweather/weatherservice.cpp
+++ b/kweather/weatherservice.cpp
@@ -192,12 +192,16 @@ void WeatherService::removeStation(const TQString &stationID)
{
m_weatherLib->remove(stationID);
saveSettings();
+ emit stationRemoved(stationID);
+ kdDebug() << "KWeatherService: station removed: " << stationID << endl;
}
void WeatherService::addStation(const TQString &stationID)
{
m_weatherLib->update(stationID);
saveSettings();
+ emit stationAdded(stationID);
+ kdDebug() << "KWeatherService: station added: " << stationID << endl;
}
void WeatherService::exit()
@@ -339,5 +343,4 @@ TQString WeatherService::civilTwilightEnd(const TQString &stationID)
}
-
#include "weatherservice.moc"
diff --git a/kweather/weatherservice.h b/kweather/weatherservice.h
index 5bc19ae..dba1ac9 100644
--- a/kweather/weatherservice.h
+++ b/kweather/weatherservice.h
@@ -51,6 +51,7 @@ class WeatherService : public TQObject, public DCOPObject
void fileUpdating(TQString);
void fileUpdate(TQString);
void stationRemoved(TQString);
+ void stationAdded(TQString);
k_dcop:
TQString temperature(const TQString &stationID);