示例#1
0
void MsgView::addMessage(ICQMessage *msg, bool bUnread, bool bSet)
{
    if (msg->Id >= MSG_PROCESS_ID) return;
    int x = contentsX();
    int y = contentsY();
    QString s(makeMessage(msg, bUnread));
    if (bSet) curAnchor = QString::number(msg->getUin()) + "." + QString::number(msg->Id);
    unsigned long foreColor = 0;
    unsigned long backColor = 0;
    if (!pMain->UseOwnColors() && (msg->Type() == ICQ_MSGxMSG)){
        ICQMsg *m = static_cast<ICQMsg*>(msg);
        foreColor = m->ForeColor();
        backColor = m->BackColor();
    }
    if (bBack){
        setText(s + text(), curAnchor);
        if (foreColor != backColor)
            setMsgBgColor(msg->getUin(), msg->Id, backColor, 0);
    }else{
        int n = paragraphs();
        if (n > 0) n--;
        append(s);
        if (foreColor != backColor)
            setMsgBgColor(msg->getUin(), msg->Id, backColor, n);
    }
    if (bSet){
        scrollToBottom();
    }else{
        setContentsPos(x, y);
    }
}
示例#2
0
QString MsgView::makeMessage(ICQMessage *msg, bool bUnread)
{
    QString s;
    s.sprintf("<p><a name=\"%lu.%lu\"></a></p>"
              "<table width=100%%><tr>"
              "<td><a href=\"msg://%lu.%lu\"><img src=\"icon:%s\"></a>&nbsp;",
              msg->Uin(), msg->Id, msg->Uin(), msg->Id, Client::getMessageIcon(msg->Type()));
    if (bUnread) s += "<b>";
    QString color;
    color.sprintf(FONT_FORMAT, msg->Received ? pMain->ColorReceive() : pMain->ColorSend());
    s += color;
    if (msg->Received){
        CUser u(msg->Uin);
        s += u.name(true);
    }else{
        CUser u(pClient);
        s += u.name(true);
    }
    s += "</font>";
    if (bUnread) s += "</b>";
    s += "</td><td align=right>";
    if (bUnread) s += "<b>";
    QDateTime time;
    time.setTime_t(msg->Time);
#if USE_KDE
    s += KGlobal::locale()->formatDateTime(time);
#else
    s += time.toString();
#endif
    if (bUnread) s += "</b>";
    s += "</td></tr></table>";
    unsigned long foreColor = 0;
    unsigned long backColor = 0;
    if (msg->Type() == ICQ_MSGxMSG){
        ICQMsg *m = static_cast<ICQMsg*>(msg);
        foreColor = m->ForeColor();
        backColor = m->BackColor();
    }
    s += "<table width=100%";
    if (foreColor != backColor){
        QString bg;
        bg.sprintf(" bgcolor=#%06lX", backColor);
        s += bg;
    }
    s += "><tr><td>";
    if (foreColor != backColor){
        QString fg;
        fg.sprintf("<font color=#%06lX>", foreColor);
        s += fg;
    }
    s += makeMessageText(msg);
    if (foreColor != backColor) s += "</font>";
    s += "</td></tr></table>";
    return s;
}
示例#3
0
void HistoryView::fill()
{
    if (!bFill){
        bFill = true;
        u = pClient->getUser(m_nUin);
        if (u == NULL) return;
        h = new History(m_nUin);
        colors.clear();
        t = "";
        showProgress(0);
    }
    if ((u == NULL) || (h == NULL)) return;
    History::iterator &it = h->messages();
    list<unsigned long>::iterator unreadIt;
    ++it;
    if (*it){
        showProgress(it.progress());
        for (unreadIt = u->unreadMsgs.begin(); unreadIt != u->unreadMsgs.end(); unreadIt++)
            if ((*unreadIt) == (*it)->Id) break;
        t = makeMessage(*it, unreadIt != u->unreadMsgs.end()) + t;
        unsigned long foreColor = 0;
        unsigned long backColor = 0;
        if (!pMain->UseOwnColors() && ((*it)->Type() == ICQ_MSGxMSG)){
            ICQMsg *m = static_cast<ICQMsg*>(*it);
            foreColor = m->ForeColor();
            backColor = m->BackColor();
        }
        if (foreColor != backColor){
            MsgBgColor pc;
            pc.id = (*it)->Id;
            pc.rgb = backColor;
            colors.prepend(pc);
        }
        QTimer::singleShot(0, this, SLOT(fill()));
        return;
    }

    setText(t);
    t = "";
    int n = 0;
    for (QValueList<MsgBgColor>::Iterator itCol = colors.begin(); itCol != colors.end(); ++itCol){
        MsgBgColor pc = *itCol;
        n = setMsgBgColor(m_nUin, pc.id, pc.rgb, n);
    }
    colors.clear();
    delete h;
    h = NULL;
    u = NULL;
    showProgress(101);
}
示例#4
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();
}
示例#5
0
void MsgEdit::makeMessage()
{
    if (msg == NULL) return;
    switch (msg->Type()){
    case ICQ_MSGxMSG:{
            ICQMsg *m = static_cast<ICQMsg*>(msg);
            m->Message = edit->text().local8Bit();
            if (edit->colorChanged()){
                m->BackColor = (edit->background().rgb() & 0xFFFFFF);
                m->ForeColor = (edit->foreground().rgb() & 0xFFFFFF);
                pMain->MessageBgColor = m->BackColor();
                pMain->MessageFgColor = m->ForeColor();
            }
            break;
        }
    case ICQ_MSGxURL:{
            ICQUrl *m = static_cast<ICQUrl*>(msg);
            m->Message = edit->text().local8Bit();
            m->URL = urlEdit->text().local8Bit();
            break;
        }
    case ICQ_MSGxFILE:{
            ICQFile *m = static_cast<ICQFile*>(msg);
            m->Description = edit->text().local8Bit();
            m->Name = fileEdit->text().local8Bit();
            break;
        }
    case ICQ_MSGxCHAT:{
            ICQChat *m = static_cast<ICQChat*>(msg);
            m->Reason = edit->text().local8Bit();
            break;
        }
    case ICQ_MSGxSMS:{
            ICQSMS *m = static_cast<ICQSMS*>(msg);
            string s;
            s = edit->text().local8Bit();
            s = pClient->clearHTML(s.c_str());
            msgTail = trim(QString::fromLocal8Bit(s.c_str()));
            m->Message = smsChunk();
            m->Phone = phoneEdit->lineEdit()->text().local8Bit();
            break;
        }
    case ICQ_MSGxCONTACTxLIST:{
            ICQContacts *m = static_cast<ICQContacts*>(msg);
            users->fillList(m->Contacts);
            break;
        }
    case ICQ_MSGxAUTHxREQUEST:{
            ICQAuthRequest *m = static_cast<ICQAuthRequest*>(msg);
            m->Message = edit->text().local8Bit();
            break;
        }
    case ICQ_MSGxAUTHxREFUSED:{
            ICQAuthRefused *m = static_cast<ICQAuthRefused*>(msg);
            m->Message = edit->text().local8Bit();
            break;
        }
    case ICQ_MSGxAUTHxGRANTED:
        break;
    default:
        log(L_WARN, "Bad message type %u", msg->Type());
        return;
    }
    if (bMultiply){
        msg->Uin.clear();
        UserBox *box = static_cast<UserBox*>(topLevelWidget());
        if (box->users){
            UserView *users = box->users;
            if (users) users->fillChecked(msg);
        }
    }
    realSend();
}