| 1 |
/* Copyright (C) 2014-2016 Dan Chapman <[email protected]> |
| 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 |
*/ |
| 18 |
import QtQuick 2.4 |
| 19 |
import Lomiri.Components 1.3 |
| 20 |
import Lomiri.Components.Popups 1.3 |
| 21 |
|
| 22 |
// NOTE when queuing a popup make sure to add the parent and properties, even if the properties is empty {} |
| 23 |
// USAGE: popupQueue.queue("PopupPath", root, {}) |
| 24 |
QtObject { |
| 25 |
id: popupQueue |
| 26 |
|
| 27 |
readonly property bool popupVisible: __popupOnScreen |
| 28 |
readonly property int queueSize: __popups.length |
| 29 |
|
| 30 |
property bool __popupOnScreen: false |
| 31 |
// List of queued popups |
| 32 |
property var __popups: [] |
| 33 |
// List of properties to be attched to the popups |
| 34 |
property var __properties: [] |
| 35 |
// List of popup parent's |
| 36 |
property var __parents: [] |
| 37 |
|
| 38 |
property Timer __timer: Timer { |
| 39 |
id: timer |
| 40 |
interval: 20 |
| 41 |
repeat: false |
| 42 |
onTriggered: { |
| 43 |
if (!__popups.length) { |
| 44 |
return; |
| 45 |
} |
| 46 |
console.log("Popup queue triggered") |
| 47 |
if (!__popupOnScreen && __popups.length) { |
| 48 |
__showNextPopup(__popups.shift(), __parents.shift(), __properties.shift()); |
| 49 |
} |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
function queue(popup, parent, properties) { |
| 54 |
__popups.push(popup) |
| 55 |
__parents.push(parent) |
| 56 |
__properties.push(properties) |
| 57 |
timer.start() |
| 58 |
} |
| 59 |
|
| 60 |
function __showNextPopup(popup, parent, properties) { |
| 61 |
var nextPopup = PopupUtils.open(popup, parent, properties) |
| 62 |
nextPopup.closing.connect(__popupOnScreenClosed) |
| 63 |
__popupOnScreen = true |
| 64 |
} |
| 65 |
|
| 66 |
function __popupOnScreenClosed() { |
| 67 |
__popupOnScreen = false |
| 68 |
// Trigger the next one |
| 69 |
timer.start() |
| 70 |
} |
| 71 |
} |