aboutsummaryrefslogtreecommitdiff
path: root/examples/GuiClient/mainDialog.cpp
diff options
context:
space:
mode:
authorManjeet Dahiya <manjeetdahiya@gmail.com>2010-10-14 06:31:00 +0000
committerManjeet Dahiya <manjeetdahiya@gmail.com>2010-10-14 06:31:00 +0000
commit207f28a8704a7d713373c8277f9fa23cd29f6eb3 (patch)
treeffd40cd09c78c44040b16746f1bfb831b8834da1 /examples/GuiClient/mainDialog.cpp
parent4eb75a59fc1758b8f08feae4f2a18745afdc1a37 (diff)
downloadqxmpp-207f28a8704a7d713373c8277f9fa23cd29f6eb3.tar.gz
implement vcardUpdate during send
Diffstat (limited to 'examples/GuiClient/mainDialog.cpp')
-rw-r--r--examples/GuiClient/mainDialog.cpp45
1 files changed, 38 insertions, 7 deletions
diff --git a/examples/GuiClient/mainDialog.cpp b/examples/GuiClient/mainDialog.cpp
index d6300121..9cc74097 100644
--- a/examples/GuiClient/mainDialog.cpp
+++ b/examples/GuiClient/mainDialog.cpp
@@ -373,6 +373,7 @@ void mainDialog::statusTextChanged(const QString& status)
{
QXmppPresence presence = m_xmppClient.clientPresence();
presence.status().setStatusText(status);
+ addPhotoHash(presence);
m_xmppClient.setClientPresence(presence);
}
@@ -388,6 +389,7 @@ void mainDialog::presenceTypeChanged(QXmppPresence::Type presenceType)
QXmppPresence newPresence = m_xmppClient.clientPresence();
newPresence.setType(presenceType);
newPresence.status().setType(QXmppPresence::Status::Online);
+ addPhotoHash(newPresence);
m_xmppClient.setClientPresence(newPresence);
}
m_statusWidget.setStatusText(
@@ -402,6 +404,7 @@ void mainDialog::presenceStatusTypeChanged(QXmppPresence::Status::Type statusTyp
else
presence.setType(QXmppPresence::Available);
presence.status().setType(statusType);
+ addPhotoHash(presence);
m_xmppClient.setClientPresence(presence);
m_statusWidget.setStatusText(
presenceToStatusText(m_xmppClient.clientPresence()));
@@ -409,17 +412,25 @@ void mainDialog::presenceStatusTypeChanged(QXmppPresence::Status::Type statusTyp
void mainDialog::avatarChanged(const QImage& image)
{
- QXmppVCardIq vcard;
+ QXmppVCardIq& vcard = m_vCardCache.getVCard(m_xmppClient.configuration().jidBare());
vcard.setType(QXmppIq::Set);
QByteArray ba;
QBuffer buffer(&ba);
- buffer.open(QIODevice::WriteOnly);
- image.save(&buffer, "PNG");
- vcard.setPhoto(ba);
-
- m_xmppClient.sendPacket(vcard);
- m_statusWidget.setAvatar(image);
+ if(buffer.open(QIODevice::WriteOnly))
+ {
+ if(image.save(&buffer, "PNG"))
+ {
+ vcard.setPhoto(ba);
+ m_xmppClient.sendPacket(vcard);
+ m_statusWidget.setAvatar(image);
+
+ // update photo hash
+ QXmppPresence presence = m_xmppClient.clientPresence();
+ addPhotoHash(presence);
+ m_xmppClient.setClientPresence(presence);
+ }
+ }
}
void mainDialog::updateStatusWidget()
@@ -824,3 +835,23 @@ void mainDialog::action_showXml()
{
m_consoleDlg.show();
}
+
+void mainDialog::addPhotoHash(QXmppPresence& pre)
+{
+ QString clientBareJid = m_xmppClient.configuration().jidBare();
+
+ if(m_vCardCache.isVCardAvailable(clientBareJid))
+ {
+ QByteArray hash = m_vCardCache.getPhotoHash(clientBareJid);
+ if(hash.isEmpty())
+ pre.setVCardUpdateType(QXmppPresence::PhotoNotAdvertized);
+ else
+ pre.setVCardUpdateType(QXmppPresence::PhotoAdvertised);
+ pre.setPhotoHash(hash);
+ }
+ else
+ {
+ pre.setVCardUpdateType(QXmppPresence::VCardUpdateNone);
+ pre.setPhotoHash(QByteArray());
+ }
+}