Пример #1
0
bool WinDockPlugin::processEvent(Event *e)
{
    if (e->type() == eEventCommandExec){
        EventCommandExec *ece = static_cast<EventCommandExec*>(e);
        CommandDef *cmd = ece->cmd();
        if (cmd->id == CmdAutoHide){
            dock->setAutoHide((cmd->flags & COMMAND_CHECKED) != 0);
            bAutoHideVisible = true;
            setBarState();
            enableAutoHide(getAutoHide());
            return true;
        }
    } else
    if (e->type() == eEventCheckCommandState){
        EventCheckCommandState *ecs = static_cast<EventCheckCommandState*>(e);
        CommandDef *cmd = ecs->cmd();
        if ((cmd->id == CmdAutoHide) && (dock->getState() != ABE_FLOAT)){
            cmd->flags &= ~COMMAND_CHECKED;
            if (dock->getAutoHide())
                cmd->flags |= COMMAND_CHECKED;
            return true;
        }
    } else
    if ((e->type() == eEventInit) && !m_bInit)
        init();
    if (e->type() == eEventInTaskManager){
        EventInTaskManager *eitm = static_cast<EventInTaskManager*>(e);
        if ((dock->getState() != ABE_FLOAT) && eitm->showInTaskmanager()){
            EventInTaskManager(false).process();
            return true;
        }
    }
    return false;
}
Пример #2
0
bool MsgUrl::processEvent(Event *e)
{
    if (e->type() == eEventCheckCommandState){
        EventCheckCommandState *ecs = static_cast<EventCheckCommandState*>(e);
        CommandDef *cmd = ecs->cmd();
        if (cmd->param == m_edit){
            unsigned id = cmd->bar_grp;
            if ((id >= MIN_INPUT_BAR_ID) && (id < MAX_INPUT_BAR_ID)){
                cmd->flags |= BTN_HIDE;
                if (cmd->id == CmdUrlInput)
                    cmd->flags &= ~BTN_HIDE;
                return true;
            }
            switch (cmd->id){
            case CmdTranslit:
            case CmdSmile:
            case CmdSend:
            case CmdSendClose:
                e->process(this);
                cmd->flags &= ~BTN_HIDE;
                return true;
            case CmdNextMessage:
            case CmdMsgAnswer:
                e->process(this);
                cmd->flags |= BTN_HIDE;
                return true;
            }
        }
    } else
    if (e->type() == eEventCommandExec){
        EventCommandExec *ece = static_cast<EventCommandExec*>(e);
        CommandDef *cmd = ece->cmd();
        if ((cmd->id == CmdSend) && (cmd->param == m_edit)){
            QString msgText = m_edit->m_edit->toPlainText();
            QString urlText;
            Command cmd;
            cmd->id    = CmdUrlInput;
            cmd->param = m_edit;
            EventCommandWidget eWidget(cmd);
            eWidget.process();
            CToolEdit *edtUrl = qobject_cast<CToolEdit*>(eWidget.widget());
            if (edtUrl)
                urlText = edtUrl->text();
            if (!urlText.isEmpty()){
                UrlMessage *msg = new UrlMessage;
                msg->setContact(m_edit->m_userWnd->id());
                msg->setText(msgText);
                msg->setUrl(urlText);
                msg->setClient(m_client);
                m_edit->sendMessage(msg);
            }
            return true;
        }
    }
    return false;
}
Пример #3
0
bool MsgJournal::processEvent(Event *e)
{
    if (e->type() == eEventCheckCommandState){
        EventCheckCommandState *ecs = static_cast<EventCheckCommandState*>(e);
        CommandDef *cmd = ecs->cmd();
        if (cmd->param == m_edit){
            unsigned id = cmd->bar_grp;
            if ((id >= MIN_INPUT_BAR_ID) && (id < MAX_INPUT_BAR_ID)){
                cmd->flags |= BTN_HIDE;
                if ((cmd->id == CmdDeleteJournalMessage + CmdReceived) && m_ID)
                    cmd->flags &= ~BTN_HIDE;
                return true;
            }
            switch (cmd->id){
            case CmdSend:
            case CmdSendClose:
                e->process(this);
                cmd->flags &= ~BTN_HIDE;
                return true;
            case CmdTranslit:
            case CmdSmile:
            case CmdNextMessage:
            case CmdMsgAnswer:
                e->process(this);
                cmd->flags |= BTN_HIDE;
                return true;
            }
        }
    } else
    if (e->type() == eEventCommandExec){
        EventCommandExec *ece = static_cast<EventCommandExec*>(e);
        CommandDef *cmd = ece->cmd();
        if (cmd->param == m_edit){
            if (cmd->id == CmdSend){
                QString msgText = m_edit->m_edit->text();
                if (!msgText.isEmpty())
                    send(msgText);
                return true;
            }
            if (cmd->id == CmdDeleteJournalMessage + CmdReceived){
                QWidget *w = m_edit->m_bar;
                Command cmd;
                cmd->id		= CmdDeleteJournalMessage + CmdReceived;
                cmd->param	= m_edit;
                EventCommandWidget eWidget(cmd);
                eWidget.process();
                QWidget *btnRemove = eWidget.widget();
                if (btnRemove)
                    w = btnRemove;
                BalloonMsg::ask(NULL, i18n("Remove record from journal?"), w, SLOT(removeRecord(void*)), NULL, NULL, this);
                return true;
            }
            return false;
        }
Пример #4
0
bool MsgContacts::processEvent(Event *e)
{
    if (e->type() == eEventCheckCommandState){
        EventCheckCommandState *ecs = static_cast<EventCheckCommandState*>(e);
        CommandDef *cmd = ecs->cmd();
        if (cmd->param == m_edit){
            unsigned id = cmd->bar_grp;
            if ((id >= MIN_INPUT_BAR_ID) && (id < MAX_INPUT_BAR_ID)){
                cmd->flags |= BTN_HIDE;
                return true;
            }
            switch (cmd->id){
            case CmdSend:
            case CmdSendClose:
                e->process(this);
                cmd->flags &= ~BTN_HIDE;
                return true;
            case CmdTranslit:
            case CmdSmile:
            case CmdNextMessage:
            case CmdMsgAnswer:
                e->process(this);
                cmd->flags |= BTN_HIDE;
                return true;
            }
        }
    } else
    if (e->type() == eEventCommandExec){
        EventCommandExec *ece = static_cast<EventCommandExec*>(e);
        CommandDef *cmd = ece->cmd();
        if ((cmd->id == CmdSend) && (cmd->param == m_edit)){
            QString msgText = m_edit->m_edit->text();
            QString contacts;
            for (list<unsigned>::iterator it = m_list->selected.begin(); it != m_list->selected.end(); ++it){
                Contact *contact = getContacts()->contact(*it);
                if (contact){
                    if (!contacts.isEmpty())
                        contacts += ';';
                    contacts += QString("sim:%1,%2") .arg(*it) .arg(contact->getName());
                }
            }
            if (!contacts.isEmpty()){
                ContactsMessage *msg = new ContactsMessage;
                msg->setContact(m_edit->m_userWnd->id());
                msg->setContacts(contacts);
                msg->setClient(m_client);
                m_edit->sendMessage(msg);
            }
            return true;
        }
    }
    return false;
}
Пример #5
0
bool MsgGen::processEvent(Event *e)
{
    if (e->type() == eEventCheckCommandState){
        EventCheckCommandState *ecs = static_cast<EventCheckCommandState*>(e);
        CommandDef *cmd = ecs->cmd();
        if (cmd->param == m_edit){
            unsigned id = cmd->bar_grp;
            if ((id >= MIN_INPUT_BAR_ID) && (id < MAX_INPUT_BAR_ID)){
                cmd->flags |= BTN_HIDE;
                return true;
            }
            switch (cmd->id){
            case CmdTranslit:
            case CmdSmile:
            case CmdSend:
            case CmdSendClose:
                e->process(this);
                cmd->flags &= ~BTN_HIDE;
                return true;
            case CmdNextMessage:
            case CmdMsgAnswer:
                e->process(this);
                cmd->flags |= BTN_HIDE;
                return true;
            }
        }
    } else
    if (e->type() == eEventCommandExec){
        EventCommandExec *ece = static_cast<EventCommandExec*>(e);
        CommandDef *cmd = ece->cmd();
        if ((cmd->id == CmdSend) && (cmd->param == m_edit)){
            QString msgText = m_edit->m_edit->text();
            if (!msgText.isEmpty()){
                log(L_DEBUG, "Send: %s", msgText.local8Bit().data());
                Message *msg = new Message;
                msg->setText(msgText);
                msg->setContact(m_edit->m_userWnd->id());
                msg->setClient(m_client);
                msg->setFlags(MESSAGE_RICHTEXT);
                msg->setForeground(m_edit->m_edit->foreground().rgb() & 0xFFFFFF);
                msg->setBackground(m_edit->m_edit->background().rgb() & 0xFFFFFF);
                msg->setFont(CorePlugin::m_plugin->getEditFont());
                m_edit->sendMessage(msg);
            }
            return true;
        }
    }
    return false;
}
Пример #6
0
bool MsgAuth::processEvent(Event *e)
{
    if (e->type() == eEventCheckCommandState){
        EventCheckCommandState *ecs = static_cast<EventCheckCommandState*>(e);
        CommandDef *cmd = ecs->cmd();
        if (cmd->param == m_edit){
            unsigned id = cmd->bar_grp;
            if ((id >= MIN_INPUT_BAR_ID) && (id < MAX_INPUT_BAR_ID)){
                cmd->flags |= BTN_HIDE;
                return true;
            }
            switch (cmd->id){
            case CmdTranslit:
            case CmdSmile:
            case CmdSend:
            case CmdSendClose:
                e->process(this);
                cmd->flags &= ~BTN_HIDE;
                return true;
            case CmdNextMessage:
            case CmdMsgAnswer:
                e->process(this);
                cmd->flags |= BTN_HIDE;
                return true;
            }
        }
    } else
    if (e->type() == eEventCommandExec){
        EventCommandExec *ece = static_cast<EventCommandExec*>(e);
        CommandDef *cmd = ece->cmd();
        if ((cmd->id == CmdSend) && (cmd->param == m_edit)){
            QString msgText = m_edit->m_edit->text();
            AuthMessage *msg = new AuthMessage(m_type);
            msg->setText(msgText);
            msg->setContact(m_edit->m_userWnd->id());
            msg->setClient(m_client);
            m_edit->sendMessage(msg);
            return true;
        }
    }
    return false;
}
Пример #7
0
bool DockPlugin::processEvent(Event *e)
{
    switch (e->type()){
    case eEventInit:
        init();
        break;
    case eEventQuit:
        if (m_dock){
            delete m_dock;
            m_dock = NULL;
        }
        break;
    case eEventRaiseWindow: {
        EventRaiseWindow *w = static_cast<EventRaiseWindow*>(e);
        if (w->widget() == getMainWindow()){
            if (m_dock == NULL)
                init();
            if (!getShowMain())
                return (void*)1;
        }
        break;
    }
    case eEventCommandCreate: {
        EventCommandCreate *ecc = static_cast<EventCommandCreate*>(e);
        CommandDef *def = ecc->cmd();
        if (def->menu_id == MenuMain){
            CommandDef d = *def;
            if (def->flags & COMMAND_IMPORTANT){
                if (d.menu_grp == 0)
                    d.menu_grp = 0x1001;
            }else{
                d.menu_grp = 0;
            }
            d.menu_id = DockMenu;
            d.bar_id  = 0;
            EventCommandCreate(&d).process();
        }
        break;
    }
    case eEventCheckCommandState: {
        EventCheckCommandState *ecs = static_cast<EventCheckCommandState*>(e);
        CommandDef *def = ecs->cmd();
        if (def->id == CmdToggle){
            def->flags &= ~COMMAND_CHECKED;
            def->text = isMainShow() ?
                        I18N_NOOP("Hide main window") :
                        I18N_NOOP("Show main window");
            return (void*)1;
        }
        break;
    }
    case eEventCommandExec: {
        EventCommandExec *ece = static_cast<EventCommandExec*>(e);
        CommandDef *def = ece->cmd();
        if (def->id == CmdToggle){
            QWidget *main = getMainWindow();
            if(!main)
                return false;
            if (isMainShow()){
                setShowMain(false);
                main->hide();
            }else{
                m_inactiveTime = 0;
                setShowMain(true);
                raiseWindow(main,getDesktop());
            }
            return (void*)1;
        }
        if (def->id == CmdCustomize){
            EventMenu(DockMenu, EventMenu::eCustomize).process();
            return (void*)1;
        }
        if (def->id == CmdQuit)
            m_bQuit = true;
        break;
    }
    default:
        break;
    }
    return false;
}
Пример #8
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;
    }
Пример #9
0
bool TextEdit::processEvent(Event *e)
{
    if (m_param == NULL)
        return false;
    if (e->type() == eEventCheckCommandState){
        EventCheckCommandState *ecs = static_cast<EventCheckCommandState*>(e);
        CommandDef *cmd = ecs->cmd();
        if (cmd->param != m_param)
            return false;
        switch (cmd->id){
        case CmdBgColor:
        case CmdFgColor:
        case CmdBold:
        case CmdItalic:
        case CmdUnderline:
        case CmdFont:
            if (!isReadOnly()){
                cmd->flags &= ~BTN_HIDE;
            }else{
                cmd->flags |= BTN_HIDE;
            }
            return true;
        default:
            break;
        }
    } else
    if (e->type() == eEventCommandExec){
        EventCommandExec *ece = static_cast<EventCommandExec*>(e);
        CommandDef *cmd = ece->cmd();
        if (cmd->param != m_param)
            return false;
        switch (cmd->id){
        case CmdBgColor:{
                EventCommandWidget eWidget(cmd);
                eWidget.process();
                CToolButton *btnBg = dynamic_cast<CToolButton*>(eWidget.widget());
                if (btnBg){
                    ColorPopup *popup = new ColorPopup(this, background());
                    popup->move(CToolButton::popupPos(btnBg, popup));
                    connect(popup, SIGNAL(colorChanged(QColor)), this, SLOT(bgColorChanged(QColor)));
                    popup->show();
                }
                return true;
            }
        case CmdFgColor:{
                EventCommandWidget eWidget(cmd);
                eWidget.process();
                CToolButton *btnFg = dynamic_cast<CToolButton*>(eWidget.widget());
                if (btnFg){
                    ColorPopup *popup = new ColorPopup(this, foreground());
                    popup->move(CToolButton::popupPos(btnFg, popup));
                    connect(popup, SIGNAL(colorChanged(QColor)), this, SLOT(fgColorChanged(QColor)));
                    popup->show();
                }
                return true;
            }
        case CmdBold:
            if (!m_bChanged){
                m_bSelected = true;
                setFontWeight((cmd->flags & COMMAND_CHECKED) != 0 ? QFont::Bold : QFont::Normal);
            }
            return true;
        case CmdItalic:
            if (!m_bChanged){
                m_bSelected = true;
                setFontItalic((cmd->flags & COMMAND_CHECKED) != 0);
            }
            return true;
        case CmdUnderline:
            if (!m_bChanged){
                m_bSelected = true;
                setFontUnderline((cmd->flags & COMMAND_CHECKED) != 0);
            }
            return true;
        case CmdFont:{
#ifdef USE_KDE
                QFont f = font();
                if (KFontDialog::getFont(f, false, topLevelWidget()) != KFontDialog::Accepted)
                    break;
#else
                bool ok = false;
                QFont f = QFontDialog::getFont(&ok, font(), topLevelWidget());
                if (!ok)
                    break;
#endif
                m_bSelected = true;
                setCurrentFont(f);
                break;
            }
        default:
            return false;
        }
    }
    return false;
}
Пример #10
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;
    }
Пример #11
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;
    }
Пример #12
0
bool MsgFile::processEvent(Event *e)
{
    if (e->type() == eEventCheckCommandState){
        EventCheckCommandState *ecs = static_cast<EventCheckCommandState*>(e);
        CommandDef *cmd = ecs->cmd();
        if (cmd->param == m_edit){
            unsigned id = cmd->bar_grp;
            if ((id >= MIN_INPUT_BAR_ID) && (id < MAX_INPUT_BAR_ID)){
                cmd->flags |= BTN_HIDE;
                if (cmd->id == CmdFileName)
                    cmd->flags &= ~BTN_HIDE;
                return true;
            }
            switch (cmd->id){
            case CmdTranslit:
            case CmdSmile:
            case CmdSend:
            case CmdSendClose:
                e->process(this);
                cmd->flags &= ~BTN_HIDE;
                return true;
            case CmdNextMessage:
            case CmdMsgAnswer:
                e->process(this);
                cmd->flags |= BTN_HIDE;
                return true;
            }
        }
    } else
    if (e->type() == eEventCommandExec){
        EventCommandExec *ece = static_cast<EventCommandExec*>(e);
        CommandDef *cmd = ece->cmd();
        if (cmd->param == m_edit){
            if (cmd->id == CmdSend){
                Command cmd;
                cmd->id		= CmdFileName;
                cmd->param	= m_edit;
                EventCommandWidget eWidget(cmd);
                eWidget.process();
                CToolEdit *edtName = qobject_cast<CToolEdit*>(eWidget.widget());
                if (edtName == NULL)
                    return false;
                QString msgText = m_edit->m_edit->toPlainText();
                QString file = edtName->text();
                QStringList files;
                QString f;
                for (int i = 0; i < (int)file.length(); i++){
                    if (file[i] == '\"'){
                        f = f.trimmed();
                        if (!f.isEmpty())
                            files.append(f);
                        f = QString::null;
                        for (i++; i < (int)file.length(); i++){
                            if (file[i] == '\"')
                                break;
                            f += file[i];
                        }
                        f = f.trimmed();
                        if (!f.isEmpty())
                            files.append(f);
                        f = QString::null;
                        continue;
                    }
                    f += file[i];
                }
                f = f.trimmed();
                if (!f.isEmpty())
                    files.append(f);
                file = QString::null;
                for (QStringList::Iterator it = files.begin(); it != files.end(); ++it){
                    if (!file.isEmpty())
                        file += ';';
                    file += quoteChars(*it, ";");
                }
                if (!file.isEmpty()){
                    FileMessage *msg = new FileMessage;
                    msg->setText(msgText);
                    msg->setFile(file);
                    msg->setContact(m_edit->m_userWnd->id());
                    msg->setClient(m_client);
                    m_edit->sendMessage(msg);
                }
                return true;
            }
            if (cmd->id == CmdFileName){
                selectFile();
                return true;
            }
        }
    }
    return false;
}
Пример #13
0
bool HistoryWindow::processEvent(Event *e)
{
    switch(e->type()) {
case eEventContact: 
    {
        EventContact *ec = static_cast<EventContact*>(e);
        Contact *contact = ec->contact();
        if (contact->id() != m_id)
            break;
        switch(ec->action()) 
        {
        case EventContact::eDeleted:
            QTimer::singleShot(0, this, SLOT(close()));
            break;
        case EventContact::eChanged:
            setName();
            break;
        default:
            break;
        }
        break;
    }
case eEventCheckCommandState: 
    {
        EventCheckCommandState *ecs = static_cast<EventCheckCommandState*>(e);
        CommandDef *cmd = ecs->cmd();
        if (cmd->id == CmdHistoryDirection && (unsigned long)(cmd->param) == m_id)
        {
            cmd->flags &= ~COMMAND_CHECKED;
            if (m_bDirection)
                cmd->flags |= COMMAND_CHECKED;
            return true;
        }
        if (cmd->id != CmdDeleteMessage && cmd->id != CmdCutHistory || cmd->param != m_view || !m_view->currentMessage())
            return false;

        cmd->flags &= ~COMMAND_CHECKED;
        return true;
    }
case eEventCommandExec: 
    {
        EventCommandExec *ece = static_cast<EventCommandExec*>(e);
        CommandDef *cmd = ece->cmd();
        if ((unsigned long)(cmd->param) != m_id)
            return false;
        if (cmd->id == CmdHistoryDirection)
        {
            bool bDirection = ((cmd->flags & COMMAND_CHECKED) != 0);
            CorePlugin::instance()->setValue("HistoryDirection", bDirection);
            if (bDirection != m_bDirection)
            {
                m_bDirection = bDirection;
                m_page = 0;
                m_states.clear();
                fill();
            }
            return true;
        }
        if (cmd->id == CmdHistoryNext)
        {
            if (m_page + 1 < m_states.size())
            {
                m_page++;
                fill();
            }
            return true;
        }
        if (cmd->id == CmdHistoryPrev)
        {
            if (m_page > 0)
            {
                m_page--;
                fill();
            }
            return true;
        }
        if (cmd->id == CmdHistorySave)
        {
            QString str = QFileDialog::getSaveFileName(this, QString::null, QString::null, i18n("Textfile (*.txt)"));
            if(!str.isEmpty())
            {
                bool res = true;
                if (QFile::exists(str))
                {
                    QMessageBox mb(i18n("Error"), i18n("File already exists. Overwrite?"), 
                        QMessageBox::Warning,
                        QMessageBox::Yes | QMessageBox::Default,
                        QMessageBox::No,
                        QMessageBox::Cancel | QMessageBox::Escape);
                    mb.setButtonText(QMessageBox::Yes, i18n("&Overwrite"));
                    mb.setButtonText(QMessageBox::No, i18n("&Append"));
                    switch (mb.exec())
                    {
                    case QMessageBox::Yes:
                        res = History::save(m_id, str, false);
                        break;
                    case QMessageBox::No:
                        res = History::save(m_id, str, true);
                        break;
                    case QMessageBox::Cancel:
                        break;
                    }
                }else
                    res = History::save(m_id, str);
                if (!res)
                    QMessageBox::critical(this, i18n("Error"), i18n("Save failed"), QMessageBox::Ok, Qt::NoButton, Qt::NoButton);
            }
            return true;
        }
        if (cmd->id == CmdHistoryFind)
        {
            m_filter.clear();
            if (cmd->flags & COMMAND_CHECKED)
            {
                Command cmd;
                cmd->id		= CmdHistoryFind;
                cmd->param	= (void*)m_id;
                EventCommandWidget eWidget(cmd);
                eWidget.process();
                CToolCombo *cmbFind = qobject_cast<CToolCombo*>(eWidget.widget());
                QString text = cmbFind->lineEdit()->text();
                if (cmbFind && !text.isEmpty())
                {
                    addHistory(text);
                    m_filter = text;
                }
            }
            m_page = 0;
            m_states.clear();
            m_view->setSelect(m_filter);
            fill();
            return true;
        }
        break;
    }
    default:
        break;
    }
    return false;
}
Пример #14
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;
}
Пример #15
0
bool DockPlugin::processEvent(Event *e)
{
    switch (e->type())
    {
    case eEventInit:
        init();
        break;
    case eEventQuit:
        if (m_dock){
            delete m_dock;
            m_dock = NULL;
        }
        break;
    case eEventRaiseWindow: 
    {
        EventRaiseWindow *w = static_cast<EventRaiseWindow*>(e);
        if (w->widget() == getMainWindow()){
            if (!m_dock)
                init();
            if (!value("ShowMain").toBool())
                return true;
        }
        break;
    }
    case eEventCommandCreate: 
    {
        EventCommandCreate *ecc = static_cast<EventCommandCreate*>(e);
        CommandDef *def = ecc->cmd();
        if (def->menu_id == MenuMain)
        {
            CommandDef d = *def;
            if (def->flags & COMMAND_IMPORTANT)
            {
                if (d.menu_grp == 0)
                    d.menu_grp = 0x1001;
            }
            else
                d.menu_grp = 0;
            d.menu_id = DockMenu;
            d.bar_id  = 0;
            EventCommandCreate(&d).process();
        }
        break;
    }
    case eEventCheckCommandState: 
    {
        EventCheckCommandState *ecs = static_cast<EventCheckCommandState*>(e);
        CommandDef *def = ecs->cmd();
        if (def->id == CmdToggle)
        {
            def->flags &= ~COMMAND_CHECKED;
            def->text = isMainShow() ?
                        I18N_NOOP("Hide main window") :
                        I18N_NOOP("Show main window");
            return true;
        }
        break;
    }
    case eEventCommandExec: 
    {
        EventCommandExec *ece = static_cast<EventCommandExec*>(e);
        CommandDef *def = ece->cmd();
        if (def->id == CmdToggle)
        {
            QWidget *main = getMainWindow();
            if(!main)
                return false;
            if (isMainShow())
            {
                setValue("ShowMain", false);
                main->hide();
            }
            else
            {
                m_inactiveTime = QDateTime();
                setValue("ShowMain", true);
                raiseWindow(main, value("Desktop").toUInt());
            }
            return true;
        }
        if (def->id == CmdCustomize){
            EventMenu(DockMenu, EventMenu::eCustomize).process();
            return true;
        }
        if (def->id == CmdQuit)
            m_bQuit = true;
        break;
    }
    case eEventPluginLoadConfig:
    {
        PropertyHubPtr hub = ProfileManager::instance()->getPropertyHub("dock");
        if(!hub.isNull())
            setPropertyHub(hub);
        break;
    }
    default:
        break;
    }
    return false;
}