/
translationinterface.h
175 lines (148 loc) · 5.57 KB
/
translationinterface.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
* TAO Translator
* Copyright (C) 2013-2014 Oleksii Serdiuk <contacts[at]oleksii[dot]name>
*
* $Id: $Format:%h %ai %an$ $
*
* This file is part of TAO Translator.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TRANSLATIONINTERFACE_H
#define TRANSLATIONINTERFACE_H
#include "translationservice.h"
#ifdef Q_OS_SYMBIAN
# include "symbian/symbianapplication.h"
#endif
#include <QObject>
#include <QStringList>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QSettings>
#ifdef Q_OS_BLACKBERRY
# include <bb/system/InvokeRequest>
#endif
class TranslationServicesModel;
class TranslationServiceItem;
class LanguageListModel;
class LanguageItem;
class DictionaryModel;
class TranslationInterface: public QObject
{
Q_OBJECT
Q_PROPERTY(QString version READ version CONSTANT)
Q_PROPERTY(TranslationServicesModel *services READ supportedServices CONSTANT)
Q_PROPERTY(TranslationServiceItem *selectedService READ selectedService NOTIFY selectedServiceChanged)
Q_PROPERTY(bool supportsTranslation READ supportsTranslation NOTIFY selectedServiceChanged)
// Translation related properties
Q_PROPERTY(bool busy READ busy NOTIFY busyChanged)
Q_PROPERTY(LanguageListModel *sourceLanguages READ sourceLanguages CONSTANT)
Q_PROPERTY(LanguageListModel *targetLanguages READ targetLanguages CONSTANT)
Q_PROPERTY(LanguageItem *sourceLanguage READ sourceLanguage NOTIFY sourceLanguageChanged)
Q_PROPERTY(LanguageItem *targetLanguage READ targetLanguage NOTIFY targetLanguageChanged)
Q_PROPERTY(bool canSwapLanguages READ canSwapLanguages NOTIFY canSwapLanguagesChanged)
Q_PROPERTY(QString sourceText READ sourceText WRITE setSourceText NOTIFY sourceTextChanged)
Q_PROPERTY(QString detectedLanguageName READ detectedLanguageName NOTIFY detectedLanguageChanged)
Q_PROPERTY(QString translatedText READ translatedText NOTIFY translatedTextChanged)
Q_PROPERTY(DictionaryModel *dictionary READ dictionary CONSTANT)
#ifdef Q_OS_SYMBIAN
Q_PROPERTY(TranslationInterface::AppVisibility appVisibility READ appVisibility
NOTIFY appVisibilityChanged)
Q_ENUMS(AppVisibility)
#endif
public:
enum SupportedServices {
GoogleTranslateService,
MicrosoftTranslatorService,
YandexTranslateService,
YandexDictionariesService
};
#ifdef Q_OS_SYMBIAN
enum AppVisibility {
AppNotVisible = SymbianApplication::NotVisible,
AppPartiallyVisible = SymbianApplication::PartiallyVisible,
AppFullyVisible = SymbianApplication::FullyVisible
};
#endif
explicit TranslationInterface(QObject *parent = 0);
static QString version();
TranslationServicesModel *supportedServices() const;
TranslationServiceItem *selectedService() const;
bool supportsTranslation() const;
bool busy() const;
LanguageListModel *sourceLanguages() const;
LanguageListModel *targetLanguages() const;
LanguageItem *sourceLanguage() const;
LanguageItem *targetLanguage() const;
bool canSwapLanguages() const;
QString sourceText() const;
QString detectedLanguageName() const;
QString translatedText() const;
DictionaryModel *dictionary() const;
#ifdef Q_OS_SYMBIAN
TranslationInterface::AppVisibility appVisibility() const;
#endif
~TranslationInterface();
signals:
void error(const QString &errorString) const;
void selectedServiceChanged();
void busyChanged();
void sourceLanguageChanged();
void targetLanguageChanged();
void canSwapLanguagesChanged();
void sourceTextChanged();
void detectedLanguageChanged();
void translatedTextChanged();
#ifdef Q_OS_SYMBIAN
void appVisibilityChanged();
#endif
public slots:
QString getSettingsValue(const QString &key) const;
void setSettingsValue(const QString &key, const QVariant &value);
void selectService(int index);
void selectSourceLanguage(int index);
void selectTargetLanguage(int index);
void swapLanguages();
void setSourceText(const QString &sourceText);
void translate();
#ifdef Q_OS_SAILFISH
QString urlDecode(const QString &url) const;
#endif
private:
TranslationService *m_service;
TranslationServicesModel *m_services;
TranslationServiceItem *m_serviceItem;
bool m_busy;
LanguageListModel *m_sourceLanguages;
LanguageListModel *m_targetLanguages;
LanguageItem *m_sourceLanguage;
LanguageItem *m_targetLanguage;
Language m_detectedLanguage;
QString m_srcText;
QString m_translation;
DictionaryModel *m_dict;
QSettings *m_settings;
void createService(uint id);
void resetTranslation();
void setBusy(bool busy);
void setDetectedLanguage(const Language &detectedLanguageName);
void setTranslatedText(const QString &translatedText);
private slots:
void onTranslationFinished();
void retranslate();
#ifdef Q_OS_BLACKBERRY
void onInvoked(const bb::system::InvokeRequest &request);
#endif
};
#endif // TRANSLATIONINTERFACE_H