[Glade-users] Urgent Help Needed! - GLADE-Database-Connection
- From: kshivdeep rediffmail com (Shivdeep Krishnan)
- Subject: [Glade-users] Urgent Help Needed! - GLADE-Database-Connection
- Date: 5 May 2001 06:13:20 -0000
Dear Friends,
I am very happy to be a part of this wonderful group. I have currently shifted to the Linux operating system.
I am currently doing a database application project using GLADE with MySQL as the database. I use the C code
generation. To start with I created a CList and a Button. I want to populate the CList with data from the
table on clicking the Button. I am unable to do it. What code should I write and in which file should I
write?. I am confused with all the files interface.c,support.c,main.c and callbacks.c. I am giving the
enitire code of the C files also below. Please help me. I would also like to know to connect StarOffice BAse
to C. You can also send answers to my mail ID. kshivdeep rediffmail com.
--------------------------------------------------------
main.c:
=======
/*
* Initial main.c file generated by Glade. Edit as required.
* Glade will not overwrite this file.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <gnome.h>
#include "interface.h"
#include "support.h"
int
main (int argc, char *argv[])
{
GtkWidget *window1;
#ifdef ENABLE_NLS
bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
textdomain (PACKAGE);
#endif
gnome_init ("cdb", VERSION, argc, argv);
/*
* The following code was added by Glade to create one of each component
* (except popup menus), just so that you see something after building
* the project. Delete any components that you don't want shown initially.
*/
window1 = create_window1 ();
gtk_widget_show (window1);
gtk_main ();
return 0;
}
---------------------------------------------------------
interface.c:
============
/*
* DO NOT EDIT THIS FILE - it is generated by Glade.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <gnome.h>
#include "callbacks.h"
#include "interface.h"
#include "support.h"
GtkWidget*
create_window1 (void)
{
GtkWidget *window1;
GtkWidget *fixed1;
GtkWidget *button1;
GtkWidget *clist1;
GtkWidget *label2;
window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_object_set_data (GTK_OBJECT (window1), "window1", window1);
gtk_window_set_title (GTK_WINDOW (window1), _("C Database Demo"));
fixed1 = gtk_fixed_new ();
gtk_widget_ref (fixed1);
gtk_object_set_data_full (GTK_OBJECT (window1), "fixed1", fixed1,
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show (fixed1);
gtk_container_add (GTK_CONTAINER (window1), fixed1);
button1 = gtk_button_new_with_label (_("Generate"));
gtk_widget_ref (button1);
gtk_object_set_data_full (GTK_OBJECT (window1), "button1", button1,
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show (button1);
gtk_fixed_put (GTK_FIXED (fixed1), button1, 8, 184);
gtk_widget_set_uposition (button1, 8, 184);
gtk_widget_set_usize (button1, 144, 32);
clist1 = gtk_clist_new (1);
gtk_widget_ref (clist1);
gtk_object_set_data_full (GTK_OBJECT (window1), "clist1", clist1,
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show (clist1);
gtk_fixed_put (GTK_FIXED (fixed1), clist1, 8, 16);
gtk_widget_set_uposition (clist1, 8, 16);
gtk_widget_set_usize (clist1, 144, 160);
gtk_clist_set_column_width (GTK_CLIST (clist1), 0, 80);
gtk_clist_column_titles_show (GTK_CLIST (clist1));
label2 = gtk_label_new (_("Name"));
gtk_widget_ref (label2);
gtk_object_set_data_full (GTK_OBJECT (window1), "label2", label2,
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show (label2);
gtk_clist_set_column_widget (GTK_CLIST (clist1), 0, label2);
gtk_signal_connect (GTK_OBJECT (button1), "clicked",
GTK_SIGNAL_FUNC (on_button1_clicked),
NULL);
return window1;
}
---------------------------------------------------------
callbacks.c:
============
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <gnome.h>
#include "callbacks.h"
#include "interface.h"
#include "support.h"
#include <mysql.h>
MYSQL mysql;
MYSQL_RES *res;
MYSQL_ROW row;
void exiterr(int exitcode)
{
fprintf( stderr, "%s\n", mysql_error(&mysql) );
exit( exitcode );
}
void
on_button1_clicked (GtkButton *button,
gpointer user_data)
{
uint i = 0;
if (!(mysql_connect(&mysql,"","","")))
exiterr(1);
if (mysql_select_db(&mysql,"siddi"))
exiterr(2);
if (mysql_query(&mysql,"SELECT name FROM emp"))
exiterr(3);
if (!(res = mysql_store_result(&mysql)))
exiterr(4);
while((row = mysql_fetch_row(res)))
{
for (i=0 ; i < mysql_num_fields(res); i++)
printf("%s\n",row[i]);
}
if (!mysql_eof(res))
exiterr(5);
mysql_free_result(res);
mysql_close(&mysql);
}
--------------------------------------------------------
/*
* DO NOT EDIT THIS FILE - it is generated by Glade.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <gnome.h>
#include "support.h"
/* This is an internally used function to create pixmaps. */
static GtkWidget* create_dummy_pixmap (GtkWidget *widget,
gboolean gnome_pixmap);
GtkWidget*
lookup_widget (GtkWidget *widget,
const gchar *widget_name)
{
GtkWidget *parent, *found_widget;
for (;;)
{
if (GTK_IS_MENU (widget))
parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
else
parent = widget->parent;
if (parent == NULL)
break;
widget = parent;
}
found_widget = (GtkWidget*) gtk_object_get_data (GTK_OBJECT (widget),
widget_name);
if (!found_widget)
g_warning ("Widget not found: %s", widget_name);
return found_widget;
}
/* This is a dummy pixmap we use when a pixmap can't be found. */
static char *dummy_pixmap_xpm[] = {
/* columns rows colors chars-per-pixel */
"1 1 1 1",
" c None",
/* pixels */
" ",
" "
};
/* This is an internally used function to create pixmaps. */
static GtkWidget*
create_dummy_pixmap (GtkWidget *widget,
gboolean gnome_pixmap)
{
GdkColormap *colormap;
GdkPixmap *gdkpixmap;
GdkBitmap *mask;
GtkWidget *pixmap;
if (gnome_pixmap)
{
return gnome_pixmap_new_from_xpm_d (dummy_pixmap_xpm);
}
colormap = gtk_widget_get_colormap (widget);
gdkpixmap = gdk_pixmap_colormap_create_from_xpm_d (NULL, colormap, &mask,
NULL, dummy_pixmap_xpm);
if (gdkpixmap == NULL)
g_error ("Couldn't create replacement pixmap.");
pixmap = gtk_pixmap_new (gdkpixmap, mask);
gdk_pixmap_unref (gdkpixmap);
gdk_bitmap_unref (mask);
return pixmap;
}
/* This is an internally used function to create pixmaps. */
GtkWidget*
create_pixmap (GtkWidget *widget,
const gchar *filename,
gboolean gnome_pixmap)
{
GtkWidget *pixmap;
GdkColormap *colormap;
GdkPixmap *gdkpixmap;
GdkBitmap *mask;
gchar *pathname;
if (!filename || !filename[0])
return create_dummy_pixmap (widget, gnome_pixmap);
pathname = gnome_pixmap_file (filename);
if (!pathname)
{
g_warning (_("Couldn't find pixmap file: %s"), filename);
return create_dummy_pixmap (widget, gnome_pixmap);
}
if (gnome_pixmap)
{
pixmap = gnome_pixmap_new_from_file (pathname);
g_free (pathname);
return pixmap;
}
colormap = gtk_widget_get_colormap (widget);
gdkpixmap = gdk_pixmap_colormap_create_from_xpm (NULL, colormap, &mask,
NULL, pathname);
if (gdkpixmap == NULL)
{
g_warning (_("Couldn't create pixmap from file: %s"), pathname);
g_free (pathname);
return create_dummy_pixmap (widget, gnome_pixmap);
}
g_free (pathname);
pixmap = gtk_pixmap_new (gdkpixmap, mask);
gdk_pixmap_unref (gdkpixmap);
gdk_bitmap_unref (mask);
return pixmap;
}
/* This is an internally used function to create imlib images. */
GdkImlibImage*
create_image (const gchar *filename)
{
GdkImlibImage *image;
gchar *pathname;
pathname = gnome_pixmap_file (filename);
if (!pathname)
{
g_warning (_("Couldn't find pixmap file: %s"), filename);
return NULL;
}
image = gdk_imlib_load_image (pathname);
g_free (pathname);
return image;
}
---------------------------------------------------------
cdb.glade:
===========
<?xml version="1.0"?>
<GTK-Interface>
<project>
<name>CDb</name>
<program_name>cdb</program_name>
<directory></directory>
<source_directory>src</source_directory>
<pixmaps_directory>pixmaps</pixmaps_directory>
<language>C</language>
<gnome_support>True</gnome_support>
<gettext_support>True</gettext_support>
</project>
<widget>
<class>GtkWindow</class>
<name>window1</name>
<title>C Database Demo</title>
<type>GTK_WINDOW_TOPLEVEL</type>
<position>GTK_WIN_POS_NONE</position>
<modal>False</modal>
<allow_shrink>False</allow_shrink>
<allow_grow>True</allow_grow>
<auto_shrink>False</auto_shrink>
<widget>
<class>GtkFixed</class>
<name>fixed1</name>
<widget>
<class>GtkButton</class>
<name>button1</name>
<x>8</x>
<y>184</y>
<width>144</width>
<height>32</height>
<can_focus>True</can_focus>
<signal>
<name>clicked</name>
<handler>on_button1_clicked</handler>
<last_modification_time>Fri, 04 May 2001 09:51:39 GMT</last_modification_time>
</signal>
<label>Generate</label>
</widget>
<widget>
<class>GtkCList</class>
<name>clist1</name>
<x>8</x>
<y>16</y>
<width>144</width>
<height>160</height>
<can_focus>True</can_focus>
<columns>1</columns>
<column_widths>80</column_widths>
<selection_mode>GTK_SELECTION_SINGLE</selection_mode>
<show_titles>True</show_titles>
<shadow_type>GTK_SHADOW_IN</shadow_type>
<widget>
<class>GtkLabel</class>
<child_name>CList:title</child_name>
<name>label2</name>
<label>Name</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
</widget>
</widget>
</widget>
</widget>
</GTK-Interface>
love,
Shivdeep
_____________________________________________________
Chat with your friends as soon as they come online. Get Rediff Bol at
http://bol.rediff.com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]