• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

KonsoleKalendar

  • sources
  • kde-4.12
  • kdepim
  • console
  • konsolekalendar
konsolekalendarexports.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * konsolekalendarexports.cpp *
3  * *
4  * KonsoleKalendar is a command line interface to KDE calendars *
5  * Copyright (C) 2002-2004 Tuukka Pasanen <illuusio@mailcity.com> *
6  * Copyright (C) 2003-2005,2009 Allen Winter <winter@kde.org> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the Free Software *
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
21  * *
22  * As a special exception, permission is given to link this program *
23  * with any edition of Qt, and distribute the resulting executable, *
24  * without including the source code for Qt in the source distribution. *
25  * *
26  ******************************************************************************/
33 #include "konsolekalendarexports.h"
34 
35 
36 #include <kdebug.h>
37 #include <klocale.h>
38 #include <KGlobal>
39 
40 #include <KCalCore/Event>
41 
42 #include <QtCore/QDateTime>
43 
44 #include <stdlib.h>
45 #include <iostream>
46 
47 using namespace KCalCore;
48 using namespace std;
49 
50 KonsoleKalendarExports::KonsoleKalendarExports( KonsoleKalendarVariables *vars )
51 {
52  m_variables = vars;
53  m_firstEntry = true;
54 }
55 
56 KonsoleKalendarExports::~KonsoleKalendarExports()
57 {
58 }
59 
60 bool KonsoleKalendarExports::exportAsTxt( QTextStream *ts,
61  const Event::Ptr &event, const QDate &date )
62 {
63 
64  // Export "Text" Format:
65  //
66  // Date:\t<Incidence Date>(dddd yyyy-MM-dd)
67  // [\t<Incidence Start Time>(hh:mm) - <Incidence End Time>(hh:mm)]
68  // Summary:
69  // \t<Incidence Summary | "(no summary available)">
70  // Location:
71  // \t<Incidence Location | "(no location available)">
72  // Description:
73  // \t<Incidence Description | "(no description available)">
74  // UID:
75  // \t<Incidence UID>
76  // --------------------------------------------------
77 
78  // Print Event Date (in user's preferred format)
79  *ts << i18n( "Date:" )
80  << "\t"
81  << KGlobal::locale()->formatDate( date )
82  << endl;
83 
84  // Print Event Starttime - Endtime, for Non-All-Day Events Only
85  if ( !event->allDay() ) {
86  *ts << "\t"
87  << KGlobal::locale()->formatTime( event->dtStart().time() )
88  << " - "
89  << KGlobal::locale()->formatTime( event->dtEnd().time() );
90  }
91  *ts << endl;
92 
93  // Print Event Summary
94  *ts << i18n( "Summary:" )
95  << endl;
96  if ( !event->summary().isEmpty() ) {
97  *ts << "\t"
98  << event->summary()
99  << endl;
100  } else {
101  *ts << "\t"
102  << i18n( "(no summary available)" )
103  << endl;
104  }
105 
106  // Print Event Location
107  *ts << i18n( "Location:" )
108  << endl;
109  if ( !event->location().isEmpty() ) {
110  *ts << "\t"
111  << event->location()
112  << endl;
113  } else {
114  *ts << "\t"
115  << i18n( "(no location available)" )
116  << endl;
117  }
118 
119  // Print Event Description
120  *ts << i18n( "Description:" )
121  << endl;
122  if ( !event->description().isEmpty() ) {
123  *ts << "\t"
124  << event->description()
125  << endl;
126  } else {
127  *ts << "\t"
128  << i18n( "(no description available)" )
129  << endl;
130  }
131 
132  // Print Event UID
133  *ts << i18n( "UID:" )
134  << endl
135  << "\t"
136  << event->uid()
137  << endl;
138 
139  // Print Line Separator
140  *ts << "--------------------------------------------------"
141  << endl;
142 
143  return true;
144 }
145 
146 bool KonsoleKalendarExports::exportAsTxtShort( QTextStream *ts,
147  const Event::Ptr &event, const QDate &date,
148  bool sameday )
149 {
150 
151  // Export "Text-Short" Format:
152  //
153  // [--------------------------------------------------]
154  // {<Incidence Date>(dddd yyyy-MM-dd)]
155  // [<Incidence Start Time>(hh:mm) - <Incidence End Time>(hh:mm) | "\t"]
156  // \t<Incidence Summary | \t>[, <Incidence Location>]
157  // \t\t<Incidence Description | "\t">
158 
159  if ( !sameday ) {
160  // If a new date, then Print the Event Date (in user's preferred format)
161  *ts << KGlobal::locale()->formatDate( date ) << ":"
162  << endl;
163  }
164 
165  // Print Event Starttime - Endtime
166  if ( !event->allDay() ) {
167  *ts << KGlobal::locale()->formatTime( event->dtStart().time() )
168  << " - "
169  << KGlobal::locale()->formatTime( event->dtEnd().time() );
170  } else {
171  *ts << i18n( "[all day]\t" );
172  }
173  *ts << "\t";
174 
175  // Print Event Summary
176  *ts << event->summary().replace( QLatin1Char( '\n' ), QLatin1Char( ' ' ) );
177 
178  // Print Event Location
179  if ( !event->location().isEmpty() ) {
180  if ( !event->summary().isEmpty() ) {
181  *ts << ", ";
182  }
183  *ts << event->location().replace( QLatin1Char( '\n' ), QLatin1Char( ' ' ) );
184  }
185  *ts << endl;
186 
187  // Print Event Description
188  if ( !event->description().isEmpty() ) {
189  *ts << "\t\t\t"
190  << event->description().replace( QLatin1Char( '\n' ), QLatin1Char( ' ' ) )
191  << endl;
192  }
193 
194 // By user request, no longer print UIDs if export-type==short
195 
196  // Print Separator
197  *ts << endl;
198 
199  return true;
200 }
201 
202 QString KonsoleKalendarExports::processField( const QString &field,
203  const QString &dquote )
204 {
205  // little function that processes a field for CSV compliance:
206  // 1. Replaces double quotes by a pair of consecutive double quotes
207  // 2. Surrounds field with double quotes
208 
209  QString double_dquote = dquote + dquote;
210  QString retField = field;
211  retField = dquote + retField.replace( dquote, double_dquote ) + dquote;
212  return retField;
213 }
214 
215 //@cond IGNORE
216 #define pF( x ) processField( ( x ), dquote )
217 //@endcond
218 
219 bool KonsoleKalendarExports::exportAsCSV( QTextStream *ts,
220  const Event::Ptr &event, const QDate &date )
221 {
222 
223  // Export "CSV" Format:
224  //
225  // startdate,starttime,enddate,endtime,summary,location,description,UID
226 
227  QString delim = i18n( "," ); // character to use as CSV field delimiter
228  QString dquote = i18n( "\"" ); // character to use to quote CSV fields
229 
230  if ( !event->allDay() ) {
231  *ts << pF( KGlobal::locale()->formatDate( date ) )
232  << delim << pF( KGlobal::locale()->formatTime( event->dtStart().time() ) )
233  << delim << pF( KGlobal::locale()->formatDate( date ) )
234  << delim << pF( KGlobal::locale()->formatTime( event->dtEnd().time() ) );
235  } else {
236  *ts << pF( KGlobal::locale()->formatDate( date ) )
237  << delim << pF( QLatin1String("") )
238  << delim << pF( KGlobal::locale()->formatDate( date ) )
239  << delim << pF( QLatin1String("") );
240  }
241 
242  *ts << delim << pF( event->summary().replace( QLatin1Char( '\n' ), QLatin1Char( ' ' ) ) )
243  << delim << pF( event->location().replace( QLatin1Char( '\n' ), QLatin1Char( ' ' ) ) )
244  << delim << pF( event->description().replace( QLatin1Char( '\n' ), QLatin1Char( ' ' ) ) )
245  << delim << pF( event->uid() )
246  << endl;
247 
248  return true;
249 }
KonsoleKalendarExports::exportAsTxtShort
bool exportAsTxtShort(QTextStream *ts, const KCalCore::Event::Ptr &event, const QDate &date, bool sameday)
Export the Event in Short Text Mode.
Definition: konsolekalendarexports.cpp:146
KonsoleKalendarExports::exportAsTxt
bool exportAsTxt(QTextStream *ts, const KCalCore::Event::Ptr &event, const QDate &date)
Export the Event in Text Mode.
Definition: konsolekalendarexports.cpp:60
KonsoleKalendarVariables
This class provides all the variables for the program.
Definition: konsolekalendarvariables.h:73
KonsoleKalendarExports::KonsoleKalendarExports
KonsoleKalendarExports(KonsoleKalendarVariables *vars=0)
Constructs a KonsoleKalendarChange object from command line arguments.
Definition: konsolekalendarexports.cpp:50
konsolekalendarexports.h
Provides the KonsoleKalendarExports class definition.
KonsoleKalendarExports::exportAsCSV
bool exportAsCSV(QTextStream *ts, const KCalCore::Event::Ptr &event, const QDate &date)
Export the Event in Comma-Separated Values (CSV) Mode.
Definition: konsolekalendarexports.cpp:219
KonsoleKalendarExports::~KonsoleKalendarExports
~KonsoleKalendarExports()
Destructor.
Definition: konsolekalendarexports.cpp:56
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:04 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KonsoleKalendar

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

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



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