From 6a60591ff2cf015ffdaebb73f28d4aa30440e654 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Mon, 17 Jul 2023 03:33:04 +0300 Subject: [PATCH] kdeplasma-addons: use KMessageWidget instead of KMessageBox for the weather configuration error 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 --- .../libs/plasmaweather/weatherconfig.cpp | 27 +++++++++----- .../libs/plasmaweather/weatherconfig.ui | 42 +++++++++++++--------- .../libs/plasmaweather/weatherlocation.cpp | 6 ++-- .../libs/plasmaweather/weathervalidator.cpp | 4 +-- 4 files changed, 49 insertions(+), 30 deletions(-) diff --git a/kdeplasma-addons/libs/plasmaweather/weatherconfig.cpp b/kdeplasma-addons/libs/plasmaweather/weatherconfig.cpp index fc27faf0..ab2d8e80 100644 --- a/kdeplasma-addons/libs/plasmaweather/weatherconfig.cpp +++ b/kdeplasma-addons/libs/plasmaweather/weatherconfig.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #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 &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) diff --git a/kdeplasma-addons/libs/plasmaweather/weatherconfig.ui b/kdeplasma-addons/libs/plasmaweather/weatherconfig.ui index fdda3677..f6c61622 100644 --- a/kdeplasma-addons/libs/plasmaweather/weatherconfig.ui +++ b/kdeplasma-addons/libs/plasmaweather/weatherconfig.ui @@ -35,7 +35,11 @@ 0 - + + + + + @@ -48,7 +52,7 @@ - + @@ -67,7 +71,7 @@ - + 0 @@ -90,7 +94,7 @@ - + 0 @@ -123,7 +127,7 @@ - + @@ -142,7 +146,7 @@ - + 0 @@ -184,7 +188,7 @@ - + @@ -197,7 +201,7 @@ - + 0 @@ -227,7 +231,7 @@ - + @@ -246,7 +250,7 @@ - + @@ -265,7 +269,7 @@ - + 0 @@ -295,7 +299,7 @@ - + @@ -314,7 +318,7 @@ - + 0 @@ -344,7 +348,7 @@ - + @@ -363,7 +367,7 @@ - + 0 @@ -393,7 +397,7 @@ - + Qt::Vertical @@ -410,6 +414,12 @@ + KMessageWidget + QFrame +
kmessagewidget.h
+ 1 +
+ KIntSpinBox QSpinBox
knuminput.h
diff --git a/kdeplasma-addons/libs/plasmaweather/weatherlocation.cpp b/kdeplasma-addons/libs/plasmaweather/weatherlocation.cpp index 98d77a0c..48b3170a 100644 --- a/kdeplasma-addons/libs/plasmaweather/weatherlocation.cpp +++ b/kdeplasma-addons/libs/plasmaweather/weatherlocation.cpp @@ -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") { } diff --git a/kdeplasma-addons/libs/plasmaweather/weathervalidator.cpp b/kdeplasma-addons/libs/plasmaweather/weathervalidator.cpp index bdb2ead0..ca030852 100644 --- a/kdeplasma-addons/libs/plasmaweather/weathervalidator.cpp +++ b/kdeplasma-addons/libs/plasmaweather/weathervalidator.cpp @@ -39,8 +39,8 @@ public: }; WeatherValidator::WeatherValidator(QObject *parent) - : QObject(parent) - , d(new Private()) + : QObject(parent), + d(new Private()) { Weatheri18nCatalog::loadCatalog(); } -- 2.11.0