summaryrefslogtreecommitdiffabout
path: root/kabc/vcardconverter.cpp
authorzautrix <zautrix>2004-06-26 19:01:18 (UTC)
committer zautrix <zautrix>2004-06-26 19:01:18 (UTC)
commitb9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff)
tree2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /kabc/vcardconverter.cpp
downloadkdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2
Initial revision
Diffstat (limited to 'kabc/vcardconverter.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/vcardconverter.cpp115
1 files changed, 115 insertions, 0 deletions
diff --git a/kabc/vcardconverter.cpp b/kabc/vcardconverter.cpp
new file mode 100644
index 0000000..266cdf9
--- a/dev/null
+++ b/kabc/vcardconverter.cpp
@@ -0,0 +1,115 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28//US
29#include "kglobal.h"
30
31#include "vcard21parser.h"
32#include "vcardformatimpl.h"
33
34#include "vcardconverter.h"
35
36using namespace KABC;
37
38struct VCardConverter::VCardConverterData
39{
40 VCard21Parser vcard21parser;
41 VCardFormatImpl vcard30parser;
42};
43
44VCardConverter::VCardConverter()
45 : d( new VCardConverterData )
46{
47}
48
49VCardConverter::~VCardConverter()
50{
51 delete d;
52 d = 0;
53}
54
55bool VCardConverter::vCardToAddressee( const QString &str, Addressee &addr, Version version )
56{
57 if ( version == v2_1 ) {
58 addr = d->vcard21parser.readFromString( str );
59 return true;
60 }
61
62 if ( version == v3_0 )
63 return d->vcard30parser.readFromString( str, addr );
64
65 return false;
66}
67
68bool VCardConverter::addresseeToVCard( const Addressee &addr, QString &str, Version version )
69{
70 if ( version == v2_1 )
71 return false;
72
73 if ( version == v3_0 )
74 return d->vcard30parser.writeToString( addr, str );
75
76 return false;
77}
78
79
80/* Helper functions */
81
82QString KABC::dateToVCardString( const QDateTime &dateTime )
83{
84qDebug("vcardconverter.cpp : KABC::dateToVCardString transformation does not work yet");
85 return KGlobal::locale()->formatDate(dateTime.date(), true);
86//US return dateTime.toString("yyyyMMddThhmmssZ");
87}
88
89QString KABC::dateToVCardString( const QDate &date )
90{
91qDebug("vcardconverter.cpp : KABC::dateToVCardString transformation does not work yet");
92 return KGlobal::locale()->formatDate(date, true);
93//US return date.toString("yyyyMMdd");
94}
95
96QDateTime KABC::VCardStringToDate( const QString &dateString )
97{
98 QDate date;
99 QTime time;
100 QString d( dateString );
101
102//US I hope this is correct
103//US d = d.remove('-').remove(':');
104 d = d.replace( QRegExp("-"), "" );
105 d = d.replace( QRegExp(":"), "" );
106
107
108 if (d.length()>=8)
109 date = QDate( d.mid(0,4).toUInt(), d.mid(4,2).toUInt(), d.mid(6,2).toUInt() );
110 if (d.length()>9 && d[8].upper()=='T')
111 time = QTime( d.mid(9,2).toUInt(), d.mid(11,2).toUInt(), d.mid(13,2).toUInt() );
112
113 return QDateTime( date, time );
114}
115