Ejemplo n.º 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;
}
Ejemplo n.º 2
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);
}
Ejemplo n.º 3
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);
}
Ejemplo n.º 4
0
/**
 * fm_path_new_for_gfile
 * @gf: a GFile object
 *
 * This function converts a GFile object to FmPath.
 *
 * 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_gfile (GFile *gf)
{
    FmPath *path;
    char *str;
    
    if (g_file_is_native (gf))
    {
        str = g_file_get_path (gf);
        path = fm_path_new_for_path (str);
    }
    else
    {
        str = g_file_get_uri (gf);
        path = fm_path_new_for_uri (str);
    }
    
    g_free (str);
    return path;
}
Ejemplo n.º 5
0
void DesktopWindow::setDesktopFolder() {
  FmPath *path = fm_path_new_for_path(XdgDir::readDesktopDir().toStdString().c_str());
  model_ = Fm::CachedFolderModel::modelFromPath(path);
  proxyModel_->setSourceModel(model_);
}