kmail
scalix.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "scalix.h"
00021 #include "kmfolder.h"
00022 #include "kmfolderdir.h"
00023
00024 #include <QtCore/QMap>
00025
00026 using namespace Scalix;
00027
00028 FolderAttributeParser::FolderAttributeParser( const QString &attribute )
00029 {
00030 QStringList parts = attribute.split( ',', QString::SkipEmptyParts );
00031
00032 for ( int i = 0; i < parts.count(); ++i ) {
00033 if ( parts[i].startsWith( "\\X-SpecialFolder=" ) )
00034 mFolderName = parts[i].mid( 17 );
00035 else if ( parts[i].startsWith( "\\X-FolderClass=" ) )
00036 mFolderClass = parts[i].mid( 15 );
00037 }
00038 }
00039
00040 QString FolderAttributeParser::folderClass() const
00041 {
00042 return mFolderClass;
00043 }
00044
00045 QString FolderAttributeParser::folderName() const
00046 {
00047 return mFolderName;
00048 }
00049
00050 KMFolder* Utils::findStandardResourceFolder( KMFolderDir* folderParentDir,
00051 KMail::FolderContentsType contentsType,
00052 const QStringList &attributes )
00053 {
00054 QMap<int, QString> typeMap;
00055 typeMap.insert( KMail::ContentsTypeCalendar, "IPF.Appointment" );
00056 typeMap.insert( KMail::ContentsTypeContact, "IPF.Contact" );
00057 typeMap.insert( KMail::ContentsTypeNote, "IPF.StickyNote" );
00058 typeMap.insert( KMail::ContentsTypeTask, "IPF.Task" );
00059
00060 if ( !typeMap.contains( contentsType ) )
00061 return 0;
00062
00063 for ( int i = 0; i < attributes.count(); ++i ) {
00064 FolderAttributeParser parser( attributes[ i ] );
00065 if ( parser.folderClass() == typeMap[ contentsType ] ) {
00066 KMFolderNode* node = folderParentDir->hasNamedFolder( parser.folderName() );
00067 if ( node && !node->isDir() )
00068 return static_cast<KMFolder*>( node );
00069 }
00070 }
00071
00072 return 0;
00073 }
00074
00075 KMail::FolderContentsType Utils::scalixIdToContentsType( const QString &name )
00076 {
00077 if ( name == "IPF.Appointment" )
00078 return KMail::ContentsTypeCalendar;
00079 else if ( name == "IPF.Contact" )
00080 return KMail::ContentsTypeContact;
00081 else if ( name == "IPF.StickyNote" )
00082 return KMail::ContentsTypeNote;
00083 else if ( name == "IPF.Task" )
00084 return KMail::ContentsTypeTask;
00085 else
00086 return KMail::ContentsTypeMail;
00087 }
00088
00089 QString Utils::contentsTypeToScalixId( KMail::FolderContentsType type )
00090 {
00091 if ( type == KMail::ContentsTypeCalendar )
00092 return "IPF.Appointment";
00093 else if ( type == KMail::ContentsTypeContact )
00094 return "IPF.Contact";
00095 else if ( type == KMail::ContentsTypeNote )
00096 return "IPF.StickyNote";
00097 else if ( type == KMail::ContentsTypeTask )
00098 return "IPF.Task";
00099 else
00100 return "IPF.Note";
00101 }