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 3276 2008-11-03 00:08:59Z 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 <QPushButton>
00019 
00020 #include "controlpasswordinputdialog.h"
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 
00057 QString
00058 ControlPasswordInputDialog::password() const
00059 {
00060   return ui.linePassword->text();
00061 }
00062 
00063 bool
00064 ControlPasswordInputDialog::isSavePasswordChecked() const
00065 {
00066   return ui.chkSavePassword->isChecked();
00067 }
00068 
00069 void
00070 ControlPasswordInputDialog::passwordEdited(const QString &text)
00071 {
00072   QPushButton *okButton = ui.buttonBox->button(QDialogButtonBox::Ok);
00073   if (okButton)
00074     okButton->setEnabled(! text.isEmpty());
00075 }
00076 
00077 void
00078 ControlPasswordInputDialog::clicked(QAbstractButton *button)
00079 {
00080   QDialogButtonBox::StandardButton btn = ui.buttonBox->standardButton(button);
00081   switch (btn) {
00082     case QDialogButtonBox::Ok:
00083     case QDialogButtonBox::Reset:
00084     case QDialogButtonBox::Cancel:
00085       done(btn);
00086       break;
00087 
00088     case QDialogButtonBox::Help:
00089       emit helpRequested("troubleshooting.password");
00090       break;
00091 
00092     default:
00093       break;
00094   }
00095 }
00096 
00097 void
00098 ControlPasswordInputDialog::setVisible(bool visible)
00099 {
00100   if (visible)
00101     resize(minimumSizeHint());
00102   QDialog::setVisible(visible);
00103 }
00104 

Generated on Tue Jul 7 17:00:55 2009 for Vidalia by  doxygen 1.4.7