00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
#include "kmwother.h"
00021
#include "kmwizard.h"
00022
#include "kmprinter.h"
00023
#include "kmmanager.h"
00024
#include "cupsinfos.h"
00025
00026
#include <qlabel.h>
00027
#include <qlayout.h>
00028
#include <qlineedit.h>
00029
#include <qheader.h>
00030
#include <qdict.h>
00031
00032
#include <klocale.h>
00033
#include <klistview.h>
00034
#include <kiconloader.h>
00035
#include <kdebug.h>
00036
00037 KMWOther::KMWOther(
QWidget *parent,
const char *name)
00038 : KMWizardPage(parent,name)
00039 {
00040 m_ID = KMWizard::Custom+5;
00041 m_title = i18n(
"URI Selection");
00042 m_nextpage = KMWizard::Driver;
00043
00044 m_uri =
new QLineEdit(
this);
00045
QLabel *l1 =
new QLabel(
this);
00046 l1->setText(i18n(
"<p>Enter the URI corresponding to the printer to be installed. "
00047
"Examples:</p><ul>"
00048
"<li>smb://[login[:passwd]@]server/printer</li>"
00049
"<li>lpd://server/queue</li>"
00050
"<li>parallel:/dev/lp0</li></ul>"));
00051 QLabel *l2 =
new QLabel(i18n(
"URI:"),
this);
00052 m_uriview =
new KListView(
this );
00053 m_uriview->addColumn(
"" );
00054 m_uriview->header()->hide();
00055 m_uriview->setSorting( -1 );
00056 connect( m_uriview, SIGNAL( pressed(
QListViewItem* ) ), SLOT( slotPressed(
QListViewItem* ) ) );
00057
00058
QVBoxLayout *lay1 =
new QVBoxLayout(
this, 0, 15);
00059 QVBoxLayout *lay2 =
new QVBoxLayout(0, 0, 5);
00060 lay1->addWidget(l1);
00061 lay1->addLayout(lay2);
00062 lay1->addWidget( m_uriview );
00063 lay2->addWidget(l2);
00064 lay2->addWidget(m_uri);
00065 }
00066
00067
void KMWOther::initPrinter(KMPrinter *p)
00068 {
00069 m_uri->setText(p->device());
00070
00071
if ( m_uriview->childCount() == 0 )
00072 {
00073
QStringList l = KMManager::self()->detectLocalPrinters();
00074
if ( l.isEmpty() || l.count() % 4 != 0 )
00075
return;
00076
00077
QListViewItem *item = 0, *lastparent = 0, *root;
00078 root =
new QListViewItem( m_uriview, i18n(
"CUPS Server %1:%2" ).arg( CupsInfos::self()->host() ).arg( CupsInfos::self()->port() ) );
00079 root->setPixmap( 0, SmallIcon(
"gear" ) );
00080 root->setOpen(
true );
00081
QDict<QListViewItem> parents, last;
00082 parents.setAutoDelete(
false );
00083 last.setAutoDelete(
false );
00084
for ( QStringList::Iterator it=l.begin(); it!=l.end(); ++it )
00085 {
00086
QString cl = *it;
00087
QString uri = *( ++it );
00088
QString desc = *( ++it );
00089
QString prt = *( ++it );
00090
if ( !prt.isEmpty() )
00091 desc.append(
" [" + prt +
"]" );
00092 QListViewItem *parent = parents.find( cl );
00093
if ( !parent )
00094 {
00095 parent =
new QListViewItem( root, lastparent, cl );
00096 parent->setOpen(
true );
00097
if ( cl ==
"network" )
00098 parent->setPixmap( 0, SmallIcon(
"network" ) );
00099
else if ( cl ==
"direct" )
00100 parent->setPixmap( 0, SmallIcon(
"kdeprint_computer" ) );
00101
else if ( cl ==
"serial" )
00102 parent->setPixmap( 0, SmallIcon(
"usb" ) );
00103
else
00104 parent->setPixmap( 0, SmallIcon(
"package" ) );
00105 lastparent = parent;
00106 parents.insert( cl, parent );
00107 }
00108 item =
new QListViewItem( parent, last.find( cl ), desc, uri);
00109 last.insert( cl, item );
00110 }
00111 }
00112 }
00113
00114
void KMWOther::updatePrinter(KMPrinter *p)
00115 {
00116 p->setDevice( m_uri->text() );
00117 }
00118
00119
void KMWOther::slotPressed( QListViewItem *item )
00120 {
00121
if ( item && !item->text( 1 ).isEmpty() )
00122 m_uri->setText( item->text( 1 ) );
00123 }
00124
00125
#include "kmwother.moc"