From 7eac9876a754d1e5f40ed59e69f03fa9bf1d8a1a Mon Sep 17 00:00:00 2001
From: Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com>
Date: Mon, 19 Jan 2015 17:07:35 -0500
Subject: [PATCH] [ #64072 ] Fix bookmark and contact d-pointers

Also remove the legacy history backend, it is not needed anymore
---
 CMakeLists.txt               |   2 -
 src/bookmarkmodel.cpp        | 168 +++++++++++++++++++++++------------
 src/bookmarkmodel.h          |  40 +--------
 src/contact.cpp              | 126 +++++++++++++-------------
 src/contact.h                |   2 +-
 src/contactproxymodel.cpp    |  40 ++++-----
 src/historymodel.h           |   1 -
 src/legacyhistorybackend.cpp | 121 -------------------------
 src/legacyhistorybackend.h   |  54 -----------
 9 files changed, 197 insertions(+), 357 deletions(-)
 delete mode 100644 src/legacyhistorybackend.cpp
 delete mode 100644 src/legacyhistorybackend.h

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3f6b9e2c..46223aee 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -103,7 +103,6 @@ SET( libringclient_LIB_SRCS
 
   #Data backends
   src/transitionalcontactbackend.cpp
-  src/legacyhistorybackend.cpp
   src/abstractitembackend.cpp
 
   #Communication
@@ -167,7 +166,6 @@ SET( libringclient_LIB_HDRS
   src/categorizedcompositenode.h
   src/abstractitembackendmodelextension.h
   src/commonbackendmanagerinterface.h
-  src/legacyhistorybackend.h
   src/networkinterfacemodel.h
 )
 
diff --git a/src/bookmarkmodel.cpp b/src/bookmarkmodel.cpp
index 7a8e483b..169aba57 100644
--- a/src/bookmarkmodel.cpp
+++ b/src/bookmarkmodel.cpp
@@ -31,6 +31,50 @@
 #include "mime.h"
 #include "abstractitembackend.h"
 
+///Top level bookmark item
+class BookmarkTopLevelItem : public CategorizedCompositeNode {
+   friend class BookmarkModel;
+   public:
+      virtual QObject* getSelf() const;
+      int m_Row;
+   private:
+      explicit BookmarkTopLevelItem(QString name);
+      QList<NumberTreeBackend*> m_lChildren;
+      QString m_Name;
+      bool m_MostPopular;
+};
+
+class BookmarkModelPrivate : public QObject
+{
+   Q_OBJECT
+public:
+   BookmarkModelPrivate(BookmarkModel* parent);
+
+   QVector<AbstractBookmarkBackend*> m_lBackends;
+
+   //Attributes
+   QList<BookmarkTopLevelItem*>         m_lCategoryCounter ;
+   QHash<QString,BookmarkTopLevelItem*> m_hCategories      ;
+   QStringList                  m_lMimes           ;
+
+   //Getters
+   QModelIndex getContactIndex(Contact* ct) const;
+
+   //Helpers
+   QVariant commonCallInfo(NumberTreeBackend* call, int role = Qt::DisplayRole) const;
+   QString category(NumberTreeBackend* number) const;
+   bool                  displayFrequentlyUsed() const;
+   QList<PhoneNumber*>   bookmarkList         () const;
+   static QVector<PhoneNumber*> serialisedToList(const QStringList& list);
+
+private Q_SLOTS:
+   void slotRequest(const QString& uri);
+   void slotIndexChanged(const QModelIndex& idx);
+
+private:
+   BookmarkModel* q_ptr;
+};
+
 BookmarkModel* BookmarkModel::m_spInstance = nullptr;
 
 class BookmarkItemNode;
@@ -46,7 +90,7 @@ class NumberTreeBackend : public CategorizedCompositeNode
       virtual QObject* getSelf() const { return nullptr; }
 
       PhoneNumber* m_pNumber;
-      BookmarkModel::TopLevelItem* m_pParent;
+      BookmarkTopLevelItem* m_pParent;
       int m_Index;
       BookmarkItemNode* m_pNode;
 };
@@ -66,6 +110,11 @@ Q_SIGNALS:
    void changed(const QModelIndex& idx);
 };
 
+BookmarkModelPrivate::BookmarkModelPrivate(BookmarkModel* parent) : QObject(parent), q_ptr(parent)
+{
+   
+}
+
 NumberTreeBackend::NumberTreeBackend(PhoneNumber* number): CategorizedCompositeNode(CategorizedCompositeNode::Type::BOOKMARK),
    m_pNumber(number),m_pParent(nullptr),m_pNode(nullptr),m_Index(-1){
    Q_ASSERT(number != nullptr);
@@ -85,18 +134,19 @@ void BookmarkItemNode::slotNumberChanged()
    emit changed(m_pModel->index(m_pBackend->m_Index,0,m_pModel->index(m_pBackend->m_pParent->m_Row,0)));
 }
 
-QObject* BookmarkModel::TopLevelItem::getSelf() const
+QObject* BookmarkTopLevelItem::getSelf() const
 {
    return nullptr;
 }
 
-BookmarkModel::BookmarkModel(QObject* parent) : QAbstractItemModel(parent){
+BookmarkModel::BookmarkModel(QObject* parent) : QAbstractItemModel(parent), d_ptr(new BookmarkModelPrivate(this))
+{
    setObjectName("BookmarkModel");
    reloadCategories();
-   m_lMimes << RingMimes::PLAIN_TEXT << RingMimes::PHONENUMBER;
+   d_ptr->m_lMimes << RingMimes::PLAIN_TEXT << RingMimes::PHONENUMBER;
 
    //Connect
-   connect(&DBus::PresenceManager::instance(),SIGNAL(newServerSubscriptionRequest(QString)),this,SLOT(slotRequest(QString)));
+   connect(&DBus::PresenceManager::instance(),SIGNAL(newServerSubscriptionRequest(QString)),d_ptr,SLOT(slotRequest(QString)));
 //    if (Call::contactBackend()) {
 //       connect(Call::contactBackend(),SIGNAL(collectionChanged()),this,SLOT(reloadCategories()));
 //    } //TODO implement reordering
@@ -114,24 +164,24 @@ void BookmarkModel::reloadCategories()
 {
    test = true;
    beginResetModel(); {
-      m_hCategories.clear();
+      d_ptr->m_hCategories.clear();
 
       //TODO this is not efficient, nor necessary
-      foreach(TopLevelItem* item, m_lCategoryCounter) {
+      foreach(BookmarkTopLevelItem* item, d_ptr->m_lCategoryCounter) {
          foreach (NumberTreeBackend* child, item->m_lChildren) {
             delete child;
          }
          delete item;
       }
-      m_lCategoryCounter.clear();
+      d_ptr->m_lCategoryCounter.clear();
 
       //Load most used contacts
-      if (displayFrequentlyUsed()) {
-         TopLevelItem* item = new TopLevelItem(tr("Most popular"));
-         m_hCategories["mp"] = item;
-         item->m_Row = m_lCategoryCounter.size();
+      if (d_ptr->displayFrequentlyUsed()) {
+         BookmarkTopLevelItem* item = new BookmarkTopLevelItem(tr("Most popular"));
+         d_ptr->m_hCategories["mp"] = item;
+         item->m_Row = d_ptr->m_lCategoryCounter.size();
          item->m_MostPopular = true;
-         m_lCategoryCounter << item;
+         d_ptr->m_lCategoryCounter << item;
          const QVector<PhoneNumber*> cl = PhoneDirectoryModel::instance()->getNumbersByPopularity();
 
          for (int i=0;i<((cl.size()>=10)?10:cl.size());i++) {
@@ -140,28 +190,28 @@ void BookmarkModel::reloadCategories()
             bm->m_pParent = item;
             bm->m_Index = item->m_lChildren.size();
             bm->m_pNode = new BookmarkItemNode(this,n,bm);
-            connect(bm->m_pNode,SIGNAL(changed(QModelIndex)),this,SLOT(slotIndexChanged(QModelIndex)));
+            connect(bm->m_pNode,SIGNAL(changed(QModelIndex)),d_ptr,SLOT(slotIndexChanged(QModelIndex)));
             item->m_lChildren << bm;
          }
 
       }
 
-      foreach(PhoneNumber* bookmark, bookmarkList()) {
+      foreach(PhoneNumber* bookmark, d_ptr->bookmarkList()) {
          NumberTreeBackend* bm = new NumberTreeBackend(bookmark);
-         const QString val = category(bm);
-         if (!m_hCategories[val]) {
-            TopLevelItem* item = new TopLevelItem(val);
-            m_hCategories[val] = item;
-            item->m_Row = m_lCategoryCounter.size();
-            m_lCategoryCounter << item;
+         const QString val = d_ptr->category(bm);
+         if (!d_ptr->m_hCategories[val]) {
+            BookmarkTopLevelItem* item = new BookmarkTopLevelItem(val);
+            d_ptr->m_hCategories[val] = item;
+            item->m_Row = d_ptr->m_lCategoryCounter.size();
+            d_ptr->m_lCategoryCounter << item;
          }
-         TopLevelItem* item = m_hCategories[val];
+         BookmarkTopLevelItem* item = d_ptr->m_hCategories[val];
          if (item) {
             bookmark->setBookmarked(true);
             bm->m_pParent = item;
             bm->m_Index = item->m_lChildren.size();
             bm->m_pNode = new BookmarkItemNode(this,bookmark,bm);
-            connect(bm->m_pNode,SIGNAL(changed(QModelIndex)),this,SLOT(slotIndexChanged(QModelIndex)));
+            connect(bm->m_pNode,SIGNAL(changed(QModelIndex)),d_ptr,SLOT(slotIndexChanged(QModelIndex)));
             item->m_lChildren << bm;
          }
          else
@@ -197,18 +247,18 @@ QVariant BookmarkModel::data( const QModelIndex& index, int role) const
       case CategorizedCompositeNode::Type::TOP_LEVEL:
          switch (role) {
             case Qt::DisplayRole:
-               return static_cast<TopLevelItem*>(modelItem)->m_Name;
+               return static_cast<BookmarkTopLevelItem*>(modelItem)->m_Name;
             case Call::Role::Name:
-               if (static_cast<TopLevelItem*>(modelItem)->m_MostPopular) {
+               if (static_cast<BookmarkTopLevelItem*>(modelItem)->m_MostPopular) {
                   return "000000";
                }
                else {
-                  return static_cast<TopLevelItem*>(modelItem)->m_Name;
+                  return static_cast<BookmarkTopLevelItem*>(modelItem)->m_Name;
                }
          }
          break;
       case CategorizedCompositeNode::Type::BOOKMARK:
-         return commonCallInfo(static_cast<NumberTreeBackend*>(modelItem),role);
+         return d_ptr->commonCallInfo(static_cast<NumberTreeBackend*>(modelItem),role);
          break;
       case CategorizedCompositeNode::Type::CALL:
       case CategorizedCompositeNode::Type::NUMBER:
@@ -233,9 +283,9 @@ int BookmarkModel::rowCount( const QModelIndex& parent ) const
 {
    if (test) return 0; //HACK
    if (!parent.isValid())
-      return m_lCategoryCounter.size();
-   else if (!parent.parent().isValid() && parent.row() < m_lCategoryCounter.size()) {
-      TopLevelItem* item = static_cast<TopLevelItem*>(parent.internalPointer());
+      return d_ptr->m_lCategoryCounter.size();
+   else if (!parent.parent().isValid() && parent.row() < d_ptr->m_lCategoryCounter.size()) {
+      BookmarkTopLevelItem* item = static_cast<BookmarkTopLevelItem*>(parent.internalPointer());
       return item->m_lChildren.size();
    }
    return 0;
@@ -263,7 +313,7 @@ QModelIndex BookmarkModel::parent( const QModelIndex& idx) const
    }
    const CategorizedCompositeNode* modelItem = static_cast<CategorizedCompositeNode*>(idx.internalPointer());
    if (modelItem->type() == CategorizedCompositeNode::Type::BOOKMARK) {
-      TopLevelItem* item = static_cast<const NumberTreeBackend*>(modelItem)->m_pParent;
+      BookmarkTopLevelItem* item = static_cast<const NumberTreeBackend*>(modelItem)->m_pParent;
       if (item) {
          return index(item->m_Row,0);
       }
@@ -275,16 +325,16 @@ QModelIndex BookmarkModel::parent( const QModelIndex& idx) const
 QModelIndex BookmarkModel::index(int row, int column, const QModelIndex& parent) const
 {
    if (parent.isValid())
-      return createIndex(row,column,(void*) static_cast<CategorizedCompositeNode*>(m_lCategoryCounter[parent.row()]->m_lChildren[row]));
+      return createIndex(row,column,(void*) static_cast<CategorizedCompositeNode*>(d_ptr->m_lCategoryCounter[parent.row()]->m_lChildren[row]));
    else {
-      return createIndex(row,column,(void*) static_cast<CategorizedCompositeNode*>(m_lCategoryCounter[row]));
+      return createIndex(row,column,(void*) static_cast<CategorizedCompositeNode*>(d_ptr->m_lCategoryCounter[row]));
    }
 }
 
 ///Get bookmarks mime types
 QStringList BookmarkModel::mimeTypes() const
 {
-   return m_lMimes;
+   return d_ptr->m_lMimes;
 }
 
 ///Generate mime data
@@ -309,7 +359,7 @@ int BookmarkModel::acceptedPayloadTypes()
 }
 
 ///Get call info TODO use Call:: one
-QVariant BookmarkModel::commonCallInfo(NumberTreeBackend* number, int role) const
+QVariant BookmarkModelPrivate::commonCallInfo(NumberTreeBackend* number, int role) const
 {
    if (!number)
       return QVariant();
@@ -364,7 +414,7 @@ QVariant BookmarkModel::commonCallInfo(NumberTreeBackend* number, int role) cons
 } //commonCallInfo
 
 ///Get category
-QString BookmarkModel::category(NumberTreeBackend* number) const
+QString BookmarkModelPrivate::category(NumberTreeBackend* number) const
 {
    QString cat = commonCallInfo(number).toString();
    if (cat.size())
@@ -372,7 +422,7 @@ QString BookmarkModel::category(NumberTreeBackend* number) const
    return cat;
 }
 
-void BookmarkModel::slotRequest(const QString& uri)
+void BookmarkModelPrivate::slotRequest(const QString& uri)
 {
    Q_UNUSED(uri)
    qDebug() << "Presence Request" << uri << "denied";
@@ -381,7 +431,7 @@ void BookmarkModel::slotRequest(const QString& uri)
 
 
 
-QVector<PhoneNumber*> BookmarkModel::serialisedToList(const QStringList& list)
+QVector<PhoneNumber*> BookmarkModelPrivate::serialisedToList(const QStringList& list)
 {
    QVector<PhoneNumber*> numbers;
    foreach(const QString& item,list) {
@@ -395,17 +445,17 @@ QVector<PhoneNumber*> BookmarkModel::serialisedToList(const QStringList& list)
    return numbers;
 }
 
-bool BookmarkModel::displayFrequentlyUsed() const
+bool BookmarkModelPrivate::displayFrequentlyUsed() const
 {
    return true;
 }
 
-QList<PhoneNumber*> BookmarkModel::bookmarkList() const
+QList<PhoneNumber*> BookmarkModelPrivate::bookmarkList() const
 {
    return (m_lBackends.size() > 0) ? m_lBackends[0]->items() : QList<PhoneNumber*>();
 }
 
-BookmarkModel::TopLevelItem::TopLevelItem(QString name) 
+BookmarkTopLevelItem::BookmarkTopLevelItem(QString name) 
    : CategorizedCompositeNode(CategorizedCompositeNode::Type::TOP_LEVEL),m_Name(name),
       m_MostPopular(false),m_Row(-1)
 {
@@ -417,14 +467,14 @@ bool BookmarkModel::removeRows( int row, int count, const QModelIndex & parent)
       const int parentRow = parent.row();
       beginRemoveRows(parent,row,row+count-1);
       for (int i=row;i<row+count;i++)
-         m_lCategoryCounter[parent.row()]->m_lChildren.removeAt(i);
+         d_ptr->m_lCategoryCounter[parent.row()]->m_lChildren.removeAt(i);
       endRemoveRows();
-      if (!m_lCategoryCounter[parentRow]->m_lChildren.size()) {
+      if (!d_ptr->m_lCategoryCounter[parentRow]->m_lChildren.size()) {
          beginRemoveRows(QModelIndex(),parentRow,parentRow);
-         m_hCategories.remove(m_hCategories.key(m_lCategoryCounter[parentRow]));
-         m_lCategoryCounter.removeAt(parentRow);
-         for (int i=0;i<m_lCategoryCounter.size();i++) {
-            m_lCategoryCounter[i]->m_Row =i;
+         d_ptr->m_hCategories.remove(d_ptr->m_hCategories.key(d_ptr->m_lCategoryCounter[parentRow]));
+         d_ptr->m_lCategoryCounter.removeAt(parentRow);
+         for (int i=0;i<d_ptr->m_lCategoryCounter.size();i++) {
+            d_ptr->m_lCategoryCounter[i]->m_Row =i;
          }
          endRemoveRows();
       }
@@ -436,8 +486,8 @@ bool BookmarkModel::removeRows( int row, int count, const QModelIndex & parent)
 void BookmarkModel::addBookmark(PhoneNumber* number)
 {
    Q_UNUSED(number)
-   if (m_lBackends.size())
-      m_lBackends[0]->append(number);
+   if (d_ptr->m_lBackends.size())
+      d_ptr->m_lBackends[0]->append(number);
    else
       qWarning() << "No bookmark backend is set";
 }
@@ -461,28 +511,28 @@ void BookmarkModel::remove(const QModelIndex& idx)
 PhoneNumber* BookmarkModel::getNumber(const QModelIndex& idx)
 {
    if (idx.isValid()) {
-      if (idx.parent().isValid() && idx.parent().row() < m_lCategoryCounter.size()) {
-         return m_lCategoryCounter[idx.parent().row()]->m_lChildren[idx.row()]->m_pNumber;
+      if (idx.parent().isValid() && idx.parent().row() < d_ptr->m_lCategoryCounter.size()) {
+         return d_ptr->m_lCategoryCounter[idx.parent().row()]->m_lChildren[idx.row()]->m_pNumber;
       }
    }
    return nullptr;
 }
 
 ///Callback when an item change
-void BookmarkModel::slotIndexChanged(const QModelIndex& idx)
+void BookmarkModelPrivate::slotIndexChanged(const QModelIndex& idx)
 {
-   emit dataChanged(idx,idx);
+   emit q_ptr->dataChanged(idx,idx);
 }
 
 
 bool BookmarkModel::hasBackends() const
 {
-   return m_lBackends.size();
+   return d_ptr->m_lBackends.size();
 }
 
 bool BookmarkModel::hasEnabledBackends() const
 {
-   foreach(AbstractBookmarkBackend* b, m_lBackends) {
+   foreach(AbstractBookmarkBackend* b, d_ptr->m_lBackends) {
       if (b->isEnabled())
          return true;
    }
@@ -491,12 +541,12 @@ bool BookmarkModel::hasEnabledBackends() const
 
 const QVector<AbstractBookmarkBackend*> BookmarkModel::backends() const
 {
-   return m_lBackends;
+   return d_ptr->m_lBackends;
 }
 
 const QVector<AbstractBookmarkBackend*> BookmarkModel::enabledBackends() const
 {
-   return m_lBackends; //TODO filter them
+   return d_ptr->m_lBackends; //TODO filter them
 }
 
 CommonItemBackendModel* BookmarkModel::backendModel() const
@@ -506,7 +556,7 @@ CommonItemBackendModel* BookmarkModel::backendModel() const
 
 bool BookmarkModel::clearAllBackends() const
 {
-   foreach (AbstractBookmarkBackend* backend, m_lBackends) {
+   foreach (AbstractBookmarkBackend* backend, d_ptr->m_lBackends) {
       if (backend->supportedFeatures() & AbstractBookmarkBackend::ADD) {
          backend->clear();
       }
@@ -520,7 +570,7 @@ bool BookmarkModel::enableBackend(AbstractBookmarkBackend* backend, bool enable)
 
 void BookmarkModel::addBackend(AbstractBookmarkBackend* backend, LoadOptions options)
 {
-   m_lBackends << backend;
+   d_ptr->m_lBackends << backend;
    connect(backend,SIGNAL(newBookmarkAdded(PhoneNumber*)),this,SLOT(reloadCategories()));
    if (options & LoadOptions::FORCE_ENABLED)
       backend->load();
diff --git a/src/bookmarkmodel.h b/src/bookmarkmodel.h
index 922f7540..9b4bca12 100644
--- a/src/bookmarkmodel.h
+++ b/src/bookmarkmodel.h
@@ -32,6 +32,8 @@
 class ContactBackend;
 class NumberTreeBackend;
 
+class BookmarkModelPrivate;
+
 class LIB_EXPORT BookmarkModel :  public QAbstractItemModel, public CommonBackendManagerInterface<AbstractBookmarkBackend>
 {
    #pragma GCC diagnostic push
@@ -83,45 +85,11 @@ public:
    //Singleton
    static BookmarkModel* instance();
 
-protected:
-   bool                  displayFrequentlyUsed() const;
-   QList<PhoneNumber*>   bookmarkList         () const;
-
-   //Helpers
-   static QVector<PhoneNumber*> serialisedToList(const QStringList& list);
-
 private:
    static BookmarkModel* m_spInstance;
-   ///Top level bookmark item
-   class TopLevelItem : public CategorizedCompositeNode {
-      friend class BookmarkModel;
-      public:
-         virtual QObject* getSelf() const;
-         int m_Row;
-      private:
-         explicit TopLevelItem(QString name);
-         QList<NumberTreeBackend*> m_lChildren;
-         QString m_Name;
-         bool m_MostPopular;
-   };
-
-   QVector<AbstractBookmarkBackend*> m_lBackends;
-
-   //Attributes
-   QList<TopLevelItem*>         m_lCategoryCounter ;
-   QHash<QString,TopLevelItem*> m_hCategories      ;
-   QStringList                  m_lMimes           ;
-
-   //Getters
-   QModelIndex getContactIndex(Contact* ct) const;
-
-   //Helpers
-   QVariant commonCallInfo(NumberTreeBackend* call, int role = Qt::DisplayRole) const;
-   QString category(NumberTreeBackend* number) const;
 
-private Q_SLOTS:
-   void slotRequest(const QString& uri);
-   void slotIndexChanged(const QModelIndex& idx);
+   BookmarkModelPrivate* d_ptr;
+   Q_DECLARE_PRIVATE(BookmarkModel);
 
 public Q_SLOTS:
    void reloadCategories();
diff --git a/src/contact.cpp b/src/contact.cpp
index bff43fe6..926e006a 100644
--- a/src/contact.cpp
+++ b/src/contact.cpp
@@ -148,188 +148,188 @@ Contact* Contact::PhoneNumbers::contact() const
 
 ///Constructor
 Contact::Contact(AbstractContactBackend* parent):QObject(parent?parent:TransitionalContactBackend::instance()),
-   d(new ContactPrivate(this,parent))
+   d_ptr(new ContactPrivate(this,parent))
 {
-   d->m_isPlaceHolder = false;
-   d->m_lParents << this;
+   d_ptr->m_isPlaceHolder = false;
+   d_ptr->m_lParents << this;
 }
 
 ///Destructor
 Contact::~Contact()
 {
    //Unregister itself from the D-Pointer list
-   d->m_lParents.removeAll(this);
+   d_ptr->m_lParents.removeAll(this);
 
-   if (!d->m_lParents.size()) {
-      delete d;
+   if (!d_ptr->m_lParents.size()) {
+      delete d_ptr;
    }
 }
 
 ///Get the phone number list
 const Contact::PhoneNumbers& Contact::phoneNumbers() const
 {
-   return d->m_Numbers;
+   return d_ptr->m_Numbers;
 }
 
 ///Get the nickname
 const QString& Contact::nickName() const
 {
-   return d->m_NickName;
+   return d_ptr->m_NickName;
 }
 
 ///Get the firstname
 const QString& Contact::firstName() const
 {
-   return d->m_FirstName;
+   return d_ptr->m_FirstName;
 }
 
 ///Get the second/family name
 const QString& Contact::secondName() const
 {
-   return d->m_SecondName;
+   return d_ptr->m_SecondName;
 }
 
 ///Get the photo
 const QPixmap* Contact::photo() const
 {
-   return d->m_pPhoto;
+   return d_ptr->m_pPhoto;
 }
 
 ///Get the formatted name
 const QString& Contact::formattedName() const
 {
-   return d->m_FormattedName;
+   return d_ptr->m_FormattedName;
 }
 
 ///Get the organisation
 const QString& Contact::organization()  const
 {
-   return d->m_Organization;
+   return d_ptr->m_Organization;
 }
 
 ///Get the preferred email
 const QString& Contact::preferredEmail()  const
 {
-   return d->m_PreferredEmail;
+   return d_ptr->m_PreferredEmail;
 }
 
 ///Get the unique identifier (used for drag and drop) 
 const QByteArray& Contact::uid() const
 {
-   return d->m_Uid;
+   return d_ptr->m_Uid;
 }
 
 ///Get the group
 const QString& Contact::group() const
 {
-   return d->m_Group;
+   return d_ptr->m_Group;
 }
 
 const QString& Contact::department() const
 {
-   return d->m_Department;
+   return d_ptr->m_Department;
 }
 
 ///Set the phone number (type and number)
 void Contact::setPhoneNumbers(PhoneNumbers numbers)
 {
-   const int oldCount(d->m_Numbers.size()),newCount(numbers.size());
-   foreach(PhoneNumber* n, d->m_Numbers)
+   const int oldCount(d_ptr->m_Numbers.size()),newCount(numbers.size());
+   foreach(PhoneNumber* n, d_ptr->m_Numbers)
       disconnect(n,SIGNAL(presentChanged(bool)),this,SLOT(slotPresenceChanged()));
-   d->m_Numbers = numbers;
+   d_ptr->m_Numbers = numbers;
    if (newCount < oldCount) //Rows need to be removed from models first
-      d->phoneNumberCountAboutToChange(newCount,oldCount);
-   foreach(PhoneNumber* n, d->m_Numbers)
+      d_ptr->phoneNumberCountAboutToChange(newCount,oldCount);
+   foreach(PhoneNumber* n, d_ptr->m_Numbers)
       connect(n,SIGNAL(presentChanged(bool)),this,SLOT(slotPresenceChanged()));
    if (newCount > oldCount) //Need to be updated after the data to prevent invalid memory access
-      d->phoneNumberCountChanged(newCount,oldCount);
-   d->changed();
+      d_ptr->phoneNumberCountChanged(newCount,oldCount);
+   d_ptr->changed();
 }
 
 ///Set the nickname
 void Contact::setNickName(const QString& name)
 {
-   d->m_NickName = name;
-   d->changed();
+   d_ptr->m_NickName = name;
+   d_ptr->changed();
 }
 
 ///Set the first name
 void Contact::setFirstName(const QString& name)
 {
-   d->m_FirstName = name;
+   d_ptr->m_FirstName = name;
    setObjectName(formattedName());
-   d->changed();
+   d_ptr->changed();
 }
 
 ///Set the family name
 void Contact::setFamilyName(const QString& name)
 {
-   d->m_SecondName = name;
+   d_ptr->m_SecondName = name;
    setObjectName(formattedName());
-   d->changed();
+   d_ptr->changed();
 }
 
 ///Set the Photo/Avatar
 void Contact::setPhoto(QPixmap* photo)
 {
-   d->m_pPhoto = photo;
-   d->changed();
+   d_ptr->m_pPhoto = photo;
+   d_ptr->changed();
 }
 
 ///Set the formatted name (display name)
 void Contact::setFormattedName(const QString& name)
 {
-   d->m_FormattedName = name;
-   d->changed();
+   d_ptr->m_FormattedName = name;
+   d_ptr->changed();
 }
 
 ///Set the organisation / business
 void Contact::setOrganization(const QString& name)
 {
-   d->m_Organization = name;
-   d->changed();
+   d_ptr->m_Organization = name;
+   d_ptr->changed();
 }
 
 ///Set the default email
 void Contact::setPreferredEmail(const QString& name)
 {
-   d->m_PreferredEmail = name;
-   d->changed();
+   d_ptr->m_PreferredEmail = name;
+   d_ptr->changed();
 }
 
 ///Set UID
 void Contact::setUid(const QByteArray& id)
 {
-   d->m_Uid = id;
-   d->changed();
+   d_ptr->m_Uid = id;
+   d_ptr->changed();
 }
 
 ///Set Group
 void Contact::setGroup(const QString& name)
 {
-   d->m_Group = name;
-   d->changed();
+   d_ptr->m_Group = name;
+   d_ptr->changed();
 }
 
 ///Set department
 void Contact::setDepartment(const QString& name)
 {
-   d->m_Department = name;
-   d->changed();
+   d_ptr->m_Department = name;
+   d_ptr->changed();
 }
 
 ///If the contact have been deleted or not yet fully created
 void Contact::setActive( bool active)
 {
-   d->m_Active = active;
-   d->statusChanged(d->m_Active);
-   d->changed();
+   d_ptr->m_Active = active;
+   d_ptr->statusChanged(d_ptr->m_Active);
+   d_ptr->changed();
 }
 
 ///Return if one of the PhoneNumber is present
 bool Contact::isPresent() const
 {
-   foreach(const PhoneNumber* n,d->m_Numbers) {
+   foreach(const PhoneNumber* n,d_ptr->m_Numbers) {
       if (n->isPresent())
          return true;
    }
@@ -339,7 +339,7 @@ bool Contact::isPresent() const
 ///Return if one of the PhoneNumber is tracked
 bool Contact::isTracked() const
 {
-   foreach(const PhoneNumber* n,d->m_Numbers) {
+   foreach(const PhoneNumber* n,d_ptr->m_Numbers) {
       if (n->isTracked())
          return true;
    }
@@ -349,13 +349,13 @@ bool Contact::isTracked() const
 ///Have this contact been deleted or doesn't exist yet
 bool Contact::isActive() const
 {
-   return d->m_Active;
+   return d_ptr->m_Active;
 }
 
 ///Return if one of the PhoneNumber support presence
 bool Contact::supportPresence() const
 {
-   foreach(const PhoneNumber* n,d->m_Numbers) {
+   foreach(const PhoneNumber* n,d_ptr->m_Numbers) {
       if (n->supportPresence())
          return true;
    }
@@ -380,45 +380,45 @@ time_t Contact::PhoneNumbers::lastUsedTimeStamp() const
 ///Recomputing the filter string is heavy, cache it
 QString Contact::filterString() const
 {
-   return d->filterString();
+   return d_ptr->filterString();
 }
 
 ///Callback when one of the phone number presence change
 void Contact::slotPresenceChanged()
 {
-   d->changed();
+   d_ptr->changed();
 }
 
 ///Save the contact
 bool Contact::save() const
 {
-   return d->m_pBackend->save(this);
+   return d_ptr->m_pBackend->save(this);
 }
 
 ///Show an implementation dependant dialog to edit the contact
 bool Contact::edit()
 {
-   return d->m_pBackend->edit(this);
+   return d_ptr->m_pBackend->edit(this);
 }
 
 ///Remove the contact from the backend
 bool Contact::remove()
 {
-   return d->m_pBackend->remove(this);
+   return d_ptr->m_pBackend->remove(this);
 }
 
 ///Add a new phone number to the backend
 ///@note The backend is expected to notify the Contact (asynchronously) when done
 bool Contact::addPhoneNumber(PhoneNumber* n)
 {
-   return d->m_pBackend->addPhoneNumber(this,n);
+   return d_ptr->m_pBackend->addPhoneNumber(this,n);
 }
 
 ///Create a placeholder contact, it will eventually be replaced when the real one is loaded
 ContactPlaceHolder::ContactPlaceHolder(const QByteArray& uid)
 {
    setUid(uid);
-   d->m_isPlaceHolder = true;
+   d_ptr->m_isPlaceHolder = true;
 }
 
 
@@ -427,7 +427,7 @@ bool ContactPlaceHolder::merge(Contact* contact)
    if ((!contact) || ((*contact) == this))
       return false;
 
-   ContactPrivate* currentD = d;
+   ContactPrivate* currentD = d_ptr;
    replaceDPointer(contact);
    currentD->m_lParents.removeAll(this);
    if (!currentD->m_lParents.size())
@@ -437,18 +437,18 @@ bool ContactPlaceHolder::merge(Contact* contact)
 
 void Contact::replaceDPointer(Contact* c)
 {
-   this->d = c->d;
-   d->m_lParents << this;
+   this->d_ptr = c->d_ptr;
+   d_ptr->m_lParents << this;
    emit changed();
    emit rebased(c);
 }
 
 bool Contact::operator==(const Contact* other) const
 {
-   return other && this->d == other->d;
+   return other && this->d_ptr == other->d_ptr;
 }
 
 bool Contact::operator==(const Contact& other) const
 {
-   return &other && this->d == other.d;
+   return &other && this->d_ptr == other.d_ptr;
 }
diff --git a/src/contact.h b/src/contact.h
index 7c160551..374cb0a3 100644
--- a/src/contact.h
+++ b/src/contact.h
@@ -85,7 +85,7 @@ public:
 
 protected:
    //The D-Pointer can be shared if a PlaceHolderContact is merged with a real one
-   ContactPrivate* d;
+   ContactPrivate* d_ptr;
    void replaceDPointer(Contact* other);
 
 public:
diff --git a/src/contactproxymodel.cpp b/src/contactproxymodel.cpp
index 55d0bc60..b25dc5b1 100644
--- a/src/contactproxymodel.cpp
+++ b/src/contactproxymodel.cpp
@@ -50,15 +50,15 @@ private Q_SLOTS:
    void slotPhoneNumberCountAboutToChange(int,int);
 };
 
-class TopLevelItem : public CategorizedCompositeNode {
+class ContactTopLevelItem : public CategorizedCompositeNode {
    friend class ContactProxyModel;
    friend class ContactProxyModelPrivate;
    friend class ContactTreeBinder;
    public:
       virtual QObject* getSelf() const override;
-      virtual ~TopLevelItem();
+      virtual ~ContactTopLevelItem();
    private:
-      explicit TopLevelItem(const QString& name) : CategorizedCompositeNode(CategorizedCompositeNode::Type::TOP_LEVEL),m_Name(name),
+      explicit ContactTopLevelItem(const QString& name) : CategorizedCompositeNode(CategorizedCompositeNode::Type::TOP_LEVEL),m_Name(name),
       m_lChildren(),m_Index(-1){
          m_lChildren.reserve(32);
       }
@@ -72,7 +72,7 @@ public:
    ContactTreeNode(Contact* ct, ContactProxyModel* parent);
    virtual ~ContactTreeNode();
    Contact* m_pContact;
-   TopLevelItem* m_pParent3;
+   ContactTopLevelItem* m_pParent3;
    uint m_Index;
    virtual QObject* getSelf() const override;
    ContactTreeBinder* m_pBinder;
@@ -89,14 +89,14 @@ public:
 
    //Attributes
    QHash<Contact*, time_t>      m_hContactByDate   ;
-   QVector<TopLevelItem*>       m_lCategoryCounter ;
-   QHash<QString,TopLevelItem*> m_hCategories      ;
+   QVector<ContactTopLevelItem*>       m_lCategoryCounter ;
+   QHash<QString,ContactTopLevelItem*> m_hCategories      ;
    int                          m_Role             ;
    bool                         m_ShowAll          ;
    QStringList                  m_lMimes           ;
 
    //Helper
-   TopLevelItem* getTopLevelItem(const QString& category);
+   ContactTopLevelItem* getContactTopLevelItem(const QString& category);
 
 private:
    ContactProxyModel* q_ptr;
@@ -106,7 +106,7 @@ public Q_SLOTS:
    void slotContactAdded(Contact* c);
 };
 
-TopLevelItem::~TopLevelItem() {
+ContactTopLevelItem::~ContactTopLevelItem() {
    while(m_lChildren.size()) {
       ContactTreeNode* node = m_lChildren[0];
       m_lChildren.remove(0);
@@ -114,7 +114,7 @@ TopLevelItem::~TopLevelItem() {
    }
 }
 
-QObject* TopLevelItem::getSelf() const
+QObject* ContactTopLevelItem::getSelf() const
 {
    return nullptr;
 }
@@ -210,15 +210,15 @@ ContactProxyModel::ContactProxyModel(int role, bool showAll) : QAbstractItemMode
 
 ContactProxyModel::~ContactProxyModel()
 {
-   foreach(TopLevelItem* item,d_ptr->m_lCategoryCounter) {
+   foreach(ContactTopLevelItem* item,d_ptr->m_lCategoryCounter) {
       delete item;
    }
 }
 
-TopLevelItem* ContactProxyModelPrivate::getTopLevelItem(const QString& category)
+ContactTopLevelItem* ContactProxyModelPrivate::getContactTopLevelItem(const QString& category)
 {
    if (!m_hCategories[category]) {
-      TopLevelItem* item = new TopLevelItem(category);
+      ContactTopLevelItem* item = new ContactTopLevelItem(category);
       m_hCategories[category] = item;
       item->m_Index = m_lCategoryCounter.size();
 //       emit layoutAboutToBeChanged();
@@ -227,7 +227,7 @@ TopLevelItem* ContactProxyModelPrivate::getTopLevelItem(const QString& category)
       } q_ptr->endInsertRows();
 //       emit layoutChanged();
    }
-   TopLevelItem* item = m_hCategories[category];
+   ContactTopLevelItem* item = m_hCategories[category];
    return item;
 }
 
@@ -237,7 +237,7 @@ void ContactProxyModelPrivate::reloadCategories()
    q_ptr->beginResetModel();
    m_hCategories.clear();
    q_ptr->beginRemoveRows(QModelIndex(),0,m_lCategoryCounter.size()-1);
-   foreach(TopLevelItem* item,m_lCategoryCounter) {
+   foreach(ContactTopLevelItem* item,m_lCategoryCounter) {
       delete item;
    }
    q_ptr->endRemoveRows();
@@ -245,7 +245,7 @@ void ContactProxyModelPrivate::reloadCategories()
    foreach(const Contact* cont, ContactModel::instance()->contacts()) {
       if (cont) {
          const QString val = category(cont);
-         TopLevelItem* item = getTopLevelItem(val);
+         ContactTopLevelItem* item = getContactTopLevelItem(val);
          ContactTreeNode* contactNode = new ContactTreeNode(const_cast<Contact*>(cont),q_ptr);
          contactNode->m_pParent3 = item;
          contactNode->m_Index = item->m_lChildren.size();
@@ -260,7 +260,7 @@ void ContactProxyModelPrivate::slotContactAdded(Contact* c)
 {
    if (!c) return;
    const QString val = category(c);
-   TopLevelItem* item = getTopLevelItem(val);
+   ContactTopLevelItem* item = getContactTopLevelItem(val);
    ContactTreeNode* contactNode = new ContactTreeNode(c,q_ptr);
    contactNode->m_pParent3 = item;
    contactNode->m_Index = item->m_lChildren.size();
@@ -294,7 +294,7 @@ QVariant ContactProxyModel::data( const QModelIndex& index, int role) const
       case CategorizedCompositeNode::Type::TOP_LEVEL:
       switch (role) {
          case Qt::DisplayRole:
-            return static_cast<const TopLevelItem*>(modelItem)->m_Name;
+            return static_cast<const ContactTopLevelItem*>(modelItem)->m_Name;
          case ContactModel::Role::IndexedLastUsed:
             return index.child(0,0).data(ContactModel::Role::IndexedLastUsed);
          case ContactModel::Role::Active:
@@ -406,7 +406,7 @@ int ContactProxyModel::rowCount( const QModelIndex& parent ) const
    const CategorizedCompositeNode* parentNode = static_cast<CategorizedCompositeNode*>(parent.internalPointer());
    switch(parentNode->type()) {
       case CategorizedCompositeNode::Type::TOP_LEVEL:
-         return static_cast<const TopLevelItem*>(parentNode)->m_lChildren.size();
+         return static_cast<const ContactTopLevelItem*>(parentNode)->m_lChildren.size();
       case CategorizedCompositeNode::Type::CONTACT: {
          const Contact* ct = static_cast<Contact*>(parentNode->getSelf());
          const int size = ct->phoneNumbers().size();
@@ -441,7 +441,7 @@ QModelIndex ContactProxyModel::parent( const QModelIndex& index) const
    const CategorizedCompositeNode* modelItem = static_cast<CategorizedCompositeNode*>(index.internalPointer());
    switch (modelItem->type()) {
       case CategorizedCompositeNode::Type::CONTACT: {
-         const TopLevelItem* tl = ((ContactTreeNode*)(modelItem))->m_pParent3;
+         const ContactTopLevelItem* tl = ((ContactTreeNode*)(modelItem))->m_pParent3;
          return createIndex(tl->m_Index,0,(void*)tl);
       }
       break;
@@ -464,7 +464,7 @@ QModelIndex ContactProxyModel::index( int row, int column, const QModelIndex& pa
       CategorizedCompositeNode* parentNode = static_cast<CategorizedCompositeNode*>(parent.internalPointer());
       switch(parentNode->type()) {
          case CategorizedCompositeNode::Type::TOP_LEVEL: {
-            TopLevelItem* tld = static_cast<TopLevelItem*>(parentNode);
+            ContactTopLevelItem* tld = static_cast<ContactTopLevelItem*>(parentNode);
             if (tld && row < tld->m_lChildren.size())
                return createIndex(row,column,(void*)tld->m_lChildren[row]);
          }
diff --git a/src/historymodel.h b/src/historymodel.h
index a3aef0f5..b69324cf 100644
--- a/src/historymodel.h
+++ b/src/historymodel.h
@@ -46,7 +46,6 @@ class LIB_EXPORT HistoryModel : public QAbstractItemModel, public CommonBackendM
 public:
    friend class HistoryItemNode;
    friend class HistoryTopLevelItem;
-   friend class TopLevelItem;
 
    //Properties
    Q_PROPERTY(bool hasBackends   READ hasBackends  )
diff --git a/src/legacyhistorybackend.cpp b/src/legacyhistorybackend.cpp
deleted file mode 100644
index c0e98272..00000000
--- a/src/legacyhistorybackend.cpp
+++ /dev/null
@@ -1,121 +0,0 @@
-/************************************************************************************
- *   Copyright (C) 2014-2015 by Savoir-Faire Linux                                       *
- *   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 Lesser General Public               *
- *   License along with this library; if not, write to the Free Software            *
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA *
- ***********************************************************************************/
-#include "legacyhistorybackend.h"
-
-//Ring
-#include "dbus/configurationmanager.h"
-#include "call.h"
-#include "private/call_p.h"
-
-LegacyHistoryBackend::LegacyHistoryBackend(QObject* parent) : AbstractHistoryBackend(nullptr,parent)
-{
-   setObjectName("LegacyHistoryBackend");
-}
-
-LegacyHistoryBackend::~LegacyHistoryBackend()
-{
-   
-}
-
-
-QString LegacyHistoryBackend::name () const
-{
-   return "Legacy history backend";
-}
-
-QVariant LegacyHistoryBackend::icon() const
-{
-   return QVariant();
-}
-
-bool LegacyHistoryBackend::isEnabled() const
-{
-   return false; //This one is never considered enabled
-}
-
-bool LegacyHistoryBackend::load()
-{
-   ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
-   const QVector< QMap<QString, QString> > history = configurationManager.getHistory();
-   for(int i = history.size()-1;i>=0;i--) {
-      const MapStringString& hc = history[i];
-      Call* pastCall = Call::buildHistoryCall(hc);
-      if (pastCall->peerName().isEmpty()) {
-         pastCall->setPeerName(tr("Unknown"));
-      }
-      pastCall->setRecordingPath(hc[ Call::HistoryMapFields::RECORDING_PATH ]);
-      emit newHistoryCallAdded(pastCall);
-   }
-   return true;
-}
-
-bool LegacyHistoryBackend::reload()
-{
-   return false;
-}
-
-bool LegacyHistoryBackend::append(const Call* item)
-{
-   Q_UNUSED(item)
-   return false;
-}
-
-bool LegacyHistoryBackend::save(const Call* call)
-{
-   Q_UNUSED(call)
-   return false;
-}
-
-AbstractHistoryBackend::SupportedFeatures LegacyHistoryBackend::supportedFeatures() const
-{
-   return (AbstractHistoryBackend::SupportedFeatures) (
-      AbstractHistoryBackend::SupportedFeatures::LOAD );
-}
-
-///Edit 'item', the implementation may be a GUI or somehting else
-bool LegacyHistoryBackend::edit( Call* call)
-{
-   Q_UNUSED(call)
-   return false;
-}
-///Add a new item to the backend
-bool LegacyHistoryBackend::addNew( Call* call)
-{
-   Q_UNUSED(call)
-   return true;
-}
-
-///Add a new phone number to an existing item
-bool LegacyHistoryBackend::addPhoneNumber( Call* call , PhoneNumber* number )
-{
-   Q_UNUSED(call)
-   Q_UNUSED(number)
-   return false;
-}
-
-QByteArray LegacyHistoryBackend::id() const
-{
-   return "lhb";
-}
-
-QList<Call*> LegacyHistoryBackend::items() const
-{
-   return QList<Call*>();
-}
-
diff --git a/src/legacyhistorybackend.h b/src/legacyhistorybackend.h
deleted file mode 100644
index 57f71a32..00000000
--- a/src/legacyhistorybackend.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/************************************************************************************
- *   Copyright (C) 2014-2015 by Savoir-Faire Linux                                       *
- *   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 Lesser General Public               *
- *   License along with this library; if not, write to the Free Software            *
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA *
- ***********************************************************************************/
-#ifndef LEGACYHISTORYBACKEND_H
-#define LEGACYHISTORYBACKEND_H
-
-#include "abstractitembackend.h"
-
-/// @deprecated Remove once the daemon drop configurationmanager::getHistory()
-class LIB_EXPORT LegacyHistoryBackend : public AbstractHistoryBackend
-{
-public:
-   explicit LegacyHistoryBackend(QObject* parent = nullptr);
-   virtual ~LegacyHistoryBackend();
-
-   virtual bool load() override;
-   virtual bool reload() override;
-   virtual bool save(const Call* call) override;
-   virtual bool append(const Call* item) override;
-
-   virtual QString name () const override;
-   virtual QVariant icon() const override;
-   virtual bool isEnabled() const override;
-   virtual QByteArray id() const override;
-
-   virtual SupportedFeatures supportedFeatures() const override;
-
-   virtual QList<Call*> items() const override;
-
-   ///Edit 'item', the implementation may be a GUI or somehting else
-   virtual bool edit( Call* call) override;
-   ///Add a new item to the backend
-   virtual bool addNew( Call* call) override;
-
-   ///Add a new phone number to an existing item
-   virtual bool addPhoneNumber( Call* call , PhoneNumber* number ) override;
-};
-
-#endif
-- 
GitLab