QStringList sslidListToQStrList(std::list<RsPeerId> in){ QStringList qResults; std::list<RsPeerId>::iterator it; for(it = in.begin(); it != in.end(); it++) { RsPeerId dd; dd = *it; qResults.append(dd.toStdString().c_str()); } return qResults; }
void VOIPGUIHandler::ReceivedInvitation(const RsPeerId &peer_id, int flags) { #ifdef VOIPGUIHANDLER_DEBUG std::cerr << "****** VOIPGUIHandler: received Invitation from peer " << peer_id.toStdString() << " with flags==" << flags << std::endl; #endif ChatDialog *di = ChatDialog::getChat(ChatId(peer_id), Settings->getChatFlags()); if (di) { ChatWidget *cw = di->getChatWidget(); if(cw) { const QList<ChatWidgetHolder*> &chatWidgetHolderList = cw->chatWidgetHolderList(); foreach (ChatWidgetHolder *chatWidgetHolder, chatWidgetHolderList) { VOIPChatWidgetHolder *acwh = dynamic_cast<VOIPChatWidgetHolder*>(chatWidgetHolder) ; if (acwh) acwh->ReceivedInvitation(peer_id, flags); } } } else {
void VOIPChatWidgetHolder::addAudioData(const RsPeerId &peer_id, QByteArray* array) { if (!audioCaptureToggleButton->isChecked()) { //launch an animation. Don't launch it if already animating if (!audioCaptureToggleButton->graphicsEffect() || (audioCaptureToggleButton->graphicsEffect()->inherits("QGraphicsOpacityEffect") && ((QGraphicsOpacityEffect*)audioCaptureToggleButton->graphicsEffect())->opacity() == 1) ) { QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect(audioListenToggleButton); audioCaptureToggleButton->setGraphicsEffect(effect); QPropertyAnimation *anim = new QPropertyAnimation(effect, "opacity", effect); anim->setStartValue(1); anim->setKeyValueAt(0.5,0); anim->setEndValue(1); anim->setDuration(400); anim->start(); } if (mChatWidget) { QString buttonName = QString::fromUtf8(rsPeers->getPeerName(peer_id).c_str()); if (buttonName.isEmpty()) buttonName = "VoIP";//TODO maybe change all with GxsId button_map::iterator it = buttonMapTakeVideo.find(buttonName); if (it == buttonMapTakeVideo.end()){ mChatWidget->addChatMsg(true, tr("VoIP Status"), QDateTime::currentDateTime(), QDateTime::currentDateTime() , tr("%1 inviting you to start a audio conversation. do you want Accept or Decline the invitation?").arg(buttonName), ChatWidget::MSGTYPE_SYSTEM); RSButtonOnText *button = mChatWidget->getNewButtonOnTextBrowser(tr("Accept Call")); button->setToolTip(tr("Activate audio")); button->setStyleSheet(QString("border: 1px solid #199909;") .append("font-size: 12pt; color: white;") .append("min-width: 128px; min-height: 24px;") .append("border-radius: 6px;") .append("background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 0.67, " "stop: 0 #22c70d, stop: 1 #116a06);") ); button->updateImage(); connect(button,SIGNAL(clicked()),this,SLOT(startAudioCapture())); connect(button,SIGNAL(mouseEnter()),this,SLOT(botMouseEnter())); connect(button,SIGNAL(mouseLeave()),this,SLOT(botMouseLeave())); buttonMapTakeVideo.insert(buttonName, button); } } audioCaptureToggleButton->setToolTip(tr("Answer")); //TODO make a sound for the incoming call // soundManager->play(VOIP_SOUND_INCOMING_CALL); if (mVOIPNotify) mVOIPNotify->notifyReceivedVoipAudioCall(peer_id); return; } if (!outputAudioDevice) { outputAudioDevice = AudioDeviceHelper::getDefaultOutputDevice(); } if (!outputAudioProcessor) { //start output audio device outputAudioProcessor = new QtSpeex::SpeexOutputProcessor(); if (inputAudioProcessor) { connect(outputAudioProcessor, SIGNAL(playingFrame(QByteArray*)), inputAudioProcessor, SLOT(addEchoFrame(QByteArray*))); } outputAudioProcessor->open(QIODevice::ReadOnly | QIODevice::Unbuffered); outputAudioDevice->start(outputAudioProcessor); } if (outputAudioDevice && outputAudioDevice->error() != QAudio::NoError) { std::cerr << "Restarting output device. Error before reset " << outputAudioDevice->error() << " buffer size : " << outputAudioDevice->bufferSize() << std::endl; outputAudioDevice->stop(); outputAudioDevice->reset(); if (outputAudioDevice->error() == QAudio::UnderrunError) outputAudioDevice->setBufferSize(20); outputAudioDevice->start(outputAudioProcessor); } outputAudioProcessor->putNetworkPacket(QString::fromStdString(peer_id.toStdString()), *array); //check the input device for errors if (inputAudioDevice && inputAudioDevice->error() != QAudio::NoError) { std::cerr << "Restarting input device. Error before reset " << inputAudioDevice->error() << std::endl; inputAudioDevice->stop(); inputAudioDevice->reset(); inputAudioDevice->start(inputAudioProcessor); } }
/** Constructor */ MessengerWindow::MessengerWindow(QWidget* parent, Qt::WindowFlags flags) : RWindow("MessengerWindow", parent, flags) { /* Invoke the Qt Designer generated object setup routine */ ui.setupUi(this); setAttribute ( Qt::WA_DeleteOnClose, true ); ui.avatar->setFrameType(AvatarWidget::STATUS_FRAME); ui.avatar->setOwnId(); connect(ui.messagelineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(savestatusmessage())); connect(NotifyQt::getInstance(), SIGNAL(ownStatusMessageChanged()), this, SLOT(loadmystatusmessage())); connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(QString,int)), this, SLOT(updateOwnStatus(QString,int))); for (std::set<std::string>::iterator peerIt = expandedPeers.begin(); peerIt != expandedPeers.end(); ++peerIt) { ui.friendList->addPeerToExpand(*peerIt); } expandedPeers.clear(); for (std::set<RsNodeGroupId>::iterator groupIt = expandedGroups.begin(); groupIt != expandedGroups.end(); ++groupIt) { ui.friendList->addGroupToExpand(*groupIt); } expandedGroups.clear(); ui.messagelineEdit->setMinimumWidth(20); /* Initialize friend list */ QToolButton *button = new QToolButton(this); button->setIcon(QIcon(":/images/user/add_user24.png")); button->setToolTip(tr("Add a Friend")); connect(button, SIGNAL(clicked()), this, SLOT(addFriend())); ui.friendList->addToolButton(button); button = new QToolButton(this); button->setIcon(QIcon(":/images/friendsfolder24.png")); button->setToolTip(tr("Share files for your friends")); connect(button, SIGNAL(clicked()), this, SLOT(openShareManager())); ui.friendList->addToolButton(button); // load settings RsAutoUpdatePage::lockAllEvents(); ui.friendList->setColumnVisible(FriendList::COLUMN_LAST_CONTACT, false); ui.friendList->setColumnVisible(FriendList::COLUMN_IP, false); ui.friendList->setShowGroups(false); processSettings(true); RsAutoUpdatePage::unlockAllEvents(); // add self nick RsPeerDetails pd; RsPeerId ownId = rsPeers->getOwnId(); if (rsPeers->getPeerDetails(ownId, pd)) { /* calculate only once */ m_nickName = QString::fromUtf8(pd.name.c_str()); } /* Show nick and current state */ StatusInfo statusInfo; rsStatus->getOwnStatus(statusInfo); updateOwnStatus(QString::fromStdString(ownId.toStdString()), statusInfo.status); MainWindow *pMainWindow = MainWindow::getInstance(); if (pMainWindow) { QMenu *pStatusMenu = new QMenu(); pMainWindow->initializeStatusObject(pStatusMenu, true); ui.statusButton->setMenu(pStatusMenu); } loadmystatusmessage(); }
void NotifyQt::testToasters(uint notifyFlags, /*RshareSettings::enumToasterPosition*/ int position, QPoint margin) { QString title = tr("Test"); QString message = tr("This is a test."); RsPeerId id = rsPeers->getOwnId(); RsPgpId pgpid = rsPeers->getGPGOwnId(); uint pos = 0; while (notifyFlags) { uint type = notifyFlags & (1 << pos); notifyFlags &= ~(1 << pos); ++pos; ToasterItem *toaster = NULL; switch(type) { case RS_POPUP_ENCRYPTED_MSG: toaster = new ToasterItem(new MessageToaster(std::string(), tr("Unknown title"), QString("[%1]").arg(tr("Encrypted message")))); break; case RS_POPUP_MSG: toaster = new ToasterItem(new MessageToaster(id.toStdString(), title, message)); break; case RS_POPUP_CONNECT: toaster = new ToasterItem(new OnlineToaster(id)); break; case RS_POPUP_DOWNLOAD: toaster = new ToasterItem(new DownloadToaster(RsFileHash::random(), title)); break; case RS_POPUP_CHAT: toaster = new ToasterItem(new ChatToaster(id, message)); break; case RS_POPUP_GROUPCHAT: toaster = new ToasterItem(new GroupChatToaster(id, message)); break; case RS_POPUP_CHATLOBBY: { std::list<RsGxsId> gxsid; if(rsIdentity->getOwnIds(gxsid) && (gxsid.size() > 0)){ toaster = new ToasterItem(new ChatLobbyToaster(0, gxsid.front(), message)); } break; } case RS_POPUP_CONNECT_ATTEMPT: toaster = new ToasterItem(new FriendRequestToaster(pgpid, title, id)); break; } if (toaster) { /* init attributes */ toaster->widget->setWindowFlags(Qt::ToolTip | Qt::WindowStaysOnTopHint); toaster->position = (RshareSettings::enumToasterPosition) position; toaster->margin = margin; /* add toaster to waiting list */ //QMutexLocker lock(&waitingToasterMutex); waitingToasterList.push_back(toaster); } } }
void ChatHandler::tick() { RS_STACK_MUTEX(mMtx); /********** LOCKED **********/ // first fetch lobbies std::vector<Lobby> lobbies; std::list<ChatLobbyId> subscribed_ids; mRsMsgs->getChatLobbyList(subscribed_ids); for(std::list<ChatLobbyId>::iterator lit = subscribed_ids.begin(); lit != subscribed_ids.end(); ++lit) { ChatLobbyInfo info; if(mRsMsgs->getChatLobbyInfo(*lit,info)) { Lobby l; l.id = *lit; l.name = info.lobby_name; l.topic = info.lobby_topic; l.subscribed = true; l.auto_subscribe = info.lobby_flags & RS_CHAT_LOBBY_FLAGS_AUTO_SUBSCRIBE; l.is_private = !(info.lobby_flags & RS_CHAT_LOBBY_FLAGS_PUBLIC); l.is_broadcast = false; l.gxs_id = info.gxs_id; lobbies.push_back(l); } } ChatId id = ChatId::makeBroadcastId(); { Lobby l; l.id = id.toLobbyId(); l.name = "BroadCast"; l.topic = "Retroshare broadcast chat: messages are sent to all connected friends."; l.subscribed = true; l.auto_subscribe = false; l.is_private = false; l.is_broadcast = true; l.gxs_id = id.toGxsId(); lobbies.push_back(l); } std::vector<VisibleChatLobbyRecord> unsubscribed_lobbies; mRsMsgs->getListOfNearbyChatLobbies(unsubscribed_lobbies); for(std::vector<VisibleChatLobbyRecord>::iterator vit = unsubscribed_lobbies.begin(); vit != unsubscribed_lobbies.end(); ++vit) { const VisibleChatLobbyRecord& info = *vit; if(std::find(subscribed_ids.begin(), subscribed_ids.end(), info.lobby_id) == subscribed_ids.end()) { Lobby l; l.id = info.lobby_id; l.name = info.lobby_name; l.topic = info.lobby_topic; l.subscribed = false; l.auto_subscribe = info.lobby_flags & RS_CHAT_LOBBY_FLAGS_AUTO_SUBSCRIBE; l.is_private = !(info.lobby_flags & RS_CHAT_LOBBY_FLAGS_PUBLIC); l.is_broadcast = false; l.gxs_id = RsGxsId(); lobbies.push_back(l); } } // process new messages bool changed = false; bool lobby_unread_count_changed = false; std::vector<std::list<ChatMessage>::iterator> done; std::vector<RsPeerId> peers_changed; bool gxs_id_failed = false; // to prevent asking for multiple failing gxs ids in one tick, to not flush the cache for(std::list<ChatMessage>::iterator lit = mRawMsgs.begin(); lit != mRawMsgs.end(); ++lit) { ChatMessage& msg = *lit; std::string author_id; std::string author_name; if(msg.chat_id.isBroadcast()) { author_id = msg.broadcast_peer_id.toStdString(); author_name = mRsPeers->getPeerName(msg.broadcast_peer_id); } else if(msg.chat_id.isGxsId()) { author_id = msg.chat_id.toGxsId().toStdString(); RsIdentityDetails details; if(!gxs_id_failed && mRsIdentity->getIdDetails(msg.chat_id.toGxsId(), details)) { author_name = details.mNickname; } else { gxs_id_failed = true; continue; } } else if(msg.chat_id.isLobbyId()) { author_id = msg.lobby_peer_gxs_id.toStdString(); RsIdentityDetails details; if(!gxs_id_failed && mRsIdentity->getIdDetails(msg.lobby_peer_gxs_id, details)) { author_name = details.mNickname; lobby_unread_count_changed = true; } else { gxs_id_failed = true; continue; } } else if(msg.chat_id.isPeerId()) { RsPeerId id; if(msg.incoming) id = msg.chat_id.toPeerId(); else id = mRsPeers->getOwnId(); author_id = id.toStdString(); author_name = mRsPeers->getPeerName(id); if(std::find(peers_changed.begin(), peers_changed.end(), msg.chat_id.toPeerId()) == peers_changed.end()) peers_changed.push_back(msg.chat_id.toPeerId()); } else { std::cerr << "Error in ChatHandler::tick(): unhandled chat_id=" << msg.chat_id.toStdString() << std::endl; // remove from queue, so msgs with wrong ids to not pile up done.push_back(lit); continue; } if(mChatInfo.find(msg.chat_id) == mChatInfo.end()) { ChatInfo info; info.is_broadcast = msg.chat_id.isBroadcast(); info.is_gxs_id = msg.chat_id.isGxsId(); info.is_lobby = msg.chat_id.isLobbyId(); info.is_peer = msg.chat_id.isPeerId(); if(msg.chat_id.isLobbyId()) { for(std::vector<Lobby>::iterator vit = mLobbies.begin(); vit != mLobbies.end(); ++vit) { if(vit->id == msg.chat_id.toLobbyId()) info.remote_author_name = vit->name; } } else if(msg.chat_id.isGxsId()) { RsIdentityDetails details; if(!gxs_id_failed && mRsIdentity->getIdDetails(msg.chat_id.toGxsId(), details)) { info.remote_author_id = msg.chat_id.toGxsId().toStdString(); info.remote_author_name = details.mNickname; } else { gxs_id_failed = true; continue; } } else if(msg.chat_id.isPeerId()) { info.remote_author_id = msg.chat_id.toPeerId().toStdString(); info.remote_author_name = mRsPeers->getPeerName(msg.chat_id.toPeerId()); } mChatInfo[msg.chat_id] = info; } Msg m; m.read = !msg.incoming; m.incoming = msg.incoming; m.was_send = msg.online; m.author_id = author_id; m.author_name = author_name; // remove html tags from chat message // extract links form href getPlainText(msg.msg, m.msg, m.links); m.recv_time = msg.recvTime; m.send_time = msg.sendTime; m.id = RSRandom::random_u32(); mMsgs[msg.chat_id].push_back(m); done.push_back(lit); changed = true; } for(std::vector<std::list<ChatMessage>::iterator>::iterator vit = done.begin(); vit != done.end(); ++vit) mRawMsgs.erase(*vit); // send changes if(changed) { mStateTokenServer->replaceToken(mMsgStateToken); mStateTokenServer->replaceToken(mUnreadMsgsStateToken); } for(std::vector<RsPeerId>::iterator vit = peers_changed.begin(); vit != peers_changed.end(); ++vit) { const std::list<Msg>& msgs = mMsgs[ChatId(*vit)]; uint32_t count = 0; for(std::list<Msg>::const_iterator lit = msgs.begin(); lit != msgs.end(); ++lit) if(!lit->read) count++; if(mUnreadMsgNotify) mUnreadMsgNotify->notifyUnreadMsgCountChanged(*vit, count); } std::sort(lobbies.begin(), lobbies.end(), &compare_lobby_id); if(lobby_unread_count_changed || mLobbies != lobbies) { mStateTokenServer->replaceToken(mLobbiesStateToken); mLobbies = lobbies; } }