summaryrefslogtreecommitdiffabout
path: root/libkcal
Unidiff
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calstorage.h2
-rw-r--r--libkcal/filestorage.cpp4
-rw-r--r--libkcal/filestorage.h2
-rw-r--r--libkcal/icalformat.cpp24
-rw-r--r--libkcal/icalformat.h3
5 files changed, 7 insertions, 28 deletions
diff --git a/libkcal/calstorage.h b/libkcal/calstorage.h
index 72972ea..82c8682 100644
--- a/libkcal/calstorage.h
+++ b/libkcal/calstorage.h
@@ -30,23 +30,23 @@ class Calendar;
30class CalStorage 30class CalStorage
31{ 31{
32 public: 32 public:
33 CalStorage( Calendar *calendar ) 33 CalStorage( Calendar *calendar )
34 { 34 {
35 mCalendar = calendar; 35 mCalendar = calendar;
36 } 36 }
37 virtual ~CalStorage() {} 37 virtual ~CalStorage() {}
38 38
39 Calendar *calendar() const { return mCalendar; } 39 Calendar *calendar() const { return mCalendar; }
40 40
41 virtual bool open() = 0; 41 virtual bool open() = 0;
42 virtual bool load(bool = false ) = 0; 42 virtual bool load( ) = 0;
43 virtual bool save() = 0; 43 virtual bool save() = 0;
44 virtual bool close() = 0; 44 virtual bool close() = 0;
45 45
46 private: 46 private:
47 Calendar *mCalendar; 47 Calendar *mCalendar;
48}; 48};
49 49
50} 50}
51 51
52#endif 52#endif
diff --git a/libkcal/filestorage.cpp b/libkcal/filestorage.cpp
index 00c15d9..a139124 100644
--- a/libkcal/filestorage.cpp
+++ b/libkcal/filestorage.cpp
@@ -67,35 +67,35 @@ void FileStorage::setSaveFormat( CalFormat *format )
67 67
68CalFormat *FileStorage::saveFormat()const 68CalFormat *FileStorage::saveFormat()const
69{ 69{
70 return mSaveFormat; 70 return mSaveFormat;
71} 71}
72 72
73 73
74bool FileStorage::open() 74bool FileStorage::open()
75{ 75{
76 return true; 76 return true;
77} 77}
78 78
79bool FileStorage::load( bool quick ) 79bool FileStorage::load( )
80{ 80{
81 kdDebug(5800) << "FileStorage::load(): '" << mFileName << "'" << endl; 81 kdDebug(5800) << "FileStorage::load(): '" << mFileName << "'" << endl;
82 82
83 // do we want to silently accept this, or make some noise? Dunno... 83 // do we want to silently accept this, or make some noise? Dunno...
84 // it is a semantical thing vs. a practical thing. 84 // it is a semantical thing vs. a practical thing.
85 if (mFileName.isEmpty()) return false; 85 if (mFileName.isEmpty()) return false;
86 86
87 // Always try to load with iCalendar. It will detect, if it is actually a 87 // Always try to load with iCalendar. It will detect, if it is actually a
88 // vCalendar file. 88 // vCalendar file.
89 ICalFormat iCal (quick ); 89 ICalFormat iCal;
90 90
91 bool success = iCal.load( calendar(), mFileName); 91 bool success = iCal.load( calendar(), mFileName);
92 92
93 if ( !success ) { 93 if ( !success ) {
94 if ( iCal.exception() ) { 94 if ( iCal.exception() ) {
95// kdDebug(5800) << "---Error: " << mFormat->exception()->errorCode() << endl; 95// kdDebug(5800) << "---Error: " << mFormat->exception()->errorCode() << endl;
96 if ( iCal.exception()->errorCode() == ErrorFormat::CalVersion1 ) { 96 if ( iCal.exception()->errorCode() == ErrorFormat::CalVersion1 ) {
97 // Expected non vCalendar file, but detected vCalendar 97 // Expected non vCalendar file, but detected vCalendar
98 kdDebug(5800) << "FileStorage::load() Fallback to VCalFormat" << endl; 98 kdDebug(5800) << "FileStorage::load() Fallback to VCalFormat" << endl;
99 VCalFormat vCal; 99 VCalFormat vCal;
100 success = vCal.load( calendar(), mFileName ); 100 success = vCal.load( calendar(), mFileName );
101 calendar()->setLoadedProductId( vCal.productId() ); 101 calendar()->setLoadedProductId( vCal.productId() );
diff --git a/libkcal/filestorage.h b/libkcal/filestorage.h
index e9dc15e..17010ac 100644
--- a/libkcal/filestorage.h
+++ b/libkcal/filestorage.h
@@ -35,24 +35,24 @@ class FileStorage : public CalStorage
35 virtual ~FileStorage(); 35 virtual ~FileStorage();
36 36
37 void setFileName( const QString &mFileName ); 37 void setFileName( const QString &mFileName );
38 QString fileName()const; 38 QString fileName()const;
39 39
40 /** 40 /**
41 FileStorage takes ownership of format object. 41 FileStorage takes ownership of format object.
42 */ 42 */
43 void setSaveFormat( CalFormat * ); 43 void setSaveFormat( CalFormat * );
44 CalFormat *saveFormat()const; 44 CalFormat *saveFormat()const;
45 45
46 bool open(); 46 bool open();
47 bool load(bool quick = false ); 47 bool load( );
48 bool save(); 48 bool save();
49 bool close(); 49 bool close();
50 50
51 private: 51 private:
52 QString mFileName; 52 QString mFileName;
53 CalFormat *mSaveFormat; 53 CalFormat *mSaveFormat;
54}; 54};
55 55
56} 56}
57 57
58#endif 58#endif
diff --git a/libkcal/icalformat.cpp b/libkcal/icalformat.cpp
index f2e7dfc..3a2aac6 100644
--- a/libkcal/icalformat.cpp
+++ b/libkcal/icalformat.cpp
@@ -41,60 +41,50 @@ extern "C" {
41 41
42#include "calendar.h" 42#include "calendar.h"
43#include "calendarlocal.h" 43#include "calendarlocal.h"
44#include "journal.h" 44#include "journal.h"
45 45
46#include "icalformat.h" 46#include "icalformat.h"
47#include "icalformatimpl.h" 47#include "icalformatimpl.h"
48 48
49#define _ICAL_VERSION "2.0" 49#define _ICAL_VERSION "2.0"
50 50
51using namespace KCal; 51using namespace KCal;
52 52
53ICalFormat::ICalFormat(bool quick ) 53ICalFormat::ICalFormat( )
54{ 54{
55 mQuicksave = false; //quick;
56 mImpl = new ICalFormatImpl( this ); 55 mImpl = new ICalFormatImpl( this );
57 tzOffsetMin = 0; 56 tzOffsetMin = 0;
58 //qDebug("new ICalFormat() "); 57 //qDebug("new ICalFormat() ");
59} 58}
60 59
61ICalFormat::~ICalFormat() 60ICalFormat::~ICalFormat()
62{ 61{
63 delete mImpl; 62 delete mImpl;
64 //qDebug("delete ICalFormat "); 63 //qDebug("delete ICalFormat ");
65} 64}
66 65
67bool ICalFormat::load( Calendar *calendar, const QString &fileName) 66bool ICalFormat::load( Calendar *calendar, const QString &fileName)
68{ 67{
69 68
70 clearException(); 69 clearException();
71 70
72 QFile file( fileName ); 71 QFile file( fileName );
73 if (!file.open( IO_ReadOnly ) ) { 72 if (!file.open( IO_ReadOnly ) ) {
74 setException(new ErrorFormat(ErrorFormat::LoadError)); 73 setException(new ErrorFormat(ErrorFormat::LoadError));
75 return false; 74 return false;
76 } 75 }
77 QTextStream ts( &file ); 76 QTextStream ts( &file );
78 QString text; 77 QString text;
79#if 0 78
80 if ( !mQuicksave ) {
81 qDebug("KO: No quickload!");
82 ts.setEncoding( QTextStream::Latin1 );
83 text = ts.read();
84 } else {
85 ts.setCodec( QTextCodec::codecForName("utf8") );
86 text = ts.read();
87 }
88#endif
89 ts.setEncoding( QTextStream::Latin1 ); 79 ts.setEncoding( QTextStream::Latin1 );
90 text = ts.read(); 80 text = ts.read();
91 file.close(); 81 file.close();
92 82
93 return fromString( calendar, text ); 83 return fromString( calendar, text );
94} 84}
95 85
96//#include <qdatetime.h> 86//#include <qdatetime.h>
97bool ICalFormat::save( Calendar *calendar, const QString &fileName ) 87bool ICalFormat::save( Calendar *calendar, const QString &fileName )
98{ 88{
99 //kdDebug(5800) << "ICalFormat::save(): " << fileName << endl; 89 //kdDebug(5800) << "ICalFormat::save(): " << fileName << endl;
100 //qDebug("ICalFormat::save "); 90 //qDebug("ICalFormat::save ");
@@ -105,34 +95,24 @@ bool ICalFormat::save( Calendar *calendar, const QString &fileName )
105 if ( text.isNull() ) return false; 95 if ( text.isNull() ) return false;
106 96
107 // TODO: write backup file 97 // TODO: write backup file
108 //is.restart(); 98 //is.restart();
109 QFile file( fileName ); 99 QFile file( fileName );
110 if (!file.open( IO_WriteOnly ) ) { 100 if (!file.open( IO_WriteOnly ) ) {
111 setException(new ErrorFormat(ErrorFormat::SaveError, 101 setException(new ErrorFormat(ErrorFormat::SaveError,
112 i18n("Could not open file '%1'").arg(fileName))); 102 i18n("Could not open file '%1'").arg(fileName)));
113 return false; 103 return false;
114 } 104 }
115 QTextStream ts( &file ); 105 QTextStream ts( &file );
116 106
117// #ifdef DESKTOP_VERSION
118// mQuicksave = false;
119// #endif
120// if ( mQuicksave ) {
121// ts << text.utf8();
122// } else {
123// ts.setEncoding( QTextStream::Latin1 );
124// ts << text;
125// //ts << text.latin1();
126// }
127 ts.setEncoding( QTextStream::Latin1 ); 107 ts.setEncoding( QTextStream::Latin1 );
128 ts << text; 108 ts << text;
129 file.close(); 109 file.close();
130 //qDebug("saving file takes ms: %d ", is.elapsed() ); 110 //qDebug("saving file takes ms: %d ", is.elapsed() );
131 return true; 111 return true;
132} 112}
133 113
134bool ICalFormat::fromString( Calendar *cal, const QString &text ) 114bool ICalFormat::fromString( Calendar *cal, const QString &text )
135{ 115{
136 setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); 116 setTimeZone( cal->timeZoneId(), !cal->isLocalTime() );
137 // qDebug("ICalFormat::fromString tz: %s ", cal->timeZoneId().latin1()); 117 // qDebug("ICalFormat::fromString tz: %s ", cal->timeZoneId().latin1());
138 // Get first VCALENDAR component. 118 // Get first VCALENDAR component.
diff --git a/libkcal/icalformat.h b/libkcal/icalformat.h
index 236efbf..485ab6e 100644
--- a/libkcal/icalformat.h
+++ b/libkcal/icalformat.h
@@ -31,25 +31,25 @@ namespace KCal {
31class ICalFormatImpl; 31class ICalFormatImpl;
32 32
33/** 33/**
34 This class implements the iCalendar format. It provides methods for 34 This class implements the iCalendar format. It provides methods for
35 loading/saving/converting iCalendar format data into the internal KOrganizer 35 loading/saving/converting iCalendar format data into the internal KOrganizer
36 representation as Calendar and Events. 36 representation as Calendar and Events.
37 37
38 @short iCalendar format implementation 38 @short iCalendar format implementation
39*/ 39*/
40class ICalFormat : public CalFormat { 40class ICalFormat : public CalFormat {
41 public: 41 public:
42 /** Create new iCalendar format. */ 42 /** Create new iCalendar format. */
43 ICalFormat( bool quick = false ); 43 ICalFormat( );
44 virtual ~ICalFormat(); 44 virtual ~ICalFormat();
45 45
46 /** 46 /**
47 Loads a calendar on disk in iCalendar format into calendar. 47 Loads a calendar on disk in iCalendar format into calendar.
48 Returns true if successful, else returns false. Provides more error 48 Returns true if successful, else returns false. Provides more error
49 information by exception(). 49 information by exception().
50 @param calendar Calendar object to be filled. 50 @param calendar Calendar object to be filled.
51 @param fileName The name of the calendar file on disk. 51 @param fileName The name of the calendar file on disk.
52 */ 52 */
53 bool load( Calendar *, const QString &fileName ); 53 bool load( Calendar *, const QString &fileName );
54 /** 54 /**
55 Writes out the calendar to disk in iCalendar format. Returns true if 55 Writes out the calendar to disk in iCalendar format. Returns true if
@@ -95,22 +95,21 @@ class ICalFormat : public CalFormat {
95 /** Parse scheduling message provided as string \s */ 95 /** Parse scheduling message provided as string \s */
96 ScheduleMessage *parseScheduleMessage( Calendar *, const QString &s); 96 ScheduleMessage *parseScheduleMessage( Calendar *, const QString &s);
97 97
98 /** Set id of used time zone and whether this time zone is UTC or not. */ 98 /** Set id of used time zone and whether this time zone is UTC or not. */
99 void setTimeZone( const QString &id, bool utc ); 99 void setTimeZone( const QString &id, bool utc );
100 QString timeZoneId() const; 100 QString timeZoneId() const;
101 int timeOffset(); 101 int timeOffset();
102 const char * tzString(); 102 const char * tzString();
103 bool utc() const; 103 bool utc() const;
104 104
105 private: 105 private:
106 ICalFormatImpl *mImpl; 106 ICalFormatImpl *mImpl;
107 bool mQuicksave;
108 QString mTimeZoneId; 107 QString mTimeZoneId;
109 QCString mTzString; 108 QCString mTzString;
110 int tzOffsetMin; 109 int tzOffsetMin;
111 bool mUtc; 110 bool mUtc;
112}; 111};
113 112
114} 113}
115 114
116#endif 115#endif