File indexing completed on 2024-05-12 04:19:49

0001 // vim: set tabstop=4 shiftwidth=4 expandtab:
0002 /*
0003 Gwenview: an image viewer
0004 Copyright 2012 Aurélien Gâteau <agateau@kde.org>
0005 
0006 This program is free software; you can redistribute it and/or
0007 modify it under the terms of the GNU General Public License
0008 as published by the Free Software Foundation; either version 2
0009 of the License, or (at your option) any later version.
0010 
0011 This program is distributed in the hope that it will be useful,
0012 but WITHOUT ANY WARRANTY; without even the implied warranty of
0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014 GNU General Public License for more details.
0015 
0016 You should have received a copy of the GNU General Public License
0017 along with this program; if not, write to the Free Software
0018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
0019 
0020 */
0021 #ifndef THUMBNAILGENERATOR_H
0022 #define THUMBNAILGENERATOR_H
0023 
0024 // Local
0025 #include <lib/thumbnailgroup.h>
0026 
0027 // KF
0028 #include <KFileItem>
0029 
0030 // Qt
0031 #include <QImage>
0032 #include <QMutex>
0033 #include <QThread>
0034 #include <QWaitCondition>
0035 
0036 namespace Gwenview
0037 {
0038 struct ThumbnailContext {
0039     QImage mImage;
0040     int mOriginalWidth;
0041     int mOriginalHeight;
0042     bool mNeedCaching;
0043 
0044     bool load(const QString &pixPath, int pixelSize);
0045 };
0046 
0047 class ThumbnailGenerator : public QThread
0048 {
0049     Q_OBJECT
0050 public:
0051     ThumbnailGenerator();
0052 
0053     // Because we override run(), like you're not really supposed to do, we
0054     // can't trust isRunning()
0055     bool isStopped();
0056 
0057     void load(const QString &originalUri,
0058               time_t originalTime,
0059               KIO::filesize_t originalFileSize,
0060               const QString &originalMimeType,
0061               const QString &pixPath,
0062               const QString &thumbnailPath,
0063               ThumbnailGroup::Enum group);
0064 
0065     void cancel();
0066 
0067     QString originalUri() const;
0068     time_t originalTime() const;
0069     KIO::filesize_t originalFileSize() const;
0070     QString originalMimeType() const;
0071 
0072 protected:
0073     void run() override;
0074 
0075 Q_SIGNALS:
0076     void done(const QImage &, const QSize &);
0077     void thumbnailReadyToBeCached(const QString &thumbnailPath, const QImage &);
0078 
0079 private:
0080     bool testCancel();
0081     void cacheThumbnail();
0082     QImage mImage;
0083     QString mPixPath;
0084     QString mThumbnailPath;
0085     QString mOriginalUri;
0086     time_t mOriginalTime;
0087     KIO::filesize_t mOriginalFileSize;
0088     QString mOriginalMimeType;
0089     int mOriginalWidth;
0090     int mOriginalHeight;
0091     QMutex mMutex;
0092     QWaitCondition mCond;
0093     ThumbnailGroup::Enum mThumbnailGroup;
0094     bool mCancel;
0095     bool mStopped = false;
0096 };
0097 
0098 } // namespace
0099 
0100 #endif /* THUMBNAILGENERATOR_H */