kmail

scalix.cpp

Go to the documentation of this file.
00001 /*
00002  *   This file is part of KMail.
00003  *
00004  *   Copyright (C) 2007 Trolltech ASA. All rights reserved.
00005  *
00006  *   This program is free software; you can redistribute it and/or modify
00007  *   it under the terms of the GNU General Public License as published by
00008  *   the Free Software Foundation; either version 2 of the License, or
00009  *   (at your option) any later version.
00010  *
00011  *   This program is distributed in the hope that it will be useful,
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *   GNU General Public License for more details.
00015  *
00016  *   You should have received a copy of the GNU General Public License
00017  *   along with this program; if not, write to the Free Software
00018  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #include <qmap.h>
00022 #include <qstringlist.h>
00023 
00024 #include "scalix.h"
00025 
00026 #include "kmfolder.h"
00027 #include "kmfolderdir.h"
00028 
00029 using namespace Scalix;
00030 
00031 FolderAttributeParser::FolderAttributeParser( const QString &attribute )
00032 {
00033   QStringList parts = QStringList::split( ",", attribute, false );
00034 
00035   for ( uint i = 0; i < parts.count(); ++i ) {
00036     if ( parts[i].startsWith( "\\X-SpecialFolder=" ) )
00037       mFolderName = parts[i].mid( 17 );
00038     else if ( parts[i].startsWith( "\\X-FolderClass=" ) )
00039       mFolderClass = parts[i].mid( 15 );
00040   }
00041 }
00042 
00043 QString FolderAttributeParser::folderClass() const
00044 {
00045   return mFolderClass;
00046 }
00047 
00048 QString FolderAttributeParser::folderName() const
00049 {
00050   return mFolderName;
00051 }
00052 
00053 KMFolder* Utils::findStandardResourceFolder( KMFolderDir* folderParentDir,
00054                                              KMail::FolderContentsType contentsType,
00055                                              const QStringList &attributes )
00056 {
00057   QMap<int, QString> typeMap;
00058   typeMap.insert( KMail::ContentsTypeCalendar, "IPF.Appointment" );
00059   typeMap.insert( KMail::ContentsTypeContact, "IPF.Contact" );
00060   typeMap.insert( KMail::ContentsTypeNote, "IPF.StickyNote" );
00061   typeMap.insert( KMail::ContentsTypeTask, "IPF.Task" );
00062 
00063   if ( !typeMap.contains( contentsType ) )
00064     return 0;
00065 
00066   for ( uint i = 0; i < attributes.count(); ++i ) {
00067     FolderAttributeParser parser( attributes[ i ] );
00068     if ( parser.folderClass() == typeMap[ contentsType ] ) {
00069       KMFolderNode* node = folderParentDir->hasNamedFolder( parser.folderName() );
00070       if ( node && !node->isDir() )
00071         return static_cast<KMFolder*>( node );
00072     }
00073   }
00074 
00075   return 0;
00076 }
00077 
00078 KMail::FolderContentsType Utils::scalixIdToContentsType( const QString &name )
00079 {
00080   if ( name == "IPF.Appointment" )
00081     return KMail::ContentsTypeCalendar;
00082   else if ( name == "IPF.Contact" )
00083     return KMail::ContentsTypeContact;
00084   else if ( name == "IPF.StickyNote" )
00085     return KMail::ContentsTypeNote;
00086   else if ( name == "IPF.Task" )
00087     return KMail::ContentsTypeTask;
00088   else
00089     return KMail::ContentsTypeMail;
00090 }
00091 
00092 QString Utils::contentsTypeToScalixId( KMail::FolderContentsType type )
00093 {
00094   if ( type == KMail::ContentsTypeCalendar )
00095     return "IPF.Appointment";
00096   else if ( type == KMail::ContentsTypeContact )
00097     return "IPF.Contact";
00098   else if ( type == KMail::ContentsTypeNote )
00099     return "IPF.StickyNote";
00100   else if ( type == KMail::ContentsTypeTask )
00101     return "IPF.Task";
00102   else
00103     return "IPF.Note";
00104 }