From 460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- konsolekalendar/konsolekalendarexports.cpp | 243 +++++++++++++++++++++++++++++ 1 file changed, 243 insertions(+) create mode 100644 konsolekalendar/konsolekalendarexports.cpp (limited to 'konsolekalendar/konsolekalendarexports.cpp') diff --git a/konsolekalendar/konsolekalendarexports.cpp b/konsolekalendar/konsolekalendarexports.cpp new file mode 100644 index 000000000..cad79964a --- /dev/null +++ b/konsolekalendar/konsolekalendarexports.cpp @@ -0,0 +1,243 @@ +/******************************************************************************* + * konsolekalendarexports.cpp * + * * + * KonsoleKalendar is a command line interface to KDE calendars * + * Copyright (C) 2002-2004 Tuukka Pasanen * + * Copyright (C) 2003-2005 Allen Winter * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + * * + * As a special exception, permission is given to link this program * + * with any edition of Qt, and distribute the resulting executable, * + * without including the source code for Qt in the source distribution. * + * * + ******************************************************************************/ +/** + * @file konsolekalendarexports.cpp + * Provides the KonsoleKalendarExports class definition. + * @author Tuukka Pasanen + * @author Allen Winter + */ +#include +#include + +#include + +#include +#include + +#include +#include +#include + +#include "konsolekalendarexports.h" + +using namespace KCal; +using namespace std; + +KonsoleKalendarExports::KonsoleKalendarExports( KonsoleKalendarVariables *vars ) +{ + m_variables = vars; + m_firstEntry = true; +} + + +KonsoleKalendarExports::~KonsoleKalendarExports() +{ +} + +bool KonsoleKalendarExports::exportAsTxt( QTextStream *ts, + Event *event, QDate date ) +{ + + // Export "Text" Format: + // + // Date:\t(dddd yyyy-MM-dd) + // [\t(hh:mm) - (hh:mm)] + // Summary: + // \t + // Location: + // \t + // Description: + // \t + // UID: + // \t + // -------------------------------------------------- + + // Print Event Date (in user's prefered format) + *ts << i18n( "Date:" ) + << "\t" + << KGlobal::locale()->formatDate( date ) + << endl; + + // Print Event Starttime - Endtime, for Non-Floating Events Only + if ( !event->doesFloat() ) { + *ts << "\t" + << KGlobal::locale()->formatTime( event->dtStart().time() ) + << " - " + << KGlobal::locale()->formatTime( event->dtEnd().time() ); + } + *ts << endl; + + // Print Event Summary + *ts << i18n( "Summary:" ) + << endl; + if ( !event->summary().isEmpty() ) { + *ts << "\t" + << event->summary() + << endl; + } else { + *ts << "\t" + << i18n( "(no summary available)" ) + << endl; + } + + // Print Event Location + *ts << i18n( "Location:" ) + << endl; + if ( !event->location().isEmpty() ) { + *ts << "\t" + <location() + << endl; + } else { + *ts << "\t" + << i18n( "(no location available)" ) + << endl; + } + + // Print Event Description + *ts << i18n( "Description:" ) + << endl; + if ( !event->description().isEmpty() ) { + *ts << "\t" + << event->description() + << endl; + } else { + *ts << "\t" + << i18n( "(no description available)" ) + << endl; + } + + // Print Event UID + *ts << i18n( "UID:" ) + << endl + << "\t" + << event->uid() + << endl; + + // Print Line Separator + *ts << "--------------------------------------------------" + << endl; + + return true; +} + +bool KonsoleKalendarExports::exportAsTxtShort( QTextStream *ts, + Event *event, QDate date, + bool sameday ) +{ + + // Export "Text-Short" Format: + // + // [--------------------------------------------------] + // {(dddd yyyy-MM-dd)] + // [(hh:mm) - (hh:mm) | "\t"] + // \t[, ] + // \t\t + + if ( !sameday ) { + // If a new date, then Print the Event Date (in user's prefered format) + *ts << KGlobal::locale()->formatDate( date ) << ":" + << endl; + } + + // Print Event Starttime - Endtime + if ( !event->doesFloat() ) { + *ts << KGlobal::locale()->formatTime( event->dtStart().time() ) + << " - " + << KGlobal::locale()->formatTime( event->dtEnd().time() ); + } else { + *ts << i18n( "[all day]\t" ); + } + *ts << "\t"; + + // Print Event Summary + *ts << event->summary().replace( QChar( '\n' ), QChar( ' ' ) ); + + // Print Event Location + if ( !event->location().isEmpty() ) { + if ( !event->summary().isEmpty() ) { + *ts << ", "; + } + *ts << event->location().replace( QChar( '\n' ), QChar( ' ' ) ); + } + *ts << endl; + + // Print Event Description + if ( !event->description().isEmpty() ) { + *ts << "\t\t\t" + << event->description().replace( QChar( '\n' ), QChar( ' ' ) ) + << endl; + } + +// By user request, no longer print UIDs if export-type==short + + return true; +} + +QString KonsoleKalendarExports::processField( QString field, QString dquote ) +{ + // little function that processes a field for CSV compliance: + // 1. Replaces double quotes by a pair of consecutive double quotes + // 2. Surrounds field with double quotes + + QString double_dquote = dquote + dquote; + QString retField = dquote + field.replace( dquote, double_dquote ) + dquote; + return retField; +} + +#define pF( x ) processField( ( x ), dquote ) + +bool KonsoleKalendarExports::exportAsCSV( QTextStream *ts, + Event *event, QDate date ) +{ + + // Export "CSV" Format: + // + // startdate,starttime,enddate,endtime,summary,location,description,UID + + QString delim = i18n( "," ); // character to use as CSV field delimiter + QString dquote = i18n( "\"" ); // character to use to quote CSV fields + + if ( !event->doesFloat() ) { + *ts << pF( KGlobal::locale()->formatDate( date ) ) + << delim << pF( KGlobal::locale()->formatTime( event->dtStart().time() ) ) + << delim << pF( KGlobal::locale()->formatDate( date ) ) + << delim << pF( KGlobal::locale()->formatTime( event->dtEnd().time() ) ); + } else { + *ts << pF( KGlobal::locale()->formatDate( date ) ) + << delim << pF( "" ) + << delim << pF( KGlobal::locale()->formatDate( date ) ) + << delim << pF( "" ); + } + + *ts << delim << pF( event->summary().replace( QChar('\n'), QChar(' ') ) ) + << delim << pF( event->location().replace( QChar('\n'), QChar(' ') ) ) + << delim << pF( event->description().replace( QChar('\n'), QChar(' ') ) ) + << delim << pF( event->uid() ) + << endl; + + return true; +} -- cgit v1.2.1