12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- #include "chatmanager.h"
-
- ChatManager::ChatManager(QObject *parent) : QObject(parent)
- {
- }
-
- ChatManager::~ChatManager()
- {
- qDeleteAll(m_dlgChat);
- }
-
- void ChatManager::chat(NetSoul::Users users)
- {
- foreach(NetSoul::User user, users)
- {
- DialogChat* ch = getChatWindow(user);
- ch->show();
- ch->raise();
- }
- }
-
- void ChatManager::newMessage(NetSoul::Message msg)
- {
- DialogChat* ch = getChatWindow(msg.from);
- ch->newMessage(msg);
- if(!ch->isVisible())
- ch->showMinimized();
- if(!ch->isActiveWindow())
- QApplication::alert(ch);
- }
-
- void ChatManager::setMe(NetSoul::User user)
- {
- if(user.login != m_me.login)
- {
- qDeleteAll(m_dlgChat);
- m_dlgChat.clear();
- }
- m_me = user;
- }
-
- void ChatManager::dlgChatsendMessage(NetSoul::User usr, QString msg)
- {
- emit sendMessageRequested(usr, msg);
- }
-
- DialogChat*ChatManager::getChatWindow(NetSoul::User user)
- {
- foreach(DialogChat* ch, m_dlgChat)
- if(ch->match(user))
- return ch;
- DialogChat* ch = new DialogChat();
- connect(ch, SIGNAL(sendMessageRequested(NetSoul::User,QString)), this, SLOT(dlgChatsendMessage(NetSoul::User,QString)));
- m_dlgChat.append(ch);
- ch->setUser(user);
- ch->setMe(m_me);
- return ch;
- }
|