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
00029
#include <kcursor.h>
00030
#include <klocale.h>
00031
#include <kseparator.h>
00032
#include <kdialog.h>
00033
00034
class KRadioButton :
public QRadioButton
00035 {
00036
public:
00037 KRadioButton(
const QString& txt,
QWidget *parent = 0,
const char *name = 0);
00038 };
00039
00040 KRadioButton::KRadioButton(
const QString& txt,
QWidget *parent,
const char *name)
00041 :
QRadioButton(txt,parent,name)
00042 {
00043 setCursor(KCursor::handCursor());
00044 }
00045
00046
00047
00048 KMWBackend::KMWBackend(
QWidget *parent,
const char *name)
00049 : KMWizardPage(parent,name)
00050 {
00051 m_ID = KMWizard::Backend;
00052 m_title = i18n(
"Backend Selection");
00053
00054 m_buttons =
new QButtonGroup(
this);
00055 m_buttons->hide();
00056
00057 m_layout =
new QVBoxLayout(
this, 0, KDialog::spacingHint());
00058 m_layout->addStretch(1);
00059 m_count = 0;
00060 }
00061
00062
bool KMWBackend::isValid(
QString& msg)
00063 {
00064
if (!m_buttons->selected())
00065 {
00066 msg = i18n(
"You must select a backend!");
00067
return false;
00068 }
00069
return true;
00070 }
00071
00072
void KMWBackend::initPrinter(KMPrinter *p)
00073 {
00074
QString s = p->option(
"kde-backend");
00075
int ID(-1);
00076
00077
if (!s.
isEmpty())
00078 ID = s.
toInt();
00079
else
00080 {
00081 s = p->deviceProtocol();
00082
00083
if (s ==
"parallel" || s ==
"serial" || s ==
"usb") ID = KMWizard::Local;
00084
else if (s ==
"smb") ID = KMWizard::SMB;
00085
else if (s ==
"ipp" || s ==
"http") ID = KMWizard::IPP;
00086
else if (s ==
"lpd") ID = KMWizard::LPD;
00087
else if (s ==
"socket") ID = KMWizard::TCP;
00088
else if (s ==
"file") ID = KMWizard::File;
00089
else if (p->members().count() > 0) ID = KMWizard::Class;
00090 }
00091
00092
if (m_buttons->find(ID))
00093 m_buttons->setButton(ID);
00094 }
00095
00096
void KMWBackend::updatePrinter(KMPrinter *p)
00097 {
00098
int ID = m_buttons->id(m_buttons->selected());
00099
if (ID == KMWizard::Class) p->setType(KMPrinter::Class);
00100
else p->setType(KMPrinter::Printer);
00101 p->setOption(
"kde-backend",QString::number(ID));
00102
QString s = m_buttons->selected()->text();
00103 s.
replace(
QRegExp(
"&(?=\\w)"), QString::fromLatin1(
""));
00104 p->setOption(
"kde-backend-description",s);
00105 setNextPage((m_map.contains(ID) ? m_map[ID] : KMWizard::Error));
00106 }
00107
00108
void KMWBackend::addBackend(
int ID,
const QString& txt,
bool on,
int nextpage)
00109 {
00110
if (ID == -1)
00111 {
00112 KSeparator* sep =
new KSeparator( KSeparator::HLine,
this);
00113 m_layout->insertWidget(m_count, sep);
00114 }
00115
else
00116 {
00117 KRadioButton *btn =
new KRadioButton(txt,
this);
00118 btn->setEnabled(on);
00119 m_buttons->insert(btn, ID);
00120 m_map[ID] = (nextpage == -1 ? ID : nextpage);
00121 m_layout->insertWidget(m_count, btn);
00122 }
00123 m_count++;
00124 }
00125
00126
void KMWBackend::enableBackend(
int ID,
bool on)
00127 {
00128
QButton *btn = m_buttons->find(ID);
00129
if (btn)
00130 btn->setEnabled(on);
00131 }