void SMSClient::phoneCall(const QString &number) { if (m_call && (number == m_callNumber)) return; if (m_call){ m_callTimer->stop(); Event e(EventMessageDeleted, m_call); e.process(); delete m_call; m_call = NULL; } m_callNumber = number; m_call = new Message(MessagePhoneCall); if (!number.isEmpty()){ bool bNew = false; Contact *contact = getContacts()->contactByPhone(number.latin1()); if (contact->getFlags() & CONTACT_TEMPORARY){ bNew = true; contact->setFlags(contact->getFlags() & ~CONTACT_TEMPORARY); contact->setName(number); } QString phones = contact->getPhones(); bool bFound = false; while (!phones.isEmpty()){ QString item = getToken(phones, ';', false); QString phone = getToken(item, ','); if (number == phone){ bFound = true; break; } } if (!bFound){ phones = contact->getPhones(); if (!phones.isEmpty()) phones += ";"; contact->setPhones(phones + number + ",,2/-"); } if (bNew){ Event e(EventContactChanged, contact); e.process(); } m_call->setContact(contact->id()); } m_call->setFlags(MESSAGE_RECEIVED | MESSAGE_TEMP); Event e(EventMessageReceived, m_call); if (e.process()){ m_call = NULL; return; } m_bCall = false; m_callTimer->start(12000); }
void SMSClient::phonebookEntry(int index, int type, const QString &phone, const QString &name) { bool bNew = false; Contact *contact; ContactList::ContactIterator it; while ((contact = ++it) != NULL){ smsUserData *data; ClientDataIterator itd(contact->clientData); while ((data = (smsUserData*)(++itd)) != NULL){ if (name == QString::fromUtf8(data->Name.ptr)) break; } if (data) break; } if (contact == NULL){ contact = getContacts()->contactByPhone(phone.latin1()); if (contact->getFlags() & CONTACT_TEMPORARY){ bNew = true; contact->setFlags(contact->getFlags() & ~CONTACT_TEMPORARY); contact->setName(name); } } QString phones = contact->getPhones(); bool bFound = false; while (!phones.isEmpty()){ QString item = getToken(phones, ';', false); QString number = getToken(item, ','); if (number == phone){ bFound = true; break; } } if (!bFound){ phones = contact->getPhones(); if (!phones.isEmpty()) phones += ";"; contact->setPhones(phones + phone + ",,2/-"); } smsUserData *data = (smsUserData*)contact->clientData.createData(this); set_str(&data->Phone.ptr, phone.utf8()); set_str(&data->Name.ptr, name.utf8()); data->Index.value = index; data->Type.value = type; if (bNew){ Event e(EventContactChanged, contact); e.process(); } }
void DataService::savePhones(Contact &contact) { for (int i = 0; i < contact.getPhones().length(); i++) { Phone phone = contact.getPhones().at(i); QSqlQuery query; if (phone.id > 0) { query.prepare("UPDATE phones SET number = ?, type = ? WHERE id = ?"); query.bindValue(0, phone.number); query.bindValue(1, Phone::getPhoneTypeStr(phone.type)); query.bindValue(2, phone.id); if (!query.exec()) { qDebug() << query.lastError(); } } else { query.prepare("INSERT INTO phones(contact_id, number, type) " "VALUES (?, ?, ?);"); query.bindValue(0, contact.id); query.bindValue(1, phone.number); query.bindValue(2, Phone::getPhoneTypeStr(phone.type)); if (!query.exec()) { qDebug() << query.lastError(); } phone.id = query.lastInsertId().toInt(); contact.getPhones()[i] = phone; } } }
void *ActionPlugin::processEvent(Event *e) { if (e->type() == EventCheckState){ CommandDef *cmd = (CommandDef*)(e->param()); if ((cmd->id == CmdAction) && (cmd->menu_id == MenuContact)){ Contact *contact = getContacts()->contact((unsigned long)(cmd->param)); if (contact == NULL) return NULL; ActionUserData *data = (ActionUserData*)(contact->getUserData(action_data_id)); if ((data == NULL) || (data->NMenu.value == 0)) return NULL; CommandDef *cmds = new CommandDef[data->NMenu.value + 1]; memset(cmds, 0, sizeof(CommandDef) * (data->NMenu.value + 1)); unsigned n = 0; for (unsigned i = 0; i < data->NMenu.value; i++){ QString str = get_str(data->Menu, i + 1); QString item = getToken(str, ';'); int pos = item.find("&IP;"); if (pos >= 0){ Event e(EventGetContactIP, contact); if (e.process() == NULL) continue; } pos = item.find("&Mail;"); if (pos >= 0){ if (contact->getEMails().isEmpty()) continue; } pos = item.find("&Phone;"); if (pos >= 0){ if (contact->getPhones().isEmpty()) continue; } cmds[n].id = CmdAction + i; cmds[n].text = "_"; cmds[n].text_wrk = strdup(item.utf8()); n++; } if (n == 0){ delete[] cmds; return NULL; } cmd->param = cmds; cmd->flags |= COMMAND_RECURSIVE; return e->param(); } return NULL; } if (e->type() == EventCommandExec){ CommandDef *cmd = (CommandDef*)(e->param()); if ((cmd->menu_id == MenuContact) && (cmd->id >= CmdAction)){ unsigned n = cmd->id - CmdAction; Contact *contact = getContacts()->contact((unsigned long)(cmd->param)); if (contact == NULL) return NULL; ActionUserData *data = (ActionUserData*)(contact->getUserData(action_data_id)); if ((data == NULL) || (n >= data->NMenu.value)) return NULL; QString str = get_str(data->Menu, n + 1); getToken(str, ';'); TemplateExpand t; t.tmpl = str; t.contact = contact; t.receiver = this; t.param = NULL; Event eTmpl(EventTemplateExpand, &t); eTmpl.process(); return e->param(); } return NULL; } if (e->type() == EventContactOnline){ Contact *contact = (Contact*)(e->param()); if (contact == NULL) return NULL; ActionUserData *data = (ActionUserData*)(contact->getUserData(action_data_id)); if ((data == NULL) || (data->OnLine.ptr == NULL)) return NULL; TemplateExpand t; t.tmpl = QString::fromUtf8(data->OnLine.ptr); t.contact = contact; t.receiver = this; t.param = NULL; Event eTmpl(EventTemplateExpand, &t); eTmpl.process(); return e->param(); } if (e->type() == EventMessageReceived){ Message *msg = (Message*)(e->param()); Contact *contact = getContacts()->contact(msg->contact()); if (contact == NULL) return NULL; ActionUserData *data = (ActionUserData*)(contact->getUserData(action_data_id)); if (data == NULL) return NULL; if (msg->type() == MessageStatus){ if (data->Status.ptr == NULL) return NULL; TemplateExpand t; t.tmpl = QString::fromUtf8(data->Status.ptr); t.contact = contact; t.receiver = this; t.param = NULL; Event eTmpl(EventTemplateExpand, &t); eTmpl.process(); return NULL; } const char *cmd = get_str(data->Message, msg->baseType()); if ((cmd == NULL) || (*cmd == 0)) return NULL; TemplateExpand t; t.tmpl = QString::fromUtf8(cmd); t.contact = contact; t.receiver = this; t.param = msg; Event eTmpl(EventTemplateExpand, &t); eTmpl.process(); return e->param(); } if (e->type() == EventTemplateExpanded){ TemplateExpand *t = (TemplateExpand*)(e->param()); Message *msg = (Message*)(t->param); if (msg){ MsgExec *exec = new MsgExec; exec->msg = msg; m_exec.push_back(exec); connect(exec, SIGNAL(ready(Exec*,int,const char*)), this, SLOT(msg_ready(Exec*,int,const char*))); QString text = msg->presentation(); exec->execute(t->tmpl.local8Bit(), unquoteText(text).local8Bit()); }else{
QString Tmpl::process(TmplExpand &t, const QString &str) { QString res; QString s = str; while (!s.isEmpty()){ res += getToken(s, '&'); if(s.isEmpty()) break; QString tag = getToken(s, ';'); if (tag.isEmpty()) { res += tag; log(L_WARN, "Found '&' without ';' while parsing %s", str.local8Bit().data()); continue; } Contact *contact; if (tag.startsWith("My")){ contact = getContacts()->owner(); tag = tag.mid(2); }else{ contact = t.tmpl.contact; } if (contact == NULL) continue; if (tag == "TimeStatus"){ QDateTime dt; dt.setTime_t(CorePlugin::m_plugin->getStatusTime()); res += dt.toString("hh:mm"); continue; } if (tag == "IntervalStatus"){ res += QString::number(time(NULL) - CorePlugin::m_plugin->getStatusTime()); continue; } if (tag == "IP"){ EventGetContactIP e(contact); struct in_addr addr; e.process(); if (e.ip()) addr.s_addr = e.ip()->ip(); else addr.s_addr = 0; res += inet_ntoa(addr); continue; } if (tag == "Mail"){ QString mails = contact->getEMails(); QString mail = getToken(mails, ';', false); res += getToken(mail, '/'); continue; } if (tag == "Phone"){ QString phones = contact->getPhones(); QString phone_item = getToken(phones, ';', false); phone_item = getToken(phone_item, '/', false); res += getToken(phone_item, ','); continue; } if (tag == "Unread"){ unsigned nUnread = 0; for (list<msg_id>::iterator it = CorePlugin::m_plugin->unread.begin(); it != CorePlugin::m_plugin->unread.end(); ++it){ if ((*it).contact == contact->id()) nUnread++; } res += QString::number(nUnread); continue; } if (getTag(tag, &(contact->data.Group), contact->dataDef(), res)) continue; clientData *data; ClientDataIterator itc(contact->clientData); while ((data = ++itc) != NULL){ if (getTag(tag, &(data->Sign), itc.client()->protocol()->userDataDef(), res)) break; } if (data) continue; UserDataDef *def; ContactList::UserDataIterator it; while ((def = ++it) != NULL){ SIM::Data *data = (SIM::Data*)contact->getUserData(def->id); if (data == NULL) continue; if (getTag(tag, data, def->def, res)){ break; } } } return res; }
void MainInfo::fill() { Contact *contact = m_contact; if (contact == NULL) contact = getContacts()->owner(); QString firstName = contact->getFirstName(); firstName = getToken(firstName, '/'); edtFirstName->setText(firstName); QString lastName = contact->getLastName(); lastName = getToken(lastName, '/'); edtLastName->setText(lastName); cmbDisplay->clear(); QString name = contact->getName(); if (name.length()) cmbDisplay->insertItem(name); if (firstName.length() && lastName.length()){ cmbDisplay->insertItem(firstName + " " + lastName); cmbDisplay->insertItem(lastName + " " + firstName); } if (firstName.length()) cmbDisplay->insertItem(firstName); if (lastName.length()) cmbDisplay->insertItem(lastName); cmbDisplay->lineEdit()->setText(contact->getName()); edtNotes->setText(contact->getNotes()); QString mails = contact->getEMails(); lstMails->clear(); while (mails.length()){ QString mailItem = getToken(mails, ';', false); QString mail = getToken(mailItem, '/'); QListViewItem *item = new QListViewItem(lstMails); item->setText(MAIL_ADDRESS, mail); item->setText(MAIL_PROTO, mailItem); item->setPixmap(MAIL_ADDRESS, Pict("mail_generic")); if ((m_contact == NULL) && mailItem.isEmpty()) item->setText(MAIL_PUBLISH, i18n("Yes")); } mailSelectionChanged(); QString phones = contact->getPhones(); lstPhones->clear(); unsigned n = 1; cmbCurrent->clear(); cmbCurrent->insertItem(""); while (phones.length()){ QString number; QString type; unsigned icon = 0; QString proto; QString phone = getToken(phones, ';', false); QString phoneItem = getToken(phone, '/', false); proto = phone; number = getToken(phoneItem, ','); type = getToken(phoneItem, ','); if (!phoneItem.isEmpty()) icon = atol(getToken(phoneItem, ',').latin1()); QListViewItem *item = new QListViewItem(lstPhones); fillPhoneItem(item, number, type, icon, proto); cmbCurrent->insertItem(number); if (!phoneItem.isEmpty()){ item->setText(PHONE_ACTIVE, "1"); cmbCurrent->setCurrentItem(n); } n++; } connect(lstPhones, SIGNAL(selectionChanged()), this, SLOT(phoneSelectionChanged())); phoneSelectionChanged(); }
bool ActionPlugin::processEvent(Event *e) { switch (e->type() ) { case eEventCheckCommandState: { EventCheckCommandState *ecs = static_cast<EventCheckCommandState*>(e); CommandDef *cmd = ecs->cmd(); if ((cmd->id == CmdAction) && (cmd->menu_id == MenuContact)){ Contact *contact = getContacts()->contact((unsigned long)(cmd->param)); if (contact == NULL) return false; PropertyHubPtr data = contact->getUserData("action"); if (!data || data->value("NMenu").toInt() == 0) return false; CommandDef *cmds = new CommandDef[data->value("NMenu").toInt() + 1]; unsigned n = 0; for (int i = 0; i < data->value("NMenu").toInt(); i++){ QString str = data->stringMapValue("Menu", i +1); QString item = getToken(str, ';'); int pos = item.indexOf("&IP;"); if (pos >= 0) { EventGetContactIP e(contact); if (!e.process()) continue; } pos = item.indexOf("&Mail;"); if (pos >= 0) { if (contact->getEMails().isEmpty()) continue; } pos = item.indexOf("&Phone;"); if (pos >= 0) { if (contact->getPhones().isEmpty()) continue; } cmds[n].id = CmdAction + i; cmds[n].text = "_"; cmds[n].text_wrk = item; n++; } if (n == 0) { delete[] cmds; return false; } cmd->param = cmds; cmd->flags |= COMMAND_RECURSIVE; return true; } break; } case eEventCommandExec: { EventCommandExec *ece = static_cast<EventCommandExec*>(e); CommandDef *cmd = ece->cmd(); if ((cmd->menu_id == MenuContact) && (cmd->id >= CmdAction)){ unsigned n = cmd->id - CmdAction; Contact *contact = getContacts()->contact((unsigned long)(cmd->param)); PropertyHubPtr data = contact->getUserData("action"); if (!contact || !data || n >= data->value("NMenu").toLongLong()) return false; QString str = data->stringMapValue("Menu", n +1); getToken(str, ';'); EventTemplate::TemplateExpand t; t.tmpl = str; t.contact = contact; t.receiver = this; t.param = NULL; EventTemplateExpand(&t).process(); return true; } break; } case eEventContact: { EventContact *ec = static_cast<EventContact*>(e); if(ec->action() != EventContact::eOnline) break; Contact *contact = ec->contact(); if (contact == NULL) return false; PropertyHubPtr data = contact->getUserData("action"); if (!data || data->value("OnLine").toString().isEmpty()) return false; EventTemplate::TemplateExpand t; t.tmpl = data->value("OnLine").toString(); t.contact = contact; t.receiver = this; t.param = NULL; EventTemplateExpand(&t).process(); return true; } case eEventMessageReceived: { EventMessage *em = static_cast<EventMessage*>(e); Message *msg = em->msg(); Contact *contact = getContacts()->contact(msg->contact()); if (contact == NULL) return false; PropertyHubPtr data = contact->getUserData("action"); if (!data) return false; if (msg->type() == MessageStatus){ if (data->value("Status").toString().isEmpty()) return false; EventTemplate::TemplateExpand t; t.tmpl = data->value("Status").toString(); t.contact = contact; t.receiver = this; t.param = NULL; EventTemplateExpand(&t).process(); return false; } QString cmd = data->stringMapValue("Message",msg->baseType()); if (cmd.isEmpty()) return false; EventTemplate::TemplateExpand t; t.tmpl = cmd; t.contact = contact; t.receiver = this; t.param = msg; EventTemplateExpand(&t).process(); return true; } case eEventTemplateExpanded: { EventTemplate *et = static_cast<EventTemplate*>(e); EventTemplate::TemplateExpand *t = et->templateExpand(); Message *msg = (Message*)(t->param); QProcess *proc; if (msg){ QString text = t->tmpl + unquoteText(msg->presentation()); proc = new MsgProcess(msg, this); connect(proc, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(msg_ready(int, QProcess::ExitStatus))); proc->start(text); }else{ proc = new QProcess(this); connect(proc, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(ready(int, QProcess::ExitStatus))); proc->start(t->tmpl); } break; } default: break; }
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; }