File indexing completed on 2024-05-12 04:42:33

0001 /*
0002     SPDX-FileCopyrightText: 2019-2023 Volker Krause <vkrause@kde.org>
0003     SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 
0006 #include "efamodeoftransport.h"
0007 #include "logging.h"
0008 
0009 #include <QUrlQuery>
0010 
0011 #include <vector>
0012 
0013 using namespace KPublicTransport;
0014 
0015 // comments below are EFA names found in XML responses (usually translated)
0016 // the mapping isn't necessary 100% obvious everywhere
0017 static constexpr const Line::Mode mot_map[] = {
0018     Line::Train, // 0
0019     Line::RapidTransit, // 1 "Commuter railway"
0020     Line::Metro, // 2 "Subway"
0021     Line::RapidTransit, // 3 "City rail" / "Stadtbahn"
0022     Line::Tramway, // 4
0023     Line::Bus, // 5
0024     Line::Bus, // 6 "Regional bus"
0025     Line::BusRapidTransit, // 7 "Express bus"
0026     Line::Funicular, // 8 "Cable car/Rack railway"
0027     Line::Ferry, // 9
0028     Line::Taxi, // 10 "Taxi on demand"
0029     Line::Unknown, // 11 "Other"
0030     Line::Air, // 12 "Airplane"
0031     Line::LocalTrain, // 13
0032     Line::LongDistanceTrain,
0033     Line::LongDistanceTrain,
0034     Line::LongDistanceTrain, // 14-16 "Train (intercity)"
0035     Line::Bus, // 17 "Rail replacement service"
0036     Line::Train, // 18 "Rail shuttle"
0037     Line::Bus, // 19 "Peoples bus" / "Bürgerbus"
0038 };
0039 
0040 Line::Mode EfaModeOfTransport::motTypeToLineMode(int mot)
0041 {
0042     if (mot < (int)std::size(mot_map)) {
0043         return mot_map[mot];
0044     }
0045     qCDebug(Log) << "Unknown means of transport: " << mot;
0046     return Line::Unknown;
0047 }
0048 
0049 void EfaModeOfTransport::lineModesToQuery(const std::vector<Line::Mode> &lineModes, QUrlQuery &query)
0050 {
0051     if (lineModes.empty()) {
0052         return;
0053     }
0054 
0055     for (auto mode : lineModes) {
0056         for (std::size_t i = 0; i < std::size(mot_map); ++i) {
0057             if (mode == mot_map[i]) {
0058                 const QString key = QLatin1String("inclMOT_") + QString::number(i);
0059                 if (!query.hasQueryItem(key)) {
0060                     query.addQueryItem(key, QStringLiteral("on"));
0061                 }
0062             }
0063         }
0064     }
0065 }