Re: Connecting by data source?



On Thu, 3 Feb 2000, Brian Jepson wrote:

[...]

> How can I refer to it in a program like rolodex that doesn't use the login
> widget (or in a command-line program that doesn't use any widgets at all)?

Sorry to have troubled you all with this problem - I'm rethinking my
examples in such a way that I'll use the login dialog from the beginning,
since I think it will make it easier for readers.  I wanted to avoid the
popt struct to simplify the program, and I've managed to get a simple
example that uses the login widget, the login dialog, and the error dialog
to create a connection that I can then use in a little program. It's based
on the fe program and the gda-ui-test2.c program (I've appended my example
after my .signature).

Anyhow, great work on GNOME-DB.  As I explore it further, I'm finding that
it's very easy to use, and very well-designed.  I've managed to create a
sample program that uses libglade + a custom widget (which happens to be a
GNOME DB combo box)!  I'll be merging this with the example program shown
below, and I think it will be pretty cool (you can add this example to the
gnome-db distribution if you think it is worthwhile).

Thanks,

Brian Jepson * (bjepson@ids.net)  *  http://users.ids.net/~bjepson

/* GNOME DB libary
 * Copyright (C) 1998,1999 Michael Lausch
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
#include <stdio.h>

#include <libgnorba/gnorba.h>
#include "gda.h"
#include "gda-connection.h"
#include "gda-command.h"
#include "gnome-db-error-dlg.h"
#include "gnome-db-login-dlg.h"
#include "gnome-db-login.h"
#include "gnome-db-error.h"

static void create_main_dialog (GtkWidget*);

/* Event handler for closing the dialog */
static gint login_dlg_closed(GtkWidget*   w,
                             GdkEventAny* e,
                             gpointer data)
{
    fprintf(stderr, "Closing dialog.\n");
    return FALSE; 
}

/* FIXME: How to clean up the Exception handler or rely on
 * an existing handler?  I don't like cutting and pasting
 * this code into all my examples. 
 */
void Exception( CORBA_Environment *ev )
{
  switch( ev->_major )
    {
    case CORBA_SYSTEM_EXCEPTION:
      fprintf( stderr, "CORBA system exception %s.\n",
	       CORBA_exception_id(ev));
      exit ( 1 );
    case CORBA_USER_EXCEPTION:
      fprintf( stderr, "CORBA user exception: %s.\n",
	       CORBA_exception_id( ev ) );
      exit ( 1 );
    default:
      break;
    }
}

void cb_error(Gda_Connection* cnc, gpointer data) {
  GtkWidget *error_dialog;
  error_dialog = gnome_db_errordlg_new(cnc, _("Error Viewer"));
  gtk_window_set_modal(GTK_WINDOW(error_dialog), TRUE);
  gnome_db_errordlg_show_errors(GNOME_DB_ERRORDLG(error_dialog)); 
}

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

  CORBA_ORB orb;
  CORBA_Environment ev;
  GnomeDbLogin* login;
  GnomeDbLoginDlg* dialog;
  Gda_Connection* cnc;

  
  CORBA_exception_init(&ev);
  orb = gnome_CORBA_init("gda-client-test1", /* app_id */
					     "0.1",	/* app_version */
					     &argc,
					     argv,
					     0, /* gnorba_flags */
					     &ev);
  Exception(&ev);

  cnc = gda_connection_new(orb);

  /* Maybe move this into a do_login function? */
  login = gnome_db_login_new(cnc, NULL, NULL);
  dialog = gnome_db_logindlg_new(login, "Please Log In");
  gtk_signal_connect(GTK_OBJECT(cnc),"error", 
                     GTK_SIGNAL_FUNC(cb_error), NULL);
  gtk_signal_connect(GTK_OBJECT(dialog),"delete_event", 
                     GTK_SIGNAL_FUNC(login_dlg_closed), NULL);
  /* 
   * FIXME: How do I connect a signal handler to the OK button
   * of the logindlg so I can dismiss the login dialog after 
   * the connection is established?
   */
  gnome_db_logindlg_popup(dialog);

  /* FIXME:
   *
   * I need to plug in a glade-based example program here that 
   * uses the connection we just established.
   */
  gtk_main();
  return (0);
}



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