コード例 #1
0
ファイル: friendlist.cpp プロジェクト: qTox/qTox
QString FriendList::decideNickname(const ToxPk& friendPk, const QString& origName)
{
    Friend* f = FriendList::findFriend(friendPk);
    if (f != nullptr) {
        return f->getDisplayedName();
    } else if (!origName.isEmpty()) {
        return origName;
    } else {
        return friendPk.toString();
    }
}
コード例 #2
0
ファイル: group.cpp プロジェクト: barry-ran/qTox
void Group::updatePeer(int peerId, QString name)
{
    ToxPk peerKey = Core::getInstance()->getGroupPeerPk(groupId, peerId);
    toxpks[peerKey] = name;

    Friend* f = FriendList::findFriend(peerKey);
    if (f != nullptr) {
        // use the displayed name from the friends list
        toxpks[peerKey] = f->getDisplayedName();
    } else {
        emit userListChanged(groupId, toxpks);
    }
}
コード例 #3
0
ファイル: friendwidget.cpp プロジェクト: darkcoconuts/qTox
void FriendWidget::setFriendAlias()
{
    bool ok;
    Friend* f = FriendList::findFriend(friendId);

    QString alias = QInputDialog::getText(nullptr, tr("User alias"), tr("Alias:"), QLineEdit::Normal,
                                          f->getDisplayedName(), &ok);

    if (ok)
    {
        alias = alias.trimmed();
        alias.remove(QRegExp("[\t\n\v\f\r]"));
        alias = alias.left(128); // same as TOX_MAX_NAME_LENGTH
        f->setAlias(alias);
        Settings::getInstance().setFriendAlias(f->getToxID(), alias);
        hide();
        show();

        if (f->getFriendWidget()->isActive())
            Widget::getInstance()->setWindowTitle(f->getFriendWidget()->getName() + " - qTox");
    }
}
コード例 #4
0
ファイル: group.cpp プロジェクト: barry-ran/qTox
void Group::regeneratePeerList()
{
    const Core* core = Core::getInstance();

    QStringList peers = core->getGroupPeerNames(groupId);
    toxpks.clear();
    const int nPeers = peers.size();
    for (int i = 0; i < nPeers; ++i) {
        const auto pk = core->getGroupPeerPk(groupId, i);

        toxpks[pk] = peers[i];
        if (toxpks[pk].isEmpty()) {
            toxpks[pk] =
                tr("<Empty>", "Placeholder when someone's name in a group chat is empty");
        }

        Friend* f = FriendList::findFriend(pk);
        if (f != nullptr && f->hasAlias()) {
            toxpks[pk] = f->getDisplayedName();
        }
    }

    emit userListChanged(groupId, toxpks);
}
コード例 #5
0
ファイル: widget.cpp プロジェクト: darkcoconuts/qTox
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() == true)
    {
        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());
    }
}
コード例 #6
0
ファイル: widget.cpp プロジェクト: AWeinb/qTox
void Widget::onFriendStatusChanged(int friendId, Status status)
{
    Friend* f = FriendList::findFriend(friendId);
    if (!f)
        return;

    bool isActualChange = f->getStatus() != status;

    if (isActualChange)
    {
        if (f->getStatus() == Status::Offline)
        {
            contactListWidget->moveWidget(f->getFriendWidget(), Status::Online, f->getEventFlag());
        }
        else if (status == Status::Offline)
        {
            contactListWidget->moveWidget(f->getFriendWidget(), Status::Offline, f->getEventFlag());
        }
    }

    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");
            f->getChatForm()->setFriendTyping(false); // Hide the "is typing" message when a friend goes offline
            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),
                                                   ChatMessage::INFO, QDateTime::currentDateTime());
    }

    if (isActualChange && status != Status::Offline)
    { // wait a little
        QTimer::singleShot(250, f->getChatForm()->getOfflineMsgEngine(), SLOT(deliverOfflineMsgs()));
    }
}