libosmscout  1.1.1
AvailableVoicesModel.h
Go to the documentation of this file.
1 #ifndef OSMSCOUT_CLIENT_QT_VAILABLEVOICESMODEL_H
2 #define OSMSCOUT_CLIENT_QT_VAILABLEVOICESMODEL_H
3 
4 /*
5  OSMScout - a Qt backend for libosmscout and libosmscout-map
6  Copyright (C) 2020 Lukas Karas
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22 
23 #include <osmscout/VoiceProvider.h>
24 #include <osmscout/VoiceManager.h>
25 #include <osmscout/Voice.h>
26 
28 
29 #include <QAbstractListModel>
30 #include <QNetworkDiskCache>
31 #include <QNetworkAccessManager>
32 
33 namespace osmscout {
34 
55 class OSMSCOUT_CLIENT_QT_API AvailableVoicesModel : public QAbstractListModel {
56  Q_OBJECT
57 
58  Q_PROPERTY(bool loading READ isLoading NOTIFY loadingChanged)
59  Q_PROPERTY(QString fetchError READ getFetchError NOTIFY loadingChanged)
60 
61 signals:
62  void loadingChanged();
63 
64 public slots:
65  void listDownloaded(const VoiceProvider &provider, QNetworkReply*);
66  void reload();
67 
68  void onVoiceStateChanged(const AvailableVoice &voice);
69 
70 public:
72 
73  virtual ~AvailableVoicesModel();
74 
75  enum Roles {
76  NameRole = Qt::UserRole,
77  LangRole = Qt::UserRole + 1,
78  GenderRole = Qt::UserRole + 2,
79  LicenseRole = Qt::UserRole + 3,
80  DirectoryRole = Qt::UserRole + 4,
81  AuthorRole = Qt::UserRole + 5,
82  DescriptionRole = Qt::UserRole + 6,
83  StateRole = Qt::UserRole + 7
84  };
85  Q_ENUM(Roles)
86 
87  enum VoiceState {
90  Downloaded
91  };
92  Q_ENUM(VoiceState)
93 
94  Q_INVOKABLE virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
95  Q_INVOKABLE virtual QVariant data(const QModelIndex &index, int role) const;
96  virtual QHash<int, QByteArray> roleNames() const;
97  Q_INVOKABLE virtual Qt::ItemFlags flags(const QModelIndex &index) const;
98 
99  Q_INVOKABLE void download(const QModelIndex &index);
100  Q_INVOKABLE void remove(const QModelIndex &index);
101 
102  Q_INVOKABLE QString stateStr(VoiceState state) const;
103 
104  inline bool isLoading(){
105  return requests>0;
106  }
107 
108  inline QString getFetchError(){
109  return fetchError;
110  }
111 
112 private:
113  int findRow(const QString &lang, const QString &name);
114 
115 private:
116  VoiceManagerRef voiceManager;
117  QNetworkAccessManager webCtrl;
118  QNetworkDiskCache diskCache;
119  QList<VoiceProvider> voiceProviders;
120  size_t requests{0};
121  QList<AvailableVoice*> items;
122  QString fetchError;
123 };
124 
125 }
126 
127 #endif //OSMSCOUT_CLIENT_QT_VAILABLEVOICESMODEL_H
#define OSMSCOUT_CLIENT_QT_API
Definition: ClientQtImportExport.h:45
VoiceState
Definition: AvailableVoicesModel.h:87
std::shared_ptr< VoiceManager > VoiceManagerRef
Definition: VoiceManager.h:125
Definition: Area.h:38
Definition: AvailableVoicesModel.h:55
Definition: Voice.h:30
QString getFetchError()
Definition: AvailableVoicesModel.h:108
Definition: AvailableVoicesModel.h:89
Definition: VoiceProvider.h:38
bool isLoading()
Definition: AvailableVoicesModel.h:104
Roles
Definition: AvailableVoicesModel.h:75
Definition: AvailableVoicesModel.h:88