forked from goldendict/goldendict
/
preferences.cc
345 lines (277 loc) · 12.4 KB
/
preferences.cc
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
#include "preferences.hh"
#include "keyboardstate.hh"
#include "language.hh"
#include "langcoder.hh"
#include <QMessageBox>
#include "broken_xrecord.hh"
Preferences::Preferences( QWidget * parent, Config::Preferences const & p ):
QDialog( parent ), prevInterfaceLanguage( 0 )
{
ui.setupUi( this );
connect( ui.enableScanPopup, SIGNAL( toggled( bool ) ),
this, SLOT( enableScanPopupToggled( bool ) ) );
connect( ui.enableScanPopupModifiers, SIGNAL( toggled( bool ) ),
this, SLOT( enableScanPopupModifiersToggled( bool ) ) );
connect( ui.altKey, SIGNAL( clicked( bool ) ),
this, SLOT( wholeAltClicked( bool ) ) );
connect( ui.ctrlKey, SIGNAL( clicked( bool ) ),
this, SLOT( wholeCtrlClicked( bool ) ) );
connect( ui.shiftKey, SIGNAL( clicked( bool ) ),
this, SLOT( wholeShiftClicked( bool ) ) );
connect( ui.leftAlt, SIGNAL( clicked( bool ) ),
this, SLOT( sideAltClicked( bool ) ) );
connect( ui.rightAlt, SIGNAL( clicked( bool ) ),
this, SLOT( sideAltClicked( bool ) ) );
connect( ui.leftCtrl, SIGNAL( clicked( bool ) ),
this, SLOT( sideCtrlClicked( bool ) ) );
connect( ui.rightCtrl, SIGNAL( clicked( bool ) ),
this, SLOT( sideCtrlClicked( bool ) ) );
connect( ui.leftShift, SIGNAL( clicked( bool ) ),
this, SLOT( sideShiftClicked( bool ) ) );
connect( ui.rightShift, SIGNAL( clicked( bool ) ),
this, SLOT( sideShiftClicked( bool ) ) );
// Load values into form
ui.interfaceLanguage->addItem( tr( "System default" ), QString() );
ui.interfaceLanguage->addItem( QIcon( ":/flags/us.png" ), Language::localizedNameForId( LangCoder::code2toInt( "en" ) ), QString( "en_US" ) );
// See which other translations do we have
QStringList availLocs = QDir( Config::getLocDir() ).entryList( QStringList( "*.qm" ),
QDir::Files );
// We need to sort by language name -- otherwise list looks really weird
QMap< QString, QPair< QIcon, QString > > sortedLocs;
for( QStringList::iterator i = availLocs.begin(); i != availLocs.end(); ++i )
{
// Here we assume the xx_YY naming, where xx is language and YY is region.
QString lang = i->mid( 0, 2 );
if ( lang == "qt" )
continue; // We skip qt's own localizations
sortedLocs.insertMulti(
Language::localizedNameForId( LangCoder::code2toInt( lang.toAscii().data() ) ),
QPair< QIcon, QString >(
QIcon( QString( ":/flags/%1.png" ).arg( i->mid( 3, 2 ).toLower() ) ),
i->mid( 0, i->size() - 3 ) ) );
}
for( QMap< QString, QPair< QIcon, QString > >::iterator i = sortedLocs.begin();
i != sortedLocs.end(); ++i )
ui.interfaceLanguage->addItem( i.value().first, i.key(), i.value().second );
for( int x = 0; x < ui.interfaceLanguage->count(); ++x )
if ( ui.interfaceLanguage->itemData( x ).toString() == p.interfaceLanguage )
{
ui.interfaceLanguage->setCurrentIndex( x );
prevInterfaceLanguage = x;
break;
}
ui.displayStyle->addItem( QIcon( ":/icons/programicon.png" ), tr( "Default" ), QString() );
ui.displayStyle->addItem( QIcon( ":/icons/icon32_dsl.png" ), tr( "Lingvo" ), QString( "lingvo" ) );
ui.displayStyle->addItem( QIcon( ":/icons/icon32_bgl.png" ), tr( "Babylon" ), QString( "babylon" ) );
for( int x = 0; x < ui.displayStyle->count(); ++x )
if ( ui.displayStyle->itemData( x ).toString() == p.displayStyle )
{
ui.displayStyle->setCurrentIndex( x );
break;
}
ui.newTabsOpenAfterCurrentOne->setChecked( p.newTabsOpenAfterCurrentOne );
ui.newTabsOpenInBackground->setChecked( p.newTabsOpenInBackground );
ui.hideSingleTab->setChecked( p.hideSingleTab );
ui.mruTabOrder->setChecked( p.mruTabOrder );
ui.enableTrayIcon->setChecked( p.enableTrayIcon );
ui.startToTray->setChecked( p.startToTray );
ui.closeToTray->setChecked( p.closeToTray );
ui.cbAutostart->setChecked( p.autoStart );
ui.doubleClickTranslates->setChecked( p.doubleClickTranslates );
ui.escKeyHidesMainWindow->setChecked( p.escKeyHidesMainWindow );
ui.enableMainWindowHotkey->setChecked( p.enableMainWindowHotkey );
ui.mainWindowHotkey->setHotKey( p.mainWindowHotkey );
ui.enableClipboardHotkey->setChecked( p.enableClipboardHotkey );
ui.clipboardHotkey->setHotKey( p.clipboardHotkey );
ui.enableScanPopup->setChecked( p.enableScanPopup );
ui.startWithScanPopupOn->setChecked( p.startWithScanPopupOn );
ui.enableScanPopupModifiers->setChecked( p.enableScanPopupModifiers );
ui.altKey->setChecked( p.scanPopupModifiers & KeyboardState::Alt );
ui.ctrlKey->setChecked( p.scanPopupModifiers & KeyboardState::Ctrl );
ui.shiftKey->setChecked( p.scanPopupModifiers & KeyboardState::Shift );
ui.winKey->setChecked( p.scanPopupModifiers & KeyboardState::Win );
ui.leftAlt->setChecked( p.scanPopupModifiers & KeyboardState::LeftAlt );
ui.rightAlt->setChecked( p.scanPopupModifiers & KeyboardState::RightAlt );
ui.leftCtrl->setChecked( p.scanPopupModifiers & KeyboardState::LeftCtrl );
ui.rightCtrl->setChecked( p.scanPopupModifiers & KeyboardState::RightCtrl );
ui.leftShift->setChecked( p.scanPopupModifiers & KeyboardState::LeftShift );
ui.rightShift->setChecked( p.scanPopupModifiers & KeyboardState::RightShift );
ui.scanPopupAltMode->setChecked( p.scanPopupAltMode );
ui.scanPopupAltModeSecs->setValue( p.scanPopupAltModeSecs );
ui.scanToMainWindow->setChecked( p.scanToMainWindow );
ui.scanPopupUseUIAutomation->setChecked( p.scanPopupUseUIAutomation );
ui.scanPopupUseIAccessibleEx->setChecked( p.scanPopupUseIAccessibleEx );
ui.scanPopupUseGDMessage->setChecked( p.scanPopupUseGDMessage );
// Different platforms have different keys available
#ifdef Q_OS_WIN32
ui.winKey->hide();
#else
ui.leftAlt->hide();
ui.rightAlt->hide();
ui.leftCtrl->hide();
ui.rightCtrl->hide();
ui.leftShift->hide();
ui.rightShift->hide();
#endif
//Platform-specific options
#ifndef Q_OS_WIN32
// ui.groupBox_ScanPopupTechnologies->hide();
ui.tabWidget->removeTab( 5 );
#endif
// Sound
#ifdef Q_WS_WIN
// Since there's only one Phonon backend under Windows, be more precise
ui.playViaPhonon->setText( tr( "Play via DirectShow" ) );
#else
// This setting is Windows-specific
ui.useWindowsPlaySound->hide();
#endif
ui.pronounceOnLoadMain->setChecked( p.pronounceOnLoadMain );
ui.pronounceOnLoadPopup->setChecked( p.pronounceOnLoadPopup );
ui.useExternalPlayer->setChecked( p.useExternalPlayer );
#ifdef Q_WS_WIN
if ( p.useWindowsPlaySound && !p.useExternalPlayer )
ui.useWindowsPlaySound->setChecked( true );
#endif
ui.audioPlaybackProgram->setText( p.audioPlaybackProgram );
if ( !isRECORDBroken() )
ui.brokenXRECORD->hide();
// Proxy server
ui.useProxyServer->setChecked( p.proxyServer.enabled );
ui.proxyType->addItem( "SOCKS5" );
ui.proxyType->addItem( "HTTP Transp." );
ui.proxyType->addItem( "HTTP Caching" );
ui.proxyType->setCurrentIndex( p.proxyServer.type );
ui.proxyHost->setText( p.proxyServer.host );
ui.proxyPort->setValue( p.proxyServer.port );
ui.proxyUser->setText( p.proxyServer.user );
ui.proxyPassword->setText( p.proxyServer.password );
ui.checkForNewReleases->setChecked( p.checkForNewReleases );
ui.disallowContentFromOtherSites->setChecked( p.disallowContentFromOtherSites );
ui.enableWebPlugins->setChecked( p.enableWebPlugins );
}
Config::Preferences Preferences::getPreferences()
{
Config::Preferences p;
p.interfaceLanguage =
ui.interfaceLanguage->itemData(
ui.interfaceLanguage->currentIndex() ).toString();
p.displayStyle =
ui.displayStyle->itemData(
ui.displayStyle->currentIndex() ).toString();
p.newTabsOpenAfterCurrentOne = ui.newTabsOpenAfterCurrentOne->isChecked();
p.newTabsOpenInBackground = ui.newTabsOpenInBackground->isChecked();
p.hideSingleTab = ui.hideSingleTab->isChecked();
p.mruTabOrder = ui.mruTabOrder->isChecked();
p.enableTrayIcon = ui.enableTrayIcon->isChecked();
p.startToTray = ui.startToTray->isChecked();
p.closeToTray = ui.closeToTray->isChecked();
p.autoStart = ui.cbAutostart->isChecked();
p.doubleClickTranslates = ui.doubleClickTranslates->isChecked();
p.escKeyHidesMainWindow = ui.escKeyHidesMainWindow->isChecked();
p.enableMainWindowHotkey = ui.enableMainWindowHotkey->isChecked();
p.mainWindowHotkey = ui.mainWindowHotkey->getHotKey();
p.enableClipboardHotkey = ui.enableClipboardHotkey->isChecked();
p.clipboardHotkey = ui.clipboardHotkey->getHotKey();
p.enableScanPopup = ui.enableScanPopup->isChecked();
p.startWithScanPopupOn = ui.startWithScanPopupOn->isChecked();
p.enableScanPopupModifiers = ui.enableScanPopupModifiers->isChecked();
p.scanPopupModifiers += ui.altKey->isChecked() ? KeyboardState::Alt : 0;
p.scanPopupModifiers += ui.ctrlKey->isChecked() ? KeyboardState::Ctrl: 0;
p.scanPopupModifiers += ui.shiftKey->isChecked() ? KeyboardState::Shift: 0;
p.scanPopupModifiers += ui.winKey->isChecked() ? KeyboardState::Win: 0;
p.scanPopupModifiers += ui.leftAlt->isChecked() ? KeyboardState::LeftAlt: 0;
p.scanPopupModifiers += ui.rightAlt->isChecked() ? KeyboardState::RightAlt: 0;
p.scanPopupModifiers += ui.leftCtrl->isChecked() ? KeyboardState::LeftCtrl: 0;
p.scanPopupModifiers += ui.rightCtrl->isChecked() ? KeyboardState::RightCtrl: 0;
p.scanPopupModifiers += ui.leftShift->isChecked() ? KeyboardState::LeftShift: 0;
p.scanPopupModifiers += ui.rightShift->isChecked() ? KeyboardState::RightShift: 0;
p.scanPopupAltMode = ui.scanPopupAltMode->isChecked();
p.scanPopupAltModeSecs = ui.scanPopupAltModeSecs->value();
p.scanToMainWindow = ui.scanToMainWindow->isChecked();
p.scanPopupUseUIAutomation = ui.scanPopupUseUIAutomation->isChecked();
p.scanPopupUseIAccessibleEx = ui.scanPopupUseIAccessibleEx->isChecked();
p.scanPopupUseGDMessage = ui.scanPopupUseGDMessage->isChecked();
p.pronounceOnLoadMain = ui.pronounceOnLoadMain->isChecked();
p.pronounceOnLoadPopup = ui.pronounceOnLoadPopup->isChecked();
p.useExternalPlayer = ui.useExternalPlayer->isChecked();
#ifdef Q_WS_WIN
p.useWindowsPlaySound = ui.useWindowsPlaySound->isChecked();
#endif
p.audioPlaybackProgram = ui.audioPlaybackProgram->text();
p.proxyServer.enabled = ui.useProxyServer->isChecked();
p.proxyServer.type = ( Config::ProxyServer::Type ) ui.proxyType->currentIndex();
p.proxyServer.host = ui.proxyHost->text();
p.proxyServer.port = ( unsigned ) ui.proxyPort->value();
p.proxyServer.user = ui.proxyUser->text();
p.proxyServer.password = ui.proxyPassword->text();
p.checkForNewReleases = ui.checkForNewReleases->isChecked();
p.disallowContentFromOtherSites = ui.disallowContentFromOtherSites->isChecked();
p.enableWebPlugins = ui.enableWebPlugins->isChecked();
return p;
}
void Preferences::enableScanPopupToggled( bool b )
{
ui.scanPopupModifiers->setEnabled( b && ui.enableScanPopupModifiers->isChecked() );
}
void Preferences::enableScanPopupModifiersToggled( bool b )
{
ui.scanPopupModifiers->setEnabled( b && ui.enableScanPopup->isChecked() );
}
void Preferences::wholeAltClicked( bool b )
{
if ( b )
{
ui.leftAlt->setChecked( false );
ui.rightAlt->setChecked( false );
}
}
void Preferences::wholeCtrlClicked( bool b )
{
if ( b )
{
ui.leftCtrl->setChecked( false );
ui.rightCtrl->setChecked( false );
}
}
void Preferences::wholeShiftClicked( bool b )
{
if ( b )
{
ui.leftShift->setChecked( false );
ui.rightShift->setChecked( false );
}
}
void Preferences::sideAltClicked( bool )
{
if ( ui.leftAlt->isChecked() || ui.rightAlt->isChecked() )
ui.altKey->setChecked( false );
}
void Preferences::sideCtrlClicked( bool )
{
if ( ui.leftCtrl->isChecked() || ui.rightCtrl->isChecked() )
ui.ctrlKey->setChecked( false );
}
void Preferences::sideShiftClicked( bool )
{
if ( ui.leftShift->isChecked() || ui.rightShift->isChecked() )
ui.shiftKey->setChecked( false );
}
void Preferences::on_enableMainWindowHotkey_toggled( bool checked )
{
ui.mainWindowHotkey->setEnabled( checked );
}
void Preferences::on_enableClipboardHotkey_toggled( bool checked )
{
ui.clipboardHotkey->setEnabled( checked );
}
void Preferences::on_buttonBox_accepted()
{
if ( prevInterfaceLanguage != ui.interfaceLanguage->currentIndex() )
QMessageBox::information( this, tr( "Changing Language" ),
tr( "Restart the program to apply the language change." ) );
}
void Preferences::on_useExternalPlayer_toggled( bool enabled )
{
ui.audioPlaybackProgram->setEnabled( enabled );
}