KIO
kwalletwizard.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "kwalletwizard.h"
00020 #include "kwalletwizard.moc"
00021
00022 #include "ui_kwalletwizardpageexplanation.h"
00023 #include "ui_kwalletwizardpageintro.h"
00024 #include "ui_kwalletwizardpageoptions.h"
00025 #include "ui_kwalletwizardpagepassword.h"
00026
00027 #include <QtGui/QButtonGroup>
00028
00029 #include <klocale.h>
00030
00031 class PageIntro : public QWizardPage
00032 {
00033 public:
00034 PageIntro(QWidget *parent)
00035 : QWizardPage(parent)
00036 {
00037 ui.setupUi(this);
00038
00039 bg = new QButtonGroup(this);
00040 bg->setExclusive(true);
00041 bg->addButton(ui._basic, 0);
00042 bg->addButton(ui._advanced, 1);
00043
00044
00045 ui._basic->setChecked(true);
00046 }
00047
00048 QButtonGroup *bg;
00049
00050 private:
00051 Ui::KWalletWizardPageIntro ui;
00052 };
00053
00054
00055 class PagePassword : public QWizardPage
00056 {
00057 public:
00058 PagePassword(QWidget *parent)
00059 : QWizardPage(parent)
00060 {
00061 ui.setupUi(this);
00062
00063 registerField("useWallet", ui._useWallet);
00064 registerField("pass1", ui._pass1);
00065 registerField("pass2", ui._pass2);
00066
00067 connect(ui._useWallet, SIGNAL(clicked()), parent, SLOT(passwordPageUpdate()));
00068 connect(ui._pass1, SIGNAL(textChanged(QString)), parent, SLOT(passwordPageUpdate()));
00069 connect(ui._pass2, SIGNAL(textChanged(QString)), parent, SLOT(passwordPageUpdate()));
00070 }
00071
00072 virtual int nextId() const
00073 {
00074 return static_cast<KWalletWizard*>(wizard())->wizardType() == KWalletWizard::Basic ? -1 : KWalletWizard::PageOptionsId;
00075 }
00076
00077 void setMatchLabelText(const QString &text)
00078 {
00079 ui._matchLabel->setText(text);
00080 }
00081
00082 private:
00083 Ui::KWalletWizardPagePassword ui;
00084 };
00085
00086
00087 class PageOptions : public QWizardPage
00088 {
00089 public:
00090 PageOptions(QWidget *parent)
00091 : QWizardPage(parent)
00092 {
00093 ui.setupUi(this);
00094
00095 registerField("closeWhenIdle", ui._closeIdle);
00096 registerField("networkWallet", ui._networkWallet);
00097 }
00098
00099 private:
00100 Ui::KWalletWizardPageOptions ui;
00101 };
00102
00103
00104 class PageExplanation : public QWizardPage
00105 {
00106 public:
00107 PageExplanation(QWidget *parent)
00108 : QWizardPage(parent)
00109 {
00110 ui.setupUi(this);
00111 setFinalPage(true);
00112 }
00113
00114 private:
00115 Ui::KWalletWizardPageExplanation ui;
00116 };
00117
00118
00119
00120 KWalletWizard::KWalletWizard( QWidget *parent )
00121 : QWizard(parent)
00122 {
00123 setOption(HaveFinishButtonOnEarlyPages);
00124
00125 m_pageIntro = new PageIntro(this);
00126 setPage(PageIntroId, m_pageIntro);
00127 m_pagePasswd = new PagePassword(this);
00128 setPage(PagePasswordId, m_pagePasswd);
00129 setPage(PageOptionsId, new PageOptions(this));
00130 setPage(PageExplanationId, new PageExplanation(this));
00131 }
00132
00133 void KWalletWizard::passwordPageUpdate()
00134 {
00135 bool complete = true;
00136 if (field("useWallet").toBool()) {
00137 if (field("pass1").toString() == field("pass2").toString()) {
00138 if (field("pass1").toString().isEmpty()) {
00139 m_pagePasswd->setMatchLabelText(i18n("<qt>Password is empty. <b>(WARNING: Insecure)</b></qt>"));
00140 } else {
00141 m_pagePasswd->setMatchLabelText(i18n("Passwords match."));
00142 }
00143 } else {
00144 m_pagePasswd->setMatchLabelText(i18n("Passwords do not match."));
00145 complete = false;
00146 }
00147 } else {
00148 m_pagePasswd->setMatchLabelText(QString());
00149 }
00150 button(wizardType() == Basic ? FinishButton : NextButton)->setEnabled(complete);
00151 }
00152
00153 KWalletWizard::WizardType KWalletWizard::wizardType() const
00154 {
00155 return (KWalletWizard::WizardType)m_pageIntro->bg->checkedId();
00156 }
00157
00158 void KWalletWizard::initializePage(int id)
00159 {
00160 switch (id) {
00161 case PagePasswordId:
00162 {
00163 bool islast = m_pageIntro->bg->checkedId() == 0;
00164 m_pagePasswd->setFinalPage(islast);
00165 button(NextButton)->setVisible(!islast);
00166 break;
00167 }
00168 }
00169 }
00170