2008-01-14 13:17:36 +00:00
/* -*- 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 >
*/
# include <config.h>
# include <string.h>
# include <glib/gi18n.h>
# include <gio/gio.h>
# include <gtk/gtk.h>
# include <gdk/gdkx.h>
# include <gio/gdesktopappinfo.h>
2008-01-17 13:45:27 +00:00
# include <X11/XKBlib.h>
2008-01-14 13:17:36 +00:00
# include <eel/eel-glib-extensions.h>
# include <eel/eel-stock-dialogs.h>
# include "nautilus-icon-info.h"
# include "nautilus-global-preferences.h"
# include "nautilus-file-operations.h"
# include "nautilus-autorun.h"
# include "nautilus-program-choosing.h"
2008-01-17 13:45:27 +00:00
# include "nautilus-open-with-dialog.h"
# include "nautilus-desktop-icon-file.h"
2008-01-28 12:50:51 +00:00
# include "nautilus-file-utilities.h"
2008-01-14 13:17:36 +00:00
enum
{
AUTORUN_ASK ,
AUTORUN_IGNORE ,
AUTORUN_APP ,
2008-01-17 13:45:27 +00:00
AUTORUN_OPEN_FOLDER ,
2008-01-14 13:17:36 +00:00
AUTORUN_SEP ,
2008-07-29 21:40:22 +00:00
AUTORUN_OTHER_APP ,
2008-01-14 13:17:36 +00:00
} ;
enum
{
COLUMN_AUTORUN_PIXBUF ,
COLUMN_AUTORUN_NAME ,
COLUMN_AUTORUN_APP_INFO ,
COLUMN_AUTORUN_X_CONTENT_TYPE ,
2008-07-29 21:40:22 +00:00
COLUMN_AUTORUN_ITEM_TYPE ,
2008-01-14 13:17:36 +00:00
} ;
2008-01-30 15:52:03 +00:00
static gboolean should_autorun_mount ( GMount * mount ) ;
2008-07-29 21:40:22 +00:00
static void nautilus_autorun_rebuild_combo_box ( GtkWidget * combo_box ) ;
2008-01-14 13:17:36 +00:00
void
2008-07-29 21:40:22 +00:00
nautilus_autorun_get_preferences ( const char * x_content_type ,
gboolean * pref_start_app ,
gboolean * pref_ignore ,
2008-01-17 13:45:27 +00:00
gboolean * pref_open_folder )
2008-01-14 13:17:36 +00:00
{
2008-07-29 21:40:22 +00:00
char * * x_content_start_app ;
2008-01-14 13:17:36 +00:00
char * * x_content_ignore ;
2008-01-17 13:45:27 +00:00
char * * x_content_open_folder ;
2008-01-14 13:17:36 +00:00
2008-07-29 21:40:22 +00:00
g_return_if_fail ( pref_start_app ! = NULL ) ;
2008-01-14 13:17:36 +00:00
g_return_if_fail ( pref_ignore ! = NULL ) ;
2008-01-17 13:45:27 +00:00
g_return_if_fail ( pref_open_folder ! = NULL ) ;
2008-01-14 13:17:36 +00:00
2008-07-29 21:40:22 +00:00
* pref_start_app = FALSE ;
2008-01-14 13:17:36 +00:00
* pref_ignore = FALSE ;
2008-01-17 13:45:27 +00:00
* pref_open_folder = FALSE ;
2008-07-29 21:40:22 +00:00
x_content_start_app = eel_preferences_get_string_array ( NAUTILUS_PREFERENCES_MEDIA_AUTORUN_X_CONTENT_START_APP ) ;
2008-01-14 13:17:36 +00:00
x_content_ignore = eel_preferences_get_string_array ( NAUTILUS_PREFERENCES_MEDIA_AUTORUN_X_CONTENT_IGNORE ) ;
2008-01-17 13:45:27 +00:00
x_content_open_folder = eel_preferences_get_string_array ( NAUTILUS_PREFERENCES_MEDIA_AUTORUN_X_CONTENT_OPEN_FOLDER ) ;
2008-07-29 21:40:22 +00:00
if ( x_content_start_app ! = NULL ) {
* pref_start_app = eel_g_strv_find ( x_content_start_app , x_content_type ) ! = - 1 ;
2008-01-14 13:17:36 +00:00
}
if ( x_content_ignore ! = NULL ) {
* pref_ignore = eel_g_strv_find ( x_content_ignore , x_content_type ) ! = - 1 ;
}
2008-01-17 13:45:27 +00:00
if ( x_content_open_folder ! = NULL ) {
* pref_open_folder = eel_g_strv_find ( x_content_open_folder , x_content_type ) ! = - 1 ;
}
2008-01-14 13:17:36 +00:00
g_strfreev ( x_content_ignore ) ;
2008-07-29 21:40:22 +00:00
g_strfreev ( x_content_start_app ) ;
g_strfreev ( x_content_open_folder ) ;
2008-01-14 13:17:36 +00:00
}
static void
remove_elem_from_str_array ( char * * v , const char * s )
{
int n , m ;
2008-07-31 10:52:36 +00:00
if ( v = = NULL ) {
return ;
}
2008-01-14 13:17:36 +00:00
for ( n = 0 ; v [ n ] ! = NULL ; n + + ) {
if ( strcmp ( v [ n ] , s ) = = 0 ) {
for ( m = n + 1 ; v [ m ] ! = NULL ; m + + ) {
v [ m - 1 ] = v [ m ] ;
}
v [ m - 1 ] = NULL ;
n - - ;
}
}
}
static char * *
add_elem_to_str_array ( char * * v , const char * s )
{
guint len ;
char * * r ;
2008-07-31 10:52:36 +00:00
len = v ! = NULL ? g_strv_length ( v ) : 0 ;
2008-01-14 13:17:36 +00:00
r = g_new0 ( char * , len + 2 ) ;
memcpy ( r , v , len * sizeof ( char * ) ) ;
r [ len ] = g_strdup ( s ) ;
r [ len + 1 ] = NULL ;
g_free ( v ) ;
return r ;
}
void
2008-07-29 21:40:22 +00:00
nautilus_autorun_set_preferences ( const char * x_content_type ,
gboolean pref_start_app ,
gboolean pref_ignore ,
gboolean pref_open_folder )
2008-01-14 13:17:36 +00:00
{
2008-07-29 21:40:22 +00:00
char * * x_content_start_app ;
2008-01-14 13:17:36 +00:00
char * * x_content_ignore ;
2008-01-17 13:45:27 +00:00
char * * x_content_open_folder ;
2008-01-14 13:17:36 +00:00
2008-07-31 10:52:36 +00:00
g_assert ( x_content_type ! = NULL ) ;
2008-07-29 21:40:22 +00:00
x_content_start_app = eel_preferences_get_string_array ( NAUTILUS_PREFERENCES_MEDIA_AUTORUN_X_CONTENT_START_APP ) ;
2008-01-14 13:17:36 +00:00
x_content_ignore = eel_preferences_get_string_array ( NAUTILUS_PREFERENCES_MEDIA_AUTORUN_X_CONTENT_IGNORE ) ;
2008-01-17 13:45:27 +00:00
x_content_open_folder = eel_preferences_get_string_array ( NAUTILUS_PREFERENCES_MEDIA_AUTORUN_X_CONTENT_OPEN_FOLDER ) ;
2008-01-14 13:17:36 +00:00
2008-07-29 21:40:22 +00:00
remove_elem_from_str_array ( x_content_start_app , x_content_type ) ;
if ( pref_start_app ) {
x_content_start_app = add_elem_to_str_array ( x_content_start_app , x_content_type ) ;
2008-01-14 13:17:36 +00:00
}
2008-07-29 21:40:22 +00:00
eel_preferences_set_string_array ( NAUTILUS_PREFERENCES_MEDIA_AUTORUN_X_CONTENT_START_APP , x_content_start_app ) ;
2008-01-14 13:17:36 +00:00
remove_elem_from_str_array ( x_content_ignore , x_content_type ) ;
if ( pref_ignore ) {
x_content_ignore = add_elem_to_str_array ( x_content_ignore , x_content_type ) ;
}
eel_preferences_set_string_array ( NAUTILUS_PREFERENCES_MEDIA_AUTORUN_X_CONTENT_IGNORE , x_content_ignore ) ;
2008-01-17 13:45:27 +00:00
remove_elem_from_str_array ( x_content_open_folder , x_content_type ) ;
if ( pref_open_folder ) {
x_content_open_folder = add_elem_to_str_array ( x_content_open_folder , x_content_type ) ;
}
eel_preferences_set_string_array ( NAUTILUS_PREFERENCES_MEDIA_AUTORUN_X_CONTENT_OPEN_FOLDER , x_content_open_folder ) ;
g_strfreev ( x_content_open_folder ) ;
2008-01-14 13:17:36 +00:00
g_strfreev ( x_content_ignore ) ;
2008-07-29 21:40:22 +00:00
g_strfreev ( x_content_start_app ) ;
2008-01-14 13:17:36 +00:00
}
static gboolean
combo_box_separator_func ( GtkTreeModel * model ,
GtkTreeIter * iter ,
gpointer data )
{
char * str ;
gtk_tree_model_get ( model , iter ,
1 , & str ,
- 1 ) ;
if ( str ! = NULL ) {
g_free ( str ) ;
return FALSE ;
}
return TRUE ;
}
typedef struct
{
2008-01-17 13:45:27 +00:00
guint changed_signal_id ;
GtkWidget * combo_box ;
2008-07-29 21:40:22 +00:00
char * x_content_type ;
gboolean include_ask ;
gboolean include_open_with_other_app ;
2008-01-14 13:17:36 +00:00
gboolean update_settings ;
NautilusAutorunComboBoxChanged changed_cb ;
gpointer user_data ;
2008-07-29 21:40:22 +00:00
gboolean other_application_selected ;
2008-01-14 13:17:36 +00:00
} NautilusAutorunComboBoxData ;
2008-01-17 13:45:27 +00:00
static void
nautilus_autorun_combobox_data_destroy ( NautilusAutorunComboBoxData * data )
{
/* signal handler may be automatically disconnected by destroying the widget */
2008-01-18 13:34:41 +00:00
if ( g_signal_handler_is_connected ( G_OBJECT ( data - > combo_box ) , data - > changed_signal_id ) ) {
2008-01-17 13:45:27 +00:00
g_signal_handler_disconnect ( G_OBJECT ( data - > combo_box ) , data - > changed_signal_id ) ;
2008-01-18 13:34:41 +00:00
}
2008-07-29 21:40:22 +00:00
g_free ( data - > x_content_type ) ;
2008-01-17 13:45:27 +00:00
g_free ( data ) ;
}
2008-07-29 21:40:22 +00:00
static void
other_application_selected ( NautilusOpenWithDialog * dialog ,
GAppInfo * app_info ,
NautilusAutorunComboBoxData * data )
{
if ( data - > changed_cb ! = NULL ) {
data - > changed_cb ( TRUE , FALSE , FALSE , app_info , data - > user_data ) ;
}
if ( data - > update_settings ) {
nautilus_autorun_set_preferences ( data - > x_content_type , TRUE , FALSE , FALSE ) ;
g_app_info_set_as_default_for_type ( app_info ,
data - > x_content_type ,
NULL ) ;
data - > other_application_selected = TRUE ;
}
/* rebuild so we include and select the new application in the list */
nautilus_autorun_rebuild_combo_box ( data - > combo_box ) ;
}
2009-01-29 15:47:17 +00:00
static void
handle_dialog_closure ( NautilusAutorunComboBoxData * data )
{
if ( ! data - > other_application_selected ) {
/* reset combo box so we don't linger on "Open with other Application..." */
nautilus_autorun_rebuild_combo_box ( data - > combo_box ) ;
}
}
static void
dialog_response_cb ( GtkDialog * dialog ,
gint response ,
NautilusAutorunComboBoxData * data )
{
handle_dialog_closure ( data ) ;
}
static void
dialog_destroy_cb ( GtkObject * object ,
NautilusAutorunComboBoxData * data )
{
handle_dialog_closure ( data ) ;
}
2008-01-14 13:17:36 +00:00
static void
combo_box_changed ( GtkComboBox * combo_box ,
NautilusAutorunComboBoxData * data )
{
GtkTreeIter iter ;
GtkTreeModel * model ;
GAppInfo * app_info ;
char * x_content_type ;
int type ;
model = NULL ;
app_info = NULL ;
x_content_type = NULL ;
if ( ! gtk_combo_box_get_active_iter ( combo_box , & iter ) ) {
goto out ;
}
model = gtk_combo_box_get_model ( combo_box ) ;
if ( model = = NULL ) {
goto out ;
}
gtk_tree_model_get ( model , & iter ,
COLUMN_AUTORUN_APP_INFO , & app_info ,
COLUMN_AUTORUN_X_CONTENT_TYPE , & x_content_type ,
COLUMN_AUTORUN_ITEM_TYPE , & type ,
- 1 ) ;
switch ( type ) {
case AUTORUN_ASK :
if ( data - > changed_cb ! = NULL ) {
2008-01-17 13:45:27 +00:00
data - > changed_cb ( TRUE , FALSE , FALSE , NULL , data - > user_data ) ;
2008-01-14 13:17:36 +00:00
}
if ( data - > update_settings ) {
2008-07-29 21:40:22 +00:00
nautilus_autorun_set_preferences ( x_content_type , FALSE , FALSE , FALSE ) ;
2008-01-14 13:17:36 +00:00
}
break ;
case AUTORUN_IGNORE :
if ( data - > changed_cb ! = NULL ) {
2008-01-17 13:45:27 +00:00
data - > changed_cb ( FALSE , TRUE , FALSE , NULL , data - > user_data ) ;
2008-01-14 13:17:36 +00:00
}
if ( data - > update_settings ) {
2008-01-17 13:45:27 +00:00
nautilus_autorun_set_preferences ( x_content_type , FALSE , TRUE , FALSE ) ;
}
break ;
case AUTORUN_OPEN_FOLDER :
if ( data - > changed_cb ! = NULL ) {
data - > changed_cb ( FALSE , FALSE , TRUE , NULL , data - > user_data ) ;
}
if ( data - > update_settings ) {
nautilus_autorun_set_preferences ( x_content_type , FALSE , FALSE , TRUE ) ;
2008-01-14 13:17:36 +00:00
}
break ;
2008-07-29 21:40:22 +00:00
2008-01-14 13:17:36 +00:00
case AUTORUN_APP :
if ( data - > changed_cb ! = NULL ) {
2008-07-29 21:40:22 +00:00
/* TODO TODO?? */
data - > changed_cb ( TRUE , FALSE , FALSE , app_info , data - > user_data ) ;
2008-01-14 13:17:36 +00:00
}
if ( data - > update_settings ) {
2008-07-29 21:40:22 +00:00
nautilus_autorun_set_preferences ( x_content_type , TRUE , FALSE , FALSE ) ;
2008-01-14 13:17:36 +00:00
g_app_info_set_as_default_for_type ( app_info ,
x_content_type ,
NULL ) ;
}
break ;
2008-07-29 21:40:22 +00:00
case AUTORUN_OTHER_APP :
{
GtkWidget * dialog ;
data - > other_application_selected = FALSE ;
dialog = nautilus_add_application_dialog_new ( NULL , x_content_type ) ;
2009-01-29 15:47:17 +00:00
gtk_window_set_transient_for ( GTK_WINDOW ( dialog ) ,
GTK_WINDOW ( gtk_widget_get_toplevel ( GTK_WIDGET ( combo_box ) ) ) ) ;
2008-07-29 21:40:22 +00:00
g_signal_connect ( dialog , " application_selected " ,
G_CALLBACK ( other_application_selected ) ,
data ) ;
2009-01-29 15:47:17 +00:00
g_signal_connect ( dialog , " response " ,
G_CALLBACK ( dialog_response_cb ) , data ) ;
g_signal_connect ( dialog , " destroy " ,
G_CALLBACK ( dialog_destroy_cb ) , data ) ;
gtk_widget_show ( GTK_WIDGET ( dialog ) ) ;
2008-07-29 21:40:22 +00:00
break ;
}
2008-01-14 13:17:36 +00:00
}
out :
if ( app_info ! = NULL ) {
g_object_unref ( app_info ) ;
}
g_free ( x_content_type ) ;
}
2008-07-29 21:40:22 +00:00
static void
nautilus_autorun_rebuild_combo_box ( GtkWidget * combo_box )
{
NautilusAutorunComboBoxData * data ;
data = g_object_get_data ( G_OBJECT ( combo_box ) , " nautilus_autorun_combobox_data " ) ;
if ( data = = NULL ) {
g_warning ( " no 'nautilus_autorun_combobox_data' data! " ) ;
return ;
}
nautilus_autorun_prepare_combo_box ( combo_box ,
data - > x_content_type ,
data - > include_ask ,
data - > include_open_with_other_app ,
data - > update_settings ,
data - > changed_cb ,
data - > user_data ) ;
}
/* TODO: we need some kind of way to remove user-defined associations,
* e . g . the result of " Open with other Application... " .
*
* However , this is a bit hard as
* g_app_info_can_remove_supports_type ( ) will always return TRUE
* because we now have [ Removed Applications ] in the file
* ~ / . local / share / applications / mimeapps . list .
*
* We need the API outlined in
*
* http : //bugzilla.gnome.org/show_bug.cgi?id=545350
*
* to do this .
*
* Now , there ' s also the question about what the UI would look like
* given this API . Ideally we ' d include a small button on the right
* side of the combo box that the user can press to delete an
* association , e . g . :
*
* + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
* | Ask what to do |
* | Do Nothing |
* | Open Folder |
* + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
* | Open Rhythmbox Music Player |
* | Open Audio CD Extractor |
* | Open Banshee Media Player |
* | Open Frobnicator App [ x ] |
* + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
* | Open with other Application . . . |
* + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
*
* where " Frobnicator App " have been set up using " Open with other
* Application . . . " . However this is not accessible (which is a
* GTK + issue ) but probably not a big deal .
*
* And we only want show these buttons ( e . g . [ x ] ) for associations with
* GAppInfo instances that are deletable .
*/
2008-01-14 13:17:36 +00:00
void
2008-07-29 21:40:22 +00:00
nautilus_autorun_prepare_combo_box ( GtkWidget * combo_box ,
2008-01-14 13:17:36 +00:00
const char * x_content_type ,
gboolean include_ask ,
2008-07-29 21:40:22 +00:00
gboolean include_open_with_other_app ,
2008-01-14 13:17:36 +00:00
gboolean update_settings ,
NautilusAutorunComboBoxChanged changed_cb ,
gpointer user_data )
{
GList * l ;
GList * app_info_list ;
GAppInfo * default_app_info ;
GtkListStore * list_store ;
GtkTreeIter iter ;
GdkPixbuf * pixbuf ;
int icon_size ;
int set_active ;
int n ;
int num_apps ;
gboolean pref_ask ;
2008-07-29 21:40:22 +00:00
gboolean pref_start_app ;
2008-01-14 13:17:36 +00:00
gboolean pref_ignore ;
2008-01-17 13:45:27 +00:00
gboolean pref_open_folder ;
2008-01-14 13:17:36 +00:00
NautilusAutorunComboBoxData * data ;
GtkCellRenderer * renderer ;
2008-07-29 21:40:22 +00:00
nautilus_autorun_get_preferences ( x_content_type , & pref_start_app , & pref_ignore , & pref_open_folder ) ;
pref_ask = ! pref_start_app & & ! pref_ignore & & ! pref_open_folder ;
2008-01-14 13:17:36 +00:00
icon_size = nautilus_get_icon_size_for_stock_size ( GTK_ICON_SIZE_MENU ) ;
set_active = - 1 ;
2008-01-17 13:45:27 +00:00
data = NULL ;
2008-01-14 13:17:36 +00:00
app_info_list = g_app_info_get_all_for_type ( x_content_type ) ;
default_app_info = g_app_info_get_default_for_type ( x_content_type , FALSE ) ;
num_apps = g_list_length ( app_info_list ) ;
2008-07-29 21:40:22 +00:00
list_store = gtk_list_store_new ( 5 ,
GDK_TYPE_PIXBUF ,
G_TYPE_STRING ,
G_TYPE_APP_INFO ,
2008-01-14 13:17:36 +00:00
G_TYPE_STRING ,
G_TYPE_INT ) ;
/* no apps installed */
if ( num_apps = = 0 ) {
gtk_list_store_append ( list_store , & iter ) ;
pixbuf = gtk_icon_theme_load_icon ( gtk_icon_theme_get_default ( ) ,
GTK_STOCK_DIALOG_ERROR ,
icon_size ,
0 ,
NULL ) ;
/* TODO: integrate with PackageKit-gnome to find applications */
gtk_list_store_set ( list_store , & iter ,
COLUMN_AUTORUN_PIXBUF , pixbuf ,
COLUMN_AUTORUN_NAME , _ ( " No applications found " ) ,
COLUMN_AUTORUN_APP_INFO , NULL ,
COLUMN_AUTORUN_X_CONTENT_TYPE , x_content_type ,
COLUMN_AUTORUN_ITEM_TYPE , AUTORUN_ASK ,
- 1 ) ;
g_object_unref ( pixbuf ) ;
} else {
if ( include_ask ) {
gtk_list_store_append ( list_store , & iter ) ;
pixbuf = gtk_icon_theme_load_icon ( gtk_icon_theme_get_default ( ) ,
GTK_STOCK_DIALOG_QUESTION ,
icon_size ,
0 ,
NULL ) ;
gtk_list_store_set ( list_store , & iter ,
COLUMN_AUTORUN_PIXBUF , pixbuf ,
COLUMN_AUTORUN_NAME , _ ( " Ask what to do " ) ,
COLUMN_AUTORUN_APP_INFO , NULL ,
COLUMN_AUTORUN_X_CONTENT_TYPE , x_content_type ,
COLUMN_AUTORUN_ITEM_TYPE , AUTORUN_ASK ,
- 1 ) ;
g_object_unref ( pixbuf ) ;
}
gtk_list_store_append ( list_store , & iter ) ;
pixbuf = gtk_icon_theme_load_icon ( gtk_icon_theme_get_default ( ) ,
2008-01-17 13:45:27 +00:00
GTK_STOCK_CLOSE ,
2008-01-14 13:17:36 +00:00
icon_size ,
0 ,
NULL ) ;
gtk_list_store_set ( list_store , & iter ,
COLUMN_AUTORUN_PIXBUF , pixbuf ,
COLUMN_AUTORUN_NAME , _ ( " Do Nothing " ) ,
COLUMN_AUTORUN_APP_INFO , NULL ,
COLUMN_AUTORUN_X_CONTENT_TYPE , x_content_type ,
COLUMN_AUTORUN_ITEM_TYPE , AUTORUN_IGNORE ,
- 1 ) ;
2008-01-17 13:45:27 +00:00
g_object_unref ( pixbuf ) ;
gtk_list_store_append ( list_store , & iter ) ;
pixbuf = gtk_icon_theme_load_icon ( gtk_icon_theme_get_default ( ) ,
" nautilus " ,
icon_size ,
0 ,
NULL ) ;
gtk_list_store_set ( list_store , & iter ,
COLUMN_AUTORUN_PIXBUF , pixbuf ,
COLUMN_AUTORUN_NAME , _ ( " Open Folder " ) ,
COLUMN_AUTORUN_APP_INFO , NULL ,
COLUMN_AUTORUN_X_CONTENT_TYPE , x_content_type ,
COLUMN_AUTORUN_ITEM_TYPE , AUTORUN_OPEN_FOLDER ,
- 1 ) ;
g_object_unref ( pixbuf ) ;
2008-01-14 13:17:36 +00:00
gtk_list_store_append ( list_store , & iter ) ;
gtk_list_store_set ( list_store , & iter ,
COLUMN_AUTORUN_PIXBUF , NULL ,
COLUMN_AUTORUN_NAME , NULL ,
COLUMN_AUTORUN_APP_INFO , NULL ,
COLUMN_AUTORUN_X_CONTENT_TYPE , NULL ,
COLUMN_AUTORUN_ITEM_TYPE , AUTORUN_SEP ,
- 1 ) ;
2008-01-17 13:45:27 +00:00
for ( l = app_info_list , n = include_ask ? 4 : 3 ; l ! = NULL ; l = l - > next , n + + ) {
2008-01-14 13:17:36 +00:00
GIcon * icon ;
NautilusIconInfo * icon_info ;
char * open_string ;
GAppInfo * app_info = l - > data ;
/* we deliberately ignore should_show because some apps might want
* to install special handlers that should be hidden in the regular
* application launcher menus
*/
icon = g_app_info_get_icon ( app_info ) ;
icon_info = nautilus_icon_info_lookup ( icon , icon_size ) ;
pixbuf = nautilus_icon_info_get_pixbuf_at_size ( icon_info , icon_size ) ;
g_object_unref ( icon_info ) ;
open_string = g_strdup_printf ( _ ( " Open %s " ) , g_app_info_get_name ( app_info ) ) ;
2008-01-17 13:45:27 +00:00
2008-01-14 13:17:36 +00:00
gtk_list_store_append ( list_store , & iter ) ;
gtk_list_store_set ( list_store , & iter ,
COLUMN_AUTORUN_PIXBUF , pixbuf ,
COLUMN_AUTORUN_NAME , open_string ,
COLUMN_AUTORUN_APP_INFO , app_info ,
COLUMN_AUTORUN_X_CONTENT_TYPE , x_content_type ,
COLUMN_AUTORUN_ITEM_TYPE , AUTORUN_APP ,
- 1 ) ;
if ( pixbuf ! = NULL ) {
g_object_unref ( pixbuf ) ;
}
g_free ( open_string ) ;
if ( g_app_info_equal ( app_info , default_app_info ) ) {
set_active = n ;
}
}
}
2008-07-29 21:40:22 +00:00
if ( include_open_with_other_app ) {
gtk_list_store_append ( list_store , & iter ) ;
gtk_list_store_set ( list_store , & iter ,
COLUMN_AUTORUN_PIXBUF , NULL ,
COLUMN_AUTORUN_NAME , NULL ,
COLUMN_AUTORUN_APP_INFO , NULL ,
COLUMN_AUTORUN_X_CONTENT_TYPE , NULL ,
COLUMN_AUTORUN_ITEM_TYPE , AUTORUN_SEP ,
- 1 ) ;
gtk_list_store_append ( list_store , & iter ) ;
pixbuf = gtk_icon_theme_load_icon ( gtk_icon_theme_get_default ( ) ,
" application-x-executable " ,
icon_size ,
0 ,
NULL ) ;
gtk_list_store_set ( list_store , & iter ,
COLUMN_AUTORUN_PIXBUF , pixbuf ,
COLUMN_AUTORUN_NAME , _ ( " Open with other Application... " ) ,
COLUMN_AUTORUN_APP_INFO , NULL ,
COLUMN_AUTORUN_X_CONTENT_TYPE , x_content_type ,
COLUMN_AUTORUN_ITEM_TYPE , AUTORUN_OTHER_APP ,
- 1 ) ;
g_object_unref ( pixbuf ) ;
}
2008-01-14 13:17:36 +00:00
if ( default_app_info ! = NULL ) {
g_object_unref ( default_app_info ) ;
}
eel_g_object_list_free ( app_info_list ) ;
gtk_combo_box_set_model ( GTK_COMBO_BOX ( combo_box ) , GTK_TREE_MODEL ( list_store ) ) ;
2008-07-31 10:52:36 +00:00
g_object_unref ( G_OBJECT ( list_store ) ) ;
2008-01-14 13:17:36 +00:00
2008-01-17 13:45:27 +00:00
gtk_cell_layout_clear ( GTK_CELL_LAYOUT ( combo_box ) ) ;
2008-01-14 13:17:36 +00:00
renderer = gtk_cell_renderer_pixbuf_new ( ) ;
gtk_cell_layout_pack_start ( GTK_CELL_LAYOUT ( combo_box ) , renderer , FALSE ) ;
gtk_cell_layout_set_attributes ( GTK_CELL_LAYOUT ( combo_box ) , renderer ,
2008-01-17 13:45:27 +00:00
" pixbuf " , COLUMN_AUTORUN_PIXBUF ,
2008-01-14 13:17:36 +00:00
NULL ) ;
renderer = gtk_cell_renderer_text_new ( ) ;
gtk_cell_layout_pack_start ( GTK_CELL_LAYOUT ( combo_box ) , renderer , TRUE ) ;
gtk_cell_layout_set_attributes ( GTK_CELL_LAYOUT ( combo_box ) , renderer ,
2008-01-17 13:45:27 +00:00
" text " , COLUMN_AUTORUN_NAME ,
2008-01-14 13:17:36 +00:00
NULL ) ;
gtk_combo_box_set_row_separator_func ( GTK_COMBO_BOX ( combo_box ) , combo_box_separator_func , NULL , NULL ) ;
if ( num_apps = = 0 ) {
gtk_combo_box_set_active ( GTK_COMBO_BOX ( combo_box ) , 0 ) ;
gtk_widget_set_sensitive ( combo_box , FALSE ) ;
} else {
2008-01-17 13:45:27 +00:00
gtk_widget_set_sensitive ( combo_box , TRUE ) ;
2008-01-14 13:17:36 +00:00
if ( pref_ask & & include_ask ) {
gtk_combo_box_set_active ( GTK_COMBO_BOX ( combo_box ) , 0 ) ;
} else if ( pref_ignore ) {
gtk_combo_box_set_active ( GTK_COMBO_BOX ( combo_box ) , include_ask ? 1 : 0 ) ;
2008-01-17 13:45:27 +00:00
} else if ( pref_open_folder ) {
gtk_combo_box_set_active ( GTK_COMBO_BOX ( combo_box ) , include_ask ? 2 : 1 ) ;
2008-01-14 13:17:36 +00:00
} else if ( set_active ! = - 1 ) {
gtk_combo_box_set_active ( GTK_COMBO_BOX ( combo_box ) , set_active ) ;
} else {
gtk_combo_box_set_active ( GTK_COMBO_BOX ( combo_box ) , include_ask ? 1 : 0 ) ;
}
data = g_new0 ( NautilusAutorunComboBoxData , 1 ) ;
2008-07-29 21:40:22 +00:00
data - > x_content_type = g_strdup ( x_content_type ) ;
data - > include_ask = include_ask ;
data - > include_open_with_other_app = include_open_with_other_app ;
2008-01-14 13:17:36 +00:00
data - > update_settings = update_settings ;
data - > changed_cb = changed_cb ;
data - > user_data = user_data ;
2008-01-17 13:45:27 +00:00
data - > combo_box = combo_box ;
data - > changed_signal_id = g_signal_connect ( G_OBJECT ( combo_box ) ,
" changed " ,
G_CALLBACK ( combo_box_changed ) ,
data ) ;
2008-01-14 13:17:36 +00:00
}
2008-01-17 13:45:27 +00:00
g_object_set_data_full ( G_OBJECT ( combo_box ) ,
" nautilus_autorun_combobox_data " ,
data ,
( GDestroyNotify ) nautilus_autorun_combobox_data_destroy ) ;
}
2008-01-14 13:17:36 +00:00
static gboolean
is_shift_pressed ( void )
{
gboolean ret ;
XkbStateRec state ;
Bool status ;
ret = FALSE ;
gdk_error_trap_push ( ) ;
status = XkbGetState ( GDK_DISPLAY ( ) , XkbUseCoreKbd , & state ) ;
gdk_error_trap_pop ( ) ;
if ( status = = Success ) {
ret = state . mods & ShiftMask ;
}
return ret ;
}
2008-02-25 11:58:02 +00:00
enum {
AUTORUN_DIALOG_RESPONSE_EJECT = 0
} ;
2008-01-14 13:17:36 +00:00
typedef struct
{
2008-01-17 13:45:27 +00:00
GtkWidget * dialog ;
2008-01-14 13:17:36 +00:00
GMount * mount ;
gboolean should_eject ;
gboolean selected_ignore ;
2008-01-17 13:45:27 +00:00
gboolean selected_open_folder ;
2008-01-14 13:17:36 +00:00
GAppInfo * selected_app ;
gboolean remember ;
char * x_content_type ;
2008-01-17 13:45:27 +00:00
NautilusAutorunOpenWindow open_window_func ;
gpointer user_data ;
2008-01-14 13:17:36 +00:00
} AutorunDialogData ;
2008-01-17 13:45:27 +00:00
void
nautilus_autorun_launch_for_mount ( GMount * mount , GAppInfo * app_info )
2008-01-14 13:17:36 +00:00
{
GFile * root ;
NautilusFile * file ;
GList * files ;
root = g_mount_get_root ( mount ) ;
file = nautilus_file_get ( root ) ;
g_object_unref ( root ) ;
files = g_list_append ( NULL , file ) ;
nautilus_launch_application ( app_info ,
files ,
NULL ) ; /* TODO: what to set here? */
g_object_unref ( file ) ;
g_list_free ( files ) ;
}
2008-01-17 13:45:27 +00:00
static void autorun_dialog_mount_unmounted ( GMount * mount , AutorunDialogData * data ) ;
static void
autorun_dialog_destroy ( AutorunDialogData * data )
{
g_signal_handlers_disconnect_by_func ( G_OBJECT ( data - > mount ) ,
G_CALLBACK ( autorun_dialog_mount_unmounted ) ,
data ) ;
gtk_widget_destroy ( GTK_WIDGET ( data - > dialog ) ) ;
if ( data - > selected_app ! = NULL ) {
g_object_unref ( data - > selected_app ) ;
}
g_object_unref ( data - > mount ) ;
g_free ( data - > x_content_type ) ;
g_free ( data ) ;
}
static void
autorun_dialog_mount_unmounted ( GMount * mount , AutorunDialogData * data )
{
/* remove the dialog if the media is unmounted */
autorun_dialog_destroy ( data ) ;
}
2008-01-14 13:17:36 +00:00
static void
autorun_dialog_response ( GtkDialog * dialog , gint response , AutorunDialogData * data )
{
switch ( response ) {
2008-02-25 11:58:02 +00:00
case AUTORUN_DIALOG_RESPONSE_EJECT :
nautilus_file_operations_unmount_mount ( GTK_WINDOW ( dialog ) ,
data - > mount ,
data - > should_eject ,
FALSE ) ;
break ;
2008-01-14 13:17:36 +00:00
case GTK_RESPONSE_NONE :
/* window was closed */
break ;
case GTK_RESPONSE_CANCEL :
break ;
case GTK_RESPONSE_OK :
/* do the selected action */
if ( data - > remember ) {
/* make sure we don't ask again */
2008-07-29 21:40:22 +00:00
nautilus_autorun_set_preferences ( data - > x_content_type , TRUE , data - > selected_ignore , data - > selected_open_folder ) ;
2008-01-17 13:45:27 +00:00
if ( ! data - > selected_ignore & & ! data - > selected_open_folder & & data - > selected_app ! = NULL ) {
2008-01-14 13:17:36 +00:00
g_app_info_set_as_default_for_type ( data - > selected_app ,
data - > x_content_type ,
NULL ) ;
}
} else {
/* make sure we do ask again */
2008-07-29 21:40:22 +00:00
nautilus_autorun_set_preferences ( data - > x_content_type , FALSE , FALSE , FALSE ) ;
2008-01-14 13:17:36 +00:00
}
2008-01-17 13:45:27 +00:00
if ( ! data - > selected_ignore & & ! data - > selected_open_folder & & data - > selected_app ! = NULL ) {
nautilus_autorun_launch_for_mount ( data - > mount , data - > selected_app ) ;
} else if ( ! data - > selected_ignore & & data - > selected_open_folder ) {
if ( data - > open_window_func ! = NULL )
data - > open_window_func ( data - > mount , data - > user_data ) ;
2008-01-14 13:17:36 +00:00
}
break ;
}
2008-01-17 13:45:27 +00:00
autorun_dialog_destroy ( data ) ;
2008-01-14 13:17:36 +00:00
}
static void
autorun_combo_changed ( gboolean selected_ask ,
gboolean selected_ignore ,
2008-01-17 13:45:27 +00:00
gboolean selected_open_folder ,
2008-01-14 13:17:36 +00:00
GAppInfo * selected_app ,
gpointer user_data )
{
AutorunDialogData * data = user_data ;
if ( data - > selected_app ! = NULL ) {
g_object_unref ( data - > selected_app ) ;
}
data - > selected_app = selected_app ! = NULL ? g_object_ref ( selected_app ) : NULL ;
data - > selected_ignore = selected_ignore ;
2008-01-17 13:45:27 +00:00
data - > selected_open_folder = selected_open_folder ;
2008-01-14 13:17:36 +00:00
}
static void
autorun_always_toggled ( GtkToggleButton * togglebutton , AutorunDialogData * data )
{
data - > remember = gtk_toggle_button_get_active ( togglebutton ) ;
}
2008-01-17 13:45:27 +00:00
/* returns TRUE if a folder window should be opened */
static gboolean
do_autorun_for_content_type ( GMount * mount , const char * x_content_type , NautilusAutorunOpenWindow open_window_func , gpointer user_data )
2008-01-14 13:17:36 +00:00
{
AutorunDialogData * data ;
GtkWidget * dialog ;
GtkWidget * hbox ;
GtkWidget * vbox ;
GtkWidget * label ;
GtkWidget * combo_box ;
GtkWidget * always_check_button ;
GtkWidget * eject_button ;
GtkWidget * image ;
char * markup ;
char * content_description ;
char * mount_name ;
GIcon * icon ;
GdkPixbuf * pixbuf ;
NautilusIconInfo * icon_info ;
int icon_size ;
gboolean user_forced_dialog ;
gboolean pref_ask ;
2008-07-29 21:40:22 +00:00
gboolean pref_start_app ;
2008-01-14 13:17:36 +00:00
gboolean pref_ignore ;
2008-01-17 13:45:27 +00:00
gboolean pref_open_folder ;
2008-01-14 13:17:36 +00:00
char * media_greeting ;
2008-01-17 13:45:27 +00:00
gboolean ret ;
2008-01-14 13:17:36 +00:00
2008-01-17 13:45:27 +00:00
ret = FALSE ;
2008-01-14 13:17:36 +00:00
mount_name = NULL ;
user_forced_dialog = is_shift_pressed ( ) ;
2008-07-29 21:40:22 +00:00
nautilus_autorun_get_preferences ( x_content_type , & pref_start_app , & pref_ignore , & pref_open_folder ) ;
pref_ask = ! pref_start_app & & ! pref_ignore & & ! pref_open_folder ;
2008-01-14 13:17:36 +00:00
if ( user_forced_dialog ) {
goto show_dialog ;
}
2008-01-17 13:45:27 +00:00
if ( ! pref_ask & & ! pref_ignore & & ! pref_open_folder ) {
2008-01-14 13:17:36 +00:00
GAppInfo * app_info ;
app_info = g_app_info_get_default_for_type ( x_content_type , FALSE ) ;
if ( app_info ! = NULL ) {
2008-01-17 13:45:27 +00:00
nautilus_autorun_launch_for_mount ( mount , app_info ) ;
2008-01-14 13:17:36 +00:00
}
goto out ;
}
2008-01-17 13:45:27 +00:00
if ( pref_open_folder ) {
ret = TRUE ;
goto out ;
}
2008-01-14 13:17:36 +00:00
if ( pref_ignore ) {
goto out ;
}
show_dialog :
mount_name = g_mount_get_name ( mount ) ;
dialog = gtk_dialog_new ( ) ;
gtk_dialog_set_has_separator ( GTK_DIALOG ( dialog ) , FALSE ) ;
hbox = gtk_hbox_new ( FALSE , 12 ) ;
gtk_box_pack_start_defaults ( GTK_BOX ( GTK_DIALOG ( dialog ) - > vbox ) , hbox ) ;
gtk_container_set_border_width ( GTK_CONTAINER ( hbox ) , 12 ) ;
icon = g_mount_get_icon ( mount ) ;
icon_size = nautilus_get_icon_size_for_stock_size ( GTK_ICON_SIZE_DIALOG ) ;
icon_info = nautilus_icon_info_lookup ( icon , icon_size ) ;
pixbuf = nautilus_icon_info_get_pixbuf_at_size ( icon_info , icon_size ) ;
g_object_unref ( icon_info ) ;
2008-01-17 13:45:27 +00:00
g_object_unref ( icon ) ;
2008-01-14 13:17:36 +00:00
image = gtk_image_new_from_pixbuf ( pixbuf ) ;
gtk_misc_set_alignment ( GTK_MISC ( image ) , 0.5 , 0.0 ) ;
gtk_box_pack_start_defaults ( GTK_BOX ( hbox ) , image ) ;
/* also use the icon on the dialog */
gtk_window_set_title ( GTK_WINDOW ( dialog ) , mount_name ) ;
gtk_window_set_icon ( GTK_WINDOW ( dialog ) , pixbuf ) ;
2008-09-16 18:20:42 +00:00
gtk_window_set_position ( GTK_WINDOW ( dialog ) , GTK_WIN_POS_CENTER ) ;
2008-01-14 13:17:36 +00:00
g_object_unref ( pixbuf ) ;
vbox = gtk_vbox_new ( FALSE , 12 ) ;
gtk_box_pack_start_defaults ( GTK_BOX ( hbox ) , vbox ) ;
label = gtk_label_new ( NULL ) ;
2008-01-17 13:45:27 +00:00
/* Customize greeting for well-known x-content types */
2008-01-14 13:17:36 +00:00
if ( strcmp ( x_content_type , " x-content/audio-cdda " ) = = 0 ) {
2008-01-17 13:45:27 +00:00
media_greeting = _ ( " You have just inserted an Audio CD. " ) ;
} else if ( strcmp ( x_content_type , " x-content/audio-dvd " ) = = 0 ) {
media_greeting = _ ( " You have just inserted an Audio DVD. " ) ;
2008-01-14 13:17:36 +00:00
} else if ( strcmp ( x_content_type , " x-content/video-dvd " ) = = 0 ) {
2008-01-17 13:45:27 +00:00
media_greeting = _ ( " You have just inserted a Video DVD. " ) ;
2008-01-14 13:17:36 +00:00
} else if ( strcmp ( x_content_type , " x-content/video-vcd " ) = = 0 ) {
2008-01-17 13:45:27 +00:00
media_greeting = _ ( " You have just inserted a Video CD. " ) ;
2008-01-14 13:17:36 +00:00
} else if ( strcmp ( x_content_type , " x-content/video-svcd " ) = = 0 ) {
2008-01-17 13:45:27 +00:00
media_greeting = _ ( " You have just inserted a Super Video CD. " ) ;
} else if ( strcmp ( x_content_type , " x-content/blank-cd " ) = = 0 ) {
media_greeting = _ ( " You have just inserted a blank CD. " ) ;
} else if ( strcmp ( x_content_type , " x-content/blank-dvd " ) = = 0 ) {
media_greeting = _ ( " You have just inserted a blank DVD. " ) ;
} else if ( strcmp ( x_content_type , " x-content/blank-cd " ) = = 0 ) {
media_greeting = _ ( " You have just inserted a blank Blu-Ray disc. " ) ;
} else if ( strcmp ( x_content_type , " x-content/blank-cd " ) = = 0 ) {
media_greeting = _ ( " You have just inserted a blank HD DVD. " ) ;
} else if ( strcmp ( x_content_type , " x-content/image-photocd " ) = = 0 ) {
media_greeting = _ ( " You have just inserted a Photo CD. " ) ;
} else if ( strcmp ( x_content_type , " x-content/image-picturecd " ) = = 0 ) {
media_greeting = _ ( " You have just inserted a Picture CD. " ) ;
2008-01-14 13:17:36 +00:00
} else if ( strcmp ( x_content_type , " x-content/image-dcf " ) = = 0 ) {
2008-05-23 22:39:48 +00:00
media_greeting = _ ( " You have just inserted a medium with digital photos. " ) ;
2008-01-17 13:45:27 +00:00
} else if ( strcmp ( x_content_type , " x-content/audio-player " ) = = 0 ) {
media_greeting = _ ( " You have just inserted a digital audio player. " ) ;
} else if ( strcmp ( x_content_type , " x-content/software " ) = = 0 ) {
2008-05-23 22:39:48 +00:00
media_greeting = _ ( " You have just inserted a medium with software intended to be automatically started. " ) ;
2008-01-14 13:17:36 +00:00
} else {
2008-01-17 13:45:27 +00:00
/* fallback to generic greeting */
2008-05-23 22:39:48 +00:00
media_greeting = _ ( " You have just inserted a medium. " ) ;
2008-01-14 13:17:36 +00:00
}
2008-01-17 13:45:27 +00:00
markup = g_strdup_printf ( " <big><b>%s %s</b></big> " , media_greeting , _ ( " Choose what application to launch. " ) ) ;
2008-01-14 13:17:36 +00:00
gtk_label_set_markup ( GTK_LABEL ( label ) , markup ) ;
g_free ( markup ) ;
gtk_label_set_line_wrap ( GTK_LABEL ( label ) , TRUE ) ;
gtk_misc_set_alignment ( GTK_MISC ( label ) , 0.0 , 0.5 ) ;
gtk_box_pack_start_defaults ( GTK_BOX ( vbox ) , label ) ;
label = gtk_label_new ( NULL ) ;
content_description = g_content_type_get_description ( x_content_type ) ;
markup = g_strdup_printf ( _ ( " Select how to open \" %s \" and whether to perform this action in the future for other media of type \" %s \" . " ) , mount_name , content_description ) ;
g_free ( content_description ) ;
gtk_label_set_markup ( GTK_LABEL ( label ) , markup ) ;
g_free ( markup ) ;
gtk_label_set_line_wrap ( GTK_LABEL ( label ) , TRUE ) ;
gtk_misc_set_alignment ( GTK_MISC ( label ) , 0.0 , 0.5 ) ;
gtk_box_pack_start_defaults ( GTK_BOX ( vbox ) , label ) ;
data = g_new0 ( AutorunDialogData , 1 ) ;
2008-01-17 13:45:27 +00:00
data - > dialog = dialog ;
2008-01-14 13:17:36 +00:00
data - > mount = g_object_ref ( mount ) ;
data - > remember = ! pref_ask ;
data - > selected_ignore = pref_ignore ;
data - > x_content_type = g_strdup ( x_content_type ) ;
data - > selected_app = g_app_info_get_default_for_type ( x_content_type , FALSE ) ;
2008-01-17 13:45:27 +00:00
data - > open_window_func = open_window_func ;
data - > user_data = user_data ;
2008-01-14 13:17:36 +00:00
combo_box = gtk_combo_box_new ( ) ;
2008-07-29 21:40:22 +00:00
nautilus_autorun_prepare_combo_box ( combo_box , x_content_type , FALSE , TRUE , FALSE , autorun_combo_changed , data ) ;
2008-01-14 13:17:36 +00:00
gtk_box_pack_start_defaults ( GTK_BOX ( vbox ) , combo_box ) ;
always_check_button = gtk_check_button_new_with_mnemonic ( _ ( " _Always perform this action " ) ) ;
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( always_check_button ) , data - > remember ) ;
g_signal_connect ( G_OBJECT ( always_check_button ) ,
" toggled " ,
G_CALLBACK ( autorun_always_toggled ) ,
data ) ;
gtk_box_pack_start_defaults ( GTK_BOX ( vbox ) , always_check_button ) ;
gtk_dialog_add_buttons ( GTK_DIALOG ( dialog ) ,
GTK_STOCK_CANCEL , GTK_RESPONSE_CANCEL ,
GTK_STOCK_OK , GTK_RESPONSE_OK ,
NULL ) ;
gtk_dialog_set_default_response ( GTK_DIALOG ( dialog ) , GTK_RESPONSE_OK ) ;
if ( g_mount_can_eject ( mount ) ) {
GtkWidget * eject_image ;
2008-02-08 16:29:17 +00:00
eject_button = gtk_button_new_with_mnemonic ( _ ( " _Eject " ) ) ;
2008-01-14 13:17:36 +00:00
pixbuf = gtk_icon_theme_load_icon ( gtk_icon_theme_get_default ( ) ,
" media-eject " ,
nautilus_get_icon_size_for_stock_size ( GTK_ICON_SIZE_BUTTON ) ,
0 ,
NULL ) ;
eject_image = gtk_image_new_from_pixbuf ( pixbuf ) ;
g_object_unref ( pixbuf ) ;
gtk_button_set_image ( GTK_BUTTON ( eject_button ) , eject_image ) ;
data - > should_eject = TRUE ;
} else {
eject_button = gtk_button_new_with_mnemonic ( _ ( " _Unmount " ) ) ;
data - > should_eject = FALSE ;
}
2008-02-25 11:58:02 +00:00
gtk_dialog_add_action_widget ( GTK_DIALOG ( dialog ) , eject_button , AUTORUN_DIALOG_RESPONSE_EJECT ) ;
2008-01-14 13:17:36 +00:00
gtk_button_box_set_child_secondary ( GTK_BUTTON_BOX ( GTK_DIALOG ( dialog ) - > action_area ) , eject_button , TRUE ) ;
/* show the dialog */
gtk_widget_show_all ( dialog ) ;
g_signal_connect ( G_OBJECT ( dialog ) ,
" response " ,
G_CALLBACK ( autorun_dialog_response ) ,
data ) ;
2008-01-17 13:45:27 +00:00
g_signal_connect ( G_OBJECT ( data - > mount ) ,
" unmounted " ,
G_CALLBACK ( autorun_dialog_mount_unmounted ) ,
data ) ;
2008-01-14 13:17:36 +00:00
out :
g_free ( mount_name ) ;
2008-01-17 13:45:27 +00:00
return ret ;
}
typedef struct {
GMount * mount ;
NautilusAutorunOpenWindow open_window_func ;
gpointer user_data ;
} AutorunData ;
2008-01-14 13:17:36 +00:00
static void
autorun_guessed_content_type_callback ( GObject * source_object ,
GAsyncResult * res ,
gpointer user_data )
{
GError * error ;
char * * guessed_content_type ;
2008-01-17 13:45:27 +00:00
AutorunData * data = user_data ;
gboolean open_folder ;
open_folder = FALSE ;
2008-01-14 13:17:36 +00:00
error = NULL ;
2008-07-29 21:40:22 +00:00
guessed_content_type = g_mount_guess_content_type_finish ( G_MOUNT ( source_object ) , res , & error ) ;
g_object_set_data_full ( source_object ,
" nautilus-content-type-cache " ,
g_strdupv ( guessed_content_type ) ,
( GDestroyNotify ) g_strfreev ) ;
2008-01-14 13:17:36 +00:00
if ( error ! = NULL ) {
g_warning ( " Unabled to guess content type for mount: %s " , error - > message ) ;
g_error_free ( error ) ;
} else {
2008-01-17 13:45:27 +00:00
if ( guessed_content_type ! = NULL & & g_strv_length ( guessed_content_type ) > 0 ) {
2008-01-14 13:17:36 +00:00
int n ;
for ( n = 0 ; guessed_content_type [ n ] ! = NULL ; n + + ) {
2008-01-17 13:45:27 +00:00
if ( do_autorun_for_content_type ( data - > mount , guessed_content_type [ n ] ,
data - > open_window_func , data - > user_data ) ) {
open_folder = TRUE ;
}
2008-01-14 13:17:36 +00:00
}
g_strfreev ( guessed_content_type ) ;
2008-01-17 13:45:27 +00:00
} else {
2008-06-15 18:42:26 +00:00
if ( eel_preferences_get_boolean ( NAUTILUS_PREFERENCES_MEDIA_AUTOMOUNT_OPEN ) )
open_folder = TRUE ;
2008-01-14 13:17:36 +00:00
}
}
2008-01-17 13:45:27 +00:00
/* only open the folder once.. */
2008-06-15 18:42:26 +00:00
if ( open_folder & & data - > open_window_func ! = NULL ) {
data - > open_window_func ( data - > mount , data - > user_data ) ;
2008-02-04 15:51:13 +00:00
}
2008-01-17 13:45:27 +00:00
g_object_unref ( data - > mount ) ;
g_free ( data ) ;
2008-01-14 13:17:36 +00:00
}
void
2008-01-17 13:45:27 +00:00
nautilus_autorun ( GMount * mount , NautilusAutorunOpenWindow open_window_func , gpointer user_data )
2008-01-14 13:17:36 +00:00
{
2008-01-17 13:45:27 +00:00
AutorunData * data ;
2008-01-30 15:52:03 +00:00
if ( ! should_autorun_mount ( mount ) | |
2008-02-04 15:51:13 +00:00
eel_preferences_get_boolean ( NAUTILUS_PREFERENCES_MEDIA_AUTORUN_NEVER ) ) {
2008-01-17 13:45:27 +00:00
return ;
2008-02-04 15:51:13 +00:00
}
2008-01-14 13:17:36 +00:00
2008-01-17 13:45:27 +00:00
data = g_new0 ( AutorunData , 1 ) ;
data - > mount = g_object_ref ( mount ) ;
data - > open_window_func = open_window_func ;
data - > user_data = user_data ;
2008-07-29 21:40:22 +00:00
g_mount_guess_content_type ( mount ,
FALSE ,
NULL ,
autorun_guessed_content_type_callback ,
data ) ;
2008-01-17 13:45:27 +00:00
}
2008-03-05 15:29:45 +00:00
typedef struct {
NautilusAutorunGetContent callback ;
gpointer user_data ;
} GetContentTypesData ;
static void
get_types_cb ( GObject * source_object ,
GAsyncResult * res ,
gpointer user_data )
{
GetContentTypesData * data ;
char * * types ;
data = user_data ;
2008-07-29 21:40:22 +00:00
types = g_mount_guess_content_type_finish ( G_MOUNT ( source_object ) , res , NULL ) ;
g_object_set_data_full ( source_object ,
" nautilus-content-type-cache " ,
g_strdupv ( types ) ,
( GDestroyNotify ) g_strfreev ) ;
2008-03-05 15:29:45 +00:00
if ( data - > callback ) {
data - > callback ( types , data - > user_data ) ;
}
g_strfreev ( types ) ;
g_free ( data ) ;
}
void
nautilus_autorun_get_x_content_types_for_mount_async ( GMount * mount ,
NautilusAutorunGetContent callback ,
GCancellable * cancellable ,
gpointer user_data )
{
char * * cached ;
GetContentTypesData * data ;
if ( mount = = NULL ) {
if ( callback ) {
callback ( NULL , user_data ) ;
}
return ;
}
2008-07-29 21:40:22 +00:00
cached = g_object_get_data ( G_OBJECT ( mount ) , " nautilus-content-type-cache " ) ;
2008-03-05 15:29:45 +00:00
if ( cached ! = NULL ) {
if ( callback ) {
callback ( cached , user_data ) ;
}
return ;
}
data = g_new ( GetContentTypesData , 1 ) ;
data - > callback = callback ;
data - > user_data = user_data ;
2008-07-29 21:40:22 +00:00
g_mount_guess_content_type ( mount ,
FALSE ,
cancellable ,
get_types_cb ,
data ) ;
2008-03-05 15:29:45 +00:00
}
2008-01-17 13:45:27 +00:00
char * *
2008-03-05 15:29:45 +00:00
nautilus_autorun_get_cached_x_content_types_for_mount ( GMount * mount )
2008-01-17 13:45:27 +00:00
{
2008-03-05 15:29:45 +00:00
char * * cached ;
2008-01-18 12:21:44 +00:00
if ( mount = = NULL ) {
return NULL ;
2008-01-17 13:45:27 +00:00
}
2008-07-29 21:40:22 +00:00
cached = g_object_get_data ( G_OBJECT ( mount ) , " nautilus-content-type-cache " ) ;
2008-03-05 15:29:45 +00:00
if ( cached ! = NULL ) {
return g_strdupv ( cached ) ;
}
return NULL ;
2008-01-14 13:17:36 +00:00
}
2008-01-30 15:52:03 +00:00
static gboolean
2008-04-30 01:09:55 +00:00
remove_allow_volume ( gpointer data )
2008-01-30 15:52:03 +00:00
{
2008-04-30 01:09:55 +00:00
GVolume * volume = data ;
2008-01-30 15:52:03 +00:00
2008-04-30 01:09:55 +00:00
g_object_set_data ( G_OBJECT ( volume ) , " nautilus-allow-autorun " , NULL ) ;
2008-01-30 15:52:03 +00:00
return FALSE ;
}
void
2008-04-30 01:09:55 +00:00
nautilus_allow_autorun_for_volume ( GVolume * volume )
2008-01-30 15:52:03 +00:00
{
2008-04-30 01:09:55 +00:00
g_object_set_data ( G_OBJECT ( volume ) , " nautilus-allow-autorun " , GINT_TO_POINTER ( 1 ) ) ;
2008-01-30 15:52:03 +00:00
}
void
2008-04-30 01:09:55 +00:00
nautilus_allow_autorun_for_volume_finish ( GVolume * volume )
2008-01-30 15:52:03 +00:00
{
2008-04-30 01:09:55 +00:00
if ( g_object_get_data ( G_OBJECT ( volume ) , " nautilus-allow-autorun " ) ! = NULL ) {
g_timeout_add_full ( 0 ,
5000 ,
remove_allow_volume ,
g_object_ref ( volume ) ,
g_object_unref ) ;
}
2008-01-30 15:52:03 +00:00
}
2008-03-31 16:47:44 +00:00
static gboolean
should_skip_native_mount_root ( GFile * root )
{
char * path ;
gboolean should_skip ;
/* skip any mounts in hidden directory hierarchies */
path = g_file_get_path ( root ) ;
should_skip = strstr ( path , " /. " ) ! = NULL ;
g_free ( path ) ;
return should_skip ;
}
2008-01-30 15:52:03 +00:00
static gboolean
should_autorun_mount ( GMount * mount )
{
2008-04-30 01:09:55 +00:00
GFile * root ;
2008-01-30 15:52:03 +00:00
GVolume * enclosing_volume ;
gboolean ignore_autorun ;
2008-04-30 01:09:55 +00:00
ignore_autorun = TRUE ;
2008-01-30 15:52:03 +00:00
enclosing_volume = g_mount_get_volume ( mount ) ;
if ( enclosing_volume ! = NULL ) {
2008-04-30 01:09:55 +00:00
if ( g_object_get_data ( G_OBJECT ( enclosing_volume ) , " nautilus-allow-autorun " ) ! = NULL ) {
ignore_autorun = FALSE ;
g_object_set_data ( G_OBJECT ( enclosing_volume ) , " nautilus-allow-autorun " , NULL ) ;
2008-01-30 15:52:03 +00:00
}
}
if ( ignore_autorun ) {
Use g_volume_should_automount() to determine if we should autorun programs
2008-02-21 David Zeuthen <davidz@redhat.com>
* libnautilus-private/nautilus-autorun.c: (should_autorun_mount):
Use g_volume_should_automount() to determine if we should autorun
programs on a mount.
* libnautilus-private/nautilus-directory-async.c:
(nautilus_directory_set_up_request),
(nautilus_async_destroying_file), (lacks_filesystem_info),
(wants_filesystem_info), (request_is_satisfied),
(directory_count_start), (mime_list_start),
(filesystem_info_cancel), (filesystem_info_stop),
(filesystem_info_state_free), (got_filesystem_info),
(query_filesystem_info_callback), (filesystem_info_start),
(start_or_stop_io), (nautilus_directory_cancel),
(cancel_filesystem_info_for_file), (cancel_loading_attributes),
(nautilus_directory_cancel_loading_file_attributes):
* libnautilus-private/nautilus-directory-private.h:
* libnautilus-private/nautilus-file-attributes.h: Add new
filesystem info attribute; right now two bits in NautilusFile's
private structure are set; the filesystem::use-preview and
filesystem:readonly.
* libnautilus-private/nautilus-file-operations.c:
(nautilus_file_operations_mount_volume):
* src/nautilus-places-sidebar.c: (open_selected_bookmark),
(mount_shortcut_cb): Don't inhibit automount from
nautilus_file_operations_mount_volume() because then everything
will be inhibited as the mount_added callback use it as
well. Rather, move the call to inhibit out to the proper call
sites.
* libnautilus-private/nautilus-file-private.h:
* libnautilus-private/nautilus-file.c:
(nautilus_file_get_filesystem_use_preview),
(nautilus_file_should_show_thumbnail),
(get_speed_tradeoff_preference_for_file),
(nautilus_file_get_mount):
* libnautilus-private/nautilus-file.h:
* src/file-manager/fm-directory-view.c: (load_directory):
* src/file-manager/fm-icon-view.c: (should_preview_sound):
* src/nautilus-window-manage-views.c: (update_for_new_location):
Use the new filesystem::use-preview hint to determine if we should
preview non-native files (such as gphoto2:// and cdda://
mounts).
svn path=/trunk/; revision=13795
2008-02-21 13:20:19 +00:00
if ( enclosing_volume ! = NULL ) {
g_object_unref ( enclosing_volume ) ;
}
2008-01-30 15:52:03 +00:00
return FALSE ;
}
root = g_mount_get_root ( mount ) ;
Use g_volume_should_automount() to determine if we should autorun programs
2008-02-21 David Zeuthen <davidz@redhat.com>
* libnautilus-private/nautilus-autorun.c: (should_autorun_mount):
Use g_volume_should_automount() to determine if we should autorun
programs on a mount.
* libnautilus-private/nautilus-directory-async.c:
(nautilus_directory_set_up_request),
(nautilus_async_destroying_file), (lacks_filesystem_info),
(wants_filesystem_info), (request_is_satisfied),
(directory_count_start), (mime_list_start),
(filesystem_info_cancel), (filesystem_info_stop),
(filesystem_info_state_free), (got_filesystem_info),
(query_filesystem_info_callback), (filesystem_info_start),
(start_or_stop_io), (nautilus_directory_cancel),
(cancel_filesystem_info_for_file), (cancel_loading_attributes),
(nautilus_directory_cancel_loading_file_attributes):
* libnautilus-private/nautilus-directory-private.h:
* libnautilus-private/nautilus-file-attributes.h: Add new
filesystem info attribute; right now two bits in NautilusFile's
private structure are set; the filesystem::use-preview and
filesystem:readonly.
* libnautilus-private/nautilus-file-operations.c:
(nautilus_file_operations_mount_volume):
* src/nautilus-places-sidebar.c: (open_selected_bookmark),
(mount_shortcut_cb): Don't inhibit automount from
nautilus_file_operations_mount_volume() because then everything
will be inhibited as the mount_added callback use it as
well. Rather, move the call to inhibit out to the proper call
sites.
* libnautilus-private/nautilus-file-private.h:
* libnautilus-private/nautilus-file.c:
(nautilus_file_get_filesystem_use_preview),
(nautilus_file_should_show_thumbnail),
(get_speed_tradeoff_preference_for_file),
(nautilus_file_get_mount):
* libnautilus-private/nautilus-file.h:
* src/file-manager/fm-directory-view.c: (load_directory):
* src/file-manager/fm-icon-view.c: (should_preview_sound):
* src/nautilus-window-manage-views.c: (update_for_new_location):
Use the new filesystem::use-preview hint to determine if we should
preview non-native files (such as gphoto2:// and cdda://
mounts).
svn path=/trunk/; revision=13795
2008-02-21 13:20:19 +00:00
/* only do autorun on local files or files where g_volume_should_automount() returns TRUE */
ignore_autorun = TRUE ;
2008-03-31 16:47:44 +00:00
if ( ( g_file_is_native ( root ) & & ! should_skip_native_mount_root ( root ) ) | |
Use g_volume_should_automount() to determine if we should autorun programs
2008-02-21 David Zeuthen <davidz@redhat.com>
* libnautilus-private/nautilus-autorun.c: (should_autorun_mount):
Use g_volume_should_automount() to determine if we should autorun
programs on a mount.
* libnautilus-private/nautilus-directory-async.c:
(nautilus_directory_set_up_request),
(nautilus_async_destroying_file), (lacks_filesystem_info),
(wants_filesystem_info), (request_is_satisfied),
(directory_count_start), (mime_list_start),
(filesystem_info_cancel), (filesystem_info_stop),
(filesystem_info_state_free), (got_filesystem_info),
(query_filesystem_info_callback), (filesystem_info_start),
(start_or_stop_io), (nautilus_directory_cancel),
(cancel_filesystem_info_for_file), (cancel_loading_attributes),
(nautilus_directory_cancel_loading_file_attributes):
* libnautilus-private/nautilus-directory-private.h:
* libnautilus-private/nautilus-file-attributes.h: Add new
filesystem info attribute; right now two bits in NautilusFile's
private structure are set; the filesystem::use-preview and
filesystem:readonly.
* libnautilus-private/nautilus-file-operations.c:
(nautilus_file_operations_mount_volume):
* src/nautilus-places-sidebar.c: (open_selected_bookmark),
(mount_shortcut_cb): Don't inhibit automount from
nautilus_file_operations_mount_volume() because then everything
will be inhibited as the mount_added callback use it as
well. Rather, move the call to inhibit out to the proper call
sites.
* libnautilus-private/nautilus-file-private.h:
* libnautilus-private/nautilus-file.c:
(nautilus_file_get_filesystem_use_preview),
(nautilus_file_should_show_thumbnail),
(get_speed_tradeoff_preference_for_file),
(nautilus_file_get_mount):
* libnautilus-private/nautilus-file.h:
* src/file-manager/fm-directory-view.c: (load_directory):
* src/file-manager/fm-icon-view.c: (should_preview_sound):
* src/nautilus-window-manage-views.c: (update_for_new_location):
Use the new filesystem::use-preview hint to determine if we should
preview non-native files (such as gphoto2:// and cdda://
mounts).
svn path=/trunk/; revision=13795
2008-02-21 13:20:19 +00:00
( enclosing_volume ! = NULL & & g_volume_should_automount ( enclosing_volume ) ) ) {
ignore_autorun = FALSE ;
}
if ( enclosing_volume ! = NULL ) {
g_object_unref ( enclosing_volume ) ;
2008-02-04 15:51:13 +00:00
}
2008-01-30 15:52:03 +00:00
g_object_unref ( root ) ;
return ! ignore_autorun ;
}