# kdeprint Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# kmwpassword.cpp

    00001 /*
    00002  *  This file is part of the KDE libraries
    00003  *  Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
    00004  *
    00005  *  This library is free software; you can redistribute it and/or
    00006  *  modify it under the terms of the GNU Library General Public
    00007  *  License version 2 as published by the Free Software Foundation.
    00008  *
    00009  *  This library is distributed in the hope that it will be useful,
    00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00012  *  Library General Public License for more details.
    00013  *
    00014  *  You should have received a copy of the GNU Library General Public License
    00015  *  along with this library; see the file COPYING.LIB.  If not, write to
    00016  *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00017  *  Boston, MA 02111-1307, USA.
    00018  **/
    00019
    00020 #include "kmwpassword.h"
    00021 #include "kmwizard.h"
    00022 #include "kmprinter.h"
    00023
    00024 #include <qlabel.h>
    00025 #include <qlineedit.h>
    00026 #include <qvbuttongroup.h>
    00027 #include <qradiobutton.h>
    00028 #include <qlayout.h>
    00029 #include <klocale.h>
    00030 #include <kcursor.h>
    00031
    00032 #include <stdlib.h>
    00033
    00034 KMWPassword::KMWPassword(QWidget *parent, const char *name)
    00035 : KMWizardPage(parent,name)
    00036 {
    00037     m_title = i18n("User Identification");
    00038     m_ID = KMWizard::Password;
    00039     m_nextpage = KMWizard::SMB;
    00040
    00041     // create widgets
    00042     QLabel  *infotext_ = new QLabel(this);
    00043     infotext_->setText(i18n("<p>This backend may require a login/password to work properly. "
    00044                 "Select the type of access to use and fill in the login and password entries if needed.</p>"));
    00045     m_login = new QLineEdit(this);
    00046     m_login->setText(QString::fromLocal8Bit(getenv("USER")));
    00047     m_password = new QLineEdit(this);
    00048     m_password->setEchoMode(QLineEdit::Password);
    00049     QLabel  *loginlabel_ = new QLabel(i18n("&Login:"),this);
    00050     QLabel  *passwdlabel_ = new QLabel(i18n("&Password:"),this);
    00051     m_btngroup = new QVButtonGroup( this );
    00052     m_btngroup->setFrameStyle( QFrame::NoFrame );
    00053     QRadioButton *btn1 = new QRadioButton( i18n( "&Anonymous (no login/password)" ), m_btngroup );
    00054     QRadioButton *btn2 = new QRadioButton( i18n( "&Guest account (login=\"guest\")" ), m_btngroup );
    00055     QRadioButton *btn3 = new QRadioButton( i18n( "Nor&mal account" ), m_btngroup );
    00056     btn1->setCursor( KCursor::handCursor() );
    00057     btn2->setCursor( KCursor::handCursor() );
    00058     btn3->setCursor( KCursor::handCursor() );
    00059     m_btngroup->setButton( 0 );
    00060
    00061     loginlabel_->setBuddy(m_login);
    00062     passwdlabel_->setBuddy(m_password);
    00063
    00064     m_login->setEnabled(false);
    00065     m_password->setEnabled(false);
    00066     connect(btn3,SIGNAL(toggled(bool)),m_login,SLOT(setEnabled(bool)));
    00067     connect(btn3,SIGNAL(toggled(bool)),m_password,SLOT(setEnabled(bool)));
    00068
    00069     // layout
    00070     QVBoxLayout *main_ = new QVBoxLayout( this, 0, 0 );
    00071     main_->addWidget( infotext_ );
    00072     main_->addSpacing( 10 );
    00073     main_->addWidget( m_btngroup );
    00074     QGridLayout *l1 = new QGridLayout( 0, 2, 3 );
    00075     main_->addLayout( l1 );
    00076     main_->addStretch( 1 );
    00077     l1->setColSpacing( 0, 35 );
    00078     l1->setColStretch( 2, 1 );
    00079     l1->addWidget( loginlabel_, 0, 1 );
    00080     l1->addWidget( passwdlabel_, 1, 1 );
    00081     l1->addWidget( m_login, 0, 2 );
    00082     l1->addWidget( m_password, 1, 2 );
    00083 }
    00084
    00085 bool KMWPassword::isValid(QString& msg)
    00086 {
    00087     if ( !m_btngroup->selected() )
    00088         msg = i18n( "Select one option" );
    00089     else if (m_btngroup->selectedId() == 2 && m_login->text().isEmpty())
    00090         msg = i18n("User name is empty.");
    00091     else
    00092         return true;
    00093     return false;
    00094 }
    00095
    00096 void KMWPassword::initPrinter( KMPrinter* p )
    00097 {
    00098     /* guest account only for SMB backend */
    00099     if ( p->option( "kde-backend" ).toInt() != KMWizard::SMB )
    00100     {
    00101         int ID = m_btngroup->selectedId();
    00102         m_btngroup->find( 1 )->hide();
    00103         if ( ID == 1 )
    00104             m_btngroup->setButton( 0 );
    00105     }
    00106     else
    00107         m_btngroup->find( 1 )->show();
    00108 }
    00109
    00110 void KMWPassword::updatePrinter(KMPrinter *p)
    00111 {
    00112     QString s = p->option("kde-backend");
    00113     if (!s.isEmpty())
    00114         setNextPage(s.toInt());
    00115     else
    00116         setNextPage(KMWizard::Error);
    00117     switch ( m_btngroup->selectedId() )
    00118     {
    00119         case 0:
    00120             p->setOption( "kde-login", QString::null );
    00121             p->setOption( "kde-password", QString::null );
    00122             break;
    00123         case 1:
    00124             p->setOption( "kde-login", QString::fromLatin1( "guest" ) );
    00125             p->setOption( "kde-password", QString::null );
    00126             break;
    00127         case 2:
    00128             p->setOption( "kde-login", m_login->text() );
    00129             p->setOption( "kde-password", m_password->text() );
    00130             break;
    00131     }
    00132 }
    00133

This file is part of the documentation for kdeprint Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:31:03 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003