• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeprint
 

tdeprint

  • tdeprint
  • management
kmwlocal.cpp
1/*
2 * This file is part of the KDE libraries
3 * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License version 2 as published by the Free Software Foundation.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 **/
19
20#include "kmwlocal.h"
21#include "kmwizard.h"
22#include "kmprinter.h"
23#include "kmfactory.h"
24#include "kmmanager.h"
25
26#include <tdelocale.h>
27#include <tqlayout.h>
28#include <tqlineedit.h>
29#include <tqlabel.h>
30#include <tqheader.h>
31#include <tdelistview.h>
32#include <tdemessagebox.h>
33#include <kiconloader.h>
34
35KMWLocal::KMWLocal(TQWidget *parent, const char *name)
36: KMWizardPage(parent,name)
37{
38 m_title = i18n("Local Port Selection");
39 m_ID = KMWizard::Local;
40 m_nextpage = KMWizard::Driver;
41 m_initialized = false;
42 m_block = false;
43
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"));
52 root->setOpen(true);
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"));
61 for (int i=0;i<4;i++)
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);
64
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);
72}
73
74bool KMWLocal::isValid(TQString& msg)
75{
76 if (m_localuri->text().isEmpty())
77 {
78 msg = i18n("The URI is empty","Empty URI.");
79 return false;
80 }
81 else if (m_uris.findIndex(m_localuri->text()) == -1)
82 {
83 if (KMessageBox::warningContinueCancel(this, i18n("The local URI doesn't correspond to a detected port. Continue?")) == KMessageBox::Cancel)
84 {
85 msg = i18n("Select a valid port.");
86 return false;
87 }
88 }
89 return true;
90}
91
92void KMWLocal::slotPortSelected(TQListViewItem *item)
93{
94 if ( m_block )
95 return;
96
97 TQString uri;
98 if (!item || item->depth() <= 1 || item->depth() > 3)
99 uri = TQString::null;
100 else if (item->depth() == 3)
101 uri = item->parent()->text( 1 );
102 else
103 uri = item->text( 1 );
104 m_block = true;
105 m_localuri->setText( uri );
106 m_block = false;
107}
108
109void KMWLocal::updatePrinter(KMPrinter *printer)
110{
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());
115}
116
117void KMWLocal::initPrinter(KMPrinter *printer)
118{
119 if (!m_initialized)
120 initialize();
121
122 if (printer)
123 {
124 m_localuri->setText(printer->device());
125 }
126}
127
128TQListViewItem* KMWLocal::lookForItem( const TQString& uri )
129{
130 for ( int i=0; i<4; i++ )
131 {
132 TQListViewItem *item = m_parents[ i ]->firstChild();
133 while ( item )
134 if ( item->text( 1 ) == uri )
135 if ( item->firstChild() )
136 return item->firstChild();
137 else
138 return item;
139 else
140 item = item->nextSibling();
141 }
142 return 0;
143}
144
145void KMWLocal::slotTextChanged( const TQString& txt )
146{
147 if ( m_block )
148 return;
149
150 TQListViewItem *item = lookForItem( txt );
151 if ( item )
152 {
153 m_block = true;
154 m_ports->setSelected( item, true );
155 m_block = false;
156 }
157 else
158 m_ports->clearSelection();
159}
160
161void KMWLocal::initialize()
162{
163 TQStringList list = KMFactory::self()->manager()->detectLocalPrinters();
164 if (list.isEmpty() || (list.count() % 4) != 0)
165 {
166 KMessageBox::error(this, i18n("Unable to detect local ports."));
167 return;
168 }
169 TQListViewItem *last[4] = {0, 0, 0, 0};
170 for (TQStringList::Iterator it=list.begin(); it!=list.end(); ++it)
171 {
172 TQString cl = *it;
173 ++it;
174
175 TQString uri = *it;
176 int p = uri.find( ':' );
177 TQString desc = *(++it), prot = ( p != -1 ? uri.left( p ) : TQString::null );
178 TQString printer = *(++it);
179 int index(-1);
180 if (desc.isEmpty())
181 desc = uri;
182 if (prot == "parallel" || prot == "file")
183 index = 0;
184 else if (prot == "serial")
185 index = 1;
186 else if (prot == "usb")
187 index = 2;
188 else if (cl == "direct")
189 index = 3;
190 else
191 continue;
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);
195 m_uris << uri;
196 if (!printer.isEmpty())
197 {
198 TQListViewItem *pItem = new TQListViewItem(last[index], printer);
199 last[index]->setOpen(true);
200 pItem->setPixmap(0, SmallIcon("tdeprint_printer"));
201 }
202 }
203 m_initialized = true;
204}
205
206#include "kmwlocal.moc"

tdeprint

Skip menu "tdeprint"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeprint

Skip menu "tdeprint"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeprint by doxygen 1.9.4
This website is maintained by Timothy Pearson.