[Xfce4-commits] [xfce/libxfce4ui] 01/05: Add a tests directory

noreply at xfce.org noreply at xfce.org
Mon Jun 6 15:02:06 CEST 2016


This is an automated email from the git hooks/post-receive script.

eric pushed a commit to branch master
in repository xfce/libxfce4ui.

commit 3cf15d51476c7e2455df7a8bee67c953b4ce8aaf
Author: Eric Koegel <eric.koegel at gmail.com>
Date:   Fri Jun 3 15:31:35 2016 +0300

    Add a tests directory
    
    With a test-ui program with -gtk2 and -gtk3 versions for easily
    testing and reviewing changes to libxfce4ui especially with all
    the GTK_STOCK changes.
    Additionally fix up a couple of the dialog displays.
---
 Makefile.am               |   3 +-
 configure.ac.in           |   1 +
 libxfce4ui/xfce-dialogs.c |  97 +++++++++++++------
 tests/Makefile.am         |  69 ++++++++++++++
 tests/test-ui.c           | 232 ++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 374 insertions(+), 28 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 1d64b00..ea8a250 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -7,7 +7,8 @@ SUBDIRS = \
 	glade \
 	icons \
 	docs \
-	po
+	po \
+	tests
 
 distuninstallcheck_listfiles = \ 
 	find . -type f -print | grep -v ./share/icons/hicolor/icon-theme.cache
diff --git a/configure.ac.in b/configure.ac.in
index 99aa079..cd3b2e1 100644
--- a/configure.ac.in
+++ b/configure.ac.in
@@ -338,6 +338,7 @@ libxfce4ui/libxfce4ui-config.h
 libxfce4ui/Makefile
 xfce4-about/Makefile
 po/Makefile.in
+tests/Makefile
 ])
 
 dnl ***************************
diff --git a/libxfce4ui/xfce-dialogs.c b/libxfce4ui/xfce-dialogs.c
index 2057c1b..8b4aa40 100644
--- a/libxfce4ui/xfce-dialogs.c
+++ b/libxfce4ui/xfce-dialogs.c
@@ -341,7 +341,7 @@ xfce_dialog_show_info (GtkWindow   *parent,
 #if !GTK_CHECK_VERSION (3, 10, 0)
                        GTK_STOCK_CLOSE,
 #else
-                       "window-close",
+                       XFCE_BUTTON_TYPE_MIXED, "window-close", _("Close"),
 #endif
                        GTK_RESPONSE_CLOSE, NULL);
 
@@ -384,7 +384,7 @@ xfce_dialog_show_warning (GtkWindow   *parent,
 #if !GTK_CHECK_VERSION (3, 10, 0)
                        GTK_STOCK_CLOSE,
 #else
-                       "window-close",
+                       XFCE_BUTTON_TYPE_MIXED, "window-close", _("Close"),
 #endif
                        GTK_RESPONSE_CLOSE, NULL);
 
@@ -428,7 +428,7 @@ xfce_dialog_show_error (GtkWindow    *parent,
 #if !GTK_CHECK_VERSION (3, 10, 0)
                        GTK_STOCK_CLOSE,
 #else
-                       "window-close",
+                       XFCE_BUTTON_TYPE_MIXED, "window-close", _("Close"),
 #endif
                        GTK_RESPONSE_CLOSE, NULL);
 
@@ -477,7 +477,7 @@ xfce_dialog_confirm (GtkWindow   *parent,
   if (stock_id != NULL && (strcmp (stock_id, "gtk-yes") == 0 || strcmp (stock_id, "yes")) == 0)
     {
 #if GTK_CHECK_VERSION (3, 10, 0)
-      no_stock_id = "gtk-no";
+      no_stock_id = _("No");
 #else
       no_stock_id = GTK_STOCK_NO;
 #endif
@@ -485,22 +485,29 @@ xfce_dialog_confirm (GtkWindow   *parent,
   else
     {
 #if GTK_CHECK_VERSION (3, 10, 0)
-      no_stock_id = "gtk-cancel";
+      no_stock_id = _("Cancel");
 #else
       no_stock_id = GTK_STOCK_CANCEL;
 #endif
     }
 
+#if GTK_CHECK_VERSION (3, 0, 0)
   response_id = xfce_message_dialog (parent, _("Question"),
-#if !GTK_CHECK_VERSION (3, 10, 0)
-                                     GTK_STOCK_DIALOG_QUESTION,
-#else
                                      "dialog-question",
-#endif
-                                     primary_text, secondary_text,
+                                     primary_text,
+                                     secondary_text,
                                      no_stock_id, GTK_RESPONSE_NO,
-                                     XFCE_BUTTON_TYPE_MIXED, stock_id,
-                                     confirm_label, GTK_RESPONSE_YES, NULL);
+                                     XFCE_BUTTON_TYPE_MIXED, stock_id, confirm_label, GTK_RESPONSE_YES,
+                                     NULL);
+#else
+  response_id = xfce_message_dialog (parent, _("Question"),
+                                     GTK_STOCK_DIALOG_QUESTION,
+                                     primary_text,
+                                     secondary_text,
+                                     no_stock_id, GTK_RESPONSE_NO,
+                                     XFCE_BUTTON_TYPE_MIXED, stock_id, confirm_label, GTK_RESPONSE_YES,
+                                     NULL);
+#endif
 
   g_free (primary_text);
 
@@ -574,21 +581,6 @@ xfce_message_dialog_new_valist (GtkWindow   *parent,
   if (parent == NULL)
     xfce_gtk_window_center_on_active_screen (GTK_WINDOW (dialog));
 
-  if (icon_stock_id != NULL)
-    {
-      /* set dialog and window icon */
-#if GTK_CHECK_VERSION (3, 10, 0)
-      image = gtk_image_new_from_icon_name (icon_stock_id, GTK_ICON_SIZE_DIALOG);
-      gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), image);
-#else
-      image = gtk_image_new_from_stock (icon_stock_id, GTK_ICON_SIZE_DIALOG);
-      gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog), image);
-#endif
-
-      gtk_widget_show (image);
-      gtk_window_set_icon_name (GTK_WINDOW (dialog), icon_stock_id);
-    }
-
   /* add buttons */
   while (text != NULL)
     {
@@ -648,6 +640,57 @@ xfce_message_dialog_new_valist (GtkWindow   *parent,
       text = va_arg (args, const gchar *);
     }
 
+  if (icon_stock_id != NULL)
+    {
+      /* set dialog and window icon */
+#if GTK_CHECK_VERSION (3, 10, 0)
+      /* This is fun. We want to put the image back on the left. Best way to
+       * do that is create an hbox, put the image in position 0, then pack
+       * in a vbox with all the children of the dialog.
+       */
+      GtkWidget *content = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
+      GList     *children = gtk_container_get_children (GTK_CONTAINER (content));
+      GtkWidget *hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
+      GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
+      GList     *iter;
+
+      image = gtk_image_new_from_icon_name (icon_stock_id, GTK_ICON_SIZE_DIALOG);
+
+      /* Add the image first */
+      gtk_container_add (GTK_CONTAINER (hbox), image);
+      /* next add the vbox */
+      gtk_container_add (GTK_CONTAINER (hbox), vbox);
+
+      /* move the widgets from the parent to the vbox */
+      for (iter = g_list_first (children); iter != NULL; iter = g_list_next (iter))
+        {
+          /* Skip the action area */
+          if (GTK_IS_BOX (iter->data))
+            continue;
+
+          /* keep the widget alive */
+          g_object_ref (iter->data);
+          /* remove from parent */
+          gtk_container_remove (GTK_CONTAINER (content), iter->data);
+          /* add to vbox */
+          gtk_container_add (GTK_CONTAINER (vbox), iter->data);
+          /* new container has a ref, we don't need ours anymore */
+          g_object_unref (iter->data);
+        }
+
+      /* Finally add the hbox to the parent */
+      gtk_container_add (GTK_CONTAINER (content), hbox);
+      gtk_widget_show (hbox);
+      gtk_widget_show (vbox);
+#else
+      image = gtk_image_new_from_stock (icon_stock_id, GTK_ICON_SIZE_DIALOG);
+      gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog), image);
+#endif
+
+      gtk_widget_show (image);
+      gtk_window_set_icon_name (GTK_WINDOW (dialog), icon_stock_id);
+    }
+
   return dialog;
 }
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..fffeadb
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,69 @@
+# vi:set ts=8 sw=8 noet ai nocindent syntax=automake:
+#
+# Copyright (c) 2016 Eric Koegel <eric at xfce.org>
+#
+# This 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.
+#
+# 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 Library General Public License for more details.
+#
+# You should have received a copy of the GNU Library General
+# Public License along with this library; if not, write to the
+# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+AM_CPPFLAGS =								\
+	-I$(top_srcdir)							\
+	-DG_LOG_DOMAIN=\"libxfce4ui-tests\"
+
+noinst_PROGRAMS =					\
+	test-ui-gtk2					\
+	test-ui-gtk3
+
+
+# test-ui-gtk2
+test_ui_gtk2_SOURCES =				\
+	test-ui.c
+
+test_ui_gtk2_CFLAGS =					\
+	$(LIBSM_CFLAGS) \
+	$(GTK2_CFLAGS) \
+	$(LIBSTARTUP_NOTIFICATION_CFLAGS) \
+	$(LIBXFCE4UTIL_CFLAGS) \
+	$(PLATFORM_CFLAGS)
+
+test_ui_gtk2_DEPENDENCIES =				\
+	$(top_builddir)/libxfce4ui/libxfce4ui-1.la
+
+test_ui_gtk2_LDADD =					\
+	$(LIBSM_LIBS) \
+	$(GTK2_LIBS) \
+	$(LIBSTARTUP_NOTIFICATION_LIBS) \
+	$(LIBXFCE4UTIL_LIBS) \
+	$(top_builddir)/libxfce4ui/libxfce4ui-1.la
+
+# test-ui-gtk3
+test_ui_gtk3_SOURCES =				\
+	test-ui.c
+
+test_ui_gtk3_CFLAGS =					\
+	$(LIBSM_CFLAGS) \
+	$(GTK3_CFLAGS) \
+	$(LIBSTARTUP_NOTIFICATION_CFLAGS) \
+	$(LIBXFCE4UTIL_CFLAGS) \
+	$(PLATFORM_CFLAGS)
+
+test_ui_gtk3_DEPENDENCIES =				\
+	$(top_builddir)/libxfce4ui/libxfce4ui-2.la
+
+test_ui_gtk3_LDADD =					\
+	$(LIBSM_LIBS) \
+	$(GTK3_LIBS) \
+	$(LIBSTARTUP_NOTIFICATION_LIBS) \
+	$(LIBXFCE4UTIL_LIBS) \
+	$(top_builddir)/libxfce4ui/libxfce4ui-2.la
diff --git a/tests/test-ui.c b/tests/test-ui.c
new file mode 100644
index 0000000..9f164a2
--- /dev/null
+++ b/tests/test-ui.c
@@ -0,0 +1,232 @@
+/*-
+ * vi:set et ai sts=2 sw=2 cindent:
+ *
+ * Copyright (c) 2016 Eric Koegel <eric at xfce.org>
+ *
+ * This 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.
+ *
+ * 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+
+#include <gtk/gtk.h>
+#include <glib.h>
+#include <libxfce4ui/libxfce4ui.h>
+
+
+static const gchar *APP_NAME = "libxfce4ui: Test";
+
+static void
+main_window_destroy (GtkWidget *window)
+{
+  gtk_main_quit ();
+}
+
+static void
+show_xfce_message_dialog (GtkButton *button,
+                          gpointer unused)
+{
+  GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file_at_size ("../icons/48x48/xfce4-logo.png", 24, 24, NULL);
+
+#if GTK_CHECK_VERSION (3, 0, 0)
+  xfce_message_dialog (NULL, "Question - Gtk3 version with no deprecated symbols",
+                       "dialog-question",
+                       "There are unsaved modifications",
+                       "The menu has been modified, do you want to save it before quitting?",
+                       XFCE_BUTTON_TYPE_MIXED, "document-save", "Save", GTK_RESPONSE_YES,
+                       XFCE_BUTTON_TYPE_MIXED, "edit-delete", "Forget modifications", GTK_RESPONSE_APPLY,
+                       XFCE_BUTTON_TYPE_PIXBUF, pixbuf, "Quit", GTK_RESPONSE_NO,
+                       XFCE_BUTTON_TYPE_MIXED, "process-stop", "Cancel", GTK_RESPONSE_CANCEL,
+                       NULL);
+#endif
+
+/* ignore those warnings so it's easy to see what the default Gtk2 version
+ * looks like in Gtk3 with the stock icons */
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+  xfce_message_dialog (NULL, "Question - Gtk2 version",
+                       GTK_STOCK_DIALOG_QUESTION,
+                       "There are unsaved modifications",
+                       "The menu has been modified, do you want to save it before quitting?",
+                       GTK_STOCK_SAVE, GTK_RESPONSE_YES,
+                       XFCE_BUTTON_TYPE_MIXED, GTK_STOCK_DELETE, "Forget modifications", GTK_RESPONSE_APPLY,
+                       XFCE_BUTTON_TYPE_PIXBUF, pixbuf, "Quit", GTK_RESPONSE_NO,
+                       GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                       NULL);
+G_GNUC_END_IGNORE_DEPRECATIONS
+
+  if (pixbuf != NULL)
+    {
+      g_object_unref (G_OBJECT (pixbuf));
+    }
+}
+
+static void
+show_xfce_dialog_show_help (GtkButton *button,
+                            gpointer unused)
+{
+  xfce_dialog_show_help (NULL, "xfce4-session", "preferences", NULL);
+}
+
+static void
+show_xfce_dialog_show_help_with_version (GtkButton *button,
+                                         gpointer unused)
+{
+  xfce_dialog_show_help_with_version (NULL, "xfce4-power-manager", "start", NULL, "4.12");
+}
+
+static void
+show_xfce_dialog_show_info (GtkButton *button,
+                            gpointer unused)
+{
+  xfce_dialog_show_info(NULL, NULL, "%s", "xfburn_transcoder_get_description (priv->trans)");
+}
+
+static void
+show_xfce_dialog_show_warning (GtkButton *button,
+                               gpointer unused)
+{
+  xfce_dialog_show_warning(NULL, NULL, _("A file named \"%s\" already exists in this directory, the file hasn't been added."), "name");
+}
+
+static void
+show_xfce_dialog_show_error (GtkButton *button,
+                             gpointer unused)
+{
+  GError *error = NULL;
+
+  g_set_error (&error, G_FILE_ERROR, G_FILE_ERROR_NOENT, "This isn't a real error");
+
+  xfce_dialog_show_error (NULL, error, _("Failed to migrate the old panel configuration"));
+
+  g_clear_error (&error);
+}
+
+static void
+show_xfce_dialog_confirm (GtkButton *button,
+                          gpointer unused)
+{
+#if GTK_CHECK_VERSION (3, 0, 0)
+  xfce_dialog_confirm (NULL, "system-run", "Execute",
+                       "Do you want to start the panel? If you do, make sure "
+                       "you save the session on logout, so the panel is "
+                       "automatically started the next time you login.",
+                       "No running instance of %s was found", G_LOG_DOMAIN);
+#endif
+
+/* ignore those warnings so it's easy to see what the default Gtk2 version
+ * looks like in Gtk3 with the stock icons */
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+  xfce_dialog_confirm (NULL, GTK_STOCK_EXECUTE, "Execute",
+                       "Do you want to start the panel? If you do, make sure "
+                       "you save the session on logout, so the panel is "
+                       "automatically started the next time you login.",
+                       "No running instance of %s was found", G_LOG_DOMAIN);
+G_GNUC_END_IGNORE_DEPRECATIONS
+}
+
+static void
+create_main_window (void)
+{
+  GtkWidget *window;
+  GtkWidget *box;
+  GtkWidget *button;
+
+  /* Create main window */
+  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+  gtk_window_set_title (GTK_WINDOW (window), APP_NAME);
+  gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
+  gtk_container_set_border_width (GTK_CONTAINER (window), 12);
+  gtk_widget_show (window);
+
+  /* Exit main loop when when the window is closed */
+  g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (main_window_destroy), NULL);
+
+  /* Create the box to hold all the stuff */
+#if GTK_CHECK_VERSION (3, 0, 0)
+  box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
+#else
+  box = gtk_vbox_new (FALSE, 0);
+#endif
+  gtk_container_add (GTK_CONTAINER (window), box);
+  gtk_widget_show (box);
+
+  /* Create buttons */
+
+  /* xfce_message_dialog */
+  button = gtk_button_new_with_label ("show xfce_message_dialog");
+  gtk_container_add (GTK_CONTAINER (box), button);
+  gtk_widget_show (button);
+  g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (show_xfce_message_dialog), NULL);
+
+  /* xfce_dialog_show_help */
+  button = gtk_button_new_with_label ("show xfce_dialog_show_help");
+  gtk_container_add (GTK_CONTAINER (box), button);
+  gtk_widget_show (button);
+  g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (show_xfce_dialog_show_help), NULL);
+
+  /* xfce_dialog_show_help_with_version */
+  button = gtk_button_new_with_label ("show xfce_dialog_show_help_with_version");
+  gtk_container_add (GTK_CONTAINER (box), button);
+  gtk_widget_show (button);
+  g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (show_xfce_dialog_show_help_with_version), NULL);
+
+  /* xfce_dialog_show_info */
+  button = gtk_button_new_with_label ("show xfce_dialog_show_info");
+  gtk_container_add (GTK_CONTAINER (box), button);
+  gtk_widget_show (button);
+  g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (show_xfce_dialog_show_info), NULL);
+
+  /* xfce_dialog_show_warning */
+  button = gtk_button_new_with_label ("show xfce_dialog_show_warning");
+  gtk_container_add (GTK_CONTAINER (box), button);
+  gtk_widget_show (button);
+  g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (show_xfce_dialog_show_warning), NULL);
+
+  /* xfce_dialog_show_error */
+  button = gtk_button_new_with_label ("show xfce_dialog_show_error");
+  gtk_container_add (GTK_CONTAINER (box), button);
+  gtk_widget_show (button);
+  g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (show_xfce_dialog_show_error), NULL);
+
+  /* xfce_dialog_confirm */
+  button = gtk_button_new_with_label ("show xfce_dialog_confirm");
+  gtk_container_add (GTK_CONTAINER (box), button);
+  gtk_widget_show (button);
+  g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (show_xfce_dialog_confirm), NULL);
+}
+
+
+
+gint
+main (gint    argc,
+      gchar **argv)
+{
+  gint    exit_code = EXIT_SUCCESS;
+
+  /* Initialize GTK+ */
+  gtk_init (&argc, &argv);
+
+  /* create the main window */
+  create_main_window ();
+
+  /* Enter main loop */
+  gtk_main ();
+
+  return exit_code;
+}

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list