Vidalia
0.2.15
|
00001 /* 00002 ** This file is part of Vidalia, and is subject to the license terms in the 00003 ** LICENSE file, found in the top level directory of this distribution. If you 00004 ** did not receive the LICENSE file with this file, you may obtain it from the 00005 ** Vidalia source package distributed by the Vidalia Project at 00006 ** http://www.torproject.org/projects/vidalia.html. No part of Vidalia, 00007 ** including this file, may be copied, modified, propagated, or distributed 00008 ** except according to the terms described in the LICENSE file. 00009 */ 00010 00011 /* 00012 ** \file ControlPasswordInputDialog.cpp 00013 ** \brief Prompts the user to enter their control port password, and gives 00014 ** them the option to save or attempt to reset it. 00015 */ 00016 00017 #include "ControlPasswordInputDialog.h" 00018 00019 #include <QPushButton> 00020 00021 00022 ControlPasswordInputDialog::ControlPasswordInputDialog(QWidget *parent) 00023 : QDialog(parent) 00024 { 00025 ui.setupUi(this); 00026 setSizeGripEnabled(false); 00027 setAttribute(Qt::WA_DeleteOnClose, false); 00028 00029 ui.buttonBox->setStandardButtons(QDialogButtonBox::Ok 00030 | QDialogButtonBox::Cancel 00031 | QDialogButtonBox::Reset 00032 | QDialogButtonBox::Help); 00033 00034 connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton*)), 00035 this, SLOT(clicked(QAbstractButton*))); 00036 connect(ui.linePassword, SIGNAL(textEdited(QString)), 00037 this, SLOT(passwordEdited(QString))); 00038 00039 /* The dialog starts with an empty password field */ 00040 passwordEdited(QString()); 00041 } 00042 00043 void 00044 ControlPasswordInputDialog::setResetEnabled(bool enabled) 00045 { 00046 if (enabled) { 00047 ui.buttonBox->setStandardButtons(ui.buttonBox->standardButtons() 00048 | QDialogButtonBox::Reset); 00049 } else { 00050 ui.buttonBox->setStandardButtons(ui.buttonBox->standardButtons() 00051 & ~QDialogButtonBox::Reset); 00052 } 00053 } 00054 00055 QString 00056 ControlPasswordInputDialog::password() const 00057 { 00058 return ui.linePassword->text(); 00059 } 00060 00061 bool 00062 ControlPasswordInputDialog::isSavePasswordChecked() const 00063 { 00064 return ui.chkSavePassword->isChecked(); 00065 } 00066 00067 void 00068 ControlPasswordInputDialog::passwordEdited(const QString &text) 00069 { 00070 QPushButton *okButton = ui.buttonBox->button(QDialogButtonBox::Ok); 00071 if (okButton) 00072 okButton->setEnabled(! text.isEmpty()); 00073 } 00074 00075 void 00076 ControlPasswordInputDialog::clicked(QAbstractButton *button) 00077 { 00078 QDialogButtonBox::StandardButton btn = ui.buttonBox->standardButton(button); 00079 switch (btn) { 00080 case QDialogButtonBox::Ok: 00081 case QDialogButtonBox::Reset: 00082 case QDialogButtonBox::Cancel: 00083 done(btn); 00084 break; 00085 00086 case QDialogButtonBox::Help: 00087 emit helpRequested("troubleshooting.password"); 00088 break; 00089 00090 default: 00091 break; 00092 } 00093 } 00094 00095 void 00096 ControlPasswordInputDialog::setVisible(bool visible) 00097 { 00098 if (visible) 00099 resize(minimumSizeHint()); 00100 QDialog::setVisible(visible); 00101 } 00102