Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/plugins/csv/import/csvimporter.cpp
- This file was moved from kmymoney/plugins/csv/import/csvimporterplugin.cpp.
1 | /*************************************************************************** | 1 | /*************************************************************************** | ||
---|---|---|---|---|---|
2 | csvimporterplugin.cpp | 2 | csvimporter.cpp | ||
3 | (based on ofximporterplugin.cpp) | | |||
4 | ------------------- | 3 | ------------------- | ||
5 | begin : Sat Jan 01 2010 | 4 | begin : Sat Jan 01 2010 | ||
6 | copyright : (C) 2010 by Allan Anderson | 5 | copyright : (C) 2010 by Allan Anderson | ||
7 | email : agander93@gmail.com | 6 | email : agander93@gmail.com | ||
8 | copyright : (C) 2016 by Łukasz Wojniłowicz | 7 | copyright : (C) 2016 by Łukasz Wojniłowicz | ||
9 | email : lukasz.wojnilowicz@gmail.com | 8 | email : lukasz.wojnilowicz@gmail.com | ||
10 | ***************************************************************************/ | 9 | ***************************************************************************/ | ||
11 | 10 | | |||
12 | /*************************************************************************** | 11 | /*************************************************************************** | ||
13 | * * | 12 | * * | ||
14 | * This program is free software; you can redistribute it and/or modify * | 13 | * This program is free software; you can redistribute it and/or modify * | ||
15 | * it under the terms of the GNU General Public License as published by * | 14 | * it under the terms of the GNU General Public License as published by * | ||
16 | * the Free Software Foundation; either version 2 of the License, or * | 15 | * the Free Software Foundation; either version 2 of the License, or * | ||
17 | * (at your option) any later version. * | 16 | * (at your option) any later version. * | ||
18 | * * | 17 | * * | ||
19 | ***************************************************************************/ | 18 | ***************************************************************************/ | ||
20 | 19 | | |||
21 | #include "csvimporterplugin.h" | 20 | #include "csvimporter.h" | ||
22 | 21 | | |||
23 | // ---------------------------------------------------------------------------- | 22 | // ---------------------------------------------------------------------------- | ||
24 | // QT Includes | 23 | // QT Includes | ||
25 | 24 | | |||
26 | #include <QFile> | 25 | #include <QFile> | ||
27 | 26 | | |||
28 | // ---------------------------------------------------------------------------- | 27 | // ---------------------------------------------------------------------------- | ||
29 | // KDE Includes | 28 | // KDE Includes | ||
30 | 29 | | |||
30 | #include <KPluginFactory> | ||||
31 | #include <KActionCollection> | 31 | #include <KActionCollection> | ||
32 | #include <KLocalizedString> | 32 | #include <KLocalizedString> | ||
33 | 33 | | |||
34 | // ---------------------------------------------------------------------------- | 34 | // ---------------------------------------------------------------------------- | ||
35 | // Project Includes | 35 | // Project Includes | ||
36 | 36 | | |||
37 | #include "csvimporter.h" | 37 | #include "core/csvimportercore.h" | ||
38 | #include "csvwizard.h" | 38 | #include "csvwizard.h" | ||
39 | #include "statementinterface.h" | 39 | #include "statementinterface.h" | ||
40 | 40 | | |||
41 | CsvImporterPlugin::CsvImporterPlugin() : | 41 | CSVImporter::CSVImporter(QObject *parent, const QVariantList &args) : | ||
42 | KMyMoneyPlugin::Plugin(nullptr, "csvimport"/*must be the same as X-KDE-PluginInfo-Name*/) | 42 | KMyMoneyPlugin::Plugin(parent, "csvimporter"/*must be the same as X-KDE-PluginInfo-Name*/) | ||
43 | { | 43 | { | ||
44 | setComponentName("kmm_csvimport", i18n("CSV importer")); | 44 | Q_UNUSED(args); | ||
45 | setXMLFile("kmm_csvimport.rc"); | 45 | setComponentName("csvimporter", i18n("CSV importer")); | ||
46 | setXMLFile("csvimporter.rc"); | ||||
46 | createActions(); | 47 | createActions(); | ||
47 | // For information, announce that we have been loaded. | 48 | // For information, announce that we have been loaded. | ||
48 | qDebug("KMyMoney csvimport plugin loaded"); | 49 | qDebug("Plugins: csvimporter loaded"); | ||
49 | } | 50 | } | ||
50 | 51 | | |||
51 | CsvImporterPlugin::~CsvImporterPlugin() | 52 | CSVImporter::~CSVImporter() | ||
52 | { | 53 | { | ||
54 | qDebug("Plugins: csvimporter unloaded"); | ||||
53 | } | 55 | } | ||
54 | 56 | | |||
55 | void CsvImporterPlugin::createActions() | 57 | void CSVImporter::createActions() | ||
56 | { | 58 | { | ||
57 | m_action = actionCollection()->addAction("file_import_csv"); | 59 | m_action = actionCollection()->addAction("file_import_csv"); | ||
58 | m_action->setText(i18n("CSV...")); | 60 | m_action->setText(i18n("CSV...")); | ||
59 | connect(m_action, SIGNAL(triggered(bool)), this, SLOT(startWizardRun())); | 61 | connect(m_action, &QAction::triggered, this, &CSVImporter::startWizardRun); | ||
60 | } | 62 | } | ||
61 | 63 | | |||
62 | void CsvImporterPlugin::startWizardRun() | 64 | void CSVImporter::startWizardRun() | ||
63 | { | 65 | { | ||
64 | m_action->setEnabled(false); | 66 | m_action->setEnabled(false); | ||
65 | m_importer = new CSVImporter; | 67 | m_importer = new CSVImporterCore; | ||
66 | m_wizard = new CSVWizard(this, m_importer); | 68 | m_wizard = new CSVWizard(this, m_importer); | ||
67 | m_silent = false; | 69 | m_silent = false; | ||
68 | connect(m_wizard, SIGNAL(statementReady(MyMoneyStatement&)), this, SLOT(slotGetStatement(MyMoneyStatement&))); | 70 | connect(m_wizard, &CSVWizard::statementReady, this, &CSVImporter::slotGetStatement); | ||
69 | m_action->setEnabled(false);// don't allow further plugins to start while this is open | 71 | m_action->setEnabled(false);// don't allow further plugins to start while this is open | ||
70 | } | 72 | } | ||
71 | 73 | | |||
72 | bool CsvImporterPlugin::slotGetStatement(MyMoneyStatement& s) | 74 | bool CSVImporter::slotGetStatement(MyMoneyStatement& s) | ||
73 | { | 75 | { | ||
74 | bool ret = statementInterface()->import(s, m_silent); | 76 | bool ret = statementInterface()->import(s, m_silent); | ||
75 | delete m_importer; | 77 | delete m_importer; | ||
76 | return ret; | 78 | return ret; | ||
77 | } | 79 | } | ||
78 | 80 | | |||
79 | QString CsvImporterPlugin::formatName() const | 81 | QString CSVImporter::formatName() const | ||
80 | { | 82 | { | ||
81 | return QLatin1String("CSV"); | 83 | return QLatin1String("CSV"); | ||
82 | } | 84 | } | ||
83 | 85 | | |||
84 | QString CsvImporterPlugin::formatFilenameFilter() const | 86 | QString CSVImporter::formatFilenameFilter() const | ||
85 | { | 87 | { | ||
86 | return "*.csv"; | 88 | return "*.csv"; | ||
87 | } | 89 | } | ||
88 | 90 | | |||
89 | bool CsvImporterPlugin::isMyFormat(const QString& filename) const | 91 | bool CSVImporter::isMyFormat(const QString& filename) const | ||
90 | { | 92 | { | ||
91 | // filename is considered a CSV file if it can be opened | 93 | // filename is considered a CSV file if it can be opened | ||
92 | // and the filename ends in ".csv". | 94 | // and the filename ends in ".csv". | ||
93 | bool result = false; | 95 | bool result = false; | ||
94 | 96 | | |||
95 | QFile f(filename); | 97 | QFile f(filename); | ||
96 | if (f.open(QIODevice::ReadOnly | QIODevice::Text)) { | 98 | if (f.open(QIODevice::ReadOnly | QIODevice::Text)) { | ||
97 | result = f.fileName().endsWith(QLatin1String(".csv")); | 99 | result = f.fileName().endsWith(QLatin1String(".csv")); | ||
98 | f.close(); | 100 | f.close(); | ||
99 | } | 101 | } | ||
100 | 102 | | |||
101 | return result; | 103 | return result; | ||
102 | } | 104 | } | ||
103 | 105 | | |||
104 | bool CsvImporterPlugin::import(const QString& filename) | 106 | bool CSVImporter::import(const QString& filename) | ||
105 | { | 107 | { | ||
106 | bool rc = true; | 108 | bool rc = true; | ||
107 | m_importer = new CSVImporter; | 109 | m_importer = new CSVImporterCore; | ||
108 | m_wizard = new CSVWizard(this, m_importer); | 110 | m_wizard = new CSVWizard(this, m_importer); | ||
109 | m_wizard->presetFilename(filename); | 111 | m_wizard->presetFilename(filename); | ||
110 | m_silent = false; | 112 | m_silent = false; | ||
111 | connect(m_wizard, SIGNAL(statementReady(MyMoneyStatement&)), this, SLOT(slotGetStatement(MyMoneyStatement&))); | 113 | connect(m_wizard, &CSVWizard::statementReady, this, &CSVImporter::slotGetStatement); | ||
112 | return rc; | 114 | return rc; | ||
113 | } | 115 | } | ||
114 | 116 | | |||
115 | QString CsvImporterPlugin::lastError() const | 117 | QString CSVImporter::lastError() const | ||
116 | { | 118 | { | ||
117 | return QString(); | 119 | return QString(); | ||
118 | } | 120 | } | ||
121 | | ||||
122 | K_PLUGIN_FACTORY_WITH_JSON(CSVImporterFactory, "csvimporter.json", registerPlugin<CSVImporter>();) | ||||
123 | | ||||
124 | #include "csvimporter.moc" |