mirror of
https://bitbucket.org/smil3y/kde-extraapps.git
synced 2025-02-23 18:32:53 +00:00
kdeplasma-addons: attempt to validate all locations
out of 4 geolocation data engine providers 3 provide data for the city, requires the following commit from kde-workspace: d28608da5bb8b874cad1c6a9b50a5b9bfb358317 for reference: https://github.com/fluxer/katana/issues/26 Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
80fa18c5e3
commit
7f129d6c3e
3 changed files with 45 additions and 22 deletions
|
@ -21,27 +21,38 @@
|
||||||
#include "weathervalidator.h"
|
#include "weathervalidator.h"
|
||||||
#include "weatheri18ncatalog.h"
|
#include "weatheri18ncatalog.h"
|
||||||
|
|
||||||
|
#include <kdebug.h>
|
||||||
|
|
||||||
class WeatherLocation::Private
|
class WeatherLocation::Private
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Private(WeatherLocation *location)
|
Private(WeatherLocation *location)
|
||||||
: q(location),
|
: q(location),
|
||||||
locationEngine(0)
|
locationEngine(nullptr)
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void validatorFinished(const QMap<QString, QString> &results)
|
void validatorFinished(const QMap<QString, QString> &results)
|
||||||
{
|
{
|
||||||
|
WeatherValidator* validator = qobject_cast<WeatherValidator*>(q->sender());
|
||||||
QString source;
|
QString source;
|
||||||
if (!results.isEmpty()) {
|
if (!results.isEmpty()) {
|
||||||
source = results.begin().value();
|
source = results.begin().value();
|
||||||
}
|
}
|
||||||
|
|
||||||
emit q->finished(source);
|
validators.remove(validator);
|
||||||
|
if (!source.isEmpty()) {
|
||||||
|
emit q->finished(source);
|
||||||
|
}
|
||||||
|
if (validators.isEmpty()) {
|
||||||
|
emit q->finished(QString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WeatherLocation *q;
|
WeatherLocation *q;
|
||||||
Plasma::DataEngine *locationEngine;
|
Plasma::DataEngine *locationEngine;
|
||||||
WeatherValidator validator;
|
Plasma::DataEngine *weatherEngine;
|
||||||
|
QMap<WeatherValidator*,QString> validators;
|
||||||
};
|
};
|
||||||
|
|
||||||
WeatherLocation::WeatherLocation(QObject *parent)
|
WeatherLocation::WeatherLocation(QObject *parent)
|
||||||
|
@ -49,25 +60,25 @@ WeatherLocation::WeatherLocation(QObject *parent)
|
||||||
, d(new Private(this))
|
, d(new Private(this))
|
||||||
{
|
{
|
||||||
Weatheri18nCatalog::loadCatalog();
|
Weatheri18nCatalog::loadCatalog();
|
||||||
QObject::connect(&d->validator, SIGNAL(finished(QMap<QString,QString>)),
|
|
||||||
this, SLOT(validatorFinished(QMap<QString,QString>)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WeatherLocation::~WeatherLocation()
|
WeatherLocation::~WeatherLocation()
|
||||||
{
|
{
|
||||||
|
qDeleteAll(d->validators.keys());
|
||||||
|
d->validators.clear();
|
||||||
delete d;
|
delete d;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WeatherLocation::setDataEngines(Plasma::DataEngine* location, Plasma::DataEngine* weather)
|
void WeatherLocation::setDataEngines(Plasma::DataEngine* location, Plasma::DataEngine* weather)
|
||||||
{
|
{
|
||||||
d->locationEngine = location;
|
d->locationEngine = location;
|
||||||
d->validator.setDataEngine(weather);
|
d->weatherEngine = weather;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WeatherLocation::getDefault()
|
void WeatherLocation::getDefault()
|
||||||
{
|
{
|
||||||
if (d->locationEngine && d->locationEngine->isValid()) {
|
if (d->locationEngine && d->locationEngine->isValid()) {
|
||||||
d->locationEngine->connectSource(QLatin1String( "location" ), this);
|
d->locationEngine->connectSource(QLatin1String("location"), this);
|
||||||
} else {
|
} else {
|
||||||
emit finished(QString());
|
emit finished(QString());
|
||||||
}
|
}
|
||||||
|
@ -80,18 +91,31 @@ void WeatherLocation::dataUpdated(const QString &source, const Plasma::DataEngin
|
||||||
}
|
}
|
||||||
|
|
||||||
d->locationEngine->disconnectSource(source, this);
|
d->locationEngine->disconnectSource(source, this);
|
||||||
|
foreach (const QString &datakey, data.keys()) {
|
||||||
QString city = data[QLatin1String( "city" )].toString();
|
const QVariantHash datahash = data[datakey].toHash();
|
||||||
|
QString city = datahash[QLatin1String("city")].toString();
|
||||||
if (city.contains(QLatin1Char( ',' )))
|
if (city.contains(QLatin1Char(','))) {
|
||||||
city.truncate(city.indexOf(QLatin1Char( ',' )) - 1);
|
city.truncate(city.indexOf(QLatin1Char(',')) - 1);
|
||||||
|
}
|
||||||
if (!city.isEmpty()) {
|
if (!city.isEmpty()) {
|
||||||
d->validator.validate(QLatin1String( "wettercom" ), city, true);
|
WeatherValidator* validator = new WeatherValidator();
|
||||||
return;
|
validator->setDataEngine(d->weatherEngine);
|
||||||
|
connect(
|
||||||
|
validator, SIGNAL(finished(QMap<QString,QString>)),
|
||||||
|
this, SLOT(validatorFinished(QMap<QString,QString>))
|
||||||
|
);
|
||||||
|
d->validators.insert(validator, city);
|
||||||
|
kDebug() << "validating" << city;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emit finished(QString());
|
if (d->validators.isEmpty()) {
|
||||||
|
emit finished(QString());
|
||||||
|
} else {
|
||||||
|
foreach (WeatherValidator* validator, d->validators.keys()) {
|
||||||
|
validator->validate(QLatin1String("wettercom"), d->validators.value(validator), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "moc_weatherlocation.cpp"
|
#include "moc_weatherlocation.cpp"
|
||||||
|
|
|
@ -55,7 +55,7 @@ Q_SIGNALS:
|
||||||
**/
|
**/
|
||||||
void finished(const QString& source);
|
void finished(const QString& source);
|
||||||
|
|
||||||
public Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void dataUpdated(const QString &source, const Plasma::DataEngine::Data &data);
|
void dataUpdated(const QString &source, const Plasma::DataEngine::Data &data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -81,10 +81,9 @@ public:
|
||||||
q->setBusy(false);
|
q->setBusy(false);
|
||||||
q->showMessage(QIcon(), QString(), Plasma::ButtonNone);
|
q->showMessage(QIcon(), QString(), Plasma::ButtonNone);
|
||||||
q->setConfigurationRequired(true);
|
q->setConfigurationRequired(true);
|
||||||
|
location->deleteLater();
|
||||||
|
location = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
location->deleteLater();
|
|
||||||
location = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void giveUpBeingBusy()
|
void giveUpBeingBusy()
|
||||||
|
|
Loading…
Add table
Reference in a new issue