Program Listing for File creator.h

Return to documentation for file (include/zim/writer/creator.h)

/*
 * Copyright (C) 2017-2021 Matthieu Gautier <mgautier@kymeria.fr>
 * Copyright (C) 2020 Veloman Yunkan
 * Copyright (C) 2009 Tommi Maekitalo
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * is provided AS IS, WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and
 * NON-INFRINGEMENT.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 *
 */

#ifndef ZIM_WRITER_CREATOR_H
#define ZIM_WRITER_CREATOR_H

#include <memory>
#include <zim/zim.h>
#include <zim/illustration.h>
#include <zim/writer/item.h>

namespace zim
{
  class Fileheader;
  namespace writer
  {
    class CreatorData;

    class LIBZIM_API Creator
    {
      public:
        Creator();
        virtual ~Creator();

        Creator& configVerbose(bool verbose);

        Creator& configCompression(Compression compression);

        Creator& configClusterSize(zim::size_type targetSize);

        Creator& configIndexing(bool indexing, const std::string& language);

        Creator& configNbWorkers(unsigned nbWorkers);

        void startZimCreation(const std::string& filepath);

        void addItem(std::shared_ptr<Item> item);

        void addMetadata(const std::string& name, const std::string& content, const std::string& mimetype = "text/plain;charset=utf-8");

        void addMetadata(const std::string& name, std::unique_ptr<ContentProvider> provider, const std::string& mimetype = "text/plain;charset=utf-8");

        void addIllustration(const IllustrationInfo& ii, const std::string& content);

        void addIllustration(const IllustrationInfo& ii, std::unique_ptr<ContentProvider> provider);

        void addIllustration(unsigned int size, const std::string& content);

        void addIllustration(unsigned int size, std::unique_ptr<ContentProvider> provider);

        void addRedirection(
            const std::string& path,
            const std::string& title,
            const std::string& targetpath,
            const Hints& hints = Hints());


        void addAlias(
            const std::string& path,
            const std::string& title,
            const std::string& targetPath,
            const Hints& hints = Hints()
        );

        void finishZimCreation();

        void setMainPath(const std::string& mainPath) { m_mainPath = mainPath; }

        void setUuid(const zim::Uuid& uuid) { m_uuid = uuid; }

      private:
        std::unique_ptr<CreatorData> data;

        // configuration
        bool m_verbose = false;
        Compression m_compression = Compression::Zstd;
        bool m_withIndex = false;
        size_t m_clusterSize;
        std::string m_indexingLanguage;
        unsigned m_nbWorkers = 4;

        // zim data
        std::string m_mainPath;
        Uuid m_uuid = Uuid::generate();

        void fillHeader(Fileheader* header) const;
        void writeLastParts() const;
        void checkError();
    };
  }

}

#endif // ZIM_WRITER_CREATOR_H