[gnome-db and glade]

Hi,

Sorry for troubling you, but I need some help. I can't get anywhere with my
coding. I mean, I don't want go futher with coding without knowing the
code which I have already written is correct. The attachted patch is my
work which I have done up to know. Damon can you look on my code and
telling me if I use all the glade function and datastucters right.
Obviously I do not, since I doesn't not work correcty. There's somewhere
a problem because I get lots of core dumps and I can't get any
further :(

For compiling correctly you need the cvs version of gnome-db.

wagi

-- 
Daniel Wagner
email: [EMAIL PROTECTED]

GnuPG: 1024D/DCDE890A (public key available on any keyserver)
=== cd /usr/src/gnome/glade/glade/
=== cvs diff -u property.c property.h source.c

Index: property.c
===================================================================
RCS file: /cvs/gnome/glade/glade/property.c,v
retrieving revision 1.31
diff -u -r1.31 property.c
--- property.c  2001/02/15 03:42:34     1.31
+++ property.c  2001/04/21 19:11:40
@@ -183,6 +183,19 @@
 /* Font selection fialog */
 static GtkFontSelectionDialog *fontsel = NULL;
 
+#ifdef USE_GNOME_DB
+/* Gnome DB support */
+
+typedef struct
+{
+  GtkWidget* dsn_list;
+  GtkWidget* dsn_config;
+} DsnConfigInfo;
+
+static GtkDialog *dsn_dialog = NULL;
+static GtkWidget *dsn_value  = NULL;
+#endif /* USE_GNOME_DB */
+
 /* Widgets in Accelerators dialog. */
 #define ACCEL_MODIFIERS_COL    0
 #define ACCEL_KEY_COL          1
@@ -323,6 +336,21 @@
                              gint column,
                              GdkEventButton * event,
                              gpointer user_data);
+#ifdef USE_GNOME_DB
+static void show_dsn_dialog (GtkWidget * widget,
+                            gpointer value);
+static void on_dsn_dialog_add (GtkWidget * widget,
+                              DsnConfigInfo * dsn_info);
+static void on_dsn_dialog_remove (GtkWidget * widget,
+                                 DsnConfigInfo *dsn_info);
+static void on_dsn_dialog_refresh (GtkWidget * widget,
+                                  DsnConfigInfo * dsn_info);
+static void on_dsn_dialog_test (GtkWidget * widget,
+                               DsnConfigInfo * dsn_info);
+static void on_dsn_dialog_ok (GtkWidget * widget,
+                             DsnConfigInfo * dsn_info);
+#endif /* USE_GNOME_DB */
+                            
 
 #ifdef GLADE_STYLE_SUPPORT
 static void on_style_copy (GtkWidget * widget,
@@ -1869,6 +1897,314 @@
   property_add (property_name, label, value, NULL, tooltip);
 }
 
+
+#ifdef USE_GNOME_DB
+static void
+fill_dsn_list (GtkCList *clist)
+{
+  GList* dsnlist;
+  GList* node;
+  
+  g_return_if_fail (GTK_IS_CLIST (clist));
+  
+  gnome_db_clear_clist (clist);
+  dsnlist = node = gda_dsn_list ();
+  while (node)
+    {
+      gchar*   row[2];
+      GdaDsn* dsn;
+      
+      dsn = (GdaDsn *) node->data;
+      row[0] = "";
+      row[1] = GDA_DSN_GDA_NAME (dsn);
+      gtk_clist_append (clist, row);
+      
+      node = g_list_next (node);
+    }
+  gda_dsn_free_list (dsnlist);
+}
+
+
+void
+property_add_connection (const gchar * property_name,
+                        const gchar * label,
+                        const gchar * tooltip)
+{
+  GtkWidget *dialog_button;
+  GList *list = NULL;
+  
+  dsn_value = gtk_combo_new ();
+
+  list = gda_list_datasources ();
+  list = g_list_prepend (list, g_strdup (_("")));
+  gtk_combo_set_popdown_strings (GTK_COMBO (dsn_value), list);
+  g_list_foreach (list,(GFunc)g_free, 0);
+  g_list_free (list);
+
+  gtk_widget_set_usize (GTK_COMBO (dsn_value)->entry, 60, -1);
+  gtk_widget_set_usize (dsn_value, 80, -1);
+
+  gtk_signal_connect (GTK_OBJECT (GTK_COMBO (dsn_value)->entry), "changed",
+                     GTK_SIGNAL_FUNC (on_property_changed), dsn_value);
+  
+  dialog_button = gtk_button_new_with_label ("...");
+  gtk_signal_connect (GTK_OBJECT (dialog_button), "clicked",
+                     GTK_SIGNAL_FUNC (show_dsn_dialog), dsn_value);
+
+  property_add (property_name, label, dsn_value, dialog_button, tooltip);
+}
+
+
+gchar* 
+property_get_connection  (const gchar * property_name,
+                         GtkWidget   * to_apply,
+                         gboolean    * apply)
+{
+  GtkWidget *widget = (GtkWidget *) g_hash_table_lookup (gb_property_values,
+                                                        property_name);
+  if (apply)
+    *apply = (!to_apply || to_apply == widget) ? TRUE : FALSE;
+  g_return_val_if_fail (widget != NULL, "");
+  return gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (widget)->entry));
+}
+
+
+void        
+property_set_connection  (const gchar * property_name,
+                         gchar       * value)
+{
+  GtkWidget *widget = (GtkWidget *) g_hash_table_lookup (gb_property_values,
+                                                        property_name);
+  g_return_if_fail (widget != NULL);
+  gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (widget)->entry), value ? value : "");
+}
+
+
+static void
+select_dsn_dialog_cb (GtkCList * clist,
+                     gint row,
+                     gint column,
+                     GdkEventButton * event,
+                     DsnConfigInfo * dsn_info)
+{
+  gchar* txt = NULL;
+  
+  g_return_if_fail (GTK_IS_CLIST (clist));
+  g_return_if_fail (dsn_info != NULL);
+  
+  if (gtk_clist_get_text (clist, row, 1, &txt))
+    {
+      gnome_db_dsn_config_set_name (GNOME_DB_DSN_CONFIG (dsn_info->dsn_config), txt);
+    }
+}
+
+
+static void 
+show_dsn_dialog (GtkWidget * widget,
+                gpointer value)
+{
+  GtkWidget *add_button, *remove_button, *refresh_button, *test_button, *ok_button;
+  GtkWidget *frame;
+  GtkWidget *table;
+  GtkWidget *scroll;
+  DsnConfigInfo *dsn_info;
+
+  if (!dsn_dialog)
+    {
+      /* create dialog window */
+      dsn_dialog = gnome_dialog_new ((_("Data Sources"),
+                                     GNOME_STOCK_BUTTON_CLOSE,
+                                     NULL));
+      gtk_widget_set_usize (dsn_dialog, 500, 300);
+      gnome_dialog_set_close (GNOME_DIALOG (dsn_dialog), TRUE);
+      gnome_dialog_close_hides (GNOME_DIALOG (dsn_dialog), TRUE);
+
+
+      /* create data structure */
+      dsn_info = g_new0 (DsnConfigInfo, 1);
+
+      frame = gnome_db_new_frame_widget (NULL);
+      gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dsn_dialog)->vbox), frame, 1, 1, 0);
+      table = gnome_db_new_table_widget (4, 2, FALSE);
+      gtk_container_add (GTK_CONTAINER (frame), table);
+  
+      scroll = gnome_db_new_scrolled_window_widget ();
+      dsn_info->dsn_list = gnome_db_new_clist_widget (NULL, 2);
+      gtk_signal_connect (GTK_OBJECT (dsn_info->dsn_list),
+                         "select-row",
+                         GTK_SIGNAL_FUNC (select_dsn_dialog_cb),
+                         (gpointer) dsn_info);
+      fill_dsn_list (GTK_CLIST (dsn_info->dsn_list));
+      gtk_container_add (GTK_CONTAINER (scroll), dsn_info->dsn_list);
+      gtk_table_attach (GTK_TABLE (table), scroll, 0, 1, 0, 2,
+                      GTK_FILL | GTK_SHRINK | GTK_EXPAND,
+                      GTK_FILL | GTK_SHRINK | GTK_EXPAND,
+                      3, 3);
+
+      dsn_info->dsn_config = gnome_db_dsn_config_new (NULL);
+      gtk_widget_show (dsn_info->dsn_config);
+      gtk_table_attach (GTK_TABLE (table), dsn_info->dsn_config, 1, 4, 1, 2,
+                       GTK_FILL | GTK_SHRINK | GTK_EXPAND,
+                       GTK_FILL | GTK_SHRINK | GTK_EXPAND,
+                       3, 3);
+
+      /* add all button to the dialog and connect them */
+      add_button = gtk_button_new_with_label (_("Add"));
+      remove_button = gtk_button_new_with_label (_("Remove"));
+      refresh_button = gtk_button_new_with_label (_("Refresh"));
+      test_button = gtk_button_new_with_label (_("Test"));
+      ok_button = gtk_button_new_with_label (_("Ok"));
+      gtk_signal_connect (GTK_OBJECT (add_button), "clicked",
+                         GTK_SIGNAL_FUNC (on_dsn_dialog_add), dsn_info);
+      gtk_signal_connect (GTK_OBJECT (remove_button), "clicked",
+                         GTK_SIGNAL_FUNC (on_dsn_dialog_remove), dsn_info);
+      gtk_signal_connect (GTK_OBJECT (refresh_button), "clicked",
+                         GTK_SIGNAL_FUNC (on_dsn_dialog_refresh), dsn_info);
+      gtk_signal_connect (GTK_OBJECT (test_button), "clicked",
+                         GTK_SIGNAL_FUNC (on_dsn_dialog_test), dsn_info);
+      gtk_signal_connect (GTK_OBJECT (ok_button), "clicked",
+                         GTK_SIGNAL_FUNC (on_dsn_dialog_ok), dsn_info);
+      gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dsn_dialog)->action_area),
+                        add_button);
+      gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dsn_dialog)->action_area),
+                        remove_button);
+      gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dsn_dialog)->action_area),
+                        refresh_button);
+      gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dsn_dialog)->action_area),
+                        test_button);
+      gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dsn_dialog)->action_area),
+                        ok_button);
+
+      gtk_window_set_wmclass (GTK_WINDOW (dsn_dialog), "dsn_creator", "Glade");
+    }
+  
+  gtk_widget_show_all (GTK_WIDGET (dsn_dialog));
+  gdk_window_show (GTK_WIDGET (dsn_dialog)->window);
+  gdk_window_raise (GTK_WIDGET (dsn_dialog)->window);
+}
+
+
+static void 
+on_dsn_dialog_add (GtkWidget * widget, DsnConfigInfo *dsn_info)
+{
+  g_return_if_fail (dsn_info != NULL);
+  g_return_if_fail (GNOME_DB_IS_DSN_CONFIG (dsn_info->dsn_config));
+  
+  gnome_db_dsn_config_save (GNOME_DB_DSN_CONFIG (dsn_info->dsn_config));
+  fill_dsn_list (GTK_CLIST (dsn_info->dsn_list));
+}
+
+
+static void 
+on_dsn_dialog_remove (GtkWidget * widget, DsnConfigInfo *dsn_info)
+{
+  g_return_if_fail (GNOME_DB_IS_DSN_CONFIG (dsn_info->dsn_config));
+        
+  gnome_db_dsn_config_remove (GNOME_DB_DSN_CONFIG (dsn_info->dsn_config));
+  fill_dsn_list (GTK_CLIST (dsn_info->dsn_list));
+}
+
+
+static void 
+on_dsn_dialog_refresh (GtkWidget * widget, DsnConfigInfo *dsn_info)
+{
+  g_return_if_fail(dsn_info != NULL);
+        
+  gnome_db_dsn_config_clear (GNOME_DB_DSN_CONFIG (dsn_info->dsn_config));
+  fill_dsn_list (GTK_CLIST (dsn_info->dsn_list));
+}
+
+
+static void 
+on_dsn_dialog_test (GtkWidget * widget, DsnConfigInfo *dsn_info)
+{
+  gchar* gda_name;
+  gchar* username;
+  
+  g_return_if_fail (dsn_info != NULL);
+  g_return_if_fail (GNOME_DB_IS_DSN_CONFIG(dsn_info->dsn_config));
+  
+  gda_name = gnome_db_dsn_config_get_name (GNOME_DB_DSN_CONFIG 
+(dsn_info->dsn_config));
+  if (gda_name) {
+    GdaDsn* dsn = gda_dsn_find_by_name(gda_name);
+    if (dsn) {
+      GtkWidget* dialog;
+      GtkWidget* frame;
+      GtkWidget* table;
+      GtkWidget* label;
+      GtkWidget* gda_entry;
+      GtkWidget* user_entry;
+      GtkWidget* password_entry;
+      
+      /* create login dialog */
+      dialog = gnome_dialog_new(gda_name,
+                               GNOME_STOCK_BUTTON_OK,
+                               GNOME_STOCK_BUTTON_CANCEL,
+                               NULL);
+      frame = gnome_db_new_frame_widget (NULL);
+      gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), frame, 1, 1, 0);
+      table = gnome_db_new_table_widget (2, 3, FALSE);
+      gtk_container_add (GTK_CONTAINER (frame), table);
+      
+      label = gnome_db_new_label_widget (_("GDA Name"));
+      gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 3, 
+3);
+      gda_entry = gnome_db_new_entry_widget (0, FALSE);
+      gtk_entry_set_text(GTK_ENTRY (gda_entry), gda_name);
+      gtk_table_attach (GTK_TABLE (table), gda_entry, 1, 2, 0, 1, GTK_FILL, GTK_FILL, 
+3, 3);
+      
+      label = gnome_db_new_label_widget (_("Username"));
+      gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2, GTK_FILL, GTK_FILL, 3, 
+3);
+      user_entry = gnome_db_new_entry_widget (0, TRUE);
+      gtk_entry_set_text (GTK_ENTRY (user_entry), GDA_DSN_USERNAME (dsn));
+      gtk_table_attach (GTK_TABLE (table), user_entry, 1, 2, 1, 2, GTK_FILL, 
+GTK_FILL, 3, 3);
+      
+      label = gnome_db_new_label_widget (_("Password"));
+      gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3, GTK_FILL, GTK_FILL, 3, 
+3);
+      password_entry = gnome_db_new_entry_widget (0, TRUE);
+      gtk_entry_set_visibility (GTK_ENTRY (password_entry), FALSE);
+      gtk_table_attach (GTK_TABLE (table), password_entry, 1, 2, 2, 3, GTK_FILL, 
+GTK_FILL, 3, 3);
+      
+      /* run the dialog */
+      if (!gnome_dialog_run (GNOME_DIALOG (dialog))) {
+       GdaConnection* cnc = gda_connection_new (gda_corba_get_orb ());
+       
+       gda_connection_set_provider (cnc, GDA_DSN_PROVIDER (dsn));
+       if (gda_connection_open(cnc,
+                               GDA_DSN_DSN (dsn),
+                               gtk_entry_get_text (GTK_ENTRY (user_entry)),
+                               gtk_entry_get_text (GTK_ENTRY (password_entry))) < 0) {
+         if (cnc->errors_head) {
+           gnome_db_show_error (gda_error_description ((GdaError *) 
+cnc->errors_head->data));
+         }
+         else gnome_db_show_error (_("Test failed"));
+       }
+       else gnome_db_show_message (_("Connection successful"));
+       
+       gda_connection_close (cnc);
+       gda_connection_free (cnc);
+      }
+      
+      gnome_dialog_close (GNOME_DIALOG (dialog));
+      gda_dsn_free (dsn);
+    }
+    else gnome_db_show_error (_("Datasource %s not found in configuration"), 
+gda_name);              
+  }
+}
+
+static void 
+on_dsn_dialog_ok (GtkWidget * widget, DsnConfigInfo *dsn_info)
+{
+  GList *list = NULL;
+
+  close_dialog (widget, GTK_WIDGET (dsn_dialog));
+
+  list = gda_list_datasources ();
+  list = g_list_prepend (list, g_strdup (_("")));
+  gtk_combo_set_popdown_strings (GTK_COMBO (dsn_value), list);
+  g_list_foreach (list,(GFunc)g_free, 0);
+  g_list_free (list);
+}
+#endif /* USE_GNOME_DB */
 
 void
 property_add_color (const gchar * property_name,
Index: property.h
===================================================================
RCS file: /cvs/gnome/glade/glade/property.h,v
retrieving revision 1.14
diff -u -r1.14 property.h
--- property.h  2000/09/17 22:49:18     1.14
+++ property.h  2001/04/21 19:11:41
@@ -20,6 +20,10 @@
 
 #include <gtk/gtkfeatures.h>
 
+#ifdef USE_GNOME_DB
+#include <gnome-db.h>
+#endif /* USE_GNOME_DB */
+
 #include "gbwidget.h"
 #include "glade_project.h"
 
@@ -234,6 +238,16 @@
                                         gboolean           *apply);
 void       property_set_combo          (const gchar        *property_name,
                                         const gchar        *value);
+#ifdef USE_GNOME_DB
+void        property_add_connection     (const gchar        *property_name,
+                                        const gchar        *label,
+                                        const gchar        *tooltip);
+gchar*      property_get_connection     (const gchar        *property_name,
+                                        GtkWidget          *to_apply,
+                                        gboolean           *apply);
+void        property_set_connection     (const gchar        *property_name,
+                                        gchar              *value);
+#endif /* USE_GNOME_DB */
 void       property_set_combo_strings  (const gchar        *property_name,
                                         GList              *choices);
 
Index: source.c
===================================================================
RCS file: /cvs/gnome/glade/glade/source.c,v
retrieving revision 1.31
diff -u -r1.31 source.c
--- source.c    2000/09/23 14:32:23     1.31
+++ source.c    2001/04/21 19:11:53
@@ -651,7 +651,8 @@
 
       if (glade_project_get_gnome_db_support (data->project))
        {
-         fprintf (fp, "#include <gda-ui.h>\n");
+/*       fprintf (fp, "#include <gda-client.h>"); */
+         fprintf (fp, "#include <gnome-db.h>\n");
        }
     }
   else
@@ -669,6 +670,10 @@
           g_basename (data->callback_h_filename),
           g_basename (data->interface_h_filename),
           glade_project_get_support_header_file (data->project));
+
+  fprintf (fp,
+          "extern GdaConnectionPool *cnc_pool;\n\n");
+
 }
 
 
@@ -800,13 +805,21 @@
 
   if (glade_project_get_gnome_support (data->project))
     {
-      fprintf (fp, "#include <gnome.h>\n\n");
+      fprintf (fp, "#include <gnome.h>\n");
+      if (glade_project_get_gnome_db_support (data->project))
+       {
+         fprintf (fp,
+                  "#include <gnome-db.h>\n");
+       }
+      fprintf (fp, "\n");
     }
   else
     {
       fprintf (fp, "#include <gtk/gtk.h>\n\n");
     }
 
+
+
   /* Include the interface.h header to get declarations of the functions to
      create the components, and support.h so we include libintl.h if needed. */
   fprintf (fp,
@@ -815,6 +828,15 @@
           g_basename (data->interface_h_filename),
           glade_project_get_support_header_file (data->project));
 
+  /* The GdaConnectionPool is defined global, it is possible to access to 
+     pool from everywhere. */
+  if (glade_project_get_gnome_db_support (data->project))
+    {
+      fprintf (fp,
+              "GdaConnectionPool *cnc_pool;\n"
+              "\n");
+    }
+
   fprintf (fp,
           "int\n"
           "main (int argc, char *argv[])\n"
@@ -845,6 +867,13 @@
     {
       fprintf (fp, "  gnome_init (%s, VERSION, argc, argv);\n",
               source_make_string (data->program_name, FALSE));
+      if (glade_project_get_gnome_db_support (data->project))
+       {
+         fprintf (fp,
+                  "  oaf_init (argc, argv);\n"
+                  "  cnc_pool = gda_connection_pool_new ();\n"
+                  "\n");
+       }
     }
   else 
     {
@@ -1425,14 +1454,15 @@
   /* GnomeDB support. */
   if (glade_project_get_gnome_db_support (data->project))
     {
+
       fprintf (fp,
               "dnl Gnome DB support.\n"
-              "AC_PATH_PROG(gda_config, gda-config)\n"
-              "if test \"_$gda_config\" != _; then\n"
-              "  CPPFLAGS=\"`$gda_config --cflags 2>/dev/null` $CPPFLAGS\"\n"
-              "  LIBS=\"`$gda_config --libs gdaui 2>/dev/null` $LIBS\"\n"
+              "AC_PATH_PROG(gnomedb_config, gnomedb-config)\n"
+              "if test \"_$gnomedb_config\" != _; then\n"
+              "  CPPFLAGS=\"`$gnomedb_config --cflags 2>/dev/null` $CPPFLAGS\"\n"
+              "  LIBS=\"`$gnomedb_config --libs 2>/dev/null` $LIBS\"\n"
               "else\n"
-              "  AC_MSG_ERROR(gda-config not found. Check you have Gnome DB 
installed.)\n"
+              "  AC_MSG_ERROR(gnomedb-config not found. Check you have Gnome DB 
+installed.)\n"
               "fi\n"
               "\n");
     }
=== Exit status: 1
=== cd /usr/src/gnome/glade/glade/gnome-db/
=== cvs diff -u gnomedbbrowser.c

Index: gnomedbbrowser.c
===================================================================
RCS file: /cvs/gnome/glade/glade/gnome-db/gnomedbbrowser.c,v
retrieving revision 1.3
diff -u -r1.3 gnomedbbrowser.c
--- gnomedbbrowser.c    2001/02/23 01:06:57     1.3
+++ gnomedbbrowser.c    2001/04/21 19:12:08
@@ -24,19 +24,93 @@
 /* Include the 21x21 icon pixmap for this widget, to be used in the palette */
 #include "../graphics/gnome-db-browser.xpm"
 
+#define CONNECTION_INSTANCE_DATA "ConnectionInstanceData"
+
 /*
  * This is the GbWidget struct for this widget (see ../gbwidget.h).
  * It is initialized in the init() function at the end of this file
  */
-static GbWidget gbwidget;
+
+typedef struct {
+        GdaConnection*             cnc;
+        GtkWidget*                 login_dialog;
+        gchar*                     gda_dsn;
+} connection_instance_data_t;
 
 
+static GbWidget gbwidget;
+static gchar *GdaName  = "GnomeDbBrowser::gda_name";
+static gchar *UserName = "GnomeDbBrosser::user_name";
+static gchar *Password = "GnomeDbBrowser::password";
 
 /******
  * NOTE: To use these functions you need to uncomment them AND add a pointer
  * to the function in the GbWidget struct at the end of this file.
  ******/
+static connection_instance_data_t *
+get_current_connection_from_widget (GtkWidget *browser) {
+  if (browser)
+    {
+      return gtk_object_get_data (GTK_OBJECT (browser), CONNECTION_INSTANCE_DATA);
+    }
+  return NULL;
+}
+
+
+static void
+cancel_connecting_cb (GnomeDbLoginDlg *dlg, connection_instance_data_t 
+*instance_data) {
+  g_return_if_fail(instance_data != NULL);
+        
+  gnome_dialog_close (GNOME_DIALOG (instance_data->login_dialog));
+  gda_connection_free (instance_data->cnc);
+  g_free ((gpointer) instance_data);
+}
+
+
+static void
+error_in_connection_cb (GdaConnection *cnc, connection_instance_data_t 
+*instance_data) {
+  GtkWidget* error_dialog;
+        
+  error_dialog = gnome_db_errordlg_new (cnc, _("Error Viewer"));
+  gnome_db_errordlg_show_errors (GNOME_DB_ERRORDLG (error_dialog));
+}
+
+
+static void
+connection_initiated_cb (GtkWidget *w, connection_instance_data_t *instance_data) {
+  GnomeDbLogin* login;
+  gchar*        str;
+
+  g_return_if_fail (gda_connection_is_open (instance_data->cnc));
+  g_return_if_fail (instance_data != NULL);
+
+  /* get login dialog information */
+  login = GNOME_DB_LOGIN (GNOME_DB_LOGINDLG (instance_data->login_dialog)->login);
+  if (login)
+    str = gnome_db_login_get_gda_name(login);
+  else str = NULL;
+  gnome_dialog_close (GNOME_DIALOG (instance_data->login_dialog));
+  instance_data->login_dialog = NULL;
+  instance_data->gda_dsn = g_strdup (str);
+
+  gnome_db_browser_set_connection (GNOME_DB_BROWSER (property_get_widget ()), 
+instance_data->cnc);
+
+  gtk_object_set_data (GTK_OBJECT (property_get_widget ()), CONNECTION_INSTANCE_DATA, 
+instance_data);
+}
+
+
+static void
+connection_closed_cb (GtkWidget *w, connection_instance_data_t *instance_data) {
+  g_return_if_fail(instance_data != NULL);
+        
+  gda_connection_free(instance_data->cnc);
+  gnome_db_browser_set_connection (GNOME_DB_BROWSER (property_get_widget ()), NULL);
 
+  g_free((gpointer) instance_data->gda_dsn);
+  g_free((gpointer) instance_data);
+}
+
+
 /*
  * Creates a new GtkWidget of class GnomeDbBrowser, performing any specialized
  * initialization needed for the widget to work correctly in this environment.
@@ -54,27 +128,69 @@
 /*
  * Creates the components needed to edit the extra properties of this widget.
  */
-/*
 static void
 gb_gnome_db_browser_create_properties (GtkWidget * widget, GbWidgetCreateArgData * 
data)
 {
-
+  property_add_connection (GdaName, "Data Source", "Choose Gda Connection");
 }
-*/
 
 
 
+
 /*
  * Gets the properties of the widget. This is used for both displaying the
  * properties in the property editor, and also for saving the properties.
  */
-/*
 static void
 gb_gnome_db_browser_get_properties (GtkWidget *widget, GbWidgetGetArgData * data)
 {
-
+  GdaConnection *cnc;
+  
+  cnc = gnome_db_browser_get_connection (GNOME_DB_BROWSER (widget));
+  gb_widget_output_string (data, GdaName, gda_connection_get_dsn (cnc));
+  gb_widget_output_string (data, UserName, gda_connection_get_user (cnc));
+  gb_widget_output_string (data, Password, gda_connection_get_password (cnc));
 }
-*/
+
+
+static void
+open_new_connection (GtkWidget *widget, gchar *gda_name) 
+{
+  connection_instance_data_t* instance_data;  
+  gchar *gda_dsn;
+  GtkWidget *login;
+
+  instance_data = g_new0 (connection_instance_data_t, 1);
+
+  instance_data->cnc = gda_connection_new (gda_corba_get_orb ());
+  gtk_signal_connect (GTK_OBJECT (instance_data->cnc),
+                     "error",
+                     GTK_SIGNAL_FUNC (error_in_connection_cb),
+                     (gpointer) instance_data);
+  gtk_signal_connect (GTK_OBJECT (instance_data->cnc),
+                     "open",
+                     GTK_SIGNAL_FUNC (connection_initiated_cb),
+                     (gpointer) instance_data);
+  gtk_signal_connect (GTK_OBJECT(instance_data->cnc),
+                     "close",
+                     GTK_SIGNAL_FUNC (connection_closed_cb),
+                     (gpointer) instance_data);
+  
+  /* create login dialog box */
+  gda_dsn = property_get_connection (GdaName, widget, FALSE);
+  login = gnome_db_login_new (instance_data->cnc, NULL, gda_dsn);
+  instance_data->login_dialog = gnome_db_logindlg_new (GNOME_DB_LOGIN (login), 
+                                                      _("Open Connection"));
+  gtk_signal_connect (GTK_OBJECT (instance_data->login_dialog),
+                     "cancel",
+                     GTK_SIGNAL_FUNC (cancel_connecting_cb),
+                     (gpointer) instance_data);
+  
+  /* run dialog */
+  while (gtk_events_pending()) gtk_main_iteration();
+  gnome_db_logindlg_popup(GNOME_DB_LOGINDLG(instance_data->login_dialog));
+} 
+
 
 
 
@@ -82,14 +198,64 @@
  * Sets the properties of the widget. This is used for both applying the
  * properties changed in the property editor, and also for loading.
  */
-/*
 static void
 gb_gnome_db_browser_set_properties (GtkWidget * widget, GbWidgetSetArgData * data)
 {
+  gchar *entry;
+  connection_instance_data_t* instance_data;
 
+  /* 4 cases can occur:
+     instance_data = NULL && entry = NULL -> return
+     instnace_data = NULL && entry # NULL -> check if correct gda_name then 
+                                             open new connection else return
+     instance_data # NULL && entry = NULL -> close connection, return
+     instance_data # NULL && entry # NULL -> check if correct gda_name then
+                                             close old connection, open 
+                                            new connection else close connection, 
+return
+  */
+
+  
+  entry = gb_widget_input_combo (data, GdaName);
+  instance_data = get_current_connection_from_widget (widget);
+  
+  if (instance_data == NULL) 
+    {
+      if (entry == NULL)
+       {
+         /* case 1 */
+         printf ("case 1\n");
+         return;
+       }
+      else
+       {
+         /* case 2 */
+         printf ("case 2\n");
+         if (!gda_dsn_find_by_name (entry))
+           return;
+         open_new_connection (widget, entry);
+       }
+    } 
+  else 
+    {
+      if (entry == NULL)
+       {
+         /* case 3 */
+         printf ("case 3\n");
+         gda_connection_close (instance_data->cnc);
+         return;
+       }
+      else
+       {
+         /* case 4 */
+         printf ("case 4\n");
+         if (!gda_dsn_find_by_name (entry))
+           return;
+         gda_connection_close (instance_data->cnc);
+         open_new_connection (widget, entry);
+       }
+    }
+  return;
 }
-*/
-
 
 
 /*
@@ -117,7 +283,15 @@
 {
   if (data->create_widget)
     {
-      source_add (data, "  %s = gnome_db_browser_new (NULL);\n", data->wname);
+      connection_instance_data_t *instance_data;
+      instance_data = get_current_connection_from_widget (widget);
+
+      source_add_decl (data, "  GdaConnection *cnc;\n");
+      source_add (data, "  cnc = gda_connection_pool_open_connection (cnc_pool, 
+\"%s\", \"%s\", \"%s\");\n",
+                 instance_data->gda_dsn,
+                 gda_connection_get_user (gnome_db_browser_get_connection 
+(GNOME_DB_BROWSER (widget))),
+                 gda_connection_get_password (gnome_db_browser_get_connection 
+(GNOME_DB_BROWSER (widget))));
+      source_add (data, "  %s = gnome_db_browser_new (cnc);\n", data->wname);
     }
   gb_widget_write_standard_source (widget, data);
 }
@@ -143,14 +317,14 @@
   gbwidget.tooltip = _("Database Browser");
 
   /* Fill in any functions that this GbWidget has */
-  gbwidget.gb_widget_new               = gb_gnome_db_browser_new;
-  gbwidget.gb_widget_write_source      = gb_gnome_db_browser_write_source;
-/*
-  gbwidget.gb_widget_create_properties = gb_gnome_db_browser_create_properties;
-  gbwidget.gb_widget_get_properties    = gb_gnome_db_browser_get_properties;
-  gbwidget.gb_widget_set_properties    = gb_gnome_db_browser_set_properties;
+  gbwidget.gb_widget_new                = gb_gnome_db_browser_new;
+  gbwidget.gb_widget_write_source       = gb_gnome_db_browser_write_source;
+  gbwidget.gb_widget_create_properties  = gb_gnome_db_browser_create_properties;
+  gbwidget.gb_widget_get_properties     = gb_gnome_db_browser_get_properties;
+  gbwidget.gb_widget_set_properties     = gb_gnome_db_browser_set_properties;
+  /*
   gbwidget.gb_widget_create_popup_menu = gb_gnome_db_browser_create_popup_menu;
-*/
+  */
 
   return &gbwidget;
 }
=== Exit status: 1

Reply via email to