• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegraphics API Reference
  • KDE Home
  • Contact Us
 

libs/libksane/libksane

  • sources
  • kde-4.14
  • kdegraphics
  • libs
  • libksane
  • libksane
ksane_device_dialog.cpp
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is part of the KDE project
4  *
5  * Date : 2007-09-13
6  * Description : Sane interface for KDE
7  *
8  * Copyright (C) 2007-2008 by Kare Sars <kare dot sars at iki dot fi>
9  * Copyright (C) 2009 by Grzegorz Kurtyka <grzegorz dot kurtyka at gmail dot com>
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) version 3, or any
15  * later version accepted by the membership of KDE e.V. (or its
16  * successor approved by the membership of KDE e.V.), which shall
17  * act as a proxy defined in Section 6 of version 3 of the license.
18  *
19  * This library is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  * Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public
25  * License along with this program. If not, see <http://www.gnu.org/licenses/>.
26  *
27  * ============================================================ */
28 
29 // Local includes
30 #include "ksane_device_dialog.h"
31 #include "ksane_device_dialog.moc"
32 
33 
34 // Sane includes
35 extern "C"
36 {
37 #include <sane/saneopts.h>
38 #include <sane/sane.h>
39 }
40 
41 
42 // KDE includes
43 #include <KDebug>
44 #include <KPushButton>
45 
46 #include <QScrollArea>
47 #include <QLabel>
48 
49 namespace KSaneIface
50 {
51 
52 KSaneDeviceDialog::KSaneDeviceDialog(QWidget *parent)
53  : KDialog(parent)
54 {
55 
56  setButtons(KDialog::User1 | KDialog::Ok | KDialog::Cancel);
57  setButtonText(User1, i18n("Reload devices list"));
58 
59  m_btnGroup = new QButtonGroup(this);
60 
61  m_btnBox = new QGroupBox;
62  QVBoxLayout *layout = new QVBoxLayout;
63  m_btnContainer = new QWidget;
64  m_btnLayout = new QVBoxLayout(m_btnContainer);
65  QScrollArea *area = new QScrollArea;
66 
67  m_btnBox->setLayout(layout);
68 
69  QLabel *explanation =
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);
76  int l,t,r,b;
77  layout->getContentsMargins(&l, &t, &r, &b);
78  explanation->setContentsMargins(l, t, r, b);
79 
80  layout->addWidget(explanation);
81  m_btnBox->adjustSize(); // make sure to see the complete explanation text
82  layout->addWidget(area);
83  layout->setContentsMargins(0,0,0,0);
84 
85  area->setWidgetResizable(true);
86  area->setFrameShape(QFrame::NoFrame);
87  area->setWidget(m_btnContainer);
88 
89  setMainWidget(m_btnBox);
90  setMinimumHeight(200);
91  m_findDevThread = FindSaneDevicesThread::getInstance();
92 
93  connect(m_findDevThread, SIGNAL(finished()), this, SLOT(updateDevicesList()));
94  connect(this, SIGNAL(user1Clicked()), this, SLOT(reloadDevicesList()));
95 
96  reloadDevicesList();
97 }
98 
99 KSaneDeviceDialog::~KSaneDeviceDialog() {
101 }
102 
103 void KSaneDeviceDialog::reloadDevicesList()
104 {
105  setAvailable(false);
106  while (!m_btnGroup->buttons().isEmpty()) {
107  delete m_btnGroup->buttons().takeFirst();
108  }
109  m_btnBox->setTitle(i18n("Looking for devices. Please wait."));
110  m_btnBox->layout()->itemAt(0)->widget()->hide(); // explanation
111  enableButton(KDialog::User1, false);
112 
113  if(!m_findDevThread->isRunning()) {
114  m_findDevThread->start();
115  }
116 }
117 
118 void KSaneDeviceDialog::setAvailable(bool avail)
119 {
120  enableButtonOk(avail);
121  if(avail) {
122  m_selectedDevice = getSelectedName();
123  setButtonFocus(KDialog::Ok);
124  }
125 }
126 
127 void KSaneDeviceDialog::setDefault(QString defaultBackend)
128 {
129  m_selectedDevice = defaultBackend;
130 }
131 
132 QString KSaneDeviceDialog::getSelectedName() {
133  QAbstractButton *selectedButton = m_btnGroup->checkedButton();
134  if(selectedButton) {
135  return selectedButton->objectName();
136  }
137  return QString();
138 }
139 
140 void KSaneDeviceDialog::updateDevicesList()
141 {
142  while (!m_btnGroup->buttons().isEmpty()) {
143  delete m_btnGroup->buttons().takeFirst();
144  }
145 
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(); // explanation
150  m_btnBox->layout()->itemAt(1)->widget()->hide(); // scroll area
151  enableButton(KDialog::User1, true);
152  return;
153  }
154 
155  delete m_btnLayout;
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(); // explanation
160  m_btnBox->layout()->itemAt(1)->widget()->show(); // scroll area
161 
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")
167  .arg(list[i].vendor)
168  .arg(list[i].model)
169  .arg(list[i].name));
170 
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)) {
175  b->setChecked(true);
176  setAvailable(true);
177  }
178  }
179 
180  m_btnLayout->addStretch();
181 
182  if(list.size() == 1) {
183  button(KDialog::Ok)->animateClick();
184  }
185 
186  enableButton(KDialog::User1, true);
187 }
188 
189 } // NameSpace KSaneIface
QWidget::layout
QLayout * layout() const
QWidget
QScrollArea::setWidget
void setWidget(QWidget *widget)
QLayout::itemAt
virtual QLayoutItem * itemAt(int index) const =0
QLayout::setContentsMargins
void setContentsMargins(int left, int top, int right, int bottom)
QButtonGroup::addButton
void addButton(QAbstractButton *button)
QFrame::setFrameShape
void setFrameShape(Shape)
QLabel::setOpenExternalLinks
void setOpenExternalLinks(bool open)
KSaneIface::KSaneDeviceDialog::KSaneDeviceDialog
KSaneDeviceDialog(QWidget *parent=0)
Definition: ksane_device_dialog.cpp:52
QLayoutItem::widget
virtual QWidget * widget()
KSaneIface::FindSaneDevicesThread::getInstance
static FindSaneDevicesThread * getInstance()
Definition: ksane_find_devices_thread.cpp:52
KDialog
KSaneIface::KSaneDeviceDialog::reloadDevicesList
void reloadDevicesList()
Definition: ksane_device_dialog.cpp:103
QWidget::adjustSize
void adjustSize()
QList::size
int size() const
QButtonGroup
QThread::start
void start(Priority priority)
QLayout::getContentsMargins
void getContentsMargins(int *left, int *top, int *right, int *bottom) const
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
KSaneIface::KSaneDeviceDialog::~KSaneDeviceDialog
~KSaneDeviceDialog()
Definition: ksane_device_dialog.cpp:99
QWidget::setLayout
void setLayout(QLayout *layout)
QGroupBox
QList::isEmpty
bool isEmpty() const
QObject::objectName
objectName
KSaneIface::KSaneDeviceDialog::getSelectedName
QString getSelectedName()
Definition: ksane_device_dialog.cpp:132
QVBoxLayout
QString
QList
QWidget::hide
void hide()
ksane_device_dialog.h
QScrollArea::setWidgetResizable
void setWidgetResizable(bool resizable)
QThread::isRunning
bool isRunning() const
KSaneIface::FindSaneDevicesThread::devicesList
const QList< KSaneWidget::DeviceInfo > devicesList() const
Definition: ksane_find_devices_thread.cpp:102
QAbstractButton::setChecked
void setChecked(bool)
QAbstractButton
QButtonGroup::buttons
QList< QAbstractButton * > buttons() const
QBoxLayout::addStretch
void addStretch(int stretch)
QRadioButton
QGroupBox::setTitle
void setTitle(const QString &title)
QAbstractButton::setText
void setText(const QString &text)
QWidget::show
void show()
QWidget::setToolTip
void setToolTip(const QString &)
KSaneIface::KSaneDeviceDialog::setDefault
void setDefault(QString)
Definition: ksane_device_dialog.cpp:127
QScrollArea
QLabel
QButtonGroup::checkedButton
QAbstractButton * checkedButton() const
QWidget::setContentsMargins
void setContentsMargins(int left, int top, int right, int bottom)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:19:47 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libs/libksane/libksane

Skip menu "libs/libksane/libksane"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdegraphics API Reference

Skip menu "kdegraphics API Reference"
  •     libkdcraw
  •     libkexiv2
  •     libkipi
  •     libksane
  • okular

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal