void fm_tree_model_add_root_uri (FMTreeModel *model, const char *root_uri, const char *display_name, GIcon *icon, GMount *mount) { NemoFile *file; TreeNode *node, *cnode; FMTreeModelRoot *newroot; file = nemo_file_get_by_uri (root_uri); newroot = tree_model_root_new (model); node = create_node_for_file (newroot, file); node->display_name = g_strdup (display_name); node->icon = g_object_ref (icon); if (mount) { node->mount = g_object_ref (mount); } newroot->root_node = node; node->parent = NULL; if (model->details->root_node == NULL) { model->details->root_node = node; } else { /* append it */ for (cnode = model->details->root_node; cnode->next != NULL; cnode = cnode->next); cnode->next = node; node->prev = cnode; } nemo_file_unref (file); update_node_without_reporting (model, node); report_node_inserted (model, node); }
static void nemo_desktop_item_properties_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; NemoFile *file; GKeyFile *key_file; char *uri, *type, *exec; uris = g_strsplit (gtk_selection_data_get_data (selection_data), "\r\n", 0); exactly_one = uris[0] != NULL && (uris[1] == NULL || uris[1][0] == '\0'); if (!exactly_one) { g_strfreev (uris); return; } file = nemo_file_get_by_uri (uris[0]); g_return_if_fail (file != NULL); uri = nemo_file_get_uri (file); if (nemo_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); nemo_file_unref (file); g_strfreev (uris); }
/* Returns a reffed NemoFile object for this directory. */ NemoFile * nemo_directory_get_corresponding_file (NemoDirectory *directory) { NemoFile *file; char *uri; file = nemo_directory_get_existing_corresponding_file (directory); if (file == NULL) { uri = nemo_directory_get_uri (directory); file = nemo_file_get_by_uri (uri); g_free (uri); } return file; }
void fm_tree_model_remove_root_uri (FMTreeModel *model, const char *uri) { TreeNode *node; GtkTreePath *path; FMTreeModelRoot *root; NemoFile *file; file = nemo_file_get_by_uri (uri); for (node = model->details->root_node; node != NULL; node = node->next) { if (file == node->file) { break; } } nemo_file_unref (file); if (node) { /* remove the node */ if (node->mount) { g_object_unref (node->mount); node->mount = NULL; } nemo_file_monitor_remove (node->file, model); path = get_node_path (model, node); /* Report row_deleted before actually deleting */ gtk_tree_model_row_deleted (GTK_TREE_MODEL (model), path); gtk_tree_path_free (path); if (node->prev) { node->prev->next = node->next; } if (node->next) { node->next->prev = node->prev; } if (node == model->details->root_node) { model->details->root_node = node->next; } /* destroy the root identifier */ root = node->root; destroy_node_without_reporting (model, node); g_hash_table_destroy (root->file_to_node_map); g_free (root); } }
static void search_engine_hits_added (NemoSearchEngine *engine, GList *hits, NemoSearchDirectory *search) { GList *hit_list; GList *file_list; NemoFile *file; char *uri; SearchMonitor *monitor; GList *monitor_list; file_list = NULL; for (hit_list = hits; hit_list != NULL; hit_list = hit_list->next) { uri = hit_list->data; if (g_str_has_suffix (uri, NEMO_SAVED_SEARCH_EXTENSION)) { /* Never return saved searches themselves as hits */ continue; } file = nemo_file_get_by_uri (uri); for (monitor_list = search->details->monitor_list; monitor_list; monitor_list = monitor_list->next) { monitor = monitor_list->data; /* Add monitors */ nemo_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); } search->details->files = g_list_concat (search->details->files, file_list); nemo_directory_emit_files_added (NEMO_DIRECTORY (search), file_list); file = nemo_directory_get_corresponding_file (NEMO_DIRECTORY (search)); nemo_file_emit_changed (file); nemo_file_unref (file); }
/* 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 nemo_file_changed() is thread-safe. */ static gboolean thumbnail_thread_notify_file_changed (gpointer image_uri) { NemoFile *file; file = nemo_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) { nemo_file_set_is_thumbnailing (file, FALSE); nemo_file_invalidate_attributes (file, NEMO_FILE_ATTRIBUTE_THUMBNAIL | NEMO_FILE_ATTRIBUTE_INFO); nemo_file_unref (file); } g_free (image_uri); return FALSE; }
static NemoFile * file_for_path (NemoTreeViewDragDest *dest, GtkTreePath *path) { NemoFile *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 = nemo_file_get_by_uri (uri); } g_free (uri); } return file; }
static void nemo_icon_dnd_update_drop_target (NemoIconContainer *container, GdkDragContext *context, int x, int y) { NemoIcon *icon; NemoFile *file; double world_x, world_y; char *uri; g_assert (NEMO_IS_ICON_CONTAINER (container)); canvas_widget_to_world (EEL_CANVAS (container), x, y, &world_x, &world_y); /* Find the item we hit with our drop, if any. */ icon = nemo_icon_container_item_at (container, world_x, world_y); /* FIXME bugzilla.gnome.org 42485: * These "can_accept_items" tests need to be done by * the icon view, not here. This file is not supposed to know * that the target is a file. */ /* Find if target icon accepts our drop. */ if (icon != NULL) { uri = nemo_icon_container_get_icon_uri (container, icon); file = nemo_file_get_by_uri (uri); g_free (uri); if (!nemo_drag_can_accept_info (file, container->details->dnd_info->drag_info.data_type, container->details->dnd_info->drag_info.selection_list)) { icon = NULL; } nemo_file_unref (file); } set_drop_target (container, icon); }
static void search_engine_hits_subtracted (NemoSearchEngine *engine, GList *hits, NemoSearchDirectory *search) { GList *hit_list; GList *monitor_list; SearchMonitor *monitor; GList *file_list; char *uri; NemoFile *file; file_list = NULL; for (hit_list = hits; hit_list != NULL; hit_list = hit_list->next) { uri = hit_list->data; file = nemo_file_get_by_uri (uri); for (monitor_list = search->details->monitor_list; monitor_list; monitor_list = monitor_list->next) { monitor = monitor_list->data; /* Remove monitors */ nemo_file_monitor_remove (file, monitor); } g_signal_handlers_disconnect_by_func (file, file_changed, search); search->details->files = g_list_remove (search->details->files, file); file_list = g_list_prepend (file_list, file); } nemo_directory_emit_files_changed (NEMO_DIRECTORY (search), file_list); nemo_file_list_free (file_list); file = nemo_directory_get_corresponding_file (NEMO_DIRECTORY (search)); nemo_file_emit_changed (file); nemo_file_unref (file); }
static char * nemo_icon_container_find_drop_target (NemoIconContainer *container, GdkDragContext *context, int x, int y, gboolean *icon_hit, gboolean rewrite_desktop) { NemoIcon *drop_target_icon; double world_x, world_y; NemoFile *file; char *icon_uri; char *container_uri; if (icon_hit) { *icon_hit = FALSE; } if (!container->details->dnd_info->drag_info.got_drop_data_type) { return NULL; } canvas_widget_to_world (EEL_CANVAS (container), x, y, &world_x, &world_y); /* FIXME bugzilla.gnome.org 42485: * These "can_accept_items" tests need to be done by * the icon view, not here. This file is not supposed to know * that the target is a file. */ /* Find the item we hit with our drop, if any */ drop_target_icon = nemo_icon_container_item_at (container, world_x, world_y); if (drop_target_icon != NULL) { icon_uri = nemo_icon_container_get_icon_uri (container, drop_target_icon); if (icon_uri != NULL) { file = nemo_file_get_by_uri (icon_uri); if (!nemo_drag_can_accept_info (file, container->details->dnd_info->drag_info.data_type, container->details->dnd_info->drag_info.selection_list)) { /* the item we dropped our selection on cannot accept the items, * do the same thing as if we just dropped the items on the canvas */ drop_target_icon = NULL; } g_free (icon_uri); nemo_file_unref (file); } } if (drop_target_icon == NULL) { if (icon_hit) { *icon_hit = FALSE; } container_uri = get_container_uri (container); if (rewrite_desktop && container_uri != NULL && eel_uri_is_desktop (container_uri)) { g_free (container_uri); container_uri = nemo_get_desktop_directory_uri (); } return container_uri; } if (icon_hit) { *icon_hit = TRUE; } return nemo_icon_container_get_icon_drop_target_uri (container, drop_target_icon); }
static void handle_local_move (NemoIconContainer *container, double world_x, double world_y) { GList *moved_icons, *p; NemoDragSelectionItem *item; NemoIcon *icon; NemoFile *file; char screen_string[32]; GdkScreen *screen; time_t now; if (container->details->auto_layout) { return; } time (&now); /* Move and select the icons. */ moved_icons = NULL; for (p = container->details->dnd_info->drag_info.selection_list; p != NULL; p = p->next) { item = p->data; icon = nemo_icon_container_get_icon_by_uri (container, item->uri); if (icon == NULL) { /* probably dragged from another screen. Add it to * this screen */ file = nemo_file_get_by_uri (item->uri); screen = gtk_widget_get_screen (GTK_WIDGET (container)); g_snprintf (screen_string, sizeof (screen_string), "%d", gdk_screen_get_number (screen)); nemo_file_set_metadata (file, NEMO_METADATA_KEY_SCREEN, NULL, screen_string); nemo_file_set_time_metadata (file, NEMO_METADATA_KEY_ICON_POSITION_TIMESTAMP, now); nemo_icon_container_add (container, NEMO_ICON_CONTAINER_ICON_DATA (file)); icon = nemo_icon_container_get_icon_by_uri (container, item->uri); } if (item->got_icon_position) { nemo_icon_container_move_icon (container, icon, world_x + item->icon_x, world_y + item->icon_y, icon->scale, TRUE, TRUE, TRUE); } moved_icons = g_list_prepend (moved_icons, icon); } nemo_icon_container_select_list_unselect_others (container, moved_icons); /* Might have been moved in a way that requires adjusting scroll region. */ nemo_icon_container_update_scroll_region (container); g_list_free (moved_icons); }
void nemo_launch_application_by_uri (GAppInfo *application, GList *uris, GtkWindow *parent_window) { char *uri; GList *locations, *l; GFile *location; NemoFile *file; gboolean result; GError *error; GdkDisplay *display; GdkAppLaunchContext *launch_context; NemoIconInfo *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 = nemo_file_get_by_uri (uris->data); icon = nemo_file_get_icon (file, 48, gtk_widget_get_scale_factor (GTK_WIDGET (parent_window)), 0); nemo_file_unref (file); if (icon) { gdk_app_launch_context_set_icon_name (launch_context, nemo_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 = nemo_file_get_by_uri (l->data); nemo_recent_add_file (file, application); nemo_file_unref (file); } } g_list_free_full (locations, g_object_unref); }
static void handle_local_move (NemoIconContainer *container, double world_x, double world_y) { GList *moved_icons, *p; NemoDragSelectionItem *item; NemoIcon *icon; NemoFile *file = NULL; gint monitor; time_t now; if (container->details->auto_layout) { return; } time (&now); /* Move and select the icons. */ moved_icons = NULL; for (p = container->details->dnd_info->drag_info.selection_list; p != NULL; p = p->next) { item = p->data; icon = nemo_icon_container_get_icon_by_uri (container, item->uri); if (icon == NULL) { /* probably dragged from another screen. Add it to * this screen */ file = nemo_file_get_by_uri (item->uri); nemo_file_set_time_metadata (file, NEMO_METADATA_KEY_ICON_POSITION_TIMESTAMP, now); nemo_icon_container_add (container, NEMO_ICON_CONTAINER_ICON_DATA (file)); icon = nemo_icon_container_get_icon_by_uri (container, item->uri); } if (file == NULL) file = NEMO_FILE (icon->data); nemo_file_set_is_desktop_orphan (file, FALSE); monitor = nemo_desktop_utils_get_monitor_for_widget (GTK_WIDGET (container)); nemo_file_set_integer_metadata (file, NEMO_METADATA_KEY_MONITOR, 0, monitor); if (item->got_icon_position) { nemo_icon_container_move_icon (container, icon, world_x + item->icon_x, world_y + item->icon_y, icon->scale, TRUE, TRUE, TRUE); } moved_icons = g_list_prepend (moved_icons, icon); } nemo_icon_container_select_list_unselect_others (container, moved_icons); /* Might have been moved in a way that requires adjusting scroll region. */ nemo_icon_container_update_scroll_region (container); g_list_free (moved_icons); }
void nemo_self_check_directory (void) { NemoDirectory *directory; NemoFile *file; directory = nemo_directory_get_by_uri ("file:///etc"); file = nemo_file_get_by_uri ("file:///etc/passwd"); EEL_CHECK_INTEGER_RESULT (g_hash_table_size (directories), 1); nemo_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. nemo_file_set_metadata (file, "test", "default", "value"); EEL_CHECK_STRING_RESULT (nemo_file_get_metadata (file, "test", "default"), "value"); nemo_file_set_boolean_metadata (file, "test_boolean", TRUE, TRUE); EEL_CHECK_BOOLEAN_RESULT (nemo_file_get_boolean_metadata (file, "test_boolean", TRUE), TRUE); nemo_file_set_boolean_metadata (file, "test_boolean", TRUE, FALSE); EEL_CHECK_BOOLEAN_RESULT (nemo_file_get_boolean_metadata (file, "test_boolean", TRUE), FALSE); EEL_CHECK_BOOLEAN_RESULT (nemo_file_get_boolean_metadata (NULL, "test_boolean", TRUE), TRUE); nemo_file_set_integer_metadata (file, "test_integer", 0, 17); EEL_CHECK_INTEGER_RESULT (nemo_file_get_integer_metadata (file, "test_integer", 0), 17); nemo_file_set_integer_metadata (file, "test_integer", 0, -1); EEL_CHECK_INTEGER_RESULT (nemo_file_get_integer_metadata (file, "test_integer", 0), -1); nemo_file_set_integer_metadata (file, "test_integer", 42, 42); EEL_CHECK_INTEGER_RESULT (nemo_file_get_integer_metadata (file, "test_integer", 42), 42); EEL_CHECK_INTEGER_RESULT (nemo_file_get_integer_metadata (NULL, "test_integer", 42), 42); EEL_CHECK_INTEGER_RESULT (nemo_file_get_integer_metadata (file, "nonexistent_key", 42), 42); */ EEL_CHECK_BOOLEAN_RESULT (nemo_directory_get_by_uri ("file:///etc") == directory, TRUE); nemo_directory_unref (directory); EEL_CHECK_BOOLEAN_RESULT (nemo_directory_get_by_uri ("file:///etc/") == directory, TRUE); nemo_directory_unref (directory); EEL_CHECK_BOOLEAN_RESULT (nemo_directory_get_by_uri ("file:///etc////") == directory, TRUE); nemo_directory_unref (directory); nemo_file_unref (file); nemo_directory_file_monitor_remove (directory, &data_dummy); nemo_directory_unref (directory); while (g_hash_table_size (directories) != 0) { gtk_main_iteration (); } EEL_CHECK_INTEGER_RESULT (g_hash_table_size (directories), 0); directory = nemo_directory_get_by_uri ("file:///etc"); got_files_flag = FALSE; nemo_directory_call_when_ready (directory, NEMO_FILE_ATTRIBUTE_INFO | NEMO_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 = nemo_file_get_by_uri ("file:///etc/passwd"); /* EEL_CHECK_STRING_RESULT (nemo_file_get_metadata (file, "test", "default"), "value"); */ nemo_file_unref (file); nemo_directory_unref (directory); EEL_CHECK_INTEGER_RESULT (g_hash_table_size (directories), 0); }