libosmscout  1.1.1
VoiceManager.h
Go to the documentation of this file.
1 #ifndef OSMSCOUT_CLIENT_QT_VOICEMANAGER_H
2 #define OSMSCOUT_CLIENT_QT_VOICEMANAGER_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 <QObject>
24 
27 #include <osmscout/Voice.h>
28 
29 #include <memory>
30 
31 namespace osmscout {
32 
39 {
40  Q_OBJECT
41 
42 public:
43  VoiceDownloadJob(QNetworkAccessManager *webCtrl,
44  const AvailableVoice &voice,
45  const QDir &target,
46  bool replaceExisting);
47 
48  virtual ~VoiceDownloadJob();
49 
50  void start();
51 
52  inline uint64_t expectedSize() const override
53  {
54  return 0;
55  }
56 
58  {
59  return voice;
60  }
61 
62 private:
63  AvailableVoice voice;
64 };
65 
66 
72 class OSMSCOUT_CLIENT_QT_API VoiceManager: public QObject {
73  Q_OBJECT
74 
75 signals:
76  void reloaded();
77 
78  void startDownloading(const AvailableVoice &item);
79  void downloaded(const AvailableVoice &item);
80  void removed(const AvailableVoice &item);
81 
82  void voiceDownloadFails(const QString &errorMessage);
83 
84 public slots:
85  void reload();
86 
87  void download(const AvailableVoice &item);
88  void remove(const AvailableVoice &item);
89  void cancelDownload(const AvailableVoice &item);
90 
91  void onJobFinished();
92  void onJobFailed(QString errorMessage);
93 
94 public:
95  VoiceManager();
96 
97  VoiceManager(const VoiceManager&) = delete;
98  VoiceManager(VoiceManager&&) = delete;
99 
100  VoiceManager& operator=(const VoiceManager&) = delete;
101  VoiceManager& operator=(VoiceManager&&) = delete;
102 
103  ~VoiceManager() override;
104 
105  QList<Voice> getInstalledVoices() const
106  {
107  return installedVoices;
108  }
109 
110  bool isDownloaded(const AvailableVoice &voice) const;
111  bool isDownloading(const AvailableVoice &voice) const;
112 
113  void downloadNext();
114 
115 private:
116  QList<Voice> installedVoices;
117  QList<VoiceDownloadJob*> downloadJobs;
118  QNetworkAccessManager webCtrl;
119  QString lookupDir;
120 };
121 
125 using VoiceManagerRef = std::shared_ptr<VoiceManager>;
126 
127 }
128 #endif //OSMSCOUT_CLIENT_QT_VOICEMANAGER_H
#define OSMSCOUT_CLIENT_QT_API
Definition: ClientQtImportExport.h:45
Definition: FileDownloader.h:131
uint64_t expectedSize() const override
Definition: VoiceManager.h:52
QList< Voice > getInstalledVoices() const
Definition: VoiceManager.h:105
std::shared_ptr< VoiceManager > VoiceManagerRef
Definition: VoiceManager.h:125
Definition: Area.h:38
AvailableVoice getVoice() const
Definition: VoiceManager.h:57
Definition: Voice.h:30
Definition: VoiceManager.h:38
Definition: VoiceManager.h:72