• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.10.5 API Reference
  • KDE Home
  • Contact Us
 

KCalUtils Library

  • kcalutils
stringify.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the kcalutils library.
3 
4  Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5  Copyright (c) 2004 Reinhold Kainhofer <reinhold@kainhofer.com>
6  Copyright (c) 2005 Rafal Rzepecki <divide@users.sourceforge.net>
7  Copyright (c) 2009-2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Library General Public
11  License as published by the Free Software Foundation; either
12  version 2 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Library General Public License for more details.
18 
19  You should have received a copy of the GNU Library General Public License
20  along with this library; see the file COPYING.LIB. If not, write to
21  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22  Boston, MA 02110-1301, USA.
23 */
36 #include "stringify.h"
37 
38 #include <kcalcore/exceptions.h>
39 using namespace KCalCore;
40 
41 #include <KLocale>
42 #include <KGlobal>
43 #include <KSystemTimeZone>
44 
45 using namespace KCalUtils;
46 using namespace Stringify;
47 
48 QString Stringify::incidenceType( Incidence::IncidenceType type )
49 {
50  switch( type ) {
51  case Incidence::TypeEvent:
52  return i18nc( "@item incidence type is event", "event" );
53  case Incidence::TypeTodo:
54  return i18nc( "@item incidence type is to-do/task", "to-do" );
55  case Incidence::TypeJournal:
56  return i18nc( "@item incidence type is journal", "journal" );
57  case Incidence::TypeFreeBusy:
58  return i18nc( "@item incidence type is freebusy", "free/busy" );
59  default:
60  return QString();
61  }
62 }
63 
64 QString Stringify::todoCompletedDateTime( const Todo::Ptr &todo,
65  bool shortfmt )
66 {
67  return KGlobal::locale()->formatDateTime( todo->completed().dateTime(),
68  ( shortfmt ? KLocale::ShortDate :
69  KLocale::LongDate ) );
70 }
71 
72 QString Stringify::incidenceSecrecy( Incidence::Secrecy secrecy )
73 {
74  switch ( secrecy ) {
75  case Incidence::SecrecyPublic:
76  return i18nc( "@item incidence access if for everyone", "Public" );
77  case Incidence::SecrecyPrivate:
78  return i18nc( "@item incidence access is by owner only", "Private" );
79  case Incidence::SecrecyConfidential:
80  return i18nc( "@item incidence access is by owner and a controlled group", "Confidential" );
81  default: // to make compiler happy
82  return QString();
83  }
84 }
85 
86 QStringList Stringify::incidenceSecrecyList()
87 {
88  QStringList list;
89  list << incidenceSecrecy( Incidence::SecrecyPublic );
90  list << incidenceSecrecy( Incidence::SecrecyPrivate );
91  list << incidenceSecrecy( Incidence::SecrecyConfidential );
92 
93  return list;
94 }
95 
96 QString Stringify::incidenceStatus( Incidence::Status status )
97 {
98  switch ( status ) {
99  case Incidence::StatusTentative:
100  return i18nc( "@item event is tentative", "Tentative" );
101  case Incidence::StatusConfirmed:
102  return i18nc( "@item event is definite", "Confirmed" );
103  case Incidence::StatusCompleted:
104  return i18nc( "@item to-do is complete", "Completed" );
105  case Incidence::StatusNeedsAction:
106  return i18nc( "@item to-do needs action", "Needs-Action" );
107  case Incidence::StatusCanceled:
108  return i18nc( "@item event orto-do is canceled; journal is removed", "Canceled" );
109  case Incidence::StatusInProcess:
110  return i18nc( "@item to-do is in process", "In-Process" );
111  case Incidence::StatusDraft:
112  return i18nc( "@item journal is in draft form", "Draft" );
113  case Incidence::StatusFinal:
114  return i18nc( "@item journal is in final form", "Final" );
115  case Incidence::StatusX:
116  case Incidence::StatusNone:
117  default:
118  return QString();
119  }
120 }
121 
122 QString Stringify::incidenceStatus( const Incidence::Ptr &incidence )
123 {
124  if ( incidence->status() == Incidence::StatusX ) {
125  return incidence->customStatus();
126  } else {
127  return incidenceStatus( incidence->status() );
128  }
129 }
130 
131 QString Stringify::attendeeRole( Attendee::Role role )
132 {
133  switch ( role ) {
134  case Attendee::Chair:
135  return i18nc( "@item chairperson", "Chair" );
136  break;
137  default:
138  case Attendee::ReqParticipant:
139  return i18nc( "@item participation is required", "Participant" );
140  break;
141  case Attendee::OptParticipant:
142  return i18nc( "@item participation is optional", "Optional Participant" );
143  break;
144  case Attendee::NonParticipant:
145  return i18nc( "@item non-participant copied for information", "Observer" );
146  break;
147  }
148 }
149 
150 QStringList Stringify::attendeeRoleList()
151 {
152  QStringList list;
153  list << attendeeRole( Attendee::ReqParticipant );
154  list << attendeeRole( Attendee::OptParticipant );
155  list << attendeeRole( Attendee::NonParticipant );
156  list << attendeeRole( Attendee::Chair );
157 
158  return list;
159 }
160 
161 QString Stringify::attendeeStatus( Attendee::PartStat status )
162 {
163  switch ( status ) {
164  default:
165  case Attendee::NeedsAction:
166  return i18nc( "@item event, to-do or journal needs action", "Needs Action" );
167  break;
168  case Attendee::Accepted:
169  return i18nc( "@item event, to-do or journal accepted", "Accepted" );
170  break;
171  case Attendee::Declined:
172  return i18nc( "@item event, to-do or journal declined", "Declined" );
173  break;
174  case Attendee::Tentative:
175  return i18nc( "@item event or to-do tentatively accepted", "Tentative" );
176  break;
177  case Attendee::Delegated:
178  return i18nc( "@item event or to-do delegated", "Delegated" );
179  break;
180  case Attendee::Completed:
181  return i18nc( "@item to-do completed", "Completed" );
182  break;
183  case Attendee::InProcess:
184  return i18nc( "@item to-do in process of being completed", "In Process" );
185  break;
186  case Attendee::None:
187  return i18nc( "@item event or to-do status unknown", "Unknown" );
188  break;
189  }
190 }
191 
192 QStringList Stringify::attendeeStatusList()
193 {
194  QStringList list;
195  list << attendeeStatus( Attendee::NeedsAction );
196  list << attendeeStatus( Attendee::Accepted );
197  list << attendeeStatus( Attendee::Declined );
198  list << attendeeStatus( Attendee::Tentative );
199  list << attendeeStatus( Attendee::Delegated );
200  list << attendeeStatus( Attendee::Completed );
201  list << attendeeStatus( Attendee::InProcess );
202 
203  return list;
204 }
205 
206 QString Stringify::formatTime( const KDateTime &dt, bool shortfmt, const KDateTime::Spec &spec )
207 {
208  if ( spec.isValid() ) {
209 
210  QString timeZone;
211  if ( spec.timeZone() != KSystemTimeZones::local() ) {
212  timeZone = ' ' + spec.timeZone().name();
213  }
214 
215  return KGlobal::locale()->formatTime( dt.toTimeSpec( spec ).time(), !shortfmt ) + timeZone;
216  } else {
217  return KGlobal::locale()->formatTime( dt.time(), !shortfmt );
218  }
219 }
220 
221 QString Stringify::formatDate( const KDateTime &dt, bool shortfmt, const KDateTime::Spec &spec )
222 {
223  if ( spec.isValid() ) {
224 
225  QString timeZone;
226  if ( spec.timeZone() != KSystemTimeZones::local() ) {
227  timeZone = ' ' + spec.timeZone().name();
228  }
229 
230  return
231  KGlobal::locale()->formatDate( dt.toTimeSpec( spec ).date(),
232  ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) ) +
233  timeZone;
234  } else {
235  return
236  KGlobal::locale()->formatDate( dt.date(),
237  ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) );
238  }
239 }
240 
241 QString Stringify::formatDateTime( const KDateTime &dt, bool allDay,
242  bool shortfmt, const KDateTime::Spec &spec )
243 {
244  if ( allDay ) {
245  return formatDate( dt, shortfmt, spec );
246  }
247 
248  if ( spec.isValid() ) {
249  QString timeZone;
250  if ( spec.timeZone() != KSystemTimeZones::local() ) {
251  timeZone = ' ' + spec.timeZone().name();
252  }
253 
254  return KGlobal::locale()->formatDateTime(
255  dt.toTimeSpec( spec ).dateTime(),
256  ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) ) + timeZone;
257  } else {
258  return KGlobal::locale()->formatDateTime(
259  dt.dateTime(),
260  ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) );
261  }
262 }
263 
264 QString Stringify::errorMessage( const Exception &exception )
265 {
266  QString message = "";
267 
268  switch ( exception.code() ) {
269  case Exception::LoadError:
270  message = i18nc( "@item", "Load Error" );
271  break;
272  case Exception::SaveError:
273  message = i18nc( "@item", "Save Error" );
274  break;
275  case Exception::ParseErrorIcal:
276  message = i18nc( "@item", "Parse Error in libical" );
277  break;
278  case Exception::ParseErrorKcal:
279  message = i18nc( "@item", "Parse Error in the kcalcore library" );
280  break;
281  case Exception::NoCalendar:
282  message = i18nc( "@item", "No calendar component found." );
283  break;
284  case Exception::CalVersion1:
285  message = i18nc( "@item", "Expected iCalendar, got vCalendar format" );
286  break;
287  case Exception::CalVersion2:
288  message = i18nc( "@item", "iCalendar Version 2.0 detected." );
289  break;
290  case Exception::CalVersionUnknown:
291  message = i18nc( "@item", "Expected iCalendar, got unknown format" );
292  break;
293  case Exception::Restriction:
294  message = i18nc( "@item", "Restriction violation" );
295  break;
296  case Exception::NoWritableFound:
297  message = i18nc( "@item", "No writable resource found" );
298  break;
299  case Exception::SaveErrorOpenFile:
300  Q_ASSERT( exception.arguments().count() == 1 );
301  message = i18nc( "@item", "Error saving to '%1'.", exception.arguments()[0] );
302  break;
303  case Exception::SaveErrorSaveFile:
304  Q_ASSERT( exception.arguments().count() == 1 );
305  message = i18nc( "@item", "Could not save '%1'", exception.arguments()[0] );
306  break;
307  case Exception::LibICalError:
308  message = i18nc( "@item", "libical error" );
309  break;
310  case Exception::VersionPropertyMissing:
311  message = i18nc( "@item", "No VERSION property found" );
312  break;
313  case Exception::ExpectedCalVersion2:
314  message = i18nc( "@item", "Expected iCalendar, got vCalendar format" );
315  break;
316  case Exception::ExpectedCalVersion2Unknown:
317  message = i18nc( "@item", "Expected iCalendar, got unknown format" );
318  break;
319  case Exception::ParseErrorNotIncidence:
320  message = i18nc( "@item", "object is not a freebusy, event, todo or journal" );
321  break;
322  case Exception::ParseErrorEmptyMessage:
323  message = i18nc( "@item", "messageText is empty, unable to parse into a ScheduleMessage" );
324  break;
325  case Exception::ParseErrorUnableToParse:
326  message = i18nc( "@item", "icalparser is unable to parse messageText into a ScheduleMessage" );
327  break;
328  case Exception::ParseErrorMethodProperty:
329  message = i18nc( "@item", "message does not contain ICAL_METHOD_PROPERTY" );
330  break;
331  case Exception::UserCancel:
332  // no real error; the user canceled the operation
333  break;
334 
335  }
336 
337  return message;
338 }
339 
340 QString Stringify::scheduleMessageStatus( ScheduleMessage::Status status )
341 {
342  switch( status ) {
343  case ScheduleMessage::PublishNew:
344  return i18nc( "@item this is a new scheduling message",
345  "New Scheduling Message" );
346  case ScheduleMessage::PublishUpdate:
347  return i18nc( "@item this is an update to an existing scheduling message",
348  "Updated Scheduling Message" );
349  case ScheduleMessage::Obsolete:
350  return i18nc( "@item obsolete status", "Obsolete" );
351  case ScheduleMessage::RequestNew:
352  return i18nc( "@item this is a request for a new scheduling message",
353  "New Scheduling Message Request" );
354  case ScheduleMessage::RequestUpdate:
355  return i18nc( "@item this is a request for an update to an existing scheduling message",
356  "Updated Scheduling Message Request" );
357  default:
358  return i18nc( "@item unknown status", "Unknown Status: %1", int( status ) );
359  }
360 }
361 
362 QString Stringify::secrecyName( Incidence::Secrecy secrecy )
363 {
364  switch ( secrecy ) {
365  case Incidence::SecrecyPublic:
366  return i18nc( "@item incidence access if for everyone", "Public" );
367  case Incidence::SecrecyPrivate:
368  return i18nc( "@item incidence access is by owner only", "Private" );
369  case Incidence::SecrecyConfidential:
370  return i18nc( "@item incidence access is by owner and a controlled group", "Confidential" );
371  default:
372  return QString(); // to make compilers happy
373  }
374 }
375 
376 QStringList Stringify::secrecyList()
377 {
378  QStringList list;
379  list << secrecyName( Incidence::SecrecyPublic );
380  list << secrecyName( Incidence::SecrecyPrivate );
381  list << secrecyName( Incidence::SecrecyConfidential );
382 
383  return list;
384 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:26:46 by doxygen 1.8.3.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KCalUtils Library

Skip menu "KCalUtils Library"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Members
  • File List
  • Related Pages

kdepimlibs-4.10.5 API Reference

Skip menu "kdepimlibs-4.10.5 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal