diff options
author | Corentin Noël <corentin.noel@collabora.com> | 2021-12-07 16:36:23 +0100 |
---|---|---|
committer | Corentin Noël <tintou@noel.tf> | 2022-04-09 00:44:24 +0200 |
commit | cadb1d8eef69b1029c5a893c81bc8e204d192d63 (patch) | |
tree | 41d18848d1ade01e73f8bd3ad51ed90420dad5f0 /tools | |
parent | d8c7ba55555acab2dbdeefda5b0decbb84d1d701 (diff) | |
download | gcr-cadb1d8eef69b1029c5a893c81bc8e204d192d63.tar.gz |
gcr-gtk3: Remove all the unused widgets, Rewrite GcrCertificateWidget
The UI is now aligned with the GTK4 version.
Keep GcrSecureEntryBuffer as there is no GTK3 version in GTK.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/frob-unlock.c | 123 | ||||
-rw-r--r-- | tools/gcr-prompter-tool.c | 258 | ||||
-rw-r--r-- | tools/gcr-prompter.desktop.in.in | 9 | ||||
-rw-r--r-- | tools/gcr-viewer-tool.c | 126 | ||||
-rw-r--r-- | tools/gcr-viewer-window.c | 201 | ||||
-rw-r--r-- | tools/gcr-viewer-window.h | 68 | ||||
-rw-r--r-- | tools/gcr-viewer.desktop.in.in | 7 | ||||
-rw-r--r-- | tools/gtk3/meson.build | 7 | ||||
-rw-r--r-- | tools/gtk3/viewer.c | 139 | ||||
-rw-r--r-- | tools/gtk4/meson.build | 7 | ||||
-rw-r--r-- | tools/gtk4/viewer.c | 139 | ||||
-rw-r--r-- | tools/meson.build | 70 |
12 files changed, 298 insertions, 856 deletions
diff --git a/tools/frob-unlock.c b/tools/frob-unlock.c deleted file mode 100644 index 83636c9..0000000 --- a/tools/frob-unlock.c +++ /dev/null @@ -1,123 +0,0 @@ -/* - * gnome-keyring - * - * Copyright (C) 2011 Collabora Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This program 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, see <http://www.gnu.org/licenses/>. - * - * Author: Stef Walter <stefw@collabora.co.uk> - */ - -#include "config.h" - -#include "gcr/gcr.h" - -#include "gcr-gtk3/gcr-unlock-renderer.h" -#include "tools/gcr-viewer-window.h" - -#include <gtk/gtk.h> - -#include <unistd.h> -#include <string.h> -#include <errno.h> - -static gboolean -delete_event(GtkWidget *widget, - GdkEvent *event, - gpointer data) -{ - gtk_main_quit (); - return FALSE; -} - -static void -on_parser_parsed (GcrParser *parser, gpointer unused) -{ - -} - -static void -on_unlock_clicked (GcrUnlockRenderer *renderer, - GcrParser *parser) -{ - const gchar *password; - password = _gcr_unlock_renderer_get_password (renderer); - gcr_parser_add_password (parser, password); - gtk_main_quit (); -} - -static void -on_parser_authenticate (GcrParser *parser, - gint count, - gpointer user_data) -{ - GcrUnlockRenderer *renderer; - GtkWindow *window; - - window = GTK_WINDOW (gcr_viewer_window_new ()); - g_object_ref_sink (window); - - renderer = _gcr_unlock_renderer_new_for_parsed (parser); - g_signal_connect (renderer, "unlock-clicked", G_CALLBACK (on_unlock_clicked), parser); - gcr_viewer_add_renderer (gcr_viewer_window_get_viewer (GCR_VIEWER_WINDOW (window)), GCR_RENDERER (renderer)); - g_object_unref (renderer); - - gtk_window_set_default_size (window, 550, 400); - gtk_container_set_border_width (GTK_CONTAINER (window), 20); - - g_signal_connect (window, "delete-event", G_CALLBACK (delete_event), NULL); - gtk_widget_show (GTK_WIDGET (window)); - - gtk_main (); - - g_object_unref (window); -} - -static void -test_key (const gchar *path) -{ - GcrParser *parser; - GError *err = NULL; - guchar *data; - gsize n_data; - GBytes *bytes; - - if (!g_file_get_contents (path, (gchar**)&data, &n_data, NULL)) - g_error ("couldn't read file: %s", path); - - parser = gcr_parser_new (); - g_signal_connect (parser, "parsed", G_CALLBACK (on_parser_parsed), NULL); - g_signal_connect (parser, "authenticate", G_CALLBACK (on_parser_authenticate), NULL); - bytes = g_bytes_new_take (data, n_data); - if (!gcr_parser_parse_bytes (parser, bytes, &err)) - g_error ("couldn't parse data: %s", err->message); - - g_object_unref (parser); - g_bytes_unref (bytes); -} - -int -main(int argc, char *argv[]) -{ - gtk_init (&argc, &argv); - g_set_prgname ("frob-unlock"); - - if (argc > 1) { - test_key (argv[1]); - } else { - test_key (SRCDIR "/gcr-gtk3/fixtures/email.p12"); - } - - return 0; -} diff --git a/tools/gcr-prompter-tool.c b/tools/gcr-prompter-tool.c deleted file mode 100644 index b6392ac..0000000 --- a/tools/gcr-prompter-tool.c +++ /dev/null @@ -1,258 +0,0 @@ -/* -*- 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, - see <http://www.gnu.org/licenses/>. - - Author: Stef Walter <stefw@collabora.co.uk> -*/ - -#include "config.h" - -#include "gcr/gcr.h" -#include "gcr/gcr-dbus-constants.h" -#include "gcr-gtk3/gcr-gtk3.h" - -#include <glib/gi18n.h> -#include <gtk/gtk.h> - -#include <locale.h> -#include <stdlib.h> -#include <string.h> -#include <syslog.h> - -#define QUIT_TIMEOUT 10 - -static GcrSystemPrompter *the_prompter = NULL; -static gboolean registered_prompter = FALSE; -static gboolean acquired_system_prompter = FALSE; -static gboolean acquired_private_prompter = FALSE; -static guint timeout_source = 0; - -static gboolean -on_timeout_quit (gpointer unused) -{ - g_debug ("%d second inactivity timeout, quitting", QUIT_TIMEOUT); - gtk_main_quit (); - - return FALSE; /* Don't run again */ -} - -static void -start_timeout (void) -{ - if (g_getenv ("GCR_PERSIST") != NULL) - return; - - if (!timeout_source) - timeout_source = g_timeout_add_seconds (QUIT_TIMEOUT, on_timeout_quit, NULL); -} - -static void -stop_timeout (void) -{ - if (timeout_source) - g_source_remove (timeout_source); - timeout_source = 0; -} - -static void -on_prompter_prompting (GObject *obj, - GParamSpec *param, - gpointer user_data) -{ - if (gcr_system_prompter_get_prompting (the_prompter)) - stop_timeout (); - else - start_timeout (); -} - -static void -on_bus_acquired (GDBusConnection *connection, - const gchar *name, - gpointer user_data) -{ - g_debug ("bus acquired: %s", name); - - if (!registered_prompter) - gcr_system_prompter_register (the_prompter, connection); - - registered_prompter = TRUE; -} - -static void -on_name_acquired (GDBusConnection *connection, - const gchar *name, - gpointer user_data) -{ - g_debug ("acquired name: %s", name); - - if (g_strcmp0 (name, GCR_DBUS_PROMPTER_SYSTEM_BUS_NAME) == 0) - acquired_system_prompter = TRUE; - - else if (g_strcmp0 (name, GCR_DBUS_PROMPTER_PRIVATE_BUS_NAME) == 0) - acquired_private_prompter = TRUE; -} - -static void -on_name_lost (GDBusConnection *connection, - const gchar *name, - gpointer user_data) -{ - g_debug ("lost name: %s", name); - - /* Called like so when no connection can be made */ - if (connection == NULL) { - g_warning ("couldn't connect to session bus"); - gtk_main_quit (); - - } else if (g_strcmp0 (name, GCR_DBUS_PROMPTER_SYSTEM_BUS_NAME) == 0) { - acquired_system_prompter = FALSE; - - } else if (g_strcmp0 (name, GCR_DBUS_PROMPTER_PRIVATE_BUS_NAME) == 0) { - acquired_private_prompter = FALSE; - - } -} - -static void -log_handler (const gchar *log_domain, - GLogLevelFlags log_level, - const gchar *message, - gpointer user_data) -{ - int level; - - /* Note that crit and err are the other way around in syslog */ - - switch (G_LOG_LEVEL_MASK & log_level) { - case G_LOG_LEVEL_ERROR: - level = LOG_CRIT; - break; - case G_LOG_LEVEL_CRITICAL: - level = LOG_ERR; - break; - case G_LOG_LEVEL_WARNING: - level = LOG_WARNING; - break; - case G_LOG_LEVEL_MESSAGE: - level = LOG_NOTICE; - break; - case G_LOG_LEVEL_INFO: - level = LOG_INFO; - break; - case G_LOG_LEVEL_DEBUG: - level = LOG_DEBUG; - break; - default: - level = LOG_ERR; - break; - } - - /* Log to syslog first */ - if (log_domain) - syslog (level, "%s: %s", log_domain, message); - else - syslog (level, "%s", message); - - /* And then to default handler for aborting and stuff like that */ - g_log_default_handler (log_domain, log_level, message, user_data); -} - -static void -printerr_handler (const gchar *string) -{ - /* Print to syslog and stderr */ - syslog (LOG_WARNING, "%s", string); - fprintf (stderr, "%s", string); -} - -static void -prepare_logging () -{ - GLogLevelFlags flags = G_LOG_FLAG_FATAL | G_LOG_LEVEL_ERROR | - G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | - G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO; - - openlog ("gcr-prompter", LOG_PID, LOG_AUTH); - - g_log_set_handler (NULL, flags, log_handler, NULL); - g_log_set_handler ("Glib", flags, log_handler, NULL); - g_log_set_handler ("Gtk", flags, log_handler, NULL); - g_log_set_handler ("Gnome", flags, log_handler, NULL); - g_log_set_handler ("Gcr", flags, log_handler, NULL); - g_log_set_handler ("Gck", flags, log_handler, NULL); - g_log_set_default_handler (log_handler, NULL); - g_set_printerr_handler (printerr_handler); -} - -int -main (int argc, char *argv[]) -{ - guint system_owner_id; - guint private_owner_id; - - gtk_init (&argc, &argv); - -#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 - - prepare_logging (); - - the_prompter = gcr_system_prompter_new (GCR_SYSTEM_PROMPTER_SINGLE, - GCR_TYPE_PROMPT_DIALOG); - g_signal_connect (the_prompter, "notify::prompting", - G_CALLBACK (on_prompter_prompting), NULL); - - system_owner_id = g_bus_own_name (G_BUS_TYPE_SESSION, - GCR_DBUS_PROMPTER_SYSTEM_BUS_NAME, - G_BUS_NAME_OWNER_FLAGS_REPLACE, - on_bus_acquired, - on_name_acquired, - on_name_lost, - NULL, - NULL); - - private_owner_id = g_bus_own_name (G_BUS_TYPE_SESSION, - GCR_DBUS_PROMPTER_PRIVATE_BUS_NAME, - G_BUS_NAME_OWNER_FLAGS_REPLACE, - on_bus_acquired, - on_name_acquired, - on_name_lost, - NULL, - NULL); - - start_timeout (); - gtk_main (); - - if (registered_prompter) - gcr_system_prompter_unregister (the_prompter, TRUE); - - g_bus_unown_name (system_owner_id); - g_bus_unown_name (private_owner_id); - - g_object_unref (the_prompter); - - return 0; -} diff --git a/tools/gcr-prompter.desktop.in.in b/tools/gcr-prompter.desktop.in.in deleted file mode 100644 index 086ec17..0000000 --- a/tools/gcr-prompter.desktop.in.in +++ /dev/null @@ -1,9 +0,0 @@ -[Desktop Entry] -Name=Access Prompt -Comment=Unlock access to passwords and other secrets -# Translators: Do NOT translate or transliterate this text (this is an icon file name)! -Icon=security-medium -Exec=@libexecdir@/gcr-prompter -Terminal=false -Type=Application -NoDisplay=true diff --git a/tools/gcr-viewer-tool.c b/tools/gcr-viewer-tool.c deleted file mode 100644 index 0117d70..0000000 --- a/tools/gcr-viewer-tool.c +++ /dev/null @@ -1,126 +0,0 @@ -/* -*- 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, - see <http://www.gnu.org/licenses/>. - - 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 void -on_window_destroy (GtkWidget *widget, - gpointer unused) -{ - gtk_widget_hide (widget); - gtk_main_quit (); -} - -int -main (int argc, char *argv[]) -{ - GOptionContext *context; - GError *error = NULL; - GtkWindow *window; - -#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, "destroy", G_CALLBACK (on_window_destroy), NULL); - gtk_main (); - - return 0; -} diff --git a/tools/gcr-viewer-window.c b/tools/gcr-viewer-window.c deleted file mode 100644 index a25e10e..0000000 --- a/tools/gcr-viewer-window.c +++ /dev/null @@ -1,201 +0,0 @@ -/* -*- 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, - see <http://www.gnu.org/licenses/>. - - Author: Stef Walter <stefw@collabora.co.uk> -*/ - -#include "config.h" - -#include "gcr-viewer-window.h" - -#include <glib/gi18n-lib.h> -#include <gtk/gtk.h> - -#include <locale.h> -#include <string.h> - -struct _GcrViewerWindowPrivate { - GcrViewerWidget *viewer; - GcrImportButton *import; -}; - -G_DEFINE_TYPE_WITH_PRIVATE (GcrViewerWindow, gcr_viewer_window, GTK_TYPE_WINDOW); - -static void -on_viewer_renderer_added (GcrViewerWidget *viewer, - GcrRenderer *renderer, - GcrParsed *parsed, - gpointer user_data) -{ - GcrViewerWindow *self = GCR_VIEWER_WINDOW (user_data); - gcr_import_button_add_parsed (self->pv->import, parsed); -} - -static void -gcr_viewer_window_init (GcrViewerWindow *self) -{ - self->pv = gcr_viewer_window_get_instance_private (self); -} - -static void -on_import_button_importing (GcrImportButton *button, - GcrImporter *importer, - gpointer user_data) -{ - GcrViewerWindow *self = GCR_VIEWER_WINDOW (user_data); - gcr_viewer_widget_clear_error (self->pv->viewer); -} - -static void -on_import_button_imported (GcrImportButton *button, - GcrImporter *importer, - GError *error, - gpointer user_data) -{ - GcrViewerWindow *self = GCR_VIEWER_WINDOW (user_data); - - if (error == NULL) { - g_object_set (button, "label", _("Imported"), NULL); - - } else { - if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - gcr_viewer_widget_show_error (self->pv->viewer, _("Import failed"), error); - } -} - -static void -on_close_clicked (GtkButton *button, - gpointer user_data) -{ - GcrViewerWindow *self = GCR_VIEWER_WINDOW (user_data); - gtk_widget_destroy (GTK_WIDGET (self)); -} - -static void -gcr_viewer_window_constructed (GObject *obj) -{ - GcrViewerWindow *self = GCR_VIEWER_WINDOW (obj); - GtkWidget *bbox; - GtkWidget *box; - GtkWidget *button; - - G_OBJECT_CLASS (gcr_viewer_window_parent_class)->constructed (obj); - - bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL); - gtk_box_set_spacing (GTK_BOX (bbox), 12); - gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END); - gtk_widget_show (bbox); - - self->pv->import = gcr_import_button_new (_("Import")); - g_signal_connect_object (self->pv->import, "importing", - G_CALLBACK (on_import_button_importing), - self, 0); - g_signal_connect_object (self->pv->import, "imported", - G_CALLBACK (on_import_button_imported), - self, 0); - gtk_widget_show (GTK_WIDGET (self->pv->import)); - - button = gtk_button_new_with_mnemonic (_("_Close")); - g_signal_connect_object (button, "clicked", - G_CALLBACK (on_close_clicked), - self, 0); - gtk_widget_show (button); - - gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, TRUE, 0); - gtk_box_pack_start (GTK_BOX (bbox), GTK_WIDGET (self->pv->import), FALSE, TRUE, 0); - - gtk_widget_set_halign (bbox, 0.5); - gtk_widget_set_valign (bbox, 0.5); -#if GTK_CHECK_VERSION (3, 12, 0) - gtk_widget_set_margin_end (bbox, 12); -#else - gtk_widget_set_margin_right (bbox, 12); -#endif - - self->pv->viewer = gcr_viewer_widget_new (); - g_object_bind_property (self->pv->viewer, "display-name", - self, "title", G_BINDING_SYNC_CREATE); - g_signal_connect_object (self->pv->viewer, "added", - G_CALLBACK (on_viewer_renderer_added), - self, 0); - gtk_widget_show (GTK_WIDGET (self->pv->viewer)); - - box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); - gtk_widget_show (box); - - gtk_box_pack_start (GTK_BOX (box), GTK_WIDGET (self->pv->viewer), TRUE, TRUE, 0); - gtk_box_pack_start (GTK_BOX (box), bbox, FALSE, FALSE, 6); - - gtk_container_add (GTK_CONTAINER (self), box); - - gtk_window_set_default_size (GTK_WINDOW (self), 250, 400); -} - -static void -gcr_viewer_window_class_init (GcrViewerWindowClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - - gobject_class->constructed = gcr_viewer_window_constructed; -} - -/** - * gcr_viewer_window_new: - * - * Create a new viewer window. - * - * Returns: (transfer full) (type GcrUi.ViewerWindow): a new viewer window - */ -GtkWindow * -gcr_viewer_window_new (void) -{ - return g_object_new (GCR_TYPE_VIEWER_WINDOW, NULL); -} - -/** - * gcr_viewer_window_load: - * @self: a viewer window - * @file: file to load - * - * Load a file into a viewer window. It may not appear immediately. - */ -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)); - - return gcr_viewer_widget_load_file (self->pv->viewer, file); -} - -/** - * gcr_viewer_window_get_viewer: - * @self: a viewer window - * - * Get the actual viewer showing information in the window. - * - * Returns: the viewer - */ -GcrViewer * -gcr_viewer_window_get_viewer (GcrViewerWindow *self) -{ - g_return_val_if_fail (GCR_IS_VIEWER_WINDOW (self), NULL); - return gcr_viewer_widget_get_viewer (self->pv->viewer); -} diff --git a/tools/gcr-viewer-window.h b/tools/gcr-viewer-window.h deleted file mode 100644 index 6af2e30..0000000 --- a/tools/gcr-viewer-window.h +++ /dev/null @@ -1,68 +0,0 @@ -/* -*- 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, - see <http://www.gnu.org/licenses/>. - - Author: Stef Walter <stefw@collabora.co.uk> -*/ - -#ifndef GCR_VIEWER_WINDOW_H -#define GCR_VIEWER_WINDOW_H - -#include <gtk/gtk.h> - -#ifndef GCR_DISABLE_DEPRECATED - -#include "gcr/gcr.h" -#include "gcr-gtk3/gcr-gtk3.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 { - /*< private >*/ - GtkWindow parent; - GcrViewerWindowPrivate *pv; -}; - -struct _GcrViewerWindowClass { - /*< private >*/ - GtkWindowClass parent_class; -}; - -GType gcr_viewer_window_get_type (void); - -GtkWindow * gcr_viewer_window_new (void); - -void gcr_viewer_window_load (GcrViewerWindow *self, - GFile *file); - -GcrViewer * gcr_viewer_window_get_viewer (GcrViewerWindow *self); - -G_DEFINE_AUTOPTR_CLEANUP_FUNC (GcrViewerWindow, g_object_unref) - -#endif /* GCR_DISABLE_DEPRECATED */ - -#endif /* GCR_VIEWER_WINDOW_H */ diff --git a/tools/gcr-viewer.desktop.in.in b/tools/gcr-viewer.desktop.in.in deleted file mode 100644 index d3b0f57..0000000 --- a/tools/gcr-viewer.desktop.in.in +++ /dev/null @@ -1,7 +0,0 @@ -[Desktop Entry] -Name=View file -MimeType=application/pkcs12;application/pkcs12+pem;application/pkcs7-mime;application/pkcs7-mime+pem;application/pkcs8;application/pkcs8+pem;application/pkix-cert;application/pkix-cert+pem;application/pkix-crl;application/pkix-crl+pem;application/x-pem-file;application/x-pem-key;application/x-pkcs12;application/x-pkcs7-certificates;application/x-x509-ca-cert;application/x-x509-user-cert;application/pkcs10;application/pkcs10+pem;application/x-spkac;application/x-spkac+base64; -Exec=@bindir@/gcr-viewer -Type=Application -Terminal=false -NoDisplay=true diff --git a/tools/gtk3/meson.build b/tools/gtk3/meson.build new file mode 100644 index 0000000..e2da60f --- /dev/null +++ b/tools/gtk3/meson.build @@ -0,0 +1,7 @@ +gcr_viewer_gtk3 = executable('gcr-viewer-gtk3', + 'viewer.c', + dependencies: [ gcr_gtk3_dep, gcr_gtk3_deps ], + c_args: gcr_gtk3_cflags, + include_directories: config_h_dir, + install: true, +) diff --git a/tools/gtk3/viewer.c b/tools/gtk3/viewer.c new file mode 100644 index 0000000..e8e6e7c --- /dev/null +++ b/tools/gtk3/viewer.c @@ -0,0 +1,139 @@ +/* + * Copyright 2011,2021 Collabora Ltd. + * Copyright Corentin Noël <corentin.noel@collabora.com> + * Copyright Stef Walter <stefw@collabora.co.uk> + * SPDX-License-Identifier: LGPL-2.0-or-later + */ + +#include <glib.h> +#include <glib/gi18n.h> +#include <gtk/gtk.h> +#include <gcr-gtk3/gcr-gtk3.h> + +#include "config.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 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 void +on_parser_parsed (GcrParser *parser, + gpointer user_data) +{ + GcrCertificate **cert = user_data; + GckAttributes *attributes; + const GckAttribute *attr; + + attributes = gcr_parser_get_parsed_attributes (parser); + attr = gck_attributes_find (attributes, CKA_VALUE); + *cert = gcr_simple_certificate_new (attr->value, attr->length); +} + +GcrCertificate * +simple_certificate_new_from_file (GFile *file, + GCancellable *cancellable, + GError **error) +{ + GcrCertificate *cert = NULL; + GcrParser *parser; + GBytes *bytes; + + g_return_val_if_fail (G_IS_FILE (file), NULL); + g_return_val_if_fail (!error || !*error, NULL); + + + bytes = g_file_load_bytes (file, cancellable, NULL, error); + if (!bytes) { + return NULL; + } + + parser = gcr_parser_new (); + g_signal_connect (parser, "parsed", G_CALLBACK (on_parser_parsed), &cert); + if (!gcr_parser_parse_bytes (parser, bytes, error)) { + g_bytes_unref (bytes); + g_object_unref (parser); + g_object_unref (cert); + return NULL; + } + + g_bytes_unref (bytes); + g_object_unref (parser); + return cert; +} + + +static void +activate (GtkApplication* app, + gpointer user_data) +{ + GtkWidget *window; + GtkWidget *box; + GtkWidget *scrolled; + GCancellable *cancellable = NULL; + + window = gtk_application_window_new (app); + gtk_window_set_title (GTK_WINDOW (window), "Window"); + gtk_window_set_default_size (GTK_WINDOW (window), 400, 300); + scrolled = gtk_scrolled_window_new (NULL, NULL); + box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); + g_object_set (G_OBJECT (scrolled), + "child", box, + "hscrollbar-policy", GTK_POLICY_NEVER, + NULL); + + if (remaining_args) { + for (int i = 0; remaining_args[i] != NULL; ++i) { + GFile *file; + GError *error = NULL; + GcrCertificate *certificate; + GtkWidget *widget; + + file = g_file_new_for_commandline_arg (remaining_args[i]); + certificate = simple_certificate_new_from_file (file, cancellable, &error); + g_object_unref (file); + widget = gcr_certificate_widget_new (GCR_CERTIFICATE (certificate)); + g_object_unref (certificate); + gtk_widget_set_halign (widget, GTK_ALIGN_CENTER); + gtk_container_add (GTK_CONTAINER (box), widget); + } + + g_clear_pointer (&remaining_args, g_strfreev); + remaining_args = NULL; + } + + gtk_container_add (GTK_CONTAINER (window), scrolled); + gtk_widget_show_all (window); +} + +int +main (int argc, + char **argv) +{ + GtkApplication *app; + int status; + + app = gtk_application_new ("org.gnome.GcrViewerGtk4", G_APPLICATION_FLAGS_NONE); + g_application_add_main_option_entries (G_APPLICATION (app), options); + g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); + status = g_application_run (G_APPLICATION (app), argc, argv); + g_object_unref (app); + + return status; +} diff --git a/tools/gtk4/meson.build b/tools/gtk4/meson.build new file mode 100644 index 0000000..f15e00b --- /dev/null +++ b/tools/gtk4/meson.build @@ -0,0 +1,7 @@ +gcr_viewer_gtk4 = executable('gcr-viewer-gtk4', + 'viewer.c', + dependencies: [ gcr_gtk4_dep, gcr_gtk4_deps ], + c_args: gcr_gtk4_cflags, + include_directories: config_h_dir, + install: true, +) diff --git a/tools/gtk4/viewer.c b/tools/gtk4/viewer.c new file mode 100644 index 0000000..9440b28 --- /dev/null +++ b/tools/gtk4/viewer.c @@ -0,0 +1,139 @@ +/* + * Copyright 2011,2021 Collabora Ltd. + * Copyright Corentin Noël <corentin.noel@collabora.com> + * Copyright Stef Walter <stefw@collabora.co.uk> + * SPDX-License-Identifier: LGPL-2.0-or-later + */ + +#include <glib.h> +#include <glib/gi18n.h> +#include <gtk/gtk.h> +#include <gcr-gtk4/gcr-gtk4.h> + +#include "config.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 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 void +on_parser_parsed (GcrParser *parser, + gpointer user_data) +{ + GcrCertificate **cert = user_data; + GckAttributes *attributes; + const GckAttribute *attr; + + attributes = gcr_parser_get_parsed_attributes (parser); + attr = gck_attributes_find (attributes, CKA_VALUE); + *cert = gcr_simple_certificate_new (attr->value, attr->length); +} + +GcrCertificate * +simple_certificate_new_from_file (GFile *file, + GCancellable *cancellable, + GError **error) +{ + GcrCertificate *cert = NULL; + GcrParser *parser; + GBytes *bytes; + + g_return_val_if_fail (G_IS_FILE (file), NULL); + g_return_val_if_fail (!error || !*error, NULL); + + + bytes = g_file_load_bytes (file, cancellable, NULL, error); + if (!bytes) { + return NULL; + } + + parser = gcr_parser_new (); + g_signal_connect (parser, "parsed", G_CALLBACK (on_parser_parsed), &cert); + if (!gcr_parser_parse_bytes (parser, bytes, error)) { + g_bytes_unref (bytes); + g_object_unref (parser); + g_object_unref (cert); + return NULL; + } + + g_bytes_unref (bytes); + g_object_unref (parser); + return cert; +} + + +static void +activate (GtkApplication* app, + gpointer user_data) +{ + GtkWidget *window; + GtkWidget *box; + GtkWidget *scrolled; + GCancellable *cancellable = NULL; + + window = gtk_application_window_new (app); + gtk_window_set_title (GTK_WINDOW (window), "Window"); + gtk_window_set_default_size (GTK_WINDOW (window), 400, 300); + scrolled = gtk_scrolled_window_new (); + box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); + g_object_set (G_OBJECT (scrolled), + "child", box, + "hscrollbar-policy", GTK_POLICY_NEVER, + NULL); + + if (remaining_args) { + for (int i = 0; remaining_args[i] != NULL; ++i) { + GFile *file; + GError *error = NULL; + GcrCertificate *certificate; + GtkWidget *widget; + + file = g_file_new_for_commandline_arg (remaining_args[i]); + certificate = simple_certificate_new_from_file (file, cancellable, &error); + g_object_unref (file); + widget = gcr_certificate_widget_new (GCR_CERTIFICATE (certificate)); + g_object_unref (certificate); + gtk_widget_set_halign (widget, GTK_ALIGN_CENTER); + gtk_box_append (GTK_BOX (box), widget); + } + + g_clear_pointer (&remaining_args, g_strfreev); + remaining_args = NULL; + } + + gtk_window_set_child (GTK_WINDOW (window), scrolled); + gtk_widget_show (window); +} + +int +main (int argc, + char **argv) +{ + GtkApplication *app; + int status; + + app = gtk_application_new ("org.gnome.GcrViewerGtk4", G_APPLICATION_FLAGS_NONE); + g_application_add_main_option_entries (G_APPLICATION (app), options); + g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); + status = g_application_run (G_APPLICATION (app), argc, argv); + g_object_unref (app); + + return status; +} diff --git a/tools/meson.build b/tools/meson.build index a8d2309..4db190e 100644 --- a/tools/meson.build +++ b/tools/meson.build @@ -1,65 +1,7 @@ -# gcr-viewer -gcr_viewer = executable('gcr-viewer', - 'gcr-viewer-tool.c', - 'gcr-viewer-window.c', - dependencies: [ gcr_gtk3_dep, gcr_gtk3_deps ], - c_args: gcr_gtk3_cflags, - include_directories: config_h_dir, - install: true, -) +if get_option('gtk3') + subdir('gtk3') +endif -i18n.merge_file( - input: configure_file( - input: 'gcr-viewer.desktop.in.in', - output: '@BASENAME@', - configuration: { 'bindir': gcr_prefix / get_option('bindir') }, - ), - output: '@BASENAME@', - type: 'desktop', - po_dir: podir, - install: true, - install_dir: get_option('datadir') / 'applications', -) - -# gcr-prompter -gcr_prompter = executable('gcr-prompter', - 'gcr-prompter-tool.c', - dependencies: [ gcr_gtk3_dep, gcr_gtk3_deps ], - c_args: gcr_gtk3_cflags, - include_directories: config_h_dir, - install: true, - install_dir: get_option('libexecdir'), -) - -i18n.merge_file( - input: configure_file( - input: 'gcr-prompter.desktop.in.in', - output: '@BASENAME@', - configuration: { 'libexecdir': gcr_prefix / get_option('libexecdir') }, - ), - output: '@BASENAME@', - type: 'desktop', - po_dir: podir, - install: true, - install_dir: get_option('datadir') / 'applications', -) - - -# Manual UI testing programs -gcr_tools_manual_tests = [ - 'frob-unlock', -] - -gcr_tools_test_cflags = [ - '-DSRCDIR="@0@"'.format(source_root), -] - -foreach _test : gcr_tools_manual_tests - test_bin = executable('test-'+_test, - '@0@.c'.format(_test), - 'gcr-viewer-window.c', - dependencies: [ gcr_gtk3_deps, gcr_gtk3_dep ], - c_args: [ gcr_gtk3_cflags, gcr_tools_test_cflags ], - include_directories: config_h_dir, - ) -endforeach +if get_option('gtk4') + subdir('gtk4') +endif |