arnaucube
arnaucube/openEventsPlatformAppPublic Self-hosted repository
openEventsPlatformApp/plugins/cordova-plugin-camera/src/ubuntu/camera.h
plugins/cordova-plugin-camera/src/ubuntu/camera.hRaw
 1/*
 2 *
 3 * Licensed to the Apache Software Foundation (ASF) under one
 4 * or more contributor license agreements.  See the NOTICE file
 5 * distributed with this work for additional information
 6 * regarding copyright ownership.  The ASF licenses this file
 7 * to you under the Apache License, Version 2.0 (the
 8 * "License"); you may not use this file except in compliance
 9 * with the License.  You may obtain a copy of the License at
10 *
11 *   http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied.  See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20*/
21
22#ifndef CAMERA_H
23#define CAMERA_H
24
25#include <cplugin.h>
26
27#include <QtCore>
28#include <QQuickView>
29#include <QCamera>
30#include <QtMultimediaWidgets/QCameraViewfinder>
31#include <QCameraImageCapture>
32
33class Camera: public CPlugin {
34    Q_OBJECT
35public:
36    explicit Camera(Cordova *cordova);
37
38    virtual const QString fullName() override {
39        return Camera::fullID();
40    }
41
42    virtual const QString shortName() override {
43        return "Camera";
44    }
45
46    static const QString fullID() {
47        return "Camera";
48    }
49
50public slots:
51    void takePicture(int scId, int ecId, int quality, int destinationType, int/*sourceType*/, int targetWidth, int targetHeight, int encodingType,
52                     int/*mediaType*/, bool/*allowEdit*/, bool/*correctOrientation*/, bool/*saveToPhotoAlbum*/, const QVariantMap &popoverOptions, int cameraDirection);
53    void cancel();
54
55    void onImageSaved(QString path);
56
57    QString generateLocation(const QString &extension) {
58        int i = 1;
59        for (;;++i) {
60            QString path = QString("%1/.local/share/%2/persistent/%3.%4").arg(QDir::homePath())
61                .arg(QCoreApplication::applicationName()).arg(i).arg(extension);
62
63            if (!QFileInfo(path).exists())
64                return path;
65        }
66    }
67private:
68    bool preprocessImage(QString &path);
69
70    int _lastScId;
71    int _lastEcId;
72    QSharedPointer<QCamera> _camera;
73
74    QVariantMap _options;
75protected:
76    enum DestinationType {
77        DATA_URL = 0,
78        FILE_URI = 1
79    };
80    enum EncodingType {
81        JPEG = 0,
82        PNG = 1
83    };
84};
85
86#endif // CAMERA_H