Warning, /plasma/plasma-workspace/wallpapers/image/imagepackage/contents/ui/AddFileDialog.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2023 Fushan Wen <qydwhotmail@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 import QtCore
0008 import QtQuick
0009 import QtQuick.Dialogs as QtDialogs
0010 
0011 Loader {
0012     id: dialogLoader
0013 
0014     asynchronous: true
0015     sourceComponent: configDialog.currentWallpaper === "org.kde.image" ? addFileDialog : addFolderDialog
0016 
0017     readonly property url defaultFolder: {
0018         let defaultPaths = StandardPaths.standardLocations(StandardPaths.PicturesLocation);
0019         if (defaultPaths.length === 0) {
0020             // HomeLocation is guaranteed not to be empty.
0021             defaultPaths = StandardPaths.standardLocations(StandardPaths.HomeLocation);
0022         }
0023         return defaultPaths[0];
0024     }
0025 
0026     Connections {
0027         target: dialogLoader.item
0028         function onAccepted() {
0029             let added = false;
0030             if (dialogLoader.item instanceof QtDialogs.FileDialog) {
0031                 dialogLoader.item.selectedFiles.forEach(url => {
0032                     added |= imageWallpaper.addUsersWallpaper(url).length > 0;
0033                 });
0034             } else if (dialogLoader.item instanceof QtDialogs.FolderDialog) {
0035                 added = imageWallpaper.addSlidePath(dialogLoader.item.selectedFolder);
0036             }
0037             if (added) {
0038                 root.wallpaperBrowseCompleted();
0039                 root.configurationChanged();
0040             }
0041             dialogLoader.destroy();
0042         }
0043         function onRejected() {
0044             dialogLoader.destroy();
0045         }
0046     }
0047 
0048     Component {
0049         id: addFileDialog
0050 
0051         QtDialogs.FileDialog {
0052             id: fileDialog
0053             visible: dialogLoader.status === Loader.Ready
0054             currentFolder: dialogLoader.defaultFolder
0055             nameFilters: imageWallpaper.nameFilters()
0056             options: QtDialogs.FileDialog.ReadOnly
0057             title: i18nc("@title:window", "Open Image")
0058         }
0059     }
0060 
0061     Component {
0062         id: addFolderDialog
0063 
0064         QtDialogs.FolderDialog {
0065             id: folderDialog
0066             visible: dialogLoader.status === Loader.Ready
0067             currentFolder: dialogLoader.defaultFolder
0068             options: QtDialogs.FolderDialog.ReadOnly
0069             title: i18nc("@title:window", "Directory with the wallpaper to show slides from")
0070         }
0071     }
0072 }