532
533
totem_recent_manager_changed_callback (totem->recent_manager, totem);
536
recent_info_cb (GFile *file,
541
char *groups[] = { NULL, NULL };
542
GFileInfo *file_info;
543
const char *uri, *display_name;
545
memset (&data, 0, sizeof (data));
547
file_info = g_file_query_info_finish (file, res, NULL);
548
uri = g_object_get_data (G_OBJECT (file), "uri");
549
display_name = g_object_get_data (G_OBJECT (file), "display_name");
551
/* Probably an unsupported URI scheme */
552
if (file_info == NULL) {
553
data.display_name = g_strdup (display_name);
554
/* Bogus mime-type, we just want it added */
555
data.mime_type = g_strdup ("video/x-totem-stream");
556
groups[0] = (gchar*) "TotemStreams";
558
data.mime_type = g_strdup (g_file_info_get_content_type (file_info));
559
data.display_name = g_strdup (g_file_info_get_display_name (file_info));
560
g_object_unref (file_info);
561
groups[0] = (gchar*) "Totem";
564
data.app_name = g_strdup (g_get_application_name ());
565
data.app_exec = g_strjoin (" ", g_get_prgname (), "%u", NULL);
566
data.groups = groups;
567
if (gtk_recent_manager_add_full (totem->recent_manager,
568
uri, &data) == FALSE) {
569
g_warning ("Couldn't add recent file for '%s'", uri);
572
g_free (data.display_name);
573
g_free (data.mime_type);
574
g_free (data.app_name);
575
g_free (data.app_exec);
577
g_object_unref (file);
581
totem_action_add_recent (Totem *totem,
583
const char *display_name,
584
const char *content_type)
588
if (totem_is_special_mrl (uri) != FALSE)
591
/* If we already have a content-type, the display_name is
592
* probably decent as well */
593
if (content_type != NULL) {
595
char *groups[] = { NULL, NULL };
597
memset (&data, 0, sizeof (data));
599
data.mime_type = (char *) content_type;
600
data.display_name = (char *) display_name;
601
groups[0] = (char*) "Totem";
602
data.app_name = (char *) g_get_application_name ();
603
data.app_exec = g_strjoin (" ", g_get_prgname (), "%u", NULL);
604
data.groups = groups;
606
if (gtk_recent_manager_add_full (totem->recent_manager,
607
uri, &data) == FALSE) {
608
g_warning ("Couldn't add recent file for '%s'", uri);
610
g_free (data.app_exec);
615
file = g_file_new_for_uri (uri);
616
g_object_set_data_full (G_OBJECT (file), "uri", g_strdup (uri), g_free);
617
g_object_set_data_full (G_OBJECT (file), "display_name", g_strdup (display_name), g_free);
618
g_file_query_info_async (file,
619
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "," G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
620
G_FILE_QUERY_INFO_NONE, 0, NULL, (GAsyncReadyCallback) recent_info_cb, totem);
623
/* Play Disc menu items */
626
on_play_disc_activate (GtkAction *action, Totem *totem)
630
device_path = g_object_get_data (G_OBJECT (action), "device_path");
631
totem_action_play_media_device (totem, device_path);
635
get_icon_name_for_gicon (GtkIconTheme *theme,
638
const char * const *icon_names;
639
const char *icon_name;
644
if (G_IS_EMBLEMED_ICON (icon) != FALSE) {
646
new_icon = g_emblemed_icon_get_icon (G_EMBLEMED_ICON (icon));
647
g_object_unref (icon);
648
icon = g_object_ref (new_icon);
651
if (G_IS_THEMED_ICON (icon)) {
652
icon_names = g_themed_icon_get_names (G_THEMED_ICON (icon));
654
for (j = 0; icon_names[j] != NULL; j++) {
655
icon_name = icon_names[j];
656
if (gtk_icon_theme_has_icon (theme, icon_name) != FALSE)
665
unescape_archive_name (GFile *root)
669
char *escape1, *escape2;
671
uri = g_file_get_uri (root);
673
/* Remove trailing slash */
675
if (uri[len - 1] == '/')
678
/* Unescape the path */
679
escape1 = g_uri_unescape_string (uri + strlen ("archive://"), NULL);
680
escape2 = g_uri_unescape_string (escape1, NULL);
688
add_mount_to_menu (GMount *mount,
693
char *name, *escaped_name, *label;
696
const char *icon_name;
701
char **content_types;
702
gboolean has_content;
705
/* Check whether we have an archive mount */
706
volume = g_mount_get_volume (mount);
707
if (volume != NULL) {
708
g_object_unref (volume);
712
root = g_mount_get_root (mount);
713
if (g_file_has_uri_scheme (root, "archive") == FALSE) {
714
g_object_unref (root);
718
/* Check whether it's a DVD or VCD image */
719
content_types = g_content_type_guess_for_tree (root);
720
if (content_types == NULL ||
721
g_strv_length (content_types) == 0) {
722
g_strfreev (content_types);
723
g_object_unref (root);
728
for (i = 0; content_types[i] != NULL; i++) {
729
/* XXX: Keep in sync with mime-type-list.txt */
730
if (g_str_equal (content_types[i], "x-content/video-dvd") ||
731
g_str_equal (content_types[i], "x-content/video-vcd") ||
732
g_str_equal (content_types[i], "x-content/video-svcd")) {
737
g_strfreev (content_types);
739
if (has_content == FALSE) {
740
g_object_unref (root);
744
device_path = unescape_archive_name (root);
745
g_object_unref (root);
747
/* And ensure it's a local path */
748
iso = g_file_new_for_uri (device_path);
749
g_free (device_path);
750
device_path = g_file_get_path (iso);
751
g_object_unref (iso);
753
/* Work out an icon to display */
754
icon = g_mount_get_icon (mount);
755
icon_name = get_icon_name_for_gicon (theme, icon);
757
/* Get the mount's pretty name for the menu label */
758
name = g_mount_get_name (mount);
760
escaped_name = escape_label_for_menu (name);
763
* This is not a JPEG image, but a disc image, for example,
765
label = g_strdup_printf (_("Play Image '%s'"), escaped_name);
766
g_free (escaped_name);
768
name = g_strdup_printf (_("device%d"), position);
770
action = gtk_action_new (name, label, NULL, NULL);
771
g_object_set (G_OBJECT (action),
772
"icon-name", icon_name, NULL);
773
gtk_action_set_always_show_image (action, TRUE);
774
gtk_action_group_add_action (totem->devices_action_group, action);
775
g_object_unref (action);
777
gtk_ui_manager_add_ui (totem->ui_manager, totem->devices_ui_id,
778
"/tmw-menubar/movie/devices-placeholder", name, name,
779
GTK_UI_MANAGER_MENUITEM, FALSE);
783
g_object_unref (icon);
785
g_object_set_data_full (G_OBJECT (action),
786
"device_path", device_path,
787
(GDestroyNotify) g_free);
789
g_signal_connect (G_OBJECT (action), "activate",
790
G_CALLBACK (on_play_disc_activate), totem);
794
add_volume_to_menu (GVolume *volume,
800
char *name, *escaped_name, *label;
804
const char *icon_name;
806
GtkWidget *menu_item;
807
char *menu_item_path;
812
/* Add devices with blank CDs and audio CDs in them, but disable them */
814
device_path = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
815
if (device_path == NULL)
819
/* Check whether we have a media... */
821
g_drive_has_media (drive) == FALSE) {
824
/* ... Or an audio CD or a blank media */
828
mount = g_volume_get_mount (volume);
830
root = g_mount_get_root (mount);
831
g_object_unref (mount);
833
if (g_file_has_uri_scheme (root, "burn") != FALSE || g_file_has_uri_scheme (root, "cdda") != FALSE)
835
g_object_unref (root);
839
/* Work out an icon to display */
840
icon = g_volume_get_icon (volume);
841
icon_name = get_icon_name_for_gicon (theme, icon);
843
/* Get the volume's pretty name for the menu label */
844
name = g_volume_get_name (volume);
846
escaped_name = escape_label_for_menu (name);
848
label = g_strdup_printf (_("Play Disc '%s'"), escaped_name);
849
g_free (escaped_name);
851
name = g_strdup_printf (_("device%d"), position);
853
action = gtk_action_new (name, label, NULL, NULL);
854
g_object_set (G_OBJECT (action),
855
"icon-name", icon_name,
856
"sensitive", !disabled, NULL);
857
gtk_action_group_add_action (totem->devices_action_group, action);
858
g_object_unref (action);
860
gtk_ui_manager_add_ui (totem->ui_manager, totem->devices_ui_id,
861
"/tmw-menubar/movie/devices-placeholder", name, name,
862
GTK_UI_MANAGER_MENUITEM, FALSE);
864
/* TODO: This can be made cleaner once bug #589842 is fixed */
865
menu_item_path = g_strdup_printf ("/tmw-menubar/movie/devices-placeholder/%s", name);
866
menu_item = gtk_ui_manager_get_widget (totem->ui_manager, menu_item_path);
867
g_free (menu_item_path);
869
if (menu_item != NULL)
870
gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (menu_item), TRUE);
874
g_object_unref (icon);
876
if (disabled != FALSE) {
877
g_free (device_path);
881
g_object_set_data_full (G_OBJECT (action),
882
"device_path", device_path,
883
(GDestroyNotify) g_free);
885
g_signal_connect (G_OBJECT (action), "activate",
886
G_CALLBACK (on_play_disc_activate), totem);
890
add_drive_to_menu (GDrive *drive,
897
/* FIXME: We used to explicitly check whether it was a CD/DVD drive
899
* udi = g_volume_get_identifier (i->data, G_VOLUME_IDENTIFIER_KIND_HAL_UDI); */
900
if (g_drive_can_eject (drive) == FALSE)
903
/* Repeat for all the drive's volumes */
904
volumes = g_drive_get_volumes (drive);
906
for (i = volumes; i != NULL; i = i->next) {
907
GVolume *volume = i->data;
908
add_volume_to_menu (volume, drive, theme, position, totem);
909
g_object_unref (volume);
912
g_list_free (volumes);
916
update_drive_menu_items (GtkMenuItem *movie_menuitem, Totem *totem)
918
GList *drives, *mounts, *i;
922
/* Add any suitable devices to the menu */
925
theme = gtk_icon_theme_get_default ();
927
drives = g_volume_monitor_get_connected_drives (totem->monitor);
928
for (i = drives; i != NULL; i = i->next) {
929
GDrive *drive = i->data;
932
add_drive_to_menu (drive, theme, position, totem);
933
g_object_unref (drive);
935
g_list_free (drives);
937
/* Look for mounted archives */
938
mounts = g_volume_monitor_get_mounts (totem->monitor);
939
for (i = mounts; i != NULL; i = i->next) {
940
GMount *mount = i->data;
943
add_mount_to_menu (mount, theme, position, totem);
944
g_object_unref (mount);
946
g_list_free (mounts);
948
totem->drives_changed = FALSE;
952
on_movie_menu_select (GtkMenuItem *movie_menuitem, Totem *totem)
954
if (totem->drives_changed == FALSE)
958
gtk_ui_manager_remove_ui (totem->ui_manager, totem->devices_ui_id);
959
gtk_ui_manager_ensure_update (totem->ui_manager);
961
/* Create new ActionGroup */
962
if (totem->devices_action_group) {
963
gtk_ui_manager_remove_action_group (totem->ui_manager,
964
totem->devices_action_group);
965
g_object_unref (totem->devices_action_group);
967
totem->devices_action_group = gtk_action_group_new ("devices-action-group");
968
gtk_ui_manager_insert_action_group (totem->ui_manager,
969
totem->devices_action_group, -1);
971
update_drive_menu_items (movie_menuitem, totem);
973
gtk_ui_manager_ensure_update (totem->ui_manager);
977
on_g_volume_monitor_event (GVolumeMonitor *monitor,
981
totem->drives_changed = TRUE;
985
totem_setup_play_disc (Totem *totem)
989
item = gtk_ui_manager_get_widget (totem->ui_manager, "/tmw-menubar/movie");
990
g_signal_connect (G_OBJECT (item), "select",
991
G_CALLBACK (on_movie_menu_select), totem);
993
g_signal_connect (G_OBJECT (totem->monitor),
995
G_CALLBACK (on_g_volume_monitor_event), totem);
996
g_signal_connect (G_OBJECT (totem->monitor),
998
G_CALLBACK (on_g_volume_monitor_event), totem);
999
g_signal_connect (G_OBJECT (totem->monitor),
1001
G_CALLBACK (on_g_volume_monitor_event), totem);
1002
g_signal_connect (G_OBJECT (totem->monitor),
1004
G_CALLBACK (on_g_volume_monitor_event), totem);
1006
totem->drives_changed = TRUE;
1010
537
open_action_callback (GtkAction *action, Totem *totem)