~michael-sheldon/webbrowser-app/fix-1531179

« back to all changes in this revision

Viewing changes to src/app/webcontainer/ContentPickerDialog.qml

  • Committer: CI Train Bot
  • Author(s): Michael Sheldon
  • Date: 2015-12-21 20:39:33 UTC
  • mfrom: (1106.3.119 implement-download-folder)
  • Revision ID: ci-train-bot@canonical.com-20151221203933-o2ijlcmhhyoi62wk
Add support for handling downloads internally within the browser. Fixes: #1354391
Approved by: Olivier Tilloy

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2014-2015 Canonical Ltd.
 
3
 *
 
4
 * This file is part of webbrowser-app.
 
5
 *
 
6
 * webbrowser-app is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; version 3.
 
9
 *
 
10
 * webbrowser-app 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
 
 
19
import QtQuick 2.4
 
20
import Ubuntu.Components 1.3
 
21
import Ubuntu.Components.Popups 1.3 as Popups
 
22
import Ubuntu.Content 1.3
 
23
import "../MimeTypeMapper.js" as MimeTypeMapper
 
24
 
 
25
Component {
 
26
    Popups.PopupBase {
 
27
        id: picker
 
28
        objectName: "contentPickerDialog"
 
29
 
 
30
        // Set the parent at construction time, instead of letting show()
 
31
        // set it later on, which for some reason results in the size of
 
32
        // the dialog not being updated.
 
33
        parent: QuickUtils.rootItem(this)
 
34
 
 
35
        property var activeTransfer
 
36
 
 
37
        Rectangle {
 
38
            anchors.fill: parent
 
39
 
 
40
            ContentTransferHint {
 
41
                anchors.fill: parent
 
42
                activeTransfer: picker.activeTransfer
 
43
            }
 
44
 
 
45
            ContentPeerPicker {
 
46
                id: peerPicker
 
47
                anchors.fill: parent
 
48
                visible: true
 
49
                contentType: ContentType.All
 
50
                handler: ContentHandler.Source
 
51
 
 
52
                onPeerSelected: {
 
53
                    if (model.allowMultipleFiles) {
 
54
                        peer.selectionType = ContentTransfer.Multiple
 
55
                    } else {
 
56
                        peer.selectionType = ContentTransfer.Single
 
57
                    }
 
58
                    picker.activeTransfer = peer.request()
 
59
                    stateChangeConnection.target = picker.activeTransfer
 
60
                }
 
61
 
 
62
                onCancelPressed: {
 
63
                    model.reject()
 
64
                }
 
65
            }
 
66
        }
 
67
 
 
68
        Connections {
 
69
            id: stateChangeConnection
 
70
            target: null
 
71
            onStateChanged: {
 
72
                if (picker.activeTransfer.state === ContentTransfer.Charged) {
 
73
                    var selectedItems = []
 
74
                    for(var i in picker.activeTransfer.items) {
 
75
                        selectedItems.push(String(picker.activeTransfer.items[i].url).replace("file://", ""))
 
76
                    }
 
77
                    model.accept(selectedItems)
 
78
                }
 
79
            }
 
80
        }
 
81
 
 
82
        Component.onCompleted: {
 
83
            if(acceptTypes.length === 1) {
 
84
                var contentType = MimeTypeMapper.mimeTypeToContentType(acceptTypes[0])
 
85
                if(contentType == ContentType.Unknown) {
 
86
                    // If we don't recognise the type, allow uploads from any app
 
87
                    contentType = ContentType.All
 
88
                }
 
89
                peerPicker.contentType = contentType
 
90
            } else {
 
91
                peerPicker.contentType = ContentType.All
 
92
            }
 
93
            show()
 
94
        }
 
95
    }
 
96
}