summaryrefslogtreecommitdiff
path: root/tests/test-ui.c
blob: a7c0b54ac51116286652ba099ccd3aeb8e05b1db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
/*-
 * vi:set et ai sts=2 sw=2 cindent:
 *
 * Copyright (c) 2016 Eric Koegel <eric@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);

  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);

  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
remove_auto_online (GtkButton *button,
                    gpointer unused)
{
  XfceRc   *rc;
  gboolean  response;

  response = xfce_dialog_confirm (NULL, "system-run", "Execute",
                                  "Removing this will enable the show help "
                                  "dialogs to appear. Do you want to do this?",
                                  "Remove auto-online in rc file? (Gtk3)");

  if (response == FALSE)
    return;

  rc = xfce_rc_config_open (XFCE_RESOURCE_CONFIG, "xfce4/help.rc", FALSE);
  if (rc != NULL)
    {
      xfce_rc_write_bool_entry (rc, "auto-online", FALSE);
      xfce_rc_close (rc);
    }
}

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)
{
  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);
}


static void
close_window (GtkDialog *dialog,
              gint       response_id,
              gpointer   user_data)
{
  gtk_widget_destroy (GTK_WIDGET (dialog));
}

static void
show_xfce_titled_dialog_new_with_buttons (GtkButton *button,
                                          gpointer unused)
{
  GtkWidget *dialog_gtk3;

  dialog_gtk3 = xfce_titled_dialog_new_with_buttons ("Settings Editor (Gtk3)", NULL,
                                                GTK_DIALOG_DESTROY_WITH_PARENT,
                                                "gtk-help", GTK_RESPONSE_HELP,
                                                "gtk-close", GTK_RESPONSE_OK,
                                                NULL);

  xfce_titled_dialog_set_subtitle (XFCE_TITLED_DIALOG (dialog_gtk3),
                                   _("Customize settings stored by Xfconf"));

  gtk_window_set_icon_name (GTK_WINDOW (dialog_gtk3), "preferences-system");
  gtk_window_set_type_hint (GTK_WINDOW (dialog_gtk3), GDK_WINDOW_TYPE_HINT_NORMAL);

  g_signal_connect (dialog_gtk3, "response", G_CALLBACK (close_window), NULL);

  gtk_widget_show_all (dialog_gtk3);
}

static void
show_xfce_titled_dialog_new_with_mixed_buttons (GtkButton *button,
                                                gpointer unused)
{
  GtkWidget *dialog_gtk3;

  dialog_gtk3 = xfce_titled_dialog_new_with_mixed_buttons ("Settings Editor (Gtk3)", NULL,
                                                           GTK_DIALOG_DESTROY_WITH_PARENT,
                                                           "help-browser", "Help", GTK_RESPONSE_HELP,
                                                           "window-close-symbolic", "Close", GTK_RESPONSE_OK,
                                                           "weather-snow", "Snow!", GTK_RESPONSE_APPLY,
                                                           "", "no icon", GTK_RESPONSE_CANCEL,
                                                           NULL);

  xfce_titled_dialog_set_subtitle (XFCE_TITLED_DIALOG (dialog_gtk3),
                                   _("Customize settings stored by Xfconf"));

  gtk_window_set_icon_name (GTK_WINDOW (dialog_gtk3), "preferences-system");
  gtk_window_set_type_hint (GTK_WINDOW (dialog_gtk3), GDK_WINDOW_TYPE_HINT_NORMAL);

  g_signal_connect (dialog_gtk3, "response", G_CALLBACK (close_window), NULL);

  gtk_widget_show_all (dialog_gtk3);

}

static void
show_xfce_gdk_screen_get_active (GtkButton *button,
                                 gpointer unused)
{
  gint       monitor_num;
  GdkScreen *screen;

  screen = xfce_gdk_screen_get_active (&monitor_num);

  xfce_dialog_show_info (NULL, NULL, "monitor num: %d of %d",
                         monitor_num, gdk_screen_get_n_monitors (screen));
}



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 */
  box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
  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);

  /* remove auto-online check from rc file */
  button = gtk_button_new_with_label ("remove auto-online check from rc file");
  gtk_container_add (GTK_CONTAINER (box), button);
  gtk_widget_show (button);
  g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (remove_auto_online), 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);

  /* xfce_titled_dialog_new_with_buttons */
  button = gtk_button_new_with_label ("show xfce_titled_dialog_new_with_buttons");
  gtk_container_add (GTK_CONTAINER (box), button);
  gtk_widget_show (button);
  g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (show_xfce_titled_dialog_new_with_buttons), NULL);

  /* xfce_titled_dialog_new_with_mixed_buttons */
  button = gtk_button_new_with_label ("show xfce_titled_dialog_new_with_mixed_buttons");
  gtk_container_add (GTK_CONTAINER (box), button);
  gtk_widget_show (button);
  g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (show_xfce_titled_dialog_new_with_mixed_buttons), NULL);

  /* xfce_gdk_screen_get_active */
  button = gtk_button_new_with_label ("show xfce_gdk_screen_get_active");
  gtk_container_add (GTK_CONTAINER (box), button);
  gtk_widget_show (button);
  g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (show_xfce_gdk_screen_get_active), 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;
}