1/*
2 *  driversetup.c
3 *
4 *  $Id: driversetup.c,v 1.6 2007/02/02 11:58:14 source Exp $
5 *
6 *  The iODBC driver manager.
7 *
8 *  Copyright (C) 1996-2006 by OpenLink Software <iodbc@openlinksw.com>
9 *  All Rights Reserved.
10 *
11 *  This software is released under the terms of either of the following
12 *  licenses:
13 *
14 *      - GNU Library General Public License (see LICENSE.LGPL)
15 *      - The BSD License (see LICENSE.BSD).
16 *
17 *  Note that the only valid version of the LGPL license as far as this
18 *  project is concerned is the original GNU Library General Public License
19 *  Version 2, dated June 1991.
20 *
21 *  While not mandated by the BSD license, any patches you make to the
22 *  iODBC source code may be contributed back into the iODBC project
23 *  at your discretion. Contributions will benefit the Open Source and
24 *  Data Access community as a whole. Submissions may be made at:
25 *
26 *      http://www.iodbc.org
27 *
28 *
29 *  GNU Library Generic Public License Version 2
30 *  ============================================
31 *  This library is free software; you can redistribute it and/or
32 *  modify it under the terms of the GNU Library General Public
33 *  License as published by the Free Software Foundation; only
34 *  Version 2 of the License dated June 1991.
35 *
36 *  This library is distributed in the hope that it will be useful,
37 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
38 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
39 *  Library General Public License for more details.
40 *
41 *  You should have received a copy of the GNU Library General Public
42 *  License along with this library; if not, write to the Free
43 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
44 *
45 *
46 *  The BSD License
47 *  ===============
48 *  Redistribution and use in source and binary forms, with or without
49 *  modification, are permitted provided that the following conditions
50 *  are met:
51 *
52 *  1. Redistributions of source code must retain the above copyright
53 *     notice, this list of conditions and the following disclaimer.
54 *  2. Redistributions in binary form must reproduce the above copyright
55 *     notice, this list of conditions and the following disclaimer in
56 *     the documentation and/or other materials provided with the
57 *     distribution.
58 *  3. Neither the name of OpenLink Software Inc. nor the names of its
59 *     contributors may be used to endorse or promote products derived
60 *     from this software without specific prior written permission.
61 *
62 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
63 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
64 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
65 *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL OPENLINK OR
66 *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
67 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
68 *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
69 *  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
70 *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
71 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
72 *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
73 */
74
75
76#include "gui.h"
77
78
79static char* STRCONN = "%s\0Driver=%s\0Setup=%s\0\0";
80static int STRCONN_NB_TOKENS = 3;
81
82char *szKeysColumnNames[] = {
83  "Keyword",
84  "Value"
85};
86
87char *szKeysButtons[] = {
88  "_Add",
89  "_Update"
90};
91
92
93static void
94addkeywords_to_list (GtkWidget *widget, LPCSTR attrs,
95    TDRIVERSETUP *driversetup_t)
96{
97  char *curr, *cour;
98  char *data[2];
99
100  if (!GTK_IS_CLIST (widget))
101    return;
102  gtk_clist_clear (GTK_CLIST (widget));
103
104  for (curr = (LPSTR) attrs; *curr; curr += (STRLEN (curr) + 1))
105    {
106      if (!strncasecmp (curr, "Driver=", STRLEN ("Driver=")))
107	{
108	  gtk_entry_set_text (GTK_ENTRY (driversetup_t->driver_entry),
109	      curr + STRLEN ("Driver="));
110	  continue;
111	}
112
113      if (!strncasecmp (curr, "Setup=", STRLEN ("Setup=")))
114	{
115	  gtk_entry_set_text (GTK_ENTRY (driversetup_t->setup_entry),
116	      curr + STRLEN ("Setup="));
117	  continue;
118	}
119
120      data[0] = curr;
121
122      if ((cour = strchr (curr, '=')))
123	{
124	  data[1] = cour + 1;
125	  *cour = 0;
126	  gtk_clist_append (GTK_CLIST (widget), data);
127	  *cour = '=';
128	}
129      else
130	{
131	  data[1] = "";
132	  gtk_clist_append (GTK_CLIST (widget), data);
133	}
134    }
135
136  if (GTK_CLIST (widget)->rows > 0)
137    gtk_clist_sort (GTK_CLIST (widget));
138}
139
140
141static void
142parse_attribute_line (TDRIVERSETUP *driversetup_t, LPCSTR driver,
143    LPCSTR attrs, BOOL add)
144{
145  if (driver)
146    {
147      gtk_entry_set_text (GTK_ENTRY (driversetup_t->name_entry), driver);
148      if (add)
149	gtk_entry_set_editable (GTK_ENTRY (driversetup_t->name_entry), FALSE);
150      else
151	gtk_entry_set_editable (GTK_ENTRY (driversetup_t->name_entry), TRUE);
152    }
153
154  addkeywords_to_list (driversetup_t->key_list, attrs, driversetup_t);
155}
156
157
158static void
159driver_file_choosen (GtkWidget *widget, TDRIVERSETUP *driversetup_t)
160{
161  if (driversetup_t)
162    {
163      gtk_entry_set_text (GTK_ENTRY (driversetup_t->driver_entry),
164	  gtk_file_selection_get_filename (GTK_FILE_SELECTION (driversetup_t->
165		  filesel)));
166      driversetup_t->filesel = NULL;
167    }
168}
169
170
171static void
172setup_file_choosen (GtkWidget *widget, TDRIVERSETUP *driversetup_t)
173{
174  if (driversetup_t)
175    {
176      gtk_entry_set_text (GTK_ENTRY (driversetup_t->setup_entry),
177	  gtk_file_selection_get_filename (GTK_FILE_SELECTION (driversetup_t->
178		  filesel)));
179      driversetup_t->filesel = NULL;
180    }
181}
182
183
184static void
185driversetup_browsedriver_clicked (GtkWidget *widget,
186    TDRIVERSETUP *driversetup_t)
187{
188  GtkWidget *filesel;
189
190  if (driversetup_t)
191    {
192      filesel = gtk_file_selection_new ("Choose your driver library ...");
193      gtk_window_set_modal (GTK_WINDOW (filesel), TRUE);
194      gtk_file_selection_set_filename (GTK_FILE_SELECTION (filesel),
195	  gtk_entry_get_text (GTK_ENTRY (driversetup_t->driver_entry)));
196      /* Ok button events */
197      gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filesel)->
198	      ok_button), "clicked", GTK_SIGNAL_FUNC (driver_file_choosen),
199	  driversetup_t);
200      gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filesel)->
201	      ok_button), "clicked", GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
202      /* Cancel button events */
203      gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filesel)->
204	      cancel_button), "clicked", GTK_SIGNAL_FUNC (gtk_main_quit),
205	  NULL);
206      /* Close window button events */
207      gtk_signal_connect (GTK_OBJECT (filesel), "delete_event",
208	  GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
209
210      driversetup_t->filesel = filesel;
211
212      gtk_widget_show_all (filesel);
213      gtk_main ();
214      gtk_widget_destroy (filesel);
215
216      driversetup_t->filesel = NULL;
217    }
218}
219
220
221static void
222driversetup_browsesetup_clicked (GtkWidget *widget,
223    TDRIVERSETUP *driversetup_t)
224{
225  GtkWidget *filesel;
226
227  if (driversetup_t)
228    {
229      filesel = gtk_file_selection_new ("Choose your setup library ...");
230      gtk_window_set_modal (GTK_WINDOW (filesel), TRUE);
231      gtk_file_selection_set_filename (GTK_FILE_SELECTION (filesel),
232	  gtk_entry_get_text (GTK_ENTRY (driversetup_t->setup_entry)));
233      /* Ok button events */
234      gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filesel)->
235	      ok_button), "clicked", GTK_SIGNAL_FUNC (setup_file_choosen),
236	  driversetup_t);
237      gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filesel)->
238	      ok_button), "clicked", GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
239      /* Cancel button events */
240      gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filesel)->
241	      cancel_button), "clicked", GTK_SIGNAL_FUNC (gtk_main_quit),
242	  NULL);
243      /* Close window button events */
244      gtk_signal_connect (GTK_OBJECT (filesel), "delete_event",
245	  GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
246
247      driversetup_t->filesel = filesel;
248
249      gtk_widget_show_all (filesel);
250      gtk_main ();
251      gtk_widget_destroy (filesel);
252
253      driversetup_t->filesel = NULL;
254    }
255}
256
257
258static void
259driversetup_add_clicked (GtkWidget *widget, TDRIVERSETUP *driversetup_t)
260{
261  char *szKey;
262  char *data[2];
263  int i = 0;
264
265  if (driversetup_t)
266    {
267      data[0] = gtk_entry_get_text (GTK_ENTRY (driversetup_t->key_entry));
268      if (!STRLEN (data[0]))
269	goto done;
270      data[1] = gtk_entry_get_text (GTK_ENTRY (driversetup_t->value_entry));
271
272      for (i = 0; i < GTK_CLIST (driversetup_t->key_list)->rows; i++)
273	{
274	  gtk_clist_get_text (GTK_CLIST (driversetup_t->key_list), i, 0,
275	      &szKey);
276	  if (!strcmp (szKey, data[0]))
277	    {
278	      gtk_clist_remove (GTK_CLIST (driversetup_t->key_list), i);
279	      break;
280	    }
281	}
282
283      gtk_clist_append (GTK_CLIST (driversetup_t->key_list), data);
284      if (GTK_CLIST (driversetup_t->key_list)->rows > 0)
285	gtk_clist_sort (GTK_CLIST (driversetup_t->key_list));
286
287    done:
288      gtk_entry_set_text (GTK_ENTRY (driversetup_t->key_entry), "");
289      gtk_entry_set_text (GTK_ENTRY (driversetup_t->value_entry), "");
290    }
291}
292
293
294static void
295driversetup_update_clicked (GtkWidget *widget, TDRIVERSETUP *driversetup_t)
296{
297  char *data[2];
298
299  if (driversetup_t && GTK_CLIST (driversetup_t->key_list)->selection != NULL)
300    {
301      data[0] = gtk_entry_get_text (GTK_ENTRY (driversetup_t->key_entry));
302      data[1] = gtk_entry_get_text (GTK_ENTRY (driversetup_t->value_entry));
303      gtk_clist_remove (GTK_CLIST (driversetup_t->key_list),
304	  GPOINTER_TO_INT (GTK_CLIST (driversetup_t->key_list)->selection->
305	      data));
306
307      if (STRLEN (data[0]))
308	{
309	  gtk_clist_append (GTK_CLIST (driversetup_t->key_list), data);
310	  if (GTK_CLIST (driversetup_t->key_list)->rows > 0)
311	    gtk_clist_sort (GTK_CLIST (driversetup_t->key_list));
312	}
313
314      gtk_entry_set_text (GTK_ENTRY (driversetup_t->key_entry), "");
315      gtk_entry_set_text (GTK_ENTRY (driversetup_t->value_entry), "");
316    }
317}
318
319
320static void
321driversetup_list_select (GtkWidget *widget, gint row, gint column,
322    GdkEvent *event, TDRIVERSETUP *driversetup_t)
323{
324  char *szKey, *szValue;
325
326  if (driversetup_t && GTK_CLIST (driversetup_t->key_list)->selection != NULL)
327    {
328      gtk_clist_get_text (GTK_CLIST (driversetup_t->key_list),
329	  GPOINTER_TO_INT (GTK_CLIST (driversetup_t->key_list)->selection->
330	      data), 0, &szKey);
331      gtk_clist_get_text (GTK_CLIST (driversetup_t->key_list),
332	  GPOINTER_TO_INT (GTK_CLIST (driversetup_t->key_list)->selection->
333	      data), 1, &szValue);
334      gtk_entry_set_text (GTK_ENTRY (driversetup_t->key_entry), szKey);
335      gtk_entry_set_text (GTK_ENTRY (driversetup_t->value_entry), szValue);
336      gtk_widget_set_sensitive (driversetup_t->bupdate, TRUE);
337    }
338}
339
340
341static void
342driversetup_list_unselect (GtkWidget *widget, gint row, gint column,
343    GdkEvent *event, TDRIVERSETUP *driversetup_t)
344{
345  if (driversetup_t)
346    {
347      gtk_widget_set_sensitive (driversetup_t->bupdate, FALSE);
348      gtk_entry_set_text (GTK_ENTRY (driversetup_t->key_entry), "");
349      gtk_entry_set_text (GTK_ENTRY (driversetup_t->value_entry), "");
350    }
351}
352
353
354static void
355driversetup_ok_clicked (GtkWidget *widget, TDRIVERSETUP *driversetup_t)
356{
357  char *curr, *cour, *szKey, *szValue;
358  int i = 0, size;
359
360  if (driversetup_t)
361    {
362      driversetup_t->connstr = (char *) malloc (sizeof (char) * (size =
363	      ((STRLEN (gtk_entry_get_text (GTK_ENTRY (driversetup_t->
364				  name_entry))) ?
365		      STRLEN (gtk_entry_get_text (GTK_ENTRY (driversetup_t->
366				  name_entry))) + 1 : 0) +
367		  (STRLEN (gtk_entry_get_text (GTK_ENTRY (driversetup_t->
368				  driver_entry))) ?
369		      STRLEN (gtk_entry_get_text (GTK_ENTRY (driversetup_t->
370				  driver_entry))) + STRLEN ("Driver=") +
371		      1 : 0) +
372		  (STRLEN (gtk_entry_get_text (GTK_ENTRY (driversetup_t->
373				  setup_entry))) ?
374		      STRLEN (gtk_entry_get_text (GTK_ENTRY (driversetup_t->
375				  setup_entry))) + STRLEN ("Setup=") +
376		      1 : 0) + 1)));
377
378      if (driversetup_t->connstr)
379	{
380	  for (curr = STRCONN, cour = driversetup_t->connstr;
381	      i < STRCONN_NB_TOKENS; i++, curr += (STRLEN (curr) + 1))
382	    switch (i)
383	      {
384	      case 0:
385		if (STRLEN (gtk_entry_get_text (GTK_ENTRY (driversetup_t->
386				name_entry))))
387		  {
388		    sprintf (cour, curr,
389			gtk_entry_get_text (GTK_ENTRY (driversetup_t->
390				name_entry)));
391		    cour += (STRLEN (cour) + 1);
392		  }
393		break;
394	      case 1:
395		if (STRLEN (gtk_entry_get_text (GTK_ENTRY (driversetup_t->
396				driver_entry))))
397		  {
398		    sprintf (cour, curr,
399			gtk_entry_get_text (GTK_ENTRY (driversetup_t->
400				driver_entry)));
401		    cour += (STRLEN (cour) + 1);
402		  }
403		break;
404	      case 2:
405		if (STRLEN (gtk_entry_get_text (GTK_ENTRY (driversetup_t->
406				setup_entry))))
407		  {
408		    sprintf (cour, curr,
409			gtk_entry_get_text (GTK_ENTRY (driversetup_t->
410				setup_entry)));
411		    cour += (STRLEN (cour) + 1);
412		  }
413		break;
414	      };
415
416	  for (i = 0; i < GTK_CLIST (driversetup_t->key_list)->rows; i++)
417	    {
418	      gtk_clist_get_text (GTK_CLIST (driversetup_t->key_list), i, 0,
419		  &szKey);
420	      gtk_clist_get_text (GTK_CLIST (driversetup_t->key_list), i, 1,
421		  &szValue);
422
423	      cour = (char *) driversetup_t->connstr;
424	      driversetup_t->connstr =
425		  (LPSTR) malloc (size + STRLEN (szKey) + STRLEN (szValue) +
426		  2);
427	      if (driversetup_t->connstr)
428		{
429		  memcpy (driversetup_t->connstr, cour, size);
430		  sprintf (driversetup_t->connstr + size - 1, "%s=%s", szKey,
431		      szValue);
432		  free (cour);
433		  size += STRLEN (szKey) + STRLEN (szValue) + 2;
434		}
435	      else
436		driversetup_t->connstr = cour;
437	    }
438
439	  driversetup_t->connstr[size - 1] = 0;
440	}
441
442      driversetup_t->name_entry = driversetup_t->driver_entry =
443	  driversetup_t->setup_entry = NULL;
444      driversetup_t->key_list = driversetup_t->filesel = NULL;
445
446      gtk_signal_disconnect_by_func (GTK_OBJECT (driversetup_t->mainwnd),
447	  GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
448      gtk_main_quit ();
449      gtk_widget_destroy (driversetup_t->mainwnd);
450    }
451}
452
453
454static void
455driversetup_cancel_clicked (GtkWidget *widget, TDRIVERSETUP *driversetup_t)
456{
457  if (driversetup_t)
458    {
459      driversetup_t->connstr = (LPSTR) - 1L;
460
461      driversetup_t->name_entry = driversetup_t->driver_entry =
462	  driversetup_t->setup_entry = NULL;
463      driversetup_t->key_list = driversetup_t->filesel = NULL;
464
465      gtk_signal_disconnect_by_func (GTK_OBJECT (driversetup_t->mainwnd),
466	  GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
467      gtk_main_quit ();
468      gtk_widget_destroy (driversetup_t->mainwnd);
469    }
470}
471
472
473static gint
474delete_event (GtkWidget *widget, GdkEvent *event,
475    TDRIVERSETUP *driversetup_t)
476{
477  driversetup_cancel_clicked (widget, driversetup_t);
478
479  return FALSE;
480}
481
482
483LPSTR
484create_driversetup (HWND hwnd, LPCSTR driver, LPCSTR attrs, BOOL add, BOOL user)
485{
486  GtkWidget *driversetup, *dialog_vbox1, *fixed1, *t_name, *t_driver,
487      *t_keyword;
488  GtkWidget *t_value, *l_name, *b_browse, *t_setup, *l_driver, *b_browse1;
489  GtkWidget *l_setup, *scrolledwindow1, *clist1, *l_key, *l_value, *l_keyword;
490  GtkWidget *l_valeur, *vbuttonbox1, *b_add, *b_update, *l_copyright;
491  GtkWidget *dialog_action_area1, *hbuttonbox1, *b_ok, *b_cancel;
492  guint b_add_key, b_update_key, b_ok_key, b_cancel_key;
493  GtkAccelGroup *accel_group;
494  TDRIVERSETUP driversetup_t;
495
496  if (hwnd == NULL || !GTK_IS_WIDGET (hwnd))
497    return (LPSTR) attrs;
498
499  accel_group = gtk_accel_group_new ();
500
501  driversetup = gtk_dialog_new ();
502  gtk_object_set_data (GTK_OBJECT (driversetup), "driversetup", driversetup);
503  gtk_window_set_title (GTK_WINDOW (driversetup), "ODBC Driver Add/Setup");
504  gtk_window_set_position (GTK_WINDOW (driversetup), GTK_WIN_POS_CENTER);
505  gtk_window_set_modal (GTK_WINDOW (driversetup), TRUE);
506  gtk_window_set_policy (GTK_WINDOW (driversetup), FALSE, FALSE, FALSE);
507
508#if GTK_CHECK_VERSION(2,0,0)
509  gtk_widget_show (driversetup);
510#endif
511
512  dialog_vbox1 = GTK_DIALOG (driversetup)->vbox;
513  gtk_object_set_data (GTK_OBJECT (driversetup), "dialog_vbox1",
514      dialog_vbox1);
515  gtk_widget_show (dialog_vbox1);
516
517  fixed1 = gtk_fixed_new ();
518  gtk_widget_ref (fixed1);
519  gtk_object_set_data_full (GTK_OBJECT (driversetup), "fixed1", fixed1,
520      (GtkDestroyNotify) gtk_widget_unref);
521  gtk_widget_show (fixed1);
522  gtk_box_pack_start (GTK_BOX (dialog_vbox1), fixed1, TRUE, TRUE, 0);
523  gtk_container_set_border_width (GTK_CONTAINER (fixed1), 6);
524
525  t_name = gtk_entry_new ();
526  gtk_widget_ref (t_name);
527  gtk_object_set_data_full (GTK_OBJECT (driversetup), "t_name", t_name,
528      (GtkDestroyNotify) gtk_widget_unref);
529  gtk_widget_show (t_name);
530  gtk_fixed_put (GTK_FIXED (fixed1), t_name, 160, 56);
531  gtk_widget_set_uposition (t_name, 160, 56);
532  gtk_widget_set_usize (t_name, 250, 0);
533
534  t_driver = gtk_entry_new ();
535  gtk_widget_ref (t_driver);
536  gtk_object_set_data_full (GTK_OBJECT (driversetup), "t_driver", t_driver,
537      (GtkDestroyNotify) gtk_widget_unref);
538  gtk_widget_show (t_driver);
539  gtk_fixed_put (GTK_FIXED (fixed1), t_driver, 160, 88);
540  gtk_widget_set_uposition (t_driver, 160, 88);
541  gtk_widget_set_usize (t_driver, 250, 0);
542
543  t_keyword = gtk_entry_new ();
544  gtk_widget_ref (t_keyword);
545  gtk_object_set_data_full (GTK_OBJECT (driversetup), "t_keyword", t_keyword,
546      (GtkDestroyNotify) gtk_widget_unref);
547  gtk_widget_show (t_keyword);
548#if GTK_CHECK_VERSION(2,0,0)
549  gtk_fixed_put (GTK_FIXED (fixed1), t_keyword, 88, 360);
550  gtk_widget_set_uposition (t_keyword, 88, 360);
551#else
552  gtk_fixed_put (GTK_FIXED (fixed1), t_keyword, 88, 352);
553  gtk_widget_set_uposition (t_keyword, 88, 352);
554#endif
555  gtk_widget_set_usize (t_keyword, 301, 22);
556
557  t_value = gtk_entry_new ();
558  gtk_widget_ref (t_value);
559  gtk_object_set_data_full (GTK_OBJECT (driversetup), "t_value", t_value,
560      (GtkDestroyNotify) gtk_widget_unref);
561  gtk_widget_show (t_value);
562#if GTK_CHECK_VERSION(2,0,0)
563  gtk_fixed_put (GTK_FIXED (fixed1), t_value, 88, 392);
564  gtk_widget_set_uposition (t_value, 88, 392);
565#else
566  gtk_fixed_put (GTK_FIXED (fixed1), t_value, 88, 384);
567  gtk_widget_set_uposition (t_value, 88, 384);
568#endif
569  gtk_widget_set_usize (t_value, 301, 22);
570
571  l_name = gtk_label_new ("Description of the driver : ");
572  gtk_widget_ref (l_name);
573  gtk_object_set_data_full (GTK_OBJECT (driversetup), "l_name", l_name,
574      (GtkDestroyNotify) gtk_widget_unref);
575  gtk_widget_show (l_name);
576  gtk_fixed_put (GTK_FIXED (fixed1), l_name, 8, 59);
577  gtk_widget_set_uposition (l_name, 8, 59);
578  gtk_widget_set_usize (l_name, 0, 0);
579  gtk_label_set_justify (GTK_LABEL (l_name), GTK_JUSTIFY_LEFT);
580
581  b_browse = gtk_button_new_with_label ("Browse ...");
582  gtk_widget_ref (b_browse);
583  gtk_object_set_data_full (GTK_OBJECT (driversetup), "b_browse", b_browse,
584      (GtkDestroyNotify) gtk_widget_unref);
585  gtk_widget_show (b_browse);
586  gtk_fixed_put (GTK_FIXED (fixed1), b_browse, 424, 88);
587  gtk_widget_set_uposition (b_browse, 424, 88);
588  gtk_widget_set_usize (b_browse, 65, 22);
589
590  t_setup = gtk_entry_new ();
591  gtk_widget_ref (t_setup);
592  gtk_object_set_data_full (GTK_OBJECT (driversetup), "t_setup", t_setup,
593      (GtkDestroyNotify) gtk_widget_unref);
594  gtk_widget_show (t_setup);
595  gtk_fixed_put (GTK_FIXED (fixed1), t_setup, 160, 120);
596  gtk_widget_set_uposition (t_setup, 160, 120);
597  gtk_widget_set_usize (t_setup, 250, 0);
598
599  l_driver = gtk_label_new ("Driver file name : ");
600  gtk_widget_ref (l_driver);
601  gtk_object_set_data_full (GTK_OBJECT (driversetup), "l_driver", l_driver,
602      (GtkDestroyNotify) gtk_widget_unref);
603  gtk_widget_show (l_driver);
604  gtk_fixed_put (GTK_FIXED (fixed1), l_driver, 55, 92);
605  gtk_widget_set_uposition (l_driver, 55, 92);
606  gtk_widget_set_usize (l_driver, 0, 0);
607  gtk_label_set_justify (GTK_LABEL (l_driver), GTK_JUSTIFY_LEFT);
608
609  b_browse1 = gtk_button_new_with_label ("Browse ...");
610  gtk_widget_ref (b_browse1);
611  gtk_object_set_data_full (GTK_OBJECT (driversetup), "b_browse1", b_browse1,
612      (GtkDestroyNotify) gtk_widget_unref);
613  gtk_widget_show (b_browse1);
614  gtk_fixed_put (GTK_FIXED (fixed1), b_browse1, 424, 120);
615  gtk_widget_set_uposition (b_browse1, 424, 120);
616  gtk_widget_set_usize (b_browse1, 65, 22);
617
618  l_setup = gtk_label_new ("Setup file name : ");
619  gtk_widget_ref (l_setup);
620  gtk_object_set_data_full (GTK_OBJECT (driversetup), "l_setup", l_setup,
621      (GtkDestroyNotify) gtk_widget_unref);
622  gtk_widget_show (l_setup);
623  gtk_fixed_put (GTK_FIXED (fixed1), l_setup, 56, 123);
624  gtk_widget_set_uposition (l_setup, 56, 123);
625  gtk_widget_set_usize (l_setup, 0, 0);
626  gtk_label_set_justify (GTK_LABEL (l_setup), GTK_JUSTIFY_LEFT);
627
628  scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
629  gtk_widget_ref (scrolledwindow1);
630  gtk_object_set_data_full (GTK_OBJECT (driversetup), "scrolledwindow1",
631      scrolledwindow1, (GtkDestroyNotify) gtk_widget_unref);
632  gtk_widget_show (scrolledwindow1);
633  gtk_fixed_put (GTK_FIXED (fixed1), scrolledwindow1, 8, 152);
634  gtk_widget_set_uposition (scrolledwindow1, 8, 152);
635  gtk_widget_set_usize (scrolledwindow1, 480, 192);
636
637  clist1 = gtk_clist_new (2);
638  gtk_widget_ref (clist1);
639  gtk_object_set_data_full (GTK_OBJECT (driversetup), "clist1", clist1,
640      (GtkDestroyNotify) gtk_widget_unref);
641  gtk_widget_show (clist1);
642  gtk_container_add (GTK_CONTAINER (scrolledwindow1), clist1);
643  gtk_clist_set_column_width (GTK_CLIST (clist1), 0, 134);
644  gtk_clist_set_column_width (GTK_CLIST (clist1), 1, 80);
645  gtk_clist_column_titles_show (GTK_CLIST (clist1));
646
647  l_key = gtk_label_new (szKeysColumnNames[0]);
648  gtk_widget_ref (l_key);
649  gtk_object_set_data_full (GTK_OBJECT (driversetup), "l_key", l_key,
650      (GtkDestroyNotify) gtk_widget_unref);
651  gtk_widget_show (l_key);
652  gtk_clist_set_column_widget (GTK_CLIST (clist1), 0, l_key);
653
654  l_value = gtk_label_new (szKeysColumnNames[1]);
655  gtk_widget_ref (l_value);
656  gtk_object_set_data_full (GTK_OBJECT (driversetup), "l_value", l_value,
657      (GtkDestroyNotify) gtk_widget_unref);
658  gtk_widget_show (l_value);
659  gtk_clist_set_column_widget (GTK_CLIST (clist1), 1, l_value);
660
661  l_keyword = gtk_label_new ("Keyword : ");
662  gtk_widget_ref (l_keyword);
663  gtk_object_set_data_full (GTK_OBJECT (driversetup), "l_keyword", l_keyword,
664      (GtkDestroyNotify) gtk_widget_unref);
665  gtk_widget_show (l_keyword);
666#if GTK_CHECK_VERSION(2,0,0)
667  gtk_fixed_put (GTK_FIXED (fixed1), l_keyword, 16, 363);
668  gtk_widget_set_uposition (l_keyword, 16, 363);
669#else
670  gtk_fixed_put (GTK_FIXED (fixed1), l_keyword, 16, 355);
671  gtk_widget_set_uposition (l_keyword, 16, 355);
672#endif
673  gtk_widget_set_usize (l_keyword, 69, 16);
674  gtk_label_set_justify (GTK_LABEL (l_keyword), GTK_JUSTIFY_LEFT);
675
676  l_valeur = gtk_label_new ("Value : ");
677  gtk_widget_ref (l_valeur);
678  gtk_object_set_data_full (GTK_OBJECT (driversetup), "l_valeur", l_valeur,
679      (GtkDestroyNotify) gtk_widget_unref);
680  gtk_widget_show (l_valeur);
681#if GTK_CHECK_VERSION(2,0,0)
682  gtk_fixed_put (GTK_FIXED (fixed1), l_valeur, 32, 396);
683  gtk_widget_set_uposition (l_valeur, 32, 396);
684#else
685  gtk_fixed_put (GTK_FIXED (fixed1), l_valeur, 32, 388);
686  gtk_widget_set_uposition (l_valeur, 32, 388);
687#endif
688  gtk_widget_set_usize (l_valeur, 51, 16);
689  gtk_label_set_justify (GTK_LABEL (l_valeur), GTK_JUSTIFY_LEFT);
690
691  vbuttonbox1 = gtk_vbutton_box_new ();
692  gtk_widget_ref (vbuttonbox1);
693  gtk_object_set_data_full (GTK_OBJECT (driversetup), "vbuttonbox1",
694      vbuttonbox1, (GtkDestroyNotify) gtk_widget_unref);
695  gtk_widget_show (vbuttonbox1);
696#if GTK_CHECK_VERSION(2,0,0)
697  gtk_fixed_put (GTK_FIXED (fixed1), vbuttonbox1, 400, 357);
698  gtk_widget_set_uposition (vbuttonbox1, 400, 357);
699#else
700  gtk_fixed_put (GTK_FIXED (fixed1), vbuttonbox1, 400, 344);
701  gtk_widget_set_uposition (vbuttonbox1, 400, 344);
702#endif
703  gtk_widget_set_usize (vbuttonbox1, 85, 67);
704
705  b_add = gtk_button_new_with_label ("");
706  b_add_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (b_add)->child),
707      szKeysButtons[0]);
708  gtk_widget_add_accelerator (b_add, "clicked", accel_group,
709      b_add_key, GDK_MOD1_MASK, 0);
710  gtk_widget_ref (b_add);
711  gtk_object_set_data_full (GTK_OBJECT (driversetup), "b_add", b_add,
712      (GtkDestroyNotify) gtk_widget_unref);
713  gtk_widget_show (b_add);
714  gtk_container_add (GTK_CONTAINER (vbuttonbox1), b_add);
715  GTK_WIDGET_SET_FLAGS (b_add, GTK_CAN_DEFAULT);
716  gtk_widget_add_accelerator (b_add, "clicked", accel_group,
717      'A', GDK_MOD1_MASK, GTK_ACCEL_VISIBLE);
718
719  b_update = gtk_button_new_with_label ("");
720  b_update_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (b_update)->child),
721      szKeysButtons[1]);
722  gtk_widget_add_accelerator (b_update, "clicked", accel_group,
723      b_update_key, GDK_MOD1_MASK, 0);
724  gtk_widget_ref (b_update);
725  gtk_object_set_data_full (GTK_OBJECT (driversetup), "b_update", b_update,
726      (GtkDestroyNotify) gtk_widget_unref);
727  gtk_widget_show (b_update);
728  gtk_container_add (GTK_CONTAINER (vbuttonbox1), b_update);
729  GTK_WIDGET_SET_FLAGS (b_update, GTK_CAN_DEFAULT);
730  gtk_widget_add_accelerator (b_update, "clicked", accel_group,
731      'U', GDK_MOD1_MASK, GTK_ACCEL_VISIBLE);
732
733  l_copyright = gtk_label_new ("ODBC Driver Add/Setup");
734  gtk_widget_ref (l_copyright);
735  gtk_object_set_data_full (GTK_OBJECT (driversetup), "l_copyright",
736      l_copyright, (GtkDestroyNotify) gtk_widget_unref);
737  gtk_widget_show (l_copyright);
738  gtk_fixed_put (GTK_FIXED (fixed1), l_copyright, 6, 6);
739  gtk_widget_set_uposition (l_copyright, 0, 0);
740  gtk_widget_set_usize (l_copyright, 482, 42);
741
742  dialog_action_area1 = GTK_DIALOG (driversetup)->action_area;
743  gtk_object_set_data (GTK_OBJECT (driversetup), "dialog_action_area1",
744      dialog_action_area1);
745  gtk_widget_show (dialog_action_area1);
746  gtk_container_set_border_width (GTK_CONTAINER (dialog_action_area1), 5);
747
748  hbuttonbox1 = gtk_hbutton_box_new ();
749  gtk_widget_ref (hbuttonbox1);
750  gtk_object_set_data_full (GTK_OBJECT (driversetup), "hbuttonbox1",
751      hbuttonbox1, (GtkDestroyNotify) gtk_widget_unref);
752  gtk_widget_show (hbuttonbox1);
753  gtk_box_pack_start (GTK_BOX (dialog_action_area1), hbuttonbox1, TRUE, TRUE,
754      0);
755  gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox1), GTK_BUTTONBOX_END);
756  gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbuttonbox1), 10);
757
758  b_ok = gtk_button_new_with_label ("");
759  b_ok_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (b_ok)->child), "_Ok");
760  gtk_widget_add_accelerator (b_ok, "clicked", accel_group,
761      b_ok_key, GDK_MOD1_MASK, 0);
762  gtk_widget_ref (b_ok);
763  gtk_object_set_data_full (GTK_OBJECT (driversetup), "b_ok", b_ok,
764      (GtkDestroyNotify) gtk_widget_unref);
765  gtk_widget_show (b_ok);
766  gtk_container_add (GTK_CONTAINER (hbuttonbox1), b_ok);
767  GTK_WIDGET_SET_FLAGS (b_ok, GTK_CAN_DEFAULT);
768  gtk_widget_add_accelerator (b_ok, "clicked", accel_group,
769      'O', GDK_MOD1_MASK, GTK_ACCEL_VISIBLE);
770
771  b_cancel = gtk_button_new_with_label ("");
772  b_cancel_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (b_cancel)->child),
773      "_Cancel");
774  gtk_widget_add_accelerator (b_cancel, "clicked", accel_group,
775      b_cancel_key, GDK_MOD1_MASK, 0);
776  gtk_widget_ref (b_cancel);
777  gtk_object_set_data_full (GTK_OBJECT (driversetup), "b_cancel", b_cancel,
778      (GtkDestroyNotify) gtk_widget_unref);
779  gtk_widget_show (b_cancel);
780  gtk_container_add (GTK_CONTAINER (hbuttonbox1), b_cancel);
781  GTK_WIDGET_SET_FLAGS (b_cancel, GTK_CAN_DEFAULT);
782  gtk_widget_add_accelerator (b_cancel, "clicked", accel_group,
783      'C', GDK_MOD1_MASK, GTK_ACCEL_VISIBLE);
784
785  /* Ok button events */
786  gtk_signal_connect (GTK_OBJECT (b_ok), "clicked",
787      GTK_SIGNAL_FUNC (driversetup_ok_clicked), &driversetup_t);
788  /* Cancel button events */
789  gtk_signal_connect (GTK_OBJECT (b_cancel), "clicked",
790      GTK_SIGNAL_FUNC (driversetup_cancel_clicked), &driversetup_t);
791  /* Add button events */
792  gtk_signal_connect (GTK_OBJECT (b_add), "clicked",
793      GTK_SIGNAL_FUNC (driversetup_add_clicked), &driversetup_t);
794  /* Update button events */
795  gtk_signal_connect (GTK_OBJECT (b_update), "clicked",
796      GTK_SIGNAL_FUNC (driversetup_update_clicked), &driversetup_t);
797  /* Close window button events */
798  gtk_signal_connect (GTK_OBJECT (driversetup), "delete_event",
799      GTK_SIGNAL_FUNC (delete_event), &driversetup_t);
800  gtk_signal_connect (GTK_OBJECT (driversetup), "destroy",
801      GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
802  /* List events */
803  gtk_signal_connect (GTK_OBJECT (clist1), "select_row",
804      GTK_SIGNAL_FUNC (driversetup_list_select), &driversetup_t);
805  gtk_signal_connect (GTK_OBJECT (clist1), "unselect_row",
806      GTK_SIGNAL_FUNC (driversetup_list_unselect), &driversetup_t);
807  /* Browse button events */
808  gtk_signal_connect (GTK_OBJECT (b_browse), "clicked",
809      GTK_SIGNAL_FUNC (driversetup_browsedriver_clicked), &driversetup_t);
810  gtk_signal_connect (GTK_OBJECT (b_browse1), "clicked",
811      GTK_SIGNAL_FUNC (driversetup_browsesetup_clicked), &driversetup_t);
812
813  gtk_window_add_accel_group (GTK_WINDOW (driversetup), accel_group);
814
815  driversetup_t.name_entry = t_name;
816  driversetup_t.driver_entry = t_driver;
817  driversetup_t.key_list = clist1;
818  driversetup_t.bupdate = b_update;
819  driversetup_t.key_entry = t_keyword;
820  driversetup_t.value_entry = t_value;
821  driversetup_t.mainwnd = driversetup;
822  driversetup_t.setup_entry = t_setup;
823
824  /* Parse the attributes line */
825  parse_attribute_line (&driversetup_t, driver, attrs, add);
826
827  gtk_widget_show_all (driversetup);
828  gtk_main ();
829
830  return driversetup_t.connstr;
831}
832