Marble

ExternalEditorDialog.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2010 Dennis Nienhüser <nienhueser@kde.org>
4//
5
6#include "ExternalEditorDialog.h"
7
8#include <QProcessEnvironment>
9#include <QFileInfo>
10#include <QDir>
11
12namespace Marble
13{
14
15namespace {
16 QString const merkaartor = "merkaartor";
17 QString const josm = "josm";
18 QString const potlatch = "potlatch";
19}
20
21class ExternalEditorDialogPrivate {
22public:
23 QString m_defaultEditor;
24
25 QMap<QString,bool> m_installedEditors;
26
27 ExternalEditorDialogPrivate();
28};
29
30ExternalEditorDialogPrivate::ExternalEditorDialogPrivate() :
31 m_defaultEditor( potlatch )
32{
33 QString path = QProcessEnvironment::systemEnvironment().value(QStringLiteral("PATH"), QStringLiteral("/usr/local/bin:/usr/bin:/bin"));
34 auto const applications = QStringList() << merkaartor << josm;
35 for( const QString &application: applications ) {
36 m_installedEditors[application] = false;
37 /** @todo: what's the qt way to get the path entry separator? Will be a semicolon on Windows */
38 for( const QString &dir: path.split( QLatin1Char( ':' ) ) ) {
39 QFileInfo executable( QDir( dir ), application );
40 if ( executable.exists() ) {
41 m_installedEditors[application] = true;
42 break;
43 }
44 }
45 }
46}
47
48ExternalEditorDialog::ExternalEditorDialog( QWidget * parent, Qt::WindowFlags flags ) :
49 QDialog( parent, flags ), d( new ExternalEditorDialogPrivate )
50{
51 setupUi( this );
52
53 connect( editorComboBox, SIGNAL(currentIndexChanged(int)),
54 this, SLOT(updateDefaultEditor(int)) );
55
56 if ( d->m_installedEditors[merkaartor] ) {
57 d->m_defaultEditor = merkaartor;
58 editorComboBox->setCurrentIndex( 1 );
59 } else if ( d->m_installedEditors[josm] ) {
60 d->m_defaultEditor = josm;
61 editorComboBox->setCurrentIndex( 2 );
62 }
63}
64
65ExternalEditorDialog::~ExternalEditorDialog()
66{
67 delete d;
68}
69
70QString ExternalEditorDialog::externalEditor() const
71{
72 return d->m_defaultEditor;
73}
74
75bool ExternalEditorDialog::saveDefault() const
76{
77 return saveDefaultCheckBox->isChecked();
78}
79
80void ExternalEditorDialog::updateDefaultEditor( int index )
81{
82 QString description;
83
84 switch( index ) {
85 case 1:
86 d->m_defaultEditor = merkaartor;
87 description = tr( "Merkaartor is an OpenStreetMap editor that is powerful and easy to use. It integrates well into the used workspace." );
88 if ( !d->m_installedEditors[d->m_defaultEditor] ) {
89 description += QLatin1String(" <b>") + tr("Please ask your system administrator to install %1 on your system.").arg(QStringLiteral("Merkaartor")) + QLatin1String("</b>");
90 }
91 break;
92 case 2:
93 d->m_defaultEditor = josm;
94 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." );
95 if ( !d->m_installedEditors[d->m_defaultEditor] ) {
96 description += QLatin1String(" <b>") + tr("Please ask your system administrator to install %1 on your system.").arg(QStringLiteral("JOSM")) + QLatin1String("</b>");
97 }
98 break;
99 default:
100 d->m_defaultEditor = potlatch;
101 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." );
102 break;
103 }
104
105 screenshotLabel->setPixmap(QPixmap(QLatin1String(":/data/editors/") + d->m_defaultEditor + QLatin1String(".png")));
106 descriptionLabel->setText( description );
107}
108
109}
110
111#include "moc_ExternalEditorDialog.cpp"
QString path(const QString &relativePath)
Binds a QML item to a specific geodetic location in screen coordinates.
QProcessEnvironment systemEnvironment()
QString value(const QString &name, const QString &defaultValue) const const
typedef WindowFlags
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:18:17 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.