File indexing completed on 2024-06-23 03:50:32

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