Commit 2761f4f9 authored by Alexander Larsson's avatar Alexander Larsson Committed by Alexander Larsson

Add check_trash arg to nautilus_file_operations_unmount_mount. Add

2008-01-14  Alexander Larsson  <alexl@redhat.com>

        * libnautilus-private/nautilus-file-operations.[ch]:
	Add check_trash arg to nautilus_file_operations_unmount_mount.
	Add nautilus_file_operations_mount_volume().
	
        * libnautilus-private/nautilus-desktop-icon-file.c:
        * src/nautilus-places-sidebar.c:
        * src/file-manager/fm-tree-view.c:
	Update to API change.
	
        * data/nautilus.xml.in:
        * libnautilus-private/Makefile.am:
        * libnautilus-private/apps_nautilus_preferences.schemas.in:
        * libnautilus-private/nautilus-autorun.[ch]: Added.
        * libnautilus-private/nautilus-global-preferences.[ch]:
        * src/nautilus-application.c:
        * src/nautilus-file-management-properties.c:
        * src/nautilus-file-management-properties.glade:
	Add new autorun setup (by David Zeuthen)


svn path=/trunk/; revision=13594
parent 7884f134
2008-01-14 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/nautilus-file-operations.[ch]:
Add check_trash arg to nautilus_file_operations_unmount_mount.
Add nautilus_file_operations_mount_volume().
* libnautilus-private/nautilus-desktop-icon-file.c:
* src/nautilus-places-sidebar.c:
* src/file-manager/fm-tree-view.c:
Update to API change.
* data/nautilus.xml.in:
* libnautilus-private/Makefile.am:
* libnautilus-private/apps_nautilus_preferences.schemas.in:
* libnautilus-private/nautilus-autorun.[ch]: Added.
* libnautilus-private/nautilus-global-preferences.[ch]:
* src/nautilus-application.c:
* src/nautilus-file-management-properties.c:
* src/nautilus-file-management-properties.glade:
Add new autorun setup (by David Zeuthen)
2008-01-11 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/nautilus-file.[ch]:
......
......@@ -5,4 +5,74 @@
<_comment>Saved search</_comment>
<glob pattern="*.savedSearch"/>
</mime-type>
<!-- this section lists definitions for x-content/* types; this should be
standardized on xdg-list (TODO: davidz)
-->
<mime-type type="x-content/video-vcd">
<!-- http://en.wikipedia.org/wiki/Video_CD -->
<_comment>VCD Video</_comment>
</mime-type>
<mime-type type="x-content/video-svcd">
<!-- http://en.wikipedia.org/wiki/Super_Video_CD -->
<_comment>SVCD Video</_comment>
</mime-type>
<mime-type type="x-content/video-dvd">
<!-- http://en.wikipedia.org/wiki/DVD-Video -->
<_comment>DVD Video</_comment>
</mime-type>
<mime-type type="x-content/image-dcf">
<!-- http://en.wikipedia.org/wiki/Design_rule_for_Camera_File_system -->
<_comment>Digital Photos</_comment>
</mime-type>
<mime-type type="x-content/audio-cdda">
<!-- http://en.wikipedia.org/wiki/Red_Book_(audio_CD_standard) -->
<_comment>Compact Disc Audio</_comment>
</mime-type>
<mime-type type="x-content/blank-media">
<!-- http://en.wikipedia.org/wiki/Compact_Disc -->
<!-- http://en.wikipedia.org/wiki/DVD -->
<_comment>Blank Media</_comment>
</mime-type>
<mime-type type="x-content/software-autostart">
<!-- http://www.freedesktop.org/wiki/Specifications/autostart-spec -->
<_comment>Software</_comment>
</mime-type>
<!-- TODO:
- Blu-Ray video : http://en.wikipedia.org/wiki/Blu-ray_Disc
- HD-DVD video : http://en.wikipedia.org/wiki/HD_DVD
- DVD-Audio : http://en.wikipedia.org/wiki/DVD-Audio
- Photo CD : http://en.wikipedia.org/wiki/Photo_CD
- Picture CD : http://en.wikipedia.org/wiki/Picture_CD
- SACD : http://en.wikipedia.org/wiki/Super_Audio_CD
- This might be dead and appear to be totally unsupported anyway
- Enhanced Audio CD (see link 1. below)
- http://en.wikipedia.org/wiki/Enhanced_CD
- Enhanced DVD Movie (see link 1. below)
- ??
- music player (x-content/music-player)
- picture files
- audio files
- video files
- for these three; launch a given program when detecting such files in the root
directory. Should default to "Don't do anything" since it's a bit crackful
See also
1. http://www.phdcc.com/shellrun/autorun.htm
-->
</mime-info>
......@@ -41,6 +41,8 @@ marshal_sources = \
$(NULL)
libnautilus_private_la_SOURCES = \
nautilus-autorun.c \
nautilus-autorun.h \
nautilus-bookmark.c \
nautilus-bookmark.h \
nautilus-cell-renderer-pixbuf-emblem.c \
......
......@@ -67,6 +67,69 @@
</long>
</locale>
</schema>
<schema>
<key>/schemas/apps/nautilus/preferences/media_automount</key>
<applyto>/apps/nautilus/preferences/media_automount</applyto>
<owner>nautilus</owner>
<type>bool</type>
<default>true</default>
<locale name="C">
<short>Whether to automatically mount media</short>
<long>
If set to true, then Nautilus will automatically mount media
such as user-visible hard disks and removable media on start-up
and and media insertion.
</long>
</locale>
</schema>
<schema>
<key>/schemas/apps/nautilus/preferences/media_automount_open</key>
<applyto>/apps/nautilus/preferences/media_automount_open</applyto>
<owner>nautilus</owner>
<type>bool</type>
<default>true</default>
<locale name="C">
<short>Whether to automatically open a folder for automounted media</short>
<long>
If set to true, then Nautilus will automatically open a folder when
media is automounted. This only applies to media where no known
x-content/* type was detected; for media where a known x-content
type is detected, the user configurable action will be taken instead.
</long>
</locale>
</schema>
<schema>
<key>/schemas/apps/nautilus/preferences/media_autorun_x_content_ask</key>
<applyto>/apps/nautilus/preferences/media_autorun_x_content_ask</applyto>
<owner>nautilus</owner>
<type>list</type>
<list_type>string</list_type>
<default>[]</default>
<locale name="C">
<short>list of x-content/* types to ask the user what to do on insertion</short>
<long>
list of x-content/* types to ask the user what to do on insertion
</long>
</locale>
</schema>
<schema>
<key>/schemas/apps/nautilus/preferences/media_autorun_x_content_ignore</key>
<applyto>/apps/nautilus/preferences/media_autorun_x_content_ignore</applyto>
<owner>nautilus</owner>
<type>list</type>
<list_type>string</list_type>
<default>[]</default>
<locale name="C">
<short>list of x-content/* types to ignore on insertion</short>
<long>
list of x-content/* types to ask the user what to do on insertion
</long>
</locale>
</schema>
<schema>
<key>/schemas/apps/nautilus/preferences/confirm_trash</key>
......
This diff is collapsed.
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/*
* Nautilus
*
* Copyright (C) 2008 Red Hat, Inc.
*
* Nautilus is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: David Zeuthen <davidz@redhat.com>
*/
/* TODO:
*
* - automount all user-visible media on startup
* - but avoid doing autorun for these
* - unmount all the media we've automounted on shutdown
* - finish x-content / * types
* - finalize the semi-spec
* - add probing/sniffing code
* - clean up code
* - implement missing features
* - "Open Folder when mounted"
* - Autorun spec (e.g. $ROOT/.autostart)
*
*/
#ifndef NAUTILUS_AUTORUN_H
#define NAUTILUS_AUTORUN_H
#include <gtk/gtkvbox.h>
#include <eel/eel-background.h>
#include <libnautilus-private/nautilus-file.h>
typedef void (*NautilusAutorunComboBoxChanged) (gboolean selected_ask,
gboolean selected_ignore,
GAppInfo *selected_app,
gpointer user_data);
void nautilus_autorun_prepare_combo_box (GtkWidget *combo_box,
const char *x_content_type,
gboolean include_ask,
gboolean update_settings,
NautilusAutorunComboBoxChanged changed_cb,
gpointer user_data);
void nautilus_autorun_set_preferences (const char *x_content_type, gboolean pref_ask, gboolean pref_ignore);
void nautilus_autorun_get_preferences (const char *x_content_type, gboolean *pref_ask, gboolean *pref_ignore);
void nautilus_autorun (GMount *mount);
#endif /* NAUTILUS_AUTORUN_H */
......@@ -311,7 +311,7 @@ nautilus_desktop_icon_file_unmount (NautilusFile *file)
if (desktop_file) {
mount = nautilus_desktop_link_get_mount (desktop_file->details->link);
if (mount != NULL) {
nautilus_file_operations_unmount_mount (NULL, mount, FALSE);
nautilus_file_operations_unmount_mount (NULL, mount, FALSE, TRUE);
}
}
......@@ -327,7 +327,7 @@ nautilus_desktop_icon_file_eject (NautilusFile *file)
if (desktop_file) {
mount = nautilus_desktop_link_get_mount (desktop_file->details->link);
if (mount != NULL) {
nautilus_file_operations_unmount_mount (NULL, mount, TRUE);
nautilus_file_operations_unmount_mount (NULL, mount, TRUE, TRUE);
}
}
}
......
......@@ -47,6 +47,7 @@
#include <eel/eel-gtk-extensions.h>
#include <eel/eel-stock-dialogs.h>
#include <eel/eel-vfs-extensions.h>
#include <eel/eel-mount-operation.h>
#include <glib/gstdio.h>
#include <gnome.h>
......@@ -1908,8 +1909,9 @@ prompt_empty_trash (GtkWindow *parent_window)
void
nautilus_file_operations_unmount_mount (GtkWindow *parent_window,
GMount *mount,
gboolean eject)
GMount *mount,
gboolean eject,
gboolean check_trash)
{
UnmountData *data;
int response;
......@@ -1921,7 +1923,7 @@ nautilus_file_operations_unmount_mount (GtkWindow *parent_w
data->eject = eject;
data->mount = g_object_ref (mount);
if (has_trash_files (mount)) {
if (check_trash && has_trash_files (mount)) {
response = prompt_empty_trash (parent_window);
if (response == GTK_RESPONSE_ACCEPT) {
......@@ -1950,6 +1952,45 @@ nautilus_file_operations_unmount_mount (GtkWindow *parent_w
do_unmount (data);
}
static void
volume_mount_cb (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
GMountOperation *mount_op = user_data;
GError *error;
char *primary;
char *name;
error = NULL;
if (!g_volume_mount_finish (G_VOLUME (source_object), res, &error)) {
if (error->code != G_IO_ERROR_FAILED_HANDLED) {
name = g_volume_get_name (G_VOLUME (source_object));
primary = g_strdup_printf (_("Unable to mount %s"), name);
g_free (name);
eel_show_error_dialog (primary,
error->message,
NULL);
g_free (primary);
}
g_error_free (error);
}
g_object_unref (mount_op);
}
void
nautilus_file_operations_mount_volume (GtkWindow *parent_window,
GVolume *volume)
{
GMountOperation *mount_op;
mount_op = eel_mount_operation_new (parent_window);
g_volume_mount (volume, mount_op, NULL, volume_mount_cb, mount_op);
}
static void
report_count_progress (CommonJob *job,
SourceInfo *source_info)
......
......@@ -87,8 +87,11 @@ void nautilus_file_set_permissions_recursive (const char *di
gpointer callback_data);
void nautilus_file_operations_unmount_mount (GtkWindow *parent_window,
GMount *mount,
gboolean eject);
GMount *mount,
gboolean eject,
gboolean check_trash);
void nautilus_file_operations_mount_volume (GtkWindow *parent_window,
GVolume *volume);
void nautilus_file_operations_copy (GList *files,
......
......@@ -483,7 +483,23 @@ static const PreferenceDefault preference_defaults[] = {
NULL,
default_network_link_name, g_free,
},
{ NAUTILUS_PREFERENCES_MEDIA_AUTOMOUNT,
PREFERENCE_BOOLEAN,
GINT_TO_POINTER (TRUE)
},
{ NAUTILUS_PREFERENCES_MEDIA_AUTOMOUNT_OPEN,
PREFERENCE_BOOLEAN,
GINT_TO_POINTER (TRUE)
},
{ NAUTILUS_PREFERENCES_MEDIA_AUTORUN_X_CONTENT_ASK,
PREFERENCE_STRING_ARRAY,
"", NULL, NULL, NULL
},
{ NAUTILUS_PREFERENCES_MEDIA_AUTORUN_X_CONTENT_IGNORE,
PREFERENCE_STRING_ARRAY,
"", NULL, NULL, NULL
},
{ NULL }
};
......
......@@ -46,6 +46,14 @@ G_BEGIN_DECLS
/* How wide the sidebar is (or how wide it will be when expanded) */
#define NAUTILUS_PREFERENCES_SIDEBAR_WIDTH "preferences/sidebar_width"
/* Automount options */
#define NAUTILUS_PREFERENCES_MEDIA_AUTOMOUNT "preferences/media_automount"
#define NAUTILUS_PREFERENCES_MEDIA_AUTOMOUNT_OPEN "preferences/media_automount_open"
/* Autorun options */
#define NAUTILUS_PREFERENCES_MEDIA_AUTORUN_X_CONTENT_ASK "preferences/media_autorun_x_content_ask"
#define NAUTILUS_PREFERENCES_MEDIA_AUTORUN_X_CONTENT_IGNORE "preferences/media_autorun_x_content_ignore"
/* Trash options */
#define NAUTILUS_PREFERENCES_CONFIRM_TRASH "preferences/confirm_trash"
#define NAUTILUS_PREFERENCES_ENABLE_DELETE "preferences/enable_delete"
......
......@@ -1098,7 +1098,7 @@ fm_tree_view_unmount_cb (GtkWidget *menu_item,
if (mount != NULL) {
nautilus_file_operations_unmount_mount (fm_tree_view_get_containing_window (view),
mount,
g_mount_can_eject (mount));
g_mount_can_eject (mount), TRUE);
}
}
......
......@@ -55,6 +55,7 @@
#include "nautilus-shell-interface.h"
#include "nautilus-shell.h"
#include "nautilus-window-bookmarks.h"
#include "nautilus-file-operations.h"
#include "nautilus-window-private.h"
#include "nautilus-window-manage-views.h"
#include <libxml/xmlsave.h>
......@@ -81,6 +82,7 @@
#include <libnautilus-private/nautilus-signaller.h>
#include <libnautilus-extension/nautilus-menu-provider.h>
#include <bonobo-activation/bonobo-activation.h>
#include <libnautilus-private/nautilus-autorun.h>
#ifdef HAVE_STARTUP_NOTIFICATION
#define SN_API_NOT_YET_FROZEN Yes_i_know_DO_IT
......@@ -107,12 +109,15 @@ static GList *nautilus_application_spatial_window_list;
static void desktop_changed_callback (gpointer user_data);
static void desktop_location_changed_callback (gpointer user_data);
static void mount_removed_callback (GVolumeMonitor *monitor,
GMount *mount,
NautilusApplication *application);
static void mount_added_callback (GVolumeMonitor *monitor,
GMount *mount,
NautilusApplication *application);
static void mount_removed_callback (GVolumeMonitor *monitor,
GMount *mount,
NautilusApplication *application);
static void mount_added_callback (GVolumeMonitor *monitor,
GMount *mount,
NautilusApplication *application);
static void volume_added_callback (GVolumeMonitor *monitor,
GVolume *volume,
NautilusApplication *application);
static void update_session (gpointer callback_data);
static void init_session (void);
static gboolean is_kdesktop_present (void);
......@@ -180,6 +185,8 @@ nautilus_application_instance_init (NautilusApplication *application)
G_CALLBACK (mount_removed_callback), application, 0);
g_signal_connect_object (application->volume_monitor, "mount_added",
G_CALLBACK (mount_added_callback), application, 0);
g_signal_connect_object (application->volume_monitor, "volume_added",
G_CALLBACK (volume_added_callback), application, 0);
/* register views */
fm_icon_view_register ();
......@@ -1303,6 +1310,16 @@ window_can_be_closed (NautilusWindow *window)
return FALSE;
}
static void
volume_added_callback (GVolumeMonitor *monitor,
GVolume *volume,
NautilusApplication *application)
{
if (eel_preferences_get_boolean (NAUTILUS_PREFERENCES_MEDIA_AUTOMOUNT)) {
nautilus_file_operations_mount_volume (NULL, volume);
}
}
static void
mount_added_callback (GVolumeMonitor *monitor,
GMount *mount,
......@@ -1318,6 +1335,8 @@ mount_added_callback (GVolumeMonitor *monitor,
nautilus_directory_force_reload (directory);
nautilus_directory_unref (directory);
}
nautilus_autorun (mount);
}
/* Called whenever a mount is unmounted. Check and see if there are
......
......@@ -50,6 +50,8 @@
#include <libnautilus-private/nautilus-global-preferences.h>
#include <libnautilus-private/nautilus-module.h>
#include <libnautilus-private/nautilus-autorun.h>
/* string enum preferences */
#define NAUTILUS_FILE_MANAGEMENT_PROPERTIES_DEFAULT_VIEW_WIDGET "default_view_combobox"
#define NAUTILUS_FILE_MANAGEMENT_PROPERTIES_ICON_VIEW_ZOOM_WIDGET "icon_view_zoom_combobox"
......@@ -72,6 +74,8 @@
#define NAUTILUS_FILE_MANAGEMENT_PROPERTIES_OPEN_NEW_WINDOW_WIDGET "new_window_checkbutton"
#define NAUTILUS_FILE_MANAGEMENT_PROPERTIES_SHOW_HIDDEN_WIDGET "hidden_files_checkbutton"
#define NAUTILUS_FILE_MANAGEMENT_PROPERTIES_TREE_VIEW_FOLDERS_WIDGET "treeview_folders_checkbutton"
#define NAUTILUS_FILE_MANAGEMENT_PROPERTIES_MEDIA_AUTOMOUNT "media_automount_checkbutton"
#define NAUTILUS_FILE_MANAGEMENT_PROPERTIES_MEDIA_AUTOMOUNT_OPEN "media_automount_open_checkbutton"
/* int enums */
#define NAUTILUS_FILE_MANAGEMENT_PROPERTIES_THUMBNAIL_LIMIT_WIDGET "preview_image_size_combobox"
......@@ -513,6 +517,26 @@ nautilus_file_management_properties_dialog_setup_list_column_page (GladeXML *xml
gtk_box_pack_start (GTK_BOX (box), chooser, TRUE, TRUE, 0);
}
static void
nautilus_file_management_properties_dialog_setup_media_page (GladeXML *xml_dialog)
{
unsigned int n;
const char *s[] = {"media_audio_cdda_combobox", "x-content/audio-cdda",
"media_video_dvd_combobox", "x-content/video-dvd",
"media_video_vcd_combobox", "x-content/video-vcd",
"media_video_svcd_combobox", "x-content/video-svcd",
"media_blank_combobox", "x-content/blank-media",
"media_music_player_combobox", "x-content/music-player",
"media_dcf_combobox", "x-content/image-dcf",
NULL};
for (n = 0; s[n*2] != NULL; n++) {
nautilus_autorun_prepare_combo_box (glade_xml_get_widget (xml_dialog, s[n*2]), s[n*2 + 1],
TRUE, TRUE, NULL, NULL);
}
}
static void
nautilus_file_management_properties_dialog_setup (GladeXML *xml_dialog, GtkWindow *window)
{
......@@ -553,6 +577,14 @@ nautilus_file_management_properties_dialog_setup (GladeXML *xml_dialog, GtkWindo
eel_preferences_glade_connect_bool (xml_dialog,
NAUTILUS_FILE_MANAGEMENT_PROPERTIES_ALWAYS_USE_BROWSER_WIDGET,
NAUTILUS_PREFERENCES_ALWAYS_USE_BROWSER);
eel_preferences_glade_connect_bool (xml_dialog,
NAUTILUS_FILE_MANAGEMENT_PROPERTIES_MEDIA_AUTOMOUNT,
NAUTILUS_PREFERENCES_MEDIA_AUTOMOUNT);
eel_preferences_glade_connect_bool (xml_dialog,
NAUTILUS_FILE_MANAGEMENT_PROPERTIES_MEDIA_AUTOMOUNT_OPEN,
NAUTILUS_PREFERENCES_MEDIA_AUTOMOUNT_OPEN);
eel_preferences_glade_connect_bool (xml_dialog,
NAUTILUS_FILE_MANAGEMENT_PROPERTIES_TRASH_CONFIRM_WIDGET,
NAUTILUS_PREFERENCES_CONFIRM_TRASH);
......@@ -626,6 +658,8 @@ nautilus_file_management_properties_dialog_setup (GladeXML *xml_dialog, GtkWindo
nautilus_file_management_properties_dialog_setup_icon_caption_page (xml_dialog);
nautilus_file_management_properties_dialog_setup_list_column_page (xml_dialog);
nautilus_file_management_properties_dialog_setup_media_page (xml_dialog);
/* UI callbacks */
dialog = glade_xml_get_widget (xml_dialog, "file_management_dialog");
......
......@@ -1266,33 +1266,6 @@ bookmarks_selection_changed_cb (GtkTreeSelection *selection,
bookmarks_check_popup_sensitivity (sidebar);
}
static void
volume_mount_cb (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
GMountOperation *mount_op = user_data;
GError *error;
char *primary;
char *name;
error = NULL;
if (!g_volume_mount_finish (G_VOLUME (source_object), res, &error)) {
if (error->code != G_IO_ERROR_FAILED_HANDLED) {
name = g_volume_get_name (G_VOLUME (source_object));
primary = g_strdup_printf (_("Unable to mount %s"), name);
g_free (name);
eel_show_error_dialog (primary,
error->message,
NULL);
g_free (primary);
}
g_error_free (error);
}
g_object_unref (mount_op);
}
static void
open_selected_bookmark (NautilusPlacesSidebar *sidebar,
GtkTreeModel *model,
......@@ -1339,9 +1312,7 @@ open_selected_bookmark (NautilusPlacesSidebar *sidebar,
GVolume *volume;
gtk_tree_model_get (model, &iter, PLACES_SIDEBAR_COLUMN_VOLUME, &volume, -1);
if (volume != NULL) {
GMountOperation *mount_op;
mount_op = g_mount_operation_new ();
g_volume_mount (volume, mount_op, NULL, volume_mount_cb, mount_op);
nautilus_file_operations_mount_volume (NULL, volume);
g_object_unref (volume);
}
}
......@@ -1456,9 +1427,7 @@ mount_shortcut_cb (GtkMenuItem *item,
-1);
if (volume != NULL) {
GMountOperation *mount_op;
mount_op = g_mount_operation_new ();
g_volume_mount (volume, mount_op, NULL, volume_mount_cb, mount_op);
nautilus_file_operations_mount_volume (NULL, volume);
g_object_unref (volume);
}
}
......@@ -1485,7 +1454,7 @@ unmount_shortcut_cb (GtkMenuItem *item,
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (sidebar->tree_view));
nautilus_file_operations_unmount_mount (GTK_WINDOW (toplevel),
mount, FALSE);
mount, FALSE, TRUE);
}
if (mount != NULL) {
g_object_unref (mount);
......@@ -2071,7 +2040,7 @@ nautilus_places_sidebar_iface_init (NautilusSidebarIface *iface)
static void
nautilus_places_sidebar_set_parent_window (NautilusPlacesSidebar *sidebar,
NautilusWindowInfo *window)
NautilusWindowInfo *window)
{
sidebar->window = window;