File indexing completed on 2024-11-24 04:44:12
0001 /* 0002 * SPDX-FileCopyrightText: 2012 Christian Mollekopf <mollekopf@kolabsys.com> 0003 * 0004 * SPDX-License-Identifier: LGPL-3.0-or-later 0005 */ 0006 0007 #include "formathelpers.h" 0008 #include "kolabdefinitions.h" 0009 #include <KLazyLocalizedString> 0010 #include <KLocalizedString> 0011 namespace Kolab 0012 { 0013 static const struct { 0014 const char *name; 0015 const KLazyLocalizedString label; 0016 } folderTypeData[] = {{KOLAB_FOLDER_TYPE_MAIL, KLazyLocalizedString()}, 0017 {KOLAB_FOLDER_TYPE_CONTACT, kli18n("Contacts")}, 0018 {KOLAB_FOLDER_TYPE_EVENT, kli18n("Calendar")}, 0019 {KOLAB_FOLDER_TYPE_TASK, kli18n("Tasks")}, 0020 {KOLAB_FOLDER_TYPE_JOURNAL, kli18n("Journal")}, 0021 {KOLAB_FOLDER_TYPE_NOTE, kli18n("Notes")}, 0022 {KOLAB_FOLDER_TYPE_CONFIGURATION, kli18n("Configuration")}, 0023 {KOLAB_FOLDER_TYPE_FREEBUSY, kli18n("Freebusy")}, 0024 {KOLAB_FOLDER_TYPE_FILE, kli18n("Files")}}; 0025 static const int numFolderTypeData = sizeof folderTypeData / sizeof *folderTypeData; 0026 0027 std::string folderAnnotation(FolderType type, bool isDefault) 0028 { 0029 Q_ASSERT(type >= 0 && type < LastType); 0030 std::string result = folderTypeData[type].name; 0031 if (isDefault) { 0032 result += KOLAB_FOLDER_TYPE_DEFAULT_SUFFIX; 0033 } 0034 return result; 0035 } 0036 0037 FolderType folderTypeFromString(const std::string &folderTypeName) 0038 { 0039 if (folderTypeName == KOLAB_FOLDER_TYPE_CONTACT || folderTypeName == KOLAB_FOLDER_TYPE_CONTACT KOLAB_FOLDER_TYPE_DEFAULT_SUFFIX) { 0040 return ContactType; 0041 } 0042 0043 if (folderTypeName == KOLAB_FOLDER_TYPE_EVENT || folderTypeName == KOLAB_FOLDER_TYPE_EVENT KOLAB_FOLDER_TYPE_DEFAULT_SUFFIX) { 0044 return EventType; 0045 } 0046 0047 if (folderTypeName == KOLAB_FOLDER_TYPE_TASK || folderTypeName == KOLAB_FOLDER_TYPE_TASK KOLAB_FOLDER_TYPE_DEFAULT_SUFFIX) { 0048 return TaskType; 0049 } 0050 0051 if (folderTypeName == KOLAB_FOLDER_TYPE_JOURNAL || folderTypeName == KOLAB_FOLDER_TYPE_JOURNAL KOLAB_FOLDER_TYPE_DEFAULT_SUFFIX) { 0052 return JournalType; 0053 } 0054 0055 if (folderTypeName == KOLAB_FOLDER_TYPE_NOTE || folderTypeName == KOLAB_FOLDER_TYPE_NOTE KOLAB_FOLDER_TYPE_DEFAULT_SUFFIX) { 0056 return NoteType; 0057 } 0058 0059 if (folderTypeName == KOLAB_FOLDER_TYPE_CONFIGURATION || folderTypeName == KOLAB_FOLDER_TYPE_CONFIGURATION KOLAB_FOLDER_TYPE_DEFAULT_SUFFIX) { 0060 return ConfigurationType; 0061 } 0062 0063 if (folderTypeName == KOLAB_FOLDER_TYPE_FREEBUSY || folderTypeName == KOLAB_FOLDER_TYPE_FREEBUSY KOLAB_FOLDER_TYPE_DEFAULT_SUFFIX) { 0064 return FreebusyType; 0065 } 0066 0067 if (folderTypeName == KOLAB_FOLDER_TYPE_FILE || folderTypeName == KOLAB_FOLDER_TYPE_FILE KOLAB_FOLDER_TYPE_DEFAULT_SUFFIX) { 0068 return FileType; 0069 } 0070 0071 return MailType; 0072 } 0073 0074 FolderType guessFolderTypeFromName(const std::string &name) 0075 { 0076 for (int i = 0; i < numFolderTypeData; ++i) { 0077 if (name == folderTypeData[i].label.toString().toStdString() || name == folderTypeData[i].label.untranslatedText()) { 0078 return static_cast<FolderType>(i); 0079 } 0080 } 0081 return MailType; 0082 } 0083 0084 std::string nameForFolderType(FolderType type) 0085 { 0086 Q_ASSERT(type >= 0 && type < LastType); 0087 return folderTypeData[type].label.toString().toStdString(); 0088 } 0089 }