delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / runtime / kwalletd / kwalletwizard.cpp
blob42f4238e618ed86ed4ce66ae492abba9f02fbf88
1 /* This file is part of the KDE libraries
2 Copyright (C) 2004 George Staikos <staikos@kde.org>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #include "kwalletwizard.h"
20 #include "kwalletwizard.moc"
22 #include "ui_kwalletwizardpageexplanation.h"
23 #include "ui_kwalletwizardpageintro.h"
24 #include "ui_kwalletwizardpageoptions.h"
25 #include "ui_kwalletwizardpagepassword.h"
27 #include <QtGui/QButtonGroup>
29 #include <klocale.h>
31 class PageIntro : public QWizardPage
33 public:
34 PageIntro(QWidget *parent)
35 : QWizardPage(parent)
37 ui.setupUi(this);
39 bg = new QButtonGroup(this);
40 bg->setExclusive(true);
41 bg->addButton(ui._basic, 0);
42 bg->addButton(ui._advanced, 1);
44 // force the "basic" button to be selected
45 ui._basic->setChecked(true);
48 QButtonGroup *bg;
50 private:
51 Ui::KWalletWizardPageIntro ui;
55 class PagePassword : public QWizardPage
57 public:
58 PagePassword(QWidget *parent)
59 : QWizardPage(parent)
61 ui.setupUi(this);
63 registerField("useWallet", ui._useWallet);
64 registerField("pass1", ui._pass1);
65 registerField("pass2", ui._pass2);
67 connect(ui._useWallet, SIGNAL(clicked()), parent, SLOT(passwordPageUpdate()));
68 connect(ui._pass1, SIGNAL(textChanged(QString)), parent, SLOT(passwordPageUpdate()));
69 connect(ui._pass2, SIGNAL(textChanged(QString)), parent, SLOT(passwordPageUpdate()));
72 virtual int nextId() const
74 return static_cast<KWalletWizard*>(wizard())->wizardType() == KWalletWizard::Basic ? -1 : KWalletWizard::PageOptionsId;
77 void setMatchLabelText(const QString &text)
79 ui._matchLabel->setText(text);
82 private:
83 Ui::KWalletWizardPagePassword ui;
87 class PageOptions : public QWizardPage
89 public:
90 PageOptions(QWidget *parent)
91 : QWizardPage(parent)
93 ui.setupUi(this);
95 registerField("closeWhenIdle", ui._closeIdle);
96 registerField("networkWallet", ui._networkWallet);
99 private:
100 Ui::KWalletWizardPageOptions ui;
104 class PageExplanation : public QWizardPage
106 public:
107 PageExplanation(QWidget *parent)
108 : QWizardPage(parent)
110 ui.setupUi(this);
111 setFinalPage(true);
114 private:
115 Ui::KWalletWizardPageExplanation ui;
120 KWalletWizard::KWalletWizard( QWidget *parent )
121 : QWizard(parent)
123 setOption(HaveFinishButtonOnEarlyPages);
125 m_pageIntro = new PageIntro(this);
126 setPage(PageIntroId, m_pageIntro);
127 m_pagePasswd = new PagePassword(this);
128 setPage(PagePasswordId, m_pagePasswd);
129 setPage(PageOptionsId, new PageOptions(this));
130 setPage(PageExplanationId, new PageExplanation(this));
133 void KWalletWizard::passwordPageUpdate()
135 bool complete = true;
136 if (field("useWallet").toBool()) {
137 if (field("pass1").toString() == field("pass2").toString()) {
138 if (field("pass1").toString().isEmpty()) {
139 m_pagePasswd->setMatchLabelText(i18n("<qt>Password is empty. <b>(WARNING: Insecure)</b></qt>"));
140 } else {
141 m_pagePasswd->setMatchLabelText(i18n("Passwords match."));
143 } else {
144 m_pagePasswd->setMatchLabelText(i18n("Passwords do not match."));
145 complete = false;
147 } else {
148 m_pagePasswd->setMatchLabelText(QString());
150 button(wizardType() == Basic ? FinishButton : NextButton)->setEnabled(complete);
153 KWalletWizard::WizardType KWalletWizard::wizardType() const
155 return (KWalletWizard::WizardType)m_pageIntro->bg->checkedId();
158 void KWalletWizard::initializePage(int id)
160 switch (id) {
161 case PagePasswordId:
163 bool islast = m_pageIntro->bg->checkedId() == 0;
164 m_pagePasswd->setFinalPage(islast);
165 button(NextButton)->setVisible(!islast);
166 break;