filters

xcfimport.cpp

00001 /*
00002  *  Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.org>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018  */
00019 #include <qstring.h>
00020 
00021 #include <xcfimport.h>
00022 #include <kgenericfactory.h>
00023 #include <KoDocument.h>
00024 #include <KoFilterChain.h>
00025 
00026 #include <kis_doc.h>
00027 #include <kis_view.h>
00028 #include <kis_xcf_converter.h>
00029 #include <kis_progress_display_interface.h>
00030 
00031 typedef KGenericFactory<XCFImport, KoFilter> XCFImportFactory;
00032 K_EXPORT_COMPONENT_FACTORY(libkritaxcfimport, XCFImportFactory("kofficefilters"))
00033 
00034 XCFImport::XCFImport(KoFilter *, const char *, const QStringList&) : KoFilter()
00035 {
00036 }
00037 
00038 XCFImport::~XCFImport()
00039 {
00040 }
00041 
00042 KoFilter::ConversionStatus XCFImport::convert(const QCString&, const QCString& to)
00043 {
00044     kdDebug(41008) << "Importing using XCFImport!\n";
00045 
00046     if (to != "application/x-krita")
00047         return KoFilter::BadMimeType;
00048 
00049     KisDoc * doc = dynamic_cast<KisDoc*>(m_chain -> outputDocument());
00050     KisView * view = static_cast<KisView*>(doc -> views().getFirst());
00051 
00052     QString filename = m_chain -> inputFile();
00053 
00054     if (!doc)
00055         return KoFilter::CreationError;
00056 
00057     doc -> prepareForImport();
00058 
00059 
00060     if (!filename.isEmpty()) {
00061 
00062         KURL url(filename);
00063 
00064         if (url.isEmpty())
00065             return KoFilter::FileNotFound;
00066 
00067         KisXCFConverter ib(doc, doc -> undoAdapter());
00068 
00069         switch (ib.buildImage(url)) {
00070             case KisImageBuilder_RESULT_UNSUPPORTED:
00071                 return KoFilter::NotImplemented;
00072                 break;
00073             case KisImageBuilder_RESULT_INVALID_ARG:
00074                 return KoFilter::BadMimeType;
00075                 break;
00076             case KisImageBuilder_RESULT_NO_URI:
00077             case KisImageBuilder_RESULT_NOT_LOCAL:
00078                 return KoFilter::FileNotFound;
00079                 break;
00080             case KisImageBuilder_RESULT_BAD_FETCH:
00081             case KisImageBuilder_RESULT_EMPTY:
00082                 return KoFilter::ParsingError;
00083                 break;
00084             case KisImageBuilder_RESULT_FAILURE:
00085                 return KoFilter::InternalError;
00086                 break;
00087             case KisImageBuilder_RESULT_OK:
00088                 doc -> setCurrentImage( ib.image());
00089                 return KoFilter::OK;
00090             default:
00091                 break;
00092         }
00093 
00094     }
00095     return KoFilter::StorageCreationError;
00096 }
00097 
00098 #include <xcfimport.moc>
00099 
KDE Home | KDE Accessibility Home | Description of Access Keys