[ekiga/ds-gtk-application] Call History: Generate the proper popup menu on contact selection.



commit 2ad44c7af85cae82ff04b0a885c4346634e89c64
Author: Damien Sandras <dsandras beip be>
Date:   Tue Mar 4 20:30:34 2014 +0100

    Call History: Generate the proper popup menu on contact selection.
    
    This uses the new ActorMenu/ContactActorMenu widget.

 .../gui/gtk-frontend/call-history-view-gtk.cpp     |   83 ++++++++++----------
 .../gui/gtk-frontend/call-history-view-gtk.h       |    3 +
 2 files changed, 43 insertions(+), 43 deletions(-)
---
diff --git a/lib/engine/gui/gtk-frontend/call-history-view-gtk.cpp 
b/lib/engine/gui/gtk-frontend/call-history-view-gtk.cpp
index fe0700c..842774b 100644
--- a/lib/engine/gui/gtk-frontend/call-history-view-gtk.cpp
+++ b/lib/engine/gui/gtk-frontend/call-history-view-gtk.cpp
@@ -43,7 +43,7 @@
 #include "menu-builder-tools.h"
 #include "menu-builder-gtk.h"
 #include "gm-cell-renderer-bitext.h"
-#include "live-object-menu.h"
+#include "actor-menu.h"
 
 
 struct null_deleter
@@ -87,6 +87,7 @@ static guint signals[LAST_SIGNAL] = { 0 };
 
 G_DEFINE_TYPE (CallHistoryViewGtk, call_history_view_gtk, GTK_TYPE_SCROLLED_WINDOW);
 
+
 /* react to a new call being inserted in history */
 static void
 on_contact_added (Ekiga::ContactPtr contact,
@@ -168,55 +169,43 @@ on_clicked (GtkWidget *tree,
 {
   GtkWidget *menu = NULL;
   GtkBuilder *builder = NULL;
-  GtkTreeModel *model = NULL;
-  GtkTreePath *path = NULL;
-  GtkTreeIter iter;
   History::Contact *contact = NULL;
 
   CallHistoryViewGtk *self = CALL_HISTORY_VIEW_GTK (data);
 
-  model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree));
-
-  if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (tree),
-                                    (gint) event->x, (gint) event->y,
-                                    &path, NULL, NULL, NULL)) {
-
-    if (gtk_tree_model_get_iter (model, &iter, path)) {
-
-      gtk_tree_model_get (model, &iter,
-                         COLUMN_CONTACT, &contact,
-                         -1);
-
-      if (event->type == GDK_BUTTON_PRESS && event->button == 3) {
+  /* Ignore no click events */
+  if (event->type != GDK_BUTTON_PRESS && event->type != GDK_2BUTTON_PRESS)
+    return TRUE;
 
-        builder = gtk_builder_new ();
+  /* Set or reset ContactActor data */
+  call_history_view_gtk_get_selected (self, &contact);
+  if (contact == NULL) {
+    return TRUE;
+  }
 
-        self->priv->contact_menu->set_data (Ekiga::ContactPtr (contact, null_deleter ()),
-                                            contact->get_uri ());
-        std::string menu_content = self->priv->contact_menu->as_xml () + self->priv->menu->as_xml ();
-        gtk_builder_add_from_string (builder,
-                                     Ekiga::ActorMenu::get_xml_menu ("popup", menu_content, true).c_str (),
-                                     -1, NULL);
-        menu = gtk_menu_new_from_model (G_MENU_MODEL (gtk_builder_get_object (builder, "popup")));
-        gtk_widget_insert_action_group (menu, "win", G_ACTION_GROUP (g_application_get_default ()));
-       gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
-                       NULL, NULL, event->button, event->time);
-       g_object_ref (menu);
-        g_object_unref (builder);
-      }
-      if (event->type == GDK_2BUTTON_PRESS) {
+  if (event->type == GDK_BUTTON_PRESS && event->button == 3) {
+
+    builder = gtk_builder_new ();
+    std::string menu_content = self->priv->contact_menu->as_xml () + self->priv->menu->as_xml ();
+    gtk_builder_add_from_string (builder,
+                                 Ekiga::ActorMenu::get_xml_menu ("popup", menu_content, true).c_str (),
+                                 -1, NULL);
+    menu = gtk_menu_new_from_model (G_MENU_MODEL (gtk_builder_get_object (builder, "popup")));
+    gtk_widget_insert_action_group (menu, "win", G_ACTION_GROUP (g_application_get_default ()));
+    gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
+                    NULL, NULL, event->button, event->time);
+    g_object_ref (menu);
+    g_object_unref (builder);
+  }
 
-        std::cout << "FIXME" << std::endl << std::flush;
-       if (contact != NULL) {
+  if (event->type == GDK_2BUTTON_PRESS) {
 
-         Ekiga::TriggerMenuBuilder builder;
+    if (contact != NULL) {
 
-         contact->populate_menu (builder);
-       }
-      }
+      Ekiga::TriggerMenuBuilder tbuilder;
 
+      contact->populate_menu (tbuilder);
     }
-    gtk_tree_path_free (path);
   }
 
   return TRUE;
@@ -227,9 +216,19 @@ on_selection_changed (G_GNUC_UNUSED GtkTreeSelection* selection,
                      gpointer data)
 {
   CallHistoryViewGtk* self = NULL;
+  History::Contact *contact = NULL;
 
   self = CALL_HISTORY_VIEW_GTK (data);
 
+  /* Set or reset ContactActor data */
+  call_history_view_gtk_get_selected (self, &contact);
+
+  if (contact == NULL)
+    self->priv->contact_menu->set_data ();
+  else
+    self->priv->contact_menu->set_data (Ekiga::ContactPtr (contact, null_deleter ()),
+                                        contact->get_uri ());
+
   g_signal_emit (self, signals[SELECTION_CHANGED_SIGNAL], 0);
 }
 
@@ -374,10 +373,8 @@ call_history_view_gtk_new (boost::shared_ptr<History::Book> book,
   on_book_updated(self);
 
   /* register book actions */
-  self->priv->menu =
-    boost::shared_ptr<Ekiga::ActorMenu> (new Ekiga::ActorMenu (*book));
-  self->priv->contact_menu =
-    boost::shared_ptr<Ekiga::ContactActorMenu> (new Ekiga::ContactActorMenu (*ccore));
+  self->priv->menu = Ekiga::ActorMenuPtr (Ekiga::ActorMenu::create (*book));
+  self->priv->contact_menu = Ekiga::ContactActorMenuPtr (Ekiga::ContactActorMenu::create (*ccore));
 
   return GTK_WIDGET (self);
 }
diff --git a/lib/engine/gui/gtk-frontend/call-history-view-gtk.h 
b/lib/engine/gui/gtk-frontend/call-history-view-gtk.h
index 58ae367..1f74734 100644
--- a/lib/engine/gui/gtk-frontend/call-history-view-gtk.h
+++ b/lib/engine/gui/gtk-frontend/call-history-view-gtk.h
@@ -59,6 +59,9 @@ GtkWidget *call_history_view_gtk_new (boost::shared_ptr<History::Book> book,
 bool call_history_view_gtk_populate_menu_for_selected (CallHistoryViewGtk* self,
                                                       Ekiga::MenuBuilder &builder);
 
+void call_history_view_gtk_get_selected (CallHistoryViewGtk* self,
+                                         History::Contact** contact);
+
 /* The signals emitted by this widget:
  *
  * - "selection-changed", comes with nothing -- it just says that either


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