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

akonadi

mimetypechecker.cpp

00001 /*
00002     Copyright (c) 2009 Kevin Krammer <kevin.krammer@gmx.at>
00003 
00004     This library is free software; you can redistribute it and/or modify it
00005     under the terms of the GNU Library General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or (at your
00007     option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful, but WITHOUT
00010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012     License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to the
00016     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017     02110-1301, USA.
00018 */
00019 
00020 #include "mimetypechecker.h"
00021 
00022 #include "mimetypechecker_p.h"
00023 
00024 #include "collection.h"
00025 #include "item.h"
00026 
00027 using namespace Akonadi;
00028 
00029 MimeTypeChecker::MimeTypeChecker()
00030 {
00031   d = new MimeTypeCheckerPrivate();
00032 }
00033 
00034 MimeTypeChecker::MimeTypeChecker( const MimeTypeChecker &other )
00035   : d( other.d )
00036 {
00037 }
00038 
00039 MimeTypeChecker::~MimeTypeChecker()
00040 {
00041 }
00042 
00043 MimeTypeChecker &MimeTypeChecker::operator=( const MimeTypeChecker &other )
00044 {
00045   if ( &other != this )
00046     d = other.d;
00047 
00048   return *this;
00049 }
00050 
00051 QStringList MimeTypeChecker::wantedMimeTypes() const
00052 {
00053   return d->mWantedMimeTypes.values();
00054 }
00055 
00056 void MimeTypeChecker::setWantedMimeTypes( const QStringList &mimeTypes )
00057 {
00058   d->mWantedMimeTypes = QSet<QString>::fromList( mimeTypes );
00059 }
00060 
00061 void MimeTypeChecker::addWantedMimeType( const QString &mimeType )
00062 {
00063   d->mWantedMimeTypes.insert( mimeType );
00064 }
00065 
00066 void MimeTypeChecker::removeWantedMimeType(const QString &mimeType )
00067 {
00068   d->mWantedMimeTypes.remove( mimeType ); 
00069 }
00070 
00071 bool MimeTypeChecker::isWantedItem( const Item &item ) const
00072 {
00073   if ( d->mWantedMimeTypes.isEmpty() || !item.isValid() )
00074     return false;
00075 
00076   const QString mimeType = item.mimeType();
00077   if ( mimeType.isEmpty() )
00078     return false;
00079 
00080   return d->isWantedMimeType( mimeType );
00081 }
00082 
00083 bool MimeTypeChecker::isWantedCollection( const Collection &collection ) const
00084 {
00085   if ( d->mWantedMimeTypes.isEmpty() || !collection.isValid() )
00086     return false;
00087 
00088   const QStringList contentMimeTypes = collection.contentMimeTypes();
00089   if ( contentMimeTypes.isEmpty() )
00090     return false;
00091 
00092   foreach ( const QString &mimeType, contentMimeTypes ) {
00093     if ( mimeType.isEmpty() )
00094       continue;
00095 
00096     if ( d->isWantedMimeType( mimeType ) )
00097       return true;
00098   }
00099 
00100   return false;
00101 }
00102 
00103 bool MimeTypeChecker::isWantedItem( const Item &item, const QString &wantedMimeType )
00104 {
00105   if ( wantedMimeType.isEmpty() || !item.isValid() )
00106     return false;
00107 
00108   const QString mimeType = item.mimeType();
00109   if ( mimeType.isEmpty() )
00110     return false;
00111 
00112   if ( mimeType == wantedMimeType )
00113     return true;
00114 
00115   KMimeType::Ptr mimeTypePtr = KMimeType::mimeType( mimeType, KMimeType::ResolveAliases );
00116   if ( mimeTypePtr.isNull() )
00117     return false;
00118 
00119   return mimeTypePtr->is( wantedMimeType );
00120 }
00121 
00122 bool MimeTypeChecker::isWantedCollection( const Collection &collection, const QString &wantedMimeType )
00123 {
00124   if ( wantedMimeType.isEmpty() || !collection.isValid() )
00125     return false;
00126 
00127   const QStringList contentMimeTypes = collection.contentMimeTypes();
00128   if ( contentMimeTypes.isEmpty() )
00129     return false;
00130 
00131   foreach ( const QString &mimeType, contentMimeTypes ) {
00132     if ( mimeType.isEmpty() )
00133       continue;
00134 
00135     if ( mimeType == wantedMimeType )
00136       return true;
00137 
00138     KMimeType::Ptr mimeTypePtr = KMimeType::mimeType( mimeType, KMimeType::ResolveAliases );
00139     if ( mimeTypePtr.isNull() )
00140       continue;
00141 
00142    if ( mimeTypePtr->is( wantedMimeType ) )
00143      return true;
00144   }
00145 
00146   return false;
00147 }
00148 
00149 // kate: space-indent on; indent-width 2; replace-tabs on;

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