#include "vcard.h" ... VCard *vc = VCard::parseVCard(filename);
Because the dialog is non-modal, the vcard is destructed on destruction of the dialog.vcdlg = new KMDisplayVCard(vc); kernel->kbp()->idle(); vcdlg->show();
The message reader deals with vcard attachments in the following manner
The URL of the anchor begins with `part:´ and refers to the vcard attachment
If further checks (by parsing the vcard attachment) if the attachment contains a valid vcard
The same happens if the Icon which is representing the VCard attachment is clicked on.
VCard
Class
The usual way to construct a VCard object is by parsing it from a file (or from a message part):
On success, vc is different from#include "vcard.h" ... VCard *vc = VCard::parseVCard(filename);
NULL
and refers to a
valid VCard
object.It should be possible to construct a VCard from scratch (using the primitives VCard::addLine() and VCard::addQualifiedLine(). However, vcards are not created this way in KMail.
VCard
The methods getValue(...) and getValues(...) can be used to query data from a
VCard
object, either by querying by keyword, e.g.
or by keyword and qualifier, e.g.QString s = vc->getValue(VCARD_TEL);
There are also entrys (like name, address of the person) which do not consist of one single text string, but rather consist of a number of strings. These entries are then queried by the corresponding getValues(...) methods.QString s = vc->getValue(VCARD_TEL, VCARD_TEL_CELL);
Again, querying by keyword
or querying by keyword and qualifier, e.g.QStringList l = vc->getValues(VCARD_ADR);
is possible.QStringList l = vc->getValues(VCARD_ADR, VCARD_ADR_HOME);
Unfortunately, one has to know which entry has to be queried by
getValue()
and which one by getValues()
.
Have a look into kmdisplayvcard.cpp
for concrete examples.
Is there any vcard attached?void KMReaderWin::slotUrlPopup(const QString &aUrl, const QPoint& aPos) ... menu->insertItem(i18n("Open..."), this, SLOT(slotAtmOpen())); menu->insertItem(i18n("Open with..."), this, SLOT(slotAtmOpenWith())); menu->insertItem(i18n("View..."), this, SLOT(slotAtmView())); menu->insertItem(i18n("Save as..."), this, SLOT(slotAtmSave())); ...
Add "[vCard]" to the from-addressvoid KMReaderWin::parseMsg(KMMessage* aMsg) ... for (int j = 0; j < aMsg->numBodyParts(); j++) { ... if (!qstricmp(msgPart.typeStr(), "text") && !qstricmp(msgPart.subtypeStr(), "x-vcard")) { ... vc = VCard::parseVCard(msgPart.body(), &vcerr); if (vc) { ... vcnum = j; break; } } } writeMsgHeader(vcnum); ...
Opening a vCard...void KMReaderWin::writeMsgHeader(int vcpartnum) ... if (vcpartnum >= 0) { mViewer->write("<a href=\""+vcname+"\">"+i18n("[vCard]")+"</a>"); } ...
...or viewing it (part 1)void KMReaderWin::slotAtmOpen() { ... if (qstricmp(msgPart.typeStr(), "text") == 0) { if (qstricmp(msgPart.subtypeStr(), "x-vcard") == 0) { ... VCard *vc = VCard::parseVCard(msgPart.body(), &vcerr); ... vcdlg = new KMDisplayVCard(vc); vcdlg->show(); return; } }
(part 2)void KMReaderWin::slotAtmView() { KMMessagePart msgPart; mMsg->bodyPart(mAtmCurrent, &msgPart); QString pname = msgPart.fileName(); if (pname.isEmpty()) pname=msgPart.name(); if (pname.isEmpty()) pname=msgPart.contentDescription(); if (pname.isEmpty()) pname="unnamed"; // image Attachment is saved already atmView(this, &msgPart, htmlMail(), QString("%1part%2/%3").arg(mAttachDir). arg(mAtmCurrent+1).arg(pname), pname, mCodec); }
void KMReaderWin::atmView(KMReaderWin* aReaderWin, KMMessagePart* aMsgPart, bool aHTML, const QString& aFileName, const QString& pname, QTextCodec *codec) ... if (qstricmp(aMsgPart->typeStr(), "text")==0) { if (qstricmp(aMsgPart->subtypeStr(), "x-vcard") == 0) { ... VCard *vc = VCard::parseVCard(aMsgPart->body(), &vcerr); ... vcdlg = new KMDisplayVCard(vc); kernel->kbp()->idle(); vcdlg->show(); ...