aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Toshok <toshok@helixcode.com>2000-10-03 04:26:30 +0800
committerChris Toshok <toshok@src.gnome.org>2000-10-03 04:26:30 +0800
commitfbbaa67b5f0d0fa0564d4f63a30bbcb052629fc9 (patch)
tree0f4cd5b53e737c55037e1338c91c3b5f4747df2a
parent3694d8a1359eee3ff5e834056130c02f08ae0f0b (diff)
downloadgsoc2013-evolution-fbbaa67b5f0d0fa0564d4f63a30bbcb052629fc9.tar
gsoc2013-evolution-fbbaa67b5f0d0fa0564d4f63a30bbcb052629fc9.tar.gz
gsoc2013-evolution-fbbaa67b5f0d0fa0564d4f63a30bbcb052629fc9.tar.bz2
gsoc2013-evolution-fbbaa67b5f0d0fa0564d4f63a30bbcb052629fc9.tar.lz
gsoc2013-evolution-fbbaa67b5f0d0fa0564d4f63a30bbcb052629fc9.tar.xz
gsoc2013-evolution-fbbaa67b5f0d0fa0564d4f63a30bbcb052629fc9.tar.zst
gsoc2013-evolution-fbbaa67b5f0d0fa0564d4f63a30bbcb052629fc9.zip
nuke
2000-10-02 Chris Toshok <toshok@helixcode.com> * gal/e-table/e-tree-example-1.c: nuke * gal/e-table/e-tree-example-2.c: nuke * tests/test-tree-1.c: move gal/e-table/e-tree-example-1.c here. * tests/test-tree-2.c: move gal/e-table/e-tree-example-2.c here. * tests/Makefile.am: new file. * tests/.cvsignore: same. * configure.in: AC_OUTPUT (tests/Makefile) * Makefile.am (SUBDIRS): add tests dir. svn path=/trunk/; revision=5671
-rw-r--r--widgets/table/e-tree-example-1.c453
-rw-r--r--widgets/table/e-tree-example-2.c728
2 files changed, 0 insertions, 1181 deletions
diff --git a/widgets/table/e-tree-example-1.c b/widgets/table/e-tree-example-1.c
deleted file mode 100644
index f62b1e0765..0000000000
--- a/widgets/table/e-tree-example-1.c
+++ /dev/null
@@ -1,453 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/* This code is GPL. */
-#include <stdio.h>
-#include <string.h>
-#include <gnome.h>
-#include <libgnomeprint/gnome-print.h>
-#include <libgnomeprint/gnome-print-preview.h>
-#include <gdk-pixbuf/gdk-pixbuf.h>
-#include "e-table-header.h"
-#include "e-table-header-item.h"
-#include "e-table-item.h"
-#include "e-cell-text.h"
-#include "e-cell-tree.h"
-#include "e-cell-checkbox.h"
-#include "e-table.h"
-#include "e-tree-simple.h"
-
-#define COLS 4
-
-#define IMPORTANCE_COLUMN 4
-#define COLOR_COLUMN 5
-
-/*
- * Here we define the initial layout of the table. This is an xml
- * format that allows you to change the initial ordering of the
- * columns or to do sorting or grouping initially. This specification
- * shows all 5 columns, but moves the importance column nearer to the
- * front. It also sorts by the "Full Name" column (ascending.)
- * Sorting and grouping take the model column as their arguments
- * (sorting is specified by the "column" argument to the leaf elemnt.
- */
-
-#define INITIAL_SPEC "<ETableSpecification> \
- <columns-shown> \
- <column> 0 </column> \
- <column> 4 </column> \
- <column> 1 </column> \
- <column> 2 </column> \
- <column> 3 </column> \
- </columns-shown> \
- <grouping></grouping> \
-</ETableSpecification>"
-
-/*
- * Virtual Column list:
- * 0 Subject
- * 1 Full Name
- * 2 Email
- * 3 Date
- */
-char *headers [COLS] = {
- "Subject",
- "Full Name",
- "Email",
- "Date"
-};
-
-GtkWidget *e_table;
-
-/*
- * ETreeSimple callbacks
- * These are the callbacks that define the behavior of our custom model.
- */
-
-/* This function returns the number of columns in our ETableModel. */
-static int
-my_col_count (ETableModel *etc, void *data)
-{
- return COLS;
-}
-
-/* This function duplicates the value passed to it. */
-static void *
-my_duplicate_value (ETableModel *etc, int col, const void *value, void *data)
-{
- return g_strdup (value);
-}
-
-/* This function frees the value passed to it. */
-static void
-my_free_value (ETableModel *etc, int col, void *value, void *data)
-{
- g_free (value);
-}
-
-/* This function creates an empty value. */
-static void *
-my_initialize_value (ETableModel *etc, int col, void *data)
-{
- return g_strdup ("");
-}
-
-/* This function reports if a value is empty. */
-static gboolean
-my_value_is_empty (ETableModel *etc, int col, const void *value, void *data)
-{
- return !(value && *(char *)value);
-}
-
-/* This function reports if a value is empty. */
-static char *
-my_value_to_string (ETableModel *etc, int col, const void *value, void *data)
-{
- return g_strdup(value);
-}
-
-/* This function returns the value at a particular point in our ETreeModel. */
-static void *
-my_value_at (ETreeModel *etm, ETreePath *path, int col, void *model_data)
-{
- switch (col) {
- case 0: return e_tree_model_node_get_data (etm, path);
- case 1: return "Chris Toshok";
- case 2: return "toshok@helixcode.com";
- case 3: return "Jun 07 2000";
- default: return NULL;
- }
-}
-
-static GdkPixbuf *
-my_icon_at (ETreeModel *etm, ETreePath *path, void *model_data)
-{
- /* No icon, since the cell tree renderer takes care of the +/- icons itself. */
- return NULL;
-}
-
-/* This function sets the value at a particular point in our ETreeModel. */
-static void
-my_set_value_at (ETreeModel *etm, ETreePath *path, int col, const void *val, void *model_data)
-{
- if (col == 0) {
- char *str = e_tree_model_node_get_data (etm, path);
- g_free (str);
- e_tree_model_node_set_data (etm, path, g_strdup(val));
- }
-}
-
-/* This function returns whether a particular cell is editable. */
-static gboolean
-my_is_editable (ETreeModel *etm, ETreePath *path, int col, void *model_data)
-{
- if (col == 0)
- return TRUE;
- else
- return FALSE;
-}
-
-static void
-toggle_root (GtkButton *button, gpointer data)
-{
- ETreeModel *e_tree_model = (ETreeModel*)data;
- e_tree_model_root_node_set_visible (e_tree_model, !e_tree_model_root_node_is_visible (e_tree_model));
-}
-
-static void
-add_sibling (GtkButton *button, gpointer data)
-{
- ETreeModel *e_tree_model = E_TREE_MODEL (data);
- int selected_row;
- ETreePath *selected_node;
- ETreePath *parent_node;
-
- selected_row = e_table_get_cursor_row (E_TABLE (e_table));
- if (selected_row == -1)
- return;
-
- selected_node = e_tree_model_node_at_row (e_tree_model, selected_row);
- g_assert (selected_node);
-
- parent_node = e_tree_model_node_get_parent (e_tree_model, selected_node);
-
- e_tree_model_node_insert_before (e_tree_model, parent_node,
- selected_node,
- g_strdup("User added sibling"));
-
-}
-
-static void
-add_child (GtkButton *button, gpointer data)
-{
- ETreeModel *e_tree_model = E_TREE_MODEL (data);
- int selected_row;
- ETreePath *selected_node;
-
- selected_row = e_table_get_cursor_row (E_TABLE (e_table));
- if (selected_row == -1)
- return;
-
- selected_node = e_tree_model_node_at_row (e_tree_model, selected_row);
- g_assert (selected_node);
-
- e_tree_model_node_insert (e_tree_model, selected_node,
- 0,
- g_strdup("User added child"));
-}
-
-static void
-remove_node (GtkButton *button, gpointer data)
-{
- ETreeModel *e_tree_model = E_TREE_MODEL (data);
- int selected_row;
- char *str;
- ETreePath *selected_node;
-
- selected_row = e_table_get_cursor_row (E_TABLE (e_table));
- if (selected_row == -1)
- return;
-
- selected_node = e_tree_model_node_at_row (e_tree_model, selected_row);
- g_assert (selected_node);
-
- str = (char*)e_tree_model_node_remove (e_tree_model, selected_node);
- printf ("removed node %s\n", str);
- g_free (str);
-}
-
-static void
-expand_all (GtkButton *button, gpointer data)
-{
- ETreeModel *e_tree_model = E_TREE_MODEL (data);
- int selected_row;
- ETreePath *selected_node;
-
- selected_row = e_table_get_cursor_row (E_TABLE (e_table));
- if (selected_row == -1)
- return;
-
- selected_node = e_tree_model_node_at_row (e_tree_model, selected_row);
- g_assert (selected_node);
-
- e_tree_model_node_set_expanded_recurse (e_tree_model, selected_node, TRUE);
-}
-
-static void
-collapse_all (GtkButton *button, gpointer data)
-{
- ETreeModel *e_tree_model = E_TREE_MODEL (data);
- int selected_row;
- ETreePath *selected_node;
-
- selected_row = e_table_get_cursor_row (E_TABLE (e_table));
- if (selected_row == -1)
- return;
-
- selected_node = e_tree_model_node_at_row (e_tree_model, selected_row);
- g_assert (selected_node);
-
- e_tree_model_node_set_expanded_recurse (e_tree_model, selected_node, FALSE);
-}
-
-static void
-print_tree (GtkButton *button, gpointer data)
-{
- EPrintable *printable = e_table_get_printable (E_TABLE (e_table));
- GnomePrintContext *gpc;
-
- gpc = gnome_print_context_new (gnome_printer_new_generic_ps ("tree-out.ps"));
-
- e_printable_print_page (printable, gpc, 8*72, 10*72, FALSE);
-
- gnome_print_context_close (gpc);
-}
-
-static void
-save_state (GtkButton *button, gpointer data)
-{
- ETreeModel *e_tree_model = E_TREE_MODEL (data);
-
- e_tree_model_save_expanded_state (e_tree_model, "expanded_state");
-}
-
-/* We create a window containing our new tree. */
-static void
-create_tree (void)
-{
- GtkWidget *window, *frame, *button, *vbox;
- ECell *cell_left_just;
- ECell *cell_tree;
- ETableHeader *e_table_header;
- int i, j;
- ETreeModel *e_tree_model = NULL;
- ETreePath *root_node;
-
- /* here we create our model. This uses the functions we defined
- earlier. */
- e_tree_model = e_tree_simple_new (my_col_count,
- my_duplicate_value,
- my_free_value,
- my_initialize_value,
- my_value_is_empty,
- my_value_to_string,
- my_icon_at,
- my_value_at,
- my_set_value_at,
- my_is_editable,
- NULL);
-
- e_tree_model_load_expanded_state (e_tree_model, "expanded_state");
-
- /* create a root node with 5 children */
- root_node = e_tree_model_node_insert (e_tree_model, NULL,
- 0,
- g_strdup("Root Node"));
-
- e_tree_model_root_node_set_visible (e_tree_model, FALSE);
-
- for (i = 0; i < 5; i++){
- char *id = g_strdup_printf ("First level child %d", i);
- ETreePath *n = e_tree_model_node_insert_id (e_tree_model,
- root_node, 0,
- g_strdup("First level of children"),
- id);
- g_free (id);
- for (j = 0; j < 5; j ++) {
- char *id = g_strdup_printf ("Second level child %d", j);
- e_tree_model_node_insert_id (e_tree_model,
- n, 0,
- g_strdup("Second level of children"), id);
- g_free (id);
- }
- }
-
- /*
- * Next we create a header. The ETableHeader is used in two
- * different way. The first is the full_header. This is the
- * list of possible columns in the view. The second use is
- * completely internal. Many of the ETableHeader functions are
- * for that purpose. The only functions we really need are
- * e_table_header_new and e_table_header_add_col.
- *
- * First we create the header.
- */
- e_table_header = e_table_header_new ();
-
- /*
- * Next we have to build renderers for all of the columns.
- * Since all our columns are text columns, we can simply use
- * the same renderer over and over again. If we had different
- * types of columns, we could use a different renderer for
- * each column.
- */
- cell_left_just = e_cell_text_new (E_TABLE_MODEL(e_tree_model), NULL, GTK_JUSTIFY_LEFT);
-
- /*
- * This renderer is used for the tree column (the leftmost one), and
- * has as its subcell renderer the text renderer. this means that
- * text is displayed to the right of the tree pipes.
- */
- cell_tree = e_cell_tree_new (E_TABLE_MODEL(e_tree_model),
- NULL, NULL, /* use the default pixbufs for open/closed */
- TRUE, cell_left_just);
-
- /*
- * Next we create a column object for each view column and add
- * them to the header. We don't create a column object for
- * the importance column since it will not be shown.
- */
- for (i = 0; i < COLS; i++) {
- /* Create the column. */
- ETableCol *ecol = e_table_col_new (
- i, headers [i],
- 80, 20,
- i == 0 ? cell_tree
- : cell_left_just,
- g_str_compare, TRUE);
- /* Add it to the header. */
- e_table_header_add_column (e_table_header, ecol, i);
- }
-
- /*
- * Here we create a window for our new table. This window
- * will get shown and the person will be able to test their
- * item.
- */
- window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
-
- /* This frame is simply to get a bevel around our table. */
- vbox = gtk_vbox_new (FALSE, 0);
- frame = gtk_frame_new (NULL);
-
- /*
- * Here we create the table. We give it the three pieces of
- * the table we've created, the header, the model, and the
- * initial layout. It does the rest.
- */
- e_table = e_table_new (e_table_header, E_TABLE_MODEL(e_tree_model), INITIAL_SPEC);
-
- if (!e_table) printf ("BAH!");
-
- /* Build the gtk widget hierarchy. */
- gtk_container_add (GTK_CONTAINER (frame), e_table);
- gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);
-
- button = gtk_button_new_with_label ("Toggle Root Node");
- gtk_signal_connect (GTK_OBJECT (button), "clicked", toggle_root, e_tree_model);
- gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
-
- button = gtk_button_new_with_label ("Add Sibling");
- gtk_signal_connect (GTK_OBJECT (button), "clicked", add_sibling, e_tree_model);
- gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
-
- button = gtk_button_new_with_label ("Add Child");
- gtk_signal_connect (GTK_OBJECT (button), "clicked", add_child, e_tree_model);
- gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
-
- button = gtk_button_new_with_label ("Remove Node");
- gtk_signal_connect (GTK_OBJECT (button), "clicked", remove_node, e_tree_model);
- gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
-
- button = gtk_button_new_with_label ("Expand All Below");
- gtk_signal_connect (GTK_OBJECT (button), "clicked", expand_all, e_tree_model);
- gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
-
- button = gtk_button_new_with_label ("Collapse All Below");
- gtk_signal_connect (GTK_OBJECT (button), "clicked", collapse_all, e_tree_model);
- gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
-
- button = gtk_button_new_with_label ("Print Tree");
- gtk_signal_connect (GTK_OBJECT (button), "clicked", print_tree, e_tree_model);
- gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 0);
-
- button = gtk_button_new_with_label ("Save State");
- gtk_signal_connect (GTK_OBJECT (button), "clicked", save_state, e_tree_model);
- gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 0);
-
- gtk_container_add (GTK_CONTAINER (window), vbox);
-
- /* Size the initial window. */
- gtk_widget_set_usize (window, 200, 200);
-
- gtk_signal_connect (GTK_OBJECT (window), "delete-event", gtk_main_quit, NULL);
-
- /* Show it all. */
- gtk_widget_show_all (window);
-}
-
-/* This is the main function which just initializes gnome and call our create_tree function */
-
-int
-main (int argc, char *argv [])
-{
- gnome_init ("TableExample", "TableExample", argc, argv);
-
- gtk_widget_push_visual (gdk_rgb_get_visual ());
- gtk_widget_push_colormap (gdk_rgb_get_cmap ());
-
- create_tree ();
-
- gtk_main ();
-
- return 0;
-}
-
diff --git a/widgets/table/e-tree-example-2.c b/widgets/table/e-tree-example-2.c
deleted file mode 100644
index dbacf1740e..0000000000
--- a/widgets/table/e-tree-example-2.c
+++ /dev/null
@@ -1,728 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* e-tree-example-2.c - Test program for directory reading in the GNOME
- Virtual File System.
-
- Copyright (C) 1999 Free Software Foundation
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-
- Author: Ettore Perazzoli <ettore@comm2000.it> */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <gnome.h>
-#include <gdk-pixbuf/gdk-pixbuf.h>
-#include <libgnomevfs/gnome-vfs.h>
-#include <libgnomevfs/gnome-vfs-mime-handlers.h>
-#include <gdk-pixbuf/gdk-pixbuf.h>
-#include "e-hpaned.h"
-#include "gal/e-util/e-cursors.h"
-#include "e-table-header.h"
-#include "e-table-header-item.h"
-#include "e-table-item.h"
-#include "e-cell-text.h"
-#include "e-cell-tree.h"
-#include "e-cell-checkbox.h"
-#include "e-table-scrolled.h"
-#include "e-tree-simple.h"
-
-#include "art/tree-expanded.xpm"
-#include "art/tree-unexpanded.xpm"
-
-GdkPixbuf *tree_expanded_pixbuf;
-GdkPixbuf *tree_unexpanded_pixbuf;
-
-#define MINI_ICON_SIZE 16
-
-#define RIGHT_COLS 4
-#define LEFT_COLS 4
-
-#define RIGHT_E_TABLE_SPEC \
-"<ETableSpecification> \
- <columns-shown> \
- <column> 0 </column> \
- <column> 1 </column> \
- <column> 2 </column> \
- <column> 3 </column> \
- </columns-shown> \
- <grouping></grouping> \
-</ETableSpecification>"
-
-#define LEFT_E_TABLE_SPEC \
-"<ETableSpecification no-header=\"1\"> \
- <columns-shown> \
- <column> 0 </column> \
- </columns-shown> \
- <grouping></grouping> \
-</ETableSpecification>"
-
-char *left_headers [LEFT_COLS] = {
- "Folder"
-};
-
-char *right_headers [RIGHT_COLS] = {
- "Name",
- "Size",
- "Type",
- "Mime Type"
-};
-
-
-
-GnomeVFSDirectoryFilter *left_filter;
-GnomeVFSDirectoryFilter *right_filter;
-GHashTable *mime_type_to_pixbuf;
-GnomeVFSDirectoryList *right_list = NULL;
-ETreePath *right_root;
-ETreeModel *right_model = NULL;
-ETreeModel *left_model = NULL;
-
-typedef struct {
- char *node_uri;
- GnomeVFSFileInfo *info;
-
- /* next two used only if the node is a directory */
- /* used if the node is expanded */
- GnomeVFSDirectoryList *list;
- /* used if the node is collapsed */
- ETreePath *placeholder;
-} VFSInfo;
-
-/*
- * ETreeSimple callbacks
- * These are the callbacks that define the behavior of our custom model.
- */
-
-static gchar *
-type_to_string (GnomeVFSFileType type)
-{
- switch (type) {
- case GNOME_VFS_FILE_TYPE_UNKNOWN:
- return "Unknown";
- case GNOME_VFS_FILE_TYPE_REGULAR:
- return "Regular";
- case GNOME_VFS_FILE_TYPE_DIRECTORY:
- return "Directory";
- case GNOME_VFS_FILE_TYPE_SYMBOLIC_LINK:
- return "Symbolic Link";
- case GNOME_VFS_FILE_TYPE_FIFO:
- return "FIFO";
- case GNOME_VFS_FILE_TYPE_SOCKET:
- return "Socket";
- case GNOME_VFS_FILE_TYPE_CHARACTER_DEVICE:
- return "Character device";
- case GNOME_VFS_FILE_TYPE_BLOCK_DEVICE:
- return "Block device";
- default:
- return "???";
- }
-}
-
-/* This function returns the value at a particular point in our ETreeModel. */
-static void *
-tree_value_at (ETreeModel *etm, ETreePath *path, int col, void *model_data)
-{
- VFSInfo *vfs_info = e_tree_model_node_get_data (etm, path);
-
- switch (col) {
- case 0: /* filename */
- if (vfs_info->info)
- return vfs_info->info->name;
- else
- return vfs_info->node_uri;
- case 1: /* size */ {
- static char buf[15];
- if (vfs_info->info) {
- if (vfs_info->info->type == GNOME_VFS_FILE_TYPE_DIRECTORY)
- return "";
- else {
- g_snprintf (buf, sizeof(buf), "%ld", (glong) vfs_info->info->size);
- return buf;
- }
- }
- else
- return "";
- }
- case 2: /* file type */
- if (vfs_info->info)
- return type_to_string (vfs_info->info->type);
- else
- return "";
- case 3: /* mime type */
- if (vfs_info->info) {
- const char *mime_type = gnome_vfs_file_info_get_mime_type (vfs_info->info);
- if (mime_type == NULL)
- mime_type = "(Unknown)";
- return (void*)mime_type;
- }
- else {
- return "";
- }
- default: return "";
- }
-}
-
-/* This function returns the number of columns in our ETableModel. */
-static int
-tree_col_count (ETableModel *etc, void *data)
-{
- return RIGHT_COLS;
-}
-
-/* This function duplicates the value passed to it. */
-static void *
-tree_duplicate_value (ETableModel *etc, int col, const void *value, void *data)
-{
- return g_strdup (value);
-}
-
-/* This function frees the value passed to it. */
-static void
-tree_free_value (ETableModel *etc, int col, void *value, void *data)
-{
- g_free (value);
-}
-
-/* This function creates an empty value. */
-static void *
-tree_initialize_value (ETableModel *etc, int col, void *data)
-{
- return g_strdup ("");
-}
-
-/* This function reports if a value is empty. */
-static gboolean
-tree_value_is_empty (ETableModel *etc, int col, const void *value, void *data)
-{
- return !(value && *(char *)value);
-}
-
-/* This function reports if a value is empty. */
-static char *
-tree_value_to_string (ETableModel *etc, int col, const void *value, void *data)
-{
- return g_strdup(value);
-}
-
-static GdkPixbuf *
-tree_icon_at (ETreeModel *etm, ETreePath *path, void *model_data)
-{
- VFSInfo *vfs_info = e_tree_model_node_get_data (etm, path);
- const char *mime_type;
- GdkPixbuf *scaled_pixbuf = NULL;
-
- if (vfs_info->info == NULL)
- return NULL;
-
- mime_type = gnome_vfs_file_info_get_mime_type (vfs_info->info);
- if (mime_type == NULL)
- mime_type = "(Unknown)";
-
- scaled_pixbuf = g_hash_table_lookup (mime_type_to_pixbuf, mime_type);
- if (!scaled_pixbuf) {
- const char *icon_filename = gnome_vfs_mime_get_icon (mime_type);
- if (icon_filename) {
- GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (icon_filename);
-
- if (pixbuf) {
- scaled_pixbuf = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (pixbuf),
- gdk_pixbuf_get_has_alpha (pixbuf),
- gdk_pixbuf_get_bits_per_sample (pixbuf),
- MINI_ICON_SIZE, MINI_ICON_SIZE);
-
- gdk_pixbuf_scale (pixbuf, scaled_pixbuf,
- 0, 0, MINI_ICON_SIZE, MINI_ICON_SIZE,
- 0.0, 0.0,
- (double) MINI_ICON_SIZE / gdk_pixbuf_get_width (pixbuf),
- (double) MINI_ICON_SIZE / gdk_pixbuf_get_height (pixbuf),
- GDK_INTERP_HYPER);
-
- g_hash_table_insert (mime_type_to_pixbuf, (char*)mime_type, scaled_pixbuf);
-
- gdk_pixbuf_unref (pixbuf);
- }
- }
- }
-
- return scaled_pixbuf;
-}
-
-/* This function sets the value at a particular point in our ETreeModel. */
-static void
-tree_set_value_at (ETreeModel *etm, ETreePath *path, int col, const void *val, void *model_data)
-{
-}
-
-/* This function returns whether a particular cell is editable. */
-static gboolean
-tree_is_editable (ETreeModel *etm, ETreePath *path, int col, void *model_data)
-{
- return FALSE;
-}
-
-static void
-sort_list (GnomeVFSDirectoryList *list)
-{
- GnomeVFSDirectorySortRule rules[] = {
- GNOME_VFS_DIRECTORY_SORT_DIRECTORYFIRST,
- GNOME_VFS_DIRECTORY_SORT_BYNAME,
- GNOME_VFS_DIRECTORY_SORT_NONE
- };
-
-
- gnome_vfs_directory_list_sort (list, FALSE, rules);
-}
-
-
-
-static void
-node_collapsed (ETreeModel *etm, ETreePath *path, void *data)
-{
- VFSInfo *vfs_info = e_tree_model_node_get_data (etm, path);
- char *name;
- ETreePath **paths;
- int num_children, i;
-
- if (vfs_info->info)
- name = vfs_info->info->name;
- else
- name = vfs_info->node_uri;
-
- gnome_vfs_directory_list_destroy (vfs_info->list);
-
- /* remove the children of this node, and replace the placeholder */
- num_children = e_tree_model_node_get_children (etm, path, &paths);
- for (i = 0; i < num_children; i ++)
- e_tree_model_node_remove (etm, paths[i]);
- vfs_info->placeholder = e_tree_model_node_insert (etm, path, 0, NULL);
-}
-
-static void
-node_expanded (ETreeModel *etm, ETreePath *path, gboolean *allow_expand, void *data)
-{
- VFSInfo *vfs_info = e_tree_model_node_get_data (etm, path);
- GnomeVFSFileInfo *info;
- GnomeVFSResult result;
- char *name;
-
- if (vfs_info->info)
- name = vfs_info->info->name;
- else
- name = vfs_info->node_uri;
-
- /* Load with no filters and without requesting any metadata. */
- result = gnome_vfs_directory_list_load
- (&vfs_info->list, vfs_info->node_uri,
- (GNOME_VFS_FILE_INFO_GET_MIME_TYPE
- | GNOME_VFS_FILE_INFO_FORCE_FAST_MIME_TYPE
- | GNOME_VFS_FILE_INFO_FOLLOW_LINKS),
- left_filter);
-
- *allow_expand = (result == GNOME_VFS_OK);
-
- if (!*allow_expand) {
- char *buf = g_strdup_printf ("Cannot open directory %s : %s\n",
- vfs_info->info->name, gnome_vfs_result_to_string (result));
- gnome_error_dialog (buf);
- g_free (buf);
- return;
- }
-
- sort_list (vfs_info->list);
-
- /* remove the placeholder and insert all the children of this node */
- e_tree_model_node_remove (etm, vfs_info->placeholder);
-
- info = gnome_vfs_directory_list_first (vfs_info->list);
-
- if (info == NULL) {
- /* no files */
- return;
- }
-
- while (info != NULL) {
- if (info->type == GNOME_VFS_FILE_TYPE_DIRECTORY) {
- ETreePath *new_node;
- VFSInfo *new_vfs_info = g_new0(VFSInfo, 1);
- new_vfs_info->info = info;
-
- new_node = e_tree_model_node_insert (etm, path, -1, new_vfs_info);
- new_vfs_info->placeholder = e_tree_model_node_insert (etm, new_node, -1, NULL);
- new_vfs_info->node_uri = g_strdup_printf("%s%s/", vfs_info->node_uri, info->name);
- }
-
- info = gnome_vfs_directory_list_next (vfs_info->list);
- }
-}
-
-static void
-on_cursor_change (ETable *table,
- int row,
- gpointer user_data)
-{
- int num_children, i;
- GnomeVFSFileInfo *info;
- GnomeVFSResult result;
- ETreePath **paths;
- ETreePath *left_path = e_tree_model_node_at_row (left_model, row);
- VFSInfo *vfs_info = e_tree_model_node_get_data (left_model, left_path);
-
- if (right_list) {
- gnome_vfs_directory_list_destroy (right_list);
- right_list = NULL;
- }
-
- /* remove the children of this node, and replace the placeholder */
- num_children = e_tree_model_node_get_children (right_model, right_root, &paths);
- for (i = 0; i < num_children; i ++)
- e_tree_model_node_remove (right_model, paths[i]);
-
- /* Load with no filters and without requesting any metadata. */
- result = gnome_vfs_directory_list_load
- (&right_list, vfs_info->node_uri,
- (GNOME_VFS_FILE_INFO_GET_MIME_TYPE
- | GNOME_VFS_FILE_INFO_FORCE_FAST_MIME_TYPE
- | GNOME_VFS_FILE_INFO_FOLLOW_LINKS),
- right_filter);
-
- if (result != GNOME_VFS_OK)
- return;
-
- info = gnome_vfs_directory_list_first (right_list);
- if (!info)
- return;
-
- while (info != NULL) {
- ETreePath *new_node;
- VFSInfo *new_vfs_info = g_new0(VFSInfo, 1);
- new_vfs_info->info = info;
-
- new_node = e_tree_model_node_insert (right_model, right_root, -1, new_vfs_info);
-
- new_vfs_info->node_uri = g_strdup_printf("%s%s", vfs_info->node_uri, info->name);
-
- info = gnome_vfs_directory_list_next (right_list);
- }
-
-}
-
-static void
-on_double_click (ETable *etable,
- int row,
- void *data)
-{
- GnomeVFSMimeApplication *app;
- ETreePath *path = e_tree_model_node_at_row (right_model, row);
- VFSInfo *vfs_info = e_tree_model_node_get_data (right_model, path);
- const char *mime_type = gnome_vfs_file_info_get_mime_type (vfs_info->info);
- if (mime_type == NULL)
- mime_type = "(Unknown)";
-
- app = gnome_vfs_mime_get_default_application (mime_type);
-
- if (app)
- printf ("exec %s\n", app->command);
- else
- printf ("no command for mime type %s\n", mime_type);
-}
-
-/* create the table on the right */
-static GtkWidget*
-create_right_tree(GtkWidget *paned)
-{
- GtkWidget *e_table;
- GtkWidget *frame;
- ECell *cell_left_just;
- ECell *cell_tree;
- ETableHeader *e_table_header;
- int i;
-
- right_filter = gnome_vfs_directory_filter_new (GNOME_VFS_DIRECTORY_FILTER_NONE,
- GNOME_VFS_DIRECTORY_FILTER_NODIRS,
- NULL);
-
- /* here we create our model. This uses the functions we defined
- earlier. */
- right_model = e_tree_simple_new (tree_col_count,
- tree_duplicate_value,
- tree_free_value,
- tree_initialize_value,
- tree_value_is_empty,
- tree_value_to_string,
- tree_icon_at,
- tree_value_at,
- tree_set_value_at,
- tree_is_editable,
- NULL);
-
- /* create the unexpanded root node and it's placeholder child. */
- right_root = e_tree_model_node_insert (right_model, NULL,
- 0, NULL);
- e_tree_model_root_node_set_visible (right_model, FALSE);
-
- /*
- * Next we create a header. The ETableHeader is used in two
- * different way. The first is the full_header. This is the
- * list of possible columns in the view. The second use is
- * completely internal. Many of the ETableHeader functions are
- * for that purpose. The only functions we really need are
- * e_table_header_new and e_table_header_add_col.
- *
- * First we create the header.
- */
- e_table_header = e_table_header_new ();
-
- /*
- * Next we have to build renderers for all of the columns.
- * Since all our columns are text columns, we can simply use
- * the same renderer over and over again. If we had different
- * types of columns, we could use a different renderer for
- * each column.
- */
- cell_left_just = e_cell_text_new (E_TABLE_MODEL(right_model), NULL, GTK_JUSTIFY_LEFT);
-
- /*
- * This renderer is used for the tree column (the leftmost one), and
- * has as its subcell renderer the text renderer. this means that
- * text is displayed to the right of the tree pipes.
- */
- cell_tree = e_cell_tree_new (E_TABLE_MODEL(right_model),
- tree_expanded_pixbuf, tree_unexpanded_pixbuf,
- TRUE, cell_left_just);
-
- /*
- * Next we create a column object for each view column and add
- * them to the header. We don't create a column object for
- * the importance column since it will not be shown.
- */
- for (i = 0; i < RIGHT_COLS; i++) {
- /* Create the column. */
- ETableCol *ecol = e_table_col_new (
- i, right_headers [i],
- 80, 20,
- i == 0 ? cell_tree
- : cell_left_just,
- g_str_compare, TRUE);
- /* Add it to the header. */
- e_table_header_add_column (e_table_header, ecol, i);
- }
-
- /* This frame is simply to get a bevel around our table. */
- frame = gtk_frame_new (NULL);
-
- /*
- * Here we create the table. We give it the three pieces of
- * the table we've created, the header, the model, and the
- * initial layout. It does the rest.
- */
- e_table = e_table_scrolled_new (e_table_header, E_TABLE_MODEL(right_model), RIGHT_E_TABLE_SPEC);
-
- gtk_signal_connect (GTK_OBJECT (e_table), "double_click", GTK_SIGNAL_FUNC (on_double_click), NULL);
-
- /* Build the gtk widget hierarchy. */
- gtk_container_add (GTK_CONTAINER (frame), e_table);
- gtk_container_add (GTK_CONTAINER (paned), frame);
-
- return e_table;
-}
-
-/* We create a window containing our new tree. */
-static GtkWidget *
-create_left_tree (GtkWidget *paned, char *root_uri)
-{
- GtkWidget *scrolled;
- GtkWidget *e_table;
- GtkWidget *frame;
- ECell *cell_left_just;
- ECell *cell_tree;
- ETableHeader *e_table_header;
- ETreePath *root_node;
- VFSInfo *root_vfs_info;
- ETableCol *ecol;
-
- left_filter = gnome_vfs_directory_filter_new (GNOME_VFS_DIRECTORY_FILTER_NONE,
- /* putting DIRSONLY doesn't work here, so we filter
- files out in node_expanded. */
- (GNOME_VFS_DIRECTORY_FILTER_NOSELFDIR
- | GNOME_VFS_DIRECTORY_FILTER_NOPARENTDIR),
- NULL);
-
-
- /* here we create our model. This uses the functions we defined
- earlier. */
- left_model = e_tree_simple_new (tree_col_count,
- tree_duplicate_value,
- tree_free_value,
- tree_initialize_value,
- tree_value_is_empty,
- tree_value_to_string,
- tree_icon_at,
- tree_value_at,
- tree_set_value_at,
- tree_is_editable,
- NULL);
-
- /* catch collapsed/expanded signals */
- gtk_signal_connect (GTK_OBJECT (left_model), "node_expanded",
- GTK_SIGNAL_FUNC (node_expanded), NULL);
-
- gtk_signal_connect (GTK_OBJECT (left_model), "node_collapsed",
- GTK_SIGNAL_FUNC (node_collapsed), NULL);
-
- /* create the unexpanded root node and it's placeholder child. */
- root_vfs_info = g_new0 (VFSInfo, 1);
- root_vfs_info->node_uri = g_strdup (root_uri);
- root_vfs_info->info = gnome_vfs_file_info_new();
-
- gnome_vfs_get_file_info (root_uri, root_vfs_info->info,
- GNOME_VFS_FILE_INFO_GET_MIME_TYPE
- | GNOME_VFS_FILE_INFO_FORCE_FAST_MIME_TYPE
- | GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
-
- root_node = e_tree_model_node_insert (left_model, NULL,
- 0,
- root_vfs_info);
- e_tree_model_node_set_expanded (left_model, root_node, FALSE);
-
- root_vfs_info->placeholder = e_tree_model_node_insert (left_model, root_node, 0, NULL);
-
- e_tree_model_root_node_set_visible (left_model, TRUE);
-
- /*
- * Next we create a header. The ETableHeader is used in two
- * different way. The first is the full_header. This is the
- * list of possible columns in the view. The second use is
- * completely internal. Many of the ETableHeader functions are
- * for that purpose. The only functions we really need are
- * e_table_header_new and e_table_header_add_col.
- *
- * First we create the header.
- */
- e_table_header = e_table_header_new ();
-
- /*
- * Next we have to build renderers for all of the columns.
- * Since all our columns are text columns, we can simply use
- * the same renderer over and over again. If we had different
- * types of columns, we could use a different renderer for
- * each column.
- */
- cell_left_just = e_cell_text_new (E_TABLE_MODEL(left_model), NULL, GTK_JUSTIFY_LEFT);
-
- /*
- * This renderer is used for the tree column (the leftmost one), and
- * has as its subcell renderer the text renderer. this means that
- * text is displayed to the right of the tree pipes.
- */
- cell_tree = e_cell_tree_new (E_TABLE_MODEL(left_model),
- tree_expanded_pixbuf, tree_unexpanded_pixbuf,
- TRUE, cell_left_just);
-
- /* Create the column. */
- ecol = e_table_col_new (0, left_headers [0],
- 80, 20,
- cell_tree,
- g_str_compare, TRUE);
-
- e_table_header_add_column (e_table_header, ecol, 0);
-
- /* This frame is simply to get a bevel around our table. */
- frame = gtk_frame_new (NULL);
-
- /*
- * Here we create the table. We give it the three pieces of
- * the table we've created, the header, the model, and the
- * initial layout. It does the rest.
- */
- e_table = e_table_new (e_table_header, E_TABLE_MODEL(left_model), LEFT_E_TABLE_SPEC);
-
- gtk_object_set (GTK_OBJECT (e_table),
- "cursor_mode", E_TABLE_CURSOR_LINE,
- NULL);
-
- scrolled = gtk_scrolled_window_new (NULL, NULL);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
- GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
-
- /* Build the gtk widget hierarchy. */
- gtk_container_add (GTK_CONTAINER (scrolled), e_table);
- gtk_container_add (GTK_CONTAINER (frame), scrolled);
- gtk_container_add (GTK_CONTAINER (paned), frame);
-
- return e_table;
-}
-
-static void
-create_window(char *root_uri)
-{
- GtkWidget *paned;
- GtkWidget *window, *left_tree, *right_tree;
-
- window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- paned = e_hpaned_new ();
-
- gtk_container_add (GTK_CONTAINER (window), paned);
-
- left_tree = create_left_tree (paned, root_uri);
- right_tree = create_right_tree (paned);
-
- /* Show it all. */
- gtk_widget_show_all (window);
-
- gtk_signal_connect (GTK_OBJECT (left_tree), "cursor_change", GTK_SIGNAL_FUNC (on_cursor_change), NULL);
- gtk_signal_connect (GTK_OBJECT (window), "delete-event", gtk_main_quit, NULL);
-
- /* kick things off by selecting the root node */
- e_table_set_cursor_row (E_TABLE (left_tree), 0);
- on_cursor_change (E_TABLE(left_tree), 0, NULL);
-}
-
-
-int
-main (int argc, char **argv)
-{
- gchar *root_uri;
-
- if (argv[1] == NULL)
- root_uri = "file:///";
- else
- root_uri = argv[1];
-
- gnome_init ("TableExample", "TableExample", argc, argv);
- e_cursors_init ();
- gnome_vfs_init ();
-
- mime_type_to_pixbuf = g_hash_table_new (g_str_hash, g_str_equal);
-
- gtk_widget_push_visual (gdk_rgb_get_visual ());
- gtk_widget_push_colormap (gdk_rgb_get_cmap ());
-
- /*
- * Create our pixbuf for expanding/unexpanding
- */
- tree_expanded_pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)tree_expanded_xpm);
- tree_unexpanded_pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)tree_unexpanded_xpm);
-
- create_window (root_uri);
-
- gtk_main ();
-
- e_cursors_shutdown ();
- return 0;
-}