[system/kconfigeditor] /: Use KFileUtils to find files

Nicolas Fella <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 019d8aadeeda5a9659c035f7c5a10acfbc40686f by Nicolas Fella.
Committed on 22/07/2026 at 13:00.
Pushed by nicolasfella into branch 'master'.

Use KFileUtils to find files

M  +5    -1    build.rs
M  +19   -19   src/util.rs

https://invent.kde.org/system/kconfigeditor/-/commit/019d8aadeeda5a9659c035f7c5a10acfbc40686f

diff --git a/build.rs b/build.rs
index 0ae23fa..b5e5df8 100644
--- a/build.rs
+++ b/build.rs
@@ -5,7 +5,10 @@ use cmake_package::find_package;
 use cxx_qt_build::{CxxQtBuilder, QmlModule};
 
 // list of (LibraryName, [LibraryTargets])
-const LIBRARIES: &[(&str, &[&str])] = &[("KF6Config", &["KF6::ConfigCore"])];
+const LIBRARIES: &[(&str, &[&str])] = &[
+    ("KF6Config", &["KF6::ConfigCore"]),
+    ("KF6CoreAddons", &["KF6::CoreAddons"]),
+];
 
 fn main() {
     let mut builder = CxxQtBuilder::new_qml_module(
@@ -22,6 +25,7 @@ fn main() {
         "src/groupsmodel.rs",
         "src/entrymodel.rs",
         "src/qstandardpaths.rs",
+        "src/util.rs",
     ])
     .cpp_file("src/helper.cpp")
     .cpp_file("src/qstandardpaths.cpp");
diff --git a/src/util.rs b/src/util.rs
index 0181aa4..e2ebccc 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -12,6 +12,20 @@ use crate::qstandardpaths::{
     QStandardPaths, QStandardPathsLocateOption, QStandardPathsStandardLocation,
 };
 
+#[cxx_qt::bridge()]
+mod ffi {
+    unsafe extern "C++" {
+        include!("KFileUtils");
+
+        include!("cxx-qt-lib/qstringlist.h");
+        type QStringList = cxx_qt_lib::QStringList;
+
+        #[namespace = "KFileUtils"]
+        #[rust_name = "find_all_unique_files"]
+        pub fn findAllUniqueFiles(dirs: &QStringList, nameFilters: &QStringList) -> QStringList;
+    }
+}
+
 fn kcfg_dirs(location: &QString) -> QStringList {
     if location.is_empty() {
         return QStandardPaths::locate_all(
@@ -29,27 +43,13 @@ fn kcfg_dirs(location: &QString) -> QStringList {
     }
 }
 
+use ffi::find_all_unique_files;
+
 pub fn find_kcfg_files(location: &QString) -> QStringList {
-    let mut result = QStringList::default();
+    let mut patterns = QStringList::default();
+    patterns.append(QString::from("*.kcfg"));
 
     let dirs = kcfg_dirs(location);
 
-    for dir in Upcast::<QList<QString>>::upcast(&dirs) {
-        let r = fs::read_dir(dir.to_string());
-        if r.is_err() {
-            println!("error: {:?}", r.err().unwrap());
-            continue;
-        }
-
-        let listing = r.unwrap();
-
-        for file in listing {
-            let name: String = file.unwrap().path().to_str().unwrap().to_string();
-            result.append(QString::from(&name));
-        }
-    }
-
-    result.remove_duplicates();
-
-    result
+    return find_all_unique_files(&dirs, &patterns);
 }
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.