978
remove_elem_from_str_array (char **v,
984
array = g_ptr_array_new ();
986
for (idx = 0; v[idx] != NULL; idx++) {
987
if (g_strcmp0 (v[idx], s) == 0) {
991
g_ptr_array_add (array, v[idx]);
994
g_ptr_array_add (array, NULL);
998
return (char **) g_ptr_array_free (array, FALSE);
1002
add_elem_to_str_array (char **v,
1008
array = g_ptr_array_new ();
1010
for (idx = 0; v[idx] != NULL; idx++) {
1011
g_ptr_array_add (array, v[idx]);
1014
g_ptr_array_add (array, g_strdup (s));
1015
g_ptr_array_add (array, NULL);
1019
return (char **) g_ptr_array_free (array, FALSE);
1023
media_panel_g_strv_find (char **strv,
1024
const char *find_me)
1028
g_return_val_if_fail (find_me != NULL, -1);
1030
for (index = 0; strv[index] != NULL; ++index) {
1031
if (g_strcmp0 (strv[index], find_me) == 0) {
1040
autorun_get_preferences (CcInfoPanel *self,
1041
const char *x_content_type,
1042
gboolean *pref_start_app,
1043
gboolean *pref_ignore,
1044
gboolean *pref_open_folder)
1046
char **x_content_start_app;
1047
char **x_content_ignore;
1048
char **x_content_open_folder;
1050
g_return_if_fail (pref_start_app != NULL);
1051
g_return_if_fail (pref_ignore != NULL);
1052
g_return_if_fail (pref_open_folder != NULL);
1054
*pref_start_app = FALSE;
1055
*pref_ignore = FALSE;
1056
*pref_open_folder = FALSE;
1057
x_content_start_app = g_settings_get_strv (self->priv->media_settings,
1058
PREF_MEDIA_AUTORUN_X_CONTENT_START_APP);
1059
x_content_ignore = g_settings_get_strv (self->priv->media_settings,
1060
PREF_MEDIA_AUTORUN_X_CONTENT_IGNORE);
1061
x_content_open_folder = g_settings_get_strv (self->priv->media_settings,
1062
PREF_MEDIA_AUTORUN_X_CONTENT_OPEN_FOLDER);
1063
if (x_content_start_app != NULL) {
1064
*pref_start_app = media_panel_g_strv_find (x_content_start_app, x_content_type) != -1;
1066
if (x_content_ignore != NULL) {
1067
*pref_ignore = media_panel_g_strv_find (x_content_ignore, x_content_type) != -1;
1069
if (x_content_open_folder != NULL) {
1070
*pref_open_folder = media_panel_g_strv_find (x_content_open_folder, x_content_type) != -1;
1072
g_strfreev (x_content_ignore);
1073
g_strfreev (x_content_start_app);
1074
g_strfreev (x_content_open_folder);
1078
autorun_set_preferences (CcInfoPanel *self,
1079
const char *x_content_type,
1080
gboolean pref_start_app,
1081
gboolean pref_ignore,
1082
gboolean pref_open_folder)
1084
char **x_content_start_app;
1085
char **x_content_ignore;
1086
char **x_content_open_folder;
1088
g_assert (x_content_type != NULL);
1090
x_content_start_app = g_settings_get_strv (self->priv->media_settings,
1091
PREF_MEDIA_AUTORUN_X_CONTENT_START_APP);
1092
x_content_ignore = g_settings_get_strv (self->priv->media_settings,
1093
PREF_MEDIA_AUTORUN_X_CONTENT_IGNORE);
1094
x_content_open_folder = g_settings_get_strv (self->priv->media_settings,
1095
PREF_MEDIA_AUTORUN_X_CONTENT_OPEN_FOLDER);
1097
x_content_start_app = remove_elem_from_str_array (x_content_start_app, x_content_type);
1098
if (pref_start_app) {
1099
x_content_start_app = add_elem_to_str_array (x_content_start_app, x_content_type);
1101
g_settings_set_strv (self->priv->media_settings,
1102
PREF_MEDIA_AUTORUN_X_CONTENT_START_APP, (const gchar * const*) x_content_start_app);
1104
x_content_ignore = remove_elem_from_str_array (x_content_ignore, x_content_type);
1106
x_content_ignore = add_elem_to_str_array (x_content_ignore, x_content_type);
1108
g_settings_set_strv (self->priv->media_settings,
1109
PREF_MEDIA_AUTORUN_X_CONTENT_IGNORE, (const gchar * const*) x_content_ignore);
1111
x_content_open_folder = remove_elem_from_str_array (x_content_open_folder, x_content_type);
1112
if (pref_open_folder) {
1113
x_content_open_folder = add_elem_to_str_array (x_content_open_folder, x_content_type);
1115
g_settings_set_strv (self->priv->media_settings,
1116
PREF_MEDIA_AUTORUN_X_CONTENT_OPEN_FOLDER, (const gchar * const*) x_content_open_folder);
1118
g_strfreev (x_content_open_folder);
1119
g_strfreev (x_content_ignore);
1120
g_strfreev (x_content_start_app);
1125
custom_item_activated_cb (GtkAppChooserButton *button,
1129
CcInfoPanel *self = user_data;
1130
gchar *content_type;
1132
content_type = gtk_app_chooser_get_content_type (GTK_APP_CHOOSER (button));
1134
if (g_strcmp0 (item, CUSTOM_ITEM_ASK) == 0) {
1135
autorun_set_preferences (self, content_type,
1136
FALSE, FALSE, FALSE);
1137
} else if (g_strcmp0 (item, CUSTOM_ITEM_OPEN_FOLDER) == 0) {
1138
autorun_set_preferences (self, content_type,
1139
FALSE, FALSE, TRUE);
1140
} else if (g_strcmp0 (item, CUSTOM_ITEM_DO_NOTHING) == 0) {
1141
autorun_set_preferences (self, content_type,
1142
FALSE, TRUE, FALSE);
1145
g_free (content_type);
1149
combo_box_changed_cb (GtkComboBox *combo_box,
1152
CcInfoPanel *self = user_data;
1154
gchar *content_type;
1156
info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (combo_box));
1161
content_type = gtk_app_chooser_get_content_type (GTK_APP_CHOOSER (combo_box));
1162
autorun_set_preferences (self, content_type,
1163
TRUE, FALSE, FALSE);
1164
g_app_info_set_as_default_for_type (info, content_type, NULL);
1166
g_object_unref (info);
1167
g_free (content_type);
1171
prepare_combo_box (CcInfoPanel *self,
1172
GtkWidget *combo_box,
1173
const gchar *heading)
1175
GtkAppChooserButton *app_chooser = GTK_APP_CHOOSER_BUTTON (combo_box);
1177
gboolean pref_start_app;
1178
gboolean pref_ignore;
1179
gboolean pref_open_folder;
1181
gchar *content_type;
1183
content_type = gtk_app_chooser_get_content_type (GTK_APP_CHOOSER (app_chooser));
1185
/* fetch preferences for this content type */
1186
autorun_get_preferences (self, content_type,
1187
&pref_start_app, &pref_ignore, &pref_open_folder);
1188
pref_ask = !pref_start_app && !pref_ignore && !pref_open_folder;
1190
info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (combo_box));
1192
/* append the separator only if we have >= 1 apps in the chooser */
1194
gtk_app_chooser_button_append_separator (app_chooser);
1195
g_object_unref (info);
1198
gtk_app_chooser_button_append_custom_item (app_chooser, CUSTOM_ITEM_ASK,
1199
_("Ask what to do"),
1202
gtk_app_chooser_button_append_custom_item (app_chooser, CUSTOM_ITEM_DO_NOTHING,
1206
gtk_app_chooser_button_append_custom_item (app_chooser, CUSTOM_ITEM_OPEN_FOLDER,
1210
gtk_app_chooser_button_set_show_dialog_item (app_chooser, TRUE);
1211
gtk_app_chooser_button_set_heading (app_chooser, _(heading));
1214
gtk_app_chooser_button_set_active_custom_item (app_chooser, CUSTOM_ITEM_ASK);
1215
} else if (pref_ignore) {
1216
gtk_app_chooser_button_set_active_custom_item (app_chooser, CUSTOM_ITEM_DO_NOTHING);
1217
} else if (pref_open_folder) {
1218
gtk_app_chooser_button_set_active_custom_item (app_chooser, CUSTOM_ITEM_OPEN_FOLDER);
1221
g_signal_connect (app_chooser, "changed",
1222
G_CALLBACK (combo_box_changed_cb), self);
1223
g_signal_connect (app_chooser, "custom-item-activated",
1224
G_CALLBACK (custom_item_activated_cb), self);
1226
g_free (content_type);
1230
other_type_combo_box_changed (GtkComboBox *combo_box,
1234
GtkTreeModel *model;
1235
char *x_content_type;
1236
GtkWidget *action_container;
1238
x_content_type = NULL;
1240
if (!gtk_combo_box_get_active_iter (combo_box, &iter)) {
1244
model = gtk_combo_box_get_model (combo_box);
1245
if (model == NULL) {
1249
gtk_tree_model_get (model, &iter,
1253
action_container = GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
1254
"media_other_action_container"));
1255
if (self->priv->other_application_combo != NULL) {
1256
gtk_widget_destroy (self->priv->other_application_combo);
1259
self->priv->other_application_combo = gtk_app_chooser_button_new (x_content_type);
1260
gtk_box_pack_start (GTK_BOX (action_container), self->priv->other_application_combo, TRUE, TRUE, 0);
1261
prepare_combo_box (self, self->priv->other_application_combo, NULL);
1262
gtk_widget_show (self->priv->other_application_combo);
1264
g_free (x_content_type);
1268
on_extra_options_dialog_response (GtkWidget *dialog,
1272
gtk_widget_hide (dialog);
1274
if (self->priv->other_application_combo != NULL) {
1275
gtk_widget_destroy (self->priv->other_application_combo);
1276
self->priv->other_application_combo = NULL;
1281
on_extra_options_button_clicked (GtkWidget *button,
1285
GtkWidget *combo_box;
1287
dialog = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "extra_options_dialog"));
1288
combo_box = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "media_other_type_combobox"));
1289
gtk_window_set_transient_for (GTK_WINDOW (dialog),
1290
GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self))));
1291
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
1292
g_signal_connect (dialog,
1294
G_CALLBACK (on_extra_options_dialog_response),
1296
/* update other_application_combo */
1297
other_type_combo_box_changed (GTK_COMBO_BOX (combo_box), self);
1298
gtk_window_present (GTK_WINDOW (dialog));
1302
info_panel_setup_media (CcInfoPanel *self)
1305
GList *l, *content_types;
1306
GtkWidget *other_type_combo_box;
1307
GtkWidget *extras_button;
1308
GtkListStore *other_type_list_store;
1309
GtkCellRenderer *renderer;
1311
GtkBuilder *builder = self->priv->builder;
1314
const gchar *widget_name;
1315
const gchar *content_type;
1316
const gchar *heading;
1318
{ "media_audio_cdda_combobox", "x-content/audio-cdda", N_("Select an application for audio CDs") },
1319
{ "media_video_dvd_combobox", "x-content/video-dvd", N_("Select an application for video DVDs") },
1320
{ "media_music_player_combobox", "x-content/audio-player", N_("Select an application to run when a music player is connected") },
1321
{ "media_dcf_combobox", "x-content/image-dcf", N_("Select an application to run when a camera is connected") },
1322
{ "media_software_combobox", "x-content/unix-software", N_("Select an application for software CDs") },
1326
const gchar *content_type;
1327
const gchar *description;
1328
} const other_defs[] = {
1329
/* translators: these strings are duplicates of shared-mime-info
1330
* strings, just here to fix capitalization of the English originals.
1331
* If the shared-mime-info translation works for your language,
1332
* simply leave these untranslated.
1334
{ "x-content/audio-dvd", N_("audio DVD") },
1335
{ "x-content/blank-bd", N_("blank Blu-ray disc") },
1336
{ "x-content/blank-cd", N_("blank CD disc") },
1337
{ "x-content/blank-dvd", N_("blank DVD disc") },
1338
{ "x-content/blank-hddvd", N_("blank HD DVD disc") },
1339
{ "x-content/video-bluray", N_("Blu-ray video disc") },
1340
{ "x-content/ebook-reader", N_("e-book reader") },
1341
{ "x-content/video-hddvd", N_("HD DVD video disc") },
1342
{ "x-content/image-picturecd", N_("Picture CD") },
1343
{ "x-content/video-svcd", N_("Super Video CD") },
1344
{ "x-content/video-vcd", N_("Video CD") }
1347
for (n = 0; n < G_N_ELEMENTS (defs); n++) {
1348
prepare_combo_box (self,
1349
GTK_WIDGET (gtk_builder_get_object (builder, defs[n].widget_name)),
1353
other_type_combo_box = GTK_WIDGET (gtk_builder_get_object (builder, "media_other_type_combobox"));
1355
other_type_list_store = gtk_list_store_new (3,
1360
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (other_type_list_store),
1361
1, GTK_SORT_ASCENDING);
1364
content_types = g_content_types_get_registered ();
1366
for (l = content_types; l != NULL; l = l->next) {
1367
char *content_type = l->data;
1368
char *description = NULL;
1371
if (!g_str_has_prefix (content_type, "x-content/"))
1374
for (n = 0; n < G_N_ELEMENTS (defs); n++) {
1375
if (g_content_type_is_a (content_type, defs[n].content_type)) {
1380
for (n = 0; n < G_N_ELEMENTS (other_defs); n++) {
1381
if (strcmp (content_type, other_defs[n].content_type) == 0) {
1382
const gchar *s = other_defs[n].description;
1384
description = g_content_type_get_description (content_type);
1386
description = g_strdup (_(s));
1392
gtk_list_store_append (other_type_list_store, &iter);
1393
icon = g_content_type_get_icon (content_type);
1395
gtk_list_store_set (other_type_list_store, &iter,
1400
g_free (description);
1401
g_object_unref (icon);
1406
g_list_free_full (content_types, g_free);
1408
gtk_combo_box_set_model (GTK_COMBO_BOX (other_type_combo_box),
1409
GTK_TREE_MODEL (other_type_list_store));
1411
renderer = gtk_cell_renderer_pixbuf_new ();
1412
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (other_type_combo_box), renderer, FALSE);
1413
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (other_type_combo_box), renderer,
1417
renderer = gtk_cell_renderer_text_new ();
1418
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (other_type_combo_box), renderer, TRUE);
1419
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (other_type_combo_box), renderer,
1423
g_signal_connect (other_type_combo_box,
1425
G_CALLBACK (other_type_combo_box_changed),
1428
gtk_combo_box_set_active (GTK_COMBO_BOX (other_type_combo_box), 0);
1430
extras_button = GTK_WIDGET (gtk_builder_get_object (builder, "extra_options_button"));
1431
g_signal_connect (extras_button,
1433
G_CALLBACK (on_extra_options_button_clicked),
1436
g_settings_bind (self->priv->media_settings,
1437
PREF_MEDIA_AUTORUN_NEVER,
1438
gtk_builder_get_object (self->priv->builder, "media_autorun_never_checkbutton"),
1440
G_SETTINGS_BIND_DEFAULT);
1442
g_settings_bind (self->priv->media_settings,
1443
PREF_MEDIA_AUTORUN_NEVER,
1444
GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "media_handling_vbox")),
1446
G_SETTINGS_BIND_INVERT_BOOLEAN);
950
1450
info_panel_setup_selector (CcInfoPanel *self)