Pimcommon

collectiontypeutil.cpp
1/*
2 SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5
6*/
7
8#include "collectiontypeutil.h"
9using namespace Qt::Literals::StringLiterals;
10
11#include <KLocalizedString>
12
13using namespace PimCommon;
14CollectionTypeUtil::CollectionTypeUtil() = default;
15
16CollectionTypeUtil::~CollectionTypeUtil() = default;
17
18QByteArray CollectionTypeUtil::kolabFolderType()
19{
20 return "/shared/vendor/kolab/folder-type";
21}
22
23QByteArray CollectionTypeUtil::kolabIncidencesFor()
24{
25 return "/shared/vendor/kolab/incidences-for";
26}
27
28QByteArray CollectionTypeUtil::kolabSharedSeen()
29{
30 return "/shared/vendor/cmu/cyrus-imapd/sharedseen";
31}
32
33QString CollectionTypeUtil::folderContentDescription(CollectionTypeUtil::FolderContentsType type)
34{
35 switch (type) {
36 case CollectionTypeUtil::ContentsTypeMail:
37 return i18nc("type of folder content", "Mail");
38 case CollectionTypeUtil::ContentsTypeCalendar:
39 return i18nc("type of folder content", "Calendar");
40 case CollectionTypeUtil::ContentsTypeContact:
41 return i18nc("type of folder content", "Contacts");
42 case CollectionTypeUtil::ContentsTypeNote:
43 return i18nc("type of folder content", "Notes");
44 case CollectionTypeUtil::ContentsTypeTask:
45 return i18nc("type of folder content", "Tasks");
46 case CollectionTypeUtil::ContentsTypeJournal:
47 return i18nc("type of folder content", "Journal");
48 case CollectionTypeUtil::ContentsTypeConfiguration:
49 return i18nc("type of folder content", "Configuration");
50 case CollectionTypeUtil::ContentsTypeFreebusy:
51 return i18nc("type of folder content", "Freebusy");
52 case CollectionTypeUtil::ContentsTypeFile:
53 return i18nc("type of folder content", "Files");
54 default:
55 return i18nc("type of folder content", "Unknown");
56 }
57}
58
59QString CollectionTypeUtil::incidencesForToString(CollectionTypeUtil::IncidencesFor type)
60{
61 switch (type) {
62 case CollectionTypeUtil::IncForNobody:
63 return QStringLiteral("nobody");
64 case CollectionTypeUtil::IncForAdmins:
65 return QStringLiteral("admins");
66 case CollectionTypeUtil::IncForReaders:
67 return QStringLiteral("readers");
68 }
69
70 return {}; // can't happen
71}
72
73CollectionTypeUtil::IncidencesFor CollectionTypeUtil::incidencesForFromString(const QString &string)
74{
75 if (string == "nobody"_L1) {
76 return CollectionTypeUtil::IncForNobody;
77 } else if (string == "admins"_L1) {
78 return CollectionTypeUtil::IncForAdmins;
79 } else if (string == "readers"_L1) {
80 return CollectionTypeUtil::IncForReaders;
81 }
82
83 return CollectionTypeUtil::IncForAdmins; // by default
84}
85
86CollectionTypeUtil::FolderContentsType CollectionTypeUtil::typeFromKolabName(const QByteArray &name)
87{
88 if (name == "task" || name == "task.default") {
89 return CollectionTypeUtil::ContentsTypeTask;
90 }
91 if (name == "event" || name == "event.default") {
92 return CollectionTypeUtil::ContentsTypeCalendar;
93 }
94 if (name == "contact" || name == "contact.default") {
95 return CollectionTypeUtil::ContentsTypeContact;
96 }
97 if (name == "note" || name == "note.default") {
98 return CollectionTypeUtil::ContentsTypeNote;
99 }
100 if (name == "journal" || name == "journal.default") {
101 return CollectionTypeUtil::ContentsTypeJournal;
102 }
103 if (name == "configuration" || name == "configuration.default") {
104 return CollectionTypeUtil::ContentsTypeConfiguration;
105 }
106 if (name == "freebusy" || name == "freebusy.default") {
107 return CollectionTypeUtil::ContentsTypeFreebusy;
108 }
109 if (name == "file" || name == "file.default") {
110 return CollectionTypeUtil::ContentsTypeFile;
111 }
112
113 return CollectionTypeUtil::ContentsTypeMail;
114}
115
116QByteArray CollectionTypeUtil::kolabNameFromType(CollectionTypeUtil::FolderContentsType type)
117{
118 switch (type) {
119 case CollectionTypeUtil::ContentsTypeCalendar:
120 return "event";
121 case CollectionTypeUtil::ContentsTypeContact:
122 return "contact";
123 case CollectionTypeUtil::ContentsTypeNote:
124 return "note";
125 case CollectionTypeUtil::ContentsTypeTask:
126 return "task";
127 case CollectionTypeUtil::ContentsTypeJournal:
128 return "journal";
129 case CollectionTypeUtil::ContentsTypeConfiguration:
130 return "configuration";
131 case CollectionTypeUtil::ContentsTypeFreebusy:
132 return "freebusy";
133 case CollectionTypeUtil::ContentsTypeFile:
134 return "file";
135 default:
136 return {};
137 }
138}
139
140CollectionTypeUtil::FolderContentsType CollectionTypeUtil::contentsTypeFromString(const QString &type)
141{
142 if (type == i18nc("type of folder content", "Mail")) {
143 return CollectionTypeUtil::ContentsTypeMail;
144 }
145 if (type == i18nc("type of folder content", "Calendar")) {
146 return CollectionTypeUtil::ContentsTypeCalendar;
147 }
148 if (type == i18nc("type of folder content", "Contacts")) {
149 return CollectionTypeUtil::ContentsTypeContact;
150 }
151 if (type == i18nc("type of folder content", "Notes")) {
152 return CollectionTypeUtil::ContentsTypeNote;
153 }
154 if (type == i18nc("type of folder content", "Tasks")) {
155 return CollectionTypeUtil::ContentsTypeTask;
156 }
157 if (type == i18nc("type of folder content", "Journal")) {
158 return CollectionTypeUtil::ContentsTypeJournal;
159 }
160 if (type == i18nc("type of folder content", "Configuration")) {
161 return CollectionTypeUtil::ContentsTypeConfiguration;
162 }
163 if (type == i18nc("type of folder content", "Freebusy")) {
164 return CollectionTypeUtil::ContentsTypeFreebusy;
165 }
166 if (type == i18nc("type of folder content", "Files")) {
167 return CollectionTypeUtil::ContentsTypeFile;
168 }
169
170 return CollectionTypeUtil::ContentsTypeMail; // safety return value
171}
172
173QString CollectionTypeUtil::typeNameFromKolabType(const QByteArray &type)
174{
175 if (type == "task" || type == "task.default") {
176 return i18nc("type of folder content", "Tasks");
177 }
178 if (type == "event" || type == "event.default") {
179 return i18nc("type of folder content", "Calendar");
180 }
181 if (type == "contact" || type == "contact.default") {
182 return i18nc("type of folder content", "Contacts");
183 }
184 if (type == "note" || type == "note.default") {
185 return i18nc("type of folder content", "Notes");
186 }
187 if (type == "journal" || type == "journal.default") {
188 return i18nc("type of folder content", "Journal");
189 }
190 if (type == "configuration" || type == "configuration.default") {
191 return i18nc("type of folder content", "Configuration");
192 }
193 if (type == "freebusy" || type == "freebusy.default") {
194 return i18nc("type of folder content", "Freebusy");
195 }
196 if (type == "file" || type == "file.default") {
197 return i18nc("type of folder content", "Files");
198 }
199
200 return i18nc("type of folder content", "Mail");
201}
202
203QString CollectionTypeUtil::iconNameFromContentsType(CollectionTypeUtil::FolderContentsType type)
204{
205 QString iconName;
206 switch (type) {
207 case CollectionTypeUtil::ContentsTypeCalendar:
208 iconName = QStringLiteral("view-calendar");
209 break;
210 case CollectionTypeUtil::ContentsTypeContact:
211 iconName = QStringLiteral("view-pim-contacts");
212 break;
213 case CollectionTypeUtil::ContentsTypeNote:
214 iconName = QStringLiteral("view-pim-notes");
215 break;
216 case CollectionTypeUtil::ContentsTypeTask:
217 iconName = QStringLiteral("view-pim-tasks");
218 break;
219 case CollectionTypeUtil::ContentsTypeJournal:
220 iconName = QStringLiteral("view-pim-journal");
221 break;
222 case CollectionTypeUtil::ContentsTypeConfiguration:
223 iconName = QStringLiteral("configure");
224 break;
225 case CollectionTypeUtil::ContentsTypeFreebusy:
226 iconName = QStringLiteral("view-calendar-agenda");
227 break;
228 case CollectionTypeUtil::ContentsTypeFile:
229 iconName = QStringLiteral("document-open");
230 break;
231 case CollectionTypeUtil::ContentsTypeMail:
232 default:
233 break;
234 }
235
236 return iconName;
237}
QString i18nc(const char *context, const char *text, const TYPE &arg...)
folderdialogacltab.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:14:35 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.