kmail

scalix.cpp
1 /*
2  * This file is part of KMail.
3  *
4  * Copyright (C) 2007 Trolltech ASA. All rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #include <tqmap.h>
22 #include <tqstringlist.h>
23 
24 #include "scalix.h"
25 
26 #include "kmfolder.h"
27 #include "kmfolderdir.h"
28 
29 using namespace Scalix;
30 
31 FolderAttributeParser::FolderAttributeParser( const TQString &attribute )
32 {
33  TQStringList parts = TQStringList::split( ",", attribute, false );
34 
35  for ( uint i = 0; i < parts.count(); ++i ) {
36  if ( parts[i].startsWith( "\\X-SpecialFolder=" ) )
37  mFolderName = parts[i].mid( 17 );
38  else if ( parts[i].startsWith( "\\X-FolderClass=" ) )
39  mFolderClass = parts[i].mid( 15 );
40  }
41 }
42 
43 TQString FolderAttributeParser::folderClass() const
44 {
45  return mFolderClass;
46 }
47 
48 TQString FolderAttributeParser::folderName() const
49 {
50  return mFolderName;
51 }
52 
53 KMFolder* Utils::findStandardResourceFolder( KMFolderDir* folderParentDir,
54  KMail::FolderContentsType contentsType,
55  const TQStringList &attributes )
56 {
57  TQMap<int, TQString> typeMap;
58  typeMap.insert( KMail::ContentsTypeCalendar, "IPF.Appointment" );
59  typeMap.insert( KMail::ContentsTypeContact, "IPF.Contact" );
60  typeMap.insert( KMail::ContentsTypeNote, "IPF.StickyNote" );
61  typeMap.insert( KMail::ContentsTypeTask, "IPF.Task" );
62 
63  if ( !typeMap.contains( contentsType ) )
64  return 0;
65 
66  for ( uint i = 0; i < attributes.count(); ++i ) {
67  FolderAttributeParser parser( attributes[ i ] );
68  if ( parser.folderClass() == typeMap[ contentsType ] ) {
69  KMFolderNode* node = folderParentDir->hasNamedFolder( parser.folderName() );
70  if ( node && !node->isDir() )
71  return static_cast<KMFolder*>( node );
72  }
73  }
74 
75  return 0;
76 }
77 
78 KMail::FolderContentsType Utils::scalixIdToContentsType( const TQString &name )
79 {
80  if ( name == "IPF.Appointment" )
81  return KMail::ContentsTypeCalendar;
82  else if ( name == "IPF.Contact" )
83  return KMail::ContentsTypeContact;
84  else if ( name == "IPF.StickyNote" )
85  return KMail::ContentsTypeNote;
86  else if ( name == "IPF.Task" )
87  return KMail::ContentsTypeTask;
88  else
89  return KMail::ContentsTypeMail;
90 }
91 
92 TQString Utils::contentsTypeToScalixId( KMail::FolderContentsType type )
93 {
94  if ( type == KMail::ContentsTypeCalendar )
95  return "IPF.Appointment";
96  else if ( type == KMail::ContentsTypeContact )
97  return "IPF.Contact";
98  else if ( type == KMail::ContentsTypeNote )
99  return "IPF.StickyNote";
100  else if ( type == KMail::ContentsTypeTask )
101  return "IPF.Task";
102  else
103  return "IPF.Note";
104 }
KMail list that manages the contents of one directory that may contain folders and/or other directori...
Definition: kmfolderdir.h:16
virtual KMFolderNode * hasNamedFolder(const TQString &name)
Returns folder with given name or zero if it does not exist.
Mail folder.
Definition: kmfolder.h:69
This class takes a folder attribute string as argument and provides access to the single parts.
Definition: scalix.h:57