• Skip to content
  • Skip to link menu
KDE 4.5 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

akonadi

  • Akonadi
  • Akonadi::MimeTypeChecker
Public Member Functions | Static Public Member Functions

Akonadi::MimeTypeChecker Class Reference

Helper for checking MIME types of Collections and Items. More...

#include <mimetypechecker.h>

List of all members.

Public Member Functions

 MimeTypeChecker ()
 MimeTypeChecker (const MimeTypeChecker &other)
 ~MimeTypeChecker ()
void addWantedMimeType (const QString &mimeType)
bool isWantedCollection (const Collection &collection) const
bool isWantedItem (const Item &item) const
MimeTypeChecker & operator= (const MimeTypeChecker &other)
void removeWantedMimeType (const QString &mimeType)
void setWantedMimeTypes (const QStringList &mimeTypes)
QStringList wantedMimeTypes () const

Static Public Member Functions

static bool isWantedCollection (const Collection &collection, const QString &wantedMimeType)
static bool isWantedItem (const Item &item, const QString &wantedMimeType)

Detailed Description

Helper for checking MIME types of Collections and Items.

When it is necessary to decide whether an item has a certain MIME type or whether a collection can contain a certain MIME type, direct string comparison might not render the desired result because MIME types can have aliases and be a node in an "inheritance" hierachy.

For example a check like this

 if ( item.mimeType() == QLatin1String( "text/directory" ) )

would fail to detect "text/x-vcard" as being the same MIME type.

Note:
KDE deals with this inside the KMimeType framework, this class is just a convenience helper for common Akonadi related checks.

Example: Checking whether an Akonadi::Item is contact MIME type

 Akonadi::MimeTypeChecker checker;
 checker.addWantedMimeType( KABC::Addressee::mimeType() );

 if ( checker.isWantedItem( item ) ){
   // item.mimeType() is equal KABC::Addressee::mimeType(), an aliases
   // or a sub type.
 }

Example: Checking whether an Akonadi::Collection could contain calendar items

 Akonadi::MimeTypeChecker checker;
 checker.addWantedMimeType( QLatin1String( "text/calendar" ) );

 if ( checker.isWantedCollection( collection ) ) {
   // collection.contentMimeTypes() contains @c "text/calendar"
   // or a sub type.
 }

Example: Checking whether an Akonadi::Collection could contain Calendar Event items (i.e. KCal::Event), making use of the respective MIME type "subclassing" provided by Akonadi's MIME type extensions.

 Akonadi::MimeTypeChecker checker;
 checker.addWantedMimeType( QLatin1String( "application/x-vnd.akonadi.calendar.event" ) );

 if ( checker.isWantedCollection( collection ) ) {
   // collection.contentMimeTypes() contains @c "application/x-vnd.akonadi.calendar.event"
   // or a sub type, but just containing @c "text/calendar" would not
   // get here
 }

Example: Checking for items of more than one MIME type and treat one of them specially.

 Akonadi::MimeTypeChecker mimeFilter;
 mimeFilter.setWantedMimeTypes( QStringList() << KABC::Addressee::mimeType()
                                << KABC::ContactGroup::mimeType() );

 if ( mimeFilter.isWantedItem( item ) ) {
   if ( Akonadi::MimeTypeChecker::isWantedItem( item, KABC::ContactGroup::mimeType() ) {
     // treat contact group's differently
   }
 }

This class is implicitly shared.

Author:
Kevin Krammer <kevin.krammer@gmx.at>
Since:
4.3

Definition at line 109 of file mimetypechecker.h.


Constructor & Destructor Documentation

Akonadi::MimeTypeChecker::MimeTypeChecker (  ) 

Creates an empty MIME type checker.

An empty checker will not report any items or collections as wanted.

Akonadi::MimeTypeChecker::MimeTypeChecker ( const MimeTypeChecker &  other  ) 

Creates a new MIME type checker from an other.

Akonadi::MimeTypeChecker::~MimeTypeChecker (  ) 

Destroys the MIME type checker.


Member Function Documentation

void Akonadi::MimeTypeChecker::addWantedMimeType ( const QString &  mimeType  ) 

Adds another MIME type to the list of wanted MIME types this instance checks against.

Parameters:
mimeType The MIME types to add to the checklist.
See also:
setWantedMimeTypes()
static bool Akonadi::MimeTypeChecker::isWantedCollection ( const Collection &  collection,
const QString &  wantedMimeType 
) [static]

Checks whether a given collection has the given MIME type.

Parameters:
item The collection to check the content MIME types of.
wantedMimeType The MIME type to check against.
Returns:
true if one of the collection content MIME types is the given wanted one, false if it isn't, the collection is invalid or has an empty content MIME type list.
See also:
setWantedMimeTypes()
Collection::contentMimeTypes()
bool Akonadi::MimeTypeChecker::isWantedCollection ( const Collection &  collection  )  const

Checks whether a given collection has one of the wanted MIME types.

Parameters:
collection The collection to check the content MIME types of.
Returns:
true if one of the collection content MIME types is one of the wanted ones, false if non is, the collection is invalid or has an empty content MIME type list.
See also:
setWantedMimeTypes()
Collection::contentMimeTypes()
static bool Akonadi::MimeTypeChecker::isWantedItem ( const Item &  item,
const QString &  wantedMimeType 
) [static]

Checks whether a given item has the given wanted MIME type.

Parameters:
item The item to check the MIME type of.
wantedMimeType The MIME type to check against.
Returns:
true if the item MIME type is the given one, false if it isn't, the item is invalid or has an empty MIME type.
See also:
setWantedMimeTypes()
Item::mimeType()
bool Akonadi::MimeTypeChecker::isWantedItem ( const Item &  item  )  const

Checks whether a given item has one of the wanted MIME types.

Parameters:
item The item to check the MIME type of.
Returns:
true if the item MIME type is one of the wanted ones, false if it isn't, the item is invalid or has an empty MIME type.
See also:
setWantedMimeTypes()
Item::mimeType()
MimeTypeChecker& Akonadi::MimeTypeChecker::operator= ( const MimeTypeChecker &  other  ) 

Assigns the other to this checker and returns a reference to this checker.

void Akonadi::MimeTypeChecker::removeWantedMimeType ( const QString &  mimeType  ) 

Removes a MIME type from the list of wanted MIME types this instance checks against.

Parameters:
mimeType The MIME type to remove from the checklist.
See also:
addWantedMimeType()
void Akonadi::MimeTypeChecker::setWantedMimeTypes ( const QStringList &  mimeTypes  ) 

Sets the list of wanted MIME types this instance checks against.

Parameters:
mimeTypes The list of MIME types to check against.
See also:
wantedMimeTypes()
QStringList Akonadi::MimeTypeChecker::wantedMimeTypes (  )  const

Returns the list of wanted MIME types this instance checks against.

See also:
setWantedMimeTypes()

The documentation for this class was generated from the following file:
  • mimetypechecker.h

akonadi

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

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.7.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal