populate gtk tree view from outside




Dear friends,
I have defined a treeview model as follows:

enum
{
  COL_FIRST_NAME = 0,
  COL_LAST_NAME,
  COL_YEAR_BORN,
  NUM_COLS
} ;

static GtkTreeModel *
create_and_fill_model (void)
{
  GtkTreeStore  *treestore;
  GtkTreeIter    toplevel, child;

  treestore = gtk_tree_store_new(NUM_COLS,
                                 G_TYPE_STRING,
                                 G_TYPE_STRING,
                                 G_TYPE_UINT);

int i;
FILE *fauth; 
char alst[10][500], buffer[500];
fauth=fopen("fauth.dat","r");
if(!fauth){
        printf("fauth failed\n");
}

while(fgets(buffer,500,fauth)){
        strcpy(alst[i],buffer);
        i++;
    }
fclose(fauth);

for (i = 0; i < 10; i++){
  gtk_tree_store_append(treestore, &toplevel, NULL);
  gtk_tree_store_set(treestore, &toplevel,
                     COL_FIRST_NAME, alst[i],
                     COL_LAST_NAME, "Average",
                     COL_YEAR_BORN, (guint) 1962,
                     -1);
}

  return GTK_TREE_MODEL(treestore);
}


static GtkWidget *
create_view_and_model (void)
{
  GtkTreeViewColumn   *col;
  GtkCellRenderer     *renderer;
  GtkWidget           *view;
  GtkTreeModel        *model;
  view = gtk_tree_view_new();
  col = gtk_tree_view_column_new();
  gtk_tree_view_column_set_title(col, "First Name");
  gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
  renderer = gtk_cell_renderer_text_new();
  gtk_tree_view_column_pack_start(col, renderer, TRUE);
  gtk_tree_view_column_add_attribute(col, renderer, "text",
COL_FIRST_NAME);
   gtk_tree_view_column_pack_start(col, renderer, TRUE);
  model = create_and_fill_model();
gtk_tree_view_set_model(GTK_TREE_VIEW(view), model);
  g_object_unref(model); 

gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(view)),
                              GTK_SELECTION_NONE);
  return view;
}
//For brevity, I have cut out the 2nd and 3rd column



In a different function, I have


  strAuth = gtk_entry_get_text(GTK_ENTRY(e->entryAuth));
    strEditor = gtk_entry_get_text(GTK_ENTRY(e->entryEditor));


Is it possible to add these strAuth, strEditor in those treeview's 1st
and 2nd column?





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]