static void update_icons(FmPlacesModel* model) { GtkTreeIter it; FmIcon* icon; GdkPixbuf* pix; /* update the eject icon */ icon = fm_icon_from_name("media-eject"); pix = fm_icon_get_pixbuf(icon, fm_config->pane_icon_size); fm_icon_unref(icon); if(model->eject_icon) g_object_unref(model->eject_icon); model->eject_icon = pix; /* reload icon for every item */ gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &it); do{ if(it.user_data != model->sep_it.user_data) { FmPlaceItem* item; gtk_tree_model_get(GTK_TREE_MODEL(model), &it, FM_PLACES_MODEL_COL_INFO, &item, -1); /* FIXME: get icon size from FmConfig */ 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, -1); g_object_unref(pix); } }while( gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &it) ); }
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); } }
gboolean update_trash(gpointer user_data) { if(fm_config->use_trash) { GFile* gf = g_file_new_for_uri("trash:///"); GFileInfo* inf = g_file_query_info(gf, G_FILE_ATTRIBUTE_TRASH_ITEM_COUNT, 0, NULL, NULL); g_object_unref(gf); if(inf) { FmIcon* icon; const char* icon_name; PlaceItem* item; GdkPixbuf* pix; guint32 n = g_file_info_get_attribute_uint32(inf, G_FILE_ATTRIBUTE_TRASH_ITEM_COUNT); g_object_unref(inf); icon_name = n > 0 ? "user-trash-full" : "user-trash"; icon = fm_icon_from_name(icon_name); gtk_tree_model_get(GTK_TREE_MODEL(model), &trash_it, COL_INFO, &item, -1); if(item->icon) fm_icon_unref(item->icon); item->icon = icon; /* update the icon */ pix = fm_icon_get_pixbuf(item->icon, fm_config->pane_icon_size); gtk_list_store_set(model, &trash_it, COL_ICON, pix, -1); g_object_unref(pix); } } return FALSE; }
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); }
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); }
static void update_vol(FmPlacesModel* model, FmPlaceItem* item, GtkTreeIter* it, FmFileInfoJob* job) { FmIcon* icon; GIcon* gicon; char* name; GdkPixbuf* pix; GMount* mount; FmPath* path; name = g_volume_get_name(item->vol); if(item->fi->icon) fm_icon_unref(item->fi->icon); gicon = g_volume_get_icon(item->vol); icon = fm_icon_from_gicon(gicon); item->fi->icon = icon; g_object_unref(gicon); mount = g_volume_get_mount(item->vol); if(mount) { GFile* gf = g_mount_get_root(mount); path = fm_path_new_for_gfile(gf); g_object_unref(gf); g_object_unref(mount); item->vol_mounted = TRUE; } else { path = NULL; item->vol_mounted = FALSE; } if(!fm_path_equal(item->fi->path, path)) { fm_file_info_set_path(item->fi, path); if(path) { if(job) fm_file_info_job_add(job, path); else { job = fm_file_info_job_new(NULL, FM_FILE_INFO_JOB_FOLLOW_SYMLINK); model->jobs = g_slist_prepend(model->jobs, job); g_signal_connect(job, "finished", G_CALLBACK(on_file_info_job_finished), model); fm_job_run_async(FM_JOB(job)); } fm_path_unref(path); } } 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, name, -1); g_object_unref(pix); g_free(name); }
void update_icons() { GtkTreeIter it; gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &it); do{ if(it.user_data != sep_it.user_data) { PlaceItem* item; gtk_tree_model_get(GTK_TREE_MODEL(model), &it, COL_INFO, &item, -1); /* FIXME: get icon size from FmConfig */ GdkPixbuf* pix = fm_icon_get_pixbuf(item->icon, fm_config->pane_icon_size); gtk_list_store_set(model, &it, COL_ICON, pix, -1); g_object_unref(pix); } }while( gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &it) ); }
static void update_vol(PlaceItem* item, GtkTreeIter* it) { FmIcon* icon; GIcon* gicon; char* name; GdkPixbuf* pix; name = g_volume_get_name(item->vol); if(item->icon) fm_icon_unref(item->icon); gicon = g_volume_get_icon(item->vol); icon = fm_icon_from_gicon(gicon); item->icon = icon; g_object_unref(gicon); pix = fm_icon_get_pixbuf(item->icon, fm_config->pane_icon_size); gtk_list_store_set(model, it, COL_ICON, pix, COL_LABEL, name, -1); g_object_unref(pix); g_free(name); }
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); }
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 fm_folder_model_get_value(GtkTreeModel *tree_model, GtkTreeIter *iter, gint column, GValue *value) { GSequenceIter* item_it; FmFolderModel* model = FM_FOLDER_MODEL(tree_model); g_return_if_fail(iter != NULL); g_return_if_fail( column < G_N_ELEMENTS(column_types) ); g_value_init(value, column_types[column]); item_it = (GSequenceIter*)iter->user_data; g_return_if_fail(item_it != NULL); FmFolderItem* item = (FmFolderItem*)g_sequence_get(item_it); FmFileInfo* info = item->inf; switch( column ) { case COL_FILE_GICON: g_value_set_object(value, info->icon->gicon); break; case COL_FILE_ICON: { if( G_UNLIKELY(!item->icon) ) { if( !info->icon ) return; item->icon = fm_icon_get_pixbuf(info->icon, model->icon_size); } /* if we want to show a thumbnail */ /* if we're on local filesystem or thumbnailing for remote files is allowed */ if(fm_config->show_thumbnail && (fm_path_is_local(item->inf->path) || !fm_config->thumbnail_local)) { if(!item->is_thumbnail && !item->thumbnail_failed && !item->thumbnail_loading) { if(fm_file_info_can_thumbnail(item->inf)) { if(item->inf->size > 0 && (fm_config->thumbnail_max == 0 || item->inf->size <= (fm_config->thumbnail_max << 10))) { GdkPixbuf * pix = fm_thumbnail_try_read_from_cache(item->inf, model->icon_size); if (pix) { if (item->icon) g_object_unref(item->icon); item->icon = pix; item->is_thumbnail = TRUE; } else { FmThumbnailRequest* req = fm_thumbnail_request2(item->inf, model->icon_size, on_thumbnail_loaded, model, item->iter_age, item); model->thumbnail_requests = g_list_prepend(model->thumbnail_requests, req); item->thumbnail_loading = TRUE; } } } else { item->thumbnail_failed = TRUE; } } } g_value_set_object(value, item->icon); break; } case COL_FILE_NAME: g_value_set_string(value, info->disp_name); break; case COL_FILE_NAME_HINT_SIZE: case COL_FILE_NAME_HINT_MTIME: case COL_FILE_NAME_HINT_DESC: { //g_value_set_string(value, info->disp_name); if (!item->hinted_disp_name || item->hint_column != column) { item->hint_column != column; if (item->hinted_disp_name) g_free(item->hinted_disp_name); gchar * s = NULL; if (fm_file_info_is_symlink(info)) s = fm_file_info_get_target(info); if (!s) { switch (column) { case COL_FILE_NAME_HINT_SIZE: s = fm_file_info_get_disp_size(info); break; case COL_FILE_NAME_HINT_MTIME: s = fm_file_info_get_disp_mtime(info); break; case COL_FILE_NAME_HINT_DESC: s = fm_file_info_get_desc(info); break; } } if (!s) s = fm_file_info_get_desc(info); if (!s) s = ""; item->hinted_disp_name = g_markup_printf_escaped("%s<span size='small'>\n<i>%s</i></span>", info->disp_name, s); } g_value_set_string(value, item->hinted_disp_name); break; } case COL_FILE_SIZE: g_value_set_string( value, fm_file_info_get_disp_size(info) ); break; case COL_FILE_DESC: g_value_set_string( value, fm_file_info_get_desc(info) ); break; case COL_FILE_PERM: // g_value_set_string( value, fm_file_info_get_disp_perm(info) ); break; case COL_FILE_OWNER: // g_value_set_string( value, fm_file_info_get_disp_owner(info) ); break; case COL_FILE_MTIME: g_value_set_string( value, fm_file_info_get_disp_mtime(info) ); break; case COL_FILE_INFO: g_value_set_pointer(value, info); break; } }