[frameworks/kio] src/filewidgets: knewfileinfo: add parsing fallbacks

Antti Savolainen <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 0e929a70e4c6ffb87e66bf798a0a9929e171b61e by Antti Savolainen.
Committed on 18/07/2026 at 00:38.
Pushed by asavolainen into branch 'master'.

knewfileinfo: add parsing fallbacks

M  +16   -13   src/filewidgets/knewfilemenu.cpp

https://invent.kde.org/frameworks/kio/-/commit/0e929a70e4c6ffb87e66bf798a0a9929e171b61e

diff --git a/src/filewidgets/knewfilemenu.cpp b/src/filewidgets/knewfilemenu.cpp
index 34f1c8ab4e..674dd2db67 100644
--- a/src/filewidgets/knewfilemenu.cpp
+++ b/src/filewidgets/knewfilemenu.cpp
@@ -162,6 +162,7 @@ QDebug operator<<(QDebug debug, const KNewFileMenuSingleton::Entry &Entry)
 bool KNewFileMenuSingleton::Entry::parseFile(QString file)
 {
     QMimeDatabase db;
+    sourceFileInfo = QFileInfo(file);
     // Parse .desktop files
     if (KDesktopFile::isDesktopFile(file)) {
         const KDesktopFile desktopFile(file);
@@ -176,8 +177,6 @@ bool KNewFileMenuSingleton::Entry::parseFile(QString file)
         comment = desktopFile.readComment();
         icon = QIcon::fromTheme(desktopFile.readIcon());
 
-        sourceFileInfo = QFileInfo(file);
-
         if (desktopFile.readType() == QLatin1String("Link") && !url.isEmpty()) {
             if (!url.isLocalFile() && !url.isRelative()) {
                 templatePath = url.toString();
@@ -193,31 +192,35 @@ bool KNewFileMenuSingleton::Entry::parseFile(QString file)
             templatePath = sourceFileInfo.filePath();
         }
 
-        if (text.isEmpty()) {
-            text = QFileInfo(sourceFileInfo).baseName();
-        }
-
         // TODO: Allow external files through non-local urls
         if (!QFileInfo(templatePath).isReadable() && QFileInfo(sourceFileInfo).isNativePath()) {
             return false;
         }
-        mimeType = db.mimeTypeForFile(file);
+        mimeType = db.mimeTypeForFile(templatePath);
     }
     // Parse non-.desktop files
     else {
-        QFileInfo fileinfo(file);
-        if (!fileinfo.isReadable()) {
+        if (!sourceFileInfo.isReadable()) {
             return false;
         }
         url = QUrl(file);
-        key = fileinfo.fileName();
-        text = fileinfo.baseName();
-        sourceFileInfo = QFileInfo(file);
         templatePath = file;
         mimeType = db.mimeTypeForFile(file);
-        icon = QIcon::fromTheme(mimeType.iconName());
+    }
+
+    if (key.isEmpty()) {
+        key = sourceFileInfo.fileName();
+    }
+    if (text.isEmpty()) {
+        text = sourceFileInfo.baseName();
+    }
+    if (comment.isEmpty()) {
         comment = i18nc("@label:textbox Prompt for new file of type", "Enter %1 filename:", mimeType.comment());
     }
+    if (icon.isNull()) {
+        icon = QIcon::fromTheme(mimeType.iconName());
+    }
+
     // Put Directory first in the list (a bit hacky),
     // and TextFile before others because it's the most used one.
     // This also sorts by user-visible name.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.