summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am19
-rw-r--r--tests/testappchooser.c218
-rw-r--r--tests/testappchooserbutton.c136
-rw-r--r--tests/testmerge.c10
-rwxr-xr-xtests/testscale.c24
-rw-r--r--tests/testswitch.c86
6 files changed, 492 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 78151044d7..283285311b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -31,6 +31,8 @@ noinst_PROGRAMS = $(TEST_PROGS) \
print-editor \
testaccel \
testadjustsize \
+ testappchooser \
+ testappchooserbutton \
testassistant \
testbbox \
testbuttons \
@@ -96,7 +98,8 @@ noinst_PROGRAMS = $(TEST_PROGS) \
testexpander \
testvolumebutton \
testscrolledwindow \
- testcellarea
+ testcellarea \
+ testswitch
if USE_X11
noinst_PROGRAMS += testerrors
@@ -154,6 +157,8 @@ testnotebookdnd_DEPENDENCIES = $(TEST_DEPS)
testnouiprint_DEPENDENCIES = $(TEST_DEPS)
testoffscreen_DEPENDENCIES = $(TEST_DEPS)
testoffscreenwindow_DEPENDENCIES = $(TEST_DEPS)
+testappchooser_DEPENDENCIES = $(TEST_DEPS)
+testappchooserbutton_DEPENDENCIES = $(TEST_DEPS)
testorientable_DEPENDENCIES = $(TEST_DEPS)
testprint_DEPENDENCIES = $(TEST_DEPS)
testrecentchooser_DEPENDENCIES = $(TEST_DEPS)
@@ -186,6 +191,7 @@ testcellarea_DEPENDENCIES = $(TEST_DEPS)
testwindows_DEPENDENCIES = $(TEST_DEPS)
testexpand_DEPENDENCIES = $(TEST_DEPS)
testexpander_DEPENDENCIES = $(TEST_DEPS)
+testswitch_DEPENDENCIES = $(TEST_DEPS)
flicker_LDADD = $(LDADDS)
simple_LDADD = $(LDADDS)
@@ -227,6 +233,8 @@ testnotebookdnd_LDADD = $(LDADDS)
testnouiprint_LDADD = $(LDADDS)
testoffscreen_LDADD = $(LDADDS)
testoffscreenwindow_LDADD = $(LDADDS)
+testappchooser_LDADD = $(LDADDS)
+testappchooserbutton_LDADD = $(LDADDS)
testorientable_LDADD = $(LDADDS)
testprint_LDADD = $(LDADDS)
testrecentchooser_LDADD = $(LDADDS)
@@ -261,6 +269,7 @@ testcellarea_LDADD = $(LDADDS)
testwindows_LDADD = $(LDADDS)
testexpand_LDADD = $(LDADDS)
testexpander_LDADD = $(LDADDS)
+testswitch_LDADD = $(LDADDS)
testentrycompletion_SOURCES = \
prop-editor.c \
@@ -383,6 +392,12 @@ testoffscreen_SOURCES = \
testoffscreenwindow_SOURCES = \
testoffscreenwindow.c
+testappchooser_SOURCES = \
+ testappchooser.c
+
+testappchooserbutton_SOURCES = \
+ testappchooserbutton.c
+
testwindows_SOURCES = \
testwindows.c
@@ -390,6 +405,8 @@ testexpand_SOURCES = testexpand.c
testexpander_SOURCES = testexpander.c
+testswitch_SOURCES = testswitch.c
+
EXTRA_DIST += \
prop-editor.h \
testgtk.1 \
diff --git a/tests/testappchooser.c b/tests/testappchooser.c
new file mode 100644
index 0000000000..a50f1b4e4c
--- /dev/null
+++ b/tests/testappchooser.c
@@ -0,0 +1,218 @@
+/* testappchooser.c
+ * Copyright (C) 2010 Red Hat, Inc.
+ * Authors: Cosimo Cecchi
+ *
+ * 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <stdlib.h>
+#include <gtk/gtk.h>
+
+static GtkWidget *toplevel;
+static GFile *file;
+static GtkWidget *grid, *file_l, *open;
+static GtkWidget *radio_file, *radio_content, *dialog;
+static GtkWidget *app_chooser_widget;
+static GtkWidget *recommended, *fallback, *other, *all;
+
+static void
+dialog_response (GtkDialog *d,
+ gint response_id,
+ gpointer user_data)
+{
+ GAppInfo *app_info;
+ const gchar *name;
+
+ g_print ("Response: %d\n", response_id);
+
+ if (response_id == GTK_RESPONSE_OK)
+ {
+ app_info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (d));
+ name = g_app_info_get_name (app_info);
+ g_print ("Application selected: %s\n", name);
+
+ g_object_unref (app_info);
+ }
+
+ gtk_widget_destroy (GTK_WIDGET (d));
+ dialog = NULL;
+}
+
+static void
+bind_props (void)
+{
+ g_object_bind_property (recommended, "active",
+ app_chooser_widget, "show-recommended",
+ G_BINDING_SYNC_CREATE);
+ g_object_bind_property (fallback, "active",
+ app_chooser_widget, "show-fallback",
+ G_BINDING_SYNC_CREATE);
+ g_object_bind_property (other, "active",
+ app_chooser_widget, "show-other",
+ G_BINDING_SYNC_CREATE);
+ g_object_bind_property (all, "active",
+ app_chooser_widget, "show-all",
+ G_BINDING_SYNC_CREATE);
+}
+
+static void
+prepare_dialog (void)
+{
+ gboolean use_file = FALSE;
+ gchar *content_type = NULL;
+
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radio_file)))
+ use_file = TRUE;
+ else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radio_content)))
+ use_file = FALSE;
+
+ if (use_file)
+ {
+ dialog = gtk_app_chooser_dialog_new (GTK_WINDOW (toplevel), 0, file);
+ }
+ else
+ {
+ GFileInfo *info;
+
+ info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+ 0, NULL, NULL);
+ content_type = g_strdup (g_file_info_get_content_type (info));
+
+ g_object_unref (info);
+
+ dialog = gtk_app_chooser_dialog_new_for_content_type (GTK_WINDOW (toplevel),
+ 0, content_type);
+ }
+
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (dialog_response), NULL);
+
+ g_free (content_type);
+
+ app_chooser_widget = gtk_app_chooser_dialog_get_widget (GTK_APP_CHOOSER_DIALOG (dialog));
+ bind_props ();
+}
+
+static void
+display_dialog (void)
+{
+ if (dialog == NULL)
+ prepare_dialog ();
+
+ gtk_widget_show (dialog);
+}
+
+static void
+button_clicked (GtkButton *b,
+ gpointer user_data)
+{
+ GtkWidget *w;
+ gchar *path;
+
+ w = gtk_file_chooser_dialog_new ("Select file",
+ GTK_WINDOW (toplevel),
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+ NULL);
+
+ gtk_dialog_run (GTK_DIALOG (w));
+ file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (w));
+ path = g_file_get_path (file);
+ gtk_button_set_label (GTK_BUTTON (file_l), path);
+
+ gtk_widget_destroy (w);
+
+ gtk_widget_set_sensitive (open, TRUE);
+
+ g_free (path);
+}
+
+int
+main (int argc, char **argv)
+{
+ GtkWidget *w1;
+ gchar *path;
+
+ g_type_init ();
+ gtk_init (&argc, &argv);
+
+ toplevel = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_container_set_border_width (GTK_CONTAINER (toplevel), 12);
+ grid = gtk_grid_new ();
+
+ w1 = gtk_label_new ("File:");
+ gtk_widget_set_halign (w1, GTK_ALIGN_START);
+ gtk_grid_attach (GTK_GRID (grid),
+ w1, 0, 0, 1, 1);
+
+ file_l = gtk_button_new ();
+ path = g_build_filename (g_get_current_dir (), "apple-red.png", NULL);
+ file = g_file_new_for_path (path);
+ gtk_button_set_label (GTK_BUTTON (file_l), path);
+ g_free (path);
+
+ gtk_widget_set_halign (file_l, GTK_ALIGN_START);
+ gtk_grid_attach_next_to (GTK_GRID (grid), file_l,
+ w1, GTK_POS_RIGHT, 3, 1);
+ g_signal_connect (file_l, "clicked",
+ G_CALLBACK (button_clicked), NULL);
+
+ radio_file = gtk_radio_button_new_with_label (NULL, "Use GFile");
+ radio_content = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio_file),
+ "Use content type");
+
+ gtk_grid_attach (GTK_GRID (grid), radio_file,
+ 0, 1, 1, 1);
+ gtk_grid_attach_next_to (GTK_GRID (grid), radio_content,
+ radio_file, GTK_POS_BOTTOM, 1, 1);
+
+ open = gtk_button_new_with_label ("Trigger App Chooser dialog");
+ gtk_grid_attach_next_to (GTK_GRID (grid), open,
+ radio_content, GTK_POS_BOTTOM, 1, 1);
+
+ recommended = gtk_check_button_new_with_label ("Show recommended");
+ gtk_grid_attach_next_to (GTK_GRID (grid), recommended,
+ open, GTK_POS_BOTTOM, 1, 1);
+ g_object_set (recommended, "active", TRUE, NULL);
+
+ fallback = gtk_check_button_new_with_label ("Show fallback");
+ gtk_grid_attach_next_to (GTK_GRID (grid), fallback,
+ recommended, GTK_POS_RIGHT, 1, 1);
+
+ other = gtk_check_button_new_with_label ("Show other");
+ gtk_grid_attach_next_to (GTK_GRID (grid), other,
+ fallback, GTK_POS_RIGHT, 1, 1);
+
+ all = gtk_check_button_new_with_label ("Show all");
+ gtk_grid_attach_next_to (GTK_GRID (grid), all,
+ other, GTK_POS_RIGHT, 1, 1);
+
+ prepare_dialog ();
+ g_signal_connect (open, "clicked",
+ G_CALLBACK (display_dialog), NULL);
+
+ gtk_container_add (GTK_CONTAINER (toplevel), grid);
+
+ gtk_widget_show_all (toplevel);
+ g_signal_connect (toplevel, "delete-event",
+ G_CALLBACK (gtk_main_quit), NULL);
+
+ gtk_main ();
+
+ return EXIT_SUCCESS;
+}
diff --git a/tests/testappchooserbutton.c b/tests/testappchooserbutton.c
new file mode 100644
index 0000000000..0416af72c5
--- /dev/null
+++ b/tests/testappchooserbutton.c
@@ -0,0 +1,136 @@
+/* testappchooserbutton.c
+ * Copyright (C) 2010 Red Hat, Inc.
+ * Authors: Cosimo Cecchi
+ *
+ * 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <stdlib.h>
+
+#include <gtk/gtk.h>
+
+#define CUSTOM_ITEM "custom-item"
+
+static GtkWidget *toplevel, *combobox, *box;
+static GtkWidget *sel_image, *sel_name;
+
+static void
+combo_changed_cb (GtkComboBox *cb,
+ gpointer user_data)
+{
+ GAppInfo *app_info;
+
+ app_info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (cb));
+
+ if (app_info == NULL)
+ return;
+
+ gtk_image_set_from_gicon (GTK_IMAGE (sel_image), g_app_info_get_icon (app_info),
+ GTK_ICON_SIZE_DIALOG);
+ gtk_label_set_text (GTK_LABEL (sel_name), g_app_info_get_display_name (app_info));
+
+ g_object_unref (app_info);
+}
+
+static void
+special_item_activated_cb (GtkAppChooserButton *b,
+ const gchar *item_name,
+ gpointer user_data)
+{
+ gtk_image_set_from_gicon (GTK_IMAGE (sel_image), g_themed_icon_new ("face-smile"),
+ GTK_ICON_SIZE_DIALOG);
+ gtk_label_set_text (GTK_LABEL (sel_name), "Special Item");
+}
+
+static void
+action_cb (GtkAppChooserButton *b,
+ const gchar *item_name,
+ gpointer user_data)
+{
+ g_print ("Activated custom item %s\n", item_name);
+}
+
+int
+main (int argc,
+ char **argv)
+{
+ GtkWidget *w;
+
+ g_type_init ();
+ gtk_init (&argc, &argv);
+
+ toplevel = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_container_set_border_width (GTK_CONTAINER (toplevel), 12);
+
+ box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
+ gtk_container_add (GTK_CONTAINER (toplevel), box);
+
+ combobox = gtk_app_chooser_button_new ("image/jpeg");
+ gtk_box_pack_start (GTK_BOX (box), combobox, TRUE, TRUE, 0);
+
+ g_signal_connect (combobox, "changed",
+ G_CALLBACK (combo_changed_cb), NULL);
+
+ w = gtk_label_new (NULL);
+ gtk_label_set_markup (GTK_LABEL (w), "<b>Selected app info</b>");
+ gtk_box_pack_start (GTK_BOX (box), w, TRUE, TRUE, 0);
+
+ w = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
+ gtk_box_pack_start (GTK_BOX (box), w, TRUE, TRUE, 0);
+
+ sel_image = gtk_image_new ();
+ gtk_box_pack_start (GTK_BOX (w), sel_image, TRUE, TRUE, 0);
+ sel_name = gtk_label_new (NULL);
+ gtk_box_pack_start (GTK_BOX (w), sel_name, TRUE, TRUE, 0);
+
+ gtk_app_chooser_button_append_separator (GTK_APP_CHOOSER_BUTTON (combobox));
+ gtk_app_chooser_button_append_custom_item (GTK_APP_CHOOSER_BUTTON (combobox),
+ CUSTOM_ITEM,
+ "Hey, I'm special!",
+ g_themed_icon_new ("face-smile"));
+
+ /* this one will trigger a warning, and will not be added */
+ gtk_app_chooser_button_append_custom_item (GTK_APP_CHOOSER_BUTTON (combobox),
+ CUSTOM_ITEM,
+ "Hey, I'm fake!",
+ g_themed_icon_new ("face-evil"));
+
+ gtk_app_chooser_button_set_show_dialog_item (GTK_APP_CHOOSER_BUTTON (combobox),
+ TRUE);
+
+ /* connect to the detailed signal */
+ g_signal_connect (combobox, "custom-item-activated::" CUSTOM_ITEM,
+ G_CALLBACK (special_item_activated_cb), NULL);
+
+ /* connect to the generic signal too */
+ g_signal_connect (combobox, "custom-item-activated",
+ G_CALLBACK (action_cb), NULL);
+
+ /* test refresh on a combo */
+ gtk_app_chooser_refresh (GTK_APP_CHOOSER (combobox));
+
+ gtk_app_chooser_button_set_active_custom_item (GTK_APP_CHOOSER_BUTTON (combobox),
+ CUSTOM_ITEM);
+
+ gtk_widget_show_all (toplevel);
+
+ g_signal_connect (toplevel, "delete-event",
+ G_CALLBACK (gtk_main_quit), NULL);
+
+ gtk_main ();
+
+ return EXIT_SUCCESS;
+}
diff --git a/tests/testmerge.c b/tests/testmerge.c
index 1e43bb818b..3f1eba0eb2 100644
--- a/tests/testmerge.c
+++ b/tests/testmerge.c
@@ -592,6 +592,7 @@ main (int argc, char **argv)
GtkUIManager *merge;
GtkWidget *window, *table, *frame, *menu_box, *vbox, *view;
GtkWidget *button, *area, *statusbar;
+ GtkWidget *box;
gint i;
gtk_init (&argc, &argv);
@@ -652,6 +653,15 @@ main (int argc, char **argv)
gtk_action_group_get_action (action_group, "BoldAction"));
gtk_widget_show (button);
+ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
+ gtk_box_pack_end (GTK_BOX (menu_box), box, FALSE, FALSE, 0);
+ gtk_container_add (GTK_CONTAINER (box), gtk_label_new ("Bold:"));
+ button = gtk_switch_new ();
+ gtk_container_add (GTK_CONTAINER (box), button);
+ gtk_activatable_set_related_action (GTK_ACTIVATABLE (button),
+ gtk_action_group_get_action (action_group, "BoldAction"));
+ gtk_widget_show_all (box);
+
merge = gtk_ui_manager_new ();
g_signal_connect (merge, "connect-proxy", G_CALLBACK (connect_proxy), statusbar);
diff --git a/tests/testscale.c b/tests/testscale.c
index 8621c3f2c9..0756607f5a 100755
--- a/tests/testscale.c
+++ b/tests/testscale.c
@@ -20,6 +20,16 @@
#include <gtk/gtk.h>
+static void
+show_trough_toggled (GtkToggleButton *button,
+ GtkScale *scale)
+{
+ gboolean value;
+
+ value = gtk_toggle_button_get_active (button);
+ gtk_range_set_range (GTK_RANGE (scale), 0., value ? 100.0 : 0.);
+}
+
int main (int argc, char *argv[])
{
GtkWidget *window;
@@ -27,6 +37,7 @@ int main (int argc, char *argv[])
GtkWidget *box2;
GtkWidget *frame;
GtkWidget *scale;
+ GtkWidget *toggle;
gdouble marks[3] = { 0.0, 50.0, 100.0 };
const gchar *labels[3] = {
"<small>Left</small>",
@@ -96,6 +107,19 @@ int main (int argc, char *argv[])
gtk_container_add (GTK_CONTAINER (frame), scale);
gtk_box_pack_start (GTK_BOX (box), frame, FALSE, FALSE, 0);
+ frame = gtk_frame_new ("Show/hide trough");
+ box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
+ scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL,
+ 0, 100, 1);
+ gtk_box_pack_start (GTK_BOX (box2), scale, TRUE, TRUE, 0);
+ toggle = gtk_toggle_button_new_with_label ("Show slider trough");
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), TRUE);
+ g_signal_connect (G_OBJECT (toggle), "toggled",
+ G_CALLBACK (show_trough_toggled), scale);
+ gtk_box_pack_start (GTK_BOX (box2), toggle, TRUE, TRUE, 0);
+ gtk_container_add (GTK_CONTAINER (frame), box2);
+ gtk_box_pack_start (GTK_BOX (box), frame, FALSE, FALSE, 0);
+
box2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
gtk_box_pack_start (GTK_BOX (box), box2, TRUE, TRUE, 0);
diff --git a/tests/testswitch.c b/tests/testswitch.c
new file mode 100644
index 0000000000..60aae773bc
--- /dev/null
+++ b/tests/testswitch.c
@@ -0,0 +1,86 @@
+#include <stdlib.h>
+#include <gtk/gtk.h>
+
+static gboolean
+boolean_to_text (GBinding *binding,
+ const GValue *source,
+ GValue *target,
+ gpointer dummy G_GNUC_UNUSED)
+{
+ if (g_value_get_boolean (source))
+ g_value_set_string (target, "Enabled");
+ else
+ g_value_set_string (target, "Disabled");
+
+ return TRUE;
+}
+
+static GtkWidget *
+make_switch (gboolean is_on,
+ gboolean is_sensitive)
+{
+ GtkWidget *hbox;
+ GtkWidget *sw, *label;
+
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
+
+ sw = gtk_switch_new ();
+ gtk_switch_set_active (GTK_SWITCH (sw), is_on);
+ gtk_box_pack_start (GTK_BOX (hbox), sw, FALSE, FALSE, 0);
+ gtk_widget_set_sensitive (sw, is_sensitive);
+ gtk_widget_show (sw);
+
+ label = gtk_label_new (is_on ? "Enabled" : "Disabled");
+ gtk_box_pack_end (GTK_BOX (hbox), label, TRUE, TRUE, 0);
+ gtk_widget_show (label);
+
+ g_object_bind_property_full (sw, "active",
+ label, "label",
+ G_BINDING_DEFAULT,
+ boolean_to_text,
+ NULL,
+ NULL, NULL);
+
+ return hbox;
+}
+
+int
+main (int argc,
+ char *argv[])
+{
+ GtkWidget *window;
+ GtkWidget *vbox, *hbox;
+
+ gtk_init (&argc, &argv);
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title (GTK_WINDOW (window), "GtkSwitch");
+ gtk_window_set_default_size (GTK_WINDOW (window), 400, -1);
+ gtk_container_set_border_width (GTK_CONTAINER (window), 6);
+ g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
+ gtk_widget_show (window);
+
+ vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
+ gtk_container_add (GTK_CONTAINER (window), vbox);
+ gtk_widget_show (vbox);
+
+ hbox = make_switch (FALSE, TRUE);
+ gtk_container_add (GTK_CONTAINER (vbox), hbox);
+ gtk_widget_show (hbox);
+
+ hbox = make_switch (TRUE, TRUE);
+ gtk_container_add (GTK_CONTAINER (vbox), hbox);
+ gtk_widget_show (hbox);
+
+ hbox = make_switch (FALSE, FALSE);
+ gtk_container_add (GTK_CONTAINER (vbox), hbox);
+ gtk_widget_show (hbox);
+
+ hbox = make_switch (TRUE, FALSE);
+ gtk_container_add (GTK_CONTAINER (vbox), hbox);
+ gtk_widget_show (hbox);
+
+ gtk_main ();
+
+ return EXIT_SUCCESS;
+}