Merge pull request #6 from F1ynn/master
Added basic friend chat notifications
|
@ -1,12 +1,15 @@
|
||||||
#include "friend.h"
|
#include "friend.h"
|
||||||
#include "friendlist.h"
|
#include "friendlist.h"
|
||||||
#include "widget/friendwidget.h"
|
#include "widget/friendwidget.h"
|
||||||
|
#include "status.h"
|
||||||
|
|
||||||
Friend::Friend(int FriendId, QString UserId)
|
Friend::Friend(int FriendId, QString UserId)
|
||||||
: friendId(FriendId), userId(UserId)
|
: friendId(FriendId), userId(UserId)
|
||||||
{
|
{
|
||||||
widget = new FriendWidget(friendId, userId);
|
widget = new FriendWidget(friendId, userId);
|
||||||
chatForm = new ChatForm(this);
|
chatForm = new ChatForm(this);
|
||||||
|
hasNewMessages = 0;
|
||||||
|
friendStatus = Status::Offline;
|
||||||
}
|
}
|
||||||
|
|
||||||
Friend::~Friend()
|
Friend::~Friend()
|
||||||
|
|
3
friend.h
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include "widget/form/chatform.h"
|
#include "widget/form/chatform.h"
|
||||||
|
#include "status.h"
|
||||||
|
|
||||||
class FriendWidget;
|
class FriendWidget;
|
||||||
|
|
||||||
|
@ -20,6 +21,8 @@ public:
|
||||||
int friendId;
|
int friendId;
|
||||||
QString userId;
|
QString userId;
|
||||||
ChatForm* chatForm;
|
ChatForm* chatForm;
|
||||||
|
int hasNewMessages;
|
||||||
|
Status friendStatus;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FRIEND_H
|
#endif // FRIEND_H
|
||||||
|
|
Before Width: | Height: | Size: 407 B After Width: | Height: | Size: 378 B |
Before Width: | Height: | Size: 472 B After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 240 B After Width: | Height: | Size: 376 B |
Before Width: | Height: | Size: 458 B After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 272 B After Width: | Height: | Size: 288 B |
Before Width: | Height: | Size: 424 B After Width: | Height: | Size: 1.0 KiB |
|
@ -89,6 +89,7 @@ void GroupWidget::setAsActiveChatroom()
|
||||||
QPalette pal3;
|
QPalette pal3;
|
||||||
pal3.setColor(QPalette::Background, Qt::white);
|
pal3.setColor(QPalette::Background, Qt::white);
|
||||||
this->setPalette(pal3);
|
this->setPalette(pal3);
|
||||||
|
avatar.setPixmap(QPixmap("img/contact list icons/group_dark_2x.png"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GroupWidget::setAsInactiveChatroom()
|
void GroupWidget::setAsInactiveChatroom()
|
||||||
|
@ -105,4 +106,5 @@ void GroupWidget::setAsInactiveChatroom()
|
||||||
QPalette pal3;
|
QPalette pal3;
|
||||||
pal3.setColor(QPalette::Background, QColor(63,63,63,255));
|
pal3.setColor(QPalette::Background, QColor(63,63,63,255));
|
||||||
this->setPalette(pal3);
|
this->setPalette(pal3);
|
||||||
|
avatar.setPixmap(QPixmap("img/contact list icons/group_2x.png"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,6 +82,8 @@ Widget::Widget(QWidget *parent) :
|
||||||
coreThread->start();
|
coreThread->start();
|
||||||
|
|
||||||
friendForm.show(*ui);
|
friendForm.show(*ui);
|
||||||
|
isFriendWidgetActive = 0;
|
||||||
|
isGroupWidgetActive = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget::~Widget()
|
Widget::~Widget()
|
||||||
|
@ -164,6 +166,8 @@ void Widget::onSettingsClicked()
|
||||||
{
|
{
|
||||||
hideMainForms();
|
hideMainForms();
|
||||||
settingsForm.show(*ui);
|
settingsForm.show(*ui);
|
||||||
|
isFriendWidgetActive = 0;
|
||||||
|
isGroupWidgetActive = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::hideMainForms()
|
void Widget::hideMainForms()
|
||||||
|
@ -267,12 +271,8 @@ void Widget::onFriendStatusChanged(int friendId, Status status)
|
||||||
if (!f)
|
if (!f)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (status == Status::Online)
|
f->friendStatus = status;
|
||||||
f->widget->statusPic.setPixmap(QPixmap("img/status/dot_online.png"));
|
updateFriendStatusLights(friendId);
|
||||||
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"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::onFriendStatusMessageChanged(int friendId, const QString& message)
|
void Widget::onFriendStatusMessageChanged(int friendId, const QString& message)
|
||||||
|
@ -325,6 +325,13 @@ void Widget::onFriendWidgetClicked(FriendWidget *widget)
|
||||||
}
|
}
|
||||||
activeFriendWidget = widget;
|
activeFriendWidget = widget;
|
||||||
widget->setAsActiveChatroom();
|
widget->setAsActiveChatroom();
|
||||||
|
isFriendWidgetActive = 1;
|
||||||
|
isGroupWidgetActive = 0;
|
||||||
|
|
||||||
|
if (f->hasNewMessages != 0)
|
||||||
|
f->hasNewMessages = 0;
|
||||||
|
|
||||||
|
updateFriendStatusLights(f->friendId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::onFriendMessageReceived(int friendId, const QString& message)
|
void Widget::onFriendMessageReceived(int friendId, const QString& message)
|
||||||
|
@ -334,6 +341,35 @@ void Widget::onFriendMessageReceived(int friendId, const QString& message)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
f->chatForm->addFriendMessage(message);
|
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)
|
void Widget::onFriendRequestReceived(const QString& userId, const QString& message)
|
||||||
|
@ -406,6 +442,8 @@ void Widget::onGroupWidgetClicked(GroupWidget* widget)
|
||||||
}
|
}
|
||||||
activeGroupWidget = widget;
|
activeGroupWidget = widget;
|
||||||
widget->setAsActiveChatroom();
|
widget->setAsActiveChatroom();
|
||||||
|
isFriendWidgetActive = 0;
|
||||||
|
isGroupWidgetActive = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::removeGroup(int groupId)
|
void Widget::removeGroup(int groupId)
|
||||||
|
|
|
@ -82,6 +82,8 @@ private:
|
||||||
static Widget* instance;
|
static Widget* instance;
|
||||||
FriendWidget* activeFriendWidget;
|
FriendWidget* activeFriendWidget;
|
||||||
GroupWidget* activeGroupWidget;
|
GroupWidget* activeGroupWidget;
|
||||||
|
void updateFriendStatusLights(int friendId);
|
||||||
|
int isFriendWidgetActive, isGroupWidgetActive;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WIDGET_H
|
#endif // WIDGET_H
|
||||||
|
|