void *YahooClient::processEvent(Event *e) { if (e->type() == EventContactChanged) { Contact *contact = (Contact*)(e->param()); string grpName; string name; name = contact->getName().utf8(); Group *grp = NULL; if (contact->getGroup()) grp = getContacts()->group(contact->getGroup()); if (grp) grpName = grp->getName().utf8(); ClientDataIterator it(contact->clientData, this); YahooUserData *data; while ((data = (YahooUserData*)(++it)) != NULL) { moveBuddy(data, grpName.c_str()); } } if (e->type() == EventContactDeleted) { Contact *contact = (Contact*)(e->param()); ClientDataIterator it(contact->clientData, this); YahooUserData *data; while ((data = (YahooUserData*)(++it)) != NULL) { removeBuddy(data); } } if (e->type() == EventTemplateExpanded) { TemplateExpand *t = (TemplateExpand*)(e->param()); sendStatus(YAHOO_STATUS_CUSTOM, t->tmpl.local8Bit()); } return NULL; }
QString SoundPlugin::messageSound(unsigned type, unsigned long contact_id) { SIM::PropertyHubPtr data; Contact *c = getContacts()->contact(contact_id); if(!contact_id) data = getContacts()->userdata(); else if(c) { data = c->getUserData()->root(); if(!data->value("sound/override").toBool()) { Group* g = getContacts()->group(c->getGroup(), false); if(g->userdata()->value("sound/override").toBool()) data = g->userdata(); else data = getContacts()->userdata(); } } QString sound; if(data) sound = data->value("sound/Receive" + QString::number(type)).toString(); if(sound == "(nosound)") return QString(); return sound; }
void YahooClient::loadList(const char *str) { Contact *contact; ContactList::ContactIterator it; while ((contact = ++it) != NULL) { YahooUserData *data; ClientDataIterator itd(contact->clientData, this); while ((data = (YahooUserData*)(++itd)) != NULL) { data->bChecked.bValue = (contact->getGroup() == 0); } } if (str) { string s = str; while (!s.empty()) { string line = getToken(s, '\n'); string grp = getToken(line, ':'); if (line.empty()) { line = grp; grp = ""; } while (!line.empty()) { string id = getToken(line, ','); Contact *contact; YahooUserData *data = findContact(id.c_str(), grp.c_str(), contact, false); data->bChecked.bValue = true; } } } it.reset(); list<Contact*> forRemove; while ((contact = ++it) != NULL) { YahooUserData *data; ClientDataIterator itd(contact->clientData, this); list<YahooUserData*> dataForRemove; bool bChanged = false; while ((data = (YahooUserData*)(++itd)) != NULL) { if (!data->bChecked.bValue) { dataForRemove.push_back(data); bChanged = true; } } if (!bChanged) continue; for (list<YahooUserData*>::iterator it = dataForRemove.begin(); it != dataForRemove.end(); ++it) contact->clientData.freeData(*it); if (contact->clientData.size()) { Event e(EventContactChanged, contact); e.process(); } else { forRemove.push_back(contact); } } for (list<Contact*>::iterator itr = forRemove.begin(); itr != forRemove.end(); ++itr) delete *itr; }
bool UserList::isGroupSelected(unsigned id) { bool bRes = false; ContactList::ContactIterator it; Contact *contact; while ((contact = ++it) != NULL){ if (contact->getGroup() != id) continue; if (!isSelected(contact->id())) return false; bRes = true; } return bRes; }
void ColGroup::impl_outputRenderRow(ext::ostream& tos, const Contact& contact, DisplayType display) { if (display == asContact) { ext::string groupName = contact.getGroup(); // replace subgroup separator with something better (really better?) utils::replaceAllInPlace(groupName, _T("\\"), _T(" > ")); tos << _T("<td>") << utils::htmlEscape(groupName) << _T("</td>") << ext::endl; } else { tos << _T("<td> </td>"); } }
void JabberAdd::startSearch() { if (m_result == NULL) return; JabberClient *client = findClient(cmbServices->currentText().latin1()); if (client == NULL) return; if (tabAdd->currentPageIndex() == 0){ QString jid = edtID->text(); if (client->add_contact(jid.utf8())){ unsigned grp_id = 0; ContactList::GroupIterator it; Group *grp; unsigned nGrp = cmbGroup->currentItem(); while ((grp = ++it) != NULL){ if (grp->id() == 0) continue; if (nGrp-- == 0){ grp_id = grp->id(); break; } } Contact *contact; JabberUserData *data = client->findContact(jid.utf8(), NULL, false, contact); if (data && (contact->getGroup() != grp_id)){ contact->setGroup(grp_id); Event e(EventContactChanged, contact); e.process(); } }else{ m_result->setText(i18n("%1 already in contact list") .arg(jid)); } }else if (tabAdd->currentPage()->inherits("JabberSearch")){ JabberSearch *search = static_cast<JabberSearch*>(tabAdd->currentPage()); QString condition = search->condition(); string search_id = client->search(search->id(), NULL, condition.utf8()); m_result->setSearch(client, search_id.c_str()); } }
void UserListBase::drawUpdates() { m_bDirty = false; updTimer->stop(); QListViewItem *item; list<unsigned long>::iterator it; for (it = updGroups.begin(); it != updGroups.end(); ++it){ Group *group = getContacts()->group(*it); if (group == NULL) continue; switch (m_groupMode){ case 1: item = findGroupItem(group->id()); if (item){ static_cast<GroupItem*>(item)->update(group); repaintItem(item); }else{ new GroupItem(this, group, true); } break; case 2: for (item = firstChild(); item; item = item->nextSibling()){ UserViewItemBase *i = static_cast<UserViewItemBase*>(item); if (i->type() != DIV_ITEM) continue; DivItem *divItem = static_cast<DivItem*>(i); GroupItem *grpItem = findGroupItem(group->id(), divItem); if (grpItem){ grpItem->update(group); repaintItem(grpItem); }else{ new GroupItem(divItem, group, divItem->state() == DIV_OFFLINE); } } break; } } updGroups.clear(); DivItem *itemOnline = NULL; DivItem *itemOffline = NULL; if (updContacts.size()){ if (m_groupMode != 1){ for (item = firstChild(); item != NULL; item = item->nextSibling()){ UserViewItemBase *i = static_cast<UserViewItemBase*>(item); if (i->type() != DIV_ITEM) continue; DivItem *divItem = static_cast<DivItem*>(i); if (divItem->state() == DIV_ONLINE) itemOnline = divItem; if (divItem->state() == DIV_OFFLINE) itemOffline = divItem; } } } for (it = updContacts.begin(); it != updContacts.end(); ++it){ Contact *contact = getContacts()->contact(*it); if (contact == NULL) continue; ContactItem *contactItem; GroupItem *grpItem; unsigned style; string icons; unsigned status = getUserStatus(contact, style, icons); unsigned unread = getUnread(contact->id()); bool bShow = false; ListUserData *data = (ListUserData*)(contact->getUserData(CorePlugin::m_plugin->list_data_id)); if (data && data->ShowAllways) bShow = true; switch (m_groupMode){ case 0: if (status == STATUS_OFFLINE){ if (itemOnline){ contactItem = findContactItem(contact->id(), itemOnline); if (contactItem){ deleteItem(contactItem); if (itemOnline->firstChild() == NULL){ deleteItem(itemOnline); itemOnline = NULL; } } } if ((unread == 0) && !bShow && m_bShowOnline){ if (itemOffline){ contactItem = findContactItem(contact->id(), itemOffline); if (contactItem){ deleteItem(contactItem); if (itemOffline->firstChild() == NULL){ deleteItem(itemOffline); itemOffline = NULL; } } } break; } if (itemOffline == NULL){ itemOffline = new DivItem(this, DIV_OFFLINE); setOpen(itemOffline, true); } contactItem = findContactItem(contact->id(), itemOffline); if (contactItem){ if (contactItem->update(contact, status, style, icons.c_str(), unread)) addSortItem(itemOffline); repaintItem(contactItem); }else{ contactItem = new ContactItem(itemOffline, contact, status, style, icons.c_str(), unread); } }else{ if (itemOffline){ contactItem = findContactItem(contact->id(), itemOffline); if (contactItem){ deleteItem(contactItem); if (itemOffline->firstChild() == NULL){ deleteItem(itemOffline); itemOffline = NULL; } } } if (itemOnline == NULL){ itemOnline = new DivItem(this, DIV_ONLINE); setOpen(itemOnline, true); } contactItem = findContactItem(contact->id(), itemOnline); if (contactItem){ if (contactItem->update(contact, status, style, icons.c_str(), unread)) addSortItem(itemOnline); repaintItem(contactItem); }else{ contactItem = new ContactItem(itemOnline, contact, status, style, icons.c_str(), unread); } } break; case 1: contactItem = findContactItem(contact->id()); grpItem = NULL; if (contactItem){ grpItem = static_cast<GroupItem*>(contactItem->parent()); if (((status == STATUS_OFFLINE) && (unread == 0) && !bShow && m_bShowOnline) || (contact->getGroup() != grpItem->id())){ grpItem->m_nContacts--; if (contactItem->m_bOnline) grpItem->m_nContactsOnline--; addGroupForUpdate(grpItem->id()); deleteItem(contactItem); contactItem = NULL; grpItem = NULL; } } if ((status != STATUS_OFFLINE) || unread || bShow || !m_bShowOnline){ if (grpItem == NULL) grpItem = findGroupItem(contact->getGroup()); if (grpItem){ if (contactItem){ if (contactItem->update(contact, status, style, icons.c_str(), unread)) addSortItem(grpItem); repaintItem(contactItem); if (!m_bShowOnline && (contactItem->m_bOnline != (status != STATUS_OFFLINE))){ if (status == STATUS_OFFLINE){ grpItem->m_nContactsOnline--; contactItem->m_bOnline = false; }else{ grpItem->m_nContactsOnline++; contactItem->m_bOnline = true; } addGroupForUpdate(grpItem->id()); } }else{ contactItem = new ContactItem(grpItem, contact, status, style, icons.c_str(), unread); grpItem->m_nContacts++; if (!m_bShowOnline && (status != STATUS_OFFLINE)){ grpItem->m_nContactsOnline++; contactItem->m_bOnline = true; } addGroupForUpdate(grpItem->id()); } } } break; case 2: contactItem = findContactItem(contact->id(), itemOnline); grpItem = NULL; if (contactItem){ grpItem = static_cast<GroupItem*>(contactItem->parent()); if ((status == STATUS_OFFLINE) || (grpItem->id() != contact->getGroup())){ grpItem->m_nContacts--; addGroupForUpdate(grpItem->id()); deleteItem(contactItem); contactItem = NULL; } } if (itemOffline){ contactItem = findContactItem(contact->id(), itemOffline); grpItem = NULL; if (contactItem){ grpItem = static_cast<GroupItem*>(contactItem->parent()); if ((status != STATUS_OFFLINE) || (grpItem->id() != contact->getGroup())){ grpItem->m_nContacts--; addGroupForUpdate(grpItem->id()); deleteItem(contactItem); contactItem = NULL; if (m_bShowOnline && (grpItem->firstChild() == NULL)){ deleteItem(grpItem); grpItem = NULL; if (itemOffline->firstChild() == NULL){ deleteItem(itemOffline); itemOffline = NULL; } } } } } if ((unread == 0) && !bShow && (status == STATUS_OFFLINE) && m_bShowOnline) break; DivItem *divItem; if (status == STATUS_OFFLINE){ if (itemOffline == NULL){ itemOffline = new DivItem(this, DIV_OFFLINE); setOpen(itemOffline, true); } divItem = itemOffline; }else{ divItem = itemOnline; } grpItem = findGroupItem(contact->getGroup(), divItem); if (grpItem == NULL){ Group *grp = getContacts()->group(contact->getGroup()); if (grp == NULL) break; grpItem = new GroupItem(divItem, grp, true); } contactItem = findContactItem(contact->id(), grpItem); if (contactItem){ if (contactItem->update(contact, status, style, icons.c_str(), unread)) addSortItem(grpItem); }else{ new ContactItem(grpItem, contact, status, style, icons.c_str(), unread); grpItem->m_nContacts++; addGroupForUpdate(grpItem->id()); } } } updContacts.clear(); for (list<QListViewItem*>::iterator it_sort = sortItems.begin(); it_sort != sortItems.end(); ++it_sort){ (*it_sort)->sort(); } sortItems.clear(); }
void RostersRequest::element_end(const char *el) { if (strcmp(el, "group") == 0){ m_data = NULL; return; } if (strcmp(el, "item") == 0){ bool bChanged = false; JabberListRequest *lr = m_client->findRequest(m_jid.c_str(), false); Contact *contact; JabberUserData *data = m_client->findContact(m_jid.c_str(), NULL, m_name.c_str(), false, contact); if (data == NULL){ if (lr && lr->bDelete){ m_client->findRequest(m_jid.c_str(), true); }else{ bChanged = true; data = m_client->findContact(m_jid.c_str(), NULL, m_name.c_str(), true, contact); if (m_bSubscription){ contact->setTemporary(CONTACT_TEMP); Event eContact(EventContactChanged, contact); eContact.process(); m_client->auth_request(m_jid.c_str(), MessageAuthRequest, m_subscription.c_str(), true); data = m_client->findContact(m_jid.c_str(), NULL, m_name.c_str(), false, contact); } } } if (data == NULL) return; if (data->Subscribe != m_subscribe){ bChanged = true; data->Subscribe = m_subscribe; } data->bChecked = true; if (lr == NULL){ unsigned grp = 0; if (!m_grp.empty()){ Group *group = NULL; ContactList::GroupIterator it; while ((group = ++it) != NULL){ if (m_grp == (const char*)(group->getName().utf8())){ grp = group->id(); break; } } if (group == NULL){ group = getContacts()->group(0, true); group->setName(QString::fromUtf8(m_grp.c_str())); grp = group->id(); Event e(EventGroupChanged, group); e.process(); } } if (contact->getGroup() != grp){ if (grp == 0){ void *d = NULL; ClientDataIterator it_d(contact->clientData); while ((d = ++it_d) != NULL){ if (d != data) break; } if (d){ grp = contact->getGroup(); Group *group = getContacts()->group(grp); if (group) m_client->listRequest(data, contact->getName().utf8(), group->getName().utf8(), false); } } contact->setGroup(grp); bChanged = true; } } if (bChanged){ Event e(EventContactChanged, contact); e.process(); } } }
void *JabberClient::processEvent(Event *e) { if (e->type() == EventTemplateExpanded){ TemplateExpand *t = (TemplateExpand*)(e->param()); setStatus((unsigned)(t->param), quoteString(t->tmpl, false).utf8()); } if (e->type() == EventContactChanged){ Contact *contact = (Contact*)(e->param()); string grpName; string name; name = contact->getName().utf8(); Group *grp = NULL; if (contact->getGroup()) grp = getContacts()->group(contact->getGroup()); if (grp) grpName = grp->getName().utf8(); ClientDataIterator it(contact->clientData, this); JabberUserData *data; while ((data = (JabberUserData*)(++it)) != NULL){ if (!cmp(grpName, data->Group)){ listRequest(data, name.c_str(), grpName.c_str(), false); continue; } if (data->Name && *data->Name){ if (!cmp(name, data->Name)) listRequest(data, name.c_str(), grpName.c_str(), false); continue; } if (!cmp(name, data->ID)) listRequest(data, name.c_str(), grpName.c_str(), false); } return NULL; } if (e->type() == EventContactDeleted){ Contact *contact = (Contact*)(e->param()); ClientDataIterator it(contact->clientData, this); JabberUserData *data; while ((data = (JabberUserData*)(++it)) != NULL){ listRequest(data, NULL, NULL, true); } return NULL; } if (e->type() == EventGroupChanged){ Group *grp = (Group*)(e->param()); string grpName; grpName = grp->getName().utf8(); ContactList::ContactIterator itc; Contact *contact; while ((contact = ++itc) != NULL){ if (contact->getGroup() != grp->id()) continue; ClientDataIterator it(contact->clientData, this); JabberUserData *data; while ((data = (JabberUserData*)(++it)) != NULL){ if (!cmp(grpName, data->Group)) listRequest(data, contact->getName().utf8(), grpName.c_str(), false); } } } return NULL; }
void *UserView::processEvent(Event *e) { switch (e->type()){ case EventInit: m_bInit = true; fill(); break; case EventContactOnline: if (m_bInit){ Contact *contact = (Contact*)(e->param()); bool bStart = blinks.empty(); list<BlinkCount>::iterator it; for (it = blinks.begin(); it != blinks.end(); ++it){ if ((*it).id == contact->id()) break; } if (it != blinks.end()){ (*it).count = BLINK_COUNT; return NULL; } BlinkCount bc; bc.id = contact->id(); bc.count = BLINK_COUNT; blinks.push_back(bc); if (bStart) blinkTimer->start(BLINK_TIMEOUT); return NULL; } break; case EventMessageDeleted: case EventMessageRead: case EventMessageReceived:{ Message *msg = (Message*)(e->param()); addContactForUpdate(msg->contact()); break; } case EventCommandExec:{ CommandDef *cmd = (CommandDef*)(e->param()); if (cmd->menu_id == MenuContact){ Contact *contact = getContacts()->contact((unsigned)(cmd->param)); if (contact){ if (cmd->id == CmdContactDelete){ QListViewItem *item = findContactItem(contact->id()); if (item){ ensureItemVisible(item); QRect rc = itemRect(item); QPoint p = viewport()->mapToGlobal(rc.topLeft()); rc = QRect(p.x(), p.y(), rc.width(), rc.height()); BalloonMsg::ask((void*)contact->id(), i18n("Delete \"%1\"?") .arg(contact->getName()), this, SLOT(deleteContact(void*)), NULL, &rc); } return e->param(); } if (cmd->id == CmdContactRename){ QListViewItem *item = findContactItem(contact->id()); if (item){ setCurrentItem(item); renameContact(); } return e->param(); } if (cmd->id == CmdShowAlways){ ListUserData *data = (ListUserData*)(contact->getUserData(CorePlugin::m_plugin->list_data_id, true)); if (data){ bool bShow = false; if (cmd->flags & COMMAND_CHECKED) bShow = true; if ((data->ShowAlways != 0) != bShow){ data->ShowAlways = bShow; Event e(EventContactChanged, contact); e.process(); } } return e->param(); } if (cmd->id == CmdClose){ UserWnd *wnd = NULL; QWidgetList *list = QApplication::topLevelWidgets(); QWidgetListIt it(*list); QWidget * w; while ((w = it.current()) != NULL){ if (w->inherits("Container")){ Container *c = static_cast<Container*>(w); wnd = c->wnd((unsigned)(cmd->param)); if (wnd) break; } ++it; } delete list; if (wnd){ delete wnd; return e->param(); } } if (cmd->id > CmdSendMessage){ Command c; c->id = cmd->id - CmdSendMessage; c->menu_id = MenuMessage; c->param = (void*)(contact->id()); Event eCmd(EventCommandExec, c); if (eCmd.process()) return e->param(); } } } if (cmd->menu_id == MenuContactGroup){ Contact *contact = getContacts()->contact((unsigned)(cmd->param)); if (contact){ Group *grp = getContacts()->group(cmd->id - CmdContactGroup); if (grp && (grp->id() != contact->getGroup())){ contact->setGroup(grp->id()); Event eChanged(EventContactChanged, contact); eChanged.process(); return e->param(); } } } if (cmd->menu_id == MenuContainer){ Contact *contact = getContacts()->contact((unsigned)(cmd->param)); if (contact){ Container *from = NULL; Container *to = NULL; QWidgetList *list = QApplication::topLevelWidgets(); QWidgetListIt it(*list); QWidget * w; unsigned max_id = 0; while ((w = it.current()) != NULL){ if (w->inherits("Container")){ Container *c = static_cast<Container*>(w); if (c->getId() == cmd->id) to = c; if (c->wnd(contact->id())) from = c; if (!(c->getId() & CONTAINER_GRP)){ if (max_id < c->getId()) max_id = c->getId(); } } ++it; } if (from && to && (from == to)) return e->param(); UserWnd *userWnd = NULL; if (from){ userWnd = from->wnd(contact->id()); from->removeUserWnd(userWnd); } if (userWnd == NULL) userWnd = new UserWnd(contact->id(), NULL, true); if (to == NULL) to = new Container(max_id + 1); to->addUserWnd(userWnd); to->setNoSwitch(); raiseWindow(to); } return e->param(); } if (cmd->id == CmdOnline){ CorePlugin::m_plugin->setShowOnLine((cmd->flags & COMMAND_CHECKED) != 0); m_bShowOnline = (cmd->flags & COMMAND_CHECKED); if (cmd->menu_id){ CommandDef c = *cmd; c.bar_id = ToolBarMain; c.bar_grp = 0x4000; Event eCmd(EventCommandChange, &c); eCmd.process(); } fill(); } if (cmd->id == CmdGrpOff) setGroupMode(0); if (cmd->id == CmdGrpMode1) setGroupMode(1); if (cmd->id == CmdGrpMode2) setGroupMode(2); if (cmd->id == CmdGrpCreate){ if (CorePlugin::m_plugin->getGroupMode()){ Group *g = getContacts()->group(0, true); drawUpdates(); QListViewItem *item = findGroupItem(g->id()); if (item){ setCurrentItem(item); QTimer::singleShot(0, this, SLOT(renameGroup())); } } return e->param(); } if (cmd->id == CmdGrpRename){ QListViewItem *item = findGroupItem((unsigned)(cmd->param)); if (item){ setCurrentItem(item); renameGroup(); } return e->param(); } if (cmd->id == CmdGrpUp){ unsigned grp_id = (unsigned)(cmd->param); getContacts()->moveGroup(grp_id, true); QListViewItem *item = findGroupItem(grp_id); if (item){ ensureItemVisible(item); setCurrentItem(item); } return e->param(); } if (cmd->id == CmdGrpDown){ unsigned grp_id = (unsigned)(cmd->param); getContacts()->moveGroup(grp_id, false); QListViewItem *item = findGroupItem(grp_id); if (item){ ensureItemVisible(item); setCurrentItem(item); } return e->param(); } if (cmd->id == CmdGrpDelete){ unsigned grp_id = (unsigned)(cmd->param); QListViewItem *item = findGroupItem(grp_id); Group *g = getContacts()->group(grp_id); if (item && g){ ensureItemVisible(item); QRect rc = itemRect(item); QPoint p = viewport()->mapToGlobal(rc.topLeft()); rc = QRect(p.x(), p.y(), rc.width(), rc.height()); BalloonMsg::ask((void*)grp_id, i18n("Delete \"%1\"?") .arg(g->getName()), this, SLOT(deleteGroup(void*)), NULL, &rc); }
void *FilterPlugin::processEvent(Event *e) { if (e->type() == EventMessageReceived){ Message *msg = (Message*)(e->param()); if (!msg || (msg->type() == MessageStatus)) return NULL; Contact *contact = getContacts()->contact(msg->contact()); FilterUserData *data = NULL; // check if we accept only from users on the list if (getFromList() && ((contact == NULL) || contact->getTemporary())){ delete msg; delete contact; return msg; } if (!contact) return NULL; // check if the user is a ignored user if (contact->getIgnore()){ delete msg; return msg; } // get filter-data data = (FilterUserData*)(contact->getUserData(user_data_id)); if (data && data->SpamList.ptr && *data->SpamList.ptr){ if (checkSpam(msg->getPlainText(), QString::fromUtf8(data->SpamList.ptr))){ delete msg; return msg; } } return NULL; } if (e->type() == EventCheckState){ CommandDef *cmd = (CommandDef*)(e->param()); if (cmd->id == CmdIgnore){ cmd->flags &= ~BTN_HIDE; Contact *contact = getContacts()->contact((unsigned)(cmd->param)); if (contact && contact->getGroup()) cmd->flags |= BTN_HIDE; return e->param(); } if (cmd->id == CmdIgnoreText){ cmd->flags &= ~COMMAND_CHECKED; if (cmd->menu_id == MenuMsgView){ MsgViewBase *edit = (MsgViewBase*)(cmd->param); if (edit->hasSelectedText()) return e->param(); }else if (cmd->menu_id == MenuTextEdit){ TextEdit *edit = ((MsgEdit*)(cmd->param))->m_edit; if (edit->hasSelectedText()) return e->param(); } return NULL; } if (cmd->menu_id == MenuContactGroup){ if (cmd->id == CmdIgnoreList){ Contact *contact = getContacts()->contact((unsigned)(cmd->param)); if (contact == NULL) return NULL; cmd->flags &= COMMAND_CHECKED; if (contact->getIgnore()) cmd->flags |= COMMAND_CHECKED; return e->param(); } } } if (e->type() == EventCommandExec){ CommandDef *cmd = (CommandDef*)(e->param()); if (cmd->id == CmdIgnore){ Contact *contact = getContacts()->contact((unsigned)(cmd->param)); if (contact){ QString text = i18n("Add %1 to ignore list?") .arg(contact->getName()); Command cmd; cmd->id = CmdIgnore; cmd->param = (void*)(contact->id()); Event e(EventCommandWidget, cmd); QWidget *w = (QWidget*)(e.process()); BalloonMsg::ask((void*)(contact->id()), text, w, SLOT(addToIgnore(void*)), NULL, NULL, this); } return e->param(); }
void SynPacket::answer(const char *_cmd, vector<string> &args) { string cmd = _cmd; if (cmd == "SYN"){ m_ver = atol(args[0].c_str()); if (m_ver != m_client->getListVer()){ ContactList::GroupIterator itg; Group *grp; while ((grp = ++itg) != NULL){ MSNUserData *data; ClientDataIterator it(grp->clientData, m_client); while ((data = (MSNUserData*)(++it)) != NULL){ data->sFlags = data->Flags; data->Flags = 0; } } ContactList::ContactIterator itc; Contact *contact; while ((contact = ++itc) != NULL){ MSNUserData *data; ClientDataIterator it(contact->clientData, m_client); while ((data = (MSNUserData*)(++it)) != NULL){ data->sFlags = data->Flags; data->Flags = 0; } } } } if (cmd == "LSG"){ if (args.size() < 5){ log(L_WARN, "Bad LSG size"); return; } unsigned id = atol(args[3].c_str()); if (id == 0) return; Group *grp; string grp_name; grp_name = m_client->unquote(QString::fromUtf8(args[4].c_str())).utf8(); MSNListRequest *lr = m_client->findRequest(id, LR_GROUPxREMOVED); if (lr) return; MSNUserData *data = m_client->findGroup(id, NULL, grp); if (data){ lr = m_client->findRequest(grp->id(), LR_GROUPxCHANGED); if (lr){ data->sFlags |= MSN_CHECKED; return; } } data = m_client->findGroup(id, grp_name.c_str(), grp); data->sFlags |= MSN_CHECKED; } if (cmd == "LST"){ if (args.size() < 6){ log(L_WARN, "Bad size for LST"); return; } string mail; mail = m_client->unquote(QString::fromUtf8(args[4].c_str())).utf8(); string name; name = m_client->unquote(QString::fromUtf8(args[5].c_str())).utf8(); Contact *contact; MSNListRequest *lr = m_client->findRequest(mail.c_str(), LR_CONTACTxREMOVED); if (lr) return; bool bNew = false; MSNUserData *data = m_client->findContact(mail.c_str(), contact); if (data == NULL){ data = m_client->findContact(mail.c_str(), name.c_str(), contact); bNew = true; }else{ set_str(&data->EMail, mail.c_str()); set_str(&data->ScreenName, name.c_str()); } data->sFlags |= MSN_CHECKED; lr = m_client->findRequest(mail.c_str(), LR_CONTACTxCHANGED); if (args[0] == "FL"){ unsigned grp = atol(args[6].c_str()); data->Group = grp; data->Flags |= MSN_FORWARD; Group *group = NULL; m_client->findGroup(grp, NULL, group); if ((lr == NULL) && group && (group->id() != contact->getGroup())){ unsigned grp = group->id(); if (grp == 0){ void *d; ClientDataIterator it_d(contact->clientData); while ((d = ++it_d) != NULL){ if (d != data) break; } if (d){ grp = contact->getGroup(); m_client->findRequest(data->EMail, LR_CONTACTxCHANGED, true); MSNListRequest lr; lr.Type = LR_CONTACTxCHANGED; lr.Name = data->EMail; m_client->m_requests.push_back(lr); m_client->processRequests(); } } contact->setGroup(grp); Event e(EventContactChanged, contact); e.process(); } return; } if (args[0] == "RL"){ if (((data->sFlags & MSN_REVERSE) == 0) && m_client->getListVer()) m_client->auth_message(contact, MessageAdded, data); data->Flags |= MSN_REVERSE; return; } if (args[0] == "AL"){ data->Flags |= MSN_ACCEPT; return; } if (args[0] == "BL"){ data->Flags |= MSN_BLOCKED; if ((lr == NULL) && !contact->getIgnore()){ contact->setIgnore(true); Event e(EventContactChanged, contact); e.process(); } return; } } }
void ICQClient::snac_lists(unsigned short type, unsigned short seq) { switch (type){ case ICQ_SNACxLISTS_ERROR: break; case ICQ_SNACxLISTS_RIGHTS: log(L_DEBUG, "List rights"); break; case ICQ_SNACxLISTS_ROSTER:{ char c; unsigned short list_len; log(L_DEBUG,"Rosters"); m_socket->readBuffer >> c; if (c){ log(L_WARN, "Bad first roster byte %02X", c); break; } bool bIgnoreTime = false; if (!m_bRosters){ m_bRosters = true; setContactsInvisible(0); Group *grp; ContactList::GroupIterator it_g; while ((grp = ++it_g) != NULL){ ICQUserData *data; ClientDataIterator it(grp->clientData, this); while ((data = (ICQUserData*)(++it)) != NULL){ if (data->IcqID == 0){ data->bChecked = true; continue; } data->bChecked = false; } } Contact *contact; ContactList::ContactIterator it_c; while ((contact = ++it_c) != NULL){ ICQUserData *data; ClientDataIterator it(contact->clientData, this); while ((data = (ICQUserData*)(++it)) != NULL){ data->bChecked = false; data->GrpId = 0; data->IgnoreId = 0; data->VisibleId = 0; data->InvisibleId = 0; } } } m_socket->readBuffer >> list_len; for (unsigned i = 0; i < list_len; i++){ string str; unsigned short id, grp_id, type, len; m_socket->readBuffer.unpackStr(str); m_socket->readBuffer >> grp_id >> id >> type >> len; TlvList *inf = NULL; if (len){ Buffer b(len); b.pack(m_socket->readBuffer.data(m_socket->readBuffer.readPos()), len); m_socket->readBuffer.incReadPos(len); inf = new TlvList(b); } switch (type){ case ICQ_USER: { if (str.length()){ log(L_DEBUG, "User %s", str.c_str()); // check for own uin in contact lsit if (!m_bAIM && ((unsigned)atol(str.c_str()) == getUin())) { log(L_DEBUG, "Own Uin in contact list - removing!"); seq = sendRoster(ICQ_SNACxLISTS_DELETE, "", grp_id, id); m_listRequest = new ContactServerRequest(seq, number(id).c_str(), 0, 0); break; } ListRequest *lr = findContactListRequest(str.c_str()); if (lr){ log(L_DEBUG, "Request found"); lr->icq_id = id; lr->grp_id = grp_id; Contact *contact; ICQUserData *data = findContact(lr->screen.c_str(), NULL, false, contact); if (data){ data->IcqID = id; data->GrpId = grp_id; } }else{ bool bChanged = false; string alias; Tlv *tlv_name = NULL; if (inf) tlv_name = (*inf)(TLV_ALIAS); if (tlv_name) alias = (char*)(*tlv_name); log(L_DEBUG, "User %s [%s] - %u", str.c_str(), alias.c_str(), grp_id); Contact *contact; Group *grp = NULL; ICQUserData *data = findGroup(grp_id, NULL, grp); data = findContact(str.c_str(), alias.c_str(), true, contact, grp); if (inf && (*inf)(TLV_WAIT_AUTH)){ if (!data->WaitAuth){ data->WaitAuth = true; bChanged = true; } } data->IcqID = id; data->GrpId = grp_id; Tlv *tlv_phone = NULL; if (inf) tlv_phone = (*inf)(TLV_CELLULAR); if (tlv_phone){ set_str(&data->Cellular, *tlv_phone); string phone = trimPhone(*tlv_phone); QString phone_str = quoteChars(QString::fromUtf8(phone.c_str()), ","); phone_str += ",Private Cellular,"; phone_str += number(CELLULAR).c_str(); bChanged |= contact->setPhones(phone_str, NULL); }else{ set_str(&data->Cellular, NULL); } if ((unsigned)atol(str.c_str()) == getUin()) { log(L_DEBUG,"Own Uin in contact list"); Event e(EventContactDeleted, contact); e.process(); break; } if (bChanged){ Event e(EventContactChanged, contact); e.process(); } if ((data->InfoFetchTime == 0) && data->Uin) addFullInfoRequest(data->Uin); } }else{ bIgnoreTime = true; } break; } case ICQ_GROUPS:{ if (str.size() == 0) break; log(L_DEBUG, "group %s %u", str.c_str(), grp_id); ListRequest *lr = findGroupListRequest(grp_id); if (lr) break; Group *grp; ICQUserData *data = findGroup(grp_id, str.c_str(), grp); if (data->IcqID){ lr = findGroupListRequest(data->IcqID); if (lr) removeListRequest(lr); } data->IcqID = grp_id; data->bChecked = true; if (grp->getName() != QString::fromUtf8(str.c_str())){ grp->setName(QString::fromUtf8(str.c_str())); Event e(EventGroupChanged, grp); e.process(); } break; } case ICQ_VISIBLE_LIST:{ if (str.length()){ log(L_DEBUG, "Visible %s", str.c_str()); ListRequest *lr = findContactListRequest(str.c_str()); if (lr) lr->visible_id = id; if ((lr == NULL) || (lr->type != LIST_USER_DELETED)){ Contact *contact; ICQUserData *data = findContact(str.c_str(), NULL, true, contact); data->ContactVisibleId = id; if ((lr == NULL) && (data->VisibleId != id)){ data->VisibleId = id; Event e(EventContactChanged, contact); e.process(); } if ((data->InfoFetchTime == 0) && data->Uin) addFullInfoRequest(data->Uin); } } break; } case ICQ_INVISIBLE_LIST:{ if (str.length()){ log(L_DEBUG, "Invisible %s", str.c_str()); ListRequest *lr = findContactListRequest(str.c_str()); if (lr) lr->invisible_id = id; if ((lr == NULL) || (lr->type != LIST_USER_DELETED)){ Contact *contact; ICQUserData *data = findContact(str.c_str(), NULL, true, contact); data->ContactInvisibleId = id; if ((lr == NULL) && (data->InvisibleId != id)){ data->InvisibleId = id; Event e(EventContactChanged, contact); e.process(); } if ((data->InfoFetchTime == 0) && data->Uin) addFullInfoRequest(data->Uin); } } break; } case ICQ_IGNORE_LIST:{ if (str.length()){ log(L_DEBUG, "Ignore %s", str.c_str()); ListRequest *lr = findContactListRequest(str.c_str()); if (lr) lr->ignore_id = id; Contact *contact; ICQUserData *data = findContact(str.c_str(), NULL, true, contact); if (data->IgnoreId != id){ data->IgnoreId = id; if (lr == NULL){ contact->setIgnore(true); Event e(EventContactChanged, contact); e.process(); } } } break; } case ICQ_INVISIBLE_STATE: setContactsInvisible(id); break; case 0x0009: case 0x0011: case 0x0013: break; default: log(L_WARN,"Unknown roster type %04X", type); } if (inf) delete inf; } unsigned long time; m_socket->readBuffer >> time; if ((time == 0) && list_len && !bIgnoreTime) break; setContactsTime(time); Group *grp; ContactList::GroupIterator it_g; list<Group*> forRemove; while ((grp = ++it_g) != NULL){ ICQUserData *data = (ICQUserData*)(grp->clientData.getData(this)); string n; if (grp->id()) n = grp->getName().local8Bit(); log(L_DEBUG, "Check %u %s %X %u", grp->id(), n.c_str(), data, data ? data->bChecked : 0); if ((data == NULL) || data->bChecked) continue; ListRequest *lr = findGroupListRequest(data->IcqID); if (lr) continue; forRemove.push_back(grp); } for (list<Group*>::iterator it = forRemove.begin(); it != forRemove.end(); ++it){ delete *it; } Contact *contact; ContactList::ContactIterator it_c; while ((contact = ++it_c) != NULL){ ICQUserData *data; ClientDataIterator it_d(contact->clientData); bool bOther = (contact->clientData.size() == 0); bool bMy = false; unsigned long newGroup = 0; while ((data = (ICQUserData*)(++it_d)) != NULL){ if (it_d.client() != this){ bOther = true; continue; } unsigned grpId = data->GrpId; ContactList::GroupIterator it_g; while ((grp = ++it_g) != NULL){ ICQUserData *data = (ICQUserData*)(grp->clientData.getData(this)); if (data && (data->IcqID == grpId)) break; } if (grp) newGroup = grp->id(); bMy = true; } if (newGroup != contact->getGroup()){ if ((newGroup == 0) && bOther){ if (bMy) addContactRequest(contact); }else{ contact->setGroup(newGroup); } Event e(EventContactChanged, contact); e.process(); } } } getContacts()->save(); case ICQ_SNACxLISTS_ROSTERxOK: // FALLTHROUGH { log(L_DEBUG, "Rosters OK"); snac(ICQ_SNACxFAM_LISTS, ICQ_SNACxLISTS_UNKNOWN); sendPacket(); QTimer::singleShot(PING_TIMEOUT * 1000, this, SLOT(ping())); setPreviousPassword(NULL); sendClientReady(); if (m_bAIM){ Group *grp; ContactList::GroupIterator it; while ((grp = ++it) != NULL){ if (grp->id()) break; } if (grp == NULL){ grp = getContacts()->group(0, true); grp->setName("General"); Event e(EventGroupChanged, grp); e.process(); } time_t now; time(&now); data.owner.OnlineTime = now; if (m_logonStatus == STATUS_ONLINE){ m_status = STATUS_ONLINE; sendCapability(); sendICMB(1, 11); sendICMB(0, 11); processListRequest(); fetchProfiles(); }else{ m_status = STATUS_AWAY; ar_request req; req.bDirect = false; arRequests.push_back(req); ARRequest ar; ar.contact = NULL; ar.param = &arRequests.back(); ar.receiver = this; ar.status = m_logonStatus; Event eAR(EventARRequest, &ar); eAR.process(); } setState(Connected); break; } sendCapability(); sendICMB(1, 11); sendICMB(0, 3); sendLogonStatus(); setState(Connected); sendMessageRequest(); if (getContactsInvisible() == 0){ snac(ICQ_SNACxFAM_LISTS, ICQ_SNACxLISTS_EDIT); sendPacket(); snac(ICQ_SNACxFAM_LISTS, ICQ_SNACxLISTS_CREATE, true); m_socket->writeBuffer << 0x00000000L << 0x00000001L << 0x000400C8L << (unsigned short)0; sendPacket(); snac(ICQ_SNACxFAM_LISTS, ICQ_SNACxLISTS_SAVE); sendPacket(); } fetchProfiles(); break; } case ICQ_SNACxLISTS_ADDED:{ string screen = m_socket->readBuffer.unpackScreen(); messageReceived(new AuthMessage(MessageAdded), screen.c_str()); break; } case ICQ_SNACxLISTS_AUTHxREQUEST:{ string screen = m_socket->readBuffer.unpackScreen(); string message; string charset; unsigned short have_charset; m_socket->readBuffer.unpackStr(message); m_socket->readBuffer >> have_charset; if (have_charset){ m_socket->readBuffer.incReadPos(2); m_socket->readBuffer.unpackStr(charset); } log(L_DEBUG, "Auth request %s", screen.c_str()); ICQAuthMessage *msg = new ICQAuthMessage(MessageICQAuthRequest); msg->setServerText(message.c_str()); msg->setCharset(charset.c_str()); messageReceived(msg, screen.c_str()); Contact *contact; ICQUserData *data = findContact(screen.c_str(), NULL, false, contact); if (data) data->WantAuth = true; break; } case ICQ_SNACxLISTS_AUTH:{ string screen = m_socket->readBuffer.unpackScreen(); char auth_ok; m_socket->readBuffer >> auth_ok; string message; string charset; unsigned short have_charset; m_socket->readBuffer.unpackStr(message); m_socket->readBuffer >> have_charset; if (have_charset){ m_socket->readBuffer.incReadPos(2); m_socket->readBuffer.unpackStr(charset); } log(L_DEBUG, "Auth %u %s", auth_ok, screen.c_str()); ICQAuthMessage *msg = new ICQAuthMessage(auth_ok ? MessageICQAuthGranted : MessageICQAuthRefused); msg->setServerText(message.c_str()); msg->setCharset(charset.c_str()); messageReceived(msg, screen.c_str()); if (auth_ok){ Contact *contact; ICQUserData *data = findContact(screen.c_str(), NULL, false, contact); if (data){ data->WaitAuth = false; Event e(EventContactChanged, contact); e.process(); addPluginInfoRequest(data->Uin, PLUGIN_QUERYxSTATUS); addPluginInfoRequest(data->Uin, PLUGIN_QUERYxINFO); } } break; } case ICQ_SNACxLISTS_DONE: if (m_listRequest && m_listRequest->seq() == seq){ unsigned short res; m_socket->readBuffer >> res; log(L_DEBUG, "List request answer %u", res); m_listRequest->process(this, res); delete m_listRequest; m_listRequest = NULL; processListRequest(); } break; default: log(L_WARN, "Unknown lists family type %04X", type); }
bool SynPacket::answer(const char *_cmd, vector<string> &args) { string cmd = _cmd; if (cmd == "SYN"){ m_ver = atol(args[0].c_str()); if (m_ver == m_client->getListVer()) return false; ContactList::GroupIterator itg; Group *grp; while ((grp = ++itg) != NULL){ MSNUserData *data; ClientDataIterator it(grp->clientData, m_client); while ((data = (MSNUserData*)(++it)) != NULL){ data->sFlags = data->Flags; data->Flags = 0; } } ContactList::ContactIterator itc; Contact *contact; while ((contact = ++itc) != NULL){ MSNUserData *data; ClientDataIterator it(contact->clientData, m_client); while ((data = (MSNUserData*)(++it)) != NULL){ data->sFlags = data->Flags; data->Flags = 0; } } return true; } if (cmd == "GTC") return true; if (cmd == "BLP") return true; if (cmd == "PRP"){ if (args.size() < 2){ log(L_WARN, "Bad PRP size"); return true; } if (args[0] == "PHH") set_str(&m_client->data.owner.PhoneHome, m_client->unquote(QString::fromUtf8(args[1].c_str())).utf8()); if (args[0] == "PHW") set_str(&m_client->data.owner.PhoneWork, m_client->unquote(QString::fromUtf8(args[1].c_str())).utf8()); if (args[0] == "PHM") set_str(&m_client->data.owner.PhoneMobile, m_client->unquote(QString::fromUtf8(args[1].c_str())).utf8()); if (args[0] == "MBE") m_client->data.owner.Mobile = (args[1] == "Y"); return true; } if (cmd == "BPR"){ if (args.size() < 2){ log(L_WARN, "Bad BPR size"); return true; } if (m_data == NULL){ log(L_WARN, "BRP without LST"); return true; } if (args[0] == "PHH") set_str(&m_data->PhoneHome, m_client->unquote(QString::fromUtf8(args[1].c_str())).utf8()); if (args[0] == "PHW") set_str(&m_data->PhoneWork, m_client->unquote(QString::fromUtf8(args[1].c_str())).utf8()); if (args[0] == "PHM") set_str(&m_data->PhoneMobile, m_client->unquote(QString::fromUtf8(args[1].c_str())).utf8()); if (args[0] == "MBE") m_data->Mobile = (args[1] == "Y"); return true; } if (cmd == "LSG"){ if (args.size() < 3){ log(L_WARN, "Bad LSG size"); return true; } unsigned id = atol(args[0].c_str()); if (id == 0) return true; Group *grp; string grp_name; grp_name = m_client->unquote(QString::fromUtf8(args[1].c_str())).utf8(); MSNListRequest *lr = m_client->findRequest(id, LR_GROUPxREMOVED); if (lr) return true; MSNUserData *data = m_client->findGroup(id, NULL, grp); if (data){ lr = m_client->findRequest(grp->id(), LR_GROUPxCHANGED); if (lr){ data->sFlags |= MSN_CHECKED; return true; } } data = m_client->findGroup(id, grp_name.c_str(), grp); data->sFlags |= MSN_CHECKED; return true; } if (cmd == "LST"){ if (m_data){ Contact *contact; if (m_client->findContact(m_data->EMail, contact)){ m_client->setupContact(contact, m_data); Event e(EventContactChanged, contact); e.process(); } } if (args.size() < 3){ log(L_WARN, "Bad size for LST"); return true; } string mail; mail = m_client->unquote(QString::fromUtf8(args[0].c_str())).utf8(); string name; name = m_client->unquote(QString::fromUtf8(args[1].c_str())).utf8(); Contact *contact; MSNListRequest *lr = m_client->findRequest(mail.c_str(), LR_CONTACTxREMOVED); if (lr) return true; bool bNew = false; m_data = m_client->findContact(mail.c_str(), contact); if (m_data == NULL){ m_data = m_client->findContact(mail.c_str(), name.c_str(), contact); bNew = true; }else{ set_str(&m_data->EMail, mail.c_str()); set_str(&m_data->ScreenName, name.c_str()); if (name != (const char*)(contact->getName().utf8())) contact->setName(QString::fromUtf8(name.c_str())); } m_data->sFlags |= MSN_CHECKED; lr = m_client->findRequest(mail.c_str(), LR_CONTACTxCHANGED); unsigned grp = NO_GROUP; if (args.size() > 3) grp = atol(args[3].c_str()); m_data->Group = grp; m_data->Flags |= MSN_FORWARD; set_str(&m_data->PhoneHome, NULL); set_str(&m_data->PhoneWork, NULL); set_str(&m_data->PhoneMobile, NULL); m_data->Mobile = false; Group *group = NULL; if ((grp == 0) || (grp == NO_GROUP)){ group = getContacts()->group(0); }else{ m_client->findGroup(grp, NULL, group); } if ((lr == NULL) && group && (group->id() != contact->getGroup())){ unsigned grp = group->id(); if (grp == 0){ void *d; ClientDataIterator it_d(contact->clientData); while ((d = ++it_d) != NULL){ if (d != m_data) break; } if (d){ grp = contact->getGroup(); m_client->findRequest(m_data->EMail, LR_CONTACTxCHANGED, true); MSNListRequest lr; lr.Type = LR_CONTACTxCHANGED; lr.Name = m_data->EMail; m_client->m_requests.push_back(lr); } } contact->setGroup(grp); } return true; } bDone = true; return false; }
bool FilterPlugin::processEvent(Event *e) { switch (e->type()) { case eEventContact: { EventContact *ec = static_cast<EventContact*>(e); if(ec->action() != EventContact::eChanged) break; Contact *contact = ec->contact(); if (contact->getGroup()){ Command cmd; cmd->id = CmdIgnore; cmd->flags = BTN_HIDE; cmd->param = (void*)(contact->id()); EventCommandShow(cmd).process(); } break; } case eEventPluginLoadConfig: { setPropertyHub( ProfileManager::instance()->getPropertyHub("filter") ); break; } case eEventMessageReceived: { EventMessage *em = static_cast<EventMessage*>(e); Message *msg = em->msg(); if (!msg || (msg->type() == MessageStatus)) return false; Contact *contact = getContacts()->contact(msg->contact()); PropertyHubPtr data = contact->getUserData("filter"); // check if we accept only from users on the list if (((contact == NULL) || contact->getFlags() & CONTACT_TEMPORARY) && ((value("FromList").toBool() && msg->type() != MessageAuthRequest && msg->type() != MessageAuthGranted && msg->type() != MessageAuthRefused) || (value("AuthFromList").toBool() && msg->type() <= MessageContacts))) { delete msg; delete contact; return msg; } if (!contact) return false; // check if the user is a ignored user if (contact->getIgnore()){ delete msg; return true; } // get filter-data if (data && !data->value("SpamList").toString().isEmpty() && (!contact || (contact->getFlags() & CONTACT_TEMPORARY) )) { if (checkSpam(msg->getPlainText(), data->value("SpamList").toString())){ delete msg; return true; } } break; } case eEventCheckCommandState: { EventCheckCommandState *ecs = static_cast<EventCheckCommandState*>(e); CommandDef *cmd = ecs->cmd(); if (cmd->id == CmdIgnore){ cmd->flags &= ~BTN_HIDE; Contact *contact = getContacts()->contact((unsigned long)(cmd->param)); if (contact && contact->getGroup()) cmd->flags |= BTN_HIDE; return true; } if (cmd->id == CmdIgnoreText){ cmd->flags &= ~COMMAND_CHECKED; if (cmd->menu_id == MenuMsgView){ MsgViewBase *edit = (MsgViewBase*)(cmd->param); if (edit->textCursor().hasSelection()) return true; } else /*if (cmd->menu_id == MenuTextEdit){ TextEdit *edit = ((MsgEdit*)(cmd->param))->m_edit; if (edit->textCursor().hasSelection()) return true; }*/ //Fixme Block (crashing on rightclick in msgedit from container) return false; } if (cmd->menu_id == MenuContactGroup){ if (cmd->id == CmdIgnoreList){ Contact *contact = getContacts()->contact((unsigned long)(cmd->param)); if (contact == NULL) return false; cmd->flags &= COMMAND_CHECKED; if (contact->getIgnore()) cmd->flags |= COMMAND_CHECKED; return true; } } break; } case eEventCommandExec: { EventCommandExec *ece = static_cast<EventCommandExec*>(e); CommandDef *cmd = ece->cmd(); if (cmd->id == CmdIgnore){ Contact *contact = getContacts()->contact((unsigned long)(cmd->param)); if (contact){ QString text = i18n("Add %1 to ignore list?") .arg(contact->getName()); Command cmd; cmd->id = CmdIgnore; cmd->param = (void*)(contact->id()); EventCommandWidget eWidget(cmd); eWidget.process(); QWidget *w = eWidget.widget(); BalloonMsg::ask((void*)(contact->id()), text, w, SLOT(addToIgnore(void*)), NULL, NULL, this); } return true; } if (cmd->id == CmdIgnoreText){ QString text; unsigned id = 0; if (cmd->menu_id == MenuMsgView){ MsgViewBase *view = (MsgViewBase*)(cmd->param); if (view->textCursor().hasSelection()){ text = view->textCursor().selectedText(); text = unquoteText(text); id = view->m_id; } }else if (cmd->menu_id == MenuTextEdit){ MsgEdit *medit = (MsgEdit*)(cmd->param); TextEdit *edit = medit->m_edit; if (edit->textCursor().hasSelection()){ text = edit->textCursor().selectedText(); text = unquoteText(text); id = medit->m_userWnd->id(); } } Contact *contact = getContacts()->contact(id); PropertyHubPtr data = contact->getUserData("filter"); QString s = data->value("SpamList").toString(); while (!text.isEmpty()){ QString line = getToken(text, '\n'); line = line.remove('\r'); if (line.isEmpty()) continue; bool bSpace = false; for (int i = 0; i < (int)(line.length()); i++) if (line[i] == ' '){ bSpace = true; break; } if (bSpace) line = '\"' + line + '\"'; if (!s.isEmpty()) s += ' '; s += line; } data->setValue("SpamList", s); return false; } if (cmd->menu_id == MenuContactGroup) { if (cmd->id == CmdIgnoreList) { Contact *contact = getContacts()->contact((unsigned long)(cmd->param)); if (!contact) return false; contact->setIgnore((cmd->flags & COMMAND_CHECKED) == 0); EventContact(contact, EventContact::eChanged).process(); return true; } } break; } default: break; }
void UserListBase::fill() { m_pressedItem = NULL; clear(); GroupItem *grpItem; ContactItem *contactItem; UserViewItemBase *divItem; UserViewItemBase *divItemOnline = NULL; UserViewItemBase *divItemOffline = NULL; ContactList *list = getContacts(); ContactList::GroupIterator grp_it; ContactList::ContactIterator contact_it; Group *grp; Contact *contact; switch (m_groupMode){ case 0: divItemOnline = NULL; divItemOffline = NULL; while ((contact = ++contact_it) != NULL){ if (contact->getIgnore() || contact->getTemporary()) continue; unsigned style; string icons; unsigned status = getUserStatus(contact, style, icons); unsigned unread = getUnread(contact->id()); bool bShow = false; ListUserData *data = (ListUserData*)contact->getUserData(CorePlugin::m_plugin->list_data_id); if (data && data->ShowAllways) bShow = true; if ((unread == 0) && !bShow && (status == STATUS_OFFLINE) && m_bShowOnline) continue; divItem = (status == STATUS_OFFLINE) ? divItemOffline : divItemOnline; if (divItem == NULL){ if (status == STATUS_OFFLINE){ divItemOffline = new DivItem(this, DIV_OFFLINE); setOpen(divItemOffline, true); divItem = divItemOffline; }else{ divItemOnline = new DivItem(this, DIV_ONLINE); setOpen(divItemOnline, true); divItem = divItemOnline; } } new ContactItem(divItem, contact, status, style, icons.c_str(), unread); } break; case 1: while ((grp = ++grp_it) != NULL){ if (grp->id() == 0) continue; grpItem = new GroupItem(this, grp, true); } grp = list->group(0); if (grp){ grpItem = new GroupItem(this, grp, true); } while ((contact = ++contact_it) != NULL){ if (contact->getIgnore() || contact->getTemporary()) continue; unsigned style; string icons; unsigned status = getUserStatus(contact, style, icons); unsigned unread = getUnread(contact->id()); bool bShow = false; ListUserData *data = (ListUserData*)contact->getUserData(CorePlugin::m_plugin->list_data_id); if (data && data->ShowAllways) bShow = true; if ((status == STATUS_OFFLINE) && !bShow && (unread == 0) && m_bShowOnline) continue; grpItem = findGroupItem(contact->getGroup()); if (grpItem == NULL) continue; contactItem = new ContactItem(grpItem, contact, status, style, icons.c_str(), unread); grpItem->m_nContacts++; if ((status != STATUS_OFFLINE) && !m_bShowOnline){ grpItem->m_nContactsOnline++; contactItem->m_bOnline = true; } } break; case 2: divItemOnline = new DivItem(this, DIV_ONLINE); setOpen(divItemOnline, true); while ((grp = ++grp_it) != NULL){ if (grp->id() == 0) continue; grpItem = new GroupItem(divItemOnline, grp, false); } grp = list->group(0); if (grp){ grpItem = new GroupItem(divItemOnline, grp, false); } if (!m_bShowOnline){ divItemOffline = new DivItem(this, DIV_OFFLINE); setOpen(divItemOffline, true); grp_it.reset(); while ((grp = ++grp_it) != NULL){ if (grp->id() == 0) continue; grpItem = new GroupItem(divItemOffline, grp, true); } grp = list->group(0); if (grp){ grpItem = new GroupItem(divItemOffline, grp, true); } } while ((contact = ++contact_it) != NULL){ if (contact->getIgnore() || contact->getTemporary()) continue; unsigned style; string icons; unsigned status = getUserStatus(contact, style, icons); unsigned unread = getUnread(contact->id()); bool bShow = false; ListUserData *data = (ListUserData*)contact->getUserData(CorePlugin::m_plugin->list_data_id); if (data && data->ShowAllways) bShow = true; if ((unread == 0) && !bShow && (status == STATUS_OFFLINE) && m_bShowOnline) continue; if (status == STATUS_OFFLINE){ if (divItemOffline == NULL){ divItemOffline = new DivItem(this, DIV_OFFLINE); setOpen(divItemOffline, true); } divItem = divItemOffline; }else{ divItem = divItemOnline; } grpItem = findGroupItem(contact->getGroup(), divItem); if (grpItem == NULL){ Group *grp = getContacts()->group(contact->getGroup()); if (grp == NULL) continue; grpItem = new GroupItem(divItem, grp, true); } new ContactItem(grpItem, contact, status, style, icons.c_str(), unread); grpItem->m_nContacts++; } break; } adjustColumn(); }
bool JabberClient::send(Message *msg, void *_data) { if (getState() != Connected) return false; JabberUserData *data = (JabberUserData*)_data; switch (msg->type()){ case MessageAuthRefused:{ string grp; Group *group = NULL; Contact *contact = getContacts()->contact(msg->contact()); if (contact && contact->getGroup()) group = getContacts()->group(contact->getGroup()); if (group) grp = group->getName().utf8(); listRequest(data, data->Name, grp.c_str(), false); if (data->Subscribe & SUBSCRIBE_FROM){ m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<presence to=\"" << data->ID; m_socket->writeBuffer << "\" type=\"unsubscribed\"><status>" << (const char*)(quoteString(msg->getPlainText(), false).utf8()) << "</status></presence>"; sendPacket(); if ((msg->getFlags() & MESSAGE_NOHISTORY) == 0){ msg->setClient(dataName(data).c_str()); Event e(EventSent, msg); e.process(); } Event e(EventMessageSent, msg); e.process(); delete msg; return true; } } case MessageGeneric:{ Contact *contact = getContacts()->contact(msg->contact()); if ((contact == NULL) || (data == NULL)) return false; m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<message to=\"" << data->ID; m_socket->writeBuffer << "\"><body>" << (const char*)msg->getPlainText().utf8() << "</body></message>"; sendPacket(); if ((msg->getFlags() & MESSAGE_NOHISTORY) == 0){ msg->setClient(dataName(data).c_str()); Event e(EventSent, msg); e.process(); } Event e(EventMessageSent, msg); e.process(); delete msg; return true; } case MessageAuthRequest:{ m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<presence to=\"" << data->ID; m_socket->writeBuffer << "\" type=\"subscribe\"><status>" << (const char*)(quoteString(msg->getPlainText(), false).utf8()) << "</status></presence>"; sendPacket(); if ((msg->getFlags() & MESSAGE_NOHISTORY) == 0){ msg->setClient(dataName(data).c_str()); Event e(EventSent, msg); e.process(); } Event e(EventMessageSent, msg); e.process(); delete msg; return true; } case MessageAuthGranted:{ m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<presence to=\"" << data->ID; m_socket->writeBuffer << "\" type=\"subscribed\"></presence>"; sendPacket(); if ((msg->getFlags() & MESSAGE_NOHISTORY) == 0){ msg->setClient(dataName(data).c_str()); Event e(EventSent, msg); e.process(); } Event e(EventMessageSent, msg); e.process(); delete msg; return true; } case MessageJabberOnline: if (isAgent(data->ID) && (data->Status == STATUS_OFFLINE)){ m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<presence to=\"" << data->ID << "\"></presence>"; sendPacket(); delete msg; return true; } break; case MessageJabberOffline: if (isAgent(data->ID) && (data->Status != STATUS_OFFLINE)){ m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<presence to=\"" << data->ID << "\" type=\"unavailable\"></presence>"; sendPacket(); delete msg; return true; } break; } return false; }
bool JabberClient::send(Message *msg, void *_data) { if ((getState() != Connected) || (_data == NULL)) return false; JabberUserData *data = (JabberUserData*)_data; switch (msg->type()){ case MessageAuthRefused:{ string grp; Group *group = NULL; Contact *contact = getContacts()->contact(msg->contact()); if (contact && contact->getGroup()) group = getContacts()->group(contact->getGroup()); if (group) grp = group->getName().utf8(); listRequest(data, data->Name, grp.c_str(), false); if (data->Subscribe & SUBSCRIBE_FROM){ m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<presence to=\"" << data->ID; m_socket->writeBuffer << "\" type=\"unsubscribed\"><status>" << (const char*)(quoteString(msg->getPlainText(), false).utf8()) << "</status></presence>"; sendPacket(); if ((msg->getFlags() & MESSAGE_NOHISTORY) == 0){ msg->setClient(dataName(data).c_str()); Event e(EventSent, msg); e.process(); } Event e(EventMessageSent, msg); e.process(); delete msg; return true; } } case MessageGeneric:{ Contact *contact = getContacts()->contact(msg->contact()); if ((contact == NULL) || (data == NULL)) return false; m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<message type=\"chat\" to=\"" << data->ID; m_socket->writeBuffer << "\"><body>" << (const char*)msg->getPlainText().utf8() << "</body>"; if (data->richText){ char bgColor[8]; sprintf(bgColor, "%06X", msg->getBackground() & 0xFFFFFF); m_socket->writeBuffer << "<html xmlns='http://jabber.org/protocol/xhtml-im'>" << "<body bgcolor=\"#" << bgColor << "\">" << removeImages(msg->getRichText()).utf8() << "</body></html>"; } m_socket->writeBuffer << "</message>"; sendPacket(); if ((msg->getFlags() & MESSAGE_NOHISTORY) == 0){ msg->setClient(dataName(data).c_str()); Event e(EventSent, msg); e.process(); } Event e(EventMessageSent, msg); e.process(); delete msg; return true; } case MessageAuthRequest:{ m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<presence to=\"" << data->ID; m_socket->writeBuffer << "\" type=\"subscribe\"><status>" << (const char*)(quoteString(msg->getPlainText(), false).utf8()) << "</status></presence>"; sendPacket(); if ((msg->getFlags() & MESSAGE_NOHISTORY) == 0){ msg->setClient(dataName(data).c_str()); Event e(EventSent, msg); e.process(); } Event e(EventMessageSent, msg); e.process(); delete msg; return true; } case MessageAuthGranted:{ m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<presence to=\"" << data->ID; m_socket->writeBuffer << "\" type=\"subscribed\"></presence>"; sendPacket(); if ((msg->getFlags() & MESSAGE_NOHISTORY) == 0){ msg->setClient(dataName(data).c_str()); Event e(EventSent, msg); e.process(); } Event e(EventMessageSent, msg); e.process(); delete msg; return true; } case MessageJabberOnline: if (isAgent(data->ID) && (data->Status == STATUS_OFFLINE)){ m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<presence to=\"" << data->ID << "\"></presence>"; sendPacket(); delete msg; return true; } break; case MessageJabberOffline: if (isAgent(data->ID) && (data->Status != STATUS_OFFLINE)){ m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<presence to=\"" << data->ID << "\" type=\"unavailable\"></presence>"; sendPacket(); delete msg; return true; } break; case MessageTypingStart: if (getTyping()){ data->composeId = ++m_msg_id; string msg_id = "msg"; msg_id += number(data->composeId); m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<message to=\"" << data->ID << "\"><x xmlns='jabber:x:event'><composing/><id>" << msg_id.c_str() << "</id></x></message>"; sendPacket(); delete msg; return true; } break; case MessageTypingStop: if (getTyping()){ if (data->composeId == 0) return false; string msg_id = "msg"; msg_id += number(data->composeId); m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<message to=\"" << data->ID << "\"><x xmlns='jabber:x:event'><id>" << msg_id.c_str() << "</id></x></message>"; sendPacket(); delete msg; return true; } break; } return false; }