[system/kjar] src: Parse file names better

Hadi Chokr <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 4e00f6f09868e25fdc48a05a8ae6ca6376b5736d by Hadi Chokr.
Committed on 03/08/2026 at 11:09.
Pushed by silverhadch into branch 'master'.

Parse file names better

Closes #1

Signed-off-by: Hadi Chokr <[email protected]>

M  +10   -4    src/main.cpp
M  +2    -1    src/watcher/kjar_watcher.cpp

https://invent.kde.org/system/kjar/-/commit/4e00f6f09868e25fdc48a05a8ae6ca6376b5736d

diff --git a/src/main.cpp b/src/main.cpp
index 2077a2e..6208759 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -9,8 +9,17 @@
 #include <QFile>
 #include <QDir>
 #include <QProcess>
+#include <QUrl>
 #include "kjarapp.h"
 
+static QString toLocalPath(const QString &input)
+{
+  if (input.startsWith(QLatin1String("file://"))) {
+    return QUrl(input).toLocalFile();
+  }
+  return input;
+}
+
 static int showGui(KjarApp &kjarApp, const QString &initialError = QString()) {
   QQmlApplicationEngine engine;
   engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
@@ -121,10 +130,7 @@ int main(int argc, char *argv[])
       }
 
       if (arg.endsWith(QLatin1String(".jar"), Qt::CaseInsensitive)) {
-        QString filePath = arg;
-        if (filePath.startsWith(QLatin1String("file://"))) {
-          filePath.remove(0, 7);
-        }
+        const QString filePath = toLocalPath(arg);
 
         QGuiApplication app(argc, argv);
         app.setApplicationName(QStringLiteral("org.kde.kjar"));
diff --git a/src/watcher/kjar_watcher.cpp b/src/watcher/kjar_watcher.cpp
index 2725586..76939dc 100644
--- a/src/watcher/kjar_watcher.cpp
+++ b/src/watcher/kjar_watcher.cpp
@@ -7,6 +7,7 @@
 #include <QQmlContext>
 #include <QProcess>
 #include <QFile>
+#include <QUrl>
 #include <KLocalizedString>
 
 int main(int argc, char *argv[])
@@ -17,7 +18,7 @@ int main(int argc, char *argv[])
 
     QString jarPath = QString::fromLocal8Bit(argv[1]);
     if (jarPath.startsWith(QStringLiteral("file://"))) {
-        jarPath.remove(0, 7);
+        jarPath = QUrl(jarPath).toLocalFile();
     }
 
     if (!QFile::exists(jarPath)) {
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.