31 #include "ksane_device_dialog.moc"
37 #include <sane/saneopts.h>
38 #include <sane/sane.h>
44 #include <KPushButton>
46 #include <QScrollArea>
56 setButtons(KDialog::User1 | KDialog::Ok | KDialog::Cancel);
57 setButtonText(User1, i18n(
"Reload devices list"));
59 m_btnGroup =
new QButtonGroup(
this);
61 m_btnBox =
new QGroupBox;
62 QVBoxLayout *layout =
new QVBoxLayout;
64 m_btnLayout =
new QVBoxLayout(m_btnContainer);
65 QScrollArea *area =
new QScrollArea;
67 m_btnBox->setLayout(layout);
70 new QLabel(i18n(
"<html>The SANE (Scanner Access Now Easy) system could not find any device.<br>"
71 "Check that the scanner is plugged in and turned on<br>"
72 "or check your systems scanner setup.<br>"
73 "For details about SANE see the "
74 "<a href='http://www.sane-project.org/'>SANE homepage</a>.</html>"));
75 explanation->setOpenExternalLinks(
true);
77 layout->getContentsMargins(&l, &t, &r, &b);
78 explanation->setContentsMargins(l, t, r, b);
80 layout->addWidget(explanation);
81 m_btnBox->adjustSize();
82 layout->addWidget(area);
83 layout->setContentsMargins(0,0,0,0);
85 area->setWidgetResizable(
true);
86 area->setFrameShape(QFrame::NoFrame);
87 area->setWidget(m_btnContainer);
89 setMainWidget(m_btnBox);
90 setMinimumHeight(200);
93 connect(m_findDevThread, SIGNAL(finished()),
this, SLOT(updateDevicesList()));
106 while (!m_btnGroup->buttons().isEmpty()) {
107 delete m_btnGroup->buttons().takeFirst();
109 m_btnBox->setTitle(i18n(
"Looking for devices. Please wait."));
110 m_btnBox->layout()->itemAt(0)->widget()->hide();
111 enableButton(KDialog::User1,
false);
113 if(!m_findDevThread->isRunning()) {
114 m_findDevThread->start();
118 void KSaneDeviceDialog::setAvailable(
bool avail)
120 enableButtonOk(avail);
123 setButtonFocus(KDialog::Ok);
129 m_selectedDevice = defaultBackend;
133 QAbstractButton *selectedButton = m_btnGroup->checkedButton();
135 return selectedButton->objectName();
140 void KSaneDeviceDialog::updateDevicesList()
142 while (!m_btnGroup->buttons().isEmpty()) {
143 delete m_btnGroup->buttons().takeFirst();
146 const QList<KSaneWidget::DeviceInfo> list = m_findDevThread->
devicesList();
147 if (list.isEmpty()) {
148 m_btnBox->setTitle(i18n(
"Sorry. No devices found."));
149 m_btnBox->layout()->itemAt(0)->widget()->show();
150 m_btnBox->layout()->itemAt(1)->widget()->hide();
151 enableButton(KDialog::User1,
true);
156 m_btnLayout =
new QVBoxLayout;
157 m_btnContainer->setLayout(m_btnLayout);
158 m_btnBox->setTitle(i18n(
"Found devices:"));
159 m_btnBox->layout()->itemAt(0)->widget()->hide();
160 m_btnBox->layout()->itemAt(1)->widget()->show();
162 for (
int i=0; i< list.size(); i++) {
163 QRadioButton *b =
new QRadioButton(
this);
164 b->setObjectName(list[i].name);
165 b->setToolTip(list[i].name);
166 b->setText(QString(
"%1 : %2\n%3")
171 m_btnLayout->addWidget(b);
172 m_btnGroup->addButton(b);
173 connect(b, SIGNAL(clicked(
bool)),
this, SLOT(setAvailable(
bool)));
174 if((i==0) || (list[i].name == m_selectedDevice)) {
180 m_btnLayout->addStretch();
182 if(list.size() == 1) {
183 button(KDialog::Ok)->animateClick();
186 enableButton(KDialog::User1,
true);
KSaneDeviceDialog(QWidget *parent=0)
static FindSaneDevicesThread * getInstance()
QString getSelectedName()
const QList< KSaneWidget::DeviceInfo > devicesList() const