Example #1
0
bool AIMInfo::processEvent(Event *e)
{
    if (e->type() == eEventContact){
        EventContact *ec = static_cast<EventContact*>(e);
        if(ec->action() != EventContact::eChanged)
            return false;
        Contact *contact = ec->contact();
        if (contact->have(m_data))
            fill();
    } else
    if ((e->type() == eEventMessageReceived) && m_data){
        EventMessage *em = static_cast<EventMessage*>(e);
        Message *msg = em->msg();
        if (msg->type() == MessageStatus){
            if (m_client->dataName(m_data) == msg->client())
                fill();
        }
    } else
    if ((e->type() == eEventClientChanged) && (m_data == 0)){
        EventClientChanged *ecc = static_cast<EventClientChanged*>(e);
        if (ecc->client() == m_client)
            fill();
    }
    return false;
}
Example #2
0
void IOHandler::HandleIOMessageFailure(const EventMessage& message) {
  ProtocolMessage* protocol_message = message.GetProtocolMessage();
  if (protocol_message->direction == ProtocolMessage::kOutgoingRequest) {
    protocol_message->status = ProtocolMessage::kInternalFailure;
    if (!GetIOService()->GetServiceStage()->Send(protocol_message)) {
      MI_LOG_WARN(logger, "IOHandler::HandleIOMessageFailure send fail");
    }
  } else {
    message.Destroy();
  }
}
Example #3
0
    size_t Client::ClientsRegistered(std::string eventType)
    {
        EventMessage msg;
        msg.setEventType(REGISTERED_MSG);
        msg.pushParam(eventType);

        this->Send(msg, PRIORITY_COMMAND);
        this->WaitForEvent(msg, REGISTERED_RESP);

        return (size_t)msg.getParamInt(0);
    }
Example #4
0
    bool Client::IsClientConnected(std::string target)
    {
        EventMessage msg;
        msg.setEventType(ISCONNECTED_MSG);
        msg.pushParam(target);

        this->Send(msg, PRIORITY_COMMAND);
        this->WaitForEvent(msg, ISCONNECTED_RESP);

        return ( msg.getParamInt(0) != 0 );
    }
Example #5
0
bool DeclineDlg::processEvent(Event *e)
{
    if (e->type() == eEventMessageDeleted)
    {
        EventMessage *em = static_cast<EventMessage*>(e);
        Message *msg = em->msg();
        if (msg->id() == m_msg->id())
            close();
    }
    return false;
}
Example #6
0
Serializable*
EventMessage::deserialize(SerializedInstance* data) {
    unsigned int source = data->getUnsigned();
    unsigned int dest = data->getUnsigned();
    unsigned int incNum = data->getUnsigned();
    Event* event = dynamic_cast<Event*>(data->getSerializable());
    const string gvtInfo = data->getString();

    EventMessage* retval = new EventMessage(source, dest, event, gvtInfo);
    retval->setIncarnationNumber(incNum);
    return retval;
}
Example #7
0
void IOHandler::HandleIOMessageEvent(const EventMessage& message) {
  MI_LOG_TRACE(logger, "HandleIOMessageEvent");
  IODescriptor* descriptor = 
      IODescriptorFactory::GetIODescriptor(message.descriptor_id);
  if (!descriptor) {
    MI_LOG_DEBUG(logger, "HandleIOCloseEvent descriptor not found:"
        << message.descriptor_id);
    HandleIOMessageFailure(message);
    return;
  }

  Channel* channel = dynamic_cast<Channel*>(descriptor);
  if (!channel) {
    MI_LOG_ERROR(logger, "IOHandler::HandleIOMessageEvent descriptor is not channel");
    HandleIOMessageFailure(message);
    return;
  }

  ProtocolMessage* protocol_message = message.GetProtocolMessage();
  if (0 != channel->EncodeMessage(protocol_message)) {
    HandleIOMessageFailure(message);
    return;    
  }

  descriptor->OnWrite();
}
Example #8
0
    bool Client::Peek(EventMessage &msg)
    {
        message_queue* const mq = (message_queue*)this->privateQueue;

        // check local deque for message
        if(!this->storedMessages.empty())
        {
            // get first queued element and pop it
            msg = this->storedMessages.front();
            this->storedMessages.pop_front();
            return true;
        }

        std::stringbuf msgBuffer;

        char buff[MAX_MSG_SIZE];
        size_t recvd;
        unsigned int priority;

        if(mq->try_receive(buff, MAX_MSG_SIZE, recvd, priority))
        {
            msgBuffer.sputn(buff, recvd);
            msg.deserialize(msgBuffer);

            return HandleMessage(msg, priority);
        }
        else
            return false;
        return true;
    }
Example #9
0
bool WarnDlg::processEvent(Event *e)
{
    if (e->type() == eEventMessageSent) {
        EventMessage *em = static_cast<EventMessage*>(e);
        Message *msg = em->msg();
        if (msg == m_msg) {
            m_msg = false;
            QString err = msg->getError();
            if (!err.isEmpty()) {
                showError(err);
            } else {
                QTimer::singleShot(0, this, SLOT(close()));
            }
        }
    }
    return false;
}
Example #10
0
static void registerEventCallback(char *name, char *buf, int bufSize, void *arg, bool isSynch, int retSize, char *retData, int type)
{
printf("REGISTER EVENT CALLBACK %s %s\n", name, buf);

	EventMessage *evMessage = new EventMessage(buf);
	int msgLen;
	char *msg = evMessage->serialize(msgLen, msgManager); 
	for(int i = 0; i < numExtAddresses; i++)
	{
		try {
			msgManager->sendMessage(extAddresses[i], msg, msgLen);
		}catch(SystemException *exc)
		{
			printf("Error Sending registration message: %s\n", exc->what());
		}
	}
	((UDPNetworkManager*)udpMsgManager)->join(getMulticastAddr(evMessage->name));
	delete [] msg;
	delete evMessage;
}
Example #11
0
 bool Client::HandleMessage(EventMessage &msg, size_t priority)
 {
     if( // dataPacket
        0 == msg.getEventType().compare(PACKET_MSG) )
     {
         if(HandlePacket(msg, *this->packetData))
             return this->HandleMessage(msg, priority); // handle recieved data
         else
             return this->Peek(msg); // packet discarded, continue peek
     }
     else
         return true;
 }
Example #12
0
    void Client::SendTo(const std::string target, EventMessage &msg)
    {
        msg.setSender(this->name);
        std::stringbuf msgBuffer;
        msg.serialize(msgBuffer);

        EventMessage targetPacket;
        targetPacket.setEventType(DIRECTSEND_MSG);
        targetPacket.pushParam(target);
        targetPacket.pushParam(msgBuffer.str());
        targetPacket.setSender(this->name);

        this->Send(targetPacket, PRIORITY_COMMAND);
    }
Example #13
0
bool Container::processEvent(Event *e)
{
    if (m_tabBar == NULL)
        return false;
    switch (e->type()){
    case eEventMessageReceived: {
        EventMessage *em = static_cast<EventMessage*>(e);
        Message *msg = em->msg();
        if (msg->type() == MessageStatus){
            Contact *contact = getContacts()->contact(msg->contact());
            if (contact)
                contactChanged(contact);
            return false;
        }
        if (msg->getFlags() & MESSAGE_NOVIEW)
            return false;
        if (CorePlugin::m_plugin->getContainerMode()){
            if (isActiveWindow() && !isMinimized()){
                UserWnd *userWnd = m_tabBar->currentWnd();
                if (userWnd && (userWnd->id() == msg->contact()))
                    userWnd->markAsRead();
            }else{
                UserWnd *userWnd = wnd(msg->contact());
                if (userWnd)
                    QTimer::singleShot(0, this, SLOT(flash()));
            }
        }
        // no break here - otherwise we have to duplicate the code below...
    }
    case eEventMessageRead: {
        EventMessage *em = static_cast<EventMessage*>(e);
        Message *msg = em->msg();
        UserWnd *userWnd = wnd(msg->contact());
        if (userWnd){
            bool bBold = false;
            for (list<msg_id>::iterator it = CorePlugin::m_plugin->unread.begin(); it != CorePlugin::m_plugin->unread.end(); ++it){
                if ((*it).contact != msg->contact())
                    continue;
                bBold = true;
                break;
            }
            m_tabBar->setBold(msg->contact(), bBold);
        }
        break;
    }
    case eEventActiveContact: {
        EventActiveContact *eac = static_cast<EventActiveContact*>(e);
        if (!isActiveWindow())
            return false;
        UserWnd *userWnd = m_tabBar->currentWnd();
        if (userWnd) {
            eac->setContactID(userWnd->id());
            return true;
        }
        break;
    }
    case eEventContact: {
        EventContact *ec = static_cast<EventContact*>(e);
        Contact *contact = ec->contact();
        UserWnd *userWnd = wnd(contact->id());
        if(!userWnd)
            break;
        switch(ec->action()) {
            case EventContact::eDeleted: {
                removeUserWnd(userWnd);
                break;
            }
            case EventContact::eChanged: {
                if (contact->getIgnore()){
                    removeUserWnd(userWnd);
                    break;
                }
                m_tabBar->changeTab(contact->id());
                contactChanged(contact);
                break;
            }
            case EventContact::eStatus: {
                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 (userWnd->m_bTyping != bTyping){
                    userWnd->m_bTyping = bTyping;
                    if (bTyping){
                        userWnd->setStatus(g_i18n("%1 is typing", contact) .arg(contact->getName()));
                    }else{
                        userWnd->setStatus("");
                    }
                    userWnd = m_tabBar->currentWnd();
                    if (userWnd && (contact->id() == userWnd->id()))
                        m_status->message(userWnd->status());
                }
            }
            default:
                break;
        }
        break;
    }
    case eEventClientsChanged:
        setupAccel();
        break;
    case eEventContactClient: {
        EventContactClient *ecc = static_cast<EventContactClient*>(e);
        contactChanged(ecc->contact());
        break;
    }
    case eEventInit:
        init();
        break;
    case eEventCommandExec: {
        EventCommandExec *ece = static_cast<EventCommandExec*>(e);
        CommandDef *cmd = ece->cmd();
        UserWnd *userWnd = m_tabBar->currentWnd();
        if (userWnd && ((unsigned long)(cmd->param) == userWnd->id())){
            if (cmd->menu_id == MenuContainerContact){
                m_tabBar->raiseTab(cmd->id);
                return true;
            }
            if (cmd->id == CmdClose){
                delete userWnd;
                return true;
            }
            if (cmd->id == CmdInfo && cmd->menu_id != MenuContact){
                CommandDef c = *cmd;
                c.menu_id = MenuContact;
                c.param   = (void*)userWnd->id();
                EventCommandExec(&c).process();
                return true;
            }
        }
        break;
    }
    case eEventCheckCommandState: {
        EventCheckCommandState *ecs = static_cast<EventCheckCommandState*>(e);
        CommandDef *cmd = ecs->cmd();
        UserWnd *userWnd = m_tabBar->currentWnd();
        if (userWnd && ((unsigned long)(cmd->param) == userWnd->id()) &&
                (cmd->menu_id == MenuContainerContact) &&
                (cmd->id == CmdContainerContacts)){
            list<UserWnd*> userWnds = m_tabBar->windows();
            CommandDef *cmds = new CommandDef[userWnds.size() + 1];
            unsigned n = 0;
            for (list<UserWnd*>::iterator it = userWnds.begin(); it != userWnds.end(); ++it){
                cmds[n].id = (*it)->id();
                cmds[n].flags = COMMAND_DEFAULT;
                cmds[n].text_wrk = (*it)->getName();
                cmds[n].icon  = (*it)->getIcon();
                cmds[n].text  = "_";
                cmds[n].menu_id = n + 1;
                if (n < sizeof(accels) / sizeof(const char*))
                    cmds[n].accel = accels[n];
                if (*it == m_tabBar->currentWnd())
                    cmds[n].flags |= COMMAND_CHECKED;
                n++;
            }
            cmd->param = cmds;
            cmd->flags |= COMMAND_RECURSIVE;
            return true;
        }
        break;
    }
    default:
        break;
    }
    return false;
}
Example #14
0
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;
}
Example #15
0
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;
}
Example #16
0
    bool Client::WaitForEvent(EventMessage &msg, std::string eventType, unsigned int timeout)
    {
        namespace pt = boost::posix_time;

        message_queue* const mq = (message_queue*)this->privateQueue;

        // initialize timer
        pt::ptime timeoutInstant;
        if(timeout != 0)
        {
            timeoutInstant = pt::microsec_clock::universal_time() + pt::millisec(timeout);
        }

        // check local deque for message
        if(!this->storedMessages.empty())
        {
            for (unsigned int i=0; i<this->storedMessages.size(); i++)
            {
                EventMessage & dequeMsg = this->storedMessages[i];
                if( 0 ==dequeMsg.getEventType().compare(eventType) )
                {
                    // copy message to the output
                    msg = dequeMsg;
                    // erase message from deque
                    this->storedMessages.erase(this->storedMessages.begin()+i);
                    return true;
                }
            }
        }

        char buff[MAX_MSG_SIZE];
        size_t recvd;
        unsigned int priority;
        std::stringbuf msgBuffer;

        bool gotRequest = false;
        while(!gotRequest)
        {
            // try to get message
            if(timeout == 0)
                mq->receive(buff, MAX_MSG_SIZE, recvd, priority);
            else
            {

                if(!mq->timed_receive(buff, MAX_MSG_SIZE, recvd, priority, timeoutInstant))
                {
                    // timeout reached
                    return false;
                }
            }

            // transform buffer into message
            msgBuffer.sputn(buff, recvd);
            msg.deserialize(msgBuffer);

            // check if recieved message has correct type
            if( 0 == msg.getEventType().compare(eventType) )
            {
                gotRequest = true;
            }
            else
            {
                // store recieved message into local deque
                this->storedMessages.push_back(msg);
            }

        }
        return true;
    }
Example #17
0
 void Client::Send(EventMessage &msg, unsigned int priority)
 {
     msg.setSender(this->name);
     MetaSendMessage(this->publicQueue, msg, priority, this->emptyPacketSize);
 }
Example #18
0
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;
    }
Example #19
0
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;
}
Example #20
0
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;
    }
Example #21
0
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;
}
Example #22
0
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;
    }