File indexing completed on 2024-05-12 04:42:37
0001 /* 0002 SPDX-FileCopyrightText: 2021-2023 Volker Krause <vkrause@kde.org> 0003 SPDX-License-Identifier: LGPL-2.0-or-later 0004 */ 0005 0006 #include "ivvassproductmap.h" 0007 0008 #include <QDebug> 0009 #include <QUrlQuery> 0010 0011 using namespace KPublicTransport; 0012 0013 struct { 0014 const char *product; 0015 Line::Mode mode; 0016 } static constexpr const product_mode_map[] = { 0017 { "Boat", Line::Ferry }, 0018 { "Bus", Line::Bus }, 0019 { "CommunityBus", Line::Bus }, 0020 { "LightRail", Line::Tramway }, 0021 { "LongDistanceTrains", Line::LongDistanceTrain }, 0022 { "OnDemandServices", Line::Taxi }, 0023 { "RailReplacementServices", Line::Bus }, 0024 { "RegionalTrains", Line::LocalTrain }, 0025 { "SuburbanTrains", Line::RapidTransit }, 0026 { "Underground", Line::Metro } 0027 }; 0028 0029 Line::Mode IvvAssProductMap::parseProduct(QStringView product) 0030 { 0031 for (const auto &m : product_mode_map) { 0032 if (product == QLatin1String(m.product)) { 0033 return m.mode; 0034 break; 0035 } 0036 } 0037 0038 qWarning() << "Unknown IVV ASS product type:" << product; 0039 return Line::Unknown; 0040 } 0041 0042 void IvvAssProductMap::lineModesToQuery(const std::vector<Line::Mode> &lineModes, QUrlQuery &query) 0043 { 0044 if (lineModes.empty()) { 0045 return; 0046 } 0047 0048 QStringList products; 0049 for (auto &m : product_mode_map) { 0050 // lineModes is guaranteed to be sorted 0051 if (std::binary_search(lineModes.begin(), lineModes.end(), m.mode)) { 0052 products.push_back(QLatin1String(m.product)); 0053 } 0054 } 0055 if (!products.isEmpty()) { 0056 query.addQueryItem(QStringLiteral("p"), products.join(QLatin1Char(','))); 0057 } 0058 }