summaryrefslogtreecommitdiff
path: root/kolabformat/formathelpers.cpp
blob: b376b8cd89cb142fd7fb9e4bb57be6d1145c4541 (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
#include "formathelpers.h"
#include <klocalizedstring.h>
#include "kolabdefinitions.h"

namespace Kolab {

static const struct {
  const char *name;
  const char *label;
} folderTypeData[] = {
  { KOLAB_FOLDER_TYPE_MAIL,    ""                      },
  { KOLAB_FOLDER_TYPE_CONTACT, I18N_NOOP( "Contacts" ) },
  { KOLAB_FOLDER_TYPE_EVENT,   I18N_NOOP( "Calendar" ) },
  { KOLAB_FOLDER_TYPE_TASK,    I18N_NOOP( "Tasks" )    },
  { KOLAB_FOLDER_TYPE_JOURNAL, I18N_NOOP( "Journal" )  },
  { KOLAB_FOLDER_TYPE_NOTE,    I18N_NOOP( "Notes" )    },
  { KOLAB_FOLDER_TYPE_CONFIGURATION, I18N_NOOP( "Configuration" )    },
  { KOLAB_FOLDER_TYPE_FREEBUSY,    I18N_NOOP( "Freebusy" ) },
  { KOLAB_FOLDER_TYPE_FILE,    I18N_NOOP( "Files" ) }
};
static const int numFolderTypeData = sizeof folderTypeData / sizeof *folderTypeData;

std::string folderAnnotation(FolderType type, bool isDefault)
{
    Q_ASSERT( type >= 0 && type < LastType );
    std::string result = folderTypeData[ type ].name;
    if ( isDefault ) {
        result += KOLAB_FOLDER_TYPE_DEFAULT_SUFFIX;
    }
    return result;
}

FolderType folderTypeFromString(const std::string& folderTypeName)
{
    if ( folderTypeName == KOLAB_FOLDER_TYPE_CONTACT ||
    folderTypeName == KOLAB_FOLDER_TYPE_CONTACT KOLAB_FOLDER_TYPE_DEFAULT_SUFFIX ) {
        return ContactType;
    }

    if ( folderTypeName == KOLAB_FOLDER_TYPE_EVENT ||
        folderTypeName == KOLAB_FOLDER_TYPE_EVENT KOLAB_FOLDER_TYPE_DEFAULT_SUFFIX ) {
        return EventType;
    }

    if ( folderTypeName == KOLAB_FOLDER_TYPE_TASK ||
        folderTypeName == KOLAB_FOLDER_TYPE_TASK KOLAB_FOLDER_TYPE_DEFAULT_SUFFIX ) {
        return TaskType;
    }

    if ( folderTypeName == KOLAB_FOLDER_TYPE_JOURNAL ||
        folderTypeName == KOLAB_FOLDER_TYPE_JOURNAL KOLAB_FOLDER_TYPE_DEFAULT_SUFFIX ) {
        return JournalType;
    }

    if ( folderTypeName == KOLAB_FOLDER_TYPE_NOTE ||
        folderTypeName == KOLAB_FOLDER_TYPE_NOTE KOLAB_FOLDER_TYPE_DEFAULT_SUFFIX ) {
        return NoteType;
    }
    
    if ( folderTypeName == KOLAB_FOLDER_TYPE_CONFIGURATION ||
        folderTypeName == KOLAB_FOLDER_TYPE_CONFIGURATION KOLAB_FOLDER_TYPE_DEFAULT_SUFFIX ) {
        return ConfigurationType;
    }
    
    if ( folderTypeName == KOLAB_FOLDER_TYPE_FREEBUSY ||
        folderTypeName == KOLAB_FOLDER_TYPE_FREEBUSY KOLAB_FOLDER_TYPE_DEFAULT_SUFFIX ) {
        return FreebusyType;
    }

    if ( folderTypeName == KOLAB_FOLDER_TYPE_FILE ||
        folderTypeName == KOLAB_FOLDER_TYPE_FILE KOLAB_FOLDER_TYPE_DEFAULT_SUFFIX ) {
        return FileType;
    }

    return MailType;
}

FolderType guessFolderTypeFromName(const std::string& name)
{
    for ( int i = 0; i < numFolderTypeData; ++i ) {
        if ( name == i18n( folderTypeData[ i ].label ).toStdString() ||
            name == folderTypeData[ i ].label ) {
            return static_cast<FolderType>( i );
        }
    }
    return MailType;
}

std::string nameForFolderType(FolderType type)
{
    Q_ASSERT( type >= 0 && type < LastType );
    return i18n( folderTypeData[ type ].label ).toStdString();
}

}