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

akonadi

  • akonadi
  • kmime
specialmailcollections.cpp
1 /*
2  Copyright (c) 2009 Constantin Berzan <exit3219@gmail.com>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "specialmailcollections.h"
21 #include "akonadi/entitydisplayattribute.h"
22 #include "akonadi/collectionmodifyjob.h"
23 #include "specialmailcollectionssettings.h"
24 
25 #include <KGlobal>
26 #include <KLocale>
27 #include "akonadi/agentinstance.h"
28 
29 using namespace Akonadi;
30 
31 class Akonadi::SpecialMailCollectionsPrivate
32 {
33  public:
34  SpecialMailCollectionsPrivate();
35  ~SpecialMailCollectionsPrivate();
36 
37  SpecialMailCollections *mInstance;
38 };
39 
40 typedef SpecialMailCollectionsSettings Settings;
41 
42 K_GLOBAL_STATIC( SpecialMailCollectionsPrivate, sInstance )
43 
44 static inline QByteArray enumToType( SpecialMailCollections::Type type )
45 {
46  switch ( type ) {
47  case SpecialMailCollections::Root: return "local-mail"; break;
48  case SpecialMailCollections::Inbox: return "inbox"; break;
49  case SpecialMailCollections::Outbox: return "outbox"; break;
50  case SpecialMailCollections::SentMail: return "sent-mail"; break;
51  case SpecialMailCollections::Trash: return "trash"; break;
52  case SpecialMailCollections::Drafts: return "drafts"; break;
53  case SpecialMailCollections::Templates: return "templates"; break;
54  case SpecialMailCollections::LastType: // fallthrough
55  default: return QByteArray(); break;
56  }
57 }
58 
59 SpecialMailCollectionsPrivate::SpecialMailCollectionsPrivate()
60  : mInstance( new SpecialMailCollections( this ) )
61 {
62 }
63 
64 SpecialMailCollectionsPrivate::~SpecialMailCollectionsPrivate()
65 {
66  delete mInstance;
67 }
68 
69 SpecialMailCollections::SpecialMailCollections( SpecialMailCollectionsPrivate *dd )
70  : SpecialCollections( Settings::self() ),
71  d( dd )
72 {
73 }
74 
75 SpecialMailCollections *SpecialMailCollections::self()
76 {
77  return sInstance->mInstance;
78 }
79 
80 bool SpecialMailCollections::hasCollection( Type type, const AgentInstance &instance ) const
81 {
82  return SpecialCollections::hasCollection( enumToType( type ), instance );
83 }
84 
85 Collection SpecialMailCollections::collection( Type type, const AgentInstance &instance ) const
86 {
87  return SpecialCollections::collection( enumToType( type ), instance );
88 }
89 
90 bool SpecialMailCollections::registerCollection( Type type, const Collection &collection )
91 {
92  return SpecialCollections::registerCollection( enumToType( type ), collection );
93 }
94 
95 bool SpecialMailCollections::hasDefaultCollection( Type type ) const
96 {
97  return SpecialCollections::hasDefaultCollection( enumToType( type ) );
98 }
99 
100 Collection SpecialMailCollections::defaultCollection( Type type ) const
101 {
102  return SpecialCollections::defaultCollection( enumToType( type ) );
103 }
104 
105 void SpecialMailCollections::verifyI18nDefaultCollection( Type type )
106 {
107  Collection collection = defaultCollection( type );
108  QString defaultI18n;
109 
110  switch ( type ) {
111  case SpecialMailCollections::Inbox:
112  defaultI18n = i18nc( "local mail folder", "inbox" );
113  break;
114  case SpecialMailCollections::Outbox:
115  defaultI18n = i18nc( "local mail folder", "outbox" );
116  break;
117  case SpecialMailCollections::SentMail:
118  defaultI18n = i18nc( "local mail folder", "sent-mail" );
119  break;
120  case SpecialMailCollections::Trash:
121  defaultI18n = i18nc( "local mail folder", "trash" );
122  break;
123  case SpecialMailCollections::Drafts:
124  defaultI18n = i18nc( "local mail folder", "drafts" );
125  break;
126  case SpecialMailCollections::Templates:
127  defaultI18n = i18nc( "local mail folder", "templates" );
128  break;
129  default:
130  break;
131  }
132  if(!defaultI18n.isEmpty()) {
133  if(collection.hasAttribute<Akonadi::EntityDisplayAttribute>()) {
134  if( collection.attribute<Akonadi::EntityDisplayAttribute>()->displayName() != defaultI18n) {
135  collection.attribute<Akonadi::EntityDisplayAttribute>()->setDisplayName( defaultI18n );
136  Akonadi::CollectionModifyJob *job = new Akonadi::CollectionModifyJob( collection, this );
137  connect( job, SIGNAL(result(KJob*)), this, SLOT(slotCollectionModified(KJob*)) );
138  }
139  }
140  }
141 }
142 
143 void SpecialMailCollections::slotCollectionModified(KJob*job)
144 {
145  if ( job->error() ) {
146  kDebug()<<" Error when we modified collection";
147  return;
148  }
149 }
150 
151 #include "specialmailcollections.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jan 5 2013 19:46:09 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