| # kabc Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# testread.cpp

    00001 #include <iostream>
    00002 #include <stdlib.h>
    00003 #include <assert.h>
    00004
    00005 #include <qfile.h>
    00006 #include <qtextstream.h>
    00007
    00008 #include <VCard.h>
    00009
    00010 using namespace std;
    00011
    00012 int main(int argc, char * argv[])
    00013 {
    00014     if (argc != 2) {
    00015         cerr << "Usage: " << argv[0] << " <filename>" << endl;
    00016         exit(1);
    00017     }
    00018
    00019     QFile f(argv[1]);
    00020
    00021     QCString str;
    00022
    00023     if (!f.open(IO_ReadOnly)) {
    00024         cerr << "Couldn't open file \"" << argv[1] << endl;
    00025         exit(1);
    00026     }
    00027
    00028     QTextStream t(&f);
    00029
    00030     while (!t.eof())
    00031         str += t.readLine().utf8() + '\n';
    00032
    00033     using namespace VCARD;
    00034
    00035     // Iterate through all vCards in the file.
    00036
    00037         cout << "--------- begin ----------" << endl;
    00038         cout << str.data();
    00039         cout << "---------  end  ----------" << endl;
    00040
    00041     VCardEntity e(str);
    00042
    00043     VCardListIterator it(e.cardList());
    00044
    00045     for (; it.current(); ++it) {
    00046
    00047         cerr << "****************** VCARD ********************" << endl;
    00048
    00049         // Create a vcard using the string representation.
    00050         VCard & v (*it.current());
    00051
    00052         if (v.has(EntityEmail)) {
    00053             cerr << "Email parameter found" << endl;
    00054
    00055             QCString s = v.contentLine(EntityEmail)->value()->asString();
    00056
    00057             cerr << "Email value == " << s << endl;
    00058         }
    00059
    00060         if (v.has(EntityNickname)) {
    00061             cerr << "Nickname parameter found" << endl;
    00062
    00063             cerr << "Nickname value == " <<
    00064                 v.contentLine(EntityNickname)->value()->asString() <<
    00065                 endl;
    00066         }
    00067
    00068         if (v.has(EntityRevision)) {
    00069
    00070             cerr << "Revision parameter found" << endl;
    00071
    00072             DateValue * d =
    00073                 (DateValue *)
    00074                 v.contentLine(EntityRevision)->value();
    00075
    00076             assert(d != 0);
    00077
    00078             cerr << "Revision date: " << endl;
    00079             cerr << "Day   : " << d->day()      << endl;
    00080             cerr << "Month : " << d->month()    << endl;
    00081             cerr << "Year  : " << d->year()     << endl;
    00082
    00083             if (d->hasTime()) {
    00084                 cerr << "Revision date has a time component" << endl;
    00085                 cerr << "Revision time: " << endl;
    00086                 cerr << "Hour   : " << d->hour()    << endl;
    00087                 cerr << "Minute : " << d->minute()  << endl;
    00088                 cerr << "Second : " << d->second()  << endl;
    00089
    00090             }
    00091             else cerr << "Revision date does NOT have a time component" << endl;
    00092         }
    00093
    00094         if (v.has(EntityURL)) {
    00095             cerr << "URL Parameter found" << endl;
    00096
    00097             cerr << "URL Value == " <<
    00098                 v.contentLine(EntityURL)->value()->asString() <<
    00099                 endl;
    00100
    00101             URIValue * urlVal =
    00102                 (URIValue *)v.contentLine(EntityURL)->value();
    00103
    00104             assert(urlVal != 0);
    00105
    00106             cerr << "URL scheme == " <<
    00107                 urlVal->scheme() << endl;
    00108
    00109             cerr << "URL scheme specific part == " <<
    00110                 urlVal->schemeSpecificPart() << endl;
    00111         }
    00112
    00113         if (v.has(EntityN)) {
    00114             cerr << "N Parameter found" << endl;
    00115
    00116             NValue * n =
    00117                 (NValue *)(v.contentLine(EntityN)->value());
    00118
    00119             cerr << "Family name  == " << n->family()   << endl;
    00120             cerr << "Given  name  == " << n->given()    << endl;
    00121             cerr << "Middle name  == " << n->middle()   << endl;
    00122             cerr << "Prefix       == " << n->prefix()   << endl;
    00123             cerr << "Suffix       == " << n->suffix()   << endl;
    00124         }
    00125
    00126         cerr << "***************** END VCARD ******************" << endl;
    00127     }
    00128 }
    00129

This file is part of the documentation for kabc Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:31:31 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003