// This will treat a < b iff a is 'lower' in the file tree than b static int cmp_prefix(GFile *a, GFile *b) { if (a == NULL && b == NULL) return 0; else if (b == NULL || g_file_has_prefix(a, b)) return -1; else if (a == NULL || g_file_has_prefix(b, a)) return 1; else return 0; }
static gboolean _fm_file_ops_job_check_paths(FmFileOpsJob* job, GFile* src, GFileInfo* src_inf, GFile* dest) { GError* err = NULL; FmJob* fmjob = FM_JOB(job); if(job->type == FM_FILE_OP_MOVE && g_file_equal(src, dest)) { err = g_error_new_literal(G_IO_ERROR, G_IO_ERROR_FAILED, _("Source and destination are the same.")); } else if(g_file_info_get_file_type(src_inf) == G_FILE_TYPE_DIRECTORY && g_file_has_prefix(dest, src) ) { const char* msg = NULL; if(job->type == FM_FILE_OP_MOVE) msg = _("Cannot move a folder into its sub folder"); else if(job->type == FM_FILE_OP_COPY) msg = _("Cannot copy a folder into its sub folder"); else msg = _("Destination is a sub folder of source"); err = g_error_new_literal(G_IO_ERROR, G_IO_ERROR_FAILED, msg); } if(err) { if(!fm_job_is_cancelled(fmjob)) { fm_file_ops_job_emit_cur_file(job, g_file_info_get_display_name(src_inf)); fm_job_emit_error(fmjob, err, FM_JOB_ERROR_CRITICAL); } g_error_free(err); } return (err == NULL); }
IdeBufferChangeMonitor * gbp_git_buffer_change_monitor_new (IdeBuffer *buffer, IpcGitRepository *repository, GFile *file, GCancellable *cancellable, GError **error) { GbpGitBufferChangeMonitor *ret; g_autoptr(IpcGitChangeMonitor) proxy = NULL; g_autoptr(IdeContext) context = NULL; g_autoptr(GFile) workdir = NULL; g_autofree gchar *relative_path = NULL; g_autofree gchar *obj_path = NULL; GDBusConnection *connection; g_return_val_if_fail (IDE_IS_MAIN_THREAD (), NULL); g_return_val_if_fail (IDE_IS_BUFFER (buffer), NULL); g_return_val_if_fail (G_IS_FILE (file), NULL); g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), NULL); context = ide_buffer_ref_context (buffer); workdir = ide_context_ref_workdir (context); if (!g_file_has_prefix (file, workdir)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Cannot monitor files outside the working directory"); return NULL; } relative_path = g_file_get_relative_path (workdir, file); if (!ipc_git_repository_call_create_change_monitor_sync (repository, relative_path, &obj_path, cancellable, error)) return NULL; connection = g_dbus_proxy_get_connection (G_DBUS_PROXY (repository)); if (!(proxy = ipc_git_change_monitor_proxy_new_sync (connection, G_DBUS_PROXY_FLAGS_NONE, NULL, obj_path, cancellable, error))) return NULL; ret = g_object_new (GBP_TYPE_GIT_BUFFER_CHANGE_MONITOR, "buffer", buffer, NULL); ret->proxy = g_steal_pointer (&proxy); return IDE_BUFFER_CHANGE_MONITOR (g_steal_pointer (&ret)); }
gboolean directory_has_makefile_am (BasicAutotoolsPlugin *bb_plugin, GFile *dir) { GFile *file; gboolean exists; /* We need configure.ac or configure.in too */ if (bb_plugin->project_root_dir == NULL) return FALSE; exists = TRUE; file = g_file_get_child (bb_plugin->project_root_dir, "configure.ac"); if (!g_file_query_exists (file, NULL)) { g_object_unref (file); file = g_file_get_child (bb_plugin->project_root_dir, "configure.in"); if (!g_file_query_exists (file, NULL)) { exists = FALSE; } } g_object_unref (file); /* Check for Makefile.am or GNUmakefile.am */ if (g_file_has_prefix (dir, bb_plugin->project_build_dir)) { /* Check for Makefile.am in source directory not build directory */ gchar *relative; GFile *src_dir; relative = g_file_get_relative_path (bb_plugin->project_build_dir, dir); src_dir = g_file_get_child (bb_plugin->project_root_dir, relative); file = g_file_get_child (src_dir, "Makefile.am"); g_object_unref (src_dir); g_free (relative); } else if (g_file_equal (dir, bb_plugin->project_build_dir)) { file = g_file_get_child (bb_plugin->project_root_dir, "Makefile.am"); } else { file = g_file_get_child (dir, "Makefile.am"); } if (!g_file_query_exists (file, NULL)) { g_object_unref (file); file = g_file_get_child (dir, "GNUmakefile.am"); if (!g_file_query_exists (file, NULL)) { exists = FALSE; } } g_object_unref (file); return exists; }
static void show_completed_file (GFile *hit, gboolean is_dir, const char *arg) { char *path, *cwd, *display, *t; GFile *cwd_f; GFile *home; if (g_file_is_native (hit)) { cwd = g_get_current_dir (); cwd_f = g_file_new_for_path (cwd); g_free (cwd); home = g_file_new_for_path (g_get_home_dir ()); if ((g_file_has_prefix (hit, home) || g_file_equal (hit, home)) && arg[0] == '~') { t = g_file_get_relative_path (home, hit); path = g_strconcat ("~", (t != NULL) ? "/": "", t, NULL); g_free (t); } else if (g_file_has_prefix (hit, cwd_f) && !g_path_is_absolute (arg)) path = g_file_get_relative_path (cwd_f, hit); else path = g_file_get_path (hit); g_object_unref (cwd_f); g_object_unref (home); display = shell_quote (path); g_free (path); } else display = g_file_get_uri (hit); g_print ("%s%s\n", display, (is_dir)?"/":""); g_free (display); }
void watcher_remove_monitor_for_recursive_path(const watcher_t *watcher, const gchar *path) { GFile *w_file, *file; GFileMonitor *w_monitor; gchar *w_path; GHashTableIter iter; gpointer key, value; LOG_DEBUG("%s: %s (path=%s)", watcher->name, N_("removing file monitors for recursive path"), path); file = g_file_new_for_path(path); g_hash_table_iter_init(&iter, watcher->monitors); while (g_hash_table_iter_next(&iter, &key, &value)) { w_path = (gchar *) key; w_monitor = (GFileMonitor *) value; if (g_strcmp0(w_path, watcher->path) == 0) continue; w_file = g_file_new_for_path(w_path); if (g_file_equal(w_file, file) || g_file_has_prefix(w_file, file)) { if (!g_file_monitor_is_cancelled(w_monitor)) { g_file_monitor_cancel(w_monitor); LOG_DEBUG("%s: %s (%s)", watcher->name, N_("file monitor cancelled"), w_path); } else { LOG_DEBUG("%s: %s (%s)", watcher->name, N_("file monitor already cancelled"), w_path); } g_hash_table_iter_remove(&iter); g_object_unref(w_file); g_free(w_path); g_object_unref(w_monitor); } } g_object_unref(file); }
static gboolean on_tv_button_press (GtkWidget *widget, GdkEventButton *event, gpointer data) { GtkTreePath *path; GtkTreeIter iter; GFile *file; gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget), event->x, event->y, &path, NULL, NULL, NULL); if (!path) return TRUE; /* get the selected path */ g_free (baobab.selected_path); gtk_tree_model_get_iter (GTK_TREE_MODEL (baobab.model), &iter, path); gtk_tree_model_get (GTK_TREE_MODEL (baobab.model), &iter, COL_H_PARSENAME, &baobab.selected_path, -1); file = g_file_parse_name (baobab.selected_path); if (baobab.CONTENTS_CHANGED_DELAYED) { GFile *home_file; home_file = g_file_new_for_path (g_get_home_dir ()); if (g_file_has_prefix (file, home_file)) { baobab.CONTENTS_CHANGED_DELAYED = FALSE; if (baobab.STOP_SCANNING) { contents_changed (); } } g_object_unref (home_file); } /* right-click */ if (event->button == 3) { if (g_file_query_exists (file, NULL)) { popupmenu_list (path, event, can_trash_file (file)); } } gtk_tree_path_free (path); g_object_unref (file); return FALSE; }
static gboolean is_dir_included(GFile *file) { GList *p; for (p = dirs; p; p = p->next) { if (g_file_equal(file, (GFile *)p->data) || g_file_has_prefix(file, (GFile *)p->data)) { gboolean included; included = GPOINTER_TO_INT(g_object_get_data(p->data, "included")); return included; } } return FALSE; }
/* Return build path from a source directory */ static GFile * build_file_from_directory (BasicAutotoolsPlugin *plugin, GFile *directory) { GFile *build_file; if ((plugin->project_root_dir == NULL) || (plugin->project_build_dir == NULL)) { /* No change if there is no project or no build directory */ build_file = g_object_ref (directory); } else if (g_file_has_prefix (directory, plugin->project_build_dir) || g_file_equal (directory, plugin->project_build_dir)) { /* No change, already in build directory */ build_file = g_object_ref (directory); } else if (g_file_equal (directory, plugin->project_root_dir)) { /* Use build directory instead of source directory */ build_file = g_object_ref (plugin->project_build_dir); } else if (g_file_has_prefix (directory, plugin->project_root_dir)) { /* Get corresponding file in build directory */ gchar *relative; relative = g_file_get_relative_path (plugin->project_root_dir, directory); build_file = g_file_resolve_relative_path (plugin->project_build_dir, relative); g_free (relative); } else { /* File outside the project directory */ build_file = g_object_ref (directory); } return build_file; }
static void ev_previewer_unlink_tempfile (const gchar *filename) { GFile *file, *tempdir; file = g_file_new_for_path (filename); tempdir = g_file_new_for_path (g_get_tmp_dir ()); if (g_file_has_prefix (file, tempdir)) { g_file_delete (file, NULL, NULL); } g_object_unref (file); g_object_unref (tempdir); }
static void prepare_unmount(GMount* mount) { /* ensure that CWD is not on the mounted filesystem. */ char* cwd_str = g_get_current_dir(); GFile* cwd = g_file_new_for_path(cwd_str); GFile* root = g_mount_get_root(mount); g_free(cwd_str); /* FIXME: This cannot cover 100% cases since symlinks are not checked. * There may be other cases that cwd is actually under mount root * but checking prefix is not enough. We already did our best, though. */ if(g_file_has_prefix(cwd, root)) g_chdir("/"); g_object_unref(cwd); g_object_unref(root); }
gboolean nemo_window_slot_should_close_with_mount (NemoWindowSlot *slot, GMount *mount) { GFile *mount_location; gboolean close_with_mount; mount_location = g_mount_get_root (mount); close_with_mount = g_file_has_prefix (NEMO_WINDOW_SLOT (slot)->location, mount_location) || g_file_equal (NEMO_WINDOW_SLOT (slot)->location, mount_location); g_object_unref (mount_location); return close_with_mount; }
/* Work even if file is not a descendant of parent */ static gchar* get_relative_path (GFile *parent, GFile *file) { gchar *relative; relative = g_file_get_relative_path (parent, file); if (relative == NULL) { if (g_file_equal (parent, file)) { relative = g_strdup (""); } else { GFile *grand_parent = g_file_get_parent (parent); gint level; gchar *grand_relative; gchar *ptr; gsize len; for (level = 1; !g_file_has_prefix (file, grand_parent); level++) { GFile *next = g_file_get_parent (grand_parent); g_object_unref (grand_parent); grand_parent = next; } grand_relative = g_file_get_relative_path (grand_parent, file); g_object_unref (grand_parent); len = strlen (grand_relative); relative = g_new (gchar, len + level * 3 + 1); ptr = relative; for (; level; level--) { memcpy(ptr, ".." G_DIR_SEPARATOR_S, 3); ptr += 3; } memcpy (ptr, grand_relative, len + 1); g_free (grand_relative); } } return relative; }
static void mount_removed (GVolumeMonitor *volume_monitor, GMount *mount, gpointer user_data) { NautilusMonitor *monitor = user_data; GFile *mount_location; mount_location = g_mount_get_root (mount); if (g_file_has_prefix (monitor->location, mount_location)) { nautilus_file_changes_queue_file_removed (monitor->location); schedule_call_consume_changes (); } g_object_unref (mount_location); }
static void collect_directories_by_container (gpointer key, gpointer value, gpointer callback_data) { NautilusDirectory *directory; CollectData *collect_data; GFile *location; location = (GFile *) key; directory = NAUTILUS_DIRECTORY (value); collect_data = (CollectData *) callback_data; if (g_file_has_prefix (location, collect_data->container) || g_file_equal (collect_data->container, location)) { nautilus_directory_ref (directory); collect_data->directories = g_list_prepend (collect_data->directories, directory); } }
static gboolean workbench_manages_file (IdeWorkbench *workbench, GFile *file) { IdeContext *context; IdeVcs *vcs; GFile *workdir; g_assert (IDE_IS_WORKBENCH (workbench)); g_assert (G_IS_FILE (file)); if (NULL == (context = ide_workbench_get_context (workbench))) return FALSE; vcs = ide_context_get_vcs (context); workdir = ide_vcs_get_working_directory (vcs); return g_file_has_prefix (file, workdir); }
static void file_view_directory_expanded (FileModel* model, GtkTreeIter* iter, GtkTreePath* path, gpointer user_data) { AnjutaFileView* view = user_data; AnjutaFileViewPrivate *priv = ANJUTA_FILE_VIEW_GET_PRIVATE (view); if (priv->pending_selected_file) { GFile *dir; gtk_tree_model_get (GTK_TREE_MODEL (priv->model), iter, COLUMN_FILE, &dir, -1); if (g_file_has_prefix (priv->pending_selected_file, dir)) file_view_select_from_iter (view, *iter); g_object_unref (dir); } }
static void cancel_tasks (TrackerController *controller, const gchar *subject, GFile *file) { TrackerControllerPrivate *priv; GList *elem; priv = controller->priv; for (elem = priv->ongoing_tasks; elem; elem = elem->next) { WritebackData *data = elem->data; if (g_strcmp0 (subject, data->subject) == 0) { g_message ("Cancelling not yet processed task ('%s')", data->subject); g_cancellable_cancel (data->cancellable); } if (file) { guint i; for (i = 0; i < data->results->len; i++) { GStrv row = g_ptr_array_index (data->results, i); if (row[0] != NULL) { GFile *task_file; task_file = g_file_new_for_uri (row[0]); if (g_file_equal (task_file, file) || g_file_has_prefix (task_file, file)) { /* Mount path contains some file being processed */ g_message ("Cancelling task ('%s')", row[0]); g_cancellable_cancel (data->cancellable); } g_object_unref (task_file); } } } } }
gboolean panel_launcher_is_in_personal_path (const char *location) { GFile *file; GFile *launchers_dir; char *launchers_path; gboolean retval; if (!location) return FALSE; launchers_path = panel_launcher_get_personal_path (); launchers_dir = g_file_new_for_path (launchers_path); g_free (launchers_path); file = panel_launcher_get_gfile (location); retval = g_file_has_prefix (file, launchers_dir); g_object_unref (file); g_object_unref (launchers_dir); return retval; }
static gboolean xdg_cache_cache_is_thumbnail (TumblerCache *cache, const gchar *uri) { XDGCacheCache *xdg_cache = XDG_CACHE_CACHE (cache); const gchar *cachedir; const gchar *dirname; gboolean is_thumbnail = FALSE; GList *iter; GFile *flavor_dir; GFile *file; gchar *path; g_return_val_if_fail (XDG_CACHE_IS_CACHE (cache), FALSE); g_return_val_if_fail (uri != NULL, FALSE); for (iter = xdg_cache->flavors; !is_thumbnail && iter != NULL; iter = iter->next) { cachedir = g_get_user_cache_dir (); dirname = tumbler_thumbnail_flavor_get_name (iter->data); path = g_build_filename (cachedir, "thumbnails", dirname, NULL); flavor_dir = g_file_new_for_path (path); file = g_file_new_for_uri (uri); if (g_file_has_prefix (file, flavor_dir)) is_thumbnail = TRUE; g_object_unref (file); g_object_unref (flavor_dir); g_free (path); } return is_thumbnail; }
static void check_eligible (void) { TrackerConfig *config; GFile *file; GFileInfo *info; GError *error = NULL; gchar *path; guint log_handler_id; gboolean exists = TRUE; gboolean is_dir; gboolean print_dir_check; gboolean print_dir_check_with_content; gboolean print_file_check; gboolean print_monitor_check; gboolean would_index = TRUE; gboolean would_notice = TRUE; /* Set log handler for library messages */ log_handler_id = g_log_set_handler (NULL, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL, dummy_log_handler, NULL); g_log_set_default_handler (dummy_log_handler, NULL); /* Start check */ file = g_file_new_for_commandline_arg (eligible); info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE, G_FILE_QUERY_INFO_NONE, NULL, &error); if (error) { if (error->code == G_IO_ERROR_NOT_FOUND) { exists = FALSE; } g_error_free (error); } if (info) { is_dir = g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY; g_object_unref (info); } else { /* Assume not a dir */ is_dir = FALSE; } config = tracker_config_new (); path = g_file_get_path (file); if (exists) { if (is_dir) { print_dir_check = TRUE; print_dir_check_with_content = TRUE; print_file_check = FALSE; print_monitor_check = TRUE; } else { print_dir_check = FALSE; print_dir_check_with_content = FALSE; print_file_check = TRUE; print_monitor_check = TRUE; } } else { print_dir_check = TRUE; print_dir_check_with_content = FALSE; print_file_check = TRUE; print_monitor_check = TRUE; } g_print (exists ? _("Data object '%s' currently exists") : _("Data object '%s' currently does not exist"), path); g_print ("\n"); if (print_dir_check) { gboolean check; check = tracker_miner_files_check_directory (file, tracker_config_get_index_recursive_directories (config), tracker_config_get_index_single_directories (config), tracker_config_get_ignored_directory_paths (config), tracker_config_get_ignored_directory_patterns (config)); g_print (" %s\n", check ? _("Directory is eligible to be mined (based on rules)") : _("Directory is NOT eligible to be mined (based on rules)")); would_index &= check; } if (print_dir_check_with_content) { GList *children; gboolean check; children = get_dir_children_as_gfiles (path); check = tracker_miner_files_check_directory_contents (file, children, tracker_config_get_ignored_directories_with_content (config)); g_list_foreach (children, (GFunc) g_object_unref, NULL); g_list_free (children); g_print (" %s\n", check ? _("Directory is eligible to be mined (based on contents)") : _("Directory is NOT eligible to be mined (based on contents)")); would_index &= check; } if (print_monitor_check) { gboolean check = TRUE; check &= tracker_config_get_enable_monitors (config); if (check) { GSList *dirs_to_check, *l; gboolean is_covered_single; gboolean is_covered_recursive; is_covered_single = FALSE; dirs_to_check = tracker_config_get_index_single_directories (config); for (l = dirs_to_check; l && !is_covered_single; l = l->next) { GFile *dir; GFile *parent; parent = g_file_get_parent (file); dir = g_file_new_for_path (l->data); is_covered_single = g_file_equal (parent, dir) || g_file_equal (file, dir); g_object_unref (dir); g_object_unref (parent); } is_covered_recursive = FALSE; dirs_to_check = tracker_config_get_index_recursive_directories (config); for (l = dirs_to_check; l && !is_covered_recursive; l = l->next) { GFile *dir; dir = g_file_new_for_path (l->data); is_covered_recursive = g_file_has_prefix (file, dir) || g_file_equal (file, dir); g_object_unref (dir); } check &= is_covered_single || is_covered_recursive; } if (exists && is_dir) { g_print (" %s\n", check ? _("Directory is eligible to be monitored (based on config)") : _("Directory is NOT eligible to be monitored (based on config)")); } else if (exists && !is_dir) { g_print (" %s\n", check ? _("File is eligible to be monitored (based on config)") : _("File is NOT eligible to be monitored (based on config)")); } else { g_print (" %s\n", check ? _("File or Directory is eligible to be monitored (based on config)") : _("File or Directory is NOT eligible to be monitored (based on config)")); } would_notice &= check; } if (print_file_check) { gboolean check; check = tracker_miner_files_check_file (file, tracker_config_get_ignored_file_paths (config), tracker_config_get_ignored_file_patterns (config)); g_print (" %s\n", check ? _("File is eligible to be mined (based on rules)") : _("File is NOT eligible to be mined (based on rules)")); would_index &= check; } g_print ("\n" "%s: %s\n" "%s: %s\n" "\n", _("Would be indexed"), would_index ? _("Yes") : _("No"), _("Would be monitored"), would_notice ? _("Yes") : _("No")); if (log_handler_id != 0) { /* Unset log handler */ g_log_remove_handler (NULL, log_handler_id); } g_free (path); g_object_unref (config); g_object_unref (file); }
void nautilus_drag_default_drop_action_for_icons (GdkDragContext *context, const char *target_uri_string, const GList *items, int *action) { gboolean same_fs; gboolean target_is_source_parent; const char *dropped_uri; GFile *target, *dropped; GdkDragAction actions; NautilusFile *target_file; if (target_uri_string == NULL) { *action = 0; return; } actions = context->actions & (GDK_ACTION_MOVE | GDK_ACTION_COPY); if (actions == 0) { /* We can't use copy or move, just go with the suggested action. */ *action = context->suggested_action; return; } if (context->suggested_action == GDK_ACTION_ASK) { /* Don't override ask */ *action = context->suggested_action; return; } dropped_uri = ((NautilusDragSelectionItem *)items->data)->uri; target_file = nautilus_file_get_existing_by_uri (dropped_uri); /* * Check for trash URI. We do a find_directory for any Trash directory. * Passing 0 permissions as gnome-vfs would override the permissions * passed with 700 while creating .Trash directory */ if (eel_uri_is_trash (target_uri_string)) { /* Only move to Trash */ if (actions & GDK_ACTION_MOVE) { *action = GDK_ACTION_MOVE; } nautilus_file_unref (target_file); return; } else if (target_file != NULL && nautilus_file_is_launcher (target_file)) { if (actions & GDK_ACTION_MOVE) { *action = GDK_ACTION_MOVE; } nautilus_file_unref (target_file); return; } else if (eel_uri_is_desktop (target_uri_string)) { target = nautilus_get_desktop_location (); if (eel_uri_is_desktop (dropped_uri)) { /* Only move to Desktop icons */ if (actions & GDK_ACTION_MOVE) { *action = GDK_ACTION_MOVE; } nautilus_file_unref (target_file); return; } } else { target = g_file_new_for_uri (target_uri_string); } nautilus_file_unref (target_file); /* Compare the first dropped uri with the target uri for same fs match. */ dropped = g_file_new_for_uri (dropped_uri); same_fs = check_same_fs (target, dropped); target_is_source_parent = g_file_has_prefix (dropped, target); if (same_fs || target_is_source_parent || g_file_has_uri_scheme (dropped, "trash")) { if (actions & GDK_ACTION_MOVE) { *action = GDK_ACTION_MOVE; } else { *action = context->suggested_action; } } else { if (actions & GDK_ACTION_COPY) { *action = GDK_ACTION_COPY; } else { *action = context->suggested_action; } } g_object_unref (target); g_object_unref (dropped); }
/** * anjuta_session_get_relative_uri_from_file: * @session: an #AnjutaSession object * @file: a GFile * @fragment: an optional fragment * * Return an URI relative to the session directory file with an optional * fragment. * It is useful to keep only relative file paths in a session file to be able * to copy the whole project without breaking references. * * Returns: (transfer full): A string that has to be freed with g_free(). */ gchar * anjuta_session_get_relative_uri_from_file (AnjutaSession *session, GFile *file, const gchar *fragment) { GFile *parent; gchar *uri; gint level; parent = g_file_new_for_path (session->priv->dir_path); for (level = 0; (parent != NULL) && !g_file_equal (file, parent) && !g_file_has_prefix (file, parent); level++) { GFile *next = g_file_get_parent (parent); g_object_unref (parent); parent = next; } if (parent == NULL) { uri = g_file_get_uri (file); } else { gchar *path; if (g_file_equal (file, parent)) { uri = g_strdup("."); } else { path = g_file_get_relative_path (parent, file); uri = g_uri_escape_string (path, G_URI_RESERVED_CHARS_ALLOWED_IN_PATH, TRUE); g_free (path); } if (level != 0) { gsize len; gchar *buffer; gchar *ptr; len = strlen (uri); buffer = g_new (gchar, len + level * 3 + 1); for (ptr = buffer; level; level--) { memcpy (ptr, ".." G_DIR_SEPARATOR_S, 3); ptr += 3; } memcpy (ptr, uri, len + 1); g_free (uri); uri = buffer; } } if (fragment != NULL) { gchar *with_fragment; with_fragment = g_strconcat (uri, "#", fragment, NULL); g_free (uri); uri = with_fragment; } return uri; }
char * panel_xdg_icon_name_from_icon_path (const char *path, GdkScreen *screen) { GtkIconTheme *theme; GtkSettings *settings; char *theme_name; char *icon; char **paths; int n_paths; int i; GFile *file; /* we look if the icon comes from the current icon theme */ if (!screen) screen = gdk_screen_get_default (); settings = gtk_settings_get_for_screen (screen); g_object_get (settings, "gtk-icon-theme-name", &theme_name, NULL); theme = gtk_icon_theme_get_for_screen (screen); gtk_icon_theme_get_search_path (theme, &paths, &n_paths); file = g_file_new_for_path (path); icon = NULL; for (i = 0; i < n_paths; i++) { GFile *parent; char *basename; parent = g_file_new_for_path (paths[i]); if (!g_file_has_prefix (file, parent)) { g_object_unref (parent); continue; } basename = g_file_get_basename (parent); if (g_strcmp0 (basename, "pixmaps") == 0) { char *relative_path; relative_path = g_file_get_relative_path (parent, file); /* if the icon is in a subdir of pixmaps, then it's not * a real icon name */ if (!strchr (relative_path, G_DIR_SEPARATOR)) icon = panel_xdg_icon_remove_extension (relative_path); g_free (relative_path); } else { /* real icon theme; but is it the current one? */ GFile *theme_dir; gboolean current; theme_dir = g_file_get_child (parent, theme_name); current = FALSE; if (g_file_has_prefix (file, theme_dir)) { /* it's the current one */ current = TRUE; } else { /* it's the default one */ g_object_unref (theme_dir); theme_dir = g_file_get_child (parent, DEFAULT_THEME_NAME); current = g_file_has_prefix (file, theme_dir); } g_object_unref (theme_dir); if (current) { char *buffer; buffer = g_file_get_basename (file); icon = panel_xdg_icon_remove_extension (buffer); g_free (buffer); } } g_free (basename); g_object_unref (parent); break; } g_object_unref (file); g_free (theme_name); return icon; }
static void xdg_cache_cache_copy_or_move (TumblerCache *cache, gboolean do_copy, const gchar *const *from_uris, const gchar *const *to_uris) { XDGCacheCache *xdg_cache = XDG_CACHE_CACHE (cache); GFileInfo *info; guint64 mtime; GFile *dest_source_file; GList *iter; guint n; GFile *dummy_file; GFile *parent; gchar *dirname; GDir *dir; const gchar *file_basename; gchar *filename; gchar *uri; GFile *original_file; GFile *base_file; gchar *to_uri; g_return_if_fail (XDG_CACHE_IS_CACHE (cache)); g_return_if_fail (from_uris != NULL); g_return_if_fail (to_uris != NULL); for (iter = xdg_cache->flavors; iter != NULL; iter = iter->next) { for (n = 0; n < g_strv_length ((gchar **)from_uris); ++n) { dest_source_file = g_file_new_for_uri (to_uris[n]); info = g_file_query_info (dest_source_file, G_FILE_ATTRIBUTE_STANDARD_TYPE "," G_FILE_ATTRIBUTE_TIME_MODIFIED, G_FILE_QUERY_INFO_NONE, NULL, NULL); if (info == NULL) { g_object_unref (dest_source_file); continue; } if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) { /* compute the flavor directory filename */ dummy_file = xdg_cache_cache_get_file ("foo", iter->data); parent = g_file_get_parent (dummy_file); dirname = g_file_get_path (parent); g_object_unref (parent); g_object_unref (dummy_file); /* the base path */ base_file = g_file_new_for_uri (from_uris[n]); /* attempt to open the directory for reading */ dir = g_dir_open (dirname, 0, NULL); if (dir != NULL) { /* iterate over all files in the directory */ file_basename = g_dir_read_name (dir); while (file_basename != NULL) { /* build the thumbnail filename */ filename = g_build_filename (dirname, file_basename, NULL); /* read thumbnail information from the file */ if (xdg_cache_cache_read_thumbnail_info (filename, &uri, &mtime, NULL, NULL) && uri != NULL) { /* create a GFile for the original URI. we need this for * reliably checking the ancestor/descendant relationship */ original_file = g_file_new_for_uri (uri); /* check if we have a thumbnail that is located in the moved/copied folder */ if (g_file_equal (original_file, base_file) || g_file_has_prefix (original_file, base_file)) { /* build the new target (replace old base with new base) */ to_uri = g_build_filename (to_uris[n], uri + strlen (from_uris[n]), NULL); /* move or copy the thumbnail */ xdg_cache_cache_copy_or_move_file (cache, iter->data, do_copy, uri, to_uri, mtime); g_free (to_uri); } g_object_unref (original_file); g_free (uri); } g_free (filename); /* try to determine the next filename in the directory */ file_basename = g_dir_read_name (dir); } g_dir_close (dir); } g_free (dirname); g_object_unref (base_file); } else { mtime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED); xdg_cache_cache_copy_or_move_file (cache, iter->data, do_copy, from_uris[n], to_uris[n], mtime); } g_object_unref (info); g_object_unref (dest_source_file); } } }
static void xdg_cache_cache_cleanup (TumblerCache *cache, const gchar *const *base_uris, guint64 since) { XDGCacheCache *xdg_cache = XDG_CACHE_CACHE (cache); const gchar *file_basename; guint64 mtime; GFile *base_file; GFile *dummy_file; GFile *original_file; GFile *parent; GList *iter; gchar *dirname; gchar *filename; gchar *uri; guint n; GDir *dir; g_return_if_fail (XDG_CACHE_IS_CACHE (cache)); /* iterate over all flavors */ for (iter = xdg_cache->flavors; iter != NULL; iter = iter->next) { /* compute the flavor directory filename */ dummy_file = xdg_cache_cache_get_file ("foo", iter->data); parent = g_file_get_parent (dummy_file); dirname = g_file_get_path (parent); g_object_unref (parent); g_object_unref (dummy_file); /* attempt to open the directory for reading */ dir = g_dir_open (dirname, 0, NULL); if (dir != NULL) { /* iterate over all files in the directory */ file_basename = g_dir_read_name (dir); while (file_basename != NULL) { /* build the thumbnail filename */ filename = g_build_filename (dirname, file_basename, NULL); /* read thumbnail information from the file */ if (xdg_cache_cache_read_thumbnail_info (filename, &uri, &mtime, NULL, NULL)) { /* check if the thumbnail information is valid or the mtime * is too old */ if (uri == NULL || mtime <= since) { /* it's invalid, so let's remove the thumbnail */ g_unlink (filename); } else { /* create a GFile for the original URI. we need this for * reliably checking the ancestor/descendant relationship */ original_file = g_file_new_for_uri (uri); for (n = 0; base_uris != NULL && base_uris[n] != NULL; ++n) { /* create a GFile for the base URI */ base_file = g_file_new_for_uri (base_uris[n]); /* delete the file if it is a descendant of the base URI */ if (g_file_equal (original_file, base_file) || g_file_has_prefix (original_file, base_file)) { g_unlink (filename); } /* releas the base file */ g_object_unref(base_file); } /* release the original file */ g_object_unref (original_file); } } /* free the thumbnail filename */ g_free (filename); /* try to determine the next filename in the directory */ file_basename = g_dir_read_name (dir); } /* close the handle used to reading from the directory */ g_dir_close (dir); } /* free the thumbnail flavor directory filename */ g_free (dirname); } }
static void file_view_select_from_iter (AnjutaFileView* view, GtkTreeIter iter) { AnjutaFileViewPrivate* priv = ANJUTA_FILE_VIEW_GET_PRIVATE (view); GtkTreeModelSort* model_sort; gboolean valid; GtkTreeIter sort_iter; GFile* file; model_sort = GTK_TREE_MODEL_SORT (gtk_tree_view_get_model (GTK_TREE_VIEW (view))); do { gboolean is_dummy, is_dir; gtk_tree_model_get (GTK_TREE_MODEL (priv->model), &iter, COLUMN_FILE, &file, COLUMN_DUMMY, &is_dummy, COLUMN_IS_DIR, &is_dir, -1); if (is_dummy) break; if (g_file_equal (priv->pending_selected_file, file)) { file_view_select_iter (view, iter); break; } else if (g_file_has_prefix (priv->pending_selected_file, file)) { if (is_dir) { GtkTreePath *path = NULL; gtk_tree_model_sort_convert_child_iter_to_iter (model_sort, &sort_iter, &iter); path = gtk_tree_model_get_path (GTK_TREE_MODEL (model_sort), &sort_iter); if (gtk_tree_view_row_expanded (GTK_TREE_VIEW (view), path)) { GtkTreeIter parent = iter; valid = gtk_tree_model_iter_children (GTK_TREE_MODEL (priv->model), &iter, &parent); gtk_tree_path_free (path); } else { gtk_tree_view_expand_row (GTK_TREE_VIEW (view), path, FALSE); gtk_tree_path_free (path); break; } } else { file_view_select_iter (view, iter); break; } } else valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->model), &iter); g_clear_object (&file); } while (valid); if (file) g_object_unref (file); }