File indexing completed on 2024-04-21 05:48:08

0001 /**
0002  * SPDX-FileCopyrightText: 2021 Sebastian Engel <kde@sebastianengel.eu>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef WEAVER_H
0008 #define WEAVER_H
0009 
0010 #include <QCommandLineOption>
0011 #include <QCommandLineParser>
0012 
0013 #include <QString>
0014 
0015 /**
0016  * @brief The Weaver class encapsulates the flow control to encode and decode @c .baskets archives
0017  *
0018  * @author Sebastian Engel <kde@sebastianengel.eu>
0019  */
0020 class Weaver
0021 {
0022 public:
0023     Weaver(QCommandLineParser *parser,
0024            const QCommandLineOption &mode_weave,
0025            const QCommandLineOption &mode_unweave,
0026            const QCommandLineOption &output,
0027            const QCommandLineOption &basename,
0028            const QCommandLineOption &previewImg,
0029            const QCommandLineOption &force);
0030 
0031     /**
0032      * This method processes the given command line options. If the options describe a valid operation it will encode,
0033      * or decode the input respectively.
0034      */
0035     int runMain();
0036 
0037 private:
0038     /**
0039      * This method decodes the given @c .baskets file.
0040      */
0041     bool unweave();
0042 
0043     /**
0044      * This method encodes the directory given to a @c .baskets file.
0045      */
0046     bool weave();
0047 
0048     /**
0049      * Superficially tests whether @p basketsDirectory has a valid source structure.
0050      * @param basketsDirectory
0051      * @return @c true if the directory structure seems valid
0052      * @return @c false if the directory does not seem to be a baskets source, or an IO error occured.
0053      */
0054     static bool isBasketSourceValid(const QString &basketsDirectory);
0055 
0056     /**
0057      * Superficially tests whether @p basketsFile is a valid @c .baskets format.
0058      *
0059      * It tests for a correctly formated file header, whether the preview image and archive body have the specified
0060      * length, respectively. The calling method should make sure that @p basketsFile exists.
0061      *
0062      * modeled after Archive::extractArchive
0063      * @param basketsFile is the path to the .baskets file to be tested.
0064      * @return @c true if a valid file structure was found
0065      * @return @c false if the file structure was not valid, or any other IO error occured.
0066      */
0067     static bool isBasketFile(const QString &basketsFile);
0068 
0069     /**
0070      * This method tests whether the given path is an existing @c .png file.
0071      *
0072      * @param previewFile is the path to the file to be tested
0073      * @return true if @p previewFile is an existing @c .png file
0074      */
0075     static bool isPreviewValid(const QString &previewFile);
0076 
0077     QCommandLineParser *const m_parser;
0078 
0079     QCommandLineOption m_weave;
0080     QCommandLineOption m_unweave;
0081     QCommandLineOption m_output;
0082     QCommandLineOption m_basename;
0083     QCommandLineOption m_previewImg;
0084     QCommandLineOption m_force;
0085 
0086     QString m_in;
0087     QString m_out;
0088     QString m_preview;
0089 };
0090 
0091 #endif // WEAVER_H