ekiga r6513 - in trunk: . lib/engine/addressbook/ldap lib/engine/gui/gtk-frontend



Author: jpuydt
Date: Fri Jul 25 20:46:38 2008
New Revision: 6513
URL: http://svn.gnome.org/viewvc/ekiga?rev=6513&view=rev

Log:
Merge branch 'improvements'

Modified:
   trunk/ChangeLog
   trunk/lib/engine/addressbook/ldap/ldap-book.cpp
   trunk/lib/engine/addressbook/ldap/ldap-book.h
   trunk/lib/engine/addressbook/ldap/ldap-source.cpp
   trunk/lib/engine/addressbook/ldap/ldap-source.h
   trunk/lib/engine/gui/gtk-frontend/book-view-gtk.cpp

Modified: trunk/lib/engine/addressbook/ldap/ldap-book.cpp
==============================================================================
--- trunk/lib/engine/addressbook/ldap/ldap-book.cpp	(original)
+++ trunk/lib/engine/addressbook/ldap/ldap-book.cpp	Fri Jul 25 20:46:38 2008
@@ -71,6 +71,25 @@
   return result;
 }
 
+/* another helper, which helps avoid crashes */
+static void
+robust_xmlNodeSetContent (xmlNodePtr parent,
+			  xmlNodePtr* child,
+			  const std::string& name,
+			  const std::string& value)
+{
+  if (*child == NULL) {
+
+    *child = xmlNewChild (parent, NULL,
+			  BAD_CAST name.c_str (),
+			  BAD_CAST value.c_str ());
+  } else {
+
+    xmlNodeSetContent (*child, xmlEncodeSpecialChars ((*child)->doc,
+						      BAD_CAST value.c_str ()));
+  }
+}
+
 /* parses a message to construct a nice contact */
 static OPENLDAP::Contact *
 parse_result (Ekiga::ServiceCore &core,
@@ -134,13 +153,14 @@
 	       const std::string _base,
 	       const std::string _scope,
 	       const std::string _call_attribute,
+	       const std::string _password,
 	       const std::string _search_string,
 	       sigc::slot<void, std::vector<OPENLDAP::Contact *> > _publish_results):
     core(_core), name(_name), hostname(_hostname), port(_port),
     base(_base), scope(_scope), call_attribute(_call_attribute),
-    search_string(_search_string), publish_results (_publish_results)
+    password(_password), search_string(_search_string),
+    error(false), publish_results (_publish_results)
   {
-    error = false;
   }
 
   /* search data */
@@ -151,6 +171,7 @@
   std::string base;
   std::string scope;
   std::string call_attribute;
+  std::string password;
   std::string search_string;
 
   /* result data */
@@ -166,7 +187,9 @@
 
 OPENLDAP::Book::Book (Ekiga::ServiceCore &_core,
 		      xmlNodePtr _node):
-  core(_core), node(_node), ldap_context(NULL), patience(0), 
+  core(_core), node(_node), name_node(NULL), hostname_node(NULL),
+  port_node(NULL), base_node(NULL), scope_node(NULL), call_attribute_node(NULL),
+  password_node(NULL), ldap_context(NULL), patience(0),
   runtime (*(dynamic_cast<Ekiga::Runtime *>(core.get ("runtime"))))
 {
   xmlChar *xml_str;
@@ -227,6 +250,14 @@
 	call_attribute_node = child;
 	xmlFree (xml_str);
       }
+
+      if (xmlStrEqual (BAD_CAST ("password"), child->name)) {
+
+	xml_str = xmlNodeGetContent (child);
+	password = (const char *)xml_str;
+	password_node = child;
+	xmlFree (xml_str);
+      }
     }
   }
 }
@@ -237,10 +268,13 @@
 		      int _port,
 		      const std::string _base,
 		      const std::string _scope,
-		      const std::string _call_attribute):
-  core(_core), name(_name), hostname(_hostname), port(_port),
-  base(_base), scope(_scope), call_attribute(_call_attribute),
-  ldap_context(NULL), patience(0), 
+		      const std::string _call_attribute,
+		      const std::string _password):
+  core(_core), name(_name), name_node(NULL),
+  hostname(_hostname), hostname_node(NULL), port(_port), port_node(NULL),
+  base(_base), base_node(NULL), scope(_scope), scope_node(NULL),
+  call_attribute(_call_attribute), call_attribute_node(NULL),
+  password (_password), password_node(NULL), ldap_context(NULL), patience(0),
   runtime (*(dynamic_cast<Ekiga::Runtime *>(core.get ("runtime"))))
 {
   contact_core = dynamic_cast<Ekiga::ContactCore *>(core.get ("contact-core"));
@@ -251,7 +285,7 @@
 			   BAD_CAST "name", BAD_CAST name.c_str ());
 
   hostname_node = xmlNewChild (node, NULL,
-			   BAD_CAST "hostname", BAD_CAST hostname.c_str ());
+			       BAD_CAST "hostname", BAD_CAST hostname.c_str ());
 
   { // Snark hates C++ -- and there isn't only a reason for it -- but many
     std::stringstream strm;
@@ -272,6 +306,10 @@
   call_attribute_node = xmlNewChild (node, NULL,
 				     BAD_CAST "call_attribute",
 				     BAD_CAST call_attribute.c_str ());
+
+  password_node = xmlNewChild (node, NULL,
+			       BAD_CAST "password",
+			       BAD_CAST password.c_str ());
 }
 
 OPENLDAP::Book::~Book ()
@@ -298,7 +336,7 @@
   return true;
 }
 
-void 
+void
 OPENLDAP::Book::set_search_filter (std::string _search_filter)
 {
   search_filter = _search_filter;
@@ -369,11 +407,26 @@
   (void)ldap_set_option (ldap_context,
 			 LDAP_OPT_PROTOCOL_VERSION, &ldap_version);
 
+  if (password.empty ()) {
+
+    result = ldap_sasl_bind (ldap_context, NULL,
+			     LDAP_SASL_SIMPLE, NULL,
+			     NULL, NULL,
+			     &msgid);
+  } else {
+
+    struct berval passwd = { 0, NULL };
+    passwd.bv_val = g_strdup (password.c_str ());
+    passwd.bv_len = strlen (password.c_str ());
+
+    result = ldap_sasl_bind (ldap_context, NULL,
+			     LDAP_SASL_SIMPLE, &passwd,
+			     NULL, NULL,
+			     &msgid);
+
+    g_free (passwd.bv_val);
+  }
 
-  result = ldap_sasl_bind (ldap_context, NULL,
-			   LDAP_SASL_SIMPLE, NULL,
-			   NULL, NULL,
-			   &msgid);
   if (result != LDAP_SUCCESS) {
 
     status = std::string (_("Could not contact server"));
@@ -586,6 +639,8 @@
 
   request.text ("call-attribute", _("Call _Attribute"), call_attribute);
 
+  request.private_text ("password", _("_Password"), password);
+
   request.submitted.connect (sigc::mem_fun (this,
 					    &OPENLDAP::Book::on_edit_form_submitted));
 
@@ -610,34 +665,30 @@
     std::string new_base = result.text ("base");
     std::string new_scope = result.single_choice ("scope");
     std::string new_call_attribute = result.text ("call-attribute");
+    std::string new_password = result.private_text ("password");
     int new_port = std::atoi (new_port_string.c_str ());
 
     name = new_name;
-    xmlNodeSetContent (name_node,
-		       xmlEncodeSpecialChars(name_node->doc,
-					     BAD_CAST name.c_str ()));
+    robust_xmlNodeSetContent (node, &name_node, "name", name);
 
     hostname = new_hostname;
-    xmlNodeSetContent (hostname_node,
-		       xmlEncodeSpecialChars(hostname_node->doc,
-					     BAD_CAST hostname.c_str ()));
+    robust_xmlNodeSetContent (node, &hostname_node, "hostname", hostname);
 
     port = new_port;
-    xmlNodeSetContent (port_node,
-		       xmlEncodeSpecialChars(port_node->doc,
-					     BAD_CAST new_port_string.c_str ()));
+    robust_xmlNodeSetContent (node, &port_node, "port", new_port_string);
+
     base = new_base;
-    xmlNodeSetContent (base_node,
-		       xmlEncodeSpecialChars(base_node->doc,
-					     BAD_CAST base.c_str ()));
+    robust_xmlNodeSetContent (node, &base_node, "base", base);
+
     scope = new_scope;
-    xmlNodeSetContent (scope_node,
-		       xmlEncodeSpecialChars(scope_node->doc,
-					     BAD_CAST scope.c_str ()));
+    robust_xmlNodeSetContent (node, &scope_node, "scope", scope);
+
     call_attribute = new_call_attribute;
-    xmlNodeSetContent (call_attribute_node,
-		       xmlEncodeSpecialChars(call_attribute_node->doc,
-					     BAD_CAST call_attribute.c_str ()));
+    robust_xmlNodeSetContent (node, &call_attribute_node,
+			      "call_attribute", call_attribute);
+
+    password = new_password;
+    robust_xmlNodeSetContent (node, &password_node, "password", password);
 
     updated.emit ();
     trigger_saving.emit ();

Modified: trunk/lib/engine/addressbook/ldap/ldap-book.h
==============================================================================
--- trunk/lib/engine/addressbook/ldap/ldap-book.h	(original)
+++ trunk/lib/engine/addressbook/ldap/ldap-book.h	Fri Jul 25 20:46:38 2008
@@ -70,7 +70,8 @@
 	  int _port,
 	  const std::string _base,
 	  const std::string _scope,
-	  const std::string _call_attribute);
+	  const std::string _call_attribute,
+	  const std::string _password);
 
     ~Book ();
 
@@ -121,6 +122,9 @@
     std::string call_attribute;
     xmlNodePtr call_attribute_node;
 
+    std::string password;
+    xmlNodePtr password_node;
+
     struct ldap *ldap_context;
     unsigned int patience;
 

Modified: trunk/lib/engine/addressbook/ldap/ldap-source.cpp
==============================================================================
--- trunk/lib/engine/addressbook/ldap/ldap-source.cpp	(original)
+++ trunk/lib/engine/addressbook/ldap/ldap-source.cpp	Fri Jul 25 20:46:38 2008
@@ -107,13 +107,15 @@
 		       int port,
 		       const std::string base,
 		       const std::string scope,
-		       const std::string call_attribute)
+		       const std::string call_attribute,
+		       const std::string password)
 {
   Book *book = NULL;
   xmlNodePtr root;
 
   root = xmlDocGetRootElement (doc);
-  book = new Book (core, name, hostname, port, base, scope, call_attribute);
+  book = new Book (core, name, hostname, port, base,
+		   scope, call_attribute, password);
 
   xmlAddChild (root, book->get_node ());
 
@@ -158,7 +160,8 @@
     request.single_choice ("scope", _("_Scope"), "sub", choices);
   }
 
-  request.text ("call-attribute", _("Call _Attribute:"), "telephoneNumber");
+  request.text ("call-attribute", _("Call _Attribute"), "telephoneNumber");
+  request.private_text ("password", _("Password"), "");
 
   request.submitted.connect (sigc::mem_fun (this,
 					    &OPENLDAP::Source::on_new_book_form_submitted));
@@ -184,9 +187,10 @@
     std::string base = result.text ("base");
     std::string scope = result.single_choice ("scope");
     std::string call_attribute = result.text ("call-attribute");
+    std::string password = result.private_text ("password");
     int port = atoi (port_string.c_str ());
 
-    add (name, hostname, port, base, scope, call_attribute);
+    add (name, hostname, port, base, scope, call_attribute, password);
     save ();
 
   } catch (Ekiga::Form::not_found) {

Modified: trunk/lib/engine/addressbook/ldap/ldap-source.h
==============================================================================
--- trunk/lib/engine/addressbook/ldap/ldap-source.h	(original)
+++ trunk/lib/engine/addressbook/ldap/ldap-source.h	Fri Jul 25 20:46:38 2008
@@ -84,7 +84,8 @@
 	      int port,
 	      const std::string base,
 	      const std::string scope,
-	      const std::string call_attribute);
+	      const std::string call_attribute,
+	      const std::string password);
 
     void common_add (Book &book);
 

Modified: trunk/lib/engine/gui/gtk-frontend/book-view-gtk.cpp
==============================================================================
--- trunk/lib/engine/gui/gtk-frontend/book-view-gtk.cpp	(original)
+++ trunk/lib/engine/gui/gtk-frontend/book-view-gtk.cpp	Fri Jul 25 20:46:38 2008
@@ -119,11 +119,7 @@
 enum
   {
     COLUMN_CONTACT_POINTER,
-    COLUMN_PIXBUF,
-    COLUMN_GROUP_NAME,
     COLUMN_NAME,
-    COLUMN_VIDEO_URL,
-    COLUMN_PHONE,
     COLUMN_NUMBER
   };
 
@@ -417,36 +413,6 @@
 		      COLUMN_NAME, contact.get_name ().c_str (),
 		      -1);
 
-// FIXME: that doesn't look good at all!
-//   std::map<std::string, std::string> uris = contact.get_uris ();
-//   GdkPixbuf *icon = NULL;
-//   std::string phone;
-
-//   for (std::map<std::string, std::string>::const_iterator uri = uris.begin () ;
-//        uri != uris.end () ;
-//        uri++) {
-
-//     std::string::size_type loc = uri->second.find ("sip:", 0);
-//     if (loc != std::string::npos) {
-//       gtk_list_store_set (store, iter, COLUMN_VIDEO_URL, uri->second.c_str (), -1);
-//     }
-//     else if (!uri->second.empty ()) {
-//       if (!phone.empty ())
-//         phone += ", ";
-//       phone += uri->second;
-//     }
-//   }
-
-//   icon = gtk_widget_render_icon (GTK_WIDGET (self),
-//                                  GM_STOCK_PHONE_PICK_UP_16,
-//                                  GTK_ICON_SIZE_MENU, NULL);
-
-//   gtk_list_store_set (store, iter,
-//                       COLUMN_PHONE, phone.c_str (),
-//                       COLUMN_PIXBUF, icon, -1);
-
-//   g_object_unref (icon);
-
   if (GDK_IS_WINDOW (GTK_WIDGET (self)->window))
     gdk_window_set_cursor (GTK_WIDGET (self)->window, NULL);
 }
@@ -631,10 +597,6 @@
 
   store = gtk_list_store_new (COLUMN_NUMBER,
 			      G_TYPE_POINTER,
-                              GDK_TYPE_PIXBUF,
-                              G_TYPE_STRING,
-                              G_TYPE_STRING,
-                              G_TYPE_STRING,
                               G_TYPE_STRING);
 
   gtk_tree_view_set_model (result->priv->tree_view, GTK_TREE_MODEL (store));
@@ -642,11 +604,6 @@
 
   /* Name */
   column = gtk_tree_view_column_new ();
-  renderer = gtk_cell_renderer_pixbuf_new ();
-  gtk_tree_view_column_pack_start (column, renderer, FALSE);
-  gtk_tree_view_column_set_attributes (column, renderer,
-                                       "pixbuf", COLUMN_PIXBUF,
-                                       NULL);
 
   renderer = gtk_cell_renderer_text_new ();
   gtk_tree_view_column_pack_start (column, renderer, FALSE);
@@ -661,37 +618,6 @@
   gtk_tree_view_column_set_resizable (column, true);
   gtk_tree_view_append_column (GTK_TREE_VIEW (result->priv->tree_view), column);
 
-
-  /* URI */
-  renderer = gtk_cell_renderer_text_new ();
-  column = gtk_tree_view_column_new_with_attributes (_("VoIP URI"),
-                                                     renderer,
-                                                     "text",
-                                                     COLUMN_VIDEO_URL,
-                                                     NULL);
-  gtk_tree_view_column_set_sort_column_id (column, COLUMN_VIDEO_URL);
-  gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column),
-                                   GTK_TREE_VIEW_COLUMN_AUTOSIZE);
-  gtk_tree_view_column_set_resizable (column, true);
-  gtk_tree_view_append_column (GTK_TREE_VIEW (result->priv->tree_view), column);
-  g_object_set (G_OBJECT (renderer), "foreground", "blue",
-                "underline", TRUE, NULL);
-
-  /* Phone */
-  renderer = gtk_cell_renderer_text_new ();
-  column = gtk_tree_view_column_new_with_attributes ("Phone",
-                                                     renderer,
-                                                     "text",
-                                                     COLUMN_PHONE,
-                                                     NULL);
-  gtk_tree_view_column_set_sort_column_id (column, COLUMN_PHONE);
-  gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column),
-                                   GTK_TREE_VIEW_COLUMN_AUTOSIZE);
-  gtk_tree_view_column_set_resizable (column, true);
-  gtk_tree_view_append_column (GTK_TREE_VIEW (result->priv->tree_view), column);
-  g_object_set (G_OBJECT (renderer), "foreground", "darkgray", NULL);
-
-
   /* The Search Box */
   hbox = gtk_hbox_new (FALSE, 0);
   result->priv->entry = gtk_entry_new ();



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