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 view mode of the dialog spawned by this button, which overrides the
48 * default one (ViewMode.Tiles). This should be set using the
49 * NewStuff.Page.ViewMode enum. Note that ViewMode.Icons has been removed,
50 * and asking for it will return ViewMode.Tiles.
51 * @see NewStuff.Page.ViewMode
52 */
53 property int viewMode: NewStuff.Page.ViewMode.Tiles
55 /**
56 * emitted when the Hot New Stuff dialog is about to be shown, usually
57 * as a result of the user having click on the button
58 */
59 signal aboutToShowDialog()
60
61 /**
62 * The engine which handles the content in this Button
63 */
64 property NewStuff.Engine engine
65
66 /**
67 * This forwards the entryEvent from the QtQuick engine
68 * @see Engine::entryEvent
69 * @since 5.82
70 */
71 signal entryEvent(var entry, int event)
72
73 property Connections engineConnections: Connections {
74 target: component.engine
75 function onEntryEvent(entry, event) {
76 component.entryEvent(entry, event);
77 }
78 }
79
80 /**
81 * If this is true (default is false), the button will be shown when the Kiosk settings are such
82 * that Get Hot New Stuff is disallowed (and any other time enabled is set to false).
83 * Usually you would want to leave this alone, but occasionally you may have a reason to
84 * leave a button in place that the user is unable to enable.
85 */
86 property bool visibleWhenDisabled: false
87
88 /**
89 * @internal The NewStuff dialog that is opened by the button.
90 * Use showDialog() to create and open the dialog.
91 */
92 property NewStuff.Dialog __ghnsDialog
93
94 /**
95 * Show the dialog (same as clicking the button), if allowed by the Kiosk settings
96 */
97 function showDialog() {
98 if (!NewStuff.Settings.allowedByKiosk) {
99 // make some noise, because silently doing nothing is a bit annoying
100 console.warn("Not allowed by Kiosk");
101 return;
102 }
103 component.aboutToShowDialog();
104 // Use this function to open the dialog. It seems roundabout, but this ensures
105 // that the dialog is not constructed until we want it to be shown the first time,
106 // since it will initialise itself/compile itself when using Loader on the first
107 // load and we don't want that until the user explicitly asks for it.
108 if (component.__ghnsDialog === null) {
109 const dialogComponent = Qt.createComponent("Dialog.qml");
110 component.__ghnsDialog = dialogComponent.createObject(component, {
111 "configFile": Qt.binding(() => component.configFile),
112 "viewMode": Qt.binding(() => component.viewMode),
113 });
114 dialogComponent.destroy();
115 }
116 component.__ghnsDialog.open();
117 component.engine = component.__ghnsDialog.engine;
118 }
119
120 onClicked: showDialog()
121
122 icon.name: "get-hot-new-stuff"
123 visible: enabled || visibleWhenDisabled
124 enabled: NewStuff.Settings.allowedByKiosk
125 onEnabledChanged: {
126 // If the user resets this when kiosk has disallowed ghns, force enabled back to false
127 if (enabled && !NewStuff.Settings.allowedByKiosk) {
128 enabled = false;
129 }
130 }
131}
KNSCore::EngineBase for interfacing with QML.
Definition quickengine.h:29
void entryEvent(const KNSCore::Entry &entry, KNSCore::Entry::EntryEvent event)
This is fired for events related directly to a single Entry instance The intermediate states Updating...
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 Mon Nov 18 2024 12:20:03 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.