Пример #1
0
FmFolder* fm_folder_get_for_path_name(const char* path)
{
    FmPath* fm_path = fm_path_new_for_str(path);
    FmFolder* folder = fm_folder_get_internal(fm_path, NULL);
    fm_path_unref(fm_path);
    return folder;
}
Пример #2
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));
    }
}
Пример #3
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);
}
Пример #4
0
gboolean fm_folder_view_chdir_by_name(FmFolderView* fv, const char* path_str)
{
    gboolean ret;
    FmPath* path;

    if( G_UNLIKELY( !path_str ) )
        return FALSE;

    path = fm_path_new_for_str(path_str);
    if(!path) /* might be a malformed path */
        return FALSE;
    ret = fm_folder_view_chdir(fv, path);
    fm_path_unref(path);
    return ret;
}
Пример #5
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;
}
Пример #6
0
/**
 * fm_get_user_input_path
 * @parent: a window to place dialog over it
 * @title: title for dialog window
 * @msg: the message to present to the user
 * @default_path: the default path
 *
 * Presents the message to user and retrieves entered path string.
 * Returned data should be freed with fm_path_unref() after usage.
 *
 * Returns: (transfer full): entered text.
 *
 * Since: 0.1.0
 *
 * Deprecated: 1.2.0:
 */
FmPath* fm_get_user_input_path(GtkWindow* parent, const char* title, const char* msg, FmPath* default_path)
{

    GtkDialog* dlg = _fm_get_user_input_dialog( parent, title, msg);
    GtkEntry* entry = GTK_ENTRY(gtk_entry_new());
    char *str, *path_str = NULL;
    FmPath* path;

    gtk_entry_set_activates_default(entry, TRUE);

    if(default_path)
    {
        path_str = fm_path_display_name(default_path, FALSE);
        gtk_entry_set_text(entry, path_str);
    }

    str = _fm_user_input_dialog_run(dlg, entry, NULL);
    path = fm_path_new_for_str(str);

    g_free(path_str);
    g_free(str);
    return path;
}
Пример #7
0
/* Handler for activate event on popup Open menu item. */
static void dirmenu_menuitem_open_directory(GtkWidget * item, DirMenuPlugin * dm)
{
    FmPath *path = fm_path_new_for_str(g_object_get_data(G_OBJECT(gtk_widget_get_parent(item)), "path"));
    lxpanel_launch_path(dm->panel, path);
    fm_path_unref(path);
}