summaryrefslogtreecommitdiffstats
path: root/kmail/scalix.cpp
blob: 4910119d04a996cf57b9274ce2517156d8031fd7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
 *   This file is part of KMail.
 *
 *   Copyright (C) 2007 Trolltech ASA. All rights reserved.
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include <tqmap.h>
#include <tqstringlist.h>

#include "scalix.h"

#include "kmfolder.h"
#include "kmfolderdir.h"

using namespace Scalix;

FolderAttributeParser::FolderAttributeParser( const TQString &attribute )
{
  TQStringList parts = TQStringList::split( ",", attribute, false );

  for ( uint i = 0; i < parts.count(); ++i ) {
    if ( parts[i].startsWith( "\\X-SpecialFolder=" ) )
      mFolderName = parts[i].mid( 17 );
    else if ( parts[i].startsWith( "\\X-FolderClass=" ) )
      mFolderClass = parts[i].mid( 15 );
  }
}

TQString FolderAttributeParser::folderClass() const
{
  return mFolderClass;
}

TQString FolderAttributeParser::folderName() const
{
  return mFolderName;
}

KMFolder* Utils::findStandardResourceFolder( KMFolderDir* folderParentDir,
                                             KMail::FolderContentsType contentsType,
                                             const TQStringList &attributes )
{
  TQMap<int, TQString> typeMap;
  typeMap.insert( KMail::ContentsTypeCalendar, "IPF.Appointment" );
  typeMap.insert( KMail::ContentsTypeContact, "IPF.Contact" );
  typeMap.insert( KMail::ContentsTypeNote, "IPF.StickyNote" );
  typeMap.insert( KMail::ContentsTypeTask, "IPF.Task" );

  if ( !typeMap.contains( contentsType ) )
    return 0;

  for ( uint i = 0; i < attributes.count(); ++i ) {
    FolderAttributeParser parser( attributes[ i ] );
    if ( parser.folderClass() == typeMap[ contentsType ] ) {
      KMFolderNode* node = folderParentDir->hasNamedFolder( parser.folderName() );
      if ( node && !node->isDir() )
        return static_cast<KMFolder*>( node );
    }
  }

  return 0;
}

KMail::FolderContentsType Utils::scalixIdToContentsType( const TQString &name )
{
  if ( name == "IPF.Appointment" )
    return KMail::ContentsTypeCalendar;
  else if ( name == "IPF.Contact" )
    return KMail::ContentsTypeContact;
  else if ( name == "IPF.StickyNote" )
    return KMail::ContentsTypeNote;
  else if ( name == "IPF.Task" )
    return KMail::ContentsTypeTask;
  else
    return KMail::ContentsTypeMail;
}

TQString Utils::contentsTypeToScalixId( KMail::FolderContentsType type )
{
  if ( type == KMail::ContentsTypeCalendar )
    return "IPF.Appointment";
  else if ( type == KMail::ContentsTypeContact )
    return "IPF.Contact";
  else if ( type == KMail::ContentsTypeNote )
    return "IPF.StickyNote";
  else if ( type == KMail::ContentsTypeTask )
    return "IPF.Task";
  else
    return "IPF.Note";
}