1 //===========================================
2 //  Lumina Desktop source code
3 //  Copyright (c) 2017, Ken Moore & JT Pennington
4 //  Available under the 3-clause BSD license
5 //  See the LICENSE file for full details
6 //===========================================
7 //  This is the main browsing backend for the file manager
8 //===========================================
9 #ifndef _LUMINA_FM_BROWSER_MODEL_BACKEND_H
10 #define _LUMINA_FM_BROWSER_MODEL_BACKEND_H
11 
12 #include <QAbstractItemModel>
13 #include <QModelIndex>
14 #include <QMimeData>
15 #include <QMap>
16 #include <QVariant>
17 #include <QHash>
18 
19 #include <LuminaXDG.h>
20 
21 class BrowserModel : public QAbstractItemModel {
22 	Q_OBJECT
23 public:
24 	BrowserModel(QObject *parent = 0);
25 	~BrowserModel();
26 
27 	//Virtual overrides
28 	QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
29 	QModelIndex parent(const QModelIndex &index) const;
30 
31 	// item management
32 	int rowCount(const QModelIndex &parent = QModelIndex()) const;
33 	bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
34 	bool removeRow(int row, const QModelIndex &parent = QModelIndex());
35 	bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
36 
37 	int columnCount(const QModelIndex &parent = QModelIndex()) const;
38 	bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex());
39 	bool removeColumn(int column, const QModelIndex &parent = QModelIndex());
40 	bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex());
41 
42 	//bool hasChildren(const QModelIndex &parent = QModelIndex()) const;
43 
44 	// data functions
45 	Qt::ItemFlags flags(const QModelIndex &index) const;
46 	QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
47 	QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
48 	// data modification functions
49 	bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
50 	bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole);
51 
52 	// drag and drop
53 	//QMimeData* mimeData(const QModelIndexList &indexes) const;
54 	//QStringList mimeTypes() const;
55 	//bool setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles);
56 	//Qt::DropActions supportedDropActions() const;
57 	//bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
58 
59 	//Special Functions (non virtual replacements)
60 	LFileInfo* fileInfo(QString name);
61 	QString currentDirectory();
62 
63 	void setShowHidden(bool showHidden);
64 	bool showHidden
65 
66 public slots:
67 	void loadDirectory(QString dir="");
68 	void loadItem(QString item);
69 
70 private:
71 	QHash<quintptr, QModelIndex> HASH; //QString: "row/column"
72 	QString cDir;
73 	//simplification functions
74 	/*QString findInHash(QString path);
75 	QString findInHash(QModelIndex index);
76 	LFileInfo* indexToInfo(QString path);*/
77 	LFileInfo* indexToInfo(QModelIndex index);
78 
79 private slots:
80 
81 protected:
82 
83 signals:
84 
85 };
86 
87 #endif
88