1 // vim: set tabstop=4 shiftwidth=4 expandtab 2 /* Gwenview - A simple image viewer for KDE 3 Copyright 2000-2004 Aurélien Gâteau <agateau@kde.org> 4 This class is based on the ImagePreviewJob class from Konqueror. 5 */ 6 /* This file is part of the KDE project 7 Copyright (C) 2000 David Faure <faure@kde.org> 8 9 This program is free software; you can redistribute it and/or modify 10 it under the terms of the GNU General Public License as published by 11 the Free Software Foundation; either version 2 of the License, or 12 (at your option) any later version. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program; if not, write to the Free Software 21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 22 */ 23 24 #ifndef THUMBNAILPROVIDER_H 25 #define THUMBNAILPROVIDER_H 26 27 #include <lib/gwenviewlib_export.h> 28 29 // Qt 30 #include <QImage> 31 #include <QPixmap> 32 #include <QPointer> 33 34 // KF 35 #include <KFileItem> 36 #include <KIO/Job> 37 38 // Local 39 #include <lib/thumbnailgroup.h> 40 41 namespace Gwenview 42 { 43 class ThumbnailGenerator; 44 class ThumbnailWriter; 45 46 /** 47 * A job that determines the thumbnails for the images in the current directory 48 */ 49 class GWENVIEWLIB_EXPORT ThumbnailProvider : public KIO::Job 50 { 51 Q_OBJECT 52 public: 53 ThumbnailProvider(); 54 ~ThumbnailProvider() override; 55 56 void stop(); 57 58 /** 59 * To be called whenever items are removed from the view 60 */ 61 void removeItems(const KFileItemList &itemList); 62 63 /** 64 * Remove all pending items 65 */ 66 void removePendingItems(); 67 68 /** 69 * Returns the list of items waiting for a thumbnail 70 */ 71 const KFileItemList &pendingItems() const; 72 73 /** 74 * Add items to the job 75 */ 76 void appendItems(const KFileItemList &items); 77 78 /** 79 * Defines size of thumbnails to generate 80 */ 81 void setThumbnailGroup(ThumbnailGroup::Enum); 82 83 bool isRunning() const; 84 85 /** 86 * Returns the thumbnail base dir, independent of the thumbnail size 87 */ 88 static QString thumbnailBaseDir(); 89 90 /** 91 * Sets the thumbnail base dir, useful for unit-testing 92 */ 93 static void setThumbnailBaseDir(const QString &); 94 95 /** 96 * Returns the thumbnail base dir, for the @p group 97 */ 98 static QString thumbnailBaseDir(ThumbnailGroup::Enum group); 99 100 /** 101 * Delete the thumbnail for the @p url 102 */ 103 static void deleteImageThumbnail(const QUrl &url); 104 105 /** 106 * Move a thumbnail to match a file move 107 */ 108 static void moveThumbnail(const QUrl &oldUrl, const QUrl &newUrl); 109 110 /** 111 * Returns true if all thumbnails have been written to disk. Useful for 112 * unit-testing. 113 */ 114 static bool isThumbnailWriterEmpty(); 115 116 Q_SIGNALS: 117 /** 118 * Emitted when the thumbnail for the @p item has been loaded 119 */ 120 void thumbnailLoaded(const KFileItem &item, const QPixmap &, const QSize &, qulonglong); 121 122 void thumbnailLoadingFailed(const KFileItem &item); 123 124 /** 125 * Queue is empty 126 */ 127 void finished(); 128 129 protected: 130 void slotResult(KJob *job) override; 131 132 private Q_SLOTS: 133 void determineNextIcon(); 134 void slotGotPreview(const KFileItem &, const QPixmap &); 135 void checkThumbnail(); 136 void thumbnailReady(const QImage &, const QSize &); 137 void emitThumbnailLoadingFailed(); 138 139 private: 140 enum { 141 STATE_STATORIG, 142 STATE_DOWNLOADORIG, 143 STATE_PREVIEWJOB, 144 STATE_NEXTTHUMB, 145 } mState; 146 147 KFileItemList mItems; 148 KFileItem mCurrentItem; 149 150 // The Url of the current item (always equivalent to m_items.first()->item()->url()) 151 QUrl mCurrentUrl; 152 153 // The Uri of the original image (might be different from mCurrentUrl.url()) 154 QString mOriginalUri; 155 156 // The modification time of the original image 157 time_t mOriginalTime; 158 159 // The file size of the original image 160 KIO::filesize_t mOriginalFileSize; 161 162 // The thumbnail path 163 QString mThumbnailPath; 164 165 // The temporary path for remote urls 166 QString mTempPath; 167 168 // Thumbnail group 169 ThumbnailGroup::Enum mThumbnailGroup; 170 171 ThumbnailGenerator *mThumbnailGenerator; 172 QPointer<ThumbnailGenerator> mPreviousThumbnailGenerator; 173 174 QStringList mPreviewPlugins; 175 176 void createNewThumbnailGenerator(); 177 void abortSubjob(); 178 void startCreatingThumbnail(const QString &path); 179 180 void emitThumbnailLoaded(const QImage &img, const QSize &size); 181 182 QImage loadThumbnailFromCache() const; 183 }; 184 185 } // namespace 186 #endif /* THUMBNAILPROVIDER_H */ 187