[gnome-disk-utility/udisks2-port] Move unlock dialog into separate file
- From: David Zeuthen <davidz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-disk-utility/udisks2-port] Move unlock dialog into separate file
- Date: Thu, 22 Sep 2011 17:11:46 +0000 (UTC)
commit 55031c999189659b014536934b2017e9ad4d96e8
Author: David Zeuthen <davidz redhat com>
Date: Thu Sep 22 13:11:42 2011 -0400
Move unlock dialog into separate file
Signed-off-by: David Zeuthen <davidz redhat com>
src/palimpsest/Makefile.am | 1 +
src/palimpsest/gdupartitiondialog.c | 1 -
src/palimpsest/gduunlockdialog.c | 128 +++++++++++++++++++++++++++++++++
src/palimpsest/gduunlockdialog.h | 36 +++++++++
src/palimpsest/gduutils.c | 40 ++++++++++
src/palimpsest/gduutils.h | 4 +
src/palimpsest/gduwindow.c | 135 ++---------------------------------
7 files changed, 214 insertions(+), 131 deletions(-)
---
diff --git a/src/palimpsest/Makefile.am b/src/palimpsest/Makefile.am
index d58b762..591b5d8 100644
--- a/src/palimpsest/Makefile.am
+++ b/src/palimpsest/Makefile.am
@@ -36,6 +36,7 @@ palimpsest_SOURCES = \
gdufilesystemdialog.h gdufilesystemdialog.c \
gdufstabdialog.h gdufstabdialog.c \
gdupartitiondialog.h gdupartitiondialog.c \
+ gduunlockdialog.h gduunlockdialog.c \
$(enum_built_sources) \
$(NULL)
diff --git a/src/palimpsest/gdupartitiondialog.c b/src/palimpsest/gdupartitiondialog.c
index 109a63f..279c5c6 100644
--- a/src/palimpsest/gdupartitiondialog.c
+++ b/src/palimpsest/gdupartitiondialog.c
@@ -67,7 +67,6 @@ void
gdu_partition_dialog_show (GduWindow *window,
UDisksObject *object)
{
-
gint response;
GtkBuilder *builder;
GtkWidget *dialog;
diff --git a/src/palimpsest/gduunlockdialog.c b/src/palimpsest/gduunlockdialog.c
new file mode 100644
index 0000000..7b7ce76
--- /dev/null
+++ b/src/palimpsest/gduunlockdialog.c
@@ -0,0 +1,128 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2008-2011 Red Hat, Inc.
+ *
+ * This library 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 of the License, or (at your option) any later version.
+ *
+ * This 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: David Zeuthen <davidz redhat com>
+ */
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+
+#include "gduapplication.h"
+#include "gduwindow.h"
+#include "gduunlockdialog.h"
+#include "gduvolumegrid.h"
+#include "gduutils.h"
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
+unlock_cb (UDisksEncrypted *encrypted,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GduWindow *window = GDU_WINDOW (user_data);
+ GError *error;
+
+ error = NULL;
+ if (!udisks_encrypted_call_unlock_finish (encrypted,
+ NULL, /* out_cleartext_device */
+ res,
+ &error))
+ {
+ gdu_window_show_error (window,
+ _("Error unlocking encrypted device"),
+ error);
+ g_error_free (error);
+ }
+ g_object_unref (window);
+}
+
+void
+gdu_unlock_dialog_show (GduWindow *window,
+ UDisksObject *object)
+{
+ gint response;
+ GtkBuilder *builder;
+ GtkWidget *dialog;
+ GtkWidget *entry;
+ GtkWidget *show_passphrase_check_button;
+ UDisksBlock *block;
+ UDisksEncrypted *encrypted;
+ const gchar *passphrase;
+ gboolean has_passphrase;
+
+ dialog = NULL;
+ builder = NULL;
+
+ /* TODO: look up passphrase from gnome-keyring? */
+
+ block = udisks_object_peek_block (object);
+ encrypted = udisks_object_peek_encrypted (object);
+
+ passphrase = "";
+ has_passphrase = FALSE;
+ if (gdu_utils_has_configuration (block, "crypttab", &has_passphrase) && has_passphrase)
+ goto do_call;
+
+ dialog = gdu_application_new_widget (gdu_window_get_application (window),
+ "unlock-device-dialog.ui",
+ "unlock-device-dialog",
+ &builder);
+ entry = GTK_WIDGET (gtk_builder_get_object (builder, "unlock-device-passphrase-entry"));
+ show_passphrase_check_button = GTK_WIDGET (gtk_builder_get_object (builder, "unlock-device-show-passphrase-check-button"));
+
+ gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (window));
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (show_passphrase_check_button), FALSE);
+ gtk_entry_set_text (GTK_ENTRY (entry), "");
+
+ g_object_bind_property (show_passphrase_check_button,
+ "active",
+ entry,
+ "visibility",
+ G_BINDING_SYNC_CREATE);
+
+ gtk_widget_show_all (dialog);
+ gtk_widget_grab_focus (entry);
+
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
+ if (response != GTK_RESPONSE_OK)
+ goto out;
+
+ passphrase = gtk_entry_get_text (GTK_ENTRY (entry));
+
+ do_call:
+ udisks_encrypted_call_unlock (encrypted,
+ passphrase,
+ g_variant_new ("a{sv}", NULL), /* options */
+ NULL, /* cancellable */
+ (GAsyncReadyCallback) unlock_cb,
+ g_object_ref (window));
+
+ out:
+ if (dialog != NULL)
+ {
+ gtk_widget_hide (dialog);
+ gtk_widget_destroy (dialog);
+ }
+ if (builder != NULL)
+ g_object_unref (builder);
+}
diff --git a/src/palimpsest/gduunlockdialog.h b/src/palimpsest/gduunlockdialog.h
new file mode 100644
index 0000000..db25cb3
--- /dev/null
+++ b/src/palimpsest/gduunlockdialog.h
@@ -0,0 +1,36 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2008-2011 Red Hat, Inc.
+ *
+ * This library 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 of the License, or (at your option) any later version.
+ *
+ * This 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: David Zeuthen <davidz redhat com>
+ */
+
+#ifndef __GDU_UNLOCK_DIALOG_H_H__
+#define __GDU_UNLOCK_DIALOG_H_H__
+
+#include <gtk/gtk.h>
+#include "gdutypes.h"
+
+G_BEGIN_DECLS
+
+void gdu_unlock_dialog_show (GduWindow *window,
+ UDisksObject *object);
+
+G_END_DECLS
+
+#endif /* __GDU_UNLOCK_DIALOG_H__ */
diff --git a/src/palimpsest/gduutils.c b/src/palimpsest/gduutils.c
index 804ee3f..a484c4c 100644
--- a/src/palimpsest/gduutils.c
+++ b/src/palimpsest/gduutils.c
@@ -51,3 +51,43 @@ gdu_utils_drive_treat_as_removable (UDisksDrive *drive,
out:
return ret;
}
+
+gboolean
+gdu_utils_has_configuration (UDisksBlock *block,
+ const gchar *type,
+ gboolean *out_has_passphrase)
+{
+ GVariantIter iter;
+ const gchar *config_type;
+ GVariant *config_details;
+ gboolean ret;
+ gboolean has_passphrase;
+
+ ret = FALSE;
+ has_passphrase = FALSE;
+
+ g_variant_iter_init (&iter, udisks_block_get_configuration (block));
+ while (g_variant_iter_next (&iter, "(&s a{sv})", &config_type, &config_details))
+ {
+ if (g_strcmp0 (config_type, type) == 0)
+ {
+ if (g_strcmp0 (type, "crypttab") == 0)
+ {
+ const gchar *passphrase_path;
+ if (g_variant_lookup (config_details, "passphrase-path", "^&ay", &passphrase_path) &&
+ strlen (passphrase_path) > 0 &&
+ !g_str_has_prefix (passphrase_path, "/dev"))
+ has_passphrase = TRUE;
+ }
+ ret = TRUE;
+ g_variant_unref (config_details);
+ goto out;
+ }
+ g_variant_unref (config_details);
+ }
+
+ out:
+ if (out_has_passphrase != NULL)
+ *out_has_passphrase = has_passphrase;
+ return ret;
+}
diff --git a/src/palimpsest/gduutils.h b/src/palimpsest/gduutils.h
index d80a038..a61582d 100644
--- a/src/palimpsest/gduutils.h
+++ b/src/palimpsest/gduutils.h
@@ -31,6 +31,10 @@ G_BEGIN_DECLS
gboolean gdu_utils_drive_treat_as_removable (UDisksDrive *drive,
UDisksBlock *block);
+gboolean gdu_utils_has_configuration (UDisksBlock *block,
+ const gchar *type,
+ gboolean *out_has_passphrase);
+
G_END_DECLS
#endif /* __GDU_UTILS_H__ */
diff --git a/src/palimpsest/gduwindow.c b/src/palimpsest/gduwindow.c
index e168d48..297f809 100644
--- a/src/palimpsest/gduwindow.c
+++ b/src/palimpsest/gduwindow.c
@@ -42,6 +42,7 @@
#include "gdufstabdialog.h"
#include "gdufilesystemdialog.h"
#include "gdupartitiondialog.h"
+#include "gduunlockdialog.h"
/* Keep in sync with tabs in palimpsest.ui file */
typedef enum
@@ -1696,46 +1697,6 @@ calculate_configuration_for_display (UDisksBlock *block,
return ret;
}
-static gboolean
-has_configuration (UDisksBlock *block,
- const gchar *type,
- gboolean *out_has_passphrase)
-{
- GVariantIter iter;
- const gchar *config_type;
- GVariant *config_details;
- gboolean ret;
- gboolean has_passphrase;
-
- ret = FALSE;
- has_passphrase = FALSE;
-
- g_variant_iter_init (&iter, udisks_block_get_configuration (block));
- while (g_variant_iter_next (&iter, "(&s a{sv})", &config_type, &config_details))
- {
- if (g_strcmp0 (config_type, type) == 0)
- {
- if (g_strcmp0 (type, "crypttab") == 0)
- {
- const gchar *passphrase_path;
- if (g_variant_lookup (config_details, "passphrase-path", "^&ay", &passphrase_path) &&
- strlen (passphrase_path) > 0 &&
- !g_str_has_prefix (passphrase_path, "/dev"))
- has_passphrase = TRUE;
- }
- ret = TRUE;
- g_variant_unref (config_details);
- goto out;
- }
- g_variant_unref (config_details);
- }
-
- out:
- if (out_has_passphrase != NULL)
- *out_has_passphrase = has_passphrase;
- return ret;
-}
-
static void
update_device_page_for_block (GduWindow *window,
UDisksObject *object,
@@ -1755,9 +1716,9 @@ update_device_page_for_block (GduWindow *window,
* the relevant menu option (to get to the configuration dialog)
* if the device matches the configuration....
*/
- if (has_configuration (block, "fstab", NULL))
+ if (gdu_utils_has_configuration (block, "fstab", NULL))
*show_flags |= SHOW_FLAGS_POPUP_MENU_CONFIGURE_FSTAB;
- if (has_configuration (block, "crypttab", NULL))
+ if (gdu_utils_has_configuration (block, "crypttab", NULL))
*show_flags |= SHOW_FLAGS_POPUP_MENU_CONFIGURE_CRYPTTAB;
/* if the device has no media and there is no existing configuration, then
@@ -2317,101 +2278,15 @@ on_devtab_action_eject_activated (GtkAction *action,
/* ---------------------------------------------------------------------------------------------------- */
static void
-unlock_cb (UDisksEncrypted *encrypted,
- GAsyncResult *res,
- gpointer user_data)
-{
- GduWindow *window = GDU_WINDOW (user_data);
- GError *error;
-
- error = NULL;
- if (!udisks_encrypted_call_unlock_finish (encrypted,
- NULL, /* out_cleartext_device */
- res,
- &error))
- {
- gdu_window_show_error (window,
- _("Error unlocking encrypted device"),
- error);
- g_error_free (error);
- }
- g_object_unref (window);
-}
-
-static void
on_devtab_action_unlock_activated (GtkAction *action,
gpointer user_data)
{
GduWindow *window = GDU_WINDOW (user_data);
- gint response;
- GtkBuilder *builder;
- GtkWidget *dialog;
- GtkWidget *entry;
- GtkWidget *show_passphrase_check_button;
UDisksObject *object;
- UDisksBlock *block;
- UDisksEncrypted *encrypted;
- const gchar *passphrase;
- gboolean has_passphrase;
-
- dialog = NULL;
- builder = NULL;
-
- /* TODO: look up passphrase from gnome-keyring? */
object = gdu_volume_grid_get_selected_device (GDU_VOLUME_GRID (window->volume_grid));
- block = udisks_object_peek_block (object);
- encrypted = udisks_object_peek_encrypted (object);
-
- passphrase = "";
- has_passphrase = FALSE;
- if (has_configuration (block, "crypttab", &has_passphrase) && has_passphrase)
- goto do_call;
-
- dialog = gdu_application_new_widget (window->application,
- "unlock-device-dialog.ui",
- "unlock-device-dialog",
- &builder);
- entry = GTK_WIDGET (gtk_builder_get_object (builder, "unlock-device-passphrase-entry"));
- show_passphrase_check_button = GTK_WIDGET (gtk_builder_get_object (builder, "unlock-device-show-passphrase-check-button"));
-
- gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (window));
- gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
-
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (show_passphrase_check_button), FALSE);
- gtk_entry_set_text (GTK_ENTRY (entry), "");
-
- g_object_bind_property (show_passphrase_check_button,
- "active",
- entry,
- "visibility",
- G_BINDING_SYNC_CREATE);
-
- gtk_widget_show_all (dialog);
- gtk_widget_grab_focus (entry);
-
- response = gtk_dialog_run (GTK_DIALOG (dialog));
- if (response != GTK_RESPONSE_OK)
- goto out;
-
- passphrase = gtk_entry_get_text (GTK_ENTRY (entry));
-
- do_call:
- udisks_encrypted_call_unlock (encrypted,
- passphrase,
- g_variant_new ("a{sv}", NULL), /* options */
- NULL, /* cancellable */
- (GAsyncReadyCallback) unlock_cb,
- g_object_ref (window));
-
- out:
- if (dialog != NULL)
- {
- gtk_widget_hide (dialog);
- gtk_widget_destroy (dialog);
- }
- if (builder != NULL)
- g_object_unref (builder);
+ g_assert (object != NULL);
+ gdu_unlock_dialog_show (window, object);
}
/* ---------------------------------------------------------------------------------------------------- */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]