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