QString MsgViewBase::messageText(Message *msg, bool bUnread) { QString options; QString info; QString status; const char *icon = "message"; const CommandDef *def = CorePlugin::m_plugin->messageTypes.find(msg->type()); if (def) icon = def->icon; bool bDirection = false; if (msg->type() == MessageStatus){ icon = "empty"; StatusMessage *sm = static_cast<StatusMessage*>(msg); Client *client = NULL; string clientStr; if (msg->client()) clientStr = msg->client(); int n = clientStr.find_last_of('.'); if (n >= 0){ clientStr = clientStr.substr(0, n); }else{ clientStr = ""; } if (!clientStr.empty()){ for (unsigned i = 0; i < getContacts()->nClients(); i++){ string n = getContacts()->getClient(i)->name(); if (n.length() < clientStr.length()) continue; n = n.substr(0, clientStr.length()); if (clientStr == n){ client = getContacts()->getClient(i); break; } } } if ((client == NULL) && getContacts()->nClients()) client = getContacts()->getClient(0); if (client){ for (def = client->protocol()->statusList(); def->text; def++){ if (def->id == sm->getStatus()){ icon = def->icon; status = i18n(def->text); break; } } } options += " direction=\"2\""; bDirection = true; }else{ MessageDef *m_def = (MessageDef*)(def->param); if (m_def->flags & MESSAGE_INFO){ options += " direction=\"2\""; bDirection = true; } } info = QString("<icon>%1</icon>") .arg(icon); QString contactName; if (msg->getFlags() & MESSAGE_RECEIVED){ if (!bDirection) options += " direction=\"1\""; Contact *contact = getContacts()->contact(msg->contact()); if (contact){ contactName = contact->getName(); if (contactName.isEmpty()){ Client *client = NULL; ClientDataIterator it(contact->clientData); void *data; while ((data = ++it) != NULL){ if (it.client()->dataName(data) == msg->client()){ client = it.client(); break; } } } } if (!bUnread){ for (list<msg_id>::iterator it = CorePlugin::m_plugin->unread.begin(); it != CorePlugin::m_plugin->unread.end(); ++it){ msg_id &m = (*it); if ((m.id == msg->id()) && (m.contact == msg->contact()) && (m.client == msg->client())){ bUnread = true; break; } } } if (bUnread) options += " unread=\"1\""; }else{ if (!bDirection) options += " direction=\"0\""; contactName = getContacts()->owner()->getName(); } if (contactName.isEmpty()) contactName = "???"; info += QString("<from>%1</from>") .arg(quoteString(contactName)); QString id = QString::number(msg->id()); id += ","; // <hack> // Terrible hack to set message bgcolor. We prefer to insert the entire history // in one chunk (since it's more efficient and causes less redraws), and there's // no way to set block's background color directly in Qt's HTML), so we make a note // of it in the HTML and set it retroactively in setBackground. if ((msg->getBackground() != 0xFFFFFFFF) && (msg->getForeground() != msg->getBackground())) id += QString::number(msg->getBackground()); // </hack> string client_str; if (msg->client()) client_str = msg->client(); if (!client_str.empty()){ id += ","; id += quoteString(client_str.c_str()); } if (m_cut.size()){ id += ","; id += QString::number(m_cut.size()); } info += "<id>"; info += id; info += "</id>"; QString icons; if (msg->getFlags() & MESSAGE_SECURE) options += " encrypted=\"1\""; if (msg->getFlags() & MESSAGE_URGENT) options += " urgent=\"1\""; if (msg->getFlags() & MESSAGE_LIST) options += " list=\"1\""; QString s; QDateTime t; t.setTime_t(msg->getTime()); info += s.sprintf("<time><date>%%1</date><hour>%02u</hour><minute>%02u</minute><second>%02u</second></time>", t.time().hour(), t.time().minute(), t.time().second()) .arg(formatDate(msg->getTime())); s = "<?xml version=\"1.0\"?><message"; s += options; s += ">"; s += info; QString msgText; if (msg->type() != MessageStatus){ msgText = msg->presentation(); if (msgText.isEmpty()){ unsigned type = msg->baseType(); CommandDef *cmd = CorePlugin::m_plugin->messageTypes.find(type); if (cmd){ MessageDef *def = (MessageDef*)(cmd->param); msgText = i18n(def->singular, def->plural, 1); int n = msgText.find("1 "); if (n == 0){ msgText = msgText.mid(2); }else if (n > 0){ msgText = msgText.left(n); } msgText = QString("<p>") + msgText + "</p>"; } QString text = msg->getRichText(); msgText += text; } }else{ msgText = status; } Event e(EventEncodeText, &msgText); e.process(); ViewParser parser(CorePlugin::m_plugin->getOwnColors(), CorePlugin::m_plugin->getUseSmiles()); msgText = parser.parse(msgText); s += "<body"; if ((msg->getForeground() != 0xFFFFFFFF) && (msg->getForeground() != msg->getBackground())) { s += " fgcolor=\"#"; s += QString::number(msg->getForeground(), 16).rightJustify(6, '0'); s += "\""; } // Some bright day might come when one could specify background color from inside Qt's richtext. // Meanwhile, this is useless: if ((msg->getBackground() != 0xFFFFFFFF) && (msg->getForeground() != msg->getBackground())) { s += " bgcolor=\"#"; s += QString::number(msg->getBackground(), 16).rightJustify(6, '0'); s += "\""; } s += ">"; // We pass the rich text quoted, since we're not sure of its' XML validity. // The XSL engine should copy it as-is (using xsl:value-of with disable-output-escaping="yes"). s += quoteString(QString(MSG_BEGIN) + msgText); s += "</body>"; s += "</message>"; XSL *p = xsl; if (p == NULL) p = CorePlugin::m_plugin->historyXSL; QString res = p->process(s); QString anchor = MSG_ANCHOR; anchor += id; anchor += "\">"; res = anchor + res; int startPos = res.find(MSG_BEGIN); int paraPos; if (parser.m_bParaStart){ paraPos = res.find("<p"); if (paraPos >= 0) res = res.left(paraPos) + "</p>" + res.mid(paraPos); } paraPos = res.findRev("<p", startPos); QString dir = " dir=\""; dir += parser.RTL ? "rtl" : "ltr"; dir += "\""; if (paraPos >= 0){ res = res.left(paraPos + 2) + dir + res.mid(paraPos + 2); }else{ res = QString("<p") + dir + ">" + res; } return res; }
QString MsgViewBase::messageText(Message *msg) { QString color; color.sprintf("%06lX", ((msg->getFlags() & MESSAGE_RECEIVED) ? CorePlugin::m_plugin->getColorReceiver() : CorePlugin::m_plugin->getColorSender()) & 0xFFFFFF); const char *icon = "message"; const CommandDef *def = CorePlugin::m_plugin->messageTypes.find(msg->type()); if (def) icon = def->icon; QString contactName; Client *client = NULL; Contact *contact = getContacts()->contact(msg->contact()); if (contact){ ClientDataIterator it(contact->clientData); void *data; while ((data = ++it) != NULL){ if (it.client()->dataName(data) == msg->client()){ client = it.client(); break; } } } if (msg->type() == MessageStatus){ icon = "empty"; StatusMessage *sm = static_cast<StatusMessage*>(msg); if (client == NULL) client = getContacts()->getClient(0); if (client){ for (def = client->protocol()->statusList(); def->text; def++){ if (def->id == sm->getStatus()){ icon = def->icon; break; } } } } bool bUnread = false; if (msg->getFlags() & MESSAGE_RECEIVED){ if (contact) contactName = contact->getName(); for (list<msg_id>::iterator it = CorePlugin::m_plugin->unread.begin(); it != CorePlugin::m_plugin->unread.end(); ++it){ msg_id &m = (*it); if ((m.id == msg->id()) && (m.contact == msg->contact()) && (m.client == msg->client())){ bUnread = true; break; } } }else{ if (client) contactName = client->ownerName(); if (contactName.isEmpty()) contactName = getContacts()->owner()->getName(); } if (contactName.isEmpty()) contactName = "???"; QString id = QString::number(msg->id()); id += ","; if (msg->getBackground() != msg->getForeground()) id += QString::number(msg->getBackground() & 0xFFFFFF); string client_str; if (msg->client()) client_str = msg->client(); if (!client_str.empty()){ id += ","; id += quoteText(client_str.c_str()); } QString s = QString("<p><nobr>" "<a href=\"msg://%1\"><img src=\"icon:%2\"></a>%3" " %4<font color=\"#%5\">%6</font> " "<font size=-1>%7</font>%8" "</nobr></p>") .arg(id) .arg(icon) .arg((msg->getFlags() & MESSAGE_SECURE) ? "<img src=\"icon:encrypted\">" : "") .arg(bUnread ? "<b>" : "") .arg(color) .arg(quoteString(contactName)) .arg(formatTime(msg->getTime())) .arg(bUnread ? "</b>" : ""); if (msg->type() != MessageStatus){ QString msgText = msg->presentation(); if (msgText.isEmpty()){ unsigned type = msg->type(); for (;;){ CommandDef *cmd = CorePlugin::m_plugin->messageTypes.find(type); if (cmd == NULL) break; MessageDef *def = (MessageDef*)(cmd->param); if (def->base_type){ type = def->base_type; continue; } msgText += "<p>"; msgText += i18n(def->singular, def->plural, 1); msgText += "</p>"; break; } QString text = msg->getRichText(); if (!text.isEmpty()){ msgText += "<p>"; msgText += text; msgText += "</p>"; } } string msg_text; msg_text = msgText.utf8(); Event e(EventEncodeText, &msg_text); e.process(); s += parseText(msg_text.c_str(), CorePlugin::m_plugin->getOwnColors(), CorePlugin::m_plugin->getUseSmiles()); } return s; }
QString MsgViewBase::messageText(Message *msg) { QString color; unsigned long c_sender = 0x800000; unsigned long c_receiver = 0x000080; unsigned long c_send = 0x000000; unsigned long c_receive = 0x000000; if (CorePlugin::m_plugin->getOwnColors()) { c_send = (CorePlugin::m_plugin->getColorSend()) & 0xFFFFFF; c_receive = (CorePlugin::m_plugin->getColorReceive()) & 0xFFFFFF; c_sender = (CorePlugin::m_plugin->getColorSender()) & 0xFFFFFF; c_receiver = (CorePlugin::m_plugin->getColorReceiver())& 0xFFFFFF; } color.sprintf(FONT_FORMAT, ((msg->getFlags() & MESSAGE_RECEIVED) ? c_receiver : c_sender)); const char *icon = "message"; const CommandDef *def = CorePlugin::m_plugin->messageTypes.find(msg->type()); if (def) icon = def->icon; QString contactName; Client *client = NULL; Contact *contact = getContacts()->contact(msg->contact()); if (contact) { ClientDataIterator it(contact->clientData); void *data; while ((data = ++it) != NULL) { if (it.client()->dataName(data) == msg->client()) { client = it.client(); break; } } } if (msg->type() == MessageStatus) { icon = "empty"; StatusMessage *sm = static_cast<StatusMessage*>(msg); if (client == NULL) client = getContacts()->getClient(0); if (client) { for (def = client->protocol()->statusList(); def->text; def++) { if (def->id == sm->getStatus()) { icon = def->icon; break; } } } } bool bUnread = false; if (msg->getFlags() & MESSAGE_RECEIVED) { if (contact) contactName = contact->getName(); for (list<msg_id>::iterator it = CorePlugin::m_plugin->unread.begin(); it != CorePlugin::m_plugin->unread.end(); ++it) { msg_id &m = (*it); if ((m.id == msg->id()) && (m.contact == msg->contact()) && (m.client == msg->client())) { bUnread = true; break; } } } else { if (client) contactName = client->ownerName(); if (contactName.isEmpty()) contactName = getContacts()->owner()->getName(); } if (contactName.isEmpty()) contactName = "???"; QString id = QString::number(msg->id()); id += ","; if (msg->getBackground() != msg->getForeground()) id += QString::number(msg->getBackground() & 0xFFFFFF); string client_str; if (msg->client()) client_str = msg->client(); if (!client_str.empty()) { id += ","; id += quoteText(client_str.c_str()); } QString icons; if (msg->getFlags() & MESSAGE_SECURE) icons += "<img src=\"icon:encrypted\">"; if (msg->getFlags() & MESSAGE_URGENT) icons += "<img src=\"icon:urgentmsg\">"; if (msg->getFlags() & MESSAGE_LIST) icons += "<img src=\"icon:listmsg\">"; QString s = QString("<p><nobr>" "<a href=\"msg://%1\"><img src=\"icon:%2\"></a>%3" " %4<span style=\"color:#%5\">%6</span> " "<span style=\"font-size:10pt\">%7</span>%8" "</nobr></p>") .arg(id) .arg(icon) .arg(icons) .arg(bUnread ? "<b>" : "") .arg(color) .arg(quoteString(contactName)) .arg(formatTime(msg->getTime())) .arg(bUnread ? "</b>" : ""); if (msg->type() != MessageStatus) { QString msgText = msg->presentation(); // replace font color if we use own colors // some of the incoming messages are saved as html with an extra <font> - tag // so we need to replace until no more <font> - tag is found // this behaviour should be checked! if (CorePlugin::m_plugin->getOwnColors()) { int pos = msgText.find("font color=\"#",0); while (pos != -1) { pos += 13; QString color; color.sprintf(FONT_FORMAT, (msg->getFlags() & MESSAGE_RECEIVED) ? c_receive : c_send); msgText.replace(pos,6,color); pos = msgText.find("font color=\"#",pos); } } if (msgText.isEmpty()) { unsigned type = msg->type(); for (;;) { CommandDef *cmd = CorePlugin::m_plugin->messageTypes.find(type); if (cmd == NULL) break; MessageDef *def = (MessageDef*)(cmd->param); if (def->base_type) { type = def->base_type; continue; } msgText += "<p>"; msgText += i18n(def->singular, def->plural, 1); msgText += "</p>"; break; } QString text = msg->getRichText(); msgText += text; } Event e(EventEncodeText, &msgText); e.process(); msgText = parseText(msgText, false, CorePlugin::m_plugin->getUseSmiles()); s += msgText; } return s; }
QString MsgViewBase::messageText(Message *msg, bool bUnread) { QString options; QString info; QString status; const char *icon = "message"; const CommandDef *def = CorePlugin::m_plugin->messageTypes.find(msg->type()); if (def) icon = def->icon; bool bDirection = false; if (msg->type() == MessageStatus){ icon = "empty"; StatusMessage *sm = static_cast<StatusMessage*>(msg); Client *client = NULL; string clientStr; if (msg->client()) clientStr = msg->client(); int n = clientStr.find_last_of('.'); if (n >= 0){ clientStr = clientStr.substr(0, n); }else{ clientStr = ""; } if (!clientStr.empty()){ for (unsigned i = 0; i < getContacts()->nClients(); i++){ string n = getContacts()->getClient(i)->name(); if (n.length() < clientStr.length()) continue; n = n.substr(0, clientStr.length()); if (clientStr == n){ client = getContacts()->getClient(i); break; } } } if ((client == NULL) && getContacts()->nClients()) client = getContacts()->getClient(0); if (client){ for (def = client->protocol()->statusList(); def->text; def++){ if (def->id == sm->getStatus()){ icon = def->icon; status = i18n(def->text); break; } } } options += " direction=\"2\""; bDirection = true; }else{ MessageDef *m_def = (MessageDef*)(def->param); if (m_def->flags & MESSAGE_INFO){ options += " direction=\"2\""; bDirection = true; } } info = QString("<icon>%1</icon>") .arg(icon); QString contactName; if (msg->getFlags() & MESSAGE_RECEIVED){ if (!bDirection) options += " direction=\"1\""; Contact *contact = getContacts()->contact(msg->contact()); if (contact){ contactName = contact->getName(); if (contactName.isEmpty()){ Client *client = NULL; ClientDataIterator it(contact->clientData); void *data; while ((data = ++it) != NULL){ if (it.client()->dataName(data) == msg->client()){ client = it.client(); break; } } } } if (!bUnread){ for (list<msg_id>::iterator it = CorePlugin::m_plugin->unread.begin(); it != CorePlugin::m_plugin->unread.end(); ++it){ msg_id &m = (*it); if ((m.id == msg->id()) && (m.contact == msg->contact()) && (m.client == msg->client())){ bUnread = true; break; } } } if (bUnread) options += " unread=\"1\""; }else{ if (!bDirection) options += " direction=\"0\""; contactName = getContacts()->owner()->getName(); } if (contactName.isEmpty()) contactName = "???"; info += QString("<from>%1</from>") .arg(quoteString(contactName)); QString id = QString::number(msg->id()); id += ","; if (msg->getBackground() != msg->getForeground()) id += QString::number(msg->getBackground() & 0xFFFFFF); string client_str; if (msg->client()) client_str = msg->client(); if (!client_str.empty()){ id += ","; id += quoteString(client_str.c_str()); } info += "<id>"; info += id; info += "</id>"; QString icons; if (msg->getFlags() & MESSAGE_SECURE) options += " encrypted=\"1\""; if (msg->getFlags() & MESSAGE_URGENT) options += " urgent=\"1\""; if (msg->getFlags() & MESSAGE_LIST) options += " list=\"1\""; QString s; QDateTime t; t.setTime_t(msg->getTime()); info += s.sprintf("<time><date>%%1</date><hour>%02u</hour><minute>%02u</minute><second>%02u</second></time>", t.time().hour(), t.time().minute(), t.time().second()) .arg(formatDate(msg->getTime())); s = "<?xml version=\"1.0\"?><message"; s += options; s += ">"; s += info; QString msgText; if (msg->type() != MessageStatus){ msgText = msg->presentation(); if (msgText.isEmpty()){ unsigned type = msg->baseType(); CommandDef *cmd = CorePlugin::m_plugin->messageTypes.find(type); if (cmd){ MessageDef *def = (MessageDef*)(cmd->param); msgText = i18n(def->singular, def->plural, 1); int n = msgText.find("1 "); if (n == 0){ msgText = msgText.mid(2); }else if (n > 0){ msgText = msgText.left(n); } msgText = QString("<p>") + msgText + "</p>"; } QString text = msg->getRichText(); msgText += text; } }else{ msgText = status; } Event e(EventEncodeText, &msgText); e.process(); msgText = parseText(msgText, CorePlugin::m_plugin->getOwnColors(), CorePlugin::m_plugin->getUseSmiles()); msgText = QString(MSG_BEGIN) + msgText; s += "<body>"; s += quoteString(msgText); s += "</body>"; s += "</message>"; XSL *p = xsl; if (p == NULL) p = CorePlugin::m_plugin->historyXSL; QString anchor = MSG_ANCHOR; anchor += id; anchor += "\">"; QString res = p->process(s); if (res.left(3) == "<p>"){ res = QString("<p>") + anchor + res.mid(3); }else{ res = anchor + res; } return res; }
void *OSDPlugin::processEvent(Event *e) { OSDRequest osd; Contact *contact; Message *msg; OSDUserData *data; switch (e->type()){ case EventContactOnline: contact = (Contact*)(e->param()); if (contact->getIgnore()) break; osd.contact = contact->id(); osd.type = OSD_ALERTONLINE; queue.push_back(osd); processQueue(); break; case EventMessageDeleted: case EventMessageRead: case EventMessageReceived: msg = (Message*)(e->param()); contact = getContacts()->contact(msg->contact()); if (contact == NULL) break; data = (OSDUserData*)(contact->getUserData(user_data_id)); if (data == NULL) break; osd.contact = msg->contact(); if (msg->type() == MessageStatus) { StatusMessage *smsg = (StatusMessage*)msg; switch (smsg->getStatus()) { case STATUS_AWAY: osd.type = OSD_ALERTAWAY; break; case STATUS_NA: osd.type = OSD_ALERTNA; break; case STATUS_DND: osd.type = OSD_ALERTDND; break; case 100: /* STATUS_OCCUPIED, but defined in icqclient.h ! */ osd.type = OSD_ALERTOCCUPIED; break; case STATUS_FFC: osd.type = OSD_ALERTFFC; break; case STATUS_OFFLINE: osd.type = OSD_ALERTOFFLINE; break; case STATUS_ONLINE: osd.type = OSD_NONE; return NULL; default: log(L_DEBUG,"OSD: Unknown status %ld",smsg->getStatus()); osd.type = OSD_NONE; return NULL; } queue.push_back(osd); processQueue(); }else{ osd.type = OSD_MESSAGE; if ((m_request.type == OSD_MESSAGE) && (m_request.contact == msg->contact())){ queue.push_front(osd); m_timer->stop(); m_timer->start(100); }else{ queue.push_back(osd); processQueue(); } } break; case EventContactStatus: contact = (Contact*)(e->param()); if (contact->getIgnore()) break; data = (OSDUserData*)(contact->getUserData(user_data_id)); if (data){ unsigned style = 0; string wrkIcons; const char *statusIcon = NULL; contact->contactInfo(style, statusIcon, &wrkIcons); bool bTyping = false; while (!wrkIcons.empty()){ if (getToken(wrkIcons, ',') == "typing"){ bTyping = true; break; } } if (bTyping){ list<unsigned>::iterator it; for (it = typing.begin(); it != typing.end(); ++it) if ((*it) == contact->id()) break; if (it == typing.end()){ typing.push_back(contact->id()); osd.contact = contact->id(); osd.type = OSD_TYPING; queue.push_back(osd); processQueue(); } }else{ list<unsigned>::iterator it; for (it = typing.begin(); it != typing.end(); ++it) if ((*it) == contact->id()) break; if (it != typing.end()) typing.erase(it); if ((m_request.type == OSD_TYPING) && (m_request.contact == contact->id())){ m_timer->stop(); m_timer->start(100); } } } break; } return NULL; }
bool OSDPlugin::processEvent(Event *e) { OSDRequest osd; switch (e->type()){ case eEventContact: { EventContact *ec = static_cast<EventContact*>(e); Contact *contact = ec->contact(); if (contact->getIgnore()) break; switch(ec->action()) { case EventContact::eOnline: { osd.contact = contact->id(); osd.type = OSD_ALERTONLINE; m_queue.push_back(osd); processQueue(); break; } case EventContact::eStatus: { SIM::PropertyHubPtr data = contact->getUserData("OSD"); if(!data.isNull()) { unsigned style = 0; QSet<QString> wrkIcons; QString statusIcon; contact->contactInfo(style, statusIcon, &wrkIcons); if (wrkIcons.contains("typing")){ if (!m_typing.contains(contact->id())) { m_typing += contact->id(); osd.contact = contact->id(); osd.type = OSD_TYPING; m_queue.push_back(osd); processQueue(); } }else{ m_typing.remove(contact->id()); if ((m_request.type == OSD_TYPING) && (m_request.contact == contact->id())){ m_timer->stop(); bTimerActive=false; m_timer->start(100); bTimerActive=true; } } } break; } default: break; } break; } case eEventMessageReceived: { EventMessage *em = static_cast<EventMessage*>(e); Message *msg = em->msg(); Contact *contact = getContacts()->contact(msg->contact()); if (contact == NULL) break; SIM::PropertyHubPtr data = contact->getUserData("OSD"); if(data.isNull()) break; osd.contact = msg->contact(); CorePlugin* core = GET_CorePlugin(); if (!core->unread.empty()) bHaveUnreadMessages=true; if (msg->type() == MessageStatus) { StatusMessage *smsg = (StatusMessage*)msg; switch (smsg->getStatus()) { case STATUS_AWAY: osd.type = OSD_ALERTAWAY; break; case STATUS_NA: osd.type = OSD_ALERTNA; break; case STATUS_DND: osd.type = OSD_ALERTDND; break; case STATUS_OCCUPIED: /* STATUS_OCCUPIED, took over from contacts.h! */ osd.type = OSD_ALERTOCCUPIED; break; case STATUS_FFC: osd.type = OSD_ALERTFFC; break; case STATUS_OFFLINE: osd.type = OSD_ALERTOFFLINE; break; case STATUS_ONLINE: osd.type = OSD_NONE; return false; default: log(L_DEBUG,"OSD: Unknown status %ld",smsg->getStatus()); osd.type = OSD_NONE; return false; } m_queue.push_back(osd); processQueue(); }else{ osd.type = OSD_MESSAGE; if ((m_request.type == OSD_MESSAGE) && (m_request.contact == msg->contact())){ m_queue.push_front(osd); m_timer->stop(); bTimerActive=false; m_timer->start(100);bTimerActive=true; }else{ m_queue.push_back(osd); processQueue(); } } break; } case eEventMessageDeleted: case eEventMessageRead: { EventMessage *em = static_cast<EventMessage*>(e); Message *msg = em->msg(); Contact *contact = getContacts()->contact(msg->contact()); if (contact == NULL) break; SIM::PropertyHubPtr data = contact->getUserData("OSD"); if (data.isNull()) break; osd.contact = msg->contact(); CorePlugin* core = GET_CorePlugin(); if (core->unread.empty()) bHaveUnreadMessages=false; if (msg->type() == MessageStatus) { StatusMessage *smsg = (StatusMessage*)msg; switch (smsg->getStatus()) { case STATUS_AWAY: osd.type = OSD_ALERTAWAY; break; case STATUS_NA: osd.type = OSD_ALERTNA; break; case STATUS_DND: osd.type = OSD_ALERTDND; break; case STATUS_OCCUPIED: /* STATUS_OCCUPIED, took over from contacts.h! */ osd.type = OSD_ALERTOCCUPIED; break; case STATUS_FFC: osd.type = OSD_ALERTFFC; break; case STATUS_OFFLINE: osd.type = OSD_ALERTOFFLINE; break; case STATUS_ONLINE: osd.type = OSD_NONE; return false; default: log(L_DEBUG,"OSD: Unknown status %ld",smsg->getStatus()); osd.type = OSD_NONE; return false; } m_queue.push_back(osd); processQueue(); }else{ osd.type = OSD_MESSAGE; if ((m_request.type == OSD_MESSAGE) && (m_request.contact == msg->contact())){ m_queue.push_front(osd); m_timer->stop(); bTimerActive=false; m_timer->start(100);bTimerActive=true; }else{ m_queue.push_back(osd); processQueue(); } } break; } default: break; } return false; }
bool OSDPlugin::processEvent(Event *e) { OSDRequest osd; switch (e->type()){ case eEventContact: { EventContact *ec = static_cast<EventContact*>(e); Contact *contact = ec->contact(); if (contact->getIgnore()) break; switch(ec->action()) { case EventContact::eOnline: { osd.contact = contact->id(); osd.type = OSD_ALERTONLINE; queue.push_back(osd); processQueue(); break; } case EventContact::eStatus: { OSDUserData *data = (OSDUserData*)(contact->getUserData(user_data_id)); if (data){ unsigned style = 0; QString wrkIcons; QString statusIcon; contact->contactInfo(style, statusIcon, &wrkIcons); bool bTyping = false; while (!wrkIcons.isEmpty()){ if (getToken(wrkIcons, ',') == "typing"){ bTyping = true; break; } } if (bTyping){ list<unsigned>::iterator it; for (it = typing.begin(); it != typing.end(); ++it) if ((*it) == contact->id()) break; if (it == typing.end()){ typing.push_back(contact->id()); osd.contact = contact->id(); osd.type = OSD_TYPING; queue.push_back(osd); processQueue(); } }else{ list<unsigned>::iterator it; for (it = typing.begin(); it != typing.end(); ++it) if ((*it) == contact->id()) break; if (it != typing.end()) typing.erase(it); if ((m_request.type == OSD_TYPING) && (m_request.contact == contact->id())){ m_timer->stop(); m_timer->start(100); } } } break; } default: break; } break; } case eEventMessageReceived: { EventMessage *em = static_cast<EventMessage*>(e); Message *msg = em->msg(); Contact *contact = getContacts()->contact(msg->contact()); if (contact == NULL) break; OSDUserData *data = (OSDUserData*)(contact->getUserData(user_data_id)); if (data == NULL) break; osd.contact = msg->contact(); if (! core->unread.empty()) bHaveUnreadMessages=true; if (msg->type() == MessageStatus) { StatusMessage *smsg = (StatusMessage*)msg; switch (smsg->getStatus()) { case STATUS_AWAY: osd.type = OSD_ALERTAWAY; break; case STATUS_NA: osd.type = OSD_ALERTNA; break; case STATUS_DND: osd.type = OSD_ALERTDND; break; case STATUS_OCCUPIED: /* STATUS_OCCUPIED, took over from contacts.h! */ osd.type = OSD_ALERTOCCUPIED; break; case STATUS_FFC: osd.type = OSD_ALERTFFC; break; case STATUS_OFFLINE: osd.type = OSD_ALERTOFFLINE; break; case STATUS_ONLINE: osd.type = OSD_NONE; return false; default: log(L_DEBUG,"OSD: Unknown status %ld",smsg->getStatus()); osd.type = OSD_NONE; return false; } queue.push_back(osd); processQueue(); }else{ osd.type = OSD_MESSAGE; if ((m_request.type == OSD_MESSAGE) && (m_request.contact == msg->contact())){ queue.push_front(osd); m_timer->stop(); m_timer->start(100); }else{ queue.push_back(osd); processQueue(); } } break; } case eEventMessageDeleted: case eEventMessageRead: { EventMessage *em = static_cast<EventMessage*>(e); Message *msg = em->msg(); Contact *contact = getContacts()->contact(msg->contact()); if (contact == NULL) break; OSDUserData *data = (OSDUserData*)(contact->getUserData(user_data_id)); if (data == NULL) break; osd.contact = msg->contact(); if (core->unread.empty()) bHaveUnreadMessages=false; if (msg->type() == MessageStatus) { StatusMessage *smsg = (StatusMessage*)msg; switch (smsg->getStatus()) { case STATUS_AWAY: osd.type = OSD_ALERTAWAY; break; case STATUS_NA: osd.type = OSD_ALERTNA; break; case STATUS_DND: osd.type = OSD_ALERTDND; break; case STATUS_OCCUPIED: /* STATUS_OCCUPIED, took over from contacts.h! */ osd.type = OSD_ALERTOCCUPIED; break; case STATUS_FFC: osd.type = OSD_ALERTFFC; break; case STATUS_OFFLINE: osd.type = OSD_ALERTOFFLINE; break; case STATUS_ONLINE: osd.type = OSD_NONE; return false; default: log(L_DEBUG,"OSD: Unknown status %ld",smsg->getStatus()); osd.type = OSD_NONE; return false; } queue.push_back(osd); processQueue(); }else{ osd.type = OSD_MESSAGE; if ((m_request.type == OSD_MESSAGE) && (m_request.contact == msg->contact())){ queue.push_front(osd); m_timer->stop(); m_timer->start(100); }else{ queue.push_back(osd); processQueue(); } } break; } default: break; } return false; }