[ekiga] External presence&status now get pushed to the presentities : things look nice
- From: Julien Puydt <jpuydt src gnome org>
- To: svn-commits-list gnome org
- Subject: [ekiga] External presence&status now get pushed to the presentities : things look nice
- Date: Thu, 11 Jun 2009 11:42:25 -0400 (EDT)
commit d6e83dfe65cdc613fe8e6e012b0c5f4492740091
Author: Julien Puydt <jpuydt noether localdomain>
Date: Tue Dec 2 18:41:46 2008 +0100
External presence&status now get pushed to the presentities : things look nice
lib/engine/components/loudmouth/loudmouth-heap.cpp | 25 ++++--
.../components/loudmouth/loudmouth-presentity.cpp | 89 +++++++++++++++++++-
.../components/loudmouth/loudmouth-presentity.h | 14 +++
3 files changed, 119 insertions(+), 9 deletions(-)
---
diff --git a/lib/engine/components/loudmouth/loudmouth-heap.cpp b/lib/engine/components/loudmouth/loudmouth-heap.cpp
index 10c838b..b388af5 100644
--- a/lib/engine/components/loudmouth/loudmouth-heap.cpp
+++ b/lib/engine/components/loudmouth/loudmouth-heap.cpp
@@ -150,11 +150,20 @@ LM::Heap::iq_handler (LmMessage* message)
LmHandlerResult
LM::Heap::presence_handler (LmMessage* message)
{
- const gchar* jid = lm_message_node_get_attribute (lm_message_get_node (message), "from");
- gmref_ptr<Presentity> item = find_item (jid);
+ const gchar* from_c = lm_message_node_get_attribute (lm_message_get_node (message), "from");
const gchar* type_attr = lm_message_node_get_attribute (lm_message_get_node (message), "type");
+ std::string base_jid;
+ std::string resource;
- std::cout << lm_message_node_to_string (lm_message_get_node (message)) << std::endl;
+ if (from_c != 0) {
+
+ std::string from (from_c);
+ std::string::size_type index = from.find ('/');
+ base_jid = std::string (from, 0, index);
+ resource = std::string (from, index + 1, std::string::npos);
+ }
+
+ gmref_ptr<Presentity> item = find_item (base_jid);
if (type_attr != NULL && strcmp (type_attr, "subscribe") == 0) {
@@ -168,7 +177,7 @@ LM::Heap::presence_handler (LmMessage* message)
name = item->get_name ();
} else {
- name = jid;
+ name = base_jid;
}
request.title (_("Authorization to see your presence"));
@@ -190,7 +199,7 @@ LM::Heap::presence_handler (LmMessage* message)
choices["later"] = _("decide later (also close or cancel this dialog)");
request.single_choice ("answer", _("Your answer is: "), "grant", choices);
- request.hidden ("jid", jid);
+ request.hidden ("jid", base_jid);
if (!questions.handle_request (&request)) {
@@ -202,10 +211,12 @@ LM::Heap::presence_handler (LmMessage* message)
}
} else {
- // FIXME: the rest of the presence handling comes here!
+ if (item) {
+
+ item->push_presence (resource, lm_message_get_node (message));
+ }
}
- std::cout << lm_message_node_to_string (lm_message_get_node (message)) << std::endl;
return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
}
diff --git a/lib/engine/components/loudmouth/loudmouth-presentity.cpp b/lib/engine/components/loudmouth/loudmouth-presentity.cpp
index 3b79d10..a6fb2ef 100644
--- a/lib/engine/components/loudmouth/loudmouth-presentity.cpp
+++ b/lib/engine/components/loudmouth/loudmouth-presentity.cpp
@@ -35,6 +35,7 @@
#include <iostream>
#include <string.h>
+#include <stdlib.h>
#include <glib/gi18n.h>
#include "form-request-simple.h"
@@ -76,13 +77,53 @@ LM::Presentity::get_name () const
const std::string
LM::Presentity::get_presence () const
{
- return "FIXME";
+ std::string result = "offline";
+
+ if ( !infos.empty ()) {
+
+ infos_type::const_iterator iter = infos.begin ();
+ ResourceInfo best = iter->second;
+ ++iter;
+ while (iter != infos.end ()) {
+
+ if (iter->second.priority > best.priority) {
+
+ best = iter->second;
+ }
+ }
+ if (best.presence == "") {
+
+ result = "online";
+ } else {
+
+ result = best.presence;
+ }
+ }
+
+ return result;
}
const std::string
LM::Presentity::get_status () const
{
- return "FIXME";
+ std::string result = "";
+
+ if ( !infos.empty ()) {
+
+ infos_type::const_iterator iter = infos.begin ();
+ ResourceInfo best = iter->second;
+ ++iter;
+ while (iter != infos.end ()) {
+
+ if (iter->second.priority > best.priority) {
+
+ best = iter->second;
+ }
+ }
+ result = best.status;
+ }
+
+ return result;
}
const std::string
@@ -162,6 +203,50 @@ LM::Presentity::update (LmMessageNode* item_)
}
void
+LM::Presentity::push_presence (const std::string resource,
+ LmMessageNode* presence)
+{
+ if (resource.empty ())
+ return;
+
+ ResourceInfo info;
+
+ LmMessageNode* priority = lm_message_node_find_child (presence, "priority");
+ if (priority != NULL) {
+
+ info.priority = atoi (lm_message_node_get_value (priority));
+
+ } else {
+
+ info.priority = 50;
+ }
+
+ LmMessageNode* status = lm_message_node_find_child (presence, "status");
+ if (status != NULL) {
+
+ info.status = lm_message_node_get_value (status);
+ }
+
+ LmMessageNode* away = lm_message_node_find_child (presence, "show");
+ if (away != NULL) {
+
+ info.presence = lm_message_node_get_value (away);
+ } else {
+
+ info.presence = "online";
+ }
+
+ infos[resource] = info;
+
+ if (info.presence == "unavailable") {
+
+ infos.erase (resource);
+ }
+
+ updated.emit ();
+}
+
+void
LM::Presentity::edit_presentity ()
{
Ekiga::FormRequestSimple request(sigc::mem_fun (this, &LM::Presentity::edit_presentity_form_submitted));
diff --git a/lib/engine/components/loudmouth/loudmouth-presentity.h b/lib/engine/components/loudmouth/loudmouth-presentity.h
index 7a9a871..0f2dd93 100644
--- a/lib/engine/components/loudmouth/loudmouth-presentity.h
+++ b/lib/engine/components/loudmouth/loudmouth-presentity.h
@@ -71,10 +71,24 @@ namespace LM
void update (LmMessageNode* item_);
+ void push_presence (const std::string resource,
+ LmMessageNode* presence);
+
private:
LmConnection* connection;
LmMessageNode* item;
+ struct ResourceInfo {
+
+ int priority;
+ std::string presence;
+ std::string status;
+ };
+
+ typedef std::map<std::string, ResourceInfo> infos_type;
+
+ infos_type infos;
+
void edit_presentity ();
void edit_presentity_form_submitted (bool submitted,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]