File indexing completed on 2025-01-05 04:58:21
0001 /* 0002 SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 0006 */ 0007 0008 #include "collectiontypeutil.h" 0009 #include <KLocalizedString> 0010 0011 using namespace PimCommon; 0012 CollectionTypeUtil::CollectionTypeUtil() = default; 0013 0014 CollectionTypeUtil::~CollectionTypeUtil() = default; 0015 0016 QByteArray CollectionTypeUtil::kolabFolderType() 0017 { 0018 return "/shared/vendor/kolab/folder-type"; 0019 } 0020 0021 QByteArray CollectionTypeUtil::kolabIncidencesFor() 0022 { 0023 return "/shared/vendor/kolab/incidences-for"; 0024 } 0025 0026 QByteArray CollectionTypeUtil::kolabSharedSeen() 0027 { 0028 return "/shared/vendor/cmu/cyrus-imapd/sharedseen"; 0029 } 0030 0031 QString CollectionTypeUtil::folderContentDescription(CollectionTypeUtil::FolderContentsType type) 0032 { 0033 switch (type) { 0034 case CollectionTypeUtil::ContentsTypeMail: 0035 return i18nc("type of folder content", "Mail"); 0036 case CollectionTypeUtil::ContentsTypeCalendar: 0037 return i18nc("type of folder content", "Calendar"); 0038 case CollectionTypeUtil::ContentsTypeContact: 0039 return i18nc("type of folder content", "Contacts"); 0040 case CollectionTypeUtil::ContentsTypeNote: 0041 return i18nc("type of folder content", "Notes"); 0042 case CollectionTypeUtil::ContentsTypeTask: 0043 return i18nc("type of folder content", "Tasks"); 0044 case CollectionTypeUtil::ContentsTypeJournal: 0045 return i18nc("type of folder content", "Journal"); 0046 case CollectionTypeUtil::ContentsTypeConfiguration: 0047 return i18nc("type of folder content", "Configuration"); 0048 case CollectionTypeUtil::ContentsTypeFreebusy: 0049 return i18nc("type of folder content", "Freebusy"); 0050 case CollectionTypeUtil::ContentsTypeFile: 0051 return i18nc("type of folder content", "Files"); 0052 default: 0053 return i18nc("type of folder content", "Unknown"); 0054 } 0055 } 0056 0057 QString CollectionTypeUtil::incidencesForToString(CollectionTypeUtil::IncidencesFor type) 0058 { 0059 switch (type) { 0060 case CollectionTypeUtil::IncForNobody: 0061 return QStringLiteral("nobody"); 0062 case CollectionTypeUtil::IncForAdmins: 0063 return QStringLiteral("admins"); 0064 case CollectionTypeUtil::IncForReaders: 0065 return QStringLiteral("readers"); 0066 } 0067 0068 return {}; // can't happen 0069 } 0070 0071 CollectionTypeUtil::IncidencesFor CollectionTypeUtil::incidencesForFromString(const QString &string) 0072 { 0073 if (string == QLatin1StringView("nobody")) { 0074 return CollectionTypeUtil::IncForNobody; 0075 } else if (string == QLatin1StringView("admins")) { 0076 return CollectionTypeUtil::IncForAdmins; 0077 } else if (string == QLatin1StringView("readers")) { 0078 return CollectionTypeUtil::IncForReaders; 0079 } 0080 0081 return CollectionTypeUtil::IncForAdmins; // by default 0082 } 0083 0084 CollectionTypeUtil::FolderContentsType CollectionTypeUtil::typeFromKolabName(const QByteArray &name) 0085 { 0086 if (name == "task" || name == "task.default") { 0087 return CollectionTypeUtil::ContentsTypeTask; 0088 } 0089 if (name == "event" || name == "event.default") { 0090 return CollectionTypeUtil::ContentsTypeCalendar; 0091 } 0092 if (name == "contact" || name == "contact.default") { 0093 return CollectionTypeUtil::ContentsTypeContact; 0094 } 0095 if (name == "note" || name == "note.default") { 0096 return CollectionTypeUtil::ContentsTypeNote; 0097 } 0098 if (name == "journal" || name == "journal.default") { 0099 return CollectionTypeUtil::ContentsTypeJournal; 0100 } 0101 if (name == "configuration" || name == "configuration.default") { 0102 return CollectionTypeUtil::ContentsTypeConfiguration; 0103 } 0104 if (name == "freebusy" || name == "freebusy.default") { 0105 return CollectionTypeUtil::ContentsTypeFreebusy; 0106 } 0107 if (name == "file" || name == "file.default") { 0108 return CollectionTypeUtil::ContentsTypeFile; 0109 } 0110 0111 return CollectionTypeUtil::ContentsTypeMail; 0112 } 0113 0114 QByteArray CollectionTypeUtil::kolabNameFromType(CollectionTypeUtil::FolderContentsType type) 0115 { 0116 switch (type) { 0117 case CollectionTypeUtil::ContentsTypeCalendar: 0118 return "event"; 0119 case CollectionTypeUtil::ContentsTypeContact: 0120 return "contact"; 0121 case CollectionTypeUtil::ContentsTypeNote: 0122 return "note"; 0123 case CollectionTypeUtil::ContentsTypeTask: 0124 return "task"; 0125 case CollectionTypeUtil::ContentsTypeJournal: 0126 return "journal"; 0127 case CollectionTypeUtil::ContentsTypeConfiguration: 0128 return "configuration"; 0129 case CollectionTypeUtil::ContentsTypeFreebusy: 0130 return "freebusy"; 0131 case CollectionTypeUtil::ContentsTypeFile: 0132 return "file"; 0133 default: 0134 return {}; 0135 } 0136 } 0137 0138 CollectionTypeUtil::FolderContentsType CollectionTypeUtil::contentsTypeFromString(const QString &type) 0139 { 0140 if (type == i18nc("type of folder content", "Mail")) { 0141 return CollectionTypeUtil::ContentsTypeMail; 0142 } 0143 if (type == i18nc("type of folder content", "Calendar")) { 0144 return CollectionTypeUtil::ContentsTypeCalendar; 0145 } 0146 if (type == i18nc("type of folder content", "Contacts")) { 0147 return CollectionTypeUtil::ContentsTypeContact; 0148 } 0149 if (type == i18nc("type of folder content", "Notes")) { 0150 return CollectionTypeUtil::ContentsTypeNote; 0151 } 0152 if (type == i18nc("type of folder content", "Tasks")) { 0153 return CollectionTypeUtil::ContentsTypeTask; 0154 } 0155 if (type == i18nc("type of folder content", "Journal")) { 0156 return CollectionTypeUtil::ContentsTypeJournal; 0157 } 0158 if (type == i18nc("type of folder content", "Configuration")) { 0159 return CollectionTypeUtil::ContentsTypeConfiguration; 0160 } 0161 if (type == i18nc("type of folder content", "Freebusy")) { 0162 return CollectionTypeUtil::ContentsTypeFreebusy; 0163 } 0164 if (type == i18nc("type of folder content", "Files")) { 0165 return CollectionTypeUtil::ContentsTypeFile; 0166 } 0167 0168 return CollectionTypeUtil::ContentsTypeMail; // safety return value 0169 } 0170 0171 QString CollectionTypeUtil::typeNameFromKolabType(const QByteArray &type) 0172 { 0173 if (type == "task" || type == "task.default") { 0174 return i18nc("type of folder content", "Tasks"); 0175 } 0176 if (type == "event" || type == "event.default") { 0177 return i18nc("type of folder content", "Calendar"); 0178 } 0179 if (type == "contact" || type == "contact.default") { 0180 return i18nc("type of folder content", "Contacts"); 0181 } 0182 if (type == "note" || type == "note.default") { 0183 return i18nc("type of folder content", "Notes"); 0184 } 0185 if (type == "journal" || type == "journal.default") { 0186 return i18nc("type of folder content", "Journal"); 0187 } 0188 if (type == "configuration" || type == "configuration.default") { 0189 return i18nc("type of folder content", "Configuration"); 0190 } 0191 if (type == "freebusy" || type == "freebusy.default") { 0192 return i18nc("type of folder content", "Freebusy"); 0193 } 0194 if (type == "file" || type == "file.default") { 0195 return i18nc("type of folder content", "Files"); 0196 } 0197 0198 return i18nc("type of folder content", "Mail"); 0199 } 0200 0201 QString CollectionTypeUtil::iconNameFromContentsType(CollectionTypeUtil::FolderContentsType type) 0202 { 0203 QString iconName; 0204 switch (type) { 0205 case CollectionTypeUtil::ContentsTypeCalendar: 0206 iconName = QStringLiteral("view-calendar"); 0207 break; 0208 case CollectionTypeUtil::ContentsTypeContact: 0209 iconName = QStringLiteral("view-pim-contacts"); 0210 break; 0211 case CollectionTypeUtil::ContentsTypeNote: 0212 iconName = QStringLiteral("view-pim-notes"); 0213 break; 0214 case CollectionTypeUtil::ContentsTypeTask: 0215 iconName = QStringLiteral("view-pim-tasks"); 0216 break; 0217 case CollectionTypeUtil::ContentsTypeJournal: 0218 iconName = QStringLiteral("view-pim-journal"); 0219 break; 0220 case CollectionTypeUtil::ContentsTypeConfiguration: 0221 iconName = QStringLiteral("configure"); 0222 break; 0223 case CollectionTypeUtil::ContentsTypeFreebusy: 0224 iconName = QStringLiteral("view-calendar-agenda"); 0225 break; 0226 case CollectionTypeUtil::ContentsTypeFile: 0227 iconName = QStringLiteral("document-open"); 0228 break; 0229 case CollectionTypeUtil::ContentsTypeMail: 0230 default: 0231 break; 0232 } 0233 0234 return iconName; 0235 }