PCManFM-Qt
thumbnailloader.h
1 /*
2  <one line to give the program's name and a brief idea of what it does.>
3  Copyright (C) 2013 PCMan <email>
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 
20 
21 #ifndef FM_THUMBNAILLOADER_H
22 #define FM_THUMBNAILLOADER_H
23 
24 #include "libfmqtglobals.h"
25 #include <QImage>
26 #include <libfm/fm.h>
27 #include <gio/gio.h>
28 
29 namespace Fm {
30 
31 class LIBFM_QT_API ThumbnailLoader {
32 
33 public:
35  virtual ~ThumbnailLoader();
36 
37  static ThumbnailLoader* instance() {
38  return theThumbnailLoader;
39  }
40 
41  static FmThumbnailLoader* load(FmFileInfo* fileInfo, int size, FmThumbnailLoaderCallback callback, gpointer user_data) {
42  // qDebug("load thumbnail: %s", fm_file_info_get_disp_name(fileInfo));
43  return fm_thumbnail_loader_load(fileInfo, size, callback, user_data);
44  }
45 
46  static FmFileInfo* fileInfo(FmThumbnailLoader* result) {
47  return fm_thumbnail_loader_get_file_info(result);
48  }
49 
50  static void cancel(FmThumbnailLoader* result) {
51  fm_thumbnail_loader_cancel(result);
52  }
53 
54  static QImage image(FmThumbnailLoader* result);
55 
56  static int size(FmThumbnailLoader* result) {
57  return fm_thumbnail_loader_get_size(result);
58  }
59 
60  static void setLocalFilesOnly(bool value) {
61  localFilesOnly_ = value;
62  if(fm_config)
63  fm_config->thumbnail_local = localFilesOnly_;
64  }
65 
66  static bool localFilesOnly() {
67  return localFilesOnly_;
68  }
69 
70  static int maxThumbnailFileSize() {
71  return maxThumbnailFileSize_;
72  }
73 
74  static void setMaxThumbnailFileSize(int size) {
75  maxThumbnailFileSize_ = size;
76  if(fm_config)
77  fm_config->thumbnail_max = maxThumbnailFileSize_;
78  }
79 
80 private:
81  static GObject* readImageFromFile(const char* filename);
82  static GObject* readImageFromStream(GInputStream* stream, guint64 len, GCancellable* cancellable);
83  static gboolean writeImage(GObject* image, const char* filename);
84  static GObject* scaleImage(GObject* ori_pix, int new_width, int new_height);
85  static int getImageWidth(GObject* image);
86  static int getImageHeight(GObject* image);
87  static char* getImageText(GObject* image, const char* key);
88  static gboolean setImageText(GObject* image, const char* key, const char* val);
89  static GObject* rotateImage(GObject* image, int degree);
90 
91 private:
92  static ThumbnailLoader* theThumbnailLoader;
93  static bool localFilesOnly_;
94  static int maxThumbnailFileSize_;
95 };
96 
97 }
98 
99 #endif // FM_THUMBNAILLOADER_H
Definition: appchoosercombobox.cpp:26
Definition: thumbnailloader.h:31