Changeset View
Changeset View
Standalone View
Standalone View
src/qtquick/qml/NewStuffButton.qml
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2019 Dan Leinir Turthra Jensen <admin@leinir.dk> | ||||
3 | * | ||||
4 | * This library is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU Lesser General Public | ||||
6 | * License as published by the Free Software Foundation; either | ||||
7 | * version 2.1 of the License, or (at your option) version 3, or any | ||||
8 | * later version accepted by the membership of KDE e.V. (or its | ||||
9 | * successor approved by the membership of KDE e.V.), which shall | ||||
10 | * act as a proxy defined in Section 6 of version 3 of the license. | ||||
11 | * | ||||
12 | * This library is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
15 | * Lesser General Public License for more details. | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU Lesser General Public | ||||
18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | * | ||||
20 | */ | ||||
21 | | ||||
22 | /** | ||||
23 | * @brief A button which when clicked will open a dialog with a NewStuffPage at the base | ||||
24 | * | ||||
25 | * This component is equivalent to the old Button | ||||
26 | * @see KNewStuff::Button | ||||
27 | */ | ||||
28 | | ||||
29 | import QtQuick 2.7 | ||||
30 | import QtQuick.Controls 2.5 as QtControls | ||||
31 | | ||||
32 | QtControls.Button { | ||||
33 | id: component | ||||
34 | | ||||
35 | /** | ||||
36 | * The configuration file to use for this button | ||||
37 | */ | ||||
38 | property alias configFile: ghnsDialog.configFile | ||||
39 | | ||||
40 | /** | ||||
41 | * Set the text that should appear on the button. Will be set as | ||||
42 | * i18n("Download New %1"). The string is also used to give the dialog spawned | ||||
43 | * by clicking the button its title (the same as the button's text). | ||||
44 | * | ||||
45 | * @default The name defined by your knsrc config file | ||||
46 | * @note For the sake of consistency, you should NOT override the text propety, just set this one | ||||
47 | */ | ||||
48 | property string downloadNewWhat: ghnsDialog.engine.name | ||||
49 | text: i18n("Download New %1").arg(downloadNewWhat) | ||||
50 | | ||||
51 | /** | ||||
52 | * The default view mode of the dialog spawned by this button. This should be | ||||
53 | * set using the NewStuffPage.ViewMode enum | ||||
54 | * @see NewStuffPage.ViewMode | ||||
55 | */ | ||||
56 | property alias viewMode: ghnsDialog.viewMode | ||||
57 | | ||||
58 | /** | ||||
59 | * emitted when the Hot New Stuff dialog is about to be shown, usually | ||||
60 | * as a result of the user having click on the button | ||||
61 | */ | ||||
62 | signal aboutToShowDialog(); | ||||
63 | | ||||
64 | /** | ||||
65 | * emitted when the dialog has been closed | ||||
66 | */ | ||||
67 | signal dialogFinished(var changedEntries); | ||||
68 | | ||||
69 | /** | ||||
70 | * If this is true (default), the button will be hidden when the Kiosk settings are such | ||||
71 | * that Get Hot New Stuff is disallowed (and any other time enabled is set to false). | ||||
72 | * Usually you would want to leave this alone, but occasionally you may have a reason to | ||||
73 | * leave a button in place that the user is unable to enable. | ||||
74 | */ | ||||
75 | property bool hideWhenDisabled: true | ||||
76 | | ||||
77 | /** | ||||
78 | * Show the dialog (same as clicking the button), if allowed by the Kiosk settings | ||||
79 | */ | ||||
80 | function showDialog() { | ||||
81 | if (ghnsDialog.engine.allowedByKiosk) { | ||||
82 | component.aboutToShowDialog(); | ||||
83 | ghnsDialog.open(); | ||||
84 | } else { | ||||
85 | // make some noise, because silently doing nothing is a bit annoying | ||||
86 | } | ||||
87 | } | ||||
88 | | ||||
89 | onClicked: { showDialog(); } | ||||
90 | | ||||
91 | icon.name: "get-hot-new-stuff" | ||||
92 | visible: enabled && hideWhenDisabled | ||||
93 | enabled: ghnsDialog.engine.allowedByKiosk | ||||
94 | | ||||
95 | NewStuffDialog { | ||||
96 | id: ghnsDialog | ||||
97 | onDialogFinished: { component.dialogFinished(changedEntries); } | ||||
98 | } | ||||
99 | } |