~ubuntu-branches/ubuntu/gutsy/kde4libs/gutsy

« back to all changes in this revision

Viewing changes to kdeui/tests/kpassworddialogtest.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-02-21 11:00:12 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070221110012-6kw8khr9knv6lmg1
Tags: 3.80.3-0ubuntu1
New upstream unstable release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE libraries
 
2
    Copyright (C) 2007 Olivier Goffart  <ogoffart at kde.org>
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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.
 
18
*/
 
19
 
 
20
#include <kaboutdata.h>
 
21
#include <kcmdlineargs.h>
 
22
#include <kapplication.h>
 
23
#include <kpassworddialog.h>
 
24
#include <klocale.h>
 
25
#include <iostream>
 
26
 
 
27
int main( int argc, char *argv[] )
 
28
{
 
29
        //KLocale::setMainCatalog("kdelibs");
 
30
        QApplication::setColorSpec( QApplication::CustomColor );
 
31
        KAboutData about("KNewPasswordDialogTest", "KNewPasswordDialogTest", "1");
 
32
        KCmdLineArgs::init(argc, argv, &about);
 
33
        
 
34
    KApplication a;
 
35
 
 
36
    //step 1  simple password
 
37
    {
 
38
        KPasswordDialog dlg(0, KPasswordDialog::ShowKeepPassword);
 
39
        dlg.setPrompt(i18n("Enter a password for the test"));
 
40
        
 
41
        if( dlg.exec() )
 
42
        {
 
43
            std::cout << "Entered password: " << (const char*)dlg.password().toAscii() << std::endl;
 
44
        }
 
45
        else
 
46
        {
 
47
            std::cout << "No password" << std::endl;
 
48
            return -1;
 
49
        }
 
50
    }
 
51
    
 
52
    //step 2 readonly username
 
53
    {
 
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") );
 
58
        
 
59
        if( dlg.exec() )
 
60
        {
 
61
            std::cout << "Entered password: " << (const char*)dlg.password().toAscii() << std::endl;
 
62
        }
 
63
        else
 
64
        {
 
65
            std::cout << "No password" << std::endl;
 
66
            return -1;
 
67
        }
 
68
    }
 
69
 
 
70
    
 
71
    //step 3 with some username preset
 
72
    {
 
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" , "");
 
79
        
 
80
        dlg.setKnownLogins(logins);
 
81
 
 
82
        if( dlg.exec() )
 
83
        {
 
84
            std::cout << "Entered password: " << (const char*)dlg.password().toAscii() << " for username " <<  (const  char*)dlg.username().toAscii() <<std::endl;
 
85
        }
 
86
        else
 
87
        {
 
88
            std::cout << "No password" << std::endl;
 
89
            return -1;
 
90
        }
 
91
    }
 
92
 
 
93
    
 
94
    return 0;
 
95
    
 
96
    
 
97
 
 
98
}
 
99