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

akonadi

  • sources
  • kde-4.14
  • kdepimlibs
  • akonadi
etmviewstatesaver.cpp
1 /*
2  Copyright (C) 2010 Klarälvdalens Datakonsult AB,
3  a KDAB Group company, info@kdab.net,
4  author Stephen Kelly <stephen@kdab.com>
5 
6  This library is free software; you can redistribute it and/or modify it
7  under the terms of the GNU Library General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or (at your
9  option) any later version.
10 
11  This library is distributed in the hope that it will be useful, but WITHOUT
12  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14  License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to the
18  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  02110-1301, USA.
20 */
21 
22 #include "etmviewstatesaver.h"
23 
24 #include <QtCore/QModelIndex>
25 
26 #include "entitytreemodel.h"
27 
28 using namespace Akonadi;
29 
30 ETMViewStateSaver::ETMViewStateSaver(QObject *parent)
31  : KViewStateSaver(parent)
32 {
33 }
34 
35 QModelIndex ETMViewStateSaver::indexFromConfigString(const QAbstractItemModel *model, const QString &key) const
36 {
37  if (key.startsWith(QLatin1Char('x'))) {
38  return QModelIndex();
39  }
40 
41  Entity::Id id = key.mid(1).toLongLong();
42  if (id < 0) {
43  return QModelIndex();
44  }
45 
46  if (key.startsWith(QLatin1Char('c'))) {
47  QModelIndex idx = EntityTreeModel::modelIndexForCollection(model, Collection(id));
48  if (!idx.isValid()) {
49  return QModelIndex();
50  }
51  return idx;
52  } else if (key.startsWith(QLatin1Char('i'))) {
53  QModelIndexList list = EntityTreeModel::modelIndexesForItem(model, Item(id));
54  if (list.isEmpty()) {
55  return QModelIndex();
56  }
57  return list.first();
58  }
59  return QModelIndex();
60 }
61 
62 QString ETMViewStateSaver::indexToConfigString(const QModelIndex &index) const
63 {
64  if (!index.isValid()) {
65  return QLatin1String("x-1");
66  }
67  const Collection c = index.data(EntityTreeModel::CollectionRole).value<Collection>();
68  if (c.isValid()) {
69  return QString::fromLatin1("c%1").arg(c.id());
70  }
71  Entity::Id id = index.data(EntityTreeModel::ItemIdRole).value<Entity::Id>();
72  if (id >= 0) {
73  return QString::fromLatin1("i%1").arg(id);
74  }
75  return QString();
76 }
77 
78 void ETMViewStateSaver::selectCollections(const Akonadi::Collection::List &list)
79 {
80  QStringList colStrings;
81  foreach (const Collection &col, list) {
82  colStrings << QString::fromLatin1("c%1").arg(col.id());
83  }
84  restoreSelection(colStrings);
85 }
86 
87 void ETMViewStateSaver::selectCollections(const QList< Collection::Id > &list)
88 {
89  QStringList colStrings;
90  foreach (const Collection::Id &colId, list) {
91  colStrings << QString::fromLatin1("c%1").arg(colId);
92  }
93  restoreSelection(colStrings);
94 }
95 
96 void ETMViewStateSaver::selectItems(const Akonadi::Item::List &list)
97 {
98  QStringList itemStrings;
99  foreach (const Item &item, list) {
100  itemStrings << QString::fromLatin1("i%1").arg(item.id());
101  }
102  restoreSelection(itemStrings);
103 }
104 
105 void ETMViewStateSaver::selectItems(const QList< Item::Id > &list)
106 {
107  QStringList itemStrings;
108  foreach (const Item::Id &itemId, list) {
109  itemStrings << QString::fromLatin1("i%1").arg(itemId);
110  }
111  restoreSelection(itemStrings);
112 }
QModelIndex
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:75
Akonadi::Entity::Id
qint64 Id
Describes the unique id type.
Definition: entity.h:65
QVariant::value
T value() const
QModelIndex::isValid
bool isValid() const
QObject
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
Akonadi::EntityTreeModel::CollectionRole
The collection.
Definition: entitytreemodel.h:336
QString
QList
Akonadi::Entity::id
Id id() const
Returns the unique identifier of the entity.
Definition: entity.cpp:72
QStringList
Akonadi::EntityTreeModel::modelIndexForCollection
static QModelIndex modelIndexForCollection(const QAbstractItemModel *model, const Collection &collection)
Returns a QModelIndex in model which points to collection.
Definition: entitytreemodel.cpp:1238
QLatin1Char
QString::mid
QString mid(int position, int n) const
QModelIndex::data
QVariant data(int role) const
QLatin1String
QAbstractItemModel
QString::fromLatin1
QString fromLatin1(const char *str, int size)
Akonadi::EntityTreeModel::modelIndexesForItem
static QModelIndexList modelIndexesForItem(const QAbstractItemModel *model, const Item &item)
Returns a QModelIndex in model which points to item.
Definition: entitytreemodel.cpp:1247
Akonadi::Entity::isValid
bool isValid() const
Returns whether the entity is valid.
Definition: entity.cpp:97
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QString::toLongLong
qlonglong toLongLong(bool *ok, int base) const
Akonadi::EntityTreeModel::ItemIdRole
The item id.
Definition: entitytreemodel.h:331
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:38:03 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2

Search



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