OSDN Git Service

kdeplasma-addons: use KMessageWidget instead of KMessageBox for the weather configura...
authorIvailo Monev <xakepa10@gmail.com>
Mon, 17 Jul 2023 00:33:04 +0000 (03:33 +0300)
committerIvailo Monev <xakepa10@gmail.com>
Mon, 17 Jul 2023 00:33:04 +0000 (03:33 +0300)
also not emitting the configValueChanged() signal while searching to not
trigger changes on the weather applet side while that is happening (after
search the source will be changed after selecting location item)

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
kdeplasma-addons/libs/plasmaweather/weatherconfig.cpp
kdeplasma-addons/libs/plasmaweather/weatherconfig.ui
kdeplasma-addons/libs/plasmaweather/weatherlocation.cpp
kdeplasma-addons/libs/plasmaweather/weathervalidator.cpp

index fc27faf..ab2d8e8 100644 (file)
@@ -25,7 +25,6 @@
 #include <KPixmapSequence>
 #include <KPixmapSequenceWidget>
 #include <KUnitConversion>
-#include <KMessageBox>
 
 #include "weatherlocation.h"
 #include "weathervalidator.h"
@@ -47,15 +46,26 @@ public:
 
     void setSource(int index)
     {
+        // do not emit the signals when searching, valid source may not even be found
+        if (!searchLocation.isEmpty()) {
+            return;
+        }
+
         QString text = ui.locationCombo->itemData(index).toString();
         if (!text.isEmpty()) {
             source = text;
             emit q->settingsChanged();
+            emit q->configValueChanged();
         }
     }
 
     void changePressed()
     {
+        if (!validator) {
+            kWarning() << "No validator";
+            return;
+        }
+
         QString text = ui.locationCombo->currentText();
 
         if (text.isEmpty()) {
@@ -127,6 +137,9 @@ WeatherConfig::WeatherConfig(QWidget *parent)
         d->ui.visibilityComboBox->addItem(KLength::unitDescription(unit), unit);
     }
 
+    d->ui.locationMessage->hide();
+    d->ui.locationMessage->setMessageType(KMessageWidget::Error);
+
     connect(d->ui.locationCombo, SIGNAL(returnPressed()), this, SLOT(changePressed()));
     connect(d->ui.changeButton, SIGNAL(clicked()), this, SLOT(changePressed()));
 
@@ -145,8 +158,7 @@ WeatherConfig::WeatherConfig(QWidget *parent)
             this, SIGNAL(settingsChanged()));
     connect(d->ui.locationCombo, SIGNAL(currentIndexChanged(int)),
             this, SLOT(setSource(int)));
-    
-    connect(d->ui.locationCombo, SIGNAL(currentIndexChanged(int)) , this , SIGNAL(configValueChanged()));
+
     connect(d->ui.pressureComboBox, SIGNAL(currentIndexChanged(int)) , this , SIGNAL(configValueChanged()));
     connect(d->ui.updateIntervalSpinBox, SIGNAL(valueChanged(int)) , this , SIGNAL(configValueChanged()));
     connect(d->ui.temperatureComboBox, SIGNAL(currentIndexChanged(int)) , this , SIGNAL(configValueChanged()));
@@ -210,15 +222,12 @@ void WeatherConfig::Private::addSources(const QMap<QString, QString> &sources)
     busyWidget = nullptr;
     kDebug() << ui.locationCombo->count();
     if (ui.locationCombo->count() == 0) {
-        KMessageBox::information(
-            q,
-            i18n("No weather stations found for '%1'", searchLocation),
-            i18n("No weather stations found"),
-            QString::fromLatin1("WeatherConfig")
-        );
+        ui.locationMessage->setText(i18n("No weather stations found for '%1'", searchLocation));
+        ui.locationMessage->animatedShow();
     } else {
         ui.locationCombo->showPopup();
     }
+    searchLocation.clear();
 }
 
 void WeatherConfig::setUpdateInterval(int interval)
index fdda367..f6c6162 100644 (file)
    <property name="margin">
     <number>0</number>
    </property>
-   <item row="0" column="0">
+   <item row="0" column="0" colspan="2">
+    <widget class="KMessageWidget" name="locationMessage">
+    </widget>
+   </item>
+   <item row="1" column="0">
     <widget class="QLabel" name="locationLabel">
      <property name="font">
       <font>
@@ -48,7 +52,7 @@
      </property>
     </widget>
    </item>
-   <item row="1" column="0">
+   <item row="2" column="0">
     <widget class="QLabel" name="cityLabel">
      <property name="minimumSize">
       <size>
@@ -67,7 +71,7 @@
      </property>
     </widget>
    </item>
-   <item row="1" column="1">
+   <item row="2" column="1">
     <layout class="QHBoxLayout" name="locationlayout">
      <property name="spacing">
       <number>0</number>
@@ -90,7 +94,7 @@
      </item>
     </layout>
    </item>
-   <item row="2" column="1">
+   <item row="3" column="1">
     <layout class="QHBoxLayout" name="locationSearchLayout">
      <property name="spacing">
       <number>0</number>
      </item>
     </layout>
    </item>
-   <item row="3" column="0">
+   <item row="4" column="0">
     <widget class="QLabel" name="intervalLabel">
      <property name="minimumSize">
       <size>
      </property>
     </widget>
    </item>
-   <item row="3" column="1">
+   <item row="4" column="1">
     <layout class="QHBoxLayout" name="horizontalLayout_4">
      <property name="spacing">
       <number>0</number>
      </item>
     </layout>
    </item>
-   <item row="4" column="0">
+   <item row="5" column="0">
     <widget class="QLabel" name="unitsLabel">
      <property name="font">
       <font>
      </property>
     </widget>
    </item>
-   <item row="5" column="1">
+   <item row="6" column="1">
     <layout class="QHBoxLayout" name="horizontalLayout_5">
      <property name="spacing">
       <number>0</number>
      </item>
     </layout>
    </item>
-   <item row="5" column="0">
+   <item row="6" column="0">
     <widget class="QLabel" name="temperatureLabel">
      <property name="minimumSize">
       <size>
      </property>
     </widget>
    </item>
-   <item row="6" column="0">
+   <item row="7" column="0">
     <widget class="QLabel" name="pressureLabel">
      <property name="minimumSize">
       <size>
      </property>
     </widget>
    </item>
-   <item row="6" column="1">
+   <item row="7" column="1">
     <layout class="QHBoxLayout" name="horizontalLayout_6">
      <property name="spacing">
       <number>0</number>
      </item>
     </layout>
    </item>
-   <item row="7" column="0">
+   <item row="8" column="0">
     <widget class="QLabel" name="speedLabel">
      <property name="minimumSize">
       <size>
      </property>
     </widget>
    </item>
-   <item row="7" column="1">
+   <item row="8" column="1">
     <layout class="QHBoxLayout" name="horizontalLayout_7">
      <property name="spacing">
       <number>0</number>
      </item>
     </layout>
    </item>
-   <item row="8" column="0">
+   <item row="9" column="0">
     <widget class="QLabel" name="visibilityLabel">
      <property name="minimumSize">
       <size>
      </property>
     </widget>
    </item>
-   <item row="8" column="1">
+   <item row="9" column="1">
     <layout class="QHBoxLayout" name="horizontalLayout_8">
      <property name="spacing">
       <number>0</number>
      </item>
     </layout>
    </item>
-   <item row="9" column="0">
+   <item row="10" column="0">
     <spacer name="verticalSpacer">
      <property name="orientation">
       <enum>Qt::Vertical</enum>
  </widget>
  <customwidgets>
   <customwidget>
+   <class>KMessageWidget</class>
+   <extends>QFrame</extends>
+   <header>kmessagewidget.h</header>
+   <container>1</container>
+  </customwidget>
+  <customwidget>
    <class>KIntSpinBox</class>
    <extends>QSpinBox</extends>
    <header>knuminput.h</header>
index 98d77a0..48b3170 100644 (file)
@@ -28,9 +28,9 @@ class WeatherLocation::Private
 public:
     Private(WeatherLocation *location)
         : q(location),
-          locationEngine(nullptr),
-          weatherEngine(nullptr),
-          ion("wettercom")
+        locationEngine(nullptr),
+        weatherEngine(nullptr),
+        ion("wettercom")
     {
     }
 
index bdb2ead..ca03085 100644 (file)
@@ -39,8 +39,8 @@ public:
 };
 
 WeatherValidator::WeatherValidator(QObject *parent)
-    : QObject(parent)
-    d(new Private())
+    : QObject(parent),
+    d(new Private())
 {
     Weatheri18nCatalog::loadCatalog();
 }