File indexing completed on 2024-04-28 15:32:07

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2014 David Faure <faure@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007 
0008 #include "kmimetypeeditor.h"
0009 #include "kmessagedialog.h"
0010 
0011 #include <QObject>
0012 #include <QProcess>
0013 #include <QStandardPaths>
0014 
0015 static const char s_keditfiletypeExecutable[] = "keditfiletype5";
0016 
0017 void KMimeTypeEditor::editMimeType(const QString &mimeType, QWidget *widget)
0018 {
0019     QStringList args;
0020 #ifndef Q_OS_WIN
0021     args << QStringLiteral("--parent") << QString::number(widget->window()->winId());
0022 #endif
0023     args << mimeType;
0024 
0025     const QString exec = QStandardPaths::findExecutable(QLatin1String(s_keditfiletypeExecutable));
0026     if (exec.isEmpty()) {
0027         auto *dlg = new KMessageDialog(KMessageDialog::Error, QObject::tr("Could not find the \"keditfiletype5\" executable in PATH."), widget);
0028         dlg->setAttribute(Qt::WA_DeleteOnClose);
0029         dlg->setModal(true);
0030         dlg->show();
0031         return;
0032     }
0033 
0034     const bool result = QProcess::startDetached(exec, args);
0035     if (!result) {
0036         auto *dlg = new KMessageDialog(KMessageDialog::Error,
0037                                        QObject::tr("Could not start the \"keditfiletype5\" executable, please check your installation."),
0038                                        widget);
0039         dlg->setAttribute(Qt::WA_DeleteOnClose);
0040         dlg->setModal(true);
0041         dlg->show();
0042     }
0043 }