Example #1
0
// properties.at(0): Login
// properties.at(1): Id
// properties.at(2): Ip
// properties.at(3): Promo
// properties.at(4): State
// properties.at(5): Location
// properties.at(6): Comment
void    QNetsoul::showConversation(const QStringList& properties,
                                   const QString& message)
{
  bool ok;
  const int id = properties.at(1).toInt(&ok);
  if (ok == false)
    qFatal("[QNetsoul::showConversation] Invalid id (%d)", id);

  Chat* window = getChat(id);
  const bool userEvent = message.isEmpty();

  if (NULL == window)
    {
      // DEBUG focus
      //qDebug() << "CASE 1";
      window = createWindowChat(id, properties.at(0), properties.at(5));
      window->show();
    }
  if (false == window->isVisible())
    {
      // DEBUG focus
      //qDebug() << "CASE 2";
      //window->outputTextBrowser->clear();
      //window->inputTextEdit->clear();
      if (userEvent)
        {
          window->show();
          window->activateWindow();
          QApplication::setActiveWindow(window);
          window->inputTextEdit->setFocus();
        }
      else window->showMinimized();
    }
  else
    {
      // DEBUG focus
      //qDebug() << "CASE 3";
      if (userEvent)
        {
          window->showNormal();
          window->activateWindow();
          QApplication::setActiveWindow(window);
          window->inputTextEdit->setFocus();
        }
    }
  if (message.isEmpty() == false)
    {
      if (window)
        {
          window->insertMessage(properties.at(0), message, QColor(204, 0, 0));
          window->autoReply(statusComboBox->currentIndex());
          QApplication::alert(window);
        }
      if (this->_trayIcon && this->_options->chatWidget->notifyMsg())
        this->_trayIcon->showMessage(properties.at(0), tr(" is talking to you."));
    }
}
Example #2
0
void MessageWind::DoubleClicked(QTreeWidgetItem *item, int row)
{
    if(item->parent()==NULL)      //顶级节点,不做任何响应
    {
        return;
    }
    for(int i=0;i<childBlinkItems.count();i++)  //删除对应联系人的闪烁
    {
        if(item==childBlinkItems[i]->getitem())
        {
            Blink *temp=childBlinkItems[i];
            childBlinkItems.removeAt(i);
            delete temp;
            i--;          //因为删除后,余下闪烁项目的未知会改变,所以要-1
        }
    }
    Contact contact=texttocontact(item->whatsThis(0)); //提取联系人信息
    Chat *chat;
    if(chatdialogexist(contact,&chat)) //存在联系人的聊天窗口
    {
        chat->activateWindow();        //将窗口激活
    }
    else               //不存在联系人的聊天窗口
    {
        chat=new Chat(contact); //则打开此联系人的新的聊天窗口
        if(chat!=NULL)
        {
            connect(chat,SIGNAL(have_chat_dialog_closed()),this,SLOT(havechatdialogclosed()));
            chats.append(chat);
        }
    }
    for(int i=0;i<unreadsms.count();i++) //若有此联系人的未读信息,则将这些未读信息显示在聊天窗口中,并将这些信息移到收件箱或者垃圾箱
    {
        QString number=chat->getcontact().number;

        if(unreadsms[i].number==number)
        {
            Message temp;
            temp=unreadsms[i];
            unreadsms.removeAt(i);
            i--;
            chat->addnewmessage(numberToName(number),temp);
            if(temp.now==2)  //来自黑名单,放入垃圾箱
            {
                temp.now=temp.from=2;
                allMessages.prepend(temp);
            }
            else
            {
                temp.now=temp.from=1;       //否则放入收件箱
                allMessages.prepend(temp);
            }
        }
    }
    update();   //刷新界面
}
Example #3
0
void MessageWind::insertSms(Message newsms)  //将消息保存到合适的短信集合
{
    if(newsms.content=="+++"||newsms.content=="---"||newsms.content=="+-+")//若为上线或者下线的消息
    {
       if(newsms.content=="+++") //对方发来对方的上线消息
        {
            contact_online(newsms.number,true);//标示对方上线,并且回发响应信息和对方的离线消息
            Chat *chat;
            if(chatdialogexist(*(indexofcontact(newsms.number)),&chat))
                chat->contatonline();//存在对应联系人的聊天窗口,则重建到对应联系人的连接
        }
        else
            if(newsms.content=="---") //离线消息,标志对方离线
                contact_offline(newsms.number);
            else//收到+-+            //收到对方发送的我上线的响应消息,则只需要将对方标记为上线,并发送对方的离线消息
            {
                contact_online(newsms.number,false);
            }
        return;
    }
    //若消息为正常消息
    newsms.content=newsms.content.mid(3,newsms.content.length()-3);//去除消息的头部
    if(hasBadWords(newsms.content)) //还有敏感词汇,直接扔进垃圾箱
    {
        newsms.from=3;//设置为未读
        newsms.now=2;
        allMessages.prepend(newsms);
        update();
        return;
    }
    else
    {
       QTreeWidgetItem *item=finditem(newsms.number);//查找对应号码的子节点
        if(item!=NULL)//存在对应的联系人
        {
            Contact contact=texttocontact(item->whatsThis(0)); //提取联系人信息
            if(contact.number==newsms.number)
            {
                Chat *chat;
                if(chatdialogexist(contact,&chat))//联系人已有聊天窗口打开
                {
                    chat->activateWindow();       //则将窗口激活
                    chat->addnewmessage(numberToName(newsms.number),newsms);//在聊天窗口中显示此消息
                    if(recogniseNumber(newsms.number)==-1)//来自黑名单
                        newsms.from=newsms.now=2;   //放入垃圾箱
                    else
                        newsms.from=newsms.now=1;    // 放入收件箱
                    allMessages.prepend(newsms);
                    update();
                    return;
                }
                else           //没有聊天窗口打开
                {
                    if(recogniseNumber(newsms.number)==-1)//来自黑名单
                        newsms.now=2;   //查看后放入垃圾箱
                    else
                        newsms.now=1;    // 查看后放入收件箱
                    unreadsms.append(newsms); //保存在未读短信集合中
                    addchildblink(item);       //让对应的子节点闪烁
                    update();
                    return;
                }
            }
        }
        else
        {
                //没有对应此号码的联系人
            Contact newcontact;
            newcontact.name=QString::null;
            newcontact.number=newsms.number;
            newcontact.onLine=true;    //将联系人设置为在线
            strangers.append(newcontact); //保存未知联系人
            QTreeWidgetItem *child=new QTreeWidgetItem(QStringList()<<(newcontact.name+":"+newcontact.number));
            child->setIcon(0,QIcon(":/icon/icons/user.png"));
            child->setWhatsThis(0,newcontact.name+":"+newcontact.number);
            ui->contactsTreeWidget->topLevelItem(1)->addChild(child);  //在联系人列表显示未知联系人
            newsms.now=1;  //将陌生人的信息存到收件箱
            unreadsms.append(newsms);  //添加未读消息
            addchildblink(child);   //设置为闪烁
            update();
        }
    }
}