File indexing completed on 2024-05-12 16:46:29

0001 /***************************************************************************
0002     Copyright (C) 2003-2009 Robby Stephenson <robby@periapsis.org>
0003  ***************************************************************************/
0004 
0005 /***************************************************************************
0006  *                                                                         *
0007  *   This program is free software; you can redistribute it and/or         *
0008  *   modify it under the terms of the GNU General Public License as        *
0009  *   published by the Free Software Foundation; either version 2 of        *
0010  *   the License or (at your option) version 3 or any later version        *
0011  *   accepted by the membership of KDE e.V. (or its successor approved     *
0012  *   by the membership of KDE e.V.), which shall act as a proxy            *
0013  *   defined in Section 14 of version 3 of the license.                    *
0014  *                                                                         *
0015  *   This program is distributed in the hope that it will be useful,       *
0016  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0017  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0018  *   GNU General Public License for more details.                          *
0019  *                                                                         *
0020  *   You should have received a copy of the GNU General Public License     *
0021  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
0022  *                                                                         *
0023  ***************************************************************************/
0024 
0025 #ifndef TELLICO_CSVIMPORTER_H
0026 #define TELLICO_CSVIMPORTER_H
0027 
0028 #include "textimporter.h"
0029 #include "../datavectors.h"
0030 
0031 class CSVImporterWidget;
0032 
0033 class KComboBox;
0034 
0035 class QSpinBox;
0036 class QLineEdit;
0037 class QPushButton;
0038 class QCheckBox;
0039 class QRadioButton;
0040 class QTableWidget;
0041 
0042 namespace Tellico {
0043   namespace GUI {
0044     class CollectionTypeCombo;
0045   }
0046   class CSVParser;
0047   namespace Import {
0048 
0049 /**
0050  * @author Robby Stephenson
0051  */
0052 class CSVImporter : public TextImporter {
0053 Q_OBJECT
0054 
0055 public:
0056   /**
0057    */
0058   CSVImporter(const QUrl& url);
0059   ~CSVImporter();
0060 
0061   /**
0062    * @return A pointer to a @ref Data::Collection, or 0 if none can be created.
0063    */
0064   virtual Data::CollPtr collection() Q_DECL_OVERRIDE;
0065   /**
0066    * The CSVImporter can import any type known to Tellico.
0067    */
0068   virtual bool canImport(int type) const Q_DECL_OVERRIDE { Q_UNUSED(type); return true; }
0069   /**
0070    */
0071   virtual QWidget* widget(QWidget* parent) Q_DECL_OVERRIDE;
0072 
0073   virtual bool validImport() const Q_DECL_OVERRIDE;
0074 
0075 public Q_SLOTS:
0076   void slotActionChanged(int action) Q_DECL_OVERRIDE;
0077   void slotCancel() Q_DECL_OVERRIDE;
0078 
0079 private Q_SLOTS:
0080   void slotTypeChanged();
0081   void slotFieldChanged(int idx);
0082   void slotFirstRowHeader(bool b);
0083   void slotDelimiter();
0084   void slotCurrentChanged(int row, int col);
0085   void slotHeaderClicked(int col);
0086   void slotSelectColumn(int col);
0087   void slotSetColumnTitle();
0088 
0089 private:
0090   void fillTable();
0091   void updateHeader();
0092   void createCollection();
0093   void updateFieldCombo();
0094 
0095   Data::CollPtr m_coll;
0096   Data::CollPtr m_existingCollection; // used to grab fields from current collection in window
0097   bool m_firstRowHeader;
0098   QString m_delimiter;
0099   QString m_colDelimiter;
0100   QString m_rowDelimiter;
0101   bool m_cancelled;
0102 
0103   QWidget* m_widget;
0104   GUI::CollectionTypeCombo* m_comboColl;
0105   QCheckBox* m_checkFirstRowHeader;
0106   QRadioButton* m_radioComma;
0107   QRadioButton* m_radioSemicolon;
0108   QRadioButton* m_radioTab;
0109   QRadioButton* m_radioOther;
0110   QLineEdit* m_editOther;
0111   QLineEdit* m_editColDelimiter;
0112   QLineEdit* m_editRowDelimiter;
0113   QTableWidget* m_table;
0114   QSpinBox* m_colSpinBox;
0115   KComboBox* m_comboField;
0116   QPushButton* m_setColumnBtn;
0117   bool m_hasAssignedFields;
0118   bool m_isLibraryThing;
0119 
0120   CSVParser* m_parser;
0121 };
0122 
0123   } // end namespace
0124 } // end namespace
0125 #endif