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

akonadi

  • 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  Entity::Id id = key.mid( 1 ).toLongLong();
41  if ( id < 0 )
42  return QModelIndex();
43 
44  if ( key.startsWith( QLatin1Char( 'c' ) ) ) {
45  QModelIndex idx = EntityTreeModel::modelIndexForCollection( model, Collection( id ) );
46  if ( !idx.isValid() ) {
47  return QModelIndex();
48  }
49  return idx;
50  } else if ( key.startsWith( QLatin1Char( 'i' ) ) ) {
51  QModelIndexList list = EntityTreeModel::modelIndexesForItem( model, Item( id ) );
52  if ( list.isEmpty() ) {
53  return QModelIndex();
54  }
55  return list.first();
56  }
57  return QModelIndex();
58 }
59 
60 QString ETMViewStateSaver::indexToConfigString(const QModelIndex& index) const
61 {
62  if ( !index.isValid() ) {
63  return QLatin1String( "x-1" );
64  }
65  const Collection c = index.data( EntityTreeModel::CollectionRole ).value<Collection>();
66  if ( c.isValid() ) {
67  return QString::fromLatin1( "c%1" ).arg( c.id() );
68  }
69  Entity::Id id = index.data( EntityTreeModel::ItemIdRole ).value<Entity::Id>();
70  if ( id >= 0 ) {
71  return QString::fromLatin1( "i%1" ).arg( id );
72  }
73  return QString();
74 }
75 
76 void ETMViewStateSaver::selectCollections(const Akonadi::Collection::List& list)
77 {
78  QStringList colStrings;
79  foreach ( const Collection &col, list ) {
80  colStrings << QString::fromLatin1( "c%1" ).arg( col.id() );
81  }
82  restoreSelection( colStrings );
83 }
84 
85 void ETMViewStateSaver::selectCollections(const QList< Collection::Id >& list)
86 {
87  QStringList colStrings;
88  foreach ( const Collection::Id &colId, list ) {
89  colStrings << QString::fromLatin1( "c%1" ).arg( colId );
90  }
91  restoreSelection( colStrings );
92 }
93 
94 void ETMViewStateSaver::selectItems(const Akonadi::Item::List& list)
95 {
96  QStringList itemStrings;
97  foreach ( const Item &item, list ) {
98  itemStrings << QString::fromLatin1( "i%1" ).arg( item.id() );
99  }
100  restoreSelection( itemStrings );
101 }
102 
103 void ETMViewStateSaver::selectItems(const QList< Item::Id >& list)
104 {
105  QStringList itemStrings;
106  foreach (const Item::Id &itemId, list) {
107  itemStrings << QString::fromLatin1( "i%1" ).arg( itemId );
108  }
109  restoreSelection( itemStrings );
110 }
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
Akonadi::EntityTreeModel::CollectionRole
The collection.
Definition: entitytreemodel.h:335
Akonadi::Entity::id
Id id() const
Returns the unique identifier of the entity.
Definition: entity.cpp:72
Akonadi::EntityTreeModel::modelIndexForCollection
static QModelIndex modelIndexForCollection(const QAbstractItemModel *model, const Collection &collection)
Returns a QModelIndex in model which points to collection.
Definition: entitytreemodel.cpp:1191
Akonadi::EntityTreeModel::modelIndexesForItem
static QModelIndexList modelIndexesForItem(const QAbstractItemModel *model, const Item &item)
Returns a QModelIndex in model which points to item.
Definition: entitytreemodel.cpp:1200
Akonadi::Entity::isValid
bool isValid() const
Returns whether the entity is valid.
Definition: entity.cpp:97
Akonadi::Collection::List
QList< Collection > List
Describes a list of collections.
Definition: collection.h:81
Akonadi::EntityTreeModel::ItemIdRole
The item id.
Definition: entitytreemodel.h:330
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Mon Jul 21 2014 08:03:52 by doxygen 1.8.6 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-4.13.3 API Reference

Skip menu "kdepimlibs-4.13.3 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
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