]> Pileus Git - ~andy/gtk/blob - tests/testopenwith.c
open-with: initial implementation of GtkOpenWithDialog
[~andy/gtk] / tests / testopenwith.c
1 /* testopenwith.c
2  * Copyright (C) 2010 Red Hat, Inc.
3  * Authors: Cosimo Cecchi
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #include <config.h>
22
23 #include <stdlib.h>
24 #include <gtk/gtk.h>
25
26 static void
27 dialog_response_cb (GtkDialog *dialog,
28                     gint response_id,
29                     gpointer _user_data)
30 {
31   g_print ("Response: %d\n", response_id);
32
33   gtk_widget_destroy (GTK_WIDGET (dialog));
34   gtk_main_quit ();
35 }
36
37 int
38 main (int argc,
39       char **argv)
40 {
41   GOptionContext *context;
42   GError *error = NULL;
43   gchar **files = NULL;
44   GtkWidget *dialog;
45   GFile *file;
46   GOptionEntry entries[] = {
47     { G_OPTION_REMAINING, 0, G_OPTION_FLAG_FILENAME,
48       G_OPTION_ARG_FILENAME_ARRAY, &files, NULL, NULL},
49     { NULL }
50   };
51
52   g_type_init ();
53
54   context = g_option_context_new ("- Test for GtkOpenWithDialog");
55   g_option_context_add_main_entries (context, entries, NULL);
56   g_option_context_add_group (context, gtk_get_option_group (TRUE));
57
58   g_option_context_parse (context, &argc, &argv, &error);
59
60   if (error != NULL)
61     {
62       g_critical ("Error: %s\n", error->message);
63       g_error_free (error);
64       g_option_context_free (context);
65
66       return EXIT_FAILURE;
67     }
68
69   g_option_context_free (context);
70
71   if (files == NULL || files[0] == NULL)
72     {
73       g_critical ("You need to specify a file path.");
74       return EXIT_FAILURE;
75     }
76
77   file = g_file_new_for_commandline_arg (files[0]);
78   dialog = gtk_open_with_dialog_new (NULL, 0, GTK_OPEN_WITH_DIALOG_MODE_SELECT_DEFAULT,
79                                      file);
80
81   gtk_widget_show (dialog);
82   g_signal_connect (dialog, "response",
83                     G_CALLBACK (dialog_response_cb), NULL);
84
85   gtk_main ();
86
87   return EXIT_SUCCESS;
88 }