summaryrefslogtreecommitdiff
path: root/libopie/todovcalresource.cpp
authorzecke <zecke>2002-04-13 16:27:19 (UTC)
committer zecke <zecke>2002-04-13 16:27:19 (UTC)
commitdef870c6fcccf2b20d7ce3821055391b18243a24 (patch) (unidiff)
tree006357788654cf0e18c76640bd821cf87731d952 /libopie/todovcalresource.cpp
parente42465b45553f51cf7c7d24130aa3a90a6be3ddd (diff)
downloadopie-def870c6fcccf2b20d7ce3821055391b18243a24.zip
opie-def870c6fcccf2b20d7ce3821055391b18243a24.tar.gz
opie-def870c6fcccf2b20d7ce3821055391b18243a24.tar.bz2
multiple categories
Diffstat (limited to 'libopie/todovcalresource.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/todovcalresource.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/libopie/todovcalresource.cpp b/libopie/todovcalresource.cpp
index a6afe68..75f2197 100644
--- a/libopie/todovcalresource.cpp
+++ b/libopie/todovcalresource.cpp
@@ -1,153 +1,153 @@
1/* 1/*
2               =. This file is part of the OPIE Project 2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 Holger Freyther <freyther@kde.org> 3             .=l. Copyright (c) 2002 Holger Freyther <freyther@kde.org>
4           .>+-= the use of vobject was inspired by libkcal 4           .>+-= the use of vobject was inspired by libkcal
5 _;:,     .>    :=|. This library is free software; you can 5 _;:,     .>    :=|. This library is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under 6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software 8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License, 9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version. 10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_. 11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that 12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of 14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more 17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details. 18++=   -.     .`     .: details.
19 :     =  ...= . :.=- 19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU 20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with 21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB. 22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation, 23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, 24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29#include <qfile.h> 29#include <qfile.h>
30#include <qvaluelist.h> 30#include <qvaluelist.h>
31#include <opie/todoevent.h> 31#include <opie/todoevent.h>
32#include <opie/todovcalresource.h> 32#include <opie/todovcalresource.h>
33 33
34#include "../library/backend/vobject_p.h" 34#include "../library/backend/vobject_p.h"
35#include "../library/backend/timeconversion.h" 35#include "../library/backend/timeconversion.h"
36#include "../library/backend/qfiledirect_p.h" 36#include "../library/backend/qfiledirect_p.h"
37 37
38static VObject *vobjByEvent( const ToDoEvent &event ) 38static VObject *vobjByEvent( const ToDoEvent &event )
39{ 39{
40 VObject *task = newVObject( VCTodoProp ); 40 VObject *task = newVObject( VCTodoProp );
41 if( task == 0 ) 41 if( task == 0 )
42 return 0l; 42 return 0l;
43 if( event.hasDate() ) 43 if( event.hasDate() )
44 addPropValue( task, VCDueProp, TimeConversion::toISO8601( event.date() ) ); 44 addPropValue( task, VCDueProp, TimeConversion::toISO8601( event.date() ) );
45 45
46 if( event.isCompleted() ) 46 if( event.isCompleted() )
47 addPropValue( task, VCStatusProp, "COMPLETED"); 47 addPropValue( task, VCStatusProp, "COMPLETED");
48 48
49 QString string = QString::number(event.priority() ); 49 QString string = QString::number(event.priority() );
50 addPropValue( task, VCPriorityProp, string.local8Bit() ); 50 addPropValue( task, VCPriorityProp, string.local8Bit() );
51 addPropValue( task, VCCategoriesProp, event.category().local8Bit() ); 51 addPropValue( task, VCCategoriesProp, event.allCategories().join(";").local8Bit() );
52 addPropValue( task, VCDescriptionProp, event.description().local8Bit() ); 52 addPropValue( task, VCDescriptionProp, event.description().local8Bit() );
53 addPropValue( task, VCSummaryProp, event.description().left(15).local8Bit() ); 53 addPropValue( task, VCSummaryProp, event.description().left(15).local8Bit() );
54 return task; 54 return task;
55}; 55};
56 56
57static ToDoEvent eventByVObj( VObject *obj ){ 57static ToDoEvent eventByVObj( VObject *obj ){
58 ToDoEvent event; 58 ToDoEvent event;
59 VObject *ob; 59 VObject *ob;
60 QCString name; 60 QCString name;
61 // no uid, attendees, ... and no fun 61 // no uid, attendees, ... and no fun
62 // description 62 // description
63 if( ( ob = isAPropertyOf( obj, VCDescriptionProp )) != 0 ){ 63 if( ( ob = isAPropertyOf( obj, VCDescriptionProp )) != 0 ){
64 name = vObjectStringZValue( ob ); 64 name = vObjectStringZValue( ob );
65 event.setDescription( name ); 65 event.setDescription( name );
66 } 66 }
67 // completed 67 // completed
68 if( ( ob = isAPropertyOf( obj, VCStatusProp )) != 0 ){ 68 if( ( ob = isAPropertyOf( obj, VCStatusProp )) != 0 ){
69 name = vObjectStringZValue( ob ); 69 name = vObjectStringZValue( ob );
70 if( name == "COMPLETED" ){ 70 if( name == "COMPLETED" ){
71 event.setCompleted( true ); 71 event.setCompleted( true );
72 }else{ 72 }else{
73 event.setCompleted( false ); 73 event.setCompleted( false );
74 } 74 }
75 }else 75 }else
76 event.setCompleted( false ); 76 event.setCompleted( false );
77 // priority 77 // priority
78 if ((ob = isAPropertyOf(obj, VCPriorityProp))) { 78 if ((ob = isAPropertyOf(obj, VCPriorityProp))) {
79 name = vObjectStringZValue( ob ); 79 name = vObjectStringZValue( ob );
80 bool ok; 80 bool ok;
81 event.setPriority(name.toInt(&ok) ); 81 event.setPriority(name.toInt(&ok) );
82 } 82 }
83 //due date 83 //due date
84 if((ob = isAPropertyOf(obj, VCDueProp)) ){ 84 if((ob = isAPropertyOf(obj, VCDueProp)) ){
85 event.setHasDate( true ); 85 event.setHasDate( true );
86 name = vObjectStringZValue( ob ); 86 name = vObjectStringZValue( ob );
87 event.setDate( TimeConversion::fromISO8601( name).date() ); 87 event.setDate( TimeConversion::fromISO8601( name).date() );
88 } 88 }
89 // categories 89 // categories
90 if((ob = isAPropertyOf( obj, VCCategoriesProp )) != 0 ){ 90 if((ob = isAPropertyOf( obj, VCCategoriesProp )) != 0 ){
91 name = vObjectStringZValue( ob ); 91 name = vObjectStringZValue( ob );
92 qWarning("Categories:%s", name.data() ); 92 qWarning("Categories:%s", name.data() );
93 } 93 }
94 94
95 return event; 95 return event;
96}; 96};
97 97
98 98
99QValueList<ToDoEvent> ToDoVCalResource::load(const QString &file) 99QValueList<ToDoEvent> ToDoVCalResource::load(const QString &file)
100{ 100{
101 QValueList<ToDoEvent> events; 101 QValueList<ToDoEvent> events;
102 VObject *vcal = 0l; 102 VObject *vcal = 0l;
103 vcal = Parse_MIME_FromFileName( (char *)file.utf8().data() ); // from vobject 103 vcal = Parse_MIME_FromFileName( (char *)file.utf8().data() ); // from vobject
104 if(!vcal ) 104 if(!vcal )
105 return events; 105 return events;
106 // start parsing 106 // start parsing
107 107
108 VObjectIterator it; 108 VObjectIterator it;
109 VObject *vobj; 109 VObject *vobj;
110 initPropIterator(&it, vcal); 110 initPropIterator(&it, vcal);
111 111
112 while( moreIteration( &it ) ) { 112 while( moreIteration( &it ) ) {
113 vobj = ::nextVObject( &it ); 113 vobj = ::nextVObject( &it );
114 QCString name = ::vObjectName( vobj ); 114 QCString name = ::vObjectName( vobj );
115 //QCString objVal = ::vObjectStringZValue( vobj ); 115 //QCString objVal = ::vObjectStringZValue( vobj );
116 // let's find out the type 116 // let's find out the type
117 if( name == VCTodoProp ){ 117 if( name == VCTodoProp ){
118 events.append( eventByVObj( vobj ) ); 118 events.append( eventByVObj( vobj ) );
119 119
120 } // parse the value 120 } // parse the value
121 } 121 }
122 return events; 122 return events;
123} 123}
124bool ToDoVCalResource::save(const QString &fileName, const QValueList<ToDoEvent>&list ) 124bool ToDoVCalResource::save(const QString &fileName, const QValueList<ToDoEvent>&list )
125{ 125{
126 QFileDirect file ( fileName ); 126 QFileDirect file ( fileName );
127 if(!file.open(IO_WriteOnly ) ) 127 if(!file.open(IO_WriteOnly ) )
128 return false; 128 return false;
129 // obj 129 // obj
130 VObject *obj; 130 VObject *obj;
131 obj = newVObject( VCCalProp ); 131 obj = newVObject( VCCalProp );
132 addPropValue( obj, VCVersionProp, "1.0" ); 132 addPropValue( obj, VCVersionProp, "1.0" );
133 VObject *vo; 133 VObject *vo;
134 for(QValueList<ToDoEvent>::ConstIterator it = list.begin(); it != list.end(); ++it ){ 134 for(QValueList<ToDoEvent>::ConstIterator it = list.begin(); it != list.end(); ++it ){
135 vo = vobjByEvent( (*it) ); 135 vo = vobjByEvent( (*it) );
136 addVObjectProp(obj, vo ); 136 addVObjectProp(obj, vo );
137 } 137 }
138 writeVObject( file.directHandle(), obj ); 138 writeVObject( file.directHandle(), obj );
139 cleanVObject( obj ); 139 cleanVObject( obj );
140 cleanStrTbl(); 140 cleanStrTbl();
141 141
142 return true; 142 return true;
143} 143}
144 144
145 145
146 146
147 147
148 148
149 149
150 150
151 151
152 152
153 153