[Gpa-commits] r1013 - branches/mo-branch/src

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sun Jun 21 18:11:00 CEST 2009


Author: moritzs
Date: 2009-06-21 18:10:59 +0200 (Sun, 21 Jun 2009)
New Revision: 1013

Added:
   branches/mo-branch/src/gpa-key-window.c
   branches/mo-branch/src/gpa-key-window.h
Modified:
   branches/mo-branch/src/ChangeLog
   branches/mo-branch/src/Makefile.am
   branches/mo-branch/src/keylist.c
   branches/mo-branch/src/keylist.h
   branches/mo-branch/src/keymanager.c
Log:
2009-06-21  Moritz  <moritz at gnu.org>

	* gpa-key-window.c, gpa-key-window.h: New files.
	* keymanager.c (key_manager_key_listed): Call
	gpa_keylist_update_key_window.
	* keylist.c: Include "gpa-key-window.h".
	(enum): New entry GPA_KEYLIST_COLUMN_KEY_WINDOW.
	(key_window_weak_ref_cb): New function.
	(keylist_row_activated): New function.
	(gpa_keylist_init): Adjust gtk_list_store_new call for new
	column (GPA_KEYLIST_COLUMN_KEY_WINDOW).
	(gpa_keylist_init): Connect keylist_row_activated to the
	"row-activated" signal.
	(gpa_keylist_next): Also set GPA_KEYLIST_COLUMN_KEY_WINDOW value
	when calling gtk_list_store_set.
	(update_key_window_func): New function.
	(gpa_keylist_update_key_window): New function.
	* keylist.h: Declare gpa_keylist_update_key_window.
	* Makefile.am (gpa_SOURCES): Added gpa-key-window.c and
	gpa-key-window.h.



Modified: branches/mo-branch/src/ChangeLog
===================================================================
--- branches/mo-branch/src/ChangeLog	2009-06-21 15:42:56 UTC (rev 1012)
+++ branches/mo-branch/src/ChangeLog	2009-06-21 16:10:59 UTC (rev 1013)
@@ -1,3 +1,24 @@
+2009-06-21  Moritz  <moritz at gnu.org>
+
+	* gpa-key-window.c, gpa-key-window.h: New files.
+	* keymanager.c (key_manager_key_listed): Call
+	gpa_keylist_update_key_window.
+	* keylist.c: Include "gpa-key-window.h".
+	(enum): New entry GPA_KEYLIST_COLUMN_KEY_WINDOW.
+	(key_window_weak_ref_cb): New function.
+	(keylist_row_activated): New function.
+	(gpa_keylist_init): Adjust gtk_list_store_new call for new
+	column (GPA_KEYLIST_COLUMN_KEY_WINDOW).
+	(gpa_keylist_init): Connect keylist_row_activated to the
+	"row-activated" signal.
+	(gpa_keylist_next): Also set GPA_KEYLIST_COLUMN_KEY_WINDOW value
+	when calling gtk_list_store_set.
+	(update_key_window_func): New function.
+	(gpa_keylist_update_key_window): New function.
+	* keylist.h: Declare gpa_keylist_update_key_window.
+	* Makefile.am (gpa_SOURCES): Added gpa-key-window.c and
+	gpa-key-window.h.
+
 2009-06-20  Werner Koch  <wk at g10code.com>
 
 	* gpastreamdecryptop.c (gpa_stream_decrypt_operation_new): Use

Modified: branches/mo-branch/src/Makefile.am
===================================================================
--- branches/mo-branch/src/Makefile.am	2009-06-21 15:42:56 UTC (rev 1012)
+++ branches/mo-branch/src/Makefile.am	2009-06-21 16:10:59 UTC (rev 1013)
@@ -95,6 +95,7 @@
               selectkeydlg.c selectkeydlg.h \
 	      keymanager.c keymanager.h \
 	      gpa-key-details.c gpa-key-details.h \
+	      gpa-key-window.c gpa-key-window.h \
 	      ownertrustdlg.c ownertrustdlg.h \
 	      keysigndlg.c keysigndlg.h \
 	      keygendlg.c keygendlg.h \

Added: branches/mo-branch/src/gpa-key-window.c
===================================================================
--- branches/mo-branch/src/gpa-key-window.c	2009-06-21 15:42:56 UTC (rev 1012)
+++ branches/mo-branch/src/gpa-key-window.c	2009-06-21 16:10:59 UTC (rev 1013)
@@ -0,0 +1,177 @@
+/* gpa-key-window.c - per-key window
+ * Copyright (C) 2009 g10 Code GmbH.
+ *
+ * This file is part of GPA.
+ *
+ * GPA is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GPA is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "gpa.h"   
+//#include "convert.h"
+//#include "siglist.h"
+#include "gpa-key-window.h"
+
+
+
+
+/* Local prototypes */
+//static void gpa_key_details_finalize (GObject *object);
+
+
+
+/************************************************************ 
+ *******************   Implementation   *********************
+ ************************************************************/
+
+
+static void
+gpa_key_window_class_init (void *class_ptr, void *class_data)
+{
+}
+
+static void
+close_button_cb (GtkButton *button, gpointer user_data)
+{
+  gtk_widget_destroy (GTK_WIDGET (user_data));
+}
+
+static void
+gpa_key_window_init (GTypeInstance *instance, gpointer class_ptr)
+{
+  GpaKeyWindow *key_window = GPA_KEY_WINDOW (instance);
+  GtkWidget *vbox;
+  GtkWidget *button_box;
+  GtkWidget *close_button;
+  GtkWidget *halign;
+
+  gtk_window_set_title (GTK_WINDOW (key_window), "Key details");
+  gtk_window_set_default_size (GTK_WINDOW (key_window), 600, 480);
+  key_window->key_details = gpa_key_details_new ();
+
+  vbox = gtk_vbox_new (FALSE, 18);
+  button_box = gtk_hbox_new (FALSE, 6);
+  close_button = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
+
+  g_signal_connect (G_OBJECT (close_button), "clicked",
+		    G_CALLBACK (close_button_cb), key_window);
+
+  halign = gtk_alignment_new (1, 0, 0, 0);
+  gtk_container_add (GTK_CONTAINER (halign), close_button);
+  gtk_container_add (GTK_CONTAINER (button_box), halign);
+
+  gtk_container_set_border_width (GTK_CONTAINER (key_window), 12);
+
+  gtk_box_pack_start (GTK_BOX (vbox), key_window->key_details,
+		      TRUE, TRUE, 0);
+  gtk_box_pack_start (GTK_BOX (vbox), button_box, FALSE, FALSE, 0);
+  
+
+  gtk_container_add (GTK_CONTAINER (key_window), vbox);
+  gtk_widget_show_all (vbox);
+
+  
+}
+
+
+#if 0
+static void
+gpa_key_details_finalize (GObject *object)
+{  
+  GpaKeyDetails *kdt = GPA_KEY_DETAILS (object);
+
+  if (kdt->current_key)
+    {
+      gpgme_key_unref (kdt->current_key);
+      kdt->current_key = NULL;
+    }
+  if (kdt->signatures_list)
+    {
+      g_object_unref (kdt->signatures_list);
+      kdt->signatures_list = NULL;
+    }
+  if (kdt->certchain_list)
+    {
+      g_object_unref (kdt->certchain_list);
+      kdt->certchain_list = NULL;
+    }
+  if (kdt->subkeys_list)
+    {
+      g_object_unref (kdt->subkeys_list);
+      kdt->subkeys_list = NULL;
+    }
+
+  parent_class->finalize (object);
+}
+#endif
+
+/* Construct the class.  */
+GType
+gpa_key_window_get_type (void)
+{
+  static GType this_type = 0;
+  
+  if (!this_type)
+    {
+      static const GTypeInfo this_info =
+	{
+	  sizeof (GpaKeyWindowClass),
+	  NULL,
+	  NULL,
+	  (GClassInitFunc) gpa_key_window_class_init,
+	  NULL,
+	  NULL, /* class_data */
+	  sizeof (GpaKeyWindow),
+	  0,    /* n_preallocs */
+	  (GInstanceInitFunc) gpa_key_window_init
+	};
+      
+      this_type = g_type_register_static (GTK_TYPE_WINDOW,
+                                          "GpaKeyWindow",
+                                          &this_info, 0);
+    }
+  
+  return this_type;
+}
+
+
+
+GtkWidget *
+gpa_key_window_new ()
+{
+  return GTK_WIDGET (g_object_new (GPA_KEY_WINDOW_TYPE, NULL));
+}
+
+
+/* Update the key details widget KEYDETAILS with KEY.  The caller also
+   needs to provide the number of keys, so that the widget may show a
+   key count instead of a key.  The actual key details are only shown
+   if KEY is not NULL and KEYCOUNT is 1.  */
+void
+gpa_key_window_update (GtkWidget *widget, gpgme_key_t key)
+{
+  GpaKeyWindow *key_window;
+
+  g_return_if_fail (IS_GPA_KEY_WINDOW (widget));
+  key_window = GPA_KEY_WINDOW (widget);
+
+  gpa_key_details_update (key_window->key_details, key, 1);
+}

Added: branches/mo-branch/src/gpa-key-window.h
===================================================================
--- branches/mo-branch/src/gpa-key-window.h	2009-06-21 15:42:56 UTC (rev 1012)
+++ branches/mo-branch/src/gpa-key-window.h	2009-06-21 16:10:59 UTC (rev 1013)
@@ -0,0 +1,67 @@
+/* gpa-key-window.h - per-key window
+ *      Copyright (C) 2009 g10 Code GmbH
+ *
+ * This file is part of GPA.
+ *
+ * GPA is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GPA is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.  
+ */
+
+#ifndef GPA_KEY_WINDOW_H
+#define GPA_KEY_WINDOW_H
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <gpgme.h>
+#include "gpa-key-details.h"
+
+#define GPA_KEY_WINDOW_TYPE            (gpa_key_window_get_type ())
+#define GPA_KEY_WINDOW(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GPA_KEY_WINDOW_TYPE, GpaKeyWindow))
+#define GPA_KEY_WINDOW_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GPA_KEY_WINDOW_TYPE, GpaKeyWindowClass))
+#define IS_GPA_KEY_WINDOW(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GPA_KEY_WINDOW_TYPE))
+#define IS_GPA_KEY_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GPA_KEY_WINDOW_TYPE))
+
+typedef struct _GpaKeyWindow      GpaKeyWindow;
+typedef struct _GpaKeyWindowClass GpaKeyWindowClass;
+
+struct _GpaKeyWindow
+{
+  GtkDialog parent;
+
+  GtkWidget *key_details;
+};
+
+struct _GpaKeyWindowClass
+{
+  GtkDialogClass parent_class;
+};
+
+GType gpa_key_window_get_type (void) G_GNUC_CONST;
+
+#if 0
+#define GPA_KEY_DETAILS_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj),    \
+                              GPA_KEY_DETAILS_TYPE, GpaKeyDetailsClass))
+#endif
+
+
+
+/*
+ * Public API.
+ */
+
+GtkWidget *gpa_key_window_new    (void);
+void       gpa_key_window_update (GtkWidget *key_window,
+				  gpgme_key_t key);
+#endif /* GPA_KEY_WINDOW_H */

Modified: branches/mo-branch/src/keylist.c
===================================================================
--- branches/mo-branch/src/keylist.c	2009-06-21 15:42:56 UTC (rev 1012)
+++ branches/mo-branch/src/keylist.c	2009-06-21 16:10:59 UTC (rev 1013)
@@ -1,6 +1,6 @@
 /* keylist.c - The GNU Privacy Assistant keylist.
    Copyright (C) 2003 Miguel Coca.
-   Copyright (C) 2005, 2008 g10 Code GmbH.
+   Copyright (C) 2005, 2008, 2009 g10 Code GmbH.
 
    This file is part of GPA
 
@@ -31,6 +31,7 @@
 #include "icons.h"
 #include "format-dn.h"
 
+#include "gpa-key-window.h"
 
 /* Properties */
 enum
@@ -61,6 +62,8 @@
   GPA_KEYLIST_COLUMN_USERID,
   /* This column contains the gpgme_key_t */
   GPA_KEYLIST_COLUMN_KEY,
+  /* This column references the key window. */
+  GPA_KEYLIST_COLUMN_KEY_WINDOW,
   /* These columns are used only internally for sorting */
   GPA_KEYLIST_COLUMN_HAS_SECRET,
   GPA_KEYLIST_COLUMN_EXPIRY_TS,
@@ -175,8 +178,117 @@
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
+/* This function is called whenever a key window object is destroyed
+   in order to delete the reference to the key window object
+   previously installed in the tree model.  */
+static void
+key_window_weak_ref_cb (gpointer data, GObject *where_the_object_was)
+{
+  GtkTreeRowReference *rowref;
+  GtkTreeModel *model;
+  GtkTreePath *path;
 
+  rowref = data;
+  model = gtk_tree_row_reference_get_model (rowref);
+  path = gtk_tree_row_reference_get_path (rowref);
+
+  if (path)
+    {
+      GtkTreeIter iter;
+      gboolean iter_found;
+      
+      iter_found = gtk_tree_model_get_iter (model, &iter, path);
+      if (iter_found)
+	gtk_list_store_set (GTK_LIST_STORE (model), &iter,
+			    GPA_KEYLIST_COLUMN_KEY_WINDOW, NULL, -1);
+
+      gtk_tree_path_free (path);
+    }
+
+  gtk_tree_row_reference_free (rowref);
+}
+
+/* This function is called when the user "activates"
+   (i.e. double-clicks) on a key contained in the key list and either
+   creates a new key window for that key or focuses a previously
+   opened key window. */
 static void
+keylist_row_activated (GtkTreeView *tree_view,
+		       GtkTreePath *path,
+		       GtkTreeViewColumn *column,
+		       gpointer user_data)
+{
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+  gboolean iter_found;
+
+  model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view));
+
+  iter_found = gtk_tree_model_get_iter (model, &iter, path);
+  if (iter_found)
+    {
+      GValue value = {0,};
+      GtkWidget *key_window;
+
+      fprintf (stderr, "row activated\n");
+
+      gtk_tree_model_get_value (model, &iter,
+				GPA_KEYLIST_COLUMN_KEY_WINDOW,
+				&value);
+      key_window = g_value_get_pointer (&value);
+      g_value_unset (&value);
+
+      if (key_window)
+	{
+	  /* Key already opened in a window, request to focus it. */
+	  fprintf (stderr, "present window\n");
+	  gtk_window_present (GTK_WINDOW (key_window));
+	}
+      else
+	{
+	  gpgme_key_t key;
+
+	  /* Key not yet opened in a window, create the key
+	     window.  */
+	  fprintf (stderr, "open window\n");
+	  
+	  gtk_tree_model_get_value (model, &iter,
+				    GPA_KEYLIST_COLUMN_KEY,
+				    &value);
+	  key = g_value_get_pointer (&value);
+	  g_value_unset (&value);
+
+	  if (!key)
+	    {
+	      /* FIXME: display error message? */
+	      fprintf (stderr, "key not found\n");
+	    }
+	  else
+	    {
+	      /* Key found, set up key window. */
+
+	      if (key->uids && key->uids->name)
+		fprintf (stderr, "UID: %s\n", key->uids->name);
+
+	      key_window = gpa_key_window_new ();
+
+	      g_object_weak_ref (G_OBJECT (key_window),
+				 &key_window_weak_ref_cb,
+				 gtk_tree_row_reference_new (model, path));
+	      gpa_key_window_update (key_window, key);
+	      gtk_widget_show (key_window);
+
+	      gtk_list_store_set (GTK_LIST_STORE (model), &iter,
+				  GPA_KEYLIST_COLUMN_KEY_WINDOW,
+				  key_window, -1);
+	    }
+	}
+    }
+}
+
+
+
+static void
 gpa_keylist_init (GTypeInstance *instance, void *class_ptr)
 {
   GpaKeyList *list = GPA_KEYLIST (instance);
@@ -193,6 +305,7 @@
 			      G_TYPE_STRING,
 			      G_TYPE_STRING,
 			      G_TYPE_POINTER,
+			      G_TYPE_POINTER,
 			      G_TYPE_INT,
 			      G_TYPE_ULONG,
 			      G_TYPE_ULONG,
@@ -205,6 +318,12 @@
   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (list));
   gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
 
+
+  /* Add support for key windows, created through a double click on a
+     row in the key list. */
+  g_signal_connect (GTK_TREE_VIEW (list), "row-activated",
+		    G_CALLBACK (keylist_row_activated), NULL);
+
   /* Load the keyring.  */
   add_trustdb_dialog (list);
   if (list->initial_keys)
@@ -495,6 +614,8 @@
 		      /* Set revoked and expired keys to "never trust"
 		         for sorting.  */
 		      GPA_KEYLIST_COLUMN_VALIDITY_VALUE, val_value,
+		      /* Initially there are no key windows. */
+		      GPA_KEYLIST_COLUMN_KEY_WINDOW, NULL,
                       /* Store the image only if enabled.  */
 		      list->public_only ? -1 : GPA_KEYLIST_COLUMN_IMAGE,
                       list->public_only ? NULL : get_key_pixbuf (key),
@@ -868,4 +989,55 @@
   gtk_main ();
 }
 
+/* This function is called through gtk_tree_model_foreach().  It's
+   purpose is to find the key window for a given gpgme_key_t object
+   and update that window with the data contained in the new gpgme
+   key. */
+static gboolean
+update_key_window_func (GtkTreeModel *model,
+			GtkTreePath *path,
+			GtkTreeIter *iter,
+			gpointer data)
+{
+  gpgme_key_t key_provided = data;
+  gpgme_key_t key;
+  GValue value = { 0 };
+      
+  gtk_tree_model_get_value (model, iter,
+			    GPA_KEYLIST_COLUMN_KEY,
+			    &value);
+  key = g_value_get_pointer (&value);
+  g_value_unset (&value);
 
+  /* FIXME: do we need more checks here? e.g: are there subkeys at
+     all? can subkeys->fpr be empty? -mo */
+  if (strcmp (key_provided->subkeys->fpr, key->subkeys->fpr) == 0)
+    {
+      GtkWidget *key_window;
+
+      gtk_tree_model_get_value (model, iter,
+				GPA_KEYLIST_COLUMN_KEY_WINDOW,
+				&value);
+      key_window = g_value_get_pointer (&value);
+      g_value_unset (&value);
+
+      if (key_window)
+	{
+	  gpa_key_window_update (key_window, key_provided);
+	  return TRUE;
+	}
+      else
+	return FALSE;
+    }
+  return FALSE;
+}
+
+/* In case a key window exists for the key KEY, update that window
+   with the data contained in KEY.  */
+void
+gpa_keylist_update_key_window (GpaKeyList *keylist, gpgme_key_t key)
+{
+  GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (keylist));
+
+  gtk_tree_model_foreach (model, &update_key_window_func, key);
+}

Modified: branches/mo-branch/src/keylist.h
===================================================================
--- branches/mo-branch/src/keylist.h	2009-06-21 15:42:56 UTC (rev 1012)
+++ branches/mo-branch/src/keylist.h	2009-06-21 16:10:59 UTC (rev 1013)
@@ -1,6 +1,6 @@
 /* keylist.h  -  The GNU Privacy Assistant
  *      Copyright (C) 2000, 2001 G-N-U GmbH.
- *      Copyright (C) 2008 g10 Code GmbH,
+ *      Copyright (C) 2008, 2009 g10 Code GmbH,
  *
  * This file is part of GPA
  *
@@ -121,5 +121,9 @@
 /* Let the keylist know that a new sceret key has been imported.  */
 void gpa_keylist_imported_secret_key (GpaKeyList * keylist);
 
+/* In case a key window exists for the key KEY, update that window
+   with the data contained in KEY.  */
+void gpa_keylist_update_key_window (GpaKeyList *keylist,
+				    gpgme_key_t key);
 
 #endif /* GPA_KEYLIST_H */

Modified: branches/mo-branch/src/keymanager.c
===================================================================
--- branches/mo-branch/src/keymanager.c	2009-06-21 15:42:56 UTC (rev 1012)
+++ branches/mo-branch/src/keymanager.c	2009-06-21 16:10:59 UTC (rev 1013)
@@ -630,6 +630,9 @@
   self->current_key = key;
 
   keyring_selection_update_actions (self);
+
+  /* Update key window if necessary. */
+  gpa_keylist_update_key_window (self->keylist, key);
 }
 
 



More information about the Gpa-commits mailing list