Warning, /frameworks/knewstuff/src/qtquick/qml/Button.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2019 Dan Leinir Turthra Jensen <admin@leinir.dk> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 /** 0008 * @brief A button which when clicked will open a dialog with a NewStuff.Page at the base 0009 * 0010 * This component is equivalent to the old Button 0011 * @see KNewStuff::Button 0012 * @since 5.63 0013 */ 0014 0015 import QtQuick 2.11 0016 import QtQuick.Controls 2.11 as QtControls 0017 0018 import org.kde.newstuff 1.81 as NewStuff 0019 0020 QtControls.Button { 0021 id: component 0022 0023 /* 0024 * The configuration file is not aliased, because then we end up initialising the 0025 * KNSCore::Engine immediately the Button is shown, which we want to avoid (as that 0026 * is effectively a phone-home scenario, and causes internet traffic in situations 0027 * where it would not seem likely that there should be any). 0028 * If we want, in the future, to add some status display to Button (such as "there 0029 * are updates to be had" or somesuch, then we can do this, but until that choice is 0030 * made, let's not) 0031 */ 0032 /** 0033 * The configuration file to use for this button 0034 */ 0035 property string configFile 0036 0037 /** 0038 * Set the text that should appear on the button. Will be set as 0039 * i18nd("knewstuff5", "Download New %1..."). 0040 * 0041 * @note For the sake of consistency, you should NOT override the text property, just set this one 0042 */ 0043 property string downloadNewWhat: i18ndc("knewstuff5", "Used to construct the button's label (which will become Download New 'this value'...)", "Stuff") 0044 text: i18nd("knewstuff5", "Download New %1...", downloadNewWhat) 0045 0046 /** 0047 * The default view mode of the dialog spawned by this button. This should be 0048 * set using the NewStuff.Page.ViewMode enum 0049 * @see NewStuff.Page.ViewMode 0050 */ 0051 property int viewMode: NewStuff.Page.ViewMode.Preview 0052 0053 /** 0054 * emitted when the Hot New Stuff dialog is about to be shown, usually 0055 * as a result of the user having click on the button 0056 */ 0057 signal aboutToShowDialog(); 0058 0059 /** 0060 * The engine which handles the content in this Button 0061 */ 0062 property QtObject engine: null 0063 0064 /** 0065 * This forwards the entryEvent from the QtQuick engine 0066 * @see Engine::entryEvent 0067 * @since 5.82 0068 */ 0069 signal entryEvent(QtObject entry, int event); 0070 property Connections engineConnections: Connections { 0071 target: component.engine 0072 function onEntryEvent(entry, event) { 0073 entryEvent(entry, event); 0074 } 0075 } 0076 0077 /** 0078 * Contains the entries which have been changed. 0079 * @note This is cleared when the dialog is shown, so the changed entries are those 0080 * changed since the dialog was opened most recently (rather than the lifetime 0081 * of the instance of the Button component) 0082 * @deprecated Since 5.82, use entryEvent instead 0083 */ 0084 property var changedEntries 0085 property Binding changedEntriesBinding: Binding { 0086 target: component 0087 property: "changedEntries" 0088 value: component.engine ? component.engine.changedEntries : [] 0089 } 0090 0091 /** 0092 * Show the details page for a specific entry. 0093 * If you call this function before the engine initialisation has been completed, 0094 * the action itself will be postponed until that has happened. 0095 * @param providerId The provider ID for the entry you wish to show details for 0096 * @param entryId The unique ID for the entry you wish to show details for 0097 * @since 5.79 0098 */ 0099 function showEntryDetails(providerId, entryId) { 0100 newStuffPage.showEntryDetails(providerId, entryId); 0101 } 0102 0103 /** 0104 * If this is true (default is false), the button will be shown when the Kiosk settings are such 0105 * that Get Hot New Stuff is disallowed (and any other time enabled is set to false). 0106 * Usually you would want to leave this alone, but occasionally you may have a reason to 0107 * leave a button in place that the user is unable to enable. 0108 */ 0109 property bool visibleWhenDisabled: false 0110 0111 /** 0112 * Show the dialog (same as clicking the button), if allowed by the Kiosk settings 0113 */ 0114 function showDialog() { 0115 if (NewStuff.Settings.allowedByKiosk) { 0116 component.aboutToShowDialog(); 0117 ghnsDialog.open(); 0118 } else { 0119 // make some noise, because silently doing nothing is a bit annoying 0120 } 0121 } 0122 0123 onClicked: { showDialog(); } 0124 0125 icon.name: "get-hot-new-stuff" 0126 visible: enabled || visibleWhenDisabled 0127 enabled: NewStuff.Settings.allowedByKiosk 0128 onEnabledChanged: { 0129 // If the user resets this when kiosk has disallowed ghns, force enabled back to false 0130 if (enabled === true && NewStuff.Settings.allowedByKiosk === false) { 0131 enabled = false; 0132 } 0133 } 0134 0135 property Item ghnsDialog : Loader { 0136 // Use this function to open the dialog. It seems roundabout, but this ensures 0137 // that the dialog is not constructed until we want it to be shown the first time, 0138 // since it will initialise itself on the first load (which causes it to phone 0139 // home) and we don't want that until the user explicitly asks for it. 0140 function open() { 0141 if (item) { 0142 item.open(); 0143 } else { 0144 active = true; 0145 } 0146 } 0147 onLoaded: { 0148 item.open(); 0149 component.engine = item.engine 0150 } 0151 0152 active: false 0153 asynchronous: true 0154 0155 sourceComponent: NewStuff.Dialog { 0156 configFile: component.configFile 0157 viewMode: component.viewMode 0158 } 0159 } 0160 }