void OSDPlugin::processQueue() { if (bTimerActive /*m_timer->isActive()*/) //Due to a f*****g bug in QTimer::isActive() return; while (m_queue.size()){ m_request = m_queue.takeFirst(); Contact *contact = getContacts()->contact(m_request.contact); if ((contact == NULL) || contact->getIgnore()) continue; QString text; SIM::PropertyHubPtr data = contact->getUserData("OSD"); uint ms = STATUS_ONLINE; switch (m_request.type){ case OSD_ALERTONLINE: if (data->value("EnableAlert").toBool() && data->value("EnableAlertOnline").toBool()){ unsigned style = 0; QString statusIcon; if (contact->contactInfo(style, statusIcon) == STATUS_ONLINE) text = g_i18n("%1 is online", contact) .arg(contact->getName()); } break; case OSD_ALERTAWAY: if (data->value("EnableAlert").toBool() && data->value("EnableAlertAway").toBool()){ text = g_i18n("%1 is away", contact) .arg(contact->getName()); } break; case OSD_ALERTNA: if (data->value("EnableAlert").toBool() && data->value("EnableAlertNA").toBool()){ text = g_i18n("%1 is not available", contact) .arg(contact->getName()); } break; case OSD_ALERTDND: if (data->value("EnableAlert").toBool() && data->value("EnableAlertDND").toBool()){ text = g_i18n("%1 doesn't want to be disturbed", contact) .arg(contact->getName()); } break; case OSD_ALERTOCCUPIED: if (data->value("EnableAlert").toBool() && data->value("EnableAlertOccupied").toBool()){ text = g_i18n("%1 is occupied", contact) .arg(contact->getName()); } break; case OSD_ALERTFFC: if (data->value("EnableAlert").toBool() && data->value("EnableAlertFFC").toBool()){ text = g_i18n("%1 is free for chat", contact) .arg(contact->getName()); } break; case OSD_ALERTOFFLINE: if (data->value("EnableAlert").toBool() && data->value("EnableAlertOffline").toBool() && (ms-1) ){ text = g_i18n("%1 is offline", contact) .arg(contact->getName()); } break; case OSD_TYPING: if (data->value("EnableTyping").toBool()){ unsigned style = 0; QSet<QString> wrkIcons; QString statusIcon; contact->contactInfo(style, statusIcon, &wrkIcons); if (wrkIcons.contains("typing")) text = g_i18n("%1 is typing", contact) .arg(contact->getName()); } break; case OSD_MESSAGE: /* if (data->EnableMessage.toBool() && core ){ * list<msg_id>::iterator it; * TYPE_MAP types; * TYPE_MAP::iterator itc; * QString msg_text; * for (it = core->unread.begin(); it != core->unread.end(); ++it){ * if (it->contact != m_request.contact) * continue; * unsigned type = it->type; * itc = types.find(type); * if (itc == types.end()){ * types.insert(TYPE_MAP::value_type(type, 1)); * }else{ * (*itc).second++; * } * if (!data->EnableMessageShowContent.toBool()) * continue; * EventLoadMessage e(it->id, it->client, it->contact); * e.process(); * Message *msg = e.message(); * if (msg == NULL) * continue; * QString msgText = msg->getPlainText().trimmed(); * if (msgText.isEmpty()) * continue; * if (!msg_text.isEmpty()) * msg_text += "\n"; * msg_text += msgText; * } * if (types.empty()) * break; * for (itc = types.begin(); itc != types.end(); ++itc){ * CommandDef *def = core->messageTypes.find((*itc).first); * if (def == NULL) * continue; * MessageDef *mdef = (MessageDef*)(def->param); * QString msg = i18n(mdef->singular, mdef->plural, (*itc).second); * if ((*itc).second == 1){ * int pos = msg.indexOf("1 "); * if (pos > 0){ * msg = msg.left(pos); * }else if (pos == 0){ * msg = msg.mid(2); * } * msg = msg.left(1).toUpper() + msg.mid(1); * } * if (!text.isEmpty()) * text += ", "; * text += msg; * } * * * if ( core->getManualStatus()==STATUS_NA && * data->EnableCapsLockFlash.toBool() && * ! this->isRunning() * ) * this->start(); //Start flashing the CapsLock if enabled * text = i18n("%1 from %2") .arg(text) .arg(contact->getName()); * if (msg_text.isEmpty()) * break; * text += ":\n"; * text += msg_text; * } */ break; default: break; } if (!text.isEmpty()){ if (m_osd == NULL){ m_osd = new OSDWidget(this); connect(m_osd, SIGNAL(dblClick()), this, SLOT(dblClick())); connect(m_osd, SIGNAL(closeClick()), this, SLOT(closeClick())); } static_cast<OSDWidget*>(m_osd)->showOSD(text, data); m_timer->start(data->value("Timeout").toUInt() * 1000); bTimerActive=true; //Due to a f*****g bug in QTimer::isActive() return; } } m_timer->stop(); bTimerActive=false; //Due to a f*****g bug in QTimer::isActive() m_request.contact = 0; m_request.type = OSD_NONE; }
bool OSDPlugin::processEvent(Event *e) { OSDRequest osd; switch (e->type()){ case eEventContact: { EventContact *ec = static_cast<EventContact*>(e); Contact *contact = ec->contact(); if (contact->getIgnore()) break; switch(ec->action()) { case EventContact::eOnline: { osd.contact = contact->id(); osd.type = OSD_ALERTONLINE; m_queue.push_back(osd); processQueue(); break; } case EventContact::eStatus: { SIM::PropertyHubPtr data = contact->getUserData("OSD"); if(!data.isNull()) { unsigned style = 0; QSet<QString> wrkIcons; QString statusIcon; contact->contactInfo(style, statusIcon, &wrkIcons); if (wrkIcons.contains("typing")){ if (!m_typing.contains(contact->id())) { m_typing += contact->id(); osd.contact = contact->id(); osd.type = OSD_TYPING; m_queue.push_back(osd); processQueue(); } }else{ m_typing.remove(contact->id()); if ((m_request.type == OSD_TYPING) && (m_request.contact == contact->id())){ m_timer->stop(); bTimerActive=false; m_timer->start(100); bTimerActive=true; } } } break; } default: break; } break; } case eEventMessageReceived: { EventMessage *em = static_cast<EventMessage*>(e); Message *msg = em->msg(); Contact *contact = getContacts()->contact(msg->contact()); if (contact == NULL) break; SIM::PropertyHubPtr data = contact->getUserData("OSD"); if(data.isNull()) break; osd.contact = msg->contact(); CorePlugin* core = GET_CorePlugin(); if (!core->unread.empty()) bHaveUnreadMessages=true; if (msg->type() == MessageStatus) { StatusMessage *smsg = (StatusMessage*)msg; switch (smsg->getStatus()) { case STATUS_AWAY: osd.type = OSD_ALERTAWAY; break; case STATUS_NA: osd.type = OSD_ALERTNA; break; case STATUS_DND: osd.type = OSD_ALERTDND; break; case STATUS_OCCUPIED: /* STATUS_OCCUPIED, took over from contacts.h! */ osd.type = OSD_ALERTOCCUPIED; break; case STATUS_FFC: osd.type = OSD_ALERTFFC; break; case STATUS_OFFLINE: osd.type = OSD_ALERTOFFLINE; break; case STATUS_ONLINE: osd.type = OSD_NONE; return false; default: log(L_DEBUG,"OSD: Unknown status %ld",smsg->getStatus()); osd.type = OSD_NONE; return false; } m_queue.push_back(osd); processQueue(); }else{ osd.type = OSD_MESSAGE; if ((m_request.type == OSD_MESSAGE) && (m_request.contact == msg->contact())){ m_queue.push_front(osd); m_timer->stop(); bTimerActive=false; m_timer->start(100);bTimerActive=true; }else{ m_queue.push_back(osd); processQueue(); } } break; } case eEventMessageDeleted: case eEventMessageRead: { EventMessage *em = static_cast<EventMessage*>(e); Message *msg = em->msg(); Contact *contact = getContacts()->contact(msg->contact()); if (contact == NULL) break; SIM::PropertyHubPtr data = contact->getUserData("OSD"); if (data.isNull()) break; osd.contact = msg->contact(); CorePlugin* core = GET_CorePlugin(); if (core->unread.empty()) bHaveUnreadMessages=false; if (msg->type() == MessageStatus) { StatusMessage *smsg = (StatusMessage*)msg; switch (smsg->getStatus()) { case STATUS_AWAY: osd.type = OSD_ALERTAWAY; break; case STATUS_NA: osd.type = OSD_ALERTNA; break; case STATUS_DND: osd.type = OSD_ALERTDND; break; case STATUS_OCCUPIED: /* STATUS_OCCUPIED, took over from contacts.h! */ osd.type = OSD_ALERTOCCUPIED; break; case STATUS_FFC: osd.type = OSD_ALERTFFC; break; case STATUS_OFFLINE: osd.type = OSD_ALERTOFFLINE; break; case STATUS_ONLINE: osd.type = OSD_NONE; return false; default: log(L_DEBUG,"OSD: Unknown status %ld",smsg->getStatus()); osd.type = OSD_NONE; return false; } m_queue.push_back(osd); processQueue(); }else{ osd.type = OSD_MESSAGE; if ((m_request.type == OSD_MESSAGE) && (m_request.contact == msg->contact())){ m_queue.push_front(osd); m_timer->stop(); bTimerActive=false; m_timer->start(100);bTimerActive=true; }else{ m_queue.push_back(osd); processQueue(); } } break; } default: break; } return false; }
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(); }
bool MsgEdit::sendMessage(Message *msg) { if (m_retry.msg){ delete m_retry.msg; m_retry.msg = NULL; } if (m_msg){ delete msg; Event e(EventMessageCancel, m_msg); if (e.process()) m_msg = NULL; stopSend(false); return false; } bool bClose = true; if (CorePlugin::m_plugin->getContainerMode()){ bClose = false; Command cmd; cmd->id = CmdSendClose; cmd->param = this; Event e(EventCommandWidget, cmd); QToolButton *btnClose = (QToolButton*)(e.process()); if (btnClose) bClose = btnClose->isOn(); } CorePlugin::m_plugin->setCloseSend(bClose); Contact *contact = getContacts()->contact(m_userWnd->id()); if (contact){ TranslitUserData *data = (TranslitUserData*)(contact->getUserData(CorePlugin::m_plugin->translit_data_id)); if (data && data->Translit) msg->setFlags(msg->getFlags() | MESSAGE_TRANSLIT); } msg->setFlags(msg->getFlags() | m_flags); m_flags = 0; if (m_userWnd->m_list){ multiply = m_userWnd->m_list->selected; if (multiply.empty()) return false; multiply_it = multiply.begin(); msg->setContact(*multiply_it); msg->setClient(NULL); ++multiply_it; if (multiply_it != multiply.end()) msg->setFlags(msg->getFlags() | MESSAGE_MULTIPLY); } editLostFocus(); Command cmd; cmd->id = CmdSend; cmd->text = I18N_NOOP("Cancel"); cmd->icon = "cancel"; cmd->flags = BTN_PICT; cmd->param = this; Event eCmd(EventCommandChange, cmd); eCmd.process(); m_msg = msg; return send(); }
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 *MsgEdit::processEvent(Event *e) { if ((e->type() == EventContactChanged) && (((Contact*)(e->param()))->id() == m_userWnd->m_id)){ adjustType(); return NULL; } if (e->type() == EventClientChanged){ adjustType(); return NULL; } if (e->type() == EventMessageReceived){ Message *msg = (Message*)(e->param()); if (msg->getFlags() & MESSAGE_NOVIEW) return NULL; if ((msg->contact() == m_userWnd->id()) && (msg->type() != MessageStatus)){ if (CorePlugin::m_plugin->getContainerMode()){ bool bSetFocus = false; if (topLevelWidget() && topLevelWidget()->inherits("Container")){ Container *container = static_cast<Container*>(topLevelWidget()); if (container->wnd() == m_userWnd) bSetFocus = true; } setMessage(msg, bSetFocus); }else{ if (m_edit->isReadOnly()) QTimer::singleShot(0, this, SLOT(setupNext())); } } } if (e->type() == EventRealSendMessage){ MsgSend *s = (MsgSend*)(e->param()); if (s->edit == this){ sendMessage(s->msg); return e->param(); } } if (e->type() == EventCheckState){ CommandDef *cmd = (CommandDef*)(e->param()); if ((cmd->param == this) && (cmd->id == CmdTranslit)){ Contact *contact = getContacts()->contact(m_userWnd->id()); if (contact){ TranslitUserData *data = (TranslitUserData*)(contact->getUserData(CorePlugin::m_plugin->translit_data_id)); if (data){ cmd->flags &= ~COMMAND_CHECKED; if (data->Translit.bValue) cmd->flags |= COMMAND_CHECKED; } } return NULL; } if ((cmd->menu_id != MenuTextEdit) || (cmd->param != this)) return NULL; cmd->flags &= ~(COMMAND_CHECKED | COMMAND_DISABLED); switch (cmd->id){ case CmdUndo: if (m_edit->isReadOnly()) return NULL; if (!m_edit->isUndoAvailable()) cmd->flags |= COMMAND_DISABLED; return e->param(); case CmdRedo: if (m_edit->isReadOnly()) return NULL; if (!m_edit->isRedoAvailable()) cmd->flags |= COMMAND_DISABLED; return e->param(); case CmdCut: if (m_edit->isReadOnly()) return NULL; case CmdCopy: if (!m_edit->hasSelectedText()) cmd->flags |= COMMAND_DISABLED; return e->param(); case CmdPaste: if (m_edit->isReadOnly()) return NULL; if (QApplication::clipboard()->text().isEmpty()) cmd->flags |= COMMAND_DISABLED; return e->param(); case CmdClear: if (m_edit->isReadOnly()) return NULL; case CmdSelectAll: if (m_edit->text().isEmpty()) cmd->flags |= COMMAND_DISABLED; return e->param(); } return NULL; } if (e->type() == EventCommandExec){ CommandDef *cmd = (CommandDef*)(e->param()); #if defined(USE_KDE) #if KDE_IS_VERSION(3,2,0) if (cmd->id == CmdEnableSpell){ m_edit->setCheckSpellingEnabled(cmd->flags & COMMAND_CHECKED); return NULL; } if ((cmd->id == CmdSpell) && (cmd->param == this)){ m_edit->checkSpelling(); return e->param(); } #endif #endif if ((cmd->id == CmdSmile) && (cmd->param == this)){ Event eBtn(EventCommandWidget, cmd); QToolButton *btnSmile = (QToolButton*)(eBtn.process()); if (btnSmile){ SmilePopup *popup = new SmilePopup(this); QSize s = popup->minimumSizeHint(); popup->resize(s); connect(popup, SIGNAL(insert(const char*)), this, SLOT(insertSmile(const char*))); QPoint p = CToolButton::popupPos(btnSmile, popup); popup->move(p); popup->show(); } return e->param(); }
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; if (!contact) { delete msg; return msg; } // check if we accept only from users on the list if (getFromList() && contact->getTemporary()){ delete msg; delete contact; return msg; } // 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 && *data->SpamList){ if (checkSpam(msg->getPlainText(), QString::fromUtf8(data->SpamList))){ 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){ 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 *SoundPlugin::processEvent(Event *e) { if (e->type() == EventSoundChanged){ Command cmd; cmd->id = CmdSoundDisable; SoundUserData *data = (SoundUserData*)(getContacts()->getUserData(user_data_id)); if (data->Disable == 0) cmd->flags |= COMMAND_CHECKED; m_bChanged = true; Event e(EventCommandChecked, cmd); e.process(); m_bChanged = false; return NULL; } if (e->type() == EventCheckState){ CommandDef *cmd = (CommandDef*)(e->param()); if (cmd->id == CmdSoundDisable){ cmd->flags &= ~COMMAND_CHECKED; SoundUserData *data = (SoundUserData*)(getContacts()->getUserData(user_data_id)); if (data->Disable == 0) cmd->flags |= COMMAND_CHECKED; return e->param(); } return NULL; } if (e->type() == EventCommandExec){ CommandDef *cmd = (CommandDef*)(e->param()); if (!m_bChanged && (cmd->id == CmdSoundDisable)){ SoundUserData *data = (SoundUserData*)(getContacts()->getUserData(user_data_id)); data->Disable = (data->Disable == 0); Event eChanged(EventSoundChanged); eChanged.process(); return e->param(); } return NULL; } if (e->type() == EventContactOnline){ Contact *contact = (Contact*)(e->param()); SoundUserData *data = (SoundUserData*)(contact->getUserData(user_data_id)); if (data && data->Alert && *data->Alert && (data->Disable == 0) && (!getDisableAlert() || (core && ((core->getManualStatus() == STATUS_ONLINE) || (core->getManualStatus() == STATUS_OFFLINE))))){ Event eSound(EventPlaySound, data->Alert); eSound.process(); } return NULL; } if (e->type() == EventMessageSent){ Message *msg = (Message*)(e->param()); const char *err = msg->getError(); if (err && *err) return NULL; const char *sound = NULL; if (msg->type() == MessageFile){ sound = getFileDone(); }else if ((msg->getFlags() & MESSAGE_NOHISTORY) == 0){ if ((msg->getFlags() & MESSAGE_MULTIPLY) && ((msg->getFlags() & MESSAGE_LAST) == 0)) return NULL; sound = getMessageSent(); } if (sound && *sound && (!getDisableAlert() || (core && (core->getManualStatus() == STATUS_ONLINE)))){ Event eSound(EventPlaySound, (void*)sound); eSound.process(); } return NULL; } if (e->type() == EventMessageReceived){ Message *msg = (Message*)(e->param()); if (msg->type() == MessageStatus) return NULL; if (getDisableAlert() && core && (core->getManualStatus() != STATUS_ONLINE)) return NULL; if (msg->getFlags() & MESSAGE_LIST) return NULL; Contact *contact = getContacts()->contact(msg->contact()); if (contact == NULL) return NULL; SoundUserData *data = (SoundUserData*)(contact->getUserData(user_data_id)); bool bEnable = (data->Disable == 0); if (bEnable && data->NoSoundIfActive){ Event e(EventActiveContact); if ((unsigned)(e.process()) == contact->id()) bEnable = false; } if (bEnable){ string sound = messageSound(msg->baseType(), data); if (!sound.empty()) playSound(sound.c_str()); } return NULL; } if (e->type() == EventPlaySound){ char *name = (char*)(e->param()); playSound(name); return e->param(); } return NULL; }
void OSDPlugin::processQueue() { if (m_timer->isActive()) return; while (queue.size()){ m_request = queue.front(); queue.erase(queue.begin()); Contact *contact = getContacts()->contact(m_request.contact); if ((contact == NULL) || contact->getIgnore()){ continue; } QString text; OSDUserData *data = NULL; data = (OSDUserData*)contact->getUserData(user_data_id); uint ms=core->getManualStatus(); switch (m_request.type){ case OSD_ALERTONLINE: if (data->EnableAlert.toBool() && data->EnableAlertOnline.toBool()){ unsigned style = 0; QString statusIcon; if (contact->contactInfo(style, statusIcon) == STATUS_ONLINE) text = g_i18n("%1 is online", contact) .arg(contact->getName()); } break; case OSD_ALERTAWAY: if (data->EnableAlert.toBool() && data->EnableAlertAway.toBool()){ text = g_i18n("%1 is away", contact) .arg(contact->getName()); } break; case OSD_ALERTNA: if (data->EnableAlert.toBool() && data->EnableAlertNA.toBool()){ text = g_i18n("%1 is not available", contact) .arg(contact->getName()); } break; case OSD_ALERTDND: if (data->EnableAlert.toBool() && data->EnableAlertDND.toBool()){ text = g_i18n("%1 doesn't want to be disturbed", contact) .arg(contact->getName()); } break; case OSD_ALERTOCCUPIED: if (data->EnableAlert.toBool() && data->EnableAlertOccupied.toBool()){ text = g_i18n("%1 is occupied", contact) .arg(contact->getName()); } break; case OSD_ALERTFFC: if (data->EnableAlert.toBool() && data->EnableAlertFFC.toBool()){ text = g_i18n("%1 is free for chat", contact) .arg(contact->getName()); } break; case OSD_ALERTOFFLINE: if (data->EnableAlert.toBool() && data->EnableAlertOffline.toBool() && (ms-1) ){ text = g_i18n("%1 is offline", contact) .arg(contact->getName()); } break; case OSD_TYPING: if (data->EnableTyping.toBool()){ unsigned style = 0; QString wrkIcons; QString statusIcon; contact->contactInfo(style, statusIcon, &wrkIcons); bool bTyping = false; while (!wrkIcons.isEmpty()){ if (getToken(wrkIcons, ',') == "typing"){ bTyping = true; break; } } if (bTyping) text = g_i18n("%1 is typing", contact) .arg(contact->getName()); } break; case OSD_MESSAGE: if (data->EnableMessage.toBool() && core){ list<msg_id>::iterator it; TYPE_MAP types; TYPE_MAP::iterator itc; QString msg_text; for (it = core->unread.begin(); it != core->unread.end(); ++it){ if ((*it).contact != m_request.contact) continue; unsigned type = (*it).type; itc = types.find(type); if (itc == types.end()){ types.insert(TYPE_MAP::value_type(type, 1)); }else{ (*itc).second++; } if (!data->EnableMessageShowContent.toBool()) continue; EventLoadMessage e((*it).id, (*it).client, (*it).contact); e.process(); Message *msg = e.message(); if (msg == NULL) continue; QString msgText = msg->getPlainText().stripWhiteSpace(); if (msgText.isEmpty()) continue; if (!msg_text.isEmpty()) msg_text += "\n"; msg_text += msgText; } if (types.empty()) break; for (itc = types.begin(); itc != types.end(); ++itc){ CommandDef *def = core->messageTypes.find((*itc).first); if (def == NULL) continue; MessageDef *mdef = (MessageDef*)(def->param); QString msg = i18n(mdef->singular, mdef->plural, (*itc).second); if ((*itc).second == 1){ int pos = msg.find("1 "); if (pos > 0){ msg = msg.left(pos); }else if (pos == 0){ msg = msg.mid(2); } msg = msg.left(1).upper() + msg.mid(1); } if (!text.isEmpty()) text += ", "; text += msg; } if ( core->getManualStatus()==STATUS_NA && data->EnableCapsLockFlash.toBool() && ! this->running() ) this->start(); //Start flashing the CapsLock if enabled text = i18n("%1 from %2") .arg(text) .arg(contact->getName()); if (msg_text.isEmpty()) break; text += ":\n"; text += msg_text; } break; default: break; } if (!text.isEmpty()){ if (m_osd == NULL){ m_osd = new OSDWidget(this); connect(m_osd, SIGNAL(dblClick()), this, SLOT(dblClick())); connect(m_osd, SIGNAL(closeClick()), this, SLOT(closeClick())); } static_cast<OSDWidget*>(m_osd)->showOSD(text, data); m_timer->start(data->Timeout.toULong() * 1000); return; } } m_timer->stop(); m_request.contact = 0; m_request.type = OSD_NONE; }
bool OSDPlugin::processEvent(Event *e) { OSDRequest osd; switch (e->type()){ case eEventContact: { EventContact *ec = static_cast<EventContact*>(e); Contact *contact = ec->contact(); if (contact->getIgnore()) break; switch(ec->action()) { case EventContact::eOnline: { osd.contact = contact->id(); osd.type = OSD_ALERTONLINE; queue.push_back(osd); processQueue(); break; } case EventContact::eStatus: { OSDUserData *data = (OSDUserData*)(contact->getUserData(user_data_id)); if (data){ unsigned style = 0; QString wrkIcons; QString statusIcon; contact->contactInfo(style, statusIcon, &wrkIcons); bool bTyping = false; while (!wrkIcons.isEmpty()){ if (getToken(wrkIcons, ',') == "typing"){ bTyping = true; break; } } if (bTyping){ list<unsigned>::iterator it; for (it = typing.begin(); it != typing.end(); ++it) if ((*it) == contact->id()) break; if (it == typing.end()){ typing.push_back(contact->id()); osd.contact = contact->id(); osd.type = OSD_TYPING; queue.push_back(osd); processQueue(); } }else{ list<unsigned>::iterator it; for (it = typing.begin(); it != typing.end(); ++it) if ((*it) == contact->id()) break; if (it != typing.end()) typing.erase(it); if ((m_request.type == OSD_TYPING) && (m_request.contact == contact->id())){ m_timer->stop(); m_timer->start(100); } } } break; } default: break; } break; } case eEventMessageReceived: { EventMessage *em = static_cast<EventMessage*>(e); Message *msg = em->msg(); Contact *contact = getContacts()->contact(msg->contact()); if (contact == NULL) break; OSDUserData *data = (OSDUserData*)(contact->getUserData(user_data_id)); if (data == NULL) break; osd.contact = msg->contact(); if (! core->unread.empty()) bHaveUnreadMessages=true; if (msg->type() == MessageStatus) { StatusMessage *smsg = (StatusMessage*)msg; switch (smsg->getStatus()) { case STATUS_AWAY: osd.type = OSD_ALERTAWAY; break; case STATUS_NA: osd.type = OSD_ALERTNA; break; case STATUS_DND: osd.type = OSD_ALERTDND; break; case STATUS_OCCUPIED: /* STATUS_OCCUPIED, took over from contacts.h! */ osd.type = OSD_ALERTOCCUPIED; break; case STATUS_FFC: osd.type = OSD_ALERTFFC; break; case STATUS_OFFLINE: osd.type = OSD_ALERTOFFLINE; break; case STATUS_ONLINE: osd.type = OSD_NONE; return false; default: log(L_DEBUG,"OSD: Unknown status %ld",smsg->getStatus()); osd.type = OSD_NONE; return false; } queue.push_back(osd); processQueue(); }else{ osd.type = OSD_MESSAGE; if ((m_request.type == OSD_MESSAGE) && (m_request.contact == msg->contact())){ queue.push_front(osd); m_timer->stop(); m_timer->start(100); }else{ queue.push_back(osd); processQueue(); } } break; } case eEventMessageDeleted: case eEventMessageRead: { EventMessage *em = static_cast<EventMessage*>(e); Message *msg = em->msg(); Contact *contact = getContacts()->contact(msg->contact()); if (contact == NULL) break; OSDUserData *data = (OSDUserData*)(contact->getUserData(user_data_id)); if (data == NULL) break; osd.contact = msg->contact(); if (core->unread.empty()) bHaveUnreadMessages=false; if (msg->type() == MessageStatus) { StatusMessage *smsg = (StatusMessage*)msg; switch (smsg->getStatus()) { case STATUS_AWAY: osd.type = OSD_ALERTAWAY; break; case STATUS_NA: osd.type = OSD_ALERTNA; break; case STATUS_DND: osd.type = OSD_ALERTDND; break; case STATUS_OCCUPIED: /* STATUS_OCCUPIED, took over from contacts.h! */ osd.type = OSD_ALERTOCCUPIED; break; case STATUS_FFC: osd.type = OSD_ALERTFFC; break; case STATUS_OFFLINE: osd.type = OSD_ALERTOFFLINE; break; case STATUS_ONLINE: osd.type = OSD_NONE; return false; default: log(L_DEBUG,"OSD: Unknown status %ld",smsg->getStatus()); osd.type = OSD_NONE; return false; } queue.push_back(osd); processQueue(); }else{ osd.type = OSD_MESSAGE; if ((m_request.type == OSD_MESSAGE) && (m_request.contact == msg->contact())){ queue.push_front(osd); m_timer->stop(); m_timer->start(100); }else{ queue.push_back(osd); processQueue(); } } break; } default: break; } return false; }
bool ForwardPlugin::processEvent(Event *e) { if (e->type() == eEventMessageReceived){ EventMessage *em = static_cast<EventMessage*>(e); Message *msg = em->msg(); if (msg->type() == MessageStatus) return false; QString text = msg->getPlainText(); if (text.isEmpty()) return false; if (msg->type() == MessageSMS){ SMSMessage *sms = static_cast<SMSMessage*>(msg); QString phone = sms->getPhone(); bool bMyPhone; SIM::PropertyHubPtr data = getContacts()->getUserData("forward"); bMyPhone = ContactList::cmpPhone(phone, data->value("Phone").toString()); if (!bMyPhone){ Group *grp; ContactList::GroupIterator it; while ((grp = ++it) != NULL){ data = grp->getUserData("forward", false); if (data && !data->value("Phone").toString().isEmpty()){ bMyPhone = ContactList::cmpPhone(phone, data->value("Phone").toString()); break; } } } if (!bMyPhone){ Contact *contact; ContactList::ContactIterator it; while ((contact = ++it) != NULL){ data = contact->getUserData("forward", false); if (data && !data->value("Phone").toString().isEmpty()) { bMyPhone = ContactList::cmpPhone(phone, data->value("Phone").toString()); break; } } } if (bMyPhone){ int n = text.indexOf(": "); if (n > 0){ QString name = text.left(n); QString msg_text = text.mid(n + 2); Contact *contact; ContactList::ContactIterator it; while ((contact = ++it) != NULL){ if (contact->getName() == name){ Message *msg = new Message(MessageGeneric); msg->setContact(contact->id()); msg->setText(msg_text); void *data; ClientDataIterator it(contact->clientData); while ((data = ++it) != NULL){ if (it.client()->send(msg, data)) break; } if (data == NULL) delete msg; return true; } } } } } Contact *contact = getContacts()->contact(msg->contact()); if (contact == NULL) return false; SIM::PropertyHubPtr data = contact->getUserData("forward"); if (!data || data->value("Key").toString().isEmpty()) return false; CorePlugin *core = GET_CorePlugin(); unsigned status = core->getManualStatus(); if ((status == STATUS_AWAY) || (status == STATUS_NA)){ text = contact->getName() + ": " + text; unsigned flags = MESSAGE_NOHISTORY; if (data->value("Send1st").toBool()) flags |= MESSAGE_1ST_PART; if (data->value("Translit").toBool()) flags |= MESSAGE_TRANSLIT; SMSMessage *m = new SMSMessage; m->setPhone(data->value("Phone").toString()); m->setText(text); m->setFlags(flags); unsigned i; for (i = 0; i < getContacts()->nClients(); i++){ Client *client = getContacts()->getClient(i); if (client->send(m, NULL)) break; } if (i >= getContacts()->nClients()) delete m; } } return false; }
void OSDPlugin::processQueue() { if (m_timer->isActive()) return; while (queue.size()){ m_request = queue.front(); queue.erase(queue.begin()); Contact *contact = getContacts()->contact(m_request.contact); if ((contact == NULL) || contact->getIgnore()){ continue; } QString text; OSDUserData *data = NULL; data = (OSDUserData*)contact->getUserData(user_data_id); switch (m_request.type){ case OSD_ALERT: if (data->EnableAlert.bValue){ unsigned style = 0; const char *statusIcon = NULL; if (contact->contactInfo(style, statusIcon) >= STATUS_ONLINE) text = g_i18n("%1 is online", contact) .arg(contact->getName()); } break; case OSD_TYPING: if (data->EnableTyping.bValue){ unsigned style = 0; string wrkIcons; const char *statusIcon = NULL; contact->contactInfo(style, statusIcon, &wrkIcons); bool bTyping = false; while (!wrkIcons.empty()){ if (getToken(wrkIcons, ',') == "typing"){ bTyping = true; break; } } if (bTyping) text = g_i18n("%1 is typing", contact) .arg(contact->getName()); } break; case OSD_MESSAGE: if (data->EnableMessage.bValue && core){ list<msg_id>::iterator it; TYPE_MAP types; TYPE_MAP::iterator itc; QString msg_text; for (it = core->unread.begin(); it != core->unread.end(); ++it){ if ((*it).contact != m_request.contact) continue; unsigned type = (*it).type; itc = types.find(type); if (itc == types.end()){ types.insert(TYPE_MAP::value_type(type, 1)); }else{ (*itc).second++; } if (!data->EnableMessageShowContent.bValue) continue; MessageID id; id.id = (*it).id; id.contact = (*it).contact; id.client = (*it).client.c_str(); Event e(EventLoadMessage, &id); Message *msg = (Message*)(e.process()); if (msg == NULL) continue; QString msgText = msg->getPlainText().stripWhiteSpace(); if (msgText.isEmpty()) continue; if (!msg_text.isEmpty()) msg_text += "\n"; msg_text += msgText; } if (types.empty()) break; for (itc = types.begin(); itc != types.end(); ++itc){ CommandDef *def = core->messageTypes.find((*itc).first); if (def == NULL) continue; MessageDef *mdef = (MessageDef*)(def->param); QString msg = i18n(mdef->singular, mdef->plural, (*itc).second); if ((*itc).second == 1){ int pos = msg.find("1 "); if (pos > 0){ msg = msg.left(pos); }else if (pos == 0){ msg = msg.mid(2); } msg = msg.left(1).upper() + msg.mid(1); } if (!text.isEmpty()) text += ", "; text += msg; } text = i18n("%1 from %2") .arg(text) .arg(contact->getName()); if (msg_text.isEmpty()) break; text += ":\n"; text += msg_text; } } if (!text.isEmpty()){ if (m_osd == NULL){ m_osd = new OSDWidget; connect(m_osd, SIGNAL(dblClick()), this, SLOT(dblClick())); } static_cast<OSDWidget*>(m_osd)->showOSD(text, data); m_timer->start(data->Timeout.value * 1000); return; } } m_timer->stop(); m_request.contact = 0; m_request.type = OSD_NONE; }
void *OSDPlugin::processEvent(Event *e) { OSDRequest osd; Contact *contact; Message *msg; OSDUserData *data; switch (e->type()){ case EventContactOnline: contact = (Contact*)(e->param()); if (contact->getIgnore()) break; osd.contact = contact->id(); osd.type = OSD_ALERTONLINE; queue.push_back(osd); processQueue(); break; case EventMessageDeleted: case EventMessageRead: case EventMessageReceived: msg = (Message*)(e->param()); contact = getContacts()->contact(msg->contact()); if (contact == NULL) break; data = (OSDUserData*)(contact->getUserData(user_data_id)); if (data == NULL) break; osd.contact = msg->contact(); if (msg->type() == MessageStatus) { StatusMessage *smsg = (StatusMessage*)msg; switch (smsg->getStatus()) { case STATUS_AWAY: osd.type = OSD_ALERTAWAY; break; case STATUS_NA: osd.type = OSD_ALERTNA; break; case STATUS_DND: osd.type = OSD_ALERTDND; break; case 100: /* STATUS_OCCUPIED, but defined in icqclient.h ! */ osd.type = OSD_ALERTOCCUPIED; break; case STATUS_FFC: osd.type = OSD_ALERTFFC; break; case STATUS_OFFLINE: osd.type = OSD_ALERTOFFLINE; break; case STATUS_ONLINE: osd.type = OSD_NONE; return NULL; default: log(L_DEBUG,"OSD: Unknown status %ld",smsg->getStatus()); osd.type = OSD_NONE; return NULL; } queue.push_back(osd); processQueue(); }else{ osd.type = OSD_MESSAGE; if ((m_request.type == OSD_MESSAGE) && (m_request.contact == msg->contact())){ queue.push_front(osd); m_timer->stop(); m_timer->start(100); }else{ queue.push_back(osd); processQueue(); } } break; case EventContactStatus: contact = (Contact*)(e->param()); if (contact->getIgnore()) break; data = (OSDUserData*)(contact->getUserData(user_data_id)); if (data){ unsigned style = 0; string wrkIcons; const char *statusIcon = NULL; contact->contactInfo(style, statusIcon, &wrkIcons); bool bTyping = false; while (!wrkIcons.empty()){ if (getToken(wrkIcons, ',') == "typing"){ bTyping = true; break; } } if (bTyping){ list<unsigned>::iterator it; for (it = typing.begin(); it != typing.end(); ++it) if ((*it) == contact->id()) break; if (it == typing.end()){ typing.push_back(contact->id()); osd.contact = contact->id(); osd.type = OSD_TYPING; queue.push_back(osd); processQueue(); } }else{ list<unsigned>::iterator it; for (it = typing.begin(); it != typing.end(); ++it) if ((*it) == contact->id()) break; if (it != typing.end()) typing.erase(it); if ((m_request.type == OSD_TYPING) && (m_request.contact == contact->id())){ m_timer->stop(); m_timer->start(100); } } } break; } return NULL; }
void *OSDPlugin::processEvent(Event *e) { OSDRequest osd; Contact *contact; Message *msg; OSDUserData *data; switch (e->type()){ case EventContactOnline: contact = (Contact*)(e->param()); if (contact->getIgnore()) break; osd.contact = contact->id(); osd.type = OSD_ALERT; queue.push_back(osd); processQueue(); break; case EventMessageReceived: msg = (Message*)(e->param()); if (msg->type() == MessageStatus) break; osd.contact = msg->contact(); osd.type = msg->type(); osd.msg_id = msg->id(); osd.client = msg->client(); queue.push_back(osd); processQueue(); break; case EventContactStatus: contact = (Contact*)(e->param()); if (contact->getIgnore()) break; data = (OSDUserData*)(contact->getUserData(user_data_id)); if (data){ unsigned style = 0; string wrkIcons; const char *statusIcon = NULL; contact->contactInfo(style, statusIcon, &wrkIcons); bool bTyping = false; while (!wrkIcons.empty()){ if (getToken(wrkIcons, ',') == "typing"){ bTyping = true; break; } } if (bTyping){ list<unsigned>::iterator it; for (it = typing.begin(); it != typing.end(); ++it) if ((*it) == contact->id()) break; if (it == typing.end()){ typing.push_back(contact->id()); osd.contact = contact->id(); osd.type = OSD_TYPING; queue.push_back(osd); processQueue(); } }else{ list<unsigned>::iterator it; for (it = typing.begin(); it != typing.end(); ++it) if ((*it) == contact->id()) break; if (it != typing.end()) typing.erase(it); } } break; } return NULL; }
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; }
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); }
bool MsgEdit::processEvent(Event *e) { switch (e->type()) { case eEventContact: { EventContact *ec = static_cast<EventContact*>(e); if (ec->contact()->id() != m_userWnd->m_id) break; adjustType(); break; } case eEventClientChanged: { adjustType(); break; } case eEventMessageReceived: { EventMessage *em = static_cast<EventMessage*>(e); Message *msg = em->msg(); if (msg->getFlags() & MESSAGE_NOVIEW) return false; if ((msg->contact() == m_userWnd->id()) && (msg->type() != MessageStatus)){ if (CorePlugin::instance()->getContainerMode()){ bool bSetFocus = false; if (topLevelWidget() && topLevelWidget()->inherits("Container")){ Container *container = static_cast<Container*>(topLevelWidget()); if (container->wnd() == m_userWnd) bSetFocus = true; } setMessage(msg, bSetFocus); }else{ if (m_edit->isReadOnly()) QTimer::singleShot(0, this, SLOT(setupNext())); } } break; } case eEventRealSendMessage: { EventRealSendMessage *ersm = static_cast<EventRealSendMessage*>(e); if (ersm->edit() == this){ sendMessage(ersm->msg()); return true; } break; } case eEventCheckCommandState: { EventCheckCommandState *ecs = static_cast<EventCheckCommandState*>(e); CommandDef *cmd = ecs->cmd(); if ((cmd->param == (TextEdit*)m_edit) && (cmd->id == CmdTranslit)){ Contact *contact = getContacts()->contact(m_userWnd->id()); if (contact){ SIM::PropertyHubPtr data = contact->getUserData("translit"); if(!data.isNull()) { cmd->flags &= ~COMMAND_CHECKED; if (data->value("Translit").toBool()) cmd->flags |= COMMAND_CHECKED; // FIXME: return true; missing here? } } return false; } if ((cmd->menu_id != MenuTextEdit) || (cmd->param != (TextEdit*)m_edit)) return false; cmd->flags &= ~(COMMAND_CHECKED | COMMAND_DISABLED); switch (cmd->id){ case CmdUndo: if (m_edit->isReadOnly()) return false; if (!m_edit->document()->isUndoAvailable()) cmd->flags |= COMMAND_DISABLED; return true; case CmdRedo: if (m_edit->isReadOnly()) return false; if (!m_edit->document()->isRedoAvailable()) cmd->flags |= COMMAND_DISABLED; return true; case CmdCut: if (m_edit->isReadOnly()) return false; case CmdCopy: if (m_edit->textCursor().selectedText().isEmpty()) cmd->flags |= COMMAND_DISABLED; return true; case CmdPaste: if (m_edit->isReadOnly()) return false; if (QApplication::clipboard()->text().isEmpty()) cmd->flags |= COMMAND_DISABLED; return true; case CmdClear: if (m_edit->isReadOnly()) return false; case CmdSelectAll: if (m_edit->toPlainText().isEmpty()) cmd->flags |= COMMAND_DISABLED; return true; } break; } case eEventCommandExec: { EventCommandExec *ece = static_cast<EventCommandExec*>(e); CommandDef *cmd = ece->cmd(); #if defined(USE_KDE) #if KDE_IS_VERSION(3,2,0) if (cmd->id == CmdEnableSpell){ m_edit->setCheckSpellingEnabled(cmd->flags & COMMAND_CHECKED); return false; } else if ((cmd->id == CmdSpell) && (cmd->param == this)){ m_edit->checkSpelling(); return true; } else #endif #endif if ((cmd->id == CmdSmile) && (cmd->param == this)){ EventCommandWidget eWidget(cmd); eWidget.process(); QToolButton *btnSmile = qobject_cast<QToolButton*>(eWidget.widget()); if (btnSmile){ SmilePopup *popup = new SmilePopup(this); connect(popup, SIGNAL(insert(const QString &)), this, SLOT(insertSmile(const QString &))); QPoint p = CToolButton::popupPos(btnSmile, popup); popup->move(p); popup->show(); } return true; } else if ((cmd->id == CmdTranslit) && (cmd->param == this)){ Contact *contact = getContacts()->contact(m_userWnd->id()); if (contact){ SIM::PropertyHubPtr data = contact->getUserData("translit", true); data->setValue("Translit", ((cmd->flags & COMMAND_CHECKED) != 0)); } return true; } else if ((cmd->id == CmdMultiply) && (cmd->param == this)){ m_userWnd->showListView((cmd->flags & COMMAND_CHECKED) != 0); return true; } else if ((cmd->bar_id == ToolBarMsgEdit) && m_edit->isReadOnly() && (cmd->param == this)){ switch (cmd->id){ case CmdMsgAnswer:{ Message *msg = new Message(MessageGeneric); msg->setContact(m_userWnd->id()); msg->setClient(m_client); EventOpenMessage(msg).process(); delete msg; } case CmdNextMessage: QTimer::singleShot(0, this, SLOT(goNext())); break; } } else if ((cmd->menu_id != MenuTextEdit) || (cmd->param != this)) return false; switch (cmd->id){ case CmdUndo: m_edit->undo(); return true; case CmdRedo: m_edit->redo(); return true; case CmdCut: m_edit->cut(); return true; case CmdCopy: m_edit->copy(); return true; case CmdPaste: m_edit->paste(); return true; case CmdClear: m_edit->clear(); return true; case CmdSelectAll: m_edit->selectAll(); return true; } break; }
bool SoundPlugin::processEvent(SIM::Event *e) { switch (e->type()) { case eEventLoginStart: { playSound(value("StartUp").toString()); break; } case eEventPluginLoadConfig: { PropertyHubPtr hub = ProfileManager::instance()->getPropertyHub("sound"); if(!hub.isNull()) setPropertyHub(hub); if(!value("StartUp").isValid()) setValue("StartUp", "sounds/startup.ogg"); if(!value("MessageSent").isValid()) setValue("MessageSent", "sounds/msgsent.ogg"); if(!value("FileDone").isValid()) setValue("FileDone", "sounds/filedone.ogg"); break; } case eEventContact: { EventContact *ec = static_cast<EventContact*>(e); if(ec->action() != EventContact::eOnline) break; Contact *contact = ec->contact(); bool disable = contact->getUserData()->root()->value("sound/Disable").toBool(); QString alert = contact->getUserData()->root()->value("sound/Alert").toString(); if(alert.isEmpty()) alert = getContacts()->userdata()->value("sound/Alert").toString(); if (!alert.isEmpty() && !disable) EventPlaySound(alert).process(); break; } case eEventMessageSent: { EventMessage *em = static_cast<EventMessage*>(e); Message *msg = em->msg(); QString err = msg->getError(); if (!err.isEmpty()) return false; QString sound; if (msg->type() == MessageFile) sound = value("FileDone").toString(); else if ((msg->getFlags() & MESSAGE_NOHISTORY) == 0) { if ((msg->getFlags() & MESSAGE_MULTIPLY) && ((msg->getFlags() & MESSAGE_LAST) == 0)) return false; sound = value("MessageSent").toString(); } if (!sound.isEmpty()) EventPlaySound(sound).process(); break; } case eEventMessageReceived: { EventMessage *em = static_cast<EventMessage*>(e); Message *msg = em->msg(); if(msg->type() == MessageStatus) return false; Contact *contact = getContacts()->contact(msg->contact()); bool nosound, disable; if(contact) { nosound = contact->getUserData()->root()->value("sound/NoSoundIfActive").toBool(); disable = contact->getUserData()->root()->value("sound/Disable").toBool(); } else { nosound = getContacts()->userdata()->value("sound/NoSoundIfActive").toBool(); disable = getContacts()->userdata()->value("sound/Disable").toBool(); } if(!disable && nosound) { EventActiveContact e; e.process(); if (e.contactID() == contact->id()) disable = true; } if(!disable) { QString sound = messageSound(msg->baseType(), contact->id()); playSound(sound); } break; } case eEventPlaySound: { EventPlaySound *s = static_cast<EventPlaySound*>(e); playSound(s->sound()); return true; } default: break; } return false; }
bool MsgEdit::sendMessage(Message *msg) { if (m_retry.msg){ delete m_retry.msg; m_retry.msg = NULL; } if (m_msg){ delete msg; if (EventMessageCancel(m_msg).process()) m_msg = NULL; stopSend(false); return false; } bool bClose = true; if (CorePlugin::instance()->getContainerMode()){ bClose = false; Command cmd; cmd->id = CmdSendClose; cmd->param = this; EventCommandWidget eWidget(cmd); eWidget.process(); QToolButton *btnClose = qobject_cast<QToolButton*>(eWidget.widget()); if (btnClose) bClose = btnClose->isChecked(); } CorePlugin::instance()->setValue("CloseSend", bClose); Contact *contact = getContacts()->contact(m_userWnd->id()); if (contact){ SIM::PropertyHubPtr data = contact->getUserData("translit"); if (!data.isNull() && data->value("Translit").toBool()) msg->setFlags(msg->getFlags() | MESSAGE_TRANSLIT); } msg->setFlags(msg->getFlags() | m_flags); m_flags = 0; if (m_userWnd->m_list){ if( !m_userWnd->m_list->isHaveSelected() ) return false; multiply = m_userWnd->m_list->selected(); msg->setContact( multiply.first() ); multiply.pop_front(); msg->setClient(NULL); if( multiply.count() > 0 ) msg->setFlags(msg->getFlags() | MESSAGE_MULTIPLY); }else if (!m_resource.isEmpty()){ void *data = NULL; Client *c = client(data, true, false, msg->contact(), true); if (c){ QString resources = c->resources(data); while (!resources.isEmpty()){ QString res = getToken(resources, ';'); getToken(res, ','); if (m_resource == res){ msg->setResource(m_resource); break; } } } } editLostFocus(); Command cmd; cmd->id = CmdSend; cmd->text = I18N_NOOP("Cancel"); cmd->icon = "cancel"; cmd->flags = BTN_PICT; cmd->param = this; EventCommandChange(cmd).process(); m_msg = msg; return send(); }
void *ForwardPlugin::processEvent(Event *e) { if (e->type() == EventMessageReceived){ Message *msg = (Message*)(e->param()); if (msg->type() == MessageStatus) return NULL; QString text = msg->getPlainText(); if (text.isEmpty()) return NULL; if (msg->type() == MessageSMS){ SMSMessage *sms = static_cast<SMSMessage*>(msg); QString phone = sms->getPhone(); bool bMyPhone = false; ForwardUserData *data = (ForwardUserData*)(getContacts()->getUserData(user_data_id)); if (data->Phone.ptr) bMyPhone = ContactList::cmpPhone(phone.utf8(), data->Phone.ptr); if (!bMyPhone){ Group *grp; ContactList::GroupIterator it; while ((grp = ++it) != NULL){ data = (ForwardUserData*)(grp->userData.getUserData(user_data_id, false)); if (data && data->Phone.ptr){ bMyPhone = ContactList::cmpPhone(phone.utf8(), data->Phone.ptr); break; } } } if (!bMyPhone){ Contact *contact; ContactList::ContactIterator it; while ((contact = ++it) != NULL){ data = (ForwardUserData*)(contact->userData.getUserData(user_data_id, false)); if (data && data->Phone.ptr){ bMyPhone = ContactList::cmpPhone(phone.utf8(), data->Phone.ptr); break; } } } if (bMyPhone){ int n = text.find(": "); if (n > 0){ QString name = text.left(n); QString msg_text = text.mid(n + 2); Contact *contact; ContactList::ContactIterator it; while ((contact = ++it) != NULL){ if (contact->getName() == name){ Message *msg = new Message(MessageGeneric); msg->setContact(contact->id()); msg->setText(msg_text); void *data; ClientDataIterator it(contact->clientData); while ((data = ++it) != NULL){ if (it.client()->send(msg, data)) break; } if (data == NULL) delete msg; return e->param(); } } } } } Contact *contact = getContacts()->contact(msg->contact()); if (contact == NULL) return NULL; ForwardUserData *data = (ForwardUserData*)(contact->getUserData(user_data_id)); if ((data == NULL) || (data->Phone.ptr == NULL) || (*data->Phone.ptr == 0)) return NULL; unsigned status = core->getManualStatus(); if ((status == STATUS_AWAY) || (status == STATUS_NA)){ text = contact->getName() + ": " + text; unsigned flags = MESSAGE_NOHISTORY; if (data->Send1st.bValue) flags |= MESSAGE_1ST_PART; if (data->Translit.bValue) flags |= MESSAGE_TRANSLIT; SMSMessage *m = new SMSMessage; m->setPhone(QString::fromUtf8(data->Phone.ptr)); m->setText(text); m->setFlags(flags); unsigned i; for (i = 0; i < getContacts()->nClients(); i++){ Client *client = getContacts()->getClient(i); if (client->send(m, NULL)) break; } if (i >= getContacts()->nClients()) delete m; } } return NULL; }
void *MsgEdit::processEvent(Event *e) { if (e->type() == EventContactChanged){ Command cmd; cmd->id = m_type; cmd->menu_id = MenuMessage; cmd->param = (void*)(m_userWnd->m_id); Event e(EventCheckState, cmd); if (e.process()) return NULL; Event eMenu(EventGetMenuDef, (void*)MenuMessage); CommandsDef *cmdsMsg = (CommandsDef*)(eMenu.process()); CommandsList itc(*cmdsMsg, true); CommandDef *c; while ((c = ++itc) != NULL){ c->param = (void*)(m_userWnd->m_id); Event eCheck(EventCheckState, c); if (eCheck.process()){ Event eCmd(EventCommandExec, c); eCmd.process(); return NULL; } } return NULL; } if (e->type() == EventMessageReceived){ Message *msg = (Message*)(e->param()); if ((msg->contact() == m_userWnd->id()) && (msg->type() != MessageStatus)){ if (CorePlugin::m_plugin->getContainerMode()){ bool bSetFocus = false; if (topLevelWidget() && topLevelWidget()->inherits("Container")){ Container *container = static_cast<Container*>(topLevelWidget()); if (container->wnd() == m_userWnd) bSetFocus = true; } setMessage(msg, bSetFocus); }else{ if (m_edit->isReadOnly()) QTimer::singleShot(0, this, SLOT(setupNext())); } } } if (e->type() == EventRealSendMessage){ MsgSend *s = (MsgSend*)(e->param()); if (s->edit == this){ sendMessage(s->msg); return e->param(); } } if (e->type() == EventCheckState){ CommandDef *cmd = (CommandDef*)(e->param()); if ((cmd->param == this) && (cmd->id == CmdTranslit)){ Contact *contact = getContacts()->contact(m_userWnd->id()); if (contact){ TranslitUserData *data = (TranslitUserData*)(contact->getUserData(CorePlugin::m_plugin->translit_data_id)); if (data){ cmd->flags &= ~COMMAND_CHECKED; if (data->Translit) cmd->flags |= COMMAND_CHECKED; } } return NULL; } if ((cmd->menu_id != MenuTextEdit) || (cmd->param != this)) return NULL; cmd->flags &= ~(COMMAND_CHECKED | COMMAND_DISABLED); switch (cmd->id){ case CmdUndo: if (m_edit->isReadOnly()) return NULL; if (!m_edit->isUndoAvailable()) cmd->flags |= COMMAND_DISABLED; return e->param(); case CmdRedo: if (m_edit->isReadOnly()) return NULL; if (!m_edit->isRedoAvailable()) cmd->flags |= COMMAND_DISABLED; return e->param(); case CmdCut: if (m_edit->isReadOnly()) return NULL; case CmdCopy: if (!m_edit->hasSelectedText()) cmd->flags |= COMMAND_DISABLED; return e->param(); case CmdPaste: if (m_edit->isReadOnly()) return NULL; if (QApplication::clipboard()->text().isEmpty()) cmd->flags |= COMMAND_DISABLED; return e->param(); case CmdClear: if (m_edit->isReadOnly()) return NULL; case CmdSelectAll: if (m_edit->text().isEmpty()) cmd->flags |= COMMAND_DISABLED; return e->param(); } return NULL; } if (e->type() == EventCommandExec){ CommandDef *cmd = (CommandDef*)(e->param()); if ((cmd->id == CmdSmile) && (cmd->param == this)){ Event eBtn(EventCommandWidget, cmd); QToolButton *btnSmile = (QToolButton*)(eBtn.process()); if (btnSmile){ SmilePopup *popup = new SmilePopup(this); QSize s = popup->minimumSizeHint(); popup->resize(s); connect(popup, SIGNAL(insert(int)), this, SLOT(insertSmile(int))); QPoint p = CToolButton::popupPos(btnSmile, popup); popup->move(p); popup->show(); } return e->param(); }
bool MsgEdit::sendMessage(Message *msg) { if (m_retry.msg){ delete m_retry.msg; m_retry.msg = NULL; } if (m_msg){ delete msg; Event e(EventMessageCancel, m_msg); if (e.process()) m_msg = NULL; stopSend(false); return false; } bool bClose = true; if (CorePlugin::m_plugin->getContainerMode()){ bClose = false; Command cmd; cmd->id = CmdSendClose; cmd->param = this; Event e(EventCommandWidget, cmd); QToolButton *btnClose = (QToolButton*)(e.process()); if (btnClose) bClose = btnClose->isOn(); } CorePlugin::m_plugin->setCloseSend(bClose); Contact *contact = getContacts()->contact(m_userWnd->id()); if (contact){ TranslitUserData *data = (TranslitUserData*)(contact->getUserData(CorePlugin::m_plugin->translit_data_id)); if (data && data->Translit.bValue) msg->setFlags(msg->getFlags() | MESSAGE_TRANSLIT); } msg->setFlags(msg->getFlags() | m_flags); m_flags = 0; if (m_userWnd->m_list){ multiply = m_userWnd->m_list->selected; if (multiply.empty()) return false; multiply_it = multiply.begin(); msg->setContact(*multiply_it); msg->setClient(NULL); ++multiply_it; if (multiply_it != multiply.end()) msg->setFlags(msg->getFlags() | MESSAGE_MULTIPLY); }else if (!m_resource.isEmpty()){ void *data = NULL; Client *c = client(data, true, false, msg->contact(), true); if (c){ string resources = c->resources(data); while (!resources.empty()){ string res = getToken(resources, ';'); getToken(res, ','); if (m_resource == QString::fromUtf8(res.c_str())){ msg->setResource(m_resource); break; } } } } editLostFocus(); Command cmd; cmd->id = CmdSend; cmd->text = I18N_NOOP("Cancel"); cmd->icon = "cancel"; cmd->flags = BTN_PICT; cmd->param = this; Event eCmd(EventCommandChange, cmd); eCmd.process(); m_msg = msg; return send(); }
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; }