2 Copyright (c) 2013-2015 Montel Laurent <montel@kde.org>
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License, version 2, as
6 published by the Free Software Foundation.
8 This program is distributed in the hope that it will be useful, but
9 WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 General Public License for more details.
13 You should have received a copy of the GNU General Public License along
14 with this program; if not, write to the Free Software Foundation, Inc.,
15 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <QItemSelectionModel>
22 #include <KContacts/Addressee>
23 #include <AkonadiCore/EntityTreeModel>
24 #include <KContacts/ContactGroup>
26 Akonadi::Item::List
Utils::collectSelectedContactsItem(QItemSelectionModel
*model
)
28 Akonadi::Item::List lst
;
30 const QModelIndexList indexes
= model
->selectedRows(0);
31 for (int i
= 0; i
< indexes
.count(); ++i
) {
32 const QModelIndex index
= indexes
.at(i
);
33 if (index
.isValid()) {
34 const Akonadi::Item item
=
35 index
.data(Akonadi::EntityTreeModel::ItemRole
).value
<Akonadi::Item
>();
36 if (item
.isValid() && item
.hasPayload
<KContacts::Addressee
>()) {
44 Akonadi::Item::List
Utils::collectSelectedAllContactsItem(QItemSelectionModel
*model
)
46 Akonadi::Item::List lst
;
48 const QModelIndexList indexes
= model
->selectedRows(0);
49 for (int i
= 0; i
< indexes
.count(); ++i
) {
50 const QModelIndex index
= indexes
.at(i
);
51 if (index
.isValid()) {
52 const Akonadi::Item item
=
53 index
.data(Akonadi::EntityTreeModel::ItemRole
).value
<Akonadi::Item
>();
55 if (item
.hasPayload
<KContacts::Addressee
>() || item
.hasPayload
<KContacts::ContactGroup
>()) {