Esempio n. 1
0
void GetSupportedFileFormats(QList<QByteArray> &g_supportedFormats)
{

    // Assemble list of supported Image Formats from our plugin
    int numPlugins = g_pluginManager.getNumPlugins();
    for (int i = 0; i< numPlugins; i++)
    {
        if (strcmp(g_pluginManager.getPluginType(i), "IMAGE") == 0)
        {
            QByteArray bArray = g_pluginManager.getPluginName(i);
            QByteArray fformat = bArray.toUpper();
            if (!g_supportedFormats.contains(fformat))
                g_supportedFormats.append(fformat);
        }
    }

    // Get a list of all Supported file formats from Qt Plugins
    QList<QByteArray> QtFormats = QImageReader::supportedImageFormats();

    // Upppercase List
    QList<QByteArray>::Iterator i;
    for (i = QtFormats.begin(); i != QtFormats.end(); ++i)
    {
        QByteArray fformat = (*i);
        fformat = fformat.toUpper();
        if (!g_supportedFormats.contains(fformat))
            g_supportedFormats.append(fformat);
    }
    
    // Sort the list to alphabetical order
    std::sort(g_supportedFormats.begin(), g_supportedFormats.end());

}
Esempio n. 2
0
void HttpMessage::setHeader(const QByteArray &name, const QByteArray &value)
{
    if (!name.isEmpty()) {
        if (!value.isNull())
            // sets the value
            m_headers[name.toUpper()] = value;
        else
            // erases the header
            m_headers.remove(name.toUpper());
    }
}
Esempio n. 3
0
void CiscoSecret7::transform(const QByteArray &input, QByteArray &output)
{
    if (wayValue == INBOUND) {
        QByteArray data;

        cipher(seed,input, data);
        output = data.toHex().prepend(QByteArray::number(seed));

    } else {
        QByteArray encrypted = input.toUpper();

        if (encrypted.isEmpty())
            return;

        if (encrypted.size() < 3) {
            emit error(tr("Invalid hash (far too small)"),id);
            return;
        }
        bool k = true;
        seed = encrypted.mid(0,2).toInt(&k);
        if (!k || seed > MAXSEED) {
            emit error(tr("Invalid seed, it must be an unsigned integer <= %1").arg(MAXSEED),id);
            return;
        }

        QByteArray data = encrypted.mid(2);
        data = fromHex(data);
        cipher(seed,data,output);
    }
}
Esempio n. 4
0
QByteArray vCardParam::toByteArray(QList<vCardParam> params, vCardVersion version)
{
    QByteArray buffer;

    switch (version)
    {
        case VC_VER_2_1:
        {
            QStringList ps;
            for (const vCardParam& param : params)
                ps.append(param.toByteArray(VC_VER_2_1));
            buffer.append(ps.join(QString(VC_SEPARATOR_TOKEN)));
        }
        break;

        case VC_VER_3_0:
        {
            QStringList types;
            QStringList encodings;
            QStringList charsets;
            QStringList unknowns;
            for (const vCardParam& param : params)
            {
                QByteArray param_str = param.toByteArray(VC_VER_2_1);
                switch (param.group())
                {
                    case Type:
                        types.append(param_str);
                        break;

                    case Encoding:
                        encodings.append(param_str);
                        break;

                    case Charset:
                        charsets.append(param_str);
                        break;

                    default:
                        unknowns.append(param_str);
                }
            }

            unknowns += charsets;
            unknowns += encodings;

            if (!types.isEmpty())
                unknowns.prepend(QString(VC_GROUP_TOKEN).arg(VC_TYPE_TOKEN).arg(types.join(QString(VC_TYPE_SEP_TOKEN))));

            if (!unknowns.isEmpty())
                buffer.append(unknowns.join(QString(VC_SEPARATOR_TOKEN)));
        }
        break;

        default:
            break;
    }

    return buffer.toUpper();
}
QByteArray TwitterDataUtil::authorizationHeader(const QByteArray &oauthConsumerKey,
                                                const QByteArray &oauthConsumerSecret,
                                                const QByteArray &requestMethod,
                                                const QByteArray &requestUrl,
                                                const std::vector<std::pair<QByteArray, QByteArray>> &parameters,
                                                const QByteArray &oauthToken,
                                                const QByteArray &oauthTokenSecret,
                                                const QByteArray &oauthNonce,
                                                const QByteArray &oauthTimestamp)
{
    // Twitter requires all requests to be signed with an authorization header.
    QByteArray nonce {oauthNonce};
    if (nonce.isEmpty()) {
        nonce = QUuid::createUuid().toByteArray().toBase64();
    }
    QByteArray timestamp {oauthTimestamp};
    if (timestamp.isEmpty()) {
        timestamp = QByteArray::number(qFloor(QDateTime::currentMSecsSinceEpoch() / 1000.0));
    }

    // now build up the encoded parameters map.  We use a map to perform alphabetical sorting.
    QMap<QByteArray, QByteArray> encodedParams {};
    encodedParams.insert(QByteArray("oauth_consumer_key").toPercentEncoding(), QByteArray(oauthConsumerKey).toPercentEncoding());
    encodedParams.insert(QByteArray("oauth_nonce").toPercentEncoding(), nonce.toPercentEncoding());
    encodedParams.insert(QByteArray("oauth_signature_method").toPercentEncoding(), QByteArray(OAUTH_SIGNATURE_METHOD).toPercentEncoding());
    encodedParams.insert(QByteArray("oauth_timestamp").toPercentEncoding(), timestamp.toPercentEncoding());
    encodedParams.insert(QByteArray("oauth_version").toPercentEncoding(), QByteArray(OAUTH_VERSION).toPercentEncoding());
    if (!oauthToken.isEmpty()) {
        encodedParams.insert(QByteArray("oauth_token").toPercentEncoding(), oauthToken.toPercentEncoding());
    }
    for (const std::pair<QByteArray, QByteArray> &parameter : parameters) {
        encodedParams.insert(parameter.first, parameter.second);
    }

    QByteArray parametersByteArray {};
    QList<QByteArray> keys = encodedParams.keys();
    for (const QByteArray &key : keys) {
        parametersByteArray += key + QByteArray("=") + encodedParams.value(key) + QByteArray("&");
    }
    parametersByteArray.chop(1);

    QByteArray signatureBaseString {requestMethod.toUpper() + QByteArray("&") + requestUrl.toPercentEncoding() + QByteArray("&") + parametersByteArray.toPercentEncoding()};
    QByteArray signingKey {oauthConsumerSecret.toPercentEncoding() + QByteArray("&") + oauthTokenSecret.toPercentEncoding()};

    QByteArray oauthSignature {QMessageAuthenticationCode::hash(signatureBaseString, signingKey, QCryptographicHash::Sha1).toBase64()};
    encodedParams.insert(QByteArray("oauth_signature").toPercentEncoding(), oauthSignature.toPercentEncoding());

    // now generate the Authorization header from the encoded parameters map.
    // we need to remove the query items from the encoded parameters map first.
    QByteArray authHeader = QByteArray("OAuth ");

    for (const std::pair<QByteArray, QByteArray> &parameter : parameters) {
        encodedParams.remove(parameter.first);
    }
    keys = encodedParams.keys();
    foreach (const QByteArray &key, keys) {
        authHeader += key + "=\"" + encodedParams.value(key) + "\", ";
    } 
Esempio n. 6
0
QByteArray vCardParam::toByteArray(vCardVersion version) const
{
    QByteArray buffer;

    switch (version)
    {
        case VC_VER_2_1:
        {
            switch (m_group)
            {
                case vCardParam::Charset:
                    buffer.append(QString(VC_GROUP_TOKEN).arg(VC_CHARSET_TOKEN).arg(m_value));
                    break;

                case vCardParam::Encoding:
                    buffer.append(QString(VC_GROUP_TOKEN).arg(VC_ENCODING_TOKEN).arg(m_value));
                    break;

                default:
                    buffer.append(m_value);
                    break;
            }
            break;
        }
        break;

        case VC_VER_3_0:
        {
            switch (m_group)
            {
                case vCardParam::Type:
                    buffer.append(QString(VC_GROUP_TOKEN).arg(VC_TYPE_TOKEN).arg(m_value));
                    break;

                case vCardParam::Charset:
                    buffer.append(QString(VC_GROUP_TOKEN).arg(VC_CHARSET_TOKEN).arg(m_value));
                    break;

                case vCardParam::Encoding:
                    buffer.append(QString(VC_GROUP_TOKEN).arg(VC_ENCODING_TOKEN).arg(m_value));
                    break;

                default:
                    buffer.append(m_value);
                    break;
            }
        }
        break;

        default:
            break;
    }

    return buffer.toUpper();
}
Esempio n. 7
0
bool QImageLoader::save(const QString& filePath, DImgLoaderObserver* const observer)
{
    QVariant qualityAttr = imageGetAttribute(QLatin1String("quality"));
    int quality          = qualityAttr.isValid() ? qualityAttr.toInt() : 90;

    if (quality < 0)
    {
        quality = 90;
    }

    if (quality > 100)
    {
        quality = 100;
    }

    QVariant formatAttr = imageGetAttribute(QLatin1String("format"));
    QByteArray format   = formatAttr.toByteArray();
    QImage image        = m_image->copyQImage();

    if (observer)
    {
        observer->progressInfo(m_image, 0.1F);
    }

    // Saving is opaque to us. No support for stopping from observer,
    // progress info are only pseudo values
    bool success = image.save(filePath, format.toUpper().constData(), quality);

    if (observer && success)
    {
        observer->progressInfo(m_image, 1.0F);
    }

    imageSetAttribute(QLatin1String("format"), format.toUpper());

    saveMetadata(filePath);

    return success;
}
static inline bool detectKDEDesktopIsRunning()
{
    const QByteArray xdgCurrentDesktop = qgetenv("XDG_CURRENT_DESKTOP");

    if (!xdgCurrentDesktop.isEmpty())
        return (xdgCurrentDesktop.toUpper() == "KDE");

    // Classic fallbacks

    if (!qgetenv("KDE_FULL_SESSION").isEmpty())
        return true;

    return false;
}
void BestPositionFindTask::run() {
    U2SequenceObject dnaSeq("sequence", sequenceRef);
    QByteArray sequence = dnaSeq.getWholeSequenceData(stateInfo);
    CHECK_OP(stateInfo, );

    if(sequence.isEmpty()) {
        return;
    }
    if(!inputMsa->getAlphabet()->isCaseSensitive()) {
        sequence = sequence.toUpper();
    }
    const int aliLen = inputMsa->getLength();
    const int nSeq = inputMsa->getNumRows();

    int similarity = 0;

    if(referenceRowId >= 0) {
        const MultipleSequenceAlignmentRow row = inputMsa->getMsaRow(referenceRowId);
        int iterationsNum = aliLen - sequence.length() + 1;
        for (int p = 0; p < iterationsNum; p++ ) {
            stateInfo.setProgress(100 * p / iterationsNum);
            char c = row->charAt(p);
            int selLength = 0;
            int patternSimilarity = MSAUtils::getPatternSimilarityIgnoreGaps(row, p, sequence, selLength);
            if (U2Msa::GAP_CHAR != c && patternSimilarity > similarity) {
                similarity = patternSimilarity;
                bestPosition = p;
            }
        }
    } else {
        int processedRows = 0;
        foreach(const MultipleSequenceAlignmentRow &row, inputMsa->getMsaRows()) {
            stateInfo.setProgress(100 * processedRows / nSeq);
            for (int p = 0; p < ( aliLen - sequence.length() + 1 ); p++ ) {
                char c = row->charAt(p);
                int selLength = 0;
                int patternSimilarity = MSAUtils::getPatternSimilarityIgnoreGaps(row, p, sequence, selLength);
                if (U2Msa::GAP_CHAR != c && patternSimilarity > similarity) {
                    similarity = patternSimilarity;
                    bestPosition = p;
                }
            }
            processedRows++;
        }
    }
}
Esempio n. 10
0
void MainWindow::export_as()
{
   QAction *action = qobject_cast<QAction *>(sender());
   QByteArray fileFormat = action->data().toByteArray();
   QString initialPath = QDir::currentPath() + "/map." + fileFormat;

   QString fileName = QFileDialog::getSaveFileName(this, tr("Export As"),
                                                   initialPath,
                                                   tr("%1 Files (*.%2);;All Files (*)")
                                                   .arg(QString(fileFormat.toUpper()))
                                                   .arg(QString(fileFormat)));
   if (!fileName.isEmpty()) 
   {
      QPixmap const& pix = mapWidget_->pixmap();
      pix.save(fileName);
   }
}
void CurrencyPairItem::setSymbol(QByteArray symb)
{
    symbol=symb.toUpper();
    if(symbol.size()!=6){symbol.clear();return;}

    currAStr=symbol.left(3);
	currAStrLow=currAStr.toLower();

    currBStr=symbol.right(3);
	currBStrLow=currBStr.toLower();


	currAInfo=baseValues_->currencyMap.value(currAStr,CurencyInfo("$"));
	currBInfo=baseValues_->currencyMap.value(currBStr,CurencyInfo("$"));
	
	currASign=currAInfo.sign;
	currBSign=currBInfo.sign;

	currAName=currAInfo.name;
}
Esempio n. 12
0
static inline QByteArray detectDesktopEnvironment()
{
    const QByteArray xdgCurrentDesktop = qgetenv("XDG_CURRENT_DESKTOP");
    if (!xdgCurrentDesktop.isEmpty())
        return xdgCurrentDesktop.toUpper(); // KDE, GNOME, UNITY, LXDE, MATE, XFCE...

    // Classic fallbacks
    if (!qEnvironmentVariableIsEmpty("KDE_FULL_SESSION"))
        return QByteArrayLiteral("KDE");
    if (!qEnvironmentVariableIsEmpty("GNOME_DESKTOP_SESSION_ID"))
        return QByteArrayLiteral("GNOME");

    // Fallback to checking $DESKTOP_SESSION (unreliable)
    const QByteArray desktopSession = qgetenv("DESKTOP_SESSION");
    if (desktopSession == "gnome")
        return QByteArrayLiteral("GNOME");
    if (desktopSession == "xfce")
        return QByteArrayLiteral("XFCE");

    return QByteArrayLiteral("UNKNOWN");
}
Esempio n. 13
0
static inline QByteArray detectDesktopEnvironment()
{
    const QByteArray xdgCurrentDesktop = qgetenv("XDG_CURRENT_DESKTOP");
    if (!xdgCurrentDesktop.isEmpty())
        // See http://standards.freedesktop.org/menu-spec/latest/apb.html
        return xdgCurrentDesktop.toUpper(); 

    // Classic fallbacks
    if (!qEnvironmentVariableIsEmpty("KDE_FULL_SESSION"))
        return QByteArrayLiteral("KDE");
    if (!qEnvironmentVariableIsEmpty("GNOME_DESKTOP_SESSION_ID"))
        return QByteArrayLiteral("GNOME");

    // Fallback to checking $DESKTOP_SESSION (unreliable)
    const QByteArray desktopSession = qgetenv("DESKTOP_SESSION");
    if (desktopSession == "gnome")
        return QByteArrayLiteral("GNOME");
    if (desktopSession == "xfce")
        return QByteArrayLiteral("XFCE");

    return QByteArrayLiteral("UNKNOWN");
}
Esempio n. 14
0
ImapMailbox *ImapPrivate::parseMailbox (const QString& mailboxName) {
    ImapMailbox *mailbox = NULL;       
    

    QByteArray response = readLine();
    //QByteArray response = socket->readAll().data();


    if (response.startsWith(IMAP_TAG) ||  response.startsWith('*')) {
        QRegExp regexUnseen("\\[UNSEEN (\\d+)\\]");
        QRegExp regexExists("(\\d+) EXISTS");
        QRegExp regexRecent("(\\d+) RECENT");
        QRegExp regexFlags(" FLAGS \\((.*)\\)");
        
        mailbox = new ImapMailbox(mailboxName);
        do {
            if (regexExists.indexIn(response) != -1) {
                mailbox->setExists(regexExists.cap(1).toInt());
            } else if (regexRecent.indexIn(response) != -1) {
                mailbox->setRecent(regexRecent.cap(1).toInt());
            } else if (regexFlags.indexIn(response) != -1) {
                mailbox->setFlags(regexFlags.cap(1));
            } else if (regexUnseen.indexIn(response) != -1) {
                mailbox->setUnseen(regexUnseen.cap(1).toInt());
            }
            
            response = readLine();
        } while (response.startsWith('*'));
        
        response = response.toUpper();
        if (isResponseOk(response) &&
           (response.contains("READ/WRITE") || response.contains("READ-WRITE")))
        {
            mailbox->setReadWrite(true);
        }
    }
    
    return(mailbox);
}
Esempio n. 15
0
QByteArray Driver::escapeIdentifier(const QByteArray& str, int options) const
{
    if (options & EscapeKexi) {
        return KexiDB::escapeIdentifier(str, options);
    }

    bool needOuterQuotes = false;

// Need to use quotes if ...
// ... we have been told to, or ...
    if (options & EscapeAlways)
        needOuterQuotes = true;

// ... or if the driver does not have a list of keywords,
    else if (d->driverSpecificSQLKeywords.isEmpty())
        needOuterQuotes = true;

// ... or if it's a keyword in Kexi's SQL dialect,
    else if (KexiDB::isKexiSQLKeyword(str))
        needOuterQuotes = true;

// ... or if it's a keyword in the backends SQL dialect,
    else if ((options & EscapeDriver) && d->driverSpecificSQLKeywords.contains(str.toUpper()))
        needOuterQuotes = true;

// ... or if the identifier has a space in it...
    else if (str.contains(' '))
        needOuterQuotes = true;

    if (needOuterQuotes) {
        const char quote = beh->QUOTATION_MARKS_FOR_IDENTIFIER.toLatin1();
        return quote + drv_escapeIdentifier(str) + quote;
    } else {
        return drv_escapeIdentifier(str);
    }
}
Esempio n. 16
0
QByteArray UmlOperation::compute_name(QByteArray s)
{
    if (!s.isEmpty()) {
        UmlClassMember * m = getOf();

        if ((m != 0) || ((m = setOf()) != 0)) {
            QByteArray n = (m->kind() == aRelation)
                          ? ((UmlRelation *) m)->roleName()
                          : m->name();
            int index;

            if ((index = s.indexOf("${name}")) != -1)
                return s.left(index) + n + s.mid(index + 7);
            else if ((index = s.indexOf("${Name}")) != -1)
                return s.left(index) + n.left(1).toUpper() + n.mid(1) + s.mid(index + 7);
            else if ((index = s.indexOf("${NAME}")) != -1)
                return s.left(index) + n.toUpper() + s.mid(index + 7);
            else
                return s;
        }
    }

    return name();
}
Esempio n. 17
0
void QHexEditPrivate::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);

    // draw some patterns if needed
    painter.fillRect(event->rect(), this->palette().color(QPalette::Base));
    if (_addressArea)
        painter.fillRect(QRect(_xPosAdr, event->rect().top(), _xPosHex - GAP_ADR_HEX + 2, height()), _addressAreaColor);
    if (_asciiArea)
    {
        int linePos = _xPosAscii - (GAP_HEX_ASCII / 2);
        painter.setPen(Qt::gray);
        painter.drawLine(linePos, event->rect().top(), linePos, height());
    }

    painter.setPen(this->palette().color(QPalette::WindowText));

    // calc position
    int firstLineIdx = ((event->rect().top()/ _charHeight) - _charHeight) * BYTES_PER_LINE;
    if (firstLineIdx < 0)
        firstLineIdx = 0;
    int lastLineIdx = ((event->rect().bottom() / _charHeight) + _charHeight) * BYTES_PER_LINE;
    if (lastLineIdx > _xData.size())
        lastLineIdx = _xData.size();
    int yPosStart = ((firstLineIdx) / BYTES_PER_LINE) * _charHeight + _charHeight;

    // paint address area
    if (_addressArea)
    {
        for (int lineIdx = firstLineIdx, yPos = yPosStart; lineIdx < lastLineIdx; lineIdx += BYTES_PER_LINE, yPos +=_charHeight)
        {
            QString address = QString("%1")
                              .arg(lineIdx + _xData.addressOffset(), _xData.realAddressNumbers(), 16, QChar('0'));
            painter.drawText(_xPosAdr, yPos, address);
        }
    }

    // paint hex area
    QByteArray hexBa(_xData.data().mid(firstLineIdx, lastLineIdx - firstLineIdx + 1).toHex());
    QBrush highLighted = QBrush(_highlightingColor);
    QPen colHighlighted = QPen(this->palette().color(QPalette::WindowText));
    QBrush selected = QBrush(_selectionColor);
    QPen colSelected = QPen(Qt::white);
    QPen colStandard = QPen(this->palette().color(QPalette::WindowText));

    painter.setBackgroundMode(Qt::TransparentMode);

    for (int lineIdx = firstLineIdx, yPos = yPosStart; lineIdx < lastLineIdx; lineIdx += BYTES_PER_LINE, yPos +=_charHeight)
    {
        QByteArray hex;
        int xPos = _xPosHex;
        for (int colIdx = 0; ((lineIdx + colIdx) < _xData.size() && (colIdx < BYTES_PER_LINE)); colIdx++)
        {
            int posBa = lineIdx + colIdx;
            if ((getSelectionBegin() <= posBa) && (getSelectionEnd() > posBa))
            {
                painter.setBackground(selected);
                painter.setBackgroundMode(Qt::OpaqueMode);
                painter.setPen(colSelected);
            }
            else
            {
                if (_highlighting)
                {
                    // hilight diff bytes
                    painter.setBackground(highLighted);
                    if (_xData.dataChanged(posBa))
                    {
                        painter.setPen(colHighlighted);
                        painter.setBackgroundMode(Qt::OpaqueMode);
                    }
                    else
                    {
                        painter.setPen(colStandard);
                        painter.setBackgroundMode(Qt::TransparentMode);
                    }
                }
            }

            // render hex value
            if (colIdx == 0)
            {
                hex = hexBa.mid((lineIdx - firstLineIdx) * 2, 2);
                painter.drawText(xPos, yPos, hex.toUpper());
                xPos += 2 * _charWidth;
            } else {
                hex = hexBa.mid((lineIdx + colIdx - firstLineIdx) * 2, 2).prepend(" ");
                painter.drawText(xPos, yPos, hex.toUpper());
                xPos += 3 * _charWidth;
            }

        }
    }
    painter.setBackgroundMode(Qt::TransparentMode);
    painter.setPen(this->palette().color(QPalette::WindowText));

    // paint ascii area
    if (_asciiArea)
    {
        for (int lineIdx = firstLineIdx, yPos = yPosStart; lineIdx < lastLineIdx; lineIdx += BYTES_PER_LINE, yPos +=_charHeight)
        {
            int xPosAscii = _xPosAscii;
            for (int colIdx = 0; ((lineIdx + colIdx) < _xData.size() && (colIdx < BYTES_PER_LINE)); colIdx++)
            {
                painter.drawText(xPosAscii, yPos, _xData.asciiChar(lineIdx + colIdx));
                xPosAscii += _charWidth;
            }
        }
    }

    // paint cursor
    if (_blink && !_readOnly && hasFocus())
    {
        if (_overwriteMode)
            painter.fillRect(_cursorX, _cursorY + _charHeight - 2, _charWidth, 2, this->palette().color(QPalette::WindowText));
        else
            painter.fillRect(_cursorX, _cursorY, 2, _charHeight, this->palette().color(QPalette::WindowText));
    }

    if (_size != _xData.size())
    {
        _size = _xData.size();
        emit currentSizeChanged(_size);
    }
}
Esempio n. 18
0
/*! parse an ADIF record
 *
 * the first record found in data is returned as a SQL log record
 * Designed for WSJTX ADIF ouput, may not work well on more general
 *   ADIF sources.
 *  @todo validate each field and return a bool
 */
bool ADIFParse::parse(QByteArray data, Qso *qso)
{
    const QByteArray token_names[] = { "CALL",
                                       "GRIDSQUARE",
                                       "MODE",
                                       "QSO_DATE_OFF",
                                       "TIME_OFF",
                                       "BAND",
                                       "FREQ"};
    const int n_token_names = 7;

    // only common and WSJTX modes will be matched
    const QByteArray mode_name[] = { "AM",
                                     "CW",
                                     "FM",
                                     "SSB",
                                     "USB",
                                     "LSB",
                                     "FT8",
                                     "ISCAT",
                                     "JT4",
                                     "JT9",
                                     "JT65",
                                     "MSK144",
                                     "QRA64",
                                     "RTTY"};
    const rmode_t modes[] = { RIG_MODE_AM,
                              RIG_MODE_CW,
                              RIG_MODE_FM,
                              RIG_MODE_USB,
                              RIG_MODE_USB,
                              RIG_MODE_LSB,
                              RIG_MODE_RTTY,
                              RIG_MODE_RTTY,
                              RIG_MODE_RTTY,
                              RIG_MODE_RTTY,
                              RIG_MODE_RTTY,
                              RIG_MODE_RTTY,
                              RIG_MODE_RTTY,
                              RIG_MODE_RTTY};
    const int n_mode_names=14;

    // bands are in the same order as in defines.h
    const QByteArray band_name[]= { "160M",
                                    "80M",
                                    "40M",
                                    "20M",
                                    "15M",
                                    "10M",
                                    "60M",
                                    "30M",
                                    "17M",
                                    "12M",
                                    "6M",
                                    "2M",
                                    "1.25M",
                                    "70CM",
                                    "33CM",
                                    "23CM"};

    qso->clear();
    data=data.toUpper();
    int end=data.indexOf("<EOR>");
    int start=data.indexOf("<EOH>");
    if (start==-1) {
        start=0;
    } else {
        start+=5;
    }
    data=data.mid(start,end-start);
    QList<QByteArray>elements=data.split('<');

    QDateTime time;
    time.setTimeSpec(Qt::UTC);
    QByteArray key,val;
    for (int i=0;i<elements.size();i++) {
        parseBit(elements.at(i),key,val);
        for (int j = 0; j < n_token_names; j++) {
            if (key == token_names[j]) {
                switch (j) {
                case 0:  // CALL
                    qso->call=val;
                    break;
                case 1: // GRID
                    qso->exch=val;
                    qso->rcv_exch[0]=val;
                    break;
                case 2: // MODE
                {
                    for (int k=0;k<n_mode_names;k++) {
                        if (val==mode_name[k]) {
                            qso->mode=modes[k];
                            qso->modeType=getModeType(modes[k]);
                            break;
                        }
                    }
                    break;
                }
                case 3: // DATE
                {
                    int y=val.mid(0,4).toInt();
                    int m=val.mid(4,2).toInt();
                    int d=val.mid(6,2).toInt();
                    time.setDate(QDate(y, m, d));
                    break;
                }
                case 4: // TIME
                {
                    int h=val.mid(0,2).toInt();
                    int m=val.mid(2,2).toInt();
                    int s=0;
                    if (val.size()==6) {
                        s=val.mid(4,2).toInt();
                    }
                    time.setTime(QTime(h,m,s));
                    break;
                }
                case 5: // BAND
                {
                    for (int k=0;k<N_BANDS;k++) {
                        if (val==band_name[k]) {
                            qso->band=k;
                            break;
                        }
                    }
                    break;
                }
                case 6: // FREQ
                    qso->freq=val.toDouble()*1000000;
                    break;
                }
            }
        }
    }
    qso->time=time;
    return true;
}
Esempio n. 19
0
void Wms::getMap( const QString &image_format, const QString &layers, const QSize &image_size, const BoundingBox &bbox) {

  // check the validity of the input parameters
  
  // bbox
  // TODO
  qDebug() << /*"BBOX : "  <<*/ bbox;


  // layers
  if (layers.isEmpty()) {
    serviceException(
      "noLayers",
      "no layers specified");
    return;
  }
  QStringList layer_names = layers.split(",");
  QStringList layer_names_cleaned;
  for (int i=0; i<layer_names.size(); ++i) {
    QString layer_name = layer_names.at(i).trimmed();
    
    if (!layer_name.isEmpty()) {
      if (renderer.map.hasLayer(layer_name)) {
        layer_names_cleaned.append(layer_name);  
      }
      else {
        serviceException(
          "layerDoesNotExist",
          "one of the layers does not exist");
        return;       
      }
    }
  }

  // format
  QByteArray renderformat;
  QList<QByteArray> supported_formats = renderer.getImageFormats();
  if (image_format == MIMETYPE_PNG) {
    renderformat = "png";  
  }
  else if (image_format == MIMETYPE_JPG) {
    renderformat = "jpeg";  
  }
  else if (image_format == MIMETYPE_TIF) {
    renderformat = "tiff";  
  };

  if (renderformat.isEmpty() || !supported_formats.contains(renderformat.data())) {
    serviceException(
      "formatNotsupported",
      "the imageformat is not supported");
    return;
  }


  // render
  renderer.map.setVisibleLayers(layer_names_cleaned);

  QByteArray bytes;
  QBuffer buffer(&bytes); // write binary data
  buffer.open(QIODevice::WriteOnly);

  if (renderer.render( buffer, renderformat.toUpper(), image_size)) {

    m_request->setHeader(HTTP_CONTENT_TYPE, image_format.toUtf8());
    QByteArray content_length = QByteArray::number(bytes.length());
    m_request->setHeader(HTTP_CONTENT_LEN, content_length );
    m_request->write(bytes);
  }
  else {
    serviceException(
      "renderError",
      "could not render the image - this should realy not happen, sorry");
    return;
  }
}
Esempio n. 20
0
void QHexEdit::paintEvent(QPaintEvent *event)
{
    QPainter painter(viewport());
    int pxOfsX = horizontalScrollBar()->value();

    if (event->rect() != _cursorRect)
    {
        int pxPosStartY = _pxCharHeight;

        // draw some patterns if needed
        painter.fillRect(event->rect(), viewport()->palette().color(QPalette::Base));
        if (_addressArea)
            painter.fillRect(QRect(-pxOfsX, event->rect().top(), _pxPosHexX - _pxGapAdrHex/2, height()), _addressAreaColor);
        if (_asciiArea)
        {
            int linePos = _pxPosAsciiX - (_pxGapHexAscii / 2);
            painter.setPen(Qt::gray);
            painter.drawLine(linePos - pxOfsX, event->rect().top(), linePos - pxOfsX, height());
        }

        painter.setPen(viewport()->palette().color(QPalette::WindowText));

        // paint address area
        if (_addressArea)
        {
            QString address;
            for (int row=0, pxPosY = _pxCharHeight; row <= (_dataShown.size()/_bytesPerLine); row++, pxPosY +=_pxCharHeight)
            {
                address = QString("%1").arg(_bPosFirst + row*_bytesPerLine + _addressOffset, _addrDigits, 16, QChar('0'));
                painter.drawText(_pxPosAdrX - pxOfsX, pxPosY, address);
            }
        }

        // paint hex and ascii area
        QPen colStandard = QPen(viewport()->palette().color(QPalette::WindowText));

        painter.setBackgroundMode(Qt::TransparentMode);

        for (int row = 0, pxPosY = pxPosStartY; row <= _rowsShown; row++, pxPosY +=_pxCharHeight)
        {
            QByteArray hex;
            int pxPosX = _pxPosHexX  - pxOfsX;
            int pxPosAsciiX2 = _pxPosAsciiX  - pxOfsX;
            qint64 bPosLine = row * _bytesPerLine;
            for (int colIdx = 0; ((bPosLine + colIdx) < _dataShown.size() && (colIdx < _bytesPerLine)); colIdx++)
            {
                QColor c = viewport()->palette().color(QPalette::Base);
                painter.setPen(colStandard);

                qint64 posBa = _bPosFirst + bPosLine + colIdx;
                if ((getSelectionBegin() <= posBa) && (getSelectionEnd() > posBa))
                {
                    c = _brushSelection.color();
                    painter.setPen(_penSelection);
                }
                else
                {
                    if (_highlighting)
                        if (_markedShown.at((int)(posBa - _bPosFirst)))
                        {
                            c = _brushHighlighted.color();
                            painter.setPen(_penHighlighted);
                        }
                }

                // render hex value
                QRect r;
                if (colIdx == 0)
                    r.setRect(pxPosX, pxPosY - _pxCharHeight + _pxSelectionSub, 2*_pxCharWidth, _pxCharHeight);
                else
                    r.setRect(pxPosX - _pxCharWidth, pxPosY - _pxCharHeight + _pxSelectionSub, 3*_pxCharWidth, _pxCharHeight);
                painter.fillRect(r, c);
                hex = _hexDataShown.mid((bPosLine + colIdx) * 2, 2);
                painter.drawText(pxPosX, pxPosY, hexCaps()?hex.toUpper():hex);
                pxPosX += 3*_pxCharWidth;

                // render ascii value
                if (_asciiArea)
                {
                    int ch = (uchar)_dataShown.at(bPosLine + colIdx);
                    if ( ch < ' ' || ch > '~' )
                        ch = '.';
                    r.setRect(pxPosAsciiX2, pxPosY - _pxCharHeight + _pxSelectionSub, _pxCharWidth, _pxCharHeight);
                    painter.fillRect(r, c);
                    painter.drawText(pxPosAsciiX2, pxPosY, QChar(ch));
                    pxPosAsciiX2 += _pxCharWidth;
                }
            }
        }
        painter.setBackgroundMode(Qt::TransparentMode);
        painter.setPen(viewport()->palette().color(QPalette::WindowText));
    }

    // _cursorPosition counts in 2, _bPosFirst counts in 1
    int hexPositionInShowData = _cursorPosition - 2 * _bPosFirst;

    // due to scrolling the cursor can go out of the currently displayed data
    if ((hexPositionInShowData >= 0) && (hexPositionInShowData < _hexDataShown.size()))
    {
            // paint cursor
            if (_readOnly)
            {
                // make the background stick out
                QColor color = viewport()->palette().dark().color();
                painter.fillRect(QRect(_pxCursorX - pxOfsX, _pxCursorY - _pxCharHeight + _pxSelectionSub, _pxCharWidth, _pxCharHeight), color);
            }
            else
            {
                if (_blink && hasFocus())
                    painter.fillRect(_cursorRect, this->palette().color(QPalette::WindowText));
            }

            if (_editAreaIsAscii)
            {
                // every 2 hex there is 1 ascii
                int asciiPositionInShowData = hexPositionInShowData / 2;
                int ch = (uchar)_dataShown.at(asciiPositionInShowData);
                if (ch < ' ' || ch > '~')
                    ch = '.';
                painter.drawText(_pxCursorX - pxOfsX, _pxCursorY, QChar(ch));
            }
            else
            {
                painter.drawText(_pxCursorX - pxOfsX, _pxCursorY, _hexDataShown.mid(hexPositionInShowData, 1));
            }
    }

    // emit event, if size has changed
    if (_lastEventSize != _chunks->size())
    {
        _lastEventSize = _chunks->size();
        emit currentSizeChanged(_lastEventSize);
    }
}
Esempio n. 21
0
int
StarDictDictionaryManager::lookupSimilarWord(QByteArray searchWord, int iLib)
{
    int iIndex;

    // Upper case lookup
    iIndex = d->dictionaryList.at(iLib)->lookup(searchWord.toUpper());

    // Lower case lookup
    if (iIndex == -1)
        iIndex = d->dictionaryList.at(iLib)->lookup(searchWord.toLower());

    // Upper the first character and lower others
    if (!iIndex == -1)
        iIndex = d->dictionaryList.at(iLib)->lookup(QString(QString(searchWord)[0].toUpper()) + searchWord.mid(1).toLower());

    if (isPureEnglish(searchWord))
    {
        QString caseString;
        // If not Found, try other status of searchWord.
        int searchWordLength = searchWord.size();
        bool isUpperCase;
        QByteArray searchNewWord;

        lookupPattern(searchWord, iLib, "S", 1, 1, QString(), false);
        lookupPattern(searchWord, iLib, "ED", 1, 1, QString(), false);
        lookupPattern(searchWord, iLib, "LY", 2, 2, QString(), true);
        lookupPattern(searchWord, iLib, "ING", 3, 3, "E", true);


        if (iIndex == -1 && searchWordLength > 3)
        {
            isUpperCase = (searchWord.endsWith("ES") //krazy:exclude=strings
                        && (searchWord.at(searchWordLength - 3) == 'S'
                        || searchWord.at(searchWordLength - 3) == 'X'
                        || searchWord.at(searchWordLength - 3) == 'O'
                        || (searchWordLength > 4 && searchWord.at(searchWordLength - 3) == 'H'
                        && (searchWord.at(searchWordLength - 4) == 'C'
                        || searchWord.at(searchWordLength - 4) == 'S'))));

            if (isUpperCase ||
                    (searchWord.endsWith("es") //krazy:exclude=strings
                     && (searchWord.at(searchWordLength - 3) == 's'
                     || searchWord.at(searchWordLength - 3) == 'x'
                     || searchWord.at(searchWordLength - 3) == 'o'
                     || (searchWordLength > 4 && searchWord.at(searchWordLength - 3) == 'h'
                     && (searchWord.at(searchWordLength - 4) == 'c'
                     || searchWord.at(searchWordLength - 4) == 's')))))
            {
                searchNewWord = searchWord.left(searchWordLength - 2);
                if ((iIndex = d->dictionaryList.at(iLib)->lookup(searchNewWord)) == -1
                    && (isUpperCase || QString::fromUtf8(searchWord).at(0).isUpper()))
                {
                    caseString = searchNewWord.toLower();
                    if (caseString.compare(searchNewWord))
                    {
                        iIndex = d->dictionaryList.at(iLib)->lookup(caseString);
                    }
                }
            }
        }

        lookupPattern(searchWord, iLib, "ED", 3, 2, QString(), true);
        lookupPattern(searchWord, iLib, "IED", 3, 3, "Y", false);
        lookupPattern(searchWord, iLib, "IES", 3, 3, "Y", false);
        lookupPattern(searchWord, iLib, "ER", 2, 3, QString(), false);
        lookupPattern(searchWord, iLib, "EST", 3, 3, QString(), false);

    }

#if 0
    else
    {
        //don't change iWordIndex here.
        //when LookupSimilarWord all failed too, we want to use the old LookupWord index to list words.
        //iWordIndex = invalidIndex;
    }
#endif
    return iIndex;
}
Esempio n. 22
0
QDbfRecord QDbfTablePrivate::record() const
{
    if (m_bufered) {
        return m_currentRecord;
    }

    m_currentRecord = m_record;
    m_bufered = true;

    if (m_currentIndex < QDbfTablePrivate::FirstRow) {
        return m_currentRecord;
    }

    if (!isOpen()) {
        qWarning("QDbfTablePrivate::record(): IODevice is not open");
        return m_currentRecord;
    }

    if (!m_file.isReadable()) {
        m_error = QDbfTable::ReadError;
        return m_currentRecord;
    }

    const qint64 position = m_headerLength + m_recordLength * m_currentIndex;

    if (!m_file.seek(position)) {
        m_error = QDbfTable::ReadError;
        return m_currentRecord;
    }

    m_currentRecord.setRecordIndex(m_currentIndex);

    const QByteArray recordData = m_file.read(m_recordLength);

    if (recordData.count() == 0) {
        m_error = QDbfTable::UnspecifiedError;
        return m_currentRecord;
    }

    m_currentRecord.setDeleted(recordData.at(0) == '*' ? true : false);

    for (int i = 0; i < m_currentRecord.count(); ++i) {
        const QByteArray byteArray = recordData.mid(m_currentRecord.field(i).offset(),
                                                    m_currentRecord.field(i).length());
        QVariant value;
        switch (m_currentRecord.field(i).type()) {
        case QVariant::String:
            value = m_textCodec->toUnicode(byteArray);
            break;
        case QVariant::Date:
            value = QVariant(QDate(byteArray.mid(0, 4).toInt(),
                                   byteArray.mid(4, 2).toInt(),
                                   byteArray.mid(6, 2).toInt()));
            break;
        case QVariant::Double:
            value = byteArray.toDouble();
            break;
        case QVariant::Bool: {
            QString val = QString::fromLatin1(byteArray.toUpper());
            if (val == QLatin1String("T") ||
                val == QLatin1String("Y")) {
                value = true;
            } else {
                value = false;
            }
            break; }
        default:
            value = QVariant::Invalid;
        }

        m_currentRecord.setValue(i, value);
    }

    m_error = QDbfTable::NoError;

    return m_currentRecord;
}
Esempio n. 23
0
void SetQuotaJob::setQuota(const QByteArray &resource, qint64 limit)
{
  Q_D( SetQuotaJob );

  d->setList[resource.toUpper()] = limit;
}
Esempio n. 24
0
bool CvsLoginJob::execute()
{
    static QByteArray repository;

    int res = m_Proc->exec(m_CvsClient, m_Arguments);
    if( res < 0 )
    {
        qCDebug(log_cervisia) << "Couldn't start 'cvs login' process!";
        return false;
    }

    bool result = false;
    while( true )
    {
        QByteArray line = m_Proc->readLine();
        if( line.isNull() )
        {
            return result;
        }

        // add line to output list
        m_output << line;
        qCDebug(log_cervisia) << "process output = " << line;

        // retrieve repository from 'Logging in to'-line
        if( line.contains(LOGIN_PHRASE) )
        {
            repository = line.remove(0, line.indexOf(":pserver:"));
            continue;
        }

        // process asks for the password
        // search case insensitive as cvs and cvsnt use different capitalization
        if( line.toUpper().contains(PASS_PHRASE) )
        {

            // show password dialog
            QString password;
            KPasswordDialog dlg;
            dlg.setPrompt(i18n("Enter password for repository %1.").arg(QString::fromLocal8Bit(repository)));
            if( dlg.exec() )
            {
                password = dlg.password();
                // send password to process
                m_Proc->waitSlave();
                m_Proc->writeLine(password.toLocal8Bit());

                // wait for the result
                while( !line.contains(FAILURE_PHRASE) )
                {
                    line = m_Proc->readLine();
                    if( line.isNull() )
                        return true;

                    // add line to output list
                    m_output << line;
                    qCDebug(log_cervisia) << "process output = " << line;
                }

                result = false;
            }
            else
            {
                // user pressed cancel so kill the process
                kill(m_Proc->pid(), SIGKILL);
                m_Proc->waitForChild();
                result = false;
            }
        }
    }
    return false;
}