konsolekalendar Library API Documentation

konsolekalendarexports.cpp

00001 /******************************************************************************* 00002 * konsolekalendarexports.cpp * 00003 * * 00004 * KonsoleKalendar is a command line interface to KDE calendars * 00005 * Copyright (C) 2002-2004 Tuukka Pasanen <illuusio@mailcity.com> * 00006 * Copyright (C) 2003-2004 Allen Winter <awinterz@users.sourceforge.net> * 00007 * * 00008 * This program is free software; you can redistribute it and/or modify * 00009 * it under the terms of the GNU General Public License as published by * 00010 * the Free Software Foundation; either version 2 of the License, or * 00011 * (at your option) any later version. * 00012 * * 00013 * This program is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00016 * GNU General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU General Public License * 00019 * along with this program; if not, write to the Free Software * 00020 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00021 * * 00022 * As a special exception, permission is given to link this program * 00023 * with any edition of Qt, and distribute the resulting executable, * 00024 * without including the source code for Qt in the source distribution. * 00025 * * 00026 ******************************************************************************/ 00027 00028 #include <stdlib.h> 00029 #include <iostream> 00030 00031 #include <qdatetime.h> 00032 00033 #include <kdebug.h> 00034 #include <klocale.h> 00035 00036 #include <libkcal/calendarlocal.h> 00037 #include <libkcal/calendar.h> 00038 #include <libkcal/event.h> 00039 00040 #include "konsolekalendarexports.h" 00041 00042 using namespace KCal; 00043 using namespace std; 00044 00045 KonsoleKalendarExports::KonsoleKalendarExports( KonsoleKalendarVariables 00046 *variables ) { 00047 m_variables = variables; 00048 m_firstEntry = true; 00049 } 00050 00051 00052 KonsoleKalendarExports::~KonsoleKalendarExports() { 00053 } 00054 00055 bool KonsoleKalendarExports::exportAsTxt( QTextStream *ts, 00056 Event *event, QDate date ) { 00057 00058 // Export "Text" Format: 00059 // 00060 // Date:\t<Incidence Date>(dddd yyyy-MM-dd) 00061 // [\t<Incidence Start Time>(hh:mm) - <Incidence End Time>(hh:mm)] 00062 // Summary: 00063 // \t<Incidence Summary | "(no summary available)"> 00064 // Location: 00065 // \t<Incidence Location | "(no location available)"> 00066 // Description: 00067 // \t<Incidence Description | "(no description available)"> 00068 // UID: 00069 // \t<Incidence UID> 00070 // -------------------------------------------------- 00071 00072 // Print Event Date (in user's prefered format) 00073 *ts << i18n( "Date:" ) 00074 << "\t" 00075 << KGlobal::locale()->formatDate( date ) 00076 << endl; 00077 00078 // Print Event Starttime - Endtime, for Non-Floating Events Only 00079 if ( !event->doesFloat() ) { 00080 *ts << "\t" 00081 << KGlobal::locale()->formatTime( event->dtStart().time() ) 00082 << " - " 00083 << KGlobal::locale()->formatTime( event->dtEnd().time() ); 00084 } 00085 *ts << endl; 00086 00087 // Print Event Summary 00088 *ts << i18n( "Summary:" ) 00089 << endl; 00090 if ( !event->summary().isEmpty() ) { 00091 *ts << "\t" 00092 << event->summary() 00093 << endl; 00094 } else { 00095 *ts << "\t" 00096 << i18n( "(no summary available)" ) 00097 << endl; 00098 } 00099 00100 // Print Event Location 00101 *ts << i18n( "Location:" ) 00102 << endl; 00103 if ( !event->location().isEmpty() ) { 00104 *ts << "\t" 00105 <<event->location() 00106 << endl; 00107 } else { 00108 *ts << "\t" 00109 << i18n( "(no location available)" ) 00110 << endl; 00111 } 00112 00113 // Print Event Description 00114 *ts << i18n( "Description:" ) 00115 << endl; 00116 if ( !event->description().isEmpty() ) { 00117 *ts << "\t" 00118 << event->description() 00119 << endl; 00120 } else { 00121 *ts << "\t" 00122 << i18n( "(no description available)" ) 00123 << endl; 00124 } 00125 00126 // Print Event UID 00127 *ts << i18n( "UID:" ) 00128 << endl 00129 << "\t" 00130 << event->uid() 00131 << endl; 00132 00133 // Print Line Separator 00134 *ts << "--------------------------------------------------" 00135 << endl; 00136 00137 return true; 00138 } 00139 00140 bool KonsoleKalendarExports::exportAsTxtShort( QTextStream *ts, 00141 Event *event, QDate date, 00142 bool sameday ) { 00143 00144 // Export "Text-Short" Format: 00145 // 00146 // [--------------------------------------------------] 00147 // {<Incidence Date>(dddd yyyy-MM-dd)] 00148 // [<Incidence Start Time>(hh:mm) - <Incidence End Time>(hh:mm) | "\t"] 00149 // \t<Incidence Summary | \t>[, <Incidence Location>] 00150 // \t\t<Incidence Description | "\t"> 00151 00152 if ( !sameday ) { 00153 // If a new date, then Print the Event Date (in user's prefered format) 00154 *ts << KGlobal::locale()->formatDate( date ) << ":" 00155 << endl; 00156 } 00157 00158 // Print Event Starttime - Endtime 00159 if ( !event->doesFloat() ) { 00160 *ts << KGlobal::locale()->formatTime( event->dtStart().time() ) 00161 << " - " 00162 << KGlobal::locale()->formatTime( event->dtEnd().time() ); 00163 } else { 00164 *ts << i18n( "[all day]\t" ); 00165 } 00166 *ts << "\t"; 00167 00168 // Print Event Summary 00169 *ts << event->summary().replace( QChar( '\n' ), QChar( ' ' ) ); 00170 00171 // Print Event Location 00172 if ( !event->location().isEmpty() ) { 00173 if ( !event->summary().isEmpty() ) { 00174 *ts << ", "; 00175 } 00176 *ts << event->location().replace( QChar( '\n' ), QChar( ' ' ) ); 00177 } 00178 *ts << endl; 00179 00180 // Print Event Description 00181 if ( !event->description().isEmpty() ) { 00182 *ts << "\t\t\t" 00183 << event->description().replace( QChar( '\n' ), QChar( ' ' ) ) 00184 << endl; 00185 } 00186 00187 // By user request, no longer print UIDs if export-type==short 00188 00189 return true; 00190 } 00191 00192 QString KonsoleKalendarExports::processField( QString field, QString dquote ) { 00193 00194 // little function that processes a field for CSV compliance: 00195 // 1. Replaces double quotes by a pair of consecutive double quotes 00196 // 2. Surrounds field with double quotes 00197 00198 QString double_dquote = dquote + dquote; 00199 QString retField = dquote + field.replace( dquote, double_dquote ) + dquote; 00200 return retField; 00201 } 00202 00203 #define pF( x ) processField( ( x ), dquote ) 00204 00205 bool KonsoleKalendarExports::exportAsCSV( QTextStream *ts, 00206 Event *event, QDate date ) { 00207 00208 // Export "CSV" Format: 00209 // 00210 // startdate,starttime,enddate,endtime,summary,location,description,UID 00211 00212 QString delim = i18n( "," ); // character to use as CSV field delimiter 00213 QString dquote = i18n( "\"" ); // character to use to quote CSV fields 00214 00215 if ( !event->doesFloat() ) { 00216 *ts << pF( KGlobal::locale()->formatDate( date ) ) 00217 << delim << pF( KGlobal::locale()->formatTime( event->dtStart().time() ) ) 00218 << delim << pF( KGlobal::locale()->formatDate( date ) ) 00219 << delim << pF( KGlobal::locale()->formatTime( event->dtEnd().time() ) ); 00220 } else { 00221 *ts << pF( KGlobal::locale()->formatDate( date ) ) 00222 << delim << pF( "" ) 00223 << delim << pF( KGlobal::locale()->formatDate( date ) ) 00224 << delim << pF( "" ); 00225 } 00226 00227 *ts << delim << pF( event->summary().replace( QChar('\n'), QChar(' ') ) ) 00228 << delim << pF( event->location().replace( QChar('\n'), QChar(' ') ) ) 00229 << delim << pF( event->description().replace( QChar('\n'), QChar(' ') ) ) 00230 << delim << pF( event->uid() ) 00231 << endl; 00232 00233 return true; 00234 }
KDE Logo
This file is part of the documentation for konsolekalendar Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Oct 21 19:46:59 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003