~osomon/ubuntu-system-settings/autopkgtest

« back to all changes in this revision

Viewing changes to plugins/time-date/timezonelocationmodel.h

  • Committer: CI Train Bot
  • Author(s): Michael Terry
  • Date: 2016-03-16 17:03:24 UTC
  • mfrom: (1595.3.9 geonames)
  • Revision ID: ci-train-bot@canonical.com-20160316170324-yimb401ceza4chb3
Use geonames library instead of timezonemap library to search city names, which gives us slightly better sorting (and future improvements)
Approved by: Jonas G. Drange

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
#include <QtConcurrent>
29
29
 
30
 
class TimeZonePopulateWorker;
 
30
#include <geonames.h>
31
31
 
32
32
class TimeZoneLocationModel : public QAbstractTableModel
33
33
{
44
44
        SimpleRole
45
45
    };
46
46
 
47
 
    struct TzLocation {
48
 
        bool operator<(const TzLocation &other) const
49
 
        {
50
 
            QString pattern("%1, %2");
51
 
 
52
 
            return pattern.arg(city).arg(country) <
53
 
                    pattern.arg(other.city).arg(other.country);
54
 
        }
55
 
 
56
 
        QString city;
57
 
        QString country;
58
 
        QString timezone;
59
 
        QString state;
60
 
        QString full_country;
61
 
    };
62
 
 
63
47
    void filter(const QString& pattern);
64
48
 
65
49
    // implemented virtual methods from QAbstractTableModel
73
57
Q_SIGNALS:
74
58
    void filterBegin();
75
59
    void filterComplete();
76
 
    void modelUpdated();
77
 
 
78
 
public Q_SLOTS:
79
 
    void store(QList<TzLocation> sortedLocations);
80
 
    void filterFinished();
81
 
 
82
 
private:
83
 
    QList<TzLocation> m_locations;
84
 
    QList<TzLocation> m_originalLocations;
85
 
    QString m_pattern;
86
 
 
87
 
    QThread *m_workerThread;
88
 
    TimeZonePopulateWorker *m_populateWorker;
89
 
 
90
 
    bool substringFilter(const QString& input);
91
 
    QFutureWatcher<TzLocation> m_watcher;
92
 
    void setModel(QList<TzLocation> locations);
93
 
};
94
 
 
95
 
Q_DECLARE_METATYPE (TimeZoneLocationModel::TzLocation)
96
 
 
97
 
class TimeZonePopulateWorker : public QObject
98
 
{
99
 
    Q_OBJECT
100
 
 
101
 
public slots:
102
 
    void run();
103
 
 
104
 
Q_SIGNALS:
105
 
    void resultReady(const QList<TimeZoneLocationModel::TzLocation> &sortedList);
106
 
    void finished();
107
 
 
108
 
private:
109
 
    void buildCityMap();
110
 
 
 
60
 
 
61
private:
 
62
    QList<GeonamesCity *> m_locations;
 
63
    GCancellable *m_cancellable;
 
64
 
 
65
    static void filterFinished(GObject      *source_object,
 
66
                               GAsyncResult *res,
 
67
                               gpointer      user_data);
 
68
    void setModel(const QList<GeonamesCity *> &locations);
111
69
};
112
70
 
113
71
#endif // TIMEZONELOCATIONMODEL_H