22 #include "kmprinter.h"
23 #include "kmfactory.h"
24 #include "kmmanager.h"
26 #include <tdelocale.h>
28 #include <tqlineedit.h>
31 #include <tdelistview.h>
32 #include <tdemessagebox.h>
33 #include <kiconloader.h>
35 KMWLocal::KMWLocal(TQWidget *parent,
const char *name)
36 : KMWizardPage(parent,name)
38 m_title = i18n(
"Local Port Selection");
39 m_ID = KMWizard::Local;
40 m_nextpage = KMWizard::Driver;
41 m_initialized =
false;
44 m_ports =
new TDEListView(
this);
45 m_ports->setFrameStyle(TQFrame::WinPanel|TQFrame::Sunken);
46 m_ports->setLineWidth(1);
47 m_ports->header()->hide();
48 m_ports->addColumn(
"");
49 m_ports->setSorting(-1);
50 TQListViewItem *root =
new TQListViewItem(m_ports, i18n(
"Local System"));
51 root->setPixmap(0, SmallIcon(
"tdeprint_computer"));
53 connect(m_ports, TQ_SIGNAL(selectionChanged(TQListViewItem*)), TQ_SLOT(slotPortSelected(TQListViewItem*)));
54 TQLabel *l1 =
new TQLabel(i18n(
"URI:"),
this);
55 m_localuri =
new TQLineEdit(
this);
56 connect( m_localuri, TQ_SIGNAL( textChanged(
const TQString& ) ), TQ_SLOT( slotTextChanged(
const TQString& ) ) );
57 m_parents[0] =
new TQListViewItem(root, i18n(
"Parallel"));
58 m_parents[1] =
new TQListViewItem(root, m_parents[0], i18n(
"Serial"));
59 m_parents[2] =
new TQListViewItem(root, m_parents[1], i18n(
"USB"));
60 m_parents[3] =
new TQListViewItem(root, m_parents[2], i18n(
"Others"));
62 m_parents[i]->setPixmap(0, SmallIcon(
"preferences-desktop-peripherals"));
63 TQLabel *l2 =
new TQLabel(i18n(
"<p>Select a valid detected port, or enter directly the corresponding URI in the bottom edit field.</p>"),
this);
65 TQVBoxLayout *lay0 =
new TQVBoxLayout(
this, 0, 10);
66 TQHBoxLayout *lay1 =
new TQHBoxLayout(0, 0, 10);
67 lay0->addWidget(l2, 0);
68 lay0->addWidget(m_ports, 1);
69 lay0->addLayout(lay1, 0);
70 lay1->addWidget(l1, 0);
71 lay1->addWidget(m_localuri, 1);
74 bool KMWLocal::isValid(TQString& msg)
76 if (m_localuri->text().isEmpty())
78 msg = i18n(
"The URI is empty",
"Empty URI.");
81 else if (m_uris.findIndex(m_localuri->text()) == -1)
83 if (KMessageBox::warningContinueCancel(
this, i18n(
"The local URI doesn't correspond to a detected port. Continue?")) == KMessageBox::Cancel)
85 msg = i18n(
"Select a valid port.");
92 void KMWLocal::slotPortSelected(TQListViewItem *item)
98 if (!item || item->depth() <= 1 || item->depth() > 3)
100 else if (item->depth() == 3)
101 uri = item->parent()->text( 1 );
103 uri = item->text( 1 );
105 m_localuri->setText( uri );
109 void KMWLocal::updatePrinter(KMPrinter *printer)
111 TQListViewItem *item = m_ports->selectedItem();
112 if ( item && item->depth() == 3 )
113 printer->setOption(
"kde-autodetect", item->text( 0 ) );
114 printer->setDevice(m_localuri->text());
117 void KMWLocal::initPrinter(KMPrinter *printer)
124 m_localuri->setText(printer->device());
128 TQListViewItem* KMWLocal::lookForItem(
const TQString& uri )
130 for (
int i=0; i<4; i++ )
132 TQListViewItem *item = m_parents[ i ]->firstChild();
134 if ( item->text( 1 ) == uri )
135 if ( item->firstChild() )
136 return item->firstChild();
140 item = item->nextSibling();
145 void KMWLocal::slotTextChanged(
const TQString& txt )
150 TQListViewItem *item = lookForItem( txt );
154 m_ports->setSelected( item,
true );
158 m_ports->clearSelection();
161 void KMWLocal::initialize()
163 TQStringList list = KMFactory::self()->manager()->detectLocalPrinters();
164 if (list.isEmpty() || (list.count() % 4) != 0)
166 KMessageBox::error(
this, i18n(
"Unable to detect local ports."));
169 TQListViewItem *last[4] = {0, 0, 0, 0};
170 for (TQStringList::Iterator it=list.begin(); it!=list.end(); ++it)
176 int p = uri.find(
':' );
177 TQString desc = *(++it), prot = ( p != -1 ? uri.left( p ) : TQString::null );
178 TQString printer = *(++it);
182 if (prot ==
"parallel" || prot ==
"file")
184 else if (prot ==
"serial")
186 else if (prot ==
"usb")
188 else if (cl ==
"direct")
192 last[index] =
new TQListViewItem(m_parents[index], last[index], desc, uri);
193 last[index]->setPixmap(0, SmallIcon(
"blockdevice"));
194 m_parents[index]->setOpen(
true);
196 if (!printer.isEmpty())
198 TQListViewItem *pItem =
new TQListViewItem(last[index], printer);
199 last[index]->setOpen(
true);
200 pItem->setPixmap(0, SmallIcon(
"tdeprint_printer"));
203 m_initialized =
true;
206 #include "kmwlocal.moc"