⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 callbacks.c

📁 SIP(Session Initiation Protocol)是由IETF定义
💻 C
📖 第 1 页 / 共 2 页
字号:
  gtk_widget_set_sensitive(talk_button, FALSE);  gtk_object_set(GTK_OBJECT(talk_button), "GtkButton::label", (gchar*)TALK, NULL);  gtk_tooltips_set_tip(GTK_TOOLTIPS(tooltips), talk_button, "Make a call", NULL);  gtk_tooltips_set_tip (GTK_TOOLTIPS(tooltips), dial_entry, _("Enter SIP URI or Phone Number"), NULL);  set_state (INACTIVE);#ifdef USE_MPEGLIB  if(mediaStartFlg)  {      Video_stop();      Player_stop();      mediaStartFlg = 0;  }#endif}voidgtk_container_remove_callback(gpointer child, gpointer data){  gtk_container_remove (GTK_CONTAINER (register_eventbox), GTK_WIDGET(child));}voidset_name(){  GtkWidget *name_label = lookup_widget(main_window, "name_label");  char *name = get_advanced_config_value(DISPLAY_NAME);  if( (name == NULL) || (strlen(name) == 0) )  {    name = get_basic_config_value(USER_NAME);  }  gtk_label_set_text(GTK_LABEL(name_label), name);}voidset_registered(int isRegistered){  char register_tooltip[100];  char *user_name = get_basic_config_value(USER_NAME);  GList *children = gtk_container_children(GTK_CONTAINER(register_eventbox));  g_list_foreach(children, gtk_container_remove_callback, NULL);  if (isRegistered)  {    gtk_widget_show (registered_pixmap);    gtk_container_add (GTK_CONTAINER (register_eventbox), registered_pixmap);    /* set tooltip for register pixmap */    sprintf(register_tooltip, "user %s is registered", user_name);  }  else  {    gtk_widget_show (unregistered_pixmap);    gtk_container_add (GTK_CONTAINER (register_eventbox), unregistered_pixmap);    gtk_tooltips_set_tip(GTK_TOOLTIPS(tooltips), register_eventbox, "Unregistered", NULL);    /* set tooltip for name label */    sprintf(register_tooltip, "user %s is not registered", user_name);  }  /* only put the user name in the tooltip if there is a user name */  if( (user_name == NULL) || (strlen(user_name) > 0) )  {    gtk_tooltips_set_tip(GTK_TOOLTIPS(tooltips), register_eventbox, register_tooltip, NULL);  }  else  {    gtk_tooltips_set_tip(GTK_TOOLTIPS(tooltips), register_eventbox, "No user name to register", NULL);  }}/* called by reader*/voidprocess_input(gchar *input_buf){  GtkWidget *logger = lookup_widget (log_dialog, "log_text");  GtkWidget *message_entry = lookup_widget (main_window, "message_entry");  char *command;  char *the_rest;  guint text_length;  /* for now, always put full text into message window */  text_length = gtk_text_get_length(GTK_TEXT(logger));  gtk_text_set_point(GTK_TEXT(logger), text_length);  gtk_text_insert (GTK_TEXT(logger), NULL, NULL, NULL, input_buf, strlen(input_buf));  gtk_text_insert (GTK_TEXT(logger), NULL, NULL, NULL, "\n", 1);  /* the first token is the command */  command = strtok(input_buf, " ");  /*printf ("received command: %s\n", command);*/  /* the rest is the message for log window */  the_rest = input_buf+(strlen(command));  the_rest = strchr(input_buf, '\0');  the_rest++;  /*  {    text_length = gtk_text_get_length(GTK_TEXT(logger));    gtk_text_set_point(GTK_TEXT(logger), text_length);    gtk_text_insert (GTK_TEXT(logger), NULL, NULL, NULL,                     the_rest, strlen(the_rest));    gtk_text_insert (GTK_TEXT(logger), NULL, NULL, NULL, "\n\n", 2);    }  */  if (strcmp(command, UA_REGISTERED_STR) == 0)  {    set_registered(TRUE);  }  else if (strcmp(command, UA_INFO_STR) == 0)  {    /* do nothing */  }  else if (strcmp(command, UA_RINGING_STR) == 0)  {    gtk_entry_set_text(GTK_ENTRY(message_entry), UA_RINGING_STR);    if (state == INACTIVE)    {      GtkWidget *label;      char display_string[50];      if (current_call != NULL)      {        free (current_call);      }      current_call = strdup(the_rest);      set_state(INCOMING_REQUEST);      incoming_call_dialog = create_incoming_call_dialog();      /* get incoming_call_label*/      label = lookup_widget(incoming_call_dialog, "incoming_call_label");      sprintf(display_string, "You have a call from %s", current_call);      gtk_label_set_text(GTK_LABEL(label), display_string);      gtk_widget_show(incoming_call_dialog);    }  }  else if (strcmp(command, UA_TRYING_STR ) == 0)  {    /* enable the Talk button*/    GtkWidget *talk_button = lookup_widget (main_window, "talk_button");    gtk_widget_set_sensitive(talk_button, TRUE);    gtk_entry_set_text(GTK_ENTRY(message_entry), UA_TRYING_STR);  }  else if (strcmp(command, UA_REDIRECT_STR ) == 0)  {    /* enable the Talk button*/    GtkWidget *talk_button = lookup_widget (main_window, "talk_button");    gtk_widget_set_sensitive(talk_button, TRUE);    gtk_entry_set_text(GTK_ENTRY(message_entry), UA_REDIRECT_STR);  }  else if(strcmp(command, UA_INCALL_STR ) == 0)  {    gtk_entry_set_text(GTK_ENTRY(message_entry), UA_INCALL_STR);    start_media();  }   else if(strcmp(command, UA_R_HOLD_STR ) == 0)  {    gtk_entry_set_text(GTK_ENTRY(message_entry), UA_R_HOLD_STR);  }  else if(strcmp(command, UA_R_RESUME_STR ) == 0)  {    gtk_entry_set_text(GTK_ENTRY(message_entry), UA_R_RESUME_STR);  }  else if(strcmp(command, UA_STOP_STR ) == 0)  {    gtk_entry_set_text(GTK_ENTRY(message_entry), "STOP CALL");    hangup_the_phone();  }  else if(strcmp(command, UA_ERROR_STR ) == 0)  {    GtkWidget *error_dialog = create_error_dialog();    GtkWidget *error_label = lookup_widget (error_dialog, "error_label");    GtkWidget *talk_button = lookup_widget (main_window, "talk_button");    hangup_the_phone();    gtk_label_set_text(GTK_LABEL(error_label), the_rest);    gtk_widget_show(error_dialog);    gtk_entry_set_text(GTK_ENTRY(message_entry), "ERROR");    gtk_widget_set_sensitive(talk_button, TRUE);  }  else if(strcmp(command, UA_BUSY_STR ) == 0)  {    gtk_entry_set_text(GTK_ENTRY(message_entry), "BUSY");  }  else if(strcmp(command, UA_L_HANGUP_STR ) == 0)  {    /* local caller hung up and call has been torn down */    GtkWidget *talk_button = lookup_widget (main_window, "talk_button");    gtk_entry_set_text(GTK_ENTRY(message_entry), "CALL FINISHED (LOCAL HANGUP)");    /* enable the Talk button */    gtk_widget_set_sensitive(GTK_WIDGET(talk_button), TRUE);  }  else if(strcmp(command, UA_R_HANGUP_STR ) == 0)  {    /* remote caller hung up and call has been torn down */    GtkWidget *talk_button = lookup_widget (main_window, "talk_button");    hangup_the_phone();    gtk_entry_set_text(GTK_ENTRY(message_entry), "CALL FINISHED (REMOTE HANGUP)");    /* enable the Talk button */    gtk_widget_set_sensitive(GTK_WIDGET(talk_button), TRUE);  }  else  {    g_message("Error: receive unrecognized command: %s\n", command);  }  }/* callback function for UI_TO_GUI pipe */voidreader (gpointer data, gint source, GdkInputCondition condition){  GtkWidget *message_entry = lookup_widget (main_window, "message_entry");  GIOError error;  gchar *buf = g_new0 (gchar, 3000);  gchar *token;  guint bytes_read;  int i;  static int reads_missed = 0;  error = g_io_channel_read(channel_in, buf, 3000, &bytes_read);  /* stop reading if the UA Controller goes away */  /* give it a few chances to come back first */  if (bytes_read <= 0)  {    reads_missed++;    if (reads_missed > 10)    {      GtkWidget *fatal_error_dialog = create_fatal_error_dialog();      GtkWidget *fatal_error_label = lookup_widget (fatal_error_dialog, "fatal_error_label");      hangup_the_phone();      set_state(FATAL_ERROR);      gtk_input_remove(handle_to_gtk_input_add_full);      gtk_entry_set_text(GTK_ENTRY(message_entry), "PLEASE RESTART");      gtk_label_set_text(GTK_LABEL(fatal_error_label), "Fatal Error. Please restart");      gtk_widget_show(fatal_error_dialog);    }    return;  }  reads_missed = 0;  if (error != G_IO_ERROR_NONE)  {    g_message("error occurred during read from UA: ");    print_error(error);    return;  }  token = buf;  for (i=0; i<bytes_read; i++)  {    if (buf[i] == '|')    {      buf[i] = '\0';      process_input(token);      token = &buf[i+1];    }  }  g_free(buf);}GtkWidget*create_pixmap_d(GtkWidget *window, gchar **data){  GdkColormap *colormap;  GdkPixmap *gdkpixmap;  GdkBitmap *mask;  GtkWidget *pixmap;  colormap = gtk_widget_get_colormap (window);  gdkpixmap = gdk_pixmap_colormap_create_from_xpm_d (NULL, colormap, &mask,                                                   NULL, data);  pixmap = gtk_pixmap_new (gdkpixmap, mask);  gdk_pixmap_unref (gdkpixmap);  gdk_bitmap_unref (mask);  return pixmap;}/* handle termination signals */void fatal_error_signal(int sig){  signal(sig, SIG_DFL);  send_message(GUI_SHUTDOWN_STR);  kill(getpid(), SIGINT);}voidsipset_init(){  char dial_buf[50];  int dial_len = 50;  int items_in_history;  char ua_to_gui_str[100];  char gui_to_ua_str[100];  pid_t pid;  int fd_out, fd_in;  char *config_name = "gua.cfg";  char config_file_path[50], argument[50], location_of_exe[50];  char local_dir[256];  struct stat statbuf;  struct stat stbuf;  int err;  char *home = getenv("HOME");  /* set up configuration */  sprintf(config_file_path, "%s/.sipset", home);  /* VOCAL_INSTALL_PATH comes from vocalconfig.h */  init_config(config_file_path, config_name);  pid = fork();  if (pid == 0)  {    static char *argv[5];    /* this is the child process  */    /* start up the UA Controller */    sprintf(argument, "%s/%s", config_file_path, config_name);    /* for some reason, execv eats argv[0] */    argv[0] = "";    argv[1] = "-g";    argv[2] = "-f";    argv[3] = argument;    argv[4] = NULL;    /* if gua is in the Vocal install dir, then run it from there */    sprintf (location_of_exe, "%s/bin/gua", VOCAL_INSTALL_PATH);    if( (stat(location_of_exe, &stbuf) == 0)       && S_ISREG(stbuf.st_mode))    {      printf ("Starting gua from %s\n", location_of_exe);      execv(location_of_exe, argv);    }    else if( (stat("./gua", &stbuf) == 0 )            && S_ISREG(stbuf.st_mode))    {      printf ("Starting gua from current directory\n");      execv("./gua", argv);    }    else    {      printf("Error: cannot find gua executable\n");      exit(1);    }    _exit;  }  /* figure out where the fifo pipes go */  snprintf(local_dir, 255, "/tmp/sipset.%d", getuid());  local_dir[254] = '\0';  mkdir(local_dir, 0700);  chmod(local_dir, 0700);  err = lstat(local_dir, &statbuf);  if(err)  {      printf("Cannot continue, failed to stat directory: %s",	    strerror(errno));      exit(-1);  }  if(statbuf.st_uid != getuid() ||     statbuf.st_mode != 0040700)  {      printf(	    "Cannot continue, directory %s does not have right permissions", 	    local_dir);      exit(-1);  }  sprintf(ua_to_gui_str, "/tmp/sipset.%d/UaToGui.%d", getuid(), pid);  sprintf(gui_to_ua_str, "/tmp/sipset.%d/GuiToUa.%d", getuid(), pid);  mkfifo(ua_to_gui_str, 0600);  mkfifo(ua_to_gui_str, 0600);  /* this is the parent process */  fd_in = open(ua_to_gui_str, O_RDONLY, 0);  if (fd_in == -1)  {    printf ("cannot open %s for reading!", ua_to_gui_str);    exit(1);  }  fd_out = open(gui_to_ua_str, O_WRONLY, 0);  if (fd_out == -1)  {    printf ("cannot open %s for writing!", ua_to_gui_str);    exit(1);  }  channel_out = g_io_channel_unix_new(fd_out);  channel_in = g_io_channel_unix_new(fd_in);  handle_to_gtk_input_add_full    = gtk_input_add_full(fd_in, GDK_INPUT_READ, reader, NULL, NULL, NULL);  /**** set up dial history ***/  dial_combo = lookup_widget (main_window, "dial_combo");  /**** set up tooltips ***/  tooltips = lookup_widget (main_window, "tooltips");  /*** set up the registration icon ***/  register_eventbox = lookup_widget (main_window, "register_eventbox");  username_eventbox = lookup_widget (main_window, "username_eventbox");  sprintf(dial_history_path, "%s/%s", config_file_path, DIAL_HISTORY);  dial_history = fopen(dial_history_path, "r");  if (dial_history == NULL)  {    if (creat(dial_history_path, 0666) != -1)    {      dial_history = fopen(dial_history_path, "r");    }    else    {      g_message ("Cannot open dial history for reading\n");    }  }  /* ensure that there is a blank space at the top of combo */  dial_items = g_list_append(dial_items, "");  items_in_history = 0;  while (fgets (dial_buf, dial_len, dial_history) != NULL)  {    if (strlen(dial_buf) > 0)    {      char *newline = strchr(dial_buf, '\n');      if (newline != NULL)      {        *newline = '\0';      }      /* ignore blank line */      if (dial_buf[0] != '\0')      {        char *new_number = strdup(dial_buf);        dial_items = g_list_append(dial_items, new_number);        items_in_history++;      }    }  }  fclose(dial_history);    if (items_in_history > 0)  {    dial_items = g_list_sort(dial_items, (GCompareFunc)strcmp);    gtk_combo_set_popdown_strings(GTK_COMBO(dial_combo), dial_items);  }  /* stop pop-up from showing when Enter pressed */  gtk_combo_disable_activate(GTK_COMBO(dial_combo));  /* set up pixmaps */  registered_pixmap = create_pixmap_d (main_window, registered_xpm);  gtk_widget_ref (registered_pixmap);  gtk_object_set_data_full (GTK_OBJECT (main_window), "registered_pixmap", registered_pixmap,                            (GtkDestroyNotify) gtk_widget_unref);  unregistered_pixmap = create_pixmap_d (main_window, unregistered_xpm);  gtk_widget_ref (unregistered_pixmap);  gtk_object_set_data_full (GTK_OBJECT (main_window), "unregistered_pixmap", unregistered_pixmap,                            (GtkDestroyNotify) gtk_widget_unref);  set_name();  set_registered(FALSE); }void on_video_enabled_button (GtkWidget *widget, gpointer *data){/*    MyConfig->SetBoolValue(CONFIG_VIDEO_ENABLE,            gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)));*/}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -