1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Add notification lights when a friend sends you a message

This commit is contained in:
Kevin Flynn 2014-06-27 09:12:43 -07:00
parent 9ec2cb1d84
commit ddaca155ef
6 changed files with 53 additions and 6 deletions

View File

@ -1,12 +1,15 @@
#include "friend.h"
#include "friendlist.h"
#include "widget/friendwidget.h"
#include "status.h"
Friend::Friend(int FriendId, QString UserId)
: friendId(FriendId), userId(UserId)
{
widget = new FriendWidget(friendId, userId);
chatForm = new ChatForm(this);
hasNewMessages = 0;
friendStatus = Status::Offline;
}
Friend::~Friend()

View File

@ -3,6 +3,7 @@
#include <QString>
#include "widget/form/chatform.h"
#include "status.h"
class FriendWidget;
@ -20,6 +21,8 @@ public:
int friendId;
QString userId;
ChatForm* chatForm;
int hasNewMessages;
Status friendStatus;
};
#endif // FRIEND_H

Binary file not shown.

Before

Width:  |  Height:  |  Size: 424 B

After

Width:  |  Height:  |  Size: 790 B

View File

@ -25,6 +25,7 @@ public:
QLabel avatar, name, statusMessage, statusPic;
QHBoxLayout layout;
QVBoxLayout textLayout;
void setNotificationLight();
};
#endif // FRIENDWIDGET_H

View File

@ -89,6 +89,7 @@ void GroupWidget::setAsActiveChatroom()
QPalette pal3;
pal3.setColor(QPalette::Background, Qt::white);
this->setPalette(pal3);
avatar.setPixmap(QPixmap("img/contact list icons/group_dark_2x.png"));
}
void GroupWidget::setAsInactiveChatroom()
@ -105,4 +106,5 @@ void GroupWidget::setAsInactiveChatroom()
QPalette pal3;
pal3.setColor(QPalette::Background, QColor(63,63,63,255));
this->setPalette(pal3);
avatar.setPixmap(QPixmap("img/contact list icons/group_2x.png"));
}

View File

@ -82,6 +82,8 @@ Widget::Widget(QWidget *parent) :
coreThread->start();
friendForm.show(*ui);
isFriendWidgetActive = 0;
isGroupWidgetActive = 0;
}
Widget::~Widget()
@ -164,6 +166,8 @@ void Widget::onSettingsClicked()
{
hideMainForms();
settingsForm.show(*ui);
isFriendWidgetActive = 0;
isGroupWidgetActive = 0;
}
void Widget::hideMainForms()
@ -267,12 +271,8 @@ void Widget::onFriendStatusChanged(int friendId, Status status)
if (!f)
return;
if (status == Status::Online)
f->widget->statusPic.setPixmap(QPixmap("img/status/dot_online.png"));
else if (status == Status::Busy || status == Status::Away)
f->widget->statusPic.setPixmap(QPixmap("img/status/dot_idle.png"));
else if (status == Status::Offline)
f->widget->statusPic.setPixmap(QPixmap("img/status/dot_away.png"));
f->friendStatus = status;
updateFriendStatusLights(friendId);
}
void Widget::onFriendStatusMessageChanged(int friendId, const QString& message)
@ -325,6 +325,13 @@ void Widget::onFriendWidgetClicked(FriendWidget *widget)
}
activeFriendWidget = widget;
widget->setAsActiveChatroom();
isFriendWidgetActive = 1;
isGroupWidgetActive = 0;
if (f->hasNewMessages != 0)
f->hasNewMessages = 0;
updateFriendStatusLights(f->friendId);
}
void Widget::onFriendMessageReceived(int friendId, const QString& message)
@ -334,6 +341,35 @@ void Widget::onFriendMessageReceived(int friendId, const QString& message)
return;
f->chatForm->addFriendMessage(message);
if (activeFriendWidget != nullptr)
{
Friend* f2 = FriendList::findFriend(activeFriendWidget->friendId);
if ((f->friendId != f2->friendId) || isFriendWidgetActive == 0)
f->hasNewMessages = 1;
}
else
f->hasNewMessages = 1;
updateFriendStatusLights(friendId);
}
void Widget::updateFriendStatusLights(int friendId)
{
Friend* f = FriendList::findFriend(friendId);
Status status = f->friendStatus;
if (status == Status::Online && f->hasNewMessages == 0)
f->widget->statusPic.setPixmap(QPixmap("img/status/dot_online.png"));
else if (status == Status::Online && f->hasNewMessages == 1)
f->widget->statusPic.setPixmap(QPixmap("img/status/dot_online_notification.png"));
else if ((status == Status::Busy || status == Status::Away) && f->hasNewMessages == 0)
f->widget->statusPic.setPixmap(QPixmap("img/status/dot_idle.png"));
else if ((status == Status::Busy || status == Status::Away) && f->hasNewMessages == 1)
f->widget->statusPic.setPixmap(QPixmap("img/status/dot_idle_notification.png"));
else if (status == Status::Offline && f->hasNewMessages == 0)
f->widget->statusPic.setPixmap(QPixmap("img/status/dot_away.png"));
else if (status == Status::Offline && f->hasNewMessages == 1)
f->widget->statusPic.setPixmap(QPixmap("img/status/dot_away_notification.png"));
}
void Widget::onFriendRequestReceived(const QString& userId, const QString& message)
@ -406,6 +442,8 @@ void Widget::onGroupWidgetClicked(GroupWidget* widget)
}
activeGroupWidget = widget;
widget->setAsActiveChatroom();
isFriendWidgetActive = 0;
isGroupWidgetActive = 1;
}
void Widget::removeGroup(int groupId)