]> git.tdb.fi Git - xinema.git/blobdiff - remote/source/directorymodel.cpp
Overhaul BrowsePage to look and feel better
[xinema.git] / remote / source / directorymodel.cpp
diff --git a/remote/source/directorymodel.cpp b/remote/source/directorymodel.cpp
new file mode 100644 (file)
index 0000000..10bf05e
--- /dev/null
@@ -0,0 +1,57 @@
+#include "directorymodel.h"
+
+void DirectoryModel::clear()
+{
+       beginResetModel();
+       entries.clear();
+       endResetModel();
+}
+
+void DirectoryModel::add_entry(const QString &name, EntryType type)
+{
+       Entry entry;
+       entry.name = name;
+       entry.type = type;
+
+       int i;
+       for(i=0; (i<entries.size() && entries[i]<entry); ++i) ;
+
+       beginInsertRows(QModelIndex(), i, i);
+       entries.insert(i, entry);
+       endInsertRows();
+}
+
+QHash<int, QByteArray> DirectoryModel::roleNames() const
+{
+       QHash<int, QByteArray> names;
+       names[0] = "name";
+       names[1] = "type";
+       return names;
+}
+
+int DirectoryModel::rowCount(const QModelIndex &) const
+{
+       return entries.size();
+}
+
+QVariant DirectoryModel::data(const QModelIndex &index, int role) const
+{
+       int i = index.row();
+       if(i>entries.size())
+               return QVariant();
+
+       if(role==0)
+               return entries[i].name;
+       else if(role==1)
+               return entries[i].type;
+       else
+               return QVariant();
+}
+
+
+bool DirectoryModel::Entry::operator<(const Entry &other) const
+{
+       if(type!=other.type)
+               return type<other.type;
+       return name<other.name;
+}