Bug 118458

Summary: KWeather will not accept new locations.
Product: [Unmaintained] kweather-kde3 Reporter: Trevor <trevor2>
Component: generalAssignee: geiseri
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: openSUSE   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Trevor 2005-12-16 16:18:49 UTC
Version:           2.1.0 (using KDE KDE 3.4.2)
Installed from:    SuSE RPMs
OS:                Linux

First of all I have two systems with Kweather  running on SuSe 10.0 and with the same location selected. One works and the other reports "unknown station" or "Station reports that it needs maintenance" when I try to update from the applet. If I go into Configure KWeather on the non-working machine, the displayed weather icon in the Selected Station field is correct (split-brain patient?). The applet's pop-up shows KWeather 0000. Uninstalling and re-installing doesn't change the situation. I think I got into this situation by accidentally adding a blank Selected Station. I'd be happy if I could uninstall it COMPLETELY, so it wouldn't remember a bad selected station when re-installed.
Comment 1 Trevor 2005-12-17 14:01:34 UTC
See this bug report for a fix,:
Bug 116375: menubar kweather applet refuses to accept my location, defaults to 0000
Comment 2 Trevor 2005-12-17 16:50:10 UTC
Per Rick's comment, reproduced below, I was able to fix this problem. Thanks, Rick.:
 
Bug 116375: menubar kweather applet refuses to accept my location, defaults to 0000 ------- Additional Comment #4 From Rick Harris 2005-12-01 05:16 -------
Manually creating/editing the files as below has kweather working well now (also fixes Bug# 107733 with Kicker crashing): 
 
 ~/.kde/share/config/KWeatherServicerc 
 [WEATHERSTATIONS] 
 stations=YPAD 
 
 ~/.kde/share/config/weather_panelappletrc 
 [General Options] 
 log_file_name= 
 logging=false 
 report_location=YPAD 
 reportview_size=743,577 
 smallview_mode=2 
 
I advise any one following the changes in the comment to NOT make changes to the fields shown below, since they're specific to your system setup and have no no affect on the station selection problem.

reportview_size=743,577 
smallview_mode=2 
Comment 3 Ken Sandham 2006-04-23 04:38:09 UTC
Mine is a newly installed SUSE 10. When I saw this applwt I thought it would be very useful. But it doesnt work as described by earlier contributors. My ~/.kde/share/config/weather_panelappletrc had no entry for rport_location so I have added the ICAO code for Manchester Uk to no avail.
I dio hope it can be fixed.
Ken
Comment 4 Martin Koller 2006-12-24 22:05:46 UTC
SVN commit 616273 by mkoller:

BUG: 124754
BUG: 138047
BUG: 136683
BUG: 126296
BUG: 113828
BUG: 122850
BUG: 118458
BUG: 116375
BUG: 103887
BUG: 76300
BUG: 73093

Long standing bug: make selection of a station work



 M  +6 -2      dockwidget.cpp  
 M  +47 -10    kcmweather.cpp  
 M  +1 -2      kcmweather.h  
 M  +4 -0      kcmweatherservice.cpp  
 M  +22 -13    kweather.cpp  
 M  +1 -0      kweather.h  
 M  +20 -6     prefdialogdata.ui  


--- branches/KDE/3.5/kdetoys/kweather/dockwidget.cpp #616272:616273
@@ -47,7 +47,8 @@
 
 void dockwidget::setLocationCode(const QString &locationCode)
 {
-	m_locationCode = locationCode;
+    m_locationCode = locationCode;
+    showWeather();
 }
 
 void dockwidget::setViewMode(int _mode)
@@ -82,7 +83,7 @@
     QString wind     = "?";
     QString pressure = "?";
 
-    if ( m_weatherService->stationNeedsMaintenance( m_locationCode ) )
+    if ( !m_locationCode.isEmpty() && m_weatherService->stationNeedsMaintenance( m_locationCode ) )
     {
         tip = i18n("Station reports that it needs maintenance\n"
                    "Please try again later");
@@ -111,6 +112,9 @@
     // On null or empty location code, or if the station needs maintenance, this will return the dunno icon.
     QPixmap icon = m_weatherService->icon( m_locationCode );
 
+    if ( ! m_locationCode.isEmpty() )
+        tip = m_weatherService->stationName( m_locationCode ) + "\n" + tip;
+
     QToolTip::remove(m_button);
     QToolTip::add(m_button, tip);
 
--- branches/KDE/3.5/kdetoys/kweather/kcmweather.cpp #616272:616273
@@ -83,17 +83,51 @@
 {
   delete mWeatherService;
 }
-void KCMWeather::focusInEvent(QFocusEvent *)
+void KCMWeather::showEvent( QShowEvent * )
 {
   fillStationList();
 }
 
 void KCMWeather::fillStationList()
 {
+  // store current selection
+  QString current = mWidget->m_reportLocation->currentText();
+
+  mWidget->m_reportLocation->clear();
+
   QStringList stationList = mWeatherService->listStations();
   QStringList::Iterator idx = stationList.begin();
+
+  // get station name from station id for sorting afterwards
   for(; idx != stationList.end(); ++idx)
-    mWidget->m_reportLocation->insertItem(mWeatherService->stationName(*idx));
+    *idx = mWeatherService->stationName(*idx);
+
+  stationList.sort();
+
+  idx = stationList.begin();
+  for(; idx != stationList.end(); ++idx)
+    mWidget->m_reportLocation->insertItem(*idx);
+
+  // restore previous selection
+  if ( current.isEmpty() )
+  {
+    // nothing defined yet; show this situation to the user, otherwise
+    // he will see the first available setting which is not what he selected to view
+    mWidget->m_reportLocation->insertItem("");
+    mWidget->m_reportLocation->setCurrentText("");
+  }
+  else
+  {
+    for (int i = 0; i < mWidget->m_reportLocation->count(); i++)
+      if (  mWidget->m_reportLocation->text(i) == current )
+      {
+        mWidget->m_reportLocation->setCurrentItem(i);
+        break;
+      }
+  }
+
+  if ( current != mWidget->m_reportLocation->currentText() )
+    reportLocationChanged();
 }
 
 void KCMWeather::changeViewMode( int mode )
@@ -102,11 +136,6 @@
   emit changed( true );
 }
 
-void KCMWeather::processURL( const QString &url )
-{
-  kapp->invokeBrowser( url );
-}
-
 void KCMWeather::enableLogWidgets( bool value )
 {
   mWidget->m_logFile->setEnabled( value );
@@ -135,7 +164,10 @@
   QString loc =  config.readEntry( "report_location" );
 
   mWidget->m_logFile->setURL( config.readPathEntry( "log_file_name" ) );
-  mWidget->m_reportLocation->setCurrentText( mWeatherService->stationName( loc ) );
+
+  if ( ! loc.isEmpty() )
+    mWidget->m_reportLocation->setCurrentText( mWeatherService->stationName( loc ) );
+
   mWidget->m_viewMode->setButton( config.readNumEntry( "smallview_mode", dockwidget::ShowAll ) );
   changeViewMode( config.readNumEntry( "smallview_mode", dockwidget::ShowAll ) );
   emit changed( false );
@@ -149,8 +181,13 @@
   config.setGroup( "General Options" );
   config.writeEntry( "logging", mWidget->m_enableLog->isChecked() );
   config.writeEntry( "log_file_name", mWidget->m_logFile->url() );
-  // Station idx to local idx
-  config.writeEntry( "report_location", mWeatherService->stationCode( mWidget->m_reportLocation->currentText() ) );
+
+  // Station idx to local idx; if nothing selected yet, keep it empty
+  QString loc;
+  if ( ! mWidget->m_reportLocation->currentText().isEmpty() )
+    loc = mWeatherService->stationCode( mWidget->m_reportLocation->currentText() );
+  config.writeEntry( "report_location", loc);
+
   config.writeEntry( "smallview_mode", mViewMode );
   config.sync();
 
--- branches/KDE/3.5/kdetoys/kweather/kcmweather.h #616272:616273
@@ -41,10 +41,9 @@
 
   protected:
     void fillStationList();
-    void focusInEvent( QFocusEvent * );
+    virtual void showEvent( QShowEvent * );
 
   private slots:
-    void processURL( const QString& );
     void enableLogWidgets( bool value );
     void changeViewMode( int mode );
     void reportLocationChanged();
--- branches/KDE/3.5/kdetoys/kweather/kcmweatherservice.cpp #616272:616273
@@ -43,6 +43,10 @@
 {
   QVBoxLayout *layout = new QVBoxLayout( this );
   mWidget = new ServiceConfigWidget( this );
+
+  // not needed, as a change immediately changes the service
+  //connect(mWidget, SIGNAL(changed(bool)), this, SIGNAL(changed(bool)));
+
   layout->addWidget( mWidget );
   KAboutData *about = new KAboutData( "kcmweatherservice",
                                       I18N_NOOP( "KWeather Configure Dialog" ),
--- branches/KDE/3.5/kdetoys/kweather/kweather.cpp #616272:616273
@@ -52,7 +52,7 @@
         QWidget *parent, const char *name):
         KPanelApplet(configFile, t, actions, parent, name), weatherIface(),
         mFirstRun( false ), mReport( 0 ), mClient( 0 ),
-        mContextMenu( 0 ), mWeatherService( 0 )
+        mContextMenu( 0 ), mWeatherService( 0 ), settingsDialog( 0 )
 {
 	kdDebug(12004) << "Constructor " << endl;
 	setObjId("weatherIface");
@@ -146,32 +146,41 @@
 }
 
 /** prefs */
-void kweather::preferences(){
+void kweather::preferences()
+{
     kdDebug(12004) << "prefs" << endl;
 
     savePrefs();
 
-    static KCMultiDialog *dlg = 0;
+    if ( settingsDialog == 0 )
+    {
+      settingsDialog = new KCMultiDialog( this );
+      connect( settingsDialog, SIGNAL( configCommitted() ), SLOT( slotPrefsAccepted() ) );
 
-    if ( dlg == 0 ) {
-      dlg = new KCMultiDialog( );
-      connect( dlg, SIGNAL( configCommitted(const QCString&) ), SLOT( slotPrefsAccepted() ) );
-
-      dlg->addModule( "kcmweather.desktop" );
-      dlg->addModule( "kcmweatherservice.desktop" );
+      settingsDialog->addModule( "kcmweather.desktop" );
+      settingsDialog->addModule( "kcmweatherservice.desktop" );
     }
 
-    dlg->show();
-    dlg->raise();
+    settingsDialog->show();
+    settingsDialog->raise();
 }
 
 /** The help handler */
-void kweather::help(){
+void kweather::help()
+{
     kapp->invokeHelp(QString::null, QString::fromLatin1("kweather"));
 }
 
 /** Display the current weather report. */
-void kweather::doReport(){
+void kweather::doReport()
+{
+    if ( reportLocation.isEmpty() )
+    {
+        // no station to display defined -> open settings dialog
+        preferences();
+        return;
+    }
+
 	kdDebug(12004) << "Showing out the report" << endl;
 	if ( mReport == 0 )
 	{
--- branches/KDE/3.5/kdetoys/kweather/kweather.h #616272:616273
@@ -77,6 +77,7 @@
 	//DCOPRef *mWeatherService;
 	KPopupMenu *mContextMenu;
 	WeatherService_stub *mWeatherService;
+	KCMultiDialog *settingsDialog;
 };
 
 #endif
--- branches/KDE/3.5/kdetoys/kweather/prefdialogdata.ui #616272:616273
@@ -27,12 +27,6 @@
             <height>0</height>
         </size>
     </property>
-    <property name="maximumSize">
-        <size>
-            <width>640</width>
-            <height>480</height>
-        </size>
-    </property>
     <property name="focusPolicy">
         <enum>TabFocus</enum>
     </property>
@@ -83,6 +77,20 @@
                     <property name="name">
                         <cstring>m_reportLocation</cstring>
                     </property>
+                    <property name="sizePolicy">
+                        <sizepolicy>
+                            <hsizetype>3</hsizetype>
+                            <vsizetype>0</vsizetype>
+                            <horstretch>0</horstretch>
+                            <verstretch>0</verstretch>
+                        </sizepolicy>
+                    </property>
+                    <property name="minimumSize">
+                        <size>
+                            <width>0</width>
+                            <height>0</height>
+                        </size>
+                    </property>
                 </widget>
                 <spacer>
                     <property name="name">
@@ -284,4 +292,10 @@
 </includes>
 <layoutdefaults spacing="3" margin="6"/>
 <layoutfunctions spacing="KDialog::spacingHint" margin="KDialog::marginHint"/>
+<includehints>
+    <includehint>kcombobox.h</includehint>
+    <includehint>kurlrequester.h</includehint>
+    <includehint>klineedit.h</includehint>
+    <includehint>kpushbutton.h</includehint>
+</includehints>
 </UI>