• 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_find_devices_thread.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  *
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 #include "ksane_find_devices_thread.h"
30 #include "ksane_find_devices_thread.moc"
31 
32 #include "ksane_widget_private.h"
33 
34 // Sane includes
35 extern "C"
36 {
37 #include <sane/saneopts.h>
38 #include <sane/sane.h>
39 }
40 
41 // KDE includes
42 #include <KDebug>
43 
44 // Qt includes
45 #include <QMutex>
46 
47 namespace KSaneIface
48 {
49 static FindSaneDevicesThread *s_instancesane = 0;
50 static QMutex s_mutexsane;
51 
52 FindSaneDevicesThread *FindSaneDevicesThread::getInstance()
53 {
54  s_mutexsane.lock();
55 
56  if (s_instancesane == 0) {
57  s_instancesane = new FindSaneDevicesThread();
58  }
59  s_mutexsane.unlock();
60 
61  return s_instancesane;
62 }
63 
64 FindSaneDevicesThread::FindSaneDevicesThread() : QThread(0)
65 {
66 }
67 
68 FindSaneDevicesThread::~FindSaneDevicesThread()
69 {
70  s_mutexsane.lock();
71  wait();
72  s_mutexsane.unlock();
73 }
74 
75 
76 void FindSaneDevicesThread::run()
77 {
78  SANE_Device const **devList;
79  //SANE_Int version;
80  SANE_Status status;
81 
82  // This is unfortunately not very reliable as many back-ends do not refresh
83  // the device list after the sane_init() call...
84  status = sane_get_devices(&devList, SANE_FALSE);
85 
86  m_deviceList.clear();
87  if (status == SANE_STATUS_GOOD) {
88  int i = 0;
89  KSaneWidget::DeviceInfo tmp;
90 
91  while(devList[i] != 0) {
92  tmp.name = devList[i]->name;
93  tmp.vendor = devList[i]->vendor;
94  tmp.model = devList[i]->model;
95  tmp.type = devList[i]->type;
96  m_deviceList << tmp;
97  i++;
98  }
99  }
100 }
101 
102 const QList<KSaneWidget::DeviceInfo> FindSaneDevicesThread::devicesList() const
103 {
104  return m_deviceList;
105 }
106 
107 }
QMutex
KSaneIface::FindSaneDevicesThread::getInstance
static FindSaneDevicesThread * getInstance()
Definition: ksane_find_devices_thread.cpp:52
QMutex::unlock
void unlock()
KSaneIface::FindSaneDevicesThread::~FindSaneDevicesThread
~FindSaneDevicesThread()
Definition: ksane_find_devices_thread.cpp:68
KSaneIface::s_instancesane
static FindSaneDevicesThread * s_instancesane
Definition: ksane_find_devices_thread.cpp:49
KSaneIface::KSaneWidget::DeviceInfo::vendor
QString vendor
Definition: ksane.h:85
KSaneIface::KSaneWidget::DeviceInfo::type
QString type
Definition: ksane.h:87
ksane_widget_private.h
QList
KSaneIface::FindSaneDevicesThread::run
void run()
Definition: ksane_find_devices_thread.cpp:76
QMutex::lock
void lock()
KSaneIface::FindSaneDevicesThread::devicesList
const QList< KSaneWidget::DeviceInfo > devicesList() const
Definition: ksane_find_devices_thread.cpp:102
KSaneIface::s_mutexsane
static QMutex s_mutexsane
Definition: ksane_find_devices_thread.cpp:50
ksane_find_devices_thread.h
QThread::wait
bool wait(unsigned long time)
KSaneIface::FindSaneDevicesThread
Definition: ksane_find_devices_thread.h:39
QThread
KSaneIface::KSaneWidget::DeviceInfo::name
QString name
Definition: ksane.h:84
KSaneIface::KSaneWidget::DeviceInfo::model
QString model
Definition: ksane.h:86
KSaneIface::KSaneWidget::DeviceInfo
Definition: ksane.h:82
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