MsgContacts::MsgContacts(MsgEdit *parent, Message *msg) : QObject(parent) { m_client = msg->client(); m_edit = parent; m_list = new UserList(m_edit->m_frame); m_edit->m_layout->addWidget(m_list); m_edit->m_edit->setTextFormat(QTextEdit::PlainText); connect(m_list, SIGNAL(selectChanged()), this, SLOT(changed())); ContactsMessage *m = static_cast<ContactsMessage*>(msg); QString contacts = m->getContacts(); while (contacts.length()){ QString item = getToken(contacts, ';'); QString url = getToken(item, ','); QString proto = getToken(url, ':'); if (proto == "sim"){ unsigned contact_id = atol(url.latin1()); if (getContacts()->contact(contact_id)) m_list->selected.push_back(contact_id); } } changed(); connect(m_edit, SIGNAL(finished()), this, SLOT(editFinished())); connect(m_list, SIGNAL(finished()), this, SLOT(listFinished())); }
static Message *dropContacts(QMimeSource *src) { if (ContactDragObject::canDecode(src)){ Contact *contact = ContactDragObject::decode(src); ContactsMessage *msg = new ContactsMessage; QString name = contact->getName(); msg->setContacts(QString("sim:") + QString::number(contact->id()) + "," + getToken(name, '/')); return msg; } return NULL; }
bool MsgContacts::processEvent(Event *e) { if (e->type() == eEventCheckCommandState){ EventCheckCommandState *ecs = static_cast<EventCheckCommandState*>(e); CommandDef *cmd = ecs->cmd(); if (cmd->param == m_edit){ unsigned id = cmd->bar_grp; if ((id >= MIN_INPUT_BAR_ID) && (id < MAX_INPUT_BAR_ID)){ cmd->flags |= BTN_HIDE; return true; } switch (cmd->id){ case CmdSend: case CmdSendClose: e->process(this); cmd->flags &= ~BTN_HIDE; return true; case CmdTranslit: case CmdSmile: case CmdNextMessage: case CmdMsgAnswer: e->process(this); cmd->flags |= BTN_HIDE; return true; } } } else if (e->type() == eEventCommandExec){ EventCommandExec *ece = static_cast<EventCommandExec*>(e); CommandDef *cmd = ece->cmd(); if ((cmd->id == CmdSend) && (cmd->param == m_edit)){ QString msgText = m_edit->m_edit->text(); QString contacts; for (list<unsigned>::iterator it = m_list->selected.begin(); it != m_list->selected.end(); ++it){ Contact *contact = getContacts()->contact(*it); if (contact){ if (!contacts.isEmpty()) contacts += ';'; contacts += QString("sim:%1,%2") .arg(*it) .arg(contact->getName()); } } if (!contacts.isEmpty()){ ContactsMessage *msg = new ContactsMessage; msg->setContact(m_edit->m_userWnd->id()); msg->setContacts(contacts); msg->setClient(m_client); m_edit->sendMessage(msg); } return true; } } return false; }