ekiga r7143 - in trunk: . lib/engine lib/engine/components lib/engine/components/resource-list



Author: jpuydt
Date: Thu Oct  2 13:06:23 2008
New Revision: 7143
URL: http://svn.gnome.org/viewvc/ekiga?rev=7143&view=rev

Log:
New resource-list code, using the XCAP code

Added:
   trunk/lib/engine/components/resource-list/
   trunk/lib/engine/components/resource-list/Makefile.am
   trunk/lib/engine/components/resource-list/resource-list-main.cpp
   trunk/lib/engine/components/resource-list/resource-list-main.h
   trunk/lib/engine/components/resource-list/rl-cluster.cpp
   trunk/lib/engine/components/resource-list/rl-cluster.h
   trunk/lib/engine/components/resource-list/rl-heap.cpp
   trunk/lib/engine/components/resource-list/rl-heap.h
   trunk/lib/engine/components/resource-list/rl-presentity.cpp
   trunk/lib/engine/components/resource-list/rl-presentity.h
Modified:
   trunk/ChangeLog
   trunk/configure.ac
   trunk/lib/engine/Makefile.am
   trunk/lib/engine/components/Makefile.am
   trunk/lib/engine/engine.cpp

Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac	(original)
+++ trunk/configure.ac	Thu Oct  2 13:06:23 2008
@@ -610,10 +610,11 @@
 
 if test "x$enable_xcap" = "xyes"; then
    PKG_CHECK_MODULES([SOUP], [libsoup-2.4])
-   found_xcap="yes"
+   found_xcap=yes
    XCAP="enabled"
    AC_SUBST(SOUP_CFLAGS)
    AC_SUBST(SOUP_LIBS)
+  AC_DEFINE(HAVE_XCAP,1,[XCAP support])
 fi
 
 AM_CONDITIONAL(HAVE_XCAP, test "x$found_xcap" = "xyes")
@@ -809,6 +810,7 @@
 lib/engine/components/avahi-publisher/Makefile
 lib/engine/components/gstreamer/Makefile
 lib/engine/components/kde/Makefile
+lib/engine/components/resource-list/Makefile
 lib/engine/components/xcap/Makefile
 )
 

Modified: trunk/lib/engine/Makefile.am
==============================================================================
--- trunk/lib/engine/Makefile.am	(original)
+++ trunk/lib/engine/Makefile.am	Thu Oct  2 13:06:23 2008
@@ -28,6 +28,7 @@
 	-I$(top_srcdir)/lib/engine/components/avahi-publisher		\
 	-I$(top_srcdir)/lib/engine/components/gstreamer			\
 	-I$(top_srcdir)/lib/engine/components/kde			\
+	-I$(top_srcdir)/lib/engine/components/resource-list		\
 	-I$(top_srcdir)/lib/engine/components/xcap
 
 # XVideo/X
@@ -146,7 +147,9 @@
 endif
 
 if HAVE_XCAP
-libekiga_engine_la_LIBADD += components/xcap/libgmxcap.la
+libekiga_engine_la_LIBADD += \
+	components/xcap/libgmxcap.la \
+	components/resource-list/libgmresource_list.la
 endif
 
 #### FIXME should be removed at a later stage

Modified: trunk/lib/engine/components/Makefile.am
==============================================================================
--- trunk/lib/engine/components/Makefile.am	(original)
+++ trunk/lib/engine/components/Makefile.am	Thu Oct  2 13:06:23 2008
@@ -11,7 +11,7 @@
 endif
 
 if HAVE_XCAP
-XCAP_DIR = xcap
+XCAP_DIRS = xcap resource-list
 endif
 
 SUBDIRS = \
@@ -19,4 +19,4 @@
 	$(AVAHI_DIR) \
 	$(GSTREAMER_DIR) \
 	$(KDE_DIR) \
-	$(XCAP_DIR)
\ No newline at end of file
+	$(XCAP_DIRS)
\ No newline at end of file

Added: trunk/lib/engine/components/resource-list/Makefile.am
==============================================================================
--- (empty file)
+++ trunk/lib/engine/components/resource-list/Makefile.am	Thu Oct  2 13:06:23 2008
@@ -0,0 +1,24 @@
+noinst_LTLIBRARIES = libgmresource_list.la
+
+resource_list_dir = $(top_srcdir)/lib/engine/components/resource-list/
+
+AM_CXXFLAGS = $(SIGC_CFLAGS) $(GLIB_CFLAGS) $(XML_CFLAGS)
+
+INCLUDES = 						\
+	-I$(top_srcdir)/lib/gmconf			\
+	-I$(top_srcdir)/lib/engine/framework		\
+	-I$(top_srcdir)/lib/engine/presence/skel	\
+	-I$(top_srcdir)/lib/engine/account/skel		\
+	-I$(top_srcdir)/lib/engine/components/xcap
+
+libgmresource_list_la_SOURCES = \
+	$(resource_list_dir)/resource-list-main.h \
+	$(resource_list_dir)/resource-list-main.cpp \
+	$(resource_list_dir)/rl-presentity.h \
+	$(resource_list_dir)/rl-presentity.cpp \
+	$(resource_list_dir)/rl-heap.h \
+	$(resource_list_dir)/rl-heap.cpp \
+	$(resource_list_dir)/rl-cluster.h \
+	$(resource_list_dir)/rl-cluster.cpp
+
+libgmresource_list_la_LDFLAGS = -export-dynamic -no-undefined $(SIGC_LIBS) $(GLIB_LIBS) $(XML_LIBS)

Added: trunk/lib/engine/components/resource-list/resource-list-main.cpp
==============================================================================
--- (empty file)
+++ trunk/lib/engine/components/resource-list/resource-list-main.cpp	Thu Oct  2 13:06:23 2008
@@ -0,0 +1,70 @@
+
+/* Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2008 Damien Sandras
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *
+ * Ekiga is licensed under the GPL license and as a special exception,
+ * you have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination,
+ * without applying the requirements of the GNU GPL to the OPAL, OpenH323
+ * and PWLIB programs, as long as you do follow the requirements of the
+ * GNU GPL for all the rest of the software thus combined.
+ */
+
+
+/*
+ *                         resource-list-main.cpp  -  description
+ *                         ------------------------------------------
+ *   begin                : written in 2008 by Julien Puydt
+ *   copyright            : (c) 2008 by Julien Puydt
+ *   description          : code to hook the resource-list code
+ *                          to the main program
+ *
+ */
+
+#include "resource-list-main.h"
+#include "presence-core.h"
+#include "rl-cluster.h"
+
+bool
+resource_list_init (Ekiga::ServiceCore& services,
+		    int* /*argc*/,
+		    char** /*argv*/[])
+{
+  bool result = false;
+  Ekiga::Service* service = NULL;
+
+  service = services.get ("resource-list");
+
+  if (service == NULL) {
+
+    Ekiga::PresenceCore* core = NULL;
+    XCAP::Core* xcap = NULL;
+
+    core = dynamic_cast<Ekiga::PresenceCore*>(services.get ("presence-core"));
+    xcap = dynamic_cast<XCAP::Core*>(services.get ("xcap-core"));
+    if (core != NULL && xcap != NULL) {
+
+      RL::Cluster* cluster = new RL::Cluster (services);
+      services.add (*cluster);
+      core->add_cluster (*cluster);
+      result = true;
+    }
+  }
+
+  return result;
+}

Added: trunk/lib/engine/components/resource-list/resource-list-main.h
==============================================================================
--- (empty file)
+++ trunk/lib/engine/components/resource-list/resource-list-main.h	Thu Oct  2 13:06:23 2008
@@ -0,0 +1,48 @@
+
+/* Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2008 Damien Sandras
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *
+ * Ekiga is licensed under the GPL license and as a special exception,
+ * you have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination,
+ * without applying the requirements of the GNU GPL to the OPAL, OpenH323
+ * and PWLIB programs, as long as you do follow the requirements of the
+ * GNU GPL for all the rest of the software thus combined.
+ */
+
+
+/*
+ *                         resource-list-main.h  -  description
+ *                         ------------------------------------------
+ *   begin                : written in 2008 by Julien Puydt
+ *   copyright            : (c) 2008 by Julien Puydt
+ *   description          : code to hook the resource-list code
+ *                          to the main program
+ *
+ */
+
+#ifndef __RL_MAIN_H__
+#define __RL_MAIN_H__
+
+#include "services.h"
+
+bool resource_list_init (Ekiga::ServiceCore& services,
+			 int* argc,
+			 char** argv[]);
+
+#endif

Added: trunk/lib/engine/components/resource-list/rl-cluster.cpp
==============================================================================
--- (empty file)
+++ trunk/lib/engine/components/resource-list/rl-cluster.cpp	Thu Oct  2 13:06:23 2008
@@ -0,0 +1,225 @@
+
+/* Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2008 Damien Sandras
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *
+ * Ekiga is licensed under the GPL license and as a special exception,
+ * you have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination,
+ * without applying the requirements of the GNU GPL to the OPAL, OpenH323
+ * and PWLIB programs, as long as you do follow the requirements of the
+ * GNU GPL for all the rest of the software thus combined.
+ */
+
+
+/*
+ *                         rlist-cluster.cpp  -  description
+ *                         ------------------------------------------
+ *   begin                : written in 2008 by Julien Puydt
+ *   copyright            : (c) 2008 by Julien Puydt
+ *   description          : resource-list cluster implementation
+ *
+ */
+
+#include "config.h"
+
+#include "rl-cluster.h"
+
+#include "gmconf.h"
+#include "form-request-simple.h"
+#include "presence-core.h"
+
+#include <iostream>
+
+#define KEY "/apps/" PACKAGE_NAME "/contacts/resource-lists"
+
+RL::Cluster::Cluster (Ekiga::ServiceCore& core_): core(core_), doc(NULL)
+{
+  gchar* c_raw = NULL;
+
+  Ekiga::PresenceCore* presence_core
+    = dynamic_cast<Ekiga::PresenceCore*>(core.get ("presence-core"));
+
+  presence_core->presence_received.connect (sigc::mem_fun (this, &RL::Cluster::on_presence_received));
+  presence_core->status_received.connect (sigc::mem_fun (this, &RL::Cluster::on_status_received));
+
+  c_raw = gm_conf_get_string (KEY);
+
+  if (c_raw != NULL) {
+
+    const std::string raw = c_raw;
+    doc = xmlRecoverMemory (raw.c_str (), raw.length ());
+
+    xmlNodePtr root = xmlDocGetRootElement (doc);
+    if (root == NULL) {
+
+      root = xmlNewDocNode (doc, NULL, BAD_CAST "list", NULL);
+      xmlDocSetRootElement (doc, root);
+    } else {
+
+      for (xmlNodePtr child = root->children;
+	   child != NULL;
+	   child = child->next)
+	if (child->type == XML_ELEMENT_NODE
+	    && child->name != NULL
+	    && xmlStrEqual (BAD_CAST "entry", child->name))
+	  add (child);
+    }
+    g_free (c_raw);
+
+  } else {
+
+    doc = xmlNewDoc (BAD_CAST "1.0");
+    xmlNodePtr root = xmlNewDocNode (doc, NULL, BAD_CAST "list", NULL);
+    xmlDocSetRootElement (doc, root);
+    add ("http://localhost/test.rl";, "", "", "XCAP Test"); // FIXME: remove
+  }
+}
+
+RL::Cluster::~Cluster ()
+{
+  if (doc != NULL)
+    xmlFreeDoc (doc);
+}
+
+bool
+RL::Cluster::populate_menu (Ekiga::MenuBuilder& builder)
+{
+  builder.add_action ("new", _("New resource list"),
+		      sigc::bind (sigc::mem_fun (this, &RL::Cluster::new_heap),
+				  "", "", "", ""));
+  return true;
+}
+
+void
+RL::Cluster::add (xmlNodePtr node)
+{
+  Heap* heap = new Heap (core, node);
+
+  common_add (*heap);
+}
+
+void
+RL::Cluster::add (const std::string uri,
+		  const std::string username,
+		  const std::string password,
+		  const std::string name)
+{
+  Heap* heap = new Heap (core, name, uri, username, password);
+  xmlNodePtr root = xmlDocGetRootElement (doc);
+
+  xmlAddChild (root, heap->get_node ());
+
+  save ();
+  common_add (*heap);
+}
+
+void
+RL::Cluster::common_add (Heap& heap)
+{
+  add_heap (heap);
+
+  // FIXME: here we should ask for presence for the heap...
+
+  heap.trigger_saving.connect (sigc::mem_fun (this, &RL::Cluster::save));
+}
+
+void
+RL::Cluster::save () const
+{
+  xmlChar* buffer = NULL;
+  int size = 0;
+
+  xmlDocDumpMemory (doc, &buffer, &size);
+
+  gm_conf_set_string (KEY, (const char*)buffer);
+
+  xmlFree (buffer);
+}
+
+void
+RL::Cluster::new_heap (const std::string name,
+		       const std::string uri,
+		       const std::string username,
+		       const std::string password)
+{
+  Ekiga::FormRequestSimple request;
+
+  request.title (_("Add new resource-list"));
+  request.instructions (_("Please fill in this form to add a new "
+			  "contact list to ekiga's remote roster"));
+  request.text ("name", _("Name:"), name);
+  request.text ("uri", _("Address:"), uri);
+  request.text ("username", _("Username:"), username);
+  request.private_text ("password", _("Password:"), password);
+
+  request.submitted.connect (sigc::mem_fun (this, &RL::Cluster::on_new_heap_form_submitted));
+
+  if (!questions.handle_request (&request)) {
+
+    // FIXME: better error reporting
+#ifdef __GNUC__
+    std::cout << "Unhandled form request in "
+	      << __PRETTY_FUNCTION__ << std::endl;
+#endif
+  }
+}
+
+void
+RL::Cluster::on_new_heap_form_submitted (Ekiga::Form& result)
+{
+  try {
+
+    const std::string name = result.text ("name");
+    const std::string uri = result.text ("uri");
+    const std::string username = result.text ("username");
+    const std::string password = result.private_text ("password");
+
+    add (name, uri, username, password);
+  } catch (Ekiga::Form::not_found) {
+
+#ifdef __GNUC__
+    std::cerr << "Invalid form submitted to "
+	      << __PRETTY_FUNCTION__ << std::endl;
+#endif
+  }
+}
+
+
+void
+RL::Cluster::on_presence_received (std::string uri,
+				   std::string presence)
+{
+  for (iterator iter = begin ();
+       iter != end ();
+       ++iter) {
+
+    iter->push_presence (uri, presence);
+  }
+}
+
+void
+RL::Cluster::on_status_received (std::string uri,
+				 std::string status)
+{
+  for (iterator iter = begin ();
+       iter != end ();
+       ++iter) {
+
+    iter->push_status (uri, status);
+  }
+}

Added: trunk/lib/engine/components/resource-list/rl-cluster.h
==============================================================================
--- (empty file)
+++ trunk/lib/engine/components/resource-list/rl-cluster.h	Thu Oct  2 13:06:23 2008
@@ -0,0 +1,92 @@
+
+/* Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2008 Damien Sandras
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *
+ * Ekiga is licensed under the GPL license and as a special exception,
+ * you have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination,
+ * without applying the requirements of the GNU GPL to the OPAL, OpenH323
+ * and PWLIB programs, as long as you do follow the requirements of the
+ * GNU GPL for all the rest of the software thus combined.
+ */
+
+
+/*
+ *                         rl-cluster.h  -  description
+ *                         ------------------------------------------
+ *   begin                : written in 2008 by Julien Puydt
+ *   copyright            : (c) 2008 by Julien Puydt
+ *   description          : resource-list cluster declaration
+ *
+ */
+
+#ifndef __RL_CLUSTER_H__
+#define __RL_CLUSTER_H__
+
+#include "rl-heap.h"
+
+#include "cluster-impl.h"
+
+namespace RL {
+
+  class Cluster:
+    public Ekiga::ClusterImpl<Heap>,
+    public Ekiga::Service
+  {
+  public:
+
+    Cluster (Ekiga::ServiceCore& core_);
+
+    ~Cluster ();
+
+    const std::string get_name () const
+    { return "resource-list"; }
+
+    const std::string get_description () const
+    { return "Code for support for resource-list"; }
+
+    bool populate_menu (Ekiga::MenuBuilder& builder);
+
+  private:
+
+    Ekiga::ServiceCore& core;
+    xmlDocPtr doc;
+
+    void add (xmlNodePtr node);
+    void add (const std::string uri,
+	      const std::string username,
+	      const std::string password,
+	      const std::string name);
+    void common_add (Heap& heap);
+    void save () const;
+
+    void new_heap (const std::string name,
+		   const std::string uri,
+		   const std::string username,
+		   const std::string password);
+
+    void on_new_heap_form_submitted (Ekiga::Form& result);
+
+    void on_presence_received (std::string uri,
+			       std::string presence);
+    void on_status_received (std::string uri,
+			     std::string presence);
+  };
+};
+
+#endif

Added: trunk/lib/engine/components/resource-list/rl-heap.cpp
==============================================================================
--- (empty file)
+++ trunk/lib/engine/components/resource-list/rl-heap.cpp	Thu Oct  2 13:06:23 2008
@@ -0,0 +1,315 @@
+
+/* Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2008 Damien Sandras
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *
+ * Ekiga is licensed under the GPL license and as a special exception,
+ * you have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination,
+ * without applying the requirements of the GNU GPL to the OPAL, OpenH323
+ * and PWLIB programs, as long as you do follow the requirements of the
+ * GNU GPL for all the rest of the software thus combined.
+ */
+
+
+/*
+ *                         rl-heap.cpp  -  description
+ *                         ------------------------------------------
+ *   begin                : written in 2008 by Julien Puydt
+ *   copyright            : (c) 2008 by Julien Puydt
+ *   description          : resource-list heap implementation
+ *
+ */
+
+#include "config.h"
+
+#include "rl-heap.h"
+
+#include <iostream>
+
+RL::Heap::Heap (Ekiga::ServiceCore& core_,
+		xmlNodePtr node_):
+  core(core_), node(node_), uri(NULL),
+  username(NULL), password(NULL), name(NULL)
+{
+  for (xmlNodePtr child = node->children; child != NULL; child = child->next) {
+
+    if (child->type == XML_ELEMENT_NODE
+	&& child->name != NULL) {
+
+      if (xmlStrEqual (BAD_CAST ("uri"), child->name))
+	uri = child;
+      if (xmlStrEqual (BAD_CAST ("username"), child->name))
+	username = child;
+      if (xmlStrEqual (BAD_CAST ("password"), child->name))
+	password = child;
+      if (xmlStrEqual (BAD_CAST ("name"), child->name))
+	name = child;
+    }
+  }
+
+  if (uri == NULL)
+    uri = xmlNewChild (node, NULL, BAD_CAST "uri", BAD_CAST "");
+  if (name == NULL)
+    name = xmlNewChild (node, NULL, BAD_CAST "name", BAD_CAST (_("Unnamed")));
+  if (username == NULL)
+    username = xmlNewChild (node, NULL, BAD_CAST "username", BAD_CAST "");
+  if (password == NULL)
+    password = xmlNewChild (node, NULL, BAD_CAST "password", BAD_CAST "");
+
+  update ();
+}
+
+RL::Heap::Heap (Ekiga::ServiceCore& core_,
+		const std::string name_,
+		const std::string uri_,
+		const std::string username_,
+		const std::string password_):
+  core(core_), node(NULL), uri(NULL), username(NULL), password(NULL), name(NULL)
+{
+  node = xmlNewNode (NULL, BAD_CAST "entry");
+  uri = xmlNewChild (node, NULL,
+		     BAD_CAST "uri", BAD_CAST uri_.c_str ());
+  username = xmlNewChild (node, NULL,
+			  BAD_CAST "username", BAD_CAST username_.c_str ());
+  password = xmlNewChild (node, NULL,
+			  BAD_CAST "password", BAD_CAST password_.c_str ());
+  if ( !name_.empty ())
+    name = xmlNewChild (node, NULL,
+			BAD_CAST "name", BAD_CAST name_.c_str ());
+  else
+    name = xmlNewChild (node, NULL,
+			BAD_CAST "name", BAD_CAST _("Unnamed"));
+  update ();
+}
+
+RL::Heap::~Heap ()
+{
+}
+
+const std::string
+RL::Heap::get_name () const
+{
+  std::string result;
+  xmlChar* str = xmlNodeGetContent (name);
+  if (str != NULL)
+    result = (const gchar*)str;
+  else
+    result = _("Unnamed");
+
+  xmlFree (str);
+
+  return result;
+}
+
+const std::string
+RL::Heap::get_uri () const
+{
+  std::string result;
+  xmlChar* str = xmlNodeGetContent (uri);
+  if (str != NULL)
+    result = (const gchar*)str;
+  else
+    result = "";
+
+  xmlFree (str);
+
+  return result;
+}
+
+
+bool
+RL::Heap::populate_menu (Ekiga::MenuBuilder& /*builder*/)
+{
+  return false; // FIXME
+}
+
+bool
+RL::Heap::populate_menu_for_group (std::string /*group*/,
+				   Ekiga::MenuBuilder& /*builder*/)
+{
+  return false; // FIXME
+}
+
+xmlNodePtr
+RL::Heap::get_node () const
+{
+  return node;
+}
+
+void
+RL::Heap::update ()
+{
+  XCAP::Core* xcap
+    = dynamic_cast<XCAP::Core*>(core.get ("xcap-core"));
+  xcap->read (get_uri (),
+	      sigc::mem_fun (this, &RL::Heap::on_document_received));
+}
+
+void
+RL::Heap::on_document_received (XCAP::Core::ResultType result,
+				std::string doc)
+{
+  switch (result) {
+
+  case XCAP::Core::SUCCESS:
+
+    parse_doc (doc);
+    break;
+  case XCAP::Core::ERROR:
+
+    std::cout << "Error: " << doc << std::endl;
+    break;
+  default:
+    // shouldn't happen
+    break;
+  }
+}
+
+void
+RL::Heap::parse_doc (std::string raw)
+{
+  xmlDocPtr doc = xmlRecoverMemory (raw.c_str (), raw.length ());
+  xmlNodePtr root = xmlDocGetRootElement (doc);
+
+  if (root == NULL) {
+
+    // FIXME: warn the user somehow?
+  } else {
+
+    for (xmlNodePtr child = root->children; child != NULL; child = child->next)
+      if (child->type == XML_ELEMENT_NODE
+	  && child->name != NULL
+	  && xmlStrEqual (BAD_CAST ("list"), child->name)) {
+
+	parse_list (child, NULL);
+      }
+  }
+  xmlFreeDoc (doc);
+}
+
+void
+RL::Heap::parse_list (xmlNodePtr list,
+		      const gchar* base_name)
+{
+  gchar* display_name = NULL;
+  gchar* unnamed = NULL;
+
+  if (base_name == NULL)
+    unnamed = g_strdup (_("Unnamed"));
+  else
+    unnamed = g_strdup_printf ("%s / %s",
+			       base_name, _("Unnamed"));
+
+  for (xmlNodePtr child = list->children;
+       child != NULL;
+       child = child->next) {
+
+    if (child->type == XML_ELEMENT_NODE
+	&& child->name != NULL) {
+
+      if (xmlStrEqual (BAD_CAST ("display-name"), child->name)) {
+
+	xmlChar* xml_str = xmlNodeGetContent (child);
+	if (xml_str != NULL && display_name == NULL) {
+
+	  if (base_name == NULL)
+	    display_name = g_strdup ((const gchar*)xml_str);
+	  else
+	    display_name = g_strdup_printf ("%s / %s",
+					    base_name, (const gchar*)xml_str);
+	}
+	xmlFree (xml_str);
+      }
+
+      if (xmlStrEqual (BAD_CAST ("list"), child->name)) {
+
+	if (display_name != NULL)
+	  parse_list (child, display_name);
+	else
+	  parse_list (child, unnamed);
+      }
+      if (xmlStrEqual (BAD_CAST ("entry"), child->name)) {
+
+	if (display_name != NULL)
+	  parse_entry (child, display_name);
+	else
+	  parse_entry (child, unnamed);
+      }
+    }
+  }
+
+  g_free (unnamed);
+  g_free (display_name);
+}
+
+void
+RL::Heap::parse_entry (xmlNodePtr entry,
+		       const gchar* group_name)
+{
+  gchar* entry_uri = NULL;
+  std::string display_name = _("Unnamed");
+  Presentity* presentity = NULL;
+
+  {
+    xmlChar* str = xmlGetProp (entry, BAD_CAST "uri");
+    if (str != NULL)
+      entry_uri = g_strdup ((const gchar*)str);
+  }
+
+  for (xmlNodePtr child = entry->children; child != NULL; child = child->next)
+    if (child->type == XML_ELEMENT_NODE
+	&& child->name != NULL
+	&& xmlStrEqual (BAD_CAST ("display-name"), child->name)) {
+
+      xmlChar* xml_str = xmlNodeGetContent (child);
+      if (xml_str != NULL)
+	display_name = (const gchar*)xml_str;
+      xmlFree (xml_str);
+    }
+
+  if (entry_uri != NULL) {
+
+    presentity = new Presentity (core, display_name, entry_uri);
+    if (group_name != NULL)
+      presentity->add_group (group_name);
+    add_presentity (*presentity);
+    g_free (entry_uri);
+  }
+}
+
+void
+RL::Heap::push_presence (const std::string uri_,
+			 const std::string presence)
+{
+  for (iterator iter = begin ();
+       iter != end ();
+       ++iter)
+    if (iter->get_uri () == uri_)
+      iter->set_presence (presence);
+}
+
+void
+RL::Heap::push_status (const std::string uri_,
+		       const std::string status)
+{
+  for (iterator iter = begin ();
+       iter != end ();
+       ++iter)
+    if (iter->get_uri () == uri_)
+      iter->set_status (status);
+}

Added: trunk/lib/engine/components/resource-list/rl-heap.h
==============================================================================
--- (empty file)
+++ trunk/lib/engine/components/resource-list/rl-heap.h	Thu Oct  2 13:06:23 2008
@@ -0,0 +1,110 @@
+
+/* Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2008 Damien Sandras
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *
+ * Ekiga is licensed under the GPL license and as a special exception,
+ * you have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination,
+ * without applying the requirements of the GNU GPL to the OPAL, OpenH323
+ * and PWLIB programs, as long as you do follow the requirements of the
+ * GNU GPL for all the rest of the software thus combined.
+ */
+
+
+/*
+ *                         rl-heap.h  -  description
+ *                         ------------------------------------------
+ *   begin                : written in 2008 by Julien Puydt
+ *   copyright            : (c) 2008 by Julien Puydt
+ *   description          : resource-list heap declaration
+ *
+ */
+
+#ifndef __RL_HEAP_H__
+#define __RL_HEAP_H__
+
+#include "rl-presentity.h"
+
+#include "heap-impl.h"
+#include "xcap.h"
+
+#include <glib.h>
+#include <libxml/tree.h>
+
+namespace RL {
+
+  class Heap: public Ekiga::HeapImpl<Presentity>
+  {
+  public:
+
+    Heap (Ekiga::ServiceCore& core_,
+	  xmlNodePtr node);
+
+    Heap (Ekiga::ServiceCore& core_,
+	  const std::string name_,
+	  const std::string uri_,
+	  const std::string username_,
+	  const std::string password_);
+
+    ~Heap ();
+
+    const std::string get_name () const;
+
+    bool populate_menu (Ekiga::MenuBuilder& builder);
+
+    bool populate_menu_for_group (std::string group,
+				  Ekiga::MenuBuilder& builder);
+
+    xmlNodePtr get_node () const;
+
+    void push_presence (const std::string uri,
+			const std::string presence);
+
+    void push_status (const std::string uri,
+		      const std::string status);
+
+    sigc::signal<void> trigger_saving;
+
+  private:
+
+    Ekiga::ServiceCore& core;
+
+    xmlNodePtr node;
+    xmlNodePtr uri;
+    xmlNodePtr username;
+    xmlNodePtr password;
+    xmlNodePtr name;
+
+    const std::string get_uri () const;
+
+    void update ();
+
+    void on_document_received (XCAP::Core::ResultType result,
+			       std::string doc);
+
+    void parse_doc (std::string doc);
+
+    void parse_list (xmlNodePtr list,
+		     const gchar* base_name);
+
+    void parse_entry (xmlNodePtr entry,
+		      const gchar* group_name);
+  };
+};
+
+#endif

Added: trunk/lib/engine/components/resource-list/rl-presentity.cpp
==============================================================================
--- (empty file)
+++ trunk/lib/engine/components/resource-list/rl-presentity.cpp	Thu Oct  2 13:06:23 2008
@@ -0,0 +1,84 @@
+
+/* Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2008 Damien Sandras
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *
+ * Ekiga is licensed under the GPL license and as a special exception,
+ * you have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination,
+ * without applying the requirements of the GNU GPL to the OPAL, OpenH323
+ * and PWLIB programs, as long as you do follow the requirements of the
+ * GNU GPL for all the rest of the software thus combined.
+ */
+
+
+/*
+ *                         rl-presentity.cpp  -  description
+ *                         ------------------------------------------
+ *   begin                : written in 2008 by Julien Puydt
+ *   copyright            : (c) 2008 by Julien Puydt
+ *   description          : resource-list presentity implementation
+ *
+ */
+
+#include "rl-presentity.h"
+
+#include "presence-core.h"
+
+RL::Presentity::Presentity (Ekiga::ServiceCore& core_,
+			    std::string name_,
+			    std::string uri_):
+  core(core_), name(name_), uri(uri_), presence("unknown")
+{
+}
+
+RL::Presentity::~Presentity ()
+{
+}
+
+void
+RL::Presentity::add_group (std::string group)
+{
+  groups.insert (group);
+}
+
+bool
+RL::Presentity::populate_menu (Ekiga::MenuBuilder &builder)
+{
+  bool populated = false;
+  Ekiga::PresenceCore* presence_core
+    = dynamic_cast<Ekiga::PresenceCore*>(core.get ("presence-core"));
+
+  populated = presence_core->populate_presentity_menu (*this, uri, builder);
+
+
+  return populated;
+}
+
+void
+RL::Presentity::set_presence (const std::string presence_)
+{
+  presence = presence_;
+  updated.emit ();
+}
+
+void
+RL::Presentity::set_status (const std::string status_)
+{
+  status = status_;
+  updated.emit ();
+}

Added: trunk/lib/engine/components/resource-list/rl-presentity.h
==============================================================================
--- (empty file)
+++ trunk/lib/engine/components/resource-list/rl-presentity.h	Thu Oct  2 13:06:23 2008
@@ -0,0 +1,93 @@
+
+/* Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2008 Damien Sandras
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *
+ * Ekiga is licensed under the GPL license and as a special exception,
+ * you have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination,
+ * without applying the requirements of the GNU GPL to the OPAL, OpenH323
+ * and PWLIB programs, as long as you do follow the requirements of the
+ * GNU GPL for all the rest of the software thus combined.
+ */
+
+
+/*
+ *                         rl-presentity.h  -  description
+ *                         ------------------------------------------
+ *   begin                : written in 2008 by Julien Puydt
+ *   copyright            : (c) 2008 by Julien Puydt
+ *   description          : resource-list presentity interface
+ *
+ */
+
+#ifndef __RL_PRESENTITY_H__
+#define __RL_PRESENTITY_H__
+
+#include "services.h"
+#include "presentity.h"
+
+namespace RL {
+
+  class Presentity: public Ekiga::Presentity
+  {
+  public:
+
+    Presentity (Ekiga::ServiceCore& core_,
+		std::string name_,
+		std::string uri_);
+
+    ~Presentity ();
+
+    void add_group (std::string group);
+
+    const std::string get_name () const
+    { return name; }
+
+    const std::string get_presence () const
+    { return presence; }
+
+    const std::string get_status () const
+    { return status; }
+
+    const std::string get_avatar () const
+    { return ""; }
+
+    const std::set<std::string> get_groups () const
+    { return groups; }
+
+    bool populate_menu (Ekiga::MenuBuilder& builder);
+
+    const std::string get_uri () const
+    { return uri; }
+
+    void set_presence (const std::string presence_);
+
+    void set_status (const std::string status_);
+
+  private:
+    Ekiga::ServiceCore& core;
+
+    std::string name;
+    std::string uri;
+    std::string presence;
+    std::string status;
+    std::set<std::string> groups;
+  };
+};
+
+#endif

Modified: trunk/lib/engine/engine.cpp
==============================================================================
--- trunk/lib/engine/engine.cpp	(original)
+++ trunk/lib/engine/engine.cpp	Thu Oct  2 13:06:23 2008
@@ -107,6 +107,7 @@
 
 #ifdef HAVE_XCAP
 #include "xcap-main.h"
+#include "resource-list-main.h"
 #endif
 
 void
@@ -256,6 +257,10 @@
   (void)kab_init (*core, &argc, &argv);
 #endif
 
+#ifdef HAVE_XCAP
+  resource_list_init (*core, &argc, &argv);
+#endif
+
   if (!history_init (*core, &argc, &argv)) {
 
     delete core;



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