File indexing completed on 2025-01-26 04:15:00

0001 /*
0002  * Copyright (C) 2016 Dan Leinir Turthra Jensen <admin@leinir.dk>
0003  *
0004  * This library is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU Lesser General Public
0006  * License as published by the Free Software Foundation; either
0007  * version 2.1 of the License, or (at your option) version 3, or any
0008  * later version accepted by the membership of KDE e.V. (or its
0009  * successor approved by the membership of KDE e.V.), which shall
0010  * act as a proxy defined in Section 6 of version 3 of the license.
0011  *
0012  * This library is distributed in the hope that it will be useful,
0013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015  * Lesser General Public License for more details.
0016  *
0017  * You should have received a copy of the GNU Lesser General Public
0018  * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
0019  *
0020  */
0021 
0022 #ifndef PERUSECONFIG_H
0023 #define PERUSECONFIG_H
0024 
0025 #include <QObject>
0026 /**
0027  * \brief Class to handle reading and writing the configuration.
0028  * 
0029  * Peruse will store the data in 'peruserc' at the QStandardPath
0030  * for configuration.
0031  */
0032 class PeruseConfig : public QObject
0033 {
0034     Q_OBJECT
0035     Q_ENUMS(ZoomMode)
0036     /**
0037      * \brief recently opened represents the recently opened books.
0038      */
0039     Q_PROPERTY(QStringList recentlyOpened READ recentlyOpened NOTIFY recentlyOpenedChanged)
0040     /**
0041      * \brief book locations is where Peruse will look for books, whether they have been removed, added, etc.
0042      */
0043     Q_PROPERTY(QStringList bookLocations READ bookLocations NOTIFY bookLocationsChanged)
0044     /**
0045      * \brief new stuff location is for the location of the KNewStuff config for the GHNS protocol.
0046      */
0047     Q_PROPERTY(QString newstuffLocation READ newstuffLocation NOTIFY newstuffLocationChanged)
0048     /**
0049      * \brief boolean representing whether or not we should animate jumps on the page
0050      */
0051     Q_PROPERTY(bool animateJumpAreas READ animateJumpAreas WRITE setAnimateJumpAreas NOTIFY animateJumpAreasChanged)
0052 public:
0053     /**
0054      * \brief Enum holding the preferred zoom mode.
0055      */
0056     enum ZoomMode {
0057         ZoomFull = 0,
0058         ZoomFitWidth = 1,
0059         ZoomFitHeight = 2
0060     };
0061 
0062     explicit PeruseConfig(QObject* parent = nullptr);
0063     ~PeruseConfig() override;
0064 
0065     /**
0066      * \brief Add a book to the recently opened list.
0067      * @param path the path/filename of the newly opened book.
0068      */
0069     Q_INVOKABLE void bookOpened(QString path);
0070     /**
0071      * @return a list of recently opened files.
0072      */
0073     QStringList recentlyOpened() const;
0074     /**
0075      * \brief Fires when the list of recently opened files has changed.
0076      */
0077     Q_SIGNAL void recentlyOpenedChanged();
0078 
0079     /**
0080      * \brief Add a folder to the book locations.
0081      * @param location path to the folder to add.
0082      */
0083     Q_INVOKABLE void addBookLocation(const QString& location);
0084     /**
0085      * \brief Remove a folder from the book locations.
0086      * @param location path of the folder to remove.
0087      */
0088     Q_INVOKABLE void removeBookLocation(const QString& location);
0089     /**
0090      * @return a QStringList with paths to all the folders to check for books.
0091      */
0092     QStringList bookLocations() const;
0093     /**
0094      * \brief Fires when the book locations to check have changed.
0095      */
0096     Q_SIGNAL void bookLocationsChanged();
0097 
0098     /**
0099      * \brief Holds url to the peruse's KNewStuff configuration fle, to
0100      * make it easy to retrieve.
0101      */
0102     QString newstuffLocation() const;
0103     /**
0104      * \brief Fires when the location to the KNewStuff config is changed.
0105      */
0106     Q_SIGNAL void newstuffLocationChanged();
0107 
0108     /**
0109      * @return a boolean representing  value of animateJumpAreas property
0110      */
0111     bool animateJumpAreas() const;
0112 
0113     /**
0114      * \biref sets the animateJumpAreas property value to the passed parameter
0115      * @param animate the new value for animateJumpAreas property
0116      */
0117     void setAnimateJumpAreas(bool animate);
0118 
0119     /**
0120      * \biref Fires when the animateJumpAreas property gets changed
0121      */
0122     Q_SIGNAL void animateJumpAreasChanged();
0123 
0124     /**
0125      * \brief Fires when there is an config error message to show.
0126      * @param message The Error message to show.
0127      */
0128     Q_SIGNAL void showMessage(QString message);
0129 
0130     // This should go somewhere more sensible, really... like a static on Qt. or something :P
0131     Q_INVOKABLE QString homeDir() const;
0132     /**
0133      * Creates a KFileMetaData::UserMetaData for this file, property and value so the information is not lost when files are moved around outside of Peruse
0134      */
0135     Q_INVOKABLE void setFilesystemProperty(QString fileName, QString propertyName, QString value);
0136     /**
0137      * @brief getFilesystemProperty
0138      * @param fileName file name of the file to get data from.
0139      * @param propertyName value of the proper to get data from.
0140      * @return the value of the property.
0141      */
0142     Q_INVOKABLE QString getFilesystemProperty(QString fileName, QString propertyName);
0143 
0144     /**
0145      * Convenience function which simply forwards the information from
0146      * QImageReader::supportedImageFormats() in a QML-friendly format.
0147      * @return A list of image formats by short name - see the documentation for QImageReader::supportedImageFormats() for further details
0148      */
0149     Q_INVOKABLE QStringList supportedImageFormats() const;
0150 private:
0151     class Private;
0152     Private* d;
0153 };
0154 
0155 #endif//PERUSECONFIG_H