kmwsmb.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., 51 Franklin Street, Fifth Floor,
00017  *  Boston, MA 02110-1301, USA.
00018  **/
00019 
00020 #include "kmwsmb.h"
00021 #include "kmwizard.h"
00022 #include "smbview.h"
00023 #include "kmprinter.h"
00024 #include "util.h"
00025 
00026 #include <klocale.h>
00027 #include <kpushbutton.h>
00028 #include <qlayout.h>
00029 #include <qlineedit.h>
00030 #include <qlabel.h>
00031 
00032 KMWSmb::KMWSmb(QWidget *parent, const char *name)
00033 : KMWizardPage(parent,name)
00034 {
00035     m_title = i18n("SMB Printer Settings");
00036     m_ID = KMWizard::SMB;
00037     m_nextpage = KMWizard::Driver;
00038 
00039     m_view = new SmbView(this,"SmbView");
00040     m_loginlabel = new QLabel( this );
00041     QPushButton *m_scan = new KPushButton(KGuiItem(i18n("Scan"), "viewmag"), this);
00042     QPushButton *m_abort = new KPushButton(KGuiItem(i18n("Abort"), "stop"), this);
00043     m_abort->setEnabled(false);
00044     QLabel      *m_worklabel = new QLabel(i18n("Workgroup:"), this);
00045     QLabel      *m_serverlabel = new QLabel(i18n("Server:"), this);
00046     QLabel      *m_printerlabel = new QLabel(i18n("Printer:"), this);
00047     m_work = new QLineEdit(this);
00048     m_server = new QLineEdit(this);
00049     m_printer = new QLineEdit(this);
00050 
00051     QVBoxLayout *lay0 = new QVBoxLayout(this, 0, 10);
00052     QGridLayout *lay1 = new QGridLayout(0, 3, 2, 0, 10);
00053     QHBoxLayout *lay3 = new QHBoxLayout(0, 0, 10);
00054     lay0->addLayout(lay1,0);
00055     lay0->addWidget(m_view,1);
00056     lay0->addLayout(lay3,0);
00057     lay0->addSpacing(10);
00058     lay1->setColStretch(1,1);
00059     lay1->addWidget(m_worklabel,0,0);
00060     lay1->addWidget(m_serverlabel,1,0);
00061     lay1->addWidget(m_printerlabel,2,0);
00062     lay1->addWidget(m_work,0,1);
00063     lay1->addWidget(m_server,1,1);
00064     lay1->addWidget(m_printer,2,1);
00065     lay3->addWidget( m_loginlabel );
00066     lay3->addStretch(1);
00067     lay3->addWidget(m_scan);
00068     lay3->addWidget(m_abort);
00069 
00070     connect(m_scan,SIGNAL(clicked()),SLOT(slotScan()));
00071     connect(m_abort,SIGNAL(clicked()),SLOT(slotAbort()));
00072     connect(m_view,SIGNAL(printerSelected(const QString&,const QString&,const QString&)),SLOT(slotPrinterSelected(const QString&,const QString&,const QString&)));
00073     connect(m_view,SIGNAL(running(bool)),m_abort,SLOT(setEnabled(bool)));
00074 }
00075 
00076 bool KMWSmb::isValid(QString& msg)
00077 {
00078     if (m_server->text().isEmpty())
00079         msg = i18n("Empty server name.");
00080     else if (m_printer->text().isEmpty())
00081         msg = i18n("Empty printer name.");
00082     else
00083         return true;
00084     return false;
00085 }
00086 
00087 void KMWSmb::updatePrinter(KMPrinter *printer)
00088 {
00089     QString uri = buildSmbURI( m_work->text(), m_server->text(), m_printer->text(), printer->option( "kde-login" ), printer->option( "kde-password" ) );
00090     printer->setDevice( uri );
00091 }
00092 
00093 void KMWSmb::initPrinter(KMPrinter *printer)
00094 {
00095     if (printer)
00096     {
00097         QString login = printer->option( "kde-login" );
00098         m_view->setLoginInfos(login,printer->option("kde-password"));
00099         m_loginlabel->setText( i18n( "Login: %1" ).arg( login.isEmpty() ? i18n( "<anonymous>" ) : login ) );
00100     }
00101 }
00102 
00103 void KMWSmb::slotScan()
00104 {
00105     m_view->init();
00106 }
00107 
00108 void KMWSmb::slotAbort()
00109 {
00110     m_view->abort();
00111 }
00112 
00113 void KMWSmb::slotPrinterSelected(const QString& work, const QString& server, const QString& printer)
00114 {
00115     m_work->setText(work);
00116     m_server->setText(server);
00117     m_printer->setText(printer);
00118 }
00119 #include "kmwsmb.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys