26 #include <tqtooltip.h>
28 #include <dcopclient.h>
30 #include <tdeapplication.h>
32 #include <tdeglobal.h>
33 #include <tdeglobalsettings.h>
34 #include <kiconloader.h>
35 #include <tdelocale.h>
36 #include <tdeprocess.h>
37 #include <kurllabel.h>
39 #include "summarywidget.h"
41 SummaryWidget::SummaryWidget( TQWidget *parent,
const char *name )
42 : Kontact::Summary( parent, name ),
43 DCOPObject(
"WeatherSummaryWidget" ), mProc( 0 )
45 mLayout =
new TQVBoxLayout(
this, 3, 3 );
46 mLayout->setAlignment( TQt::AlignTop );
48 TQPixmap icon = TDEGlobal::iconLoader()->loadIcon(
"kweather", TDEIcon::Desktop, TDEIcon::SizeMedium );
49 TQWidget *header = createHeader(
this, icon, i18n(
"Weather Service" ) );
50 mLayout->addWidget( header );
54 bool serviceAvailable =
true;
55 if ( !kapp->dcopClient()->isApplicationRegistered(
"KWeatherService" ) ) {
56 if ( TDEApplication::startServiceByDesktopName(
"kweatherservice", TQStringList(), &error, &appID ) ) {
57 TQLabel *label =
new TQLabel( i18n(
"No weather dcop service available;\nyou need KWeather to use this plugin." ),
this );
58 mLayout->addWidget( label, TQt::AlignHCenter | AlignVCenter );
59 serviceAvailable =
false;
63 if ( serviceAvailable ) {
64 connectDCOPSignal( 0, 0,
"fileUpdate(TQString)",
"refresh(TQString)",
false );
65 connectDCOPSignal( 0, 0,
"stationRemoved(TQString)",
"stationRemoved(TQString)",
false );
67 DCOPRef dcopCall(
"KWeatherService",
"WeatherService" );
68 DCOPReply reply = dcopCall.call(
"listStations()",
true );
69 if ( reply.isValid() ) {
72 connect( &mTimer, TQ_SIGNAL( timeout() ),
this, TQ_SLOT( timeout() ) );
75 kdDebug(5602) <<
"ERROR: dcop reply not valid..." << endl;
81 void SummaryWidget::updateView()
83 mLayouts.setAutoDelete(
true );
85 mLayouts.setAutoDelete(
false );
87 mLabels.setAutoDelete(
true );
89 mLabels.setAutoDelete(
false );
91 if ( mStations.count() == 0 ) {
92 kdDebug(5602) <<
"No weather stations defined..." << endl;
97 TQValueList<WeatherData> dataList = mWeatherMap.values();
98 qHeapSort( dataList );
100 TQValueList<WeatherData>::Iterator it;
101 for ( it = dataList.begin(); it != dataList.end(); ++it ) {
103 for ( uint i = 0; i < (*it).cover().count(); ++i )
104 cover += TQString(
"- %1\n" ).arg( (*it).cover()[ i ] );
109 TQGridLayout *layout =
new TQGridLayout( mLayout, 3, 3, 3 );
110 mLayouts.append( layout );
112 KURLLabel* urlLabel =
new KURLLabel(
this );
113 urlLabel->installEventFilter(
this );
114 urlLabel->setURL( (*it).stationID() );
115 urlLabel->setPixmap( img.smoothScale( 32, 32 ) );
116 urlLabel->setMaximumSize( urlLabel->sizeHint() );
117 urlLabel->setAlignment( AlignTop );
118 layout->addMultiCellWidget( urlLabel, 0, 1, 0, 0 );
119 mLabels.append( urlLabel );
120 connect ( urlLabel, TQ_SIGNAL( leftClickedURL(
const TQString& ) ),
121 this, TQ_SLOT( showReport(
const TQString& ) ) );
123 TQLabel* label =
new TQLabel(
this );
124 label->setText( TQString(
"%1 (%2)" ).arg( (*it).name() ).arg( (*it).temperature() ) );
125 TQFont font = label->font();
126 font.setBold(
true );
127 label->setFont( font );
128 label->setAlignment( AlignLeft );
129 layout->addMultiCellWidget( label, 0, 0, 1, 2 );
130 mLabels.append( label );
133 labelText = TQString(
"<b>%1:</b> %2<br>"
136 .arg( i18n(
"Last updated on" ) )
138 .arg( i18n(
"Wind Speed" ) )
139 .arg( (*it).windSpeed() )
140 .arg( i18n(
"Rel. Humidity" ) )
141 .arg( (*it).relativeHumidity() );
143 TQToolTip::add( label, labelText.replace(
" ",
" " ) );
145 label =
new TQLabel( cover,
this );
146 label->setAlignment( AlignLeft );
147 layout->addMultiCellWidget( label, 1, 1, 1, 2 );
148 mLabels.append( label );
151 for ( TQLabel *label = mLabels.first(); label; label = mLabels.next() )
155 void SummaryWidget::timeout()
159 DCOPRef dcopCall(
"KWeatherService",
"WeatherService" );
160 dcopCall.send(
"updateAll()" );
162 mTimer.start( 15 * 60000 );
165 void SummaryWidget::refresh( TQString station )
167 DCOPRef dcopCall(
"KWeatherService",
"WeatherService" );
169 mWeatherMap[ station ].setIcon( dcopCall.call(
"currentIcon(TQString)", station,
true ) );
170 mWeatherMap[ station ].setName( dcopCall.call(
"stationName(TQString)", station,
true ) );
171 mWeatherMap[ station ].setCover( dcopCall.call(
"cover(TQString)", station,
true ) );
172 mWeatherMap[ station ].setDate( dcopCall.call(
"date(TQString)", station,
true ) );
173 mWeatherMap[ station ].setTemperature( dcopCall.call(
"temperature(TQString)", station,
true ) );
174 mWeatherMap[ station ].setWindSpeed( dcopCall.call(
"wind(TQString)", station,
true ) );
175 mWeatherMap[ station ].setRelativeHumidity( dcopCall.call(
"relativeHumidity(TQString)", station,
true ) );
176 mWeatherMap[ station ].setStationID(station);
181 void SummaryWidget::stationRemoved( TQString station )
183 mWeatherMap.remove( station );
187 bool SummaryWidget::eventFilter( TQObject *obj, TQEvent* e )
189 if ( obj->inherits(
"KURLLabel" ) ) {
190 if ( e->type() == TQEvent::Enter )
192 i18n(
"View Weather Report for Station" ) );
193 if ( e->type() == TQEvent::Leave )
194 emit message( TQString() );
197 return Kontact::Summary::eventFilter( obj, e );
200 TQStringList SummaryWidget::configModules()
const
202 return TQStringList(
"kcmweatherservice.desktop" );
205 void SummaryWidget::updateSummary(
bool )
210 void SummaryWidget::showReport(
const TQString &stationID )
212 mProc =
new TDEProcess;
213 TQApplication::connect( mProc, TQ_SIGNAL( processExited( TDEProcess* ) ),
214 this, TQ_SLOT( reportFinished( TDEProcess* ) ) );
215 *mProc <<
"kweatherreport";
218 if ( !mProc->start() ) {
224 void SummaryWidget::reportFinished( TDEProcess* )
226 mProc->deleteLater();
230 #include "summarywidget.moc"