File indexing completed on 2025-01-19 04:46:30

0001 /*
0002   This file is part of KAddressBook.
0003   SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org>
0004 
0005   SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #pragma once
0009 
0010 #include <KAddressBookImportExport/ContactFields>
0011 
0012 #include <QDialog>
0013 
0014 #include <QList>
0015 
0016 class QComboBox;
0017 class QLineEdit;
0018 class KUrlRequester;
0019 
0020 class QButtonGroup;
0021 class QCheckBox;
0022 class QCsvModel;
0023 class QTableView;
0024 class QTextCodec;
0025 
0026 class CSVImportDialog : public QDialog
0027 {
0028     Q_OBJECT
0029 
0030 public:
0031     explicit CSVImportDialog(QWidget *parent = nullptr);
0032     ~CSVImportDialog() override;
0033 
0034     KContacts::AddresseeList contacts() const;
0035 
0036 private:
0037     void setFile(const QString &);
0038     void setUrl(const QUrl &);
0039     void urlChanged(const QString &);
0040 
0041     void customDelimiterChanged();
0042     void customDelimiterChanged(const QString &, bool reload = true);
0043     void delimiterClicked(int, bool reload = true);
0044     void textQuoteChanged(const QString &, bool reload = true);
0045     void skipFirstRowChanged(bool, bool reload = true);
0046     void codecChanged(bool reload = true);
0047 
0048     void modelFinishedLoading();
0049     void finalizeApplyTemplate();
0050 
0051     void slotSaveTemplate();
0052     void slotApplyTemplate();
0053     void slotOk();
0054 
0055 private:
0056     void applyTemplate();
0057     void saveTemplate();
0058 
0059     QTableView *mTable = nullptr;
0060     QButtonGroup *mDelimiterGroup = nullptr;
0061     QLineEdit *mDelimiterEdit = nullptr;
0062     QLineEdit *mDatePatternEdit = nullptr;
0063     QComboBox *mComboQuote = nullptr;
0064     QComboBox *mCodecCombo = nullptr;
0065     QCheckBox *mSkipFirstRow = nullptr;
0066     KUrlRequester *mUrlRequester = nullptr;
0067     QCsvModel *mModel = nullptr;
0068 
0069     void initGUI();
0070 
0071     void reloadCodecs();
0072     QList<QTextCodec *> mCodecs;
0073 
0074     QChar mTextQuote;
0075     QString mDelimiter;
0076     QMap<QString, uint> mTypeMap;
0077     QIODevice *mDevice = nullptr;
0078     KAddressBookImportExport::ContactFields::Fields mFieldSelection;
0079     QPushButton *mUser1Button = nullptr;
0080     QPushButton *mUser2Button = nullptr;
0081     QPushButton *mOkButton = nullptr;
0082 };