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 SPDX-FileCopyrightText: 2023 ivan tkachenko <me@ratijas.tk>
0004
0005 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007
0008 /**
0009 * @brief A button which when clicked will open a dialog with a NewStuff.Page at the base
0010 *
0011 * This component is equivalent to the old Button
0012 * @see KNewStuff::Button
0013 * @since 5.63
0014 */
0015
0016 import QtQuick
0017 import QtQuick.Controls as QQC2
0018 import org.kde.newstuff as NewStuff
0019
0020 QQC2.Button {
0021 id: component
0022
0023 /*
0024 * The configuration file is not aliased, because then we end up initialising the
0025 * 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("knewstuff6", "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("knewstuff6", "Used to construct the button's label (which will become Download New 'this value'…)", "Stuff")
0044 text: i18nd("knewstuff6", "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(var entry, int event)
0070
0071 property Connections engineConnections: Connections {
0072 target: component.engine
0073 function onEntryEvent(entry, event) {
0074 component.entryEvent(entry, event);
0075 }
0076 }
0077
0078 /**
0079 * If this is true (default is false), the button will be shown when the Kiosk settings are such
0080 * that Get Hot New Stuff is disallowed (and any other time enabled is set to false).
0081 * Usually you would want to leave this alone, but occasionally you may have a reason to
0082 * leave a button in place that the user is unable to enable.
0083 */
0084 property bool visibleWhenDisabled: false
0085
0086 /**
0087 * @internal The NewStuff dialog that is opened by the button.
0088 * Use showDialog() to create and open the dialog.
0089 */
0090 property NewStuff.Dialog __ghnsDialog: null
0091
0092 /**
0093 * Show the dialog (same as clicking the button), if allowed by the Kiosk settings
0094 */
0095 function showDialog() {
0096 if (!NewStuff.Settings.allowedByKiosk) {
0097 // make some noise, because silently doing nothing is a bit annoying
0098 console.warn("Not allowed by Kiosk");
0099 return;
0100 }
0101 component.aboutToShowDialog();
0102 // Use this function to open the dialog. It seems roundabout, but this ensures
0103 // that the dialog is not constructed until we want it to be shown the first time,
0104 // since it will initialise itself/compile itself when using Loader on the first
0105 // load and we don't want that until the user explicitly asks for it.
0106 if (component.__ghnsDialog === null) {
0107 const dialogComponent = Qt.createComponent("Dialog.qml");
0108 component.__ghnsDialog = dialogComponent.createObject(component, {
0109 "configFile": Qt.binding(() => component.configFile),
0110 "viewMode": Qt.binding(() => component.viewMode),
0111 });
0112 dialogComponent.destroy();
0113 }
0114 component.__ghnsDialog.open();
0115 component.engine = component.__ghnsDialog.engine;
0116 }
0117
0118 onClicked: showDialog()
0119
0120 icon.name: "get-hot-new-stuff"
0121 visible: enabled || visibleWhenDisabled
0122 enabled: NewStuff.Settings.allowedByKiosk
0123 onEnabledChanged: {
0124 // If the user resets this when kiosk has disallowed ghns, force enabled back to false
0125 if (enabled && !NewStuff.Settings.allowedByKiosk) {
0126 enabled = false;
0127 }
0128 }
0129 }