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

« back to all changes in this revision

Viewing changes to src/foldermodel.h

  • 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
#ifndef FM_FOLDERMODEL_H
 
22
#define FM_FOLDERMODEL_H
 
23
 
 
24
#include "libfmqtglobals.h"
 
25
#include <QAbstractListModel>
 
26
#include <QIcon>
 
27
#include <QImage>
 
28
#include <libfm/fm.h>
 
29
#include <QList>
 
30
#include <QVector>
 
31
#include <QLinkedList>
 
32
#include <QPair>
 
33
#include "foldermodelitem.h"
 
34
 
 
35
namespace Fm {
 
36
 
 
37
class LIBFM_QT_API FolderModel : public QAbstractListModel {
 
38
Q_OBJECT
 
39
public:
 
40
 
 
41
  enum Role {
 
42
    FileInfoRole = Qt::UserRole
 
43
  };
 
44
 
 
45
  enum ColumnId {
 
46
    ColumnFileName,
 
47
    ColumnFileType,
 
48
    ColumnFileSize,
 
49
    ColumnFileMTime,
 
50
    ColumnFileOwner,
 
51
    NumOfColumns
 
52
  };
 
53
 
 
54
public:
 
55
  FolderModel();
 
56
  virtual ~FolderModel();
 
57
 
 
58
  FmFolder* folder() {
 
59
    return folder_;
 
60
  }
 
61
  void setFolder(FmFolder* new_folder);
 
62
 
 
63
  FmPath* path() {
 
64
    return folder_ ? fm_folder_get_path(folder_) : NULL;
 
65
  }
 
66
 
 
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);
 
74
 
 
75
  Qt::ItemFlags flags(const QModelIndex & index) const;
 
76
 
 
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);
 
81
 
 
82
  FmFileInfo* fileInfoFromIndex(const QModelIndex& index) const;
 
83
  FolderModelItem* itemFromIndex(const QModelIndex& index) const;
 
84
  QImage thumbnailFromIndex(const QModelIndex& index, int size);
 
85
 
 
86
  void cacheThumbnails(int size);
 
87
  void releaseThumbnails(int size);
 
88
 
 
89
Q_SIGNALS:
 
90
  void thumbnailLoaded(const QModelIndex& index, int size);
 
91
 
 
92
public Q_SLOTS:
 
93
  void updateIcons();
 
94
 
 
95
protected:
 
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);
 
102
 
 
103
  void insertFiles(int row, FmFileInfoList* files);
 
104
  void removeAll();
 
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);
 
108
 
 
109
private:
 
110
  FmFolder* folder_;
 
111
  // FIXME: should we use a hash table here so item lookup becomes much faster?
 
112
  QList<FolderModelItem> items;
 
113
 
 
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;
 
117
};
 
118
 
 
119
}
 
120
 
 
121
#endif // FM_FOLDERMODEL_H