Akonadi::MimeTypeChecker

Search for usage in LXR

Akonadi::MimeTypeChecker Class Reference

#include <mimetypechecker.h>

Public Member Functions

 MimeTypeChecker ()
 
 MimeTypeChecker (const MimeTypeChecker &other)
 
 ~MimeTypeChecker ()
 
void addWantedMimeType (const QString &mimeType)
 
bool containsWantedMimeType (const QStringList &mimeTypes) const
 
bool hasWantedMimeTypes () const
 
bool isWantedCollection (const Collection &collection) const
 
bool isWantedItem (const Item &item) const
 
bool isWantedMimeType (const QString &mimeType) const
 
MimeTypeCheckeroperator= (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" hierarchy.

For example a check like this

if ( item.mimeType() == QLatin1StringView( "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

if ( checker.isWantedItem( item ) ){
// item.mimeType() is equal KContacts::Addressee::mimeType(), an aliases
// or a sub type.
}
Helper for checking MIME types of Collections and Items.
void addWantedMimeType(const QString &mimeType)
Adds another MIME type to the list of wanted MIME types this instance checks against.
bool isWantedItem(const Item &item) const
Checks whether a given item has one of the wanted MIME types.
static QString mimeType()

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

checker.addWantedMimeType( QLatin1StringView( "text/calendar" ) );
if ( checker.isWantedCollection( collection ) ) {
// collection.contentMimeTypes() contains @c "text/calendar"
// or a sub type.
}
bool isWantedCollection(const Collection &collection) const
Checks whether a given collection has one of the wanted MIME types.

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.

checker.addWantedMimeType( QLatin1StringView( "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.

if ( mimeFilter.isWantedItem( item ) ) {
// treat contact group's differently
}
}
void setWantedMimeTypes(const QStringList &mimeTypes)
Sets the list of wanted MIME types this instance checks against.
static QString mimeType()

This class is implicitly shared.

Author
Kevin Krammer kevin.nosp@m..kra.nosp@m.mmer@.nosp@m.gmx..nosp@m.at
Since
4.3

Definition at line 96 of file mimetypechecker.h.

Constructor & Destructor Documentation

◆ MimeTypeChecker() [1/2]

MimeTypeChecker::MimeTypeChecker ( )

Creates an empty MIME type checker.

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

Definition at line 16 of file mimetypechecker.cpp.

◆ MimeTypeChecker() [2/2]

MimeTypeChecker::MimeTypeChecker ( const MimeTypeChecker & other)

Creates a new MIME type checker from an other.

Definition at line 21 of file mimetypechecker.cpp.

◆ ~MimeTypeChecker()

MimeTypeChecker::~MimeTypeChecker ( )

Destroys the MIME type checker.

Definition at line 26 of file mimetypechecker.cpp.

Member Function Documentation

◆ addWantedMimeType()

void MimeTypeChecker::addWantedMimeType ( const QString & mimeType)

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

Parameters
mimeTypeThe MIME types to add to the checklist.
See also
setWantedMimeTypes()

Definition at line 54 of file mimetypechecker.cpp.

◆ containsWantedMimeType()

bool MimeTypeChecker::containsWantedMimeType ( const QStringList & mimeTypes) const
nodiscard

Checks whether any of the given MIME types is covered by one of the wanted MIME types.

Parameters
mimeTypesThe MIME types to check.
Returns
true if any of the MIME types in mimeTypes is coverd by one of the wanted MIME types, false otherwise.
Since
4.6

Definition at line 165 of file mimetypechecker.cpp.

◆ hasWantedMimeTypes()

bool MimeTypeChecker::hasWantedMimeTypes ( ) const
nodiscard

Checks whether any wanted MIME types are set.

Returns
true if any wanted MIME types are set, false otherwise.
Since
5.6.43

Definition at line 44 of file mimetypechecker.cpp.

◆ isWantedCollection() [1/2]

bool MimeTypeChecker::isWantedCollection ( const Collection & collection) const
nodiscard

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

Parameters
collectionThe 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()

Definition at line 78 of file mimetypechecker.cpp.

◆ isWantedCollection() [2/2]

bool MimeTypeChecker::isWantedCollection ( const Collection & collection,
const QString & wantedMimeType )
staticnodiscard

Checks whether a given collection has the given MIME type.

Parameters
collectionThe collection to check the content MIME types of.
wantedMimeTypeThe 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()

Definition at line 126 of file mimetypechecker.cpp.

◆ isWantedItem() [1/2]

bool MimeTypeChecker::isWantedItem ( const Item & item) const
nodiscard

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

Parameters
itemThe 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()

Definition at line 64 of file mimetypechecker.cpp.

◆ isWantedItem() [2/2]

bool MimeTypeChecker::isWantedItem ( const Item & item,
const QString & wantedMimeType )
staticnodiscard

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

Parameters
itemThe item to check the MIME type of.
wantedMimeTypeThe 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()

Definition at line 102 of file mimetypechecker.cpp.

◆ isWantedMimeType()

bool MimeTypeChecker::isWantedMimeType ( const QString & mimeType) const
nodiscard

Checks whether a given mime type is covered by one of the wanted MIME types.

Parameters
mimeTypeThe mime type to check.
Returns
true if the mime type mimeType is coverd by one of the wanted MIME types, false otherwise.
Since
4.6

Definition at line 160 of file mimetypechecker.cpp.

◆ operator=()

MimeTypeChecker & MimeTypeChecker::operator= ( const MimeTypeChecker & other)

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

Definition at line 30 of file mimetypechecker.cpp.

◆ removeWantedMimeType()

void MimeTypeChecker::removeWantedMimeType ( const QString & mimeType)

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

Parameters
mimeTypeThe MIME type to remove from the checklist.
See also
addWantedMimeType()

Definition at line 59 of file mimetypechecker.cpp.

◆ setWantedMimeTypes()

void MimeTypeChecker::setWantedMimeTypes ( const QStringList & mimeTypes)

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

Parameters
mimeTypesThe list of MIME types to check against.
See also
wantedMimeTypes()

Definition at line 49 of file mimetypechecker.cpp.

◆ wantedMimeTypes()

QStringList MimeTypeChecker::wantedMimeTypes ( ) const
nodiscard

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

Note
Don't use this just to check whether there are any wanted mimetypes. It is much faster to call hasWantedMimeTypes() instead for that purpose.
See also
setWantedMimeTypes(), hasWantedMimeTypes()

Definition at line 39 of file mimetypechecker.cpp.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:08:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.