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

KCal Library

  • kcal
filestorage.cpp
Go to the documentation of this file.
1/*
2 This file is part of the kcal library.
3
4 Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20*/
32#include "filestorage.h"
33#include "calendar.h"
34#include "vcalformat.h"
35#include "icalformat.h"
36
37#include <kdebug.h>
38
39#include <QtCore/QString>
40
41#include <stdlib.h>
42
43using namespace KCal;
44
48//@cond PRIVATE
49class KCal::FileStorage::Private
50{
51 public:
52 Private( const QString &fileName, CalFormat *format )
53 : mFileName( fileName ),
54 mSaveFormat( format )
55 {}
56 ~Private() { delete mSaveFormat; }
57
58 QString mFileName;
59 CalFormat *mSaveFormat;
60};
61//@endcond
62
63FileStorage::FileStorage( Calendar *cal, const QString &fileName,
64 CalFormat *format )
65 : CalStorage( cal ),
66 d( new Private( fileName, format ) )
67{
68}
69
70FileStorage::~FileStorage()
71{
72 delete d;
73}
74
75void FileStorage::setFileName( const QString &fileName )
76{
77 d->mFileName = fileName;
78}
79
80QString FileStorage::fileName() const
81{
82 return d->mFileName;
83}
84
85void FileStorage::setSaveFormat( CalFormat *format )
86{
87 delete d->mSaveFormat;
88 d->mSaveFormat = format;
89}
90
91CalFormat *FileStorage::saveFormat() const
92{
93 return d->mSaveFormat;
94}
95
96bool FileStorage::open()
97{
98 return true;
99}
100
101bool FileStorage::load()
102{
103 // do we want to silently accept this, or make some noise? Dunno...
104 // it is a semantical thing vs. a practical thing.
105 if ( d->mFileName.isEmpty() ) {
106 return false;
107 }
108
109 // Always try to load with iCalendar. It will detect, if it is actually a
110 // vCalendar file.
111 bool success;
112 QString productId;
113 // First try the supplied format. Otherwise fall through to iCalendar, then
114 // to vCalendar
115 success = saveFormat() && saveFormat()->load( calendar(), d->mFileName );
116 if ( success ) {
117 productId = saveFormat()->loadedProductId();
118 } else {
119 ICalFormat iCal;
120
121 success = iCal.load( calendar(), d->mFileName );
122
123 if ( success ) {
124 productId = iCal.loadedProductId();
125 } else {
126 if ( iCal.exception() ) {
127 if ( iCal.exception()->errorCode() == ErrorFormat::CalVersion1 ) {
128 // Expected non vCalendar file, but detected vCalendar
129 kDebug() << "Fallback to VCalFormat";
130 VCalFormat vCal;
131 success = vCal.load( calendar(), d->mFileName );
132 productId = vCal.loadedProductId();
133 } else {
134 return false;
135 }
136 } else {
137 kDebug() << "Warning! There should be an exception set.";
138 return false;
139 }
140 }
141 }
142
143 calendar()->setProductId( productId );
144 calendar()->setModified( false );
145
146 return true;
147}
148
149bool FileStorage::save()
150{
151 kDebug();
152 if ( d->mFileName.isEmpty() ) {
153 return false;
154 }
155
156 CalFormat *format = d->mSaveFormat ? d->mSaveFormat : new ICalFormat;
157
158 bool success = format->save( calendar(), d->mFileName );
159
160 if ( success ) {
161 calendar()->setModified( false );
162 } else {
163 if ( !format->exception() ) {
164 kDebug() << "Error. There should be an expection set.";
165 } else {
166 kDebug() << format->exception()->message();
167 }
168 }
169
170 if ( !d->mSaveFormat ) {
171 delete format;
172 }
173
174 return success;
175}
176
177bool FileStorage::close()
178{
179 return true;
180}
calendar.h
This file is part of the API for handling calendar data and defines the Calendar class.
KCal::CalFormat
An abstract base class that provides an interface to various calendar formats.
Definition calformat.h:52
KCal::CalFormat::loadedProductId
const QString & loadedProductId()
Returns the PRODID string loaded from calendar file.
Definition calformat.cpp:105
KCal::CalFormat::load
virtual bool load(Calendar *calendar, const QString &fileName)=0
Loads a calendar on disk into the calendar associated with this format.
KCal::CalStorage
An abstract base class that provides a calendar storage interface.
Definition calstorage.h:47
KCal::CalStorage::calendar
Calendar * calendar() const
Returns a pointer to the calendar whose storage is being managed.
Definition calstorage.cpp:62
KCal::Calendar
Represents the main calendar class.
Definition calendar.h:121
KCal::Calendar::setModified
void setModified(bool modified)
Sets if the calendar has been modified.
Definition calendar.cpp:1125
KCal::Calendar::setProductId
void setProductId(const QString &id)
Sets the calendar Product ID to id.
Definition calendar.cpp:1197
KCal::ErrorFormat::CalVersion1
@ CalVersion1
vCalendar v1.0 detected
Definition exceptions.h:94
KCal::FileStorage::open
bool open()
Definition filestorage.cpp:96
KCal::FileStorage::~FileStorage
virtual ~FileStorage()
Destructor.
Definition filestorage.cpp:70
KCal::FileStorage::FileStorage
FileStorage(Calendar *calendar, const QString &fileName=QString(), CalFormat *format=0)
Constructs a new FileStorage object for Calendar calendar with format format, and storage to file fil...
Definition filestorage.cpp:63
KCal::FileStorage::fileName
QString fileName() const
Returns a string containing the name of the calendar file.
Definition filestorage.cpp:80
KCal::FileStorage::saveFormat
CalFormat * saveFormat() const
Returns a pointer to the CalFormat object used by this storage.
Definition filestorage.cpp:91
KCal::FileStorage::save
bool save()
Definition filestorage.cpp:149
KCal::FileStorage::load
bool load()
Definition filestorage.cpp:101
KCal::FileStorage::setSaveFormat
void setSaveFormat(CalFormat *format)
Sets the CalFormat object to use for this storage.
Definition filestorage.cpp:85
KCal::FileStorage::setFileName
void setFileName(const QString &fileName)
Sets the name of the file that contains the calendar data.
Definition filestorage.cpp:75
KCal::FileStorage::close
bool close()
Definition filestorage.cpp:177
KCal::ICalFormat
iCalendar format implementation.
Definition icalformat.h:53
KCal::ICalFormat::save
bool save(Calendar *calendar, const QString &fileName)
Definition icalformat.cpp:110
KCal::ICalFormat::load
bool load(Calendar *calendar, const QString &fileName)
Definition icalformat.cpp:85
filestorage.h
This file is part of the API for handling calendar data and defines the FileStorage class.
icalformat.h
This file is part of the API for handling calendar data and defines the ICalFormat class.
vcalformat.h
This file is part of the API for handling calendar data and defines the VCalFormat base class.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Wed Jan 24 2024 00:00:00 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KCal Library

Skip menu "KCal Library"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepimlibs-4.14.10 API Reference

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