| 1 |
/* |
| 2 |
* Copyright (C) 2013 Canonical Ltd |
| 3 |
* |
| 4 |
* This program is free software: you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License version 3 as |
| 6 |
* published by the Free Software Foundation. |
| 7 |
* |
| 8 |
* This program is distributed in the hope that it will be useful, |
| 9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
* GNU General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU General Public License |
| 14 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 |
* |
| 16 |
* Authored by: Arto Jalkanen <[email protected]> |
| 17 |
*/ |
| 18 |
import QtQuick 2.4 |
| 19 |
import Lomiri.Components 1.3 |
| 20 |
import Lomiri.Components.Popups 1.3 |
| 21 |
import Lomiri.FileManager.folderlistmodel 1.0 |
| 22 |
|
| 23 |
Dialog { |
| 24 |
id: root |
| 25 |
property FolderListModel model |
| 26 |
property Page page |
| 27 |
property string descriptionPrepend: i18n.tr("Operation in progress") |
| 28 |
|
| 29 |
title: i18n.tr("File operation") |
| 30 |
text: descriptionPrepend |
| 31 |
|
| 32 |
function startOperation(name) { |
| 33 |
root.title = name |
| 34 |
} |
| 35 |
|
| 36 |
ProgressBar { |
| 37 |
id: progress |
| 38 |
minimumValue: 0.0 |
| 39 |
maximumValue: 100.0 |
| 40 |
value: 0.0 |
| 41 |
} |
| 42 |
|
| 43 |
Button { |
| 44 |
text: i18n.tr("Cancel") |
| 45 |
onClicked: { |
| 46 |
console.log("Cancelling file progress action") |
| 47 |
model.cancelAction() |
| 48 |
PopupUtils.close(root) |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
Connections { |
| 53 |
target: model |
| 54 |
onProgress: { |
| 55 |
// curItem == 0 && percent == 0 means the Action has just been created, check getProgressCounter() before |
| 56 |
if (curItem == 0 && percent == 0) { |
| 57 |
console.log("Creating dialog:", model.getProgressCounter()) |
| 58 |
if (model.getProgressCounter() > 20) { |
| 59 |
// show/activate/make visible the dialog here |
| 60 |
print("Showing dialog...") |
| 61 |
PopupUtils.open(root, page) |
| 62 |
root.show() |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
console.log("On progress ", curItem, totalItems, percent) |
| 67 |
|
| 68 |
progress.value = percent |
| 69 |
if (percent == 100 && curItem == totalItems) { |
| 70 |
console.log("All files processed, closing progress dialog") |
| 71 |
//PopupUtils.close(root) |
| 72 |
root.hide() |
| 73 |
} else { |
| 74 |
root.text = descriptionPrepend + " (" + curItem + "/" + totalItems + ")" |
| 75 |
} |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
// Errors from model |
| 80 |
Connections { |
| 81 |
target: model |
| 82 |
onError: { |
| 83 |
PopupUtils.close(root) |
| 84 |
} |
| 85 |
} |
| 86 |
} |