/* This is a one-shot idle callback called from the main loop to call notify_file_changed() for a thumbnail. It frees the uri afterwards. We do this in an idle callback as I don't think nautilus_file_changed() is thread-safe. */ static gboolean thumbnail_thread_notify_file_changed (gpointer image_uri) { NautilusFile *file; gdk_threads_enter (); file = nautilus_file_get_by_uri ((char *) image_uri); #ifdef DEBUG_THUMBNAILS g_message ("(Thumbnail Thread) Notifying file changed file:%p uri: %s\n", file, (char*) image_uri); #endif if (file != NULL) { nautilus_file_set_is_thumbnailing (file, FALSE); nautilus_file_invalidate_attributes (file, NAUTILUS_FILE_ATTRIBUTE_THUMBNAIL | NAUTILUS_FILE_ATTRIBUTE_INFO); nautilus_file_unref (file); } g_free (image_uri); gdk_threads_leave (); return FALSE; }
static gboolean skeleton_handle_show_item_properties_cb (NautilusFreedesktopFileManager1 *object, GDBusMethodInvocation *invocation, const gchar *const *uris, const gchar *startup_id, gpointer data) { GList *files; int i; files = NULL; for (i = 0; uris[i] != NULL; i++) { files = g_list_prepend (files, nautilus_file_get_by_uri (uris[i])); } files = g_list_reverse (files); nautilus_properties_window_present (files, NULL, startup_id); nautilus_file_list_free (files); nautilus_freedesktop_file_manager1_complete_show_item_properties (object, invocation); return TRUE; }
int main (int argc, char **argv) { const char *uri; const char *field; const char *value; NautilusFile *file; NautilusFileAttributes attributes; gtk_init (&argc, &argv); if (argc < 3) { usage (argv[0]); } uri = argv[1]; field = argv[2]; value = argv[3]; file = nautilus_file_get_by_uri (uri); attributes = nautilus_mime_actions_get_full_file_attributes (); nautilus_file_call_when_ready (file, attributes, ready_callback, NULL); while (!ready) { gtk_main_iteration (); } if (strcmp (field, "default_action_type") == 0) { puts ("default_action_type"); nautilus_mime_set_default_action_type_for_file (file, str_to_action_type (value)); } else if (strcmp (field, "default_application") == 0) { puts ("default_application"); nautilus_mime_set_default_application_for_file (file, value); } else if (strcmp (field, "default_component") == 0) { puts ("default_component"); nautilus_mime_set_default_component_for_file (file, value); } else if (strcmp (field, "short_list_applicationss") == 0) { puts ("short_list_applications"); nautilus_mime_set_short_list_applications_for_file (file, comma_separated_str_to_str_list (value)); } else if (strcmp (field, "short_list_components") == 0) { puts ("short_list_components"); nautilus_mime_set_short_list_components_for_file (file, comma_separated_str_to_str_list (value)); } else if (strcmp (field, "add_to_all_applicationss") == 0) { puts ("add_to_all_applications"); nautilus_mime_extend_all_applications_for_file (file, comma_separated_str_to_str_list (value)); } else if (strcmp (field, "remove_from_all_applications") == 0) { puts ("remove_from_all_applications"); nautilus_mime_remove_from_all_applications_for_file (file, comma_separated_str_to_str_list (value)); } else { usage (argv[0]); } return 0; }
static void fm_ditem_page_exec_drag_data_received (GtkWidget *widget, GdkDragContext *context, int x, int y, GtkSelectionData *selection_data, guint info, guint time, GtkEntry *entry) { char **uris; gboolean exactly_one; NautilusFile *file; GnomeDesktopItem *item; char *uri; const char *exec; uris = g_strsplit (selection_data->data, "\r\n", 0); exactly_one = uris[0] != NULL && (uris[1] == NULL || uris[1][0] == '\0'); if (!exactly_one) { g_strfreev (uris); return; } file = nautilus_file_get_by_uri (uris[0]); g_return_if_fail (file != NULL); uri = nautilus_file_get_uri (file); if (nautilus_file_is_mime_type (file, "application/x-desktop")) { item = gnome_desktop_item_new_from_uri (uri, GNOME_DESKTOP_ITEM_LOAD_ONLY_IF_EXISTS, NULL); if (item != NULL && gnome_desktop_item_get_entry_type (item) == GNOME_DESKTOP_ITEM_TYPE_APPLICATION) { exec = gnome_desktop_item_get_string (item, GNOME_DESKTOP_ITEM_EXEC); gtk_entry_set_text (entry, exec?exec:""); gnome_desktop_item_unref (item); gtk_widget_grab_focus (GTK_WIDGET (entry)); } } else { gtk_entry_set_text (entry, uri?uri:""); } g_free (uri); nautilus_file_unref (file); g_strfreev (uris); }
static void fm_ditem_page_exec_drag_data_received (GtkWidget *widget, GdkDragContext *context, int x, int y, GtkSelectionData *selection_data, guint info, guint time, GtkEntry *entry) { char **uris; gboolean exactly_one; NautilusFile *file; GKeyFile *key_file; char *uri, *type, *exec; uris = g_strsplit (selection_data->data, "\r\n", 0); exactly_one = uris[0] != NULL && (uris[1] == NULL || uris[1][0] == '\0'); if (!exactly_one) { g_strfreev (uris); return; } file = nautilus_file_get_by_uri (uris[0]); g_return_if_fail (file != NULL); uri = nautilus_file_get_uri (file); if (nautilus_file_is_mime_type (file, "application/x-desktop")) { key_file = _g_key_file_new_from_uri (uri, G_KEY_FILE_NONE, NULL); if (key_file != NULL) { type = g_key_file_get_string (key_file, MAIN_GROUP, "Type", NULL); if (type != NULL && strcmp (type, "Application") == 0) { exec = g_key_file_get_string (key_file, MAIN_GROUP, "Exec", NULL); if (exec != NULL) { g_free (uri); uri = exec; } } g_free (type); g_key_file_free (key_file); } } gtk_entry_set_text (entry, uri?uri:""); gtk_widget_grab_focus (GTK_WIDGET (entry)); g_free (uri); nautilus_file_unref (file); g_strfreev (uris); }
static void search_engine_hits_added (NautilusSearchEngine *engine, GList *hits, NautilusSearchDirectory *search) { GList *hit_list; GList *file_list; NautilusFile *file; SearchMonitor *monitor; GList *monitor_list; file_list = NULL; for (hit_list = hits; hit_list != NULL; hit_list = hit_list->next) { NautilusSearchHit *hit = hit_list->data; const char *uri; uri = nautilus_search_hit_get_uri (hit); if (g_str_has_suffix (uri, NAUTILUS_SAVED_SEARCH_EXTENSION)) { /* Never return saved searches themselves as hits */ continue; } nautilus_search_hit_compute_scores (hit, search->details->query); file = nautilus_file_get_by_uri (uri); nautilus_file_set_search_relevance (file, nautilus_search_hit_get_relevance (hit)); for (monitor_list = search->details->monitor_list; monitor_list; monitor_list = monitor_list->next) { monitor = monitor_list->data; /* Add monitors */ nautilus_file_monitor_add (file, monitor, monitor->monitor_attributes); } g_signal_connect (file, "changed", G_CALLBACK (file_changed), search), file_list = g_list_prepend (file_list, file); g_hash_table_add (search->details->files_hash, file); } search->details->files = g_list_concat (search->details->files, file_list); nautilus_directory_emit_files_added (NAUTILUS_DIRECTORY (search), file_list); file = nautilus_directory_get_corresponding_file (NAUTILUS_DIRECTORY (search)); nautilus_file_emit_changed (file); nautilus_file_unref (file); search_directory_add_pending_files_callbacks (search); }
/* Returns a reffed NautilusFile object for this directory. */ NautilusFile * nautilus_directory_get_corresponding_file (NautilusDirectory *directory) { NautilusFile *file; char *uri; file = nautilus_directory_get_existing_corresponding_file (directory); if (file == NULL) { uri = nautilus_directory_get_uri (directory); file = nautilus_file_get_by_uri (uri); g_free (uri); } return file; }
static void update_xdg_dir_cache (void) { GFile *file; char *config_file, *uri; int i; free_xdg_dir_cache (); g_reload_user_special_dirs_cache (); schedule_user_dirs_changed (); desktop_dir_changed (); cached_xdg_dirs = parse_xdg_dirs (NULL); for (i = 0 ; cached_xdg_dirs[i].type != NULL; i++) { cached_xdg_dirs[i].file = NULL; if (strcmp (cached_xdg_dirs[i].path, g_get_home_dir ()) != 0) { uri = g_filename_to_uri (cached_xdg_dirs[i].path, NULL, NULL); cached_xdg_dirs[i].file = nautilus_file_get_by_uri (uri); nautilus_file_monitor_add (cached_xdg_dirs[i].file, &cached_xdg_dirs[i], NAUTILUS_FILE_ATTRIBUTE_INFO); g_signal_connect (cached_xdg_dirs[i].file, "changed", G_CALLBACK (xdg_dir_changed), &cached_xdg_dirs[i]); g_free (uri); } } if (cached_xdg_dirs_monitor == NULL) { config_file = g_build_filename (g_get_user_config_dir (), "user-dirs.dirs", NULL); file = g_file_new_for_path (config_file); cached_xdg_dirs_monitor = g_file_monitor_file (file, 0, NULL, NULL); g_signal_connect (cached_xdg_dirs_monitor, "changed", G_CALLBACK (xdg_dir_cache_changed_cb), NULL); g_object_unref (file); g_free (config_file); eel_debug_call_at_shutdown (destroy_xdg_dir_cache); } }
int main (int argc, char **argv) { const char *uri; GAppInfo *default_application; GList *all_applications; NautilusFile *file; NautilusFileAttributes attributes; gtk_init (&argc, &argv); if (argc != 2) { fprintf (stderr, "Usage: %s uri\n", *argv); return 1; } uri = argv[1]; file = nautilus_file_get_by_uri (uri); attributes = nautilus_mime_actions_get_full_file_attributes (); nautilus_file_call_when_ready (file, attributes, ready_callback, NULL); while (!ready) { gtk_main_iteration (); } default_application = nautilus_mime_get_default_application_for_file (file); puts ("Default Application"); print_application (default_application); puts (""); all_applications = nautilus_mime_get_applications_for_file (file); puts ("All Applications"); print_application_list (all_applications); puts (""); return 0; }
static NautilusFile * file_for_path (NautilusTreeViewDragDest *dest, GtkTreePath *path) { NautilusFile *file; char *uri; if (path) { g_signal_emit (dest, signals[GET_FILE_FOR_PATH], 0, path, &file); } else { uri = get_root_uri (dest); file = NULL; if (uri != NULL) { file = nautilus_file_get_by_uri (uri); } g_free (uri); } return file; }
void nautilus_self_check_directory (void) { NautilusDirectory *directory; NautilusFile *file; directory = nautilus_directory_get_by_uri ("file:///etc"); file = nautilus_file_get_by_uri ("file:///etc/passwd"); EEL_CHECK_INTEGER_RESULT (g_hash_table_size (directories), 1); nautilus_directory_file_monitor_add (directory, &data_dummy, TRUE, 0, NULL, NULL); /* FIXME: these need to be updated to the new metadata infrastructure * as make check doesn't pass. nautilus_file_set_metadata (file, "test", "default", "value"); EEL_CHECK_STRING_RESULT (nautilus_file_get_metadata (file, "test", "default"), "value"); nautilus_file_set_boolean_metadata (file, "test_boolean", TRUE, TRUE); EEL_CHECK_BOOLEAN_RESULT (nautilus_file_get_boolean_metadata (file, "test_boolean", TRUE), TRUE); nautilus_file_set_boolean_metadata (file, "test_boolean", TRUE, FALSE); EEL_CHECK_BOOLEAN_RESULT (nautilus_file_get_boolean_metadata (file, "test_boolean", TRUE), FALSE); EEL_CHECK_BOOLEAN_RESULT (nautilus_file_get_boolean_metadata (NULL, "test_boolean", TRUE), TRUE); nautilus_file_set_integer_metadata (file, "test_integer", 0, 17); EEL_CHECK_INTEGER_RESULT (nautilus_file_get_integer_metadata (file, "test_integer", 0), 17); nautilus_file_set_integer_metadata (file, "test_integer", 0, -1); EEL_CHECK_INTEGER_RESULT (nautilus_file_get_integer_metadata (file, "test_integer", 0), -1); nautilus_file_set_integer_metadata (file, "test_integer", 42, 42); EEL_CHECK_INTEGER_RESULT (nautilus_file_get_integer_metadata (file, "test_integer", 42), 42); EEL_CHECK_INTEGER_RESULT (nautilus_file_get_integer_metadata (NULL, "test_integer", 42), 42); EEL_CHECK_INTEGER_RESULT (nautilus_file_get_integer_metadata (file, "nonexistent_key", 42), 42); */ EEL_CHECK_BOOLEAN_RESULT (nautilus_directory_get_by_uri ("file:///etc") == directory, TRUE); nautilus_directory_unref (directory); EEL_CHECK_BOOLEAN_RESULT (nautilus_directory_get_by_uri ("file:///etc/") == directory, TRUE); nautilus_directory_unref (directory); EEL_CHECK_BOOLEAN_RESULT (nautilus_directory_get_by_uri ("file:///etc////") == directory, TRUE); nautilus_directory_unref (directory); nautilus_file_unref (file); nautilus_directory_file_monitor_remove (directory, &data_dummy); nautilus_directory_unref (directory); while (g_hash_table_size (directories) != 0) { gtk_main_iteration (); } EEL_CHECK_INTEGER_RESULT (g_hash_table_size (directories), 0); directory = nautilus_directory_get_by_uri ("file:///etc"); got_files_flag = FALSE; nautilus_directory_call_when_ready (directory, NAUTILUS_FILE_ATTRIBUTE_INFO | NAUTILUS_FILE_ATTRIBUTE_DEEP_COUNTS, TRUE, got_files_callback, &data_dummy); while (!got_files_flag) { gtk_main_iteration (); } EEL_CHECK_BOOLEAN_RESULT (directory->details->file_list == NULL, TRUE); EEL_CHECK_INTEGER_RESULT (g_hash_table_size (directories), 1); file = nautilus_file_get_by_uri ("file:///etc/passwd"); /* EEL_CHECK_STRING_RESULT (nautilus_file_get_metadata (file, "test", "default"), "value"); */ nautilus_file_unref (file); nautilus_directory_unref (directory); EEL_CHECK_INTEGER_RESULT (g_hash_table_size (directories), 0); }
void nautilus_launch_application_by_uri (GAppInfo *application, GList *uris, GtkWindow *parent_window) { char *uri; GList *locations, *l; GFile *location; NautilusFile *file; gboolean result; GError *error; GdkDisplay *display; GdkAppLaunchContext *launch_context; NautilusIconInfo *icon; int count, total; g_assert (uris != NULL); /* count the number of uris with local paths */ count = 0; total = g_list_length (uris); locations = NULL; for (l = uris; l != NULL; l = l->next) { uri = l->data; location = g_file_new_for_uri (uri); if (g_file_is_native (location)) { count++; } locations = g_list_prepend (locations, location); } locations = g_list_reverse (locations); if (parent_window != NULL) { display = gtk_widget_get_display (GTK_WIDGET (parent_window)); } else { display = gdk_display_get_default (); } launch_context = gdk_display_get_app_launch_context (display); if (parent_window != NULL) { gdk_app_launch_context_set_screen (launch_context, gtk_window_get_screen (parent_window)); } file = nautilus_file_get_by_uri (uris->data); icon = nautilus_file_get_icon (file, 48, 0); nautilus_file_unref (file); if (icon) { gdk_app_launch_context_set_icon_name (launch_context, nautilus_icon_info_get_used_name (icon)); g_object_unref (icon); } error = NULL; if (count == total) { /* All files are local, so we can use g_app_info_launch () with * the file list we constructed before. */ result = g_app_info_launch (application, locations, G_APP_LAUNCH_CONTEXT (launch_context), &error); } else { /* Some files are non local, better use g_app_info_launch_uris (). */ result = g_app_info_launch_uris (application, uris, G_APP_LAUNCH_CONTEXT (launch_context), &error); } g_object_unref (launch_context); if (result) { for (l = uris; l != NULL; l = l->next) { file = nautilus_file_get_by_uri (l->data); nautilus_recent_add_file (file, application); nautilus_file_unref (file); } } g_list_free_full (locations, g_object_unref); }