ekiga r7359 - in branches/gnome-2-24: . lib/engine/components/avahi-publisher lib/engine/components/gmconf-personal-details lib/engine/framework src/endpoints src/gui



Author: dsandras
Date: Sat Nov 15 18:32:40 2008
New Revision: 7359
URL: http://svn.gnome.org/viewvc/ekiga?rev=7359&view=rev

Log:
Large rework of the PersonalDetails class so that the short_status and
long_status can be set at once. The GmConf notifiers are only 
triggering the updated signal when there was an update. Rewrite of the
StatusMenu Gtk widget so that it deals with the PersonalDetails service
and not directly with the GmConf keys. Renamed short_status into
presence and long_status into status to match the naming of 
presentities. All of this prevent publishing partial, duplicate or 
incorrect status information to the SIP server.


Modified:
   branches/gnome-2-24/ChangeLog
   branches/gnome-2-24/lib/engine/components/avahi-publisher/avahi-publisher.cpp
   branches/gnome-2-24/lib/engine/components/gmconf-personal-details/gmconf-personal-details.cpp
   branches/gnome-2-24/lib/engine/components/gmconf-personal-details/gmconf-personal-details.h
   branches/gnome-2-24/lib/engine/framework/personal-details.h
   branches/gnome-2-24/src/endpoints/sip-endpoint.cpp
   branches/gnome-2-24/src/gui/main.cpp
   branches/gnome-2-24/src/gui/statusicon.cpp
   branches/gnome-2-24/src/gui/statusmenu.cpp
   branches/gnome-2-24/src/gui/statusmenu.h

Modified: branches/gnome-2-24/lib/engine/components/avahi-publisher/avahi-publisher.cpp
==============================================================================
--- branches/gnome-2-24/lib/engine/components/avahi-publisher/avahi-publisher.cpp	(original)
+++ branches/gnome-2-24/lib/engine/components/avahi-publisher/avahi-publisher.cpp	Sat Nov 15 18:32:40 2008
@@ -286,10 +286,10 @@
 
   result = avahi_string_list_add_printf (result,
 					 "presence=%s",
-					 details.get_short_status ().c_str ());
+					 details.get_presence ().c_str ());
   result = avahi_string_list_add_printf (result,
 					 "status=%s",
-					 details.get_long_status ().c_str ());
+					 details.get_status ().c_str ());
   result = avahi_string_list_add_printf (result,
 					 "software=%s %s",
 					 PACKAGE_NAME, PACKAGE_VERSION);

Modified: branches/gnome-2-24/lib/engine/components/gmconf-personal-details/gmconf-personal-details.cpp
==============================================================================
--- branches/gnome-2-24/lib/engine/components/gmconf-personal-details/gmconf-personal-details.cpp	(original)
+++ branches/gnome-2-24/lib/engine/components/gmconf-personal-details/gmconf-personal-details.cpp	Sat Nov 15 18:32:40 2008
@@ -35,50 +35,45 @@
  */
 
 #include <glib.h>
+#include <iostream>
 
 #include "gmconf.h"
 #include "gmconf-personal-details.h"
 
 static void
 display_name_changed_nt (G_GNUC_UNUSED gpointer id,
-			 GmConfEntry* entry,
-			 gpointer data)
+                         GmConfEntry* entry,
+                         gpointer data)
 {
   Gmconf::PersonalDetails *details = (Gmconf::PersonalDetails *) data;
   const gchar* val = gm_conf_entry_get_string (entry);
 
   if (val != NULL)
     details->display_name_changed (val);
-  else
-    details->display_name_changed ("");
 }
 
 static void
-short_status_changed_nt (G_GNUC_UNUSED gpointer id,
-			 GmConfEntry* entry,
-			 gpointer data)
+presence_changed_nt (G_GNUC_UNUSED gpointer id,
+                     GmConfEntry* entry,
+                     gpointer data)
 {
   Gmconf::PersonalDetails *details = (Gmconf::PersonalDetails *) data;
   const gchar* val = gm_conf_entry_get_string (entry);
 
   if (val != NULL)
-    details->short_status_changed (val);
-  else
-    details->short_status_changed ("");
+    details->presence_changed (val);
 }
 
 static void
-long_status_changed_nt (G_GNUC_UNUSED gpointer id,
-			GmConfEntry* entry,
-			gpointer data)
+status_changed_nt (G_GNUC_UNUSED gpointer id,
+                   GmConfEntry* entry,
+                   gpointer data)
 {
   Gmconf::PersonalDetails *details = (Gmconf::PersonalDetails *) data;
   const gchar* val = gm_conf_entry_get_string (entry);
 
   if (val != NULL)
-    details->long_status_changed (val);
-  else
-    details->long_status_changed ("");
+    details->status_changed (val);
 }
 
 Gmconf::PersonalDetails::PersonalDetails ()
@@ -87,13 +82,13 @@
 
   display_name_notifier
     = gm_conf_notifier_add ("/apps/ekiga/general/personal_data/full_name",
-			    display_name_changed_nt, this);
-  short_status_notifier
+                            display_name_changed_nt, this);
+  presence_notifier
     = gm_conf_notifier_add ("/apps/ekiga/general/personal_data/short_status",
-			    short_status_changed_nt, this);
-  long_status_notifier
-  = gm_conf_notifier_add ("/apps/ekiga/general/personal_data/long_status",
-			  long_status_changed_nt, this);
+                            presence_changed_nt, this);
+  status_notifier
+    = gm_conf_notifier_add ("/apps/ekiga/general/personal_data/long_status",
+                            status_changed_nt, this);
 
   str = gm_conf_get_string ("/apps/ekiga/general/personal_data/full_name");
   if (str != NULL) {
@@ -106,25 +101,25 @@
   str = gm_conf_get_string ("/apps/ekiga/general/personal_data/short_status");
   if (str != NULL) {
 
-    short_status = str;
+    presence = str;
     g_free (str);
   } else
-    short_status = "";
+    presence = "";
 
   str = gm_conf_get_string ("/apps/ekiga/general/personal_data/long_status");
   if (str != NULL) {
 
-    long_status = str;
+    status = str;
     g_free (str);
   } else
-    long_status = "";
+    status = "";
 }
 
 Gmconf::PersonalDetails::~PersonalDetails ()
 {
   gm_conf_notifier_remove (display_name_notifier);
-  gm_conf_notifier_remove (short_status_notifier);
-  gm_conf_notifier_remove (long_status_notifier);
+  gm_conf_notifier_remove (presence_notifier);
+  gm_conf_notifier_remove (status_notifier);
 }
 
 const std::string
@@ -134,36 +129,49 @@
 }
 
 const std::string
-Gmconf::PersonalDetails::get_short_status () const
+Gmconf::PersonalDetails::get_presence () const
 {
-  return short_status;
+  return presence;
 }
 
 const std::string
-Gmconf::PersonalDetails::get_long_status () const
+Gmconf::PersonalDetails::get_status () const
 {
-  return long_status;
+  return status;
 }
 
 void
 Gmconf::PersonalDetails::set_display_name (const std::string display_name_)
 {
   gm_conf_set_string ("/apps/ekiga/general/personal_data/full_name",
-		      display_name_.c_str ());
+                      display_name_.c_str ());
 }
 
 void
-Gmconf::PersonalDetails::set_short_status (const std::string short_status_)
+Gmconf::PersonalDetails::set_presence (const std::string presence_)
 {
   gm_conf_set_string ("/apps/ekiga/general/personal_data/short_status",
-		      short_status_.c_str ());
+                      presence_.c_str ());
 }
 
 void
-Gmconf::PersonalDetails::set_long_status (const std::string long_status_)
+Gmconf::PersonalDetails::set_status (const std::string status_)
 {
   gm_conf_set_string ("/apps/ekiga/general/personal_data/long_status",
-		      long_status_.c_str ());
+                      status_.c_str ());
+}
+
+void
+Gmconf::PersonalDetails::set_presence_info (const std::string _presence,
+                                            const std::string _status)
+{
+  presence = _presence;
+  status = _status;
+
+  set_presence (_presence);
+  set_status (_status);
+
+  updated.emit ();
 }
 
 void
@@ -174,15 +182,19 @@
 }
 
 void
-Gmconf::PersonalDetails::short_status_changed (std::string val)
+Gmconf::PersonalDetails::presence_changed (std::string val)
 {
-  short_status = val;
-  updated.emit ();
+  if (presence != val) {
+    presence = val;
+    updated.emit ();
+  }
 }
 
 void
-Gmconf::PersonalDetails::long_status_changed (std::string val)
+Gmconf::PersonalDetails::status_changed (std::string val)
 {
-  long_status = val;
-  updated.emit ();
+  if (status != val) {
+    status = val;
+    updated.emit ();
+  }
 }

Modified: branches/gnome-2-24/lib/engine/components/gmconf-personal-details/gmconf-personal-details.h
==============================================================================
--- branches/gnome-2-24/lib/engine/components/gmconf-personal-details/gmconf-personal-details.h	(original)
+++ branches/gnome-2-24/lib/engine/components/gmconf-personal-details/gmconf-personal-details.h	Sat Nov 15 18:32:40 2008
@@ -64,29 +64,32 @@
 
     const std::string get_display_name () const;
 
-    const std::string get_short_status () const;
+    const std::string get_presence () const;
 
-    const std::string get_long_status () const;
+    const std::string get_status () const;
 
     void set_display_name (const std::string display_name);
 
-    void set_short_status (const std::string short_status);
+    void set_presence (const std::string presence);
 
-    void set_long_status (const std::string long_status);
+    void set_status (const std::string status);
+
+    void set_presence_info (const std::string presence, 
+                            const std::string status);
 
     /*** public but only to be called by C callbacks ***/
   public:
     void display_name_changed (std::string val);
-    void short_status_changed (std::string val);
-    void long_status_changed (std::string val);
+    void presence_changed (std::string val);
+    void status_changed (std::string val);
 
   private:
     void* display_name_notifier;
-    void* short_status_notifier;
-    void* long_status_notifier;
+    void* presence_notifier;
+    void* status_notifier;
     std::string display_name;
-    std::string short_status;
-    std::string long_status;
+    std::string presence;
+    std::string status;
   };
 };
 

Modified: branches/gnome-2-24/lib/engine/framework/personal-details.h
==============================================================================
--- branches/gnome-2-24/lib/engine/framework/personal-details.h	(original)
+++ branches/gnome-2-24/lib/engine/framework/personal-details.h	Sat Nov 15 18:32:40 2008
@@ -52,15 +52,18 @@
 
     virtual const std::string get_display_name () const = 0;
 
-    virtual const std::string get_short_status () const = 0;
+    virtual const std::string get_presence () const = 0;
 
-    virtual const std::string get_long_status () const = 0;
+    virtual const std::string get_status () const = 0;
 
     virtual void set_display_name (const std::string display_name) = 0;
 
-    virtual void set_short_status (const std::string short_status) = 0;
+    virtual void set_presence (const std::string presence) = 0;
 
-    virtual void set_long_status (const std::string long_status) = 0;
+    virtual void set_status (const std::string status) = 0;
+
+    virtual void set_presence_info (const std::string presence,
+                                    const std::string status) = 0;
 
     sigc::signal<void> updated;
   };

Modified: branches/gnome-2-24/src/endpoints/sip-endpoint.cpp
==============================================================================
--- branches/gnome-2-24/src/endpoints/sip-endpoint.cpp	(original)
+++ branches/gnome-2-24/src/endpoints/sip-endpoint.cpp	Sat Nov 15 18:32:40 2008
@@ -349,8 +349,8 @@
 void Opal::Sip::EndPoint::publish (const Ekiga::PersonalDetails & details)
 {
   std::string hostname = (const char *) PIPSocket::GetHostName ();
-  std::string short_status = ((Ekiga::PersonalDetails &) (details)).get_short_status ();
-  std::string long_status = ((Ekiga::PersonalDetails &) (details)).get_long_status ();
+  std::string presence = ((Ekiga::PersonalDetails &) (details)).get_presence ();
+  std::string status = ((Ekiga::PersonalDetails &) (details)).get_status ();
 
   for (std::list<std::string>::iterator it = aors.begin ();
        it != aors.end ();
@@ -370,10 +370,10 @@
     data += "\">\r\n";
 
     data += "<note>";
-    data += short_status.c_str ();
-    if (!long_status.empty ()) {
+    data += presence.c_str ();
+    if (!status.empty ()) {
       data += " - ";
-      data += long_status.c_str ();
+      data += status.c_str ();
     }
     data += "</note>\r\n";
 
@@ -390,7 +390,7 @@
     data += "</tuple>\r\n";
     data += "</presence>\r\n";
 
-    Publish (to, data, 300); // TODO: allow to change the 500 
+    Publish (to, data, 60); // TODO: allow to change the 500 
   }
 }
 

Modified: branches/gnome-2-24/src/gui/main.cpp
==============================================================================
--- branches/gnome-2-24/src/gui/main.cpp	(original)
+++ branches/gnome-2-24/src/gui/main.cpp	Sat Nov 15 18:32:40 2008
@@ -1706,6 +1706,7 @@
 
   item = gtk_tool_item_new ();
   mw->status_option_menu = status_menu_new (); 
+  mw->priv->status_option_menu = status_menu_new (*mw->priv->core); 
   status_menu_set_parent_window (STATUS_MENU (mw->status_option_menu), 
                                  GTK_WINDOW (main_window));
   gtk_container_add (GTK_CONTAINER (item), mw->status_option_menu);

Modified: branches/gnome-2-24/src/gui/statusicon.cpp
==============================================================================
--- branches/gnome-2-24/src/gui/statusicon.cpp	(original)
+++ branches/gnome-2-24/src/gui/statusicon.cpp	Sat Nov 15 18:32:40 2008
@@ -119,7 +119,7 @@
 
 static void
 statusicon_set_status (StatusIcon *widget,
-                       const std::string & short_status);
+                       const std::string & presence);
 
 static void
 statusicon_set_inacall (StatusIcon *widget,
@@ -351,7 +351,7 @@
 personal_details_updated_cb (StatusIcon* self,
 			     Ekiga::PersonalDetails* details)
 {
-  statusicon_set_status (self, details->get_short_status ());
+  statusicon_set_status (self, details->get_presence ());
 }
 
 
@@ -450,7 +450,7 @@
 
 void
 statusicon_set_status (StatusIcon *statusicon,
-                       const std::string & short_status)
+                       const std::string & presence)
 {
   GtkFrontend *frontend = NULL;
   GtkWidget *chat_window = NULL;
@@ -463,11 +463,11 @@
   chat_window = GTK_WIDGET (frontend->get_chat_window ());
 
   /* Update the status icon */
-  if (short_status == "away")
+  if (presence == "away")
     pixbuf = gtk_widget_render_icon (chat_window, GM_STOCK_STATUS_AWAY, 
                                      GTK_ICON_SIZE_MENU, NULL); 
 
-  else if (short_status == "dnd")
+  else if (presence == "dnd")
     pixbuf = gtk_widget_render_icon (chat_window, GM_STOCK_STATUS_DND, 
                                      GTK_ICON_SIZE_MENU, NULL); 
   else
@@ -477,7 +477,7 @@
   gtk_status_icon_set_from_pixbuf (GTK_STATUS_ICON (statusicon), pixbuf);
   g_object_unref (pixbuf);
 
-  statusicon->priv->status = short_status;
+  statusicon->priv->status = presence;
 }
 
 
@@ -538,7 +538,7 @@
   Ekiga::CallCore *call_core = dynamic_cast<Ekiga::CallCore*> (core.get ("call-core"));
   GtkWidget *chat_window = GTK_WIDGET (frontend->get_chat_window ());
 
-  statusicon_set_status (self, details->get_short_status ());
+  statusicon_set_status (self, details->get_presence ());
   conn = details->updated.connect (sigc::bind (sigc::ptr_fun (personal_details_updated_cb), self, details));
   self->priv->connections.push_back (conn);
 

Modified: branches/gnome-2-24/src/gui/statusmenu.cpp
==============================================================================
--- branches/gnome-2-24/src/gui/statusmenu.cpp	(original)
+++ branches/gnome-2-24/src/gui/statusmenu.cpp	Sat Nov 15 18:32:40 2008
@@ -48,6 +48,8 @@
 #include "config.h"
 #include "statusmenu.h"
 
+#include "personal-details.h"
+
 #include "gmconf.h"
 #include "gmstockicons.h"
 
@@ -56,6 +58,9 @@
 
 struct _StatusMenuPrivate
 {
+  gmref_ptr<Ekiga::PersonalDetails> personal_details;
+  std::vector<sigc::connection> connections;
+
   GtkListStore *list_store; // List store storing the menu
   GtkWindow    *parent;     // Parent window
 };
@@ -161,32 +166,14 @@
                                      gpointer data);
 
 
-/** This notifier is triggered when the long status message is modified. 
- *
- * It updates the StatusMenu content with the new value as current choice.
- *
- * @param id is the GmConf notifier id
- * @param entry is the GmConfEntry for which the notification was triggered
- * @param data is a pointer to the StatusMenu
- */
-static void
-long_status_message_changed (gpointer id,
-                             GmConfEntry *entry,
-                             gpointer data);
-
-
-/** This notifier is triggered when the short status message is modified. 
+/** This callback is triggered when the user details are modified.
  *
  * It updates the StatusMenu content with the new value as current choice.
  *
- * @param id is the GmConf notifier id
- * @param entry is the GmConfEntry for which the notification was triggered
- * @param data is a pointer to the StatusMenu
+ * @param self is a pointer to the StatusMenu
  */
 static void
-short_status_message_changed (gpointer id,
-                              GmConfEntry *entry,
-                              gpointer data);
+on_details_updated (StatusMenu *self);
 
 
 /**
@@ -207,13 +194,13 @@
 /** This function updates the default active status in the StatusMenu.
  *
  * @param self is the StatusMenu
- * @param short_status is the short status of the current status
- * @param long_status is the long status description of the current status
+ * @param presence is the short status of the current status
+ * @param status is the long status description of the current status
  */
 static void
 status_menu_set_option (StatusMenu *self,
-                        const char *short_status,
-                        const char *long_status);
+                        const std::string & presence,
+                        const std::string & status);
 
 
 /** This function presents a popup allowing to remove some of the user defined
@@ -245,8 +232,6 @@
 static void status_menu_class_init (gpointer g_class,
                                     gpointer class_data);
 
-static void status_menu_init (StatusMenu *);
-
 static void status_menu_dispose (GObject *obj);
 
 static void status_menu_finalize (GObject *obj);
@@ -273,7 +258,7 @@
                             gpointer data)
 {
   GtkTreeIter iter;
-  
+
   int i = 0;
   gchar* status = NULL;
 
@@ -291,33 +276,27 @@
     switch (i)
       {
       case TYPE_ONLINE:
-        gm_conf_set_string (PERSONAL_DATA_KEY "short_status", "online");
-        gm_conf_set_string (PERSONAL_DATA_KEY "long_status", "");
+        self->priv->personal_details->set_presence_info ("online", "");
         break;
 
       case TYPE_AWAY:
-        gm_conf_set_string (PERSONAL_DATA_KEY "short_status", "away");
-        gm_conf_set_string (PERSONAL_DATA_KEY "long_status", "");
+        self->priv->personal_details->set_presence_info ("away", "");
         break;
 
       case TYPE_DND:
-        gm_conf_set_string (PERSONAL_DATA_KEY "short_status", "dnd");
-        gm_conf_set_string (PERSONAL_DATA_KEY "long_status", "");
+        self->priv->personal_details->set_presence_info ("dnd", "");
         break;
 
       case TYPE_CUSTOM_ONLINE:
-        gm_conf_set_string (PERSONAL_DATA_KEY "short_status", "online");
-        gm_conf_set_string (PERSONAL_DATA_KEY "long_status", status);
+        self->priv->personal_details->set_presence_info ("online", status);
         break;
 
       case TYPE_CUSTOM_AWAY:
-        gm_conf_set_string (PERSONAL_DATA_KEY "short_status", "away");
-        gm_conf_set_string (PERSONAL_DATA_KEY "long_status", status);
+        self->priv->personal_details->set_presence_info ("away", status);
         break;
 
       case TYPE_CUSTOM_DND:
-        gm_conf_set_string (PERSONAL_DATA_KEY "short_status", "dnd");
-        gm_conf_set_string (PERSONAL_DATA_KEY "long_status", status);
+        self->priv->personal_details->set_presence_info ("dnd", status);
         break;
 
       case TYPE_CUSTOM_ONLINE_NEW:
@@ -371,52 +350,12 @@
 
 
 static void
-long_status_message_changed (gpointer /*id*/,
-                             GmConfEntry *entry,
-                             gpointer data)
-{
-  StatusMenu* self = STATUS_MENU (data);
-  const char* long_status = NULL;
-  char* short_status = NULL;
-
-  g_return_if_fail (self != NULL);
-
-  short_status = gm_conf_get_string (PERSONAL_DATA_KEY "short_status");
-  long_status = gm_conf_entry_get_string (entry);
-
-  if (short_status == NULL)
-    short_status = g_strdup ("");
-
-  status_menu_set_option (self, short_status, long_status);
-
-  g_free (short_status);
-}
-
-
-static void
-short_status_message_changed (gpointer /*id*/,
-                              GmConfEntry *entry,
-                              gpointer data)
+on_details_updated (StatusMenu *self)
 {
-  StatusMenu* self = STATUS_MENU (data);
-  const char* short_status = NULL;
-  char* long_status = NULL;
-
-  g_return_if_fail (self != NULL);
-
-  short_status = gm_conf_entry_get_string (entry);
-  long_status = gm_conf_get_string (PERSONAL_DATA_KEY "long_status");
-
-  if (long_status == NULL)
-    long_status = g_strdup ("");
-
-  status_menu_set_option (self, short_status, long_status);
-
-  g_free (long_status);
+  status_menu_set_option (self, self->priv->personal_details->get_presence (), self->priv->personal_details->get_status ());
 }
 
 
-
 /*
  * Static methods
  */
@@ -502,43 +441,45 @@
                         -1); 
     g_object_unref (icon);
   }
+
+  status_menu_set_option (self, self->priv->personal_details->get_presence (), self->priv->personal_details->get_status ());
 }
 
 
 static void
 status_menu_set_option (StatusMenu *self,
-                        const char *short_status,
-                        const char *long_status)
+                        const std::string & presence,
+                        const std::string & status)
 {
   GtkTreeIter iter;
 
   bool valid = false;
-  gchar *status = NULL;
+  gchar *sstatus = NULL;
   int i = 0;
   int cpt = 0;
 
-  g_return_if_fail (short_status != NULL && long_status != NULL);
+  g_return_if_fail (!presence.empty ());
 
   valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (self->priv->list_store), &iter);
   while (valid) {
 
     gtk_tree_model_get (GTK_TREE_MODEL (self->priv->list_store), &iter, 
                         COL_MESSAGE_TYPE, &i,
-                        COL_MESSAGE, &status, -1); 
+                        COL_MESSAGE, &sstatus, -1); 
 
     // Check if it is a custom status message and if it is in the list
     if (i == TYPE_CUSTOM_ONLINE || i == TYPE_CUSTOM_AWAY || i == TYPE_CUSTOM_DND) {
-      if (!strcmp (status_types_names[i - NUM_STATUS_TYPES - 1], short_status) && !strcmp (long_status, status))
+      if (presence == status_types_names[i - NUM_STATUS_TYPES - 1] && status == sstatus)
         break;
     }
 
     // Long status empty, the user did not set a custom message
     if (i == TYPE_ONLINE || i == TYPE_AWAY || i == TYPE_DND) {
-      if (long_status && !strcmp(long_status, "") && !strcmp (status_types_names[i], short_status)) 
+      if (status.empty () && presence == status_types_names[i]) 
         break;
     }
 
-    g_free (status);
+    g_free (sstatus);
 
     cpt++;
     valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (self->priv->list_store), &iter);
@@ -547,8 +488,8 @@
   if (valid) {
     gtk_combo_box_set_active (GTK_COMBO_BOX (self), cpt);
 
-    if (status)
-      g_free (status);
+    if (sstatus)
+      g_free (sstatus);
   }
 }
 
@@ -576,12 +517,12 @@
   int response = 0;
   int i = 0;
   gchar *message = NULL;
-  gchar *short_status = NULL;
-  gchar *long_status = NULL;
-  
+  gchar *presence = NULL;
+  gchar *status = NULL;
+
   // Current status
-  short_status = gm_conf_get_string (PERSONAL_DATA_KEY "short_status");
-  long_status = gm_conf_get_string (PERSONAL_DATA_KEY "long_status");
+  presence = gm_conf_get_string (PERSONAL_DATA_KEY "short_status");
+  status = gm_conf_get_string (PERSONAL_DATA_KEY "long_status");
 
   // Build the dialog
   dialog = gtk_dialog_new_with_buttons (_("Custom Message"),
@@ -642,13 +583,13 @@
         gtk_tree_model_get (GTK_TREE_MODEL (self->priv->list_store), &iter,
                             COL_ICON, &pixbuf, 
                             COL_MESSAGE, &message,
-			    -1);
+                            -1);
         gtk_list_store_append (GTK_LIST_STORE (list_store), &liter);
         gtk_list_store_set (GTK_LIST_STORE (list_store), &liter, 
                             COL_ICON, pixbuf, 
                             COL_MESSAGE, message,
                             COL_MESSAGE_TYPE, i,
-			    -1);
+                            -1);
         g_free (message);
         g_object_unref (pixbuf);
       }
@@ -667,17 +608,17 @@
 
     switch (response)
       {
-        case GTK_RESPONSE_APPLY:
-          if (gtk_tree_selection_get_selected (selection, NULL, &iter)) 
-            gtk_list_store_remove (GTK_LIST_STORE (list_store), &iter);
-          if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter)) 
-            gtk_tree_selection_select_iter (selection, &iter);
-          else
-            close = true;
+      case GTK_RESPONSE_APPLY:
+        if (gtk_tree_selection_get_selected (selection, NULL, &iter)) 
+          gtk_list_store_remove (GTK_LIST_STORE (list_store), &iter);
+        if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter)) 
+          gtk_tree_selection_select_iter (selection, &iter);
+        else
+          close = true;
         break;
 
-        case GTK_RESPONSE_CLOSE:
-        default:
+      case GTK_RESPONSE_CLOSE:
+      default:
         close = true;
       }
   }
@@ -689,7 +630,7 @@
       gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter,
                           1, &message,
                           2, &i, -1);
-      if (long_status && message && !strcmp (long_status, message))
+      if (status && message && !strcmp (status, message))
         found = true;
 
       conf_list[i - NUM_STATUS_TYPES - 1] = g_slist_append (conf_list[i - NUM_STATUS_TYPES - 1], g_strdup (message));
@@ -705,11 +646,7 @@
 
   if (!found) {
     // Reset current config
-    gm_conf_set_string (PERSONAL_DATA_KEY "short_status", "online");
-    gm_conf_set_string (PERSONAL_DATA_KEY "long_status", "");
-  }
-  else {
-    status_menu_set_option (STATUS_MENU (self), short_status, long_status);
+    self->priv->personal_details->set_presence_info ("online", "");
   }
 
   gtk_widget_destroy (dialog);
@@ -720,8 +657,8 @@
 status_menu_new_status_message_dialog_run (StatusMenu *self,
                                            int option)
 {
-  gchar *short_status = NULL;
-  gchar *long_status = NULL;
+  gchar *presence = NULL;
+  gchar *status = NULL;
 
   GSList *clist = NULL;
   GtkWidget *dialog = NULL;
@@ -735,8 +672,8 @@
 
   const char *message = NULL;
 
-  short_status = gm_conf_get_string (PERSONAL_DATA_KEY "short_status");
-  long_status = gm_conf_get_string (PERSONAL_DATA_KEY "long_status");
+  presence = gm_conf_get_string (PERSONAL_DATA_KEY "short_status");
+  status = gm_conf_get_string (PERSONAL_DATA_KEY "long_status");
 
   dialog = gtk_dialog_new_with_buttons (_("Custom Message"),
                                         self->priv->parent,
@@ -777,25 +714,24 @@
     if (strcmp (message, "")) { 
       clist = g_slist_append (clist, g_strdup (message));
       gm_conf_set_string_list (status_types_keys[option - NUM_STATUS_TYPES - 1], clist);
-      gm_conf_set_string (PERSONAL_DATA_KEY "long_status", message);
-      gm_conf_set_string (PERSONAL_DATA_KEY "short_status", status_types_names[option - NUM_STATUS_TYPES - 1]);
+      self->priv->personal_details->set_presence_info (status_types_names[option - NUM_STATUS_TYPES - 1], message);
     }
     else {
-      status_menu_set_option (self, short_status, long_status);
+      status_menu_set_option (self, presence, status);
     }
     g_slist_foreach (clist, (GFunc) g_free, NULL);
     g_slist_free (clist);
     break;
 
   default:
-    status_menu_set_option (self, short_status, long_status);
+    status_menu_set_option (self, presence, status);
     break;
   }
 
   gtk_widget_destroy (dialog);
 
-  g_free (short_status);
-  g_free (long_status);
+  g_free (presence);
+  g_free (status);
 }
 
 
@@ -817,13 +753,71 @@
 
 
 static void
-status_menu_init (StatusMenu *self)
+status_menu_dispose (GObject *obj)
 {
+  StatusMenu *self = NULL;
+
+  self = STATUS_MENU (obj);
+  delete self->priv;
+
+  self->priv = NULL;
+
+  // NULLify everything
+  parent_class->dispose (obj);
+}
+
+
+static void
+status_menu_finalize (GObject *obj)
+{
+  parent_class->finalize (obj);
+}
+
+
+GType
+status_menu_get_type (void)
+{
+  static GType status_menu_type = 0;
+
+  if (status_menu_type == 0) {
+
+    static const GTypeInfo status_menu_info =
+      {
+        sizeof (StatusMenuClass),
+        NULL,
+        NULL,
+        (GClassInitFunc) status_menu_class_init,
+        NULL,
+        NULL,
+        sizeof (StatusMenu),
+        0,
+        NULL,
+        NULL
+      };
+
+    status_menu_type = g_type_register_static (GTK_TYPE_COMBO_BOX,
+                                               "StatusMenu",
+                                               &status_menu_info,
+                                               (GTypeFlags) 0);
+  }
+
+  return status_menu_type;
+}
+
+
+GtkWidget *
+status_menu_new (Ekiga::ServiceCore & core)
+{
+  StatusMenu *self = NULL;
+
+  sigc::connection conn;
   GtkCellRenderer *renderer = NULL;
   GSList *custom_status_array [NUM_STATUS_TYPES];
 
-  self->priv = new StatusMenuPrivate;
+  self = (StatusMenu *) g_object_new (STATUS_MENU_TYPE, NULL);
+  self->priv = new StatusMenuPrivate ();
 
+  self->priv->personal_details = core.get ("personal-details");
   self->priv->parent = NULL;
   self->priv->list_store = gtk_list_store_new (NUM_COLUMNS,
                                                GDK_TYPE_PIXBUF,
@@ -851,7 +845,7 @@
     custom_status_array [i] = gm_conf_get_string_list (status_types_keys [i]);
 
   status_menu_populate (self, custom_status_array);
-  
+
   for (int i = 0 ; i < NUM_STATUS_TYPES ; i++) {
     g_slist_foreach (custom_status_array [i], (GFunc) g_free, 0);
     g_slist_free (custom_status_array [i]);
@@ -863,6 +857,7 @@
                                         (GtkTreeViewRowSeparatorFunc) status_menu_row_is_separator,
                                         NULL, NULL);
   gtk_container_set_border_width (GTK_CONTAINER (self), 0);
+  status_menu_set_option (self, self->priv->personal_details->get_presence (), self->priv->personal_details->get_status ());
 
   g_signal_connect (G_OBJECT (self), "changed",
                     G_CALLBACK (status_menu_option_changed), self);
@@ -874,71 +869,10 @@
   gm_conf_notifier_add (PERSONAL_DATA_KEY "dnd_custom_status", 
                         status_menu_custom_messages_changed, self);
 
-  gm_conf_notifier_add (PERSONAL_DATA_KEY "long_status", 
-                        long_status_message_changed, self);
-  gm_conf_notifier_add (PERSONAL_DATA_KEY "short_status", 
-                        short_status_message_changed, self);
-  gm_conf_notifier_trigger (PERSONAL_DATA_KEY "short_status");
-}
-
-
-static void
-status_menu_dispose (GObject *obj)
-{
-  StatusMenu *self = NULL;
-
-  self = STATUS_MENU (obj);
-  delete self->priv;
-
-  self->priv = NULL;
-
-  // NULLify everything
-  parent_class->dispose (obj);
-}
-
+  conn = self->priv->personal_details->updated.connect (sigc::bind (sigc::ptr_fun (on_details_updated), self)); 
+  self->priv->connections.push_back (conn);
 
-static void
-status_menu_finalize (GObject *obj)
-{
-  parent_class->finalize (obj);
-}
-
-
-GType
-status_menu_get_type (void)
-{
-  static GType status_menu_type = 0;
-
-  if (status_menu_type == 0) {
-
-    static const GTypeInfo status_menu_info =
-      {
-        sizeof (StatusMenuClass),
-        NULL,
-        NULL,
-        (GClassInitFunc) status_menu_class_init,
-        NULL,
-        NULL,
-        sizeof (StatusMenu),
-        0,
-        (GInstanceInitFunc) status_menu_init,
-        NULL
-      };
-
-    status_menu_type = g_type_register_static (GTK_TYPE_COMBO_BOX,
-                                               "StatusMenu",
-                                               &status_menu_info,
-                                               (GTypeFlags) 0);
-  }
-
-  return status_menu_type;
-}
-
-
-GtkWidget *
-status_menu_new ()
-{
-  return GTK_WIDGET (STATUS_MENU (g_object_new (STATUS_MENU_TYPE, NULL)));
+  return GTK_WIDGET (self);
 }
 
 

Modified: branches/gnome-2-24/src/gui/statusmenu.h
==============================================================================
--- branches/gnome-2-24/src/gui/statusmenu.h	(original)
+++ branches/gnome-2-24/src/gui/statusmenu.h	Sat Nov 15 18:32:40 2008
@@ -47,7 +47,7 @@
 #include <opal/manager.h>
 
 #include "call.h"
-
+#include "services.h"
 
 /** This implements a StatusMenu.
  */
@@ -83,7 +83,7 @@
 
 /** Create a new StatusMenu 
  */
-GtkWidget *status_menu_new ();
+GtkWidget *status_menu_new (Ekiga::ServiceCore & core);
 
 
 /** Set parent window for a StatusMenu 



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