Crash on accessing gtk_combo_box_entry_new_text

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

 



Hi List
I am running GTK-2.20 on Fedora14 64Bit.
I have an application developed using glade3.7.1. I add 'gtk_combo_box_entry_new_text' in run time. My application crashes most of the time when I access the combo box to display pull down menu, without any error messages on terminal. I ran this program in debug mode and surprisingly it crashes fewer times. The backtrace output is:
----------------------------------------------------------------
(gdb) run
Starting program: /opt/prog/sems-2.0/sems
[Thread debugging using libthread_db enabled]
[New Thread 0x7fffe757c700 (LWP 5468)]
[New Thread 0x7fffe6d7b700 (LWP 5469)]

[Thread 0x7fffe6d7b700 (LWP 5469) exited]

Program received signal SIGSEGV, Segmentation fault.
g_type_check_instance_is_a (type_instance=0x8a1000, iface_type=<value optimized out>) at gtype.c:3957 3957 check = node && node->is_instantiatable && iface && type_node_conforms_to_U (node, iface, TRUE, FALSE);
(gdb) backtrace
#0 g_type_check_instance_is_a (type_instance=0x8a1000, iface_type=<value optimized out>) at gtype.c:3957
#1  0x000000387c4b1492 in ?? () from /usr/lib64/libgtk-x11-2.0.so.0
#2  0x000000387c4b164e in ?? () from /usr/lib64/libgtk-x11-2.0.so.0
#3  0x000000387c4b4be1 in ?? () from /usr/lib64/libgtk-x11-2.0.so.0
#4  0x000000387c54e223 in ?? () from /usr/lib64/libgtk-x11-2.0.so.0
#5 0x00007ffff71c4fbe in g_closure_invoke (closure=0x841420, return_value=0x7fffffffdbd0, n_param_values=2, param_values=0x89a060,
    invocation_hint=0x7fffffffdb90) at gclosure.c:767
#6 0x00007ffff71d6a37 in signal_emit_unlocked_R (node=<value optimized out>, detail=0, instance=0x824df0, emission_return=0x7fffffffdd40,
    instance_and_params=0x89a060) at gsignal.c:3252
#7 0x00007ffff71dfc15 in g_signal_emit_valist (instance=<value optimized out>, signal_id=<value optimized out>, detail=<value optimized out>,
    var_args=<value optimized out>) at gsignal.c:2993
#8 0x00007ffff71e0043 in g_signal_emit (instance=<value optimized out>, signal_id=<value optimized out>, detail=<value optimized out>) at gsignal.c:3040
#9  0x000000387c685aef in ?? () from /usr/lib64/libgtk-x11-2.0.so.0
#10 0x000000387c54bd33 in gtk_propagate_event () from /usr/lib64/libgtk-x11-2.0.so.0 #11 0x000000387c54c103 in gtk_main_do_event () from /usr/lib64/libgtk-x11-2.0.so.0
#12 0x000000387cc61a8c in ?? () from /usr/lib64/libgdk-x11-2.0.so.0
#13 0x00007ffff6ad9b63 in g_main_dispatch (context=0x63f100) at gmain.c:2440
#14 g_main_context_dispatch (context=0x63f100) at gmain.c:3013
#15 0x00007ffff6ada340 in g_main_context_iterate (context=0x63f100, block=1, dispatch=1, self=<value optimized out>) at gmain.c:3091
#16 0x00007ffff6ada9b2 in g_main_loop_run (loop=0x8ed2b0) at gmain.c:3299
#17 0x000000387c54b0b7 in gtk_main () from /usr/lib64/libgtk-x11-2.0.so.0
#18 0x000000000040558d in main (argc=1, argv=0x7fffffffe248) at sems.c:706
(gdb)
-----------------------------------------------------
Is this a bug or am I doing something wrong?
Attached is my program code.
Any help will be appreciated.
Rajesh
/*-----------------------------
Program Name: Sems-2.0
Created By:   Rajesh Padalia
Date: 26-02-2009
Compile: gcc -Wall -g -o sems sems.c -export-dynamic `pkg-config --cflags --libs gtk+-2.0`
-------------------------------*/
#include <gtk/gtk.h>
#include <glib.h>
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>	/*need qsort*/
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>       /*need file status*/
#include <sys/utsname.h>    /*need uname*/
#include <unistd.h>
#include <time.h>
#include <math.h>

#define LINES_IN_A_PAGE	42

GtkBuilder *builder;

GtkWidget * CPNamecombo;
GtkWidget * Compoundcombo;
GtkWidget * BlockNamecombo;
GtkWidget * BlockTypecombo;
GtkWidget * Generalcombo;
GtkWidget * vbox4;
GtkWidget * vbox5;
GtkWidget * vbox6;
GtkWidget * vbox7;
GtkWidget * vbox8;
GtkWidget * Searchtreeview;
GtkWidget * CPCountentry;
GtkWidget * CompoundCountentry;
GtkWidget * BlockCountentry;
GtkWidget * TotalCountentry;
GtkWidget * FSaveDialog;
GtkWidget * MsgDialogPrint;
GtkWidget * Config;

GtkTreeModel    *model;                 /*Model with data*/
GtkTreeIter     iter_print;
GtkTreePath  *path_print;

gchar * CPNameDir="/opt/prog/semsdb/";
gchar * Block_Type_File="/opt/prog/sems-2.0/block_names";
gboolean exposed = FALSE;
char *CPNameList[1024];
gint CPCountTotal = 0;
gint TotalCount = 0;
gint CPCount = 0;
gint CompoundCount = 0;
gint BlockCount = 0;
gint Option_Int = 1;

FILE * fd;
FILE * fsave;
DIR * dirp;
struct dirent *direntp;
GdkColor * Colors;

static void begin_print(GtkPrintOperation *operation, GtkPrintContext *context);
static void draw_page (GtkPrintOperation *operation, GtkPrintContext *context, int page_nr);
gboolean  foreach_func (GtkTreeModel *model, GtkTreePath  *path, GtkTreeIter  *iter, gpointer  user_data);

enum
{
        CPNameCol = 0,
        CompoundCol,
        BlockCol,
        BlockTypeCol,
        NUM_COLS
};

void
on_radiobutton1_pressed         (GtkButton *button, gpointer user_data)
{
	Option_Int = 1;
}
void
on_radiobutton2_pressed         (GtkButton *button, gpointer user_data)
{
	Option_Int = 2;
}
void
on_radiobutton3_pressed         (GtkButton *button, gpointer user_data)
{
	Option_Int = 3;
}
void
on_radiobutton4_pressed         (GtkButton *button, gpointer user_data)
{
	Option_Int = 4;
}
void
on_radiobutton5_pressed         (GtkButton *button, gpointer user_data)
{
	Option_Int = 5;
}
void
on_radiobutton6_pressed         (GtkButton *button, gpointer user_data)
{
	Option_Int = 6;
}

void
on_Execute_clicked		(GtkButton *button, gpointer user_data)
{
	g_print("Option %d\n", Option_Int);

	GtkTreeIter	iter;
	GtkTreeSelection	*sel = gtk_tree_view_get_selection( GTK_TREE_VIEW(Searchtreeview));
	GList	*rows = gtk_tree_selection_get_selected_rows( sel, &model );
	GtkTreePath	*path = (GtkTreePath *)rows->data;

	if (gtk_tree_model_get_iter(model, &iter, path))
	{
        	gchar * row_cpname, * row_compound, * row_blockname, * row_blocktype;
		gtk_tree_model_get(model, &iter, CPNameCol, &row_cpname, CompoundCol, &row_compound, BlockCol, &row_blockname, BlockTypeCol, &row_blocktype, -1);
		g_print("Row Data: %s %s %s %s\n", row_cpname, row_compound, row_blockname, row_blocktype);
		g_free(row_cpname);
		g_free(row_compound);
		g_free(row_blockname);
		g_free(row_blocktype);
	}
}


void
on_configreport_clicked		(GtkButton *button, gpointer user_data)
{
	g_print("config report clicked\n");
        gtk_widget_show_all (Config);       
}

void
on_close_in_configrep_clicked(GtkButton *button, gpointer user_data)
{
	gtk_widget_hide(Config);
}

void
on_execute_in_configrep_clicked(GtkButton *button, gpointer user_data)
{
	gtk_widget_hide(Config);
}

void
on_searchtreeview_row_activated (GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *col, gpointer userdata)
{
	GtkTreeIter	iter;

	if (gtk_tree_model_get_iter(model, &iter, path))
	{
        	gchar * row_cpname, * row_compound, * row_blockname, * row_blocktype;
		gtk_tree_model_get(model, &iter, CPNameCol, &row_cpname, CompoundCol, &row_compound, BlockCol, &row_blockname, BlockTypeCol, &row_blocktype, -1);
		g_print("Row Data: %s %s %s %s\n", row_cpname, row_compound, row_blockname, row_blocktype);
		g_free(row_cpname);
		g_free(row_compound);
		g_free(row_blockname);
		g_free(row_blocktype);
	}
}

void
on_Help_clicked		(GtkButton *button, gpointer user_data)
{
	g_print("Option %d\n", Option_Int);
}


void
on_Save_clicked		(GtkButton *button, gpointer user_data)
{
	gtk_dialog_run(GTK_DIALOG(FSaveDialog));
	//gtk_widget_hide(FSaveDialog);	
}

void
on_save_activate        (GtkMenuItem *menuitem, gpointer user_data)
{
	gtk_dialog_run(GTK_DIALOG(FSaveDialog));
	//gtk_widget_hide(FSaveDialog);	
}

void
on_fsave_save_clicked         (GtkButton *button, gpointer user_data)
{
	char *filename;
	filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (FSaveDialog));
	g_print("Filename: %s\n", filename);
	fsave = fopen(filename, "w");
    	fprintf(fsave, "-----------------SEMS - Search Results Summary----------------\n\n");
    	fprintf(fsave, "Search Strings: CP Name:%s\tCompound:%s\tBlock:%s\tBlockType:%s\n", gtk_entry_get_text (GTK_ENTRY (GTK_BIN (CPNamecombo)->child)), gtk_entry_get_text (GTK_ENTRY (GTK_BIN (Compoundcombo)->child)), gtk_entry_get_text (GTK_ENTRY (GTK_BIN (BlockNamecombo)->child)), gtk_entry_get_text (GTK_ENTRY (GTK_BIN (BlockTypecombo)->child)));
    	fprintf(fsave, "Search Summary: CP Name:%d\tCompound:%d\tBlock:%d\tTotal Count:%d\n\n", CPCount, CompoundCount, BlockCount, TotalCount);
    	fprintf(fsave, "%-8s\t%-12s\t%-12s\t%-12s\n", "CP Name","Compound", "Block Name", "Block Type");
	gtk_tree_model_foreach(model, foreach_func, NULL);
        gtk_widget_hide(FSaveDialog);            
    	g_free (filename);
	fclose(fsave);
}

void
on_fsave_cancel_clicked         (GtkButton *button, gpointer user_data)
{
        gtk_widget_hide(FSaveDialog);            
}


gboolean 
foreach_func (GtkTreeModel *model,
                GtkTreePath  *path,
                GtkTreeIter  *iter,
                gpointer      user_data)
{
    gchar *cpname, *compound, *block, *blocktype, *tree_path_str;

    /* Note: here we use 'iter' and not '&iter', because we did not allocate
 *      *  the iter on the stack and are already getting the pointer to a tree iter */

    gtk_tree_model_get (model, iter,
                        CPNameCol, &cpname,
                        CompoundCol, &compound,
                        BlockCol, &block,
                        BlockTypeCol, &blocktype,
                        -1);

    tree_path_str = gtk_tree_path_to_string(path);

    //g_print ("Row %s: %s\t%s\t%s\t%s\n", tree_path_str,
    //         cpname, compound, block, blocktype);
    fprintf(fsave, "%-8s\t%-12s\t%-12s\t%-12s\n", cpname, compound, block, blocktype);
    g_free(tree_path_str);

    g_free(cpname); /* gtk_tree_model_get made copies of       */
    g_free(compound);  /* the strings for us when retrieving them */
    g_free(block);  
    g_free(blocktype);  

    return FALSE; /* do not stop walking the store, call us with next row */
}


void
on_Print_clicked         (GtkButton *button, gpointer user_data)
{
	if (TotalCount == 0) {
		gtk_dialog_run(GTK_DIALOG(MsgDialogPrint));
	}
	else {
		GtkPrintOperation *op; 
		GtkPrintOperationResult res; 
		//GtkPrintSettings *settings;

		op = gtk_print_operation_new ();

		g_signal_connect (op, "begin_print", G_CALLBACK (begin_print), NULL);
		gtk_print_operation_set_unit (op, GTK_UNIT_MM);
		g_signal_connect (op, "draw_page", G_CALLBACK (draw_page), NULL);
		res = gtk_print_operation_run (op, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, NULL, NULL);
	}
}

void
on_print_activate        (GtkMenuItem *menuitem, gpointer user_data)
{
	if (TotalCount == 0) {
		gtk_dialog_run(GTK_DIALOG(MsgDialogPrint));
	}
	else {
		GtkPrintOperation *op; 
		GtkPrintOperationResult res; 
		//GtkPrintSettings *settings;

		op = gtk_print_operation_new ();

		g_signal_connect (op, "begin_print", G_CALLBACK (begin_print), NULL);
		gtk_print_operation_set_unit (op, GTK_UNIT_MM);
		g_signal_connect (op, "draw_page", G_CALLBACK (draw_page), NULL);
		res = gtk_print_operation_run (op, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, NULL, NULL);
	}
}

void
on_msgdialog_print_response(GtkButton *button, gpointer user_data) {
        gtk_widget_hide(MsgDialogPrint);
}


static void
begin_print(GtkPrintOperation *operation, GtkPrintContext *context)
{
	gint rows = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(model), NULL);
	//g_print ("No of Rows: %d %d\n", rows, (int)ceil((double)rows/LINES_IN_A_PAGE));
	//gtk_print_operation_set_n_pages(operation, (int)((double)rows/LINES_IN_A_PAGE));
	gtk_print_operation_set_n_pages(operation, (int)ceil((double)rows/LINES_IN_A_PAGE));
	gtk_print_operation_set_use_full_page(operation, FALSE);
}


static void
draw_page (GtkPrintOperation *operation,
   	   GtkPrintContext   *context,
     	   int                page_nr)
{
	cairo_t *cr;
       	PangoLayout *layout;
       	PangoFontDescription *desc;
       	gchar *page_str;
       	int row_nr;
       	gboolean valid = TRUE;
       	gchar *cpname, *compound, *block, *blocktype, *tree_path_str;

	cr = gtk_print_context_get_cairo_context (context);
       	layout = gtk_print_context_create_pango_layout (context);
     
       	/* Header */
       	cairo_set_source_rgb (cr, 0.5, 0.5, 0.5);
       	cairo_rectangle (cr, 0, 0, gtk_print_context_get_width (context), 11);
       	cairo_fill (cr);
	cairo_move_to (cr, 2, 0);
       	//page_str = g_strdup_printf("Sems: Search Results                                                                                         Page: %d of %d", page_nr+1, (int)((double)TotalCount/LINES_IN_A_PAGE));
       	page_str = g_strdup_printf("Sems: Search Results                                                                                         Page: %d of %d", page_nr+1, (int)ceil((double)TotalCount/LINES_IN_A_PAGE));
       	pango_layout_set_text (layout, page_str, -1);
       	desc = pango_font_description_from_string ("sans 12");
       	pango_layout_set_font_description (layout, desc);
       	pango_font_description_free (desc);
       	pango_cairo_layout_path (cr, layout);
       	cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
       	cairo_set_line_width (cr, 0.3);
       	cairo_stroke_preserve (cr);
       	cairo_fill (cr);
	cairo_move_to (cr, 2, 6);
       	page_str = g_strdup_printf("Search Strings: CP Name: %s, Compound: %s, Block: %s, Block Type: %s", gtk_entry_get_text (GTK_ENTRY (GTK_BIN (CPNamecombo)->child)), gtk_entry_get_text (GTK_ENTRY (GTK_BIN (Compoundcombo)->child)), gtk_entry_get_text (GTK_ENTRY (GTK_BIN (BlockNamecombo)->child)), gtk_entry_get_text (GTK_ENTRY (GTK_BIN (BlockTypecombo)->child)));
       	pango_layout_set_text (layout, page_str, -1);
       	desc = pango_font_description_from_string ("sans 10");
       	pango_layout_set_font_description (layout, desc);
       	pango_font_description_free (desc);
       	pango_cairo_layout_path (cr, layout);
       	cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
       	cairo_set_line_width (cr, 0.3);
       	cairo_stroke_preserve (cr);
       	cairo_fill (cr);
	cairo_move_to (cr, 10, 12);
       	pango_layout_set_text (layout, "CP Name        Compound                           Block                                    Block Type", -1);
       	desc = pango_font_description_from_string ("sans 12");
	pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
       	pango_layout_set_font_description (layout, desc);
       	pango_font_description_free (desc);
       	pango_cairo_layout_path (cr, layout);
       	cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
       	cairo_set_line_width (cr, 0.3);
       	cairo_stroke_preserve (cr);
       	cairo_fill (cr);
	
	if (page_nr == 0) {
		valid = gtk_tree_model_get_iter_first (model, &iter_print);
		path_print = gtk_tree_path_new_from_string("0");
		//path_print = gtk_tree_model_get_path (model, &iter_print);
	}
	for (row_nr = (page_nr*LINES_IN_A_PAGE); row_nr < (page_nr*LINES_IN_A_PAGE) + LINES_IN_A_PAGE; row_nr++){
	 	if (valid) {	
    			gtk_tree_model_get (model, &iter_print,
                	        CPNameCol, &cpname,
                	        CompoundCol, &compound,
                	        BlockCol, &block,
                	        BlockTypeCol, &blocktype,
                	        -1);

    			tree_path_str = gtk_tree_path_to_string(path_print);
       			//page_str = g_strdup_printf("%s\t%s\t\t%s\t\t%s)", cpname, compound, block, blocktype);
			cairo_move_to (cr, 10, 6*(row_nr-page_nr*LINES_IN_A_PAGE)+20);
       			pango_layout_set_text (layout, cpname, -1);
       			desc = pango_font_description_from_string ("sans 10");
       			pango_layout_set_font_description (layout, desc);
       			pango_font_description_free (desc);
       			pango_cairo_layout_path (cr, layout);
       			cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
       			cairo_set_line_width (cr, 0.3);
       			cairo_stroke_preserve (cr);
       			cairo_fill (cr);
			cairo_move_to (cr, 40, 6*(row_nr-page_nr*LINES_IN_A_PAGE)+20);
       			pango_layout_set_text (layout, compound, -1);
       			desc = pango_font_description_from_string ("sans 10");
       			pango_layout_set_font_description (layout, desc);
       			pango_font_description_free (desc);
       			pango_cairo_layout_path (cr, layout);
       			cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
       			cairo_set_line_width (cr, 0.3);
       			cairo_stroke_preserve (cr);
       			cairo_fill (cr);
			if (g_ascii_strcasecmp(blocktype, "COMPND") != 0) { 
			  cairo_move_to (cr, 100, 6*(row_nr-page_nr*LINES_IN_A_PAGE)+20);
       			  pango_layout_set_text (layout, block, -1);
       			  desc = pango_font_description_from_string ("sans 10");
       			  pango_layout_set_font_description (layout, desc);
       			  pango_font_description_free (desc);
       			  pango_cairo_layout_path (cr, layout);
       			  cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
       			  cairo_set_line_width (cr, 0.3);
       			  cairo_stroke_preserve (cr);
       			  cairo_fill (cr);
			}
			cairo_move_to (cr, 160, 6*(row_nr-page_nr*LINES_IN_A_PAGE)+20);
       			pango_layout_set_text (layout, blocktype, -1);
       			desc = pango_font_description_from_string ("sans 10");
       			pango_layout_set_font_description (layout, desc);
       			pango_font_description_free (desc);
       			pango_cairo_layout_path (cr, layout);
       			cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
       			cairo_set_line_width (cr, 0.3);
       			cairo_stroke_preserve (cr);
       			cairo_fill (cr);
    			//g_print ("Row %s: %s\t%s\t%s\t%s\n", tree_path_str,
    			//         cpname, compound, block, blocktype);
			valid = gtk_tree_model_iter_next (model, &iter_print);   
     		}

  	}
/*    	g_free(tree_path_str);
    	g_free(cpname);
    	g_free(compound);
    	g_free(block);  
    	g_free(blocktype);  */
    	
       	g_object_unref (layout);
}


void
on_Clear_clicked		(GtkButton *button, gpointer user_data)
{
	gtk_entry_set_text (GTK_ENTRY (GTK_BIN (CPNamecombo)->child), "");
	gtk_entry_set_text (GTK_ENTRY (GTK_BIN (Compoundcombo)->child), "");
	gtk_entry_set_text (GTK_ENTRY (GTK_BIN (BlockNamecombo)->child), "");
	gtk_entry_set_text (GTK_ENTRY (GTK_BIN (BlockTypecombo)->child), "");
	gtk_entry_set_text (GTK_ENTRY (GTK_BIN (Generalcombo)->child), "");
}


void
on_Find_clicked		(GtkButton *button, gpointer user_data)
{
 	gboolean CBFound1 = FALSE;
 	gboolean Block_Found = FALSE;
	char CBList[60];
	gchar * CPName;
	gchar * CPNameFPath;
	gchar ** CBName_Temp1;
	gchar ** CBName_Temp2;
	gchar ** BType_Temp1;
	gchar * SearchList[4];
	gchar * SearchListPrev[3] = {"XXX", "XXX", "XXX"};
	const gchar * CPName2;
	const gchar * Compound2;
	const gchar * Block2;
	const gchar * BlockType2;
	const gchar * General2;
	gchar * CPName1;
	gchar * Compound1;
	gchar * Block1;
	gchar * BlockType1;
	gchar * General1;
	gchar * sCPCount;
	gchar * sCompoundCount;
	gchar * sBlockCount;
	gchar * sTotalCount;
	gint l;
	TotalCount = 0;
	CPCount = 0;
	CompoundCount = 0;
	BlockCount = 0;
        //GList   *rows;
        //GtkTreeModel    *model;                 /*Model with data*/
        //GtkTreeSelection *sel = gtk_tree_view_get_selection( GTK_TREE_VIEW(Searchtreeview) );
        GtkTreeIter     iter;
        //GtkTreePath     *path;

        //if ( ! gtk_tree_selection_count_selected_rows( sel ) )
        //    return;
        //gtk_tree_selection_select_all ()
	model = gtk_tree_view_get_model(GTK_TREE_VIEW(Searchtreeview)); 
	//Following lines added to speed up treeview column add
	//Ref: http://scentric.net/tutorial/sec-treemodel-add-rows.html#sec-treestore-adding-many-rows
	g_object_ref(model);
	gtk_tree_view_set_model(GTK_TREE_VIEW(Searchtreeview), NULL);
        //rows = gtk_tree_selection_get_selected_rows( sel, &model );
        //path = (GtkTreePath *)rows->data;
        //path = gtk_tree_path_new_from_string("0:0:0");
	//gtk_tree_selection_select_path (sel, path);
	//gtk_tree_model_get_iter( model, &iter, path );
	//gtk_tree_model_get_iter_first(GTK_TREE_MODEL(liststore), &iter);
	gtk_list_store_clear (GTK_LIST_STORE( model ));
	//gtk_tree_model_get_iter_first(model, &iter);

	CPName2 = gtk_entry_get_text (GTK_ENTRY (GTK_BIN (CPNamecombo)->child));
	Compound2 = gtk_entry_get_text (GTK_ENTRY (GTK_BIN (Compoundcombo)->child));
	Block2 = gtk_entry_get_text (GTK_ENTRY (GTK_BIN (BlockNamecombo)->child));
	BlockType2 = gtk_entry_get_text (GTK_ENTRY (GTK_BIN (BlockTypecombo)->child));
	General2 = gtk_entry_get_text (GTK_ENTRY (GTK_BIN (Generalcombo)->child));
 	CPName1 = g_ascii_strup(CPName2, -1); 
	Compound1 = g_ascii_strup(Compound2, -1); 
	Block1 = g_ascii_strup(Block2, -1);
	BlockType1 = g_ascii_strup(BlockType2, -1);
	General1 = g_ascii_strup(General2, -1);
	//g_print("Find Text: %s\t%s\t%s\t%s\t%s\n", CPName1, Compound1, Block1, BlockType1, General1);
	
	for (l=0; l < CPCountTotal; l++) {
	    if (strstr(CPNameList[l], CPName1)) {
	     CPName = CPNameList[l];
	     CPNameFPath = g_strjoin(NULL, CPNameDir, CPNameList[l], NULL);
	     fd = fopen(CPNameFPath, "r");
	     while (!feof(fd)) {
	      fgets(CBList, 60, fd);
	      if (strcmp(CBList, "") == 0) {
		break;
	      }
	      if ((strstr(CBList, Block1))&&(strstr(CBList, Compound1))&&(strstr(CBList, "NAME   = "))) {
	       CBName_Temp1 = g_strsplit(CBList, "=", 2);
	       CBName_Temp2 = g_strsplit(CBName_Temp1[1], ":", 2);
	       if (CBName_Temp2[0] != NULL) {
	          g_strstrip(CBName_Temp2[0]);
	       }
	       if (CBName_Temp2[1] != NULL) {
	          g_strstrip(CBName_Temp2[1]);
	       }
	       SearchList[0] = CPName;
	       SearchList[1] = CBName_Temp2[0];
	       SearchList[2] = CBName_Temp2[1];
	       CBFound1 = TRUE;
	      }
	      else if (CBFound1 == TRUE) {
	       CBFound1 = FALSE;
	       BType_Temp1 = g_strsplit(CBList, "=", 2);
	       if (BType_Temp1[1] != NULL) {
	          g_strstrip(BType_Temp1[1]);
	       }
	       SearchList[3] = BType_Temp1[1];
	       if ((SearchList[2] == NULL)&&(strcmp(Block1, "") == 0)) {
	        Block_Found = TRUE;
	       }
	       else if ((SearchList[2] == NULL)&&(strcmp(Block1, "") != 0)) {
	        Block_Found = FALSE;
	       }
	       else if ((SearchList[2] != NULL)&&(strstr(SearchList[2], Block1))) {
	        Block_Found = TRUE;
	       }
	       else if ((SearchList[2] != NULL)&&(!strstr(SearchList[2], Block1))) {
	        Block_Found = FALSE;
	       }
	       if ((strstr(SearchList[3], BlockType1))&&(Block_Found)&&(strstr(SearchList[1], Compound1))) {
	         TotalCount++;
		 if (g_ascii_strcasecmp(SearchList[0], SearchListPrev[0]) != 0) {
			CPCount++;
			SearchListPrev[0] = g_strdup(SearchList[0]);
		 } 
		 if (g_ascii_strcasecmp(SearchList[1], SearchListPrev[1]) != 0) {
			CompoundCount++;
			SearchListPrev[1] = g_strdup(SearchList[1]);
		 }
		 if (SearchList[2] != NULL) {
			BlockCount++;
		 }
                 gtk_list_store_append( GTK_LIST_STORE( model ), &iter );
                 gtk_list_store_set( GTK_LIST_STORE(model) , &iter,
                            CPNameCol, SearchList[0],
                            CompoundCol, SearchList[1],
                            BlockCol, SearchList[2],
                            BlockTypeCol, SearchList[3],
                            -1);
	       }
	       /*g_strfreev (BType_Temp1);
	       g_strfreev (CBName_Temp1);
	       g_strfreev (CBName_Temp2);*/
	      }
	    }
	    fclose(fd);
	   }
	 }
	 closedir(dirp);
	 //Following lines added to speed up treeview column add
	 //Ref: http://scentric.net/tutorial/sec-treemodel-add-rows.html#sec-treestore-adding-many-rows
	 gtk_tree_view_set_model(GTK_TREE_VIEW(Searchtreeview), model); /* Re-attach model to view */
	 g_object_unref(model);

	 
	 sCPCount = g_strdup_printf("%d", CPCount);
	 sCompoundCount = g_strdup_printf("%d", CompoundCount);
	 sBlockCount = g_strdup_printf("%d", BlockCount);
	 sTotalCount = g_strdup_printf("%d", TotalCount);
         gtk_entry_set_text(GTK_ENTRY(CPCountentry), sCPCount);
         gtk_entry_set_text(GTK_ENTRY(CompoundCountentry), sCompoundCount);
         gtk_entry_set_text(GTK_ENTRY(BlockCountentry), sBlockCount);
         gtk_entry_set_text(GTK_ENTRY(TotalCountentry), sTotalCount);
	 /*g_free(sCPCount);	 
	 g_free(sCompoundCount);	 
	 g_free(sBlockCount);	 
	 g_free(sTotalCount);*/

	 /*if (strcmp(Compound2, "") != 0) {
		gtk_combo_box_append_text( GTK_COMBO_BOX(Compoundcombo), Compound2);
 	 }
	 if (strcmp(Block2, "") != 0) {
		gtk_combo_box_append_text( GTK_COMBO_BOX(BlockNamecombo), Block2);
	 }
	 if (strcmp(General2, "") != 0) {
		gtk_combo_box_append_text( GTK_COMBO_BOX(Generalcombo), General2);
	 }*/
}

void 
on_window_destroy 	(GtkObject *object, gpointer user_data)
{
        gtk_main_quit();
}

void
on_exit_activate	(GtkMenuItem *menuitem, gpointer user_data)
{
  gtk_exit(1);
}

void
on_Exit_clicked		(GtkButton *button, gpointer user_data)
{
  gtk_exit(1);
}

/* qsort C-string comparison function */ 
int cstring_cmp(const void *a, const void *b) 
{ 
    return strcmp(*(char **)a, *(char **)b);
	/* strcmp functions works exactly as expected from
 * 	comparison function */ 
} 

int
main (int argc, char *argv[])
{
        GtkWidget               *sems;
        GtkWidget               *window1;
	char BlockNames_temp[12];
	int i=0, j=0;
	FILE * fBlock_Types;
        
        gtk_init (&argc, &argv);
        
        builder = gtk_builder_new ();
        gtk_builder_add_from_file (builder, "sems.xml", NULL);
        sems = GTK_WIDGET (gtk_builder_get_object (builder, "sems"));
        window1 = GTK_WIDGET (gtk_builder_get_object (builder, "window1"));
 	vbox4 = GTK_WIDGET (gtk_builder_get_object (builder, "vbox4"));
 	vbox5 = GTK_WIDGET (gtk_builder_get_object (builder, "vbox5"));
 	vbox6 = GTK_WIDGET (gtk_builder_get_object (builder, "vbox6"));
 	vbox7 = GTK_WIDGET (gtk_builder_get_object (builder, "vbox7"));
 	vbox8 = GTK_WIDGET (gtk_builder_get_object (builder, "vbox8"));
 	Searchtreeview = GTK_WIDGET (gtk_builder_get_object (builder, "searchtreeview"));
 	CPCountentry = GTK_WIDGET (gtk_builder_get_object (builder, "CPCount"));
 	CompoundCountentry = GTK_WIDGET (gtk_builder_get_object (builder, "CompoundCount"));
 	BlockCountentry = GTK_WIDGET (gtk_builder_get_object (builder, "BlockCount"));
 	TotalCountentry = GTK_WIDGET (gtk_builder_get_object (builder, "TotalCount"));
 	FSaveDialog = GTK_WIDGET (gtk_builder_get_object (builder, "fsavedialog"));
 	MsgDialogPrint = GTK_WIDGET (gtk_builder_get_object (builder, "msgdialog_print"));
 	Config = GTK_WIDGET (gtk_builder_get_object (builder, "configrep"));
        gtk_builder_connect_signals (builder, NULL);          
        g_object_unref (G_OBJECT (builder));
	CPNamecombo = gtk_combo_box_entry_new_text();
	Compoundcombo = gtk_combo_box_entry_new_text();
	BlockNamecombo = gtk_combo_box_entry_new_text();
	BlockTypecombo = gtk_combo_box_entry_new_text();
	Generalcombo = gtk_combo_box_entry_new_text();
    	gtk_container_add( GTK_CONTAINER( vbox4 ), CPNamecombo ); 
    	gtk_container_add( GTK_CONTAINER( vbox5 ), Compoundcombo ); 
    	gtk_container_add( GTK_CONTAINER( vbox6 ), BlockNamecombo ); 
    	gtk_container_add( GTK_CONTAINER( vbox7 ), BlockTypecombo ); 
    	gtk_container_add( GTK_CONTAINER( vbox8 ), Generalcombo ); 
  	dirp = opendir(CPNameDir);
  	while ((direntp = readdir(dirp)) != NULL) {
    	   if ((g_strcasecmp((direntp->d_name), ".")) && (g_strcasecmp((direntp->d_name), ".."))) {
        	CPNameList[i] = g_strdup_printf("%s", direntp->d_name);
		i++;
    	   } 	
  	}
  	closedir(dirp);
	
	qsort(CPNameList, i, sizeof(char *), cstring_cmp);
	
	for (j=0; j<i; j++) {
		gtk_combo_box_append_text( GTK_COMBO_BOX(CPNamecombo), CPNameList[j]);
	}
	CPCountTotal = i;
        i=0;

	fBlock_Types = fopen(Block_Type_File, "r");
	while (!feof(fBlock_Types)) {
      		fgets(BlockNames_temp, 12, fBlock_Types);
		BlockNames_temp[strlen(BlockNames_temp)-1] = '\0';
		gtk_combo_box_append_text( GTK_COMBO_BOX(BlockTypecombo), BlockNames_temp);
	}
	fclose(fBlock_Types);
        
        gtk_widget_show_all (sems);       
        gtk_main ();
        
        return 0;
}
_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux