1
/****************************************************************************
2
* Copyright (C) 2013-2014 by Savoir-Faire Linux *
3
* Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
5
* This library is free software; you can redistribute it and/or *
6
* modify it under the terms of the GNU Lesser General Public *
7
* License as published by the Free Software Foundation; either *
8
* version 2.1 of the License, or (at your option) any later version. *
10
* This library 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 GNU *
13
* Lesser General Public License for more details. *
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
#ifndef ABSTRACTBOOKMARKMODEL_H
19
#define ABSTRACTBOOKMARKMODEL_H
21
#include <QtCore/QAbstractItemModel>
22
#include <QtCore/QHash>
23
#include <QtCore/QStringList>
24
#include <QtCore/QDateTime>
27
#include "../lib/typedefs.h"
28
#include "../lib/contact.h"
29
#include "../lib/call.h"
31
class NumberTreeBackend;
33
class LIB_EXPORT AbstractBookmarkModel : public QAbstractItemModel
35
#pragma GCC diagnostic push
36
#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
38
#pragma GCC diagnostic pop
40
friend class NumberTreeBackend;
42
virtual ~AbstractBookmarkModel() {}
43
explicit AbstractBookmarkModel(QObject* parent);
46
void setRole(int role);
47
void setShowAll(bool showAll);
49
//Model implementation
50
virtual bool setData ( const QModelIndex& index, const QVariant &value, int role );
51
virtual QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const;
52
virtual int rowCount ( const QModelIndex& parent = QModelIndex() ) const;
53
virtual Qt::ItemFlags flags ( const QModelIndex& index ) const;
54
virtual int columnCount ( const QModelIndex& parent = QModelIndex() ) const;
55
virtual QModelIndex parent ( const QModelIndex& index ) const;
56
virtual QModelIndex index ( int row, int column, const QModelIndex& parent=QModelIndex()) const;
57
virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
58
virtual QStringList mimeTypes ( ) const;
59
virtual QMimeData* mimeData ( const QModelIndexList &indexes ) const;
60
virtual bool removeRows ( int row, int count, const QModelIndex & parent = QModelIndex() );
63
void remove(const QModelIndex& idx );
64
virtual void addBookmark (PhoneNumber* number, bool trackPresence = false) = 0;
65
virtual void removeBookmark(PhoneNumber* number ) = 0;
68
int acceptedPayloadTypes();
71
virtual bool displayFrequentlyUsed() const;
72
virtual QVector<PhoneNumber*> bookmarkList () const;
75
static QVector<PhoneNumber*> serialisedToList(const QStringList& list);
78
///Top level bookmark item
79
class TopLevelItem : public CategorizedCompositeNode {
80
friend class AbstractBookmarkModel;
82
virtual QObject* getSelf() const;
85
explicit TopLevelItem(QString name);
86
QList<NumberTreeBackend*> m_lChildren;
92
QList<TopLevelItem*> m_lCategoryCounter ;
93
QHash<QString,TopLevelItem*> m_hCategories ;
94
QStringList m_lMimes ;
97
QModelIndex getContactIndex(Contact* ct) const;
100
QVariant commonCallInfo(NumberTreeBackend* call, int role = Qt::DisplayRole) const;
101
QString category(NumberTreeBackend* number) const;
104
void slotRequest(const QString& uri);
105
void slotIndexChanged(const QModelIndex& idx);
108
void reloadCategories();
111
class BookmarkItemNode : public QObject //TODO remove this once Qt4 support is dropped
115
BookmarkItemNode(AbstractBookmarkModel* m, PhoneNumber* n, NumberTreeBackend* backend);
117
PhoneNumber* m_pNumber;
118
NumberTreeBackend* m_pBackend;
119
AbstractBookmarkModel* m_pModel;
121
void slotNumberChanged();
123
void changed(const QModelIndex& idx);