Dekko
Loading...
Searching...
No Matches
ToastQueue.qml
1/* Copyright (C) 2016 - 2017 Dan Chapman <dpniel@ubuntu.com>
2
3 This file is part of Dekko email client for Ubuntu devices
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of
8 the License or (at your option) version 3
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18import QtQuick 2.4
19
20// Now i'm a lover of toast so I couldn't resist to
21// use toast terminology in this component!
22// Should probably rename the component to Toaster :-D
23QtObject {
24
25 readonly property bool toastPopped: __toastPoppedUp
26 readonly property int count: __rounds.length
27
28 function orderToast(consumer, breadType, condiments) {
29 __consumer.push(consumer)
30 __rounds.push(breadType)
31 __condiments.push(condiments)
32 toaster.start()
33 }
34
35 property bool __toastPoppedUp: false
36 // Because i'm british you order toast in "rounds" which is basically
37 // a single slice of bread to a round.
38 property var __rounds: []
39 // Condiments are what you put on your toast. Jam/Marmalade or the daddy of all condiments "marmite"
40 // Condiments are the applied properties to the toast.
41 property var __condiments: []
42 // Consumer is usually the parent aka "me" but sometimes children can nab a round.
43 // Much to my detest!
44 // Consumer should be the component the round belongs too.
45 property var __consumer: []
46
47 // brownness timer. How long do you want to expose the rounds to the
48 // effects of the heating bars.
49 property Timer __timer: Timer {
50 id: toaster
51 interval: 20
52 onTriggered: {
53 // do we have more rounds to toast?
54 if (!__toastPoppedUp && __rounds.length) {
55 __serveToast(__consumer.shift(), __rounds.shift(), __condiments.shift())
56 }/* else {
57 toaster.start()
58 }*/
59 }
60 }
61
62 function __serveToast(consumer, toast, condiments) {
63// var c = Qt.createComponent(toast)
64 var t = toast.createObject(consumer, condiments)
65 t.closed.connect(__toastCollected)
66 __toastPoppedUp = true
67 }
68
69 function __toastCollected() {
70 __toastPoppedUp = false
71 // start the next order if there is one
72 toaster.start()
73 }
74}
75