File indexing completed on 2022-11-22 13:01:09

0001 /*
0002     general options for Parley
0003     SPDX-FileCopyrightText: 2005, 2007 Peter Hedlund <peter.hedlund@kdemail.net>
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "generaloptions.h"
0008 
0009 #include <KLocalizedString>
0010 #include <QCheckBox>
0011 
0012 #include <KFile>
0013 #include <QSpinBox>
0014 
0015 #include "prefs.h"
0016 
0017 static const char *separator_id[] = {";", // 0
0018                                      "#", // 1
0019                                      "!", // 2
0020                                      "|", // 3
0021                                      ",", // 4
0022                                      "\t", // 5
0023                                      "  ", // 6
0024                                      ":", // 7
0025                                      "::", // 8
0026                                      0};
0027 
0028 GeneralOptions::GeneralOptions(QWidget *parent)
0029     : QWidget(parent)
0030 {
0031     setupUi(this);
0032     connect(kcfg_AutoBackup, &QCheckBox::toggled, kcfg_BackupTime, &QSpinBox::setEnabled);
0033 
0034     fillWidgets();
0035     updateWidgets();
0036     kcfg_BackupTime->setEnabled(kcfg_AutoBackup->isChecked());
0037 }
0038 
0039 void GeneralOptions::fillWidgets()
0040 {
0041     kcfg_SeparatorCombo->addItem(i18nc("CSV separator", ";"));
0042     kcfg_SeparatorCombo->addItem(i18nc("CSV separator", "#"));
0043     kcfg_SeparatorCombo->addItem(i18nc("CSV separator", "!"));
0044     kcfg_SeparatorCombo->addItem(i18nc("CSV separator", "|"));
0045     kcfg_SeparatorCombo->addItem(i18nc("CSV separator", ","));
0046     kcfg_SeparatorCombo->addItem(i18nc("CSV separator: tabulator", "TAB"));
0047     kcfg_SeparatorCombo->addItem(i18nc("CSV separator", ">= 2 SPACES"));
0048     kcfg_SeparatorCombo->addItem(i18nc("CSV separator", " : "));
0049     kcfg_SeparatorCombo->addItem(i18nc("CSV separator", " :: "));
0050 }
0051 
0052 void GeneralOptions::updateWidgets()
0053 {
0054     for (int i = 0; i < 9; ++i) {
0055         if (separator_id[i] == Prefs::separator()) {
0056             kcfg_SeparatorCombo->setCurrentIndex(i);
0057             break;
0058         }
0059     }
0060 }
0061 
0062 bool GeneralOptions::hasChanged()
0063 {
0064     if (kcfg_SeparatorCombo->currentIndex() < 0)
0065         return false;
0066 
0067     return (separator_id[kcfg_SeparatorCombo->currentIndex()] != Prefs::separator());
0068 }
0069 
0070 bool GeneralOptions::isDefault()
0071 {
0072     if (kcfg_SeparatorCombo->currentIndex() < 0)
0073         return false;
0074     return !strcmp(separator_id[kcfg_SeparatorCombo->currentIndex()], "\t");
0075 }
0076 
0077 void GeneralOptions::updateSettings()
0078 {
0079     if (kcfg_SeparatorCombo->currentIndex() < 0)
0080         return;
0081     Prefs::setSeparator((separator_id[kcfg_SeparatorCombo->currentIndex()]));
0082 }