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 <QDir>
9#include <QFileInfo>
10#include <QProcessEnvironment>
11
12namespace Marble
13{
14
15namespace
16{
17QString const merkaartor = QStringLiteral("merkaartor");
18QString const josm = QStringLiteral("josm");
19QString const potlatch = QStringLiteral("potlatch");
20}
21
22class ExternalEditorDialogPrivate
23{
24public:
25 QString m_defaultEditor;
26
27 QMap<QString, bool> m_installedEditors;
28
29 ExternalEditorDialogPrivate();
30};
31
32ExternalEditorDialogPrivate::ExternalEditorDialogPrivate()
33 : m_defaultEditor(potlatch)
34{
35 QString path = QProcessEnvironment::systemEnvironment().value(QStringLiteral("PATH"), QStringLiteral("/usr/local/bin:/usr/bin:/bin"));
36 auto const applications = QStringList() << merkaartor << josm;
37 for (const QString &application : applications) {
38 m_installedEditors[application] = false;
39 /** @todo: what's the qt way to get the path entry separator? Will be a semicolon on Windows */
40 for (const QString &dir : path.split(QLatin1Char(':'))) {
41 QFileInfo executable(QDir(dir), application);
42 if (executable.exists()) {
43 m_installedEditors[application] = true;
44 break;
45 }
46 }
47 }
48}
49
50ExternalEditorDialog::ExternalEditorDialog(QWidget *parent, Qt::WindowFlags flags)
51 : QDialog(parent, flags)
52 , d(new ExternalEditorDialogPrivate)
53{
54 setupUi(this);
55
56 connect(editorComboBox, &QComboBox::currentIndexChanged, this, &ExternalEditorDialog::updateDefaultEditor);
57
58 if (d->m_installedEditors[merkaartor]) {
59 d->m_defaultEditor = merkaartor;
60 editorComboBox->setCurrentIndex(1);
61 } else if (d->m_installedEditors[josm]) {
62 d->m_defaultEditor = josm;
63 editorComboBox->setCurrentIndex(2);
64 }
65}
66
67ExternalEditorDialog::~ExternalEditorDialog()
68{
69 delete d;
70}
71
72QString ExternalEditorDialog::externalEditor() const
73{
74 return d->m_defaultEditor;
75}
76
77bool ExternalEditorDialog::saveDefault() const
78{
79 return saveDefaultCheckBox->isChecked();
80}
81
82void ExternalEditorDialog::updateDefaultEditor(int index)
83{
84 QString description;
85
86 switch (index) {
87 case 1:
88 d->m_defaultEditor = merkaartor;
89 description = tr("Merkaartor is an OpenStreetMap editor that is powerful and easy to use. It integrates well into the used workspace.");
90 if (!d->m_installedEditors[d->m_defaultEditor]) {
91 description += QLatin1StringView(" <b>")
92 + tr("Please ask your system administrator to install %1 on your system.").arg(QStringLiteral("Merkaartor")) + QLatin1StringView("</b>");
93 }
94 break;
95 case 2:
96 d->m_defaultEditor = josm;
97 description =
98 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 "
99 "all systems for which Java is available but does not integrate well into the workspace. A Java SE-compatible runtime is required.");
100 if (!d->m_installedEditors[d->m_defaultEditor]) {
101 description += QLatin1StringView(" <b>") + tr("Please ask your system administrator to install %1 on your system.").arg(QStringLiteral("JOSM"))
102 + QLatin1StringView("</b>");
103 }
104 break;
105 default:
106 d->m_defaultEditor = potlatch;
107 description =
108 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.");
109 break;
110 }
111
112 screenshotLabel->setPixmap(QPixmap(QLatin1StringView(":/data/editors/") + d->m_defaultEditor + QLatin1StringView(".png")));
113 descriptionLabel->setText(description);
114}
115
116}
117
118#include "moc_ExternalEditorDialog.cpp"
QString path(const QString &relativePath)
Binds a QML item to a specific geodetic location in screen coordinates.
void currentIndexChanged(int index)
QString arg(Args &&... args) const const
QProcessEnvironment systemEnvironment()
QString value(const QString &name, const QString &defaultValue) const const
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) 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 Fri Nov 8 2024 12:02:43 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.