22 #include "kmprinter.h"
23 #include "kmmanager.h"
24 #include "cupsinfos.h"
28 #include <tqlineedit.h>
32 #include <tdelocale.h>
33 #include <tdelistview.h>
34 #include <kiconloader.h>
37 KMWOther::KMWOther(TQWidget *parent,
const char *name)
38 : KMWizardPage(parent,name)
40 m_ID = KMWizard::Custom+5;
41 m_title = i18n(
"URI Selection");
42 m_nextpage = KMWizard::Driver;
44 m_uri =
new TQLineEdit(
this);
45 TQLabel *l1 =
new TQLabel(
this);
46 l1->setText(i18n(
"<p>Enter the URI corresponding to the printer to be installed. "
48 "<li>smb://[login[:passwd]@]server/printer</li>"
49 "<li>lpd://server/queue</li>"
50 "<li>parallel:/dev/lp0</li></ul>"));
51 TQLabel *l2 =
new TQLabel(i18n(
"URI:"),
this);
52 m_uriview =
new TDEListView(
this );
53 m_uriview->addColumn(
"" );
54 m_uriview->header()->hide();
55 m_uriview->setSorting( -1 );
56 connect( m_uriview, TQ_SIGNAL( pressed( TQListViewItem* ) ), TQ_SLOT( slotPressed( TQListViewItem* ) ) );
58 TQVBoxLayout *lay1 =
new TQVBoxLayout(
this, 0, 15);
59 TQVBoxLayout *lay2 =
new TQVBoxLayout(0, 0, 5);
61 lay1->addLayout(lay2);
62 lay1->addWidget( m_uriview );
64 lay2->addWidget(m_uri);
67 void KMWOther::initPrinter(KMPrinter *p)
69 m_uri->setText(p->device());
71 if ( m_uriview->childCount() == 0 )
73 TQStringList l = KMManager::self()->detectLocalPrinters();
74 if ( l.isEmpty() || l.count() % 4 != 0 )
77 TQListViewItem *item = 0, *lastparent = 0, *root;
78 root =
new TQListViewItem( m_uriview, i18n(
"CUPS Server %1:%2" ).arg( CupsInfos::self()->host() ).arg( CupsInfos::self()->port() ) );
79 root->setPixmap( 0, SmallIcon(
"gear" ) );
80 root->setOpen(
true );
81 TQDict<TQListViewItem> parents, last;
82 parents.setAutoDelete(
false );
83 last.setAutoDelete(
false );
84 for ( TQStringList::Iterator it=l.begin(); it!=l.end(); ++it )
87 TQString uri = *( ++it );
88 TQString desc = *( ++it );
89 TQString prt = *( ++it );
91 desc.append(
" [" + prt +
"]" );
92 TQListViewItem *parent = parents.find( cl );
95 parent =
new TQListViewItem( root, lastparent, cl );
96 parent->setOpen(
true );
97 if ( cl ==
"network" )
98 parent->setPixmap( 0, SmallIcon(
"network" ) );
99 else if ( cl ==
"direct" )
100 parent->setPixmap( 0, SmallIcon(
"tdeprint_computer" ) );
101 else if ( cl ==
"serial" )
102 parent->setPixmap( 0, SmallIcon(
"usb" ) );
104 parent->setPixmap( 0, SmallIcon(
"package" ) );
106 parents.insert( cl, parent );
108 item =
new TQListViewItem( parent, last.find( cl ), desc, uri);
109 last.insert( cl, item );
114 void KMWOther::updatePrinter(KMPrinter *p)
116 p->setDevice( m_uri->text() );
119 void KMWOther::slotPressed( TQListViewItem *item )
121 if ( item && !item->text( 1 ).isEmpty() )
122 m_uri->setText( item->text( 1 ) );
125 #include "kmwother.moc"