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
#ifndef FM_FOLDERMODEL_H
22
#define FM_FOLDERMODEL_H
24
#include "libfmqtglobals.h"
25
#include <QAbstractListModel>
31
#include <QLinkedList>
33
#include "foldermodelitem.h"
37
class LIBFM_QT_API FolderModel : public QAbstractListModel {
42
FileInfoRole = Qt::UserRole
56
virtual ~FolderModel();
61
void setFolder(FmFolder* new_folder);
64
return folder_ ? fm_folder_get_path(folder_) : NULL;
67
int rowCount(const QModelIndex & parent = QModelIndex()) const;
68
int columnCount (const QModelIndex & parent) const;
69
QVariant data(const QModelIndex & index, int role) const;
70
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
71
QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const;
72
QModelIndex parent( const QModelIndex & index ) const;
73
// void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
75
Qt::ItemFlags flags(const QModelIndex & index) const;
77
virtual QStringList mimeTypes() const;
78
virtual QMimeData* mimeData(const QModelIndexList & indexes) const;
79
virtual Qt::DropActions supportedDropActions() const;
80
virtual bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent);
82
FmFileInfo* fileInfoFromIndex(const QModelIndex& index) const;
83
FolderModelItem* itemFromIndex(const QModelIndex& index) const;
84
QImage thumbnailFromIndex(const QModelIndex& index, int size);
86
void cacheThumbnails(int size);
87
void releaseThumbnails(int size);
90
void thumbnailLoaded(const QModelIndex& index, int size);
96
static void onStartLoading(FmFolder* folder, gpointer user_data);
97
static void onFinishLoading(FmFolder* folder, gpointer user_data);
98
static void onFilesAdded(FmFolder* folder, GSList* files, gpointer user_data);
99
static void onFilesChanged(FmFolder* folder, GSList* files, gpointer user_data);
100
static void onFilesRemoved(FmFolder* folder, GSList* files, gpointer user_data);
101
static void onThumbnailLoaded(FmThumbnailLoader *res, gpointer user_data);
103
void insertFiles(int row, FmFileInfoList* files);
105
QList<FolderModelItem>::iterator findItemByPath(FmPath* path, int* row);
106
QList<FolderModelItem>::iterator findItemByName(const char* name, int* row);
107
QList<FolderModelItem>::iterator findItemByFileInfo(FmFileInfo* info, int* row);
111
// FIXME: should we use a hash table here so item lookup becomes much faster?
112
QList<FolderModelItem> items;
114
// record what size of thumbnails we should cache in an array of <size, refCount> pairs.
115
QVector<QPair<int, int> > thumbnailRefCounts;
116
QLinkedList<FmThumbnailLoader*> thumbnailResults;
121
#endif // FM_FOLDERMODEL_H