Debian Codegraph @

qml/Viewfinder/BarcodeReaderOverlay.qml

raw
1 /*
2 * Copyright 2014 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 as published by
6 * the Free Software Foundation; version 3.
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
17 import QtQuick 2.4
18 import QtQuick.Window 2.2
19 import Lomiri.Components 1.3
20 import Lomiri.Components.Popups 1.3
21 import Lomiri.Content 1.3
22 import QtMultimedia 5.9
23 import QtPositioning 5.2
24 import QtSensors 5.0
25 import CameraApp 0.1
26 import Qt.labs.settings 1.0
27 import QtGraphicalEffects 1.0
28
29 import "../components"
30
31 Item {
32 id: viewFinderOverlay
33
34 property Camera camera
35 property bool touchAcquired: zoomPinchArea.active || tagDetailsOpen
36 property var controls: controls
37 property var settings: settings
38 property bool readyForCapture
39 property int sensorOrientation
40 // Sometimes the value is FlashVideoLight, sometimes it's FlashTorch
41 property int videoFlashOnValue: Camera.FlashVideoLight
42 property alias tagDetailsOpen : tagDetailsOverlay.open
43
44 function showFocusRing(x, y) {
45 focusRing.center = Qt.point(x, y);
46 focusRing.show();
47 }
48
49 Settings {
50 id: settings
51
52 property int flashMode: Camera.FlashAuto
53 property bool gpsEnabled: false
54 property bool hdrEnabled: false
55 property bool videoFlashOn: false
56 // Left for compatibility
57 property int videoFlashMode: -1
58 property int selfTimerDelay: 0
59 property int encodingQuality: 2 // QMultimedia.NormalQuality
60 property bool gridEnabled: false
61 property bool preferRemovableStorage: false
62 property bool playShutterSound: true
63 property bool shutterVibration: false
64 property var photoResolutions
65 property var videoResolutions
66 // Left for compatibility
67 property string videoResolution: ""
68 property bool dateStampImages: false
69 property string dateStampFormat: Qt.locale().dateFormat(Locale.ShortFormat)
70 property color dateStampColor: LomiriColors.orange;
71 property real dateStampOpacity: 1.0;
72 property int dateStampAlign : Qt.AlignBottom | Qt.AlignRight;
73
74 Component.onCompleted: {
75 if (!photoResolutions) photoResolutions = {}
76
77 if (!videoResolutions) {
78 videoResolutions = {}
79 if (videoResolution)
80 // Migrate old value into default camera
81 setVideoResolution(videoResolution);
82 }
83
84 if (videoFlashMode != -1) {
85 videoFlashOn = (videoFlashMode != Camera.FlashOff);
86 videoFlashMode = -1;
87 }
88 }
89
90 onPhotoResolutionsChanged: updateViewfinderResolution();
91 onVideoResolutionsChanged: updateViewfinderResolution();
92
93 onFlashModeChanged: if (flashMode != Camera.FlashOff) hdrEnabled = false;
94 onHdrEnabledChanged: if (hdrEnabled) flashMode = Camera.FlashOff
95 }
96
97 Binding {
98 target: camera.flash
99 property: "mode"
100 value: settings.flashMode
101 when: camera.captureMode == Camera.CaptureStillImage
102 }
103
104 Binding {
105 target: camera.flash
106 property: "mode"
107 value: settings.videoFlashOn && viewFinderView.inView ? videoFlashOnValue : Camera.FlashOff
108 when: camera.captureMode == Camera.CaptureVideo
109 }
110
111 Binding {
112 target: camera.advanced
113 property: "hdrEnabled"
114 value: settings.hdrEnabled
115 }
116
117 Binding {
118 target: camera.advanced
119 property: "encodingQuality"
120 value: settings.encodingQuality
121 }
122
123 Binding {
124 target: camera.videoRecorder
125 property: "resolution"
126 value: settings.videoResolutions[camera.deviceId] || Qt.size(-1, -1)
127 }
128
129 Binding {
130 target: camera.imageCapture
131 property: "resolution"
132 value: settings.photoResolutions[camera.deviceId] || Qt.size(-1, -1)
133 }
134
135 // FIXME: where's the proper location for this?
136 function updateViewfinderResolution() {
137 var EPSILON = 0.02;
138 var supportedViewfinderResolutions = camera.supportedViewfinderResolutions();
139
140 if (supportedViewfinderResolutions.length === 0) {
141 console.log("updateViewfinderResolution: viewfinder resolutions is not known yet.");
142 return;
143 }
144
145 var targetResolution = stringToSize(
146 camera.captureMode === Camera.CaptureStillImage
147 ? settings.photoResolutions[camera.deviceId]
148 : settings.videoResolutions[camera.deviceId]
149 );
150
151 if (!targetResolution) {
152 // Resolution has not been selected yet.
153 return;
154 }
155
156 var targetAspectRatio = targetResolution.width / targetResolution.height;
157 var selectedResolution;
158
159 // Select the highest resolution with matching aspect ratio.
160 for (var i = 0; i < supportedViewfinderResolutions.length; i++) {
161 var currentResolution = supportedViewfinderResolutions[i];
162 var currentAspectRatio = currentResolution.width / currentResolution.height;
163
164 if (Math.abs(targetAspectRatio - currentAspectRatio) > EPSILON)
165 continue;
166
167 if (!selectedResolution ||
168 currentResolution.width > selectedResolution.width) {
169 selectedResolution = currentResolution;
170 }
171 }
172
173 if (!selectedResolution) {
174 // This is strange. Not sure why this would happen.
175 console.log("updateViewfinderResolution: cannot find suitable viewfinder resolution. Use the default one.");
176 selectedResolution = supportedViewfinderResolutions[0];
177 }
178
179 console.log("updateViewfinderResolution: For target resolution " +
180 sizeToString(targetResolution) + ", select " +
181 sizeToString(selectedResolution) + " for viewfinder resolution.");
182
183 camera.viewfinder.resolution =
184 Qt.size(selectedResolution.width, selectedResolution.height);
185 }
186
187 function updateVideoFlashOnValue() {
188 if (camera.captureMode != Camera.CaptureVideo) {
189 // The value can be probed only in video mode.
190 return;
191 }
192
193 var supportedModes = camera.flash.supportedModes;
194 for (var i = 0; i < supportedModes.length; i++) {
195 if (supportedModes[i] === Camera.FlashVideoLight ||
196 supportedModes[i] === Camera.FlashTorch) {
197 videoFlashOnValue = supportedModes[i];
198 return;
199 }
200 }
201 }
202
203 Connections {
204 target: camera.imageCapture
205 onImageCaptured: {
206 if(settings.shutterVibration) {
207 Haptics.play({intensity:0.25,duration:LomiriAnimation.SnapDuration/3});
208 }
209 }
210 }
211
212 Connections {
213 target: camera.flash
214 onSupportedModesChanged: { updateVideoFlashOnValue(); }
215 }
216
217 Connections {
218 target: camera
219 onCaptureModeChanged: {
220 updateViewfinderResolution();
221 }
222
223 onCameraStatusChanged: {
224 // Supported viewfinder resolution is guaranteed to be known at
225 // ActiveStatus, if not earlier.
226 if (camera.cameraStatus == Camera.LoadedStatus
227 || camera.cameraStatus == Camera.ActiveStatus) {
228 updateViewfinderResolution();
229 }
230 }
231 }
232
233 function resolutionToLabel(resolution) {
234 // takes in a resolution string (e.g. "1920x1080") and returns a nicer
235 // form of it for display in the UI: "1080p"
236 return resolution.split("x").pop() + "p";
237 }
238
239 function sizeToString(size) {
240 return size.width + "x" + size.height;
241 }
242
243 function stringToSize(resolution) {
244 var r = resolution.split("x");
245 return Qt.size(r[0], r[1]);
246 }
247
248 function sizeToAspectRatio(size) {
249 var ratio = Math.max(size.width, size.height) / Math.min(size.width, size.height);
250 var maxDenominator = 12;
251 var epsilon;
252 var numerator;
253 var denominator;
254 var bestDenominator;
255 var bestEpsilon = 10000;
256 for (denominator = 2; denominator <= maxDenominator; denominator++) {
257 numerator = ratio * denominator;
258 epsilon = Math.abs(Math.round(numerator) - numerator);
259 if (epsilon < bestEpsilon) {
260 bestEpsilon = epsilon;
261 bestDenominator = denominator;
262 }
263 }
264 numerator = Math.round(ratio * bestDenominator);
265 return "%1:%2".arg(numerator).arg(bestDenominator);
266 }
267
268 function sizeToMegapixels(size) {
269 var megapixels = (size.width * size.height) / 1000000;
270 return parseFloat(megapixels.toFixed(1))
271 }
272
273 function trimNumberToFit(numberStr, digits) {
274 return (""+numberStr).substr(0,digits).replace(/\.$/,"");
275 }
276
277 function updateVideoResolutionOptions() {
278 // Clear and refill videoResolutionOptionsModel with available resolutions
279 // Try to only display well known resolutions: 1080p, 720p and 480p
280 videoResolutionOptionsModel.clear();
281 var supported = camera.advanced.videoSupportedResolutions;
282 var wellKnown = ["1920x1080", "1280x720", "640x480"];
283
284 var supportedFiltered = supported.filter(function (resolution) {
285 return wellKnown.indexOf(resolution) !== -1;
286 });
287
288 if (supportedFiltered.length === 0)
289 supportedFiltered = supported.slice();
290
291 // Sort resolutions from low to high, but then insert them into model
292 // in reverse order (so that highest resolution appear first).
293 supportedFiltered.sort(function(a, b) {
294 return a.split("x")[0] - b.split("x")[0];
295 });
296
297 for (var i=0; i<supportedFiltered.length; i++) {
298 var resolution = supportedFiltered[i];
299 var option = {"icon": "",
300 "label": resolutionToLabel(resolution),
301 "value": resolution};
302 videoResolutionOptionsModel.insert(0, option);
303 }
304
305 // If resolution setting chosen is not supported select the highest available resolution
306 if (supportedFiltered.length > 0
307 && supportedFiltered.indexOf(settings.videoResolutions[camera.deviceId]) === -1) {
308 setVideoResolution(supportedFiltered[supportedFiltered.length - 1]);
309 }
310 }
311
312 function updatePhotoResolutionOptions() {
313 // Clear and refill photoResolutionOptionsModel with available resolutions
314 photoResolutionOptionsModel.clear();
315
316
317 //Change to Size object and sort the resolutions by megapixel ( in reverse order so it goes from top high to bottom low )
318 var sortedResolutions = [];
319 for(var i in camera.advanced.imageSupportedResolutions) {
320 sortedResolutions.push( stringToSize(camera.advanced.imageSupportedResolutions[i]) );
321 }
322 sortedResolutions.sort(function(a, b) { return sizeToMegapixels(b) - sizeToMegapixels(a) });
323
324 for(var i in sortedResolutions) {
325 var res = sortedResolutions[i];
326 photoResolutionOptionsModel.insert(i,{"icon": "",
327 "label": "%1 (%2MP)".arg(sizeToAspectRatio(res))
328 .arg(sizeToMegapixels(res)),
329 "value": sizeToString(res)});
330 }
331
332 // If resolution setting is not supported select the resolution automatically
333 var photoResolution = settings.photoResolutions[camera.deviceId];
334 if (!isPhotoResolutionAnOption(photoResolution)) {
335 setPhotoResolution(getAutomaticPhotoResolution());
336 }
337
338 }
339
340 function setPhotoResolution(resolution) {
341 var size = stringToSize(resolution);
342 if (size.width > 0 && size.height > 0
343 && resolution != settings.photoResolutions[camera.deviceId]) {
344 settings.photoResolutions[camera.deviceId] = resolution;
345 // FIXME: resetting the value of the property 'photoResolutions' is
346 // necessary to ensure that a change notification signal is emitted
347 settings.photoResolutions = settings.photoResolutions;
348 }
349 }
350
351 function setVideoResolution(resolution) {
352 if (resolution !== settings.videoResolutions[camera.deviceId]) {
353 settings.videoResolutions[camera.deviceId] = resolution;
354 // FIXME: resetting the value of the property 'videoResolutions' is
355 // necessary to ensure that a change notification signal is emitted
356 settings.videoResolutions = settings.videoResolutions;
357 }
358 }
359
360 function getAutomaticPhotoResolution() {
361 var fittingResolution = sizeToString(camera.advanced.fittingResolution);
362 var maximumResolution = sizeToString(camera.advanced.maximumResolution);
363 if (isPhotoResolutionAnOption(fittingResolution)) {
364 return fittingResolution;
365 } else {
366 return maximumResolution;
367 }
368 }
369
370 function isPhotoResolutionAnOption(resolution) {
371 for (var i=0; i<photoResolutionOptionsModel.count; i++) {
372 var option = photoResolutionOptionsModel.get(i);
373 if (option.value == resolution) {
374 return true;
375 }
376 }
377 return false;
378 }
379
380 Connections {
381 target: camera.advanced
382 onVideoSupportedResolutionsChanged: updateVideoResolutionOptions();
383 onImageSupportedResolutionsChanged: updatePhotoResolutionOptions();
384 onFittingResolutionChanged: updatePhotoResolutionOptions();
385 onMaximumResolutionChanged: updatePhotoResolutionOptions();
386 }
387
388 Connections {
389 target: camera
390 onDeviceIdChanged: {
391 // Clear viewfinder resolution settings as it might not be supported
392 // by the new device.
393 camera.viewfinder.resolution = Qt.size(-1, -1);
394 }
395 }
396
397 OrientationSensor {
398 id: orientationSensor
399 active: true
400 }
401
402 Item {
403 id: controls
404
405 anchors {
406 left: parent.left
407 right: parent.right
408 top: parent.top
409 bottom: parent.bottom
410 }
411 visible: opacity != 0.0
412 enabled: !tagDetailsOverlay.open
413
414 Behavior on opacity { LomiriNumberAnimation { duration: LomiriAnimation.FastDuration}}
415
416 Connections {
417 target: Qt.application
418 onActiveChanged: if (active) zoomControl.value = camera.currentZoom
419 }
420
421 PinchArea {
422 id: zoomPinchArea
423 anchors {
424 top: parent.top
425 bottom: parent.bottom
426 left: parent.left
427 right: parent.right
428 }
429
430 property real initialZoom
431 property real minimumScale: 0.3
432 property real maximumScale: 3.0
433 property bool active: false
434
435 enabled: !camera.photoCaptureInProgress && !camera.timedCaptureInProgress
436 onPinchStarted: {
437 active = true;
438 initialZoom = zoomControl.value;
439 zoomControl.show();
440 }
441 onPinchUpdated: {
442 zoomControl.show();
443 var scaleFactor = MathUtils.projectValue(pinch.scale, 1.0, maximumScale, 0.0, zoomControl.maximumValue);
444 zoomControl.value = MathUtils.clamp(initialZoom + scaleFactor, zoomControl.minimumValue, zoomControl.maximumValue);
445 }
446 onPinchFinished: {
447 active = false;
448 }
449
450 MouseArea {
451 id: manualFocusMouseArea
452 anchors.fill: parent
453 objectName: "manualFocusMouseArea"
454 enabled: !tagDetailsOverlay.open
455 onClicked: {
456 // mouse.x/y is relative to this item. Convert to be relative to the overlay,
457 // which in turn is relative to viewFinderView, where camera's VideoOutput resides.
458 var mappedPoint = mapToItem(viewFinderOverlay, mouse.x, mouse.y);
459 camera.manualFocus(mappedPoint.x, mappedPoint.y);
460 mouse.accepted = false;
461 }
462 }
463 }
464
465 Row {
466 anchors {
467 horizontalCenter: tagDetailsButton.horizontalCenter
468 verticalCenter: tagDetailsButton.verticalCenter
469 }
470 spacing: units.gu(2)
471 height: tagDetailsButton.height
472
473 opacity: (viewFinderView.recentlyScannedTag == "") ? 1.0 : 0.0
474 Behavior on opacity { LomiriNumberAnimation { duration: LomiriAnimation.FastDuration}}
475 visible: opacity != 0.0
476 enabled: opacity == 1.0 && !tagDetailsOverlay.open && !tagDetailsOverlay.visible
477
478 ActivityIndicator {
479 id: scanActivityIndicator
480 running: parent.visible && (camera.cameraStatus == Camera.ActiveStatus)
481 height: parent.height
482 }
483
484 Label {
485 anchors {
486 verticalCenter: scanActivityIndicator.verticalCenter
487 }
488 text: camera.cameraStatus == Camera.ActiveStatus ?
489 i18n.tr("Scanning...") : i18n.tr("Preparing...")
490 textSize: Label.Large
491 color: "white"
492 }
493 }
494
495 CircleButton {
496 id: tagDetailsButton
497 objectName: "tagDetailsButton"
498
499 anchors {
500 bottom: parent.bottom
501 bottomMargin: units.gu(3)
502 horizontalCenter: parent.horizontalCenter
503 }
504 height: units.gu(7)
505 width: height
506
507 opacity: (viewFinderView.recentlyScannedTag != "") ? 1.0 : 0.0
508 Behavior on opacity { LomiriNumberAnimation { duration: LomiriAnimation.FastDuration} }
509 visible: opacity != 0.0
510 enabled: visible
511 iconSource: !tagDetailsOverlay.open ? "../../assets/qr.svg" : ""
512 iconName: tagDetailsOverlay.open ? "close" : ""
513
514 onClicked: {
515 tagDetailsOverlay.open = true
516 }
517 }
518
519 ZoomControl {
520 id: zoomControl
521
522 anchors {
523 bottom: parent.bottom
524 bottomMargin: units.gu(2)
525 left: parent.left
526 right: parent.right
527 }
528 maximumValue: camera.maximumZoom
529
530 Binding { target: camera; property: "currentZoom"; value: zoomControl.value }
531 }
532
533 FocusRing {
534 id: focusRing
535 }
536
537 CircleButton {
538 id: exportBackButton
539 objectName: "exportBackButton"
540
541 anchors {
542 top: parent.top
543 topMargin: units.gu(4)
544 left: parent.left
545 }
546
547 iconName: visible ? "go-previous" : ""
548 visible: main.contentExportMode
549 enabled: main.contentExportMode
550 onClicked: main.cancelExport()
551 }
552 }
553
554 MouseArea {
555 anchors.fill: parent
556 enabled: tagDetailsOverlay.open
557 onClicked: {
558 tagDetailsOverlay.open = false
559 mouse.accepted = true;
560 }
561 }
562
563 LomiriShapeOverlay {
564 id: tagDetailsOverlay
565 backgroundColor: "black"
566
567 property bool open : false
568
569 anchors {
570 bottom: parent.bottom
571 bottomMargin: viewFinderOverlay.height - tagDetailsButton.y + units.gu(3)
572 horizontalCenter: parent.horizontalCenter
573 }
574
575 /*
576 // Wrong geometry when opened sideways
577 rotation: Screen.angleBetween(Screen.primaryOrientation, Screen.orientation)
578 Behavior on rotation {
579 RotationAnimator {
580 duration: LomiriAnimation.BriskDuration
581 easing: LomiriAnimation.StandardEasing
582 direction: RotationAnimator.Shortest
583 }
584 }
585 */
586 readonly property bool sideways : (rotation == 90 || rotation == 270)
587
588 opacity: tagDetailsOverlay.open ? 1.0 : 0.0
589 visible: opacity != 0.0
590 Behavior on opacity { LomiriNumberAnimation { duration: LomiriAnimation.FastDuration} }
591 onOpacityChanged: {
592 if (opacity == 0.0) {
593 viewFinderView.recentlyScannedTag = ""
594 }
595 }
596
597 readonly property int preferredWidth: units.gu(28)
598 readonly property int maximumWidth: viewFinderOverlay.width - units.gu(4)
599 readonly property int preferredHeight: tagContentLabel.height + buttonContainer.height + units.gu(2)
600 readonly property int maximumHeight: parent.height - tagDetailsButton.height -
601 (tagDetailsButton.anchors.bottomMargin * 3)
602
603 readonly property int _width: Math.min(preferredWidth, maximumWidth)
604 readonly property int _height: Math.min(preferredHeight, maximumHeight)
605 width: !sideways ? _width : _height
606 height: !sideways ? _height : _width
607
608 function isUrl(tagText) {
609 if (tagText.startsWith("https://") || tagText.startsWith("http://") || tagText.startsWith("appid://"))
610 return true
611 return false;
612 }
613
614 // VCards without a name cannot be trusted
615 function isVCard(tagText) {
616 var text = tagText.trim()
617 return text.startsWith("BEGIN:VCARD") && text.endsWith("END:VCARD") && vCardText(tagText).length > 0
618 }
619
620 function vCardText(tagText) {
621 var lines = tagText.split('\n')
622 for (const line of lines) {
623 if (line.startsWith("FN:"))
624 return line.substring(3)
625 }
626 return ""
627 }
628
629 function displayText(tagText) {
630 if (isVCard(tagText))
631 return vCardText(tagText)
632 return tagText
633 }
634
635 ScrollView {
636 id: tagContentContainer
637 anchors {
638 top: parent.top
639 left: parent.left
640 right: parent.right
641 bottom: buttonContainer.top
642 margins: units.gu(1)
643 }
644 height: parent.height - buttonContainer.height
645
646 Label {
647 id: tagContentLabel
648 text: tagDetailsOverlay.displayText(viewFinderView.recentlyScannedTag)
649 textSize: Label.Large
650 color: "white"
651 wrapMode: Text.Wrap
652 horizontalAlignment: Text.AlignHCenter
653 verticalAlignment: Text.AlignVCenter
654 width: tagContentContainer.width
655 height: Math.max(contentHeight + units.gu(3), textSize + units.gu(3))
656 }
657 }
658
659 Row {
660 id: buttonContainer
661 height: units.gu(5)
662 spacing: units.gu(2)
663 anchors {
664 bottom: parent.bottom
665 horizontalCenter: parent.horizontalCenter
666 margins: units.gu(1)
667 }
668
669 CircleButton {
670 id: shareButton
671 iconName: "share"
672 automaticOrientation: false
673 anchors.verticalCenter: parent.verticalCenter
674 onClicked: {
675 qrTagPicker.contentType = tagDetailsOverlay.isUrl(viewFinderView.recentlyScannedTag) ?
676 ContentType.Links : ContentType.Text
677 qrTagPicker.stringToSend = viewFinderView.recentlyScannedTag
678 qrTagPicker.visible = true
679 tagDetailsOverlay.open = false
680 }
681 }
682
683 CircleButton {
684 id: addContactButton
685 iconName: "contact-new"
686 automaticOrientation: false
687 anchors.verticalCenter: parent.verticalCenter
688 visible: tagDetailsOverlay.isVCard(viewFinderView.recentlyScannedTag)
689 onVisibleChanged: {
690 buttonContainer.forceLayout()
691 }
692 onClicked: {
693 qrTagPicker.contentType = ContentType.Contacts
694 qrTagPicker.stringToSend = viewFinderView.recentlyScannedTag
695 qrTagPicker.visible = true
696 tagDetailsOverlay.open = false
697 }
698 }
699
700 CircleButton {
701 id: externalLinkButton
702 iconName: "external-link"
703 automaticOrientation: false
704 anchors.verticalCenter: parent.verticalCenter
705 visible: tagDetailsOverlay.isUrl(viewFinderView.recentlyScannedTag)
706 onVisibleChanged: {
707 buttonContainer.forceLayout()
708 }
709 onClicked: {
710 Qt.openUrlExternally(viewFinderView.recentlyScannedTag)
711 tagDetailsOverlay.open = false
712 }
713 }
714
715 CircleButton {
716 id: clipboardButton
717 iconName: "edit-copy"
718 automaticOrientation: false
719 anchors.verticalCenter: parent.verticalCenter
720 visible: viewFinderView.recentlyScannedTag
721 onVisibleChanged: {
722 buttonContainer.forceLayout()
723 }
724 onClicked: {
725 Clipboard.push(viewFinderView.recentlyScannedTag)
726 tagDetailsOverlay.open = false
727 }
728 }
729 }
730 }
731
732 Component {
733 id: qrTagContentItemComponent
734 ContentItem {}
735 }
736
737 FileOperations {
738 id: fileOperations
739 }
740
741 ContentPeerPicker {
742 id: qrTagPicker
743
744 property string stringToSend : ""
745 property var activeTransfer : null
746
747 anchors.fill: parent
748 visible: false
749
750 handler: ContentHandler.Destination
751 contentType: ContentType.Text
752
753 onPeerSelected: {
754 activeTransfer = peer.request();
755
756 if (contentType != ContentType.Text) {
757 var tmpFile = "file://" + fileOperations.createTemporaryFile(stringToSend)
758 activeTransfer.items = [ qrTagContentItemComponent.createObject(viewFinderOverlay,
759 {"url": tmpFile}) ];
760 } else {
761 activeTransfer.items = [ qrTagContentItemComponent.createObject(viewFinderOverlay,
762 {"text": stringToSend}) ];
763 }
764 activeTransfer.state = ContentTransfer.Charged;
765 visible = false
766 }
767
768 onCancelPressed: {
769 visible = false
770 }
771 }
772
773 ProcessingFeedback {
774 anchors {
775 top: parent.top
776 topMargin: units.gu(2)
777 left: parent.left
778 leftMargin: units.gu(2)
779 }
780 processing: camera.photoCaptureInProgress
781 }
782
783 Component {
784 id: readOnlyMediaDialogComponent
785 Dialog {
786 id: readOnlyMediaDialog
787 objectName: "readOnlyMediaDialog"
788 title: i18n.tr("External storage not writeable")
789 text: i18n.tr("It does not seem possible to write to your external storage media. Trying to eject and insert it again might solve the issue, or you might need to format it.")
790 Button {
791 text: i18n.tr("Cancel")
792 onClicked: PopupUtils.close(readOnlyMediaDialog)
793 }
794 }
795 }
796
797 Connections {
798 id: permissionErrorMonitor
799 property var currentPermissionsDialog: null
800 target: camera
801 onError: {
802 if (errorCode == Camera.ServiceMissingError) {
803 if (currentPermissionsDialog == null) {
804 currentPermissionsDialog = PopupUtils.open(noPermissionsDialogComponent);
805 }
806 camera.failedToConnect = true;
807 }
808 }
809 onCameraStateChanged: {
810 if (camera.cameraState != Camera.UnloadedState) {
811 if (currentPermissionsDialog != null) {
812 PopupUtils.close(currentPermissionsDialog);
813 currentPermissionsDialog = null;
814 }
815 camera.failedToConnect = false;
816 } else {
817 camera.photoCaptureInProgress = false;
818 }
819 }
820 }
821
822 Component {
823 id: noPermissionsDialogComponent
824 Dialog {
825 id: noPermissionsDialog
826 objectName: "noPermissionsDialog"
827 title: i18n.tr("Cannot access camera")
828 text: i18n.tr("Camera app doesn't have permission to access the camera hardware or another error occurred.\n\nIf granting permission does not resolve this problem, reboot your device.")
829 Button {
830 text: i18n.tr("Edit Permissions")
831 color: theme.palette.normal.focus
832 onClicked: {
833 Qt.openUrlExternally("settings:///system/security-privacy?service=camera");
834 PopupUtils.close(noPermissionsDialog);
835 permissionErrorMonitor.currentPermissionsDialog = null;
836 }
837 }
838 Button {
839 text: i18n.tr("Cancel")
840 onClicked: {
841 PopupUtils.close(noPermissionsDialog);
842 permissionErrorMonitor.currentPermissionsDialog = null;
843 }
844 }
845 }
846 }
847 }