1/* 2 * Copyright (C) 2017 3 * Jean-Luc Barriere <jlbarriere68@gmail.com> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; version 3. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18import QtQuick 2.9 19import QtQuick.Controls 2.2 20import NosonApp 1.0 21import "components" 22import "components/Delegates" 23import "components/Flickables" 24import "components/ListItemActions" 25 26 27MusicPage { 28 id: servicesPage 29 objectName: "servicesPage" 30 pageTitle: qsTr("My Services") 31 pageFlickable: serviceGrid.visible ? serviceGrid : serviceList 32 multiView: true 33 addVisible: true 34 35 function removeService(type, serialNum) { 36 var acls = deserializeACLS(settings.accounts); 37 var _acls = [] 38 for (var i = 0; i < acls.length; ++i) { 39 if (acls[i].type !== type || acls[i].sn !== serialNum) 40 _acls.push(acls[i]); 41 } 42 customdebug("Remove service " + type + " with serial " + serialNum); 43 Sonos.deleteServiceOAuth(type, serialNum); 44 MyServicesModel.asyncLoad(); 45 settings.accounts = serializeACLS(_acls); 46 } 47 48 SortFilterModel { 49 id: servicesModel 50 model: MyServicesModel 51 sort.property: "title" 52 sort.order: Qt.AscendingOrder 53 sortCaseSensitivity: Qt.CaseInsensitive 54 } 55 56 MusicListView { 57 id: serviceList 58 anchors.fill: parent 59 model: servicesModel 60 delegate: MusicListItem { 61 id: serviceItem 62 63 property bool held: false 64 onPressAndHold: held = true 65 onReleased: held = false 66 67 color: serviceItem.held ? "lightgrey" : "transparent" 68 69 noCover: "qrc:/images/radio.png" 70 imageSources: [{art: model.type === "65031" ? "qrc:/images/tunein.png" : model.icon}] 71 description: qsTr("Service") 72 73 onClicked: { 74 stackView.push("qrc:/controls2/Service.qml", 75 { 76 "serviceItem": model, 77 "pageTitle": model.title 78 }) 79 } 80 81 actionVisible: false 82 menuVisible: (model.id === "SA_RINCON65031_0" ? false : true) 83 84 menuItems: [ 85 Remove { 86 onTriggered: { 87 removeService(model.type, model.serialNum) 88 } 89 } 90 ] 91 92 coverSize: units.gu(5) 93 94 column: Column { 95 Label { 96 id: serviceTitle 97 color: styleMusic.view.primaryColor 98 font.pointSize: units.fs("medium") 99 text: model.title 100 } 101 102 Label { 103 id: serviceNickName 104 color: styleMusic.view.secondaryColor 105 font.pointSize: units.fs("x-small") 106 text: model.nickName 107 visible: text !== "" 108 } 109 } 110 } 111 112 opacity: isListView ? 1.0 : 0.0 113 visible: opacity > 0.0 114 Behavior on opacity { 115 NumberAnimation { duration: 250 } 116 } 117 } 118 119 MusicGridView { 120 id: serviceGrid 121 itemWidth: units.gu(15) 122 heightOffset: units.gu(9) 123 124 model: servicesModel 125 126 delegate: Card { 127 id: serviceCard 128 height: serviceGrid.cellHeight 129 width: serviceGrid.cellWidth 130 primaryText: model.title 131 secondaryText: model.nickName 132 isFavorite: false 133 134 overlay: false // item icon could be transparent 135 noCover: "qrc:/images/radio.png" 136 coverSources: [{art: model.type === "65031" ? "qrc:/images/tunein.png" : model.icon}] 137 138 onClicked: { 139 stackView.push("qrc:/controls2/Service.qml", 140 { 141 "serviceItem": model, 142 "pageTitle": model.title 143 }) 144 } 145 } 146 147 opacity: isListView ? 0.0 : 1.0 148 visible: opacity > 0.0 149 Behavior on opacity { 150 NumberAnimation { duration: 250 } 151 } 152 } 153 154 onAddClicked: { 155 stackView.push("qrc:/controls2/AddService.qml") 156 } 157 158} 159 160