00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
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     QPushButton *m_scan = new KPushButton(KGuiItem(i18n("Scan"), "viewmag"), this);
00041     QPushButton *m_abort = new KPushButton(KGuiItem(i18n("Abort"), "stop"), this);
00042     m_abort->setEnabled(false);
00043     QLabel      *m_worklabel = new QLabel(i18n("Workgroup:"), this);
00044     QLabel      *m_serverlabel = new QLabel(i18n("Server:"), this);
00045     QLabel      *m_printerlabel = new QLabel(i18n("Printer:"), this);
00046     m_work = new QLineEdit(this);
00047     m_server = new QLineEdit(this);
00048     m_printer = new QLineEdit(this);
00049 
00050     QVBoxLayout *lay0 = new QVBoxLayout(this, 0, 10);
00051     QGridLayout *lay1 = new QGridLayout(0, 3, 2, 0, 10);
00052     QHBoxLayout *lay3 = new QHBoxLayout(0, 0, 10);
00053     lay0->addLayout(lay1,0);
00054     lay0->addWidget(m_view,1);
00055     lay0->addLayout(lay3,0);
00056     lay0->addSpacing(10);
00057     lay1->setColStretch(1,1);
00058     lay1->addWidget(m_worklabel,0,0);
00059     lay1->addWidget(m_serverlabel,1,0);
00060     lay1->addWidget(m_printerlabel,2,0);
00061     lay1->addWidget(m_work,0,1);
00062     lay1->addWidget(m_server,1,1);
00063     lay1->addWidget(m_printer,2,1);
00064     lay3->addStretch(1);
00065     lay3->addWidget(m_scan);
00066     lay3->addWidget(m_abort);
00067 
00068     connect(m_scan,SIGNAL(clicked()),SLOT(slotScan()));
00069     connect(m_abort,SIGNAL(clicked()),SLOT(slotAbort()));
00070     connect(m_view,SIGNAL(printerSelected(const QString&,const QString&,const QString&)),SLOT(slotPrinterSelected(const QString&,const QString&,const QString&)));
00071     connect(m_view,SIGNAL(running(bool)),m_abort,SLOT(setEnabled(bool)));
00072 }
00073 
00074 bool KMWSmb::isValid(QString& msg)
00075 {
00076     if (m_server->text().isEmpty())
00077         msg = i18n("Empty server name.");
00078     else if (m_printer->text().isEmpty())
00079         msg = i18n("Empty printer name.");
00080     else
00081         return true;
00082     return false;
00083 }
00084 
00085 void KMWSmb::updatePrinter(KMPrinter *printer)
00086 {
00087     QString uri = buildSmbURI( m_work->text(), m_server->text(), m_printer->text(), printer->option( "kde-login" ), printer->option( "kde-password" ) );
00088     printer->setDevice( uri );
00089 }
00090 
00091 void KMWSmb::initPrinter(KMPrinter *printer)
00092 {
00093     if (printer)
00094     {
00095         m_view->setLoginInfos(printer->option("kde-login"),printer->option("kde-password"));
00096     }
00097 }
00098 
00099 void KMWSmb::slotScan()
00100 {
00101     m_view->init();
00102 }
00103 
00104 void KMWSmb::slotAbort()
00105 {
00106     m_view->abort();
00107 }
00108 
00109 void KMWSmb::slotPrinterSelected(const QString& work, const QString& server, const QString& printer)
00110 {
00111     m_work->setText(work);
00112     m_server->setText(server);
00113     m_printer->setText(printer);
00114 }
00115 #include "kmwsmb.moc"