Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117883668
kolabformat.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
7 KB
Referenced Files
None
Subscribers
None
kolabformat.cpp
View Options
#include
"kolabformat.h"
#include
<kcalcore/event.h>
#include
<iostream>
#include
<bindings/kolabformat-xcal.hxx>
//#include "note.h"
#include
<kdebug.h>
#include
<limits>
#include
<kcalcore/recurrencerule.h>
#include
"kcalconversions.h"
#include
</home/chrigi/devel/kde/kdepim-runtime/resources/kcal/kcalresource.h>
namespace
Kolab
{
// xml_schema::date::operator Date(Date &d, const xml_schema::date &dt) {
// Date d;
// d.year = year();
// return d;
// }; //conversion operator
// bool isAvailable(const icalendar_2_0::DateDatetimePropertyType &dtProperty)
// {
// if (dtProperty.date_time() || dtProperty.date()) {
// return true;
// }
// return false;
// }
std
::
string
serializeEvent
()
{
std
::
cout
<<
"ksjdsldfj"
;
return
"bla"
;
}
void
readICalendar
(
const
std
::
string
&
s
)
{
}
void
readEvent
(
Kolab
::
Event
&
event
,
const
icalendar_2_0
::
VeventType
&
vevent
)
{
// try {
// if (!vevent.properties())
// return;
// const icalendar_2_0::BaseComponentType::properties_type& properties = *vevent.properties();
// const icalendar_2_0::ArrayOfProperties::baseProperty_sequence &propertyList = properties.baseProperty();
//
// for (icalendar_2_0::ArrayOfProperties::baseProperty_const_iterator it(propertyList.begin()); it != propertyList.end(); it++) {
// if (const icalendar_2_0::DtstartPropType* d = dynamic_cast<const icalendar_2_0::DtstartPropType*> (&(*it))) {
// std::cout << "Start" << std::endl;
// if (d->date_time()) {
// const icalendar_2_0::DateDatetimePropertyType::date_time_type datetime = *(d->date_time());
// //datetime.day()
// // (*(d->date_time()))
// } else if (d->date()) {
// const icalendar_2_0::DateDatetimePropertyType::date_type &date = *(d->date());
// event.date << date;
// }
//
// } else if (const icalendar_2_0::RrulePropType* d = dynamic_cast<const icalendar_2_0::RrulePropType*> (&(*it))) {
// std::cout << "Rrule" << std::endl;
// std::cout << d->recur().freq() << std::endl;
// std::cout << d->recur().count() << std::endl;
// //std::cout << d->recur().byhour() << std::endl;
// } else {
// std::cout << "other" << std::endl;
// const icalendar_2_0::BasePropertyType &baseProperty = *it;
// }
// }
// } catch (const xml_schema::exception& e) {
// std::cout << e << std::endl;
// }
}
KCalCore
::
Event
::
Ptr
readEvent
(
const
std
::
string
&
s
,
bool
isUrl
)
{
try
{
//TODO compile schemas and embedd in binary, see xsdcxx/xsd/examples/cxx/tree/embedded
xml_schema
::
properties
props
;
std
::
auto_ptr
<
icalendar_2_0
::
IcalendarType
>
icalendar
;
if
(
isUrl
)
{
props
.
schema_location
(
"urn:ietf:params:xml:ns:icalendar-2.0"
,
"../../../schemas/ical/kolabformat-xcal.xsd"
);
//Force schema
icalendar
=
icalendar_2_0
::
icalendar
(
s
,
0
,
props
);
}
else
{
props
.
schema_location
(
"urn:ietf:params:xml:ns:icalendar-2.0"
,
"/home/chrigi/work/kolab/xmlformat/libkolabxml/schemas/ical/kolabformat-xcal.xsd"
);
//Force schema
std
::
istringstream
is
(
s
);
icalendar
=
icalendar_2_0
::
icalendar
(
is
,
0
,
props
);
}
const
icalendar_2_0
::
VcalendarType
&
vcalendar
=
icalendar
->
vcalendar
();
QList
<
KCalCore
::
Event
::
Ptr
>
events
;
for
(
icalendar_2_0
::
VcalendarType
::
components_type
::
vevent_const_iterator
it
(
vcalendar
.
components
().
vevent
().
begin
());
it
!=
vcalendar
.
components
().
vevent
().
end
();
it
++
)
{
KCalCore
::
Event
::
Ptr
e
=
KCalCore
::
Event
::
Ptr
(
new
KCalCore
::
Event
());
const
icalendar_2_0
::
KolabEvent
&
event
=
*
it
;
readEvent
(
*
e
,
event
);
events
.
append
(
e
);
}
//TODO resolve events, exceptions can be identified based on the recurrence-id attribute
// foreach (KCalCore::Event * event, events) {
// if (!event->hasRecurrenceId()) {
// return event;
// }
// }
return
events
.
first
();
}
catch
(
const
xml_schema
::
exception
&
e
)
{
std
::
cout
<<
e
<<
std
::
endl
;
std
::
cout
<<
"Failed to read event!"
<<
std
::
endl
;
}
return
KCalCore
::
Event
::
Ptr
();
}
void
readEvent
(
KCalCore
::
Event
&
event
,
const
icalendar_2_0
::
KolabEvent
&
vevent
)
{
const
icalendar_2_0
::
KolabEvent
::
properties_type
&
prop
=
vevent
.
properties
();
setIncidenceProperties
(
event
,
prop
);
if
(
prop
.
dtend
())
{
KDateTime
date
;
kDebug
()
<<
"dtend"
;
event
.
setDtEnd
(
*
toDate
<
KCalCoreTypes
>
(
*
prop
.
dtend
()));
if
(
event
.
dtEnd
().
timeType
()
!=
event
.
dtStart
().
timeType
())
{
kWarning
()
<<
"dtEnd has wrong timespec"
;
}
}
else
if
(
prop
.
duration
())
{
// KCalCore::Duration duration.;
// event.setDuration(duration << prop.duration());
}
//TODO check for equality of timespecs
if
(
prop
.
transp
())
{
}
}
template
<
typename
T
>
std
::
string
writeEvent
(
typename
T
::
EventType
event
)
{
using
namespace
icalendar_2_0
;
try
{
typedef
DateTimeConverter
<
typename
T
::
DateType
>
DC
;
typedef
IncidenceConverter
<
typename
T
::
IncidenceType
>
IC
;
KolabEvent
::
components_type
eventComponents
;
IC
::
uid
(
event
);
IC
::
dtstamp
(
event
);
IC
::
created
(
event
);
KolabEvent
::
properties_type
::
uid_type
uid
(
event
->
uid
().
toStdString
());
//TODO thats possibly the kontact internal uid?
KolabEvent
::
properties_type
::
dtstamp_type
dtstamp
;
dtstamp
.
date_time
(
DC
::
fromDateTime
(
event
->
lastModified
()));
KolabEvent
::
properties_type
::
created_type
created
;
created
.
date_time
(
DC
::
fromDateTime
(
event
->
created
()));
KolabEvent
::
properties_type
eventProps
(
uid
,
created
,
dtstamp
);
KolabEvent
vevent
(
eventProps
,
eventComponents
);
writeEvent
(
vevent
,
*
event
);
VcalendarType
::
components_type
components
;
components
.
vevent
().
push_back
(
vevent
);
VcalendarType
::
properties_type
::
prodid_type
prodid
(
std
::
string
(
"libakonadi"
));
//TODO take from caller plus add libakonadi
VcalendarType
::
properties_type
::
version_type
version
(
std
::
string
(
"2.0"
));
//TODO define globally
VcalendarType
::
properties_type
::
x_kolab_version_type
x_kolab_version
(
std
::
string
(
"2.9.0"
));
//TODO define globally
VcalendarType
::
properties_type
properties
(
prodid
,
version
,
x_kolab_version
);
VcalendarType
vcalendar
(
properties
,
components
);
IcalendarType
icalendar
(
vcalendar
);
xml_schema
::
namespace_infomap
map
;
map
[
""
].
name
=
"urn:ietf:params:xml:ns:icalendar-2.0"
;
// map[""].schema = "note.xsd";
std
::
ostringstream
ostringstream
;
icalendar_2_0
::
icalendar
(
ostringstream
,
icalendar
,
map
);
return
ostringstream
.
str
();
}
catch
(
const
xml_schema
::
exception
&
e
)
{
return
std
::
string
();
}
}
std
::
string
writeEvent
(
KCalCore
::
Event
::
Ptr
event
)
{
return
writeEvent
<
KCalCoreTypes
>
(
event
);
}
void
writeEvent
(
icalendar_2_0
::
KolabEvent
&
vevent
,
const
KCalCore
::
Event
&
event
)
{
icalendar_2_0
::
KolabEvent
::
properties_type
&
prop
=
vevent
.
properties
();
getIncidenceProperties
(
prop
,
event
);
if
(
event
.
dtEnd
().
isValid
())
{
icalendar_2_0
::
properties
::
dtend_type
dtend
;
setDateTimeProperty
<
KCalCoreTypes
>
(
dtend
,
event
.
dtStart
());
prop
.
dtend
(
dtend
);
}
else
if
(
event
.
duration
()
!=
KCalCore
::
Duration
())
{
}
}
void
Test
::
test
()
{
std
::
cout
<<
"test"
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-c++
Expires
Mon, Apr 6, 1:07 AM (3 d, 7 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18831806
Default Alt Text
kolabformat.cpp (7 KB)
Attached To
Mode
rLKX libkolabxml
Attached
Detach File
Event Timeline