static void test_predefined_paths() { FmPath* path; char* tmp; path = fm_path_new_for_uri("trash:///"); g_assert(path == fm_path_get_trash()); fm_path_unref(path); path = fm_path_new_for_uri("trash:///xxx"); g_assert(path->parent == fm_path_get_trash()); fm_path_unref(path); path = fm_path_new_for_uri("menu://"); g_assert(path == fm_path_get_apps_menu()); fm_path_unref(path); path = fm_path_new_for_uri("menu://applications"); g_assert(path == fm_path_get_apps_menu()); fm_path_unref(path); path = fm_path_new_for_uri("menu://applications/test/"); g_assert(path->parent == fm_path_get_apps_menu()); fm_path_unref(path); /* path = fm_path_new_for_path(g_get_home_dir()); g_assert(path == fm_path_get_home()); fm_path_unref(path); tmp = g_build_filename(g_get_home_dir(), "xxxx", "xx", NULL); path = fm_path_new_for_path(tmp); g_debug("path->name=%s", path->parent->parent->name); g_assert(path->parent->parent == fm_path_get_home()); fm_path_unref(path); g_free(tmp); path = fm_path_new_for_path(g_get_user_special_dir(G_USER_DIRECTORY_DESKTOP)); g_assert(path == fm_path_get_desktop()); fm_path_unref(path); tmp = g_build_filename(g_get_user_special_dir(G_USER_DIRECTORY_DESKTOP), "xxxx", "xx", NULL); path = fm_path_new_for_path(tmp); g_assert(path->parent->parent == fm_path_get_desktop()); fm_path_unref(path); g_free(tmp); */ }
FmPath* AppMenuView::selectedAppDesktopPath() { AppMenuViewItem* item = selectedItem(); if(item && item->isApp()) { char* mpath = menu_cache_dir_make_path(MENU_CACHE_DIR(item)); FmPath* path = fm_path_new_relative(fm_path_get_apps_menu(), mpath + 13 /* skip "/Applications" */); g_free(mpath); return path; } return NULL; }
/** * fm_app_menu_view_dup_selected_app_desktop_path * @view: a widget * * Retrieves #FmPath to selected application from the widget as a child * below fm_path_get_apps_menu() root path. Return %NULL if there is no * application selected. * The returned data should be freed with fm_path_unref() after usage. * * Returns: (transfer full): path to selected application file. * * Since: 1.2.0 */ FmPath * fm_app_menu_view_dup_selected_app_desktop_path(GtkTreeView* view) { GtkTreeIter it; GtkTreeSelection* sel = gtk_tree_view_get_selection(view); /* FIXME: this should be checked if it's exactly app menu tree! */ if(gtk_tree_selection_get_selected(sel, NULL, &it)) { MenuCacheItem* item; gtk_tree_model_get(GTK_TREE_MODEL(store), &it, COL_ITEM, &item, -1); if(item && menu_cache_item_get_type(item) == MENU_CACHE_TYPE_APP) { char *mpath = menu_cache_dir_make_path(MENU_CACHE_DIR(item)); FmPath *path = fm_path_new_relative(fm_path_get_apps_menu(), mpath+13 /* skip "/Applications" */); g_free(mpath); return path; } } return NULL; }
static void init_model() { if(G_UNLIKELY(!model)) { GtkTreeIter it; PlaceItem* item; GList *vols, *l; GIcon* gicon; FmIcon* icon; GFile* gf; GdkPixbuf* pix; theme_change_handler = g_signal_connect(gtk_icon_theme_get_default(), "changed", G_CALLBACK(update_icons), NULL); use_trash_change_handler = g_signal_connect(fm_config, "changed::use_trash", G_CALLBACK(on_use_trash_changed), NULL); pane_icon_size_change_handler = g_signal_connect(fm_config, "changed::pane_icon_size", G_CALLBACK(on_pane_icon_size_changed), NULL); model = gtk_list_store_new(N_COLS, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_POINTER); g_object_weak_ref(G_OBJECT(model), on_model_destroy, NULL); item = g_slice_new0(PlaceItem); item->type = PLACE_PATH; item->path = fm_path_ref(fm_path_get_home()); item->icon = fm_icon_from_name("user-home"); gtk_list_store_append(model, &it); pix = fm_icon_get_pixbuf(item->icon, fm_config->pane_icon_size); gtk_list_store_set(model, &it, COL_ICON, pix, COL_LABEL, item->path->name, COL_INFO, item, -1); g_object_unref(pix); /* Only show desktop in side pane when the user has a desktop dir. */ if(g_file_test(g_get_user_special_dir(G_USER_DIRECTORY_DESKTOP), G_FILE_TEST_IS_DIR)) { item = g_slice_new0(PlaceItem); item->type = PLACE_PATH; item->path = fm_path_ref(fm_path_get_desktop()); item->icon = fm_icon_from_name("user-desktop"); gtk_list_store_append(model, &it); pix = fm_icon_get_pixbuf(item->icon, fm_config->pane_icon_size); gtk_list_store_set(model, &it, COL_ICON, pix, COL_LABEL, _("Desktop"), COL_INFO, item, -1); g_object_unref(pix); } if(fm_config->use_trash) create_trash(); item = g_slice_new0(PlaceItem); item->type = PLACE_PATH; item->path = fm_path_ref(fm_path_get_apps_menu()); item->icon = fm_icon_from_name("system-software-install"); gtk_list_store_append(model, &it); pix = fm_icon_get_pixbuf(item->icon, fm_config->pane_icon_size); gtk_list_store_set(model, &it, COL_ICON, pix, COL_LABEL, _("Applications"), COL_INFO, item, -1); g_object_unref(pix); /* volumes */ vol_mon = g_volume_monitor_get(); g_signal_connect(vol_mon, "volume-added", G_CALLBACK(on_vol_added), NULL); g_signal_connect(vol_mon, "volume-removed", G_CALLBACK(on_vol_removed), NULL); g_signal_connect(vol_mon, "volume-changed", G_CALLBACK(on_vol_changed), NULL); /* separator */ gtk_list_store_append(model, &sep_it); vols = g_volume_monitor_get_volumes(vol_mon); for(l=vols;l;l=l->next) { GVolume* vol = G_VOLUME(l->data); add_vol(vol); g_object_unref(vol); } g_list_free(vols); bookmarks = fm_bookmarks_get(); /* bookmarks */ g_signal_connect(bookmarks, "changed", G_CALLBACK(on_bookmarks_changed), NULL); add_bookmarks(); } else g_object_ref(model); }
static void fm_places_model_init(FmPlacesModel *self) { GType types[] = {GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_POINTER}; GtkTreeIter it; GtkTreePath* tp; FmPlaceItem* item; GList *vols, *l; GIcon* gicon; FmIcon* icon; GFile* gf; GdkPixbuf* pix; FmFileInfoJob* job = fm_file_info_job_new(NULL, FM_FILE_INFO_JOB_FOLLOW_SYMLINK); GtkListStore* model = GTK_LIST_STORE(self); gtk_list_store_set_column_types(GTK_LIST_STORE(self), FM_PLACES_MODEL_N_COLS, types); self->theme_change_handler = g_signal_connect_swapped(gtk_icon_theme_get_default(), "changed", G_CALLBACK(update_icons), self); self->use_trash_change_handler = g_signal_connect(fm_config, "changed::use_trash", G_CALLBACK(on_use_trash_changed), self); self->pane_icon_size_change_handler = g_signal_connect(fm_config, "changed::pane_icon_size", G_CALLBACK(on_pane_icon_size_changed), self); icon = fm_icon_from_name("media-eject"); pix = fm_icon_get_pixbuf(icon, fm_config->pane_icon_size); fm_icon_unref(icon); self->eject_icon = pix; 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_home()); item->fi->icon = fm_icon_from_name("user-home"); gtk_list_store_append(model, &it); pix = fm_icon_get_pixbuf(item->fi->icon, fm_config->pane_icon_size); gtk_list_store_set(model, &it, FM_PLACES_MODEL_COL_ICON, pix, FM_PLACES_MODEL_COL_LABEL, item->fi->path->name, FM_PLACES_MODEL_COL_INFO, item, -1); g_object_unref(pix); fm_file_info_job_add(job, item->fi->path); /* Only show desktop in side pane when the user has a desktop dir. */ if(g_file_test(g_get_user_special_dir(G_USER_DIRECTORY_DESKTOP), G_FILE_TEST_IS_DIR)) { 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_desktop()); item->fi->icon = fm_icon_from_name("user-desktop"); gtk_list_store_append(model, &it); pix = fm_icon_get_pixbuf(item->fi->icon, fm_config->pane_icon_size); gtk_list_store_set(model, &it, FM_PLACES_MODEL_COL_ICON, pix, FM_PLACES_MODEL_COL_LABEL, _("Desktop"), FM_PLACES_MODEL_COL_INFO, item, -1); g_object_unref(pix); fm_file_info_job_add(job, item->fi->path); } if(fm_config->use_trash) create_trash_item(self); /* FIXME: how to handle trash can? */ 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_apps_menu()); item->fi->icon = fm_icon_from_name("system-software-install"); gtk_list_store_append(model, &it); pix = fm_icon_get_pixbuf(item->fi->icon, fm_config->pane_icon_size); gtk_list_store_set(model, &it, FM_PLACES_MODEL_COL_ICON, pix, FM_PLACES_MODEL_COL_LABEL, _("Applications"), FM_PLACES_MODEL_COL_INFO, item, -1); g_object_unref(pix); /* fm_file_info_job_add(job, item->fi->path); */ /* volumes */ self->vol_mon = g_volume_monitor_get(); g_signal_connect(self->vol_mon, "volume-added", G_CALLBACK(on_vol_added), self); g_signal_connect(self->vol_mon, "volume-removed", G_CALLBACK(on_vol_removed), self); g_signal_connect(self->vol_mon, "volume-changed", G_CALLBACK(on_vol_changed), self); g_signal_connect(self->vol_mon, "mount-added", G_CALLBACK(on_mount_added), self); /* separator */ gtk_list_store_append(model, &self->sep_it); /* add volumes to side-pane */ vols = g_volume_monitor_get_volumes(self->vol_mon); for(l=vols;l;l=l->next) { GVolume* vol = G_VOLUME(l->data); add_vol(self, vol, job); g_object_unref(vol); } g_list_free(vols); /* get the path of separator */ self->sep_tp = gtk_tree_model_get_path(GTK_TREE_MODEL(self), &self->sep_it); self->bookmarks = fm_bookmarks_get(); /* bookmarks */ g_signal_connect(self->bookmarks, "changed", G_CALLBACK(on_bookmarks_changed), self); /* add bookmarks to side pane */ add_bookmarks(self, job); g_signal_connect(job, "finished", G_CALLBACK(on_file_info_job_finished), self); self->jobs = g_slist_prepend(self->jobs, job); fm_job_run_async(FM_JOB(job)); }
void on_go_apps(GtkAction* act, FmMainWin* win) { fm_main_win_chdir(win, fm_path_get_apps_menu()); }