File indexing completed on 2024-05-26 05:38:25

0001 /*
0002     SPDX-FileCopyrightText: 2014 Eike Hein <hein@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "menuentryeditor.h"
0008 
0009 #include <QDir>
0010 #include <QPointer>
0011 #include <QStandardPaths>
0012 
0013 #include <KPropertiesDialog>
0014 
0015 MenuEntryEditor::MenuEntryEditor(QObject *parent)
0016     : QObject(parent)
0017 {
0018 }
0019 
0020 MenuEntryEditor::~MenuEntryEditor()
0021 {
0022 }
0023 
0024 bool MenuEntryEditor::canEdit(const QString &entryPath) const
0025 {
0026     KFileItemList itemList;
0027     itemList << KFileItem(QUrl::fromLocalFile(entryPath));
0028 
0029     return KPropertiesDialog::canDisplay(itemList);
0030 }
0031 
0032 void MenuEntryEditor::edit(const QString &entryPath, const QString &menuId)
0033 {
0034     const QString &appsPath = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation);
0035     const QUrl &entryUrl = QUrl::fromLocalFile(entryPath);
0036 
0037     if (!appsPath.isEmpty() && entryUrl.isValid()) {
0038         const QDir appsDir(appsPath);
0039         const QString &fileName = entryUrl.fileName();
0040 
0041         if (appsDir.exists(fileName)) {
0042             KPropertiesDialog::showDialog(entryUrl, nullptr, false);
0043         } else {
0044             if (!appsDir.exists()) {
0045                 if (!QDir::root().mkpath(appsPath)) {
0046                     return;
0047                 }
0048             }
0049 
0050             KPropertiesDialog *dialog = new KPropertiesDialog(entryUrl, QUrl::fromLocalFile(appsPath), menuId);
0051             // KPropertiesDialog deletes itself
0052             dialog->show();
0053         }
0054     }
0055 }