summaryrefslogtreecommitdiffstats
path: root/kontact/plugins/weather
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 (patch)
tree67208f7c145782a7e90b123b982ca78d88cc2c87 /kontact/plugins/weather
downloadtdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.tar.gz
tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kontact/plugins/weather')
-rw-r--r--kontact/plugins/weather/Makefile.am13
-rw-r--r--kontact/plugins/weather/summarywidget.cpp230
-rw-r--r--kontact/plugins/weather/summarywidget.h123
-rw-r--r--kontact/plugins/weather/weather_plugin.cpp61
-rw-r--r--kontact/plugins/weather/weather_plugin.h44
-rw-r--r--kontact/plugins/weather/weatherplugin.desktop92
6 files changed, 563 insertions, 0 deletions
diff --git a/kontact/plugins/weather/Makefile.am b/kontact/plugins/weather/Makefile.am
new file mode 100644
index 000000000..dc547a0ce
--- /dev/null
+++ b/kontact/plugins/weather/Makefile.am
@@ -0,0 +1,13 @@
+INCLUDES = -I$(top_srcdir)/kontact/interfaces -I$(top_srcdir)/libkdepim -I$(top_srcdir) $(all_includes)
+
+kde_module_LTLIBRARIES = libkontact_weatherplugin.la
+libkontact_weatherplugin_la_LDFLAGS = $(all_libraries) $(KDE_PLUGIN)
+libkontact_weatherplugin_la_LIBADD = $(top_builddir)/kontact/interfaces/libkpinterfaces.la $(LIB_KPARTS) $(top_builddir)/libkdepim/libkdepim.la
+
+libkontact_weatherplugin_la_SOURCES = weather_plugin.cpp summarywidget.cpp \
+ summarywidget.skel
+
+METASOURCES = AUTO
+
+servicedir = $(kde_servicesdir)/kontact
+service_DATA = weatherplugin.desktop
diff --git a/kontact/plugins/weather/summarywidget.cpp b/kontact/plugins/weather/summarywidget.cpp
new file mode 100644
index 000000000..04a559ae4
--- /dev/null
+++ b/kontact/plugins/weather/summarywidget.cpp
@@ -0,0 +1,230 @@
+/*
+ This file is part of Kontact.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ 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 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.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+#include <qimage.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qtooltip.h>
+
+#include <dcopclient.h>
+#include <dcopref.h>
+#include <kapplication.h>
+#include <kdebug.h>
+#include <kglobal.h>
+#include <kglobalsettings.h>
+#include <kiconloader.h>
+#include <klocale.h>
+#include <kprocess.h>
+#include <kurllabel.h>
+
+#include "summarywidget.h"
+
+SummaryWidget::SummaryWidget( QWidget *parent, const char *name )
+ : Kontact::Summary( parent, name ),
+ DCOPObject( "WeatherSummaryWidget" ), mProc( 0 )
+{
+ mLayout = new QVBoxLayout( this, 3, 3 );
+ mLayout->setAlignment( Qt::AlignTop );
+
+ QPixmap icon = KGlobal::iconLoader()->loadIcon( "kweather", KIcon::Desktop, KIcon::SizeMedium );
+ QWidget *header = createHeader( this, icon, i18n( "Weather Service" ) );
+ mLayout->addWidget( header );
+
+ QString error;
+ QCString appID;
+ bool serviceAvailable = true;
+ if ( !kapp->dcopClient()->isApplicationRegistered( "KWeatherService" ) ) {
+ if ( KApplication::startServiceByDesktopName( "kweatherservice", QStringList(), &error, &appID ) ) {
+ QLabel *label = new QLabel( i18n( "No weather dcop service available;\nyou need KWeather to use this plugin." ), this );
+ mLayout->addWidget( label, Qt::AlignHCenter | AlignVCenter );
+ serviceAvailable = false;
+ }
+ }
+
+ if ( serviceAvailable ) {
+ connectDCOPSignal( 0, 0, "fileUpdate(QString)", "refresh(QString)", false );
+ connectDCOPSignal( 0, 0, "stationRemoved(QString)", "stationRemoved(QString)", false );
+
+ DCOPRef dcopCall( "KWeatherService", "WeatherService" );
+ DCOPReply reply = dcopCall.call( "listStations()", true );
+ if ( reply.isValid() ) {
+ mStations = reply;
+
+ connect( &mTimer, SIGNAL( timeout() ), this, SLOT( timeout() ) );
+ mTimer.start( 0 );
+ } else {
+ kdDebug(5602) << "ERROR: dcop reply not valid..." << endl;
+ }
+ }
+}
+
+
+void SummaryWidget::updateView()
+{
+ mLayouts.setAutoDelete( true );
+ mLayouts.clear();
+ mLayouts.setAutoDelete( false );
+
+ mLabels.setAutoDelete( true );
+ mLabels.clear();
+ mLabels.setAutoDelete( false );
+
+ if ( mStations.count() == 0 ) {
+ kdDebug(5602) << "No weather stations defined..." << endl;
+ return;
+ }
+
+
+ QValueList<WeatherData> dataList = mWeatherMap.values();
+ qHeapSort( dataList );
+
+ QValueList<WeatherData>::Iterator it;
+ for ( it = dataList.begin(); it != dataList.end(); ++it ) {
+ QString cover;
+ for ( uint i = 0; i < (*it).cover().count(); ++i )
+ cover += QString( "- %1\n" ).arg( (*it).cover()[ i ] );
+
+ QImage img;
+ img = (*it).icon();
+
+ QGridLayout *layout = new QGridLayout( mLayout, 3, 3, 3 );
+ mLayouts.append( layout );
+
+ KURLLabel* urlLabel = new KURLLabel( this );
+ urlLabel->installEventFilter( this );
+ urlLabel->setURL( (*it).stationID() );
+ urlLabel->setPixmap( img.smoothScale( 32, 32 ) );
+ urlLabel->setMaximumSize( urlLabel->sizeHint() );
+ urlLabel->setAlignment( AlignTop );
+ layout->addMultiCellWidget( urlLabel, 0, 1, 0, 0 );
+ mLabels.append( urlLabel );
+ connect ( urlLabel, SIGNAL( leftClickedURL( const QString& ) ),
+ this, SLOT( showReport( const QString& ) ) );
+
+ QLabel* label = new QLabel( this );
+ label->setText( QString( "%1 (%2)" ).arg( (*it).name() ).arg( (*it).temperature() ) );
+ QFont font = label->font();
+ font.setBold( true );
+ label->setFont( font );
+ label->setAlignment( AlignLeft );
+ layout->addMultiCellWidget( label, 0, 0, 1, 2 );
+ mLabels.append( label );
+
+ QString labelText;
+ labelText = QString( "<b>%1:</b> %2<br>"
+ "<b>%3:</b> %4<br>"
+ "<b>%5:</b> %6" )
+ .arg( i18n( "Last updated on" ) )
+ .arg( (*it).date() )
+ .arg( i18n( "Wind Speed" ) )
+ .arg( (*it).windSpeed() )
+ .arg( i18n( "Rel. Humidity" ) )
+ .arg( (*it).relativeHumidity() );
+
+ QToolTip::add( label, labelText.replace( " ", "&nbsp;" ) );
+
+ label = new QLabel( cover, this );
+ label->setAlignment( AlignLeft );
+ layout->addMultiCellWidget( label, 1, 1, 1, 2 );
+ mLabels.append( label );
+ }
+
+ for ( QLabel *label = mLabels.first(); label; label = mLabels.next() )
+ label->show();
+}
+
+void SummaryWidget::timeout()
+{
+ mTimer.stop();
+
+ DCOPRef dcopCall( "KWeatherService", "WeatherService" );
+ dcopCall.send( "updateAll()" );
+
+ mTimer.start( 15 * 60000 );
+}
+
+void SummaryWidget::refresh( QString station )
+{
+ DCOPRef dcopCall( "KWeatherService", "WeatherService" );
+
+ mWeatherMap[ station ].setIcon( dcopCall.call( "currentIcon(QString)", station, true ) );
+ mWeatherMap[ station ].setName( dcopCall.call( "stationName(QString)", station, true ) );
+ mWeatherMap[ station ].setCover( dcopCall.call( "cover(QString)", station, true ) );
+ mWeatherMap[ station ].setDate( dcopCall.call( "date(QString)", station, true ) );
+ mWeatherMap[ station ].setTemperature( dcopCall.call( "temperature(QString)", station, true ) );
+ mWeatherMap[ station ].setWindSpeed( dcopCall.call( "wind(QString)", station, true ) );
+ mWeatherMap[ station ].setRelativeHumidity( dcopCall.call( "relativeHumidity(QString)", station, true ) );
+ mWeatherMap[ station ].setStationID(station);
+
+ updateView();
+}
+
+void SummaryWidget::stationRemoved( QString station )
+{
+ mWeatherMap.remove( station );
+ updateView();
+}
+
+bool SummaryWidget::eventFilter( QObject *obj, QEvent* e )
+{
+ if ( obj->inherits( "KURLLabel" ) ) {
+ if ( e->type() == QEvent::Enter )
+ emit message(
+ i18n( "View Weather Report for Station" ) );
+ if ( e->type() == QEvent::Leave )
+ emit message( QString::null );
+ }
+
+ return Kontact::Summary::eventFilter( obj, e );
+}
+
+QStringList SummaryWidget::configModules() const
+{
+ return QStringList( "kcmweatherservice.desktop" );
+}
+
+void SummaryWidget::updateSummary( bool )
+{
+ timeout();
+}
+
+void SummaryWidget::showReport( const QString &stationID )
+{
+ mProc = new KProcess;
+ QApplication::connect( mProc, SIGNAL( processExited( KProcess* ) ),
+ this, SLOT( reportFinished( KProcess* ) ) );
+ *mProc << "kweatherreport";
+ *mProc << stationID;
+
+ if ( !mProc->start() ) {
+ delete mProc;
+ mProc = 0;
+ }
+}
+
+void SummaryWidget::reportFinished( KProcess* )
+{
+ mProc->deleteLater();
+ mProc = 0;
+}
+
+#include "summarywidget.moc"
diff --git a/kontact/plugins/weather/summarywidget.h b/kontact/plugins/weather/summarywidget.h
new file mode 100644
index 000000000..40e0bb705
--- /dev/null
+++ b/kontact/plugins/weather/summarywidget.h
@@ -0,0 +1,123 @@
+/*
+ This file is part of Kontact.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ 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 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.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef SUMMARYWIDGET_H
+#define SUMMARYWIDGET_H
+
+#include "summary.h"
+
+#include <dcopobject.h>
+
+#include <qmap.h>
+#include <qpixmap.h>
+#include <qptrlist.h>
+#include <qstringlist.h>
+#include <qtimer.h>
+#include <qwidget.h>
+
+class KProcess;
+
+class QGridLayout;
+class QLabel;
+class QVBoxLayout;
+
+class WeatherData
+{
+ public:
+ void setIcon( const QPixmap &icon ) { mIcon = icon; }
+ QPixmap icon() const { return mIcon; }
+
+ void setName( const QString &name ) { mName = name; }
+ QString name() const { return mName; }
+
+ void setCover( const QStringList& cover ) { mCover = cover; }
+ QStringList cover() const { return mCover; }
+
+ void setDate( const QString &date ) { mDate = date; }
+ QString date() const { return mDate; }
+
+ void setTemperature( const QString &temperature ) { mTemperature = temperature; }
+ QString temperature() const { return mTemperature; }
+
+ void setWindSpeed( const QString &windSpeed ) { mWindSpeed = windSpeed; }
+ QString windSpeed() const { return mWindSpeed; }
+
+ void setRelativeHumidity( const QString &relativeHumidity ) { mRelativeHumidity = relativeHumidity; }
+ QString relativeHumidity() const { return mRelativeHumidity; }
+
+ void setStationID( const QString &station ) { mStationID = station;}
+ QString stationID() { return mStationID; }
+
+ bool operator< ( const WeatherData &data )
+ {
+ return ( QString::localeAwareCompare( mName, data.mName ) < 0 );
+ }
+
+ private:
+ QPixmap mIcon;
+ QString mName;
+ QStringList mCover;
+ QString mDate;
+ QString mTemperature;
+ QString mWindSpeed;
+ QString mRelativeHumidity;
+ QString mStationID;
+};
+
+class SummaryWidget : public Kontact::Summary, public DCOPObject
+{
+ Q_OBJECT
+ K_DCOP
+ public:
+ SummaryWidget( QWidget *parent, const char *name = 0 );
+
+ QStringList configModules() const;
+
+ void updateSummary( bool force = false );
+
+ k_dcop:
+ virtual void refresh( QString );
+ virtual void stationRemoved( QString );
+
+ protected:
+ virtual bool eventFilter( QObject *obj, QEvent *e );
+
+ private slots:
+ void updateView();
+ void timeout();
+ void showReport( const QString& );
+ void reportFinished( KProcess* );
+
+ private:
+ QStringList mStations;
+ QMap<QString, WeatherData> mWeatherMap;
+ QTimer mTimer;
+
+ QPtrList<QLabel> mLabels;
+ QPtrList<QGridLayout> mLayouts;
+ QVBoxLayout *mLayout;
+
+ KProcess* mProc;
+};
+
+#endif
diff --git a/kontact/plugins/weather/weather_plugin.cpp b/kontact/plugins/weather/weather_plugin.cpp
new file mode 100644
index 000000000..4c1a91e6e
--- /dev/null
+++ b/kontact/plugins/weather/weather_plugin.cpp
@@ -0,0 +1,61 @@
+/*
+ This file is part of Kontact.
+ Copyright (C) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <kaboutdata.h>
+#include <kgenericfactory.h>
+#include <kparts/componentfactory.h>
+
+#include "core.h"
+#include "summarywidget.h"
+
+#include "weather_plugin.h"
+
+typedef KGenericFactory< WeatherPlugin, Kontact::Core > WeatherPluginFactory;
+K_EXPORT_COMPONENT_FACTORY( libkontact_weatherplugin,
+ WeatherPluginFactory( "kontact_weatherplugin" ) )
+
+WeatherPlugin::WeatherPlugin( Kontact::Core *core, const char *name, const QStringList& )
+ : Kontact::Plugin( core, core, name ), mAboutData( 0 )
+{
+ setInstance( WeatherPluginFactory::instance() );
+}
+
+Kontact::Summary *WeatherPlugin::createSummaryWidget( QWidget *parentWidget )
+{
+ return new SummaryWidget( parentWidget );
+}
+
+const KAboutData *WeatherPlugin::aboutData()
+{
+ if ( !mAboutData ) {
+ mAboutData = new KAboutData( "weatherplugin", I18N_NOOP( "Weather Information" ),
+ "0.1",
+ I18N_NOOP( "Weather Information" ),
+ KAboutData::License_GPL_V2,
+ "(c) 2003 The Kontact developers" );
+ mAboutData->addAuthor( "Ian Reinhart Geiser", "", "geiseri@kde.org" );
+ mAboutData->addAuthor( "Tobias Koenig", "", "tokoe@kde.org" );
+ mAboutData->addCredit( "John Ratke",
+ I18N_NOOP( "Improvements and more code cleanups" ),
+ "jratke@comcast.net" );
+ }
+
+ return mAboutData;
+}
diff --git a/kontact/plugins/weather/weather_plugin.h b/kontact/plugins/weather/weather_plugin.h
new file mode 100644
index 000000000..637ebea9c
--- /dev/null
+++ b/kontact/plugins/weather/weather_plugin.h
@@ -0,0 +1,44 @@
+/*
+ This file is part of Kontact.
+ Copyright (C) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef WEATHER_PLUGIN_H
+#define WEATHER_PLUGIN_H
+
+#include "plugin.h"
+
+class SummaryWidget;
+
+class WeatherPlugin : public Kontact::Plugin
+{
+ public:
+ WeatherPlugin( Kontact::Core *core, const char *name, const QStringList& );
+ WeatherPlugin();
+
+ virtual Kontact::Summary *createSummaryWidget( QWidget *parentWidget );
+
+ const KAboutData *aboutData();
+
+ protected:
+ virtual KParts::ReadOnlyPart *createPart() { return 0; }
+ private:
+ KAboutData *mAboutData;
+};
+
+#endif
diff --git a/kontact/plugins/weather/weatherplugin.desktop b/kontact/plugins/weather/weatherplugin.desktop
new file mode 100644
index 000000000..68c1924e3
--- /dev/null
+++ b/kontact/plugins/weather/weatherplugin.desktop
@@ -0,0 +1,92 @@
+[Desktop Entry]
+Type=Service
+Icon=kweather
+ServiceTypes=Kontact/Plugin,KPluginInfo
+TryExec=kweatherservice
+
+X-KDE-Library=libkontact_weatherplugin
+X-KDE-KontactIdentifier=weather
+X-KDE-KontactPluginVersion=6
+X-KDE-KontactPluginHasSummary=true
+X-KDE-KontactPluginHasPart=false
+
+X-KDE-PluginInfo-Name=kontact_weatherplugin
+X-KDE-PluginInfo-Version=0.1
+X-KDE-PluginInfo-License=LGPL
+X-KDE-PluginInfo-EnabledByDefault=true
+
+Comment=Kontact Weather Component
+Comment[bg]=Приставка за метеорологичното време
+Comment[ca]=Component del temps del Kontact
+Comment[da]=Vejrkomponent til Kontact
+Comment[de]=Wetter-Komponente für Kontact
+Comment[el]=Συστατικό καιρού του Kontact
+Comment[es]=Extensión de meteorología para Kontact
+Comment[et]=Kontacti ilmaplugin
+Comment[fr]=Composant météo pour Kontact
+Comment[is]=Kontact veðurfréttaeining
+Comment[it]=Componente meteorologico di Kontact
+Comment[ja]=Kontact 気象情報コンポーネント
+Comment[km]=សមាសភាគ​អាកាសធាតុ Kontact
+Comment[nds]=Kontact-Wederkomponent
+Comment[nl]=Kontact Weercomponent
+Comment[pl]=Składnik Kontaktu wiadomości o pogodzie
+Comment[ru]=Компонент информации о погоде для Kontact
+Comment[sr]=Компонента времена за Kontact
+Comment[sr@Latn]=Komponenta vremena za Kontact
+Comment[sv]=Kontacts väderkomponent
+Comment[tr]=Kontact Hava Durumu Bileşeni
+Comment[zh_CN]=Kontact 天气插件
+Comment[zh_TW]=Kontact 天氣組件
+Name=Weather Service
+Name[af]=Weer diens
+Name[ar]=خدمة الطقس
+Name[bg]=Информация за времето
+Name[br]=Servij an amzer
+Name[ca]=Servei meteorològic
+Name[cs]=Služba počasí
+Name[cy]=GwasanaethTywydd
+Name[da]=Vejrtjeneste
+Name[de]=Wetterdienst
+Name[el]=Υπηρεσία πρόβλεψης Καιρού
+Name[eo]=Veterservo
+Name[es]=Servicio meteorológico
+Name[et]=Ilmateade
+Name[eu]=Eguraldiaren zerbitzua
+Name[fa]=خدمت آب و هوا
+Name[fi]=Sääpalvelu
+Name[fr]=KWeatherService
+Name[fy]=Waarberjocht
+Name[ga]=Seirbhís Aimsire
+Name[gl]=Servicio do Tempo
+Name[he]=שירות מזג אוויר
+Name[hu]=Időjárás
+Name[is]=Veðurþjónusta
+Name[it]=Servizio meteorologico
+Name[ja]=気象サービス
+Name[ka]=ამინდის მომსახურება
+Name[kk]=Ауа райы қызметі
+Name[km]=សេវា​អាកាសធាតុ
+Name[lt]=Orų tarnyba
+Name[mk]=Временска прогноза
+Name[nb]=Værtjeneste
+Name[nds]=Wederdeenst
+Name[ne]=मौसम कार्य
+Name[nl]=Weerbericht
+Name[nn]=Vêrmelding
+Name[pl]=Pogoda
+Name[pt]=Serviço Meteorológico
+Name[pt_BR]=Serviço de Previsão do Tempo
+Name[ru]=Погода
+Name[sk]=Služba počasie
+Name[sl]=Vremenska storitev
+Name[sr]=Време
+Name[sr@Latn]=Vreme
+Name[sv]=Väderleksprognos
+Name[th]=รายงานอากาศ
+Name[tr]=Hava Durumu Servisi
+Name[uk]=Служба погоди
+Name[uz]=Ob-havo xizmati
+Name[uz@cyrillic]=Об-ҳаво хизмати
+Name[zh_CN]=天气服务
+Name[zh_TW]=天氣服務