File indexing completed on 2024-03-24 15:47:55

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 #include "kookapref.h"
0033 
0034 #include <qlayout.h>
0035 #include <qicon.h>
0036 #include <qpushbutton.h>
0037 
0038 #include <klocalizedstring.h>
0039 
0040 #include "prefspages.h"
0041 #include "kookasettings.h"
0042 #include "dialogstatesaver.h"
0043 #include "kooka_logging.h"
0044 
0045 
0046 KookaPref::KookaPref(QWidget *parent)
0047     : KPageDialog(parent)
0048 {
0049     setObjectName("KookaPref");
0050 
0051     setModal(true);
0052     setStandardButtons(QDialogButtonBox::Help | QDialogButtonBox::Ok | QDialogButtonBox::Apply | QDialogButtonBox::Cancel | QDialogButtonBox::RestoreDefaults);
0053     buttonBox()->button(QDialogButtonBox::Ok)->setDefault(true);
0054     buttonBox()->button(QDialogButtonBox::RestoreDefaults)->setIcon(QIcon::fromTheme("edit-undo"));
0055     setWindowTitle(i18n("Preferences"));
0056 
0057     createPage(new KookaGeneralPage(this), i18n("General"), i18n("General Options"), "configure");
0058     createPage(new KookaStartupPage(this), i18n("Startup"), i18n("Startup Options"), "system-run");
0059     createPage(new KookaSavingPage(this), i18n("Image Saving"), i18n("Image Saving Options"), "document-save");
0060     createPage(new KookaThumbnailPage(this), i18n("Gallery & Thumbnails"), i18n("Image Gallery and Thumbnail View"), "view-list-icons");
0061     createPage(new KookaOcrPage(this), i18n("OCR"), i18n("Optical Character Recognition"), "ocr");
0062 
0063     connect(buttonBox()->button(QDialogButtonBox::Ok), &QPushButton::clicked, this, &KookaPref::slotSaveSettings);
0064     connect(buttonBox()->button(QDialogButtonBox::Apply), &QPushButton::clicked, this, &KookaPref::slotSaveSettings);
0065     connect(buttonBox()->button(QDialogButtonBox::RestoreDefaults), &QPushButton::clicked, this, &KookaPref::slotSetDefaults);
0066 
0067     setMinimumSize(670, 380);
0068     new DialogStateSaver(this);
0069 }
0070 
0071 int KookaPref::createPage(KookaPrefsPage *page,
0072                           const QString &name,
0073                           const QString &header,
0074                           const char *icon)
0075 {
0076     QVBoxLayout *top = static_cast<QVBoxLayout *>(page->layout());
0077     if (top != nullptr) {
0078         top->addStretch(1);
0079     }
0080 
0081     KPageWidgetItem *item = addPage(page, name);
0082     item->setHeader(header);
0083     item->setIcon(QIcon::fromTheme(icon));
0084 
0085     int idx = mPages.count();               // index of new item
0086     mPages.append(item);
0087     return (idx);                   // index of item added
0088 }
0089 
0090 void KookaPref::slotSaveSettings()
0091 {
0092     for (int i = 0; i < mPages.size(); ++i) {
0093         KookaPrefsPage *page = static_cast<KookaPrefsPage *>(mPages[i]->widget());
0094         page->saveSettings();
0095     }
0096 
0097     KSharedConfig::openConfig()->sync();
0098     emit dataSaved();
0099 }
0100 
0101 void KookaPref::slotSetDefaults()
0102 {
0103     for (int i = 0; i < mPages.size(); ++i) {
0104         KookaPrefsPage *page = static_cast<KookaPrefsPage *>(mPages[i]->widget());
0105         page->defaultSettings();
0106     }
0107 }
0108 
0109 void KookaPref::showPageIndex(int page)
0110 {
0111     if (page >= 0 && page < mPages.size()) {
0112         setCurrentPage(mPages[page]);
0113     }
0114 }
0115 
0116 int KookaPref::currentPageIndex()
0117 {
0118     return (mPages.indexOf(currentPage()));
0119 }