diff --git a/ChangeLog b/ChangeLog index 91b87c900..9e47de4c3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2002-09-11 Rodrigo Moya + + * gnomedb/Makefile.in: + * gnomedb/Application.cs: added class for libgnomedb initialization. + + * sample/DbClient/GnomeDbClient.cs: new test file for libgnomedb. + 2002-09-08 Rodrigo Moya * makefile: diff --git a/gnomedb/Application.cs b/gnomedb/Application.cs new file mode 100644 index 000000000..7890539c2 --- /dev/null +++ b/gnomedb/Application.cs @@ -0,0 +1,68 @@ +// +// GnomeDb.Application.cs - libgnomedb initialization and event loop +// +// Author: Rodrigo Moya +// +// (c) 2002 Rodrigo Moya +// + +using System; +using System.Runtime.InteropServices; + +namespace GnomeDb +{ + /// + /// GnomeDb Application class + /// + /// + /// + /// Provides the initialization and event loop iteration related + /// methods for the libgnomedb library. + /// + + public class Application + { + [DllImport("gnomedb-2")] + static extern void gnome_db_init (string app_id, string version, int nargs, IntPtr args); + + public static void Init () + { + gnome_db_init ("GnomeDb#", "0.4", 0, new IntPtr(0)); + } + + public static void Init (string app_id, string version) + { + gnome_db_init (app_id, version, 0, new IntPtr(0)); + } + + static extern void gnome_db_init (string app_id, string version, ref int nargs, ref String [] args); + + public static void Init (ref string [] args) + { + int argc = args.Length; + gnome_db_init ("GnomeDb#", "0.4", ref argc, ref args); + } + + public static void Init (string app_id, string version, ref string [] args) + { + int argc = args.Length; + gnome_db_init (app_id, version, ref argc, ref args); + } + + [DllImport("gnomedb-2")] + static extern void gnome_db_main_run (IntPtr init_func, IntPtr user_data); + + public static void Run () + { + gnome_db_main_run (IntPtr.Zero, IntPtr.Zero); + } + + [DllImport("gnomedb-2")] + static extern void gnome_db_main_quit (); + + public static void Quit () + { + gnome_db_main_quit (); + } + } +} diff --git a/gnomedb/Makefile.in b/gnomedb/Makefile.in index d6eb54cc4..8ce16c10e 100755 --- a/gnomedb/Makefile.in +++ b/gnomedb/Makefile.in @@ -9,7 +9,7 @@ windows: linux: gnomedb-sharp.dll -gnomedb-sharp.dll: generated/*.cs +gnomedb-sharp.dll: Application.cs generated/*.cs $(MCS) --unsafe --target library -L ../glib -r glib-sharp.dll -r gtk-sharp.dll -r gnome-sharp.dll -r gda-sharp.dll -o gnomedb-sharp.dll --recurse '*.cs' clean: diff --git a/sample/DbClient/GnomeDbClient.cs b/sample/DbClient/GnomeDbClient.cs new file mode 100644 index 000000000..0955026e8 --- /dev/null +++ b/sample/DbClient/GnomeDbClient.cs @@ -0,0 +1,70 @@ +using System; +using Gda; +using GnomeDb; +using Gtk; +using GtkSharp; + +class GnomeDbClient { + + static Gtk.Window window; + static Toolbar toolbar; + static Browser browser; + static VBox box; + static Gda.Client client = null; + static Gda.Connection cnc = null; + + static void Main (string [] args) + { + Gtk.Application.Init (); + GnomeDb.Application.Init ("GnomeDbClient", "0.1", ref args); + + /* create the UI */ + window = new Gtk.Window ("GNOME-DB client"); + window.DeleteEvent += new DeleteEventHandler (Window_Delete); + box = new VBox (false, 0); + window.Add (box); + + toolbar = new Toolbar (); + toolbar.ToolbarStyle = ToolbarStyle.BothHoriz; + toolbar.AppendItem ("Change database", "Select another database to browse", String.Empty, + new Gtk.Image (Gtk.Stock.Add, IconSize.LargeToolbar), + new SignalFunc (DB_connect)); + box.PackStart (toolbar, false, false, 0); + + browser = new GnomeDb.Browser (); + box.PackStart (browser, true, true, 0); + + window.ShowAll (); + GnomeDb.Application.Run (); + } + + static void Client_Error (object o, ErrorArgs args) + { + System.Console.WriteLine ("There's been an error"); + } + + static void Window_Delete (object o, DeleteEventArgs args) + { + GnomeDb.Application.Quit (); + args.RetVal = true; + } + + static void DB_connect (Gtk.Object o) + { + GnomeDb.LoginDialog dialog; + + dialog = new GnomeDb.LoginDialog ("Select data source"); + if (dialog.Run () == true) { + if (client == null) { + client = new Gda.Client (); + client.Error += new GtkSharp.ErrorHandler (Client_Error); + } + + cnc = client.OpenConnection (dialog.Dsn, dialog.Username, dialog.Password); + if (cnc != null) + browser.Connection = cnc; + } + dialog.Destroy (); + } +} + diff --git a/sample/DbClient/Makefile b/sample/DbClient/Makefile index 2c9d4def9..c7bbfc43e 100644 --- a/sample/DbClient/Makefile +++ b/sample/DbClient/Makefile @@ -1,5 +1,5 @@ MCS=mcs -REFERENCES= glib-sharp gdk-sharp gtk-sharp gnome-sharp System.Data System.Drawing +REFERENCES= glib-sharp gdk-sharp gtk-sharp gnome-sharp gda-sharp gnomedb-sharp System.Data System.Drawing ### @@ -7,6 +7,7 @@ REFS= $(addprefix /r:, $(REFERENCES)) all: $(MCS) $(REFS) client.cs + $(MCS) $(REFS) GnomeDbClient.cs clean: rm -f *.exe *.pdb