-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.cpp
206 lines (170 loc) · 6.6 KB
/
settings.cpp
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/***************************************************************************
* Copyright (с) 2009 by Andrey Cherepanov <[email protected]> *
* *
* 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 3 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <settings.h>
Settings::Settings( QWidget *parent )
: QDialog( parent )
{
// Set dialog content
form = new Ui_SettingsDialog();
form->setupUi( this );
// Set default values
QString locale = QLocale::system().name().left( 2 );
QHash<QString, QString> supportedLanguage;
supportedLanguage[ "en" ] = QString( "eng" );
supportedLanguage[ "de" ] = QString( "ger" );
supportedLanguage[ "fr" ] = QString( "fra" );
supportedLanguage[ "ru" ] = QString( "ruseng" );
supportedLanguage[ "sv" ] = QString( "swe" );
supportedLanguage[ "es" ] = QString( "spa" );
supportedLanguage[ "it" ] = QString( "ita" );
supportedLanguage[ "uk" ] = QString( "ukr" );
supportedLanguage[ "sr" ] = QString( "srp" );
supportedLanguage[ "hr" ] = QString( "hrv" );
supportedLanguage[ "pl" ] = QString( "pol" );
supportedLanguage[ "da" ] = QString( "dan" );
supportedLanguage[ "pt" ] = QString( "por" );
supportedLanguage[ "nl" ] = QString( "dut" );
supportedLanguage[ "cs" ] = QString( "cze" );
supportedLanguage[ "ro" ] = QString( "rum" );
supportedLanguage[ "hu" ] = QString( "hun" );
supportedLanguage[ "bg" ] = QString( "bul" );
supportedLanguage[ "sl" ] = QString( "slo" );
supportedLanguage[ "lv" ] = QString( "lav" );
supportedLanguage[ "lt" ] = QString( "lit" );
supportedLanguage[ "et" ] = QString( "est" );
supportedLanguage[ "tr" ] = QString( "tur" );
// Try to guess language from locale
// qDebug() << "Language:" << qPrintable(locale) << supportedLanguage.contains( locale );
if( supportedLanguage.contains( locale )) {
pLanguage = supportedLanguage.value( locale );
} else {
pLanguage = QString( "eng" );
}
pFormat = QString( "html" );
pCommand = QString( "cuneiform" );
// Fill combo boxes
QComboBox *lang = form->language;
// Supported languages: eng ger fra rus swe spa ita ruseng ukr srp hrv pol dan por dut cze rum hun bul slo lav lit est tur
lang->clear();
lang->addItem( tr("English"), "eng" );
lang->addItem( tr("German"), "ger" );
lang->addItem( tr("French"), "fra" );
lang->addItem( tr("Russian"), "rus" );
lang->addItem( tr("Swedish"), "swe" );
lang->addItem( tr("Spanish"), "spa" );
lang->addItem( tr("Italian"), "ita" );
lang->addItem( tr("Russian+English"), "ruseng" );
lang->addItem( tr("Ukrainian"), "ukr" );
lang->addItem( tr("Serbian"), "srp" );
lang->addItem( tr("Croatian"), "hrv" );
lang->addItem( tr("Polish"), "pol" );
lang->addItem( tr("Danish"), "dan" );
lang->addItem( tr("Portuguese"), "por" );
lang->addItem( tr("Dutch"), "dut" );
lang->addItem( tr("Czech"), "cze" );
lang->addItem( tr("Romanian"), "rum" );
lang->addItem( tr("Hungarian"), "hun" );
lang->addItem( tr("Bulgarian"), "bul" );
lang->addItem( tr("Slovenian"), "slo" );
lang->addItem( tr("Latvian"), "lav" );
lang->addItem( tr("Lithuanian"), "lit" );
lang->addItem( tr("Estonian"), "est" );
lang->addItem( tr("Turkish"), "tur" );
QComboBox *fmt = form->format;
/* Supported formats:
html HTML format
hocr hOCR HTML format
native Cuneiform 2000 format
rtf RTF format
smarttext plain text with TeX paragraphs
text plain text
*/
fmt->clear();
fmt->addItem( tr("HTML"), "html" );
/* TODO other format currently is not supported */
fmt->addItem( tr("hOCR HTML"), "hocr" );
// Remove native option because it is binary format and it will not display correctly
//fmt->addItem( tr("Cuneiform 2000 format"), "native" );
fmt->addItem( tr("RTF"), "rtf" );
fmt->addItem( tr("Plain text with TeX paragraphs"), "smarttext" );
fmt->addItem( tr("Plain text"), "text" );
/**/
// TODO Sort languages
// Load settings
load();
}
// Load settings from config file
void Settings::load() {
int id;
QComboBox *lang = form->language;
QComboBox *fmt = form->format;
// Restore saved values
QSettings settings;
pLanguage = settings.value( "Global/Language", QVariant( pLanguage ) ).toString();
pFormat = settings.value( "Global/Format", QVariant( pFormat ) ).toString();
pCommand = settings.value( "Global/Command", QVariant( pCommand ) ).toString();
// Apply settings to form
form->command->setText( pCommand );
id = lang->findData( QVariant( pLanguage ) );
lang->setCurrentIndex( id );
id = fmt->findData( QVariant( pFormat ) );
fmt->setCurrentIndex( id );
}
// Save settings to config file
void Settings::save() {
int id;
id = form->language->currentIndex();
pLanguage = form->language->itemData( id ).toString();
id = form->format->currentIndex();
pFormat = form->format->itemData( id ).toString();
pCommand = form->command->text();
QSettings settings;
settings.setValue( "Global/Language", pLanguage );
settings.setValue( "Global/Format", pFormat );
settings.setValue( "Global/Command", pCommand );
settings.sync();
}
// Get program name
QString Settings::getProgram() {
return pCommand;
}
// Get selected language
QString Settings::getLanguage() {
return pLanguage;
}
// get selected format
QString Settings::getFormat() {
return pFormat;
}
// get input file name
QString Settings::getInputFile() {
return in;
}
// Get output file name
QString Settings::getOutputFile() {
return out;
}
// Set input file name
void Settings::setInputFile( QString fileName ) {
in = fileName;
}
// Set output file name
void Settings::setOutputFile( QString fileName ) {
out = fileName;
}