void Widget::addFriend(int friendId, const QString &userId) { //qDebug() << "Widget: Adding friend with id" << userId; ToxID userToxId = ToxID::fromString(userId); Friend* newfriend = FriendList::addFriend(friendId, userToxId); QLayout* layout = contactListWidget->getFriendLayout(Status::Offline); layout->addWidget(newfriend->getFriendWidget()); if (Settings::getInstance().getEnableLogging()) newfriend->getChatForm()->loadHistory(QDateTime::currentDateTime().addDays(-7), true); connect(newfriend->getFriendWidget(), SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), this, SLOT(onChatroomWidgetClicked(GenericChatroomWidget*))); connect(newfriend->getFriendWidget(), SIGNAL(removeFriend(int)), this, SLOT(removeFriend(int))); connect(newfriend->getFriendWidget(), SIGNAL(copyFriendIdToClipboard(int)), this, SLOT(copyFriendIdToClipboard(int))); connect(newfriend->getFriendWidget(), SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), newfriend->getChatForm(), SLOT(focusInput())); connect(newfriend->getChatForm(), SIGNAL(sendMessage(int,QString)), core, SLOT(sendMessage(int,QString))); connect(newfriend->getChatForm(), &GenericChatForm::sendAction, core, &Core::sendAction); connect(newfriend->getChatForm(), SIGNAL(sendFile(int32_t, QString, QString, long long)), core, SLOT(sendFile(int32_t, QString, QString, long long))); connect(newfriend->getChatForm(), SIGNAL(answerCall(int)), core, SLOT(answerCall(int))); connect(newfriend->getChatForm(), SIGNAL(hangupCall(int)), core, SLOT(hangupCall(int))); connect(newfriend->getChatForm(), SIGNAL(startCall(int)), core, SLOT(startCall(int))); connect(newfriend->getChatForm(), SIGNAL(startVideoCall(int,bool)), core, SLOT(startCall(int,bool))); connect(newfriend->getChatForm(), SIGNAL(cancelCall(int,int)), core, SLOT(cancelCall(int,int))); connect(newfriend->getChatForm(), SIGNAL(micMuteToggle(int)), core, SLOT(micMuteToggle(int))); connect(newfriend->getChatForm(), SIGNAL(volMuteToggle(int)), core, SLOT(volMuteToggle(int))); connect(newfriend->getChatForm(), &ChatForm::aliasChanged, newfriend->getFriendWidget(), &FriendWidget::setAlias); connect(core, &Core::fileReceiveRequested, newfriend->getChatForm(), &ChatForm::onFileRecvRequest); connect(core, &Core::avInvite, newfriend->getChatForm(), &ChatForm::onAvInvite); connect(core, &Core::avStart, newfriend->getChatForm(), &ChatForm::onAvStart); connect(core, &Core::avCancel, newfriend->getChatForm(), &ChatForm::onAvCancel); connect(core, &Core::avEnd, newfriend->getChatForm(), &ChatForm::onAvEnd); connect(core, &Core::avRinging, newfriend->getChatForm(), &ChatForm::onAvRinging); connect(core, &Core::avStarting, newfriend->getChatForm(), &ChatForm::onAvStarting); connect(core, &Core::avEnding, newfriend->getChatForm(), &ChatForm::onAvEnding); connect(core, &Core::avRequestTimeout, newfriend->getChatForm(), &ChatForm::onAvRequestTimeout); connect(core, &Core::avPeerTimeout, newfriend->getChatForm(), &ChatForm::onAvPeerTimeout); connect(core, &Core::avMediaChange, newfriend->getChatForm(), &ChatForm::onAvMediaChange); connect(core, &Core::avCallFailed, newfriend->getChatForm(), &ChatForm::onAvCallFailed); connect(core, &Core::avRejected, newfriend->getChatForm(), &ChatForm::onAvRejected); connect(core, &Core::friendAvatarChanged, newfriend->getChatForm(), &ChatForm::onAvatarChange); connect(core, &Core::friendAvatarChanged, newfriend->getFriendWidget(), &FriendWidget::onAvatarChange); connect(core, &Core::friendAvatarRemoved, newfriend->getChatForm(), &ChatForm::onAvatarRemoved); connect(core, &Core::friendAvatarRemoved, newfriend->getFriendWidget(), &FriendWidget::onAvatarRemoved); // Try to get the avatar from the cache QPixmap avatar = Settings::getInstance().getSavedAvatar(userId); if (!avatar.isNull()) { //qWarning() << "Widget: loadded avatar for id" << userId; newfriend->getChatForm()->onAvatarChange(friendId, avatar); newfriend->getFriendWidget()->onAvatarChange(friendId, avatar); } }
void Widget::onFriendStatusChanged(int friendId, Status status) { Friend* f = FriendList::findFriend(friendId); if (!f) return; contactListWidget->moveWidget(f->getFriendWidget(), status); bool isActualChange = f->getStatus() != status; f->setStatus(status); f->getFriendWidget()->updateStatusLight(); //won't print the message if there were no messages before if(!f->getChatForm()->isEmpty() && Settings::getInstance().getStatusChangeNotificationEnabled()) { QString fStatus = ""; switch(f->getStatus()){ case Status::Away: fStatus = tr("away", "contact status"); break; case Status::Busy: fStatus = tr("busy", "contact status"); break; case Status::Offline: fStatus = tr("offline", "contact status"); break; default: fStatus = tr("online", "contact status"); break; } if (isActualChange) f->getChatForm()->addSystemInfoMessage(tr("%1 is now %2", "e.g. \"Dubslow is now online\"").arg(f->getDisplayedName()).arg(fStatus), "white", QDateTime::currentDateTime()); } if (isActualChange && status != Status::Offline) { // wait a little QTimer::singleShot(250, f->getChatForm(), SLOT(deliverOfflineMsgs())); } }
bool ContentDialog::event(QEvent* event) { switch (event->type()) { case QEvent::WindowActivate: if (activeChatroomWidget != nullptr) { activeChatroomWidget->resetEventFlags(); activeChatroomWidget->updateStatusLight(); updateTitle(activeChatroomWidget); Friend* frnd = activeChatroomWidget->getFriend(); if (frnd) { frnd->getFriendWidget()->resetEventFlags(); frnd->getFriendWidget()->updateStatusLight(); } else { Group* g = activeChatroomWidget->getGroup(); g->getGroupWidget()->resetEventFlags(); g->getGroupWidget()->updateStatusLight(); } } currentDialog = this; #ifdef Q_OS_MAC emit activated(); #endif default: break; } return ActivateDialog::event(event); }
void FriendListWidget::dropEvent(QDropEvent* event) { if (event->mimeData()->hasFormat("friend")) { int friendId = event->mimeData()->data("friend").toInt(); Friend* f = FriendList::findFriend(friendId); assert(f != nullptr); FriendWidget* widget = f->getFriendWidget(); assert(widget != nullptr); // Update old circle after moved. CircleWidget* circleWidget = CircleWidget::getFromID(Settings::getInstance().getFriendCircleID(f->getToxId())); moveWidget(widget, f->getStatus(), true); if (circleWidget != nullptr) circleWidget->updateStatus(); } }
bool ContentDialog::event(QEvent* event) { switch (event->type()) { case QEvent::WindowActivate: if (activeChatroomWidget != nullptr) { activeChatroomWidget->resetEventFlags(); activeChatroomWidget->updateStatusLight(); updateTitle(activeChatroomWidget); Friend* frnd = activeChatroomWidget->getFriend(); Group* group = activeChatroomWidget->getGroup(); GenericChatroomWidget *widget = nullptr; if (frnd) widget = frnd->getFriendWidget(); else widget = group->getGroupWidget(); widget->resetEventFlags(); widget->updateStatusLight(); Widget::getInstance()->updateScroll(widget); Widget::getInstance()->resetIcon(); } currentDialog = this; #ifdef Q_OS_MAC emit activated(); #endif default: break; } return ActivateDialog::event(event); }