KWidgetsAddons

kmimetypeeditor.cpp
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
15static const char s_keditfiletypeExecutable[] = "keditfiletype";
16
17void 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(QLatin1String(s_keditfiletypeExecutable));
26 if (exec.isEmpty()) {
27 auto *dlg = new KMessageDialog(KMessageDialog::Error, QObject::tr("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(exec, args);
35 if (!result) {
36 auto *dlg =
37 new KMessageDialog(KMessageDialog::Error, QObject::tr("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}
KMessageDialog creates a message box similar to the ones you get from KMessageBox,...
@ Error
Error dialog.
void editMimeType(const QString &mimeType, QWidget *widget)
Starts the file types editor for a given MIME type.
QString tr(const char *sourceText, const char *disambiguation, int n)
bool startDetached(const QString &program, const QStringList &arguments, const QString &workingDirectory, qint64 *pid)
QString findExecutable(const QString &executableName, const QStringList &paths)
bool isEmpty() const const
QString number(double n, char format, int precision)
WA_DeleteOnClose
WId winId() const const
QWidget * window() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 19 2024 11:51:03 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.