filemodel.h 3.79 KB
Newer Older
1
/*
2
 * Copyright (C) 2014-2017 CZ.NIC
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * In addition, as a special exception, the copyright holders give
 * permission to link the code of portions of this program with the
 * OpenSSL library under certain conditions as described in each
 * individual source file, and distribute linked combinations including
 * the two.
 */

24 25
#ifndef _FILEMODEL_H_
#define _FILEMODEL_H_
26 27 28 29

#include <QAbstractListModel>
#include <QSqlQuery>

30 31
class FileListModel : public QAbstractListModel {
	Q_OBJECT
32

33
public:
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
	class Entry {
	public:
		Entry(const Entry &fme);
		Entry(const int fileId, const QString &dmFileDescr,
		    const QString &dmFileSize, const QString &icon,
		    const QString &fileContent);

		int fileId(void) const;
		QString dmFileDescr(void) const;
		void setDmFileDescr(const QString &dmFileDescr);
		QString dmFileSize(void) const;
		void setDmFileSize(const QString &dmFileSize);
		QString icon(void) const;
		void setIcon(const QString &icon);
		QString fileContent(void) const;
		void setFileContent(const QString &fileContent);

	private:
		int m_fileId; /*!< File database file identifier. */
		QString m_dmFileDescr; /*!< File name. */
		QString m_dmFileSize; /*!< File size. */
		QString m_icon; /*!< File icon? */
		QString m_fileContent; /*!< File content */
	};
58 59 60 61 62 63 64 65

	/*!
	 * @brief Roles which this model supports.
	 */
	enum Roles {
		ROLE_FILE_ID = Qt::UserRole,
		ROLE_FILE_NAME,
		ROLE_FILE_SIZE,
66 67
		ROLE_FILE_ICON,
		ROLE_FILE_DATA
68 69
	};

70 71 72 73
	/* Don't forget to declare various propertiers to the QML system. */
	static
	void declareQML(void);

74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
	/*!
	 * @brief Constructor.
	 *
	 * @param[in] parent Pointer to parent object.
	 */
	explicit FileListModel(QObject *parent = 0);

	/*!
	 * @brief Return number of rows under the given parent.
	 *
	 * @param[in] parent Parent node index.
	 * @return Number of rows.
	 */
	virtual
	int rowCount(const QModelIndex &parent = QModelIndex()) const
	    Q_DECL_OVERRIDE;

	/*!
	 * @brief Returns the model's role names.
	 *
	 * @return Model's role names.
	 */
	virtual
	QHash<int, QByteArray> roleNames(void) const Q_DECL_OVERRIDE;

	/*!
	 * @brief Return data stored in given location under given role.
	 *
	 * @param[in] index Index specifying the item.
	 * @param[in] role  Data role.
	 * @return Data from model.
	 */
	virtual
	QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE;

	/*!
	 * @brief Returns item flags for given index.
	 *
	 * @brief[in] index Index specifying the item.
	 * @return Item flags.
	 */
	virtual
	Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;

	/*!
	 * @brief Sets the content of the model according to the supplied query.
	 *
	 * @param[in,out] query SQL query result.
	 */
	void setQuery(QSqlQuery &query);

125
	/*!
126
	 * @brief Appends entry line to model.
127
	 *
128
	 * @param[in] entry Entry to append to model data.
129
	 */
130
	void appendFileEntry(const Entry &entry);
131

132 133 134 135 136
	/*!
	 * @brief Clears the model.
	 */
	void clearAll(void);

137 138 139 140 141 142
	/*!
	 * @brief Set content from ZFO file.
	 */
	Q_INVOKABLE
	bool setZfoFile(const QString &filePath);

143
private:
144
	QList<Entry> m_files; /*!< List of attachment entries. */
145 146 147
};

extern FileListModel globFilesModel;
148
extern FileListModel globFilesModelZfo;
149

150
#endif /* _FILEMODEL_H_ */