Example #1
0
ChatDialog::ChatDialog(QWidget *parent)
    : QDialog(parent)
{
    setupUi(this);

    lineEdit->setFocusPolicy(Qt::StrongFocus);
    textEdit->setFocusPolicy(Qt::NoFocus);
    textEdit->setReadOnly(true);
    listWidget->setFocusPolicy(Qt::NoFocus);

    connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
#ifdef Q_OS_SYMBIAN
    connect(sendButton, SIGNAL(clicked()), this, SLOT(returnPressed()));
#endif
    connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
    connect(&client, SIGNAL(newMessage(QString,QString)),
            this, SLOT(appendMessage(QString,QString)));
    connect(&client, SIGNAL(newParticipant(QString)),
            this, SLOT(newParticipant(QString)));
    connect(&client, SIGNAL(participantLeft(QString)),
            this, SLOT(participantLeft(QString)));

    myNickName = client.nickName();
    newParticipant(myNickName);
    tableFormat.setBorder(0);
    QTimer::singleShot(10 * 1000, this, SLOT(showInformation()));
}
Example #2
0
ChatDialog::ChatDialog(QWidget *parent)
    : QDialog(parent)
{
    setupUi(this);
// Meme generator setup
    lineEdit_2->setFocusPolicy(Qt::StrongFocus);
    connect(lineEdit_2, SIGNAL(returnPressed()), this, SLOT(memeReturnedPressed()));
    memeGenLayout->setPixmap(QPixmap(memepath+memefile));
    std::default_random_engine rand (100);
    this->qme =new QEncryption(rand());
    this->qmg =new QmemeGeneration();

    lineEdit->setFocusPolicy(Qt::StrongFocus);
    textEdit->setFocusPolicy(Qt::NoFocus);
    textEdit->setReadOnly(true);
    listWidget->setFocusPolicy(Qt::NoFocus);

    connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
    connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
    connect(&client, SIGNAL(newMessage(QString,QString)),
            this, SLOT(appendMessage(QString,QString)));
    connect(&client, SIGNAL(newParticipant(QString)),
            this, SLOT(newParticipant(QString)));
    connect(&client, SIGNAL(participantLeft(QString)),
            this, SLOT(participantLeft(QString)));

    myNickName = client.nickName();
    newParticipant(myNickName);
    tableFormat.setBorder(0);
    QTimer::singleShot(10 * 1000, this, SLOT(showInformation()));
}
Example #3
0
void Widget::processPendingDatagrams()   //接收数据UDP
{
    while(udpSocket->hasPendingDatagrams())
    {
        QByteArray datagram;
        datagram.resize(udpSocket->pendingDatagramSize());
        udpSocket->readDatagram(datagram.data(),datagram.size());
        QDataStream in(&datagram,QIODevice::ReadOnly);
        int messageType;
        in >> messageType;
        QString userName,localHostName,ipAddress,message;
        QString time = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
        switch(messageType)
        {
            case Message:
                {
                    in >>userName >>localHostName >>ipAddress >>message;
                    ui->textBrowser->setTextColor(Qt::blue);
                    ui->textBrowser->setCurrentFont(QFont("Times New Roman",12));
                    ui->textBrowser->append("[ " +userName+" ] "+ time);
                    ui->textBrowser->append(message);
                    break;
                }
            case NewParticipant:
                {
                    in >>userName >>localHostName >>ipAddress;
                    newParticipant(userName,localHostName,ipAddress);

                    break;
                }
            case ParticipantLeft:
                {
                    in >>userName >>localHostName;
                    participantLeft(userName,localHostName,time);
                    break;
                }
        case FileName:
            {
                in >>userName >>localHostName >> ipAddress;
                QString clientAddress,fileName;
                in >> clientAddress >> fileName;
                hasPendingFile(userName,ipAddress,clientAddress,fileName);
                break;
            }
        case Refuse:
            {
                in >> userName >> localHostName;
                QString serverAddress;
                in >> serverAddress;            
                QString ipAddress = getIP();

                if(ipAddress == serverAddress)
                {
                    server->refused();
                }
                break;
            }
        }
    }
}
void WebConferenceFactory::dialout(const AmArg& args, AmArg& ret) {
  for (int i=0;i<6;i++)
    assertArgCStr(args.get(1));

  string room        = args.get(0).asCStr();
  string adminpin    = args.get(1).asCStr();
  string callee      = args.get(2).asCStr();
  string from_user   = args.get(3).asCStr();
  string domain      = args.get(4).asCStr();
  string auth_user   = args.get(5).asCStr();
  string auth_pwd    = args.get(6).asCStr();

  string from = "sip:" + from_user + "@" + domain;
  string to   = "sip:" + callee + "@" + domain;

  // check adminpin
  rooms_mut.lock();
  ConferenceRoom* r = getRoom(room, adminpin);
  rooms_mut.unlock();
  if (NULL == r) {
      ret.push(1);
      ret.push("wrong adminpin");
      ret.push("");
      return;
  }

  DBG("dialout webconference room '%s', from '%s', to '%s'", 
      room.c_str(), from.c_str(), to.c_str());

  AmArg* a = new AmArg();
  a->setBorrowedPointer(new UACAuthCred("", auth_user, auth_pwd));

  AmSession* s = AmUAC::dialout(room.c_str(), APP_NAME,  to,  
				"<" + from +  ">", from, "<" + to + ">", 
				string(""), // local tag
				string(""), // hdrs
				a);
  if (s) {
    string localtag = s->getLocalTag();
    ret.push(0);
    ret.push("OK");
    ret.push(localtag.c_str());
    newParticipant(room, localtag, to);
    updateStatus(room, localtag,
		 ConferenceRoomParticipant::Connecting,
		 "INVITE");
  }
  else {
    ret.push(1);
    ret.push("internal error");
    ret.push("");
  }
}
Example #5
0
 void Client::readyForUse()
 {
     Connection *connection = qobject_cast<Connection *>(sender());
     if (!connection || hasConnection(connection->peerAddress(),
                                      connection->peerPort()))
         return;

     connect(connection, SIGNAL(newMessage(QString,QString)), this, SIGNAL(newMessage(QString,QString)));
    connect(connection, SIGNAL(newCode(QString,QString)), this, SIGNAL(newCode(QString,QString)));
     peers.insert(connection->peerAddress(), connection);
     QString nick = connection->name();
     if (!nick.isEmpty())
         emit newParticipant(nick);
 }
void ChatRoomListenSocket::dispatchDatagram()
{
    while (hasPendingDatagrams()) {
        QByteArray datagram;
        datagram.resize(pendingDatagramSize());
        if (readDatagram(datagram.data(), datagram.size()) == -1)
            return;
        
        QDataStream stream(&datagram, QIODevice::ReadOnly);
        int messageType;
        QString userName, identifier, ipAddress, message;
        stream >> messageType >> userName >> identifier;
        if (messageType == NEWPARTICIPANT) {
            stream >> ipAddress;
            emit newParticipant(userName, identifier, ipAddress);
        } else if (messageType == MESSAGE) {
int ChatDialog::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QDialog::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: appendMessage((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); break;
        case 1: returnPressed(); break;
        case 2: newParticipant((*reinterpret_cast< const QString(*)>(_a[1]))); break;
        case 3: participantLeft((*reinterpret_cast< const QString(*)>(_a[1]))); break;
        case 4: showInformation(); break;
        default: ;
        }
        _id -= 5;
    }
    return _id;
}
Example #8
0
int Client::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: newMessage((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); break;
        case 1: newParticipant((*reinterpret_cast< const QString(*)>(_a[1]))); break;
        case 2: participantLeft((*reinterpret_cast< const QString(*)>(_a[1]))); break;
        case 3: newConnection((*reinterpret_cast< Connection*(*)>(_a[1]))); break;
        case 4: connectionError((*reinterpret_cast< QAbstractSocket::SocketError(*)>(_a[1]))); break;
        case 5: disconnected(); break;
        case 6: readyForUse(); break;
        default: ;
        }
        _id -= 7;
    }
    return _id;
}
void WebConferenceFactory::dialout(const AmArg& args, AmArg& ret) {
  for (int i=0;i<6;i++)
    assertArgCStr(args.get(i));

  string room        = args.get(0).asCStr();
  string adminpin    = args.get(1).asCStr();
  string callee      = args.get(2).asCStr();
  string from_user   = args.get(3).asCStr();
  string domain      = args.get(4).asCStr();
  string auth_user   = args.get(5).asCStr();
  string auth_pwd    = args.get(6).asCStr();
  string callee_domain;
  string headers;

  try {
    assertArgCStr(args.get(7));
    headers = args.get(7).asCStr();
    int i, len;
    len = headers.length();
    for (i = 0; i < len; i++) {
      if (headers[i] == '|') headers[i] = '\n';
    }
    if (headers[len - 1] != '\n') {
      headers += '\n';
    }
  }
  catch (AmArg::OutOfBoundsException &e) {
    headers = "";
  }

  try {
    assertArgCStr(args.get(8));
    callee_domain = args.get(8).asCStr();
  }
  catch (AmArg::OutOfBoundsException &e) {
    callee_domain = domain;
  }

  string from = "sip:" + from_user + "@" + domain;
  string to   = "sip:" + callee + "@" + callee_domain;

  // check adminpin
  rooms_mut.lock();
  
  // sweep rooms (if necessary)
  sweepRooms();

  ConferenceRoom* r = getRoom(room, adminpin);
  rooms_mut.unlock();
  if (NULL == r) {
      ret.push(1);
      ret.push("wrong adminpin");
      ret.push("");
      return;
  }

  DBG("dialout webconference room '%s', from '%s', to '%s'", 
      room.c_str(), from.c_str(), to.c_str());

  AmArg* a = new AmArg();
  a->setBorrowedPointer(new UACAuthCred("", auth_user, auth_pwd));

  AmSession* s = AmUAC::dialout(room.c_str(), APP_NAME,  to,  
				"<" + from +  ">", from, "<" + to + ">", 
				string(""), // callid
				headers, // headers
				a);
  if (s) {
    string localtag = s->getLocalTag();
    ret.push(0);
    ret.push("OK");
    ret.push(localtag.c_str());
    newParticipant(room, localtag, to);
    updateStatus(room, localtag,
		 ConferenceRoomParticipant::Connecting,
		 "INVITE");
  }
  else {
    ret.push(1);
    ret.push("internal error");
    ret.push("");
  }
}
Example #10
0
//接收UDP信息信号的处理函数//接收数据,并根据type分类 槽函数
void Widget::processPendingDatagrams()//接收数据处理过程
{
    while(udpSocket->hasPendingDatagrams())//是否有数据报等待阅读//hasPendingDatagrams返回true时表示至少有一个数据报在等待被读取
    {
        QByteArray datagram;//缓存字节数组
        //pendingDatagramSize为返回第一个在等待读取报文的size,resize函数是把datagram的size归一化到参数size的大小一样
        datagram.resize(udpSocket->pendingDatagramSize());//获取缓存大小
        //将读取到的不大于datagram.size()大小数据输入到datagram.data()中,datagram.data()返回的是一个字节数组中存储数据位置的指针
        udpSocket->readDatagram(datagram.data(), datagram.size());//读取数据
        QDataStream in(&datagram, QIODevice::ReadOnly);//Qt的I/O设备接口类 从&datagram中读取串行化的数据 只读 序列化的二进制数据
        int messageType;//此处的int为qint32,在Qt中,qint8为char,qint16为uint
        in >> messageType;//读取1个32位长度的整型数据到messageTyep中//提取出messageType
        QString localHostName, ipAddress, message, secretAddress;//消息发送方昵称名,IP地址,消息内容和消息接受方IP地址
        QString time = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");//获取当前时间//将当前的时间转化到括号中的形式
        switch(messageType)
        {
            case RefuseChat://拒绝聊天
                //in>>后面如果为Qstring,则表示读取一个直到出现'\0'的字符串
                in  >> localHostName >> ipAddress >> secretAddress;//提取出消息发送方昵称名,IP和消息接收方IP
                if(secretAddress == getIP())//是发给自己的
                {
                    QMessageBox::information(this, tr("拒绝"), tr("来自(%1)的%2  拒绝你的聊天").arg(ipAddress).arg(localHostName));
                }
                break;

            case StartChat://开始聊天
                in  >> localHostName >> ipAddress >> secretAddress;
                if(secretAddress == getIP())
                {
                    ChatWidgit *chatView = new ChatWidgit();
                    list.insert(ipAddress, chatView);//插入聊天窗口列表

                    connect(chatView, SIGNAL(closeChat(QString)), this, SLOT(closeFromChat(QString)));
                    connect(this, SIGNAL(sendMessagesZ(QString, QString, QString)), chatView, SLOT(setMessage(QString, QString, QString)));
                    connect(chatView, SIGNAL(sendMessagesFromChat(QString, QString)), this, SLOT(sendMessagesToMain(QString, QString)));
                    connect(chatView, SIGNAL(sendFile(QString, QString)), this, SLOT(hasFileToSend(QString, QString)));

                    chatView->setSecAddr(ipAddress, Name);//设置具体聊天窗口(chatView)
                    chatView->show();
                }
                break;

            case AskStartChat://申请聊天
                in  >> localHostName >> ipAddress >> secretAddress;
                if(secretAddress == getIP())
                {
                    int btn = QMessageBox::information(this, tr("同意聊天"), tr("来自%1(%2)的聊天,是否接收?")\
                                                           .arg(ipAddress).arg(localHostName), QMessageBox::Yes, QMessageBox::No);
                    if(btn == QMessageBox::Yes)
                    {
                        ChatWidgit *chatView = new ChatWidgit();
                        list.insert(ipAddress, chatView);

                        connect(chatView, SIGNAL(closeChat(QString)), this, SLOT(closeFromChat(QString)));
                        connect(this, SIGNAL(sendMessagesZ(QString, QString, QString)), chatView, SLOT(setMessage(QString, QString, QString)));
                        connect(chatView, SIGNAL(sendMessagesFromChat(QString, QString)), this, SLOT(sendMessagesToMain(QString, QString)));
                        connect(chatView, SIGNAL(sendFile(QString, QString)), this, SLOT(hasFileToSend(QString, QString)));

                        chatView->setSecAddr(ipAddress, Name);
                        chatView->show();
                        sendMessage(StartChat, ipAddress);
                    }
                    else if(btn == QMessageBox::No)
                    {
                        sendMessage(RefuseChat, ipAddress);
                    }
                }
                break;

            case Message://聊天消息
                in  >> localHostName >> ipAddress >> secretAddress >> message;
                //QMessageBox::information(this, tr("0"), tr("%1sec\n%2").arg(secretAddress).arg(ipAddress));
                if(secretAddress == getIP() )//发给自己的私有聊天
                {
                    //QMessageBox::information(this, tr("0"), tr("%1sec").arg(secretAddress));
                    if(list.contains(ipAddress))
                    {
                        list[ipAddress]->show();
                        emit sendMessagesZ(ipAddress, tr("[ %1 ] %2").arg(localHostName).arg(time), message);//主窗口向具体聊天窗口发送聊天消息的信号
                    }
                    else
                    {
                        ChatWidgit *chatView = new ChatWidgit();
                        list.insert(ipAddress, chatView);

                        connect(chatView, SIGNAL(closeChat(QString)), this, SLOT(closeFromChat(QString)));
                        connect(this, SIGNAL(sendMessagesZ(QString, QString, QString)), chatView, SLOT(setMessage(QString, QString, QString)));
                        connect(chatView, SIGNAL(sendMessagesFromChat(QString, QString)), this, SLOT(sendMessagesToMain(QString, QString)));
                        connect(chatView, SIGNAL(sendFile(QString, QString)), this, SLOT(hasFileToSend(QString, QString)));

                        chatView->setSecAddr(ipAddress, Name);
                        chatView->show();
                        emit sendMessagesZ(ipAddress, tr("[ %1 ] %2").arg(localHostName).arg(time), message);
                    }
                }
                else if(secretAddress == "NULL")//群消息
                {
                    if(list.contains("NULL"))
                    {
                        list["NULL"]->show();
                        emit sendMessagesZ(secretAddress, tr("[ %1 ] %2").arg(localHostName).arg(time), message);
                    }
                    else
                    {
                        ChatWidgit *chatView = new ChatWidgit();
                        list.insert(secretAddress, chatView);

                        connect(chatView, SIGNAL(closeChat(QString)), this, SLOT(closeFromChat(QString)));
                        connect(this, SIGNAL(sendMessagesZ(QString, QString, QString)), chatView, SLOT(setMessage(QString, QString, QString)));
                        connect(chatView, SIGNAL(sendMessagesFromChat(QString, QString)), this, SLOT(sendMessagesToMain(QString, QString)));
                        connect(chatView, SIGNAL(sendFile(QString, QString)), this, SLOT(hasFileToSend(QString, QString)));

                        chatView->setSecAddr(secretAddress, Name);
                        chatView->show();
                        emit sendMessagesZ(secretAddress, tr("[ %1 ] %2").arg(localHostName).arg(time), message);
                    }
                }
                break;

            case NewParticipant://新用户加入
                in >> localHostName >> ipAddress;
                newParticipant(localHostName, ipAddress);//主窗口登记新用户
                break;

            case ParticipantLeft://用户离开
                in >> localHostName;
                //participantLeft(localHostName, time);
                participantLeft(localHostName);//主窗口处理用户离开
                break;

            case FileName://发送文件
                {
                    in >> localHostName >> ipAddress;
                    QString clientAddress, fileName;//
                    in >> clientAddress >> fileName;
                    QMessageBox::information(this, tr(""), tr("%1ipaddr\n%2sev\n%3file").arg(ipAddress).arg(clientAddress).arg(message));//
                    hasPendingFile(localHostName, ipAddress, clientAddress, fileName);//有文件需要接收
                    break;
                }
            case Refuse://拒绝接收文件
                in >> localHostName;
                QString serverAddress;//
                in >> ipAddress >> serverAddress;

                if(serverAddress == getIP())
                {
                    this->Sender->refused();
                }
                break;
        }
    }
}