ControlPasswordInputDialog.cpp

Go to the documentation of this file.
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.vidalia-project.net/. No part of Vidalia, including this file,
00007 **  may be copied, modified, propagated, or distributed except according to the
00008 **  terms described in the LICENSE file.
00009 */
00010 
00011 /*
00012 ** \file ControlPasswordInputDialog.cpp
00013 ** \version $Id: ControlPasswordInputDialog.cpp 3735 2009-04-28 20:28:01Z edmanm $
00014 ** \brief Prompts the user to enter their control port password, and gives
00015 ** them the option to save or attempt to reset it.
00016 */
00017 
00018 #include "ControlPasswordInputDialog.h"
00019 
00020 #include <QPushButton>
00021 
00022 
00023 ControlPasswordInputDialog::ControlPasswordInputDialog(QWidget *parent)
00024   : QDialog(parent)
00025 {
00026   ui.setupUi(this);
00027   setSizeGripEnabled(false);
00028   setAttribute(Qt::WA_DeleteOnClose, false);
00029 
00030   ui.buttonBox->setStandardButtons(QDialogButtonBox::Ok
00031                                      | QDialogButtonBox::Cancel
00032                                      | QDialogButtonBox::Reset
00033                                      | QDialogButtonBox::Help);
00034 
00035   connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton*)),
00036           this, SLOT(clicked(QAbstractButton*)));
00037   connect(ui.linePassword, SIGNAL(textEdited(QString)),
00038           this, SLOT(passwordEdited(QString)));
00039 
00040   /* The dialog starts with an empty password field */
00041   passwordEdited(QString());
00042 }
00043 
00044 void
00045 ControlPasswordInputDialog::setResetEnabled(bool enabled)
00046 {
00047   if (enabled) {
00048     ui.buttonBox->setStandardButtons(ui.buttonBox->standardButtons()
00049                                       | QDialogButtonBox::Reset);
00050   } else {
00051     ui.buttonBox->setStandardButtons(ui.buttonBox->standardButtons()
00052                                       & ~QDialogButtonBox::Reset);
00053   }
00054 }
00055 
00056 QString
00057 ControlPasswordInputDialog::password() const
00058 {
00059   return ui.linePassword->text();
00060 }
00061 
00062 bool
00063 ControlPasswordInputDialog::isSavePasswordChecked() const
00064 {
00065   return ui.chkSavePassword->isChecked();
00066 }
00067 
00068 void
00069 ControlPasswordInputDialog::passwordEdited(const QString &text)
00070 {
00071   QPushButton *okButton = ui.buttonBox->button(QDialogButtonBox::Ok);
00072   if (okButton)
00073     okButton->setEnabled(! text.isEmpty());
00074 }
00075 
00076 void
00077 ControlPasswordInputDialog::clicked(QAbstractButton *button)
00078 {
00079   QDialogButtonBox::StandardButton btn = ui.buttonBox->standardButton(button);
00080   switch (btn) {
00081     case QDialogButtonBox::Ok:
00082     case QDialogButtonBox::Reset:
00083     case QDialogButtonBox::Cancel:
00084       done(btn);
00085       break;
00086 
00087     case QDialogButtonBox::Help:
00088       emit helpRequested("troubleshooting.password");
00089       break;
00090 
00091     default:
00092       break;
00093   }
00094 }
00095 
00096 void
00097 ControlPasswordInputDialog::setVisible(bool visible)
00098 {
00099   if (visible)
00100     resize(minimumSizeHint());
00101   QDialog::setVisible(visible);
00102 }
00103 
Generated on Mon Aug 30 23:09:48 2010 for Vidalia by  doxygen 1.6.3