Vidalia  0.2.21
ControlPasswordInputDialog.cpp
Go to the documentation of this file.
1 /*
2 ** This file is part of Vidalia, and is subject to the license terms in the
3 ** LICENSE file, found in the top level directory of this distribution. If you
4 ** did not receive the LICENSE file with this file, you may obtain it from the
5 ** Vidalia source package distributed by the Vidalia Project at
6 ** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
7 ** including this file, may be copied, modified, propagated, or distributed
8 ** except according to the terms described in the LICENSE file.
9 */
10 
11 /*
12 ** \file ControlPasswordInputDialog.cpp
13 ** \brief Prompts the user to enter their control port password, and gives
14 ** them the option to save or attempt to reset it.
15 */
16 
18 
19 #include <QPushButton>
20 
21 
23  : QDialog(parent)
24 {
25  ui.setupUi(this);
26  setSizeGripEnabled(false);
27  setAttribute(Qt::WA_DeleteOnClose, false);
28 
29  ui.buttonBox->setStandardButtons(QDialogButtonBox::Ok
30  | QDialogButtonBox::Cancel
31  | QDialogButtonBox::Reset
32  | QDialogButtonBox::Help);
33 
34  connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton*)),
35  this, SLOT(clicked(QAbstractButton*)));
36  connect(ui.linePassword, SIGNAL(textEdited(QString)),
37  this, SLOT(passwordEdited(QString)));
38 
39  /* The dialog starts with an empty password field */
40  passwordEdited(QString());
41 }
42 
43 void
45 {
46  if (enabled) {
47  ui.buttonBox->setStandardButtons(ui.buttonBox->standardButtons()
48  | QDialogButtonBox::Reset);
49  } else {
50  ui.buttonBox->setStandardButtons(ui.buttonBox->standardButtons()
51  & ~QDialogButtonBox::Reset);
52  }
53 }
54 
55 QString
57 {
58  return ui.linePassword->text();
59 }
60 
61 bool
63 {
64  return ui.chkSavePassword->isChecked();
65 }
66 
67 void
69 {
70  QPushButton *okButton = ui.buttonBox->button(QDialogButtonBox::Ok);
71  if (okButton)
72  okButton->setEnabled(! text.isEmpty());
73 }
74 
75 void
76 ControlPasswordInputDialog::clicked(QAbstractButton *button)
77 {
78  QDialogButtonBox::StandardButton btn = ui.buttonBox->standardButton(button);
79  switch (btn) {
80  case QDialogButtonBox::Ok:
81  case QDialogButtonBox::Reset:
82  case QDialogButtonBox::Cancel:
83  done(btn);
84  break;
85 
86  case QDialogButtonBox::Help:
87  emit helpRequested("troubleshooting.password");
88  break;
89 
90  default:
91  break;
92  }
93 }
94 
95 void
97 {
98  if (visible)
99  resize(minimumSizeHint());
100  QDialog::setVisible(visible);
101 }
102