1
/* $Id: tvm-prompt.c 2340 2007-01-11 23:11:32Z benny $ */
1
/* vi:set et ai sw=2 sts=2 ts=2: */
3
* Copyright (c) 2007 Benedikt Meurer <benny@xfce.org>.
5
* This program is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License as published by the Free
7
* Software Foundation; either version 2 of the License, or (at your option)
10
* This program is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15
* You should have received a copy of the GNU General Public License along with
16
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17
* Place, Suite 330, Boston, MA 02111-1307 USA
3
* Copyright (c) 2007 Benedikt Meurer <benny@xfce.org>
4
* Copyright (c) 2010 Jannis Pohlmann <jannis@xfce.org>
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License as
8
* published by the Free Software Foundation; either version 2 of
9
* the License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public
17
* License along with this program; if not, write to the Free
18
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
* Boston, MA 02110-1301, USA.
20
22
#ifdef HAVE_CONFIG_H
25
27
#include <stdarg.h>
30
#include <gudev/gudev.h>
34
#include <libxfce4ui/libxfce4ui.h>
36
#include <thunar-volman/tvm-context.h>
28
37
#include <thunar-volman/tvm-pango-extensions.h>
29
38
#include <thunar-volman/tvm-prompt.h>
34
hal_device_removed (LibHalContext *context,
43
tvm_prompt_uevent (GUdevClient *client,
37
const gchar *dialog_udi;
38
GtkWidget *dialog = libhal_ctx_get_user_data (context);
40
/* check if the active UDI of the dialog was removed */
41
dialog_udi = g_object_get_data (G_OBJECT (dialog), "udi");
42
if (exo_str_is_equal (dialog_udi, udi))
48
GUdevDevice *dialog_device;
50
g_return_if_fail (G_UDEV_IS_CLIENT (client));
51
g_return_if_fail (action != NULL && *action != '\0');
52
g_return_if_fail (G_UDEV_IS_DEVICE (device));
53
g_return_if_fail (GTK_IS_DIALOG (dialog));
55
/* ignore "move" and "add" actions, "change" might only be correct
56
* for CDs/DVDs though */
57
if (g_strcmp0 (action, "remove") != 0 && g_strcmp0 (action, "change") != 0)
60
/* determine the device belonging to the dialog */
61
dialog_device = g_object_get_data (G_OBJECT (dialog), "device");
63
/* the device should be set, otherwise it's a bug in the application */
64
g_assert (dialog_device != NULL);
66
/* check if the removed/changed device belongs to the dialog */
67
if (g_strcmp0 (g_udev_device_get_sysfs_path (device),
68
g_udev_device_get_sysfs_path (dialog_device)) == 0)
44
70
/* cancel the dialog */
45
71
gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
53
* @context : a #LibHalContext.
54
* @udi : the UDI of the device being added, which is watched for removal.
55
* @icon : the icon or %NULL.
56
* @title : the prompt title.
57
* @primary_text : the primary prompt text.
58
* @secondary_text : the secondary prompt text.
59
* @first_button_text : the first button text.
60
* @... : %NULL-terminated list of button text, response id pairs.
62
* Return value: the selected response.
65
tvm_prompt (LibHalContext *context,
69
const gchar *primary_text,
70
const gchar *secondary_text,
71
const gchar *first_button_text,
78
tvm_prompt (TvmContext *context,
81
const gchar *primary_text,
82
const gchar *secondary_text,
83
const gchar *first_button_text,
83
g_return_val_if_fail (exo_hal_udi_validate (udi, -1, NULL), GTK_RESPONSE_CANCEL);
84
94
g_return_val_if_fail (context != NULL, GTK_RESPONSE_CANCEL);
86
/* allocate a new dialog */
96
/* create a new dialog */
87
97
dialog = gtk_dialog_new ();
88
98
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
89
gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
90
g_object_set_data_full (G_OBJECT (dialog), "udi", g_strdup (udi), g_free);
99
g_object_set_data_full (G_OBJECT (dialog), "device", g_object_ref (context->device),
91
101
gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), 6);
92
102
gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area), 12);
103
gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
94
/* setup the specified title */
95
if (G_LIKELY (title != NULL))
105
/* apply the specified title */
106
if (title != NULL && *title != '\0')
96
107
gtk_window_set_title (GTK_WINDOW (dialog), title);
98
/* setup the specified buttons */
99
if (G_LIKELY (first_button_text != NULL))
109
/* create the specified buttons */
110
if (first_button_text != NULL)
101
112
va_start (args, first_button_text);
102
113
for (response = va_arg (args, gint); first_button_text != NULL; )
104
115
/* insert the button */
105
116
gtk_dialog_add_button (GTK_DIALOG (dialog), first_button_text, response);
106
117
first_button_text = va_arg (args, const gchar *);
107
if (G_UNLIKELY (first_button_text == NULL))
118
if (first_button_text == NULL)
109
120
response = va_arg (args, gint);
125
/* create the hbox */
115
126
hbox = gtk_hbox_new (FALSE, 12);
116
127
gtk_container_set_border_width (GTK_CONTAINER (hbox), 12);
117
128
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox, TRUE, TRUE, 0);
118
129
gtk_widget_show (hbox);
120
/* setup the specified icon */
131
/* apply the specified icon */
121
132
if (G_LIKELY (icon != NULL))
134
gtk_window_set_icon_name (GTK_WINDOW (dialog), icon);
123
136
/* setup an image for the icon */
124
137
image = gtk_image_new_from_icon_name (icon, GTK_ICON_SIZE_DIALOG);
125
138
gtk_misc_set_alignment (GTK_MISC (image), 0.0f, 0.0f);
150
163
gtk_widget_show (label);
153
/* initialize D-Bus error */
154
dbus_error_init (&derror);
156
/* setup HAL to watch the UDI for removal */
157
libhal_ctx_set_user_data (context, dialog);
158
libhal_ctx_set_device_removed (context, hal_device_removed);
159
libhal_device_property_watch_all (context, &derror);
166
g_signal_connect (context->client, "uevent", G_CALLBACK (tvm_prompt_uevent), dialog);
161
168
/* run the dialog */
162
169
response = gtk_dialog_run (GTK_DIALOG (dialog));
165
libhal_ctx_set_device_removed (context, NULL);
166
libhal_ctx_set_user_data (context, NULL);
167
172
gtk_widget_destroy (dialog);
168
dbus_error_free (&derror);