File indexing completed on 2024-03-24 03:52:16
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2010 Dennis Nienhüser <nienhueser@kde.org> 0004 // 0005 0006 #include "ExternalEditorDialog.h" 0007 0008 #include <QProcessEnvironment> 0009 #include <QFileInfo> 0010 #include <QDir> 0011 0012 namespace Marble 0013 { 0014 0015 namespace { 0016 QString const merkaartor = "merkaartor"; 0017 QString const josm = "josm"; 0018 QString const potlatch = "potlatch"; 0019 } 0020 0021 class ExternalEditorDialogPrivate { 0022 public: 0023 QString m_defaultEditor; 0024 0025 QMap<QString,bool> m_installedEditors; 0026 0027 ExternalEditorDialogPrivate(); 0028 }; 0029 0030 ExternalEditorDialogPrivate::ExternalEditorDialogPrivate() : 0031 m_defaultEditor( potlatch ) 0032 { 0033 QString path = QProcessEnvironment::systemEnvironment().value(QStringLiteral("PATH"), QStringLiteral("/usr/local/bin:/usr/bin:/bin")); 0034 auto const applications = QStringList() << merkaartor << josm; 0035 for( const QString &application: applications ) { 0036 m_installedEditors[application] = false; 0037 /** @todo: what's the qt way to get the path entry separator? Will be a semicolon on Windows */ 0038 for( const QString &dir: path.split( QLatin1Char( ':' ) ) ) { 0039 QFileInfo executable( QDir( dir ), application ); 0040 if ( executable.exists() ) { 0041 m_installedEditors[application] = true; 0042 break; 0043 } 0044 } 0045 } 0046 } 0047 0048 ExternalEditorDialog::ExternalEditorDialog( QWidget * parent, Qt::WindowFlags flags ) : 0049 QDialog( parent, flags ), d( new ExternalEditorDialogPrivate ) 0050 { 0051 setupUi( this ); 0052 0053 connect( editorComboBox, SIGNAL(currentIndexChanged(int)), 0054 this, SLOT(updateDefaultEditor(int)) ); 0055 0056 if ( d->m_installedEditors[merkaartor] ) { 0057 d->m_defaultEditor = merkaartor; 0058 editorComboBox->setCurrentIndex( 1 ); 0059 } else if ( d->m_installedEditors[josm] ) { 0060 d->m_defaultEditor = josm; 0061 editorComboBox->setCurrentIndex( 2 ); 0062 } 0063 } 0064 0065 ExternalEditorDialog::~ExternalEditorDialog() 0066 { 0067 delete d; 0068 } 0069 0070 QString ExternalEditorDialog::externalEditor() const 0071 { 0072 return d->m_defaultEditor; 0073 } 0074 0075 bool ExternalEditorDialog::saveDefault() const 0076 { 0077 return saveDefaultCheckBox->isChecked(); 0078 } 0079 0080 void ExternalEditorDialog::updateDefaultEditor( int index ) 0081 { 0082 QString description; 0083 0084 switch( index ) { 0085 case 1: 0086 d->m_defaultEditor = merkaartor; 0087 description = tr( "Merkaartor is an OpenStreetMap editor that is powerful and easy to use. It integrates well into the used workspace." ); 0088 if ( !d->m_installedEditors[d->m_defaultEditor] ) { 0089 description += QLatin1String(" <b>") + tr("Please ask your system administrator to install %1 on your system.").arg(QStringLiteral("Merkaartor")) + QLatin1String("</b>"); 0090 } 0091 break; 0092 case 2: 0093 d->m_defaultEditor = josm; 0094 description = tr( "JOSM is a powerful OpenStreetMap editor which is more complex to use than other editors. It is built on the Java platform and therefor runs on all systems for which Java is available but does not integrate well into the workspace. A Java SE-compatible runtime is required." ); 0095 if ( !d->m_installedEditors[d->m_defaultEditor] ) { 0096 description += QLatin1String(" <b>") + tr("Please ask your system administrator to install %1 on your system.").arg(QStringLiteral("JOSM")) + QLatin1String("</b>"); 0097 } 0098 break; 0099 default: 0100 d->m_defaultEditor = potlatch; 0101 description = tr( "iD is a very easy to use OpenStreetMap editor, though lacks the power of Merkaartor and JOSM. It runs on all platforms with a web browser." ); 0102 break; 0103 } 0104 0105 screenshotLabel->setPixmap(QPixmap(QLatin1String(":/data/editors/") + d->m_defaultEditor + QLatin1String(".png"))); 0106 descriptionLabel->setText( description ); 0107 } 0108 0109 } 0110 0111 #include "moc_ExternalEditorDialog.cpp"