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

libs/libksane/src

  • kde-4.x
  • kdegraphics
  • libs
  • libksane
  • src
ksanefinddevicesthread.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) 2009 by Grzegorz Kurtyka <grzegorz dot kurtyka at gmail dot com>
9  * Copyright (C) 2010 by Kare Sars <kare dot sars at iki dot fi>
10  * Copyright (C) 2014 by Gregor Mitsch: port to KDE5 frameworks
11  *
12  * This library is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public
14  * License as published by the Free Software Foundation; either
15  * version 2.1 of the License, or (at your option) version 3, or any
16  * later version accepted by the membership of KDE e.V. (or its
17  * successor approved by the membership of KDE e.V.), which shall
18  * act as a proxy defined in Section 6 of version 3 of the license.
19  *
20  * This library is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23  * Lesser General Public License for more details.
24  *
25  * You should have received a copy of the GNU Lesser General Public
26  * License along with this program. If not, see <http://www.gnu.org/licenses/>.
27  *
28  * ============================================================ */
29 
30 #include "ksanefinddevicesthread.h"
31 
32 // #include "ksanewidget_p.h"
33 
34 // Sane includes
35 extern "C"
36 {
37 #include <sane/saneopts.h>
38 #include <sane/sane.h>
39 }
40 
41 #include <QMutex>
42 
43 namespace KSaneIface
44 {
45 static FindSaneDevicesThread *s_instancesane = nullptr;
46 static QMutex s_mutexsane;
47 
48 FindSaneDevicesThread *FindSaneDevicesThread::getInstance()
49 {
50  s_mutexsane.lock();
51 
52  if (s_instancesane == nullptr) {
53  s_instancesane = new FindSaneDevicesThread();
54  }
55  s_mutexsane.unlock();
56 
57  return s_instancesane;
58 }
59 
60 FindSaneDevicesThread::FindSaneDevicesThread() : QThread(nullptr)
61 {
62 }
63 
64 FindSaneDevicesThread::~FindSaneDevicesThread()
65 {
66  s_mutexsane.lock();
67  wait();
68  s_mutexsane.unlock();
69 }
70 
71 void FindSaneDevicesThread::run()
72 {
73  SANE_Device const **devList;
74  //SANE_Int version;
75  SANE_Status status;
76 
77  // This is unfortunately not very reliable as many back-ends do not refresh
78  // the device list after the sane_init() call...
79  status = sane_get_devices(&devList, SANE_FALSE);
80 
81  m_deviceList.clear();
82  if (status == SANE_STATUS_GOOD) {
83  int i = 0;
84  KSaneWidget::DeviceInfo deviceInfo;
85 
86  while (devList[i] != nullptr) {
87  deviceInfo.name = QString::fromUtf8(devList[i]->name);
88  deviceInfo.vendor = QString::fromUtf8(devList[i]->vendor);
89  deviceInfo.model = QString::fromUtf8(devList[i]->model);
90  deviceInfo.type = QString::fromUtf8(devList[i]->type);
91  m_deviceList << deviceInfo;
92  i++;
93  }
94  }
95 }
96 
97 const QList<KSaneWidget::DeviceInfo> FindSaneDevicesThread::devicesList() const
98 {
99  return m_deviceList;
100 }
101 
102 }
QMutex
KSaneIface::FindSaneDevicesThread::run
void run() override
Definition: ksanefinddevicesthread.cpp:71
KSaneIface::FindSaneDevicesThread::getInstance
static FindSaneDevicesThread * getInstance()
Definition: ksanefinddevicesthread.cpp:48
QMutex::unlock
void unlock()
KSaneIface::FindSaneDevicesThread::~FindSaneDevicesThread
~FindSaneDevicesThread()
Definition: ksanefinddevicesthread.cpp:64
KSaneIface::s_instancesane
static FindSaneDevicesThread * s_instancesane
Definition: ksanefinddevicesthread.cpp:45
ksanefinddevicesthread.h
KSaneIface::KSaneWidget::DeviceInfo::vendor
QString vendor
Definition: ksanewidget.h:81
QObject::name
const char * name() const
KSaneIface::KSaneWidget::DeviceInfo::type
QString type
Definition: ksanewidget.h:83
QString::fromUtf8
QString fromUtf8(const char *str, int size)
QList
QMutex::lock
void lock()
KSaneIface::FindSaneDevicesThread::devicesList
const QList< KSaneWidget::DeviceInfo > devicesList() const
Definition: ksanefinddevicesthread.cpp:97
KSaneIface::s_mutexsane
static QMutex s_mutexsane
Definition: ksanefinddevicesthread.cpp:46
QThread::wait
bool wait(unsigned long time)
KSaneIface::FindSaneDevicesThread
Definition: ksanefinddevicesthread.h:40
QThread
KSaneIface::KSaneWidget::DeviceInfo::name
QString name
Definition: ksanewidget.h:80
KSaneIface::KSaneWidget::DeviceInfo::model
QString model
Definition: ksanewidget.h:82
KSaneIface::KSaneWidget::DeviceInfo
Definition: ksanewidget.h:79
This file is part of the KDE documentation.
Documentation copyright © 1996-2019 The KDE developers.
Generated on Sun Dec 8 2019 03:02:35 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libs/libksane/src

Skip menu "libs/libksane/src"
  • 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"
  •     libkipiplugins
  •     src
  •     src
  •     src
  •     src
  •     src
  • 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