File indexing completed on 2025-01-05 04:02:14
0001 // vim: set tabstop=4 shiftwidth=4 expandtab 0002 /* Gwenview - A simple image viewer for KDE 0003 Copyright 2000-2004 Aurélien Gâteau <agateau@kde.org> 0004 This class is based on the ImagePreviewJob class from Konqueror. 0005 */ 0006 /* This file is part of the KDE project 0007 Copyright (C) 2000 David Faure <faure@kde.org> 0008 0009 This program is free software; you can redistribute it and/or modify 0010 it under the terms of the GNU General Public License as published by 0011 the Free Software Foundation; either version 2 of the License, or 0012 (at your option) any later version. 0013 0014 This program is distributed in the hope that it will be useful, 0015 but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0017 GNU General Public License for more details. 0018 0019 You should have received a copy of the GNU General Public License 0020 along with this program; if not, write to the Free Software 0021 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0022 */ 0023 0024 #ifndef THUMBNAILPROVIDER_H 0025 #define THUMBNAILPROVIDER_H 0026 0027 #include <lib/gwenviewlib_export.h> 0028 0029 // Qt 0030 #include <QImage> 0031 #include <QPixmap> 0032 #include <QPointer> 0033 0034 // KF 0035 #include <KFileItem> 0036 #include <KIO/Job> 0037 0038 // Local 0039 #include <lib/thumbnailgroup.h> 0040 0041 namespace Gwenview 0042 { 0043 class ThumbnailGenerator; 0044 class ThumbnailWriter; 0045 0046 /** 0047 * A job that determines the thumbnails for the images in the current directory 0048 */ 0049 class GWENVIEWLIB_EXPORT ThumbnailProvider : public KIO::Job 0050 { 0051 Q_OBJECT 0052 public: 0053 ThumbnailProvider(); 0054 ~ThumbnailProvider() override; 0055 0056 void stop(); 0057 0058 /** 0059 * To be called whenever items are removed from the view 0060 */ 0061 void removeItems(const KFileItemList &itemList); 0062 0063 /** 0064 * Remove all pending items 0065 */ 0066 void removePendingItems(); 0067 0068 /** 0069 * Returns the list of items waiting for a thumbnail 0070 */ 0071 const KFileItemList &pendingItems() const; 0072 0073 /** 0074 * Add items to the job 0075 */ 0076 void appendItems(const KFileItemList &items); 0077 0078 /** 0079 * Defines size of thumbnails to generate 0080 */ 0081 void setThumbnailGroup(ThumbnailGroup::Enum); 0082 0083 bool isRunning() const; 0084 0085 /** 0086 * Returns the thumbnail base dir, independent of the thumbnail size 0087 */ 0088 static QString thumbnailBaseDir(); 0089 0090 /** 0091 * Sets the thumbnail base dir, useful for unit-testing 0092 */ 0093 static void setThumbnailBaseDir(const QString &); 0094 0095 /** 0096 * Returns the thumbnail base dir, for the @p group 0097 */ 0098 static QString thumbnailBaseDir(ThumbnailGroup::Enum group); 0099 0100 /** 0101 * Delete the thumbnail for the @p url 0102 */ 0103 static void deleteImageThumbnail(const QUrl &url); 0104 0105 /** 0106 * Move a thumbnail to match a file move 0107 */ 0108 static void moveThumbnail(const QUrl &oldUrl, const QUrl &newUrl); 0109 0110 /** 0111 * Returns true if all thumbnails have been written to disk. Useful for 0112 * unit-testing. 0113 */ 0114 static bool isThumbnailWriterEmpty(); 0115 0116 Q_SIGNALS: 0117 /** 0118 * Emitted when the thumbnail for the @p item has been loaded 0119 */ 0120 void thumbnailLoaded(const KFileItem &item, const QPixmap &, const QSize &, qulonglong); 0121 0122 void thumbnailLoadingFailed(const KFileItem &item); 0123 0124 /** 0125 * Queue is empty 0126 */ 0127 void finished(); 0128 0129 protected: 0130 void slotResult(KJob *job) override; 0131 0132 private Q_SLOTS: 0133 void determineNextIcon(); 0134 void slotGotPreview(const KFileItem &, const QPixmap &); 0135 void checkThumbnail(); 0136 void thumbnailReady(const QImage &, const QSize &); 0137 void emitThumbnailLoadingFailed(); 0138 0139 private: 0140 enum { 0141 STATE_STATORIG, 0142 STATE_DOWNLOADORIG, 0143 STATE_PREVIEWJOB, 0144 STATE_NEXTTHUMB, 0145 } mState; 0146 0147 KFileItemList mItems; 0148 KFileItem mCurrentItem; 0149 0150 // The Url of the current item (always equivalent to m_items.first()->item()->url()) 0151 QUrl mCurrentUrl; 0152 0153 // The Uri of the original image (might be different from mCurrentUrl.url()) 0154 QString mOriginalUri; 0155 0156 // The modification time of the original image 0157 time_t mOriginalTime; 0158 0159 // The file size of the original image 0160 KIO::filesize_t mOriginalFileSize; 0161 0162 // The thumbnail path 0163 QString mThumbnailPath; 0164 0165 // The temporary path for remote urls 0166 QString mTempPath; 0167 0168 // Thumbnail group 0169 ThumbnailGroup::Enum mThumbnailGroup; 0170 0171 ThumbnailGenerator *mThumbnailGenerator; 0172 QPointer<ThumbnailGenerator> mPreviousThumbnailGenerator; 0173 0174 QStringList mPreviewPlugins; 0175 0176 void createNewThumbnailGenerator(); 0177 void abortSubjob(); 0178 void startCreatingThumbnail(const QString &path); 0179 0180 void emitThumbnailLoaded(const QImage &img, const QSize &size); 0181 0182 QImage loadThumbnailFromCache() const; 0183 }; 0184 0185 } // namespace 0186 #endif /* THUMBNAILPROVIDER_H */