KNewStuff

Button.qml
1/*
2 SPDX-FileCopyrightText: 2019 Dan Leinir Turthra Jensen <admin@leinir.dk>
3 SPDX-FileCopyrightText: 2023 ivan tkachenko <me@ratijas.tk>
4
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6*/
7
8/**
9 * @brief A button which when clicked will open a dialog with a NewStuff.Page at the base
10 *
11 * This component is equivalent to the old Button
12 * @see KNewStuff::Button
13 * @since 5.63
14 */
15
16import QtQuick
17import QtQuick.Controls as QQC2
18import org.kde.newstuff as NewStuff
19
20QQC2.Button {
21 id: component
22
23 /*
24 * The configuration file is not aliased, because then we end up initialising the
25 * Engine immediately the Button is shown, which we want to avoid (as that
26 * is effectively a phone-home scenario, and causes internet traffic in situations
27 * where it would not seem likely that there should be any).
28 * If we want, in the future, to add some status display to Button (such as "there
29 * are updates to be had" or somesuch, then we can do this, but until that choice is
30 * made, let's not)
31 */
32 /**
33 * The configuration file to use for this button
34 */
35 property string configFile
36
37 /**
38 * Set the text that should appear on the button. Will be set as
39 * i18nd("knewstuff6", "Download New %1…").
40 *
41 * @note For the sake of consistency, you should NOT override the text property, just set this one
42 */
43 property string downloadNewWhat: i18ndc("knewstuff6", "Used to construct the button's label (which will become Download New 'this value'…)", "Stuff")
44 text: i18nd("knewstuff6", "Download New %1…", downloadNewWhat)
45
46 /**
47 * The default view mode of the dialog spawned by this button. This should be
48 * set using the NewStuff.Page.ViewMode enum
49 * @see NewStuff.Page.ViewMode
50 */
51 property int viewMode: NewStuff.Page.ViewMode.Preview
53 /**
54 * emitted when the Hot New Stuff dialog is about to be shown, usually
55 * as a result of the user having click on the button
56 */
57 signal aboutToShowDialog();
58
59 /**
60 * The engine which handles the content in this Button
61 */
62 property QtObject engine: null
63
64 /**
65 * This forwards the entryEvent from the QtQuick engine
66 * @see Engine::entryEvent
67 * @since 5.82
68 */
69 signal entryEvent(var entry, int event)
70
71 property Connections engineConnections: Connections {
72 target: component.engine
73 function onEntryEvent(entry, event) {
74 component.entryEvent(entry, event);
75 }
76 }
77
78 /**
79 * If this is true (default is false), the button will be shown when the Kiosk settings are such
80 * that Get Hot New Stuff is disallowed (and any other time enabled is set to false).
81 * Usually you would want to leave this alone, but occasionally you may have a reason to
82 * leave a button in place that the user is unable to enable.
83 */
84 property bool visibleWhenDisabled: false
85
86 /**
87 * @internal The NewStuff dialog that is opened by the button.
88 * Use showDialog() to create and open the dialog.
89 */
90 property NewStuff.Dialog __ghnsDialog: null
91
92 /**
93 * Show the dialog (same as clicking the button), if allowed by the Kiosk settings
94 */
95 function showDialog() {
96 if (!NewStuff.Settings.allowedByKiosk) {
97 // make some noise, because silently doing nothing is a bit annoying
98 console.warn("Not allowed by Kiosk");
99 return;
100 }
101 component.aboutToShowDialog();
102 // Use this function to open the dialog. It seems roundabout, but this ensures
103 // that the dialog is not constructed until we want it to be shown the first time,
104 // since it will initialise itself/compile itself when using Loader on the first
105 // load and we don't want that until the user explicitly asks for it.
106 if (component.__ghnsDialog === null) {
107 const dialogComponent = Qt.createComponent("Dialog.qml");
108 component.__ghnsDialog = dialogComponent.createObject(component, {
109 "configFile": Qt.binding(() => component.configFile),
110 "viewMode": Qt.binding(() => component.viewMode),
111 });
112 dialogComponent.destroy();
113 }
114 component.__ghnsDialog.open();
115 component.engine = component.__ghnsDialog.engine;
116 }
117
118 onClicked: showDialog()
119
120 icon.name: "get-hot-new-stuff"
121 visible: enabled || visibleWhenDisabled
122 enabled: NewStuff.Settings.allowedByKiosk
123 onEnabledChanged: {
124 // If the user resets this when kiosk has disallowed ghns, force enabled back to false
125 if (enabled && !NewStuff.Settings.allowedByKiosk) {
126 enabled = false;
127 }
128 }
129}
QString i18nd(const char *domain, const char *text, const TYPE &arg...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sun Feb 25 2024 18:48:13 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.