예제 #1
0
void MsgEdit::messageReceived(ICQMessage *m)
{
    if (m->getUin() != Uin()) return;
    setupNext();
    if (msg && msg->Received && (static_cast<UserBox*>(topLevelWidget())->currentUser() == Uin)) return;
    if (canSend()) return;
    ICQMessage *msg_copy = history()->getMessage(m->Id);
    setMessage(msg_copy, false, true);
    if (qApp->activeWindow() != topLevelWidget()) return;
    if (static_cast<UserBox*>(topLevelWidget())->currentUser() != Uin) return;
    pClient->markAsRead(m);
    setupNext();
}
예제 #2
0
void TransliteratorSpec::reset() {
    if (spec != top) {
        spec = top;
        isSpecLocale = (res != 0);
        setupNext();
    }
}
예제 #3
0
void MsgEdit::markAsRead()
{
    if (msg == NULL) return;
    if (pMain->SimpleMode()){
        if (!msg->Received) return;
        pClient->markAsRead(msg);
    }else{
        ICQUser *u = pClient->getUser(Uin());
        if (u){
            History h(Uin());
            for (;;){
                bool bExit = true;
                for (list<unsigned long>::iterator it = u->unreadMsgs.begin(); it != u->unreadMsgs.end(); it++){
                    ICQMessage *msg = h.getMessage(*it);
                    if (msg == NULL) continue;
                    unsigned type = msg->Type();
                    if ((type == ICQ_MSGxMSG) || (type == ICQ_MSGxURL) || (type == ICQ_MSGxSMS)){
                        pClient->markAsRead(msg);
                        bExit = false;
                        break;
                    }
                }
                if (bExit) break;
            }
        }
    }
    setupNext();
}
예제 #4
0
const UnicodeString& TransliteratorSpec::next() {
    spec = nextSpec;
    isSpecLocale = isNextLocale;
    setupNext();
    return spec;
}
예제 #5
0
void *MsgEdit::processEvent(Event *e)
{
    if (e->type() == EventMessageReceived){
        Message *msg = (Message*)(e->param());
        if ((msg->contact() == m_userWnd->id()) && (msg->type() != MessageStatus)){
            if (CorePlugin::m_plugin->getContainerMode()){
                bool bSetFocus = false;
                if (topLevelWidget() && topLevelWidget()->inherits("Container")){
                    Container *container = static_cast<Container*>(topLevelWidget());
                    if (container->wnd() == m_userWnd)
                        bSetFocus = true;
                }
                setMessage(msg, bSetFocus);
            }else{
                if (m_edit->isReadOnly())
                    QTimer::singleShot(0, this, SLOT(setupNext()));
            }
        }
    }
    if (e->type() == EventRealSendMessage){
        MsgSend *s = (MsgSend*)(e->param());
        if (s->edit == this){
            sendMessage(s->msg);
            return e->param();
        }
    }
    if (e->type() == EventCheckState){
        CommandDef *cmd = (CommandDef*)(e->param());
        if ((cmd->param == this) && (cmd->id == CmdTranslit)){
            Contact *contact = getContacts()->contact(m_userWnd->id());
            if (contact){
                TranslitUserData *data = (TranslitUserData*)(contact->getUserData(CorePlugin::m_plugin->translit_data_id));
                if (data){
                    cmd->flags &= ~COMMAND_CHECKED;
                    if (data->Translit)
                        cmd->flags |= COMMAND_CHECKED;
                }
            }
            return NULL;
        }
        if ((cmd->menu_id != MenuTextEdit) || (cmd->param != this))
            return NULL;
        cmd->flags &= ~(COMMAND_CHECKED | COMMAND_DISABLED);
        switch (cmd->id){
        case CmdUndo:
            if (m_edit->isReadOnly())
                return NULL;
            if (!m_edit->isUndoAvailable())
                cmd->flags |= COMMAND_DISABLED;
            return e->param();
        case CmdRedo:
            if (m_edit->isReadOnly())
                return NULL;
            if (!m_edit->isRedoAvailable())
                cmd->flags |= COMMAND_DISABLED;
            return e->param();
        case CmdCut:
            if (m_edit->isReadOnly())
                return NULL;
        case CmdCopy:
            if (!m_edit->hasSelectedText())
                cmd->flags |= COMMAND_DISABLED;
            return e->param();
        case CmdPaste:
            if (m_edit->isReadOnly())
                return NULL;
            if (QApplication::clipboard()->text().isEmpty())
                cmd->flags |= COMMAND_DISABLED;
            return e->param();
        case CmdClear:
            if (m_edit->isReadOnly())
                return NULL;
        case CmdSelectAll:
            if (m_edit->text().isEmpty())
                cmd->flags |= COMMAND_DISABLED;
            return e->param();
        }
        return NULL;
    }
    if (e->type() == EventCommandExec){
        CommandDef *cmd = (CommandDef*)(e->param());
        if ((cmd->id == CmdSmile) && (cmd->param == this)){
            Event eBtn(EventCommandWidget, cmd);
            QToolButton *btnSmile = (QToolButton*)(eBtn.process());
            if (btnSmile){
                SmilePopup *popup = new SmilePopup(this);
                QSize s = popup->minimumSizeHint();
                popup->resize(s);
                connect(popup, SIGNAL(insert(int)), this, SLOT(insertSmile(int)));
                QPoint p = CToolButton::popupPos(btnSmile, popup);
                popup->move(p);
                popup->show();
            }
            return e->param();
        }
예제 #6
0
void *MsgEdit::processEvent(Event *e)
{
    if ((e->type() == EventContactChanged) && !m_bReceived){
        if (((Contact*)(e->param()))->id() != (m_userWnd->m_id))
            return NULL;
        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();
        }
예제 #7
0
void MsgEdit::setMessage(ICQMessage *_msg, bool bMark, bool bInTop, bool bSaveEdit)
{
    msgTail = "";
    setUpdatesEnabled(false);
    if (msg != _msg){
        if (msg && (msg->Id < MSG_PROCESS_ID)) delete msg;
        msg = _msg;
    }
    if (bMultiply) toggleMultiply();
    if (msg == NULL){
        edit->setText("");
        edit->resetColors(false);
        urlEdit->setText("");
        users->clear();
        url->hide();
        edit->hide();
        file->hide();
        lblUsers->hide();
        btnBgColor->hide();
        btnFgColor->hide();
        btnBold->hide();
        btnItalic->hide();
        btnUnder->hide();
        btnFont->hide();
#ifdef USE_SPELL
        btnSpell->hide();
#endif
        btnSend->hide();
        chkClose->hide();
        btnAccept->hide();
        btnDecline->hide();
        btnNext->show();
        btnReply->hide();
        btnQuote->hide();
        btnGrant->hide();
        btnRefuse->hide();
        btnMultiply->hide();
        btnForward->hide();
        users->hide();
        view->hide();
        setupNext();
        setUpdatesEnabled(true);
        repaint();
        return;
    }
    emit showMessage(Uin, msg->Id);
    if (msg->Received()){
        if (bMark) pClient->markAsRead(msg);
        phone->hide();
        url->hide();
        edit->hide();
        file->hide();
        lblUsers->hide();
        btnBgColor->hide();
        btnFgColor->hide();
        btnBold->hide();
        btnItalic->hide();
        btnUnder->hide();
        btnFont->hide();
#ifdef USE_SPELL
        btnSpell->hide();
#endif
        btnSend->hide();
        chkClose->hide();
        btnAccept->hide();
        btnDecline->hide();
        btnNext->show();
        btnMultiply->hide();
        setupNext();
        if (msg->Type() == ICQ_MSGxCONTACTxLIST){
            btnReply->hide();
            btnQuote->hide();
            btnGrant->hide();
            btnRefuse->hide();
            users->show();
            view->hide();
            btnForward->show();
            ICQContacts *m = static_cast<ICQContacts*>(msg);
            for (ContactList::iterator it = m->Contacts.begin(); it != m->Contacts.end(); it++){
                Contact *contact = static_cast<Contact*>(*it);
                users->addUser(contact->Uin, contact->Alias);
            }
            users->sender = false;
        }else{
            switch (msg->Type()){
            case ICQ_MSGxFILE:{
                    ICQFile *f = static_cast<ICQFile*>(msg);
                    btnReply->hide();
                    btnQuote->hide();
                    btnGrant->hide();
                    btnRefuse->hide();
                    if (f->Id >= MSG_PROCESS_ID){
                        btnAccept->show();
                        btnDecline->show();
                        file->show();
                        ICQUser *u = pClient->getUser(f->getUin());
                        if ((u == NULL) || !u->AcceptFileOverride()) u = pClient;
                        string path = u->AcceptFilePath.c_str();
                        if (*path.c_str() == 0)
                            pMain->buildFileName(path, "IncommingFiles/");
                        QString name = QString::fromLocal8Bit(path.c_str());
#ifdef WIN32
                        name.replace(QRegExp("/"), "\\");
                        if ((name.length() == 0) || (name[(int)(name.length() - 1)] != '\\'))
                            name += "\\";
#else
                        if ((name.length() == 0) || (name[(int)(name.length() - 1)] != '/'))
                            name += "/";
#endif
                        name += QString::fromLocal8Bit(f->Name.c_str());
                        fileEdit->setText(name);
                        fileEdit->setSaveMode(true);
                        ftChanged();
                    }else{
                        btnAccept->hide();
                        btnDecline->hide();
                    }
                    break;
                }
            case ICQ_MSGxAUTHxREQUEST:
                btnReply->hide();
                btnQuote->hide();
                btnGrant->show();
                btnRefuse->show();
                btnAccept->hide();
                btnDecline->hide();
                btnForward->hide();
                break;
            case ICQ_MSGxMSG:
            case ICQ_MSGxURL:
                if (bInTop && !pMain->SimpleMode()){
                    btnReply->hide();
                    btnQuote->show();
                    btnForward->show();
                    btnGrant->hide();
                    btnRefuse->hide();
                    btnAccept->hide();
                    btnDecline->hide();
                    users->hide();
                    view->hide();
                    edit->setTextFormat(RichText);
                    edit->setText("");
                    edit->show();
                    edit->resetColors(true);
                    textChanged();
                    setUpdatesEnabled(true);
                    edit->setFocus();
                    repaint();
                    return;
                }
                btnReply->show();
                btnQuote->show();
                btnGrant->hide();
                btnRefuse->hide();
                btnAccept->hide();
                btnDecline->hide();
                btnForward->show();
                break;
            case ICQ_MSGxCHAT:
                btnReply->hide();
                btnQuote->hide();
                btnGrant->hide();
                btnRefuse->hide();
                btnAccept->hide();
                btnDecline->hide();
                btnForward->hide();
                if (msg->Id >= MSG_PROCESS_ID){
                    btnAccept->show();
                    btnDecline->show();
                    chatChanged();
                }
                break;
            default:
                btnReply->hide();
                btnQuote->hide();
                btnGrant->hide();
                btnRefuse->hide();
                btnAccept->hide();
                btnDecline->hide();
                btnForward->hide();
            }
            users->hide();
            view->show();
            view->setText(view->makeMessageText(msg, false));
            if (msg->Type() == ICQ_MSGxMSG){
                ICQMsg *m = static_cast<ICQMsg*>(msg);
                if (m->BackColor() != m->ForeColor()){
                    view->setForeground(QColor(m->ForeColor));
                    view->setBackground(QColor(m->BackColor));
                }else{
                    view->resetColors();
                }
            }else{
                view->resetColors();
            }
        }
    }else{
        btnReply->hide();
        btnForward->hide();
        btnQuote->hide();
        btnGrant->hide();
        btnRefuse->hide();
        btnNext->hide();
        btnAccept->hide();
        btnDecline->hide();
        chkClose->show();
        btnSend->show();
        switch (msg->Type()){
        case ICQ_MSGxMSG:{
                phone->hide();
                url->hide();
                edit->show();
                users->hide();
                view->hide();
                file->hide();
                lblUsers->hide();
                btnBgColor->show();
                btnFgColor->show();
                btnBold->show();
                btnItalic->show();
                btnUnder->show();
                btnFont->show();
                btnMultiply->show();
#ifdef USE_SPELL
                btnSpell->show();
#endif
                if (!bSaveEdit){
                    edit->setTextFormat(RichText);
                    ICQMsg *m = static_cast<ICQMsg*>(msg);
                    edit->setText(QString::fromLocal8Bit(m->Message.c_str()));
                    if (m->BackColor() != m->ForeColor()){
                        edit->setBackground(QColor(m->BackColor));
                        edit->setForeground(QColor(m->ForeColor));
                    }else{
                        edit->resetColors(true);
                    }
                    edit->setFocus();
                }
                break;
            }
        case ICQ_MSGxURL:{
                phone->hide();
                url->show();
                edit->show();
                edit->setTextFormat(PlainText);
                users->hide();
                view->hide();
                file->hide();
                lblUsers->hide();
                btnBgColor->hide();
                btnFgColor->hide();
                btnBold->hide();
                btnItalic->hide();
                btnUnder->hide();
                btnFont->hide();
                btnMultiply->show();
#ifdef USE_SPELL
                btnSpell->show();
#endif
                ICQUrl *m = static_cast<ICQUrl*>(msg);
                edit->resetColors(false);
                edit->setText(QString::fromLocal8Bit(m->Message.c_str()));
                urlEdit->setText(QString::fromLocal8Bit(m->URL.c_str()));
                urlEdit->setFocus();
                break;
            }
        case ICQ_MSGxFILE:{
                phone->hide();
                url->hide();
                edit->show();
                edit->setTextFormat(PlainText);
                users->hide();
                view->hide();
                file->show();
                lblUsers->hide();
                btnBgColor->hide();
                btnFgColor->hide();
                btnBold->hide();
                btnItalic->hide();
                btnUnder->hide();
                btnFont->hide();
                btnMultiply->hide();
#ifdef USE_SPELL
                btnSpell->show();
#endif
                ICQFile *m = static_cast<ICQFile*>(msg);
                edit->resetColors(false);
                edit->setText(QString::fromLocal8Bit(m->Description.c_str()));
                fileEdit->setSaveMode(false);
                fileEdit->setText(QString::fromLocal8Bit(m->Name.c_str()));
                fileEdit->setFocus();
                break;
            }
        case ICQ_MSGxCHAT:{
                phone->hide();
                url->hide();
                edit->show();
                edit->setTextFormat(PlainText);
                users->hide();
                view->hide();
                file->hide();
                lblUsers->hide();
                btnBgColor->hide();
                btnFgColor->hide();
                btnBold->hide();
                btnItalic->hide();
                btnUnder->hide();
                btnFont->hide();
                btnMultiply->hide();
#ifdef USE_SPELL
                btnSpell->show();
#endif
                ICQChat *m = static_cast<ICQChat*>(msg);
                edit->resetColors(false);
                edit->setText(QString::fromLocal8Bit(m->Reason.c_str()));
                break;
            }
        case ICQ_MSGxSMS:{
                phone->show();
                url->hide();
                edit->show();
                edit->setTextFormat(RichText);
                users->hide();
                view->hide();
                file->hide();
                lblUsers->hide();
                btnBgColor->hide();
                btnFgColor->hide();
                btnBold->hide();
                btnItalic->hide();
                btnUnder->hide();
                btnFont->hide();
                btnMultiply->hide();
#ifdef USE_SPELL
                btnSpell->show();
#endif
                ICQSMS *m = static_cast<ICQSMS*>(msg);
                edit->resetColors(false);
                edit->setText(QString::fromLocal8Bit(pClient->clearHTML(m->Message.c_str()).c_str()));
                if (*m->Phone.c_str())
                    phoneEdit->lineEdit()->setText(QString::fromLocal8Bit(m->Phone.c_str()));
                phoneEdit->setFocus();
                break;
            }
        case ICQ_MSGxCONTACTxLIST:{
                phone->hide();
                url->hide();
                edit->hide();
                users->show();
                view->hide();
                file->hide();
                lblUsers->show();
                btnBgColor->hide();
                btnFgColor->hide();
                btnBold->hide();
                btnItalic->hide();
                btnUnder->hide();
                btnFont->hide();
                btnMultiply->show();
#ifdef USE_SPELL
                btnSpell->hide();
#endif
                ICQContacts *m = static_cast<ICQContacts*>(msg);
                for (ContactList::iterator it = m->Contacts.begin(); it != m->Contacts.end(); it++){
                    Contact *contact = static_cast<Contact*>(*it);
                    users->addUser(contact->Uin, contact->Alias);
                }
                users->sender = true;
                break;
            }
        case ICQ_MSGxAUTHxREQUEST:{
                phone->hide();
                url->hide();
                edit->show();
                edit->setTextFormat(RichText);
                users->hide();
                view->hide();
                file->hide();
                lblUsers->hide();
                btnBgColor->hide();
                btnFgColor->hide();
                btnBold->hide();
                btnItalic->hide();
                btnUnder->hide();
                btnFont->hide();
                btnMultiply->hide();
#ifdef USE_SPELL
                btnSpell->hide();
#endif
                ICQAuthRequest *m = static_cast<ICQAuthRequest*>(msg);
                edit->resetColors(false);
                edit->setText(QString::fromLocal8Bit(m->Message.c_str()));
                edit->setFocus();
                break;
            }
        case ICQ_MSGxAUTHxREFUSED:{
                phone->hide();
                url->hide();
                edit->show();
                edit->setTextFormat(RichText);
                users->hide();
                view->hide();
                file->hide();
                lblUsers->hide();
                btnBgColor->hide();
                btnFgColor->hide();
                btnBold->hide();
                btnItalic->hide();
                btnUnder->hide();
                btnFont->hide();
                btnMultiply->hide();
#ifdef USE_SPELL
                btnSpell->hide();
#endif
                ICQAuthRefused *m = static_cast<ICQAuthRefused*>(msg);
                edit->resetColors(false);
                edit->setText(QString::fromLocal8Bit(m->Message.c_str()));
                edit->setFocus();
                break;
            }
        case ICQ_MSGxAUTHxGRANTED:{
                phone->hide();
                url->hide();
                edit->hide();
                users->hide();
                view->show();
                file->hide();
                lblUsers->hide();
                btnBgColor->hide();
                btnFgColor->hide();
                btnBold->hide();
                btnItalic->hide();
                btnUnder->hide();
                btnFont->hide();
                btnMultiply->hide();
#ifdef USE_SPELL
                btnSpell->hide();
#endif
                break;
            }
        default:
            log(L_WARN, "Unknown message type %u", msg->Type());
        }
    }
    textChanged();
    setUpdatesEnabled(true);
    repaint();
}