File indexing completed on 2024-05-12 16:42:03

0001 /*
0002     SPDX-FileCopyrightText: 2001-2002 Michael Edwardes <mte@users.sourceforge.net>
0003     SPDX-FileCopyrightText: 2001-2002 Felix Rodriguez <frodriguez@users.sourceforge.net>
0004     SPDX-FileCopyrightText: 2017 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #include "kchooseimportexportdlg.h"
0009 
0010 // ----------------------------------------------------------------------------
0011 // QT Includes
0012 
0013 #include <QLabel>
0014 
0015 // ----------------------------------------------------------------------------
0016 // KDE Includes
0017 
0018 #include <KConfig>
0019 #include <KConfigGroup>
0020 #include <KSharedConfig>
0021 #include <KLocalizedString>
0022 
0023 // ----------------------------------------------------------------------------
0024 // Project Includes
0025 
0026 #include "ui_kchooseimportexportdlg.h"
0027 
0028 class KChooseImportExportDlgPrivate
0029 {
0030     Q_DISABLE_COPY(KChooseImportExportDlgPrivate)
0031 
0032 public:
0033     KChooseImportExportDlgPrivate() :
0034         ui(new Ui::KChooseImportExportDlg)
0035     {
0036     }
0037 
0038     ~KChooseImportExportDlgPrivate()
0039     {
0040         delete ui;
0041     }
0042 
0043     void readConfig()
0044     {
0045         auto config = KSharedConfig::openConfig();
0046         auto grp = config->group("Last Use Settings");
0047         m_lastType = grp.readEntry("KChooseImportExportDlg_LastType");
0048     }
0049 
0050     void writeConfig() const
0051     {
0052         auto config = KSharedConfig::openConfig();
0053         auto grp = config->group("Last Use Settings");
0054         grp.writeEntry("KChooseImportExportDlg_LastType", ui->typeCombo->currentText());
0055         config->sync();
0056     }
0057 
0058     Ui::KChooseImportExportDlg *ui;
0059     QString m_lastType;
0060 };
0061 
0062 
0063 KChooseImportExportDlg::KChooseImportExportDlg(int type, QWidget *parent) :
0064     QDialog(parent),
0065     d_ptr(new KChooseImportExportDlgPrivate)
0066 {
0067     Q_D(KChooseImportExportDlg);
0068     d->ui->setupUi(this);
0069     setModal(true);
0070 
0071     if (type == 0) { // import
0072         d->ui->topLabel->setText(i18n("Please choose the type of import you wish to perform.  A simple explanation\n"
0073                                       "of the import type is available at the bottom of the screen and is updated when\n"
0074                                       "you select an item from the choice box."
0075                                       "\n\nOnce you have chosen an import type please press the OK button."));
0076         d->ui->promptLabel->setText(i18n("Choose import type:"));
0077         setWindowTitle(i18n("Choose Import Type Dialog"));
0078     } else { // export
0079         d->ui->topLabel->setText(i18n("Please choose the type of export you wish to perform.  A simple explanation\n"
0080                                       "of the export type is available at the bottom of the screen and is updated when\n"
0081                                       "you select an item from the choice box."
0082                                       "\n\nOnce you have chosen an export type please press the OK button."));
0083         d->ui->promptLabel->setText(i18n("Choose export type:"));
0084         setWindowTitle(i18n("Choose Export Type Dialog"));
0085     }
0086 
0087     d->readConfig();
0088     slotTypeActivated(d->m_lastType);
0089     d->ui->typeCombo->setCurrentItem(((d->m_lastType == "QIF") ? i18n("QIF") : i18n("CSV")), false);
0090 
0091     connect(d->ui->typeCombo, static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::activated), this, &KChooseImportExportDlg::slotTypeActivated);
0092 }
0093 
0094 KChooseImportExportDlg::~KChooseImportExportDlg()
0095 {
0096     Q_D(KChooseImportExportDlg);
0097     d->writeConfig();
0098     delete d;
0099 }
0100 
0101 void KChooseImportExportDlg::slotTypeActivated(const QString& text)
0102 {
0103     Q_D(KChooseImportExportDlg);
0104     if (text == "QIF") {
0105         d->ui->descriptionLabel->setText(i18n("QIF files are created by the popular accounting program Quicken.\n"
0106                                               "Another dialog will appear, if you choose this type, asking for further\n"
0107                                               "information relevant to the Quicken format."));
0108     } else {
0109         d->ui->descriptionLabel->setText(i18n("The CSV type uses a comma delimited text file that can be used by\n"
0110                                               "most popular spreadsheet programs available for Linux and other operating\n"
0111                                               "systems."));
0112     }
0113 }
0114 
0115 QString KChooseImportExportDlg::importExportType() const
0116 {
0117     Q_D(const KChooseImportExportDlg);
0118     return d->ui->typeCombo->currentText();
0119 }