1 /* 2 3 Copyright 2011 Cuong Le <metacuong@gmail.com> 4 5 This program is free software; you can redistribute it and/or 6 modify it under the terms of the GNU General Public License as 7 published by the Free Software Foundation; either version 2 of 8 the License, or (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 */ 19 20 #ifndef FOLDERITEM_H 21 #define FOLDERITEM_H 22 23 #include <QObject> 24 #include "listmodel.h" 25 26 /* 27 * "revision":6226, 28 * "thumb_exists":false, 29 * "bytes":916480, 30 * "modified":"Fri, 25 Feb 2011 08:25:31 +0000", 31 * "path":"/2011-Craftly.ppt", 32 * "is_dir":false, 33 * "icon":"page_white_powerpoint", 34 * "mime_type":"application/vnd.ms-powerpoint", 35 * "size":"895KB" 36 */ 37 38 class FolderItem : public ListItem 39 { 40 Q_OBJECT 41 Q_PROPERTY(bool checked READ checked WRITE setChecked NOTIFY checkedChanged) 42 Q_PROPERTY(qreal revision READ revision WRITE setRevision NOTIFY revisionChanged) 43 Q_PROPERTY(bool thumb_exists READ thumb_exists WRITE setThumb_exists NOTIFY thumb_existsChanged) 44 Q_PROPERTY(qreal bytes READ bytes WRITE setBytes NOTIFY bytesChanged) 45 Q_PROPERTY(QString modified READ modified WRITE setModified NOTIFY modifiedChanged) 46 Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged) 47 Q_PROPERTY(bool is_dir READ is_dir WRITE setIs_dir NOTIFY is_dirChanged) 48 Q_PROPERTY(QString icon READ icon WRITE setIcon NOTIFY iconChanged) 49 Q_PROPERTY(QString mime_type READ mime_type WRITE setMime_type NOTIFY mime_typeChanged) 50 Q_PROPERTY(QString size READ size WRITE setSize NOTIFY sizeChanged) 51 Q_PROPERTY(QString name READ name) 52 Q_PROPERTY(QString section READ section) 53 54 public: 55 enum Roles { 56 RevisionRole = Qt::UserRole+1, 57 Thumb_existsRole, 58 BytesRole, 59 ModifiedRole, 60 PathRole, 61 Is_dirRole, 62 IconRole, 63 Mime_typeRole, 64 SizeRole, 65 CheckedRole, 66 NameRole, 67 SectionRole 68 }; 69 70 explicit FolderItem( 71 const qreal &revision, 72 const bool &thumb_exists, 73 const qreal &bytes, 74 const QString &modified, 75 const QString &path, 76 const bool &is_dir, 77 const QString &icon, 78 const QString &mime_type, 79 const QString &size, 80 QObject *parent = 0 ListItem(parent)81 ):ListItem(parent), 82 m_revision(revision), 83 m_thumb_exists(thumb_exists), 84 m_bytes(bytes), 85 m_modified(modified), 86 m_path(path), 87 m_is_dir(is_dir), 88 m_icon(icon), 89 m_mime_type(mime_type), 90 m_size(size), 91 m_checked(false) 92 {} 93 ListItem(parent)94 FolderItem(QObject *parent = 0): ListItem(parent) {} 95 96 QVariant data(int role) const override; 97 QHash<int, QByteArray> roleNames() const; 98 id()99 inline QString id() const override { return m_path; } revision()100 inline qreal revision() const { return m_revision;} thumb_exists()101 inline bool thumb_exists() const { return m_thumb_exists;} bytes()102 inline qreal bytes() const { return m_bytes;} modified()103 inline QString modified() const { return m_modified;} path()104 inline QString path() const { return m_path;} is_dir()105 inline bool is_dir() const { return m_is_dir;} icon()106 inline QString icon() const { return m_icon;} mime_type()107 inline QString mime_type() const { return m_mime_type;} size()108 inline QString size() const { return m_size;} checked()109 inline bool checked() const { return m_checked;} 110 QString name() const; 111 QString section() const; 112 QString xsection(); 113 114 Q_INVOKABLE void setChecked(const bool &v); 115 Q_INVOKABLE void setRevision(const qreal &v); 116 Q_INVOKABLE void setThumb_exists(const bool &v); 117 Q_INVOKABLE void setBytes(const qreal &v); 118 Q_INVOKABLE void setModified(const QString &v); 119 Q_INVOKABLE void setPath(const QString &v); 120 Q_INVOKABLE void setIs_dir(const bool &v); 121 Q_INVOKABLE void setIcon(const QString &v); 122 Q_INVOKABLE void setMime_type(const QString &v); 123 Q_INVOKABLE void setSize(const QString &v); 124 125 Q_SIGNALS: 126 void checkedChanged(); 127 void revisionChanged(); 128 void thumb_existsChanged(); 129 void bytesChanged(); 130 void modifiedChanged(); 131 void pathChanged(); 132 void is_dirChanged(); 133 void iconChanged(); 134 void mime_typeChanged(); 135 void sizeChanged(); 136 137 private: 138 qreal m_revision; 139 bool m_thumb_exists; 140 qreal m_bytes; 141 QString m_modified; 142 QString m_path; 143 bool m_is_dir; 144 QString m_icon; 145 QString m_mime_type; 146 QString m_size; 147 bool m_checked; 148 149 }; 150 151 #endif // FOLDERITEM_H 152