kdeprint Library API Documentation

kmwpassword.cpp

00001 /*
00002  *  This file is part of the KDE libraries
00003  *  Copyright (c) 2001 Michael Goffioul <goffioul@imec.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 <qcheckbox.h>
00027 #include <qlayout.h>
00028 #include <klocale.h>
00029 #include <kcursor.h>
00030 
00031 #include <stdlib.h>
00032 
00033 KMWPassword::KMWPassword(QWidget *parent, const char *name)
00034 : KMWizardPage(parent,name)
00035 {
00036     m_title = i18n("User Identification");
00037     m_ID = KMWizard::Password;
00038     m_nextpage = KMWizard::SMB;
00039 
00040     // create widgets
00041     QLabel  *infotext_ = new QLabel(this);
00042     infotext_->setText(i18n("<p>This backend may require a login/password to work properly. "
00043                 "Fill in the required entries or enable <b>Guest account</b> to "
00044                 "use anonymous access.</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_guest = new QCheckBox(i18n("&Guest account"),this);
00052     m_guest->setCursor(KCursor::handCursor());
00053 
00054     loginlabel_->setBuddy(m_login);
00055     passwdlabel_->setBuddy(m_password);
00056 
00057     m_guest->setChecked(true);
00058     m_login->setEnabled(false);
00059     m_password->setEnabled(false);
00060     connect(m_guest,SIGNAL(toggled(bool)),m_login,SLOT(setDisabled(bool)));
00061     connect(m_guest,SIGNAL(toggled(bool)),m_password,SLOT(setDisabled(bool)));
00062 
00063     // layout
00064     QGridLayout *main_ = new QGridLayout(this, 7, 2, 0, 5);
00065     main_->setRowStretch(6,1);
00066     main_->setColStretch(1,1);
00067     main_->addRowSpacing(1,20);
00068     main_->addRowSpacing(4,20);
00069     main_->addMultiCellWidget(infotext_, 0, 0, 0, 1);
00070     main_->addWidget(loginlabel_, 2, 0);
00071     main_->addWidget(passwdlabel_, 3, 0);
00072     main_->addWidget(m_login, 2, 1);
00073     main_->addWidget(m_password, 3, 1);
00074     main_->addMultiCellWidget(m_guest, 5, 5, 0, 1);
00075 }
00076 
00077 bool KMWPassword::isValid(QString& msg)
00078 {
00079     if (!m_guest->isChecked() && m_login->text().isEmpty())
00080     {
00081         msg = i18n("User name is empty!");
00082         return false;
00083     }
00084     return true;
00085 }
00086 
00087 void KMWPassword::updatePrinter(KMPrinter *p)
00088 {
00089     QString s = p->option("kde-backend");
00090     if (!s.isEmpty()) setNextPage(s.toInt());
00091     else setNextPage(KMWizard::Error);
00092     if (m_guest->isChecked())
00093     {
00094         p->setOption("kde-login",QString::null);
00095         p->setOption("kde-password",QString::null);
00096     }
00097     else
00098     {
00099         p->setOption("kde-login",m_login->text());
00100         p->setOption("kde-password",m_password->text());
00101     }
00102 }
00103 
KDE Logo
This file is part of the documentation for kdeprint Library Version 3.2.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Feb 4 12:36:23 2004 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2003