1 /*
2  * Copyright (C) 2013  Daniel Vrátil <dvratil@redhat.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  *
18  */
19 
20 #ifndef DATESMODEL_H
21 #define DATESMODEL_H
22 
23 #include <QtCore/QAbstractItemModel>
24 
25 #include <TelepathyQt/Types>
26 
27 namespace KTp {
28     class PendingLoggerOperation;
29     class LogEntity;
30     class LogSearchHit;
31 }
32 
33 /**
34  * Model with dates of all conversations between you and set entity
35  *
36  * The model automatically sorts dates in descending order
37  */
38 class DatesModel : public QAbstractItemModel
39 {
40     Q_OBJECT
41 
42   public:
43     enum Roles {
44         TypeRole = Qt::UserRole + 1,
45         DateRole,
46         HintRole,
47         AccountRole,
48         EntityRole
49     };
50 
51     enum RowTypes {
52         GroupRow,
53         DateRow,
54         ConversationRow
55     };
56 
57     explicit DatesModel(QObject* parent = 0);
58     virtual ~DatesModel();
59 
60     void addEntity(const Tp::AccountPtr &account, const KTp::LogEntity &entity);
61     void setEntity(const Tp::AccountPtr &account, const KTp::LogEntity &entity);
62 
63     void setSearchHits(const QList<KTp::LogSearchHit> &searchHits);
64     void clearSearchHits();
65 
66     void clear();
67 
68     QDate previousDate(const QModelIndex &index) const;
69     QDate nextDate(const QModelIndex &index) const;
70     QModelIndex indexForDate(const QDate &date) const;
71 
72     virtual QVariant data(const QModelIndex& index, int role) const;
73     virtual int columnCount(const QModelIndex& parent) const;
74     virtual int rowCount(const QModelIndex& parent) const;
75     virtual QModelIndex parent(const QModelIndex& child) const;
76     virtual QModelIndex index(int row, int column, const QModelIndex& parent) const;
77 
78   Q_SIGNALS:
79     void datesReceived();
80 
81   private Q_SLOTS:
82     void onDatesReceived(KTp::PendingLoggerOperation *operation);
83 
84   private:
85     class Private;
86     Private * const d;
87 };
88 
89 #endif // DATESMODEL_H
90