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 *NavigatePlugin::processEvent(Event *e) { #ifdef WIN32 if (e->type() == EventGetURL){ string *url = (string*)(e->param()); *url = getCurrentUrl(); return e->param(); } #endif if (e->type() == EventGoURL){ string url = (const char*)(e->param()); string proto; if (url.length() == 0) return NULL; int n = url.find(':'); if (n < 0){ proto = "http"; url = proto + "://" + url; }else{ proto = url.substr(0, n); if ((proto != "http") && (proto != "https") && (proto != "ftp") && (proto != "file") && (proto != "mailto")) return NULL; } #ifdef WIN32 bool bExec = false; if (getNewWindow()){ string key_name = proto; key_name += "\\Shell\\Open"; RegEntry rp(HKEY_CLASSES_ROOT, key_name.c_str()); string prg = rp.value("command"); string action = rp.value("ddeexec"); string topic = rp.value("ddeexec\\Topic"); string server = rp.value("ddeexec\\Application"); if (!action.empty()){ int pos = action.find("%1"); if (pos >= 0) action = action.substr(0, pos) + url + action.substr(pos + 2); pos = prg.find("%1"); if (pos >= 0) prg = prg.substr(0, pos) + url + prg.substr(pos + 2); if (!prg.empty()){ STARTUPINFOA si; PROCESS_INFORMATION pi; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); ZeroMemory(&pi, sizeof(pi)); if (CreateProcessA(NULL, (char*)prg.c_str(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)){ WaitForInputIdle(pi.hProcess, INFINITE); CloseHandle(pi.hProcess); CloseHandle(pi.hThread); } } DDEbase b; DDEconversation conv(server.c_str(), topic.c_str()); if (conv.Execute(action.c_str())) bExec = true; } } if (!bExec){ if (proto == "file") url = url.substr(5); ShellExecuteA(NULL, NULL, url.c_str(), NULL, NULL, SW_SHOWNORMAL); } #else ExecParam execParam; if (proto == "mailto"){ execParam.cmd = getMailer(); url = url.substr(proto.length() + 1); }else{ execParam.cmd = getBrowser(); } execParam.arg = url.c_str(); Event eExec(EventExec, &execParam); eExec.process(); #endif return e->param(); } if (e->type() == EventEncodeText){ QString *text = (QString*)(e->param()); *text = parseUrl(*text); return e->param(); } if (e->type() == EventCheckState){ CommandDef *cmd = (CommandDef*)(e->param()); if (cmd->id == CmdMail){ Contact *contact = getContacts()->contact((unsigned long)(cmd->param)); if (contact == NULL) return NULL; QString mails = contact->getEMails(); if (mails.length() == 0) return NULL; int nMails = 0; while (mails.length()){ getToken(mails, ';'); nMails++; } cmd->popup_id = (nMails <= 1) ? 0 : MenuMail; return e->param(); } if (cmd->id == CmdMailList){ Contact *contact = getContacts()->contact((unsigned long)(cmd->param)); if (contact == NULL) return NULL; QString mails = contact->getEMails(); if (mails.length() == 0) return NULL; int nMails = 0; while (mails.length()){ getToken(mails, ';'); nMails++; } CommandDef *cmds = new CommandDef[nMails + 1]; unsigned n = 0; mails = contact->getEMails(); while (mails.length()){ QString mail = getToken(mails, ';', false); mail = getToken(mail, '/'); cmds[n] = *cmd; cmds[n].id = CmdMailList + n; cmds[n].flags = COMMAND_DEFAULT; cmds[n].text_wrk = strdup(mail.utf8()); n++; } memset(&cmds[n], 0, sizeof(CommandDef)); cmd->param = cmds; cmd->flags |= COMMAND_RECURSIVE; return e->param(); } } if (e->type() == EventCommandExec){ CommandDef *cmd = (CommandDef*)(e->param()); if (cmd->id == CmdMail){ QString mail; Contact *contact = getContacts()->contact((unsigned long)(cmd->param)); if (contact) mail = contact->getEMails(); mail = getToken(mail, ';', false); mail = getToken(mail, '/'); if (mail.length()){ string addr = "mailto:"; addr += mail.local8Bit(); Event eMail(EventGoURL, (void*)addr.c_str()); eMail.process(); } return e->param(); } if (cmd->menu_id == MenuMail){ unsigned n = cmd->id - CmdMailList; QString mails; Contact *contact = getContacts()->contact((unsigned long)(cmd->param)); if (contact) mails = contact->getEMails(); while (mails.length()){ QString mail = getToken(mails, ';', false); if (n-- == 0){ mail = getToken(mail, '/'); if (mail.length()){ string addr = "mailto:"; addr += mail.local8Bit(); Event eMail(EventGoURL, (void*)addr.c_str()); eMail.process(); } break; } } return e->param(); } } 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 *NavigatePlugin::processEvent(Event *e) { if (e->type() == EventGoURL){ string url = (const char*)(e->param()); string proto; if (url.length() == 0) return NULL; int n = url.find(':'); if (n < 0){ proto = "http"; url = proto + "://" + url; }else{ proto = url.substr(0, n); if ((proto != "http") && (proto != "https") && (proto != "ftp") && (proto != "file") && (proto != "mailto")) return NULL; } #ifdef WIN32 ShellExecuteA(NULL, NULL, url.c_str(), NULL, NULL, SW_SHOWNORMAL); #else ExecParam execParam; if (proto == "mailto"){ execParam.cmd = getMailer(); url = url.substr(proto.length() + 1); }else{ execParam.cmd = getBrowser(); } execParam.arg = url.c_str(); Event eExec(EventExec, &execParam); eExec.process(); #endif return e->param(); } if (e->type() == EventEncodeText){ QString *text = (QString*)(e->param()); *text = parseUrl(*text); return e->param(); } if (e->type() == EventCheckState){ CommandDef *cmd = (CommandDef*)(e->param()); if (cmd->id == CmdMail){ Contact *contact = getContacts()->contact((unsigned long)(cmd->param)); if (contact == NULL) return NULL; QString mails = contact->getEMails(); if (mails.length() == 0) return NULL; int nMails = 0; while (mails.length()){ getToken(mails, ';'); nMails++; } cmd->popup_id = (nMails <= 1) ? 0 : MenuMail; return e->param(); } if (cmd->id == CmdMailList){ Contact *contact = getContacts()->contact((unsigned long)(cmd->param)); if (contact == NULL) return NULL; QString mails = contact->getEMails(); if (mails.length() == 0) return NULL; int nMails = 0; while (mails.length()){ getToken(mails, ';'); nMails++; } CommandDef *cmds = new CommandDef[nMails + 1]; unsigned n = 0; mails = contact->getEMails(); while (mails.length()){ QString mail = getToken(mails, ';', false); mail = getToken(mail, '/'); cmds[n] = *cmd; cmds[n].id = CmdMailList + n; cmds[n].flags = COMMAND_DEFAULT; cmds[n].text_wrk = strdup(mail.utf8()); n++; } memset(&cmds[n], 0, sizeof(CommandDef)); cmd->param = cmds; cmd->flags |= COMMAND_RECURSIVE; return e->param(); } } if (e->type() == EventCommandExec){ CommandDef *cmd = (CommandDef*)(e->param()); if (cmd->id == CmdMail){ QString mail; Contact *contact = getContacts()->contact((unsigned long)(cmd->param)); if (contact) mail = contact->getEMails(); mail = getToken(mail, ';', false); mail = getToken(mail, '/'); if (mail.length()){ string addr = "mailto:"; addr += mail.local8Bit(); Event eMail(EventGoURL, (void*)addr.c_str()); eMail.process(); } return e->param(); } if (cmd->menu_id == MenuMail){ unsigned n = cmd->id - CmdMailList; QString mails; Contact *contact = getContacts()->contact((unsigned long)(cmd->param)); if (contact) mails = contact->getEMails(); while (mails.length()){ QString mail = getToken(mails, ';', false); if (n-- == 0){ mail = getToken(mail, '/'); if (mail.length()){ string addr = "mailto:"; addr += mail.local8Bit(); Event eMail(EventGoURL, (void*)addr.c_str()); eMail.process(); } break; } } return e->param(); } } return NULL; }