gnome-terminal r2780 - trunk/src



Author: chpe
Date: Thu May 29 19:53:32 2008
New Revision: 2780
URL: http://svn.gnome.org/viewvc/gnome-terminal?rev=2780&view=rev

Log:
Make the s/key challenge window not use gtk_dialog_run.
Remove another use of priv->window from TerminalScreen by adding skey-clicked and url-clicked signals and handling them in TerminalWindow.


Added:
   trunk/src/terminal-marshal.list
Modified:
   trunk/src/Makefile.am
   trunk/src/skey-popup.c
   trunk/src/skey-popup.h
   trunk/src/terminal-screen.c
   trunk/src/terminal-screen.h
   trunk/src/terminal-util.c
   trunk/src/terminal-util.h
   trunk/src/terminal-window.c

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Thu May 29 19:53:32 2008
@@ -18,6 +18,8 @@
 	terminal-app.c \
 	terminal-app.h \
 	terminal-intl.h \
+	terminal-marshal.c \
+	terminal-marshal.h \
 	terminal-profile.c \
 	terminal-profile.h \
 	terminal-screen.c \
@@ -57,6 +59,8 @@
 	$(TERM_LIBS)
 
 BUILT_SOURCES = \
+	terminal-marshal.c \
+	terminal-marshal.h \
 	terminal-type-builtins.c \
 	terminal-type-builtins.h \
 	$(NULL)
@@ -79,6 +83,21 @@
 	&& (cmp -s xgen-ttbc terminal-type-builtins.c || cp xgen-ttbc terminal-type-builtins.c ) \
 	&& rm -f xgen-ttbc
 
+terminal-marshal.h: $(srcdir)/terminal-marshal.list
+	( $(GLIB_GENMARSHAL) --prefix=_terminal_marshal $(srcdir)/terminal-marshal.list \
+			--header \
+			--internal > terminal-marshal.h.tmp \
+	&& mv terminal-marshal.h.tmp terminal-marshal.h ) \
+	|| ( rm -f terminal-marshal.h.tmp && exit 1 )
+
+terminal-marshal.c: $(srcdir)/terminal-marshal.list
+	( $(GLIB_GENMARSHAL) --prefix=_terminal_marshal $(srcdir)/terminal-marshal.list \
+				--header \
+				--body \
+				--internal > terminal-marshal.c.tmp \
+		&& mv terminal-marshal.c.tmp terminal-marshal.c ) \
+	|| ( rm -f terminal-marshal.c.tmp && exit 1 )
+
 schemadir = $(GCONF_SCHEMA_FILE_DIR)
 schema_in_files = gnome-terminal.schemas.in
 schema_DATA = gnome-terminal.schemas
@@ -107,6 +126,7 @@
 	$(BUILT_SOURCES)
 
 EXTRA_DIST = \
+	terminal-marshal.list \
 	$(icon_DATA) \
 	$(schema_in_files) \
 	$(server_DATA) \

Modified: trunk/src/skey-popup.c
==============================================================================
--- trunk/src/skey-popup.c	(original)
+++ trunk/src/skey-popup.c	Thu May 29 19:53:32 2008
@@ -1,5 +1,6 @@
 /*
  * Copyright  2002 Jonathan Blandford <jrb gnome org>
+ * Copyright  2008 Christian Persch
  *
  * Gnome-terminal is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -29,6 +30,20 @@
 #define SKEY_PREFIX "s/key "
 #define OTP_PREFIX  "otp-"
 
+typedef struct {
+  TerminalScreen *screen;
+  char *seed;
+  int seq;
+  int hash;
+} SkeyData;
+
+static void
+skey_data_free (SkeyData *data)
+{
+  g_free (data->seed);
+  g_free (data);
+}
+
 static gboolean
 extract_seq_and_seed (const gchar  *skey_match,
 		      gint         *seq,
@@ -99,27 +114,53 @@
   return TRUE;
 }
 
+static void
+skey_challenge_response_cb (GtkWidget *dialog,
+                            int response_id,
+                            SkeyData *data)
+{  
+  if (response_id == GTK_RESPONSE_OK)
+    {
+      GtkWidget *entry;
+      const char *password;
+      char *response;
+
+      entry = g_object_get_data (G_OBJECT (dialog), "skey-entry");
+      password = gtk_entry_get_text (GTK_ENTRY (entry));
+
+      /* FIXME: fix skey to use g_malloc */
+      response = skey (data->hash, data->seq, data->seed, password);
+      if (response)
+	{
+          VteTerminal *vte_terminal = VTE_TERMINAL (data->screen);
+          static const char newline[2] = "\n";
+
+	  vte_terminal_feed_child (vte_terminal, response, strlen (response));
+          vte_terminal_feed_child (vte_terminal, newline, strlen (newline));
+	  free (response);
+	}
+    }
+
+  gtk_widget_destroy (dialog);
+}
+
 void
-terminal_skey_do_popup (TerminalScreen *screen,
+terminal_skey_do_popup (GtkWindow *window,
+                        TerminalScreen *screen,
 			const gchar    *skey_match)
 {
-  static GtkWidget *dialog = NULL;
-  GtkWidget *entry;
-  GtkWidget *transient_parent;
-  GtkWidget *ok_button;
-  gint seq;
-  gchar *seed;
-  gint hash = MD5;
-
-  transient_parent = gtk_widget_get_toplevel (GTK_WIDGET (screen));
-  if (!GTK_WIDGET_TOPLEVEL (transient_parent))
-    transient_parent = NULL;
+  GtkWidget *dialog, *label, *entry, *ok_button;
+  char *title_text;
+  char *seed;
+  int seq;
+  int hash = MD5;
+  SkeyData *data;
 
   if (strncmp (SKEY_PREFIX, skey_match, strlen (SKEY_PREFIX)) == 0)
     {
       if (!extract_seq_and_seed (skey_match, &seq, &seed))
 	{
-	  terminal_util_show_error_dialog (GTK_WINDOW (transient_parent), NULL,
+	  terminal_util_show_error_dialog (window, NULL,
 					   _("The text you clicked on doesn't "
 					     "seem to be a valid S/Key "
 					     "challenge."));
@@ -130,7 +171,7 @@
     {
       if (!extract_hash_seq_and_seed (skey_match, &hash, &seq, &seed))
 	{
-	  terminal_util_show_error_dialog (GTK_WINDOW (transient_parent), NULL,
+	  terminal_util_show_error_dialog (window, NULL,
 					   _("The text you clicked on doesn't "
 					     "seem to be a valid OTP "
 					     "challenge."));
@@ -138,60 +179,45 @@
 	}
     }
 
-  if (dialog == NULL)
-    {
-      GtkWindow *label;
-      char *title_text;
+  if (!terminal_util_load_builder_file ("skey-challenge.ui",
+                                        "skey-dialog", &dialog,
+                                        "skey-entry", &entry,
+                                        "text-label", &label,
+                                        "skey-ok-button", &ok_button,
+                                        NULL))
+    {
+      g_free (seed);
+      return;
+    }
+
+  title_text = g_strdup_printf ("<big><b>%s</b></big>",
+                                gtk_label_get_text (GTK_LABEL (label)));
+  gtk_label_set_label (GTK_LABEL (label), title_text);
+  g_free (title_text);
+
+  g_object_set_data (G_OBJECT (dialog), "skey-entry", entry);
 
-      if (!terminal_util_load_builder_file ("skey-challenge.ui",
-                                            "skey-dialog", &dialog,
-                                            "skey-entry", &entry,
-                                            "text-label", &label,
-                                            "skey-ok-button", &ok_button,
-                                            NULL))
-        return;
-
-      title_text = g_strdup_printf ("<big><b>%s</b></big>",
-				    gtk_label_get_text (GTK_LABEL (label)));
-      gtk_label_set_label (GTK_LABEL (label), title_text);
-      g_free (title_text);
-
-      g_object_set_data (G_OBJECT (dialog), "skey-entry", entry);      
-      g_object_set_data (G_OBJECT (dialog), "skey-ok-button", ok_button);
-
-      g_object_add_weak_pointer (G_OBJECT (dialog), (void**) &dialog);
-    }
-
-  gtk_window_set_transient_for (GTK_WINDOW (dialog),
-  				GTK_WINDOW (transient_parent));
-  entry = g_object_get_data (G_OBJECT (dialog), "skey-entry");
-  ok_button = g_object_get_data (G_OBJECT (dialog), "skey-ok-button");
   gtk_widget_grab_focus (entry);
   gtk_widget_grab_default (ok_button);
   gtk_entry_set_text (GTK_ENTRY (entry), "");
 
+  gtk_window_set_transient_for (GTK_WINDOW (dialog), window);
   gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
-  gtk_window_present (GTK_WINDOW (dialog));
-  
-  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
-    {
-      const gchar *password;
-      gchar *response;
-      
-      password = gtk_entry_get_text (GTK_ENTRY (entry));
-      /* FIXME: fix skey to use g_malloc */
-      response = skey (hash, seq, seed, password);
-      if (response)
-	{
-          VteTerminal *vte_terminal = VTE_TERMINAL (screen);
-          static const char newline[2] = "\n";
+  gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
 
-	  vte_terminal_feed_child (vte_terminal, response, strlen (response));
-          vte_terminal_feed_child (vte_terminal, newline, strlen (newline));
-	  free (response);
-	}
-    }
+  /* FIXMEchpe: make this dialogue close if the screen closes! */
 
-  gtk_widget_destroy (dialog);
-  g_free (seed);
+  data = g_new (SkeyData, 1);
+  data->hash = hash;
+  data->seq = seq;
+  data->seed = seed;
+  data->screen = screen;
+
+  g_signal_connect_data (dialog, "response",
+                         G_CALLBACK (skey_challenge_response_cb),
+                         data, (GClosureNotify) skey_data_free, 0);
+  g_signal_connect (dialog, "delete-event",
+                    G_CALLBACK (terminal_util_dialog_response_on_delete), NULL);
+
+  gtk_window_present (GTK_WINDOW (dialog));
 }

Modified: trunk/src/skey-popup.h
==============================================================================
--- trunk/src/skey-popup.h	(original)
+++ trunk/src/skey-popup.h	Thu May 29 19:53:32 2008
@@ -20,12 +20,14 @@
 #ifndef SKEY_POPUP_H
 #define SKEY_POPUP_H
 
-#include "terminal-screen.h"
 #include <gtk/gtk.h>
 
+#include "terminal-screen.h"
+
 G_BEGIN_DECLS
 
-void terminal_skey_do_popup (TerminalScreen *screen,
+void terminal_skey_do_popup (GtkWindow *window,
+                             TerminalScreen *screen,
 			     const gchar    *skey_match);
 
 G_END_DECLS

Added: trunk/src/terminal-marshal.list
==============================================================================
--- (empty file)
+++ trunk/src/terminal-marshal.list	Thu May 29 19:53:32 2008
@@ -0,0 +1 @@
+VOID:STRING,INT

Modified: trunk/src/terminal-screen.c
==============================================================================
--- trunk/src/terminal-screen.c	(original)
+++ trunk/src/terminal-screen.c	Thu May 29 19:53:32 2008
@@ -34,11 +34,11 @@
 #include "terminal-accels.h"
 #include "terminal-app.h"
 #include "terminal-intl.h"
+#include "terminal-marshal.h"
 #include "terminal-profile.h"
 #include "terminal-screen-container.h"
 #include "terminal-util.h"
 #include "terminal-window.h"
-#include "skey-popup.h"
 
 #define HTTP_PROXY_DIR "/system/http_proxy"
 
@@ -72,6 +72,8 @@
 {
   PROFILE_SET,
   SHOW_POPUP_MENU,
+  SKEY_CLICKED,
+  URL_CLICKED,
   CLOSE_SCREEN,
   LAST_SIGNAL
 };
@@ -457,6 +459,26 @@
                   1,
                   G_TYPE_POINTER);
 
+  signals[SKEY_CLICKED] =
+    g_signal_new (I_("skey-clicked"),
+                  G_OBJECT_CLASS_TYPE (object_class),
+                  G_SIGNAL_RUN_LAST,
+                  G_STRUCT_OFFSET (TerminalScreenClass, skey_clicked),
+                  NULL, NULL,
+                  g_cclosure_marshal_VOID__STRING,
+                  G_TYPE_NONE,
+                  1, G_TYPE_STRING);
+  
+  signals[URL_CLICKED] =
+    g_signal_new (I_("url-clicked"),
+                  G_OBJECT_CLASS_TYPE (object_class),
+                  G_SIGNAL_RUN_LAST,
+                  G_STRUCT_OFFSET (TerminalScreenClass, url_clicked),
+                  NULL, NULL,
+                  _terminal_marshal_VOID__STRING_INT,
+                  G_TYPE_NONE,
+                  2, G_TYPE_STRING, G_TYPE_INT);
+  
   signals[CLOSE_SCREEN] =
     g_signal_new (I_("close-screen"),
                   G_OBJECT_CLASS_TYPE (object_class),
@@ -1450,7 +1472,7 @@
                                                      NULL);
       if (skey_match != NULL)
 	{
-	  terminal_skey_do_popup (screen, skey_match);
+          g_signal_emit (screen, signals[SKEY_CLICKED], 0, skey_match);
 	  g_free (skey_match);
           g_free (matched_string);
 
@@ -1463,8 +1485,8 @@
       matched_string != NULL)
     {
       gtk_widget_grab_focus (widget);
-      
-      terminal_util_open_url (GTK_WIDGET (priv->window), matched_string, matched_flavor);
+
+      g_signal_emit (screen, signals[URL_CLICKED], 0, matched_string, matched_flavor);
       g_free (matched_string);
 
       return TRUE; /* don't do anything else such as select with the click */

Modified: trunk/src/terminal-screen.h
==============================================================================
--- trunk/src/terminal-screen.h	(original)
+++ trunk/src/terminal-screen.h	Thu May 29 19:53:32 2008
@@ -62,6 +62,11 @@
                                TerminalProfile *old_profile);
   void (* show_popup_menu)    (TerminalScreen *screen,
                                TerminalScreenPopupInfo *info);
+  void (* skey_clicked)       (TerminalScreen *screen,
+                               const char *skey_challenge);
+  void (* url_clicked)        (TerminalScreen *screen,
+                               const char *url,
+                               int flavour);
   void (* close_screen)       (TerminalScreen *screen);
 };
 

Modified: trunk/src/terminal-util.c
==============================================================================
--- trunk/src/terminal-util.c	(original)
+++ trunk/src/terminal-util.c	Thu May 29 19:53:32 2008
@@ -276,6 +276,13 @@
   return object_name == NULL;
 }
 
+gboolean
+terminal_util_dialog_response_on_delete (GtkWindow *widget)
+{
+  gtk_dialog_response (GTK_DIALOG (widget), GTK_RESPONSE_DELETE_EVENT);
+  return TRUE;
+}
+
 /* Bidirectional object/widget binding */
 
 typedef struct {

Modified: trunk/src/terminal-util.h
==============================================================================
--- trunk/src/terminal-util.h	(original)
+++ trunk/src/terminal-util.h	Thu May 29 19:53:32 2008
@@ -51,6 +51,8 @@
                                           const char *object_name,
                                           ...);
 
+gboolean terminal_util_dialog_response_on_delete (GtkWindow *widget);
+
 typedef enum {
   FLAG_INVERT_BOOL  = 1 << 0,
 } PropertyChangeFlags;

Modified: trunk/src/terminal-window.c
==============================================================================
--- trunk/src/terminal-window.c	(original)
+++ trunk/src/terminal-window.c	Thu May 29 19:53:32 2008
@@ -19,15 +19,6 @@
 
 #include <config.h>
 
-#include "terminal-intl.h"
-
-#include "terminal-app.h"
-#include "terminal-accels.h"
-#include "terminal-window.h"
-#include "terminal-screen-container.h"
-#include "terminal-tabs-menu.h"
-#include "terminal-util.h"
-#include "encoding.h"
 #include <string.h>
 #include <stdlib.h>
 #include <libgnome/gnome-program.h>
@@ -36,6 +27,16 @@
 #include <gdk/gdkkeysyms.h>
 #include <libsn/sn-launchee.h>
 
+#include "encoding.h"
+#include "skey-popup.h"
+#include "terminal-accels.h"
+#include "terminal-app.h"
+#include "terminal-intl.h"
+#include "terminal-screen-container.h"
+#include "terminal-tabs-menu.h"
+#include "terminal-util.h"
+#include "terminal-window.h"
+
 struct _TerminalWindowPrivate
 {
   GtkActionGroup *action_group;
@@ -1072,6 +1073,33 @@
 }
 
 static void
+screen_skey_clicked_cb (TerminalScreen *screen,
+                        const char *skey_challenge,
+                        TerminalWindow *window)
+{
+  TerminalWindowPrivate *priv = window->priv;
+
+  if (screen != priv->active_screen)
+    return;
+
+  terminal_skey_do_popup (GTK_WINDOW (window), screen, skey_challenge);
+}
+
+static void
+screen_url_clicked_cb (TerminalScreen *screen,
+                       const char *url,
+                       int flavour,
+                       TerminalWindow *window)
+{
+  TerminalWindowPrivate *priv = window->priv;
+
+  if (screen != priv->active_screen)
+    return;
+
+  terminal_util_open_url (GTK_WIDGET (window), url, flavour);
+}
+
+static void
 screen_close_cb (TerminalScreen *screen,
                  TerminalWindow *window)
 {
@@ -2089,6 +2117,10 @@
 
   g_signal_connect (screen, "show-popup-menu",
                     G_CALLBACK (screen_show_popup_menu_callback), window);
+  g_signal_connect (screen, "skey-clicked",
+                    G_CALLBACK (screen_skey_clicked_cb), window);
+  g_signal_connect (screen, "url-clicked",
+                    G_CALLBACK (screen_url_clicked_cb), window);
 
   g_signal_connect (screen, "close-screen",
                     G_CALLBACK (screen_close_cb), window);
@@ -2172,6 +2204,14 @@
                                         window);
 
   g_signal_handlers_disconnect_by_func (screen,
+                                        G_CALLBACK (screen_skey_clicked_cb),
+                                        window);
+
+  g_signal_handlers_disconnect_by_func (screen,
+                                        G_CALLBACK (screen_url_clicked_cb),
+                                        window);
+
+  g_signal_handlers_disconnect_by_func (screen,
                                         G_CALLBACK (screen_close_cb),
                                         window);
 



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