You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
178 lines
5.2 KiB
178 lines
5.2 KiB
15 years ago
|
/*
|
||
|
* This file is part of the KDE libraries
|
||
13 years ago
|
* Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
|
||
15 years ago
|
*
|
||
|
* 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 "kmwbackend.h"
|
||
|
#include "kmwizard.h"
|
||
|
#include "kmprinter.h"
|
||
|
|
||
14 years ago
|
#include <tqlayout.h>
|
||
|
#include <tqregexp.h>
|
||
|
#include <tqbuttongroup.h>
|
||
|
#include <tqradiobutton.h>
|
||
|
#include <tqwhatsthis.h>
|
||
15 years ago
|
|
||
|
#include <kcursor.h>
|
||
|
#include <klocale.h>
|
||
|
#include <kseparator.h>
|
||
|
#include <kdialog.h>
|
||
|
#include <kdebug.h>
|
||
|
|
||
14 years ago
|
class KRadioButton : public TQRadioButton
|
||
15 years ago
|
{
|
||
|
public:
|
||
14 years ago
|
KRadioButton(const TQString& txt, TQWidget *parent = 0, const char *name = 0);
|
||
15 years ago
|
};
|
||
|
|
||
14 years ago
|
KRadioButton::KRadioButton(const TQString& txt, TQWidget *parent, const char *name)
|
||
|
: TQRadioButton(txt,parent,name)
|
||
15 years ago
|
{
|
||
|
setCursor(KCursor::handCursor());
|
||
|
}
|
||
|
|
||
|
//********************************************************************************************************
|
||
|
|
||
14 years ago
|
KMWBackend::KMWBackend(TQWidget *parent, const char *name)
|
||
15 years ago
|
: KMWizardPage(parent,name)
|
||
|
{
|
||
|
m_ID = KMWizard::Backend;
|
||
|
m_title = i18n("Backend Selection");
|
||
|
|
||
14 years ago
|
m_buttons = new TQButtonGroup(this);
|
||
15 years ago
|
m_buttons->hide();
|
||
|
|
||
14 years ago
|
m_layout = new TQVBoxLayout(this, 0, KDialog::spacingHint());
|
||
|
m_layout->addStretch(1);
|
||
15 years ago
|
m_count = 0;
|
||
|
}
|
||
|
|
||
14 years ago
|
bool KMWBackend::isValid(TQString& msg)
|
||
15 years ago
|
{
|
||
|
if (!m_buttons->selected())
|
||
|
{
|
||
|
msg = i18n("You must select a backend.");
|
||
|
return false;
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
void KMWBackend::initPrinter(KMPrinter *p)
|
||
|
{
|
||
14 years ago
|
TQString s = p->option("kde-backend");
|
||
15 years ago
|
int ID(-1);
|
||
|
|
||
|
if (!s.isEmpty())
|
||
|
ID = s.toInt();
|
||
|
else
|
||
|
{
|
||
|
s = p->deviceProtocol();
|
||
|
// extract protocol
|
||
|
if (s == "parallel" || s == "serial" || s == "usb") ID = KMWizard::Local;
|
||
|
else if (s == "smb") ID = KMWizard::SMB;
|
||
|
else if (s == "ipp" || s == "http") ID = KMWizard::IPP;
|
||
|
else if (s == "lpd") ID = KMWizard::LPD;
|
||
|
else if (s == "socket") ID = KMWizard::TCP;
|
||
|
else if (s == "file") ID = KMWizard::File;
|
||
|
else if (p->members().count() > 0) ID = KMWizard::Class;
|
||
|
}
|
||
|
|
||
14 years ago
|
if (m_buttons->find(ID))
|
||
15 years ago
|
m_buttons->setButton(ID);
|
||
|
}
|
||
|
|
||
|
void KMWBackend::updatePrinter(KMPrinter *p)
|
||
|
{
|
||
|
int ID = m_buttons->id(m_buttons->selected());
|
||
|
if (ID == KMWizard::Class) p->setType(KMPrinter::Class);
|
||
|
else p->setType(KMPrinter::Printer);
|
||
14 years ago
|
p->setOption("kde-backend",TQString::number(ID));
|
||
14 years ago
|
TQString s = m_buttons->selected()->text();
|
||
14 years ago
|
s.replace(TQRegExp("&(?=\\w)"), TQString::tqfromLatin1(""));
|
||
15 years ago
|
p->setOption("kde-backend-description",s);
|
||
13 years ago
|
setNextPage((m_map.contains(ID) ? m_map[ID] : KMWizard::Error));
|
||
15 years ago
|
}
|
||
|
|
||
|
void KMWBackend::addBackend( int ID, bool on, int nextpage )
|
||
|
{
|
||
|
switch ( ID )
|
||
|
{
|
||
|
case KMWizard::Local:
|
||
|
addBackend( ID, i18n("&Local printer (parallel, serial, USB)"), on,
|
||
|
i18n( "<qt><p>Locally-connected printer</p>"
|
||
|
"<p>Use this for a printer connected "
|
||
|
"to the computer via a parallel, serial or USB port.</p></qt>" ),
|
||
|
nextpage );
|
||
|
break;
|
||
|
case KMWizard::SMB:
|
||
|
addBackend( ID, i18n("&SMB shared printer (Windows)"), on,
|
||
|
i18n( "<qt><p>Shared Windows printer</p>"
|
||
|
"<p>Use this for a printer installed "
|
||
|
"on a Windows server and shared on the network using the SMB "
|
||
|
"protocol (samba).</p></qt>" ),
|
||
|
nextpage );
|
||
|
break;
|
||
|
case KMWizard::LPD:
|
||
|
addBackend( ID, i18n("&Remote LPD queue"), on,
|
||
|
i18n( "<qt><p>Print queue on a remote LPD server</p>"
|
||
|
"<p>Use this for a print queue "
|
||
|
"existing on a remote machine running a LPD print server.</p></qt>" ),
|
||
|
nextpage );
|
||
|
break;
|
||
|
case KMWizard::TCP:
|
||
|
addBackend( ID, i18n("Ne&twork printer (TCP)"), on,
|
||
|
i18n( "<qt><p>Network TCP printer</p>"
|
||
|
"<p>Use this for a network-enabled printer "
|
||
|
"using TCP (usually on port 9100) as communication protocol. Most "
|
||
|
"network printers can use this mode.</p></qt>" ),
|
||
|
nextpage );
|
||
|
break;
|
||
|
case -1:
|
||
14 years ago
|
addBackend( ID, TQString::null, on, TQString::null, nextpage );
|
||
15 years ago
|
break;
|
||
|
default:
|
||
|
kdError( 500 ) << "Non standard wizard page ID: " << ID << endl;
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
void KMWBackend::addBackend(int ID, const TQString& txt, bool on, const TQString& whatsThis, int nextpage)
|
||
15 years ago
|
{
|
||
|
if (ID == -1)
|
||
|
{
|
||
|
KSeparator* sep = new KSeparator( KSeparator::HLine, this);
|
||
14 years ago
|
m_layout->insertWidget(m_count, sep);
|
||
15 years ago
|
}
|
||
|
else
|
||
|
{
|
||
|
KRadioButton *btn = new KRadioButton(txt, this);
|
||
|
btn->setEnabled(on);
|
||
|
if ( !whatsThis.isEmpty() )
|
||
14 years ago
|
TQWhatsThis::add( btn, whatsThis );
|
||
15 years ago
|
m_buttons->insert(btn, ID);
|
||
|
m_map[ID] = (nextpage == -1 ? ID : nextpage); // use nextpage if specified, default to ID
|
||
14 years ago
|
m_layout->insertWidget(m_count, btn);
|
||
15 years ago
|
}
|
||
|
m_count++;
|
||
|
}
|
||
|
|
||
|
void KMWBackend::enableBackend(int ID, bool on)
|
||
|
{
|
||
14 years ago
|
TQButton *btn = static_cast<TQButton*>(m_buttons->find(ID));
|
||
15 years ago
|
if (btn)
|
||
|
btn->setEnabled(on);
|
||
|
}
|