Ejemplo n.º 1
0
/** @short Take the initial text and mark it as a quotation */
QStringList quoteText(QStringList inputLines)
{
    QStringList quote;
    for (QStringList::iterator line = inputLines.begin(); line != inputLines.end(); ++line) {
        if (UiUtils::signatureSeparator().match(*line).hasMatch()) {
            // This is the signature separator, we should not include anything below that in the quote
            break;
        }
        // rewrap - we need to keep the quotes at < 79 chars, yet the grow with every level
        if (line->length() < 79-2) {
            // this line is short enough, prepend quote mark and continue
            if (line->isEmpty() || line->at(0) == QLatin1Char('>'))
                line->prepend(QLatin1Char('>'));
            else
                line->prepend(QLatin1String("> "));
            quote << *line;
            continue;
        }
        // long line -> needs to be wrapped
        // 1st, detect the quote depth and eventually stript the quotes from the line
        int quoteLevel = 0;
        int contentStart = 0;
        if (line->at(0) == QLatin1Char('>')) {
            quoteLevel = 1;
            while (quoteLevel < line->length() && line->at(quoteLevel) == QLatin1Char('>'))
                ++quoteLevel;
            contentStart = quoteLevel;
            if (quoteLevel < line->length() && line->at(quoteLevel) == QLatin1Char(' '))
                ++contentStart;
        }

        // 2nd, build a quote string
        QString quotemarks;
        for (int i = 0; i < quoteLevel; ++i)
            quotemarks += QLatin1Char('>');
        quotemarks += QLatin1String("> ");

        // 3rd, wrap the line, prepend the quotemarks to each line and add it to the quote text
        int space(contentStart), lastSpace(contentStart), pos(contentStart), length(0);
        while (pos < line->length()) {
            if (line->at(pos) == QLatin1Char(' '))
                space = pos+1;
            ++length;
            if (length > 65-quotemarks.length() && space != lastSpace) {
                // wrap
                quote << quotemarks + line->mid(lastSpace, space - lastSpace);
                lastSpace = space;
                length = pos - space;
            }
            ++pos;
        }
        quote << quotemarks + line->mid(lastSpace);
    }
    return quote;
}
Ejemplo n.º 2
0
void MacroManager::addLine(LineType Type, const char* sLine)
{
    if (this->openMacro) {
        bool comment = false;
        if (Type == Gui) {
            if (this->recordGui && this->guiAsComment)
                comment = true;
            else if (!this->recordGui)
                return; // ignore Gui commands
        }
        else if (Type == Cmt) {
            comment = true;
        }

        QStringList lines = QString::fromLatin1(sLine).split(QLatin1String("\n"));
        if (comment) {
            for (QStringList::iterator it = lines.begin(); it != lines.end(); ++it)
                it->prepend(QLatin1String("#"));
        }
        this->macroInProgress.append(lines);
    }

    if (this->scriptToPyConsole) {
        // search for the Python console
        if (!this->pyConsole)
            this->pyConsole = Gui::getMainWindow()->findChild<Gui::PythonConsole*>();
        // Python console found?
        if (this->pyConsole)
            this->pyConsole->printStatement(QString::fromUtf8(sLine));
    }
}
Ejemplo n.º 3
0
void GraphicalUriArray::btAddClicked()
{

  if(m_editAdd->text().isEmpty())
  {
    if(m_comboType->currentText() == "cpath")
    {
      SelectPathDialog spd;
      QString modified_path = m_editAdd->text();

      URI path = spd.show(modified_path.toStdString());

      if(!path.empty())
        m_editAdd->setText( path.string().c_str() );
    }
    else if(m_comboType->currentText() == "file")
    {
      NRemoteOpen::Ptr nro = NRemoteOpen::create();

      QStringList fileList = nro->showMultipleSelect("");
      QStringList::iterator file = fileList.begin();

      for( ; file != fileList.end() ; ++ file)
      {
        file->prepend( m_comboType->currentText() + ':' );
      }

      if(!fileList.isEmpty())
        m_model->setStringList( m_model->stringList() << fileList );
    }
  }

  if(!m_editAdd->text().isEmpty())
  {
    QString pathStr = m_editAdd->text();

    if( !pathStr.startsWith(m_comboType->currentText()) )
      pathStr.prepend(m_comboType->currentText() + ':');

    m_model->setStringList( m_model->stringList() << pathStr );
    m_editAdd->clear();
  }

  emit valueChanged();
}
Ejemplo n.º 4
0
QString MessageView::quoteText() const
{
    if (const AbstractPartWidget *w = dynamic_cast<const AbstractPartWidget *>(viewer)) {
        QStringList quote;
        QStringList lines = w->quoteMe().split('\n');
        for (QStringList::iterator line = lines.begin(); line != lines.end(); ++line) {
            if (Composer::Util::signatureSeparator().exactMatch(*line)) {
                // This is the signature separator, we should not include anything below that in the quote
                break;
            }
            // rewrap - we need to keep the quotes at < 79 chars, yet the grow with every level
            if (line->length() < 79-2) {
                // this line is short enough, prepend quote mark and continue
                if (line->isEmpty() || line->at(0) == '>')
                    line->prepend(">");
                else
                    line->prepend("> ");
                quote << *line;
                continue;
            }
            // long line -> needs to be wrapped
            // 1st, detect the quote depth and eventually stript the quotes from the line
            int quoteLevel = 0;
            int contentStart = 0;
            if (line->at(0) == '>') {
                quoteLevel = 1;
                while (quoteLevel < line->length() && line->at(quoteLevel) == '>')
                    ++quoteLevel;
                contentStart = quoteLevel;
                if (quoteLevel < line->length() && line->at(quoteLevel) == ' ')
                    ++contentStart;
            }

            // 2nd, build a qute string
            QString quotemarks;
            for (int i = 0; i < quoteLevel; ++i)
                quotemarks += ">";
            quotemarks += "> ";

            // 3rd, wrap the line, prepend the quotemarks to each line and add it to the quote text
            int space(contentStart), lastSpace(contentStart), pos(contentStart), length(0);
            while (pos < line->length()) {
                if (line->at(pos) == ' ')
                    space = pos+1;
                ++length;
                if (length > 65-quotemarks.length() && space != lastSpace) {
                    // wrap
                    quote << quotemarks + line->mid(lastSpace, space - lastSpace);
                    lastSpace = space;
                    length = pos - space;
                }
                ++pos;
            }
            quote << quotemarks + line->mid(lastSpace);
        }
        const Imap::Message::Envelope &e = message.data(Imap::Mailbox::RoleMessageEnvelope).value<Imap::Message::Envelope>();
        QString sender;
        if (!e.from.isEmpty())
            sender = e.from[0].prettyName(Imap::Message::MailAddress::FORMAT_JUST_NAME);
        if (e.from.isEmpty())
            sender = tr("you");

        // One extra newline at the end of the quoted text to separate the response
        quote << QString();

        return tr("On %1, %2 wrote:\n").arg(e.date.toLocalTime().toString(Qt::SystemLocaleLongDate)).arg(sender) + quote.join("\n");
    }
    return QString();
}