File indexing completed on 2025-01-26 04:14:58

0001 /*
0002  * Copyright (C) 2015 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 ARCHIVEIMAGEPROVIDER_H
0023 #define ARCHIVEIMAGEPROVIDER_H
0024 
0025 #include <QQuickAsyncImageProvider>
0026 #include <QRunnable>
0027 
0028 /**
0029  * \brief Class to return images for archives.
0030  * 
0031  * ArchiveImageProvider is for getting images out of
0032  * archives(zip, rar, cbz, cbr), as well as getting image data out of ACBF files.
0033  */
0034 class ArchiveBookModel;
0035 class ArchiveImageProvider : public QQuickAsyncImageProvider
0036 {
0037 public:
0038     explicit ArchiveImageProvider();
0039     ~ArchiveImageProvider() override;
0040 
0041     /**
0042      * \brief Request a given image.
0043      * 
0044      * @param id The url of the image to provide.
0045      * @param requestedSize The required size of the final image, unused.
0046      * 
0047      * @return an asynchronous image response
0048      */
0049     QQuickImageResponse *requestImageResponse(const QString &id, const QSize &requestedSize) override;
0050 
0051     /**
0052      * \brief Set the ArchiveBookModel to get images for.
0053      * @param model ArchiveBookModel to get images for.
0054      */
0055     void setArchiveBookModel(ArchiveBookModel* model);
0056 
0057     /**
0058      * \brief Set the prefix.
0059      * @param prefix The prefix as a string.
0060      * TODO: What is the prefix and why is it necessary?
0061      */
0062     void setPrefix(QString prefix);
0063     /**
0064      * @returns the prefix as a QString.
0065      */
0066     QString prefix() const;
0067 private:
0068     class Private;
0069     Private* d;
0070 };
0071 
0072 /**
0073  * \brief A worker class which does the bulk of the work for PreviewImageProvider
0074  */
0075 class ArchiveImageRunnable : public QObject, public QRunnable {
0076     Q_OBJECT;
0077 public:
0078     explicit ArchiveImageRunnable(const QString &id, const QSize &requestedSize, ArchiveBookModel* bookModel, const QString& prefix);
0079     ~ArchiveImageRunnable() override;
0080 
0081     void run() override;
0082 
0083     /**
0084      * Request that the preview worker abort what it's doing
0085      */
0086     Q_SLOT void abort();
0087 
0088     /**
0089      * \brief Emitted once the preview has been retrieved (successfully or not)
0090      * @param image The preview image in the requested size (possibly a placeholder)
0091      */
0092     Q_SIGNAL void done(QImage image);
0093 private:
0094     class Private;
0095     Private* d;
0096 };
0097 
0098 #endif//ARCHIVEIMAGEPROVIDER_H