File indexing completed on 2024-04-28 15:39:40
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) 2018 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 "executablepathdialogue.h" 0032 0033 #include <qlabel.h> 0034 #include <qboxlayout.h> 0035 0036 #include <klocalizedstring.h> 0037 #include <kurlrequester.h> 0038 0039 0040 ExecutablePathDialogue::ExecutablePathDialogue(QWidget *pnt) 0041 : DialogBase(pnt) 0042 { 0043 setObjectName("ExecutablePathDialogue"); 0044 setButtons(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); 0045 setWindowTitle(i18n("Executable Path")); 0046 0047 QWidget *page = new QWidget(this); 0048 setMainWidget(page); 0049 0050 QVBoxLayout *lay = new QVBoxLayout(page); 0051 0052 mLabel = new QLabel(i18n("Executable path:"), this); 0053 lay->addWidget(mLabel); 0054 0055 mPathRequester = new KUrlRequester(QUrl("file:///usr/bin/"), this); 0056 mPathRequester->setPlaceholderText(i18n("Enter or select the path...")); 0057 mPathRequester->setAcceptMode(QFileDialog::AcceptOpen); 0058 mPathRequester->setMimeTypeFilters(QStringList() << "application/x-executable"); 0059 mPathRequester->setMode(KFile::File|KFile::ExistingOnly|KFile::LocalOnly); 0060 mPathRequester->setStartDir(QUrl("file:///usr/bin/")); 0061 connect(mPathRequester, &KUrlRequester::textChanged, this, &ExecutablePathDialogue::slotTextChanged); 0062 lay->addWidget(mPathRequester); 0063 mLabel->setBuddy(mPathRequester); 0064 0065 lay->addStretch(); 0066 } 0067 0068 0069 void ExecutablePathDialogue::setPath(const QString &exec) 0070 { 0071 mPathRequester->setUrl(QUrl::fromLocalFile(exec)); 0072 } 0073 0074 0075 void ExecutablePathDialogue::setLabel(const QString &text) 0076 { 0077 mLabel->setText(text); 0078 } 0079 0080 0081 QString ExecutablePathDialogue::path() const 0082 { 0083 return (mPathRequester->url().path()); 0084 } 0085 0086 0087 void ExecutablePathDialogue::slotTextChanged(const QString &text) 0088 { 0089 setButtonEnabled(QDialogButtonBox::Ok, !text.isEmpty()); 0090 }