~lubuntu-dev/lxde/libfm-qt-debian-git

« back to all changes in this revision

Viewing changes to src/foldermodelitem.cpp

  • Committer: Alf Gaida
  • Date: 2015-12-17 15:45:00 UTC
  • Revision ID: git-v1:99d4cf5e0b3761023e2285ffb96a79d050f0bdf4
Tags: upstream/0.10.0+20151214
Adding upstream version 0.10.0+20151214.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2012 - 2015  Hong Jen Yee (PCMan) <pcman.tw@gmail.com>
 
3
 *
 
4
 * This library is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU Lesser General Public
 
6
 * License as published by the Free Software Foundation; either
 
7
 * version 2.1 of the License, or (at your option) any later version.
 
8
 *
 
9
 * This library is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 * Lesser General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU Lesser General Public
 
15
 * License along with this library; if not, write to the Free Software
 
16
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
17
 *
 
18
 */
 
19
 
 
20
 
 
21
#include "foldermodelitem.h"
 
22
 
 
23
namespace Fm {
 
24
 
 
25
FolderModelItem::FolderModelItem(FmFileInfo* _info):
 
26
  info(fm_file_info_ref(_info)) {
 
27
  displayName = QString::fromUtf8(fm_file_info_get_disp_name(info));
 
28
  icon = IconTheme::icon(fm_file_info_get_icon(_info));
 
29
  thumbnails.reserve(2);
 
30
}
 
31
 
 
32
FolderModelItem::FolderModelItem(const FolderModelItem& other) {
 
33
  info = other.info ? fm_file_info_ref(other.info) : NULL;
 
34
  displayName = QString::fromUtf8(fm_file_info_get_disp_name(info));
 
35
  icon = other.icon;
 
36
  thumbnails = other.thumbnails;
 
37
}
 
38
 
 
39
FolderModelItem::~FolderModelItem() {
 
40
  if(info)
 
41
    fm_file_info_unref(info);
 
42
}
 
43
 
 
44
// find thumbnail of the specified size
 
45
// The returned thumbnail item is temporary and short-lived
 
46
// If you need to use the struct later, copy it to your own struct to keep it.
 
47
FolderModelItem::Thumbnail* FolderModelItem::findThumbnail(int size) {
 
48
  QVector<Thumbnail>::iterator it;
 
49
  for(it = thumbnails.begin(); it != thumbnails.end(); ++it) {
 
50
    if(it->size == size) { // an image of the same size is found
 
51
      return it;
 
52
    }
 
53
  }
 
54
  if(it == thumbnails.end()) {
 
55
    Thumbnail thumbnail;
 
56
    thumbnail.status = ThumbnailNotChecked;
 
57
    thumbnail.size = size;
 
58
    thumbnails.append(thumbnail);
 
59
  }
 
60
  return &thumbnails.back();
 
61
}
 
62
 
 
63
// remove cached thumbnail of the specified size
 
64
void FolderModelItem::removeThumbnail(int size) {
 
65
  QVector<Thumbnail>::iterator it;
 
66
  for(it = thumbnails.begin(); it != thumbnails.end(); ++it) {
 
67
    if(it->size == size) { // an image of the same size is found
 
68
      thumbnails.erase(it);
 
69
      break;
 
70
    }
 
71
  }
 
72
}
 
73
 
 
74
#if 0
 
75
// cache the thumbnail of the specified size in the folder item
 
76
void FolderModelItem::setThumbnail(int size, QImage image) {
 
77
  QVector<Thumbnail>::iterator it;
 
78
  for(it = thumbnails.begin(); it != thumbnails.end(); ++it) {
 
79
    if(it->size == size) { // an image of the same size already exists
 
80
      it->image = image; // replace it
 
81
      it->status = ThumbnailLoaded;
 
82
      break;
 
83
    }
 
84
  }
 
85
  if(it == thumbnails.end()) { // the image is not found
 
86
    Thumbnail thumbnail;
 
87
    thumbnail.size = size;
 
88
    thumbnail.status = ThumbnailLoaded;
 
89
    thumbnail.image = image;
 
90
    thumbnails.append(thumbnail); // add a new entry
 
91
  }
 
92
}
 
93
#endif
 
94
 
 
95
 
 
96
} // namespace Fm