-rw-r--r-- | kabc/vcard/testread.cpp | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/kabc/vcard/testread.cpp b/kabc/vcard/testread.cpp new file mode 100644 index 0000000..919c661 --- a/dev/null +++ b/kabc/vcard/testread.cpp | |||
@@ -0,0 +1,129 @@ | |||
1 | #include <iostream> | ||
2 | #include <stdlib.h> | ||
3 | #include <assert.h> | ||
4 | |||
5 | #include <qfile.h> | ||
6 | #include <qtextstream.h> | ||
7 | |||
8 | #include <VCard.h> | ||
9 | |||
10 | using namespace std; | ||
11 | |||
12 | int main(int argc, char * argv[]) | ||
13 | { | ||
14 | if (argc != 2) { | ||
15 | cerr << "Usage: " << argv[0] << " <filename>" << endl; | ||
16 | exit(1); | ||
17 | } | ||
18 | |||
19 | QFile f(argv[1]); | ||
20 | |||
21 | QCString str; | ||
22 | |||
23 | if (!f.open(IO_ReadOnly)) { | ||
24 | cerr << "Couldn't open file \"" << argv[1] << endl; | ||
25 | exit(1); | ||
26 | } | ||
27 | |||
28 | QTextStream t(&f); | ||
29 | |||
30 | while (!t.eof()) | ||
31 | str += t.readLine().utf8() + '\n'; | ||
32 | |||
33 | using namespace VCARD; | ||
34 | |||
35 | // Iterate through all vCards in the file. | ||
36 | |||
37 | cout << "--------- begin ----------" << endl; | ||
38 | cout << str.data(); | ||
39 | cout << "--------- end ----------" << endl; | ||
40 | |||
41 | VCardEntity e(str); | ||
42 | |||
43 | VCardListIterator it(e.cardList()); | ||
44 | |||
45 | for (; it.current(); ++it) { | ||
46 | |||
47 | cerr << "****************** VCARD ********************" << endl; | ||
48 | |||
49 | // Create a vcard using the string representation. | ||
50 | VCard & v (*it.current()); | ||
51 | |||
52 | if (v.has(EntityEmail)) { | ||
53 | cerr << "Email parameter found" << endl; | ||
54 | |||
55 | QCString s = v.contentLine(EntityEmail)->value()->asString(); | ||
56 | |||
57 | cerr << "Email value == " << s << endl; | ||
58 | } | ||
59 | |||
60 | if (v.has(EntityNickname)) { | ||
61 | cerr << "Nickname parameter found" << endl; | ||
62 | |||
63 | cerr << "Nickname value == " << | ||
64 | v.contentLine(EntityNickname)->value()->asString() << | ||
65 | endl; | ||
66 | } | ||
67 | |||
68 | if (v.has(EntityRevision)) { | ||
69 | |||
70 | cerr << "Revision parameter found" << endl; | ||
71 | |||
72 | DateValue * d = | ||
73 | (DateValue *) | ||
74 | v.contentLine(EntityRevision)->value(); | ||
75 | |||
76 | assert(d != 0); | ||
77 | |||
78 | cerr << "Revision date: " << endl; | ||
79 | cerr << "Day : " << d->day() << endl; | ||
80 | cerr << "Month : " << d->month()<< endl; | ||
81 | cerr << "Year : " << d->year() << endl; | ||
82 | |||
83 | if (d->hasTime()) { | ||
84 | cerr << "Revision date has a time component" << endl; | ||
85 | cerr << "Revision time: " << endl; | ||
86 | cerr << "Hour : " << d->hour()<< endl; | ||
87 | cerr << "Minute : " << d->minute()<< endl; | ||
88 | cerr << "Second : " << d->second()<< endl; | ||
89 | |||
90 | } | ||
91 | else cerr << "Revision date does NOT have a time component" << endl; | ||
92 | } | ||
93 | |||
94 | if (v.has(EntityURL)) { | ||
95 | cerr << "URL Parameter found" << endl; | ||
96 | |||
97 | cerr << "URL Value == " << | ||
98 | v.contentLine(EntityURL)->value()->asString() << | ||
99 | endl; | ||
100 | |||
101 | URIValue * urlVal = | ||
102 | (URIValue *)v.contentLine(EntityURL)->value(); | ||
103 | |||
104 | assert(urlVal != 0); | ||
105 | |||
106 | cerr << "URL scheme == " << | ||
107 | urlVal->scheme() << endl; | ||
108 | |||
109 | cerr << "URL scheme specific part == " << | ||
110 | urlVal->schemeSpecificPart() << endl; | ||
111 | } | ||
112 | |||
113 | if (v.has(EntityN)) { | ||
114 | cerr << "N Parameter found" << endl; | ||
115 | |||
116 | NValue * n = | ||
117 | (NValue *)(v.contentLine(EntityN)->value()); | ||
118 | |||
119 | cerr << "Family name == " << n->family()<< endl; | ||
120 | cerr << "Given name == " << n->given()<< endl; | ||
121 | cerr << "Middle name == " << n->middle()<< endl; | ||
122 | cerr << "Prefix == " << n->prefix()<< endl; | ||
123 | cerr << "Suffix == " << n->suffix()<< endl; | ||
124 | } | ||
125 | |||
126 | cerr << "***************** END VCARD ******************" << endl; | ||
127 | } | ||
128 | } | ||
129 | |||