~kroq-gar78/ubuntu/precise/gnome-control-center/fix-885947

« back to all changes in this revision

Viewing changes to panels/media/cc-media-panel.c

  • Committer: Bazaar Package Importer
  • Author(s): Rodrigo Moya
  • Date: 2011-05-17 10:47:27 UTC
  • mfrom: (0.1.11 experimental) (1.1.45 upstream)
  • Revision ID: james.westby@ubuntu.com-20110517104727-lqel6m8vhfw5jby1
Tags: 1:3.0.1.1-1ubuntu1
* Rebase on Debian, remaining Ubuntu changes:
* debian/control:
  - Build-Depend on hardening-wrapper, dpkg-dev and dh-autoreconf
  - Add dependency on ubuntu-system-service
  - Remove dependency on gnome-icon-theme-symbolic
  - Move dependency on apg, gnome-icon-theme-symbolic and accountsservice to
    be a Recommends: until we get them in main
* debian/rules:
  - Use autoreconf
  - Add binary-post-install rule for gnome-control-center-data
  - Run dh-autoreconf
* debian/gnome-control-center.dirs:
* debian/gnome-control-center.links:
  - Add a link to the control center shell for indicators
* debian/patches/00_disable-nm.patch:
  - Temporary patch to disable building with NetworkManager until we get
    the new one in the archive
* debian/patches/01_git_remove_gettext_calls.patch:
  - Remove calls to AM_GNU_GETTEXT, IT_PROG_INTLTOOL should be enough
* debian/patches/01_git_kill_warning.patch:
  - Kill warning
* debian/patches/50_ubuntu_systemwide_prefs.patch:
  - Ubuntu specific proxy preferences
* debian/patches/51_ubuntu_system_keyboard.patch:
  - Implement the global keyboard spec at https://wiki.ubuntu.com/DefaultKeyboardSettings

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
 
2
 *
 
3
 * Copyright (C) 2008-2010 Red Hat, Inc.
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program 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
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
18
 *
 
19
 * Author: David Zeuthen <davidz@redhat.com>
 
20
 *         Cosimo Cecchi <cosimoc@gnome.org>
 
21
 *
 
22
 */
 
23
 
 
24
#include <config.h>
 
25
 
 
26
#include "cc-media-panel.h"
 
27
 
 
28
#include <string.h>
 
29
#include <glib/gi18n.h>
 
30
 
 
31
G_DEFINE_DYNAMIC_TYPE (CcMediaPanel, cc_media_panel, CC_TYPE_PANEL)
 
32
 
 
33
#define MEDIA_PANEL_PRIVATE(o) \
 
34
  (G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_MEDIA_PANEL, CcMediaPanelPrivate))
 
35
 
 
36
/* Autorun options */
 
37
#define PREF_MEDIA_AUTORUN_NEVER                "autorun-never"
 
38
#define PREF_MEDIA_AUTORUN_X_CONTENT_START_APP  "autorun-x-content-start-app"
 
39
#define PREF_MEDIA_AUTORUN_X_CONTENT_IGNORE     "autorun-x-content-ignore"
 
40
#define PREF_MEDIA_AUTORUN_X_CONTENT_OPEN_FOLDER "autorun-x-content-open-folder"
 
41
 
 
42
#define CUSTOM_ITEM_ASK "cc-item-ask"
 
43
#define CUSTOM_ITEM_DO_NOTHING "cc-item-do-nothing"
 
44
#define CUSTOM_ITEM_OPEN_FOLDER "cc-item-open-folder"
 
45
 
 
46
struct _CcMediaPanelPrivate {
 
47
  GtkBuilder *builder;
 
48
  GSettings *preferences;
 
49
 
 
50
  GtkWidget *other_application_combo;
 
51
};
 
52
 
 
53
static void
 
54
cc_media_panel_dispose (GObject *object)
 
55
{
 
56
  CcMediaPanel *self = CC_MEDIA_PANEL (object);
 
57
 
 
58
  if (self->priv->builder != NULL) {
 
59
    g_object_unref (self->priv->builder);
 
60
    self->priv->builder = NULL;
 
61
  }
 
62
 
 
63
  if (self->priv->preferences != NULL) {
 
64
    g_object_unref (self->priv->preferences);
 
65
    self->priv->preferences = NULL;
 
66
  }
 
67
 
 
68
  G_OBJECT_CLASS (cc_media_panel_parent_class)->dispose (object);
 
69
}
 
70
 
 
71
static void
 
72
cc_media_panel_finalize (GObject *object)
 
73
{
 
74
  G_OBJECT_CLASS (cc_media_panel_parent_class)->finalize (object);
 
75
}
 
76
 
 
77
static void
 
78
cc_media_panel_class_init (CcMediaPanelClass *klass)
 
79
{
 
80
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
81
 
 
82
  g_type_class_add_private (klass, sizeof (CcMediaPanelPrivate));
 
83
 
 
84
  object_class->dispose = cc_media_panel_dispose;
 
85
  object_class->finalize = cc_media_panel_finalize;
 
86
}
 
87
 
 
88
static void
 
89
cc_media_panel_class_finalize (CcMediaPanelClass *klass)
 
90
{
 
91
}
 
92
 
 
93
static char **
 
94
remove_elem_from_str_array (char **v,
 
95
                            const char *s)
 
96
{
 
97
  GPtrArray *array;
 
98
  guint idx;
 
99
 
 
100
  array = g_ptr_array_new ();
 
101
 
 
102
  for (idx = 0; v[idx] != NULL; idx++) {
 
103
    if (g_strcmp0 (v[idx], s) == 0) {
 
104
      continue;
 
105
    }
 
106
 
 
107
    g_ptr_array_add (array, v[idx]);
 
108
  }
 
109
 
 
110
  g_ptr_array_add (array, NULL);
 
111
 
 
112
  g_free (v);
 
113
 
 
114
  return (char **) g_ptr_array_free (array, FALSE);
 
115
}
 
116
 
 
117
static char **
 
118
add_elem_to_str_array (char **v,
 
119
                       const char *s)
 
120
{
 
121
  GPtrArray *array;
 
122
  guint idx;
 
123
 
 
124
  array = g_ptr_array_new ();
 
125
 
 
126
  for (idx = 0; v[idx] != NULL; idx++) {
 
127
    g_ptr_array_add (array, v[idx]);
 
128
  }
 
129
 
 
130
  g_ptr_array_add (array, g_strdup (s));
 
131
  g_ptr_array_add (array, NULL);
 
132
 
 
133
  g_free (v);
 
134
 
 
135
  return (char **) g_ptr_array_free (array, FALSE);
 
136
}
 
137
 
 
138
static int
 
139
media_panel_g_strv_find (char **strv,
 
140
                         const char *find_me)
 
141
{
 
142
  guint index;
 
143
 
 
144
  g_return_val_if_fail (find_me != NULL, -1);
 
145
 
 
146
  for (index = 0; strv[index] != NULL; ++index) {
 
147
    if (g_strcmp0 (strv[index], find_me) == 0) {
 
148
      return index;
 
149
    }
 
150
  }
 
151
 
 
152
  return -1;
 
153
}
 
154
 
 
155
static void
 
156
autorun_get_preferences (CcMediaPanel *self,
 
157
                         const char *x_content_type,
 
158
                         gboolean *pref_start_app,
 
159
                         gboolean *pref_ignore,
 
160
                         gboolean *pref_open_folder)
 
161
{
 
162
  char **x_content_start_app;
 
163
  char **x_content_ignore;
 
164
  char **x_content_open_folder;
 
165
 
 
166
  g_return_if_fail (pref_start_app != NULL);
 
167
  g_return_if_fail (pref_ignore != NULL);
 
168
  g_return_if_fail (pref_open_folder != NULL);
 
169
 
 
170
  *pref_start_app = FALSE;
 
171
  *pref_ignore = FALSE;
 
172
  *pref_open_folder = FALSE;
 
173
  x_content_start_app = g_settings_get_strv (self->priv->preferences,
 
174
                                             PREF_MEDIA_AUTORUN_X_CONTENT_START_APP);
 
175
  x_content_ignore = g_settings_get_strv (self->priv->preferences,
 
176
                                          PREF_MEDIA_AUTORUN_X_CONTENT_IGNORE);
 
177
  x_content_open_folder = g_settings_get_strv (self->priv->preferences,
 
178
                                               PREF_MEDIA_AUTORUN_X_CONTENT_OPEN_FOLDER);
 
179
  if (x_content_start_app != NULL) {
 
180
    *pref_start_app = media_panel_g_strv_find (x_content_start_app, x_content_type) != -1;
 
181
  }
 
182
  if (x_content_ignore != NULL) {
 
183
    *pref_ignore = media_panel_g_strv_find (x_content_ignore, x_content_type) != -1;
 
184
  }
 
185
  if (x_content_open_folder != NULL) {
 
186
    *pref_open_folder = media_panel_g_strv_find (x_content_open_folder, x_content_type) != -1;
 
187
  }
 
188
  g_strfreev (x_content_ignore);
 
189
  g_strfreev (x_content_start_app);
 
190
  g_strfreev (x_content_open_folder);
 
191
}
 
192
 
 
193
static void
 
194
autorun_set_preferences (CcMediaPanel *self,
 
195
                         const char *x_content_type,
 
196
                         gboolean pref_start_app,
 
197
                         gboolean pref_ignore,
 
198
                         gboolean pref_open_folder)
 
199
{
 
200
  char **x_content_start_app;
 
201
  char **x_content_ignore;
 
202
  char **x_content_open_folder;
 
203
 
 
204
  g_assert (x_content_type != NULL);
 
205
 
 
206
  x_content_start_app = g_settings_get_strv (self->priv->preferences,
 
207
                                             PREF_MEDIA_AUTORUN_X_CONTENT_START_APP);
 
208
  x_content_ignore = g_settings_get_strv (self->priv->preferences,
 
209
                                          PREF_MEDIA_AUTORUN_X_CONTENT_IGNORE);
 
210
  x_content_open_folder = g_settings_get_strv (self->priv->preferences,
 
211
                                               PREF_MEDIA_AUTORUN_X_CONTENT_OPEN_FOLDER);
 
212
 
 
213
  x_content_start_app = remove_elem_from_str_array (x_content_start_app, x_content_type);
 
214
  if (pref_start_app) {
 
215
    x_content_start_app = add_elem_to_str_array (x_content_start_app, x_content_type);
 
216
  }
 
217
  g_settings_set_strv (self->priv->preferences,
 
218
                       PREF_MEDIA_AUTORUN_X_CONTENT_START_APP, (const gchar * const*) x_content_start_app);
 
219
 
 
220
  x_content_ignore = remove_elem_from_str_array (x_content_ignore, x_content_type);
 
221
  if (pref_ignore) {
 
222
    x_content_ignore = add_elem_to_str_array (x_content_ignore, x_content_type);
 
223
  }
 
224
  g_settings_set_strv (self->priv->preferences,
 
225
                       PREF_MEDIA_AUTORUN_X_CONTENT_IGNORE, (const gchar * const*) x_content_ignore);
 
226
 
 
227
  x_content_open_folder = remove_elem_from_str_array (x_content_open_folder, x_content_type);
 
228
  if (pref_open_folder) {
 
229
    x_content_open_folder = add_elem_to_str_array (x_content_open_folder, x_content_type);
 
230
  }
 
231
  g_settings_set_strv (self->priv->preferences,
 
232
                       PREF_MEDIA_AUTORUN_X_CONTENT_OPEN_FOLDER, (const gchar * const*) x_content_open_folder);
 
233
 
 
234
  g_strfreev (x_content_open_folder);
 
235
  g_strfreev (x_content_ignore);
 
236
  g_strfreev (x_content_start_app);
 
237
 
 
238
}
 
239
 
 
240
static void
 
241
custom_item_activated_cb (GtkAppChooserButton *button,
 
242
                          const gchar *item,
 
243
                          gpointer user_data)
 
244
{
 
245
  CcMediaPanel *self = user_data;
 
246
  gchar *content_type;
 
247
 
 
248
  content_type = gtk_app_chooser_get_content_type (GTK_APP_CHOOSER (button));
 
249
 
 
250
  if (g_strcmp0 (item, CUSTOM_ITEM_ASK) == 0) {
 
251
    autorun_set_preferences (self, content_type,
 
252
                             FALSE, FALSE, FALSE);
 
253
  } else if (g_strcmp0 (item, CUSTOM_ITEM_OPEN_FOLDER) == 0) {
 
254
    autorun_set_preferences (self, content_type,
 
255
                             FALSE, FALSE, TRUE);
 
256
  } else if (g_strcmp0 (item, CUSTOM_ITEM_DO_NOTHING) == 0) {
 
257
    autorun_set_preferences (self, content_type,
 
258
                             FALSE, TRUE, FALSE);
 
259
  }
 
260
 
 
261
  g_free (content_type);
 
262
}
 
263
 
 
264
static void
 
265
combo_box_changed_cb (GtkComboBox *combo_box,
 
266
                      gpointer user_data)
 
267
{
 
268
  CcMediaPanel *self = user_data;
 
269
  GAppInfo *info;
 
270
  gchar *content_type;
 
271
 
 
272
  info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (combo_box));
 
273
 
 
274
  if (info == NULL)
 
275
    return;
 
276
 
 
277
  content_type = gtk_app_chooser_get_content_type (GTK_APP_CHOOSER (combo_box));
 
278
  autorun_set_preferences (self, content_type,
 
279
                           TRUE, FALSE, FALSE);
 
280
  g_app_info_set_as_default_for_type (info, content_type, NULL);
 
281
 
 
282
  g_object_unref (info);
 
283
  g_free (content_type);
 
284
}
 
285
 
 
286
static void
 
287
prepare_combo_box (CcMediaPanel *self,
 
288
                   GtkWidget *combo_box,
 
289
                   const gchar *heading)
 
290
{
 
291
  GtkAppChooserButton *app_chooser = GTK_APP_CHOOSER_BUTTON (combo_box);
 
292
  gboolean pref_ask;
 
293
  gboolean pref_start_app;
 
294
  gboolean pref_ignore;
 
295
  gboolean pref_open_folder;
 
296
  GAppInfo *info;
 
297
  gchar *content_type;
 
298
 
 
299
  content_type = gtk_app_chooser_get_content_type (GTK_APP_CHOOSER (app_chooser));
 
300
 
 
301
  /* fetch preferences for this content type */
 
302
  autorun_get_preferences (self, content_type,
 
303
                           &pref_start_app, &pref_ignore, &pref_open_folder);
 
304
  pref_ask = !pref_start_app && !pref_ignore && !pref_open_folder;
 
305
 
 
306
  info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (combo_box));
 
307
 
 
308
  /* append the separator only if we have >= 1 apps in the chooser */
 
309
  if (info != NULL) {
 
310
    gtk_app_chooser_button_append_separator (app_chooser);
 
311
    g_object_unref (info);
 
312
  }
 
313
 
 
314
  gtk_app_chooser_button_append_custom_item (app_chooser, CUSTOM_ITEM_ASK,
 
315
                                             _("Ask what to do"),
 
316
                                             NULL);
 
317
 
 
318
  gtk_app_chooser_button_append_custom_item (app_chooser, CUSTOM_ITEM_DO_NOTHING,
 
319
                                             _("Do nothing"),
 
320
                                             NULL);
 
321
 
 
322
  gtk_app_chooser_button_append_custom_item (app_chooser, CUSTOM_ITEM_OPEN_FOLDER,
 
323
                                             _("Open folder"),
 
324
                                             NULL);
 
325
 
 
326
  gtk_app_chooser_button_set_show_dialog_item (app_chooser, TRUE);
 
327
  gtk_app_chooser_button_set_heading (app_chooser, _(heading));
 
328
 
 
329
  if (pref_ask) {
 
330
    gtk_app_chooser_button_set_active_custom_item (app_chooser, CUSTOM_ITEM_ASK);
 
331
  } else if (pref_ignore) {
 
332
    gtk_app_chooser_button_set_active_custom_item (app_chooser, CUSTOM_ITEM_DO_NOTHING);
 
333
  } else if (pref_open_folder) {
 
334
    gtk_app_chooser_button_set_active_custom_item (app_chooser, CUSTOM_ITEM_OPEN_FOLDER);
 
335
  }
 
336
 
 
337
  g_signal_connect (app_chooser, "changed",
 
338
                    G_CALLBACK (combo_box_changed_cb), self);
 
339
  g_signal_connect (app_chooser, "custom-item-activated",
 
340
                    G_CALLBACK (custom_item_activated_cb), self);
 
341
 
 
342
  g_free (content_type);
 
343
}
 
344
 
 
345
static void
 
346
other_type_combo_box_changed (GtkComboBox *combo_box,
 
347
                              CcMediaPanel *self)
 
348
{
 
349
  GtkTreeIter iter;
 
350
  GtkTreeModel *model;
 
351
  char *x_content_type;
 
352
  GtkWidget *action_container;
 
353
 
 
354
  x_content_type = NULL;
 
355
 
 
356
  if (!gtk_combo_box_get_active_iter (combo_box, &iter)) {
 
357
    return;
 
358
  }
 
359
 
 
360
  model = gtk_combo_box_get_model (combo_box);
 
361
  if (model == NULL) {
 
362
    return;
 
363
  }
 
364
 
 
365
  gtk_tree_model_get (model, &iter,
 
366
                      2, &x_content_type,
 
367
                      -1);
 
368
 
 
369
  action_container = GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
 
370
                                                         "media_other_action_container"));
 
371
  if (self->priv->other_application_combo != NULL) {
 
372
    gtk_widget_destroy (self->priv->other_application_combo);
 
373
  }
 
374
 
 
375
  self->priv->other_application_combo = gtk_app_chooser_button_new (x_content_type);
 
376
  gtk_box_pack_start (GTK_BOX (action_container), self->priv->other_application_combo, TRUE, TRUE, 0);
 
377
  prepare_combo_box (self, self->priv->other_application_combo, NULL);
 
378
  gtk_widget_show (self->priv->other_application_combo);
 
379
 
 
380
  g_free (x_content_type);
 
381
}
 
382
 
 
383
static void
 
384
on_extra_options_dialog_response (GtkWidget    *dialog,
 
385
                                  int           response,
 
386
                                  CcMediaPanel *self)
 
387
{
 
388
  gtk_widget_hide (dialog);
 
389
 
 
390
  if (self->priv->other_application_combo != NULL) {
 
391
    gtk_widget_destroy (self->priv->other_application_combo);
 
392
    self->priv->other_application_combo = NULL;
 
393
  }
 
394
}
 
395
 
 
396
static void
 
397
on_extra_options_button_clicked (GtkWidget    *button,
 
398
                                 CcMediaPanel *self)
 
399
{
 
400
  GtkWidget *dialog;
 
401
  GtkWidget *combo_box;
 
402
 
 
403
  dialog = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "extra_options_dialog"));
 
404
  combo_box = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "media_other_type_combobox"));
 
405
  gtk_window_set_transient_for (GTK_WINDOW (dialog),
 
406
                                GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self))));
 
407
  gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
 
408
  g_signal_connect (dialog,
 
409
                    "response",
 
410
                    G_CALLBACK (on_extra_options_dialog_response),
 
411
                    self);
 
412
  /* update other_application_combo */
 
413
  other_type_combo_box_changed (GTK_COMBO_BOX (combo_box), self);
 
414
  gtk_window_present (GTK_WINDOW (dialog));
 
415
}
 
416
 
 
417
static void
 
418
media_panel_setup (CcMediaPanel *self)
 
419
{
 
420
  guint n;
 
421
  GList *l, *content_types;
 
422
  GtkWidget *other_type_combo_box;
 
423
  GtkWidget *extras_button;
 
424
  GtkListStore *other_type_list_store;
 
425
  GtkCellRenderer *renderer;
 
426
  GtkTreeIter iter;
 
427
  GtkBuilder *builder = self->priv->builder;
 
428
 
 
429
  struct {
 
430
    const gchar *widget_name;
 
431
    const gchar *content_type;
 
432
    const gchar *heading;
 
433
  } const defs[] = {
 
434
    { "media_audio_cdda_combobox", "x-content/audio-cdda", N_("Select an application for audio CDs") },
 
435
    { "media_video_dvd_combobox", "x-content/video-dvd", N_("Select an application for video DVDs") },
 
436
    { "media_music_player_combobox", "x-content/audio-player", N_("Select an application to run when a music player is connected") },
 
437
    { "media_dcf_combobox", "x-content/image-dcf", N_("Select an application to run when a camera is connected") },
 
438
    { "media_software_combobox", "x-content/software", N_("Select an application for software CDs") },
 
439
  };
 
440
 
 
441
  struct {
 
442
    const gchar *content_type;
 
443
    const gchar *description;
 
444
  } const other_defs[] = {
 
445
    /* translators: these strings are duplicates of shared-mime-info
 
446
     * strings, just here to fix capitalization of the English originals.
 
447
     * If the shared-mime-info translation works for your language,
 
448
     * simply leave these untranslated.
 
449
     */
 
450
    { "x-content/audio-dvd", N_("audio DVD") },
 
451
    { "x-content/blank-bd", N_("blank Blu-ray disc") },
 
452
    { "x-content/blank-cd", N_("blank CD disc") },
 
453
    { "x-content/blank-dvd", N_("blank DVD disc") },
 
454
    { "x-content/blank-hddvd", N_("blank HD DVD disc") },
 
455
    { "x-content/video-bluray", N_("Blu-ray video disc") },
 
456
    { "x-content/ebook-reader", N_("e-book reader") },
 
457
    { "x-content/video-hddvd", N_("HD DVD video disc") },
 
458
    { "x-content/image-picturecd", N_("Picture CD") },
 
459
    { "x-content/video-svcd", N_("Super Video CD") },
 
460
    { "x-content/video-vcd", N_("Video CD") }
 
461
  };
 
462
 
 
463
  for (n = 0; n < G_N_ELEMENTS (defs); n++) {
 
464
    prepare_combo_box (self,
 
465
                       GTK_WIDGET (gtk_builder_get_object (builder, defs[n].widget_name)),
 
466
                       defs[n].heading);
 
467
  }
 
468
 
 
469
  other_type_combo_box = GTK_WIDGET (gtk_builder_get_object (builder, "media_other_type_combobox"));
 
470
 
 
471
  other_type_list_store = gtk_list_store_new (3,
 
472
                                              G_TYPE_ICON,
 
473
                                              G_TYPE_STRING,
 
474
                                              G_TYPE_STRING);
 
475
 
 
476
  gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (other_type_list_store),
 
477
                                        1, GTK_SORT_ASCENDING);
 
478
 
 
479
 
 
480
  content_types = g_content_types_get_registered ();
 
481
 
 
482
  for (l = content_types; l != NULL; l = l->next) {
 
483
    char *content_type = l->data;
 
484
    char *description = NULL;
 
485
    GIcon *icon;
 
486
 
 
487
    if (!g_str_has_prefix (content_type, "x-content/"))
 
488
      continue;
 
489
 
 
490
    for (n = 0; n < G_N_ELEMENTS (defs); n++) {
 
491
      if (g_content_type_is_a (content_type, defs[n].content_type)) {
 
492
        goto skip;
 
493
      }
 
494
    }
 
495
 
 
496
    for (n = 0; n < G_N_ELEMENTS (other_defs); n++) {
 
497
       if (strcmp (content_type, other_defs[n].content_type) == 0) {
 
498
         const gchar *s = other_defs[n].description;
 
499
         if (s == _(s))
 
500
           description = g_content_type_get_description (content_type);
 
501
         else
 
502
           description = g_strdup (_(s));
 
503
 
 
504
         break;
 
505
       }
 
506
    }
 
507
 
 
508
    gtk_list_store_append (other_type_list_store, &iter);
 
509
    icon = g_content_type_get_icon (content_type);
 
510
 
 
511
    gtk_list_store_set (other_type_list_store, &iter,
 
512
                        0, icon,
 
513
                        1, description,
 
514
                        2, content_type,
 
515
                        -1);
 
516
    g_free (description);
 
517
    g_object_unref (icon);
 
518
  skip:
 
519
    ;
 
520
  }
 
521
 
 
522
  g_list_free_full (content_types, g_free);
 
523
 
 
524
  gtk_combo_box_set_model (GTK_COMBO_BOX (other_type_combo_box),
 
525
                           GTK_TREE_MODEL (other_type_list_store));
 
526
 
 
527
  renderer = gtk_cell_renderer_pixbuf_new ();
 
528
  gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (other_type_combo_box), renderer, FALSE);
 
529
  gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (other_type_combo_box), renderer,
 
530
                                  "gicon", 0,
 
531
                                  NULL);
 
532
 
 
533
  renderer = gtk_cell_renderer_text_new ();
 
534
  gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (other_type_combo_box), renderer, TRUE);
 
535
  gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (other_type_combo_box), renderer,
 
536
                                  "text", 1,
 
537
                                  NULL);
 
538
 
 
539
  g_signal_connect (other_type_combo_box,
 
540
                    "changed",
 
541
                    G_CALLBACK (other_type_combo_box_changed),
 
542
                    self);
 
543
 
 
544
  gtk_combo_box_set_active (GTK_COMBO_BOX (other_type_combo_box), 0);
 
545
 
 
546
  extras_button = GTK_WIDGET (gtk_builder_get_object (builder, "extra_options_button"));
 
547
  g_signal_connect (extras_button,
 
548
                    "clicked",
 
549
                    G_CALLBACK (on_extra_options_button_clicked),
 
550
                    self);
 
551
 
 
552
  g_settings_bind (self->priv->preferences,
 
553
                   PREF_MEDIA_AUTORUN_NEVER,
 
554
                   gtk_builder_get_object (self->priv->builder, "media_autorun_never_checkbutton"),
 
555
                   "active",
 
556
                   G_SETTINGS_BIND_DEFAULT);
 
557
 
 
558
  g_settings_bind (self->priv->preferences,
 
559
                   PREF_MEDIA_AUTORUN_NEVER,
 
560
                   GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "media_handling_vbox")),
 
561
                   "sensitive",
 
562
                   G_SETTINGS_BIND_INVERT_BOOLEAN);
 
563
}
 
564
 
 
565
static void
 
566
cc_media_panel_init (CcMediaPanel *self)
 
567
{
 
568
  CcMediaPanelPrivate *priv;
 
569
  GtkWidget *main_widget;
 
570
  guint res;
 
571
 
 
572
  priv = self->priv = MEDIA_PANEL_PRIVATE (self);
 
573
  priv->builder = gtk_builder_new ();
 
574
  priv->preferences = g_settings_new ("org.gnome.desktop.media-handling");
 
575
 
 
576
  res = gtk_builder_add_from_file (priv->builder, GNOMECC_UI_DIR "/gnome-media-properties.ui", NULL);
 
577
 
 
578
  /* TODO: error */
 
579
  if (res == 0) {
 
580
    g_critical ("Unable to load the UI file!");
 
581
  }
 
582
 
 
583
  media_panel_setup (self);
 
584
 
 
585
  main_widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
 
586
                                                    "media_preferences_vbox"));
 
587
  gtk_widget_reparent (main_widget, (GtkWidget *) self);
 
588
}
 
589
 
 
590
void
 
591
cc_media_panel_register (GIOModule *module)
 
592
{
 
593
  cc_media_panel_register_type (G_TYPE_MODULE (module));
 
594
  g_io_extension_point_implement (CC_SHELL_PANEL_EXTENSION_POINT,
 
595
                                  CC_TYPE_MEDIA_PANEL,
 
596
                                  "media", 0);
 
597
}
 
598