1
/* This file is part of the KDE libraries
2
Copyright (C) 2007 Olivier Goffart <ogoffart at kde.org>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License as published by the Free Software Foundation; either
7
version 2 of the License, or (at your option) any later version.
9
This library 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 GNU
12
Library General Public License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to
16
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
Boston, MA 02110-1301, USA.
20
#include <kaboutdata.h>
21
#include <kcmdlineargs.h>
22
#include <kapplication.h>
23
#include <kpassworddialog.h>
27
int main( int argc, char *argv[] )
29
//KLocale::setMainCatalog("kdelibs");
30
QApplication::setColorSpec( QApplication::CustomColor );
31
KAboutData about("KNewPasswordDialogTest", "KNewPasswordDialogTest", "1");
32
KCmdLineArgs::init(argc, argv, &about);
36
//step 1 simple password
38
KPasswordDialog dlg(0, KPasswordDialog::ShowKeepPassword);
39
dlg.setPrompt(i18n("Enter a password for the test"));
43
std::cout << "Entered password: " << (const char*)dlg.password().toAscii() << std::endl;
47
std::cout << "No password" << std::endl;
52
//step 2 readonly username
54
KPasswordDialog dlg(0, KPasswordDialog::ShowUsernameLine | KPasswordDialog::UsernameReadOnly);
55
dlg.setPrompt(i18n("Enter a password for the test"));
56
dlg.setUsername("konqui");
57
dlg.addCommentLine( i18n("Site") , i18n("http://www.kde.org") );
61
std::cout << "Entered password: " << (const char*)dlg.password().toAscii() << std::endl;
65
std::cout << "No password" << std::endl;
71
//step 3 with some username preset
73
KPasswordDialog dlg(0, KPasswordDialog::ShowUsernameLine);
74
dlg.setPrompt(i18n("Enter a password for the test"));
75
QMap<QString,QString> logins;
76
logins.insert("konqui" , "foo");
77
logins.insert("watson" , "bar");
78
logins.insert("ogoffart" , "");
80
dlg.setKnownLogins(logins);
84
std::cout << "Entered password: " << (const char*)dlg.password().toAscii() << " for username " << (const char*)dlg.username().toAscii() <<std::endl;
88
std::cout << "No password" << std::endl;