X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=settingsform.cpp;h=6ca1b033dceaa4981f3d51982657fbc9d0fade06;hb=0a8734cf58bf0c64b1245ce91c50cc05708daeeb;hp=be7f6c6aa9113784eaf0f406b8a6bc436fd70053;hpb=fce0a4ef7d2ce4f362f314799652514fbec56180;p=easylist diff --git a/settingsform.cpp b/settingsform.cpp index be7f6c6..6ca1b03 100755 --- a/settingsform.cpp +++ b/settingsform.cpp @@ -10,6 +10,7 @@ SettingsForm::SettingsForm(QWidget *parent) : ui->syncPasswordLineEdit->setInputMethodHints(Qt::ImhNoAutoUppercase); ui->syncUrlLineEdit->setInputMethodHints(Qt::ImhNoAutoUppercase); settings = new QSettings(WILLEM_LIU, EASY_LIST); + ui->syncPasswordLineEdit->installEventFilter(this); shown(); } @@ -20,12 +21,40 @@ SettingsForm::~SettingsForm() void SettingsForm::shown() { - ui->syncUsernameLineEdit->clear(); - ui->syncPasswordLineEdit->clear(); - ui->syncUrlLineEdit->setText(settings->value(SYNC_URL, DEFAULT_SYNC_URL).toString()); + ui->syncUsernameLineEdit->setText(settings->value(USERNAME,"").toString()); + ui->syncPasswordLineEdit->setText(settings->value(PASSWORD,"").toString()); + if(settings->contains(PASSWORD)) + { + ui->syncPasswordLineEdit->setReadOnly(true); + } + + QString syncUrl = settings->value(SYNC_URL, DEFAULT_SYNC_URL).toString(); + if(syncUrl.compare("http://www.willemliu.nl/qt/maemo/easylist/getList.php") == 0) + { + syncUrl = "http://easylist.willemliu.nl/getList.php"; + } + ui->syncUrlLineEdit->setText(syncUrl); ui->syncUsernameLineEdit->setFocus(Qt::ActiveWindowFocusReason); } +bool SettingsForm::eventFilter(QObject *obj, QEvent *e) +{ + if(obj == ui->syncPasswordLineEdit && ui->syncPasswordLineEdit->isReadOnly() && e->type() == QEvent::MouseButtonRelease) + { + int res = QMessageBox::warning(this, "Clear Password", + "Are you sure you would like to change the password?", + QMessageBox::Yes, QMessageBox::Cancel); + if(res==QMessageBox::Yes) + { + ui->syncPasswordLineEdit->setReadOnly(false); + ui->syncPasswordLineEdit->clear(); + } + } + else + return QWidget::eventFilter(obj,e); + return true; +} + void SettingsForm::on_restoreSyncPushButton_clicked() { ui->syncUrlLineEdit->setText(DEFAULT_SYNC_URL); @@ -34,6 +63,7 @@ void SettingsForm::on_restoreSyncPushButton_clicked() void SettingsForm::on_applyPushButton_clicked() { saveSync(); + shown(); } void SettingsForm::on_savePushButton_clicked() @@ -46,10 +76,19 @@ void SettingsForm::saveSync() { settings->setValue(USERNAME, ui->syncUsernameLineEdit->text()); QVariant passString = ui->syncPasswordLineEdit->text(); - QString passMd5 = QCryptographicHash::hash(passString.toByteArray(), QCryptographicHash::Md5).toHex().constData(); - // We save the md5 hash of the password instead of the real password so it won't be retrievable. - settings->setValue(PASSWORD, passMd5); + + if(ui->syncPasswordLineEdit->isReadOnly()) //Password is already a hash + { + settings->setValue(PASSWORD, passString); + } + else + { + QString passMd5 = QCryptographicHash::hash(passString.toByteArray(), QCryptographicHash::Md5).toHex().constData(); + // We save the md5 hash of the password instead of the real password so it won't be retrievable. + settings->setValue(PASSWORD, passMd5); + } settings->setValue(SYNC_URL, ui->syncUrlLineEdit->text()); + settings->sync(); } void SettingsForm::on_cancelPushButton_clicked()