From ce4a32fe52ef09d8f5ff1dd22c001110902b60a2 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kdeprint/cups/kmwother.cpp | 125 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 kdeprint/cups/kmwother.cpp (limited to 'kdeprint/cups/kmwother.cpp') diff --git a/kdeprint/cups/kmwother.cpp b/kdeprint/cups/kmwother.cpp new file mode 100644 index 000000000..034c88bb2 --- /dev/null +++ b/kdeprint/cups/kmwother.cpp @@ -0,0 +1,125 @@ +/* + * This file is part of the KDE libraries + * Copyright (c) 2001 Michael Goffioul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + **/ + +#include "kmwother.h" +#include "kmwizard.h" +#include "kmprinter.h" +#include "kmmanager.h" +#include "cupsinfos.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +KMWOther::KMWOther(QWidget *parent, const char *name) +: KMWizardPage(parent,name) +{ + m_ID = KMWizard::Custom+5; + m_title = i18n("URI Selection"); + m_nextpage = KMWizard::Driver; + + m_uri = new QLineEdit(this); + QLabel *l1 = new QLabel(this); + l1->setText(i18n("

Enter the URI corresponding to the printer to be installed. " + "Examples:

    " + "
  • smb://[login[:passwd]@]server/printer
  • " + "
  • lpd://server/queue
  • " + "
  • parallel:/dev/lp0
")); + QLabel *l2 = new QLabel(i18n("URI:"), this); + m_uriview = new KListView( this ); + m_uriview->addColumn( "" ); + m_uriview->header()->hide(); + m_uriview->setSorting( -1 ); + connect( m_uriview, SIGNAL( pressed( QListViewItem* ) ), SLOT( slotPressed( QListViewItem* ) ) ); + + QVBoxLayout *lay1 = new QVBoxLayout(this, 0, 15); + QVBoxLayout *lay2 = new QVBoxLayout(0, 0, 5); + lay1->addWidget(l1); + lay1->addLayout(lay2); + lay1->addWidget( m_uriview ); + lay2->addWidget(l2); + lay2->addWidget(m_uri); +} + +void KMWOther::initPrinter(KMPrinter *p) +{ + m_uri->setText(p->device()); + + if ( m_uriview->childCount() == 0 ) + { + QStringList l = KMManager::self()->detectLocalPrinters(); + if ( l.isEmpty() || l.count() % 4 != 0 ) + return; + + QListViewItem *item = 0, *lastparent = 0, *root; + root = new QListViewItem( m_uriview, i18n( "CUPS Server %1:%2" ).arg( CupsInfos::self()->host() ).arg( CupsInfos::self()->port() ) ); + root->setPixmap( 0, SmallIcon( "gear" ) ); + root->setOpen( true ); + QDict parents, last; + parents.setAutoDelete( false ); + last.setAutoDelete( false ); + for ( QStringList::Iterator it=l.begin(); it!=l.end(); ++it ) + { + QString cl = *it; + QString uri = *( ++it ); + QString desc = *( ++it ); + QString prt = *( ++it ); + if ( !prt.isEmpty() ) + desc.append( " [" + prt + "]" ); + QListViewItem *parent = parents.find( cl ); + if ( !parent ) + { + parent = new QListViewItem( root, lastparent, cl ); + parent->setOpen( true ); + if ( cl == "network" ) + parent->setPixmap( 0, SmallIcon( "network" ) ); + else if ( cl == "direct" ) + parent->setPixmap( 0, SmallIcon( "kdeprint_computer" ) ); + else if ( cl == "serial" ) + parent->setPixmap( 0, SmallIcon( "usb" ) ); + else + parent->setPixmap( 0, SmallIcon( "package" ) ); + lastparent = parent; + parents.insert( cl, parent ); + } + item = new QListViewItem( parent, last.find( cl ), desc, uri); + last.insert( cl, item ); + } + } +} + +void KMWOther::updatePrinter(KMPrinter *p) +{ + p->setDevice( m_uri->text() ); +} + +void KMWOther::slotPressed( QListViewItem *item ) +{ + if ( item && !item->text( 1 ).isEmpty() ) + m_uri->setText( item->text( 1 ) ); +} + +#include "kmwother.moc" -- cgit v1.2.1