20#include "kmwbackend.h" 
   26#include <tqbuttongroup.h> 
   27#include <tqradiobutton.h> 
   28#include <tqwhatsthis.h> 
   32#include <kseparator.h> 
   36class TDERadioButton : 
public TQRadioButton
 
   39    TDERadioButton(
const TQString& txt, TQWidget *parent = 0, 
const char *name = 0);
 
   42TDERadioButton::TDERadioButton(
const TQString& txt, TQWidget *parent, 
const char *name)
 
   43: TQRadioButton(txt,parent,name)
 
   45    setCursor(KCursor::handCursor());
 
   50KMWBackend::KMWBackend(TQWidget *parent, 
const char *name)
 
   51: KMWizardPage(parent,name)
 
   53    m_ID = KMWizard::Backend;
 
   54    m_title = i18n(
"Backend Selection");
 
   56    m_buttons = 
new TQButtonGroup(
this);
 
   59    m_layout = 
new TQVBoxLayout(
this, 0, KDialog::spacingHint());
 
   60    m_layout->addStretch(1);
 
   64bool KMWBackend::isValid(TQString& msg)
 
   66    if (!m_buttons->selected())
 
   68        msg = i18n(
"You must select a backend.");
 
   74void KMWBackend::initPrinter(KMPrinter *p)
 
   76    TQString    s = p->option(
"kde-backend");
 
   83        s = p->deviceProtocol();
 
   85        if (s == 
"parallel" || s == 
"serial" || s == 
"usb") ID = KMWizard::Local;
 
   86        else if (s == 
"smb") ID = KMWizard::SMB;
 
   87        else if (s == 
"ipp" || s == 
"http") ID = KMWizard::IPP;
 
   88        else if (s == 
"lpd") ID = KMWizard::LPD;
 
   89        else if (s == 
"socket") ID = KMWizard::TCP;
 
   90        else if (s == 
"file") ID = KMWizard::File;
 
   91        else if (p->members().count() > 0) ID = KMWizard::Class;
 
   94    if (m_buttons->find(ID))
 
   95        m_buttons->setButton(ID);
 
   98void KMWBackend::updatePrinter(KMPrinter *p)
 
  100    int ID = m_buttons->id(m_buttons->selected());
 
  101    if (ID == KMWizard::Class) p->setType(KMPrinter::Class);
 
  102    else p->setType(KMPrinter::Printer);
 
  103    p->setOption(
"kde-backend",TQString::number(ID));
 
  104    TQString    s = m_buttons->selected()->text();
 
  105    s.replace(TQRegExp(
"&(?=\\w)"), TQString::fromLatin1(
""));
 
  106    p->setOption(
"kde-backend-description",s);
 
  107    setNextPage((m_map.contains(ID) ? m_map[ID] : KMWizard::Error));
 
  110void KMWBackend::addBackend( 
int ID, 
bool on, 
int nextpage )
 
  114        case KMWizard::Local:
 
  115            addBackend( ID, i18n(
"&Local printer (parallel, serial, USB)"), on,
 
  116                    i18n( 
"<qt><p>Locally-connected printer</p>" 
  117                          "<p>Use this for a printer connected " 
  118                          "to the computer via a parallel, serial or USB port.</p></qt>" ),
 
  122            addBackend( ID, i18n(
"&SMB shared printer (Windows)"), on,
 
  123                    i18n( 
"<qt><p>Shared Windows printer</p>" 
  124                          "<p>Use this for a printer installed " 
  125                          "on a Windows server and shared on the network using the SMB " 
  126                          "protocol (samba).</p></qt>" ),
 
  130            addBackend( ID, i18n(
"&Remote LPD queue"), on,
 
  131                    i18n( 
"<qt><p>Print queue on a remote LPD server</p>" 
  132                          "<p>Use this for a print queue " 
  133                          "existing on a remote machine running a LPD print server.</p></qt>" ),
 
  137            addBackend( ID, i18n(
"Ne&twork printer (TCP)"), on,
 
  138                    i18n( 
"<qt><p>Network TCP printer</p>" 
  139                          "<p>Use this for a network-enabled printer " 
  140                          "using TCP (usually on port 9100) as communication protocol. Most " 
  141                          "network printers can use this mode.</p></qt>" ),
 
  145            addBackend( ID, TQString::null, on, TQString::null, nextpage );
 
  148            kdError( 500 ) << 
"Non standard wizard page ID: " << ID << endl;
 
  152void KMWBackend::addBackend(
int ID, 
const TQString& txt, 
bool on, 
const TQString& whatsThis, 
int nextpage)
 
  156        KSeparator* sep = 
new KSeparator( KSeparator::HLine, 
this);
 
  157        m_layout->insertWidget(m_count, sep);
 
  161        TDERadioButton  *btn = 
new TDERadioButton(txt, 
this);
 
  163        if ( !whatsThis.isEmpty() )
 
  164            TQWhatsThis::add( btn, whatsThis );
 
  165        m_buttons->insert(btn, ID);
 
  166        m_map[ID] = (nextpage == -1 ? ID : nextpage);   
 
  167        m_layout->insertWidget(m_count, btn);
 
  172void KMWBackend::enableBackend(
int ID, 
bool on)
 
  174    TQButton    *btn = 
static_cast<TQButton*
>(m_buttons->find(ID));