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

mailcommon

  • sources
  • kde-4.12
  • kdepim
  • mailcommon
  • folder
entitycollectionorderproxymodel.cpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-file-style: "gnu" -*-
2 
3  Copyright (c) 2010 Montel Laurent <montel@kde.org>
4 
5  This program is free software; you can redistribute it and/or modify it
6  under the terms of the GNU General Public License, version 2, as
7  published by the Free Software Foundation.
8 
9  This program is distributed in the hope that it will be useful, but
10  WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License along
15  with this program; if not, write to the Free Software Foundation, Inc.,
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #include "entitycollectionorderproxymodel.h"
20 #include "kernel/mailkernel.h"
21 #include "util/mailutil.h"
22 
23 #include <Akonadi/Collection>
24 #include <Akonadi/EntityTreeModel>
25 #include <Akonadi/KMime/SpecialMailCollections>
26 #include <Akonadi/AgentManager>
27 
28 namespace MailCommon {
29 
30 class EntityCollectionOrderProxyModel::EntityCollectionOrderProxyModelPrivate
31 {
32  public:
33  EntityCollectionOrderProxyModelPrivate()
34  : manualSortingActive( false )
35  {
36  }
37 
38  int collectionRank( const Akonadi::Collection &collection )
39  {
40  const Akonadi::Collection::Id id = collection.id();
41  if ( collectionRanks.contains( id ) ) {
42  return collectionRanks[id];
43  }
44 
45  int rank = 100;
46  if ( Kernel::folderIsInbox( collection, true ) ) {
47  rank = 1;
48  } else if ( Kernel::self()->folderIsDraftOrOutbox( collection ) ) {
49  if ( Kernel::self()->folderIsDrafts( collection ) ) {
50  rank = 5;
51  } else {
52  rank = 2;
53  }
54  } else if ( Kernel::self()->folderIsSentMailFolder( collection ) ) {
55  rank = 3;
56  } else if ( Kernel::self()->folderIsTrash( collection ) ) {
57  rank = 4;
58  } else if ( Kernel::self()->folderIsTemplates( collection ) ) {
59  rank = 6;
60  } else if ( MailCommon::Util::isVirtualCollection( collection ) ) {
61  rank = 200;
62  } else if ( !topLevelOrder.isEmpty() ) {
63  if ( collection.parentCollection() == Akonadi::Collection::root()) {
64  const QString resource = collection.resource();
65  if (resource.isEmpty()) {
66  qDebug()<<" collection has not resource: "<<collection;
67  //Don't save in collectionranks because we don't have resource name => pb.
68  return rank;
69  }
70  const int order = topLevelOrder.indexOf(resource);
71  if ( order != -1 ) {
72  rank = order;
73  }
74  }
75  }
76  collectionRanks.insert( id, rank );
77  return rank;
78  }
79 
80  bool manualSortingActive;
81  QMap<Akonadi::Collection::Id, int> collectionRanks;
82  QStringList topLevelOrder;
83 };
84 
85 EntityCollectionOrderProxyModel::EntityCollectionOrderProxyModel( QObject *parent )
86  : EntityOrderProxyModel( parent ), d( new EntityCollectionOrderProxyModelPrivate() )
87 {
88  setDynamicSortFilter( true );
89  setSortCaseSensitivity( Qt::CaseInsensitive );
90  connect( Akonadi::SpecialMailCollections::self(), SIGNAL(defaultCollectionsChanged()),
91  this, SLOT(slotSpecialCollectionsChanged()) );
92  connect( Akonadi::SpecialMailCollections::self(), SIGNAL(collectionsChanged(Akonadi::AgentInstance)),
93  this, SLOT(slotSpecialCollectionsChanged()) );
94 }
95 
96 EntityCollectionOrderProxyModel::~EntityCollectionOrderProxyModel()
97 {
98  if ( d->manualSortingActive ) {
99  saveOrder();
100  }
101  delete d;
102 }
103 
104 void EntityCollectionOrderProxyModel::slotSpecialCollectionsChanged()
105 {
106  if ( !d->manualSortingActive ) {
107  d->collectionRanks.clear();
108  invalidate();
109  }
110 }
111 
112 void EntityCollectionOrderProxyModel::setTopLevelOrder(const QStringList& list)
113 {
114  d->topLevelOrder = list;
115  clearRanks();
116 }
117 
118 void EntityCollectionOrderProxyModel::clearRanks()
119 {
120  d->collectionRanks.clear();
121  invalidate();
122 }
123 
124 bool EntityCollectionOrderProxyModel::lessThan( const QModelIndex &left,
125  const QModelIndex &right ) const
126 {
127  if ( !d->manualSortingActive ) {
128 
129  Akonadi::Collection leftData =
130  left.data( Akonadi::EntityTreeModel::CollectionRole ).value<Akonadi::Collection>();
131  Akonadi::Collection rightData =
132  right.data( Akonadi::EntityTreeModel::CollectionRole ).value<Akonadi::Collection>();
133 
134  const int rankLeft = d->collectionRank( leftData );
135  const int rankRight = d->collectionRank( rightData );
136 
137  if ( rankLeft < rankRight ) {
138  return true;
139  } else if ( rankLeft > rankRight ) {
140  return false;
141  }
142 
143  return QSortFilterProxyModel::lessThan( left, right );
144  }
145  return EntityOrderProxyModel::lessThan( left, right );
146 }
147 
148 void EntityCollectionOrderProxyModel::setManualSortingActive( bool active )
149 {
150  if ( d->manualSortingActive == active ) {
151  return;
152  }
153 
154  d->manualSortingActive = active;
155  d->collectionRanks.clear();
156  invalidate();
157 }
158 
159 bool EntityCollectionOrderProxyModel::isManualSortingActive() const
160 {
161  return d->manualSortingActive;
162 }
163 
164 }
165 
166 #include "entitycollectionorderproxymodel.moc"
MailCommon::Kernel::folderIsTrash
bool folderIsTrash(const Akonadi::Collection &collection)
Returns true if the folder is a trash folder.
Definition: mailkernel.cpp:297
MailCommon::Kernel::folderIsTemplates
bool folderIsTemplates(const Akonadi::Collection &collection)
Definition: mailkernel.cpp:265
MailCommon::Kernel::folderIsSentMailFolder
bool folderIsSentMailFolder(const Akonadi::Collection &)
Returns true if the folder is one of the sent-mail folders.
Definition: mailkernel.cpp:313
MailCommon::EntityCollectionOrderProxyModel::isManualSortingActive
bool isManualSortingActive() const
Definition: entitycollectionorderproxymodel.cpp:159
entitycollectionorderproxymodel.h
MailCommon::EntityCollectionOrderProxyModel::EntityCollectionOrderProxyModel
EntityCollectionOrderProxyModel(QObject *parent=0)
Definition: entitycollectionorderproxymodel.cpp:85
MailCommon::Util::isVirtualCollection
MAILCOMMON_EXPORT bool isVirtualCollection(const Akonadi::Collection &col)
Definition: mailutil.cpp:96
MailCommon::Kernel::folderIsInbox
static bool folderIsInbox(const Akonadi::Collection &, bool withoutPop3InboxSetting=false)
Definition: mailkernel.cpp:335
id
SearchRule::Function id
Definition: daterulewidgethandler.cpp:34
QObject
MailCommon::EntityCollectionOrderProxyModel::slotSpecialCollectionsChanged
void slotSpecialCollectionsChanged()
Definition: entitycollectionorderproxymodel.cpp:104
MailCommon::EntityCollectionOrderProxyModel::lessThan
virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const
Definition: entitycollectionorderproxymodel.cpp:124
MailCommon::EntityCollectionOrderProxyModel::~EntityCollectionOrderProxyModel
virtual ~EntityCollectionOrderProxyModel()
Definition: entitycollectionorderproxymodel.cpp:96
MailCommon::EntityCollectionOrderProxyModel::setTopLevelOrder
void setTopLevelOrder(const QStringList &list)
Definition: entitycollectionorderproxymodel.cpp:112
MailCommon::EntityCollectionOrderProxyModel::clearRanks
void clearRanks()
Definition: entitycollectionorderproxymodel.cpp:118
MailCommon::Kernel::folderIsDrafts
bool folderIsDrafts(const Akonadi::Collection &)
Definition: mailkernel.cpp:243
MailCommon::Kernel::folderIsDraftOrOutbox
bool folderIsDraftOrOutbox(const Akonadi::Collection &collection)
Returns true if the folder is either the outbox or one of the drafts-folders.
Definition: mailkernel.cpp:234
mailkernel.h
MailCommon::Kernel::self
static Kernel * self()
Definition: mailkernel.cpp:71
mailutil.h
MailCommon::EntityCollectionOrderProxyModel::setManualSortingActive
void setManualSortingActive(bool active)
Definition: entitycollectionorderproxymodel.cpp:148
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:14 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

mailcommon

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

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

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