~noskcaj/ubuntu/vivid/thunar/1.6.4

« back to all changes in this revision

Viewing changes to thunar/xfce-titled-dialog.c

  • Committer: Bazaar Package Importer
  • Author(s): Lionel Le Folgoc
  • Date: 2010-12-04 16:46:20 UTC
  • mto: (2.1.3 experimental) (1.3.1)
  • mto: This revision was merged to the branch mainline in revision 69.
  • Revision ID: james.westby@ubuntu.com-20101204164620-h7p4t2e9z6hfhz6l
Tags: upstream-1.1.4
ImportĀ upstreamĀ versionĀ 1.1.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id$ */
2
 
/*-
3
 
 * Copyright (c) 2006 Benedikt Meurer <benny@xfce.org>.
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
 
#ifdef HAVE_CONFIG_H
22
 
#include <config.h>
23
 
#endif
24
 
 
25
 
#ifdef HAVE_STDARG_H
26
 
#include <stdarg.h>
27
 
#endif
28
 
 
29
 
#include <gdk/gdkkeysyms.h>
30
 
 
31
 
#include "xfce-heading.h"
32
 
#include "xfce-titled-dialog.h"
33
 
 
34
 
 
35
 
 
36
 
#define XFCE_TITLED_DIALOG_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), XFCE_TYPE_TITLED_DIALOG, XfceTitledDialogPrivate))
37
 
 
38
 
 
39
 
 
40
 
/* Property identifiers */
41
 
enum
42
 
{
43
 
  PROP_0,
44
 
  PROP_SUBTITLE,
45
 
};
46
 
 
47
 
 
48
 
 
49
 
static void xfce_titled_dialog_class_init     (XfceTitledDialogClass  *klass);
50
 
static void xfce_titled_dialog_init           (XfceTitledDialog       *titled_dialog);
51
 
static void xfce_titled_dialog_finalize       (GObject                *object);
52
 
static void xfce_titled_dialog_get_property   (GObject                *object,
53
 
                                               guint                   prop_id,
54
 
                                               GValue                 *value,
55
 
                                               GParamSpec             *pspec);
56
 
static void xfce_titled_dialog_set_property   (GObject                *object,
57
 
                                               guint                   prop_id,
58
 
                                               const GValue           *value,
59
 
                                               GParamSpec             *pspec);
60
 
static void xfce_titled_dialog_close          (GtkDialog              *dialog);
61
 
static void xfce_titled_dialog_update_heading (XfceTitledDialog       *titled_dialog);
62
 
 
63
 
 
64
 
 
65
 
struct _XfceTitledDialogPrivate
66
 
{
67
 
  GtkWidget *heading;
68
 
  gchar     *subtitle;
69
 
};
70
 
 
71
 
 
72
 
 
73
 
G_DEFINE_TYPE (XfceTitledDialog, xfce_titled_dialog, GTK_TYPE_DIALOG);
74
 
 
75
 
 
76
 
 
77
 
static void
78
 
xfce_titled_dialog_class_init (XfceTitledDialogClass *klass)
79
 
{
80
 
  GtkDialogClass *gtkdialog_class;
81
 
  GtkBindingSet  *binding_set;
82
 
  GObjectClass   *gobject_class;
83
 
 
84
 
  /* add our private data to the class */
85
 
  g_type_class_add_private (klass, sizeof (XfceTitledDialogPrivate));
86
 
 
87
 
  gobject_class = G_OBJECT_CLASS (klass);
88
 
  gobject_class->finalize = xfce_titled_dialog_finalize;
89
 
  gobject_class->get_property = xfce_titled_dialog_get_property;
90
 
  gobject_class->set_property = xfce_titled_dialog_set_property;
91
 
 
92
 
  gtkdialog_class = GTK_DIALOG_CLASS (klass);
93
 
  gtkdialog_class->close = xfce_titled_dialog_close;
94
 
 
95
 
  /**
96
 
   * XfceTitledDialog:subtitle:
97
 
   *
98
 
   * The subtitle displayed below the main dialog title.
99
 
   *
100
 
   * Since: 4.4.0
101
 
   **/
102
 
  g_object_class_install_property (gobject_class,
103
 
                                   PROP_SUBTITLE,
104
 
                                   g_param_spec_string ("subtitle",
105
 
                                                        "subtitle",
106
 
                                                        "subtitle",
107
 
                                                        NULL,
108
 
                                                        G_PARAM_READWRITE));
109
 
 
110
 
  /* connect additional key bindings to the GtkDialog::close action signal */
111
 
  binding_set = gtk_binding_set_by_class (klass);
112
 
  gtk_binding_entry_add_signal (binding_set, GDK_w, GDK_CONTROL_MASK, "close", 0);
113
 
  gtk_binding_entry_add_signal (binding_set, GDK_W, GDK_CONTROL_MASK, "close", 0);
114
 
}
115
 
 
116
 
 
117
 
 
118
 
static void
119
 
xfce_titled_dialog_init (XfceTitledDialog *titled_dialog)
120
 
{
121
 
  GtkWidget *line;
122
 
  GtkWidget *vbox;
123
 
 
124
 
  /* connect the private data */
125
 
  titled_dialog->priv = XFCE_TITLED_DIALOG_GET_PRIVATE (titled_dialog);
126
 
 
127
 
  /* remove the main dialog box from the window */
128
 
  g_object_ref (G_OBJECT (GTK_DIALOG (titled_dialog)->vbox));
129
 
  gtk_container_remove (GTK_CONTAINER (titled_dialog), GTK_DIALOG (titled_dialog)->vbox);
130
 
 
131
 
  /* add a new vbox w/o border to the main window */
132
 
  vbox = gtk_vbox_new (FALSE, 0);
133
 
  gtk_container_add (GTK_CONTAINER (titled_dialog), vbox);
134
 
  gtk_widget_show (vbox);
135
 
 
136
 
  /* add the heading to the window */
137
 
  titled_dialog->priv->heading = xfce_heading_new ();
138
 
  gtk_box_pack_start (GTK_BOX (vbox), titled_dialog->priv->heading, FALSE, FALSE, 0);
139
 
  gtk_widget_show (titled_dialog->priv->heading);
140
 
 
141
 
  /* add the separator between header and content */
142
 
  line = gtk_hseparator_new ();
143
 
  gtk_box_pack_start (GTK_BOX (vbox), line, FALSE, FALSE, 0);
144
 
  gtk_widget_show (line);
145
 
 
146
 
  /* add the main dialog box to the new vbox */
147
 
  gtk_box_pack_start (GTK_BOX (vbox), GTK_DIALOG (titled_dialog)->vbox, TRUE, TRUE, 0);
148
 
  g_object_unref (G_OBJECT (GTK_DIALOG (titled_dialog)->vbox));
149
 
 
150
 
  /* make sure to update the heading whenever one of the relevant window properties changes */
151
 
  g_signal_connect (G_OBJECT (titled_dialog), "notify::icon", G_CALLBACK (xfce_titled_dialog_update_heading), NULL);
152
 
  g_signal_connect (G_OBJECT (titled_dialog), "notify::icon-name", G_CALLBACK (xfce_titled_dialog_update_heading), NULL);
153
 
  g_signal_connect (G_OBJECT (titled_dialog), "notify::title", G_CALLBACK (xfce_titled_dialog_update_heading), NULL);
154
 
 
155
 
  /* initially update the heading properties */
156
 
  xfce_titled_dialog_update_heading (titled_dialog);
157
 
}
158
 
 
159
 
 
160
 
 
161
 
 
162
 
static void
163
 
xfce_titled_dialog_finalize (GObject *object)
164
 
{
165
 
  XfceTitledDialog *titled_dialog = XFCE_TITLED_DIALOG (object);
166
 
 
167
 
  /* release the subtitle */
168
 
  g_free (titled_dialog->priv->subtitle);
169
 
 
170
 
  (*G_OBJECT_CLASS (xfce_titled_dialog_parent_class)->finalize) (object);
171
 
}
172
 
 
173
 
 
174
 
 
175
 
static void
176
 
xfce_titled_dialog_get_property (GObject    *object,
177
 
                                 guint       prop_id,
178
 
                                 GValue     *value,
179
 
                                 GParamSpec *pspec)
180
 
{
181
 
  XfceTitledDialog *titled_dialog = XFCE_TITLED_DIALOG (object);
182
 
 
183
 
  switch (prop_id)
184
 
    {
185
 
    case PROP_SUBTITLE:
186
 
      g_value_set_string (value, xfce_titled_dialog_get_subtitle (titled_dialog));
187
 
      break;
188
 
 
189
 
    default:
190
 
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
191
 
      break;
192
 
    }
193
 
}
194
 
 
195
 
 
196
 
 
197
 
static void
198
 
xfce_titled_dialog_set_property (GObject      *object,
199
 
                                 guint         prop_id,
200
 
                                 const GValue *value,
201
 
                                 GParamSpec   *pspec)
202
 
{
203
 
  XfceTitledDialog *titled_dialog = XFCE_TITLED_DIALOG (object);
204
 
 
205
 
  switch (prop_id)
206
 
    {
207
 
    case PROP_SUBTITLE:
208
 
      xfce_titled_dialog_set_subtitle (titled_dialog, g_value_get_string (value));
209
 
      break;
210
 
 
211
 
    default:
212
 
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
213
 
      break;
214
 
    }
215
 
}
216
 
 
217
 
 
218
 
 
219
 
static void
220
 
xfce_titled_dialog_close (GtkDialog *dialog)
221
 
{
222
 
  GdkEvent *event;
223
 
 
224
 
  /* verify that the dialog is realized */
225
 
  if (G_LIKELY (GTK_WIDGET_REALIZED (dialog)))
226
 
    {
227
 
      /* send a delete event to the dialog */
228
 
      event = gdk_event_new (GDK_DELETE);
229
 
      event->any.window = g_object_ref (GTK_WIDGET (dialog)->window);
230
 
      event->any.send_event = TRUE;
231
 
      gtk_main_do_event (event);
232
 
      gdk_event_free (event);
233
 
    }
234
 
}
235
 
 
236
 
 
237
 
 
238
 
static void
239
 
xfce_titled_dialog_update_heading (XfceTitledDialog *titled_dialog)
240
 
{
241
 
  /* update the heading properties using the window property values */
242
 
  xfce_heading_set_icon (XFCE_HEADING (titled_dialog->priv->heading), gtk_window_get_icon (GTK_WINDOW (titled_dialog)));
243
 
  xfce_heading_set_icon_name (XFCE_HEADING (titled_dialog->priv->heading), gtk_window_get_icon_name (GTK_WINDOW (titled_dialog)));
244
 
  xfce_heading_set_title (XFCE_HEADING (titled_dialog->priv->heading), gtk_window_get_title (GTK_WINDOW (titled_dialog)));
245
 
}
246
 
 
247
 
 
248
 
 
249
 
/**
250
 
 * xfce_titled_dialog_new:
251
 
 *
252
 
 * Allocates a new #XfceTitledDialog instance.
253
 
 *
254
 
 * Return value: the newly allocated #XfceTitledDialog.
255
 
 *
256
 
 * Since: 4.4.0
257
 
 **/
258
 
GtkWidget*
259
 
xfce_titled_dialog_new (void)
260
 
{
261
 
  return g_object_new (XFCE_TYPE_TITLED_DIALOG, NULL);
262
 
}
263
 
 
264
 
 
265
 
 
266
 
/**
267
 
 * xfce_titled_dialog_new_with_buttons:
268
 
 * @title             : title of the dialog, or %NULL.
269
 
 * @parent            : transient parent window of the dialog, or %NULL.
270
 
 * @flags             : from #GtkDialogFlags.
271
 
 * @first_button_text : stock ID or text to go in first, or %NULL.
272
 
 * @...               : response ID for the first button, then additional buttons, ending with %NULL.
273
 
 *
274
 
 * See the documentation of gtk_dialog_new_with_buttons() for details about the
275
 
 * parameters and the returned dialog.
276
 
 *
277
 
 * Return value: the newly allocated #XfceTitledDialog.
278
 
 *
279
 
 * Since: 4.4.0
280
 
 **/
281
 
GtkWidget*
282
 
xfce_titled_dialog_new_with_buttons (const gchar   *title,
283
 
                                     GtkWindow     *parent,
284
 
                                     GtkDialogFlags flags,
285
 
                                     const gchar   *first_button_text,
286
 
                                     ...)
287
 
{
288
 
  const gchar *button_text;
289
 
  GtkWidget   *dialog;
290
 
  va_list      args;
291
 
  gint         response_id;
292
 
 
293
 
  /* allocate the dialog */
294
 
  dialog = g_object_new (XFCE_TYPE_TITLED_DIALOG,
295
 
                         "destroy-with-parent", ((flags & GTK_DIALOG_DESTROY_WITH_PARENT) != 0),
296
 
                         "has-separator", ((flags & GTK_DIALOG_NO_SEPARATOR) == 0),
297
 
                         "modal", ((flags & GTK_DIALOG_MODAL) != 0),
298
 
                         "title", title,
299
 
                         NULL);
300
 
 
301
 
  /* set the transient parent (if any) */
302
 
  if (G_LIKELY (parent != NULL))
303
 
    gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
304
 
 
305
 
  /* add all additional buttons */
306
 
  va_start (args, first_button_text);
307
 
  for (button_text = first_button_text; button_text != NULL; )
308
 
    {
309
 
      response_id = va_arg (args, gint);
310
 
      gtk_dialog_add_button (GTK_DIALOG (dialog), button_text, response_id);
311
 
      button_text = va_arg (args, const gchar *);
312
 
    }
313
 
  va_end (args);
314
 
 
315
 
  return dialog;
316
 
}
317
 
 
318
 
 
319
 
 
320
 
/**
321
 
 * xfce_titled_dialog_get_subtitle:
322
 
 * @titled_dialog : a #XfceTitledDialog.
323
 
 *
324
 
 * Returns the subtitle of the @titled_dialog, or %NULL
325
 
 * if no subtitle is displayed in the @titled_dialog.
326
 
 *
327
 
 * Return value: the subtitle of @titled_dialog, or %NULL.
328
 
 *
329
 
 * Since: 4.4.0
330
 
 **/
331
 
G_CONST_RETURN gchar*
332
 
xfce_titled_dialog_get_subtitle (XfceTitledDialog *titled_dialog)
333
 
{
334
 
  g_return_val_if_fail (XFCE_IS_TITLED_DIALOG (titled_dialog), NULL);
335
 
  return titled_dialog->priv->subtitle;
336
 
}
337
 
 
338
 
 
339
 
 
340
 
/**
341
 
 * xfce_titled_dialog_set_subtitle:
342
 
 * @titled_dialog : a #XfceTitledDialog.
343
 
 * @subtitle      : the new subtitle for the @titled_dialog, or %NULL.
344
 
 *
345
 
 * Sets the subtitle displayed by @titled_dialog to @subtitle; if
346
 
 * @subtitle is %NULL no subtitle will be displayed by the @titled_dialog.
347
 
 *
348
 
 * Since: 4.4.0
349
 
 **/
350
 
void
351
 
xfce_titled_dialog_set_subtitle (XfceTitledDialog *titled_dialog,
352
 
                                 const gchar      *subtitle)
353
 
{
354
 
  g_return_if_fail (XFCE_IS_TITLED_DIALOG (titled_dialog));
355
 
  g_return_if_fail (subtitle == NULL || g_utf8_validate (subtitle, -1, NULL));
356
 
 
357
 
  /* release the previous subtitle */
358
 
  g_free (titled_dialog->priv->subtitle);
359
 
 
360
 
  /* activate the new subtitle */
361
 
  titled_dialog->priv->subtitle = g_strdup (subtitle);
362
 
 
363
 
  /* update the subtitle for the heading */
364
 
  xfce_heading_set_subtitle (XFCE_HEADING (titled_dialog->priv->heading), subtitle);
365
 
 
366
 
  /* notify listeners */
367
 
  g_object_notify (G_OBJECT (titled_dialog), "subtitle");
368
 
}
369
 
 
370