void exec_in_terminal( const char* app_name, const char* cwd, const char* cmd ) { // task PtkFileTask* task = ptk_file_exec_new( app_name, cwd, NULL, NULL ); task->task->exec_command = strdup( cmd ); task->task->exec_terminal = TRUE; // task->task->exec_keep_terminal = TRUE; // for test only task->task->exec_sync = FALSE; task->task->exec_export = FALSE; ptk_file_task_run( task ); }
void ptk_clipboard_paste_targets( GtkWindow* parent_win, const char* dest_dir, GtkTreeView* task_view ) //MOD added { GtkClipboard * clip = gtk_clipboard_get( GDK_SELECTION_CLIPBOARD ); GdkAtom gnome_target; GdkAtom uri_list_target; gchar **uri_list, **puri; GtkSelectionData* sel_data = NULL; GList* files = NULL; gchar* file_path; gint missing_targets = 0; char* str; PtkFileTask* task; VFSFileTaskType action; char* uri_list_str; gnome_target = gdk_atom_intern( "x-special/gnome-copied-files", FALSE ); sel_data = gtk_clipboard_wait_for_contents( clip, gnome_target ); if ( sel_data ) { if ( sel_data->length <= 0 || sel_data->format != 8 ) return ; uri_list_str = ( char* ) sel_data->data; action = VFS_FILE_TASK_COPY; if ( uri_list_str ) { while ( *uri_list_str && *uri_list_str != '\n' ) ++uri_list_str; } } else { uri_list_target = gdk_atom_intern( "text/uri-list", FALSE ); sel_data = gtk_clipboard_wait_for_contents( clip, uri_list_target ); if ( ! sel_data ) return ; if ( sel_data->length <= 0 || sel_data->format != 8 ) return ; uri_list_str = ( char* ) sel_data->data; action = VFS_FILE_TASK_COPY; } if ( uri_list_str ) { puri = uri_list = g_uri_list_extract_uris( uri_list_str ); while ( *puri ) { file_path = g_filename_from_uri( *puri, NULL, NULL ); if ( file_path ) { if ( g_file_test( file_path, G_FILE_TEST_IS_SYMLINK ) ) { str = file_path; file_path = g_file_read_link ( file_path, NULL ); g_free( str ); } if ( file_path ) { if ( g_file_test( file_path, G_FILE_TEST_EXISTS ) ) files = g_list_prepend( files, file_path ); else missing_targets++; } } ++puri; } g_strfreev( uri_list ); gtk_selection_data_free( sel_data ); //sfm if ( files ) files = g_list_reverse( files ); task = ptk_file_task_new( action, files, dest_dir, GTK_WINDOW( parent_win ), GTK_WIDGET( task_view ) ); ptk_file_task_run( task ); if ( missing_targets > 0 ) ptk_show_error( GTK_WINDOW( parent_win ), g_strdup_printf ( "Error" ), g_strdup_printf ( "%i target%s missing", missing_targets, missing_targets > 1 ? g_strdup_printf ( "s are" ) : g_strdup_printf ( " is" ) ) ); } }
void ptk_clipboard_paste_links( GtkWindow* parent_win, const char* dest_dir, GtkTreeView* task_view ) //MOD added { GtkClipboard * clip = gtk_clipboard_get( GDK_SELECTION_CLIPBOARD ); GdkAtom gnome_target; GdkAtom uri_list_target; gchar **uri_list, **puri; GtkSelectionData* sel_data = NULL; GList* files = NULL; gchar* file_path; PtkFileTask* task; VFSFileTaskType action; char* uri_list_str; gnome_target = gdk_atom_intern( "x-special/gnome-copied-files", FALSE ); sel_data = gtk_clipboard_wait_for_contents( clip, gnome_target ); if ( sel_data ) { if ( sel_data->length <= 0 || sel_data->format != 8 ) return ; uri_list_str = ( char* ) sel_data->data; action = VFS_FILE_TASK_LINK; if ( uri_list_str ) { while ( *uri_list_str && *uri_list_str != '\n' ) ++uri_list_str; } } else { uri_list_target = gdk_atom_intern( "text/uri-list", FALSE ); sel_data = gtk_clipboard_wait_for_contents( clip, uri_list_target ); if ( ! sel_data ) return ; if ( sel_data->length <= 0 || sel_data->format != 8 ) return ; uri_list_str = ( char* ) sel_data->data; action = VFS_FILE_TASK_LINK; } if ( uri_list_str ) { puri = uri_list = g_uri_list_extract_uris( uri_list_str ); while ( *puri ) { if ( file_path = g_filename_from_uri( *puri, NULL, NULL ) ) files = g_list_prepend( files, file_path ); ++puri; } g_strfreev( uri_list ); gtk_selection_data_free( sel_data ); //sfm if ( files ) files = g_list_reverse( files ); task = ptk_file_task_new( action, files, dest_dir, GTK_WINDOW( parent_win ), GTK_WIDGET( task_view ) ); ptk_file_task_run( task ); } }
void ptk_clipboard_paste_files( GtkWindow* parent_win, const char* dest_dir, GtkTreeView* task_view ) { GtkClipboard * clip = gtk_clipboard_get( GDK_SELECTION_CLIPBOARD ); GdkAtom gnome_target; GdkAtom uri_list_target; gchar **uri_list, **puri; GtkSelectionData* sel_data = NULL; GList* files = NULL; gchar* file_path; PtkFileTask* task; VFSFileTaskType action; char* uri_list_str; gnome_target = gdk_atom_intern( "x-special/gnome-copied-files", FALSE ); sel_data = gtk_clipboard_wait_for_contents( clip, gnome_target ); if ( sel_data ) { if ( sel_data->length <= 0 || sel_data->format != 8 ) return ; uri_list_str = ( char* ) sel_data->data; if ( 0 == strncmp( ( char* ) sel_data->data, "cut", 3 ) ) action = VFS_FILE_TASK_MOVE; else action = VFS_FILE_TASK_COPY; if ( uri_list_str ) { while ( *uri_list_str && *uri_list_str != '\n' ) ++uri_list_str; } } else { uri_list_target = gdk_atom_intern( "text/uri-list", FALSE ); sel_data = gtk_clipboard_wait_for_contents( clip, uri_list_target ); if ( ! sel_data ) return ; if ( sel_data->length <= 0 || sel_data->format != 8 ) return ; uri_list_str = ( char* ) sel_data->data; if ( clipboard_action == GDK_ACTION_MOVE ) action = VFS_FILE_TASK_MOVE; else action = VFS_FILE_TASK_COPY; } if ( uri_list_str ) { puri = uri_list = g_uri_list_extract_uris( uri_list_str ); while ( *puri ) { file_path = g_filename_from_uri( *puri, NULL, NULL ); if ( file_path ) { files = g_list_prepend( files, file_path ); } ++puri; } g_strfreev( uri_list ); gtk_selection_data_free( sel_data ); //sfm if ( files ) files = g_list_reverse( files ); /* * If only one item is selected and the item is a * directory, paste the files in that directory; * otherwise, paste the file in current directory. */ task = ptk_file_task_new( action, files, dest_dir, GTK_WINDOW( parent_win ), GTK_WIDGET( task_view ) ); ptk_file_task_run( task ); } }
void on_dlg_response ( GtkDialog *dialog, gint response_id, gpointer user_data ) { FilePropertiesDialogData * data; PtkFileTask* task; gboolean mod_change; uid_t uid = -1; gid_t gid = -1; const char* owner_name; const char* group_name; int i; GList* l; GList* file_list; char* file_path; GtkWidget* ask_recursive; VFSFileInfo* file; GtkAllocation allocation; gtk_widget_get_allocation ( GTK_WIDGET( dialog ), &allocation ); int width = allocation.width; int height = allocation.height; if ( width && height ) { char* str = g_strdup_printf( "%d", width ); xset_set( "app_dlg", "s", str ); g_free( str ); str = g_strdup_printf( "%d", height ); xset_set( "app_dlg", "z", str ); g_free( str ); } data = ( FilePropertiesDialogData* ) g_object_get_data( G_OBJECT( dialog ), "DialogData" ); if ( data ) { if ( data->update_label_timer ) g_source_remove( data->update_label_timer ); data->cancel = TRUE; if ( data->calc_size_thread ) g_thread_join( data->calc_size_thread ); if ( response_id == GTK_RESPONSE_OK ) { GtkWidget* open_with; /* Set default action for mimetype */ if( ( open_with = (GtkWidget*)g_object_get_data( G_OBJECT(dialog), "open_with" ) ) ) { GtkTreeModel* model = gtk_combo_box_get_model( GTK_COMBO_BOX(open_with) ); GtkTreeIter it; if( model && gtk_combo_box_get_active_iter( GTK_COMBO_BOX(open_with), &it ) ) { char* action; gtk_tree_model_get( model, &it, 2, &action, -1 ); if( action ) { file = ( VFSFileInfo* ) data->file_list->data; VFSMimeType* mime = vfs_file_info_get_mime_type( file ); vfs_mime_type_set_default_action( mime, action ); vfs_mime_type_unref( mime ); g_free( action ); } } } /* Check if we need chown */ owner_name = gtk_entry_get_text( data->owner ); if ( owner_name && *owner_name && (!data->owner_name || strcmp( owner_name, data->owner_name ) ) ) { uid = uid_from_name( owner_name ); if ( uid == -1 ) { ptk_show_error( GTK_WINDOW( dialog ), _("Error"), _( "Invalid User" ) ); return ; } } group_name = gtk_entry_get_text( data->group ); if ( group_name && *group_name && (!data->group_name || strcmp( group_name, data->group_name ) ) ) { gid = gid_from_name( group_name ); if ( gid == -1 ) { ptk_show_error( GTK_WINDOW( dialog ), _("Error"), _( "Invalid Group" ) ); return ; } } for ( i = 0; i < N_CHMOD_ACTIONS; ++i ) { if ( gtk_toggle_button_get_inconsistent( data->chmod_btns[ i ] ) ) { data->chmod_states[ i ] = 2; /* Don't touch this bit */ } else if ( data->chmod_states[ i ] != gtk_toggle_button_get_active( data->chmod_btns[ i ] ) ) { mod_change = TRUE; data->chmod_states[ i ] = gtk_toggle_button_get_active( data->chmod_btns[ i ] ); } else /* Don't change this bit */ { data->chmod_states[ i ] = 2; } } if ( uid != -1 || gid != -1 || mod_change ) { file_list = NULL; for ( l = data->file_list; l; l = l->next ) { file = ( VFSFileInfo* ) l->data; file_path = g_build_filename( data->dir_path, vfs_file_info_get_name( file ), NULL ); file_list = g_list_prepend( file_list, file_path ); } task = ptk_file_task_new( VFS_FILE_TASK_CHMOD_CHOWN, file_list, NULL, GTK_WINDOW(gtk_widget_get_parent( GTK_WIDGET( dialog ) )), NULL ); //MOD ptk_file_task_set_recursive( task, gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( data->recurse ) ) ); /* for ( l = data->file_list; l; l = l->next ) { file = ( VFSFileInfo* ) l->data; if ( vfs_file_info_is_dir( file ) ) { ask_recursive = gtk_message_dialog_new( GTK_WINDOW( data->dlg ), GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, _( "Do you want to recursively apply these changes to all files and sub-folders?" ) ); ptk_file_task_set_recursive( task, ( GTK_RESPONSE_YES == gtk_dialog_run( GTK_DIALOG( ask_recursive ) ) ) ); gtk_widget_destroy( ask_recursive ); break; } } */ if ( mod_change ) { /* If the permissions of file has been changed by the user */ ptk_file_task_set_chmod( task, data->chmod_states ); } /* For chown */ ptk_file_task_set_chown( task, uid, gid ); ptk_file_task_run( task ); /* * This file list will be freed by file operation, so we don't * need to do this. Just set the pointer to NULL. */ data->file_list = NULL; } } g_free( data->owner_name ); g_free( data->group_name ); /* *NOTE: File operation chmod/chown will free the list when it's done, *and we only need to free it when there is no file operation applyed. */ g_slice_free( FilePropertiesDialogData, data ); } gtk_widget_destroy( GTK_WIDGET( dialog ) ); }
void on_dir_tree_view_drag_data_received ( GtkWidget *widget, GdkDragContext *drag_context, gint x, gint y, GtkSelectionData *sel_data, guint info, guint time, gpointer user_data ) //MOD added { gchar **list, **puri; GList* files = NULL; PtkFileTask* task; VFSFileTaskType file_action = VFS_FILE_TASK_MOVE; PtkFileBrowser* file_browser = ( PtkFileBrowser* ) user_data; char* dest_dir; char* file_path; GtkWidget* parent_win; /* Don't call the default handler */ g_signal_stop_emission_by_name( widget, "drag-data-received" ); if ( ( gtk_selection_data_get_length( sel_data ) >= 0 ) && ( gtk_selection_data_get_format( sel_data ) == 8 ) ) { dest_dir = dir_tree_view_get_drop_dir( widget, x, y ); if ( dest_dir ) { puri = list = gtk_selection_data_get_uris( sel_data ); if( file_browser->pending_drag_status_tree ) { // We only want to update drag status, not really want to drop dev_t dest_dev; struct stat statbuf; // skip stat64 if( stat( dest_dir, &statbuf ) == 0 ) { dest_dev = statbuf.st_dev; if( 0 == file_browser->drag_source_dev_tree ) { file_browser->drag_source_dev_tree = dest_dev; for( ; *puri; ++puri ) { file_path = g_filename_from_uri( *puri, NULL, NULL ); if( stat( file_path, &statbuf ) == 0 && statbuf.st_dev != dest_dev ) { file_browser->drag_source_dev_tree = statbuf.st_dev; g_free( file_path ); break; } g_free( file_path ); } } if( file_browser->drag_source_dev_tree != dest_dev ) // src and dest are on different devices */ gdk_drag_status( drag_context, GDK_ACTION_COPY, time); else gdk_drag_status( drag_context, GDK_ACTION_MOVE, time); } else // stat failed gdk_drag_status( drag_context, GDK_ACTION_COPY, time); g_free( dest_dir ); g_strfreev( list ); file_browser->pending_drag_status_tree = 0; return; } if ( puri ) { if ( 0 == ( gdk_drag_context_get_selected_action ( drag_context ) & ( GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK ) ) ) { gdk_drag_status( drag_context, GDK_ACTION_MOVE, time); } gtk_drag_finish ( drag_context, TRUE, FALSE, time ); while ( *puri ) { if ( **puri == '/' ) file_path = g_strdup( *puri ); else file_path = g_filename_from_uri( *puri, NULL, NULL ); if ( file_path ) files = g_list_prepend( files, file_path ); ++puri; } g_strfreev( list ); switch ( gdk_drag_context_get_selected_action ( drag_context ) ) { case GDK_ACTION_COPY: file_action = VFS_FILE_TASK_COPY; break; case GDK_ACTION_LINK: file_action = VFS_FILE_TASK_LINK; break; /* FIXME: GDK_ACTION_DEFAULT, GDK_ACTION_PRIVATE, and GDK_ACTION_ASK are not handled */ default: break; } if ( files ) { /* Accept the drop and perform file actions */ { parent_win = gtk_widget_get_toplevel( GTK_WIDGET( file_browser ) ); task = ptk_file_task_new( file_action, files, dest_dir, GTK_WINDOW( parent_win ), file_browser->task_view ); ptk_file_task_run( task ); } } g_free( dest_dir ); gtk_drag_finish ( drag_context, TRUE, FALSE, time ); return ; } g_free( dest_dir ); } //else // g_warning ("bad dest_dir in on_dir_tree_view_drag_data_received"); } /* If we are only getting drag status, not finished. */ if( file_browser->pending_drag_status_tree ) { gdk_drag_status ( drag_context, GDK_ACTION_COPY, time ); file_browser->pending_drag_status_tree = 0; return; } gtk_drag_finish ( drag_context, FALSE, FALSE, time ); }