void KTextCursor::insertHtml( const QString &text, const QMap<QString, QString>& imgs ) { if(!imgs.isEmpty()) { for(QMap<QString,QString>::const_iterator iter = imgs.begin(); iter != imgs.end(); iter++) { QString key = iter.key(); QString file = iter.value(); if(moviePool()->insertMovie(file, file)) { //修改属性为动画。 document()->addResource(QTextDocument::ImageResource, QUrl(file), moviePool()->currentImage(file)); } else { QImage image(file); if(!image.isNull()) { document()->addResource(QTextDocument::ImageResource, QUrl(file), image); } } } } int istart = position(); insertHtml(text); int inow = position(); if(!imgs.isEmpty() && inow > istart) { setPosition(istart); movePosition(NextCharacter, KeepAnchor, inow-istart); QString txt = selectedText(); int index = txt.indexOf(QChar::ObjectReplacementCharacter, 0); while(index >= 0) { /*修改字体类型。*/ setPosition(istart+index); movePosition(NextCharacter, KeepAnchor, 1); QTextCharFormat fmt = charFormat(); QTextImageFormat imgFmt = fmt.toImageFormat(); QString key = imgFmt.name(); if(imgs.contains(key)) { imgFmt.setProperty(KImageKey, key); imgFmt.setName(imgs.value(key)); imgFmt.setProperty(KAnimationImage, true); setCharFormat(imgFmt); } int idx = index+1; index = txt.indexOf(QChar::ObjectReplacementCharacter, idx); } } setPosition(inow); }
QString QgsProjectionSelector::ogcWmsCrsFilterAsSqlExpression( QSet<QString> * crsFilter ) { QString sqlExpression = "1"; // it's "SQL" for "true" QMap<QString, QStringList> authParts; if ( !crsFilter ) return sqlExpression; /* Ref: WMS 1.3.0, section 6.7.3 "Layer CRS": Every Layer CRS has an identifier that is a character string. Two types of Layer CRS identifiers are permitted: "label" and "URL" identifiers: Label: The identifier includes a namespace prefix, a colon, a numeric or string code, and in some instances a comma followed by additional parameters. This International Standard defines three namespaces: CRS, EpsgCrsId and AUTO2 [...] URL: The identifier is a fully-qualified Uniform Resource Locator that references a publicly-accessible file containing a definition of the CRS that is compliant with ISO 19111. */ // iterate through all incoming CRSs Q_FOREACH ( const QString& auth_id, *crsFilter ) { QStringList parts = auth_id.split( ':' ); if ( parts.size() < 2 ) continue; authParts[ parts.at( 0 ).toUpper()].append( parts.at( 1 ).toUpper() ); } if ( authParts.isEmpty() ) return sqlExpression; if ( !authParts.isEmpty() ) { QString prefix = " AND ("; Q_FOREACH ( const QString& auth_name, authParts.keys() ) { sqlExpression += QString( "%1(upper(auth_name)='%2' AND upper(auth_id) IN ('%3'))" ) .arg( prefix, auth_name, authParts[auth_name].join( "','" ) ); prefix = " OR "; } sqlExpression += ')'; }
ParagraphFormatProperty StyleParser::parseParagraphProperty( QDomElement &parent ) { ParagraphFormatProperty property; property.setPageNumber( parent.attribute( "page-number" ).toInt() ); static QMap<QString, ParagraphFormatProperty::WritingMode> map; if ( map.isEmpty() ) { map.insert( "lr-tb", ParagraphFormatProperty::LRTB ); map.insert( "rl-tb", ParagraphFormatProperty::RLTB ); map.insert( "tb-rl", ParagraphFormatProperty::TBRL ); map.insert( "tb-lr", ParagraphFormatProperty::TBLR ); map.insert( "lr", ParagraphFormatProperty::LR ); map.insert( "rl", ParagraphFormatProperty::RL ); map.insert( "tb", ParagraphFormatProperty::TB ); map.insert( "page", ParagraphFormatProperty::PAGE ); } property.setWritingMode( map[ parent.attribute( "writing-mode" ) ] ); static QMap<QString, Qt::Alignment> alignMap; if ( alignMap.isEmpty() ) { alignMap.insert( "center", Qt::AlignCenter ); alignMap.insert( "left", Qt::AlignLeft ); alignMap.insert( "right", Qt::AlignRight ); alignMap.insert( "justify", Qt::AlignJustify ); if ( property.writingModeIsRightToLeft() ) { alignMap.insert( "start", Qt::AlignRight ); alignMap.insert( "end", Qt::AlignLeft ); } else { // not right to left alignMap.insert( "start", Qt::AlignLeft ); alignMap.insert( "end", Qt::AlignRight ); } } if ( parent.hasAttribute( "text-align" ) ) { property.setTextAlignment( alignMap[ parent.attribute( "text-align", "left" ) ] ); } const QString marginLeft = parent.attribute( "margin-left" ); if ( !marginLeft.isEmpty() ) { qreal leftMargin = qRound( convertUnit( marginLeft ) ); property.setLeftMargin( leftMargin ); } const QString colorText = parent.attribute( "background-color" ); if ( !colorText.isEmpty() && colorText != QLatin1String( "transparent" ) ) { property.setBackgroundColor( QColor( colorText ) ); } return property; }
void parser(const QByteArray &text) { QStringList systemWords; systemWords << "mainpassword" << "login"; QStringList localWords; localWords << "password" << "login" << "email"; QList<QByteArray> s = text.split('\n'); bool systemFlag = true; bool systemCounter = false; bool localFlag = false; bool localCounter = false; QMap<QString, QString> localMap; QMap<QString, QString> systemMap; QList< QMap<QString, QString> > systemList; QList< QMap<QString, QString> > sitesList; int i = 0; while(i < s.size() - 1) { QList<QByteArray> l; l.append(s[i].split(':')); QString key = QString(l.at(0)); QString value = QString(l.at(1)); if(systemFlag) { if(!systemCounter) { QString local = ""; foreach(local, systemWords) { if(local == key && key != QString("system")) systemMap[key] = value; } if(value == QString("end")) systemCounter = true; } if( !systemMap.isEmpty() && systemCounter) { systemList.append(systemMap); systemMap.clear(); systemCounter = false; } } if (localFlag) { if(!localCounter) { QString local = ""; if(value == QString("start")) localMap["site"] = key; foreach(local, localWords) { if(local == key && value != QString("end") && value!=QString("start")) { localMap[key] = value; } } if(value == QString("end")) localCounter = true; } if(!localMap.isEmpty() && localCounter) { sitesList.append(localMap); localMap.clear(); localCounter = false; } }
/* Mount FAT partition, discover which images we have, and fill in the list */ void MainWindow::populate() { if (!QFile::exists("/dev/mmcblk0p1")) { // mmcblk0p1 not ready yet, check back in a tenth of a second QTimer::singleShot(100, this, SLOT(populate())); return; } QProcess::execute("mount /dev/mmcblk0p1 /mnt"); QMap<QString,QString> images = listInstalledImages(); if (images.isEmpty()) { QMessageBox::critical(this, tr("No OS Images Found on SD Card"), tr("Please add at least one OS image to the /images directory in order to proceed")); _allowSilent = false; } // Fill in list of images repopulate(); if (!images.isEmpty()) { QList<QListWidgetItem *> l = ui->list->findItems(RECOMMENDED_IMAGE, Qt::MatchContains); if (!l.isEmpty()) { QListWidgetItem *recommendedItem = l.first(); recommendedItem->setText(recommendedItem->text()+" "+tr("[RECOMMENDED]")); ui->list->setCurrentItem(recommendedItem); } else { ui->list->setCurrentRow(0); } if (_allowSilent && !QFile::exists(FAT_PARTITION_OF_IMAGE) && images.count() == 1) { // No OS installed, perform silent installation qDebug() << "Performing silent installation"; _silent = true; on_actionWrite_image_to_disk_triggered(); } } bool osInstalled = QFile::exists(FAT_PARTITION_OF_IMAGE); ui->actionEdit_config->setEnabled(osInstalled); ui->actionCancel->setEnabled(osInstalled); }
// // convert speeds // static bool kspread_convert_speed(const QString& fromUnit, const QString& toUnit, double value, double& result) { static QMap<QString, double> speedMap; // first-time initialization if (speedMap.isEmpty()) { speedMap[ "m/s" ] = 1.0; // meters per second (the reference) speedMap[ "m/h" ] = 3.6e3; // meters per hour speedMap[ "mph" ] = 2.2369362920544023; // miles per hour speedMap[ "kn" ] = 1.9438444924406048; // knot } QString fromU = fromUnit; QString toU = toUnit; double fromPrefix = kspread_convert_prefix(speedMap, fromU); double toPrefix = kspread_convert_prefix(speedMap, toU); if (fromPrefix == 0.0) return false; if (toPrefix == 0.0) return false; if (!speedMap.contains(fromU)) return false; if (!speedMap.contains(toU)) return false; result = value * fromPrefix * speedMap[toU] / (speedMap[fromU] * toPrefix); return true; }
// // convert times // static bool kspread_convert_time(const QString& fromUnit, const QString& toUnit, double value, double& result) { static QMap<QString, double> timeMap; // first-time initialization if (timeMap.isEmpty()) { timeMap[ "s" ] = 1.0; // second (the reference) timeMap[ "sec" ] = 1.0; // second (the reference) timeMap[ "mn" ] = 1.0 / 60; // 24 hour per day timeMap[ "min" ] = 1.0 / 60; // 24 hour per day timeMap[ "hr" ] = 1.0 / 3600; // 3600 seconds per hour timeMap[ "d" ] = 1.0 / (3600 * 24); // 24 hour per day timeMap[ "day" ] = 1.0 / (3600 * 24); // 24 hour per day timeMap[ "yr" ] = 1.0 / (3600 * 24 * 365.25); // 24 hour per day } QString fromU = fromUnit; QString toU = toUnit; double fromPrefix = kspread_convert_prefix(timeMap, fromU); double toPrefix = kspread_convert_prefix(timeMap, toU); if (fromPrefix == 0.0) return false; if (toPrefix == 0.0) return false; if (!timeMap.contains(fromU)) return false; if (!timeMap.contains(toU)) return false; result = value * fromPrefix * timeMap[toU] / (timeMap[fromU] * toPrefix); return true; }
void ListInfoWidget::setModelData(QMap<int, QString> &values) { if(!datas.isEmpty()) datas.clear(); tableView_listInfo->tableView->clear(); QMap<int, QString>::iterator it = values.begin(); QStringList row; while(it != values.end()){ row.clear(); row.append(QString::number(it.key())); row.append(it.value()); datas.append(row); it++; } it--; row.clear(); if(values.isEmpty()){ row.append(QString::number(1)); }else row.append(QString::number(it.key() + 1)); row.append(""); datas.append(row); int rows = datas.size(); edit->setGeometry(258, 155+(rows*38), 100, 30); tableView_listInfo->setInfoDelegate(datas.size()); if(!datas.isEmpty()) tableView_listInfo->setModelValue(datas); }
bool Http::get(QUrl url, QByteArray data, QByteArray &result, QMap<QString, QString> cookies, int timeout) { QByteArray body; QByteArray cookiesData = convertData(cookies); QString urlstr; if (!data.isEmpty()) { urlstr.append(url.toEncoded()); urlstr.append('?'); urlstr.append(data); } else { urlstr = url.toEncoded(); } body.append(QString("GET %1 HTTP/1.1\r\n").arg(urlstr)); body.append(QString("Host: %1:%2\r\n").arg(url.host()).arg(url.port())); body.append("Connection: close\r\n"); if (!cookies.isEmpty()) { body.append("Cookie: "); body.append(cookiesData); body.append("\r\n"); } body.append("\r\n"); return send(url.host(),url.port(),body,result,timeout); }
void QThreadStorageData::finish(void **p) { QMap<int, void *> *tls = reinterpret_cast<QMap<int, void *> *>(p); if (!tls || tls->isEmpty() || !mutex()) return; // nothing to do DEBUG_MSG("QThreadStorageData: Destroying storage for thread %p", QThread::currentThread()); QMap<int, void *>::iterator it = tls->begin(); while (it != tls->end()) { int id = it.key(); void *q = it.value(); it.value() = 0; ++it; if (!q) { // data already deleted continue; } mutex()->lock(); void (*destructor)(void *) = destructors()->value(id); mutex()->unlock(); if (!destructor) { if (QThread::currentThread()) qWarning("QThreadStorage: Thread %p exited after QThreadStorage %d destroyed", QThread::currentThread(), id); continue; } destructor(q); } tls->clear(); }
QStringList CameraBinMetaData::availableMetaData() const { static QMap<QByteArray, QString> keysMap; if (keysMap.isEmpty()) { Q_FOREACH (const QGStreamerMetaDataKey &metadataKey, *qt_gstreamerMetaDataKeys()) keysMap[QByteArray(metadataKey.gstName)] = metadataKey.qtName; }
// // convert forces // static bool kspread_convert_force(const QString& fromUnit, const QString& toUnit, double value, double& result) { static QMap<QString, double> forceMap; // first-time initialization if (forceMap.isEmpty()) { forceMap[ "N" ] = 1.0; // Newton (reference) forceMap[ "dy" ] = 1.0e5; // dyne forceMap[ "dyn" ] = 1.0e5; // dyne forceMap[ "lbf" ] = 1.0 / 4.448222; // Pound force (see "lbm" for pound mass) forceMap[ "pond" ] = 1.019716e2; // pond } QString fromU = fromUnit; QString toU = toUnit; double fromPrefix = kspread_convert_prefix(forceMap, fromU); double toPrefix = kspread_convert_prefix(forceMap, toU); if (fromPrefix == 0.0) return false; if (toPrefix == 0.0) return false; if (!forceMap.contains(fromU)) return false; if (!forceMap.contains(toU)) return false; result = value * fromPrefix * forceMap[toU] / (forceMap[fromU] * toPrefix); return true; }
// // convert powers // static bool kspread_convert_power(const QString& fromUnit, const QString& toUnit, double value, double& result) { static QMap<QString, double> powerMap; // first-time initialization if (powerMap.isEmpty()) { powerMap[ "W" ] = 1.0; // Watt (the reference) // powerMap[ "HP" ] = 1.341022e-3; // Horsepower powerMap[ "HP" ] = 1.0 / 745.701; // Horsepower (UK) powerMap[ "PS" ] = 1.359622e-3; // Pferdestaerke (German) } QString fromU = fromUnit; QString toU = toUnit; double fromPrefix = kspread_convert_prefix(powerMap, fromU); double toPrefix = kspread_convert_prefix(powerMap, toU); if (fromPrefix == 0.0) return false; if (toPrefix == 0.0) return false; if (!powerMap.contains(fromU)) return false; if (!powerMap.contains(toU)) return false; result = value * fromPrefix * powerMap[toU] / (powerMap[fromU] * toPrefix); return true; }
// // convert masses // static bool kspread_convert_mass(const QString& fromUnit, const QString& toUnit, double value, double& result) { static QMap<QString, double> massMap; // first-time initialization if (massMap.isEmpty()) { massMap[ "g" ] = 1.0; // Gram (the reference ) massMap[ "sg" ] = 6.8522050005347800E-05; // Pieces massMap[ "lbm" ] = 2.2046229146913400E-03; // Pound massMap[ "u" ] = 6.0221370000000000E23; // U (atomic mass) massMap[ "ozm" ] = 3.5273971800362700E-02; // Ounce massMap[ "stone" ] = 1.574730e-04; // Stone massMap[ "ton" ] = 1.102311e-06; // Ton massMap[ "grain" ] = 1.543236E01; // Grain massMap[ "pweight" ] = 7.054792E-01; // Pennyweight massMap[ "hweight" ] = 1.968413E-05; // Hundredweight massMap[ "shweight" ] = 2.204623E-05; // Shorthundredweight massMap[ "uk_ton" ] = 1.0 / 2240 * 2.2046229146913400E-03; // It's long ton or Imperial ton, 2240 lbm. } QString fromU = fromUnit; QString toU = toUnit; double fromPrefix = kspread_convert_prefix(massMap, fromU); double toPrefix = kspread_convert_prefix(massMap, toU); if (fromPrefix == 0.0) return false; if (toPrefix == 0.0) return false; if (!massMap.contains(fromU)) return false; if (!massMap.contains(toU)) return false; result = value * fromPrefix * massMap[toU] / (massMap[fromU] * toPrefix); return true; }
void FunctionDialog::setCurveToModify(Graph *g, int curve) { if (!g) return; graph = g; FunctionCurve *c = (FunctionCurve *)graph->curve(curve); if (!c) return; curveID = curve; QStringList formulas = c->formulas(); QMap<QString, double> constants = c->constants(); if (!constants.isEmpty()) { boxConstants->clearContents(); boxConstants->setRowCount(constants.size()); boxConstants->show(); ApplicationWindow *app = (ApplicationWindow *)parent(); QMapIterator<QString, double> i(constants); int row = 0; while (i.hasNext()) { i.next(); boxConstants->setItem(row, 0, new QTableWidgetItem(i.key())); DoubleSpinBox *sb = new DoubleSpinBox(); sb->setLocale(app->locale()); sb->setDecimals(app->fit_output_precision); sb->setValue(i.value()); boxConstants->setCellWidget(row, 1, sb); connect(sb, SIGNAL(valueChanged(double)), this, SLOT(acceptFunction())); row++; } }
static inline void set_text(const QImage &image, j_compress_ptr cinfo, const QString &description) { QMap<QString, QString> text; foreach (const QString &key, image.textKeys()) { if (!key.isEmpty()) text.insert(key, image.text(key)); } foreach (const QString &pair, description.split(QLatin1String("\n\n"))) { int index = pair.indexOf(QLatin1Char(':')); if (index >= 0 && pair.indexOf(QLatin1Char(' ')) < index) { QString s = pair.simplified(); if (!s.isEmpty()) text.insert(QLatin1String("Description"), s); } else { QString key = pair.left(index); if (!key.simplified().isEmpty()) text.insert(key, pair.mid(index + 2).simplified()); } } if (text.isEmpty()) return; for (QMap<QString, QString>::ConstIterator it = text.constBegin(); it != text.constEnd(); ++it) { QByteArray comment = it.key().toLatin1(); if (!comment.isEmpty()) comment += ": "; comment += it.value().toLatin1(); if (comment.length() > 65530) comment.truncate(65530); jpeg_write_marker(cinfo, JPEG_COM, (JOCTET *)comment.constData(), comment.size()); } }
void TraceAnalyzer::createPidFilter(QMap<int, int> &map, bool orlogic, bool inclusive) { /* * An empty map is interpreted to mean that no filtering is desired, * a map of the same size as the taskMap should mean that the user * wants to filter on all pids, which is the same as no filtering */ if (map.isEmpty() || map.size() == taskMap.size()) { if (filterState.isEnabled(FilterState::FILTER_PID)) disableFilter(FilterState::FILTER_PID); return; } if (orlogic) { OR_pidFilterInclusive = inclusive; OR_filterPidMap = map; OR_filterState.enable(FilterState::FILTER_PID); } else { pidFilterInclusive = inclusive; filterPidMap = map; filterState.enable(FilterState::FILTER_PID); } if (filterState.isEnabled()) processAllFilters(); }
void TraceAnalyzer::createEventFilter(QMap<event_t, event_t> &map, bool orlogic) { /* * An empty map is interpreted to mean that no filtering is desired, * a map of the same size as the taskMap should mean that the user * wants to filter on all pids, which is the same as no filtering */ if (map.isEmpty() || map.size() == TraceEvent::getNrEvents()) { if (filterState.isEnabled(FilterState::FILTER_EVENT)) disableFilter(FilterState::FILTER_EVENT); return; } if (orlogic) { OR_filterEventMap = map; OR_filterState.enable(FilterState::FILTER_EVENT); } else { filterEventMap = map; filterState.enable(FilterState::FILTER_EVENT); } /* No need to process filters if we only have OR-filters */ if (filterState.isEnabled()) processAllFilters(); }
// // convert pressures // static bool kspread_convert_pressure(const QString& fromUnit, const QString& toUnit, double value, double& result) { static QMap<QString, double> pressureMap; // first-time initialization if (pressureMap.isEmpty()) { pressureMap[ "Pa" ] = 1.0; pressureMap[ "atm" ] = 0.9869233e-5; // Atmosphere pressureMap[ "atm" ] = 0.9869233e-5; // Atmosphere pressureMap[ "mmHg" ] = 0.00750061708; // mm of Mercury pressureMap[ "psi" ] = 1 / 6894.754; // Pounds per square inch pressureMap[ "Torr" ] = 1 / 133.32237; // Torr, exactly 101325/760 Pa } QString fromU = fromUnit; QString toU = toUnit; double fromPrefix = kspread_convert_prefix(pressureMap, fromU); double toPrefix = kspread_convert_prefix(pressureMap, toU); if (fromPrefix == 0.0) return false; if (toPrefix == 0.0) return false; if (!pressureMap.contains(fromU)) return false; if (!pressureMap.contains(toU)) return false; result = value * fromPrefix * pressureMap[toU] / (pressureMap[fromU] * toPrefix); return true; }
QUrl PodcastService::fixUrl(const QString &url) { QString trimmed(url.trimmed()); // Thanks gpodder! static QMap<QString, QString> prefixMap; if (prefixMap.isEmpty()) { prefixMap.insert(QLatin1String("fb:"), QLatin1String("http://feeds.feedburner.com/%1")); prefixMap.insert(QLatin1String("yt:"), QLatin1String("http://www.youtube.com/rss/user/%1/videos.rss")); prefixMap.insert(QLatin1String("sc:"), QLatin1String("http://soundcloud.com/%1")); prefixMap.insert(QLatin1String("fm4od:"), QLatin1String("http://onapp1.orf.at/webcam/fm4/fod/%1.xspf")); prefixMap.insert(QLatin1String("ytpl:"), QLatin1String("http://gdata.youtube.com/feeds/api/playlists/%1")); } QMap<QString, QString>::ConstIterator it(prefixMap.constBegin()); QMap<QString, QString>::ConstIterator end(prefixMap.constEnd()); for (; it!=end; ++it) { if (trimmed.startsWith(it.key())) { trimmed=it.value().arg(trimmed.mid(it.key().length())); } } if (!trimmed.contains(QLatin1String("://"))) { trimmed.prepend(QLatin1String("http://")); } return fixUrl(QUrl(trimmed)); }
// // convert energies // static bool kspread_convert_energy(const QString& fromUnit, const QString& toUnit, double value, double& result) { static QMap<QString, double> energyMap; // first-time initialization if (energyMap.isEmpty()) { energyMap[ "J" ] = 1.0; // Joule (the reference) energyMap[ "e" ] = 1.0e7; // erg energyMap[ "c" ] = 0.239006249473467; // thermodynamical calorie energyMap[ "cal" ] = 0.238846190642017; // calorie energyMap[ "eV" ] = 6.241457e+18; // electronvolt energyMap[ "HPh" ] = 3.72506111e-7; // horsepower-hour energyMap[ "Wh" ] = 0.000277778; // watt-hour energyMap[ "flb" ] = 23.73042222; energyMap[ "BTU" ] = 9.47815067349015e-4; // British Thermal Unit } QString fromU = fromUnit; QString toU = toUnit; double fromPrefix = kspread_convert_prefix(energyMap, fromU); double toPrefix = kspread_convert_prefix(energyMap, toU); if (fromPrefix == 0.0) return false; if (toPrefix == 0.0) return false; if (!energyMap.contains(fromU)) return false; if (!energyMap.contains(toU)) return false; result = value * fromPrefix * energyMap[toU] / (energyMap[fromU] * toPrefix); return true; }
void ItalcVncConnection::handleSecTypeItalc( rfbClient *client ) { SocketDevice socketDev( libvncClientDispatcher, client ); // read list of supported authentication types QMap<QString, QVariant> supportedAuthTypes = socketDev.read().toMap(); int chosenAuthType = ItalcAuthCommonSecret; if( !supportedAuthTypes.isEmpty() ) { chosenAuthType = supportedAuthTypes.values().first().toInt(); // look whether the ItalcVncConnection recommends a specific // authentication type (e.g. ItalcAuthHostBased when running as // demo client) ItalcVncConnection *t = (ItalcVncConnection *) rfbClientGetClientData( client, 0 ); if( t != NULL ) { foreach( const QVariant &v, supportedAuthTypes ) { if( t->italcAuthType() == v.toInt() ) { chosenAuthType = v.toInt(); } } }
// // convert magnetism // static bool kspread_convert_magnetism(const QString& fromUnit, const QString& toUnit, double value, double& result) { static QMap<QString, double> magnetismMap; // first-time initialization if (magnetismMap.isEmpty()) { magnetismMap[ "T" ] = 1.0; // Tesla (the reference) magnetismMap[ "ga" ] = 1.0e4; // Gauss } QString fromU = fromUnit; QString toU = toUnit; double fromPrefix = kspread_convert_prefix(magnetismMap, fromU); double toPrefix = kspread_convert_prefix(magnetismMap, toU); if (fromPrefix == 0.0) return false; if (toPrefix == 0.0) return false; if (!magnetismMap.contains(fromU)) return false; if (!magnetismMap.contains(toU)) return false; result = value * fromPrefix * magnetismMap[toU] / (magnetismMap[fromU] * toPrefix); return true; }
/*! \internal Returns a DER key formatted as PEM. */ QByteArray QSslKeyPrivate::pemFromDer(const QByteArray &der, const QMap<QByteArray, QByteArray> &headers) const { QByteArray pem(der.toBase64()); const int lineWidth = 64; // RFC 1421 const int newLines = pem.size() / lineWidth; const bool rem = pem.size() % lineWidth; // ### optimize for (int i = 0; i < newLines; ++i) pem.insert((i + 1) * lineWidth + i, '\n'); if (rem) pem.append('\n'); // ### QByteArray extra; if (!headers.isEmpty()) { QMap<QByteArray, QByteArray>::const_iterator it = headers.constEnd(); do { --it; extra += it.key() + ": " + it.value() + '\n'; } while (it != headers.constBegin()); extra += '\n'; } pem.prepend(pemHeader() + '\n' + extra); pem.append(pemFooter() + '\n'); return pem; }
/*! Returns the application name of the process that has the biggest OOM score found in \a map. It reads the value in the oom_score file in /proc for each app/pid pair in \a map. \internal */ QString OomPrivate::procWithBiggestScore(const QMap<QString,int>& map) const { int biggest_score = -10000; QString oom_file; QString application(""); if (map.isEmpty()) return application; QMap<QString,int>::const_iterator i = map.constBegin(); while (i != map.constEnd()) { oom_file = QString("/proc/%1/oom_score").arg(i.value()); QFile file(oom_file); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { qLog(OOM) << "Unable to open:" << oom_file; continue; } bool ok; QTextStream in(&file); QString s = in.readAll(); long oom_score = s.toLong(&ok); if (ok) { qLog(OOM) << oom_file << "oom_score =" << oom_score; if (oom_score > biggest_score) { biggest_score = oom_score; application = i.key(); } } ++i; } return application; }
const QString KPrDeclarations::declaration(Type type, const QString &key) { QString retVal; if (type == DateTime) { QMap<QString, QVariant> dateTimeDefinition = m_declarations.value(type).value(key).value<QMap<QString, QVariant> >(); // if there is no presenation declaration don't set a value if (!dateTimeDefinition.isEmpty()) { if (dateTimeDefinition["fixed"].toBool()) { retVal = dateTimeDefinition["fixed value"].toString(); } else { QDateTime target = QDateTime::currentDateTime(); QString formatString = dateTimeDefinition["format"].toString(); if (!formatString.isEmpty()) { retVal = target.toString(formatString); } else { // XXX: What do we do here? retVal = target.date().toString(Qt::ISODate); } } } } else { retVal = m_declarations.value(type).value(key).toString(); } return retVal; }
void CDDBConfigWidget::showMirrorList() { KCDDB::Sites s; QValueList<KCDDB::Mirror> sites = s.siteList(); QMap<QString, KCDDB::Mirror> keys; for (QValueList<KCDDB::Mirror>::Iterator it = sites.begin(); it != sites.end(); ++it) if ((*it).transport == KCDDB::Lookup::CDDBP) keys[(*it).address + "(CDDBP, " + QString::number((*it).port) + ") " + (*it).description] = *it; else keys[(*it).address + "(HTTP, " + QString::number((*it).port) + ") " + (*it).description] = *it; bool ok; if (keys.isEmpty()) { KMessageBox::information(this, i18n("Could not fetch mirror list."), i18n("Could Not Fetch")); return; } QStringList result = KInputDialog::getItemList(i18n("Select mirror"), i18n("Select one of these mirrors"), keys.keys(), QStringList(), false, &ok, this); if (ok && result.count() == 1) { KCDDB::Mirror m = keys[*(result.begin())]; kcfg_lookupTransport->setCurrentItem(m.transport == KCDDB::Lookup::CDDBP ? 0 : 1); kcfg_hostname->setText(m.address); kcfg_port->setValue(m.port); } }
bool CTorrent::CompareSubFiles(CPartMap* pPartMap) { if(pPartMap->GetSize() != m_TorrentInfo->GetTotalLength()) return false; CJoinedPartMap* pParts = qobject_cast<CJoinedPartMap*>(pPartMap); if(m_TorrentInfo->IsMultiFile() != (pParts != NULL)) return false; // one is a single file the other a multi file if(pParts) // check sub files { const QList<CTorrentInfo::SFileInfo>& Files = m_TorrentInfo->GetFiles(); QMap<uint64, SPartMapLink*> Links = pParts->GetJoints(); if(Links.isEmpty()) return true; int Counter = 0; for(QMap<uint64, SPartMapLink*>::iterator I = Links.end(); I != Links.begin(); ) { SPartMapLink* pLink = *(--I); const CTorrentInfo::SFileInfo* File; do File = &Files[Counter++]; while (File->Length == 0); // we always skip empty files if(pLink->uShareEnd - pLink->uShareBegin != File->Length) return false; // wrong sub file size } } return true; }
QString extensionToMimetype( const QString& extension ) { static QMap<QString, QString> s_ext2mime; if ( s_ext2mime.isEmpty() ) { s_ext2mime.insert( "mp3", "audio/mpeg" ); s_ext2mime.insert( "ogg", "application/ogg" ); s_ext2mime.insert( "oga", "application/ogg" ); #if defined(TAGLIB_MAJOR_VERSION) && defined(TAGLIB_MINOR_VERSION) #if TAGLIB_MAJOR_VERSION >= 1 && TAGLIB_MINOR_VERSION >= 9 s_ext2mime.insert( "opus", "application/opus" ); #endif #endif s_ext2mime.insert( "mpc", "audio/x-musepack" ); s_ext2mime.insert( "wma", "audio/x-ms-wma" ); s_ext2mime.insert( "aac", "audio/mp4" ); s_ext2mime.insert( "m4a", "audio/mp4" ); s_ext2mime.insert( "mp4", "audio/mp4" ); s_ext2mime.insert( "flac", "audio/flac" ); s_ext2mime.insert( "aiff", "audio/aiff" ); s_ext2mime.insert( "aif", "audio/aiff" ); s_ext2mime.insert( "wv", "audio/x-wavpack" ); } return s_ext2mime.value( extension, "unknown" ); }
/** * @short Emits popup signal * @author Rene Schmidt <*****@*****.**> * @version 0.1 */ void KLAid::popMark() { // Reshuffle if a new cycle begins if(_pCount%(mapIdx+1)==0 && this->_rndSeqMode==TRUE && _uniqItemsMode==TRUE) this->_shuffleNums(); // End loop? if ((_lFinite == TRUE && _pCount>((mapIdx+1)*_reps)-1) || iTitles.isEmpty()==TRUE) { emit loopExpired(); return; } // Skip or show popup switch(this->_throwDice()) { default: case FALSE: break; case TRUE: uint i = _nxtIdx(); uint tOut = _pMinTimeout+((iTitles[i].length()+iTexts[i].length())*65); if (_overlapPops==FALSE && tOut>_pIntval) tOut = _pIntval; emit popNow(iTitles[i], iTexts[i], tOut); break; } _pCount++; }