~ubuntu-branches/ubuntu/karmic/kdepim/karmic-backports

« back to all changes in this revision

Viewing changes to akonadi/resources/kolabproxy/journal.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi, Alessandro Ghersi, Harald Sitter
  • Date: 2009-06-27 04:40:05 UTC
  • mfrom: (1.1.39 upstream)
  • Revision ID: james.westby@ubuntu.com-20090627044005-4y2vm9xz7rvmzi4p
Tags: 4:4.2.95svn20090701-0ubuntu1
[ Alessandro Ghersi ]
* New upstream release
  - Bump build-deps
* Remove akonadi-kde and libmaildir4 packages
  - remove akonadi-kde.install and libmaildir4.install
  - remove libmaildir4 from debian/rules
  - remove akonadi-kde and libmaildir4 from depends
  - remove akonadi-kde and libmaildir4 from installgen
* Update kdepim-dev.install
* Update kpilot.install
* Add akonadi-kde and libmaildir4 transitional packages

[ Harald Sitter ]
* KAddressbook replaces Kontact << 4.2.85 (LP: #378373)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    This file is part of the kolab resource - the implementation of the
 
3
    Kolab storage format. See www.kolab.org for documentation on this.
 
4
 
 
5
    Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk>
 
6
 
 
7
    This library is free software; you can redistribute it and/or
 
8
    modify it under the terms of the GNU Library General Public
 
9
    License as published by the Free Software Foundation; either
 
10
    version 2 of the License, or (at your option) any later version.
 
11
 
 
12
    This library is distributed in the hope that it will be useful,
 
13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
    Library General Public License for more details.
 
16
 
 
17
    You should have received a copy of the GNU Library General Public License
 
18
    along with this library; see the file COPYING.LIB.  If not, write to
 
19
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
20
    Boston, MA 02110-1301, USA.
 
21
 
 
22
    In addition, as a special exception, the copyright holders give
 
23
    permission to link the code of this program with any edition of
 
24
    the Qt library by Trolltech AS, Norway (or with modified versions
 
25
    of Qt that use the same license as Qt), and distribute linked
 
26
    combinations including the two.  You must obey the GNU General
 
27
    Public License in all respects for all of the code used other than
 
28
    Qt.  If you modify this file, you may extend this exception to
 
29
    your version of the file, but you are not obligated to do so.  If
 
30
    you do not wish to do so, delete this exception statement from
 
31
    your version.
 
32
*/
 
33
 
 
34
#include "journal.h"
 
35
#include "kdepim-version.h"
 
36
 
 
37
#include <kcal/journal.h>
 
38
#include <kdebug.h>
 
39
 
 
40
static const char korgVersion[] = KDEPIM_VERSION;
 
41
 
 
42
using namespace Kolab;
 
43
 
 
44
 
 
45
KCal::Journal* Journal::xmlToJournal( const QString& xml, const QString& tz )
 
46
{
 
47
  Journal journal( tz );
 
48
  journal.load( xml );
 
49
  KCal::Journal* kcalJournal = new KCal::Journal();
 
50
  journal.saveTo( kcalJournal );
 
51
  return kcalJournal;
 
52
}
 
53
 
 
54
QString Journal::journalToXML( KCal::Journal* kcalJournal, const QString& tz )
 
55
{
 
56
  Journal journal( tz, kcalJournal );
 
57
  return journal.saveXML();
 
58
}
 
59
 
 
60
Journal::Journal( const QString& tz, KCal::Journal* journal )
 
61
  : KolabBase( tz )
 
62
{
 
63
  if ( journal )
 
64
    setFields( journal );
 
65
}
 
66
 
 
67
Journal::~Journal()
 
68
{
 
69
}
 
70
 
 
71
void Journal::setSummary( const QString& summary )
 
72
{
 
73
  mSummary = summary;
 
74
}
 
75
 
 
76
QString Journal::summary() const
 
77
{
 
78
  return mSummary;
 
79
}
 
80
 
 
81
void Journal::setStartDate( const KDateTime& startDate )
 
82
{
 
83
  mStartDate = startDate;
 
84
}
 
85
 
 
86
KDateTime Journal::startDate() const
 
87
{
 
88
  return mStartDate;
 
89
}
 
90
 
 
91
void Journal::setEndDate( const KDateTime& endDate )
 
92
{
 
93
  mEndDate = endDate;
 
94
}
 
95
 
 
96
KDateTime Journal::endDate() const
 
97
{
 
98
  return mEndDate;
 
99
}
 
100
 
 
101
bool Journal::loadAttribute( QDomElement& element )
 
102
{
 
103
  QString tagName = element.tagName();
 
104
 
 
105
  if ( tagName == "summary" )
 
106
    setSummary( element.text() );
 
107
  else if ( tagName == "start-date" )
 
108
    setStartDate( stringToDateTime( element.text() ) );
 
109
  else
 
110
    // Not handled here
 
111
    return KolabBase::loadAttribute( element );
 
112
 
 
113
  // We handled this
 
114
  return true;
 
115
}
 
116
 
 
117
bool Journal::saveAttributes( QDomElement& element ) const
 
118
{
 
119
  // Save the base class elements
 
120
  KolabBase::saveAttributes( element );
 
121
 
 
122
  writeString( element, "summary", summary() );
 
123
  writeString( element, "start-date", dateTimeToString( startDate() ) );
 
124
 
 
125
  return true;
 
126
}
 
127
 
 
128
 
 
129
bool Journal::loadXML( const QDomDocument& document )
 
130
{
 
131
  QDomElement top = document.documentElement();
 
132
 
 
133
  if ( top.tagName() != "journal" ) {
 
134
    qWarning( "XML error: Top tag was %s instead of the expected Journal",
 
135
              top.tagName().toAscii().data() );
 
136
    return false;
 
137
  }
 
138
 
 
139
  for ( QDomNode n = top.firstChild(); !n.isNull(); n = n.nextSibling() ) {
 
140
    if ( n.isComment() )
 
141
      continue;
 
142
    if ( n.isElement() ) {
 
143
      QDomElement e = n.toElement();
 
144
      if ( !loadAttribute( e ) ) {
 
145
        // Unhandled tag - save for later storage
 
146
        //qDebug( "Unhandled tag: %s", e.toCString().data() );
 
147
      }
 
148
    } else
 
149
      qDebug( "Node is not a comment or an element???" );
 
150
  }
 
151
 
 
152
  return true;
 
153
}
 
154
 
 
155
QString Journal::saveXML() const
 
156
{
 
157
  QDomDocument document = domTree();
 
158
  QDomElement element = document.createElement( "journal" );
 
159
  element.setAttribute( "version", "1.0" );
 
160
  saveAttributes( element );
 
161
  document.appendChild( element );
 
162
  return document.toString();
 
163
}
 
164
 
 
165
void Journal::saveTo( KCal::Journal* journal )
 
166
{
 
167
  KolabBase::saveTo( journal );
 
168
 
 
169
  journal->setSummary( summary() );
 
170
  journal->setDtStart( utcToLocal( startDate() ) );
 
171
}
 
172
 
 
173
void Journal::setFields( const KCal::Journal* journal )
 
174
{
 
175
  // Set baseclass fields
 
176
  KolabBase::setFields( journal );
 
177
 
 
178
  // Set our own fields
 
179
  setSummary( journal->summary() );
 
180
  setStartDate( localToUTC( journal->dtStart() ) );
 
181
}
 
182
 
 
183
QString Journal::productID() const
 
184
{
 
185
  return QString( "KOrganizer " ) + korgVersion + ", Kolab resource";
 
186
}