loginbox.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /*
  2. * loginbox.c
  3. *
  4. * $Id$
  5. *
  6. * The iODBC driver manager.
  7. *
  8. * Copyright (C) 1996-2021 OpenLink Software <[email protected]>
  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. #include "gui.h"
  75. static void
  76. login_ok_clicked (GtkWidget *widget, TLOGIN *log_t)
  77. {
  78. if (log_t)
  79. {
  80. log_t->user = (char *) malloc (sizeof (char) *
  81. (STRLEN (gtk_entry_get_text (GTK_ENTRY (log_t->username))) + 1));
  82. log_t->pwd = (char *) malloc (sizeof (char) *
  83. (STRLEN (gtk_entry_get_text (GTK_ENTRY (log_t->password))) + 1));
  84. if (log_t->user)
  85. strcpy (log_t->user,
  86. gtk_entry_get_text (GTK_ENTRY (log_t->username)));
  87. if (log_t->pwd)
  88. strcpy (log_t->pwd, gtk_entry_get_text (GTK_ENTRY (log_t->password)));
  89. log_t->username = log_t->password = NULL;
  90. log_t->ok = TRUE;
  91. gtk_signal_disconnect_by_func (GTK_OBJECT (log_t->mainwnd),
  92. GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
  93. gtk_main_quit ();
  94. gtk_widget_destroy (log_t->mainwnd);
  95. }
  96. }
  97. static void
  98. login_cancel_clicked (GtkWidget *widget, TLOGIN *log_t)
  99. {
  100. if (log_t)
  101. {
  102. log_t->user = log_t->pwd = NULL;
  103. log_t->username = log_t->password = NULL;
  104. log_t->ok = FALSE;
  105. gtk_signal_disconnect_by_func (GTK_OBJECT (log_t->mainwnd),
  106. GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
  107. gtk_main_quit ();
  108. gtk_widget_destroy (log_t->mainwnd);
  109. }
  110. }
  111. static gint
  112. delete_event (GtkWidget *widget, GdkEvent *event, TLOGIN *log_t)
  113. {
  114. login_cancel_clicked (widget, log_t);
  115. return FALSE;
  116. }
  117. void
  118. create_login (HWND hwnd, LPCSTR username, LPCSTR password, LPCSTR dsn,
  119. TLOGIN *log_t)
  120. {
  121. GtkWidget *login;
  122. GtkWidget *dialog_vbox8;
  123. GtkWidget *frame99;
  124. GtkWidget *alignment83;
  125. GtkWidget *table9;
  126. GtkWidget *label165;
  127. GtkWidget *t_user;
  128. GtkWidget *t_password;
  129. GtkWidget *label164;
  130. GtkWidget *dialog_action_area8;
  131. GtkWidget *b_ok;
  132. GtkWidget *b_cancel;
  133. char buff[1024];
  134. if (hwnd == (HWND) - 1L)
  135. {
  136. gtk_init (0, NULL);
  137. hwnd = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  138. }
  139. if (hwnd == NULL || !GTK_IS_WIDGET (hwnd))
  140. return;
  141. login = gtk_dialog_new ();
  142. gtk_widget_set_name (login, "login");
  143. gtk_widget_set_size_request (login, 400, 150);
  144. sprintf (buff, "Login for DSN %s ...", (dsn) ? dsn : "Unknown");
  145. gtk_window_set_title (GTK_WINDOW (login), buff);
  146. gtk_window_set_position (GTK_WINDOW (login), GTK_WIN_POS_CENTER);
  147. gtk_window_set_modal (GTK_WINDOW (login), TRUE);
  148. gtk_window_set_default_size (GTK_WINDOW (login), 400, 150);
  149. gtk_window_set_type_hint (GTK_WINDOW (login), GDK_WINDOW_TYPE_HINT_DIALOG);
  150. #if GTK_CHECK_VERSION(2,0,0)
  151. gtk_widget_show (login);
  152. #endif
  153. dialog_vbox8 = GTK_DIALOG (login)->vbox;
  154. gtk_widget_set_name (dialog_vbox8, "dialog_vbox8");
  155. gtk_widget_show (dialog_vbox8);
  156. frame99 = gtk_frame_new (NULL);
  157. gtk_widget_set_name (frame99, "frame99");
  158. gtk_widget_show (frame99);
  159. gtk_box_pack_start (GTK_BOX (dialog_vbox8), frame99, TRUE, TRUE, 0);
  160. gtk_frame_set_shadow_type (GTK_FRAME (frame99), GTK_SHADOW_NONE);
  161. alignment83 = gtk_alignment_new (0.5, 0.5, 1, 1);
  162. gtk_widget_set_name (alignment83, "alignment83");
  163. gtk_widget_show (alignment83);
  164. gtk_container_add (GTK_CONTAINER (frame99), alignment83);
  165. gtk_alignment_set_padding (GTK_ALIGNMENT (alignment83), 4, 0, 6, 7);
  166. table9 = gtk_table_new (2, 2, FALSE);
  167. gtk_widget_set_name (table9, "table9");
  168. gtk_widget_show (table9);
  169. gtk_container_add (GTK_CONTAINER (alignment83), table9);
  170. gtk_table_set_row_spacings (GTK_TABLE (table9), 10);
  171. gtk_table_set_col_spacings (GTK_TABLE (table9), 6);
  172. label165 = gtk_label_new (_("Password :"));
  173. gtk_widget_set_name (label165, "label165");
  174. gtk_widget_show (label165);
  175. gtk_table_attach (GTK_TABLE (table9), label165, 0, 1, 1, 2,
  176. (GtkAttachOptions) (GTK_FILL),
  177. (GtkAttachOptions) (0), 0, 0);
  178. gtk_misc_set_alignment (GTK_MISC (label165), 0, 0.5);
  179. t_user = gtk_entry_new ();
  180. gtk_widget_set_name (t_user, "t_user");
  181. gtk_widget_show (t_user);
  182. gtk_table_attach (GTK_TABLE (table9), t_user, 1, 2, 0, 1,
  183. (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
  184. (GtkAttachOptions) (0), 0, 0);
  185. if (username && STRLEN (username))
  186. gtk_entry_set_text (GTK_ENTRY (t_user), username);
  187. t_password = gtk_entry_new ();
  188. gtk_widget_set_name (t_password, "t_password");
  189. gtk_widget_show (t_password);
  190. gtk_table_attach (GTK_TABLE (table9), t_password, 1, 2, 1, 2,
  191. (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
  192. (GtkAttachOptions) (0), 0, 0);
  193. gtk_entry_set_visibility (GTK_ENTRY (t_password), FALSE);
  194. if (password && STRLEN (password))
  195. gtk_entry_set_text (GTK_ENTRY (t_password), password);
  196. label164 = gtk_label_new (_("Username :"));
  197. gtk_widget_set_name (label164, "label164");
  198. gtk_widget_show (label164);
  199. gtk_table_attach (GTK_TABLE (table9), label164, 0, 1, 0, 1,
  200. (GtkAttachOptions) (GTK_FILL),
  201. (GtkAttachOptions) (0), 0, 0);
  202. gtk_misc_set_alignment (GTK_MISC (label164), 0, 0.5);
  203. dialog_action_area8 = GTK_DIALOG (login)->action_area;
  204. gtk_widget_set_name (dialog_action_area8, "dialog_action_area8");
  205. gtk_widget_show (dialog_action_area8);
  206. gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area8), GTK_BUTTONBOX_END);
  207. b_cancel = gtk_button_new_from_stock ("gtk-cancel");
  208. gtk_widget_set_name (b_cancel, "b_cancel");
  209. gtk_widget_show (b_cancel);
  210. gtk_dialog_add_action_widget (GTK_DIALOG (login), b_cancel, GTK_RESPONSE_CANCEL);
  211. GTK_WIDGET_SET_FLAGS (b_cancel, GTK_CAN_DEFAULT);
  212. b_ok = gtk_button_new_from_stock ("gtk-ok");
  213. gtk_widget_set_name (b_ok, "b_ok");
  214. gtk_widget_show (b_ok);
  215. gtk_dialog_add_action_widget (GTK_DIALOG (login), b_ok, GTK_RESPONSE_OK);
  216. GTK_WIDGET_SET_FLAGS (b_ok, GTK_CAN_DEFAULT);
  217. /* Store pointers to all widgets, for use by lookup_widget(). */
  218. GLADE_HOOKUP_OBJECT_NO_REF (login, login, "login");
  219. GLADE_HOOKUP_OBJECT_NO_REF (login, dialog_vbox8, "dialog_vbox8");
  220. GLADE_HOOKUP_OBJECT (login, frame99, "frame99");
  221. GLADE_HOOKUP_OBJECT (login, alignment83, "alignment83");
  222. GLADE_HOOKUP_OBJECT (login, table9, "table9");
  223. GLADE_HOOKUP_OBJECT (login, label165, "label165");
  224. GLADE_HOOKUP_OBJECT (login, t_user, "t_user");
  225. GLADE_HOOKUP_OBJECT (login, t_password, "t_password");
  226. GLADE_HOOKUP_OBJECT (login, label164, "label164");
  227. GLADE_HOOKUP_OBJECT_NO_REF (login, dialog_action_area8, "dialog_action_area8");
  228. GLADE_HOOKUP_OBJECT (login, b_ok, "b_ok");
  229. GLADE_HOOKUP_OBJECT (login, b_cancel, "b_cancel");
  230. /* Ok button events */
  231. gtk_signal_connect (GTK_OBJECT (b_ok), "clicked",
  232. GTK_SIGNAL_FUNC (login_ok_clicked), log_t);
  233. /* Cancel button events */
  234. gtk_signal_connect (GTK_OBJECT (b_cancel), "clicked",
  235. GTK_SIGNAL_FUNC (login_cancel_clicked), log_t);
  236. /* Close window button events */
  237. gtk_signal_connect (GTK_OBJECT (login), "delete_event",
  238. GTK_SIGNAL_FUNC (delete_event), log_t);
  239. gtk_signal_connect (GTK_OBJECT (login), "destroy",
  240. GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
  241. log_t->username = t_user;
  242. log_t->password = t_password;
  243. log_t->user = log_t->pwd = NULL;
  244. log_t->mainwnd = login;
  245. gtk_widget_show_all (login);
  246. gtk_main ();
  247. }