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

KMIME Library

  • sources
  • kde-4.12
  • kdepimlibs
  • kmime
kmime_headerfactory.cpp
Go to the documentation of this file.
1 /*
2  kmime_header_factory.cpp
3 
4  KMime, the KDE Internet mail/usenet news message library.
5  Copyright (c) 2009 Constantin Berzan <exit3219@gmail.com>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 
34 #include "kmime_headerfactory_p.h"
35 #include "kmime_headers.h"
36 
37 #include <QHash>
38 
39 #include <KDebug>
40 #include <KGlobal>
41 
42 using namespace KMime;
43 
48 class KMime::HeaderFactoryPrivate
49 {
50  public:
51  HeaderFactoryPrivate();
52  ~HeaderFactoryPrivate();
53 
54  HeaderFactory *const instance;
55  QHash<QByteArray, HeaderMakerBase*> headerMakers; // Type->obj mapping; with lower-case type.
56 };
57 
58 K_GLOBAL_STATIC( HeaderFactoryPrivate, sInstance )
59 
60 HeaderFactoryPrivate::HeaderFactoryPrivate()
61  : instance( new HeaderFactory( this ) )
62 {
63 }
64 
65 HeaderFactoryPrivate::~HeaderFactoryPrivate()
66 {
67  qDeleteAll( headerMakers );
68  delete instance;
69 }
70 
71 
72 
73 HeaderFactory* HeaderFactory::self()
74 {
75  return sInstance->instance;
76 }
77 
78 Headers::Base *HeaderFactory::createHeader( const QByteArray &type )
79 {
80  Q_ASSERT( !type.isEmpty() );
81  const HeaderMakerBase *maker = d->headerMakers.value( type.toLower() );
82  if ( maker ) {
83  return maker->create();
84  } else {
85  //kError() << "Unknown header type" << type;
86  //return new Headers::Generic;
87  return 0;
88  }
89 }
90 
91 HeaderFactory::HeaderFactory( HeaderFactoryPrivate *dd )
92  : d( dd )
93 {
94 }
95 
96 HeaderFactory::~HeaderFactory()
97 {
98 }
99 
100 bool HeaderFactory::registerHeaderMaker( const QByteArray &type, HeaderMakerBase *maker )
101 {
102  if ( type.isEmpty() ) {
103  // This is probably a generic (but not abstract) header,
104  // like Address or MailboxList. We cannot register those.
105  kWarning() << "Tried to register header with empty type.";
106  return false;
107  }
108  const QByteArray ltype = type.toLower();
109  if ( d->headerMakers.contains( ltype ) ) {
110  kWarning() << "Header of type" << type << "already registered.";
111  // TODO should we make this an error?
112  return false;
113  }
114  d->headerMakers.insert( ltype, maker );
115  return true;
116 }
KMime::Headers::Base
Baseclass of all header-classes.
Definition: kmime_headers.h:124
kmime_headers.h
This file is part of the API for handling MIME data and defines the various header classes: ...
kmime_headerfactory_p.h
This file is part of the API for handling MIME data and defines the HeaderFactory class...
KMime::HeaderFactory
docu TODO
Definition: kmime_headerfactory_p.h:68
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:11 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KMIME Library

Skip menu "KMIME Library"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

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