~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to plasma/generic/dataengines/weather/ions/debianweather/iondebianweather.h

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (c) 2011 Sune Vuorela <sune@vuorela.dk>
 
3
 
 
4
    Permission is hereby granted, free of charge, to any person
 
5
    obtaining a copy of this software and associated documentation
 
6
    files (the "Software"), to deal in the Software without
 
7
    restriction, including without limitation the rights to use,
 
8
    copy, modify, merge, publish, distribute, sublicense, and/or sell
 
9
    copies of the Software, and to permit persons to whom the
 
10
    Software is furnished to do so, subject to the following
 
11
    conditions:
 
12
 
 
13
    The above copyright notice and this permission notice shall be
 
14
    included in all copies or substantial portions of the Software.
 
15
 
 
16
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
17
    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 
18
    OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
19
    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 
20
    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 
21
    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
22
    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 
23
    OTHER DEALINGS IN THE SOFTWARE.
 
24
 
 
25
*/
 
26
 
 
27
#ifndef IONDEBIANWEATHER_H
 
28
#define IONDEBIANWEATHER_H
 
29
 
 
30
#include "../ion.h"
 
31
#include <Plasma/DataEngine>
 
32
 
 
33
class KJob;
 
34
namespace KIO {
 
35
  class Job;
 
36
}
 
37
class IonDebianWeather : public IonInterface {
 
38
  Q_OBJECT
 
39
  public:
 
40
    IonDebianWeather(QObject*, const QVariantList&);
 
41
    virtual ~IonDebianWeather();
 
42
    virtual bool updateIonSource(const QString& source);
 
43
    virtual void init();
 
44
  public Q_SLOTS:
 
45
    virtual void reset();
 
46
  private:
 
47
    enum jobtype {
 
48
      validate,
 
49
      weather,
 
50
      unknown
 
51
    };
 
52
    struct xmlresult {
 
53
      int total;
 
54
      int broken;
 
55
        QString nicename;
 
56
        QString architecture;
 
57
      xmlresult() : total(0), broken(0) {}
 
58
    };
 
59
    struct locationdata {
 
60
      QString suite;
 
61
      QString arch;
 
62
      bool valid;
 
63
      QString source;
 
64
      QByteArray data;
 
65
      jobtype type;
 
66
        QString searchstring;
 
67
      locationdata() : valid(false),type(unknown) {}
 
68
    };
 
69
    void tryFindPlace(QSharedPointer<locationdata> data);
 
70
    void startFetchData(QSharedPointer<locationdata> data);
 
71
    void findAllPlaces(QSharedPointer< IonDebianWeather::locationdata > data);
 
72
    void parseLocation(QString sourcedata, QSharedPointer<locationdata> location);
 
73
    QString m_ionname;
 
74
    QHash<KJob*,QSharedPointer<locationdata> > m_jobs;
 
75
    xmlresult parseWeatherXml(QSharedPointer<locationdata> locdata);
 
76
    QStringList parseLocationXml(QSharedPointer< IonDebianWeather::locationdata > locdata);
 
77
 
 
78
    jobtype toJobType(const QString& data);
 
79
    QString toString(jobtype type);
 
80
    ConditionIcons toCondition(xmlresult);
 
81
    void cleanup();
 
82
  private Q_SLOTS:
 
83
    void jobDone(KJob*);
 
84
    void dataReceived(KIO::Job* job,QByteArray data);
 
85
};
 
86
 
 
87
K_EXPORT_PLASMA_DATAENGINE(debianweather, IonDebianWeather)
 
88
 
 
89
#endif // IONDEBIANWEATHER_H