• Skip to content
  • Skip to link menu
  • KDE API Reference
  • KDE Home
  • Contact Us
 

Nepomuk-Core

  • KTp
  • Models
accounts-tree-proxy-model.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 David Edmundson <kde@davidedmundson.co.uk>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library 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 GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include "accounts-tree-proxy-model.h"
20 
21 #include "types.h"
22 
23 #include <TelepathyQt/Account>
24 #include <TelepathyQt/AccountManager>
25 #include <TelepathyQt/AccountSet>
26 
27 #include <KIcon>
28 
29 
30 class KTp::AccountsTreeProxyModel::Private
31 {
32 public:
33  Tp::AccountManagerPtr accountManager;
34  Tp::AccountSetPtr accountSet;
35 };
36 
37 KTp::AccountsTreeProxyModel::AccountsTreeProxyModel(QAbstractItemModel *sourceModel, const Tp::AccountManagerPtr &accountManager) :
38  AbstractGroupingProxyModel(sourceModel),
39  d(new Private())
40 {
41  d->accountManager = accountManager;
42 
43  d->accountSet = accountManager->enabledAccounts();
44  connect(d->accountSet.data(), SIGNAL(accountAdded(Tp::AccountPtr)), SLOT(onAccountAdded(Tp::AccountPtr)));
45  connect(d->accountSet.data(), SIGNAL(accountRemoved(Tp::AccountPtr)), SLOT(onAccountRemoved(Tp::AccountPtr)));
46  Q_FOREACH(const Tp::AccountPtr &account, d->accountSet->accounts()) {
47  onAccountAdded(account);
48  }
49 
50 }
51 
52 QSet<QString> KTp::AccountsTreeProxyModel::groupsForIndex(const QModelIndex &sourceIndex) const
53 {
54  const Tp::AccountPtr account = sourceIndex.data(KTp::AccountRole).value<Tp::AccountPtr>();
55  if (account) {
56  return QSet<QString>() << account->objectPath();
57  } else {
58  return QSet<QString>() << QLatin1String("Unknown");
59  }
60 }
61 
62 
63 QVariant KTp::AccountsTreeProxyModel::dataForGroup(const QString &group, int role) const
64 {
65  Tp::AccountPtr account;
66  switch(role) {
67  case Qt::DisplayRole:
68  account = d->accountManager->accountForObjectPath(group);
69  if (account) {
70  return account->displayName();
71  }
72  break;
73  case Qt::DecorationRole:
74  account = d->accountManager->accountForObjectPath(group);
75  if (account) {
76  return KIcon(account->iconName());
77  }
78  break;
79  case KTp::AccountRole:
80  return QVariant::fromValue(d->accountManager->accountForObjectPath(group));
81  case KTp::RowTypeRole:
82  return KTp::AccountRowType;
83  case KTp::IdRole:
84  account = d->accountManager->accountForObjectPath(group);
85  if (account) {
86  return account->uniqueIdentifier();
87  }
88  break;
89  }
90 
91  return QVariant();
92 }
93 
94 void KTp::AccountsTreeProxyModel::onAccountChanged()
95 {
96  Tp::AccountPtr account(qobject_cast<Tp::Account*>(sender()));
97  groupChanged(account->objectPath());
98 }
99 
100 void KTp::AccountsTreeProxyModel::onAccountAdded(const Tp::AccountPtr &account)
101 {
102  forceGroup(account->objectPath());
103  connect(account.data(), SIGNAL(normalizedNameChanged(QString)), SLOT(onAccountChanged()));
104  connect(account.data(), SIGNAL(iconNameChanged(QString)), SLOT(onAccountChanged()));
105 }
106 
107 void KTp::AccountsTreeProxyModel::onAccountRemoved(const Tp::AccountPtr &account)
108 {
109  unforceGroup(account->objectPath());
110 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Fri Mar 22 2013 10:58:52 by doxygen 1.8.1.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

ktp-common-internals API Reference

Skip menu "ktp-common-internals API Reference"
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal