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

KCalUtils Library

stringify.cpp
Go to the documentation of this file.
00001 /*
00002   This file is part of the kcalutils library.
00003 
00004   Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00005   Copyright (c) 2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00006   Copyright (c) 2005 Rafal Rzepecki <divide@users.sourceforge.net>
00007   Copyright (c) 2009-2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
00008 
00009   This library is free software; you can redistribute it and/or
00010   modify it under the terms of the GNU Library General Public
00011   License as published by the Free Software Foundation; either
00012   version 2 of the License, or (at your option) any later version.
00013 
00014   This library is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017   Library General Public License for more details.
00018 
00019   You should have received a copy of the GNU Library General Public License
00020   along with this library; see the file COPYING.LIB.  If not, write to
00021   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00022   Boston, MA 02110-1301, USA.
00023 */
00036 #include "stringify.h"
00037 
00038 #include <kcalcore/exceptions.h>
00039 using namespace KCalCore;
00040 
00041 #include <KLocale>
00042 #include <KGlobal>
00043 #include <KSystemTimeZone>
00044 
00045 using namespace KCalUtils;
00046 using namespace Stringify;
00047 
00048 QString Stringify::incidenceType( Incidence::IncidenceType type )
00049 {
00050   switch( type ) {
00051   case Incidence::TypeEvent:
00052     return i18nc( "@item incidence type is event", "event" );
00053   case Incidence::TypeTodo:
00054     return i18nc( "@item incidence type is to-do/task", "to-do" );
00055   case Incidence::TypeJournal:
00056     return i18nc( "@item incidence type is journal", "journal" );
00057   case Incidence::TypeFreeBusy:
00058     return i18nc( "@item incidence type is freebusy", "free/busy" );
00059   default:
00060     return QString();
00061   }
00062 }
00063 
00064 QString Stringify::todoCompletedDateTime( const Todo::Ptr &todo,
00065                                           bool shortfmt )
00066 {
00067   return KGlobal::locale()->formatDateTime( todo->completed().dateTime(),
00068                                             ( shortfmt ? KLocale::ShortDate :
00069                                                          KLocale::LongDate ) );
00070 }
00071 
00072 QString Stringify::incidenceSecrecy( Incidence::Secrecy secrecy )
00073 {
00074   switch ( secrecy ) {
00075   case Incidence::SecrecyPublic:
00076     return i18nc( "@item incidence access if for everyone", "Public" );
00077   case Incidence::SecrecyPrivate:
00078     return i18nc( "@item incidence access is by owner only", "Private" );
00079   case Incidence::SecrecyConfidential:
00080     return i18nc( "@item incidence access is by owner and a controlled group", "Confidential" );
00081   default: // to make compiler happy
00082     return QString();
00083   }
00084 }
00085 
00086 QStringList Stringify::incidenceSecrecyList()
00087 {
00088   QStringList list;
00089   list << incidenceSecrecy( Incidence::SecrecyPublic );
00090   list << incidenceSecrecy( Incidence::SecrecyPrivate );
00091   list << incidenceSecrecy( Incidence::SecrecyConfidential );
00092 
00093   return list;
00094 }
00095 
00096 QString Stringify::incidenceStatus( Incidence::Status status )
00097 {
00098   switch ( status ) {
00099   case Incidence::StatusTentative:
00100     return i18nc( "@item event is tentative", "Tentative" );
00101   case Incidence::StatusConfirmed:
00102     return i18nc( "@item event is definite", "Confirmed" );
00103   case Incidence::StatusCompleted:
00104     return i18nc( "@item to-do is complete", "Completed" );
00105   case Incidence::StatusNeedsAction:
00106     return i18nc( "@item to-do needs action", "Needs-Action" );
00107   case Incidence::StatusCanceled:
00108     return i18nc( "@item event orto-do is canceled; journal is removed", "Canceled" );
00109   case Incidence::StatusInProcess:
00110     return i18nc( "@item to-do is in process", "In-Process" );
00111   case Incidence::StatusDraft:
00112     return i18nc( "@item journal is in draft form", "Draft" );
00113   case Incidence::StatusFinal:
00114     return i18nc( "@item journal is in final form", "Final" );
00115   case Incidence::StatusX:
00116   case Incidence::StatusNone:
00117   default:
00118     return QString();
00119   }
00120 }
00121 
00122 QString Stringify::incidenceStatus( const Incidence::Ptr &incidence )
00123 {
00124   if ( incidence->status() == Incidence::StatusX ) {
00125     return incidence->customStatus();
00126   } else {
00127     return incidenceStatus( incidence->status() );
00128   }
00129 }
00130 
00131 QString Stringify::attendeeRole( Attendee::Role role )
00132 {
00133   switch ( role ) {
00134   case Attendee::Chair:
00135     return i18nc( "@item chairperson", "Chair" );
00136     break;
00137   default:
00138   case Attendee::ReqParticipant:
00139     return i18nc( "@item participation is required", "Participant" );
00140     break;
00141   case Attendee::OptParticipant:
00142     return i18nc( "@item participation is optional", "Optional Participant" );
00143     break;
00144   case Attendee::NonParticipant:
00145     return i18nc( "@item non-participant copied for information", "Observer" );
00146     break;
00147   }
00148 }
00149 
00150 QStringList Stringify::attendeeRoleList()
00151 {
00152   QStringList list;
00153   list << attendeeRole( Attendee::ReqParticipant );
00154   list << attendeeRole( Attendee::OptParticipant );
00155   list << attendeeRole( Attendee::NonParticipant );
00156   list << attendeeRole( Attendee::Chair );
00157 
00158   return list;
00159 }
00160 
00161 QString Stringify::attendeeStatus( Attendee::PartStat status )
00162 {
00163   switch ( status ) {
00164   default:
00165   case Attendee::NeedsAction:
00166     return i18nc( "@item event, to-do or journal needs action", "Needs Action" );
00167     break;
00168   case Attendee::Accepted:
00169     return i18nc( "@item event, to-do or journal accepted", "Accepted" );
00170     break;
00171   case Attendee::Declined:
00172     return i18nc( "@item event, to-do or journal declined", "Declined" );
00173     break;
00174   case Attendee::Tentative:
00175     return i18nc( "@item event or to-do tentatively accepted", "Tentative" );
00176     break;
00177   case Attendee::Delegated:
00178     return i18nc( "@item event or to-do delegated", "Delegated" );
00179     break;
00180   case Attendee::Completed:
00181     return i18nc( "@item to-do completed", "Completed" );
00182     break;
00183   case Attendee::InProcess:
00184     return i18nc( "@item to-do in process of being completed", "In Process" );
00185     break;
00186   case Attendee::None:
00187     return i18nc( "@item event or to-do status unknown", "Unknown" );
00188     break;
00189   }
00190 }
00191 
00192 QStringList Stringify::attendeeStatusList()
00193 {
00194   QStringList list;
00195   list << attendeeStatus( Attendee::NeedsAction );
00196   list << attendeeStatus( Attendee::Accepted );
00197   list << attendeeStatus( Attendee::Declined );
00198   list << attendeeStatus( Attendee::Tentative );
00199   list << attendeeStatus( Attendee::Delegated );
00200   list << attendeeStatus( Attendee::Completed );
00201   list << attendeeStatus( Attendee::InProcess );
00202 
00203   return list;
00204 }
00205 
00206 QString Stringify::formatTime( const KDateTime &dt, bool shortfmt, const KDateTime::Spec &spec )
00207 {
00208   if ( spec.isValid() ) {
00209 
00210     QString timeZone;
00211     if ( spec.timeZone() != KSystemTimeZones::local() ) {
00212       timeZone = ' ' + spec.timeZone().name();
00213     }
00214 
00215     return KGlobal::locale()->formatTime( dt.toTimeSpec( spec ).time(), !shortfmt ) + timeZone;
00216   } else {
00217     return KGlobal::locale()->formatTime( dt.time(), !shortfmt );
00218   }
00219 }
00220 
00221 QString Stringify::formatDate( const KDateTime &dt, bool shortfmt, const KDateTime::Spec &spec )
00222 {
00223   if ( spec.isValid() ) {
00224 
00225     QString timeZone;
00226     if ( spec.timeZone() != KSystemTimeZones::local() ) {
00227       timeZone = ' ' + spec.timeZone().name();
00228     }
00229 
00230     return
00231       KGlobal::locale()->formatDate( dt.toTimeSpec( spec ).date(),
00232                                      ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) ) +
00233       timeZone;
00234   } else {
00235     return
00236       KGlobal::locale()->formatDate( dt.date(),
00237                                      ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) );
00238   }
00239 }
00240 
00241 QString Stringify::formatDateTime( const KDateTime &dt, bool allDay,
00242                                    bool shortfmt, const KDateTime::Spec &spec )
00243 {
00244   if ( allDay ) {
00245     return formatDate( dt, shortfmt, spec );
00246   }
00247 
00248   if ( spec.isValid() ) {
00249     QString timeZone;
00250     if ( spec.timeZone() != KSystemTimeZones::local() ) {
00251       timeZone = ' ' + spec.timeZone().name();
00252     }
00253 
00254     return KGlobal::locale()->formatDateTime(
00255       dt.toTimeSpec( spec ).dateTime(),
00256       ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) ) + timeZone;
00257   } else {
00258     return  KGlobal::locale()->formatDateTime(
00259       dt.dateTime(),
00260       ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) );
00261   }
00262 }
00263 
00264 QString Stringify::errorMessage( const Exception &exception )
00265 {
00266   QString message = "";
00267 
00268   switch ( exception.code() ) {
00269   case Exception::LoadError:
00270     message = i18nc( "@item", "Load Error" );
00271     break;
00272   case Exception::SaveError:
00273     message = i18nc( "@item", "Save Error" );
00274     break;
00275   case Exception::ParseErrorIcal:
00276     message = i18nc( "@item", "Parse Error in libical" );
00277     break;
00278   case Exception::ParseErrorKcal:
00279     message = i18nc( "@item", "Parse Error in the kcalcore library" );
00280     break;
00281   case Exception::NoCalendar:
00282     message = i18nc( "@item", "No calendar component found." );
00283     break;
00284   case Exception::CalVersion1:
00285     message = i18nc( "@item", "Expected iCalendar, got vCalendar format" );
00286     break;
00287   case Exception::CalVersion2:
00288     message = i18nc( "@item", "iCalendar Version 2.0 detected." );
00289     break;
00290   case Exception::CalVersionUnknown:
00291     message = i18nc( "@item", "Expected iCalendar, got unknown format" );
00292     break;
00293   case Exception::Restriction:
00294     message = i18nc( "@item", "Restriction violation" );
00295     break;
00296   case Exception::NoWritableFound:
00297     message = i18nc( "@item", "No writable resource found" );
00298     break;
00299   case Exception::SaveErrorOpenFile:
00300     Q_ASSERT( exception.arguments().count() == 1 );
00301     message = i18nc( "@item", "Error saving to '%1'.", exception.arguments()[0] );
00302     break;
00303   case Exception::SaveErrorSaveFile:
00304     Q_ASSERT( exception.arguments().count() == 1 );
00305     message = i18nc( "@item", "Could not save '%1'", exception.arguments()[0] );
00306     break;
00307   case Exception::LibICalError:
00308     message = i18nc( "@item", "libical error" );
00309     break;
00310   case Exception::VersionPropertyMissing:
00311     message = i18nc( "@item", "No VERSION property found" );
00312     break;
00313   case Exception::ExpectedCalVersion2:
00314     message = i18nc( "@item", "Expected iCalendar, got vCalendar format" );
00315     break;
00316   case Exception::ExpectedCalVersion2Unknown:
00317     message = i18nc( "@item", "Expected iCalendar, got unknown format" );
00318     break;
00319   case Exception::ParseErrorNotIncidence:
00320     message = i18nc( "@item", "object is not a freebusy, event, todo or journal" );
00321     break;
00322   case Exception::ParseErrorEmptyMessage:
00323     message = i18nc( "@item", "messageText is empty, unable to parse into a ScheduleMessage" );
00324     break;
00325   case Exception::ParseErrorUnableToParse:
00326     message = i18nc( "@item", "icalparser is unable to parse messageText into a ScheduleMessage" );
00327     break;
00328   case Exception::ParseErrorMethodProperty:
00329     message = i18nc( "@item", "message does not contain ICAL_METHOD_PROPERTY" );
00330     break;
00331   case Exception::UserCancel:
00332     // no real error; the user canceled the operation
00333     break;
00334 
00335   }
00336 
00337   return message;
00338 }
00339 
00340 QString Stringify::scheduleMessageStatus( ScheduleMessage::Status status )
00341 {
00342   switch( status ) {
00343   case ScheduleMessage::PublishNew:
00344     return i18nc( "@item this is a new scheduling message",
00345                   "New Scheduling Message" );
00346   case ScheduleMessage::PublishUpdate:
00347     return i18nc( "@item this is an update to an existing scheduling message",
00348                   "Updated Scheduling Message" );
00349   case ScheduleMessage::Obsolete:
00350     return i18nc( "@item obsolete status", "Obsolete" );
00351   case ScheduleMessage::RequestNew:
00352     return i18nc( "@item this is a request for a new scheduling message",
00353                   "New Scheduling Message Request" );
00354   case ScheduleMessage::RequestUpdate:
00355     return i18nc( "@item this is a request for an update to an existing scheduling message",
00356                   "Updated Scheduling Message Request" );
00357   default:
00358     return i18nc( "@item unknown status", "Unknown Status: %1", int( status ) );
00359   }
00360 }
00361 
00362 QString Stringify::secrecyName( Incidence::Secrecy secrecy )
00363 {
00364   switch ( secrecy ) {
00365   case Incidence::SecrecyPublic:
00366     return i18nc( "@item incidence access if for everyone", "Public" );
00367   case Incidence::SecrecyPrivate:
00368     return i18nc( "@item incidence access is by owner only", "Private" );
00369   case Incidence::SecrecyConfidential:
00370     return i18nc( "@item incidence access is by owner and a controlled group", "Confidential" );
00371   default:
00372     return QString();  // to make compilers happy
00373   }
00374 }
00375 
00376 QStringList Stringify::secrecyList()
00377 {
00378   QStringList list;
00379   list << secrecyName( Incidence::SecrecyPublic );
00380   list << secrecyName( Incidence::SecrecyPrivate );
00381   list << secrecyName( Incidence::SecrecyConfidential );
00382 
00383   return list;
00384 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Aug 27 2012 22:09:00 by doxygen 1.7.5 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.8.5 API Reference

Skip menu "kdepimlibs-4.8.5 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • 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