~ubuntu-branches/ubuntu/trusty/thunar-volman/trusty-proposed

« back to all changes in this revision

Viewing changes to thunar-volman/tvm-prompt.c

  • Committer: Bazaar Package Importer
  • Author(s): Yves-Alexis Perez
  • Date: 2011-04-20 12:49:32 UTC
  • mfrom: (3.1.3 experimental)
  • Revision ID: james.westby@ubuntu.com-20110420124932-wi70syjpvy3o9sdr
Tags: 0.6.0-3
* Upload to unstable.
* debian/control:
  - remove Simon and Emanuele from uploaders,
  - update standards version to 3.9.2. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: tvm-prompt.c 2340 2007-01-11 23:11:32Z benny $ */
 
1
/* vi:set et ai sw=2 sts=2 ts=2: */
2
2
/*-
3
 
 * Copyright (c) 2007 Benedikt Meurer <benny@xfce.org>.
4
 
 *
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)
8
 
 * any later version.
9
 
 *
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
13
 
 * more details.
14
 
 *
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>
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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.
18
20
 */
19
21
 
20
22
#ifdef HAVE_CONFIG_H
25
27
#include <stdarg.h>
26
28
#endif
27
29
 
 
30
#include <gudev/gudev.h>
 
31
 
 
32
#include <gtk/gtk.h>
 
33
 
 
34
#include <libxfce4ui/libxfce4ui.h>
 
35
 
 
36
#include <thunar-volman/tvm-context.h>
28
37
#include <thunar-volman/tvm-pango-extensions.h>
29
38
#include <thunar-volman/tvm-prompt.h>
30
39
 
31
40
 
32
41
 
33
42
static void
34
 
hal_device_removed (LibHalContext *context,
35
 
                    const gchar   *udi)
 
43
tvm_prompt_uevent (GUdevClient *client,
 
44
                   const gchar *action,
 
45
                   GUdevDevice *device,
 
46
                   GtkWidget   *dialog)
36
47
{
37
 
  const gchar *dialog_udi;
38
 
  GtkWidget   *dialog = libhal_ctx_get_user_data (context);
39
 
 
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;
 
49
 
 
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));
 
54
 
 
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)
 
58
    return;
 
59
 
 
60
  /* determine the device belonging to the dialog */
 
61
  dialog_device = g_object_get_data (G_OBJECT (dialog), "device");
 
62
 
 
63
  /* the device should be set, otherwise it's a bug in the application */
 
64
  g_assert (dialog_device != NULL);
 
65
 
 
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)
43
69
    {
44
70
      /* cancel the dialog */
45
71
      gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
48
74
 
49
75
 
50
76
 
51
 
/**
52
 
 * tvm_prompt:
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.
61
 
 *
62
 
 * Return value: the selected response.
63
 
 **/
64
77
gint
65
 
tvm_prompt (LibHalContext *context,
66
 
            const gchar   *udi,
67
 
            const gchar   *icon,
68
 
            const gchar   *title,
69
 
            const gchar   *primary_text,
70
 
            const gchar   *secondary_text,
71
 
            const gchar   *first_button_text,
 
78
tvm_prompt (TvmContext  *context,
 
79
            const gchar *icon,
 
80
            const gchar *title,
 
81
            const gchar *primary_text,
 
82
            const gchar *secondary_text,
 
83
            const gchar *first_button_text,
72
84
            ...)
73
85
{
74
86
  GtkWidget *dialog;
 
87
  GtkWidget *hbox;
75
88
  GtkWidget *image;
76
89
  GtkWidget *label;
77
 
  GtkWidget *hbox;
78
90
  GtkWidget *vbox;
79
 
  DBusError  derror;
80
91
  va_list    args;
81
92
  gint       response;
82
93
 
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);
85
 
 
86
 
  /* allocate a new dialog */
 
95
  
 
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), 
 
100
                          g_object_unref);
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);
93
104
 
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);
97
108
 
98
 
  /* setup the specified buttons */
99
 
  if (G_LIKELY (first_button_text != NULL))
 
109
  /* create the specified buttons */
 
110
  if (first_button_text != NULL)
100
111
    {
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)
108
119
            break;
109
120
          response = va_arg (args, gint);
110
121
        }
111
122
      va_end (args);
112
123
    }
113
124
 
114
 
  /* setup the hbox */
 
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);
119
130
 
120
 
  /* setup the specified icon */
 
131
  /* apply the specified icon */
121
132
  if (G_LIKELY (icon != NULL))
122
133
    {
 
134
      gtk_window_set_icon_name (GTK_WINDOW (dialog), icon);
 
135
 
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);
151
164
    }
152
165
 
153
 
  /* initialize D-Bus error */
154
 
  dbus_error_init (&derror);
155
 
 
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);
160
167
 
161
168
  /* run the dialog */
162
169
  response = gtk_dialog_run (GTK_DIALOG (dialog));
163
170
 
164
 
  /* cleanup */
165
 
  libhal_ctx_set_device_removed (context, NULL);
166
 
  libhal_ctx_set_user_data (context, NULL);
 
171
  /* clean up */
167
172
  gtk_widget_destroy (dialog);
168
 
  dbus_error_free (&derror);
169
173
 
170
174
  return response;
171
175
}
172
 
 
173