summaryrefslogtreecommitdiffstats
path: root/tdeabc/vcard21parser.h
blob: c6c75a3c8328d7392040fc80792f5ec2e62f620d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
    This file is part of libtdeabc.

    Copyright (c) 2002 Mark Westcott <mark@houseoffish.org>
    Copyright (c) 2000 George Staikos <staikos@kde.org>
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#ifndef KABC_VCARD21FORMAT_H
#define KABC_VCARD21FORMAT_H

#include <tqdatetime.h>
#include <kdebug.h>
#include <tqregexp.h>
#include <tqstring.h>
#include <kurl.h>
#include <tqvaluelist.h>

#include "addressee.h"
#include "addressbook.h"
#include "phonenumber.h"


#define VCARD_BEGIN          "begin:vcard"
#define VCARD_END            "end:vcard"
#define VCARD_BEGIN_N        "begin"
#define VCARD_END_N          "end"
#define VCARD_VERSION        "version"

#define VCARD_FN             "fn"
#define VCARD_N              "n"

// optional
#define VCARD_NAME           "name"
#define VCARD_NICKNAME       "nickname"
#define VCARD_PHOTO          "photo"
#define VCARD_BDAY           "bday"
#define VCARD_ADR            "adr"

// types
#define VCARD_ADR_DOM      "dom"
#define VCARD_ADR_INTL     "intl"
#define VCARD_ADR_POSTAL   "postal"
#define VCARD_ADR_PARCEL   "parcel"
#define VCARD_ADR_HOME     "home"
#define VCARD_ADR_WORK     "work"
#define VCARD_ADR_PREF     "pref"
// values
#define VCARD_ADR_POBOX    "PO Box"
#define VCARD_ADR_EXTADR   "Extended Address"
#define VCARD_ADR_STREET   "Street"
#define VCARD_ADR_LOCALITY "Locality"
#define VCARD_ADR_REGION   "Region"
#define VCARD_ADR_POSTCODE "Postal Code"
#define VCARD_ADR_COUNTRY  "Country Name"
#define VCARD_LABEL          "label"
#define VCARD_PROFILE        "profile"
#define VCARD_SOURCE         "source"
#define VCARD_TEL            "tel"
// types
#define VCARD_TEL_HOME     "home"
#define VCARD_TEL_WORK     "work"
#define VCARD_TEL_PREF     "pref"
#define VCARD_TEL_VOICE    "voice"
#define VCARD_TEL_FAX      "fax"
#define VCARD_TEL_MSG      "msg"
#define VCARD_TEL_CELL     "cell"
#define VCARD_TEL_PAGER    "pager"
#define VCARD_TEL_BBS      "bbs"
#define VCARD_TEL_MODEM    "modem"
#define VCARD_TEL_CAR      "car"
#define VCARD_TEL_ISDN     "isdn"
#define VCARD_TEL_VIDEO    "video"
#define VCARD_TEL_PCS      "pcs"
#define VCARD_EMAIL        "email"
// types
#define VCARD_EMAIL_PREF    "pref"
#define VCARD_EMAIL_INTERNET "internet"
#define VCARD_EMAIL_X400   "x400"
#define VCARD_TZ             "tz"
#define VCARD_GEO            "geo"
#define VCARD_MAILER         "mailer"
#define VCARD_TITLE          "title"
#define VCARD_ROLE           "role"
#define VCARD_LOGO           "logo"
#define VCARD_AGENT          "agent"
#define VCARD_ORG            "org"
#define VCARD_CATEGORIES     "categories"
#define VCARD_NOTE           "note"
#define VCARD_PRODID         "prodid"
#define VCARD_REV            "rev"
#define VCARD_SOUND          "sound"
#define VCARD_UID            "uid"
#define VCARD_URL            "url"
#define VCARD_CLASS          "class"
#define VCARD_CLASS_PUBLIC "public"
#define VCARD_CLASS_PRIVATE "private"
#define VCARD_CLASS_CONFIDENTIAL "confidential"
#define VCARD_KEY            "key"
// types
#define VCARD_KEY_X509     "x509"
#define VCARD_KEY_PGP      "pgp"

#define VCARD_QUOTED_PRINTABLE "quoted-printable"
// this one is a temporary hack until we support TYPE=VALUE
#define VCARD_ENCODING_QUOTED_PRINTABLE "encoding=quoted-printable"
#define VCARD_BASE64           "base64"

#define VC_STATE_BEGIN          1
#define VC_STATE_BODY           2
#define VC_STATE_END            4
#define VC_STATE_HAVE_N         8
#define VC_STATE_HAVE_VERSION  16

#define VC_ERR_NO_BEGIN            1
#define VC_ERR_NO_END              2
#define VC_ERR_INVALID_LINE        3
#define VC_ERR_INTERNAL            4
#define VC_ERR_INVALID_NAME        5
#define VC_ERR_MISSING_MANDATORY   6

namespace TDEABC {

class AddressBook;

/**
  @deprecated use VCardConverter instead.
 */
class KABC_EXPORT_DEPRECATED VCard21Parser
{
public:

  /**
   * Constructor.
   */
  VCard21Parser();

  /**
   * Destructor.
   */
  virtual ~VCard21Parser();

  /**
   * Parses a string in vcard2.1 format and saves the single addressees
   * to the address book.
   *
   * @param ab  The address book.
   * @param str The vcard string.
   */
  void readFromString( TDEABC::AddressBook *ab, const TQString &str );

  /**
   * FIXME: we need a writeToString method
   * TQString writeToString (TDEABC::AddressBook *);
   */

  /**
   * Parses a string in vcard2.1 format and returns the inherent addressee.
   */
  TDEABC::Addressee readFromString( const TQString &data);

  /**
   * Helper method to store a address.
   *
   * @param data  A string list, that is filled with 'street', 'house number' ...
   * @param type  The type of the returned address.
   */
  static TDEABC::Address readAddressFromQStringList (const TQStringList &data, const int type);
};

}

/**
 * @short Helper class
 */
class KABC_EXPORT VCardLineX
{
public:
  TQString name;
  bool qualified;
  TQValueList<TQString> qualifiers;
  TQValueList<TQString> parameters;
  bool isValid() const;
};

/**
 * @short Helper class
 */
class KABC_EXPORT VCard21ParserImpl
{
  friend class VCardLineX;

public:
  VCard21ParserImpl();
  virtual ~VCard21ParserImpl();
  static VCard21ParserImpl *parseVCard(const TQString& vc, int *err = NULL);
  TQString getValue(const TQString& name, const TQString& qualifier);
  TQString getValue(const TQString& name);
  TQStringList getValues(const TQString& name, const TQString& qualifier);
  TQStringList getValues(const TQString& name);

  TQValueList<VCardLineX> *_vcdata;

private:
  VCard21ParserImpl (TQValueList<VCardLineX> *_vcd);
};

#endif