File indexing completed on 2024-04-21 15:12:09

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) 2008-2016 Jonathan Marten <jjm@keelhaul.me.uk>    *
0007  *                                  *
0008  *  Kooka is free software; you can redistribute it and/or modify it    *
0009  *  under the terms of the GNU Library General Public License as    *
0010  *  published by the Free Software Foundation and appearing in the  *
0011  *  file COPYING included in the packaging of this file;  either    *
0012  *  version 2 of the License, or (at your option) any later version.    *
0013  *                                  *
0014  *  As a special exception, permission is given to link this program    *
0015  *  with any version of the KADMOS OCR/ICR engine (a product of     *
0016  *  reRecognition GmbH, Kreuzlingen), and distribute the resulting  *
0017  *  executable without including the source code for KADMOS in the  *
0018  *  source distribution.                        *
0019  *                                  *
0020  *  This program is distributed in the hope that it will be useful, *
0021  *  but WITHOUT ANY WARRANTY; without even the implied warranty of  *
0022  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   *
0023  *  GNU General Public License for more details.            *
0024  *                                  *
0025  *  You should have received a copy of the GNU General Public       *
0026  *  License along with this program;  see the file COPYING.  If     *
0027  *  not, see <http://www.gnu.org/licenses/>.                *
0028  *                                  *
0029  ************************************************************************/
0030 
0031 #include "adddevicedialog.h"
0032 
0033 #include <qlabel.h>
0034 #include <qlayout.h>
0035 #include <qcombobox.h>
0036 
0037 #include <klocalizedstring.h>
0038 #include <klineedit.h>
0039 
0040 
0041 AddDeviceDialog::AddDeviceDialog(QWidget *parent, const QString &caption)
0042     : DialogBase(parent)
0043 {
0044     setObjectName("AddDeviceDialog");
0045 
0046     setButtons(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
0047     setWindowTitle(caption);
0048 
0049     QWidget *w = new QWidget(this);
0050     QVBoxLayout *vl = new QVBoxLayout(w);
0051 
0052     QLabel *lab = new QLabel(xi18nc("@info",
0053                                     "If your scanner has not been automatically detected, you can specify it here. "
0054                                     "The <interface>Scanner device name</interface> should be a backend name (with optional parameters) "
0055                                     "that is understood by SANE, see <link url=\"man:/sane\">sane(7)</link> or "
0056                                     "<link url=\"man:/sane-dll\">sane-dll(5)</link> for more information on available backends. "
0057                                     "The <interface>Type</interface> and <interface>Description</interface> can be used to identify the scanner later."
0058                                     "<nl/><nl/>"
0059                                     "For the information that needs to be entered here, try to locate the device using the "
0060                                     "<link url=\"man:/sane-find-scanner\">sane-find-scanner(1)</link> command. For a "
0061                                     "USB or networked HP scanner using <link url=\"http://hplip.sourceforge.net/\">HPLIP</link>, "
0062                                     "try using the <command>hp-probe</command> command to locate it, for example "
0063                                     "<icode>hp-probe&nbsp;-b&nbsp;usb</icode> or <icode>hp-probe&nbsp;-b&nbsp;net</icode>. "
0064                                     "If the scanner is found, then enter the device name displayed by these commands; note "
0065                                     "that if using HPLIP then <icode>hp:</icode> needs to be replaced by <icode>hpaio:</icode>."
0066                                     "<nl/><nl/>"
0067                                     "If these commands fail to locate your scanner, then it may not be supported "
0068                                     "by SANE. Check the SANE documentation for a "
0069                                     "<link url=\"http://www.sane-project.org/sane-supported-devices.html\">list of supported devices</link>."), w);
0070     lab->setWordWrap(true);
0071     lab->setOpenExternalLinks(true);
0072     vl->addWidget(lab);
0073 
0074     vl->addSpacing(verticalSpacing());
0075     vl->addStretch(1);
0076 
0077     lab = new QLabel(i18n("Scanner device name:"), w);
0078     vl->addWidget(lab);
0079 
0080     mDevEdit = new KLineEdit(w);
0081     connect(mDevEdit, &KLineEdit::textChanged, this, &AddDeviceDialog::slotTextChanged);
0082     vl->addWidget(mDevEdit);
0083     lab->setBuddy(mDevEdit);
0084 
0085     lab = new QLabel(i18n("Device type:"), w);
0086     vl->addWidget(lab);
0087 
0088     mTypeCombo = new QComboBox(w);
0089     vl->addWidget(mTypeCombo);
0090     lab->setBuddy(mTypeCombo);
0091 
0092     lab = new QLabel(i18n("Description:"), w);
0093     vl->addWidget(lab);
0094 
0095     mDescEdit = new KLineEdit(w);
0096     connect(mDescEdit, &KLineEdit::textChanged, this, &AddDeviceDialog::slotTextChanged);
0097     vl->addWidget(mDescEdit);
0098     lab->setBuddy(mDescEdit);
0099 
0100     w->setMinimumSize(QSize(450, 420));
0101     setMainWidget(w);
0102 
0103     // This list from http://www.sane-project.org/html/doc011.html#s4.2.8
0104     QStringList types;
0105     types << "scanner" << "film scanner" << "flatbed scanner"
0106           << "frame grabber" << "handheld scanner" << "multi-function peripheral"
0107           << "sheetfed scanner" << "still camera" << "video camera"
0108           << "virtual device";
0109     mTypeCombo->addItems(types);
0110 
0111     slotTextChanged();
0112 }
0113 
0114 void AddDeviceDialog::slotTextChanged()
0115 {
0116     setButtonEnabled(QDialogButtonBox::Ok,
0117                      !mDevEdit->text().trimmed().isEmpty() &&
0118                      !mDescEdit->text().trimmed().isEmpty());
0119 }
0120 
0121 QByteArray AddDeviceDialog::getDevice() const
0122 {
0123     return mDevEdit->text().toLocal8Bit();
0124 }
0125 
0126 QString AddDeviceDialog::getDescription() const
0127 {
0128     return mDescEdit->text();
0129 }
0130 
0131 QByteArray AddDeviceDialog::getType() const
0132 {
0133     return mTypeCombo->currentText().toLocal8Bit();
0134 }