]> git.tdb.fi Git - xinema.git/blob - remote/source/directorymodel.cpp
Overhaul BrowsePage to look and feel better
[xinema.git] / remote / source / directorymodel.cpp
1 #include "directorymodel.h"
2
3 void DirectoryModel::clear()
4 {
5         beginResetModel();
6         entries.clear();
7         endResetModel();
8 }
9
10 void DirectoryModel::add_entry(const QString &name, EntryType type)
11 {
12         Entry entry;
13         entry.name = name;
14         entry.type = type;
15
16         int i;
17         for(i=0; (i<entries.size() && entries[i]<entry); ++i) ;
18
19         beginInsertRows(QModelIndex(), i, i);
20         entries.insert(i, entry);
21         endInsertRows();
22 }
23
24 QHash<int, QByteArray> DirectoryModel::roleNames() const
25 {
26         QHash<int, QByteArray> names;
27         names[0] = "name";
28         names[1] = "type";
29         return names;
30 }
31
32 int DirectoryModel::rowCount(const QModelIndex &) const
33 {
34         return entries.size();
35 }
36
37 QVariant DirectoryModel::data(const QModelIndex &index, int role) const
38 {
39         int i = index.row();
40         if(i>entries.size())
41                 return QVariant();
42
43         if(role==0)
44                 return entries[i].name;
45         else if(role==1)
46                 return entries[i].type;
47         else
48                 return QVariant();
49 }
50
51
52 bool DirectoryModel::Entry::operator<(const Entry &other) const
53 {
54         if(type!=other.type)
55                 return type<other.type;
56         return name<other.name;
57 }