File indexing completed on 2024-05-12 05:10:10

0001 /***************************************************************************
0002     Copyright (C) 2003-2009 Robby Stephenson <robby@periapsis.org>
0003  ***************************************************************************/
0004 
0005 /***************************************************************************
0006  *                                                                         *
0007  *   This program is free software; you can redistribute it and/or         *
0008  *   modify it under the terms of the GNU General Public License as        *
0009  *   published by the Free Software Foundation; either version 2 of        *
0010  *   the License or (at your option) version 3 or any later version        *
0011  *   accepted by the membership of KDE e.V. (or its successor approved     *
0012  *   by the membership of KDE e.V.), which shall act as a proxy            *
0013  *   defined in Section 14 of version 3 of the license.                    *
0014  *                                                                         *
0015  *   This program is distributed in the hope that it will be useful,       *
0016  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0017  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0018  *   GNU General Public License for more details.                          *
0019  *                                                                         *
0020  *   You should have received a copy of the GNU General Public License     *
0021  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
0022  *                                                                         *
0023  ***************************************************************************/
0024 
0025 #ifndef TELLICO_EXPORTER_H
0026 #define TELLICO_EXPORTER_H
0027 
0028 #include <QObject>
0029 
0030 #include "../entry.h"
0031 #include "../datavectors.h"
0032 
0033 #include <KSharedConfig>
0034 
0035 #include <QUrl>
0036 
0037 class KConfig;
0038 
0039 class QWidget;
0040 class QString;
0041 
0042 namespace Tellico {
0043   namespace Export {
0044     enum Options {
0045       ExportFormatted     = 1 << 0,   // format entries when exported
0046       ExportUTF8          = 1 << 1,   // valid for some text files, export as utf-8
0047       ExportImages        = 1 << 2,   // should the images be included?
0048       ExportForce         = 1 << 3,   // force the export, no confirmation of overwriting
0049       ExportComplete      = 1 << 4,   // export complete document, including loans, etc.
0050       ExportProgress      = 1 << 5,   // show progress bar
0051       ExportClean         = 1 << 6,   // specifically for bibliographies, remove latex commands
0052       ExportVerifyImages  = 1 << 7,   // don't put in an image link that's not in the cache
0053       ExportImageSize     = 1 << 8,   // include image size in the generated XML
0054       ExportAbsoluteLinks = 1 << 9    // convert relative Url links to absolute
0055     };
0056 
0057 /**
0058  * @author Robby Stephenson
0059  */
0060 class Exporter : public QObject {
0061 Q_OBJECT
0062 
0063 public:
0064   Exporter(Data::CollPtr coll);
0065   virtual ~Exporter();
0066 
0067   Data::CollPtr collection() const;
0068 
0069   void setURL(const QUrl& url_) { m_url = url_; }
0070   void setEntries(const Data::EntryList& entries) { m_entries = entries; }
0071   void setFields(const Data::FieldList& fields) { m_fields = fields; }
0072   void setOptions(long options) { m_options = options; reset(); }
0073 
0074   // used for saving config options, do not translate
0075   virtual QString formatString() const = 0;
0076   virtual QString fileFilter() const = 0;
0077   const QUrl& url() const { return m_url; }
0078   const Data::EntryList& entries() const { return m_entries; }
0079   const Data::FieldList& fields() const;
0080   long options() const { return m_options; }
0081 
0082   /**
0083    * Do the export
0084    */
0085   virtual bool exec() = 0;
0086   /**
0087    * If changing options in the exporter should cause member variables to reset, implement
0088    * that here
0089    */
0090   virtual void reset() {}
0091 
0092   virtual QWidget* widget(QWidget* parent) = 0;
0093   virtual void readOptions(KSharedConfigPtr) {}
0094   virtual void saveOptions(KSharedConfigPtr) {}
0095 
0096 private:
0097   long m_options;
0098   Data::CollPtr m_coll;
0099   Data::EntryList m_entries;
0100   Data::FieldList m_fields;
0101   QUrl m_url;
0102 };
0103 
0104   } // end namespace
0105 } // end namespace
0106 #endif