예제 #1
0
MsgFile::MsgFile(MsgEdit *parent, Message *msg)
        : QObject(parent)
{
    m_client   = msg->client();
    m_edit     = parent;
    m_bCanSend = false;
    if (m_edit->m_edit->isReadOnly()){
        m_edit->m_edit->setText("");
        m_edit->m_edit->setReadOnly(false);
    }
    m_edit->m_edit->setTextFormat(Qt::PlainText);
    QString t = msg->getPlainText();
    if (!t.isEmpty())
        m_edit->m_edit->setText(t);

    Command cmd;
    cmd->id		= CmdFileName;
    cmd->param	= parent;
    Event eWidget(EventCommandWidget, cmd);
    CToolEdit *edtName = (CToolEdit*)(eWidget.process());
    if (edtName){
        connect(edtName, SIGNAL(textChanged(const QString&)), this, SLOT(changed(const QString&)));
        edtName->setText(static_cast<FileMessage*>(msg)->getFile());
    }
    changed(static_cast<FileMessage*>(msg)->getFile());
}
예제 #2
0
void MsgFile::selectFile()
{
    Command cmd;
    cmd->id		= CmdFileName;
    cmd->param	= m_edit;
    Event eWidget(EventCommandWidget, cmd);
    CToolEdit *edtName = (CToolEdit*)(eWidget.process());
    if (edtName == NULL)
        return;
    QString s = edtName->text();
#ifdef WIN32
    s.replace(QRegExp("\\\\"), "/");
#endif
    QStringList lst = Q3FileDialog::getOpenFileNames(QString::null, QString::null, m_edit->topLevelWidget());
    if ((lst.count() > 1) || ((lst.count() > 0) && (lst[0].find(' ') >= 0))){
        for (QStringList::Iterator it = lst.begin(); it != lst.end(); ++it){
#ifdef WIN32
            (*it).replace(QRegExp("/"), "\\");
#endif
            *it = QString("\"") + *it + QString("\"");
        }
#ifdef WIN32
    }else{
        for (QStringList::Iterator it = lst.begin(); it != lst.end(); ++it){
            QString &s = *it;
            s.replace(QRegExp("/"), "\\");
        }
#endif
    }
    edtName->setText(lst.join(" "));
}
예제 #3
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;
}
예제 #4
0
void MsgFile::init()
{
    Command cmd;
    cmd->id		= CmdFileName;
    cmd->param	= m_edit;
    Event eWidget(EventCommandWidget, cmd);
    CToolEdit *edtName = (CToolEdit*)(eWidget.process());
    if (edtName){
        if (edtName->text().isEmpty()){
            selectFile();
            return;
        }
        edtName->setFocus();
    }
}
예제 #5
0
void MsgUrl::init()
{
    if (!m_edit->topLevelWidget()->isActiveWindow() || m_edit->topLevelWidget()->isMinimized())
        return;
    Command cmd;
    cmd->id    = CmdUrlInput;
    cmd->param = m_edit;
    EventCommandWidget eWidget(cmd);
    eWidget.process();
    CToolEdit *edtUrl = qobject_cast<CToolEdit*>(eWidget.widget());
    if (edtUrl && edtUrl->text().isEmpty()){
        edtUrl->setFocus();
        return;
    }
    m_edit->m_edit->setFocus();
}
예제 #6
0
MsgUrl::MsgUrl(MsgEdit *parent, Message *msg)
        : QObject(parent)
{
    m_client = msg->client();
    m_edit   = parent;
    if (m_edit->m_edit->isReadOnly()){
        m_edit->m_edit->setText(QString::null);
        m_edit->m_edit->setReadOnly(false);
    }
    QString t = msg->getPlainText();
    if (!t.isEmpty())
        m_edit->m_edit->setText(t);
    Command cmd;
    cmd->id    = CmdUrlInput;
    cmd->param = m_edit;
    EventCommandWidget eWidget(cmd);
    eWidget.process();
    CToolEdit *edtUrl = qobject_cast<CToolEdit*>(eWidget.widget());
    if (edtUrl){
        connect(edtUrl, SIGNAL(textChanged(const QString&)), this, SLOT(urlChanged(const QString&)));
        edtUrl->setText(static_cast<UrlMessage*>(msg)->getUrl());
        if (edtUrl->text().isEmpty()){
            QString url;
            EventGetURL e;
            e.process();
            url = e.url();
            if (!url.isEmpty()){
                url = url.mid(1);
                int n = url.indexOf('\"');
                if (n > 0){
                    QString u = url.left(n);
                    edtUrl->setText(u);
                    url = url.mid(n + 1);
                    n = url.indexOf('\"');
                    if (n > 0)
                        url = url.mid(n + 1);
                }
                n = url.indexOf('\"');
                if (n > 0){
                    url = url.left(n);
                    m_edit->m_edit->setText(url);
                }
            }
        }
        urlChanged(edtUrl->text());
    }
}
예제 #7
0
void MsgFile::init()
{
    if (!m_edit->topLevelWidget()->isActiveWindow() || m_edit->topLevelWidget()->isMinimized())
        return;
    Command cmd;
    cmd->id		= CmdFileName;
    cmd->param	= m_edit;
    Event eWidget(EventCommandWidget, cmd);
    CToolEdit *edtName = (CToolEdit*)(eWidget.process());
    if (edtName){
        if (edtName->text().isEmpty()){
            selectFile();
            return;
        }
        edtName->setFocus();
    }
}
예제 #8
0
void MsgFile::selectFile()
{
    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;
    QString s = edtName->text();
    QStringList lst = QFileDialog::getOpenFileNames(m_edit->topLevelWidget());
    if ((lst.count() > 1) || ((lst.count() > 0) && (lst[0].indexOf(' ') >= 0))){
        for (QStringList::Iterator it = lst.begin(); it != lst.end(); ++it){
            *it = '\"' + QDir::convertSeparators(*it) + '\"';
        }
    }else{
        for (QStringList::Iterator it = lst.begin(); it != lst.end(); ++it){
            *it = QDir::convertSeparators(*it);
        }
    }
    edtName->setText(lst.join(" "));
}
예제 #9
0
void *MsgFile::processEvent(Event *e)
{
    if (e->type() == EventCheckState){
        CommandDef *cmd = (CommandDef*)(e->param());
        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 e->param();
            }
            switch (cmd->id){
            case CmdTranslit:
            case CmdSmile:
            case CmdSend:
            case CmdSendClose:
                e->process(this);
                cmd->flags &= ~BTN_HIDE;
                return e->param();
            case CmdNextMessage:
            case CmdMsgAnswer:
                e->process(this);
                cmd->flags |= BTN_HIDE;
                return e->param();
            }
        }
    }
    if (e->type() == EventCommandExec){
        CommandDef *cmd = (CommandDef*)(e->param());
        if (cmd->param == m_edit){
            if (cmd->id == CmdSend){
                Command cmd;
                cmd->id		= CmdFileName;
                cmd->param	= m_edit;
                Event eWidget(EventCommandWidget, cmd);
                CToolEdit *edtName = (CToolEdit*)(eWidget.process());
                if (edtName == NULL)
                    return NULL;
                QString msgText = m_edit->m_edit->text();
                QString file = edtName->text();
                QStringList files;
                QString f;
                for (int i = 0; i < (int)file.length(); i++){
                    if (file[i] == '\"'){
                        f = trim(f);
                        if (!f.isEmpty())
                            files.append(f);
                        f = "";
                        for (i++; i < (int)file.length(); i++){
                            if (file[i] == '\"')
                                break;
                            f += file[i];
                        }
                        f = trim(f);
                        if (!f.isEmpty())
                            files.append(f);
                        f = "";
                        continue;
                    }
                    f += file[i];
                }
                f = trim(f);
                if (!f.isEmpty())
                    files.append(f);
                file = "";
                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.c_str());
                    m_edit->sendMessage(msg);
                }
                return e->param();
            }
            if (cmd->id == CmdFileName){
                selectFile();
                return e->param();
            }
        }
    }
    return NULL;
}
예제 #10
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;
}