File indexing completed on 2024-07-21 06:33:40

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2010 Dennis Nienhüser <nienhueser@kde.org>
0004 //
0005 
0006 #include "RoutinoPlugin.h"
0007 #include "RoutinoRunner.h"
0008 #include "MarbleDirs.h"
0009 
0010 #include "ui_RoutinoConfigWidget.h"
0011 
0012 namespace Marble
0013 {
0014 
0015 RoutinoPlugin::RoutinoPlugin( QObject *parent ) :
0016     RoutingRunnerPlugin( parent )
0017 {
0018     setSupportedCelestialBodies(QStringList(QStringLiteral("earth")));
0019     setCanWorkOffline( true );
0020 }
0021 
0022 QString RoutinoPlugin::name() const
0023 {
0024     return tr( "Routino Routing" );
0025 }
0026 
0027 QString RoutinoPlugin::guiString() const
0028 {
0029     return tr( "Routino" );
0030 }
0031 
0032 QString RoutinoPlugin::nameId() const
0033 {
0034     return QStringLiteral("routino");
0035 }
0036 
0037 QString RoutinoPlugin::version() const
0038 {
0039     return QStringLiteral("1.0");
0040 }
0041 
0042 QString RoutinoPlugin::description() const
0043 {
0044     return tr( "Retrieves routes from routino" );
0045 }
0046 
0047 QString RoutinoPlugin::copyrightYears() const
0048 {
0049     return QStringLiteral("2010");
0050 }
0051 
0052 QVector<PluginAuthor> RoutinoPlugin::pluginAuthors() const
0053 {
0054     return QVector<PluginAuthor>()
0055             << PluginAuthor(QStringLiteral("Dennis Nienhüser"), QStringLiteral("nienhueser@kde.org"));
0056 }
0057 
0058 RoutingRunner *RoutinoPlugin::newRunner() const
0059 {
0060     return new RoutinoRunner;
0061 }
0062 
0063 class RoutinoConfigWidget : public RoutingRunnerPlugin::ConfigWidget
0064 {
0065 Q_OBJECT
0066 public:
0067     RoutinoConfigWidget()
0068         : RoutingRunnerPlugin::ConfigWidget()
0069     {
0070         ui_configWidget = new Ui::RoutinoConfigWidget;
0071         ui_configWidget->setupUi( this );
0072         QStringList transports;
0073         //TODO: read from profiles.xml
0074         ui_configWidget->transport->addItem(tr("Pedestrian"), "foot");
0075         ui_configWidget->transport->addItem(tr("Horse"), "horse");
0076         ui_configWidget->transport->addItem(tr("Wheelchair"), "wheelchair");
0077         ui_configWidget->transport->addItem(tr("Bicycle"), "bicycle");
0078         ui_configWidget->transport->addItem(tr("Moped"), "moped");
0079         ui_configWidget->transport->addItem(tr("Motorbike"), "motorbike");
0080         ui_configWidget->transport->addItem(tr("Motorcar"), "motorcar");
0081         ui_configWidget->transport->addItem(tr("Small lorry"), "goods");
0082         ui_configWidget->transport->addItem(tr("Large lorry"), "hgv");
0083         ui_configWidget->transport->addItem(tr("Public Service Vehicle"), "psv");
0084     }
0085     ~RoutinoConfigWidget() override
0086     {
0087         delete ui_configWidget;
0088     }
0089     void loadSettings( const QHash<QString, QVariant> &settings_ ) override
0090     {
0091         QHash<QString, QVariant> settings = settings_;
0092 
0093         // Check if all fields are filled and fill them with default values.
0094         if (!settings.contains(QStringLiteral("transport"))) {
0095             settings.insert(QStringLiteral("transport"), QStringLiteral("motorcar"));
0096         }
0097         ui_configWidget->transport->setCurrentIndex(
0098             ui_configWidget->transport->findData(settings.value(QStringLiteral("transport")).toString()));
0099         if (settings.value(QStringLiteral("method")).toString() == QLatin1String("shortest")) {
0100             ui_configWidget->shortest->setChecked( true );
0101         } else {
0102             ui_configWidget->fastest->setChecked( true );
0103         }
0104     }
0105 
0106     QHash<QString, QVariant> settings() const override
0107     {
0108         QHash<QString,QVariant> settings;
0109         settings.insert(QStringLiteral("transport"),
0110                         ui_configWidget->transport->itemData( ui_configWidget->transport->currentIndex() ) );
0111 
0112         if ( ui_configWidget->shortest->isChecked() ) {
0113             settings.insert(QStringLiteral("method"), QStringLiteral("shortest"));
0114         } else {
0115             settings.insert(QStringLiteral("method"), QStringLiteral("fastest"));
0116         }
0117         return settings;
0118     }
0119 private:
0120     Ui::RoutinoConfigWidget *ui_configWidget;
0121 };
0122 
0123 RoutingRunnerPlugin::ConfigWidget *RoutinoPlugin::configWidget()
0124 {
0125     return new RoutinoConfigWidget();
0126 }
0127 
0128 bool RoutinoPlugin::supportsTemplate(RoutingProfilesModel::ProfileTemplate profileTemplate) const
0129 {
0130     return
0131         (profileTemplate == RoutingProfilesModel::CarFastestTemplate)  ||
0132         (profileTemplate == RoutingProfilesModel::CarShortestTemplate) ||
0133         (profileTemplate == RoutingProfilesModel::BicycleTemplate)     ||
0134         (profileTemplate == RoutingProfilesModel::PedestrianTemplate);
0135 }
0136 
0137 QHash< QString, QVariant > RoutinoPlugin::templateSettings(RoutingProfilesModel::ProfileTemplate profileTemplate) const
0138 {
0139     QHash<QString, QVariant> result;
0140     switch ( profileTemplate ) {
0141         case RoutingProfilesModel::CarFastestTemplate:
0142             result.insert(QStringLiteral("transport"), QStringLiteral("motorcar"));
0143             result.insert(QStringLiteral("method"), QStringLiteral("fastest"));
0144             break;
0145         case RoutingProfilesModel::CarShortestTemplate:
0146             result.insert(QStringLiteral("transport"), QStringLiteral("motorcar"));
0147             result.insert(QStringLiteral("method"), QStringLiteral("shortest"));
0148             break;
0149         case RoutingProfilesModel::CarEcologicalTemplate:
0150             break;
0151         case RoutingProfilesModel::BicycleTemplate:
0152             result.insert(QStringLiteral("transport"), QStringLiteral("bicycle"));
0153             result.insert(QStringLiteral("method"), QStringLiteral("shortest"));
0154             break;
0155         case RoutingProfilesModel::PedestrianTemplate:
0156             result.insert(QStringLiteral("transport"), QStringLiteral("foot"));
0157             result.insert(QStringLiteral("method"), QStringLiteral("shortest"));
0158             break;
0159         case RoutingProfilesModel::LastTemplate:
0160             Q_ASSERT( false );
0161             break;
0162     }
0163     return result;
0164 }
0165 
0166 bool RoutinoPlugin::canWork() const
0167 {
0168     QDir mapDir = QDir(MarbleDirs::localPath() + QLatin1String("/maps/earth/routino/"));
0169     return mapDir.exists();
0170 }
0171 
0172 }
0173 
0174 #include "RoutinoPlugin.moc"
0175 
0176 #include "moc_RoutinoPlugin.cpp"