/* Sets, unsets or changes the pathname and name for an icon. * Updates icons_hash and (re)stats the item. * If name is NULL then gets the leafname from pathname. * If pathname is NULL, frees everything. */ void icon_set_path(Icon *icon, const char *pathname, const char *name) { if (icon->path) { icon_unhash_path(icon); icon->src_path = NULL; icon->path = NULL; diritem_free(icon->item); icon->item = NULL; } if (pathname) { if (g_utf8_validate(pathname, -1, NULL)) icon->src_path = g_strdup(pathname); else icon->src_path = to_utf8(pathname); icon->path = expand_path(icon->src_path); icon_hash_path(icon); if (!name) name = g_basename(icon->src_path); icon->item = diritem_new(name); diritem_restat(icon->path, icon->item, NULL); } }
/* Convert uri to path and call run_by_path() */ gboolean run_by_uri(const gchar *uri, gchar **errmsg) { gboolean retval; gchar *tmp, *tmp2; gchar *scheme; gchar *cmd; scheme=get_uri_scheme((EscapedPath *) uri); if(!scheme) { *errmsg=g_strdup_printf(_("'%s' is not a valid URI"), uri); return FALSE; } if(strcmp(scheme, "file")==0) { tmp=get_local_path((EscapedPath *) uri); if(tmp) { tmp2=pathdup(tmp); retval=run_by_path(tmp2); if(!retval) *errmsg=g_strdup_printf(_("%s not accessable"), tmp); g_free(tmp2); g_free(tmp); } else { retval=FALSE; *errmsg=g_strdup_printf(_("Non-local URL %s"), uri); } } else if((cmd=choices_find_xdg_path_load(scheme, "URI", SITE))) { DirItem *item; item=diritem_new(scheme); diritem_restat(cmd, item, NULL); run_with_args(cmd, item, uri); retval=TRUE; /* we hope... */ diritem_free(item); g_free(cmd); } else { retval=FALSE; *errmsg=g_strdup_printf(_("%s: no handler for %s"), uri, scheme); } g_free(scheme); return retval; }
/* Attempt to open this item */ gboolean run_by_path(const guchar *full_path) { gboolean retval; DirItem *item; /* XXX: Loads an image - wasteful */ item = diritem_new(""); diritem_restat(full_path, item, NULL); retval = run_diritem(full_path, item, NULL, NULL, FALSE); diritem_free(item); return retval; }
/* Get the type of this file - stats the file and uses that if * possible. For regular or missing files, uses the pathname. */ MIME_type *type_get_type(const guchar *path) { DirItem *item; MIME_type *type = NULL; item = diritem_new((guchar*)""); diritem_restat(path, item, NULL); if (item->base_type != TYPE_ERROR) type = item->mime_type; diritem_free(item); if (type) return type; type = type_from_path((char*)path); if (!type) return text_plain; return type; }