kabc Library API Documentation

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