Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/plugins/gnc/import/gncimporter.cpp
Show All 29 Lines | |||||
30 | #include <KPluginFactory> | 30 | #include <KPluginFactory> | ||
31 | #include <KMessageBox> | 31 | #include <KMessageBox> | ||
32 | 32 | | |||
33 | // ---------------------------------------------------------------------------- | 33 | // ---------------------------------------------------------------------------- | ||
34 | // Project Includes | 34 | // Project Includes | ||
35 | 35 | | |||
36 | #include "mymoneygncreader.h" | 36 | #include "mymoneygncreader.h" | ||
37 | #include "viewinterface.h" | 37 | #include "viewinterface.h" | ||
38 | #include "appinterface.h" | ||||
38 | #include "mymoneyfile.h" | 39 | #include "mymoneyfile.h" | ||
39 | #include "mymoneyexception.h" | 40 | #include "mymoneyexception.h" | ||
40 | #include "mymoneystoragemgr.h" | 41 | #include "mymoneystoragemgr.h" | ||
41 | 42 | | |||
42 | class MyMoneyStatement; | 43 | class MyMoneyStatement; | ||
43 | 44 | | |||
44 | GNCImporter::GNCImporter(QObject *parent, const QVariantList &args) : | 45 | GNCImporter::GNCImporter(QObject *parent, const QVariantList &args) : | ||
45 | KMyMoneyPlugin::Plugin(parent, "gncimporter"/*must be the same as X-KDE-PluginInfo-Name*/) | 46 | KMyMoneyPlugin::Plugin(parent, "gncimporter"/*must be the same as X-KDE-PluginInfo-Name*/) | ||
46 | { | 47 | { | ||
47 | Q_UNUSED(args) | 48 | Q_UNUSED(args) | ||
48 | setComponentName("gncimporter", i18n("GnuCash importer")); | 49 | setComponentName("gncimporter", i18n("GnuCash importer")); | ||
49 | setXMLFile("gncimporter.rc"); | | |||
50 | createActions(); | | |||
51 | // For information, announce that we have been loaded. | 50 | // For information, announce that we have been loaded. | ||
52 | qDebug("Plugins: gncimporter loaded"); | 51 | qDebug("Plugins: gncimporter loaded"); | ||
53 | } | 52 | } | ||
54 | 53 | | |||
55 | GNCImporter::~GNCImporter() | 54 | GNCImporter::~GNCImporter() | ||
56 | { | 55 | { | ||
57 | qDebug("Plugins: gncimporter unloaded"); | 56 | qDebug("Plugins: gncimporter unloaded"); | ||
58 | } | 57 | } | ||
59 | 58 | | |||
60 | void GNCImporter::createActions() | 59 | bool GNCImporter::open(MyMoneyStorageMgr *storage, const QUrl &url) | ||
61 | { | 60 | { | ||
62 | m_action = actionCollection()->addAction("file_import_gnc"); | 61 | Q_UNUSED(url) | ||
63 | m_action->setText(i18n("GnuCash...")); | 62 | Q_UNUSED(storage) | ||
64 | connect(m_action, &QAction::triggered, this, &GNCImporter::slotGNCImport); | 63 | return false; | ||
65 | } | 64 | } | ||
66 | 65 | | |||
67 | void GNCImporter::slotGNCImport() | 66 | bool GNCImporter::save(const QUrl &url) | ||
68 | { | 67 | { | ||
69 | m_action->setEnabled(false); | 68 | Q_UNUSED(url) | ||
69 | return false; | ||||
70 | } | ||||
70 | 71 | | |||
71 | if (viewInterface()->fileOpen()) { | 72 | IMyMoneyOperationsFormat* GNCImporter::reader() | ||
72 | KMessageBox::information(nullptr, i18n("You cannot import GnuCash data into an existing file. Please close it.")); | 73 | { | ||
73 | m_action->setEnabled(true); | 74 | return new MyMoneyGncReader; | ||
74 | return; | | |||
75 | } | 75 | } | ||
76 | 76 | | |||
77 | auto url = QFileDialog::getOpenFileUrl(nullptr, QString(), QUrl(), i18n("GnuCash files (*.gnucash *.xac *.gnc);;All files (*)")); | 77 | QString GNCImporter::formatName() const | ||
78 | if (url.isLocalFile()) { | 78 | { | ||
79 | auto pReader = new MyMoneyGncReader; | 79 | return QStringLiteral("GNC"); | ||
80 | if (viewInterface()->readFile(url, pReader)) | | |||
81 | viewInterface()->slotRefreshViews(); | | |||
82 | } | 80 | } | ||
83 | 81 | | |||
84 | m_action->setEnabled(true); | 82 | QString GNCImporter::fileExtension() const | ||
83 | { | ||||
84 | return i18n("GnuCash files (*.gnucash *.xac *.gnc)"); | ||||
85 | } | 85 | } | ||
86 | 86 | | |||
87 | K_PLUGIN_FACTORY_WITH_JSON(GNCImporterFactory, "gncimporter.json", registerPlugin<GNCImporter>();) | 87 | K_PLUGIN_FACTORY_WITH_JSON(GNCImporterFactory, "gncimporter.json", registerPlugin<GNCImporter>();) | ||
88 | 88 | | |||
89 | #include "gncimporter.moc" | 89 | #include "gncimporter.moc" |