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

KCalCore Library

  • kcalcore
filestorage.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the kcalcore 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 */
31 #include "filestorage.h"
32 #include "exceptions.h"
33 #include "icalformat.h"
34 #include "memorycalendar.h"
35 #include "vcalformat.h"
36 
37 #include <KDebug>
38 
39 using namespace KCalCore;
40 
41 /*
42  Private class that helps to provide binary compatibility between releases.
43 */
44 //@cond PRIVATE
45 class KCalCore::FileStorage::Private
46 {
47  public:
48  Private( const QString &fileName, CalFormat *format )
49  : mFileName( fileName ),
50  mSaveFormat( format )
51  {}
52  ~Private() { delete mSaveFormat; }
53 
54  QString mFileName;
55  CalFormat *mSaveFormat;
56 };
57 //@endcond
58 
59 FileStorage::FileStorage( const Calendar::Ptr &cal, const QString &fileName,
60  CalFormat *format )
61  : CalStorage( cal ),
62  d( new Private( fileName, format ) )
63 {
64 }
65 
66 FileStorage::~FileStorage()
67 {
68  delete d;
69 }
70 
71 void FileStorage::setFileName( const QString &fileName )
72 {
73  d->mFileName = fileName;
74 }
75 
76 QString FileStorage::fileName() const
77 {
78  return d->mFileName;
79 }
80 
81 void FileStorage::setSaveFormat( CalFormat *format )
82 {
83  delete d->mSaveFormat;
84  d->mSaveFormat = format;
85 }
86 
87 CalFormat *FileStorage::saveFormat() const
88 {
89  return d->mSaveFormat;
90 }
91 
92 bool FileStorage::open()
93 {
94  return true;
95 }
96 
97 bool FileStorage::load()
98 {
99  if ( d->mFileName.isEmpty() ) {
100  kWarning() << "Empty filename while trying to load";
101  return false;
102  }
103 
104  // Always try to load with iCalendar. It will detect, if it is actually a
105  // vCalendar file.
106  bool success;
107  QString productId;
108  // First try the supplied format. Otherwise fall through to iCalendar, then
109  // to vCalendar
110  success = saveFormat() && saveFormat()->load( calendar(), d->mFileName );
111  if ( success ) {
112  productId = saveFormat()->loadedProductId();
113  } else {
114  ICalFormat iCal;
115 
116  success = iCal.load( calendar(), d->mFileName );
117 
118  if ( success ) {
119  productId = iCal.loadedProductId();
120  } else {
121  if ( iCal.exception() ) {
122  if ( iCal.exception()->code() == Exception::CalVersion1 ) {
123  // Expected non vCalendar file, but detected vCalendar
124  kDebug() << "Fallback to VCalFormat";
125  VCalFormat vCal;
126  success = vCal.load( calendar(), d->mFileName );
127  productId = vCal.loadedProductId();
128  } else {
129  return false;
130  }
131  } else {
132  kWarning() << "There should be an exception set.";
133  return false;
134  }
135  }
136  }
137 
138  calendar()->setProductId( productId );
139  calendar()->setModified( false );
140 
141  return true;
142 }
143 
144 bool FileStorage::save()
145 {
146  kDebug();
147  if ( d->mFileName.isEmpty() ) {
148  return false;
149  }
150 
151  CalFormat *format = d->mSaveFormat ? d->mSaveFormat : new ICalFormat;
152 
153  bool success = format->save( calendar(), d->mFileName );
154 
155  if ( success ) {
156  calendar()->setModified( false );
157  } else {
158  if ( !format->exception() ) {
159  kDebug() << "Error. There should be an expection set.";
160  } else {
161  kDebug() << int( format->exception()->code() );
162  }
163  }
164 
165  if ( !d->mSaveFormat ) {
166  delete format;
167  }
168 
169  return success;
170 }
171 
172 bool FileStorage::close()
173 {
174  return true;
175 }
memorycalendar.h
This file is part of the API for handling calendar data and defines the MemoryCalendar class...
KCalCore::CalFormat
An abstract base class that provides an interface to various calendar formats.
Definition: calformat.h:48
KCalCore::Exception::code
virtual ErrorCode code() const
Returns the error code.
Definition: exceptions.cpp:50
KCalCore::FileStorage::load
bool load()
Loads the calendar into memory.
Definition: filestorage.cpp:97
KCalCore::FileStorage::~FileStorage
virtual ~FileStorage()
Destructor.
Definition: filestorage.cpp:66
KCalCore::ICalFormat
iCalendar format implementation.
Definition: icalformat.h:58
KCalCore::CalFormat::load
virtual bool load(const Calendar::Ptr &calendar, const QString &fileName)=0
Loads a calendar on disk into the calendar associated with this format.
filestorage.h
This file is part of the API for handling calendar data and defines the FileStorage class...
exceptions.h
This file is part of the API for handling calendar data and defines the Exception class...
KCalCore::FileStorage::fileName
QString fileName() const
Returns the calendar file name.
Definition: filestorage.cpp:76
KCalCore::FileStorage::setSaveFormat
void setSaveFormat(KCalCore::CalFormat *format)
Sets the CalFormat object to use for this storage.
Definition: filestorage.cpp:81
KCalCore::FileStorage::close
bool close()
Closes the calendar storage.
Definition: filestorage.cpp:172
KCalCore::CalFormat::loadedProductId
QString loadedProductId()
Returns the PRODID string loaded from calendar file.
Definition: calformat.cpp:111
KCalCore::CalFormat::save
virtual bool save(const Calendar::Ptr &calendar, const QString &fileName)=0
Writes the calendar to disk.
KCalCore::FileStorage::setFileName
void setFileName(const QString &fileName)
Sets the name of the file that contains the calendar data.
Definition: filestorage.cpp:71
KCalCore::CalFormat::exception
Exception * exception() const
Returns an exception, if there is any, containing information about the last error that occurred...
Definition: calformat.cpp:89
KCalCore::VCalFormat::load
bool load(const Calendar::Ptr &calendar, const QString &fileName)
Definition: vcalformat.cpp:103
KCalCore::FileStorage::save
bool save()
Saves the calendar.
Definition: filestorage.cpp:144
KCalCore::Calendar::Ptr
QSharedPointer< Calendar > Ptr
A shared pointer to a Calendar.
Definition: calendar.h:138
KCalCore::FileStorage::open
bool open()
Opens the calendar for storage.
Definition: filestorage.cpp:92
KCalCore::CalStorage::calendar
Calendar::Ptr calendar() const
Returns the calendar for this storage object.
Definition: calstorage.cpp:61
KCalCore::FileStorage::FileStorage
FileStorage(const Calendar::Ptr &calendar, const QString &fileName=QString(), KCalCore::CalFormat *format=0)
Constructs a new FileStorage object for Calendar calendar with format format, and storage to file fil...
Definition: filestorage.cpp:59
vcalformat.h
This file is part of the API for handling calendar data and defines the VCalFormat base class...
KCalCore::VCalFormat
vCalendar format implementation.
Definition: vcalformat.h:69
KCalCore::ICalFormat::load
bool load(const Calendar::Ptr &calendar, const QString &fileName)
Definition: icalformat.cpp:77
KCalCore::FileStorage::saveFormat
CalFormat * saveFormat() const
Returns the CalFormat object used by this storage.
Definition: filestorage.cpp:87
KCalCore::CalStorage
An abstract base class that provides a calendar storage interface.
Definition: calstorage.h:46
icalformat.h
This file is part of the API for handling calendar data and defines the ICalFormat class...
KCalCore::Exception::CalVersion1
vCalendar v1.0 detected
Definition: exceptions.h:64
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Tue Nov 26 2013 09:02:04 by doxygen 1.8.5 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KCalCore Library

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

kdepimlibs-4.11.3 API Reference

Skip menu "kdepimlibs-4.11.3 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