const char *UserWnd::getIcon() { Contact *contact = getContacts()->contact(m_id); unsigned long status = STATUS_UNKNOWN; unsigned style; const char *statusIcon = NULL; void *data; Client *client = m_edit->client(data, false, true, id()); if (client){ client->contactInfo(data, status, style, statusIcon); }else{ contact->contactInfo(style, statusIcon); } return statusIcon; }
void FloatyWnd::init() { m_style = 0; m_icons = ""; m_unread = 0; Contact *contact = getContacts()->contact(m_id); if (contact == NULL) return; m_text = contact->getName(); m_status = contact->contactInfo(m_style, m_statusIcon, &m_icons); QPainter p(this); unsigned blink = m_blink; m_blink = 1; setFont(&p); m_blink = blink; QRect br = qApp->desktop()->rect(); br = p.boundingRect(br, Qt::AlignLeft | Qt::AlignVCenter, m_text); p.end(); unsigned h = br.height(); unsigned w = br.width() + 5; const QPixmap &pict = Pict(m_statusIcon).pixmap(); w += pict.width() + 2; if ((unsigned)(pict.height()) > h) h = pict.height(); string icons = m_icons; while (icons.length()){ string icon = getToken(icons, ','); const QPixmap &pict = Pict(icon.c_str()).pixmap(); w += pict.width() + 2; if ((unsigned)(pict.height()) > h) h = pict.height(); } w += 8; h += 6; resize(w, h); for (list<msg_id>::iterator it = m_plugin->core->unread.begin(); it != m_plugin->core->unread.end(); ++it){ if ((*it).contact != m_id) continue; m_unread = (*it).type; m_plugin->startBlink(); break; } }
void FloatyWnd::init() { m_style = 0; m_icons = ""; m_unread = 0; Contact *contact = getContacts()->contact(m_id); if (contact == NULL) return; m_text = contact->getName(); m_status = contact->contactInfo(m_style, m_statusIcon, &m_icons); QRect br = fontMetrics().boundingRect(m_text); unsigned h = br.height(); unsigned w = br.width() + 5; const QPixmap &pict = Pict(m_statusIcon); w += pict.width() + 2; if ((unsigned)(pict.height()) > h) h = pict.height(); string icons = m_icons; while (icons.length()){ string icon = getToken(icons, ','); const QPixmap &pict = Pict(icon.c_str()); w += pict.width() + 2; if ((unsigned)(pict.height()) > h) h = pict.height(); } w += 8; h += 6; resize(w, h); for (list<msg_id>::iterator it = m_plugin->core->unread.begin(); it != m_plugin->core->unread.end(); ++it){ if ((*it).contact != m_id) continue; m_unread = (*it).type; m_plugin->startBlink(); break; } }
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_ALERT; queue.push_back(osd); processQueue(); break; case EventMessageReceived: msg = (Message*)(e->param()); if (msg->type() == MessageStatus) break; osd.contact = msg->contact(); osd.type = msg->baseType(); osd.msg_id = msg->id(); osd.client = msg->client(); 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); } } break; } return NULL; }
void *Container::processEvent(Event *e) { UserWnd *userWnd; Contact *contact; CommandDef *cmd; Message *msg; switch (e->type()){ case EventMessageReceived: msg = (Message*)(e->param()); if (msg->type() == MessageStatus){ contact = getContacts()->contact(msg->contact()); if (contact) contactChanged(contact); return NULL; } if (CorePlugin::m_plugin->getContainerMode()){ if (isActiveWindow()){ userWnd = m_tabBar->currentWnd(); if (userWnd && (userWnd->id() == msg->contact())) userWnd->markAsRead(); } #ifdef WIN32 if (!isActiveWindow()){ msg = (Message*)(e->param()); userWnd = wnd(msg->contact()); if (userWnd){ if (!initFlash){ HINSTANCE hLib = GetModuleHandleA("user32"); if (hLib != NULL) (DWORD&)FlashWindowEx = (DWORD)GetProcAddress(hLib,"FlashWindowEx"); initFlash = true; } if (FlashWindowEx){ FLASHWINFO fInfo; fInfo.cbSize = sizeof(fInfo); fInfo.dwFlags = 0x0E; fInfo.hwnd = winId(); fInfo.uCount = 0; FlashWindowEx(&fInfo); } } } #endif } case EventMessageRead: msg = (Message*)(e->param()); userWnd = wnd(msg->contact()); if (userWnd){ bool bBold = false; for (list<msg_id>::iterator it = CorePlugin::m_plugin->unread.begin(); it != CorePlugin::m_plugin->unread.end(); ++it){ if ((*it).contact != msg->contact()) continue; bBold = true; break; } m_tabBar->setBold(msg->contact(), bBold); } break; case EventActiveContact: if (!isActiveWindow()) return NULL; userWnd = m_tabBar->currentWnd(); if (userWnd) return (void*)(userWnd->id()); break; case EventContactDeleted: contact = (Contact*)(e->param()); userWnd = wnd(contact->id()); if (userWnd) removeUserWnd(userWnd); break; case EventContactChanged: contact = (Contact*)(e->param()); userWnd = wnd(contact->id()); if (userWnd){ if (contact->getIgnore()){ removeUserWnd(userWnd); break; } m_tabBar->changeTab(contact->id()); contactChanged(contact); } case EventClientsChanged: setupAccel(); break; case EventContactStatus: contact = (Contact*)(e->param()); userWnd = m_tabBar->wnd(contact->id()); if (userWnd){ 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 (userWnd->m_bTyping != bTyping){ userWnd->m_bTyping = bTyping; if (bTyping){ userWnd->setStatus(i18n("Contact typed message")); }else{ userWnd->setStatus(""); } userWnd = m_tabBar->currentWnd(); if (userWnd && (contact->id() == userWnd->id())) m_status->message(userWnd->status()); } } break; case EventContactClient: contactChanged((Contact*)(e->param())); break; case EventInit: init(); break; case EventCommandExec: cmd = (CommandDef*)(e->param()); userWnd = m_tabBar->currentWnd(); if (userWnd && ((unsigned)(cmd->param) == userWnd->id())){ if (cmd->menu_id == MenuContainerContact){ m_tabBar->raiseTab(cmd->id); return e->param(); } if (cmd->id == CmdClose){ delete userWnd; return e->param(); } if (cmd->id == CmdInfo){ CommandDef c = *cmd; c.menu_id = MenuContact; c.param = (void*)userWnd->id(); Event eExec(EventCommandExec, &c); eExec.process(); return e->param(); } } break; case EventCheckState: cmd = (CommandDef*)(e->param()); userWnd = m_tabBar->currentWnd(); if (userWnd && ((unsigned)(cmd->param) == userWnd->id()) && (cmd->menu_id == MenuContainerContact) && (cmd->id == CmdContainerContacts)){ list<UserWnd*> userWnds = m_tabBar->windows(); CommandDef *cmds = new CommandDef[userWnds.size() + 1]; memset(cmds, 0, sizeof(CommandDef) * (userWnds.size() + 1)); unsigned n = 0; for (list<UserWnd*>::iterator it = userWnds.begin(); it != userWnds.end(); ++it){ cmds[n].id = (*it)->id(); cmds[n].flags = COMMAND_DEFAULT; cmds[n].text_wrk = strdup((*it)->getName().utf8()); cmds[n].icon = (*it)->getIcon(); cmds[n].text = "_"; cmds[n].menu_id = n + 1; if (n < sizeof(accels) / sizeof(const char*)) cmds[n].accel = accels[n]; if (*it == m_tabBar->currentWnd()) cmds[n].flags |= COMMAND_CHECKED; n++; } cmd->param = cmds; cmd->flags |= COMMAND_RECURSIVE; return e->param(); } break; } return NULL; }
void *Container::processEvent(Event *e) { UserWnd *userWnd; Contact *contact; CommandDef *cmd; Message *msg; switch (e->type()){ case EventMessageReceived: msg = (Message*)(e->param()); if (msg->type() == MessageStatus){ contact = getContacts()->contact(msg->contact()); if (contact) contactChanged(contact); return NULL; } if (msg->getFlags() & MESSAGE_NOVIEW) return NULL; if (CorePlugin::m_plugin->getContainerMode()){ if (isActiveWindow() && !isMinimized()){ userWnd = m_tabBar->currentWnd(); if (userWnd && (userWnd->id() == msg->contact())) userWnd->markAsRead(); }else{ msg = (Message*)(e->param()); userWnd = wnd(msg->contact()); if (userWnd) QTimer::singleShot(0, this, SLOT(flash())); } } break; case EventMessageRead: msg = (Message*)(e->param()); userWnd = wnd(msg->contact()); if (userWnd){ bool bBold = false; for (list<msg_id>::iterator it = CorePlugin::m_plugin->unread.begin(); it != CorePlugin::m_plugin->unread.end(); ++it){ if ((*it).contact != msg->contact()) continue; bBold = true; break; } m_tabBar->setBold(msg->contact(), bBold); } break; case EventActiveContact: if (!isActiveWindow()) return NULL; userWnd = m_tabBar->currentWnd(); if (userWnd) return (void*)(userWnd->id()); break; case EventContactDeleted: contact = (Contact*)(e->param()); userWnd = wnd(contact->id()); if (userWnd) removeUserWnd(userWnd); break; case EventContactChanged: contact = (Contact*)(e->param()); userWnd = wnd(contact->id()); if (userWnd){ if (contact->getIgnore()){ removeUserWnd(userWnd); break; } m_tabBar->changeTab(contact->id()); contactChanged(contact); } case EventClientsChanged: setupAccel(); break; case EventContactStatus: contact = (Contact*)(e->param()); userWnd = m_tabBar->wnd(contact->id()); if (userWnd){ 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 (userWnd->m_bTyping != bTyping){ userWnd->m_bTyping = bTyping; if (bTyping){ userWnd->setStatus(g_i18n("%1 typed", contact) .arg(contact->getName())); }else{ userWnd->setStatus(""); } userWnd = m_tabBar->currentWnd(); if (userWnd && (contact->id() == userWnd->id())) m_status->message(userWnd->status()); } } break; case EventContactClient: contactChanged((Contact*)(e->param())); break; case EventInit: init(); break; case EventCommandExec: cmd = (CommandDef*)(e->param()); userWnd = m_tabBar->currentWnd(); if (userWnd && ((unsigned)(cmd->param) == userWnd->id())){ if (cmd->menu_id == MenuContainerContact){ m_tabBar->raiseTab(cmd->id); return e->param(); } if (cmd->id == CmdClose){ delete userWnd; return e->param(); } if (cmd->id == CmdInfo){ CommandDef c = *cmd; c.menu_id = MenuContact; c.param = (void*)userWnd->id(); Event eExec(EventCommandExec, &c); eExec.process(); return e->param(); } } break; case EventCheckState: cmd = (CommandDef*)(e->param()); userWnd = m_tabBar->currentWnd(); if (userWnd && ((unsigned)(cmd->param) == userWnd->id()) && (cmd->menu_id == MenuContainerContact) && (cmd->id == CmdContainerContacts)){ list<UserWnd*> userWnds = m_tabBar->windows(); CommandDef *cmds = new CommandDef[userWnds.size() + 1]; memset(cmds, 0, sizeof(CommandDef) * (userWnds.size() + 1)); unsigned n = 0; for (list<UserWnd*>::iterator it = userWnds.begin(); it != userWnds.end(); ++it){ cmds[n].id = (*it)->id(); cmds[n].flags = COMMAND_DEFAULT; cmds[n].text_wrk = strdup((*it)->getName().utf8()); cmds[n].icon = (*it)->getIcon(); cmds[n].text = "_"; cmds[n].menu_id = n + 1; if (n < sizeof(accels) / sizeof(const char*)) cmds[n].accel = accels[n]; if (*it == m_tabBar->currentWnd()) cmds[n].flags |= COMMAND_CHECKED; n++; } cmd->param = cmds; cmd->flags |= COMMAND_RECURSIVE; return e->param(); } break; } return NULL; }
void OSDPlugin::processQueue() { if (m_timer->isActive()) return; while (queue.size()){ m_request = queue.front(); queue.erase(queue.begin()); Contact *contact = getContacts()->contact(m_request.contact); if ((contact == NULL) || contact->getIgnore()){ continue; } QString text; OSDUserData *data = NULL; data = (OSDUserData*)contact->getUserData(user_data_id); switch (m_request.type){ case OSD_ALERT: if (data->EnableAlert.bValue){ unsigned style = 0; const char *statusIcon = NULL; if (contact->contactInfo(style, statusIcon) >= STATUS_ONLINE) text = g_i18n("%1 is online", contact) .arg(contact->getName()); } break; case OSD_TYPING: if (data->EnableTyping.bValue){ 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) text = g_i18n("%1 is typing", contact) .arg(contact->getName()); } break; case OSD_MESSAGE: if (data->EnableMessage.bValue && core){ list<msg_id>::iterator it; TYPE_MAP types; TYPE_MAP::iterator itc; QString msg_text; for (it = core->unread.begin(); it != core->unread.end(); ++it){ if ((*it).contact != m_request.contact) continue; unsigned type = (*it).type; itc = types.find(type); if (itc == types.end()){ types.insert(TYPE_MAP::value_type(type, 1)); }else{ (*itc).second++; } if (!data->EnableMessageShowContent.bValue) continue; MessageID id; id.id = (*it).id; id.contact = (*it).contact; id.client = (*it).client.c_str(); Event e(EventLoadMessage, &id); Message *msg = (Message*)(e.process()); if (msg == NULL) continue; QString msgText = msg->getPlainText().stripWhiteSpace(); if (msgText.isEmpty()) continue; if (!msg_text.isEmpty()) msg_text += "\n"; msg_text += msgText; } if (types.empty()) break; for (itc = types.begin(); itc != types.end(); ++itc){ CommandDef *def = core->messageTypes.find((*itc).first); if (def == NULL) continue; MessageDef *mdef = (MessageDef*)(def->param); QString msg = i18n(mdef->singular, mdef->plural, (*itc).second); if ((*itc).second == 1){ int pos = msg.find("1 "); if (pos > 0){ msg = msg.left(pos); }else if (pos == 0){ msg = msg.mid(2); } msg = msg.left(1).upper() + msg.mid(1); } if (!text.isEmpty()) text += ", "; text += msg; } text = i18n("%1 from %2") .arg(text) .arg(contact->getName()); if (msg_text.isEmpty()) break; text += ":\n"; text += msg_text; } } if (!text.isEmpty()){ if (m_osd == NULL){ m_osd = new OSDWidget; connect(m_osd, SIGNAL(dblClick()), this, SLOT(dblClick())); connect(m_osd, SIGNAL(closeClick()), this, SLOT(timeout())); } static_cast<OSDWidget*>(m_osd)->showOSD(text, data); m_timer->start(data->Timeout.value * 1000); return; } } m_timer->stop(); m_request.contact = 0; m_request.type = OSD_NONE; }
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; }
void OSDPlugin::processQueue() { if (bTimerActive /*m_timer->isActive()*/) //Due to a f*****g bug in QTimer::isActive() return; while (m_queue.size()){ m_request = m_queue.takeFirst(); Contact *contact = getContacts()->contact(m_request.contact); if ((contact == NULL) || contact->getIgnore()) continue; QString text; SIM::PropertyHubPtr data = contact->getUserData("OSD"); uint ms = STATUS_ONLINE; switch (m_request.type){ case OSD_ALERTONLINE: if (data->value("EnableAlert").toBool() && data->value("EnableAlertOnline").toBool()){ unsigned style = 0; QString statusIcon; if (contact->contactInfo(style, statusIcon) == STATUS_ONLINE) text = g_i18n("%1 is online", contact) .arg(contact->getName()); } break; case OSD_ALERTAWAY: if (data->value("EnableAlert").toBool() && data->value("EnableAlertAway").toBool()){ text = g_i18n("%1 is away", contact) .arg(contact->getName()); } break; case OSD_ALERTNA: if (data->value("EnableAlert").toBool() && data->value("EnableAlertNA").toBool()){ text = g_i18n("%1 is not available", contact) .arg(contact->getName()); } break; case OSD_ALERTDND: if (data->value("EnableAlert").toBool() && data->value("EnableAlertDND").toBool()){ text = g_i18n("%1 doesn't want to be disturbed", contact) .arg(contact->getName()); } break; case OSD_ALERTOCCUPIED: if (data->value("EnableAlert").toBool() && data->value("EnableAlertOccupied").toBool()){ text = g_i18n("%1 is occupied", contact) .arg(contact->getName()); } break; case OSD_ALERTFFC: if (data->value("EnableAlert").toBool() && data->value("EnableAlertFFC").toBool()){ text = g_i18n("%1 is free for chat", contact) .arg(contact->getName()); } break; case OSD_ALERTOFFLINE: if (data->value("EnableAlert").toBool() && data->value("EnableAlertOffline").toBool() && (ms-1) ){ text = g_i18n("%1 is offline", contact) .arg(contact->getName()); } break; case OSD_TYPING: if (data->value("EnableTyping").toBool()){ unsigned style = 0; QSet<QString> wrkIcons; QString statusIcon; contact->contactInfo(style, statusIcon, &wrkIcons); if (wrkIcons.contains("typing")) text = g_i18n("%1 is typing", contact) .arg(contact->getName()); } break; case OSD_MESSAGE: /* if (data->EnableMessage.toBool() && core ){ * list<msg_id>::iterator it; * TYPE_MAP types; * TYPE_MAP::iterator itc; * QString msg_text; * for (it = core->unread.begin(); it != core->unread.end(); ++it){ * if (it->contact != m_request.contact) * continue; * unsigned type = it->type; * itc = types.find(type); * if (itc == types.end()){ * types.insert(TYPE_MAP::value_type(type, 1)); * }else{ * (*itc).second++; * } * if (!data->EnableMessageShowContent.toBool()) * continue; * EventLoadMessage e(it->id, it->client, it->contact); * e.process(); * Message *msg = e.message(); * if (msg == NULL) * continue; * QString msgText = msg->getPlainText().trimmed(); * if (msgText.isEmpty()) * continue; * if (!msg_text.isEmpty()) * msg_text += "\n"; * msg_text += msgText; * } * if (types.empty()) * break; * for (itc = types.begin(); itc != types.end(); ++itc){ * CommandDef *def = core->messageTypes.find((*itc).first); * if (def == NULL) * continue; * MessageDef *mdef = (MessageDef*)(def->param); * QString msg = i18n(mdef->singular, mdef->plural, (*itc).second); * if ((*itc).second == 1){ * int pos = msg.indexOf("1 "); * if (pos > 0){ * msg = msg.left(pos); * }else if (pos == 0){ * msg = msg.mid(2); * } * msg = msg.left(1).toUpper() + msg.mid(1); * } * if (!text.isEmpty()) * text += ", "; * text += msg; * } * * * if ( core->getManualStatus()==STATUS_NA && * data->EnableCapsLockFlash.toBool() && * ! this->isRunning() * ) * this->start(); //Start flashing the CapsLock if enabled * text = i18n("%1 from %2") .arg(text) .arg(contact->getName()); * if (msg_text.isEmpty()) * break; * text += ":\n"; * text += msg_text; * } */ break; default: break; } if (!text.isEmpty()){ if (m_osd == NULL){ m_osd = new OSDWidget(this); connect(m_osd, SIGNAL(dblClick()), this, SLOT(dblClick())); connect(m_osd, SIGNAL(closeClick()), this, SLOT(closeClick())); } static_cast<OSDWidget*>(m_osd)->showOSD(text, data); m_timer->start(data->value("Timeout").toUInt() * 1000); bTimerActive=true; //Due to a f*****g bug in QTimer::isActive() return; } } m_timer->stop(); bTimerActive=false; //Due to a f*****g bug in QTimer::isActive() m_request.contact = 0; m_request.type = OSD_NONE; }
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; }
void OSDPlugin::processQueue() { if (m_timer->isActive()) return; while (queue.size()){ m_request = queue.front(); queue.erase(queue.begin()); Contact *contact = getContacts()->contact(m_request.contact); if ((contact == NULL) || contact->getIgnore()){ continue; } QString text; OSDUserData *data = NULL; data = (OSDUserData*)contact->getUserData(user_data_id); uint ms=core->getManualStatus(); switch (m_request.type){ case OSD_ALERTONLINE: if (data->EnableAlert.toBool() && data->EnableAlertOnline.toBool()){ unsigned style = 0; QString statusIcon; if (contact->contactInfo(style, statusIcon) == STATUS_ONLINE) text = g_i18n("%1 is online", contact) .arg(contact->getName()); } break; case OSD_ALERTAWAY: if (data->EnableAlert.toBool() && data->EnableAlertAway.toBool()){ text = g_i18n("%1 is away", contact) .arg(contact->getName()); } break; case OSD_ALERTNA: if (data->EnableAlert.toBool() && data->EnableAlertNA.toBool()){ text = g_i18n("%1 is not available", contact) .arg(contact->getName()); } break; case OSD_ALERTDND: if (data->EnableAlert.toBool() && data->EnableAlertDND.toBool()){ text = g_i18n("%1 doesn't want to be disturbed", contact) .arg(contact->getName()); } break; case OSD_ALERTOCCUPIED: if (data->EnableAlert.toBool() && data->EnableAlertOccupied.toBool()){ text = g_i18n("%1 is occupied", contact) .arg(contact->getName()); } break; case OSD_ALERTFFC: if (data->EnableAlert.toBool() && data->EnableAlertFFC.toBool()){ text = g_i18n("%1 is free for chat", contact) .arg(contact->getName()); } break; case OSD_ALERTOFFLINE: if (data->EnableAlert.toBool() && data->EnableAlertOffline.toBool() && (ms-1) ){ text = g_i18n("%1 is offline", contact) .arg(contact->getName()); } break; case OSD_TYPING: if (data->EnableTyping.toBool()){ 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) text = g_i18n("%1 is typing", contact) .arg(contact->getName()); } break; case OSD_MESSAGE: if (data->EnableMessage.toBool() && core){ list<msg_id>::iterator it; TYPE_MAP types; TYPE_MAP::iterator itc; QString msg_text; for (it = core->unread.begin(); it != core->unread.end(); ++it){ if ((*it).contact != m_request.contact) continue; unsigned type = (*it).type; itc = types.find(type); if (itc == types.end()){ types.insert(TYPE_MAP::value_type(type, 1)); }else{ (*itc).second++; } if (!data->EnableMessageShowContent.toBool()) continue; EventLoadMessage e((*it).id, (*it).client, (*it).contact); e.process(); Message *msg = e.message(); if (msg == NULL) continue; QString msgText = msg->getPlainText().stripWhiteSpace(); if (msgText.isEmpty()) continue; if (!msg_text.isEmpty()) msg_text += "\n"; msg_text += msgText; } if (types.empty()) break; for (itc = types.begin(); itc != types.end(); ++itc){ CommandDef *def = core->messageTypes.find((*itc).first); if (def == NULL) continue; MessageDef *mdef = (MessageDef*)(def->param); QString msg = i18n(mdef->singular, mdef->plural, (*itc).second); if ((*itc).second == 1){ int pos = msg.find("1 "); if (pos > 0){ msg = msg.left(pos); }else if (pos == 0){ msg = msg.mid(2); } msg = msg.left(1).upper() + msg.mid(1); } if (!text.isEmpty()) text += ", "; text += msg; } if ( core->getManualStatus()==STATUS_NA && data->EnableCapsLockFlash.toBool() && ! this->running() ) this->start(); //Start flashing the CapsLock if enabled text = i18n("%1 from %2") .arg(text) .arg(contact->getName()); if (msg_text.isEmpty()) break; text += ":\n"; text += msg_text; } break; default: break; } if (!text.isEmpty()){ if (m_osd == NULL){ m_osd = new OSDWidget(this); connect(m_osd, SIGNAL(dblClick()), this, SLOT(dblClick())); connect(m_osd, SIGNAL(closeClick()), this, SLOT(closeClick())); } static_cast<OSDWidget*>(m_osd)->showOSD(text, data); m_timer->start(data->Timeout.toULong() * 1000); return; } } m_timer->stop(); m_request.contact = 0; m_request.type = OSD_NONE; }
bool Container::processEvent(Event *e) { if (m_tabBar == NULL) return false; switch (e->type()){ case eEventMessageReceived: { EventMessage *em = static_cast<EventMessage*>(e); Message *msg = em->msg(); if (msg->type() == MessageStatus){ Contact *contact = getContacts()->contact(msg->contact()); if (contact) contactChanged(contact); return false; } if (msg->getFlags() & MESSAGE_NOVIEW) return false; if (CorePlugin::m_plugin->getContainerMode()){ if (isActiveWindow() && !isMinimized()){ UserWnd *userWnd = m_tabBar->currentWnd(); if (userWnd && (userWnd->id() == msg->contact())) userWnd->markAsRead(); }else{ UserWnd *userWnd = wnd(msg->contact()); if (userWnd) QTimer::singleShot(0, this, SLOT(flash())); } } // no break here - otherwise we have to duplicate the code below... } case eEventMessageRead: { EventMessage *em = static_cast<EventMessage*>(e); Message *msg = em->msg(); UserWnd *userWnd = wnd(msg->contact()); if (userWnd){ bool bBold = false; for (list<msg_id>::iterator it = CorePlugin::m_plugin->unread.begin(); it != CorePlugin::m_plugin->unread.end(); ++it){ if ((*it).contact != msg->contact()) continue; bBold = true; break; } m_tabBar->setBold(msg->contact(), bBold); } break; } case eEventActiveContact: { EventActiveContact *eac = static_cast<EventActiveContact*>(e); if (!isActiveWindow()) return false; UserWnd *userWnd = m_tabBar->currentWnd(); if (userWnd) { eac->setContactID(userWnd->id()); return true; } break; } case eEventContact: { EventContact *ec = static_cast<EventContact*>(e); Contact *contact = ec->contact(); UserWnd *userWnd = wnd(contact->id()); if(!userWnd) break; switch(ec->action()) { case EventContact::eDeleted: { removeUserWnd(userWnd); break; } case EventContact::eChanged: { if (contact->getIgnore()){ removeUserWnd(userWnd); break; } m_tabBar->changeTab(contact->id()); contactChanged(contact); break; } case EventContact::eStatus: { 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 (userWnd->m_bTyping != bTyping){ userWnd->m_bTyping = bTyping; if (bTyping){ userWnd->setStatus(g_i18n("%1 is typing", contact) .arg(contact->getName())); }else{ userWnd->setStatus(""); } userWnd = m_tabBar->currentWnd(); if (userWnd && (contact->id() == userWnd->id())) m_status->message(userWnd->status()); } } default: break; } break; } case eEventClientsChanged: setupAccel(); break; case eEventContactClient: { EventContactClient *ecc = static_cast<EventContactClient*>(e); contactChanged(ecc->contact()); break; } case eEventInit: init(); break; case eEventCommandExec: { EventCommandExec *ece = static_cast<EventCommandExec*>(e); CommandDef *cmd = ece->cmd(); UserWnd *userWnd = m_tabBar->currentWnd(); if (userWnd && ((unsigned long)(cmd->param) == userWnd->id())){ if (cmd->menu_id == MenuContainerContact){ m_tabBar->raiseTab(cmd->id); return true; } if (cmd->id == CmdClose){ delete userWnd; return true; } if (cmd->id == CmdInfo && cmd->menu_id != MenuContact){ CommandDef c = *cmd; c.menu_id = MenuContact; c.param = (void*)userWnd->id(); EventCommandExec(&c).process(); return true; } } break; } case eEventCheckCommandState: { EventCheckCommandState *ecs = static_cast<EventCheckCommandState*>(e); CommandDef *cmd = ecs->cmd(); UserWnd *userWnd = m_tabBar->currentWnd(); if (userWnd && ((unsigned long)(cmd->param) == userWnd->id()) && (cmd->menu_id == MenuContainerContact) && (cmd->id == CmdContainerContacts)){ list<UserWnd*> userWnds = m_tabBar->windows(); CommandDef *cmds = new CommandDef[userWnds.size() + 1]; unsigned n = 0; for (list<UserWnd*>::iterator it = userWnds.begin(); it != userWnds.end(); ++it){ cmds[n].id = (*it)->id(); cmds[n].flags = COMMAND_DEFAULT; cmds[n].text_wrk = (*it)->getName(); cmds[n].icon = (*it)->getIcon(); cmds[n].text = "_"; cmds[n].menu_id = n + 1; if (n < sizeof(accels) / sizeof(const char*)) cmds[n].accel = accels[n]; if (*it == m_tabBar->currentWnd()) cmds[n].flags |= COMMAND_CHECKED; n++; } cmd->param = cmds; cmd->flags |= COMMAND_RECURSIVE; return true; } break; } default: break; } return false; }