bool Client::deserialize(QDomElement& element) { PropertyHubPtr hub = PropertyHub::create(); if(!hub->deserialize(element)) return false; setPassword(uncryptPassword(hub->value("Password").toString())); return true; }
ForwardConfig::ForwardConfig(QWidget *parent, PropertyHubPtr data, ForwardPlugin *plugin) : QWidget(parent) { setupUi(this); m_plugin = plugin; //PropertyHubPtr data = (ForwardUserData*)_data; chkFirst-> setChecked(data->value("Send1st") .toBool()); chkTranslit->setChecked(data->value("Translit") .toBool()); cmbPhone->setEditable(true); QString phones = getContacts()->owner()->getPhones(); while (!phones.isEmpty()) { QString item = getToken(phones, ';', false); QString number = getToken(item, ','); getToken(item, ','); if (item.toULong() == CELLULAR) cmbPhone->insertItem(INT_MAX,number); } cmbPhone->lineEdit()->setText(data->value("Phone").toString()); }
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; }
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; }