Пример #1
0
void ChatLobbyDialog::displayLobbyEvent(int event_type, const QString& nickname, const QString& str)
{
	switch (event_type) {
	case RS_CHAT_LOBBY_EVENT_PEER_LEFT:
		ui.chatWidget->addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 has left the lobby.").arg(RsHtml::plainText(str)), ChatWidget::TYPE_SYSTEM);
		emit peerLeft(id()) ;
		break;
	case RS_CHAT_LOBBY_EVENT_PEER_JOINED:
		ui.chatWidget->addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 joined the lobby.").arg(RsHtml::plainText(str)), ChatWidget::TYPE_SYSTEM);
		emit peerJoined(id()) ;
		break;
	case RS_CHAT_LOBBY_EVENT_PEER_STATUS:
		ui.chatWidget->updateStatusString(RsHtml::plainText(nickname) + " %1", RsHtml::plainText(str));
		if (!isParticipantMuted(nickname)) {
			emit typingEventReceived(id()) ;
		}
		break;
	case RS_CHAT_LOBBY_EVENT_PEER_CHANGE_NICKNAME:
		ui.chatWidget->addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 changed his name to: %2").arg(RsHtml::plainText(nickname), RsHtml::plainText(str)), ChatWidget::TYPE_SYSTEM);
		
		// TODO if a user was muted and changed his name, update mute list, but only, when the muted peer, dont change his name to a other peer in your chat lobby
		if (isParticipantMuted(nickname) && !isNicknameInLobby(str)) {
			muteParticipant(str);
		}
		
	break;
	case RS_CHAT_LOBBY_EVENT_KEEP_ALIVE:
		//std::cerr << "Received keep alive packet from " << nickname.toStdString() << " in lobby " << getPeerId() << std::endl;
		break;
	default:
		std::cerr << "ChatLobbyDialog::displayLobbyEvent() Unhandled lobby event type " << event_type << std::endl;
	}
	updateParticipantsList() ;
}
Пример #2
0
/**
 * We get a new Message from a chat participant
 * 
 * - Ignore Messages from muted chat participants
 */
void ChatLobbyDialog::addIncomingChatMsg(const ChatInfo& info)
{
	QDateTime sendTime = QDateTime::fromTime_t(info.sendTime);
	QDateTime recvTime = QDateTime::fromTime_t(info.recvTime);
	QString message = QString::fromStdWString(info.msg);
	QString name = QString::fromUtf8(info.peer_nickname.c_str());
	QString rsid = QString::fromUtf8(info.rsid.c_str());

	std::cerr << "message from rsid " << info.rsid.c_str() << std::endl;
	
	if(!isParticipantMuted(name)) {
	  ui.chatWidget->addChatMsg(true, name, sendTime, recvTime, message, ChatWidget::TYPE_NORMAL);
		emit messageReceived(id()) ;
	}
	
	// This is a trick to translate HTML into text.
	QTextEdit editor;
	editor.setHtml(message);
	QString notifyMsg = name + ": " + editor.toPlainText();

	if(notifyMsg.length() > 30)
		MainWindow::displayLobbySystrayMsg(tr("Lobby chat") + ": " + _lobby_name, notifyMsg.left(30) + QString("..."));
	else
		MainWindow::displayLobbySystrayMsg(tr("Lobby chat") + ": " + _lobby_name, notifyMsg);

	// also update peer list.

	time_t now = time(NULL);

	if (now > lastUpdateListTime) {
		lastUpdateListTime = now;
		updateParticipantsList();
	}
}
Пример #3
0
void ChatLobbyDialog::participantsTreeWidgetCustomPopupMenu(QPoint)
{
	QList<QTreeWidgetItem*> selectedItems = ui.participantsList->selectedItems();

	QMenu contextMnu(this);

	contextMnu.addAction(muteAct);
	muteAct->setCheckable(true);
	muteAct->setEnabled(false);
	muteAct->setChecked(false);
	if (selectedItems.size()) {

        std::string nickName;
        rsMsgs->getNickNameForChatLobby(lobbyId, nickName);
        if(selectedItems.count()>1 || (selectedItems.at(0)->text(COLUMN_NAME).toStdString()!=nickName))
        {
		muteAct->setEnabled(true);

		QList<QTreeWidgetItem*>::iterator item;
		for (item = selectedItems.begin(); item != selectedItems.end(); ++item) {
			if (isParticipantMuted((*item)->text(COLUMN_NAME))) {
				muteAct->setChecked(true);
				break;
			}
		}
	}
    }

	contextMnu.exec(QCursor::pos());
}
Пример #4
0
/**
 * Regenerate the QListWidget participant list of a Chat Lobby
 * 
 * Show unchecked Checkbox for muted Participants
 */
void ChatLobbyDialog::updateParticipantsList()
{
	ui.participantsList->clear();
	ui.participantsList->setSortingEnabled(false);

	std::list<ChatLobbyInfo> linfos;
	rsMsgs->getChatLobbyList(linfos);

	std::list<ChatLobbyInfo>::const_iterator it(linfos.begin());

	// Set it to the current ChatLobby
	for (; it!=linfos.end() && (*it).lobby_id != lobbyId; ++it);

	if (it != linfos.end()) {
		for (std::map<std::string,time_t>::const_iterator it2((*it).nick_names.begin()); it2 != (*it).nick_names.end(); ++it2) {
			QString participant = QString::fromUtf8( (it2->first).c_str() );

			// TE: Add Wigdet to participantsList with Checkbox, to mute Participant
			QListWidgetItem *widgetitem = new RSListWidgetItem;

			if (isParticipantMuted(participant)) {
				widgetitem->setCheckState(Qt::Unchecked);
			} else {
				widgetitem->setCheckState(Qt::Checked);
			}
			widgetitem->setText(participant);
 			widgetitem->setToolTip(tr("Uncheck to mute participant"));
			
			ui.participantsList->addItem(widgetitem);
		}
	}

	ui.participantsList->setSortingEnabled(true);
	ui.participantsList->sortItems(Qt::AscendingOrder);
}
Пример #5
0
/**
 * We get a new Message from a chat participant
 * 
 * - Ignore Messages from muted chat participants
 */
void ChatLobbyDialog::addIncomingChatMsg(const ChatInfo& info)
{
	QDateTime sendTime = QDateTime::fromTime_t(info.sendTime);
	QDateTime recvTime = QDateTime::fromTime_t(info.recvTime);
	QString message = QString::fromStdWString(info.msg);
	QString name = QString::fromUtf8(info.peer_nickname.c_str());
	QString rsid = QString::fromUtf8(info.rsid.c_str());

	std::cerr << "message from rsid " << info.rsid.c_str() << std::endl;
	
	if (!isParticipantMuted(name)) {
	  // ui.chatWidget->addChatMsg(true, name.append(" ").append(rsid), sendTime, recvTime, message, ChatWidget::TYPE_NORMAL);
	  ui.chatWidget->addChatMsg(true, name, sendTime, recvTime, message, ChatWidget::TYPE_NORMAL);
	} else {
	  // ui.chatWidget->addChatMsg(true, name, sendTime, recvTime, message.append(" (BLOCKED)"), ChatWidget::TYPE_NORMAL);
	}
	
	// also update peer list.

	time_t now = time(NULL);

	if (now > lastUpdateListTime) {
		lastUpdateListTime = now;
		updateParticipantsList();
	}
}
Пример #6
0
/**
 * Regenerate the QTreeWidget participant list of a Chat Lobby
 * 
 * Show yellow icon for muted Participants
 */
void ChatLobbyDialog::updateParticipantsList()
{
	/* Save selected items */
	QStringList selectedParcipants;
	QList<QTreeWidgetItem*> selectedItems = ui.participantsList->selectedItems();

	QList<QTreeWidgetItem*>::iterator item;
	for (item = selectedItems.begin(); item != selectedItems.end(); ++item) {
		selectedParcipants.append((*item)->text(COLUMN_NAME));
	}

	ui.participantsList->clear();
	ui.participantsList->setSortingEnabled(false);

	std::list<ChatLobbyInfo> linfos;
	rsMsgs->getChatLobbyList(linfos);

	std::list<ChatLobbyInfo>::const_iterator it(linfos.begin());

	// Set it to the current ChatLobby
	for (; it!=linfos.end() && (*it).lobby_id != lobbyId; ++it);

	if (it != linfos.end()) {
		for (std::map<std::string,time_t>::const_iterator it2((*it).nick_names.begin()); it2 != (*it).nick_names.end(); ++it2) {
			QString participant = QString::fromUtf8( (it2->first).c_str() );

			// TE: Add Wigdet to participantsList with Checkbox, to mute Participant
			QTreeWidgetItem *widgetitem = new RSTreeWidgetItem;

			if (isParticipantMuted(participant)) {
				widgetitem->setIcon(COLUMN_ICON, QIcon(":/images/yellowled.png"));
			} else {
				widgetitem->setIcon(COLUMN_ICON, QIcon(":/images/greenled.png"));
			}
			//widgetitem->setToolTip(COLUMN_ICON, tr("Double click to mute/unmute participant"));

			widgetitem->setText(COLUMN_NAME, participant);
			widgetitem->setToolTip(COLUMN_NAME,tr("Right click to mute/unmute participants<br/>Double click to address this person"));

			ui.participantsList->addTopLevelItem(widgetitem);
			if (selectedParcipants.contains(participant)) {
				widgetitem->setSelected(true);
			}
		}
	}
	ui.participantsList->setSortingEnabled(true);
	ui.participantsList->sortItems(COLUMN_NAME, Qt::AscendingOrder);
}
Пример #7
0
/**
 * We get a new Message from a chat participant
 *
 * - Ignore Messages from muted chat participants
 */
void ChatLobbyDialog::addChatMsg(const ChatMessage& msg)
{
    QDateTime sendTime = QDateTime::fromTime_t(msg.sendTime);
    QDateTime recvTime = QDateTime::fromTime_t(msg.recvTime);
    QString message = QString::fromUtf8(msg.msg.c_str());
    RsGxsId gxs_id = msg.lobby_peer_gxs_id ;

    if(!isParticipantMuted(gxs_id))
    {
        // We could change addChatMsg to display the peers icon, passing a ChatId

        RsIdentityDetails details ;

        QString name ;
        if(rsIdentity->getIdDetails(gxs_id,details))
            name = QString::fromUtf8(details.mNickname.c_str()) ;
        else
            name = QString::fromUtf8(msg.peer_alternate_nickname.c_str()) + " (" + QString::fromStdString(gxs_id.toStdString()) + ")" ;

        ui.chatWidget->addChatMsg(msg.incoming, name, gxs_id, sendTime, recvTime, message, ChatWidget::MSGTYPE_NORMAL);
        emit messageReceived(msg.incoming, id(), sendTime, name, message) ;
        SoundManager::play(SOUND_NEW_LOBBY_MESSAGE);

        // This is a trick to translate HTML into text.
        QTextEdit editor;
        editor.setHtml(message);
        QString notifyMsg = name + ": " + editor.toPlainText();

        if(notifyMsg.length() > 30)
            MainWindow::displayLobbySystrayMsg(tr("Lobby chat") + ": " + _lobby_name, notifyMsg.left(30) + QString("..."));
        else
            MainWindow::displayLobbySystrayMsg(tr("Lobby chat") + ": " + _lobby_name, notifyMsg);
    }

    // also update peer list.

    time_t now = time(NULL);

    QList<QTreeWidgetItem*>  qlFoundParticipants=ui.participantsList->findItems(QString::fromStdString(gxs_id.toStdString()),Qt::MatchExactly,COLUMN_ID);
    if (qlFoundParticipants.count()!=0) qlFoundParticipants.at(0)->setText(COLUMN_ACTIVITY,QString::number(now));

    if (now > lastUpdateListTime) {
        lastUpdateListTime = now;
        updateParticipantsList();
    }
}
Пример #8
0
void ChatLobbyDialog::participantsTreeWidgetCustomPopupMenu(QPoint)
{
    QList<QTreeWidgetItem*> selectedItems = ui.participantsList->selectedItems();

    QMenu contextMnu(this);

    contextMnu.addAction(distantChatAct);
    contextMnu.addAction(sendMessageAct);
    contextMnu.addSeparator();
    contextMnu.addAction(muteAct);
    contextMnu.addSeparator();
    contextMnu.addAction(actionSortByActivity);
    contextMnu.addAction(actionSortByName);


    muteAct->setCheckable(true);
    muteAct->setEnabled(false);
    muteAct->setChecked(false);

    if (selectedItems.size())
    {
        RsGxsId nickName;
        rsMsgs->getIdentityForChatLobby(lobbyId, nickName);

        if(selectedItems.count()>1 || (RsGxsId(selectedItems.at(0)->text(COLUMN_ID).toStdString())!=nickName))
        {
            muteAct->setEnabled(true);

            QList<QTreeWidgetItem*>::iterator item;
            for (item = selectedItems.begin(); item != selectedItems.end(); ++item) {

                RsGxsId gxsid ;
                if ( dynamic_cast<GxsIdRSTreeWidgetItem*>(*item)->getId(gxsid) && isParticipantMuted(gxsid))
                {
                    muteAct->setChecked(true);
                    break;
                }
            }
        }
        distantChatAct->setEnabled(selectedItems.count()==1 && RsGxsId(selectedItems.front()->text(COLUMN_ID).toStdString())!=nickName) ;
    }

    contextMnu.exec(QCursor::pos());
}
Пример #9
0
void ChatLobbyDialog::participantsTreeWidgetCustomPopupMenu(QPoint)
{
	QList<QTreeWidgetItem*> selectedItems = ui.participantsList->selectedItems();

	QMenu contextMnu(this);

	contextMnu.addAction(muteAct);
	muteAct->setCheckable(true);
	muteAct->setEnabled(false);
	muteAct->setChecked(false);
	if (selectedItems.size()) {
		muteAct->setEnabled(true);

		QList<QTreeWidgetItem*>::iterator item;
		for (item = selectedItems.begin(); item != selectedItems.end(); ++item) {
			if (isParticipantMuted((*item)->text(COLUMN_NAME))) {
				muteAct->setChecked(true);
				break;
			}
		}
	}

	contextMnu.exec(QCursor::pos());
}
Пример #10
0
/**
 * Regenerate the QTreeWidget participant list of a Chat Lobby
 *
 * Show yellow icon for muted Participants
 */
void ChatLobbyDialog::updateParticipantsList()
{
    ChatLobbyInfo linfo;

    if(rsMsgs->getChatLobbyInfo(lobbyId,linfo))
    {
        ChatLobbyInfo cliInfo=linfo;
        QList<QTreeWidgetItem*>  qlOldParticipants=ui.participantsList->findItems("*",Qt::MatchWildcard,COLUMN_ID);

        foreach(QTreeWidgetItem *qtwiCur,qlOldParticipants)
            if(cliInfo.gxs_ids.find(RsGxsId((*qtwiCur).text(COLUMN_ID).toStdString())) == cliInfo.gxs_ids.end())
            {
                //Old Participant go out, remove it
                int index = ui.participantsList->indexOfTopLevelItem(qtwiCur);
                delete ui.participantsList->takeTopLevelItem(index);
            }

        for (std::map<RsGxsId,time_t>::const_iterator it2(linfo.gxs_ids.begin()); it2 != linfo.gxs_ids.end(); ++it2)
        {
            QString participant = QString::fromUtf8( (it2->first).toStdString().c_str() );

            QList<QTreeWidgetItem*>  qlFoundParticipants=ui.participantsList->findItems(participant,Qt::MatchExactly,COLUMN_ID);
            GxsIdRSTreeWidgetItem *widgetitem;

            if (qlFoundParticipants.count()==0)
            {
                // TE: Add Wigdet to participantsList with Checkbox, to mute Participant

                widgetitem = new GxsIdRSTreeWidgetItem(mParticipantCompareRole,GxsIdDetails::ICON_TYPE_AVATAR);
                widgetitem->setId(it2->first,COLUMN_NAME, true) ;
                //widgetitem->setText(COLUMN_NAME, participant);
                // set activity time to the oast so that the peer is marked as inactive
                widgetitem->setText(COLUMN_ACTIVITY,QString::number(time(NULL) - timeToInactivity));
                widgetitem->setText(COLUMN_ID,QString::fromStdString(it2->first.toStdString()));

                ui.participantsList->addTopLevelItem(widgetitem);
            }
            else
                widgetitem = dynamic_cast<GxsIdRSTreeWidgetItem*>(qlFoundParticipants.at(0));

            if (isParticipantMuted(it2->first)) {
                widgetitem->setTextColor(COLUMN_NAME,QColor(255,0,0));
            } else {
                widgetitem->setTextColor(COLUMN_NAME,ui.participantsList->palette().color(QPalette::Active, QPalette::Text));
            }

            time_t tLastAct=widgetitem->text(COLUMN_ACTIVITY).toInt();
            time_t now = time(NULL);

            widgetitem->setSizeHint(COLUMN_ICON, QSize(20,20));


            if(isParticipantMuted(it2->first))
                widgetitem->setIcon(COLUMN_ICON, QIcon(":/icons/bullet_red_128.png"));
            else if (tLastAct + timeToInactivity < now)
                widgetitem->setIcon(COLUMN_ICON, QIcon(":/icons/bullet_grey_128.png"));
            else
                widgetitem->setIcon(COLUMN_ICON, QIcon(":/icons/bullet_green_128.png"));

            RsGxsId gxs_id;
            rsMsgs->getIdentityForChatLobby(lobbyId, gxs_id);

            if (RsGxsId(participant.toStdString()) == gxs_id) widgetitem->setIcon(COLUMN_ICON, QIcon(":/icons/bullet_yellow_128.png"));

            QTime qtLastAct=QTime(0,0,0).addSecs(now-tLastAct);
            widgetitem->setToolTip(COLUMN_ICON,tr("Right click to mute/unmute participants<br/>Double click to address this person<br/>")
                                   +tr("This participant is not active since:")
                                   +qtLastAct.toString()
                                   +tr(" seconds")
                                  );
        }
    }