Warning, /network/smb4k/plasmoid/package/contents/ui/ProfilesPage.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2017-2023 Alexander Reinholdt <alexander.reinholdt@kdemail.net>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 import QtQuick 2.3
0008 import QtQuick.Layouts 1.3
0009 import QtQml.Models 2.3
0010 import org.kde.plasma.core 2.0 as PlasmaCore
0011 import org.kde.plasma.plasmoid 2.0
0012 import org.kde.plasma.components 2.0 as PlasmaComponents
0013 import org.kde.plasma.extras 2.0 as PlasmaExtras
0014 import org.kde.smb4k.smb4kqmlplugin 2.0
0015 
0016 PlasmaComponents.Page {
0017   id: profilesPage
0018   
0019   //
0020   // Tool bar
0021   //
0022   // FIXME: Include tool bar
0023   
0024   //
0025   // Delegate Model (used for sorting)
0026   //
0027   DelegateModel {
0028     id: profileItemDelegateModel
0029     
0030     function lessThan(left, right) {
0031       return (left.profileName < right.profileName)
0032     }
0033     
0034     function insertPosition(item) {
0035       var lower = 0
0036       var upper = items.count
0037       
0038       while (lower < upper) {
0039         var middle = Math.floor(lower + (upper - lower) / 2)
0040         var result = lessThan(item.model.object, items.get(middle).model.object)
0041         if (result) {
0042           upper = middle
0043         }
0044         else {
0045           lower = middle + 1
0046         }
0047       }
0048       return lower
0049     }
0050     
0051     function sort() {
0052       while (unsortedItems.count > 0) {
0053         var item = unsortedItems.get(0)
0054         var index = insertPosition(item)
0055         
0056         item.groups = "items"
0057         items.move(item.itemsIndex, index)
0058       }
0059     }
0060     
0061     items.includeByDefault: false
0062     
0063     groups: [ 
0064       DelegateModelGroup {
0065         id: unsortedItems
0066         name: "unsorted"
0067       
0068         includeByDefault: true
0069       
0070         onChanged: {
0071           profileItemDelegateModel.sort()
0072         }
0073       }
0074     ]
0075 
0076     filterOnGroup: "items"
0077     
0078     model: ListModel {}
0079     
0080     delegate: ProfileItemDelegate {
0081       id: profileItemDelegate
0082         
0083       onItemClicked: {
0084         profilesListView.currentIndex = DelegateModel.itemsIndex
0085         iface.activeProfile = object.profileName
0086       }
0087     }
0088   }
0089   
0090   //
0091   // List view
0092   //
0093   PlasmaExtras.ScrollArea {
0094     id: profilesScrollArea
0095     
0096     anchors {
0097       top: parent.top
0098       left: parent.left
0099       right: parent.right
0100       bottom: parent.bottom
0101     }
0102     
0103     ListView {
0104       id: profilesListView
0105       model: profileItemDelegateModel
0106       clip: true
0107       focus: true
0108       highlightRangeMode: ListView.StrictlyEnforceRange
0109     }
0110   }
0111   
0112   //
0113   // Connections
0114   // 
0115   Connections {
0116     target: iface
0117     function onProfilesListChanged() { fillView() }
0118     function onActiveProfileChanged() { fillView() }
0119   }
0120   
0121   //
0122   // Initialization
0123   //
0124   Component.onCompleted: {
0125     fillView()
0126   }
0127   
0128   //
0129   // Functions
0130   //
0131   function fillView() {
0132     while (profileItemDelegateModel.model.count != 0) {
0133       profileItemDelegateModel.model.remove(0)
0134     }
0135     
0136     if (iface.profileUsage && iface.profiles.length != 0) {
0137       for (var i = 0; i < iface.profiles.length; i++) {
0138         profileItemDelegateModel.model.append({"object": iface.profiles[i]})
0139       }
0140     }
0141   }  
0142 }