2009-02-05 20:55:00 +00:00
|
|
|
#include "preferences.hh"
|
|
|
|
#include "keyboardstate.hh"
|
2009-04-12 20:46:25 +00:00
|
|
|
#include <QMessageBox>
|
2009-02-05 20:55:00 +00:00
|
|
|
|
|
|
|
Preferences::Preferences( QWidget * parent, Config::Preferences const & p ):
|
2009-04-12 20:46:25 +00:00
|
|
|
QDialog( parent ), prevInterfaceLanguage( 0 )
|
2009-02-05 20:55:00 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
|
2009-04-12 20:46:25 +00:00
|
|
|
ui.interfaceLanguage->addItem( tr( "System default" ), QString() );
|
2009-05-02 22:15:14 +00:00
|
|
|
ui.interfaceLanguage->addItem( QIcon( ":/flags/us.png" ), tr( "English" ), QString( "en_US" ) );
|
|
|
|
ui.interfaceLanguage->addItem( QIcon( ":/flags/ru.png" ), tr( "Russian" ), QString( "ru_RU" ) );
|
2009-04-12 20:46:25 +00:00
|
|
|
|
|
|
|
for( int x = 0; x < ui.interfaceLanguage->count(); ++x )
|
|
|
|
if ( ui.interfaceLanguage->itemData( x ).toString() == p.interfaceLanguage )
|
|
|
|
{
|
|
|
|
ui.interfaceLanguage->setCurrentIndex( x );
|
|
|
|
prevInterfaceLanguage = x;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-04-13 12:51:25 +00:00
|
|
|
ui.newTabsOpenAfterCurrentOne->setChecked( p.newTabsOpenAfterCurrentOne );
|
|
|
|
ui.newTabsOpenInBackground->setChecked( p.newTabsOpenInBackground );
|
2009-02-05 20:55:00 +00:00
|
|
|
ui.enableTrayIcon->setChecked( p.enableTrayIcon );
|
|
|
|
ui.startToTray->setChecked( p.startToTray );
|
|
|
|
ui.closeToTray->setChecked( p.closeToTray );
|
2009-04-18 18:21:12 +00:00
|
|
|
ui.cbAutostart->setChecked( p.autoStart );
|
2009-04-21 18:27:26 +00:00
|
|
|
|
|
|
|
ui.enableMainWindowHotkey->setChecked( p.enableMainWindowHotkey );
|
|
|
|
ui.mainWindowHotkey->setHotKey( p.mainWindowHotkey );
|
|
|
|
ui.enableClipboardHotkey->setChecked( p.enableClipboardHotkey );
|
|
|
|
ui.clipboardHotkey->setHotKey( p.clipboardHotkey );
|
|
|
|
|
2009-02-05 20:55:00 +00:00
|
|
|
ui.enableScanPopup->setChecked( p.enableScanPopup );
|
2009-02-08 20:20:02 +00:00
|
|
|
ui.startWithScanPopupOn->setChecked( p.startWithScanPopupOn );
|
2009-02-05 20:55:00 +00:00
|
|
|
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 );
|
|
|
|
|
2009-04-11 16:44:14 +00:00
|
|
|
ui.scanPopupAltMode->setChecked( p.scanPopupAltMode );
|
|
|
|
ui.scanPopupAltModeSecs->setValue( p.scanPopupAltModeSecs );
|
|
|
|
|
2009-02-05 20:55:00 +00:00
|
|
|
// 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
|
2009-04-03 17:10:27 +00:00
|
|
|
|
2009-04-10 21:07:03 +00:00
|
|
|
// Sound
|
|
|
|
|
|
|
|
ui.pronounceOnLoadPopup->setEnabled( p.enableScanPopup );
|
|
|
|
|
|
|
|
ui.pronounceOnLoadMain->setChecked( p.pronounceOnLoadMain );
|
|
|
|
ui.pronounceOnLoadPopup->setChecked( p.pronounceOnLoadPopup );
|
|
|
|
ui.audioPlaybackProgram->setText( p.audioPlaybackProgram );
|
|
|
|
|
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
ui.audioPlaybackProgram->hide();
|
2009-04-12 16:34:04 +00:00
|
|
|
ui.audioPlaybackProgramLabel->hide();
|
2009-04-10 21:07:03 +00:00
|
|
|
#endif
|
|
|
|
|
2009-04-03 17:10:27 +00:00
|
|
|
// 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 );
|
2009-04-20 19:54:34 +00:00
|
|
|
|
|
|
|
ui.checkForNewReleases->setChecked( p.checkForNewReleases );
|
2009-02-05 20:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Config::Preferences Preferences::getPreferences()
|
|
|
|
{
|
|
|
|
Config::Preferences p;
|
|
|
|
|
2009-04-12 20:46:25 +00:00
|
|
|
p.interfaceLanguage =
|
|
|
|
ui.interfaceLanguage->itemData(
|
|
|
|
ui.interfaceLanguage->currentIndex() ).toString();
|
|
|
|
|
2009-04-13 12:51:25 +00:00
|
|
|
p.newTabsOpenAfterCurrentOne = ui.newTabsOpenAfterCurrentOne->isChecked();
|
|
|
|
p.newTabsOpenInBackground = ui.newTabsOpenInBackground->isChecked();
|
2009-02-08 20:20:02 +00:00
|
|
|
p.enableTrayIcon = ui.enableTrayIcon->isChecked();
|
|
|
|
p.startToTray = ui.startToTray->isChecked();
|
|
|
|
p.closeToTray = ui.closeToTray->isChecked();
|
2009-04-18 18:21:12 +00:00
|
|
|
p.autoStart = ui.cbAutostart->isChecked();
|
2009-04-21 18:27:26 +00:00
|
|
|
|
|
|
|
p.enableMainWindowHotkey = ui.enableMainWindowHotkey->isChecked();
|
|
|
|
p.mainWindowHotkey = ui.mainWindowHotkey->getHotKey();
|
|
|
|
p.enableClipboardHotkey = ui.enableClipboardHotkey->isChecked();
|
|
|
|
p.clipboardHotkey = ui.clipboardHotkey->getHotKey();
|
|
|
|
|
2009-02-08 20:20:02 +00:00
|
|
|
p.enableScanPopup = ui.enableScanPopup->isChecked();
|
|
|
|
p.startWithScanPopupOn = ui.startWithScanPopupOn->isChecked();
|
|
|
|
p.enableScanPopupModifiers = ui.enableScanPopupModifiers->isChecked();
|
2009-02-05 20:55:00 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2009-04-11 16:44:14 +00:00
|
|
|
p.scanPopupAltMode = ui.scanPopupAltMode->isChecked();
|
|
|
|
p.scanPopupAltModeSecs = ui.scanPopupAltModeSecs->value();
|
|
|
|
|
2009-04-10 21:07:03 +00:00
|
|
|
p.pronounceOnLoadMain = ui.pronounceOnLoadMain->isChecked();
|
|
|
|
p.pronounceOnLoadPopup = ui.pronounceOnLoadPopup->isChecked();
|
|
|
|
p.audioPlaybackProgram = ui.audioPlaybackProgram->text();
|
|
|
|
|
2009-04-03 17:10:27 +00:00
|
|
|
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();
|
|
|
|
|
2009-04-20 19:54:34 +00:00
|
|
|
p.checkForNewReleases = ui.checkForNewReleases->isChecked();
|
|
|
|
|
2009-02-05 20:55:00 +00:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preferences::enableScanPopupToggled( bool b )
|
|
|
|
{
|
|
|
|
ui.scanPopupModifiers->setEnabled( b && ui.enableScanPopupModifiers->isChecked() );
|
2009-04-10 21:07:03 +00:00
|
|
|
ui.pronounceOnLoadPopup->setEnabled( b );
|
2009-02-05 20:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
2009-04-12 20:46:25 +00:00
|
|
|
|
2009-04-21 18:27:26 +00:00
|
|
|
void Preferences::on_enableMainWindowHotkey_toggled( bool checked )
|
|
|
|
{
|
|
|
|
ui.mainWindowHotkey->setEnabled( checked );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preferences::on_enableClipboardHotkey_toggled( bool checked )
|
|
|
|
{
|
|
|
|
ui.clipboardHotkey->setEnabled( checked );
|
|
|
|
}
|
|
|
|
|
2009-04-12 20:46:25 +00:00
|
|
|
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." ) );
|
|
|
|
}
|
|
|
|
|