00001 #include "settingsdialog.h" 00002 #include <QMessageBox> 00003 #include "../Data/settings.h" 00004 00005 SettingsDialog::SettingsDialog(Settings &set, QWidget *parent) : QDialog(parent) 00006 { 00007 setupUi(this); 00008 setAttribute(Qt::WA_DeleteOnClose, true); 00009 createActions(); 00010 settings = &set; 00011 restoreSettings(); 00012 } 00013 00014 void SettingsDialog::createActions() 00015 { 00016 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ok())); 00017 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(cancel())); 00018 00019 connect(buttonChooseWorkspace, SIGNAL(clicked()), this, SLOT(chooseWorkSpace())); 00020 } 00021 00022 void SettingsDialog::ok() 00023 { 00024 if(saveSettings()) 00025 { 00026 done(0); 00027 } 00028 else 00029 { 00030 QMessageBox::warning(this, tr("Fehler"), tr("Es trat ein Fehler auf! Möglicherweise ist eine Ihrer Eingaben falsch!")); 00031 } 00032 } 00033 00034 void SettingsDialog::cancel() 00035 { 00036 done(1); 00037 } 00038 00039 bool SettingsDialog::restoreSettings() 00040 { 00041 textWorkspace->setText(settings->workspace().absolutePath()); 00042 00043 checkBoxUpdatesEnabled->setChecked(settings->automaticCheckForUpdates()); 00044 radioTeacher->setChecked(settings->teacher()); 00045 radioPupil->setChecked(!(settings->teacher())); 00046 00047 return true; 00048 } 00049 00050 bool SettingsDialog::saveSettings() 00051 { 00052 if(textWorkspace->text() != QString() || !QDir(textWorkspace->text()).exists()) 00053 { 00054 settings->setWorkspace(textWorkspace->text()); 00055 } 00056 else 00057 { 00058 settings->chooseWorkspacePath(); 00059 } 00060 00061 settings->setAutomaticCheckForUpdates(checkBoxUpdatesEnabled->isChecked()); 00062 00063 if(settings->teacher() != radioTeacher->isChecked()) 00064 { 00065 settings->setTeacher(radioTeacher->isChecked()); 00066 emit teacherPupilSwitch(); 00067 } 00068 00069 return true; 00070 } 00071 00072 void SettingsDialog::chooseWorkSpace() 00073 { 00074 textWorkspace->setText(settings->chooseWorkspacePath()); 00075 }