static void cb_sort_changed (GtkTreeSortable *model, gpointer data) { GsmApplication *app = (GsmApplication *) data; gsm_tree_view_save_state (GSM_TREE_VIEW (app->disk_list)); }
static GsmTreeView * create_openfiles_tree (GsmApplication *app) { GsmTreeView *tree; GtkListStore *model; GtkTreeViewColumn *column; GtkCellRenderer *cell; gint i; const gchar * const titles[] = { /* Translators: "FD" here means "File Descriptor". Please use a very short translation if possible, and at most 2-3 characters for it to be able to fit in the UI. */ N_("FD"), N_("Type"), N_("Object") }; model = gtk_list_store_new (NUM_OPENFILES_COL, G_TYPE_INT, /* FD */ G_TYPE_STRING, /* Type */ G_TYPE_STRING, /* Object */ G_TYPE_POINTER /* open_files_entry */ ); auto settings = g_settings_get_child (app->settings->gobj (), GSM_SETTINGS_CHILD_OPEN_FILES); tree = gsm_tree_view_new (settings, FALSE); gtk_tree_view_set_model (GTK_TREE_VIEW (tree), GTK_TREE_MODEL (model)); g_object_unref (G_OBJECT (model)); for (i = 0; i < NUM_OPENFILES_COL-1; i++) { cell = gtk_cell_renderer_text_new (); switch (i) { case COL_FD: g_object_set(cell, "xalign", 1.0f, NULL); break; } column = gtk_tree_view_column_new_with_attributes (_(titles[i]), cell, "text", i, NULL); gtk_tree_view_column_set_sort_column_id (column, i); gtk_tree_view_column_set_resizable (column, TRUE); gtk_tree_view_append_column (GTK_TREE_VIEW (tree), column); } gsm_tree_view_load_state (GSM_TREE_VIEW (tree)); return tree; }
void create_disk_view(GsmApplication *app, GtkBuilder *builder) { GtkScrolledWindow *scrolled; GsmTreeView *disk_tree; GtkListStore *model; GtkTreeViewColumn *col; GtkCellRenderer *cell; guint i; init_volume_monitor (app); const gchar * const titles[] = { N_("Device"), N_("Directory"), N_("Type"), N_("Total"), N_("Free"), N_("Available"), N_("Used") }; scrolled = GTK_SCROLLED_WINDOW (gtk_builder_get_object (builder, "disks_scrolled")); model = gtk_list_store_new(DISK_N_COLUMNS, /* n columns */ G_TYPE_STRING, /* DISK_DEVICE */ G_TYPE_STRING, /* DISK_DIR */ G_TYPE_STRING, /* DISK_TYPE */ G_TYPE_UINT64, /* DISK_TOTAL */ G_TYPE_UINT64, /* DISK_FREE */ G_TYPE_UINT64, /* DISK_AVAIL */ G_TYPE_UINT64, /* DISK_USED */ GDK_TYPE_PIXBUF, /* DISK_ICON */ G_TYPE_INT /* DISK_USED_PERCENTAGE */ ); disk_tree = gsm_tree_view_new (g_settings_get_child (app->settings->gobj(), GSM_SETTINGS_CHILD_DISKS), TRUE); gtk_tree_view_set_model (GTK_TREE_VIEW (disk_tree), GTK_TREE_MODEL (model)); g_signal_connect(G_OBJECT(disk_tree), "row-activated", G_CALLBACK(open_dir), NULL); app->disk_list = disk_tree; gtk_container_add(GTK_CONTAINER(scrolled), GTK_WIDGET (disk_tree)); g_object_unref(G_OBJECT(model)); /* icon + device */ col = gtk_tree_view_column_new(); cell = gtk_cell_renderer_pixbuf_new(); gtk_tree_view_column_pack_start(col, cell, FALSE); gtk_tree_view_column_set_attributes(col, cell, "pixbuf", DISK_ICON, NULL); cell = gtk_cell_renderer_text_new(); gtk_tree_view_column_pack_start(col, cell, FALSE); gtk_tree_view_column_set_attributes(col, cell, "text", DISK_DEVICE, NULL); gtk_tree_view_column_set_title(col, _(titles[DISK_DEVICE])); gtk_tree_view_column_set_sort_column_id(col, DISK_DEVICE); gtk_tree_view_column_set_reorderable(col, TRUE); gtk_tree_view_column_set_resizable(col, TRUE); gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_FIXED); gsm_tree_view_append_and_bind_column (GSM_TREE_VIEW (disk_tree), col); /* sizes - used */ for (i = DISK_DIR; i <= DISK_AVAIL; i++) { cell = gtk_cell_renderer_text_new(); col = gtk_tree_view_column_new(); gtk_tree_view_column_pack_start(col, cell, TRUE); gtk_tree_view_column_set_title(col, _(titles[i])); gtk_tree_view_column_set_resizable(col, TRUE); gtk_tree_view_column_set_sort_column_id(col, i); gtk_tree_view_column_set_reorderable(col, TRUE); gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_FIXED); gsm_tree_view_append_and_bind_column (GSM_TREE_VIEW (disk_tree), col); switch (i) { case DISK_TOTAL: case DISK_FREE: case DISK_AVAIL: g_object_set(cell, "xalign", 1.0f, NULL); gtk_tree_view_column_set_cell_data_func(col, cell, &procman::size_si_cell_data_func, GUINT_TO_POINTER(i), NULL); break; default: gtk_tree_view_column_set_attributes(col, cell, "text", i, NULL); break; } } /* used + percentage */ col = gtk_tree_view_column_new(); cell = gtk_cell_renderer_text_new(); g_object_set(cell, "xalign", 1.0f, NULL); gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_FIXED); gtk_tree_view_column_pack_start(col, cell, FALSE); gtk_tree_view_column_set_cell_data_func(col, cell, &procman::size_si_cell_data_func, GUINT_TO_POINTER(DISK_USED), NULL); gtk_tree_view_column_set_title(col, _(titles[DISK_USED])); cell = gtk_cell_renderer_progress_new(); gtk_cell_renderer_set_padding(cell, 4.0f, 4.0f); gtk_tree_view_column_pack_start(col, cell, TRUE); gtk_tree_view_column_set_attributes(col, cell, "value", DISK_USED_PERCENTAGE, NULL); gtk_tree_view_column_set_resizable(col, TRUE); gtk_tree_view_column_set_sort_column_id(col, DISK_USED); gtk_tree_view_column_set_reorderable(col, TRUE); gsm_tree_view_append_and_bind_column (GSM_TREE_VIEW (disk_tree), col); /* numeric sort */ gsm_tree_view_load_state (GSM_TREE_VIEW (disk_tree)); g_signal_connect (G_OBJECT(disk_tree), "destroy", G_CALLBACK(cb_disk_list_destroying), app); g_signal_connect (G_OBJECT(disk_tree), "columns-changed", G_CALLBACK(cb_disk_columns_changed), app); g_signal_connect (G_OBJECT (model), "sort-column-changed", G_CALLBACK (cb_sort_changed), app); app->settings->signal_changed(GSM_SETTING_SHOW_ALL_FS).connect ([app](const Glib::ustring&) { disks_update (app); disks_reset_timeout (app); }); gtk_widget_show (GTK_WIDGET (disk_tree)); }
static void cb_disk_columns_changed(GtkTreeView *treeview, gpointer data) { gsm_tree_view_save_state (GSM_TREE_VIEW (treeview)); }