void Container::contactSelected(int) { UserWnd *userWnd = m_tabBar->currentWnd(); if (userWnd == NULL) return; m_wnds->raiseWidget(userWnd); m_bar->setParam((void*)userWnd->id()); QString name = userWnd->getName(); Command cmd; cmd->id = CmdContainerContact; cmd->text_wrk = NULL; if (!name.isEmpty()) cmd->text_wrk = strdup(name.utf8()); cmd->icon = userWnd->getIcon(); cmd->param = (void*)(userWnd->id()); cmd->popup_id = MenuContainerContact; cmd->flags = BTN_PICT; Event e(EventCommandChange, cmd); m_bar->processEvent(&e); setIcon(Pict(cmd->icon)); setCaption(userWnd->getLongName()); m_bar->checkState(); m_status->message(userWnd->status()); if (isActiveWindow()) userWnd->markAsRead(); }
void Container::contactSelected(int) { UserWnd *userWnd = m_tabBar ? m_tabBar->currentWnd() : 0; if (userWnd == NULL) return; m_wnds->raiseWidget(userWnd); userWnd->setFocus(); m_bar->setParam((void*)userWnd->id()); Command cmd; cmd->id = CmdContainerContact; cmd->text_wrk = userWnd->getName(); cmd->icon = userWnd->getIcon(); cmd->param = (void*)(userWnd->id()); cmd->popup_id = MenuContainerContact; cmd->flags = BTN_PICT; EventCommandChange e(cmd); e.setNoProcess(); m_bar->processEvent(&e); setMessageType(userWnd->type()); setIcon(Pict(cmd->icon)); setCaption(userWnd->getLongName()); m_bar->checkState(); m_status->message(userWnd->status()); if (isActiveWindow()) userWnd->markAsRead(); if (CorePlugin::m_plugin->getShowAvatarInContainer()) { Client *client = NULL; unsigned j=0; QImage img; while (j < getContacts()->nClients()){ client = getContacts()->getClient(j++); img = client->userPicture(userWnd->id()); if (!img.isNull()) break; } if (!img.isNull()) { m_avatar_label.setPixmap(img); if (!m_avatar_label.isVisible()) m_avatar_window.show(); } else { m_avatar_label.clear(); m_avatar_window.hide(); } } else { m_avatar_label.clear(); m_avatar_window.hide(); } }
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; }
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; }