File indexing completed on 2024-03-24 15:48:01

0001 /************************************************************************
0002  *                                  *
0003  *  This file is part of Kooka, a scanning/OCR application using    *
0004  *  Qt <http://www.qt.io> and KDE Frameworks <http://www.kde.org>.  *
0005  *                                  *
0006  *  Copyright (C) 2000-2016 Klaas Freitag <freitag@suse.de>     *
0007  *                          Jonathan Marten <jjm@keelhaul.me.uk>    *
0008  *                                  *
0009  *  Kooka is free software; you can redistribute it and/or modify it    *
0010  *  under the terms of the GNU Library General Public License as    *
0011  *  published by the Free Software Foundation and appearing in the  *
0012  *  file COPYING included in the packaging of this file;  either    *
0013  *  version 2 of the License, or (at your option) any later version.    *
0014  *                                  *
0015  *  As a special exception, permission is given to link this program    *
0016  *  with any version of the KADMOS OCR/ICR engine (a product of     *
0017  *  reRecognition GmbH, Kreuzlingen), and distribute the resulting  *
0018  *  executable without including the source code for KADMOS in the  *
0019  *  source distribution.                        *
0020  *                                  *
0021  *  This program is distributed in the hope that it will be useful, *
0022  *  but WITHOUT ANY WARRANTY; without even the implied warranty of  *
0023  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   *
0024  *  GNU General Public License for more details.            *
0025  *                                  *
0026  *  You should have received a copy of the GNU General Public       *
0027  *  License along with this program;  see the file COPYING.  If     *
0028  *  not, see <http://www.gnu.org/licenses/>.                *
0029  *                                  *
0030  ************************************************************************/
0031 
0032 #ifndef DEVICESELECTOR_H
0033 #define DEVICESELECTOR_H
0034 
0035 #include "kookascan_export.h"
0036 
0037 #include "dialogbase.h"
0038 
0039 #include <kguiitem.h>
0040 
0041 class QListWidget;
0042 class QCheckBox;
0043 
0044 class KGuiItem;
0045 
0046 
0047 /**
0048  * @short A dialogue to allow the user to select a scan device.
0049  *
0050  * It is possible, depending on the application preferences and
0051  * the user's previous choices, that user interaction may not be
0052  * needed.  The dialogue should therefore be used in this way:
0053  *
0054  * @code
0055  * DeviceSelector ds(parent, ScanDevices::self()->allDevices());
0056  * QByteArray selDevice = ds.getDeviceFromConfig();
0057  * if (selDevice.isEmpty())
0058  * {
0059  *     if (ds.exec()==QDialog::Accepted) selDevice = ds.getSelectedDevice();
0060  * }
0061  * @endcode
0062  *
0063  * If the user checks the "Always use this device at startup" option,
0064  * this is stored in the global scanner configuration.
0065  *
0066  * @author Klaas Freitag
0067  * @author Eduard Huguet
0068  * @author Jonathan Marten
0069  **/
0070 
0071 class KOOKASCAN_EXPORT DeviceSelector : public DialogBase
0072 {
0073     Q_OBJECT
0074 
0075 public:
0076     /**
0077      * Constructor.
0078      *
0079      * @param pnt Parent widget.
0080      * @param backends a list of SANE device names.
0081      * @param cancelGuiItem GUI item for the "Cancel" button, if required
0082      * to replace the default.
0083      **/
0084     explicit DeviceSelector(QWidget *pnt, const QList<QByteArray> &backends, const KGuiItem &cancelGuiItem = KGuiItem());
0085 
0086     /**
0087      * Destructor.
0088      **/
0089     virtual ~DeviceSelector();
0090 
0091     /**
0092      * Get the device that the user selected.
0093      *
0094      * @return The SANE device name
0095      **/
0096     QByteArray getSelectedDevice() const;
0097 
0098     /**
0099      * Check whether the user wants to skip this dialogue in future.
0100      *
0101      * @return @c true if the dialogue should be skipped
0102      **/
0103     bool getShouldSkip() const;
0104 
0105     /**
0106      * Get the selected device from the global scanner configuration file,
0107      * if there is a valid device and the user has requested that it
0108      * should be used by default.
0109      *
0110      * @return The SANE device name, or a null string if it is not
0111      * available or the user does not want to use it.
0112      **/
0113     QByteArray getDeviceFromConfig() const;
0114 
0115 private:
0116     void setScanSources(const QList<QByteArray> &backends);
0117 
0118     QListWidget *mListBox;
0119     QCheckBox *mSkipCheckbox;
0120 
0121     QStringList mDeviceList;
0122 };
0123 
0124 #endif                          // DEVICESELECTOR_H