Warning, file /office/calligra/libs/main/KoFilterManager.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* This file is part of the KDE project
0002    Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
0003                  2000, 2001 Werner Trobin <trobin@kde.org>
0004    Copyright (C) 2004 Nicolas Goutte <goutte@kde.org>
0005 
0006 This library is free software; you can redistribute it and/or
0007 modify it under the terms of the GNU Library General Public
0008 License as published by the Free Software Foundation; either
0009 version 2 of the License, or (at your option) any later version.
0010 
0011 This library is distributed in the hope that it will be useful,
0012 but WITHOUT ANY WARRANTY; without even the implied warranty of
0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014 Library General Public License for more details.
0015 
0016 You should have received a copy of the GNU Library General Public License
0017 along with this library; see the file COPYING.LIB.  If not, write to
0018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019 Boston, MA 02110-1301, USA.
0020 */
0021 
0022 #ifndef __KO_FILTER_MANAGER_H__
0023 #define __KO_FILTER_MANAGER_H__
0024 
0025 #include <QObject>
0026 #include <QMap>
0027 #include <QByteArray>
0028 
0029 #include "KoFilterChain.h"
0030 #include "KoFilterGraph.h"
0031 
0032 #include "komain_export.h"
0033 class KoDocument;
0034 class KoProgressUpdater;
0035 
0036 /**
0037  *  @brief The class managing all the filters.
0038  *
0039  *  This class manages all filters for a Calligra application. Normally
0040  *  you will not have to use it, since KoMainWindow takes care of loading
0041  *  and saving documents.
0042  *
0043  *  KoFilter
0044  *
0045  *  @author Kalle Dalheimer <kalle@kde.org>
0046  *  @author Torben Weis <weis@kde.org>
0047  *  @author Werner Trobin <trobin@kde.org>
0048  */
0049 class KOMAIN_EXPORT KoFilterManager : public QObject
0050 {
0051     Q_OBJECT
0052 public:
0053     /**
0054      * This enum is used to distinguish the import/export cases
0055      */
0056     enum Direction { Import = 1,  Export = 2 };
0057 
0058     /**
0059      * Create a filter manager for a document
0060      */
0061     explicit KoFilterManager(KoDocument *document,
0062                              KoProgressUpdater *progressUpdater = 0);
0063 
0064     /**
0065      * Create a filter manager for the Shape Collection docker.
0066      * @param mimeType the mimetype to import to.
0067      */
0068     explicit KoFilterManager(const QByteArray& mimeType);
0069 
0070     /**
0071      * Create a filter manager for a filter which wants to embed something.
0072      * The url it passes is the file to convert, obviously. You cannot use
0073      * the @ref importDocument() method -- use @ref exportDocument() to convert
0074      * the file to the destination mimetype you prefer.
0075      *
0076      * @param url The file you want to export
0077      * @param mimetypeHint The mimetype of the file you want to export. You have
0078      *        to specify this information only if the automatic detection will
0079      *        fail because e.g. you saved an embedded stream to a *.tmp file.
0080      *        Most likely you do not have to care about that.
0081      * @param parentChain The parent filter chain of this filter manager. Used
0082      *        to allow embedding for filters. Most likely you do not have to care.
0083      */
0084     explicit KoFilterManager(const QString& url, const QByteArray& mimetypeHint = QByteArray(),
0085                              KoFilterChain * const parentChain = 0);
0086 
0087     ~KoFilterManager() override;
0088 
0089     /**
0090      * Imports the passed URL and returns the resultant filename
0091      * (most likely some file in /tmp).
0092      * @p documentMimeType gives importDocument a hint about what type
0093      * the document may be. It can be left empty.
0094      * The @p status variable signals the success/error of the conversion
0095      * If the QString which is returned isEmpty() and the status is OK,
0096      * then we imported the file directly into the document.
0097      */
0098     QString importDocument(const QString& url,
0099                            const QString& documentMimeType,
0100                            KoFilter::ConversionStatus& status);
0101 
0102     /**
0103      * @brief Exports the given file/document to the specified URL/mimetype.
0104      *
0105      * If @p mimeType is empty, then the closest matching Calligra part is searched
0106      * and when the method returns @p mimeType contains this mimetype.
0107      * Oh, well, export is a C++ keyword ;)
0108      */
0109     KoFilter::ConversionStatus exportDocument(const QString& url, QByteArray& mimeType);
0110 
0111     ///@name Static API
0112     //@{
0113     /**
0114      * Suitable for passing to KoFileDialog::setMimeTypeFilters. The default mime
0115      * gets set by the "users" of this method, as we do not have enough
0116      * information here.
0117      * Optionally, @p extraNativeMimeTypes are added after the native mimetype.
0118      */
0119     static QStringList mimeFilter(const QByteArray& mimetype, Direction direction,
0120                                   const QStringList& extraNativeMimeTypes = QStringList());
0121 
0122     /**
0123      * The same method as KoFilterManager::mimeFilter but suited for KoShell.
0124      * We do not need the mimetype, as we will simply use all available
0125      * %Calligra mimetypes. The Direction enum is omitted, as we only
0126      * call this for importing. When saving from KoShell we already
0127      * know the Calligra part we are using.
0128      */
0129     static QStringList mimeFilter();
0130 
0131     /**
0132      * Method used to check if that filter is available at all.
0133      * @note Slow, but cached
0134      */
0135     static bool filterAvailable(KoFilterEntry::Ptr entry);
0136 
0137     //@}
0138 
0139     /**
0140      * Set the filter manager is batch mode (no dialog shown)
0141      * instead of the interactive mode (dialog shown)
0142      */
0143     void setBatchMode(const bool batch);
0144 
0145     /**
0146      * Get if the filter manager is batch mode (true)
0147      * or in interactive mode (true)
0148      */
0149     bool getBatchMode(void) const;
0150 
0151     /**
0152      * Return the KoProgressUpdater or nullptr if there is none.
0153      **/
0154     KoProgressUpdater *progressUpdater() const;
0155 
0156 private:
0157     // === API for KoFilterChains === (internal)
0158     // The friend methods are private in KoFilterChain and
0159     // just forward calls to the methods here. Should be
0160     // pretty safe.
0161     friend QString KoFilterChain::filterManagerImportFile() const;
0162     QString importFile() const {
0163         return m_importUrl;
0164     }
0165     friend QString KoFilterChain::filterManagerExportFile() const;
0166     QString exportFile() const {
0167         return m_exportUrl;
0168     }
0169     friend KoDocument *KoFilterChain::filterManagerKoDocument() const;
0170     KoDocument *document() const {
0171         return m_document;
0172     }
0173     friend int KoFilterChain::filterManagerDirection() const;
0174     int direction() const {
0175         return static_cast<int>(m_direction);
0176     }
0177     friend KoFilterChain *KoFilterChain::filterManagerParentChain() const;
0178     KoFilterChain *parentChain() const {
0179         return m_parentChain;
0180     }
0181 
0182     // Private API
0183     KoFilterManager(const KoFilterManager& rhs);
0184     KoFilterManager &operator=(const KoFilterManager& rhs);
0185 
0186     void importErrorHelper(const QString& mimeType, const bool suppressDialog = false);
0187 
0188     KoDocument *m_document;
0189     KoFilterChain *const m_parentChain;
0190     QString m_importUrl, m_exportUrl;
0191     QByteArray m_importUrlMimetypeHint;  ///< suggested mimetype
0192     CalligraFilter::Graph m_graph;
0193     Direction m_direction;
0194 
0195     /// A static cache for the availability checks of filters
0196     static QMap<QString, bool> m_filterAvailable;
0197 
0198     class Private;
0199     Private * const d;
0200 };
0201 
0202 #endif  // __KO_FILTER_MANAGER_H__