示例#1
0
/**
 * fm_path_new_for_display_name
 * @path_name: a UTF-8 encoded display name for the path
 * It can either be a POSIX path in UTF-8 encoding, or an unescaped URI
 *  (can contain non-ASCII characters and spaces)
 *
 * You can call fm_path_display_name () to convert a FmPath to a
 * UTF-8 encoded name ready for being displayed in the GUI.
 *
 * Returns: a newly created FmPath for the path. You have to call
 * fm_path_unref () when it's no longer needed.
 */
FmPath *fm_path_new_for_display_name (const char *path_name)
{
    FmPath *path;
    
    if (!path_name || !*path_name ||  (path_name[0]=='/' && path_name[1] == '\0'))
        return fm_path_ref (root_path);
    
    if (path_name[0] == '/') // native path
    {
        char *filename = g_filename_from_utf8 (path_name, -1, NULL, NULL, NULL);
        if (filename) // convert from utf-8 to local encoding
        {
            path = fm_path_new_for_path (filename);
            g_free (filename);
        }
        else
            path = fm_path_ref (root_path);
    }
    else // this is an URI
    {
        // UTF-8 should be allowed, I think.
        path = _fm_path_new_for_uri_internal (path_name, FALSE);
    }
    return path;
}
示例#2
0
FmPath* fm_path_new_child_len(FmPath* parent, const char* basename, int name_len)
{
	FmPath* path;
    if(parent) /* remove tailing slash if needed. */
    {
        while(basename[name_len-1] == '/')
            --name_len;
    }

    /* special case for . and .. */
    if(basename[0] == '.' && (name_len == 1 || (name_len == 2 && basename[1] == '.')))
    {
        if(name_len == 1) /* . */
            return parent ? fm_path_ref(parent) : NULL;
        else /* .. */
            return parent && parent->parent ? fm_path_ref(parent->parent) : NULL;
    }

	path = (FmPath*)g_malloc(sizeof(FmPath) + name_len);
	path->n_ref = 1;
	if(G_LIKELY(parent))
	{
		path->flags = parent->flags;
		path->parent = fm_path_ref(parent);
	}
	else
	{
    	path->flags = 0;
		if(*basename == '/') /* it's a native full path */
        {
			path->flags |= FM_PATH_IS_NATIVE|FM_PATH_IS_LOCAL;
            /* FIXME: should we add FM_PATH_IS_LOCAL HERE? */
            /* For example: a FUSE mounted remote filesystem is a native path, but it's not local. */
        }
		else
		{
            /* FIXME: do we have more efficient way here? */
			/* FIXME: trash:///, computer:///, network:/// are virtual paths */
            /* FIXME: add // if only trash:/ is supplied in basename */
            if(strncmp(basename, "trash:", 6) == 0) /* trashed files are on local filesystems */
    			path->flags |= FM_PATH_IS_TRASH|FM_PATH_IS_VIRTUAL|FM_PATH_IS_LOCAL;
            else if(strncmp(basename, "computer:", 9) == 0)
    			path->flags |= FM_PATH_IS_VIRTUAL;
            else if(strncmp(basename, "network:", 8) == 0)
    			path->flags |= FM_PATH_IS_VIRTUAL;
            else if(strncmp(basename, "applications:", 13) == 0)
    			path->flags |= FM_PATH_IS_VIRTUAL;
		}
		path->parent = NULL;
	}
	memcpy(path->name, basename, name_len);
	path->name[name_len] = '\0';
	return path;
}
示例#3
0
/**
 * fm_path_new_relative
 * @parent: a parent path
 * @rel: a path relative to @parent in glib filename encoding.  (can be
 * non-UTF-8). However this should not be a escaped ASCII string used in
 * URI. If you're building a relative path for a URI, and the relative
 * path is escaped, you have to unescape it first.
 *
 * For example, if @parent is "http://wiki.lxde.org/" and @rel is
 * "zh/%E9%A6%96%E9%A0%81", you have to unescape the relative path
 * prior to passing it to fm_path_new_relative ().
 *
 * If @parent is NULL, this works the same as fm_path_new_for_str (@rel)
 *
 * Returns: a newly created FmPath for the path. You have to call
 * fm_path_unref () when it's no longer needed.
 */
FmPath *fm_path_new_relative (FmPath *parent, const char *rel)
{
    FmPath *path;
    
    if (G_UNLIKELY (!rel || !*rel)) // relative path is empty
        return parent ? fm_path_ref (parent) : fm_path_ref (root_path); // return parent

    if (G_LIKELY (parent))
    {
        char *sep;
        
        // remove leading slashes
        while (*rel == '/')
            ++rel;
        
        if (!*rel)
            path = fm_path_ref (parent);
        else
        {
#if 0       // FIXME_pcm: Let's optimize this later. Make things working first is more important.
            // use some pre-defined paths when possible
            if (G_UNLIKELY (parent == root_path))
            {
                if (strcmp (home_dir + 1, rel) == 0)
                    return fm_path_ref (home_path);
                if (strcmp (desktop_dir + 1, rel) == 0)
                    return fm_path_ref (desktop_dir);
            }
#endif

            sep = strchr (rel, '/');
            if (sep)
            {
                FmPath *new_parent = fm_path_new_child_len (parent, rel, sep - rel);
                path = fm_path_new_relative (new_parent, sep + 1);
                fm_path_unref (new_parent);
            }
            else
            {
                path = fm_path_new_child (parent, rel);
            }
        }
    }
    else // this is actaully a full path
        path = fm_path_new_for_str (rel);
    
    return path;
}
/**
 * fm_dir_list_job_new2
 * @path: path to directory to get listing
 * @flags: listing output mode for new job
 *
 * Creates a new #FmDirListJob for directory listing.
 *
 * Returns: (transfer full): a new #FmDirListJob object.
 *
 * Since: 1.2.0
 */
FmDirListJob *fm_dir_list_job_new2(FmPath *path, FmDirListJobFlags flags)
{
    FmDirListJob* job = (FmDirListJob*)g_object_new(FM_TYPE_DIR_LIST_JOB, NULL);
    job->dir_path = fm_path_ref(path);
    job->flags = flags;
    return job;
}
示例#5
0
void fm_path_entry_set_model(FmPathEntry *entry, FmPath* path, FmFolderModel* model)
{
    FmPathEntryPrivate *priv = FM_PATH_ENTRY_GET_PRIVATE(entry);
    /* FIXME: should we use UTF-8 encoded display name here? */
    gchar *path_str = fm_path_display_name(path, FALSE);
    if(priv->path)
        fm_path_unref(priv->path);
    priv->path = fm_path_ref(path);

    if( priv->model )
        g_object_unref( priv->model );
    if( priv->completion_model )
        g_object_unref(priv->completion_model);
    if(model)
    {
        priv->model = g_object_ref(model);
        priv->completion_model = g_object_ref(model);
        gtk_entry_set_completion(GTK_ENTRY(entry), priv->completion);
    }
    else
    {
        priv->model = NULL;
        priv->completion_model = NULL;
        gtk_entry_set_completion(GTK_ENTRY(entry), NULL);
    }
    gtk_entry_completion_set_model( priv->completion, (GtkTreeModel*)priv->completion_model );
    priv->in_change = TRUE;
    gtk_entry_set_text(GTK_ENTRY(entry), path_str);
    priv->in_change = FALSE;
    gtk_editable_set_position(GTK_EDITABLE(entry), -1);
    g_free(path_str);
}
示例#6
0
static void create_trash_item(FmPlacesModel* model)
{
    GtkTreeIter it;
    FmPlaceItem* item;
    GdkPixbuf* pix;
    GFile* gf;

    gf = g_file_new_for_uri("trash:///");
    model->trash_monitor = fm_monitor_directory(gf, NULL);
    g_signal_connect(model->trash_monitor, "changed", G_CALLBACK(on_trash_changed), model);
    g_object_unref(gf);

    item = g_slice_new0(FmPlaceItem);
    item->type = FM_PLACES_ITEM_PATH;
    item->fi = fm_file_info_new();
    item->fi->path = fm_path_ref(fm_path_get_trash());
    item->fi->icon = fm_icon_from_name("user-trash");
    gtk_list_store_insert(GTK_LIST_STORE(model), &it, 2);
    pix = fm_icon_get_pixbuf(item->fi->icon, fm_config->pane_icon_size);
    gtk_list_store_set(GTK_LIST_STORE(model), &it, FM_PLACES_MODEL_COL_ICON, pix, FM_PLACES_MODEL_COL_LABEL, _("Trash"), FM_PLACES_MODEL_COL_INFO, item, -1);
    g_object_unref(pix);
    model->trash_it = it;

    if(0 == model->trash_idle)
        model->trash_idle = g_idle_add((GSourceFunc)update_trash_item, model);
}
示例#7
0
void create_trash()
{
    GtkTreeIter it;
    PlaceItem* item;
    GdkPixbuf* pix;
    GFile* gf;

    gf = g_file_new_for_uri("trash:///");
    trash_monitor = fm_monitor_directory(gf, NULL);
    g_signal_connect(trash_monitor, "changed", G_CALLBACK(on_trash_changed), NULL);
    g_object_unref(gf);

    item = g_slice_new0(PlaceItem);
    item->type = PLACE_PATH;
    item->path = fm_path_ref(fm_path_get_trash());
    item->icon = fm_icon_from_name("user-trash");
    gtk_list_store_insert(model, &it, 2);
    pix = fm_icon_get_pixbuf(item->icon, fm_config->pane_icon_size);
    gtk_list_store_set(model, &it, COL_ICON, pix, COL_LABEL, _("Trash"), COL_INFO, item, -1);
    g_object_unref(pix);
    trash_it = it;

    if(0 == trash_idle)
        trash_idle = g_idle_add((GSourceFunc)update_trash, NULL);
}
示例#8
0
/**
 * fm_path_new_for_uri
 * @path_name: a URI with special characters escaped.
 * Encoded URI such as http://wiki.lxde.org/zh/%E9%A6%96%E9%A0%81
 * will be unescaped.
 *
 * You can call fm_path_to_uri () to convert a FmPath to a escaped URI
 * string.
 *
 * Returns: a newly created FmPath for the path. You have to call
 * fm_path_unref () when it's no longer needed.
 */
static FmPath *_fm_path_new_for_uri_internal (const char *uri, gboolean need_unescape)
{
    FmPath *path, *root;
    const char *rel_path;
    
    if (!uri || !*uri)
        return fm_path_ref (root_path);

    root = _fm_path_new_uri_root (uri, strlen (uri), &rel_path, need_unescape);
    
    if (*rel_path)
    {
        if (need_unescape)
            rel_path = g_uri_unescape_string (rel_path, NULL);
        
        path = fm_path_new_relative (root, rel_path);
        fm_path_unref (root);
        
        if (need_unescape)
            g_free ((char*)rel_path);
    }
    else
    {
        path = root;
    }
    return path;
}
示例#9
0
static void fm_path_entry_paste_and_go(GtkMenuItem *menuitem, GtkEntry *entry)
{
    GtkClipboard* clipboard = gtk_clipboard_get_for_display(
        gtk_widget_get_display (GTK_WIDGET (menuitem)),GDK_SELECTION_CLIPBOARD);

    gchar* full_path = gtk_clipboard_wait_for_text(clipboard);

    if (full_path)
    {

        FmPathEntryPrivate *priv  = FM_PATH_ENTRY_GET_PRIVATE(entry);

        if(priv->path)
            fm_path_unref(priv->path);

        /* special handling for home dir */
        if(full_path[0] == '~' && full_path[1] == G_DIR_SEPARATOR)
            priv->path = fm_path_new_relative(fm_path_get_home(), full_path + 2);
        else if(full_path[0] == '~' && full_path[1] == 0)
            priv->path = fm_path_ref(fm_path_get_home());
        else
            priv->path = fm_path_new_for_str(full_path);

        gchar * disp_name = fm_path_display_name(priv->path, FALSE);
        gtk_entry_set_text(entry, disp_name);
        g_free(disp_name);

        gtk_editable_set_position(GTK_EDITABLE(entry), -1);

        g_free(full_path);

        fm_path_entry_activate(FM_PATH_ENTRY(entry));
    }
}
示例#10
0
static void  fm_path_entry_on_activate(GtkEntry *entry, gpointer user_data)
{
    FmPathEntryPrivate *priv  = FM_PATH_ENTRY_GET_PRIVATE(entry);
    const char* full_path;
    char* disp_name;
    /* convert current path string to FmPath here */

    full_path = gtk_entry_get_text(entry);
    if(priv->path)
        fm_path_unref(priv->path);

    /* special handling for home dir */
    if(full_path[0] == '~' && full_path[1] == G_DIR_SEPARATOR)
        priv->path = fm_path_new_relative(fm_path_get_home(), full_path + 2);
    else if(full_path[0] == '~' && full_path[1] == 0)
        priv->path = fm_path_ref(fm_path_get_home());
    else
        priv->path = fm_path_new_for_str(full_path);

    disp_name = fm_path_display_name(priv->path, FALSE);
    gtk_entry_set_text(entry, disp_name);
    g_free(disp_name);

    gtk_editable_set_position(GTK_EDITABLE(entry), -1);
}
示例#11
0
inline static void cache_thumbnail_in_hash(FmPath* path, GdkPixbuf* pix, guint size)
{
    ThumbnailCache* cache;
    ThumbnailCacheItem* item;
    GSList* l = NULL;
    cache = (ThumbnailCache*)g_hash_table_lookup(hash, path);
    if(cache)
    {
        for(l=cache->items;l;l=l->next)
        {
            item = (ThumbnailCacheItem*)l->data;
            if(item->size == size)
                break;
        }
    }
    else
    {
        cache = g_slice_new0(ThumbnailCache);
        cache->path = fm_path_ref(path);
        g_hash_table_insert(hash, cache->path, cache);
    }
    if(!l) /* the item is not in cache->items */
    {
        item = g_slice_new(ThumbnailCacheItem);
        item->size = size;
        item->pix = pix;
        cache->items = g_slist_prepend(cache->items, item);
        g_object_weak_ref(G_OBJECT(pix), (GWeakNotify)on_pixbuf_destroy, cache);
    }
}
/**
 * fm_dir_list_job_new
 * @path: path to directory to get listing
 * @dir_only: %TRUE to include only directories in the list
 *
 * Creates a new #FmDirListJob for directory listing. If @dir_only is
 * %TRUE then objects other than directories will be omitted from the
 * listing.
 *
 * Returns: (transfer full): a new #FmDirListJob object.
 *
 * Since: 0.1.0
 *
 * Deprecated: 1.2.0: Use fm_dir_list_job_new2() instead.
 */
FmDirListJob* fm_dir_list_job_new(FmPath* path, gboolean dir_only)
{
    FmDirListJob* job = (FmDirListJob*)g_object_new(FM_TYPE_DIR_LIST_JOB, NULL);
    job->dir_path = fm_path_ref(path);
    job->flags = dir_only ? FM_DIR_LIST_JOB_DIR_ONLY : FM_DIR_LIST_JOB_FAST;
    return job;
}
示例#13
0
static void fm_path_entry_changed(GtkEditable *editable)
{
    FmPathEntry *entry = FM_PATH_ENTRY(editable);
    FmPathEntryPrivate *priv  = FM_PATH_ENTRY_GET_PRIVATE(entry);
    const gchar *original_key = gtk_entry_get_text( GTK_ENTRY(entry) );
    /* len of directory part */
    gint key_dir_len;
    gchar *last_slash = strrchr(original_key, G_DIR_SEPARATOR);

    if( priv->in_change || !priv->path )
        return;

    /* not path -> keep current completion model */
    if( last_slash == NULL )
        return;

    /* Check if path entry is not part of current completion folder model */
    key_dir_len = last_slash - original_key;
    if( !fm_path_equal_str(priv->path, original_key, key_dir_len) )
    {
        gchar* new_path = g_path_get_dirname(original_key);
        FmPath *new_fm_path = fm_path_new(new_path);
        g_free(new_path);
        if( new_fm_path != NULL )
        {
            /* set hidden parameter based on prev. model */
            /* FIXME: this is not very good */
            gboolean show_hidden = priv->completion_model ? fm_folder_model_get_show_hidden(priv->completion_model) : FALSE;
            if(priv->completion_model)
                g_object_unref(priv->completion_model);
            if(priv->model && fm_path_equal(priv->model->dir->dir_path, new_fm_path))
            {
                if(priv->path)
                    fm_path_unref(priv->path);
                priv->path = fm_path_ref(priv->model->dir->dir_path);
                fm_path_unref(new_fm_path);
                priv->completion_model = g_object_ref(priv->model);
            }
            else
            {
                FmFolder *new_fm_folder = fm_folder_get_for_path(new_fm_path);
                FmFolderModel *new_fm = fm_folder_model_new(new_fm_folder, show_hidden);
                g_object_unref(new_fm_folder);
                priv->completion_model = new_fm;
                if(priv->path)
                    fm_path_unref(priv->path);
                priv->path = new_fm_path;
            }
            gtk_entry_completion_set_model( priv->completion, GTK_TREE_MODEL(priv->completion_model) );
        }
        else
        {
            /* FIXME: Handle invalid Paths */
            g_warning("Invalid Path: %s", new_path);
        }
    }
}
示例#14
0
gboolean fm_folder_view_chdir(FmFolderView* fv, FmPath* path)
{
    FmFolderModel* model;
    FmFolder* folder;

    if(fv->folder)
    {
        g_signal_handlers_disconnect_by_func(fv->folder, on_folder_loaded, fv);
        g_signal_handlers_disconnect_by_func(fv->folder, on_folder_unmounted, fv);
        g_signal_handlers_disconnect_by_func(fv->folder, on_folder_err, fv);
        g_object_unref(fv->folder);
        fv->folder = NULL;
        if(fv->model)
        {
            model = FM_FOLDER_MODEL(fv->model);
            g_signal_handlers_disconnect_by_func(model, on_sort_col_changed, fv);
            if(model->dir)
                g_signal_handlers_disconnect_by_func(model->dir, on_folder_err, fv);
            g_object_unref(model);
            fv->model = NULL;
        }
    }

    /* FIXME: the signal handler should be able to cancel the loading. */
    g_signal_emit(fv, signals[DIRECTORY_CHANGED], 0, path);
    if(fv->cwd)
        fm_path_unref(fv->cwd);
    fv->cwd = fm_path_ref(path);

    fv->folder = folder = fm_folder_get(path);
    if(folder)
    {
        /* connect error handler */
        g_signal_connect(folder, "loaded", on_folder_loaded, fv);
        g_signal_connect(folder, "unmount", on_folder_unmounted, fv);
        g_signal_connect(folder, "error", on_folder_err, fv);
        if(fm_folder_get_is_loaded(folder))
            on_folder_loaded(folder, fv);
        else
        {
            switch(fv->mode)
            {
            case FM_FV_LIST_VIEW:
                cancel_pending_row_activated(fv);
                gtk_tree_view_set_model(GTK_TREE_VIEW(fv->view), NULL);
                break;
            case FM_FV_ICON_VIEW:
            case FM_FV_COMPACT_VIEW:
            case FM_FV_THUMBNAIL_VIEW:
                exo_icon_view_set_model(EXO_ICON_VIEW(fv->view), NULL);
                break;
            }
            fv->model = NULL;
        }
    }
    return TRUE;
}
示例#15
0
static FmPath *_fm_path_alloc (FmPath *parent, int name_len, int flags)
{
    FmPath *path = (FmPath*) g_malloc (sizeof(FmPath) + name_len);
    path->n_ref = 1;
    
    path->flags = parent ? flags : (flags | FM_PATH_IS_ROOT);
    path->parent = parent ? fm_path_ref (parent) : NULL;
    
    return path;
}
示例#16
0
/**
 * fm_path_new_for_commandline_arg
 * @arg: a file path passed in command line argv to the program. The @arg
 * can be a POSIX path in glib filename encoding  (can be non-UTTF-8) and
 * can be a URI with non-ASCII characters escaped, like
 * http://wiki.lxde.org/zh/%E9%A6%96%E9%A0%81.
 *
 * Returns: a newly created FmPath for the path. You have to call
 * fm_path_unref () when it's no longer needed.
 */
FmPath *fm_path_new_for_commandline_arg (const char *arg)
{
    if (!arg || !*arg ||  (arg[0]=='/' && arg[1] == '\0'))
        return fm_path_ref (root_path);
    
    if (arg[0] == '/')
        return fm_path_new_for_path (arg);
    
    return _fm_path_new_for_uri_internal (arg, TRUE);
}
示例#17
0
/**
 * fm_path_new_child
 * @parent: a parent path
 * @basename: basename of a direct child of @parent directory in glib
 * filename encoding.  (can be non-UTF-8).
 *
 * Returns: a newly created FmPath for the path. You have to call
 * fm_path_unref () when it's no longer needed.
 */
FmPath *fm_path_new_child (FmPath *parent, const char *basename)
{
    if (G_LIKELY (basename && *basename))
    {
        int baselen = strlen (basename);
        return fm_path_new_child_len (parent, basename, baselen);
    }
    
    return G_LIKELY (parent) ? fm_path_ref (parent) : NULL;
}
示例#18
0
FmBookmarkItem* fm_bookmarks_insert(FmBookmarks* bookmarks, FmPath* path, const char* name, int pos)
{
    FmBookmarkItem* item = g_slice_new0(FmBookmarkItem);
    item->path = fm_path_ref(path);
    item->name = g_strdup(name);
    bookmarks->items = g_list_insert(bookmarks->items, item, pos);
    g_debug("insert %s at %d", name, pos);
    queue_save_bookmarks(bookmarks);
    return item;
}
示例#19
0
/**
 * fm_path_new_for_str
 * @path_str: a string representing the file path in its native
 * encoding  (can be non-UTF-8). It can either be a native path or an
 * unescaped URI  (can contain non-ASCII characters and spaces).
 * The function will try to figure out what to do.
 *
 * You can call fm_path_to_str () to convert a FmPath back to its string
 * presentation.
 *
 * Returns: a newly created FmPath for the path. You have to call
 * fm_path_unref () when it's no longer needed.
 */
FmPath *fm_path_new_for_str (const char *path_str)
{
    if (!path_str || !*path_str)
        return fm_path_ref (root_path);
    
    if (path_str[0] == '/')
        return fm_path_new_for_path (path_str);
    
    // UTF-8 should be allowed, I think.
    return _fm_path_new_for_uri_internal (path_str, FALSE);
}
示例#20
0
void activate_row(FmPlacesView* view, guint button, GtkTreePath* tree_path)
{
    GtkTreeIter it;
    if(gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &it, tree_path))
    {
        FmPlaceItem* item;
        FmPath* path;
        gtk_tree_model_get(GTK_TREE_MODEL(model), &it, FM_PLACES_MODEL_COL_INFO, &item, -1);
        if(!item)
            return;
        switch(item->type)
        {
        case FM_PLACES_ITEM_PATH:
            path = fm_path_ref(item->fi->path);
            break;
        case FM_PLACES_ITEM_VOL:
        {
            GFile* gf;
            GMount* mnt = g_volume_get_mount(item->vol);
            if(!mnt)
            {
                GtkWindow* parent = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(view)));
                if(!fm_mount_volume(parent, item->vol, TRUE))
                    return;
                mnt = g_volume_get_mount(item->vol);
                if(!mnt)
                {
                    g_debug("GMount is invalid after successful g_volume_mount().\nThis is quite possibly a gvfs bug.\nSee https://bugzilla.gnome.org/show_bug.cgi?id=552168");
                    return;
                }
            }
            gf = g_mount_get_root(mnt);
            g_object_unref(mnt);
            if(gf)
            {
                path = fm_path_new_for_gfile(gf);
                g_object_unref(gf);
            }
            else
                path = NULL;
            break;
        }
        default:
            return;
        }

        if(path)
        {
            g_signal_emit(view, signals[CHDIR], 0, button, path);
            fm_path_unref(path);
        }
    }
}
示例#21
0
/**
 * fm_path_new_for_path
 * @path_name: a POSIX path.
 *
 * Returns: a newly created FmPath for the path. You have to call
 * fm_path_unref () when it's no longer needed.
 */
FmPath *fm_path_new_for_path (const char *path_name)
{
    FmPath *path;
    
    if (!path_name || !*path_name)
        return fm_path_ref (root_path);

    // some special cases
    if (G_LIKELY (path_name[0] == '/'))
    {
        if (G_UNLIKELY (path_name[1] == '\0')) // pathname is /
            path = fm_path_ref (root_path);
        else
            path = fm_path_new_relative (root_path, path_name + 1);
    }
    else
    {
        // pathname should be absolute path. otherwise its invalid
        path = fm_path_ref (root_path); // return root
    }
    
    return path;
}
示例#22
0
void fm_path_entry_set_path(FmPathEntry *entry, FmPath* path)
{
    FmPathEntryPrivate *priv = FM_PATH_ENTRY_GET_PRIVATE(entry);
    char* disp_path;

    if(priv->path)
        fm_path_unref(priv->path);
    priv->path = fm_path_ref(path);

    disp_path = fm_path_display_name(path, FALSE);
    /* FIXME: blocks changed signal */
    gtk_entry_set_text(entry, disp_path);
    g_free(disp_path);
}
示例#23
0
void SidePane::setCurrentPath(FmPath* path) {
  Q_ASSERT(path != NULL);
  if(currentPath_)
    fm_path_unref(currentPath_);
  currentPath_ = fm_path_ref(path);
  switch(mode_) {
    case ModePlaces:
      static_cast<PlacesView*>(view_)->setCurrentPath(path);
      break;
    case ModeDirTree:
      static_cast<DirTreeView*>(view_)->setCurrentPath(path);
      break;
    default:;
  }
}
示例#24
0
static void add_bookmarks(FmPlacesModel* model, FmFileInfoJob* job)
{
    FmPlaceItem* item;
    GList *bms, *l;
    FmIcon* icon = fm_icon_from_name("folder");
    FmIcon* remote_icon = NULL;
    GdkPixbuf* folder_pix = fm_icon_get_pixbuf(icon, fm_config->pane_icon_size);
    GdkPixbuf* remote_pix = NULL;
    bms = fm_bookmarks_list_all(model->bookmarks);
    for(l=bms;l;l=l->next)
    {
        FmBookmarkItem* bm = (FmBookmarkItem*)l->data;
        GtkTreeIter it;
        GdkPixbuf* pix;
        item = g_slice_new0(FmPlaceItem);
        item->type = FM_PLACES_ITEM_PATH;
        item->fi = fm_file_info_new();
        item->fi->path = fm_path_ref(bm->path);
        fm_file_info_job_add(job, item->fi->path);

        if(fm_path_is_native(item->fi->path))
        {
            item->fi->icon = fm_icon_ref(icon);
            pix = folder_pix;
        }
        else
        {
            if(G_UNLIKELY(!remote_icon))
            {
                remote_icon = fm_icon_from_name("folder-remote");
                remote_pix = fm_icon_get_pixbuf(remote_icon, fm_config->pane_icon_size);
            }
            item->fi->icon = fm_icon_ref(remote_icon);
            pix = remote_pix;
        }
        item->bm_item = bm;
        gtk_list_store_append(GTK_LIST_STORE(model), &it);
        gtk_list_store_set(GTK_LIST_STORE(model), &it, FM_PLACES_MODEL_COL_ICON, pix, FM_PLACES_MODEL_COL_LABEL, bm->name, FM_PLACES_MODEL_COL_INFO, item, -1);
    }
    g_object_unref(folder_pix);
    fm_icon_unref(icon);
    if(remote_icon)
    {
        fm_icon_unref(remote_icon);
        if(remote_pix)
            g_object_unref(remote_pix);
    }
}
示例#25
0
文件: fm-folder.c 项目: engla/libfm
FmFolder* fm_folder_new_internal(FmPath* path, GFile* gf)
{
    GError* err = NULL;
    FmFolder* folder = (FmFolder*)g_object_new(FM_TYPE_FOLDER, NULL);
    folder->dir_path = fm_path_ref(path);

    folder->gf = (GFile*)g_object_ref(gf);

    folder->mon = fm_monitor_directory(gf, &err);
    if(folder->mon)
        g_signal_connect(folder->mon, "changed", G_CALLBACK(on_folder_changed), folder );
    else
        g_error_free(err);

    fm_folder_reload(folder);
    return folder;
}
示例#26
0
void PlacesView::setCurrentPath(FmPath* path) {
  if(currentPath_)
    fm_path_unref(currentPath_);
  if(path) {
    currentPath_ = fm_path_ref(path);
    // TODO: search for item with the path in model_ and select it.
    PlacesModelItem* item = model_->itemFromPath(currentPath_);
    if(item) {
      selectionModel()->select(item->index(), QItemSelectionModel::SelectCurrent|QItemSelectionModel::Rows);
    }
    else
      clearSelection();
  }
  else {
    currentPath_ = NULL;
    clearSelection();
  }
}
示例#27
0
static void create_bookmarks_menu(FmMainWin* win)
{
    GList* l;
    int i = 0;
    /* FIXME: direct access to data member is not allowed */
    for(l=win->bookmarks->items;l;l=l->next)
    {
        FmBookmarkItem* item = (FmBookmarkItem*)l->data;
        GtkWidget* mi = gtk_image_menu_item_new_with_label(item->name);
        gtk_widget_show(mi);
        // gtk_image_menu_item_set_image(); // FIXME: set icons for menu items
        g_object_set_qdata_full(G_OBJECT(mi), fm_qdata_id, fm_path_ref(item->path), (GDestroyNotify)fm_path_unref);
        g_signal_connect(mi, "activate", G_CALLBACK(on_bookmark), win);
        gtk_menu_shell_insert(GTK_MENU_SHELL(win->bookmarks_menu), mi, i);
        ++i;
    }
    if(i > 0)
        gtk_menu_shell_insert(GTK_MENU_SHELL(win->bookmarks_menu), gtk_separator_menu_item_new(), i);
}
示例#28
0
static void add_bookmarks()
{
    PlaceItem* item;
    GList *bms, *l;
    FmIcon* icon = fm_icon_from_name("folder");
    GdkPixbuf* pix = fm_icon_get_pixbuf(icon, fm_config->pane_icon_size);
    bms = fm_bookmarks_list_all(bookmarks);
    for(l=bms;l;l=l->next)
    {
        FmBookmarkItem* bm = (FmBookmarkItem*)l->data;
        GtkTreeIter it;
        item = g_slice_new0(PlaceItem);
        item->type = PLACE_PATH;
        item->path = fm_path_ref(bm->path);
        item->icon = fm_icon_ref(icon);
        item->bm_item = bm;
        gtk_list_store_append(model, &it);
        gtk_list_store_set(model, &it, COL_ICON, pix, COL_LABEL, bm->name, COL_INFO, item, -1);
    }
    g_object_unref(pix);
    fm_icon_unref(icon);
}
示例#29
0
void on_row_activated(GtkTreeView* view, GtkTreePath* tree_path, GtkTreeViewColumn *col)
{
    GtkTreeIter it;
    if(gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &it, tree_path))
    {
        PlaceItem* item;
        FmPath* path;
        gtk_tree_model_get(GTK_TREE_MODEL(model), &it, COL_INFO, &item, -1);
        if(!item)
            return;
        switch(item->type)
        {
        case PLACE_PATH:
            path = fm_path_ref(item->path);
            break;
        case PLACE_VOL:
        {
            GFile* gf;
            GMount* mnt = g_volume_get_mount(item->vol);
            if(!mnt)
            {
                if(!fm_mount_volume(NULL, item->vol))
                    return;
                mnt = g_volume_get_mount(item->vol);
            }
            gf = g_mount_get_root(mnt);
            g_object_unref(mnt);
            path = fm_path_new_for_gfile(gf);
            g_object_unref(gf);
            break;
        }
        default:
            return;
        }
        g_signal_emit(view, signals[CHDIR], 0, path);
        fm_path_unref(path);
    }
}
示例#30
0
文件: tab-page.c 项目: Mic92/stuurman
static void fm_tab_page_chdir_without_history(FmTabPage* page, FmPath* path, FmPath* select_path)
{
    if (select_path)
        select_path = fm_path_ref(select_path);
    if (page->select_path_after_chdir)
        fm_path_unref(page->select_path_after_chdir);
    page->select_path_after_chdir = select_path;

    fm_tab_page_update_label(page, path);

    free_folder(page);

    page->folder = fm_folder_from_path(path);
    g_signal_connect(page->folder, "start-loading", G_CALLBACK(on_folder_start_loading), page);
    g_signal_connect(page->folder, "finish-loading", G_CALLBACK(on_folder_finish_loading), page);
    g_signal_connect(page->folder, "error", G_CALLBACK(on_folder_error), page);
    g_signal_connect(page->folder, "fs-info", G_CALLBACK(on_folder_fs_info), page);
    /* destroy the page when the folder is unmounted or deleted. */
    g_signal_connect(page->folder, "removed", G_CALLBACK(on_folder_removed), page);
    g_signal_connect(page->folder, "unmount", G_CALLBACK(on_folder_unmount), page);
    g_signal_connect(page->folder, "content-changed", G_CALLBACK(on_folder_content_changed), page);

    if(fm_folder_is_loaded(page->folder))
    {
        on_folder_start_loading(page->folder, page);
        on_folder_finish_loading(page->folder, page);
        on_folder_fs_info(page->folder, page);
    }
    else
        on_folder_start_loading(page->folder, page);

    fm_side_pane_chdir(page->side_pane, path);

    /* tell the world that our current working directory is changed */
    g_signal_emit(page, signals[CHDIR], 0, path);
}