Example #1
0
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());
    }
}
Example #2
0
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()));
    }
}
Example #3
0
void CircleWidget::dropEvent(QDropEvent* event)
{
    setExpanded(true, false);

    // Check, that the element is dropped from qTox
    QObject* o = event->source();
    FriendWidget* widget = qobject_cast<FriendWidget*>(o);
    if (!widget)
        return;

    // Check, that the user has a friend with the same ToxId
    ToxId toxId(event->mimeData()->text());
    Friend* f = FriendList::findFriend(toxId.getPublicKey());
    if (!f)
        return;

    // Save CircleWidget before changing the Id
    int circleId = Settings::getInstance().getFriendCircleID(toxId.getPublicKey());
    CircleWidget* circleWidget = getFromID(circleId);

    addFriendWidget(widget, f->getStatus());
    Settings::getInstance().savePersonal();

    if (circleWidget != nullptr) {
        circleWidget->updateStatus();
        Widget::getInstance()->searchCircle(circleWidget);
    }

    setContainerAttribute(Qt::WA_UnderMouse, false);
}
Example #4
0
void FriendListWidget::moveWidget(FriendWidget* w, Status s, bool add)
{
    if (mode == Name)
    {
        int circleId = Settings::getInstance().getFriendCircleID(FriendList::findFriend(w->friendId)->getToxId());
        CircleWidget* circleWidget = CircleWidget::getFromID(circleId);

        if (circleWidget == nullptr || add)
        {
            if (circleId != -1)
                Settings::getInstance().setFriendCircleID(FriendList::findFriend(w->friendId)->getToxId(), -1);

            listLayout->addFriendWidget(w, s);
            return;
        }

        circleWidget->addFriendWidget(w, s);
    }
    else
    {
        Friend* contact = FriendList::findFriend(w->friendId);
        QDate activityDate = getDateFriend(contact);
        Time time = getTime(activityDate);
        CategoryWidget* categoryWidget = dynamic_cast<CategoryWidget*>(activityLayout->itemAt(time)->widget());
        categoryWidget->addFriendWidget(contact->getFriendWidget(), contact->getStatus());
        categoryWidget->show();
    }
}
Example #5
0
void FriendListWidget::moveWidget(FriendWidget* widget, Status s, bool add)
{
    if (mode == Name) {
        Friend* f = FriendList::findFriend(widget->friendId);
        int circleId = Settings::getInstance().getFriendCircleID(f->getPublicKey());
        CircleWidget* circleWidget = CircleWidget::getFromID(circleId);

        if (circleWidget == nullptr || add) {
            if (circleId != -1)
                Settings::getInstance().setFriendCircleID(f->getPublicKey(), -1);

            listLayout->addFriendWidget(widget, s);
            return;
        }

        circleWidget->addFriendWidget(widget, s);
    } else {
        Friend* contact = FriendList::findFriend(widget->friendId);
        QDate activityDate = getDateFriend(contact);
        int time = static_cast<int>(getTime(activityDate));
        QWidget* w = activityLayout->itemAt(time)->widget();
        CategoryWidget* categoryWidget = qobject_cast<CategoryWidget*>(w);
        categoryWidget->addFriendWidget(widget, contact->getStatus());
        categoryWidget->show();
    }
}
Example #6
0
void FriendListWidget::removeFriendWidget(FriendWidget* w)
{
    Friend* contact = FriendList::findFriend(w->friendId);
    if (mode == Activity) {
        QDate activityDate = getDateFriend(contact);
        int time = static_cast<int>(getTime(activityDate));
        QWidget* widget = activityLayout->itemAt(time)->widget();
        CategoryWidget* categoryWidget = qobject_cast<CategoryWidget*>(widget);
        categoryWidget->removeFriendWidget(w, contact->getStatus());
        categoryWidget->setVisible(categoryWidget->hasChatrooms());
    } else {
        int id = Settings::getInstance().getFriendCircleID(contact->getPublicKey());
        CircleWidget* circleWidget = CircleWidget::getFromID(id);
        if (circleWidget != nullptr) {
            circleWidget->removeFriendWidget(w, contact->getStatus());
            Widget::getInstance()->searchCircle(circleWidget);
        }
    }
}
Example #7
0
void ContentDialogManager::updateFriendStatus(const ToxPk& friendPk)
{
    auto dialog = contactDialogs.value(friendPk);
    if (dialog == nullptr) {
        return;
    }

    dialog->updateContactStatusLight(friendPk);
    if (dialog->isContactWidgetActive(friendPk)) {
        dialog->updateTitleAndStatusIcon();
    }

    Friend* f = FriendList::findFriend(friendPk);
    dialog->updateFriendStatus(friendPk, f->getStatus());
}
Example #8
0
QString FriendWidget::getStatusString() const
{
    Friend* f = FriendList::findFriend(friendId);
    Status status = f->getStatus();

    if (f->getEventFlag() == 1)
        return tr("New message");
    else if (status == Status::Online)
        return tr("Online");
    else if (status == Status::Away)
        return tr("Away");
    else if (status == Status::Busy)
        return tr("Busy");
    else if (status == Status::Offline)
        return tr("Offline");
    return QString::null;
}
Example #9
0
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();
    }
}
Example #10
0
void FriendListWidget::moveFriends(QLayout* layout)
{
    for (int i = 0; i < layout->count(); i++) {
        QWidget* widget = layout->itemAt(i)->widget();
        FriendWidget* friendWidget = qobject_cast<FriendWidget*>(widget);
        CircleWidget* circleWidget = qobject_cast<CircleWidget*>(widget);
        if (circleWidget) {
            circleWidget->moveFriendWidgets(this);
        } else if (friendWidget) {
            int friendId = friendWidget->friendId;
            Friend* contact = FriendList::findFriend(friendId);
            QDate activityDate = getDateFriend(contact);
            int time = static_cast<int>(getTime(activityDate));

            QWidget* w = activityLayout->itemAt(time)->widget();
            CategoryWidget* categoryWidget = qobject_cast<CategoryWidget*>(w);
            categoryWidget->addFriendWidget(friendWidget, contact->getStatus());
        }
    }
}
Example #11
0
void FriendWidget::updateStatusLight()
{
    Friend* f = FriendList::findFriend(friendId);
    Status status = f->getStatus();

    if (status == Status::Online && f->getEventFlag() == 0)
        statusPic.setPixmap(QPixmap(":img/status/dot_online.png"));
    else if (status == Status::Online && f->getEventFlag() == 1)
        statusPic.setPixmap(QPixmap(":img/status/dot_online_notification.png"));
    else if (status == Status::Away && f->getEventFlag() == 0)
        statusPic.setPixmap(QPixmap(":img/status/dot_idle.png"));
    else if (status == Status::Away && f->getEventFlag() == 1)
        statusPic.setPixmap(QPixmap(":img/status/dot_idle_notification.png"));
    else if (status == Status::Busy && f->getEventFlag() == 0)
        statusPic.setPixmap(QPixmap(":img/status/dot_busy.png"));
    else if (status == Status::Busy && f->getEventFlag() == 1)
        statusPic.setPixmap(QPixmap(":img/status/dot_busy_notification.png"));
    else if (status == Status::Offline && f->getEventFlag() == 0)
        statusPic.setPixmap(QPixmap(":img/status/dot_away.png"));
    else if (status == Status::Offline && f->getEventFlag() == 1)
        statusPic.setPixmap(QPixmap(":img/status/dot_away_notification.png"));
}
Example #12
0
void FriendListWidget::dropEvent(QDropEvent* event)
{
    // Check, that the element is dropped from qTox
    QObject* o = event->source();
    FriendWidget* widget = qobject_cast<FriendWidget*>(o);
    if (!widget)
        return;

    // Check, that the user has a friend with the same ToxId
    ToxId toxId(event->mimeData()->text());
    Friend* f = FriendList::findFriend(toxId.getPublicKey());
    if (!f)
        return;

    // Save CircleWidget before changing the Id
    int circleId = Settings::getInstance().getFriendCircleID(f->getPublicKey());
    CircleWidget* circleWidget = CircleWidget::getFromID(circleId);

    moveWidget(widget, f->getStatus(), true);

    if (circleWidget)
        circleWidget->updateStatus();
}
Example #13
0
void FriendWidget::updateStatusLight()
{
    Friend* f = FriendList::findFriend(friendId);
    Status status = f->getStatus();

    if (status == Status::Online && f->getEventFlag() == 0)
        statusPic.setPixmap(QPixmap(":img/status/dot_online.svg"));
    else if (status == Status::Online && f->getEventFlag() == 1)
        statusPic.setPixmap(QPixmap(":img/status/dot_online_notification.svg"));
    else if (status == Status::Away && f->getEventFlag() == 0)
        statusPic.setPixmap(QPixmap(":img/status/dot_away.svg"));
    else if (status == Status::Away && f->getEventFlag() == 1)
        statusPic.setPixmap(QPixmap(":img/status/dot_away_notification.svg"));
    else if (status == Status::Busy && f->getEventFlag() == 0)
        statusPic.setPixmap(QPixmap(":img/status/dot_busy.svg"));
    else if (status == Status::Busy && f->getEventFlag() == 1)
        statusPic.setPixmap(QPixmap(":img/status/dot_busy_notification.svg"));
    else if (status == Status::Offline && f->getEventFlag() == 0)
        statusPic.setPixmap(QPixmap(":img/status/dot_offline.svg"));
    else if (status == Status::Offline && f->getEventFlag() == 1)
        statusPic.setPixmap(QPixmap(":img/status/dot_offline_notification.svg"));

    if (f->getEventFlag())
    {
        CircleWidget* circleWidget = CircleWidget::getFromID(Settings::getInstance().getFriendCircleID(FriendList::findFriend(friendId)->getToxId()));
        if (circleWidget != nullptr)
            circleWidget->setExpanded(true);

        Widget::getInstance()->updateFriendActivity(FriendList::findFriend(friendId));
    }

    if (!f->getEventFlag())
        statusPic.setMargin(3);
    else
        statusPic.setMargin(0);
}
Example #14
0
void FriendListWidget::addCircleWidget(FriendWidget* friendWidget)
{
    CircleWidget* circleWidget = createCircleWidget();
    if (circleWidget != nullptr) {
        if (friendWidget != nullptr) {
            Friend* f = FriendList::findFriend(friendWidget->friendId);
            ToxPk toxPk = f->getPublicKey();
            int circleId = Settings::getInstance().getFriendCircleID(toxPk);
            CircleWidget* circleOriginal = CircleWidget::getFromID(circleId);

            circleWidget->addFriendWidget(friendWidget, f->getStatus());
            circleWidget->setExpanded(true);

            if (circleOriginal != nullptr)
                Widget::getInstance()->searchCircle(circleOriginal);
        }

        Widget::getInstance()->searchCircle(circleWidget);

        if (window()->isActiveWindow())
            circleWidget->editName();
    }
    reDraw();
}