static FmBookmarkItem* new_item(char* line) { FmBookmarkItem* item = g_slice_new0(FmBookmarkItem); char* sep; sep = strchr(line, '\n'); if(sep) *sep = '\0'; sep = strchr(line, ' '); if(sep) *sep = '\0'; /* FIXME: this is no longer needed once fm_path_new can convert file:/// to / */ if(g_str_has_prefix(line, "file:/")) { char* fpath = g_filename_from_uri(line, NULL, NULL); item->path = fm_path_new(fpath); g_free(fpath); } else { /* FIXME: is unescape needed? */ item->path = fm_path_new(line); } if(sep) item->name = g_strdup(sep+1); else item->name = g_filename_display_name(item->path->name); return item; }
int main(int argc, char** argv) { GtkWidget* w; gtk_init(&argc, &argv); fm_gtk_init(NULL); /* for debugging RTL */ /* gtk_widget_set_default_direction(GTK_TEXT_DIR_RTL); */ w = fm_main_win_new(); gtk_window_set_default_size(GTK_WINDOW(w), 640, 480); gtk_widget_show(w); if(argc > 1) { FmPath* path = fm_path_new(argv[1]); fm_main_win_chdir(FM_MAIN_WIN(w), path); fm_path_unref(path); } gtk_main(); fm_finalize(); return 0; }
FmFolder* fm_folder_get_for_path_name(const char* path) { FmPath* fm_path = fm_path_new(path); FmFolder* folder = fm_folder_get_internal(fm_path, NULL); fm_path_unref(fm_path); return folder; }
void fm_main_win_chdir_by_name(FmMainWin* win, const char* path_str) { FmPath* path; gtk_entry_set_text(GTK_ENTRY(win->location), path_str); path = fm_path_new(path_str); fm_folder_view_chdir(FM_FOLDER_VIEW(win->folder_view), path); fm_path_unref(path); }
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); } } }
FmPath* fm_path_new_for_gfile(GFile* gf) { FmPath* path; char* str; if( g_file_is_native(gf) ) str = g_file_get_path(gf); else str = g_file_get_uri(gf); path = fm_path_new(str); g_free(str); return path; }
FmPathList* fm_path_list_new_from_uris(const char** uris) { const char** uri; FmPathList* pl = fm_path_list_new(); for(uri = uris; *uri; ++uri) { FmPath* path; char* unescaped; if(g_str_has_prefix(*uri, "file:")) unescaped = g_filename_from_uri(*uri, NULL, NULL); else unescaped = g_uri_unescape_string(*uri, NULL); path = fm_path_new(unescaped); g_free(unescaped); fm_list_push_tail_noref(pl, path); } return pl; }