?? recvmsg.c
字號:
/* * Copyright (C) 2006 Takeharu KATO * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */#ifdef HAVE_CONFIG_H# include <config.h>#endif#include <stdio.h>#include <stdlib.h>#include <string.h>#include <errno.h>#include <sys/time.h>#include <gnome.h>#include <glib.h>#include <bonobo.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include "common.h"#include "interface.h"#include "callbacks.h"#include "support.h"#define GLADE_HOOKUP_OBJECT(component,widget,name) \ g_object_set_data_full (G_OBJECT (component), name, \ gtk_widget_ref (widget), (GDestroyNotify) gtk_widget_unref)static GList *store_wins=NULL;static GList *displayed_wins=NULL;static GList *opened_wins=NULL;static guint init_win_timer_id;static GtkWidget *normal_image=NULL;static GtkWidget *reverse_image=NULL;GStaticMutex openwin_mutex = G_STATIC_MUTEX_INIT;GStaticMutex displayedwin_mutex = G_STATIC_MUTEX_INIT;GStaticMutex store_win_mutex = G_STATIC_MUTEX_INIT;int init_ipmsg_private(ipmsg_private_data_t **priv,const int type){ ipmsg_private_data_t *new_priv; int rc=0; if (!priv) return -EINVAL; rc=-ENOMEM; new_priv=g_malloc(sizeof(ipmsg_private_data_t)); if (!new_priv) goto err_out; rc=0; new_priv->magic=IPMSG_PRIVATE_DATA_MAGIC; new_priv->type=type; new_priv->data=NULL; *priv=new_priv; err_out: return rc;}static voiddestroy_recvmsg_private(ipmsg_private_data_t *private) { ipmsg_recvmsg_private_t *priv; IPMSG_ASSERT_PRIVATE(private,IPMSG_PRIVATE_RECVMSG); priv=private->data; dbg_out("destroy private:ipaddr %s pktno:%d\n",priv->ipaddr,priv->pktno); g_assert(priv->ipaddr); g_free(priv->ipaddr); priv->ipaddr=NULL; if (priv->ext_part){ g_free(priv->ext_part); priv->ext_part=NULL; } g_free(priv);}intinit_recvmsg_private(const char *ipaddr,int flags,int pktno, ipmsg_private_data_t **priv) { ipmsg_recvmsg_private_t *element; ipmsg_private_data_t *new_prev; int rc=0; if ( (!ipaddr) || (!priv) ) return -EINVAL; rc=-ENOMEM; element=g_malloc(sizeof(ipmsg_recvmsg_private_t)); if (!element) goto no_free_out; memset(element,0,sizeof(ipmsg_recvmsg_private_t)); if (init_ipmsg_private(&new_prev,IPMSG_PRIVATE_RECVMSG)<0) goto err_out; element->pktno=pktno; element->flags=flags; element->ipaddr=g_strdup(ipaddr); if (element->ipaddr) { new_prev->data=(void *)element; *priv=new_prev; return 0; } no_ipaddr: g_free(new_prev); err_out: g_free(element); no_free_out: return rc;}voiddestroy_ipmsg_private(gpointer data) { ipmsg_private_data_t *private; g_assert(data); dbg_out("Called destroy private::%x\n",(unsigned int)data); private=(ipmsg_private_data_t *)data; dbg_out("Called destroy private magic::%x\n",private->magic); if (private->magic != IPMSG_PRIVATE_DATA_MAGIC) goto err_out; switch(private->type) { case IPMSG_PRIVATE_RECVMSG: destroy_recvmsg_private(private); break; default: g_assert_not_reached(); break; } err_out: dbg_out("Free private ::%x\n",(unsigned int)private); g_free(private); dbg_out("Complete free private ::%x\n",(unsigned int)private); return;}voidon_sealBtn_clicked (GtkButton *button, gpointer user_data){ int rc; GtkTextView *text_view; GtkWidget *scrolledwindow; GtkWidget *top; GtkWidget *container; GtkWidget *cite_toggle; GtkWidget *download_window; ipmsg_private_data_t *private; ipmsg_recvmsg_private_t *sender_info; private=(ipmsg_private_data_t *)lookup_widget(GTK_WIDGET(button),"senderInfo" ); IPMSG_ASSERT_PRIVATE(private,IPMSG_PRIVATE_RECVMSG); sender_info=private->data; top=lookup_widget(GTK_WIDGET(button),"viewWindow"); g_assert(top); cite_toggle=lookup_widget(GTK_WIDGET(button),"viewwindowCitationCheck"); g_assert(cite_toggle); if ( (sender_info->ipaddr) && (!(sender_info->flags & IPMSG_NO_REPLY_OPTS)) ) { dbg_out("recv notify:%s(%d)\n",sender_info->ipaddr,sender_info->pktno); ipmsg_send_read_msg(udp_con,sender_info->ipaddr,sender_info->pktno); } sender_info->flags &= ~IPMSG_SECRETOPT; dbg_out("new flags %x\n",sender_info->flags); text_view=GTK_TEXT_VIEW(lookup_widget(GTK_WIDGET(button),"viewwindowTextView")); container=gtk_widget_get_parent(GTK_WIDGET(button)); g_assert(container); dbg_out("Seal Btn Container Name:%s(0x%x)\n",gtk_widget_get_name(container),(unsigned int)container); scrolledwindow=lookup_widget(GTK_WIDGET(button),"scrolledwindow6"); /* * View Portを取り除くと自動的にviewport(とその上のボタン)が破棄される. */ gtk_container_remove(GTK_CONTAINER (scrolledwindow),GTK_WIDGET (container)); gtk_container_add (GTK_CONTAINER (scrolledwindow), GTK_WIDGET(text_view)); gtk_widget_set_sensitive(cite_toggle, TRUE); 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); if ((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); } } append_opened_window(top); if (sender_info->ext_part) { g_free(sender_info->ext_part); sender_info->ext_part=NULL; }}voidon_sealBtn_destroy (GtkObject *object, gpointer user_data){ dbg_out("here\n");}static GtkWidget *internal_create_recv_message_window(const msg_data_t *msg,const char *from){ int rc; char *message; int pktno; int flags; gchar *internal_message=NULL; 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]; char time_string[26]; 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 == NULL) { ipmsg_err_dialog(_("Can not convert message from %s into ineternal representation"), from); return NULL; } dbg_out("Recive_win:(from:%s)%s\n",from,internal_message); window=GTK_WIDGET(create_viewWindow ()); timelabel = GTK_LABEL(lookup_widget(window, "viewwindowDateLabel")); if (get_current_time_string(time_string, ((msg->tv).tv_sec))) gtk_label_set_text(timelabel, _("UnKnown")); else gtk_label_set_text(timelabel, time_string); userlabel=GTK_LABEL(lookup_widget(window,"viewwindowUserInfoLabel")); g_assert(userlabel); rc=userdb_search_user_by_addr(from,(const userdb_t **)&user_info); if (!rc) { 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{ dbg_out("Can not find user:rc=%d\n",rc); 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=g_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)){
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -