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

📄 recvmsg.c

📁 飞鸽传书的linux源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
  GtkWidget *window;  GtkTextView *text_view;  GtkTextBuffer *buffer;  GtkWidget *SealBtn;  gint len;  GtkWidget *scrolledwindow;  GtkLabel *userlabel;  GtkLabel *timelabel;  GtkWidget *cite_toggle;  ipmsg_private_data_t *priv=NULL;  userdb_t *user_info=NULL;  char label_string[64];  gint width,height;  if ( (!msg) || (!from) )    return NULL;  message=msg->message;  if (!message)    return NULL;  pktno=msg->pkt_seq_no;  flags=msg->command_opts;    convert_string_internal(message,(const gchar **)&internal_message);  if (!internal_message)    return NULL;  dbg_out("Recive_win:%s\n",internal_message);  window=GTK_WIDGET(create_viewWindow ());  timelabel=GTK_LABEL(lookup_widget(window,"viewwindowDateLabel"));  gtk_label_set_text(timelabel,asctime(localtime(&((msg->tv).tv_sec))));  userlabel=GTK_LABEL(lookup_widget(window,"viewwindowUserInfoLabel"));  g_assert(userlabel);  if (!userdb_search_user_by_addr(from,(const userdb_t **)&user_info)) {    g_assert(userlabel);    snprintf(label_string,63,"%s@%s (%s)",user_info->nickname,user_info->group,user_info->host);    label_string[63]='\0';    gtk_label_set_text(userlabel,label_string);    g_assert(!destroy_user_info(user_info));  }else{    gtk_label_set_text(userlabel,refer_user_name_from_msg(msg));  }  cite_toggle=lookup_widget(window,"viewwindowCitationCheck");  g_assert(cite_toggle);  if (hostinfo_refer_ipmsg_default_citation())     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cite_toggle),TRUE);  else    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cite_toggle),FALSE);  text_view=GTK_TEXT_VIEW(lookup_widget(GTK_WIDGET(window),"viewwindowTextView"));  buffer=gtk_text_view_get_buffer(text_view);  len=strlen(internal_message);  gtk_text_buffer_set_text(buffer,internal_message,len);  gtk_widget_set_events (GTK_WIDGET(text_view),GDK_BUTTON_PRESS_MASK);  gtk_signal_connect (GTK_OBJECT (text_view), "button_press_event",		      GTK_SIGNAL_FUNC (on_viewwindowTextView_button_press_event), NULL);  /*   * 添付ファイル   */#if 1  if (!init_recvmsg_private(from,flags,pktno,&priv)) {    dbg_out("Hook private\n");    IPMSG_HOOKUP_DATA(window,priv,"senderInfo");  }#endif  if ((priv) && (flags & IPMSG_FILEATTACHOPT) ){    ipmsg_recvmsg_private_t *element;    dbg_out("This message has attachment:%s\n",msg->extstring);    element=(ipmsg_recvmsg_private_t *)priv->data;    element->ext_part=strdup(msg->extstring);  }  /*   * 封書   */  if (flags & IPMSG_SECRETOPT) {    /*  disable citation  */    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cite_toggle),FALSE);    gtk_widget_set_sensitive(cite_toggle, FALSE);    scrolledwindow=lookup_widget(GTK_WIDGET(window),"scrolledwindow6");    g_assert(scrolledwindow);    if (flags & IPMSG_FILEATTACHOPT)      SealBtn=gtk_button_new_with_label (_("Remove the seal[Attachment]"));    else      SealBtn=gtk_button_new_with_label (_("Remove the seal"));    if (SealBtn){      gtk_container_remove(GTK_CONTAINER (scrolledwindow), GTK_WIDGET(text_view));      dbg_out("Seal set\n");      gtk_widget_show (SealBtn);      gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolledwindow), SealBtn);      g_signal_connect ((gpointer) SealBtn, "clicked",                    G_CALLBACK (on_sealBtn_clicked),                    NULL);      g_signal_connect ((gpointer) SealBtn, "destroy",                    G_CALLBACK (on_sealBtn_destroy),			NULL);      GLADE_HOOKUP_OBJECT (window, SealBtn, "SealBtn");    }  }  g_free(internal_message);  /*   *ウィンドウサイズ復元   */  if (!hostinfo_get_ipmsg_recv_window_size(&width,&height)){    dbg_out("Resize:(%d,%d)\n",width,height);    gtk_window_resize (GTK_WINDOW(window),width,height);  }  return window;}static voidprint_one_window(gpointer data,gpointer user_data) {  if (!data)    return;  dbg_out("stored window: %x\n",(unsigned int)data);  return;}static voidlistup_current_stored_windows(void){  g_static_mutex_lock(&store_win_mutex);  g_list_foreach(store_wins,		 print_one_window,		 NULL);  g_static_mutex_unlock(&store_win_mutex);}static voidshow_one_window(gpointer data,gpointer user_data) {  int rc;  GtkWidget *top;  GtkWidget *download_window;  ipmsg_private_data_t *private;  ipmsg_recvmsg_private_t *sender_info;  if (!data)    return;  top=GTK_WIDGET(data);  dbg_out("show stored window: %x\n",(unsigned int)top);  private=(ipmsg_private_data_t *)lookup_widget(GTK_WIDGET(top),"senderInfo"  );  IPMSG_ASSERT_PRIVATE(private,IPMSG_PRIVATE_RECVMSG);  sender_info=private->data;  g_assert(sender_info);  /* ダウンロードウィンドウ生成    */  if ((!(sender_info->flags & IPMSG_SECRETOPT))  &&      (sender_info->flags & IPMSG_FILEATTACHOPT) &&      (sender_info->ext_part)){    dbg_out("This message has attachment\n");     rc=internal_create_download_window(top,&download_window);    if (!rc) {      g_assert (download_window);      append_displayed_window(download_window);      gtk_widget_show (download_window);    }else{      err_out("Can not create download window %s (%d)\n",strerror(-rc),rc);    }  }  if (!(sender_info->flags & IPMSG_SECRETOPT)) {    append_opened_window(top);  }  append_displayed_window(top);  gtk_widget_show (top);  play_sound();  return;}voidshow_stored_windows(void) {  g_static_mutex_lock(&store_win_mutex);  g_list_foreach(store_wins,		 show_one_window,		 NULL);    g_list_free(store_wins);  store_wins=NULL;  g_static_mutex_unlock(&store_win_mutex);}voidstore_message_window(const msg_data_t *msg,const char *from){  GtkWidget *window;  GtkWidget *textview1;  window=internal_create_recv_message_window(msg,from);  if (window) {    g_static_mutex_lock(&store_win_mutex);    store_wins=g_list_append(store_wins,window);    g_static_mutex_unlock(&store_win_mutex);    listup_current_stored_windows();  }}gboolean recv_windows_are_stored(void) {  GList *first;  g_static_mutex_lock(&store_win_mutex);  first=g_list_first(store_wins);  g_static_mutex_unlock(&store_win_mutex);  if (first)    return TRUE;  return FALSE;}voidrecv_message_window(const msg_data_t *msg,const char *from){  int rc;  GtkWidget *window;  GtkWidget *text_view;  GtkWidget *download_window;  ipmsg_private_data_t *private;  ipmsg_recvmsg_private_t *sender_info;  if ( (!msg) || (!from) )    return;  window=internal_create_recv_message_window(msg,from);  if (window) {    private=(ipmsg_private_data_t *)lookup_widget(GTK_WIDGET(window),"senderInfo"  );    IPMSG_ASSERT_PRIVATE(private,IPMSG_PRIVATE_RECVMSG);    sender_info=private->data;    /* 封書でなければここでダウンロードウィンドウ生成    */    if ( (!(sender_info->flags & IPMSG_SECRETOPT))  &&	(sender_info->flags & IPMSG_FILEATTACHOPT) && 	(sender_info->ext_part)){      dbg_out("This message has attachment\n");       rc=internal_create_download_window(window,&download_window);      if (!rc) {	g_assert (download_window);	gtk_widget_show (download_window);	append_displayed_window(download_window);      }else{	err_out("Can not create download window %s (%d)\n",strerror(-rc),rc);      }    }    if (!(sender_info->flags & IPMSG_SECRETOPT)) {      append_opened_window(window);      text_view=lookup_widget(window,"viewwindowTextView");    }    gtk_widget_show (window);    append_displayed_window(window);    play_sound();  }}voidread_message_dialog(const gchar *user,const gchar *ipaddr, long sec){  GtkWidget *dialog;  GtkLabel *userlabel;  GtkLabel *timelabel;  userdb_t *user_info=NULL;  char buffer[64];  dbg_out("here\n");  dialog=GTK_WIDGET(create_readNotifyDialog ());  userlabel=GTK_LABEL(lookup_widget(dialog,"readNotifyDialogUserGroupLabel"));  if ( (user) && (ipaddr) ) {    if (!userdb_search_user_by_addr(ipaddr,(const userdb_t **)&user_info)) {	  g_assert(userlabel);	  snprintf(buffer,63,"%s@%s (%s)",user_info->nickname,user_info->group,user_info->host);	  buffer[63]='\0';	  gtk_label_set_text(userlabel,buffer);	  g_assert(!destroy_user_info(user_info));    }else{      gtk_label_set_text(userlabel,user);    }    g_free((gchar *)user);  }else    gtk_label_set_text(userlabel,(_("UnKnown")));  timelabel=GTK_LABEL(lookup_widget(dialog,"readNotifyLogonIPAddrLabel"));  gtk_label_set_text(timelabel,asctime(localtime(&sec)));  gtk_widget_show (dialog);}int append_opened_window(GtkWidget *window) {  g_assert(window);  dbg_out("Append openlist:%x\n",(unsigned int)window);  g_static_mutex_lock(&openwin_mutex);  opened_wins=g_list_append(opened_wins,window);  g_static_mutex_unlock(&openwin_mutex);  return 0;}int destroy_all_opened_windows(void) {  GList *node;  GtkWidget *window;  g_static_mutex_lock(&openwin_mutex);  while((node=g_list_first (opened_wins))) {    window=node->data;    g_assert(window);    opened_wins=g_list_remove (opened_wins,node);   /*  参照のみなのでここではデータは開放しない  */    g_static_mutex_unlock(&openwin_mutex);    gtk_widget_destroy(window);    g_static_mutex_lock(&openwin_mutex);  }  g_static_mutex_unlock(&openwin_mutex);  return 0;}intremove_window_from_openlist(GtkWidget *window){  g_static_mutex_lock(&openwin_mutex);  dbg_out("Remove %x from openlist\n",(unsigned int)window);  /*  参照のみなのでここではデータは開放しない  */  opened_wins=g_list_remove(opened_wins,window);  g_static_mutex_unlock(&openwin_mutex);    return 0;}int append_displayed_window(GtkWidget *window) {  g_assert(window);  dbg_out("Append displayed windows list:%x\n",(unsigned int)window);  g_static_mutex_lock(&displayedwin_mutex);  if (g_list_find(displayed_wins,window)) {    dbg_out("Already exist %x\n",(unsigned int)window);    goto unlock_out;  }  displayed_wins=g_list_append(displayed_wins,window); unlock_out:  g_static_mutex_unlock(&displayedwin_mutex);  return 0;}intremove_window_from_displaylist(GtkWidget *window){  g_static_mutex_lock(&displayedwin_mutex);  dbg_out("Remove %x from displaylist\n",(unsigned int)window);  if (g_list_find(displayed_wins,window))   /*  参照のみなのでここではデータは開放しない  */    displayed_wins=g_list_remove(displayed_wins,window);  g_static_mutex_unlock(&displayedwin_mutex);    return 0;}voidpresent_all_displayed_windows(void) {  GList *node;  GtkWidget *window;  g_static_mutex_lock(&displayedwin_mutex);  for(node=g_list_first (displayed_wins);      node;      node=g_list_next (node)) {    window=node->data;    g_assert(window);    gtk_window_present (GTK_WINDOW(window));  }  g_static_mutex_unlock(&displayedwin_mutex);  return ;}static voidon_pixmap_destroy(GtkObject *object, gpointer user_data){  //  dbg_out("here %x\n",object);}static GtkWidget*lookup_widget_with_applet(GtkWidget       *widget,			  const gchar     *widget_name) {  GtkWidget *found_widget;  found_widget = (GtkWidget*) g_object_get_data (G_OBJECT (widget),                                                 widget_name);  if (!found_widget)    found_widget=lookup_widget(widget,widget_name);  if (!found_widget)    g_warning ("Widget not found: %s", widget_name);  return found_widget;}static gboolean message_watcher(gpointer data) {  static gboolean is_normal=TRUE;  GtkWidget *init_win=data;  GtkWidget *new_image;  GtkWidget *startBtn;  GtkWidget *current_image;  if ( (is_normal) &&        (!recv_windows_are_stored()) &&        (!hostinfo_is_ipmsg_absent()) )    return TRUE;  if ( (!is_normal) &&        (!recv_windows_are_stored()) &&        (hostinfo_is_ipmsg_absent()) )    return TRUE;  g_source_remove (init_win_timer_id);  g_assert(init_win);  current_image=lookup_widget_with_applet(init_win,"image3");  g_assert(current_image);  startBtn = lookup_widget_with_applet(init_win,"startBtn");  g_assert(startBtn);  g_assert(normal_image);  g_assert(reverse_image);  if  (!is_normal) {    new_image=normal_image;    is_normal=TRUE;  }else{    new_image=reverse_image;    is_normal=FALSE;  }  g_signal_connect ((gpointer) current_image, "destroy",                    G_CALLBACK (on_pixmap_destroy),NULL);  gtk_widget_show (new_image);  //dbg_out("remove:%x\n",current_image);  gtk_container_remove (GTK_CONTAINER (startBtn), current_image);  gtk_container_add (GTK_CONTAINER (startBtn), new_image);  //dbg_out("new object relation:%x => %x\n",current_image,new_image);  GLADE_HOOKUP_OBJECT (init_win, new_image, "image3");  init_win_timer_id=g_timeout_add(MSG_WATCH_INTERVAL,message_watcher,init_win);    return TRUE; }intstart_message_watcher(GtkWidget *init_win){  if (!init_win)    return -EINVAL;  normal_image = create_pixmap (init_win, "g2ipmsg/ipmsg.xpm");  reverse_image = create_pixmap (init_win, "g2ipmsg/ipmsgrev.xpm");  g_assert(normal_image);  g_assert(reverse_image);  gtk_widget_ref (normal_image);  gtk_widget_ref (reverse_image);  dbg_out("Start message watcher \n");  init_win_timer_id=g_timeout_add(MSG_WATCH_INTERVAL,message_watcher,init_win);  return 0;}intcleanup_message_watcher(void){  dbg_out("End message watcher \n");  gtk_widget_unref (normal_image);  gtk_widget_unref (reverse_image);  g_source_remove (init_win_timer_id);  dbg_out("Cleanuped message watcher \n");  return 0;}

⌨️ 快捷键说明

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