konsolekalendar
konsolekalendarexports.cppGo to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00033 #include <stdlib.h>
00034 #include <iostream>
00035
00036 #include <qdatetime.h>
00037
00038 #include <kdebug.h>
00039 #include <klocale.h>
00040
00041 #include <libkcal/calendarlocal.h>
00042 #include <libkcal/calendar.h>
00043 #include <libkcal/event.h>
00044
00045 #include "konsolekalendarexports.h"
00046
00047 using namespace KCal;
00048 using namespace std;
00049
00050 KonsoleKalendarExports::KonsoleKalendarExports( KonsoleKalendarVariables *vars )
00051 {
00052 m_variables = vars;
00053 m_firstEntry = true;
00054 }
00055
00056
00057 KonsoleKalendarExports::~KonsoleKalendarExports()
00058 {
00059 }
00060
00061 bool KonsoleKalendarExports::exportAsTxt( QTextStream *ts,
00062 Event *event, QDate date )
00063 {
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 *ts << i18n( "Date:" )
00081 << "\t"
00082 << KGlobal::locale()->formatDate( date )
00083 << endl;
00084
00085
00086 if ( !event->doesFloat() ) {
00087 *ts << "\t"
00088 << KGlobal::locale()->formatTime( event->dtStart().time() )
00089 << " - "
00090 << KGlobal::locale()->formatTime( event->dtEnd().time() );
00091 }
00092 *ts << endl;
00093
00094
00095 *ts << i18n( "Summary:" )
00096 << endl;
00097 if ( !event->summary().isEmpty() ) {
00098 *ts << "\t"
00099 << event->summary()
00100 << endl;
00101 } else {
00102 *ts << "\t"
00103 << i18n( "(no summary available)" )
00104 << endl;
00105 }
00106
00107
00108 *ts << i18n( "Location:" )
00109 << endl;
00110 if ( !event->location().isEmpty() ) {
00111 *ts << "\t"
00112 <<event->location()
00113 << endl;
00114 } else {
00115 *ts << "\t"
00116 << i18n( "(no location available)" )
00117 << endl;
00118 }
00119
00120
00121 *ts << i18n( "Description:" )
00122 << endl;
00123 if ( !event->description().isEmpty() ) {
00124 *ts << "\t"
00125 << event->description()
00126 << endl;
00127 } else {
00128 *ts << "\t"
00129 << i18n( "(no description available)" )
00130 << endl;
00131 }
00132
00133
00134 *ts << i18n( "UID:" )
00135 << endl
00136 << "\t"
00137 << event->uid()
00138 << endl;
00139
00140
00141 *ts << "--------------------------------------------------"
00142 << endl;
00143
00144 return true;
00145 }
00146
00147 bool KonsoleKalendarExports::exportAsTxtShort( QTextStream *ts,
00148 Event *event, QDate date,
00149 bool sameday )
00150 {
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 if ( !sameday ) {
00161
00162 *ts << KGlobal::locale()->formatDate( date ) << ":"
00163 << endl;
00164 }
00165
00166
00167 if ( !event->doesFloat() ) {
00168 *ts << KGlobal::locale()->formatTime( event->dtStart().time() )
00169 << " - "
00170 << KGlobal::locale()->formatTime( event->dtEnd().time() );
00171 } else {
00172 *ts << i18n( "[all day]\t" );
00173 }
00174 *ts << "\t";
00175
00176
00177 *ts << event->summary().replace( QChar( '\n' ), QChar( ' ' ) );
00178
00179
00180 if ( !event->location().isEmpty() ) {
00181 if ( !event->summary().isEmpty() ) {
00182 *ts << ", ";
00183 }
00184 *ts << event->location().replace( QChar( '\n' ), QChar( ' ' ) );
00185 }
00186 *ts << endl;
00187
00188
00189 if ( !event->description().isEmpty() ) {
00190 *ts << "\t\t\t"
00191 << event->description().replace( QChar( '\n' ), QChar( ' ' ) )
00192 << endl;
00193 }
00194
00195
00196
00197 return true;
00198 }
00199
00200 QString KonsoleKalendarExports::processField( QString field, QString dquote )
00201 {
00202
00203
00204
00205
00206 QString double_dquote = dquote + dquote;
00207 QString retField = dquote + field.replace( dquote, double_dquote ) + dquote;
00208 return retField;
00209 }
00210
00211 #define pF( x ) processField( ( x ), dquote )
00212
00213 bool KonsoleKalendarExports::exportAsCSV( QTextStream *ts,
00214 Event *event, QDate date )
00215 {
00216
00217
00218
00219
00220
00221 QString delim = i18n( "," );
00222 QString dquote = i18n( "\"" );
00223
00224 if ( !event->doesFloat() ) {
00225 *ts << pF( KGlobal::locale()->formatDate( date ) )
00226 << delim << pF( KGlobal::locale()->formatTime( event->dtStart().time() ) )
00227 << delim << pF( KGlobal::locale()->formatDate( date ) )
00228 << delim << pF( KGlobal::locale()->formatTime( event->dtEnd().time() ) );
00229 } else {
00230 *ts << pF( KGlobal::locale()->formatDate( date ) )
00231 << delim << pF( "" )
00232 << delim << pF( KGlobal::locale()->formatDate( date ) )
00233 << delim << pF( "" );
00234 }
00235
00236 *ts << delim << pF( event->summary().replace( QChar('\n'), QChar(' ') ) )
00237 << delim << pF( event->location().replace( QChar('\n'), QChar(' ') ) )
00238 << delim << pF( event->description().replace( QChar('\n'), QChar(' ') ) )
00239 << delim << pF( event->uid() )
00240 << endl;
00241
00242 return true;
00243 }
|