2
* Copyright (C) 2012 - 2015 Hong Jen Yee (PCMan) <pcman.tw@gmail.com>
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.
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.
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
21
#include "foldermodelitem.h"
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);
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));
36
thumbnails = other.thumbnails;
39
FolderModelItem::~FolderModelItem() {
41
fm_file_info_unref(info);
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
54
if(it == thumbnails.end()) {
56
thumbnail.status = ThumbnailNotChecked;
57
thumbnail.size = size;
58
thumbnails.append(thumbnail);
60
return &thumbnails.back();
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
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;
85
if(it == thumbnails.end()) { // the image is not found
87
thumbnail.size = size;
88
thumbnail.status = ThumbnailLoaded;
89
thumbnail.image = image;
90
thumbnails.append(thumbnail); // add a new entry