1 /***************************************************************************
2 * Copyright (C) 2005 by Tarek Saidi *
3 * tarek.saidi@arcor.de *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; version 2 of the License. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18 ***************************************************************************/
20 #include <QFileDialog>
21 #include <QColorDialog>
22 #include "dialogs/SettingsDlg.h"
23 #include "dialogs/CustomizeDetailViewDlg.h"
25 //bool CSettingsDlg::PluginsModified=false;
28 CSettingsDlg::CSettingsDlg(QWidget* parent):QDialog(parent,Qt::Dialog)
31 connect(listWidget, SIGNAL( currentRowChanged(int) ), stackedWidget, SLOT( setCurrentIndex(int) ) );
33 connect(DialogButtons, SIGNAL( accepted() ), this, SLOT( OnOK() ) );
34 connect(DialogButtons, SIGNAL( rejected() ), this, SLOT( OnCancel() ) );
35 connect(DialogButtons, SIGNAL( clicked(QAbstractButton*)), this, SLOT(OnOtherButton(QAbstractButton*)));
37 connect(CheckBox_ShowSysTrayIcon, SIGNAL( toggled(bool) ), CheckBox_MinimizeTray, SLOT( setEnabled(bool) ) );
38 connect(CheckBox_OpenLast, SIGNAL( toggled(bool) ), CheckBox_RememberLastKey, SLOT( setEnabled(bool) ) );
39 connect(CheckBox_OpenLast, SIGNAL( toggled(bool) ), CheckBox_StartMinimized, SLOT( setEnabled(bool) ) );
40 connect(CheckBox_OpenLast, SIGNAL( toggled(bool) ), CheckBox_StartLocked, SLOT( setEnabled(bool) ) );
42 connect(listSelectLanguage, SIGNAL( currentRowChanged(int) ), SLOT( OnSelectLanguage(int) ) );
44 connect(Button_ClearFileDlgHistory, SIGNAL(clicked()), &fileDlgHistory, SLOT(clear()));
45 connect(ButtonColor1, SIGNAL( clicked() ), this, SLOT( OnColor1() ) );
46 connect(ButtonColor2, SIGNAL( clicked() ), this, SLOT( OnColor2() ) );
47 connect(ButtonTextColor, SIGNAL( clicked() ), this, SLOT( OnTextColor() ) );
48 connect(Button_MountDirBrowse,SIGNAL(clicked()),this,SLOT(OnMountDirBrowse()));
49 connect(Button_BrowserCmdBrowse,SIGNAL(clicked()),this,SLOT(OnBrowserCmdBrowse()));
51 //connect(Radio_IntPlugin_None,SIGNAL(toggled(bool)),this,SLOT(OnIntPluginNone()));
52 //connect(Radio_IntPlugin_Gnome,SIGNAL(toggled(bool)),this,SLOT(OnIntPluginGnome()));
53 //connect(Radio_IntPlugin_Kde,SIGNAL(toggled(bool)),this,SLOT(OnIntPluginKde()));
55 connect(Button_CustomizeEntryDetails,SIGNAL(clicked()),this,SLOT(OnCustomizeEntryDetails()));
56 connect(CheckBox_InactivityLock, SIGNAL(toggled(bool)), SLOT(OnInactivityLockChange(bool)));
58 connect(CheckBox_Backup, SIGNAL( toggled(bool) ), CheckBox_BackupDelete, SLOT( setEnabled(bool) ) );
59 connect(CheckBox_Backup, SIGNAL( toggled(bool) ), SLOT( OnBackupDeleteChange() ) );
60 connect(CheckBox_BackupDelete, SIGNAL( toggled(bool) ), SLOT( OnBackupDeleteChange() ) );
61 connect(CheckBox_AutoSave, SIGNAL(toggled(bool)), SLOT(OnAutoSaveToggle(bool)));
62 connect(CheckBox_AutoSaveChange, SIGNAL(toggled(bool)), SLOT(OnAutoSaveChangeToggle(bool)));
64 #if !defined(AUTOTYPE)
65 Box_AutoType->setVisible(false);
67 #if !defined(GLOBAL_AUTOTYPE)
68 Label_GlobalShortcut->setVisible(false);
69 Edit_GlobalShortcut->setVisible(false);
70 CheckBox_EntryTitlesMatch->setVisible(false);
73 CheckBox_AlwaysOnTop->setVisible(false);
76 #ifdef GLOBAL_AUTOTYPE
77 pShortcut = autoType->getShortcut();
78 connect(this,SIGNAL(rejected()),SLOT(resetGlobalShortcut()));
81 listWidget->setCurrentRow(0);
84 CheckBox_OpenLast->setChecked(config->openLastFile());
85 CheckBox_RememberLastKey->setChecked(config->rememberLastKey());
86 CheckBox_ShowSysTrayIcon->setChecked(config->showSysTrayIcon());
87 CheckBox_MinimizeTray->setChecked(config->minimizeTray());
88 CheckBox_StartMinimized->setChecked(config->startMinimized());
89 CheckBox_StartLocked->setChecked(config->startLocked());
90 checkBox_SaveFileDlgHistory->setChecked(config->saveFileDlgHistory());
91 checkBox_AskBeforeDelete->setChecked(config->askBeforeDelete());
94 CheckBox_Backup->setChecked(config->backup());
95 CheckBox_BackupDelete->setChecked(config->backupDelete());
96 SpinBox_BackupDeleteAfter->setValue(config->backupDeleteAfter());
97 CheckBox_AutoSave->setChecked(config->autoSave());
98 CheckBox_AutoSaveChange->setChecked(config->autoSaveChange());
100 switch(config->groupTreeState()){
101 case KpxConfig::RestoreLast:
102 Radio_GroupTreeRestore->setChecked(true);
104 case KpxConfig::ExpandAll:
105 Radio_GroupTreeExpand->setChecked(true);
108 Radio_GroupTreeDoNothing->setChecked(true);
112 CheckBox_AlwaysOnTop->setChecked(config->alwaysOnTop());
113 QPixmap *pxt=new QPixmap(pixmTextColor->width(),pixmTextColor->height());
114 pxt->fill(config->bannerTextColor());
115 pixmTextColor->clear();
116 pixmTextColor->setPixmap(*pxt);
118 QPixmap *px1=new QPixmap(pixmColor1->width(),pixmColor1->height());
119 px1->fill(config->bannerColor1());
121 pixmColor1->setPixmap(*px1);
123 QPixmap *px2=new QPixmap(pixmColor2->width(),pixmColor2->height());
124 px2->fill(config->bannerColor2());
126 pixmColor2->setPixmap(*px2);
128 color1=config->bannerColor1();
129 color2=config->bannerColor2();
130 textcolor=config->bannerTextColor();
131 CheckBox_AlternatingRowColors->setChecked(config->alternatingRowColors());
134 translations = getAllTranslations();
136 QString currentLang = config->language();
137 bool foundCurrent = false;
138 for (int i=0; i<translations.size(); i++){
139 if (translations[i].nameCode==currentLang){
140 listSelectLanguage->setCurrentRow(i+2);
145 if (currentLang=="en_US")
146 listSelectLanguage->setCurrentRow(1);
148 listSelectLanguage->setCurrentRow(0);
152 SpinBox_ClipboardTime->setValue(config->clipboardTimeOut());
153 CheckBox_ShowPasswords->setChecked(config->showPasswords());
154 CheckBox_ShowPasswords_PasswordDlg->setChecked(config->showPasswordsPasswordDlg());
155 CheckBox_LockMinimize->setChecked(config->lockOnMinimize());
156 CheckBox_InactivityLock->setChecked(config->lockOnInactivity());
157 SpinBox_InacitivtyTime->setValue(config->lockAfterSec());
160 stackedWidget->removeWidget(pageFeatures);
161 //CheckBox_FeatureBookmarks->setChecked(config->featureBookmarks());
164 // TODO Desktop Integration
165 stackedWidget->removeWidget(pageDesktop);
166 /*if(PluginLoadError==QString())
167 Label_IntPlugin_Error->hide();
169 Label_IntPlugin_Error->setText(QString("<html><p style='font-weight:600; color:#8b0000;'>%1</p></body></html>")
170 .arg(tr("Error: %1")).arg(PluginLoadError));
172 switch(config->integrPlugin()){
174 Radio_IntPlugin_Kde->setChecked(true);
176 case KpxConfig::Gnome:
177 Radio_IntPlugin_Gnome->setChecked(true);
180 Radio_IntPlugin_None->setChecked(true);
183 Label_IntPlugin_Info->hide();*/
187 Box_BrowserCmd->setChecked(!config->urlCmdDef());
188 Edit_BrowserCmd->setText(config->urlCmd());
190 Edit_MountDir->setText(config->mountDir());
191 CheckBox_SaveRelativePaths->setChecked(config->saveRelativePaths());
193 SpinBox_AutoTypePreGap->setValue(config->autoTypePreGap());
194 SpinBox_AutoTypeKeyStrokeDelay->setValue(config->autoTypeKeyStrokeDelay());
196 #ifdef GLOBAL_AUTOTYPE
197 Edit_GlobalShortcut->setShortcut(config->globalShortcut());
198 CheckBox_EntryTitlesMatch->setChecked(config->entryTitlesMatch());
202 resize( size() + QSize(20,20) );
205 CSettingsDlg::~CSettingsDlg(){
208 void CSettingsDlg::paintEvent(QPaintEvent *event){
209 QDialog::paintEvent(event);
210 QPainter painter(this);
211 painter.setClipRegion(event->region());
212 painter.drawPixmap(QPoint(0,0),BannerPixmap);
215 void CSettingsDlg::resizeEvent(QResizeEvent* event){
216 createBanner(&BannerPixmap,getPixmap("appsettings"),tr("Settings"),width());
217 QDialog::resizeEvent(event);
220 void CSettingsDlg::OnOK()
226 void CSettingsDlg::OnCancel()
231 void CSettingsDlg::OnOtherButton(QAbstractButton* button){
232 if(DialogButtons->buttonRole(button)==QDialogButtonBox::ApplyRole)
236 void CSettingsDlg::apply(){
239 config->setShowSysTrayIcon(CheckBox_ShowSysTrayIcon->isChecked());
240 config->setMinimizeTray(CheckBox_MinimizeTray->isChecked());
241 config->setStartMinimized(CheckBox_StartMinimized->isChecked());
242 config->setStartLocked(CheckBox_StartLocked->isChecked());
243 config->setSaveFileDlgHistory(checkBox_SaveFileDlgHistory->isChecked());
244 if(Radio_GroupTreeRestore->isChecked())config->setGroupTreeState(KpxConfig::RestoreLast);
245 else if(Radio_GroupTreeExpand->isChecked())config->setGroupTreeState(KpxConfig::ExpandAll);
246 else config->setGroupTreeState(KpxConfig::DoNothing);
247 config->setOpenLastFile(CheckBox_OpenLast->isChecked());
248 config->setRememberLastKey(CheckBox_RememberLastKey->isChecked());
249 config->setAskBeforeDelete(checkBox_AskBeforeDelete->isChecked());
252 config->setBackup(CheckBox_Backup->isChecked());
253 config->setBackupDelete(CheckBox_BackupDelete->isChecked());
254 config->setBackupDeleteAfter(SpinBox_BackupDeleteAfter->value());
255 config->setAutoSave(CheckBox_AutoSave->isChecked());
256 config->setAutoSaveChange(CheckBox_AutoSaveChange->isChecked());
259 config->setAlwaysOnTop(CheckBox_AlwaysOnTop->isChecked());
260 config->setBannerColor1(color1);
261 config->setBannerColor2(color2);
262 config->setBannerTextColor(textcolor);
263 config->setAlternatingRowColors(CheckBox_AlternatingRowColors->isChecked());
266 int langIndex = listSelectLanguage->currentRow();
267 QString oldLang = config->language();
269 config->setLanguage("auto");
270 else if (langIndex==1)
271 config->setLanguage("en_US");
273 config->setLanguage(translations[langIndex-2].nameCode);
274 if (config->language() != oldLang){
278 listSelectLanguage->setCurrentRow(langIndex);
282 config->setClipboardTimeOut(SpinBox_ClipboardTime->value());
283 config->setShowPasswords(CheckBox_ShowPasswords->isChecked());
284 config->setShowPasswordsPasswordDlg(CheckBox_ShowPasswords_PasswordDlg->isChecked());
285 config->setLockOnMinimize(CheckBox_LockMinimize->isChecked());
286 config->setLockOnInactivity(CheckBox_InactivityLock->isChecked());
287 config->setLockAfterSec(SpinBox_InacitivtyTime->value());
290 //config->setFeatureBookmarks(CheckBox_FeatureBookmarks->isChecked());
292 //TODO Desktop Integration
293 /*PluginsModified=Label_IntPlugin_Info->isVisible();
294 if(Radio_IntPlugin_Kde->isChecked())config->setIntegrPlugin(KpxConfig::KDE);
295 else if(Radio_IntPlugin_Gnome->isChecked())config->setIntegrPlugin(KpxConfig::Gnome);
296 else config->setIntegrPlugin(KpxConfig::NoIntegr);*/
299 config->setUrlCmdDef(!Box_BrowserCmd->isChecked());
300 config->setUrlCmd(Edit_BrowserCmd->text());
301 config->setMountDir(Edit_MountDir->text());
302 if(!config->mountDir().isEmpty() && config->mountDir().right(1)!="/")
303 config->setMountDir(config->mountDir()+"/");
304 config->setSaveRelativePaths(CheckBox_SaveRelativePaths->isChecked());
306 config->setAutoTypePreGap(SpinBox_AutoTypePreGap->value());
307 config->setAutoTypeKeyStrokeDelay(SpinBox_AutoTypeKeyStrokeDelay->value());
309 #ifdef GLOBAL_AUTOTYPE
310 config->setGlobalShortcut(Edit_GlobalShortcut->shortcut());
311 config->setEntryTitlesMatch(CheckBox_EntryTitlesMatch->isChecked());
315 void CSettingsDlg::OnTextColor()
317 QColor c=QColorDialog::getColor(textcolor,this);
320 QPixmap *px=new QPixmap(pixmTextColor->width(),pixmTextColor->height());
322 pixmTextColor->clear();
323 pixmTextColor->setPixmap(*px);
324 createBanner(&BannerPixmap,getPixmap("appsettings"),tr("Settings"),width(),color1,color2,textcolor);
329 void CSettingsDlg::OnColor2()
331 QColor c=QColorDialog::getColor(color2,this);
334 QPixmap *px=new QPixmap(pixmColor2->width(),pixmColor2->height());
337 pixmColor2->setPixmap(*px);
338 createBanner(&BannerPixmap,getPixmap("appsettings"),tr("Settings"),width(),color1,color2,textcolor);
343 void CSettingsDlg::OnColor1()
345 QColor c=QColorDialog::getColor(color1,this);
348 QPixmap *px=new QPixmap(pixmColor1->width(),pixmColor1->height());
351 pixmColor1->setPixmap(*px);
352 createBanner(&BannerPixmap,getPixmap("appsettings"),tr("Settings"),width(),color1,color2,textcolor);
356 void CSettingsDlg::OnMountDirBrowse(){
357 QString dir=QFileDialog::getExistingDirectory(this,tr("Select a directory..."));
359 Edit_MountDir->setText(dir);
363 void CSettingsDlg::OnBrowserCmdBrowse(){
364 QString filename=QFileDialog::getOpenFileName(this,tr("Select an executable..."));
365 if(!filename.isEmpty()){
366 Edit_BrowserCmd->setText(filename);
370 /*void CSettingsDlg::OnIntPluginNone(){
371 Label_IntPlugin_Info->show();
374 void CSettingsDlg::OnIntPluginGnome(){
375 Label_IntPlugin_Info->show();
378 void CSettingsDlg::OnIntPluginKde(){
379 Label_IntPlugin_Info->show();
382 void CSettingsDlg::OnCustomizeEntryDetails(){
383 CustomizeDetailViewDialog dlg(this);
387 void CSettingsDlg::OnInactivityLockChange(bool checked){
388 SpinBox_InacitivtyTime->setEnabled(checked);
391 void CSettingsDlg::OnAutoSaveToggle(bool checked){
392 CheckBox_AutoSaveChange->setEnabled(!checked);
395 void CSettingsDlg::OnAutoSaveChangeToggle(bool checked){
396 CheckBox_AutoSave->setEnabled(!checked);
399 void CSettingsDlg::OnBackupDeleteChange(){
400 SpinBox_BackupDeleteAfter->setEnabled(CheckBox_Backup->isChecked() && CheckBox_BackupDelete->isChecked());
403 void CSettingsDlg::OnSelectLanguage(int index){
409 labelAuthor->clear();
412 labelLang->setText("English (United States)");
413 labelAuthor->setText("KeePassX Development Team");
416 if (translations[index-2].nameLong != translations[index-2].nameEnglish)
417 labelLang->setText(QString("%1 / %2").arg(translations[index-2].nameLong).arg(translations[index-2].nameEnglish));
419 labelLang->setText(translations[index-2].nameEnglish);
420 labelAuthor->setText(translations[index-2].author);
424 void CSettingsDlg::initLanguageList() {
425 listSelectLanguage->clear(); // completely rebuild the list because of a bug in Qt 4.3
426 listSelectLanguage->addItem(tr("System Language"));
427 listSelectLanguage->addItem("English (United States)"); // Don't translate this string
428 for (int i=0; i<translations.size(); i++)
429 listSelectLanguage->addItem(translations[i].nameLong);
432 #ifdef GLOBAL_AUTOTYPE
433 void CSettingsDlg::resetGlobalShortcut(){
434 autoType->unregisterGlobalShortcut();
435 autoType->registerGlobalShortcut(pShortcut);