filters

xcfimport.cpp
1/*
2 * Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.org>
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#include <tqstring.h>
20
21#include <xcfimport.h>
22#include <kgenericfactory.h>
23#include <KoDocument.h>
24#include <KoFilterChain.h>
25
26#include <kis_doc.h>
27#include <kis_view.h>
28#include <kis_xcf_converter.h>
29#include <kis_progress_display_interface.h>
30
31typedef KGenericFactory<XCFImport, KoFilter> XCFImportFactory;
32K_EXPORT_COMPONENT_FACTORY(libchalkxcfimport, XCFImportFactory("kofficefilters"))
33
34XCFImport::XCFImport(KoFilter *, const char *, const TQStringList&) : KoFilter()
35{
36}
37
38XCFImport::~XCFImport()
39{
40}
41
42KoFilter::ConversionStatus XCFImport::convert(const TQCString&, const TQCString& to)
43{
44 kdDebug(41008) << "Importing using XCFImport!\n";
45
46 if (to != "application/x-chalk")
47 return KoFilter::BadMimeType;
48
49 KisDoc * doc = dynamic_cast<KisDoc*>(m_chain -> outputDocument());
50 KisView * view = static_cast<KisView*>(doc -> views().getFirst());
51
52 TQString filename = m_chain -> inputFile();
53
54 if (!doc)
55 return KoFilter::CreationError;
56
57 doc -> prepareForImport();
58
59
60 if (!filename.isEmpty()) {
61
62 KURL url(filename);
63
64 if (url.isEmpty())
65 return KoFilter::FileNotFound;
66
67 KisXCFConverter ib(doc, doc -> undoAdapter());
68
69 switch (ib.buildImage(url)) {
70 case KisImageBuilder_RESULT_UNSUPPORTED:
71 return KoFilter::NotImplemented;
72 break;
73 case KisImageBuilder_RESULT_INVALID_ARG:
74 return KoFilter::BadMimeType;
75 break;
76 case KisImageBuilder_RESULT_NO_URI:
77 case KisImageBuilder_RESULT_NOT_LOCAL:
78 return KoFilter::FileNotFound;
79 break;
80 case KisImageBuilder_RESULT_BAD_FETCH:
81 case KisImageBuilder_RESULT_EMPTY:
82 return KoFilter::ParsingError;
83 break;
84 case KisImageBuilder_RESULT_FAILURE:
85 return KoFilter::InternalError;
86 break;
87 case KisImageBuilder_RESULT_OK:
88 doc -> setCurrentImage( ib.image());
89 return KoFilter::OK;
90 default:
91 break;
92 }
93
94 }
95 return KoFilter::StorageCreationError;
96}
97
98#include <xcfimport.moc>
99