• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.9.5 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 #include <QtGui/QItemSelection>
26 #include <QtGui/QTreeView>
27 
28 #include "entitytreemodel.h"
29 
30 using namespace Akonadi;
31 
32 ETMViewStateSaver::ETMViewStateSaver(QObject* parent)
33  : KViewStateSaver(parent)
34 {
35 }
36 
37 QModelIndex ETMViewStateSaver::indexFromConfigString(const QAbstractItemModel *model, const QString& key) const
38 {
39  if ( key.startsWith( QLatin1Char( 'x' ) ) )
40  return QModelIndex();
41 
42  Entity::Id id = key.mid( 1 ).toLongLong();
43  if ( id < 0 )
44  return QModelIndex();
45 
46  if ( key.startsWith( QLatin1Char( 'c' ) ) )
47  {
48  QModelIndex idx = EntityTreeModel::modelIndexForCollection( model, Collection( id ) );
49  if ( !idx.isValid() )
50  {
51  return QModelIndex();
52  }
53  return idx;
54  }
55  else if ( key.startsWith( QLatin1Char( 'i' ) ) )
56  {
57  QModelIndexList list = EntityTreeModel::modelIndexesForItem( model, Item( id ) );
58  if ( list.isEmpty() )
59  {
60  return QModelIndex();
61  }
62  return list.first();
63  }
64  return QModelIndex();
65 }
66 
67 QString ETMViewStateSaver::indexToConfigString(const QModelIndex& index) const
68 {
69  if ( !index.isValid() )
70  return QLatin1String( "x-1" );
71  const Collection c = index.data( EntityTreeModel::CollectionRole ).value<Collection>();
72  if ( c.isValid() )
73  return QString::fromLatin1( "c%1" ).arg( c.id() );
74  Entity::Id id = index.data( EntityTreeModel::ItemIdRole ).value<Entity::Id>();
75  if ( id >= 0 )
76  return QString::fromLatin1( "i%1" ).arg( id );
77  return QString();
78 }
79 
80 void ETMViewStateSaver::selectCollections(const Akonadi::Collection::List& list)
81 {
82  QStringList colStrings;
83  foreach(const Collection &col, list)
84  colStrings << QString::fromLatin1( "c%1" ).arg( col.id() );
85  restoreSelection(colStrings);
86 }
87 
88 void ETMViewStateSaver::selectCollections(const QList< Collection::Id >& list)
89 {
90  QStringList colStrings;
91  foreach(const Collection::Id &colId, list)
92  colStrings << QString::fromLatin1( "c%1" ).arg( colId );
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  restoreSelection(itemStrings);
102 }
103 
104 void ETMViewStateSaver::selectItems(const QList< Item::Id >& list)
105 {
106  QStringList itemStrings;
107  foreach(const Item::Id &itemId, list)
108  itemStrings << QString::fromLatin1( "i%1" ).arg( itemId );
109  restoreSelection(itemStrings);
110 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jan 5 2013 19:46:04 by doxygen 1.8.1.2 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.9.5 API Reference

Skip menu "kdepimlibs-4.9.5 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • 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