[gnome-keyring] Implement basic little viewer window.
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-keyring] Implement basic little viewer window.
- Date: Tue, 30 Aug 2011 09:26:52 +0000 (UTC)
commit 2f12eaa7b9a3ad4587e4b9c16d9e662372cc304d
Author: Stef Walter <stefw collabora co uk>
Date: Fri Mar 25 12:20:51 2011 +0100
Implement basic little viewer window.
Doesn't yet layout correctly, and is pretty plain, but displays
certificates.
.gitignore | 2 +
gcr/Makefile.am | 15 +++
gcr/gcr-viewer-tool.c | 131 ++++++++++++++++++++++++++++
gcr/gcr-viewer-window.c | 222 +++++++++++++++++++++++++++++++++++++++++++++++
gcr/gcr-viewer-window.h | 56 ++++++++++++
5 files changed, 426 insertions(+), 0 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 5286d85..186ca98 100644
--- a/.gitignore
+++ b/.gitignore
@@ -186,6 +186,8 @@ run-tests
/pkcs11/xdg-store/tests/test-xdg-module
/pkcs11/xdg-store/tests/test-xdg-trust
+/gcr/gcr-viewer
+
/daemon/dbus/tests/test-secret-util
/ui/gnome-keyring-prompt.desktop
diff --git a/gcr/Makefile.am b/gcr/Makefile.am
index b9d9d40..a5a57e8 100644
--- a/gcr/Makefile.am
+++ b/gcr/Makefile.am
@@ -123,6 +123,7 @@ libgcr_ GCR_MAJOR@_la_SOURCES = \
gcr-unlock-options-widget.c gcr-unlock-options-widget.h \
gcr-util.c gcr-util.h \
gcr-viewer.c gcr-viewer.h \
+ gcr-viewer-window.c gcr-viewer-window.h \
$(BUILT_SOURCES)
libgcr_ GCR_MAJOR@_la_CFLAGS = \
@@ -179,6 +180,20 @@ gcr-$(GCR_MAJOR).pc: gcr.pc
# ----------------------------------------------------------------
+# TOOLS
+
+bin_PROGRAMS = gcr-viewer
+
+gcr_viewer_SOURCES = \
+ gcr-viewer-tool.c
+
+gcr_viewer_CFLAGS = \
+ -DLOCALEDIR=\""$(datadir)/locale"\"
+
+gcr_viewer_LDADD = \
+ $(builddir)/libgcr-$(GCR_MAJOR).la
+
+# ----------------------------------------------------------------
gcr-expected.abi: gcr.symbols
$(AM_V_GEN) cpp -P $< | sort > $@
diff --git a/gcr/gcr-viewer-tool.c b/gcr/gcr-viewer-tool.c
new file mode 100644
index 0000000..2b0e260
--- /dev/null
+++ b/gcr/gcr-viewer-tool.c
@@ -0,0 +1,131 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* gcr-viewer-tool.c: Command line utility
+
+ Copyright (C) 2011 Collabora Ltd.
+
+ The Gnome Keyring Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Keyring Library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Author: Stef Walter <stefw collabora co uk>
+*/
+
+#include "config.h"
+
+#include "gcr-viewer-window.h"
+
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+#include <locale.h>
+#include <stdlib.h>
+#include <string.h>
+
+static gchar **remaining_args = NULL;
+
+static gboolean
+print_version_and_exit (const gchar *option_name, const gchar *value,
+ gpointer data, GError **error)
+{
+ g_print("%s -- %s\n", _("GCR Certificate and Key Viewer"), VERSION);
+ exit (0);
+ return TRUE;
+}
+
+static const GOptionEntry options[] = {
+ { "version", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
+ print_version_and_exit, N_("Show the application's version"), NULL},
+ { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY,
+ &remaining_args, NULL, N_("[file...]") },
+ { NULL }
+};
+
+static gboolean
+on_idle_load_files (gpointer user_data)
+{
+ GcrViewerWindow *window = GCR_VIEWER_WINDOW (user_data);
+ GFile *file;
+ gint i;
+
+ if (remaining_args) {
+ for (i = 0; remaining_args[i] != NULL; ++i) {
+ file = g_file_new_for_commandline_arg (remaining_args[i]);
+ gcr_viewer_window_load (window, file);
+ g_object_unref (file);
+ }
+
+ g_strfreev (remaining_args);
+ remaining_args = NULL;
+ }
+
+ return FALSE; /* Don't run this again */
+}
+
+static gboolean
+on_window_delete_event (GtkWidget *widget, GdkEvent *event, gpointer unused)
+{
+ gtk_main_quit ();
+ gtk_widget_hide (widget);
+ return TRUE;
+}
+
+int
+main (int argc, char *argv[])
+{
+ GOptionContext *context;
+ GError *error = NULL;
+ GcrViewerWindow *window;
+
+ g_type_init ();
+ g_thread_init (NULL);
+
+#ifdef HAVE_LOCALE_H
+ /* internationalisation */
+ setlocale (LC_ALL, "");
+#endif
+
+#ifdef HAVE_GETTEXT
+ bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+ textdomain (GETTEXT_PACKAGE);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+#endif
+
+ context = g_option_context_new (N_("- View certificate and key files"));
+ g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
+ g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);
+
+ g_option_context_add_group (context, gtk_get_option_group (TRUE));
+
+ if (! g_option_context_parse (context, &argc, &argv, &error)) {
+ g_critical ("Failed to parse arguments: %s", error->message);
+ g_error_free (error);
+ g_option_context_free (context);
+ return 1;
+ }
+
+ g_option_context_free (context);
+ g_set_application_name (_("Certificate Viewer"));
+
+ gtk_init (&argc, &argv);
+
+ window = gcr_viewer_window_new ();
+ gtk_widget_show (GTK_WIDGET (window));
+
+ g_idle_add (on_idle_load_files, window);
+ g_signal_connect (window, "delete-event", G_CALLBACK (on_window_delete_event), NULL);
+ gtk_main ();
+
+ gtk_widget_destroy (GTK_WIDGET (window));
+ return 0;
+}
diff --git a/gcr/gcr-viewer-window.c b/gcr/gcr-viewer-window.c
new file mode 100644
index 0000000..c04ca94
--- /dev/null
+++ b/gcr/gcr-viewer-window.c
@@ -0,0 +1,222 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* gcr-viewer-window.c: Window for viewer
+
+ Copyright (C) 2011 Collabora Ltd.
+
+ The Gnome Keyring Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Keyring Library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Author: Stef Walter <stefw collabora co uk>
+*/
+
+#include "config.h"
+
+#include "gcr-parser.h"
+#include "gcr-renderer.h"
+#include "gcr-viewer-window.h"
+#include "gcr-viewer.h"
+
+#include <glib/gi18n-lib.h>
+#include <gtk/gtk.h>
+
+#include <locale.h>
+#include <string.h>
+
+struct _GcrViewerWindowPrivate {
+ GQueue *files_to_load;
+ GcrParser *parser;
+ GCancellable *cancellable;
+ GcrViewer *viewer;
+ gboolean loading;
+};
+
+static void viewer_load_next_file (GcrViewerWindow *self);
+static void viewer_stop_loading_files (GcrViewerWindow *self);
+
+G_DEFINE_TYPE (GcrViewerWindow, gcr_viewer_window, GTK_TYPE_WINDOW);
+
+static void
+on_parser_parsed (GcrParser *parser, gpointer user_data)
+{
+ GcrViewerWindow *self = GCR_VIEWER_WINDOW (user_data);
+ GcrRenderer *renderer;
+
+ renderer = gcr_renderer_create (gcr_parser_get_parsed_label (parser),
+ gcr_parser_get_parsed_attributes (parser));
+
+ if (renderer) {
+ gcr_viewer_add_renderer (self->pv->viewer, renderer);
+ g_object_unref (renderer);
+ }
+}
+
+static void
+gcr_viewer_window_init (GcrViewerWindow *self)
+{
+ self->pv = G_TYPE_INSTANCE_GET_PRIVATE (self, GCR_TYPE_VIEWER_WINDOW,
+ GcrViewerWindowPrivate);
+
+ self->pv->files_to_load = g_queue_new ();
+ self->pv->parser = gcr_parser_new ();
+ self->pv->cancellable = g_cancellable_new ();
+
+ g_signal_connect (self->pv->parser, "parsed", G_CALLBACK (on_parser_parsed), self);
+}
+
+static void
+gcr_viewer_window_constructed (GObject *obj)
+{
+ GcrViewerWindow *self = GCR_VIEWER_WINDOW (obj);
+
+ if (G_OBJECT_CLASS (gcr_viewer_window_parent_class)->constructed)
+ G_OBJECT_CLASS (gcr_viewer_window_parent_class)->constructed (obj);
+
+ self->pv->viewer = gcr_viewer_new_scrolled ();
+
+ gtk_widget_show (GTK_WIDGET (self->pv->viewer));
+ gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (self->pv->viewer));
+
+ gtk_window_set_default_size (GTK_WINDOW (self), 250, 400);
+}
+
+static void
+gcr_viewer_window_dispose (GObject *obj)
+{
+ GcrViewerWindow *self = GCR_VIEWER_WINDOW (obj);
+
+ g_signal_handlers_disconnect_by_func (self->pv->parser, on_parser_parsed, self);
+
+ while (!g_queue_is_empty (self->pv->files_to_load))
+ g_object_unref (g_queue_pop_head (self->pv->files_to_load));
+
+ g_cancellable_cancel (self->pv->cancellable);
+
+ G_OBJECT_CLASS (gcr_viewer_window_parent_class)->dispose (obj);
+}
+
+static void
+gcr_viewer_window_finalize (GObject *obj)
+{
+ GcrViewerWindow *self = GCR_VIEWER_WINDOW (obj);
+
+ /* self->pv->viewer is owned by container */
+
+ g_assert (g_queue_is_empty (self->pv->files_to_load));
+ g_queue_free (self->pv->files_to_load);
+
+ g_object_unref (self->pv->cancellable);
+ g_object_unref (self->pv->parser);
+
+ G_OBJECT_CLASS (gcr_viewer_window_parent_class)->finalize (obj);
+}
+
+static void
+gcr_viewer_window_class_init (GcrViewerWindowClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ gcr_viewer_window_parent_class = g_type_class_peek_parent (klass);
+
+ gobject_class->dispose = gcr_viewer_window_dispose;
+ gobject_class->finalize = gcr_viewer_window_finalize;
+ gobject_class->constructed = gcr_viewer_window_constructed;
+
+ g_type_class_add_private (klass, sizeof (GcrViewerWindow));
+}
+
+static void
+on_parser_parse_stream_returned (GObject *source, GAsyncResult *result,
+ gpointer user_data)
+{
+ GcrViewerWindow *self = GCR_VIEWER_WINDOW (user_data);
+ GError *error = NULL;
+
+ gcr_parser_parse_stream_finish (self->pv->parser, result, &error);
+
+ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+ viewer_stop_loading_files (self);
+
+ } else if (error) {
+ g_assert_not_reached (); /* TODO; */
+
+ } else {
+ viewer_load_next_file (self);
+ }
+}
+
+static void
+on_file_read_returned (GObject *source, GAsyncResult *result, gpointer user_data)
+{
+ GcrViewerWindow *self = GCR_VIEWER_WINDOW (user_data);
+ GFile *file = G_FILE (source);
+ GError *error = NULL;
+ GFileInputStream *fis;
+
+ fis = g_file_read_finish (file, result, &error);
+ g_object_unref (file);
+
+ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+ viewer_stop_loading_files (self);
+
+ } else if (error) {
+ g_assert_not_reached (); /* TODO: */
+ viewer_load_next_file (self);
+
+ } else {
+ gcr_parser_parse_stream_async (self->pv->parser, G_INPUT_STREAM (fis),
+ self->pv->cancellable, on_parser_parse_stream_returned,
+ self);
+ g_object_unref (fis);
+ }
+}
+
+static void
+viewer_stop_loading_files (GcrViewerWindow *self)
+{
+ self->pv->loading = FALSE;
+}
+
+static void
+viewer_load_next_file (GcrViewerWindow *self)
+{
+ GFile* file;
+
+ file = g_queue_pop_head (self->pv->files_to_load);
+ if (file == NULL) {
+ viewer_stop_loading_files (self);
+ return;
+ }
+
+ g_file_read_async (file, G_PRIORITY_DEFAULT, self->pv->cancellable,
+ on_file_read_returned, self);
+}
+
+GcrViewerWindow *
+gcr_viewer_window_new (void)
+{
+ return g_object_new (GCR_TYPE_VIEWER_WINDOW, NULL);
+}
+
+void
+gcr_viewer_window_load (GcrViewerWindow *self, GFile *file)
+{
+ g_return_if_fail (GCR_IS_VIEWER_WINDOW (self));
+ g_return_if_fail (G_IS_FILE (file));
+
+ g_queue_push_tail (self->pv->files_to_load, g_object_ref (file));
+
+ if (!self->pv->loading)
+ viewer_load_next_file (self);
+}
diff --git a/gcr/gcr-viewer-window.h b/gcr/gcr-viewer-window.h
new file mode 100644
index 0000000..5b94868
--- /dev/null
+++ b/gcr/gcr-viewer-window.h
@@ -0,0 +1,56 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* gcr-viewer-window.h: Window for viewer
+
+ Copyright (C) 2011 Collabora Ltd.
+
+ The Gnome Keyring Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Keyring Library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Author: Stef Walter <stefw collabora co uk>
+*/
+
+#ifndef GCR_VIEWER_WINDOW_H
+#define GCR_VIEWER_WINDOW_H
+
+#include <gtk/gtk.h>
+
+#define GCR_TYPE_VIEWER_WINDOW (gcr_viewer_window_get_type ())
+#define GCR_VIEWER_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GCR_TYPE_VIEWER_WINDOW, GcrViewerWindow))
+#define GCR_VIEWER_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GCR_TYPE_VIEWER_WINDOW, GcrViewerWindowClass))
+#define GCR_IS_VIEWER_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GCR_TYPE_VIEWER_WINDOW))
+#define GCR_IS_VIEWER_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GCR_TYPE_VIEWER_WINDOW))
+#define GCR_VIEWER_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GCR_TYPE_VIEWER_WINDOW, GcrViewerWindowClass))
+
+typedef struct _GcrViewerWindow GcrViewerWindow;
+typedef struct _GcrViewerWindowClass GcrViewerWindowClass;
+typedef struct _GcrViewerWindowPrivate GcrViewerWindowPrivate;
+
+struct _GcrViewerWindow {
+ GtkWindow parent;
+ GcrViewerWindowPrivate *pv;
+};
+
+struct _GcrViewerWindowClass {
+ GtkWindowClass parent_class;
+};
+
+GType gcr_viewer_window_get_type (void);
+
+GcrViewerWindow * gcr_viewer_window_new (void);
+
+void gcr_viewer_window_load (GcrViewerWindow *self,
+ GFile *file);
+
+#endif /* GCR_VIEWER_WINDOW_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]