Changeset View
Changeset View
Standalone View
Standalone View
plugins/impex/csv/kis_csv_export.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (c) 2016 Laszlo Fazekas <mneko@freemail.hu> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or modify | ||||
5 | * it under the terms of the GNU General Public License as published by | ||||
6 | * the Free Software Foundation; either version 2 of the License, or | ||||
7 | * (at your option) any later version. | ||||
8 | * | ||||
9 | * This program is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
12 | * GNU General Public License for more details. | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU General Public License | ||||
15 | * along with this program; if not, write to the Free Software | ||||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
17 | * Boston, MA 02110-1301, USA. | ||||
18 | */ | ||||
19 | | ||||
20 | #include "kis_csv_export.h" | ||||
21 | | ||||
22 | #include <QCheckBox> | ||||
23 | #include <QSlider> | ||||
24 | #include <QMessageBox> | ||||
25 | | ||||
26 | #include <kpluginfactory.h> | ||||
27 | #include <QUrl> | ||||
28 | #include <QApplication> | ||||
29 | | ||||
30 | #include <KisImportExportManager.h> | ||||
31 | #include <KisFilterChain.h> | ||||
32 | #include <KoColorSpaceConstants.h> | ||||
33 | | ||||
34 | #include <KisDocument.h> | ||||
35 | #include <kis_image.h> | ||||
36 | #include <kis_group_layer.h> | ||||
37 | #include <kis_paint_layer.h> | ||||
38 | #include <kis_paint_device.h> | ||||
39 | | ||||
40 | #include "csv_saver.h" | ||||
41 | | ||||
42 | K_PLUGIN_FACTORY_WITH_JSON(KisCSVExportFactory, "krita_csv_export.json", registerPlugin<KisCSVExport>();) | ||||
43 | | ||||
44 | bool checkHomogenity(KisNodeSP root) | ||||
45 | { | ||||
46 | bool res = true; | ||||
47 | KisNodeSP child = root->firstChild(); | ||||
48 | | ||||
49 | while (child) { | ||||
50 | if (child->childCount() > 0) { | ||||
51 | res= false; | ||||
52 | break; | ||||
53 | } | ||||
54 | child = child->nextSibling(); | ||||
55 | } | ||||
56 | return res; | ||||
57 | } | ||||
58 | | ||||
59 | KisCSVExport::KisCSVExport(QObject *parent, const QVariantList &) : KisImportExportFilter(parent) | ||||
60 | { | ||||
61 | } | ||||
62 | | ||||
63 | KisCSVExport::~KisCSVExport() | ||||
64 | { | ||||
65 | } | ||||
66 | | ||||
67 | KisImportExportFilter::ConversionStatus KisCSVExport::convert(const QByteArray& from, const QByteArray& to) | ||||
68 | { | ||||
69 | dbgFile << "CSV export! From:" << from << ", To:" << to << ""; | ||||
70 | | ||||
71 | if (from != "application/x-krita") | ||||
72 | return KisImportExportFilter::NotImplemented; | ||||
73 | | ||||
74 | KisDocument* input = m_chain->inputDocument(); | ||||
75 | QString filename = m_chain->outputFile(); | ||||
76 | | ||||
77 | if (!input) | ||||
78 | return KisImportExportFilter::NoDocumentCreated; | ||||
79 | | ||||
80 | if (!checkHomogenity(input->image()->rootLayer())) { | ||||
81 | if (!m_chain->manager()->getBatchMode()) { | ||||
82 | QMessageBox::critical(0, | ||||
83 | i18nc("@title:window", "CSV Export Error"), | ||||
84 | i18n("Unable to save to the CSV format.\n" | ||||
85 | "The CSV format not supports layer groups or masked layers.")); | ||||
86 | } | ||||
87 | return KisImportExportFilter::InvalidFormat; | ||||
88 | } | ||||
89 | qApp->processEvents(); // For vector layers to be updated | ||||
90 | input->image()->waitForDone(); | ||||
91 | | ||||
92 | if (filename.isEmpty()) return KisImportExportFilter::FileNotFound; | ||||
93 | | ||||
94 | QUrl url = QUrl::fromLocalFile(filename); | ||||
95 | | ||||
96 | CSVSaver kpc(input); | ||||
97 | KisImageBuilder_Result res; | ||||
98 | | ||||
99 | if ((res = kpc.buildAnimation(url, filename)) == KisImageBuilder_RESULT_OK) { | ||||
100 | dbgFile <<"success !"; | ||||
101 | return KisImportExportFilter::OK; | ||||
102 | } | ||||
103 | dbgFile <<" Result =" << res; | ||||
104 | return KisImportExportFilter::InternalError; | ||||
105 | } | ||||
106 | | ||||
107 | #include "kis_csv_export.moc" |