home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / yagirc-0.51.tar.gz / yagirc-0.51.tar / yagirc-0.51 / gui_connect.c < prev    next >
C/C++ Source or Header  |  1998-05-09  |  4KB  |  152 lines

  1. /*
  2.  
  3.  gui_connect.c : Connect server dialog
  4.  
  5.     Copyright (C) 1998 Timo Sirainen
  6.  
  7.     This program is free software; you can redistribute it and/or modify
  8.     it under the terms of the GNU General Public License as published by
  9.     the Free Software Foundation; either version 2 of the License, or
  10.     (at your option) any later version.
  11.  
  12.     This program is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.  
  17.     You should have received a copy of the GNU General Public License
  18.     along with this program; if not, write to the Free Software
  19.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21.  
  22. #include <stdio.h>
  23. #include <string.h>
  24.  
  25. #include <glib.h>
  26.  
  27. #include "os.h"
  28. #include "gui.h"
  29. #include "irc.h"
  30. #include "commands.h"
  31.  
  32. static GtkWidget *servdlg = NULL;
  33. static int doubleclick;
  34.  
  35. /* signal: cancel button pressed */
  36. static void sig_cancel(GtkWidget *dialog)
  37. {
  38.     servdlg = NULL;
  39.  
  40.     gui_setup_deinit();
  41.     gui_setup_init();
  42.  
  43.     gui_read_config();
  44.     gtk_widget_destroy(dialog);
  45. }
  46.  
  47. /* signal: close button pressed */
  48. static void sig_close(GtkWidget *dialog)
  49. {
  50.     servdlg = NULL;
  51.     gui_write_config();
  52.     gtk_widget_destroy(dialog);
  53. }
  54.  
  55. /* signal: connect button pressed */
  56. static void sig_connect(GtkWidget *dialog)
  57. {
  58.     GtkList *list;
  59.     char *data;
  60.  
  61.     data = NULL;
  62.     list = gtk_object_get_data(GTK_OBJECT(servdlg), "list");
  63.     if (list->selection != NULL)
  64.     {
  65.         SETUP_SERVER_REC *server;
  66.  
  67.         server = gtk_object_get_data(GTK_OBJECT(list->selection->data), "server");
  68.         data = g_strdup(server->name);
  69.     }
  70.     /*sig_close(dialog);*/
  71.  
  72.     if (data != NULL)
  73.     {
  74.         char *tmp;
  75.  
  76.         tmp = (char *) g_malloc(strlen(data)+10);
  77.         sprintf(tmp, "SERVER %s", data);
  78.         irccmd_window(tmp);
  79.         g_free(data); g_free(tmp);
  80.     }
  81. }
  82.  
  83. /* signal: mouse button pressed */
  84. static void sig_mousedown(GtkList *list, GdkEventButton *event, GtkWidget *dialog)
  85. {
  86.     if (event->button == 1)
  87.     {
  88.         if (!doubleclick)
  89.             doubleclick = 1;
  90.         else
  91.         {
  92.             doubleclick = 0;
  93.             sig_connect(dialog);
  94.         }
  95.     }
  96. }
  97.  
  98. /* signal: mouse button released */
  99. static void sig_mouseup(GtkList *list, GdkEventButton *event)
  100. {
  101.     if (event->button == 1)
  102.     {
  103.         doubleclick = 0;
  104.     }
  105. }
  106.  
  107. void gui_connect_dialog(void)
  108. {
  109.     GtkWidget *button;
  110.     GtkWidget *list;
  111.  
  112.     if (servdlg != NULL)
  113.     {
  114.         /* server dialog already created */
  115.         gdk_window_raise(servdlg->window);
  116.         return;
  117.     }
  118.     doubleclick = 0;
  119.  
  120.     servdlg = gtk_dialog_new();
  121.     gtk_widget_set_usize(servdlg, 300, 200);
  122.     gtk_signal_connect_object (GTK_OBJECT (servdlg), "delete_event",
  123.                                GTK_SIGNAL_FUNC (sig_cancel), GTK_OBJECT(servdlg));
  124.  
  125.     list = create_local_servers(GTK_DIALOG(servdlg)->vbox, TRUE);
  126.     gtk_object_set_data(GTK_OBJECT(servdlg), "list", list);
  127.     gtk_signal_connect (GTK_OBJECT (list), "button_press_event",
  128.                         GTK_SIGNAL_FUNC(sig_mousedown), servdlg);
  129.     gtk_signal_connect (GTK_OBJECT (list), "button_release_event",
  130.                         GTK_SIGNAL_FUNC(sig_mouseup), servdlg);
  131.  
  132.     button = gtk_button_new_with_label (_("Close"));
  133.     gtk_box_pack_start (GTK_BOX (GTK_DIALOG(servdlg)->action_area), button, TRUE, TRUE, 10);
  134.     gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
  135.                                GTK_SIGNAL_FUNC (sig_close), GTK_OBJECT(servdlg));
  136.     gtk_widget_show (button);
  137.  
  138.     button = gtk_button_new_with_label (_("Connect"));
  139.     gtk_box_pack_start (GTK_BOX (GTK_DIALOG(servdlg)->action_area), button, TRUE, TRUE, 10);
  140.     gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
  141.                                GTK_SIGNAL_FUNC (sig_connect), GTK_OBJECT(servdlg));
  142.     gtk_widget_show (button);
  143.  
  144.     button = gtk_button_new_with_label (_("Cancel"));
  145.     gtk_box_pack_start (GTK_BOX (GTK_DIALOG(servdlg)->action_area), button, TRUE, TRUE, 10);
  146.     gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
  147.                                GTK_SIGNAL_FUNC (sig_cancel), GTK_OBJECT(servdlg));
  148.     gtk_widget_show (button);
  149.  
  150.     gtk_widget_show(servdlg);
  151. }
  152.