• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.10.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 #include "akonadi/servermanager.h"
29 
30 using namespace Akonadi;
31 
32 class Akonadi::SpecialMailCollectionsPrivate
33 {
34  public:
35  SpecialMailCollectionsPrivate();
36  ~SpecialMailCollectionsPrivate();
37 
38  SpecialMailCollections *mInstance;
39 };
40 
41 typedef SpecialMailCollectionsSettings Settings;
42 
43 K_GLOBAL_STATIC( SpecialMailCollectionsPrivate, sInstance )
44 
45 static inline QByteArray enumToType( SpecialMailCollections::Type type )
46 {
47  switch ( type ) {
48  case SpecialMailCollections::Root: return "local-mail"; break;
49  case SpecialMailCollections::Inbox: return "inbox"; break;
50  case SpecialMailCollections::Outbox: return "outbox"; break;
51  case SpecialMailCollections::SentMail: return "sent-mail"; break;
52  case SpecialMailCollections::Trash: return "trash"; break;
53  case SpecialMailCollections::Drafts: return "drafts"; break;
54  case SpecialMailCollections::Templates: return "templates"; break;
55  case SpecialMailCollections::LastType: // fallthrough
56  default: return QByteArray(); break;
57  }
58 }
59 
60 SpecialMailCollectionsPrivate::SpecialMailCollectionsPrivate()
61  : mInstance( new SpecialMailCollections( this ) )
62 {
63 }
64 
65 SpecialMailCollectionsPrivate::~SpecialMailCollectionsPrivate()
66 {
67  delete mInstance;
68 }
69 
70 static KCoreConfigSkeleton *getConfig( const QString &filename)
71 {
72  Settings::instance( ServerManager::addNamespace(filename) );
73  return Settings::self();
74 }
75 
76 SpecialMailCollections::SpecialMailCollections( SpecialMailCollectionsPrivate *dd )
77  : SpecialCollections( getConfig(QLatin1String("specialmailcollectionsrc")) ),
78  d( dd )
79 {
80 }
81 
82 SpecialMailCollections *SpecialMailCollections::self()
83 {
84  return sInstance->mInstance;
85 }
86 
87 bool SpecialMailCollections::hasCollection( Type type, const AgentInstance &instance ) const
88 {
89  return SpecialCollections::hasCollection( enumToType( type ), instance );
90 }
91 
92 Collection SpecialMailCollections::collection( Type type, const AgentInstance &instance ) const
93 {
94  return SpecialCollections::collection( enumToType( type ), instance );
95 }
96 
97 bool SpecialMailCollections::registerCollection( Type type, const Collection &collection )
98 {
99  return SpecialCollections::registerCollection( enumToType( type ), collection );
100 }
101 
102 bool SpecialMailCollections::hasDefaultCollection( Type type ) const
103 {
104  return SpecialCollections::hasDefaultCollection( enumToType( type ) );
105 }
106 
107 Collection SpecialMailCollections::defaultCollection( Type type ) const
108 {
109  return SpecialCollections::defaultCollection( enumToType( type ) );
110 }
111 
112 void SpecialMailCollections::verifyI18nDefaultCollection( Type type )
113 {
114  Collection collection = defaultCollection( type );
115  QString defaultI18n;
116 
117  switch ( type ) {
118  case SpecialMailCollections::Inbox:
119  defaultI18n = i18nc( "local mail folder", "inbox" );
120  break;
121  case SpecialMailCollections::Outbox:
122  defaultI18n = i18nc( "local mail folder", "outbox" );
123  break;
124  case SpecialMailCollections::SentMail:
125  defaultI18n = i18nc( "local mail folder", "sent-mail" );
126  break;
127  case SpecialMailCollections::Trash:
128  defaultI18n = i18nc( "local mail folder", "trash" );
129  break;
130  case SpecialMailCollections::Drafts:
131  defaultI18n = i18nc( "local mail folder", "drafts" );
132  break;
133  case SpecialMailCollections::Templates:
134  defaultI18n = i18nc( "local mail folder", "templates" );
135  break;
136  default:
137  break;
138  }
139  if(!defaultI18n.isEmpty()) {
140  if(collection.hasAttribute<Akonadi::EntityDisplayAttribute>()) {
141  if( collection.attribute<Akonadi::EntityDisplayAttribute>()->displayName() != defaultI18n) {
142  collection.attribute<Akonadi::EntityDisplayAttribute>()->setDisplayName( defaultI18n );
143  Akonadi::CollectionModifyJob *job = new Akonadi::CollectionModifyJob( collection, this );
144  connect( job, SIGNAL(result(KJob*)), this, SLOT(slotCollectionModified(KJob*)) );
145  }
146  }
147  }
148 }
149 
150 void SpecialMailCollections::slotCollectionModified(KJob*job)
151 {
152  if ( job->error() ) {
153  kDebug()<<" Error when we modified collection";
154  return;
155  }
156 }
157 
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:27:41 by doxygen 1.8.3.1 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.10.5 API Reference

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