1/* 2 * connectionpooling.c 3 * 4 * $Id: connectionpooling.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 void 80connectionpool_finish_clicked (GtkWidget *widget, 81 TCONNECTIONPOOLING *connectionpool_t) 82{ 83 if (connectionpool_t) 84 { 85 connectionpool_t->changed = TRUE; 86 87 memset(connectionpool_t->timeout, 0, sizeof(connectionpool_t->timeout)); 88 memset(connectionpool_t->probe, 0, sizeof(connectionpool_t->probe)); 89 strncpy (connectionpool_t->timeout, 90 gtk_entry_get_text (GTK_ENTRY (connectionpool_t->timeout_entry)), 91 sizeof(connectionpool_t->timeout)-1); 92 strncpy (connectionpool_t->probe, 93 gtk_entry_get_text (GTK_ENTRY (connectionpool_t->probe_entry)), 94 sizeof(connectionpool_t->probe)-1); 95 96 gtk_signal_disconnect_by_func (GTK_OBJECT (connectionpool_t->mainwnd), 97 GTK_SIGNAL_FUNC (gtk_main_quit), NULL); 98 gtk_main_quit (); 99 gtk_widget_destroy (connectionpool_t->mainwnd); 100 } 101} 102 103 104static void 105connectionpool_cancel_clicked (GtkWidget *widget, 106 TCONNECTIONPOOLING *connectionpool_t) 107{ 108 if (connectionpool_t) 109 { 110 connectionpool_t->changed = FALSE; 111 112 gtk_signal_disconnect_by_func (GTK_OBJECT (connectionpool_t->mainwnd), 113 GTK_SIGNAL_FUNC (gtk_main_quit), NULL); 114 gtk_main_quit (); 115 gtk_widget_destroy (connectionpool_t->mainwnd); 116 } 117} 118 119 120static gint 121delete_event (GtkWidget *widget, 122 GdkEvent *event, TCONNECTIONPOOLING *connectionpool_t) 123{ 124 connectionpool_cancel_clicked (widget, connectionpool_t); 125 126 return FALSE; 127} 128 129 130BOOL 131create_connectionpool (HWND hwnd, TCONNECTIONPOOLING *choose_t) 132{ 133 GtkWidget *connectionpool, *dialog_vbox1, *fixed1, *l_question; 134 GtkWidget *t_cptimeout, *dialog_action_area1, *hbuttonbox1; 135 GtkWidget *t_probe, *l_time, *l_probe; 136 GtkWidget *b_finish, *b_cancel; 137 guint b_finish_key, b_cancel_key; 138 GtkAccelGroup *accel_group; 139 char msg[1024]; 140 141 if (hwnd == NULL || !GTK_IS_WIDGET (hwnd) || !choose_t) 142 return FALSE; 143 144 accel_group = gtk_accel_group_new (); 145 146 connectionpool = gtk_dialog_new (); 147 gtk_object_set_data (GTK_OBJECT (connectionpool), "connectionpool", 148 connectionpool); 149 gtk_window_set_title (GTK_WINDOW (connectionpool), "Connection pooling attributes"); 150 gtk_window_set_position (GTK_WINDOW (connectionpool), GTK_WIN_POS_CENTER); 151 gtk_window_set_modal (GTK_WINDOW (connectionpool), TRUE); 152 gtk_window_set_policy (GTK_WINDOW (connectionpool), FALSE, FALSE, FALSE); 153 154#if GTK_CHECK_VERSION(2,0,0) 155 gtk_widget_show (connectionpool); 156#endif 157 158 dialog_vbox1 = GTK_DIALOG (connectionpool)->vbox; 159 gtk_object_set_data (GTK_OBJECT (connectionpool), "dialog_vbox1", 160 dialog_vbox1); 161 gtk_widget_show (dialog_vbox1); 162 163 fixed1 = gtk_fixed_new (); 164 gtk_widget_ref (fixed1); 165 gtk_object_set_data_full (GTK_OBJECT (connectionpool), "fixed1", fixed1, 166 (GtkDestroyNotify) gtk_widget_unref); 167 gtk_widget_show (fixed1); 168 gtk_box_pack_start (GTK_BOX (dialog_vbox1), fixed1, TRUE, TRUE, 0); 169 gtk_container_set_border_width (GTK_CONTAINER (fixed1), 6); 170 171 l_question = 172 gtk_label_new 173 ("You have now to specify the connection pooling timeout\nin seconds of the specified driver and probe query"); 174 gtk_widget_ref (l_question); 175 gtk_object_set_data_full (GTK_OBJECT (connectionpool), "l_question", 176 l_question, (GtkDestroyNotify) gtk_widget_unref); 177 gtk_widget_show (l_question); 178 gtk_fixed_put (GTK_FIXED (fixed1), l_question, 8, 8); 179 gtk_widget_set_uposition (l_question, 8, 8); 180#if GTK_CHECK_VERSION(2,0,0) 181 gtk_widget_set_usize (l_question, 376, 36); 182#else 183 gtk_widget_set_usize (l_question, 376, 24); 184#endif 185 gtk_label_set_justify (GTK_LABEL (l_question), GTK_JUSTIFY_LEFT); 186 187 l_time = gtk_label_new ("Timeout:"); 188 gtk_widget_ref (l_time); 189 gtk_object_set_data_full (GTK_OBJECT (connectionpool), "l_time", 190 l_time, (GtkDestroyNotify) gtk_widget_unref); 191 gtk_widget_show (l_time); 192#if GTK_CHECK_VERSION(2,0,0) 193 gtk_fixed_put (GTK_FIXED (fixed1), l_time, 8, 48); 194 gtk_widget_set_uposition (l_time, 8, 48); 195#else 196 gtk_fixed_put (GTK_FIXED (fixed1), l_time, 8, 40); 197 gtk_widget_set_uposition (l_time, 8, 40); 198#endif 199 gtk_widget_set_usize (l_time, 60, 24); 200 gtk_label_set_justify (GTK_LABEL (l_time), GTK_JUSTIFY_RIGHT); 201 202 t_cptimeout = gtk_entry_new (); 203 gtk_widget_ref (t_cptimeout); 204 gtk_object_set_data_full (GTK_OBJECT (connectionpool), "t_cptimeout", 205 t_cptimeout, (GtkDestroyNotify) gtk_widget_unref); 206 gtk_widget_show (t_cptimeout); 207#if GTK_CHECK_VERSION(2,0,0) 208 gtk_fixed_put (GTK_FIXED (fixed1), t_cptimeout, 80, 48); 209 gtk_widget_set_uposition (t_cptimeout, 80, 48); 210#else 211 gtk_fixed_put (GTK_FIXED (fixed1), t_cptimeout, 80, 40); 212 gtk_widget_set_uposition (t_cptimeout, 80, 40); 213#endif 214 gtk_widget_set_usize (t_cptimeout, 300, 22); 215 216 if (choose_t) 217 gtk_entry_set_text (GTK_ENTRY (t_cptimeout), choose_t->timeout); 218 219 l_probe = gtk_label_new ("Query:"); 220 gtk_widget_ref (l_probe); 221 gtk_object_set_data_full (GTK_OBJECT (connectionpool), "l_probe", 222 l_probe, (GtkDestroyNotify) gtk_widget_unref); 223 gtk_widget_show (l_probe); 224#if GTK_CHECK_VERSION(2,0,0) 225 gtk_fixed_put (GTK_FIXED (fixed1), l_probe, 8, 78); 226 gtk_widget_set_uposition (l_probe, 8, 78); 227#else 228 gtk_fixed_put (GTK_FIXED (fixed1), l_probe, 8, 70); 229 gtk_widget_set_uposition (l_probe, 8, 70); 230#endif 231 gtk_widget_set_usize (l_probe, 60, 24); 232 gtk_label_set_justify (GTK_LABEL (l_probe), GTK_JUSTIFY_RIGHT); 233 234 t_probe = gtk_entry_new (); 235 gtk_widget_ref (t_probe); 236 gtk_object_set_data_full (GTK_OBJECT (connectionpool), "t_probe", 237 t_probe, (GtkDestroyNotify) gtk_widget_unref); 238 gtk_widget_show (t_probe); 239#if GTK_CHECK_VERSION(2,0,0) 240 gtk_fixed_put (GTK_FIXED (fixed1), t_probe, 80, 78); 241 gtk_widget_set_uposition (t_probe, 80, 78); 242#else 243 gtk_fixed_put (GTK_FIXED (fixed1), t_probe, 80, 70); 244 gtk_widget_set_uposition (t_probe, 80, 70); 245#endif 246 gtk_widget_set_usize (t_probe, 300, 22); 247 248 if (choose_t) 249 gtk_entry_set_text (GTK_ENTRY (t_probe), choose_t->probe); 250 251 dialog_action_area1 = GTK_DIALOG (connectionpool)->action_area; 252 gtk_object_set_data (GTK_OBJECT (connectionpool), "dialog_action_area1", 253 dialog_action_area1); 254 gtk_widget_show (dialog_action_area1); 255 gtk_container_set_border_width (GTK_CONTAINER (dialog_action_area1), 5); 256 257 hbuttonbox1 = gtk_hbutton_box_new (); 258 gtk_widget_ref (hbuttonbox1); 259 gtk_object_set_data_full (GTK_OBJECT (connectionpool), "hbuttonbox1", 260 hbuttonbox1, (GtkDestroyNotify) gtk_widget_unref); 261 gtk_widget_show (hbuttonbox1); 262 gtk_box_pack_start (GTK_BOX (dialog_action_area1), hbuttonbox1, TRUE, TRUE, 263 0); 264 gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox1), GTK_BUTTONBOX_END); 265 gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbuttonbox1), 10); 266 267 b_finish = gtk_button_new_with_label (""); 268 b_finish_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (b_finish)->child), 269 "_Finish"); 270 gtk_widget_add_accelerator (b_finish, "clicked", accel_group, 271 b_finish_key, GDK_MOD1_MASK, 0); 272 gtk_widget_ref (b_finish); 273 gtk_object_set_data_full (GTK_OBJECT (connectionpool), "b_finish", b_finish, 274 (GtkDestroyNotify) gtk_widget_unref); 275 gtk_widget_show (b_finish); 276 gtk_container_add (GTK_CONTAINER (hbuttonbox1), b_finish); 277 GTK_WIDGET_SET_FLAGS (b_finish, GTK_CAN_DEFAULT); 278 gtk_widget_add_accelerator (b_finish, "clicked", accel_group, 279 'F', GDK_MOD1_MASK, GTK_ACCEL_VISIBLE); 280 281 b_cancel = gtk_button_new_with_label (""); 282 b_cancel_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (b_cancel)->child), 283 "_Cancel"); 284 gtk_widget_add_accelerator (b_cancel, "clicked", accel_group, 285 b_cancel_key, GDK_MOD1_MASK, 0); 286 gtk_widget_ref (b_cancel); 287 gtk_object_set_data_full (GTK_OBJECT (connectionpool), "b_cancel", b_cancel, 288 (GtkDestroyNotify) gtk_widget_unref); 289 gtk_widget_show (b_cancel); 290 gtk_container_add (GTK_CONTAINER (hbuttonbox1), b_cancel); 291 GTK_WIDGET_SET_FLAGS (b_cancel, GTK_CAN_DEFAULT); 292 gtk_widget_add_accelerator (b_cancel, "clicked", accel_group, 293 'C', GDK_MOD1_MASK, GTK_ACCEL_VISIBLE); 294 295 /* Finish button events */ 296 gtk_signal_connect (GTK_OBJECT (b_finish), "clicked", 297 GTK_SIGNAL_FUNC (connectionpool_finish_clicked), choose_t); 298 /* Cancel button events */ 299 gtk_signal_connect (GTK_OBJECT (b_cancel), "clicked", 300 GTK_SIGNAL_FUNC (connectionpool_cancel_clicked), choose_t); 301 /* Close window button events */ 302 gtk_signal_connect (GTK_OBJECT (connectionpool), "delete_event", 303 GTK_SIGNAL_FUNC (delete_event), choose_t); 304 gtk_signal_connect (GTK_OBJECT (connectionpool), "destroy", 305 GTK_SIGNAL_FUNC (gtk_main_quit), NULL); 306 307 gtk_window_add_accel_group (GTK_WINDOW (connectionpool), accel_group); 308 309 choose_t->timeout_entry = t_cptimeout; 310 choose_t->probe_entry = t_probe; 311 choose_t->mainwnd = connectionpool; 312 313 gtk_widget_show_all (connectionpool); 314 gtk_main (); 315 316 return choose_t->changed; 317} 318