UserWnd::~UserWnd() { emit closed(this); free_data(userWndData, &data); Contact *contact = getContacts()->contact(id()); if (contact && contact->getTemporary()){ m_id = 0; delete contact; } }
ContactDragObject::~ContactDragObject() { ListView *view = static_cast<ListView*>(parent()); if (view->m_pressedItem){ QListViewItem *item = view->m_pressedItem; view->m_pressedItem = NULL; item->repaint(); } Contact *contact = getContacts()->contact(m_id); if (contact && (contact->getTemporary() & CONTACT_DRAG)) delete contact; }
void *UserListBase::processEvent(Event *e) { if (e->type() == EventRepaintView) viewport()->repaint(); if (m_bInit){ switch (e->type()){ case EventGroupCreated:{ Group *g = (Group*)(e->param()); addGroupForUpdate(g->id()); break; } case EventGroupChanged:{ Group *g = (Group*)(e->param()); addGroupForUpdate(g->id()); break; } case EventGroupDeleted:{ Group *g = (Group*)(e->param()); for (list<unsigned long>::iterator it = updGroups.begin(); it != updGroups.end(); ++it){ if (*it == g->id()){ updGroups.erase(it); break; } } QListViewItem *item = findGroupItem(g->id()); deleteItem(item); break; } case EventContactCreated:{ Contact *c = (Contact*)(e->param()); if (!c->getIgnore() && (c->getTemporary() == 0)) addContactForUpdate(c->id()); break; } case EventContactStatus: case EventContactChanged:{ Contact *c = (Contact*)(e->param()); if (!c->getIgnore() && (c->getTemporary() == 0)){ addContactForUpdate(c->id()); }else{ Event e(EventContactDeleted, c); processEvent(&e); } break; } case EventMessageReceived:{ Message *msg = (Message*)(e->param()); if (msg->type() == MessageStatus){ Contact *contact = getContacts()->contact(msg->contact()); if (contact) addContactForUpdate(contact->id()); } break; } case EventContactDeleted:{ Contact *g = (Contact*)(e->param()); for (list<unsigned long>::iterator it = updContacts.begin(); it != updContacts.end(); ++it){ if (*it == g->id()){ updContacts.erase(it); break; } } ContactItem *item = findContactItem(g->id()); if (item){ if (m_groupMode){ GroupItem *grpItem = static_cast<GroupItem*>(item->parent()); grpItem->m_nContacts--; if (item->m_bOnline) grpItem->m_nContactsOnline--; addGroupForUpdate(grpItem->id()); deleteItem(item); if ((m_groupMode == 2) && (grpItem->firstChild() == NULL) && m_bShowOnline){ DivItem *div = static_cast<DivItem*>(grpItem->parent()); if (div->state() == DIV_OFFLINE){ deleteItem(grpItem); if (div->firstChild() == NULL) deleteItem(div); } } }else{ QListViewItem *p = item->parent(); deleteItem(item); if (p->firstChild() == NULL) deleteItem(p); } } break; } } } return ListView::processEvent(e); }
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(); }
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(); }
MsgSMS::MsgSMS(CToolCustom *parent, Message *msg) : QComboBox(parent) { for (QWidget *p = parent->parentWidget(); p; p = p->parentWidget()){ if (p->inherits("MsgEdit")){ m_edit = static_cast<MsgEdit*>(p); break; } } m_bExpand = false; QString t = msg->getPlainText(); if (!t.isEmpty()) m_edit->m_edit->setText(t); m_panel = NULL; setEditable(true); setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed)); parent->addWidget(this); btnTranslit = new QToolButton(parent); btnTranslit->setIconSet(*Icon("translit")); btnTranslit->setTextLabel(i18n("Send in translit")); btnTranslit->setToggleButton(true); parent->addWidget(btnTranslit); btnTranslit->show(); parent->setText(i18n("Phone:")); m_edit->m_edit->setTextFormat(PlainText); Command cmd; cmd->id = CmdSend; cmd->param = m_edit; Event e(EventCommandWidget, cmd); btnSend = (QToolButton*)(e.process()); connect(lineEdit(), SIGNAL(textChanged(const QString&)), this, SLOT(textChanged(const QString&))); connect(m_edit->m_edit, SIGNAL(textChanged()), this, SLOT(textChanged())); connect(btnTranslit, SIGNAL(toggled(bool)), this, SLOT(translitToggled(bool))); Contact *contact = getContacts()->contact(msg->contact()); if (contact == NULL) return; SMSUserData *data = (SMSUserData*)(contact->getUserData(CorePlugin::m_plugin->sms_data_id)); btnTranslit->setOn(data->SMSTranslit); QString phones = contact->getPhones(); while (phones.length()){ QString phoneItem = getToken(phones, ';', false); phoneItem = getToken(phoneItem, '/', false); QString phone = getToken(phoneItem, ','); getToken(phoneItem, ','); if (phoneItem.toUInt() == CELLULAR) insertItem(phone); } t = static_cast<SMSMessage*>(msg)->getPhone(); if (!t.isEmpty()) lineEdit()->setText(t); textChanged(); if (contact->getTemporary()){ m_panel = new SMSPanel(m_edit->m_frame); m_edit->m_layout->insertWidget(0, m_panel); connect(m_panel, SIGNAL(destroyed()), this, SLOT(panelDestroyed())); m_panel->show(); } if (m_edit->m_edit->text().isEmpty()){ TemplateExpand t; if (data->SMSSignatureBefore){ t.tmpl = QString::fromUtf8(data->SMSSignatureBefore); t.contact = contact; t.receiver = this; t.param = NULL; Event eTmpl(EventTemplateExpand, &t); eTmpl.process(); }else{ m_bExpand = true; if (data->SMSSignatureAfter){ t.tmpl = QString::fromUtf8(data->SMSSignatureAfter); t.contact = contact; t.receiver = this; t.param = NULL; Event eTmpl(EventTemplateExpand, &t); eTmpl.process(); } } } show(); }
void *MsgSMS::processEvent(Event *e) { if (e->type() == EventTemplateExpanded){ TemplateExpand *t = (TemplateExpand*)(e->param()); if (m_bExpand){ m_edit->m_edit->append(t->tmpl); }else{ m_edit->m_edit->setText(t->tmpl); m_edit->m_edit->moveCursor(QTextEdit::MoveEnd, false); m_bExpand = true; Contact *contact = getContacts()->contact(m_id); if (contact){ SMSUserData *data = (SMSUserData*)(contact->getUserData(CorePlugin::m_plugin->sms_data_id)); if (data->SMSSignatureAfter){ t->tmpl = QString::fromUtf8(data->SMSSignatureAfter); Event eTmpl(EventTemplateExpand, t); eTmpl.process(); } } } return e->param(); } if (e->type() == EventCommandExec){ CommandDef *cmd = (CommandDef*)(e->param()); if ((cmd->id == CmdSend) && (cmd->param == m_edit)){ unsigned flags = 0; if (btnTranslit->isOn()) flags |= MESSAGE_TRANSLIT; QString msgText = m_edit->m_edit->text(); QString phone = lineEdit()->text(); if (!msgText.isEmpty() && !phone.isEmpty()){ SMSMessage *msg = new SMSMessage; msg->setText(msgText); msg->setFlags(flags); msg->setPhone(phone); msg->setContact(m_edit->m_userWnd->id()); if (m_edit->sendMessage(msg)){ Contact *contact = getContacts()->contact(m_edit->m_userWnd->id()); if (contact){ if (contact->getTemporary()){ contact->setName(phone); if (m_panel && m_panel->chkSave->isChecked()){ contact->setTemporary(0); delete m_panel; } Event e(EventContactChanged, contact); e.process(); } SMSUserData *data = (SMSUserData*)(contact->userData.getUserData(CorePlugin::m_plugin->sms_data_id, true)); data->SMSTranslit = btnTranslit->isOn(); QString newPhones; QString phones = contact->getPhones(); QString type = "Private Cellular"; QString src = "-"; while (phones.length()){ QString phoneItem = getToken(phones, ';', false); QString item = phoneItem; QString phoneStr = getToken(phoneItem, '/', false); QString phone = getToken(phoneStr, ','); QString phoneType = getToken(phoneStr, ','); if ((phone != msg->getPhone()) || (phoneStr.toUInt() != CELLULAR)){ if (!newPhones.isEmpty()) newPhones += ";"; newPhones += item; continue; } type = phoneType; src = phoneItem; } phone += ","; phone += type; phone += ","; phone += QString::number(CELLULAR); phone += "/"; phone += src; if (!newPhones.isEmpty()) phone += ";"; newPhones = phone + newPhones; if (contact->setPhones(newPhones)){ Event e(EventContactChanged, contact); e.process(); } } } } return e->param(); } } return NULL; }