[ekiga] It's now possible to add a new roster item



commit 25d4428b35a71926743f22a3cd598ba9db7b8e9b
Author: Julien Puydt <jpuydt noether localdomain>
Date:   Sun Nov 30 13:38:23 2008 +0100

    It's now possible to add a new roster item

 lib/engine/components/loudmouth/loudmouth-heap.cpp |   60 +++++++++++++++++++-
 lib/engine/components/loudmouth/loudmouth-heap.h   |    5 ++
 2 files changed, 63 insertions(+), 2 deletions(-)
---
diff --git a/lib/engine/components/loudmouth/loudmouth-heap.cpp b/lib/engine/components/loudmouth/loudmouth-heap.cpp
index d4b58c3..d356e90 100644
--- a/lib/engine/components/loudmouth/loudmouth-heap.cpp
+++ b/lib/engine/components/loudmouth/loudmouth-heap.cpp
@@ -35,6 +35,9 @@
 
 #include <iostream>
 #include <string.h>
+#include <glib/gi18n.h>
+
+#include "form-request-simple.h"
 
 #include "loudmouth-heap.h"
 
@@ -83,9 +86,10 @@ LM::Heap::get_name () const
 }
 
 bool
-LM::Heap::populate_menu (Ekiga::MenuBuilder& /*builder*/)
+LM::Heap::populate_menu (Ekiga::MenuBuilder& builder)
 {
-  return false;
+  builder.add_action ("new", _("New _Contact"), sigc::mem_fun (this, &LM::Heap::add_item));
+  return true;
 }
 
 bool
@@ -156,3 +160,55 @@ LM::Heap::parse_roster (LmMessageNode* query)
     }
   }
 }
+
+void
+LM::Heap::add_item ()
+{
+  Ekiga::FormRequestSimple request(sigc::mem_fun (this, &LM::Heap::add_item_form_submitted));
+
+  request.title (_("Add a roster element"));
+  request.instructions (_("Please fill in this form to add a new"
+			  "element to the remote roster"));
+  request.text ("jid", _("Identifier:"), _("id server"));
+
+  if (!questions.handle_request (&request)) {
+
+    // FIXME: better error reporting
+#ifdef __GNUC__
+    std::cout << "Unhandled form request in "
+	      << __PRETTY_FUNCTION__ << std::endl;
+#endif
+  }
+}
+
+void
+LM::Heap::add_item_form_submitted (bool submitted,
+				   Ekiga::Form& result)
+{
+  if ( !submitted)
+    return;
+
+  try {
+
+    const std::string jid = result.text ("jid");
+
+    if ( !jid.empty ()) {
+
+      LmMessage* message = lm_message_new_with_sub_type (NULL, LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_SET);
+      LmMessageNode* query = lm_message_node_add_child (lm_message_get_node (message), "query", NULL);
+      lm_message_node_set_attribute (query, "xmlns", "jabber:iq:roster");
+      LmMessageNode* node = lm_message_node_add_child (query, "item", NULL);
+      lm_message_node_set_attributes (node,
+				      "jid", jid.c_str (),
+				      NULL);
+
+      lm_connection_send (connection, message, NULL);
+      lm_message_unref (message);
+    }
+  } catch (Ekiga::Form::not_found) {
+#ifdef __GNUC__
+    std::cerr << "Invalid form submitted to "
+	      << __PRETTY_FUNCTION__ << std::endl;
+#endif
+  }
+}
diff --git a/lib/engine/components/loudmouth/loudmouth-heap.h b/lib/engine/components/loudmouth/loudmouth-heap.h
index 35b08ee..98ce710 100644
--- a/lib/engine/components/loudmouth/loudmouth-heap.h
+++ b/lib/engine/components/loudmouth/loudmouth-heap.h
@@ -70,6 +70,11 @@ namespace LM
     LmMessageHandler* iq_lm_handler;
 
     void parse_roster (LmMessageNode* query);
+
+    void add_item ();
+
+    void add_item_form_submitted (bool submitted,
+				  Ekiga::Form& result);
   };
 };
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]