示例#1
0
/**
 * 好友对话框入口.
 * @param grpinf 好友群组信息
 */
void DialogPeer::PeerDialogEntry(GroupInfo *grpinf)
{
        DialogPeer *dlgpr;
        GtkWidget *window, *widget;

        dlgpr = new DialogPeer(grpinf);
        window = dlgpr->CreateMainWindow();
        gtk_container_add(GTK_CONTAINER(window), dlgpr->CreateAllArea());
        gtk_widget_show_all(window);

        /* 将焦点置于文本输入框 */
        widget = GTK_WIDGET(g_datalist_get_data(&dlgpr->widset,
                                         "input-textview-widget"));
        gtk_widget_grab_focus(widget);

        /* 从消息队列中移除 */
        pthread_mutex_lock(cthrd.GetMutex());
        if (cthrd.MsglineContainItem(grpinf)) {
                mwin.MakeItemBlinking(grpinf, FALSE);
                cthrd.PopItemFromMsgline(grpinf);
        }
        pthread_mutex_unlock(cthrd.GetMutex());

        /* delete dlgpr;//请不要这样做,此类将会在窗口被摧毁后自动释放 */
}
示例#2
0
/**
 * 好友广播消息.
 */
void UdpData::SomeoneBcstmsg()
{
        GroupInfo *grpinf;
        PalInfo *pal;
        uint32_t commandno, packetno;
        char *text;

        /* 如果对方兼容iptux协议,则无须再转换编码 */
        pal = cthrd.GetPalFromList(ipv4);
        if (!pal || !FLAG_ISSET(pal->flags, 0))
                ConvertEncode(pal ? pal->encode : progdt.encode);
        /* 确保好友在线,并对编码作出适当调整 */
        pal = AssertPalOnline();
        if (strcasecmp(pal->encode, encode ? encode : "utf-8") != 0) {
                g_free(pal->encode);
                pal->encode = g_strdup(encode ? encode : "utf-8");
        }

        /* 检查此消息是否过时 */
        packetno = iptux_get_dec_number(buf, ':', 1);
        if (packetno <= pal->packetn)
                return;
        pal->packetn = packetno;

        /* 插入消息&在消息队列中注册 */
        text = ipmsg_get_attach(buf, ':', 5);
        if (text && *text != '\0') {
                commandno = iptux_get_dec_number(buf, ':', 4);
                /*/* 插入消息 */
                switch (GET_OPT(commandno)) {
                case IPTUX_BROADCASTOPT:
                        InsertMessage(pal, GROUP_BELONG_TYPE_BROADCAST, text);
                        break;
                case IPTUX_GROUPOPT:
                        InsertMessage(pal, GROUP_BELONG_TYPE_GROUP, text);
                        break;
                case IPTUX_SEGMENTOPT:
                        InsertMessage(pal, GROUP_BELONG_TYPE_SEGMENT, text);
                        break;
                case IPTUX_REGULAROPT:
                default:
                        InsertMessage(pal, GROUP_BELONG_TYPE_REGULAR, text);
                        break;
                }
                /*/* 注册消息 */
                pthread_mutex_lock(cthrd.GetMutex());
                switch (GET_OPT(commandno)) {
                case IPTUX_BROADCASTOPT:
                        grpinf = cthrd.GetPalBroadcastItem(pal);
                        break;
                case IPTUX_GROUPOPT:
                        grpinf = cthrd.GetPalGroupItem(pal);
                        break;
                case IPTUX_SEGMENTOPT:
                        grpinf = cthrd.GetPalSegmentItem(pal);
                        break;
                case IPTUX_REGULAROPT:
                default:
                        grpinf = cthrd.GetPalRegularItem(pal);
                        break;
                }
                if (!grpinf->dialog && !cthrd.MsglineContainItem(grpinf))
                        cthrd.PushItemToMsgline(grpinf);
                pthread_mutex_unlock(cthrd.GetMutex());
        }
        g_free(text);

        /* 播放提示音 */
        if (FLAG_ISSET(progdt.sndfgs, 1))
                sndsys.Playing(progdt.msgtip);
}
示例#3
0
/**
 * 好友发送消息.
 *
 */
void UdpData::SomeoneSendmsg()
{
        GroupInfo *grpinf;
        PalInfo *pal;
        Command cmd;
        uint32_t commandno, packetno;
        char *text;
        pthread_t pid;
        DialogPeer *dlgpr;
        GtkWidget *window;

        /* 如果对方兼容iptux协议,则无须再转换编码 */
        pal = cthrd.GetPalFromList(ipv4);
        if (!pal || !FLAG_ISSET(pal->flags, 0))
                ConvertEncode(pal ? pal->encode : progdt.encode);
        /* 确保好友在线,并对编码作出适当调整 */
        pal = AssertPalOnline();
        if (strcasecmp(pal->encode, encode ? encode : "utf-8") != 0) {
                g_free(pal->encode);
                pal->encode = g_strdup(encode ? encode : "utf-8");
        }

        /* 回复好友并检查此消息是否过时 */
        commandno = iptux_get_dec_number(buf, ':', 4);
        packetno = iptux_get_dec_number(buf, ':', 1);
        if (commandno & IPMSG_SENDCHECKOPT)
                cmd.SendReply(cthrd.UdpSockQuote(), pal, packetno);
        if (packetno <= pal->packetn)
                return;
        pal->packetn = packetno;

        /* 插入消息&在消息队列中注册 */
        text = ipmsg_get_attach(buf, ':', 5);
        if (text && *text != '\0') {
                /*/* 插入消息 */
//                if ((commandno & IPMSG_BROADCASTOPT) || (commandno & IPMSG_MULTICASTOPT))
//                        InsertMessage(pal, GROUP_BELONG_TYPE_BROADCAST, text);
//                else
                        InsertMessage(pal, GROUP_BELONG_TYPE_REGULAR, text);
        }
        g_free(text);
        /*/* 注册消息 */
        pthread_mutex_lock(cthrd.GetMutex());
//        if ((commandno & IPMSG_BROADCASTOPT) || (commandno & IPMSG_MULTICASTOPT))
//                grpinf = cthrd.GetPalBroadcastItem(pal);
//        else
                grpinf = cthrd.GetPalRegularItem(pal);
        if (!grpinf->dialog && !cthrd.MsglineContainItem(grpinf))
                cthrd.PushItemToMsgline(grpinf);
        pthread_mutex_unlock(cthrd.GetMutex());

        /* 标记位处理 先处理底层数据,后面显示窗口*/
        if (commandno & IPMSG_FILEATTACHOPT) {
                if ((commandno & IPTUX_SHAREDOPT) && (commandno & IPTUX_PASSWDOPT)) {
                        pthread_create(&pid, NULL, ThreadFunc(ThreadAskSharedPasswd), pal);
                        pthread_detach(pid);
                } else
                        RecvPalFile();
        }
        window = GTK_WIDGET(grpinf->dialog);
        //这里不知道为什么运行时一直会提示window不是object
        dlgpr = (DialogPeer *)(g_object_get_data(G_OBJECT(window),"dialog"));
        if(grpinf->dialog)
            dlgpr->ShowDialogPeer(dlgpr);
        /* 是否直接弹出聊天窗口 */
        if (FLAG_ISSET(progdt.flags, 7)) {
                gdk_threads_enter();
                if (!(grpinf->dialog)) {
//                     switch (grpinf->type) {
//                     case GROUP_BELONG_TYPE_REGULAR:
                          DialogPeer::PeerDialogEntry(grpinf);
//                          break;
//                     case GROUP_BELONG_TYPE_SEGMENT:
//                     case GROUP_BELONG_TYPE_GROUP:
//                     case GROUP_BELONG_TYPE_BROADCAST:
//                          DialogGroup::GroupDialogEntry(grpinf);
//                     default:
//                          break;
//                     }
                } else {
                     gtk_window_present(GTK_WINDOW(grpinf->dialog));
                }
                gdk_threads_leave();
        }

        /* 播放提示音 */
        if (FLAG_ISSET(progdt.sndfgs, 1))
                sndsys.Playing(progdt.msgtip);
}