mirror of
https://bitbucket.org/smil3y/kde-extraapps.git
synced 2025-02-23 18:32:53 +00:00
kdeplasma-addons: fill the weather configuration locations widgets with default (valid) locations
for reference: https://github.com/fluxer/katana/issues/26 Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
c52c3b15a8
commit
173699edc7
3 changed files with 71 additions and 24 deletions
|
@ -26,9 +26,8 @@
|
|||
#include <KInputDialog>
|
||||
#include <KPixmapSequence>
|
||||
#include <kpixmapsequencewidget.h>
|
||||
//#include <KPixmapSequenceWidget>
|
||||
|
||||
#include <kunitconversion.h>
|
||||
#include <Plasma/DataEngineManager>
|
||||
|
||||
#include "weathervalidator.h"
|
||||
#include "weatheri18ncatalog.h"
|
||||
|
@ -39,10 +38,11 @@ class WeatherConfig::Private
|
|||
public:
|
||||
Private(WeatherConfig *weatherconfig)
|
||||
: q(weatherconfig),
|
||||
dataengine(0),
|
||||
dlg(0),
|
||||
busyWidget(0),
|
||||
checkedInCount(0)
|
||||
dataengine(nullptr),
|
||||
dlg(nullptr),
|
||||
busyWidget(nullptr),
|
||||
checkedInCount(0),
|
||||
searching(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -57,6 +57,48 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void getDefault()
|
||||
{
|
||||
Plasma::DataEngine* locationEngine = Plasma::DataEngineManager::self()->loadEngine("geolocation");
|
||||
if (!locationEngine || !locationEngine->isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME: this will not validate until the location data is available (which will not
|
||||
// happen until after the first query)
|
||||
searching = false;
|
||||
const Plasma::DataEngine::Data locationData = locationEngine->query(QLatin1String("location"));
|
||||
// qDebug() << Q_FUNC_INFO << locationData;
|
||||
|
||||
QStringList citiesToValidate;
|
||||
foreach (const QString &datakey, locationData.keys()) {
|
||||
const QVariantHash datahash = locationData.value(datakey).toHash();
|
||||
QString city = datahash[QLatin1String("city")].toString();
|
||||
if (city.contains(QLatin1Char(','))) {
|
||||
city.truncate(city.indexOf(QLatin1Char(',')) - 1);
|
||||
}
|
||||
if (!city.isEmpty()) {
|
||||
citiesToValidate.append(city);
|
||||
}
|
||||
}
|
||||
if (citiesToValidate.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!busyWidget) {
|
||||
busyWidget = new KPixmapSequenceWidget(q);
|
||||
KPixmapSequence seq(QLatin1String("process-working"), 22);
|
||||
busyWidget->setSequence(seq);
|
||||
ui.locationSearchLayout->insertWidget(1, busyWidget);
|
||||
}
|
||||
|
||||
foreach (const QString &city, citiesToValidate) {
|
||||
foreach (WeatherValidator *validator, validators) {
|
||||
validator->validate(city, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void changePressed()
|
||||
{
|
||||
checkedInCount = 0;
|
||||
|
@ -66,6 +108,7 @@ public:
|
|||
return;
|
||||
}
|
||||
|
||||
searching = true;
|
||||
ui.locationCombo->clear();
|
||||
ui.locationCombo->lineEdit()->setText(text);
|
||||
|
||||
|
@ -92,7 +135,6 @@ public:
|
|||
void validatorError(const QString &error);
|
||||
|
||||
WeatherConfig *q;
|
||||
//QHash<QString, QString> ions;
|
||||
QList<WeatherValidator *> validators;
|
||||
Plasma::DataEngine *dataengine;
|
||||
QString source;
|
||||
|
@ -100,6 +142,7 @@ public:
|
|||
KDialog *dlg;
|
||||
KPixmapSequenceWidget *busyWidget;
|
||||
int checkedInCount;
|
||||
bool searching;
|
||||
};
|
||||
|
||||
WeatherConfig::WeatherConfig(QWidget *parent)
|
||||
|
@ -162,7 +205,6 @@ WeatherConfig::~WeatherConfig()
|
|||
void WeatherConfig::setDataEngine(Plasma::DataEngine* dataengine)
|
||||
{
|
||||
d->dataengine = dataengine;
|
||||
//d->ions.clear();
|
||||
qDeleteAll(d->validators);
|
||||
d->validators.clear();
|
||||
if (d->dataengine) {
|
||||
|
@ -171,7 +213,6 @@ void WeatherConfig::setDataEngine(Plasma::DataEngine* dataengine)
|
|||
const QStringList pluginInfo = plugin.toString().split(QLatin1Char('|'));
|
||||
if (pluginInfo.count() > 1) {
|
||||
// kDebug() << "ion: " << pluginInfo[0] << pluginInfo[1];
|
||||
//d->ions.insert(pluginInfo[1], pluginInfo[0]);
|
||||
WeatherValidator *validator = new WeatherValidator(this);
|
||||
connect(validator, SIGNAL(error(QString)), this, SLOT(validatorError(QString)));
|
||||
connect(validator, SIGNAL(finished(QMap<QString,QString>)), this, SLOT(addSources(QMap<QString,QString>)));
|
||||
|
@ -213,9 +254,11 @@ void WeatherConfig::Private::addSources(const QMap<QString, QString> &sources)
|
|||
ui.locationCombo->addItem(i18n("No weather stations found for '%1'", current));
|
||||
ui.locationCombo->lineEdit()->setText(current);
|
||||
}
|
||||
if (searching) {
|
||||
ui.locationCombo->showPopup();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WeatherConfig::setUpdateInterval(int interval)
|
||||
{
|
||||
|
@ -265,6 +308,8 @@ void WeatherConfig::setSource(const QString &source)
|
|||
d->ui.locationCombo->lineEdit()->setText(result);
|
||||
}
|
||||
d->source = source;
|
||||
|
||||
d->getDefault();
|
||||
}
|
||||
|
||||
QString WeatherConfig::source() const
|
||||
|
|
|
@ -30,7 +30,7 @@ public:
|
|||
: q(location),
|
||||
locationEngine(nullptr),
|
||||
weatherEngine(nullptr),
|
||||
foundsource(false)
|
||||
foundSource(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -43,11 +43,11 @@ public:
|
|||
}
|
||||
|
||||
validators.remove(validator);
|
||||
if (!source.isEmpty() && !foundsource) {
|
||||
foundsource = true;
|
||||
if (!source.isEmpty() && !foundSource) {
|
||||
foundSource = true;
|
||||
emit q->finished(source);
|
||||
}
|
||||
if (!foundsource && validators.isEmpty()) {
|
||||
if (!foundSource && validators.isEmpty()) {
|
||||
emit q->finished(QString());
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ public:
|
|||
WeatherLocation *q;
|
||||
Plasma::DataEngine *locationEngine;
|
||||
Plasma::DataEngine *weatherEngine;
|
||||
bool foundsource;
|
||||
bool foundSource;
|
||||
QMap<WeatherValidator*,QString> validators;
|
||||
};
|
||||
|
||||
|
@ -93,6 +93,8 @@ void WeatherLocation::dataUpdated(const QString &source, const Plasma::DataEngin
|
|||
return;
|
||||
}
|
||||
|
||||
Q_ASSERT(d->validators.size() == 0);
|
||||
d->foundSource = false;
|
||||
d->locationEngine->disconnectSource(source, this);
|
||||
// sort the data by accuracy, the lower the accuracy number the higher the accuracy is
|
||||
QMap<int, QVariant> accuratedata;
|
||||
|
|
Loading…
Add table
Reference in a new issue