filters

magickimport.cpp

00001 /*
00002  *  Copyright (c) 2002 Patrick Julien <freak@codepimps.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 <magickimport.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_image_magick_converter.h>
00029 #include <kis_progress_display_interface.h>
00030 #include <kis_image.h>
00031 #include <kis_layer.h>
00032 
00033 typedef KGenericFactory<MagickImport, KoFilter> MagickImportFactory;
00034 K_EXPORT_COMPONENT_FACTORY(libkritagmagickimport, MagickImportFactory("kofficefilters"))
00035 
00036 MagickImport::MagickImport(KoFilter *, const char *, const QStringList&) : KoFilter()
00037 {
00038 }
00039 
00040 MagickImport::~MagickImport()
00041 {
00042 }
00043 
00044 KoFilter::ConversionStatus MagickImport::convert(const QCString&, const QCString& to)
00045 {
00046     kdDebug(41008) << "Importing using MagickImport!\n";
00047 
00048     if (to != "application/x-krita")
00049         return KoFilter::BadMimeType;
00050 
00051     KisDoc * doc = dynamic_cast<KisDoc*>(m_chain -> outputDocument());
00052     KisView * view = static_cast<KisView*>(doc -> views().getFirst());
00053     
00054     QString filename = m_chain -> inputFile();
00055     
00056     if (!doc)
00057         return KoFilter::CreationError;
00058 
00059     doc -> prepareForImport();
00060         
00061 
00062     if (!filename.isEmpty()) {
00063     
00064         KURL url;
00065         url.setPath(filename);
00066 
00067         if (url.isEmpty())
00068             return KoFilter::FileNotFound;
00069             
00070         KisImageMagickConverter ib(doc, doc -> undoAdapter());
00071 
00072         if (view != 0)
00073             view -> canvasSubject() ->  progressDisplay() -> setSubject(&ib, false, true);
00074 
00075         switch (ib.buildImage(url)) {
00076             case KisImageBuilder_RESULT_UNSUPPORTED:
00077                 return KoFilter::NotImplemented;
00078                 break;
00079             case KisImageBuilder_RESULT_INVALID_ARG:
00080                 return KoFilter::BadMimeType;
00081                 break;
00082             case KisImageBuilder_RESULT_NO_URI:
00083             case KisImageBuilder_RESULT_NOT_LOCAL:
00084                 return KoFilter::FileNotFound;
00085                 break;
00086             case KisImageBuilder_RESULT_BAD_FETCH:
00087             case KisImageBuilder_RESULT_EMPTY:
00088                 return KoFilter::ParsingError;                
00089                 break;
00090             case KisImageBuilder_RESULT_FAILURE:
00091                 return KoFilter::InternalError;
00092                 break;
00093             case KisImageBuilder_RESULT_OK:
00094                 doc -> setCurrentImage( ib.image());
00095                 return KoFilter::OK;
00096             default:
00097                 break;
00098         }
00099 
00100     }
00101     return KoFilter::StorageCreationError;
00102 }
00103 
00104 #include <magickimport.moc>
00105 
KDE Home | KDE Accessibility Home | Description of Access Keys