Add (and install) svg for the new krunner interface.
[kdebase/uwolfer.git] / apps / kdepasswd / passwddlg.cpp
blob6b15bb7fde2dd6d26bb6e33a16ca7f620e5e1991
1 /* vi: ts=8 sts=4 sw=4
3 * This file is part of the KDE project, module kdesu.
4 * Copyright (C) 2000 Geert Jansen <jansen@kde.org>
6 Permission to use, copy, modify, and distribute this software
7 and its documentation for any purpose and without fee is hereby
8 granted, provided that the above copyright notice appear in all
9 copies and that both that the copyright notice and this
10 permission notice and warranty disclaimer appear in supporting
11 documentation, and that the name of the author not be used in
12 advertising or publicity pertaining to distribution of the
13 software without specific, written prior permission.
15 The author disclaim all warranties with regard to this
16 software, including all implied warranties of merchantability
17 and fitness. In no event shall the author be liable for any
18 special, indirect or consequential damages or any damages
19 whatsoever resulting from loss of use, data or profits, whether
20 in an action of contract, negligence or other tortious action,
21 arising out of or in connection with the use or performance of
22 this software.
25 #include "passwddlg.h"
26 #include "passwd.h"
28 #include <klocale.h>
29 #include <kmessagebox.h>
31 KDEpasswd1Dialog::KDEpasswd1Dialog()
32 : KPasswordDialog()
34 setCaption(i18n("Change Password"));
35 setPrompt(i18n("Please enter your current password:"));
39 KDEpasswd1Dialog::~KDEpasswd1Dialog()
43 void KDEpasswd1Dialog::accept()
45 PasswdProcess proc(0);
47 int ret = proc.checkCurrent(password().toLocal8Bit());
48 switch (ret)
50 case -1:
52 QString msg = QString::fromLocal8Bit(proc.error());
53 if (!msg.isEmpty())
54 msg = "<p>\"<i>" + msg + "</i>\"";
55 msg = "<qt>" + i18n("Conversation with 'passwd' failed.") + msg;
56 KMessageBox::error(this, msg);
57 done(Rejected);
58 return;
61 case 0:
62 return KPasswordDialog::accept();
64 case PasswdProcess::PasswdNotFound:
65 KMessageBox::error(this, i18n("Could not find the program 'passwd'."));
66 done(Rejected);
67 return;
69 case PasswdProcess::PasswordIncorrect:
70 KMessageBox::sorry(this, i18n("Incorrect password. Please try again."));
71 return;
73 default:
74 KMessageBox::error(this, i18n("Internal error: illegal return value "
75 "from PasswdProcess::checkCurrent."));
76 done(Rejected);
77 return;
82 // static
83 int KDEpasswd1Dialog::getPassword(QByteArray &password)
85 KDEpasswd1Dialog *dlg = new KDEpasswd1Dialog();
86 int res = dlg->exec();
87 if (res == Accepted)
88 password = dlg->password().toLocal8Bit();
89 delete dlg;
90 return res;
95 KDEpasswd2Dialog::KDEpasswd2Dialog(const char *oldpass, const QByteArray &user)
96 : KNewPasswordDialog()
98 m_Pass = oldpass;
99 m_User = user;
101 setCaption(i18n("Change Password"));
102 if (m_User.isEmpty())
103 setPrompt(i18n("Please enter your new password:"));
104 else
105 setPrompt(i18n("Please enter the new password for user <b>%1</b>:", QString::fromLocal8Bit(m_User)));
109 KDEpasswd2Dialog::~KDEpasswd2Dialog()
114 void KDEpasswd2Dialog::accept()
116 PasswdProcess proc(m_User);
118 QString p=password();
120 if (p.length() > 8)
122 switch(KMessageBox::warningYesNoCancel(this,
123 m_User.isEmpty() ?
124 i18n("Your password is longer than 8 characters. On some "
125 "systems, this can cause problems. You can truncate "
126 "the password to 8 characters, or leave it as it is.") :
127 i18n("The password is longer than 8 characters. On some "
128 "systems, this can cause problems. You can truncate "
129 "the password to 8 characters, or leave it as it is.")
131 i18n("Password Too Long"),
132 KGuiItem(i18n("Truncate")),
133 KGuiItem(i18n("Use as Is")),
134 KStandardGuiItem::cancel(),
135 "truncatePassword"))
137 case KMessageBox::Yes :
138 p=p.left(8);
139 break;
140 case KMessageBox::No :
141 break;
142 default : return;
146 int ret = proc.exec(m_Pass, p.toLocal8Bit());
147 switch (ret)
149 case 0:
151 hide();
152 QString msg = QString::fromLocal8Bit(proc.error());
153 if (!msg.isEmpty())
154 msg = "<p>\"<i>" + msg + "</i>\"";
155 msg = "<qt>" + i18n("Your password has been changed.") + msg;
156 KMessageBox::information(0L, msg);
157 return KNewPasswordDialog::accept();
160 case PasswdProcess::PasswordNotGood:
162 QString msg = QString::fromLocal8Bit(proc.error());
163 if (!msg.isEmpty())
164 msg = "<p>\"<i>" + msg + "</i>\"";
165 msg = "<qt>" + i18n("Your password has not been changed.") + msg;
167 // The pw change did not succeed. Print the error.
168 KMessageBox::sorry(this, msg);
169 return;
172 default:
173 QString msg = QString::fromLocal8Bit(proc.error());
174 if (!msg.isEmpty())
175 msg = "<p>\"<i>" + msg + "</i>\"";
176 msg = "<qt>" + i18n("Conversation with 'passwd' failed.") + msg;
177 KMessageBox::sorry(this, msg);
178 done(Rejected);
179 return;
182 return KNewPasswordDialog::accept();
187 #include "passwddlg.moc"