Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/plugins/csv/export/csvexporter.cpp
- This file was moved from kmymoney/plugins/csv/export/csvexporterplugin.cpp.
1 | /*************************************************************************** | 1 | /*************************************************************************** | ||
---|---|---|---|---|---|
2 | csvexporterplugin.cpp | 2 | csvexporter.cpp | ||
3 | (based on ofximporterplugin.cpp) | | |||
4 | ------------------- | 3 | ------------------- | ||
5 | begin : Wed Mar 20 2013 | 4 | begin : Wed Mar 20 2013 | ||
6 | copyright : (C) 2013 by Allan Anderson | 5 | copyright : (C) 2013 by Allan Anderson | ||
7 | email : agander93@gmail.com | 6 | email : agander93@gmail.com | ||
8 | ***************************************************************************/ | 7 | ***************************************************************************/ | ||
9 | 8 | | |||
10 | /*************************************************************************** | 9 | /*************************************************************************** | ||
11 | * * | 10 | * * | ||
12 | * This program is free software; you can redistribute it and/or modify * | 11 | * This program is free software; you can redistribute it and/or modify * | ||
13 | * it under the terms of the GNU General Public License as published by * | 12 | * it under the terms of the GNU General Public License as published by * | ||
14 | * the Free Software Foundation; either version 2 of the License, or * | 13 | * the Free Software Foundation; either version 2 of the License, or * | ||
15 | * (at your option) any later version. * | 14 | * (at your option) any later version. * | ||
16 | * * | 15 | * * | ||
17 | ***************************************************************************/ | 16 | ***************************************************************************/ | ||
18 | 17 | | |||
19 | #include "csvexporterplugin.h" | 18 | #include "csvexporter.h" | ||
20 | #include "csvexportdlg.h" | 19 | #include "csvexportdlg.h" | ||
21 | #include "csvwriter.h" | 20 | #include "csvwriter.h" | ||
22 | // ---------------------------------------------------------------------------- | 21 | // ---------------------------------------------------------------------------- | ||
23 | // QT Includes | 22 | // QT Includes | ||
24 | 23 | | |||
25 | #include <QUrl> | 24 | #include <QUrl> | ||
26 | 25 | | |||
27 | // ---------------------------------------------------------------------------- | 26 | // ---------------------------------------------------------------------------- | ||
28 | // KDE Includes | 27 | // KDE Includes | ||
29 | 28 | | |||
29 | #include <KPluginFactory> | ||||
30 | #include <KActionCollection> | 30 | #include <KActionCollection> | ||
31 | #include <KLocalizedString> | 31 | #include <KLocalizedString> | ||
32 | #include <KMessageBox> | 32 | #include <KMessageBox> | ||
33 | #include <KIO/StatJob> | 33 | #include <KIO/StatJob> | ||
34 | 34 | | |||
35 | // ---------------------------------------------------------------------------- | 35 | // ---------------------------------------------------------------------------- | ||
36 | // Project Includes | 36 | // Project Includes | ||
37 | 37 | | |||
38 | CsvExporterPlugin::CsvExporterPlugin() : | 38 | CSVExporter::CSVExporter(QObject *parent, const QVariantList &args) : | ||
39 | KMyMoneyPlugin::Plugin(nullptr, "csvexport"/*must be the same as X-KDE-PluginInfo-Name*/) | 39 | KMyMoneyPlugin::Plugin(parent, "csvexporter"/*must be the same as X-KDE-PluginInfo-Name*/) | ||
40 | { | 40 | { | ||
41 | setComponentName("kmm_csvexport", i18n("CSV exporter")); | 41 | Q_UNUSED(args); | ||
42 | setXMLFile("kmm_csvexport.rc"); | 42 | setComponentName("csvexporter", i18n("CSV exporter")); | ||
43 | setXMLFile("csvexporter.rc"); | ||||
43 | createActions(); | 44 | createActions(); | ||
44 | // For information, announce that we have been loaded. | 45 | // For information, announce that we have been loaded. | ||
45 | qDebug("KMyMoney csvexport plugin loaded"); | 46 | qDebug("Plugins: csvexporter loaded"); | ||
46 | } | 47 | } | ||
47 | 48 | | |||
48 | CsvExporterPlugin::~CsvExporterPlugin() | 49 | CSVExporter::~CSVExporter() | ||
49 | { | 50 | { | ||
51 | qDebug("Plugins: csvexporter unloaded"); | ||||
50 | } | 52 | } | ||
51 | 53 | | |||
52 | void CsvExporterPlugin::createActions() | 54 | void CSVExporter::createActions() | ||
53 | { | 55 | { | ||
54 | m_action = actionCollection()->addAction("file_export_csv"); | 56 | m_action = actionCollection()->addAction("file_export_csv"); | ||
55 | m_action->setText(i18n("&CSV...")); | 57 | m_action->setText(i18n("&CSV...")); | ||
56 | connect(m_action, SIGNAL(triggered(bool)), this, SLOT(slotCsvExport())); | 58 | connect(m_action, &QAction::triggered, this, &CSVExporter::slotCsvExport); | ||
57 | } | 59 | } | ||
58 | 60 | | |||
59 | void CsvExporterPlugin::slotCsvExport() | 61 | void CSVExporter::slotCsvExport() | ||
60 | { | 62 | { | ||
61 | m_dlg = new CsvExportDlg(); | 63 | m_dlg = new CsvExportDlg(); | ||
62 | if (m_dlg->exec()) { | 64 | if (m_dlg->exec()) { | ||
63 | if (okToWriteFile(QUrl::fromUserInput(m_dlg->filename()))) { | 65 | if (okToWriteFile(QUrl::fromUserInput(m_dlg->filename()))) { | ||
64 | m_dlg->setWindowTitle(i18nc("CSV Exporter dialog title", "CSV Exporter")); | 66 | m_dlg->setWindowTitle(i18nc("CSV Exporter dialog title", "CSV Exporter")); | ||
65 | CsvWriter* writer = new CsvWriter; | 67 | CsvWriter* writer = new CsvWriter; | ||
66 | writer->m_plugin = this; | 68 | writer->m_plugin = this; | ||
67 | connect(writer, SIGNAL(signalProgress(int,int)), m_dlg, SLOT(slotStatusProgressBar(int,int))); | 69 | connect(writer, &CsvWriter::signalProgress, m_dlg, &CsvExportDlg::slotStatusProgressBar); | ||
68 | 70 | | |||
69 | writer->write(m_dlg->filename(), m_dlg->accountId(), | 71 | writer->write(m_dlg->filename(), m_dlg->accountId(), | ||
70 | m_dlg->accountSelected(), m_dlg->categorySelected(), | 72 | m_dlg->accountSelected(), m_dlg->categorySelected(), | ||
71 | m_dlg->startDate(), m_dlg->endDate(), | 73 | m_dlg->startDate(), m_dlg->endDate(), | ||
72 | m_dlg->separator()); | 74 | m_dlg->separator()); | ||
73 | } | 75 | } | ||
74 | } | 76 | } | ||
75 | } | 77 | } | ||
76 | 78 | | |||
77 | bool CsvExporterPlugin::okToWriteFile(const QUrl &url) | 79 | bool CSVExporter::okToWriteFile(const QUrl &url) | ||
78 | { | 80 | { | ||
79 | // check if the file exists and warn the user | 81 | // check if the file exists and warn the user | ||
80 | bool reallySaveFile = true; | 82 | bool reallySaveFile = true; | ||
81 | 83 | | |||
82 | bool fileExists = false; | 84 | bool fileExists = false; | ||
83 | 85 | | |||
84 | if (url.isValid()) { | 86 | if (url.isValid()) { | ||
85 | short int detailLevel = 0; // Lowest level: file/dir/symlink/none | 87 | short int detailLevel = 0; // Lowest level: file/dir/symlink/none | ||
86 | KIO::StatJob* statjob = KIO::stat(url, KIO::StatJob::SourceSide, detailLevel); | 88 | KIO::StatJob* statjob = KIO::stat(url, KIO::StatJob::SourceSide, detailLevel); | ||
87 | bool noerror = statjob->exec(); | 89 | bool noerror = statjob->exec(); | ||
88 | if (noerror) { | 90 | if (noerror) { | ||
89 | // We want a file | 91 | // We want a file | ||
90 | fileExists = !statjob->statResult().isDir(); | 92 | fileExists = !statjob->statResult().isDir(); | ||
91 | } | 93 | } | ||
92 | } | 94 | } | ||
93 | 95 | | |||
94 | if (fileExists) { | 96 | if (fileExists) { | ||
95 | if (KMessageBox::warningYesNo(0, QString("<qt>") + i18n("The file <b>%1</b> already exists. Do you really want to overwrite it?", url.toDisplayString(QUrl::PreferLocalFile)) + QString("</qt>"), i18n("File already exists")) != KMessageBox::Yes) | 97 | if (KMessageBox::warningYesNo(0, i18n("<qt>The file <b>%1</b> already exists. Do you really want to overwrite it?</qt>", url.toDisplayString(QUrl::PreferLocalFile)), i18n("File already exists")) != KMessageBox::Yes) | ||
96 | reallySaveFile = false; | 98 | reallySaveFile = false; | ||
97 | } | 99 | } | ||
98 | return reallySaveFile; | 100 | return reallySaveFile; | ||
99 | } | 101 | } | ||
102 | | ||||
103 | K_PLUGIN_FACTORY_WITH_JSON(CSVExporterFactory, "csvexporter.json", registerPlugin<CSVExporter>();) | ||||
104 | | ||||
105 | #include "csvexporter.moc" |