Dim share and delete icons when we have no item shown
[harmattan/cameraplus] / src / fileinfomodel.cpp
1 /*!
2  * This file is part of CameraPlus.
3  *
4  * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19  */
20
21 #include "fileinfomodel.h"
22
23 FileInfoModel::FileInfoModel(QObject *parent) :
24   QAbstractListModel(parent) {
25
26 }
27
28 FileInfoModel::~FileInfoModel() {
29
30 }
31
32 int FileInfoModel::rowCount(const QModelIndex& parent) const {
33   if (parent.isValid()) {
34     return 0;
35   }
36
37   return m_info.size();
38 }
39
40 QVariant FileInfoModel::data(const QModelIndex& index, int role) const {
41   if (index.isValid() && index.row() < m_info.count() && role == Qt::DisplayRole) {
42     return m_info[index.row()];
43   }
44
45   return QVariant();
46 }
47
48 void FileInfoModel::setFiles(const QStringList& files) {
49   clear();
50
51   appendFiles(files);
52 }
53
54 void FileInfoModel::appendFile(const QString& file) {
55   appendFiles(QStringList() << file);
56 }
57
58 void FileInfoModel::appendFiles(const QStringList& files) {
59   if (files.isEmpty()) {
60     return;
61   }
62
63   beginInsertRows(QModelIndex(), m_info.size(), files.size() - 1);
64   m_info << files;
65   endInsertRows();
66 }
67
68 void FileInfoModel::removeFile(const QString& file) {
69   int index = m_info.indexOf(file);
70
71   if (index == -1) {
72     return;
73   }
74
75   beginRemoveRows(QModelIndex(), index, index);
76   m_info.removeAt(index);
77   endRemoveRows();
78 }
79
80 void FileInfoModel::clear() {
81   if (m_info.isEmpty()) {
82     return;
83   }
84
85   beginRemoveRows(QModelIndex(), 0, m_info.size());
86   m_info.clear();
87   endRemoveRows();
88 }