[ekiga] Incoming call dialog: Dropped it.



commit 6c6f50b3cb9ffe53239be80023b0500aa6ab508f
Author: Damien Sandras <dsandras beip be>
Date:   Tue May 1 14:34:19 2012 +0200

    Incoming call dialog: Dropped it.
    
    Dropped incoming call dialog and replace it by the call window.
    
    The call window is now automatically shown on incoming calls if our
    notification server does not support actions.
    This test is done through a local static method.
    
    An answer button was added to the dialog.
    
    If the notification server supports actions, we rely on the engine to
    display the incoming call notification and handle it.

 src/gui/call_window.cpp |   82 +++++++++++++++++++++++--
 src/gui/main_window.cpp |  157 +----------------------------------------------
 2 files changed, 79 insertions(+), 160 deletions(-)
---
diff --git a/src/gui/call_window.cpp b/src/gui/call_window.cpp
index 8b2aee3..f156900 100644
--- a/src/gui/call_window.cpp
+++ b/src/gui/call_window.cpp
@@ -68,6 +68,10 @@
 #include "dbus-helper/dbus.h"
 #endif
 
+#ifdef HAVE_NOTIFY
+#include <libnotify/notify.h>
+#endif
+
 #ifndef WIN32
 #include <signal.h>
 #include <gdk/gdkx.h>
@@ -119,6 +123,7 @@ struct _EkigaCallWindowPrivate
 
   GtkWidget *main_menu;
   GtkWidget *call_panel_toolbar;
+  GtkWidget *pickup_button;
   GtkWidget *hangup_button;
   GtkWidget *hold_button;
   GtkWidget *audio_settings_button;
@@ -207,6 +212,7 @@ enum {
   CHANNEL_LAST
 };
 
+static bool notify_has_actions (void);
 
 static void zoom_in_changed_cb (GtkWidget *widget,
                                 gpointer data);
@@ -227,6 +233,9 @@ static void stay_on_top_changed_nt (gpointer id,
                                     GmConfEntry *entry,
                                     gpointer data);
 
+static void pickup_call_cb (GtkWidget * /*widget*/,
+                            gpointer data);
+
 static void hangup_call_cb (GtkWidget * /*widget*/,
                             gpointer data);
 
@@ -456,6 +465,28 @@ static void ekiga_call_window_connect_engine_signals (EkigaCallWindow *cw);
 
 static void ekiga_call_window_init_gui (EkigaCallWindow *cw);
 
+static bool
+notify_has_actions (void)
+{
+  static int accepts_actions = -1;
+#ifdef HAVE_NOTIFY
+  if (accepts_actions == -1) {  // initialise accepts_actions at the first call
+    accepts_actions = 0;
+    GList *capabilities = notify_get_server_caps ();
+    if (capabilities != NULL) {
+      for (GList *c = capabilities ; c != NULL ; c = c->next) {
+        if (strcmp ((char*)c->data, "actions") == 0 ) {
+          accepts_actions = 1;
+          break;
+        }
+      }
+      g_list_foreach (capabilities, (GFunc)g_free, NULL);
+      g_list_free (capabilities);
+    }
+  }
+#endif
+  return (accepts_actions > 0);
+}
 
 static void
 stay_on_top_changed_nt (G_GNUC_UNUSED gpointer id,
@@ -576,6 +607,16 @@ fullscreen_changed_cb (G_GNUC_UNUSED GtkWidget *widget,
 }
 
 static void
+pickup_call_cb (GtkWidget * /*widget*/,
+                gpointer data)
+{
+  EkigaCallWindow *cw = EKIGA_CALL_WINDOW (data);
+
+  if (cw->priv->current_call)
+    cw->priv->current_call->answer ();
+}
+
+static void
 hangup_call_cb (GtkWidget * /*widget*/,
                 gpointer data)
 {
@@ -1093,7 +1134,7 @@ on_setup_call_cb (G_GNUC_UNUSED boost::shared_ptr<Ekiga::CallManager> manager,
   if (call->is_outgoing ())
     ekiga_call_window_set_status (cw, _("Calling %s..."), call->get_remote_uri ().c_str ());
 
-  ekiga_call_window_update_calling_state (cw, Calling);
+  ekiga_call_window_update_calling_state (cw, cw->priv->calling_state);
 }
 
 static void
@@ -1363,8 +1404,10 @@ ekiga_call_window_update_calling_state (EkigaCallWindow *cw,
       ekiga_call_window_channels_menu_update_sensitivity (cw, false, false, false);
 
       /* Update the menus and toolbar items */
+      gtk_menu_set_sensitive (cw->priv->main_menu, "connect", false);
       gtk_menu_set_sensitive (cw->priv->main_menu, "disconnect", false);
       gtk_menu_section_set_sensitive (cw->priv->main_menu, "hold_call", false);
+      gtk_widget_set_sensitive (GTK_WIDGET (cw->priv->pickup_button), false);
       gtk_widget_set_sensitive (GTK_WIDGET (cw->priv->hangup_button), false);
       gtk_widget_set_sensitive (GTK_WIDGET (cw->priv->hold_button), false);
 
@@ -1381,7 +1424,9 @@ ekiga_call_window_update_calling_state (EkigaCallWindow *cw,
       gtk_widget_show (cw->priv->call_frame);
 
       /* Update the menus and toolbar items */
+      gtk_widget_set_sensitive (GTK_WIDGET (cw->priv->pickup_button), false);
       gtk_widget_set_sensitive (GTK_WIDGET (cw->priv->hangup_button), true);
+      gtk_menu_set_sensitive (cw->priv->main_menu, "connect", false);
       gtk_menu_set_sensitive (cw->priv->main_menu, "disconnect", true);
       break;
 
@@ -1392,8 +1437,10 @@ ekiga_call_window_update_calling_state (EkigaCallWindow *cw,
       gtk_widget_show (cw->priv->call_frame);
 
       /* Update the menus and toolbar items */
+      gtk_menu_set_sensitive (cw->priv->main_menu, "connect", false);
       gtk_menu_set_sensitive (cw->priv->main_menu, "disconnect", true);
       gtk_menu_section_set_sensitive (cw->priv->main_menu, "hold_call", true);
+      gtk_widget_set_sensitive (GTK_WIDGET (cw->priv->pickup_button), false);
       gtk_widget_set_sensitive (GTK_WIDGET (cw->priv->hangup_button), true);
       gtk_widget_set_sensitive (GTK_WIDGET (cw->priv->hold_button), true);
       break;
@@ -1401,12 +1448,18 @@ ekiga_call_window_update_calling_state (EkigaCallWindow *cw,
 
     case Called:
 
-      /* Show/hide call frame */
-      gtk_widget_show (cw->priv->call_frame);
-
       /* Update the menus and toolbar items */
+      gtk_widget_set_sensitive (GTK_WIDGET (cw->priv->pickup_button), true);
       gtk_widget_set_sensitive (GTK_WIDGET (cw->priv->hangup_button), true);
+      gtk_menu_set_sensitive (cw->priv->main_menu, "connect", true);
       gtk_menu_set_sensitive (cw->priv->main_menu, "disconnect", true);
+
+      /* Show/hide call frame and call window (if no notifications */
+      gtk_widget_show (cw->priv->call_frame);
+      if (!notify_has_actions ()) {
+        gtk_window_present (GTK_WINDOW (cw));
+        gtk_widget_show (GTK_WIDGET (cw));
+      }
       break;
 
     default:
@@ -1916,6 +1969,10 @@ ekiga_call_window_init_menu (EkigaCallWindow *cw)
     {
       GTK_MENU_NEW (_("_Call")),
 
+      GTK_MENU_ENTRY("connect", _("_Pick up"), _("Pick up the current call"),
+		     GM_STOCK_PHONE_PICK_UP_16, 'd',
+		     G_CALLBACK (pickup_call_cb), cw, false),
+
       GTK_MENU_ENTRY("disconnect", _("_Hangup"), _("Hangup the current call"),
 		     GM_STOCK_PHONE_HANG_UP_16, 'd',
 		     G_CALLBACK (hangup_call_cb), cw, false),
@@ -2302,7 +2359,22 @@ ekiga_call_window_init_gui (EkigaCallWindow *cw)
   gtk_container_add (GTK_CONTAINER (cw->priv->call_frame), hbox);
   gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (cw->priv->call_frame), true, true, 2);
 
-  /* Hangup */
+  /* Pick-up */
+  item = gtk_tool_item_new ();
+  cw->priv->pickup_button = gtk_button_new ();
+  image = gtk_image_new_from_stock (GM_STOCK_PHONE_PICK_UP_24, GTK_ICON_SIZE_LARGE_TOOLBAR);
+  gtk_container_add (GTK_CONTAINER (cw->priv->pickup_button), image);
+  gtk_container_add (GTK_CONTAINER (item), cw->priv->pickup_button);
+  gtk_button_set_relief (GTK_BUTTON (cw->priv->pickup_button), GTK_RELIEF_NONE);
+  gtk_widget_show (cw->priv->pickup_button);
+  gtk_toolbar_insert (GTK_TOOLBAR (cw->priv->call_panel_toolbar),
+		      GTK_TOOL_ITEM (item), -1);
+  gtk_widget_set_sensitive (GTK_WIDGET (cw->priv->pickup_button), false);
+  gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (item),
+				  _("Hang up the current call"));
+  g_signal_connect (cw->priv->pickup_button, "clicked",
+		    G_CALLBACK (pickup_call_cb), cw);
+
   item = gtk_tool_item_new ();
   cw->priv->hangup_button = gtk_button_new ();
   image = gtk_image_new_from_stock (GM_STOCK_PHONE_HANG_UP_24, GTK_ICON_SIZE_LARGE_TOOLBAR);
diff --git a/src/gui/main_window.cpp b/src/gui/main_window.cpp
index fce5ff2..64d80d2 100644
--- a/src/gui/main_window.cpp
+++ b/src/gui/main_window.cpp
@@ -201,9 +201,6 @@ static void show_gm_window_cb (GtkWidget *widget,
 
 static gboolean on_delayed_hide_call_window_cb (gpointer data);
 
-static void ekiga_main_window_incoming_call_dialog_show (EkigaMainWindow *mw,
-                                                      boost::shared_ptr<Ekiga::Call>  call);
-
 static void ekiga_main_window_append_call_url (EkigaMainWindow *mw,
                                                const char *url);
 
@@ -607,8 +604,6 @@ static void on_setup_call_cb (boost::shared_ptr<Ekiga::CallManager> manager,
       return; // No call setup needed if already in a call
 
     audiooutput_core->start_play_event ("incoming_call_sound", 4000, 256);
-    if (!notify_has_actions ())
-      ekiga_main_window_incoming_call_dialog_show (mw, call);
 
     mw->priv->current_call = call;
     mw->priv->calling_state = Called;
@@ -708,39 +703,8 @@ static void on_cleared_call_cb (boost::shared_ptr<Ekiga::CallManager>  /*manager
   gtk_widget_set_sensitive (GTK_WIDGET (mw->priv->preview_button), true);
 }
 
-static void on_cleared_incoming_call_cb (std::string /*reason*/,
-                                         gpointer /*self*/)
-{
-  EkigaMainWindow *mw = EKIGA_MAIN_WINDOW (GnomeMeeting::Process ()->GetMainWindow ());
-  GtkWidget *call_window = NULL;
-
-  /* Update calling state */
-  if (mw->priv->current_call)
-    mw->priv->current_call = boost::shared_ptr<Ekiga::Call>();
-  mw->priv->calling_state = Standby;
-
-  boost::shared_ptr<Ekiga::AudioOutputCore> audiooutput_core = mw->priv->core->get<Ekiga::AudioOutputCore> ("audiooutput-core");
-  audiooutput_core->stop_play_event("incoming_call_sound");
-  audiooutput_core->stop_play_event("ring_tone_sound");
-
-  /* Hide call window */
-  if (!gm_conf_get_bool (VIDEO_DEVICES_KEY "enable_preview")) {
-    call_window = GnomeMeeting::Process ()->GetCallWindow ();
-    g_timeout_add_seconds (2, on_delayed_hide_call_window_cb, call_window);
-  }
-
-  /* Sensitive a few things back */
-  gtk_widget_set_sensitive (GTK_WIDGET (mw->priv->uri_toolbar), true);
-  gtk_widget_set_sensitive (GTK_WIDGET (mw->priv->preview_button), true);
-}
-
-
-static void on_incoming_call_gone_cb (gpointer self)
-{
-  gtk_widget_destroy (GTK_WIDGET (self));
-}
-
 
+// FIXME: this should be done through a notification
 static void on_missed_call_cb (boost::shared_ptr<Ekiga::CallManager>  /*manager*/,
                                boost::shared_ptr<Ekiga::Call>  call,
                                gpointer self)
@@ -754,6 +718,7 @@ static void on_missed_call_cb (boost::shared_ptr<Ekiga::CallManager>  /*manager*
   ekiga_main_window_push_message (mw, "%s", info);
   g_free (info);
 
+  // FIXME: the engine should take care of this
   /* If the cleared call is the current one, switch back to standby, otherwise return
    * as long as the information has been displayed */
   if (mw->priv->current_call && mw->priv->current_call->get_id () == call->get_id ()) {
@@ -892,30 +857,6 @@ on_audiooutput_device_removed_cb (const Ekiga::AudioOutputDevice & device,
 
 /* Implementation */
 static void
-incoming_call_response_cb (GtkDialog *incoming_call_popup,
-                           gint response,
-                           gpointer main_window)
-{
-  EkigaMainWindow *mw = EKIGA_MAIN_WINDOW (main_window);
-
-  gtk_widget_hide (GTK_WIDGET (incoming_call_popup));
-
-  if (mw->priv->current_call) {
-
-    switch (response) {
-    case 2:
-      mw->priv->current_call->answer ();
-      break;
-
-    default:
-    case 0:
-      mw->priv->current_call->hangup ();
-      break;
-    }
-  }
-}
-
-static void
 add_device_response_cb (GtkDialog *add_device_popup,
                            gint response,
                            gpointer data)
@@ -1257,100 +1198,6 @@ statusbar_clicked_cb (G_GNUC_UNUSED GtkWidget *widget,
 
 
 static void
-ekiga_main_window_incoming_call_dialog_show (EkigaMainWindow *mw,
-                                             boost::shared_ptr<Ekiga::Call>  call)
-{
-  GdkPixbuf *pixbuf = NULL;
-
-  GtkWidget *label = NULL;
-  GtkWidget *vbox = NULL;
-  GtkWidget *incoming_call_popup = NULL;
-
-  gchar *msg = NULL;
-
-  // FIXME could the call become invalid ?
-  const char *utf8_name = call->get_remote_party_name ().c_str ();
-  const char *utf8_app = call->get_remote_application ().c_str ();
-  const char *utf8_url = call->get_remote_uri ().c_str ();
-
-  g_return_if_fail (EKIGA_IS_MAIN_WINDOW (mw));
-
-  incoming_call_popup = gtk_dialog_new ();
-  gtk_dialog_add_button (GTK_DIALOG (incoming_call_popup),
-			 _("Reject"), 0);
-  gtk_dialog_add_button (GTK_DIALOG (incoming_call_popup),
-			 _("Accept"), 2);
-
-  gtk_dialog_set_default_response (GTK_DIALOG (incoming_call_popup), 2);
-
-  vbox = GTK_DIALOG (incoming_call_popup)->vbox;
-
-  msg = g_strdup_printf ("%s <i>%s</i>", _("Incoming call from"), (const char*) utf8_name);
-  label = gtk_label_new (NULL);
-  gtk_label_set_markup (GTK_LABEL (label), msg);
-  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 10);
-  gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.0);
-  gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
-  g_free (msg);
-
-  pixbuf = gtk_widget_render_icon (GTK_WIDGET (incoming_call_popup),
-				   GM_STOCK_PHONE_PICK_UP_16,
-				   GTK_ICON_SIZE_MENU, NULL);
-  gtk_window_set_icon (GTK_WINDOW (incoming_call_popup), pixbuf);
-  g_object_unref (pixbuf);
-
-  if (utf8_url) {
-
-    label = gtk_label_new (NULL);
-    msg = g_strdup_printf ("<b>%s</b> <span foreground=\"blue\"><u>%s</u></span>",
-                           _("Remote URI:"), utf8_url);
-    gtk_label_set_markup (GTK_LABEL (label), msg);
-    gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
-    gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 2);
-    gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
-    g_free (msg);
-  }
-
-  if (utf8_app) {
-
-    label = gtk_label_new (NULL);
-    msg = g_strdup_printf ("<b>%s</b> %s",
-			   _("Remote Application:"), utf8_app);
-    gtk_label_set_markup (GTK_LABEL (label), msg);
-    gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
-    gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 2);
-    gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
-    g_free (msg);
-  }
-
-  msg = g_strdup_printf (_("Call from %s"), (const char*) utf8_name);
-  gtk_window_set_title (GTK_WINDOW (incoming_call_popup), msg);
-  g_free (msg);
-  gtk_window_set_modal (GTK_WINDOW (incoming_call_popup), TRUE);
-  gtk_window_set_keep_above (GTK_WINDOW (incoming_call_popup), TRUE);
-  gtk_window_set_urgency_hint (GTK_WINDOW (mw), TRUE);
-  gtk_window_set_transient_for (GTK_WINDOW (incoming_call_popup),
-				GTK_WINDOW (mw));
-  // do not steal the focus, to avoid that user take the call by inadvertently pressing enter in another application
-  gtk_window_set_focus_on_map (GTK_WINDOW (incoming_call_popup), FALSE);
-
-  gtk_widget_show_all (incoming_call_popup);
-
-  g_signal_connect (incoming_call_popup, "delete_event",
-                    G_CALLBACK (gtk_widget_hide_on_delete), NULL);
-  g_signal_connect (incoming_call_popup, "response",
-                    G_CALLBACK (incoming_call_response_cb), mw);
-
-  call->established.connect (boost::bind (&on_incoming_call_gone_cb,
-                                         (gpointer) incoming_call_popup));
-  call->cleared.connect (boost::bind (&on_cleared_incoming_call_cb, _1,
-                                    (gpointer) incoming_call_popup));
-  call->missed.connect (boost::bind (&on_incoming_call_gone_cb, 
-                                   (gpointer) incoming_call_popup));
-}
-
-
-static void
 ekiga_main_window_append_call_url (EkigaMainWindow *mw,
 				   const char *url)
 {



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