[seahorse] gkr: Migrate seahorse_gkr_dialogs_xxx to vala
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [seahorse] gkr: Migrate seahorse_gkr_dialogs_xxx to vala
- Date: Wed, 26 Jun 2013 10:18:39 +0000 (UTC)
commit 6f78f082cfa66934596457226c216dab884a674a
Author: Stef Walter <stefw gnome org>
Date: Tue Jun 18 17:44:14 2013 +0200
gkr: Migrate seahorse_gkr_dialogs_xxx to vala
gkr/Makefile.am | 8 ++-
gkr/gkr-dialogs.vala | 83 ++++++++++++++++++++++++++++++
gkr/seahorse-gkr-add-item.c | 11 +++--
gkr/seahorse-gkr-add-keyring.c | 9 +++-
gkr/seahorse-gkr-dialogs.c | 110 ----------------------------------------
gkr/seahorse-gkr-dialogs.h | 4 --
gkr/seahorse-gkr.h | 20 -------
7 files changed, 103 insertions(+), 142 deletions(-)
---
diff --git a/gkr/Makefile.am b/gkr/Makefile.am
index 11d82b2..029ecf4 100644
--- a/gkr/Makefile.am
+++ b/gkr/Makefile.am
@@ -26,10 +26,12 @@ AM_VALAFLAGS = \
--vapidir $(top_builddir)/common \
--pkg common \
--pkg gtk+-3.0 \
+ --pkg gcr-3 \
--pkg libsecret-1 \
$(NULL)
libvala_code_la_SOURCES = \
+ gkr-dialogs.vala \
gkr-module.vala \
$(NULL)
@@ -42,7 +44,7 @@ libseahorse_gkr_la_SOURCES = \
seahorse-gkr-add-item.c \
seahorse-gkr-add-keyring.c \
seahorse-gkr-backend.c seahorse-gkr-backend.h \
- seahorse-gkr-dialogs.h seahorse-gkr-dialogs.c \
+ seahorse-gkr-dialogs.h \
seahorse-gkr-item.c seahorse-gkr-item.h \
seahorse-gkr-item-deleter.c seahorse-gkr-item-deleter.h \
seahorse-gkr-item-properties.c \
@@ -52,7 +54,9 @@ libseahorse_gkr_la_SOURCES = \
libseahorse_gkr_la_LIBADD = \
$(top_builddir)/common/libcommon.la \
- $(top_builddir)/libseahorse/libseahorse.la
+ $(top_builddir)/libseahorse/libseahorse.la \
+ libvala-code.la \
+ $(NULL)
ui_DATA = \
seahorse-add-keyring.xml \
diff --git a/gkr/gkr-dialogs.vala b/gkr/gkr-dialogs.vala
new file mode 100644
index 0000000..94f2ea3
--- /dev/null
+++ b/gkr/gkr-dialogs.vala
@@ -0,0 +1,83 @@
+/*
+ * Seahorse
+ *
+ * Copyright (C) 2009 Stefan Walter
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+namespace Seahorse {
+
+public class GkrDialog {
+
+ private static void update_wait_cursor(Gtk.Widget widget) {
+ GLib.Cancellable? cancellable = widget.get_data("gkr-request");
+
+ /* No request active? */
+ if (cancellable == null) {
+ widget.get_window().set_cursor(null);
+ return;
+ }
+
+ /*
+ * Get the wait cursor. Create a new one and cache it on the widget
+ * if first time.
+ */
+ Gdk.Cursor? cursor = widget.get_data("wait-cursor");
+ if (cursor == null) {
+ cursor = new Gdk.Cursor (Gdk.CursorType.WATCH);
+ widget.set_data("wait-cursor", cursor);
+ }
+
+ /* Indicate that we're loading stuff */
+ widget.get_window().set_cursor(cursor);
+ }
+
+ public static GLib.Cancellable begin_request(Gtk.Widget dialog) {
+ /* Cancel any old operation going on */
+ complete_request (dialog, true);
+
+ /*
+ * Start the operation and tie it to the widget so that it will get
+ * cancelled if the widget is destroyed before the operation is complete
+ */
+ var cancellable = new GLib.Cancellable ();
+ dialog.set_data_full ("gkr-request", cancellable.ref(), (data) => {
+ GLib.Cancellable? c = (GLib.Cancellable?)data;
+ c.cancel();
+ c.unref();
+ });
+
+ if (dialog.get_realized())
+ update_wait_cursor (dialog);
+ else
+ dialog.realize.connect(update_wait_cursor);
+
+ dialog.set_sensitive(false);
+ return cancellable;
+ }
+
+ public static void complete_request(Gtk.Widget dialog, bool cancel) {
+ GLib.Cancellable? cancellable = dialog.steal_data ("gkr-request");
+ if (cancellable != null && cancel)
+ cancellable.cancel();
+ if (dialog.get_realized())
+ update_wait_cursor (dialog);
+ dialog.set_sensitive(true);
+ }
+}
+
+}
diff --git a/gkr/seahorse-gkr-add-item.c b/gkr/seahorse-gkr-add-item.c
index cbde94e..c818143 100644
--- a/gkr/seahorse-gkr-add-item.c
+++ b/gkr/seahorse-gkr-add-item.c
@@ -47,17 +47,19 @@ on_item_stored (GObject *source,
SeahorseWidget *swidget = SEAHORSE_WIDGET (user_data);
GError *error = NULL;
SecretItem *item;
+ GtkWidget *dialog;
+
+ dialog = seahorse_widget_get_toplevel (swidget);
/* Clear the operation without cancelling it since it is complete */
- seahorse_gkr_dialog_complete_request (swidget, FALSE);
+ seahorse_gkr_dialog_complete_request (dialog, FALSE);
item = secret_item_create_finish (result, &error);
if (error == NULL) {
g_object_unref (item);
} else {
- seahorse_util_handle_error (&error, seahorse_widget_get_toplevel (swidget),
- _("Couldn't add item"));
+ seahorse_util_handle_error (&error, dialog, _("Couldn't add item"));
}
g_object_unref (swidget);
@@ -114,7 +116,8 @@ on_add_item_response (GtkDialog *dialog,
secret = secret_value_new (gtk_entry_get_text (GTK_ENTRY (widget)),
-1, "text/plain");
- cancellable = seahorse_gkr_dialog_begin_request (swidget);
+ widget = seahorse_widget_get_toplevel (swidget);
+ cancellable = seahorse_gkr_dialog_begin_request (widget);
attributes = g_hash_table_new (g_str_hash, g_str_equal);
secret_item_create (collection, SECRET_SCHEMA_NOTE, attributes,
label, secret, SECRET_ITEM_CREATE_NONE,
diff --git a/gkr/seahorse-gkr-add-keyring.c b/gkr/seahorse-gkr-add-keyring.c
index 0e49371..ee8a1d9 100644
--- a/gkr/seahorse-gkr-add-keyring.c
+++ b/gkr/seahorse-gkr-add-keyring.c
@@ -58,11 +58,14 @@ on_keyring_create (GObject *source,
{
SeahorseWidget *swidget = SEAHORSE_WIDGET (data);
GError *error = NULL;
+ GtkWidget *dialog;
g_return_if_fail (swidget);
+ dialog = seahorse_widget_get_toplevel (swidget);
+
/* Clear the operation without cancelling it since it is complete */
- seahorse_gkr_dialog_complete_request (swidget, FALSE);
+ seahorse_gkr_dialog_complete_request (dialog, FALSE);
secret_collection_create_finish (result, &error);
@@ -112,6 +115,7 @@ on_add_keyring_properties_response (GtkDialog *dialog,
GCancellable *cancellable;
GtkEntry *entry;
const gchar *keyring;
+ GtkWidget *widget;
if (response == GTK_RESPONSE_HELP) {
seahorse_widget_show_help (swidget);
@@ -124,7 +128,8 @@ on_add_keyring_properties_response (GtkDialog *dialog,
keyring = gtk_entry_get_text (entry);
g_return_if_fail (keyring && keyring[0]);
- cancellable = seahorse_gkr_dialog_begin_request (swidget);
+ widget = seahorse_widget_get_toplevel (swidget);
+ cancellable = seahorse_gkr_dialog_begin_request (widget);
secret_collection_create (seahorse_gkr_backend_get_service (NULL),
keyring, NULL, SECRET_COLLECTION_NONE,
diff --git a/gkr/seahorse-gkr-dialogs.h b/gkr/seahorse-gkr-dialogs.h
index 031f12b..fa565f0 100644
--- a/gkr/seahorse-gkr-dialogs.h
+++ b/gkr/seahorse-gkr-dialogs.h
@@ -38,8 +38,4 @@ void seahorse_gkr_item_properties_show (SeahorseGkrItem *git, Gtk
void seahorse_gkr_keyring_properties_show (SeahorseGkrKeyring *gkr, GtkWindow *parent);
-GCancellable * seahorse_gkr_dialog_begin_request (SeahorseWidget *swidget);
-
-void seahorse_gkr_dialog_complete_request (SeahorseWidget *swidget, gboolean cancel);
-
#endif /* __SEAHORSE_GKR_DIALOGS__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]