GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Jul 26, 2014 11:11 am

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: how to get a treeview value... it doesn't work
PostPosted: Mon Jun 23, 2014 6:57 pm 
Offline

Joined: Mon Jun 23, 2014 3:32 pm
Posts: 1
Hi everybody,

i can't get treeview value of my liststore.i've a result but the result is similar if i click on the first value or last value.

Code:
#include "fileviewer.h"



int main(int argc,char *argv[])
{         
   gtk_init(&argc,&argv);

   t_widget *p_widget = init_gtkWidget();
   
   interface();
   free_gtkWidget();

   return EXIT_SUCCESS;
   
}

t_widget *init_gtkWidget()
{
   t_widget *p_widget = malloc(sizeof(t_widget));
   
   if(p_widget) {
      
      p_widget->pMainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);;
      p_widget->pModel = NULL;
      p_widget->pTreeView =  gtk_tree_view_new();
      p_widget->pButton_def = gtk_button_new_with_label("Definir");
      p_widget->pButton_quitter = gtk_button_new_with_label("Quitter");;
      p_widget->pFixed = gtk_fixed_new();
      p_widget->pCombo_box = gtk_combo_box_new_with_entry();
      p_widget->pScrollBar = gtk_scrolled_window_new(NULL,NULL);   
      p_widget->pRenderer = gtk_cell_renderer_text_new();
      p_widget->pListe= NULL;
      p_widget->test= NULL;
      p_widget->valeur = 10;
   
      
   }
   return p_widget;
}


void interface()
{   
   t_widget *p_widget;

        /* Combo Box */
      gtk_fixed_put(GTK_FIXED(p_widget->pFixed), p_widget->pCombo_box, 25, 50);
   gtk_widget_set_size_request(p_widget->pCombo_box, 250,10);
   
        /* Bouton Definir */
   gtk_fixed_put(GTK_FIXED(p_widget->pFixed), p_widget->pButton_def , 25, 100);
   gtk_widget_set_size_request(p_widget->pButton_def, 100, 20);
   
   /* Bouton Quitter */
   gtk_fixed_put(GTK_FIXED(p_widget->pFixed), p_widget->pButton_quitter, 150, 100);
        gtk_widget_set_size_request(p_widget->pButton_quitter, 100, 20);

   /* Barre derroulante */
   gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(p_widget->pScrollBar), GTK_POLICY_ALWAYS, GTK_POLICY_NEVER);


   /* Liste */
   //gtk_container_add(GTK_CONTAINER(pScrollBar),pTreeView);

          /* Colonne 1 */
   gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW(p_widget->pTreeView), -1, "Fichier", p_widget->pRenderer, "text", 0, NULL);

   /* Colonne 2 */
   gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW(p_widget->pTreeView), -1, "Option", p_widget->pRenderer, "text", 1, NULL);
   p_widget->pModel = remplissageTreeView(p_widget);

   gtk_tree_view_set_model(GTK_TREE_VIEW(p_widget->pTreeView), p_widget->pModel);
   gtk_fixed_put(GTK_FIXED(p_widget->pFixed), p_widget->pTreeView, 350, 25);

   gtk_widget_set_size_request(p_widget->pTreeView, 900,450);
   gtk_container_add(GTK_CONTAINER(p_widget->pMainWindow),p_widget->pFixed);
   gtk_widget_show_all(p_widget->pMainWindow);
   
   /* Signaux */

   g_signal_connect(G_OBJECT(p_widget->pMainWindow), "delete event", G_CALLBACK(gtk_main_quit), NULL);
   g_signal_connect(G_OBJECT(p_widget->pButton_quitter),"clicked", G_CALLBACK(gtk_main_quit), NULL);
   g_signal_connect(G_OBJECT(p_widget->pTreeView),"button-press-event",G_CALLBACK(test),(gpointer) p_widget);
   g_signal_connect(G_OBJECT(p_widget->pTreeView), "button-release-event", G_CALLBACK(ouvrirFichier),(gpointer)  p_widget);
   
   gtk_window_set_default_size(GTK_WINDOW(p_widget->pMainWindow),300,100);
   gtk_main();

}



GtkTreeModel* remplissageTreeView(t_widget *p_widget)
{
   
       
   gchar *nom[3];
   nom[0] = "Christophe";
   nom[1] = "Pauline";
   nom[2] = "Gary";


   int i;
   /* Affiche tous les fichier contenu dans le dossier */
   GDir *repertoire = g_dir_open("/home/captainchris/Sport", 0,NULL);

   p_widget->pListe = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);

//   const gchar *rep;
//   const gchar *p_file;


   gtk_tree_selection_set_mode(p_widget->test, GTK_SELECTION_MULTIPLE);
//   gtk_list_store_append ( p_widget->pListe, &p_widget->iter);
//   gtk_list_store_set (p_widget->pListe,&p_widget->iter, 0, nom[1] , 1, "Pas Vu", -1);
   for(i =0;i < 3; i++) { ajouterTreeviewSelection(p_widget,nom[i]); }

      
   g_dir_close(repertoire);

   return GTK_TREE_MODEL(p_widget->pListe);
}

void test(GtkTreeView *p_treeView,GdkEvent *event,gpointer *data)
{
   t_widget *p_widget = data;
   

   p_widget->test = gtk_tree_view_get_selection(GTK_TREE_VIEW(p_widget->pTreeView));
   
   
}

void ajouterTreeviewSelection(t_widget *p_widget, const gchar *str)
{
   gtk_list_store_append ( p_widget->pListe, &p_widget->iter);
   gtk_list_store_set (p_widget->pListe,&p_widget->iter, 0, str,1,"Pas vu", -1);
   

}




void ouvrirFichier(GtkTreeView *p_treeView,GdkEvent *event,gpointer *data)
{
   
   t_widget *p_widget =  data;

   GtkTreeSelection *selection;
   gchar *valeur = NULL;
   
//   selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(p_widget->pTreeView));
   gtk_tree_model_get(GTK_TREE_MODEL(p_widget->pModel),&p_widget->iter,0, &valeur,-1);
   g_print(valeur);
   g_free(valeur);    

//   if(gtk_tree_selection_get_selected(GTK_TREE_SELECTION(p_widget->test),&p_widget->pModel,&p_widget->iter)) {
   
        
//   }
//   char buffer[256];
//   sprintf(buffer,"/usr/bin/vlc /home/captainchris/Sport/%s",selection);
//   gtk_widget_hide(p_rwidget->pMainWindow);
//   system(buffer);
   


   gtk_widget_show(p_widget->pMainWindow);
   
   
   

}

void free_gtkWidget()
{
   t_widget *p_widget;
   
   free(p_widget);
   
   
}



thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group