| 1 | /* |
| 2 | This file is part of the KDE libraries |
| 3 | SPDX-FileCopyrightText: 2014 David Faure <faure@kde.org> |
| 4 | |
| 5 | SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
| 6 | */ |
| 7 | |
| 8 | #include "kmimetypeeditor.h" |
| 9 | #include "kmessagedialog.h" |
| 10 | |
| 11 | #include <QObject> |
| 12 | #include <QProcess> |
| 13 | #include <QStandardPaths> |
| 14 | |
| 15 | static const char s_keditfiletypeExecutable[] = "keditfiletype" ; |
| 16 | |
| 17 | void KMimeTypeEditor::editMimeType(const QString &mimeType, QWidget *widget) |
| 18 | { |
| 19 | QStringList args; |
| 20 | #ifndef Q_OS_WIN |
| 21 | args << QStringLiteral("--parent" ) << QString::number(widget->window()->winId()); |
| 22 | #endif |
| 23 | args << mimeType; |
| 24 | |
| 25 | const QString exec = QStandardPaths::findExecutable(executableName: QLatin1String(s_keditfiletypeExecutable)); |
| 26 | if (exec.isEmpty()) { |
| 27 | auto *dlg = new KMessageDialog(KMessageDialog::Error, QObject::tr(s: "Could not find the \"keditfiletype\" executable in PATH." ), widget); |
| 28 | dlg->setAttribute(Qt::WA_DeleteOnClose); |
| 29 | dlg->setModal(true); |
| 30 | dlg->show(); |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | const bool result = QProcess::startDetached(program: exec, arguments: args); |
| 35 | if (!result) { |
| 36 | auto *dlg = |
| 37 | new KMessageDialog(KMessageDialog::Error, QObject::tr(s: "Could not start the \"keditfiletype\" executable, please check your installation." ), widget); |
| 38 | dlg->setAttribute(Qt::WA_DeleteOnClose); |
| 39 | dlg->setModal(true); |
| 40 | dlg->show(); |
| 41 | } |
| 42 | } |
| 43 | |