Warning, /plasma/latte-dock/shell/package/contents/controls/CustomIndicatorButton.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 SPDX-FileCopyrightText: 2019 Michail Vourlakos <mvourlakos@gmail.com>
0003 SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005
0006 import QtQuick 2.1
0007
0008 import org.kde.plasma.plasmoid 2.0
0009 import org.kde.plasma.core 2.0 as PlasmaCore
0010
0011 import org.kde.latte.components 1.0 as LatteComponents
0012
0013
0014 LatteComponents.ComboBoxButton{
0015 id: custom
0016 checkable: true
0017
0018 buttonToolTip: custom.type === "install:" ? i18n("Install indicators from KDE Online Store or local files") :
0019 i18n("Use %1 style for your indicators", buttonText)
0020
0021 buttonIsTransparent: true
0022 buttonIsTriggeringMenu: custom.type === "install:"
0023 comboBoxButtonIsTransparent: true
0024 comboBoxButtonIsVisible: latteView.indicator.customPluginsCount > 0
0025
0026 comboBoxTextRole: "name"
0027 comboBoxIconRole: "icon"
0028 comboBoxIconToolTipRole: "iconToolTip"
0029 comboBoxIconOnlyWhenHoveredRole: "iconOnlyWhenHovered"
0030 comboBoxBlankSpaceForEmptyIcons: true
0031 comboBoxForcePressed: latteView.indicator.type === type
0032 comboBoxPopUpAlignRight: Qt.application.layoutDirection !== Qt.RightToLeft
0033
0034 property string type: ""
0035
0036 Component.onCompleted: {
0037 reloadModel();
0038 updateButtonInformation();
0039 }
0040
0041 ListModel {
0042 id: actionsModel
0043 }
0044
0045 Connections{
0046 target: latteView.indicator
0047 onCustomPluginsCountChanged: {
0048 custom.reloadModel();
0049 custom.updateButtonInformation();
0050 }
0051 }
0052
0053 Connections {
0054 target: viewConfig
0055 onIsReadyChanged: {
0056 if (viewConfig.isReady) {
0057 custom.updateButtonInformation();
0058 }
0059 }
0060 }
0061
0062 Connections{
0063 target: custom.button
0064 onClicked: onButtonIsPressed();
0065 }
0066
0067 Connections{
0068 target: custom.comboBox
0069
0070 onActivated: {
0071 if (index>=0) {
0072 var item = actionsModel.get(index);
0073 if (item.pluginId === "add:") {
0074 viewConfig.indicatorUiManager.addIndicator();
0075 } else if (item.pluginId === "download:") {
0076 viewConfig.indicatorUiManager.downloadIndicator();
0077 } else {
0078 latteView.indicator.type = item.pluginId;
0079 }
0080 }
0081
0082 custom.updateButtonInformation();
0083 }
0084
0085 onIconClicked: {
0086 if (index>=0) {
0087 var item = actionsModel.get(index);
0088 var pluginId = item.pluginId;
0089 if (latteView.indicator.customLocalPluginIds.indexOf(pluginId)>=0) {
0090 viewConfig.indicatorUiManager.removeIndicator(pluginId);
0091 custom.comboBox.popup.close();
0092 }
0093 }
0094 }
0095 }
0096
0097 Connections{
0098 target: custom.comboBox.popup
0099 onVisibleChanged: {
0100 if (visible) {
0101 custom.selectChosenType();
0102 }
0103 }
0104 }
0105
0106 function onButtonIsPressed() {
0107 if (custom.type !== "install:") {
0108 latteView.indicator.type = custom.type;
0109 }
0110 }
0111
0112 function updateButtonInformation() {
0113 if (latteView.indicator.customPluginsCount === 0) {
0114 custom.buttonText = i18n("Install...");
0115 custom.type = "install:";
0116 custom.checkable = false;
0117 } else {
0118 custom.checkable = true;
0119
0120 var curCustomIndex = latteView.indicator.customPluginIds.indexOf(latteView.indicator.customType);
0121
0122 if (curCustomIndex>=0) {
0123 custom.buttonText = actionsModel.get(curCustomIndex).name;
0124 custom.type = actionsModel.get(curCustomIndex).pluginId;
0125 } else {
0126 custom.buttonText = actionsModel.get(0).name;
0127 custom.type = actionsModel.get(0).pluginId;
0128 }
0129 }
0130 }
0131
0132 function reloadModel() {
0133 actionsModel.clear();
0134
0135 if (latteView.indicator.customPluginsCount > 0) {
0136 var pluginIds = latteView.indicator.customPluginIds;
0137 var pluginNames = latteView.indicator.customPluginNames;
0138 var localPluginIds = latteView.indicator.customLocalPluginIds;
0139
0140 for(var i=0; i<pluginIds.length; ++i) {
0141 var canBeRemoved = localPluginIds.indexOf(pluginIds[i])>=0;
0142 var iconString = canBeRemoved ? 'remove' : '';
0143 var iconTip = canBeRemoved ? i18n("Remove indicator") : '';
0144 var iconOnlyForHovered = canBeRemoved ? true : false;
0145
0146 var element = {
0147 pluginId: pluginIds[i],
0148 name: pluginNames[i],
0149 icon: iconString,
0150 iconToolTip: iconTip,
0151 iconOnlyWhenHovered: iconOnlyForHovered
0152 };
0153
0154 actionsModel.append(element);
0155 }
0156 }
0157
0158 appendDefaults();
0159
0160 comboBox.model = actionsModel;
0161
0162 if (custom.type === latteView.indicator.type) {
0163 selectChosenType();
0164 } else {
0165 comboBox.currentIndex = -1;
0166 }
0167 }
0168
0169 function selectChosenType() {
0170 var found = false;
0171
0172 for (var i=0; i<actionsModel.count; ++i) {
0173 if (actionsModel.get(i).pluginId === custom.type) {
0174 found = true;
0175 custom.comboBox.currentIndex = i;
0176 break;
0177 }
0178 }
0179
0180 if (!found) {
0181 custom.comboBox.currentIndex = -1;
0182 }
0183 }
0184
0185 function emptyModel() {
0186 actionsModel.clear();
0187 appendDefaults();
0188
0189 comboBox.model = actionsModel;
0190 comboBox.currentIndex = -1;
0191 }
0192
0193 function appendDefaults() {
0194 //! add
0195 var addElement = {
0196 pluginId: 'add:',
0197 name: i18n("Add Indicator..."),
0198 icon: 'document-import',
0199 iconToolTip: '',
0200 iconOnlyWhenHovered: false
0201 };
0202 actionsModel.append(addElement);
0203
0204 //! download
0205 var downloadElement = {
0206 pluginId: 'download:',
0207 name: i18n("Get New Indicators..."),
0208 icon: 'get-hot-new-stuff',
0209 iconToolTip: '',
0210 iconOnlyWhenHovered: false
0211 };
0212 actionsModel.append(downloadElement);
0213 }
0214
0215 }