Ejemplo n.º 1
0
void FloatyWnd::dragEvent(QDropEvent *e, bool isDrop)
{
    Message *msg = NULL;
    CommandDef *cmd;
    CommandsMapIterator it(m_plugin->core->messageTypes);
    while ((cmd = ++it) != NULL){
        MessageDef *def = (MessageDef*)(cmd->param);
        if (def && def->drag){
            msg = def->drag(e);
            if (msg){
                unsigned type = cmd->id;
                if (def->base_type){
                    type = def->base_type;
                    for (;;){
                        const CommandDef *c = m_plugin->core->messageTypes.find(type);
                        if (c == NULL)
                            break;
                        MessageDef *def = (MessageDef*)(cmd->param);
                        if (def->base_type == 0)
                            break;
                        type = def->base_type;
                    }
                }
                Command cmd;
                cmd->id      = type;
                cmd->menu_id = MenuMessage;
                cmd->param	 = (void*)m_id;
                Event e(EventCheckState, cmd);
                if (e.process())
                    break;
            }
        }
    }
    if (msg){
        e->accept();
        if (isDrop){
            msg->setContact(m_id);
            Event e(EventOpenMessage, msg);
            e.process();
        }
        delete msg;
        return;
    }
    if (QTextDrag::canDecode(e)){
        QString str;
        if (QTextDrag::decode(e, str)){
            e->accept();
            if (isDrop){
                Message *msg = new Message(MessageGeneric);
                msg->setText(str);
                msg->setContact(m_id);
                Event e(EventOpenMessage, msg);
                e.process();
                delete msg;
            }
            return;
        }
    }
}
Ejemplo n.º 2
0
bool MsgEdit::setType(unsigned type)
{
    CommandDef *def;
    def = CorePlugin::m_plugin->messageTypes.find(type);
    if (def == NULL)
        return false;
    MessageDef *mdef = (MessageDef*)(def->param);
    if (mdef->flags & MESSAGE_SILENT)
        return false;
    if (mdef->create == NULL)
        return false;
    Message *msg = mdef->create(NULL);
    if (msg == NULL)
        return false;
    m_userWnd->setMessage(&msg);
    delete msg;
    return true;
}
Ejemplo n.º 3
0
UserWnd::UserWnd(unsigned id, const char *cfg, bool bReceived)
        : QSplitter(Horizontal, NULL)
{
    load_data(userWndData, &data, cfg);
    m_id = id;
    m_bResize = false;
    m_bClosed = false;
    m_bTyping = false;
    setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
    m_hSplitter = new QSplitter(Horizontal, this);
    m_splitter = new QSplitter(Vertical, m_hSplitter);
    m_list = NULL;
    m_view = NULL;

    if (cfg == NULL)
        memcpy(data.editBar, CorePlugin::m_plugin->data.editBar, sizeof(data.editBar));

    m_bBarChanged = true;
    if (CorePlugin::m_plugin->getContainerMode())
        bReceived = false;
    m_edit = new MsgEdit(m_splitter, this, bReceived);
    restoreToolbar(m_edit->m_bar, data.editBar);
    m_edit->m_bar->show();
    m_bBarChanged = false;

    connect(m_edit, SIGNAL(toolBarPositionChanged(QToolBar*)), this, SLOT(toolbarChanged(QToolBar*)));
    connect(CorePlugin::m_plugin, SIGNAL(modeChanged()), this, SLOT(modeChanged()));
    connect(m_edit, SIGNAL(heightChanged(int)), this, SLOT(editHeightChanged(int)));
    modeChanged();

    if (data.MessageType == 0)
        return;
    CommandDef *cmd = CorePlugin::m_plugin->messageTypes.find(data.MessageType);
    if (cmd == NULL)
        return;
    MessageDef *def = (MessageDef*)(cmd->param);
    Message *msg = def->create(NULL);
    setMessage(msg);
    delete msg;
}
Ejemplo n.º 4
0
Message *MsgTextEdit::createMessage(QMimeSource *src)
{
    Message *msg = NULL;
    CommandDef *cmd;
    CommandsMapIterator it(CorePlugin::instance()->messageTypes);
    while ((cmd = ++it) != NULL){
        MessageDef *def = (MessageDef*)(cmd->param);
        if (def && def->drag){
            msg = def->drag(src);
            if (msg){
                Command c;
                c->id      = cmd->id;
                c->menu_id = MenuMessage;
                c->param	 = (void*)(m_edit->m_userWnd->id());
                if (EventCheckCommandState(c).process())
                    break;
                delete msg;
                msg = NULL;
            }
        }
    }
    return msg;
}
Ejemplo n.º 5
0
Message *MsgTextEdit::createMessage(QMimeSource *src)
{
    Message *msg = NULL;
    CommandDef *cmd;
    CommandsMapIterator it(CorePlugin::m_plugin->messageTypes);
    while ((cmd = ++it) != NULL){
        MessageDef *def = (MessageDef*)(cmd->param);
        if (def && def->drag){
            msg = def->drag(src);
            if (msg){
                unsigned type = cmd->id;
                if (def->base_type){
                    type = def->base_type;
                    for (;;){
                        const CommandDef *c = CorePlugin::m_plugin->messageTypes.find(type);
                        if (c == NULL)
                            break;
                        MessageDef *def = (MessageDef*)(cmd->param);
                        if (def->base_type == 0)
                            break;
                        type = def->base_type;
                    }
                }
                Command cmd;
                cmd->id      = type;
                cmd->menu_id = MenuMessage;
                cmd->param	 = (void*)(m_edit->m_userWnd->id());
                Event e(EventCheckState, cmd);
                if (e.process())
                    break;
                delete msg;
            }
        }
    }
    return msg;
}
Ejemplo n.º 6
0
MessageDef* xTEDSCommand::RegInfo(const char* ItemName) const
{
	char DefinitionsBuf[MSG_DEF_SIZE] = "";
	char xTEDSPortionBuf[MSG_DEF_SIZE] = "";
	char VarPortionBuf[MSG_DEF_SIZE] = "";

	if (m_CommandMessage == NULL) return NULL;
	
	MessageDef* pCmdMsgDef = m_CommandMessage->RegInfo();
	if (NULL == pCmdMsgDef)
	  return NULL;

	VariableDef* pCmdVarDef = m_CommandMessage->GetVariableXtedsDefinitions();

	if(m_FaultMessage!=NULL)	// If there exists a fault message
	{
		MessageDef* pFltMsgDef = m_FaultMessage->RegInfo();
		if (NULL == pFltMsgDef)
		  {
		    free (pCmdMsgDef);
		    free (pCmdVarDef);
		    return NULL;
		  }
		VariableDef* pFltVarDef = m_FaultMessage->GetVariableXtedsDefinitions();
		
		snprintf(DefinitionsBuf,sizeof(DefinitionsBuf),"<Command>\n\t%s\n\t%s\n</Command>",
			 pCmdMsgDef->GetDefinitions(),
			 pFltMsgDef->GetDefinitions());
		
		// Get the full variable xTEDS definitions, into VarPortionBuf
		VariableDef::ToStringConcatVariableDefsIgnoreDuplicates ( VarPortionBuf,
				   sizeof(VarPortionBuf), pCmdVarDef, pFltVarDef );

		snprintf(xTEDSPortionBuf,sizeof(xTEDSPortionBuf),"%s\n<Command>\n\t%s\n\t%s\n</Command>",
			 VarPortionBuf, pCmdMsgDef->GetxTEDSPortion(), pFltMsgDef->GetxTEDSPortion());
		
		delete pFltMsgDef;
		pFltMsgDef = NULL;

		delete pFltVarDef;
		pFltVarDef = NULL;
	}
	else				// If this is only a command message
	{
		snprintf(DefinitionsBuf,sizeof(DefinitionsBuf),"<Command>\n\t%s\n</Command>",
			 pCmdMsgDef->GetDefinitions());

		VariableDef::ToStringConcatVariableDefs(VarPortionBuf, sizeof(VarPortionBuf),
							pCmdVarDef, NULL);

		snprintf(xTEDSPortionBuf,sizeof(xTEDSPortionBuf),"%s\n<Command>\n\t%s\n</Command>",
			 VarPortionBuf, pCmdMsgDef->GetxTEDSPortion());
	}
	
	MessageDef* ReturnDef = new MessageDef();
	
	//
	// Set the message id to the id of the requested item
	ReturnDef->SetInterfaceMessageID(pCmdMsgDef->GetInterfaceMessageID());
	if (ItemName != NULL)
	{
		if (m_FaultMessage != NULL && m_FaultMessage->NameEquals(ItemName))
			ReturnDef->SetInterfaceMessageID(m_FaultMessage->GetID());
	}
	
	delete(pCmdMsgDef);
	if (NULL != pCmdVarDef)
	  delete pCmdVarDef;

	ReturnDef->SetDefinitions(DefinitionsBuf);
	ReturnDef->SetxTEDSPortion(xTEDSPortionBuf);
	return ReturnDef;
}
Ejemplo n.º 7
0
void *MsgEdit::processEvent(Event *e)
{
    if ((e->type() == EventContactChanged) && !m_bReceived){
        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())
                continue;
            CommandDef *def;
            def = CorePlugin::m_plugin->messageTypes.find(c->id);
            if (def == NULL)
                continue;
            MessageDef *mdef = (MessageDef*)(def->param);
            if (mdef->flags & MESSAGE_SILENT)
                continue;
            if (mdef->create == NULL)
                continue;
            Message *msg = mdef->create(NULL);
            if (msg == NULL)
                continue;
            setMessage(msg, false);
            delete msg;
            break;
        }
        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)
                        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();
        }