[seahorse] util: Migrate seahorse_util_show_error() to vala



commit 4f03ce310cf5b375d952f247be92ce0c5a609b91
Author: Stef Walter <stefw gnome org>
Date:   Thu Jun 20 12:46:29 2013 +0200

    util: Migrate seahorse_util_show_error() to vala

 common/Makefile.am               |    1 +
 common/util.vala                 |   57 ++++++++++++++++++++++++++++++++++++++
 libseahorse/seahorse-util.c      |   52 ----------------------------------
 libseahorse/seahorse-util.h      |    4 --
 pgp/seahorse-gpgme.c             |    1 +
 pgp/seahorse-keyserver-results.c |    3 +-
 6 files changed, 61 insertions(+), 57 deletions(-)
---
diff --git a/common/Makefile.am b/common/Makefile.am
index 71c0568..067261f 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -19,6 +19,7 @@ libcommon_la_SOURCES = \
        place.vala \
        registry.vala \
        types.vala \
+       util.vala \
        viewable.vala \
        $(NULL)
 
diff --git a/common/util.vala b/common/util.vala
new file mode 100644
index 0000000..d2ffa5b
--- /dev/null
+++ b/common/util.vala
@@ -0,0 +1,57 @@
+/*
+ * Seahorse
+ *
+ * Copyright (C) 2003 Jacob Perkins
+ * Copyright (C) 2004-2005 Stefan Walter
+ * Copyright (C) 2011 Collabora Ltd.
+ *
+ * This program 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 2 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 General Public License for more details.
+ * You should have received a copy of the GNU 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 {
+
+namespace Util {
+
+       public void show_error (Gtk.Widget? parent,
+                               string? heading,
+                               string? message) {
+               Gtk.Window? window = null;
+
+               if (message == null)
+                       message = "";
+
+               if (parent != null) {
+                       if (!(parent is Gtk.Window))
+                               parent = parent.get_toplevel();
+                       if (parent is Gtk.Window)
+                               window = (Gtk.Window)parent;
+               }
+
+               var dialog = new Gtk.MessageDialog(window, Gtk.DialogFlags.MODAL,
+                                                  Gtk.MessageType.ERROR,
+                                                  Gtk.ButtonsType.CLOSE, "");
+               if (heading == null)
+                       dialog.set("text", message);
+               else
+                       dialog.set("text", heading, "secondary-text", message);
+
+               dialog.run();
+               dialog.destroy();
+       }
+
+}
+
+}
diff --git a/libseahorse/seahorse-util.c b/libseahorse/seahorse-util.c
index 13c9615..881aac7 100644
--- a/libseahorse/seahorse-util.c
+++ b/libseahorse/seahorse-util.c
@@ -48,58 +48,6 @@
 #include <sys/types.h>
 
 /**
- * seahorse_util_show_error:
- * @parent: The parent widget. Can be NULL
- * @heading: The heading of the dialog
- * @message: The message to display
- *
- * This displays an error dialog.
- * The parent widget can be any widget. The dialog will be a child of the window
- * the widget is in.
- *
- */
-void
-seahorse_util_show_error (gpointer parent,
-                          const gchar *heading,
-                          const gchar *message)
-{
-       GtkWidget *dialog;
-
-       g_return_if_fail (message || heading);
-       if (!message)
-               message = "";
-
-       if (parent) {
-               if (!GTK_IS_WIDGET (parent)) {
-                       g_warn_if_reached ();
-                       parent = NULL;
-               } else {
-                       if (!GTK_IS_WINDOW (parent)) 
-                               parent = gtk_widget_get_toplevel (parent);
-                       if (!GTK_IS_WINDOW (parent) && gtk_widget_is_toplevel (parent))
-                               parent = NULL;
-               }
-       }
-       
-       dialog = gtk_message_dialog_new (GTK_WINDOW (parent), 
-                                       GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR,
-                                       GTK_BUTTONS_CLOSE, NULL);
-       if (heading)
-           g_object_set (G_OBJECT (dialog),
-                         "text", heading,
-                         "secondary-text", message,
-                         NULL);
-    else
-        g_object_set (G_OBJECT (dialog),
-                         "text", message,
-                         NULL);
-       
-       
-       gtk_dialog_run (GTK_DIALOG (dialog));
-       gtk_widget_destroy (dialog);
-}
-
-/**
  * seahorse_util_handle_error:
  * @error: The #GError to print, and clear
  * @desc: The heading of the box
diff --git a/libseahorse/seahorse-util.h b/libseahorse/seahorse-util.h
index 29d0fcb..2b84aed 100644
--- a/libseahorse/seahorse-util.h
+++ b/libseahorse/seahorse-util.h
@@ -41,10 +41,6 @@ gchar*      seahorse_util_get_display_date_string   (const time_t time);
 
 GQuark      seahorse_util_error_domain          (void);
 
-void        seahorse_util_show_error            (gpointer parent,
-                                                 const gchar *heading,
-                                                 const gchar *message);
-
 void        seahorse_util_handle_error          (GError **error,
                                                  gpointer parent,
                                                  const gchar* description,
diff --git a/pgp/seahorse-gpgme.c b/pgp/seahorse-gpgme.c
index c921aae..16550fc 100644
--- a/pgp/seahorse-gpgme.c
+++ b/pgp/seahorse-gpgme.c
@@ -24,6 +24,7 @@
 
 #include "seahorse-gpgme.h"
 
+#include "seahorse-common.h"
 #define DEBUG_FLAG SEAHORSE_DEBUG_OPERATION
 #include "seahorse-debug.h"
 #include "seahorse-util.h"
diff --git a/pgp/seahorse-keyserver-results.c b/pgp/seahorse-keyserver-results.c
index 1a04468..66387d2 100644
--- a/pgp/seahorse-keyserver-results.c
+++ b/pgp/seahorse-keyserver-results.c
@@ -483,7 +483,8 @@ on_search_completed (GObject *source,
        if (error != NULL) {
                window = seahorse_catalog_get_window (SEAHORSE_CATALOG (self));
                g_dbus_error_strip_remote_error (error);
-               seahorse_util_show_error (window, _("The search for keys failed."), error->message);
+               seahorse_util_show_error (GTK_WIDGET (window),
+                                         _("The search for keys failed."), error->message);
                g_error_free (error);
        }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]