QObject* VkAccount::CreateNonRosterItem (const QString& idStr) { auto realId = idStr; if (realId.startsWith ("id")) realId = realId.remove (0, 2); bool ok = false; const auto id = realId.toULongLong (&ok); if (!ok) throw std::runtime_error (tr ("%1 is invalid VKontake ID") .arg (idStr) .toUtf8 ().constData ()); if (Entries_.contains (id)) return Entries_ [id]; const auto entry = CreateNonRosterItem (id); emit gotCLItems ({ entry }); NonRosterItems_ << id; Conn_->SetNRIList (NonRosterItems_); Conn_->GetUserInfo ({ id }); return entry; }
void ifsoproperty(const nodeListElement & node, Func func) { auto soPropertyIt = node.properties.find(subobjectPropertyKey); if (soPropertyIt != std::end(node.properties)) { const auto subobjectId = soPropertyIt->toULongLong(); func(subobjectId); } }
QVariant QDBusDemarshaller::toVariantInternal() { switch (q_dbus_message_iter_get_arg_type(&iterator)) { case DBUS_TYPE_BYTE: return qVariantFromValue(toByte()); case DBUS_TYPE_INT16: return qVariantFromValue(toShort()); case DBUS_TYPE_UINT16: return qVariantFromValue(toUShort()); case DBUS_TYPE_INT32: return toInt(); case DBUS_TYPE_UINT32: return toUInt(); case DBUS_TYPE_DOUBLE: return toDouble(); case DBUS_TYPE_BOOLEAN: return toBool(); case DBUS_TYPE_INT64: return toLongLong(); case DBUS_TYPE_UINT64: return toULongLong(); case DBUS_TYPE_STRING: return toString(); case DBUS_TYPE_OBJECT_PATH: return qVariantFromValue(toObjectPath()); case DBUS_TYPE_SIGNATURE: return qVariantFromValue(toSignature()); case DBUS_TYPE_VARIANT: return qVariantFromValue(toVariant()); case DBUS_TYPE_ARRAY: switch (q_dbus_message_iter_get_element_type(&iterator)) { case DBUS_TYPE_BYTE: // QByteArray return toByteArray(); case DBUS_TYPE_STRING: return toStringList(); case DBUS_TYPE_DICT_ENTRY: return qVariantFromValue(duplicate()); default: return qVariantFromValue(duplicate()); } case DBUS_TYPE_STRUCT: return qVariantFromValue(duplicate()); default: qWarning("QDBusDemarshaller: Found unknown D-Bus type %d '%c'", q_dbus_message_iter_get_arg_type(&iterator), q_dbus_message_iter_get_arg_type(&iterator)); return QVariant(); break; }; }
bool OsmAndTools::Styler::Configuration::parseFromCommandLineArguments( const QStringList& commandLineArgs, Configuration& outConfiguration, QString& outError) { outConfiguration = Configuration(); const std::shared_ptr<OsmAnd::ObfsCollection> obfsCollection(new OsmAnd::ObfsCollection()); outConfiguration.obfsCollection = obfsCollection; const std::shared_ptr<OsmAnd::MapStylesCollection> stylesCollection(new OsmAnd::MapStylesCollection()); outConfiguration.stylesCollection = stylesCollection; for (const auto& arg : commandLineArgs) { if (arg.startsWith(QLatin1String("-obfsPath="))) { const auto value = Utilities::resolvePath(arg.mid(strlen("-obfsPath="))); if (!QDir(value).exists()) { outError = QString("'%1' path does not exist").arg(value); return false; } obfsCollection->addDirectory(value, false); } else if (arg.startsWith(QLatin1String("-obfsRecursivePath="))) { const auto value = Utilities::resolvePath(arg.mid(strlen("-obfsRecursivePath="))); if (!QDir(value).exists()) { outError = QString("'%1' path does not exist").arg(value); return false; } obfsCollection->addDirectory(value, true); } else if (arg.startsWith(QLatin1String("-obfFile="))) { const auto value = Utilities::resolvePath(arg.mid(strlen("-obfFile="))); if (!QFile(value).exists()) { outError = QString("'%1' file does not exist").arg(value); return false; } obfsCollection->addFile(value); } else if (arg.startsWith(QLatin1String("-stylesPath="))) { const auto value = Utilities::resolvePath(arg.mid(strlen("-stylesPath="))); if (!QDir(value).exists()) { outError = QString("'%1' path does not exist").arg(value); return false; } QFileInfoList styleFilesList; OsmAnd::Utilities::findFiles(QDir(value), QStringList() << QLatin1String("*.render.xml"), styleFilesList, false); for (const auto& styleFile : styleFilesList) stylesCollection->addStyleFromFile(styleFile.absoluteFilePath()); } else if (arg.startsWith(QLatin1String("-stylesRecursivePath="))) { const auto value = Utilities::resolvePath(arg.mid(strlen("-stylesRecursivePath="))); if (!QDir(value).exists()) { outError = QString("'%1' path does not exist").arg(value); return false; } QFileInfoList styleFilesList; OsmAnd::Utilities::findFiles(QDir(value), QStringList() << QLatin1String("*.render.xml"), styleFilesList, true); for (const auto& styleFile : styleFilesList) stylesCollection->addStyleFromFile(styleFile.absoluteFilePath()); } else if (arg.startsWith(QLatin1String("-styleName="))) { const auto value = Utilities::purifyArgumentValue(arg.mid(strlen("-styleName="))); outConfiguration.styleName = value; } else if (arg.startsWith(QLatin1String("-styleSetting:"))) { const auto settingValue = arg.mid(strlen("-styleSetting:")); const auto settingKeyValue = settingValue.split(QLatin1Char('=')); if (settingKeyValue.size() != 2) { outError = QString("'%1' can not be parsed as style settings key and value").arg(settingValue); return false; } outConfiguration.styleSettings[settingKeyValue[0]] = Utilities::purifyArgumentValue(settingKeyValue[1]); } else if (arg.startsWith(QLatin1String("-mapObject="))) { const auto value = Utilities::purifyArgumentValue(arg.mid(strlen("-mapObject="))); uint64_t mapObjectId = 0u; bool ok = false; if (value[0] == QChar('-')) mapObjectId = static_cast<uint64_t>(value.toLongLong(&ok)); else mapObjectId = value.toULongLong(&ok); if (!ok) { outError = QString("'%1' can not be parsed as map object identifier").arg(value); return false; } outConfiguration.mapObjectsIds.insert(mapObjectId); } else if (arg.startsWith(QLatin1String("-zoom="))) { const auto value = Utilities::purifyArgumentValue(arg.mid(strlen("-zoom="))); bool ok = false; outConfiguration.zoom = static_cast<OsmAnd::ZoomLevel>(value.toUInt(&ok)); if (!ok || outConfiguration.zoom < OsmAnd::MinZoomLevel || outConfiguration.zoom > OsmAnd::MaxZoomLevel) { outError = QString("'%1' can not be parsed as zoom").arg(value); return false; } } else if (arg.startsWith(QLatin1String("-displayDensityFactor="))) { const auto value = Utilities::purifyArgumentValue(arg.mid(strlen("-displayDensityFactor="))); bool ok = false; outConfiguration.displayDensityFactor = value.toFloat(&ok); if (!ok) { outError = QString("'%1' can not be parsed as display density factor").arg(value); return false; } } else if (arg.startsWith(QLatin1String("-mapScale="))) { const auto value = Utilities::purifyArgumentValue(arg.mid(strlen("-mapScale="))); bool ok = false; outConfiguration.mapScale = value.toFloat(&ok); if (!ok) { outError = QString("'%1' can not be parsed as map scale factor").arg(value); return false; } } else if (arg.startsWith(QLatin1String("-symbolsScale="))) { const auto value = Utilities::purifyArgumentValue(arg.mid(strlen("-symbolsScale="))); bool ok = false; outConfiguration.symbolsScale = value.toFloat(&ok); if (!ok) { outError = QString("'%1' can not be parsed as symbols scale factor").arg(value); return false; } } else if (arg.startsWith(QLatin1String("-locale="))) { const auto value = Utilities::purifyArgumentValue(arg.mid(strlen("-locale="))); outConfiguration.locale = value; } else if (arg == QLatin1String("-metrics")) { outConfiguration.metrics = true; } else if (arg == QLatin1String("-verbose")) { outConfiguration.verbose = true; } else { outError = QString("Unrecognized argument: '%1'").arg(arg); return false; } } // Validate if (obfsCollection->getSourceOriginIds().isEmpty()) { outError = QLatin1String("No OBF files found or specified"); return false; } if (outConfiguration.styleName.isEmpty()) { outError = QLatin1String("'styleName' can not be empty"); return false; } return true; }
QVariant QDBusDemarshaller::toVariantInternal() { switch (q_dbus_message_iter_get_arg_type(&iterator)) { case DBUS_TYPE_BYTE: return QVariant::fromValue(toByte()); case DBUS_TYPE_INT16: return QVariant::fromValue(toShort()); case DBUS_TYPE_UINT16: return QVariant::fromValue(toUShort()); case DBUS_TYPE_INT32: return toInt(); case DBUS_TYPE_UINT32: return toUInt(); case DBUS_TYPE_DOUBLE: return toDouble(); case DBUS_TYPE_BOOLEAN: return toBool(); case DBUS_TYPE_INT64: return toLongLong(); case DBUS_TYPE_UINT64: return toULongLong(); case DBUS_TYPE_STRING: return toStringUnchecked(); case DBUS_TYPE_OBJECT_PATH: return QVariant::fromValue(toObjectPathUnchecked()); case DBUS_TYPE_SIGNATURE: return QVariant::fromValue(toSignatureUnchecked()); case DBUS_TYPE_VARIANT: return QVariant::fromValue(toVariant()); case DBUS_TYPE_ARRAY: switch (q_dbus_message_iter_get_element_type(&iterator)) { case DBUS_TYPE_BYTE: // QByteArray return toByteArrayUnchecked(); case DBUS_TYPE_STRING: return toStringListUnchecked(); case DBUS_TYPE_DICT_ENTRY: return QVariant::fromValue(duplicate()); default: return QVariant::fromValue(duplicate()); } case DBUS_TYPE_STRUCT: return QVariant::fromValue(duplicate()); case DBUS_TYPE_UNIX_FD: if (capabilities & QDBusConnection::UnixFileDescriptorPassing) return QVariant::fromValue(toUnixFileDescriptor()); // fall through default: // qWarning("QDBusDemarshaller: Found unknown D-Bus type %d '%c'", // q_dbus_message_iter_get_arg_type(&iterator), // q_dbus_message_iter_get_arg_type(&iterator)); char *ptr = 0; ptr += q_dbus_message_iter_get_arg_type(&iterator); q_dbus_message_iter_next(&iterator); // I hope you never dereference this pointer! return QVariant::fromValue<void *>(ptr); }; }