00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
#include "kmwbackend.h"
00021
#include "kmwizard.h"
00022
#include "kmprinter.h"
00023
00024
#include <qlayout.h>
00025
#include <qregexp.h>
00026
#include <qbuttongroup.h>
00027
#include <qradiobutton.h>
00028
#include <qwhatsthis.h>
00029
00030
#include <kcursor.h>
00031
#include <klocale.h>
00032
#include <kseparator.h>
00033
#include <kdialog.h>
00034
#include <kdebug.h>
00035
00036
class KRadioButton :
public QRadioButton
00037 {
00038
public:
00039 KRadioButton(
const QString& txt,
QWidget *parent = 0,
const char *name = 0);
00040 };
00041
00042 KRadioButton::KRadioButton(
const QString& txt,
QWidget *parent,
const char *name)
00043 :
QRadioButton(txt,parent,name)
00044 {
00045 setCursor(KCursor::handCursor());
00046 }
00047
00048
00049
00050 KMWBackend::KMWBackend(
QWidget *parent,
const char *name)
00051 : KMWizardPage(parent,name)
00052 {
00053 m_ID = KMWizard::Backend;
00054 m_title = i18n(
"Backend Selection");
00055
00056 m_buttons =
new QButtonGroup(
this);
00057 m_buttons->hide();
00058
00059 m_layout =
new QVBoxLayout(
this, 0, KDialog::spacingHint());
00060 m_layout->addStretch(1);
00061 m_count = 0;
00062 }
00063
00064
bool KMWBackend::isValid(
QString& msg)
00065 {
00066
if (!m_buttons->selected())
00067 {
00068 msg = i18n(
"You must select a backend.");
00069
return false;
00070 }
00071
return true;
00072 }
00073
00074
void KMWBackend::initPrinter(KMPrinter *p)
00075 {
00076
QString s = p->option(
"kde-backend");
00077
int ID(-1);
00078
00079
if (!s.isEmpty())
00080 ID = s.toInt();
00081
else
00082 {
00083 s = p->deviceProtocol();
00084
00085
if (s ==
"parallel" || s ==
"serial" || s ==
"usb") ID = KMWizard::Local;
00086
else if (s ==
"smb") ID = KMWizard::SMB;
00087
else if (s ==
"ipp" || s ==
"http") ID = KMWizard::IPP;
00088
else if (s ==
"lpd") ID = KMWizard::LPD;
00089
else if (s ==
"socket") ID = KMWizard::TCP;
00090
else if (s ==
"file") ID = KMWizard::File;
00091
else if (p->members().count() > 0) ID = KMWizard::Class;
00092 }
00093
00094
if (m_buttons->find(ID))
00095 m_buttons->setButton(ID);
00096 }
00097
00098
void KMWBackend::updatePrinter(KMPrinter *p)
00099 {
00100
int ID = m_buttons->id(m_buttons->selected());
00101
if (ID == KMWizard::Class) p->setType(KMPrinter::Class);
00102
else p->setType(KMPrinter::Printer);
00103 p->setOption(
"kde-backend",QString::number(ID));
00104
QString s = m_buttons->selected()->text();
00105 s.replace(
QRegExp(
"&(?=\\w)"), QString::fromLatin1(
""));
00106 p->setOption(
"kde-backend-description",s);
00107 setNextPage((m_map.contains(ID) ? m_map[ID] : KMWizard::Error));
00108 }
00109
00110
void KMWBackend::addBackend(
int ID,
bool on,
int nextpage )
00111 {
00112
switch ( ID )
00113 {
00114
case KMWizard::Local:
00115 addBackend( ID, i18n(
"&Local printer (parallel, serial, USB)"), on,
00116 i18n(
"<qt><p>Locally-connected printer</p>"
00117
"<p>Use this for a printer connected "
00118
"to the computer via a parallel, serial or USB port.</p></qt>" ),
00119 nextpage );
00120
break;
00121
case KMWizard::SMB:
00122 addBackend( ID, i18n(
"&SMB shared printer (Windows)"), on,
00123 i18n(
"<qt><p>Shared Windows printer</p>"
00124
"<p>Use this for a printer installed "
00125
"on a Windows server and shared on the network using the SMB "
00126
"protocol (samba).</p></qt>" ),
00127 nextpage );
00128
break;
00129
case KMWizard::LPD:
00130 addBackend( ID, i18n(
"&Remote LPD queue"), on,
00131 i18n(
"<qt><p>Print queue on a remote LPD server</p>"
00132
"<p>Use this for a print queue "
00133
"existing on a remote machine running a LPD print server.</p></qt>" ),
00134 nextpage );
00135
break;
00136
case KMWizard::TCP:
00137 addBackend( ID, i18n(
"Ne&twork printer (TCP)"), on,
00138 i18n(
"<qt><p>Network TCP printer</p>"
00139
"<p>Use this for a network-enabled printer "
00140
"using TCP (usually on port 9100) as communication protocol. Most "
00141
"network printers can use this mode.</p></qt>" ),
00142 nextpage );
00143
break;
00144
case -1:
00145 addBackend( ID, QString::null, on, QString::null, nextpage );
00146
break;
00147
default:
00148 kdError( 500 ) <<
"Non standard wizard page ID: " << ID << endl;
00149 }
00150 }
00151
00152
void KMWBackend::addBackend(
int ID,
const QString& txt,
bool on,
const QString& whatsThis,
int nextpage)
00153 {
00154
if (ID == -1)
00155 {
00156 KSeparator* sep =
new KSeparator( KSeparator::HLine,
this);
00157 m_layout->insertWidget(m_count, sep);
00158 }
00159
else
00160 {
00161 KRadioButton *btn =
new KRadioButton(txt,
this);
00162 btn->setEnabled(on);
00163
if ( !whatsThis.isEmpty() )
00164 QWhatsThis::add( btn, whatsThis );
00165 m_buttons->insert(btn, ID);
00166 m_map[ID] = (nextpage == -1 ? ID : nextpage);
00167 m_layout->insertWidget(m_count, btn);
00168 }
00169 m_count++;
00170 }
00171
00172
void KMWBackend::enableBackend(
int ID,
bool on)
00173 {
00174
QButton *btn = m_buttons->find(ID);
00175
if (btn)
00176 btn->setEnabled(on);
00177 }