~ubuntu-branches/ubuntu/wily/sflphone/wily

« back to all changes in this revision

Viewing changes to kde/src/lib/contactproxymodel.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2015-01-07 14:51:16 UTC
  • mfrom: (4.3.5 sid)
  • Revision ID: package-import@ubuntu.com-20150107145116-yxnafinf4lrdvrmx
Tags: 1.4.1-0.1ubuntu1
* Merge with Debian, remaining changes:
 - Drop soprano, nepomuk build-dep
* Drop ubuntu patches, now upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <QtCore/QCoreApplication>
25
25
 
26
26
//SFLPhone
27
 
#include "abstractcontactbackend.h"
28
27
#include "callmodel.h"
29
28
#include "historymodel.h"
30
29
#include "phonenumber.h"
31
30
#include "phonedirectorymodel.h"
32
31
#include "historytimecategorymodel.h"
33
32
#include "contact.h"
 
33
#include "uri.h"
 
34
#include "contactmodel.h"
34
35
 
35
36
class ContactTreeNode;
36
37
 
42
43
      virtual ~TopLevelItem();
43
44
   private:
44
45
      explicit TopLevelItem(const QString& name) : CategorizedCompositeNode(CategorizedCompositeNode::Type::TOP_LEVEL),m_Name(name),
45
 
      m_lChildren(){
 
46
      m_lChildren(),m_Index(-1){
46
47
         m_lChildren.reserve(32);
47
48
      }
48
49
      QVector<ContactTreeNode*> m_lChildren;
70
71
}
71
72
 
72
73
ContactTreeNode::ContactTreeNode(Contact* ct, ContactProxyModel* parent) : CategorizedCompositeNode(CategorizedCompositeNode::Type::CONTACT),
73
 
   m_pContact(ct),m_pParent3(nullptr)
 
74
   m_pContact(ct),m_pParent3(nullptr),m_Index(-1)
74
75
{
75
76
   m_pBinder = new ContactTreeBinder(parent,this);
76
77
}
135
136
}
136
137
 
137
138
//
138
 
ContactProxyModel::ContactProxyModel(AbstractContactBackend* parent,int role, bool showAll) : QAbstractItemModel(QCoreApplication::instance()),
139
 
m_pModel(parent),m_Role(role),m_ShowAll(showAll),m_lCategoryCounter()
 
139
ContactProxyModel::ContactProxyModel(int role, bool showAll) : QAbstractItemModel(QCoreApplication::instance()),
 
140
m_Role(role),m_ShowAll(showAll),m_lCategoryCounter()
140
141
{
141
142
   setObjectName("ContactProxyModel");
142
143
   m_lCategoryCounter.reserve(32);
143
144
   m_lMimes << MIME_PLAIN_TEXT << MIME_PHONENUMBER;
144
 
   connect(m_pModel,SIGNAL(collectionChanged()),this,SLOT(reloadCategories()));
145
 
   connect(m_pModel,SIGNAL(newContactAdded(Contact*)),this,SLOT(slotContactAdded(Contact*)));
 
145
   connect(ContactModel::instance(),SIGNAL(reloaded()),this,SLOT(reloadCategories()));
 
146
   connect(ContactModel::instance(),SIGNAL(newContactAdded(Contact*)),this,SLOT(slotContactAdded(Contact*)));
146
147
   QHash<int, QByteArray> roles = roleNames();
147
 
   roles.insert(AbstractContactBackend::Role::Organization      ,QByteArray("organization")     );
148
 
   roles.insert(AbstractContactBackend::Role::Group             ,QByteArray("group")            );
149
 
   roles.insert(AbstractContactBackend::Role::Department        ,QByteArray("department")       );
150
 
   roles.insert(AbstractContactBackend::Role::PreferredEmail    ,QByteArray("preferredEmail")   );
151
 
   roles.insert(AbstractContactBackend::Role::FormattedLastUsed ,QByteArray("formattedLastUsed"));
152
 
   roles.insert(AbstractContactBackend::Role::IndexedLastUsed   ,QByteArray("indexedLastUsed")  );
153
 
   roles.insert(AbstractContactBackend::Role::DatedLastUsed     ,QByteArray("datedLastUsed")    );
154
 
   roles.insert(AbstractContactBackend::Role::Filter            ,QByteArray("filter")           );
155
 
   roles.insert(AbstractContactBackend::Role::DropState         ,QByteArray("dropState")        );
 
148
   roles.insert(ContactModel::Role::Organization      ,QByteArray("organization")     );
 
149
   roles.insert(ContactModel::Role::Group             ,QByteArray("group")            );
 
150
   roles.insert(ContactModel::Role::Department        ,QByteArray("department")       );
 
151
   roles.insert(ContactModel::Role::PreferredEmail    ,QByteArray("preferredEmail")   );
 
152
   roles.insert(ContactModel::Role::FormattedLastUsed ,QByteArray("formattedLastUsed"));
 
153
   roles.insert(ContactModel::Role::IndexedLastUsed   ,QByteArray("indexedLastUsed")  );
 
154
   roles.insert(ContactModel::Role::DatedLastUsed     ,QByteArray("datedLastUsed")    );
 
155
   roles.insert(ContactModel::Role::Filter            ,QByteArray("filter")           );
 
156
   roles.insert(ContactModel::Role::DropState         ,QByteArray("dropState")        );
156
157
   setRoleNames(roles);
157
158
}
158
159
 
190
191
   }
191
192
   endRemoveRows();
192
193
   m_lCategoryCounter.clear();
193
 
   foreach(Contact* cont, m_pModel->getContactList()) {
 
194
   foreach(const Contact* cont, ContactModel::instance()->contacts()) {
194
195
      if (cont) {
195
196
         const QString val = category(cont);
196
197
         TopLevelItem* item = getTopLevelItem(val);
197
 
         ContactTreeNode* contactNode = new ContactTreeNode(cont,this);
 
198
         ContactTreeNode* contactNode = new ContactTreeNode(const_cast<Contact*>(cont),this);
198
199
         contactNode->m_pParent3 = item;
199
200
         contactNode->m_Index = item->m_lChildren.size();
200
201
         item->m_lChildren << contactNode;
223
224
{
224
225
   if (index.isValid() && index.parent().isValid()) {
225
226
      CategorizedCompositeNode* modelItem = (CategorizedCompositeNode*)index.internalPointer();
226
 
      if (role == AbstractContactBackend::Role::DropState) {
 
227
      if (role == ContactModel::Role::DropState) {
227
228
         modelItem->setDropState(value.toInt());
228
229
         emit dataChanged(index, index);
229
230
         return true;
243
244
      switch (role) {
244
245
         case Qt::DisplayRole:
245
246
            return static_cast<const TopLevelItem*>(modelItem)->m_Name;
246
 
         case AbstractContactBackend::Role::IndexedLastUsed:
247
 
            return index.child(0,0).data(AbstractContactBackend::Role::IndexedLastUsed);
248
 
         case AbstractContactBackend::Role::Active:
 
247
         case ContactModel::Role::IndexedLastUsed:
 
248
            return index.child(0,0).data(ContactModel::Role::IndexedLastUsed);
 
249
         case ContactModel::Role::Active:
249
250
            return true;
250
251
         default:
251
252
            break;
256
257
      switch (role) {
257
258
         case Qt::DisplayRole:
258
259
            return QVariant(c->formattedName());
259
 
         case AbstractContactBackend::Role::Organization:
 
260
         case ContactModel::Role::Organization:
260
261
            return QVariant(c->organization());
261
 
         case AbstractContactBackend::Role::Group:
 
262
         case ContactModel::Role::Group:
262
263
            return QVariant(c->group());
263
 
         case AbstractContactBackend::Role::Department:
 
264
         case ContactModel::Role::Department:
264
265
            return QVariant(c->department());
265
 
         case AbstractContactBackend::Role::PreferredEmail:
 
266
         case ContactModel::Role::PreferredEmail:
266
267
            return QVariant(c->preferredEmail());
267
 
         case AbstractContactBackend::Role::DropState:
 
268
         case ContactModel::Role::DropState:
268
269
            return QVariant(modelItem->dropState());
269
 
         case AbstractContactBackend::Role::FormattedLastUsed:
 
270
         case ContactModel::Role::FormattedLastUsed:
270
271
            return QVariant(HistoryTimeCategoryModel::timeToHistoryCategory(c->phoneNumbers().lastUsedTimeStamp()));
271
 
         case AbstractContactBackend::Role::IndexedLastUsed:
 
272
         case ContactModel::Role::IndexedLastUsed:
272
273
            return QVariant((int)HistoryTimeCategoryModel::timeToHistoryConst(c->phoneNumbers().lastUsedTimeStamp()));
273
 
         case AbstractContactBackend::Role::Active:
 
274
         case ContactModel::Role::Active:
274
275
            return c->isActive();
275
 
         case AbstractContactBackend::Role::DatedLastUsed:
 
276
         case ContactModel::Role::DatedLastUsed:
276
277
            return QVariant(QDateTime::fromTime_t( c->phoneNumbers().lastUsedTimeStamp()));
277
 
         case AbstractContactBackend::Role::Filter: {
278
 
            //Strip non essential characters like accents from the filter string
279
 
            QString normStripppedC;
280
 
            foreach(QChar char2,QString(c->formattedName()+'\n'+c->organization()+'\n'+c->group()+'\n'+
281
 
               c->department()+'\n'+c->preferredEmail()).toLower().normalized(QString::NormalizationForm_KD) ) {
282
 
               if (!char2.combiningClass())
283
 
                  normStripppedC += char2;
284
 
            }
285
 
            return normStripppedC;
286
 
         }
 
278
         case ContactModel::Role::Filter:
 
279
            return c->filterString();
287
280
         default:
288
281
            break;
289
282
      }
294
287
   case CategorizedCompositeNode::Type::BOOKMARK:
295
288
   default:
296
289
      switch (role) {
297
 
         case AbstractContactBackend::Role::Active:
 
290
         case ContactModel::Role::Active:
298
291
            return true;
299
292
      }
300
293
      break;
466
459
                  if (ct->phoneNumbers().size() == 1) {
467
460
                     mimeData->setData(MIME_PHONENUMBER , ct->phoneNumbers()[0]->toHash().toUtf8());
468
461
                  }
469
 
                  mimeData->setData(MIME_CONTACT , ct->uid().toUtf8());
 
462
                  mimeData->setData(MIME_CONTACT , ct->uid());
470
463
               }
471
464
               return mimeData;
472
465
               } break;
505
498
 ****************************************************************************/
506
499
 
507
500
 
508
 
QString ContactProxyModel::category(Contact* ct) const {
 
501
QString ContactProxyModel::category(const Contact* ct) const {
509
502
   if (!ct)
510
503
      return QString();
511
504
   QString cat;
512
505
   switch (m_Role) {
513
 
      case AbstractContactBackend::Role::Organization:
 
506
      case ContactModel::Role::Organization:
514
507
         cat = ct->organization();
515
508
         break;
516
 
      case AbstractContactBackend::Role::Group:
 
509
      case ContactModel::Role::Group:
517
510
         cat = ct->group();
518
511
         break;
519
 
      case AbstractContactBackend::Role::Department:
 
512
      case ContactModel::Role::Department:
520
513
         cat = ct->department();
521
514
         break;
522
 
      case AbstractContactBackend::Role::PreferredEmail:
 
515
      case ContactModel::Role::PreferredEmail:
523
516
         cat = ct->preferredEmail();
524
517
         break;
525
 
      case AbstractContactBackend::Role::FormattedLastUsed:
 
518
      case ContactModel::Role::FormattedLastUsed:
526
519
         cat = HistoryTimeCategoryModel::timeToHistoryCategory(ct->phoneNumbers().lastUsedTimeStamp());
527
520
         break;
528
 
      case AbstractContactBackend::Role::IndexedLastUsed:
 
521
      case ContactModel::Role::IndexedLastUsed:
529
522
         cat = QString::number((int)HistoryTimeCategoryModel::timeToHistoryConst(ct->phoneNumbers().lastUsedTimeStamp()));
530
523
         break;
531
 
      case AbstractContactBackend::Role::DatedLastUsed:
 
524
      case ContactModel::Role::DatedLastUsed:
532
525
         cat = QDateTime::fromTime_t(ct->phoneNumbers().lastUsedTimeStamp()).toString();
533
526
         break;
534
527
      default: