categorizedbookmarkmodel.h 4.14 KB
Newer Older
1
/****************************************************************************
Guillaume Roguez's avatar
Guillaume Roguez committed
2
 *   Copyright (C) 2013-2018 Savoir-faire Linux                          *
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
 *   Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
 *                                                                          *
 *   This library is free software; you can redistribute it and/or          *
 *   modify it under the terms of the GNU Lesser General Public             *
 *   License as published by the Free Software Foundation; either           *
 *   version 2.1 of the License, or (at your option) any later version.     *
 *                                                                          *
 *   This library is distributed in the hope that it will be useful,        *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU      *
 *   Lesser General Public License for more details.                        *
 *                                                                          *
 *   You should have received a copy of the GNU General Public License      *
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.  *
 ***************************************************************************/
Guillaume Roguez's avatar
Guillaume Roguez committed
18
#pragma once
19 20 21 22 23 24

#include <QtCore/QAbstractItemModel>
#include <QtCore/QHash>
#include <QtCore/QStringList>
#include <QtCore/QDateTime>

25
//Ring
26 27
#include "collectionmanagerinterface.h"
#include "collectioninterface.h"
28
#include "typedefs.h"
29
#include "contactmethod.h"
30
// #include "person.h"
31
// #include "call.h"
32
class PersonBackend;
33 34
class NumberTreeBackend;

35
class CategorizedBookmarkModelPrivate;
36
class CollectionInterface2;
37

38
class LIB_EXPORT CategorizedBookmarkModel :  public QAbstractItemModel, public CollectionManagerInterface<ContactMethod>
39 40 41 42 43 44
{
   #pragma GCC diagnostic push
   #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
   Q_OBJECT
   #pragma GCC diagnostic pop
public:
45
   friend class NumberTreeBackend;
46
   //Constructor
47
   virtual ~CategorizedBookmarkModel();
48
   explicit CategorizedBookmarkModel(QObject* parent);
49 50 51 52 53 54

   //Setters
   void setRole(int role);
   void setShowAll(bool showAll);

   //Model implementation
55 56 57 58 59 60 61 62 63 64
   virtual bool          setData     ( const QModelIndex& index, const QVariant &value, int role   )       override;
   virtual QVariant      data        ( const QModelIndex& index, int role = Qt::DisplayRole        ) const override;
   virtual int           rowCount    ( const QModelIndex& parent = QModelIndex()                   ) const override;
   virtual Qt::ItemFlags flags       ( const QModelIndex& index                                    ) const override;
   virtual int           columnCount ( const QModelIndex& parent = QModelIndex()                   ) const override;
   virtual QModelIndex   parent      ( const QModelIndex& index                                    ) const override;
   virtual QModelIndex   index       ( int row, int column, const QModelIndex& parent=QModelIndex()) const override;
   virtual QStringList   mimeTypes   (                                                             ) const override;
   virtual QMimeData*    mimeData    ( const QModelIndexList &indexes                              ) const override;
   virtual QVariant      headerData  ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
65
   virtual QHash<int,QByteArray> roleNames() const override;
66 67

   //Management
68
   void remove        (const QModelIndex& idx );
69 70
   void addBookmark   (ContactMethod* number    );
   void removeBookmark(ContactMethod* number    );
71

72
   //Getters
73
   int          acceptedPayloadTypes();
74
   ContactMethod* getNumber(const QModelIndex& idx);
75

76
   //Singleton
77
   static CategorizedBookmarkModel& instance();
78

79
private:
80 81
   CategorizedBookmarkModelPrivate* d_ptr;
   Q_DECLARE_PRIVATE(CategorizedBookmarkModel)
82

83
   //Backend interface
84 85 86
   virtual void collectionAddedCallback(CollectionInterface* backend) override;
   virtual bool addItemCallback(const ContactMethod* item) override;
   virtual bool removeItemCallback(const ContactMethod* item) override;
87

88 89 90 91
public Q_SLOTS:
   void reloadCategories();
};