summaryrefslogtreecommitdiffstats
path: root/src/plugins/symbian/ecam/s60camerasettings.cpp
blob: a5918078fca3f2f3431cea8a030bc6b65e893e48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "s60camerasettings.h"
#include "s60cameraconstants.h"

// S60 3.2 Platform
#ifdef USE_S60_32_ECAM_ADVANCED_SETTINGS_HEADER
#define POST_31_PLATFORM
#include <ecamadvancedsettings.h> // CCameraAdvancedSettings (inc. TValueInfo)
#endif // S60 3.2

// S60 5.0 or later
#ifdef USE_S60_50_ECAM_ADVANCED_SETTINGS_HEADER
#define POST_31_PLATFORM
#include <ecamadvsettings.h>    // CCameraAdvancedSettings
#include <ecam/ecamconstants.h> // TValueInfo
#endif // S60 5.0 or later

S60CameraSettings::S60CameraSettings(QObject *parent, CCameraEngine *engine) :
    QObject(parent),
#ifndef S60_31_PLATFORM // Post S60 3.1 Platforms
    m_advancedSettings(0),
    m_imageProcessingSettings(0),
#endif // S60_31_PLATFORM
    m_cameraEngine(engine),
    m_continuousFocusing(false)
{
}

S60CameraSettings::~S60CameraSettings()
{
#ifdef POST_31_PLATFORM
    if (m_advancedSettings) {
        delete m_advancedSettings;
        m_advancedSettings = 0;
    }

    if (m_imageProcessingSettings) {
        delete m_imageProcessingSettings;
        m_imageProcessingSettings = 0;
    }
#endif // POST_31_PLATFORM
}

/*
 * This is Symbian NewL kind of consructor, but unlike Symbian version this
 * constructor will not leave, but instead it will return possible errors in
 * the error variable. This is to be able to write the class without deriving
 * it form CBase. Also CleanupStack is cleaned here if the ConstructL leaves.
 */
S60CameraSettings* S60CameraSettings::New(int &error, QObject *parent, CCameraEngine *engine)
{
    S60CameraSettings* self = new S60CameraSettings(parent, engine);
    if (!self) {
        error = KErrNoMemory;
        return 0;
    }

    TRAPD(err, self->ConstructL());
    if (err) {
        // Clean created object
        delete self;
        self = 0;
        error = err;
        return 0;
    }

    error = KErrNone;
    return self;
}

void S60CameraSettings::ConstructL()
{
#ifdef POST_31_PLATFORM
    if (!m_cameraEngine)
        User::Leave(KErrGeneral);
    // From now on it is safe to assume engine exists

    // If no AdvancedSettings is available, there's no benefit of S60CameraSettings
    // Leave if creation fails
    m_advancedSettings = CCamera::CCameraAdvancedSettings::NewL(*m_cameraEngine->Camera());
    CleanupStack::PushL(m_advancedSettings);

    // ImageProcessing module may not be supported, don't Leave
    TRAPD(err, m_imageProcessingSettings = CCamera::CCameraImageProcessing::NewL(*m_cameraEngine->Camera()));
    if (err == KErrNone && m_imageProcessingSettings) {
        CleanupStack::PushL(m_imageProcessingSettings);
    } else {
        if (err == KErrNotSupported)
            m_imageProcessingSettings = 0;
        else {
            // Leave with error
            if (!m_imageProcessingSettings)
                User::Leave(KErrNoMemory);
            else
                User::Leave(err);
        }
    }

    if (m_advancedSettings) {
        RArray<TInt> digitalZoomFactors;
        CleanupClosePushL(digitalZoomFactors);

        TValueInfo info = ENotActive;
        m_advancedSettings->GetDigitalZoomStepsL(digitalZoomFactors, info);

        for (int i = 0; i < digitalZoomFactors.Count(); ++i)
            m_supportedSymbianDigitalZoomFactors << digitalZoomFactors[i];

        CleanupStack::PopAndDestroy(); // RArray<TInt> digitalZoomFactors
    }

    // Pop objects from CleanupStack
    if (m_imageProcessingSettings)
        CleanupStack::Pop(m_imageProcessingSettings);
    CleanupStack::Pop(m_advancedSettings);

#else // S60 3.1
    // AdvancedSettings are not suppoted on S60 3.1 (There's no use for S60CameraSettings)
    User::Leave(KErrNotSupported);
#endif // POST_31_PLATFORM
}

void S60CameraSettings::setFocusMode(QCameraFocus::FocusMode mode)
{
#ifdef POST_31_PLATFORM
    if (m_advancedSettings) {
        switch (mode) {
            case QCameraFocus::ManualFocus: // Manual focus mode
                m_advancedSettings->SetFocusMode(CCamera::CCameraAdvancedSettings::EFocusModeManual);
                m_continuousFocusing = false;
                break;
            case QCameraFocus::AutoFocus: // Single-shot AutoFocus mode
                m_advancedSettings->SetFocusMode(CCamera::CCameraAdvancedSettings::EFocusModeAuto);
                m_advancedSettings->SetFocusRange(CCamera::CCameraAdvancedSettings::EFocusRangeAuto);
                m_continuousFocusing = false;
                break;
            case QCameraFocus::HyperfocalFocus:
                m_advancedSettings->SetFocusMode(CCamera::CCameraAdvancedSettings::EFocusModeAuto);
                m_advancedSettings->SetFocusRange(CCamera::CCameraAdvancedSettings::EFocusRangeHyperfocal);
                m_continuousFocusing = false;
                break;
            case QCameraFocus::InfinityFocus:
                m_advancedSettings->SetFocusMode(CCamera::CCameraAdvancedSettings::EFocusModeAuto);
                m_advancedSettings->SetFocusRange(CCamera::CCameraAdvancedSettings::EFocusRangeInfinite);
                m_continuousFocusing = false;
                break;
            case QCameraFocus::ContinuousFocus:
                m_advancedSettings->SetFocusMode(CCamera::CCameraAdvancedSettings::EFocusModeAuto);
                m_advancedSettings->SetFocusRange(CCamera::CCameraAdvancedSettings::EFocusRangeAuto);
                m_continuousFocusing = true;
                break;
            case QCameraFocus::MacroFocus:
                m_advancedSettings->SetFocusMode(CCamera::CCameraAdvancedSettings::EFocusModeAuto);
                m_advancedSettings->SetFocusRange(CCamera::CCameraAdvancedSettings::EFocusRangeMacro);
                m_continuousFocusing = false;
                break;

            default:
                emit error(QCamera::NotSupportedFeatureError, tr("Requested focus mode is not supported."));
                break;
        }
    } else {
        emit error(QCamera::CameraError, tr("Unexpected camera error."));
    }
#else // S60 3.1
    Q_UNUSED(mode);
    emit error(QCamera::NotSupportedFeatureError, tr("Settings focus mode is not supported."));
#endif // POST_31_PLATFORM
}

void S60CameraSettings::startFocusing()
{
#ifdef POST_31_PLATFORM
    // Setting AutoFocusType triggers the focusing on Symbian
    if (m_advancedSettings) {
        if (m_continuousFocusing)
            m_advancedSettings->SetAutoFocusType(CCamera::CCameraAdvancedSettings::EAutoFocusTypeContinuous);
        else
            m_advancedSettings->SetAutoFocusType(CCamera::CCameraAdvancedSettings::EAutoFocusTypeSingle);
    } else {
        emit error(QCamera::CameraError, tr("Unable to focus."));
    }
#endif // POST_31_PLATFORM
}

void S60CameraSettings::cancelFocusing()
{
#ifdef POST_31_PLATFORM
    if (m_advancedSettings)
        m_advancedSettings->SetAutoFocusType(CCamera::CCameraAdvancedSettings::EAutoFocusTypeOff);
    else
        emit error(QCamera::CameraError, tr("Unable to cancel focusing."));
#endif // POST_31_PLATFORM
}

QCameraFocus::FocusMode S60CameraSettings::focusMode()
{
#ifdef POST_31_PLATFORM
    if (m_advancedSettings) {
        // First request needed info
        CCamera::CCameraAdvancedSettings::TFocusMode mode = m_advancedSettings->FocusMode();
        CCamera::CCameraAdvancedSettings::TFocusRange range = m_advancedSettings->FocusRange();
        CCamera::CCameraAdvancedSettings::TAutoFocusType autoType = m_advancedSettings->AutoFocusType();

        switch (mode) {
        case CCamera::CCameraAdvancedSettings::EFocusModeManual:
        case CCamera::CCameraAdvancedSettings::EFocusModeFixed:
            return QCameraFocus::ManualFocus;

        case CCamera::CCameraAdvancedSettings::EFocusModeAuto:
            if (autoType == CCamera::CCameraAdvancedSettings::EAutoFocusTypeContinuous) {
                return QCameraFocus::ContinuousFocus;
            } else {
                // Single-shot focusing
                switch (range) {
                case CCamera::CCameraAdvancedSettings::EFocusRangeMacro:
                case CCamera::CCameraAdvancedSettings::EFocusRangeSuperMacro:
                    return QCameraFocus::MacroFocus;
                case CCamera::CCameraAdvancedSettings::EFocusRangeHyperfocal:
                    return QCameraFocus::HyperfocalFocus;
                case CCamera::CCameraAdvancedSettings::EFocusRangeInfinite:
                    return QCameraFocus::InfinityFocus;
                case CCamera::CCameraAdvancedSettings::EFocusRangeAuto:
                case CCamera::CCameraAdvancedSettings::EFocusRangeNormal:
                    return QCameraFocus::AutoFocus;

                default:
                    return QCameraFocus::AutoFocus;
                }
            }
        default:
            return QCameraFocus::AutoFocus; // Return automatic focusing
        }
    } else {
        emit error(QCamera::CameraError, tr("Unexpected camera error."));
    }
#endif // POST_31_PLATFORM
    return QCameraFocus::AutoFocus; // Return automatic focusing
}

QCameraFocus::FocusModes S60CameraSettings::supportedFocusModes()
{
    QCameraFocus::FocusModes modes = 0;

#ifdef POST_31_PLATFORM
    TInt supportedModes = 0;
    TInt autoFocusTypes = 0;
    TInt supportedRanges = 0;

    if (m_advancedSettings) {
        supportedModes = m_advancedSettings->SupportedFocusModes();
        autoFocusTypes = m_advancedSettings->SupportedAutoFocusTypes();
        supportedRanges = m_advancedSettings->SupportedFocusRanges();

        if (supportedModes == 0 || autoFocusTypes == 0 || supportedRanges == 0)
            return modes;

        // EFocusModeAuto is the only supported on Symbian
        if (supportedModes & CCamera::CCameraAdvancedSettings::EFocusModeAuto) {
            // Check supported types (Single-shot Auto vs. Continuous)
            if (autoFocusTypes & CCamera::CCameraAdvancedSettings::EAutoFocusTypeSingle)
                modes |= QCameraFocus::AutoFocus;
            if (autoFocusTypes & CCamera::CCameraAdvancedSettings::EAutoFocusTypeContinuous)
                modes |= QCameraFocus::ContinuousFocus;

            // Check supported ranges (Note! Some are actually fixed focuses
            // even though the mode is Auto on Symbian)
            if (supportedRanges & CCamera::CCameraAdvancedSettings::EFocusRangeMacro)
                modes |= QCameraFocus::MacroFocus;
            if (supportedRanges & CCamera::CCameraAdvancedSettings::EFocusRangeHyperfocal)
                modes |= QCameraFocus::HyperfocalFocus;
            if (supportedRanges & CCamera::CCameraAdvancedSettings::EFocusRangeInfinite)
                modes |= QCameraFocus::InfinityFocus;
        }
    } else {
        emit error(QCamera::CameraError, tr("Unexpected camera error."));
    }
#endif // POST_31_PLATFORM

    return modes;
}

qreal S60CameraSettings::opticalZoomFactorL() const
{
    // Not supported on Symbian
    return 1.0;
}

void S60CameraSettings::setOpticalZoomFactorL(const qreal zoomFactor)
{
    // Not supported on Symbian
    Q_UNUSED(zoomFactor);
}

QList<qreal> S60CameraSettings::supportedDigitalZoomFactors() const
{
    QList<qreal> zoomFactors;
    foreach (int factor, m_supportedSymbianDigitalZoomFactors)
        zoomFactors << qreal(factor) / KSymbianFineResolutionFactor;

    return zoomFactors;
}

qreal S60CameraSettings::digitalZoomFactorL() const
{
    qreal factor = 1.0;

#ifdef POST_31_PLATFORM
    int symbianFactor = 0;
    if (m_advancedSettings)
        symbianFactor = m_advancedSettings->DigitalZoom();
    else
        User::Leave(KErrNotSupported);

    if (symbianFactor != 0)
        factor = qreal(symbianFactor) / KSymbianFineResolutionFactor;
#endif // POST_31_PLATFORM

    return factor;
}

void S60CameraSettings::setDigitalZoomFactorL(const qreal zoomFactor)
{
#ifdef POST_31_PLATFORM
    int symbianFactor = zoomFactor * KSymbianFineResolutionFactor;

    // Find closest supported Symbian ZoomFactor if needed
    if (!m_supportedSymbianDigitalZoomFactors.contains(symbianFactor)) {
        int closestIndex = -1;
        int closestDiff = 1000000; // Sensible maximum
        for (int i = 0; i < m_supportedSymbianDigitalZoomFactors.count(); ++i) {
            int diff = abs(m_supportedSymbianDigitalZoomFactors.at(i) - symbianFactor);
            if (diff < closestDiff) {
                closestDiff = diff;
                closestIndex = i;
            }
        }
        if (closestIndex != -1)
            symbianFactor = m_supportedSymbianDigitalZoomFactors.at(closestIndex);
        else
            User::Leave(KErrGeneral);
    }
    if (m_advancedSettings)
        m_advancedSettings->SetDigitalZoom(symbianFactor);
    else
        User::Leave(KErrNotSupported);
#else // S60 3.1 Platform
    Q_UNUSED(zoomFactor);
    emit error(QCamera::NotSupportedFeatureError, tr("Settings digital zoom factor is not supported."));
#endif // POST_31_PLATFORM
}

// MCameraObserver2
void S60CameraSettings::HandleAdvancedEvent(const TECAMEvent& aEvent)
{
#ifdef POST_31_PLATFORM

    if (aEvent.iErrorCode != KErrNone) {
        switch (aEvent.iErrorCode) {
            case KErrECamCameraDisabled:
                emit error(QCamera::CameraError, tr("Unexpected camera error."));
                return;
            case KErrECamSettingDisabled:
                emit error(QCamera::CameraError, tr("Unexpected camera error."));
                return;
            case KErrECamParameterNotInRange:
                emit error(QCamera::NotSupportedFeatureError, tr("Requested value is not in supported range."));
                return;
            case KErrECamSettingNotSupported:
                emit error(QCamera::NotSupportedFeatureError, tr("Requested setting is not supported."));
                return;
            case KErrECamNotOptimalFocus:
                if (m_continuousFocusing)
                    emit focusStatusChanged(QCamera::Searching, QCamera::LockTemporaryLost);
                else
                    emit focusStatusChanged(QCamera::Unlocked, QCamera::LockFailed);
                return;
        }

        if (aEvent.iEventType == KUidECamEventCameraSettingFocusRange ||
            aEvent.iEventType == KUidECamEventCameraSettingAutoFocusType2) {
            emit focusStatusChanged(QCamera::Unlocked, QCamera::LockFailed);
            return;
        } else if (aEvent.iEventType == KUidECamEventCameraSettingIsoRate) {
            if (aEvent.iErrorCode == KErrNotSupported)
                emit error(QCamera::NotSupportedFeatureError, tr("Requested ISO value is not supported."));
            else
                emit error(QCamera::CameraError, tr("Setting ISO value failed."));
            return;
        } else if (aEvent.iEventType == KUidECamEventCameraSettingAperture) {
            if (aEvent.iErrorCode == KErrNotSupported)
                emit error(QCamera::NotSupportedFeatureError, tr("Requested aperture value is not supported."));
            else
                emit error(QCamera::CameraError, tr("Setting aperture value failed."));
            return;
        } else if (aEvent.iEventType == KUidECamEventCameraSettingExposureCompensation) {
            if (aEvent.iErrorCode == KErrNotSupported)
                emit error(QCamera::NotSupportedFeatureError, tr("Requested exposure compensation is not supported."));
            else
                emit error(QCamera::CameraError, tr("Setting exposure compensation failed."));
            return;
        } else if (aEvent.iEventType == KUidECamEventCameraSettingOpticalZoom ||
                   aEvent.iEventType == KUidECamEventCameraSettingDigitalZoom) {
            if (aEvent.iErrorCode == KErrNotSupported)
                return; // Discard
            else {
                emit error(QCamera::CameraError, tr("Setting zoom factor failed."));
                return;
            }
        } else if (aEvent.iEventType == KUidECamEventCameraSettingFocusMode) {
            if (aEvent.iErrorCode == KErrNotSupported)
                if (m_cameraEngine && m_cameraEngine->CurrentCameraIndex() != 0)
                    emit error(QCamera::NotSupportedFeatureError, tr("Focusing is not supported with this camera."));
                else
                    emit error(QCamera::NotSupportedFeatureError, tr("Requested focus mode is not supported."));
            else
                emit error(QCamera::CameraError, tr("Setting focus mode failed."));
            return;
        } else {
            emit error(QCamera::CameraError, tr("Unexpected camera error."));
            return;
        }
    }

    if (aEvent.iEventType == KUidECamEventCameraSettingExposureLock) {
        if (m_advancedSettings) {
            if (m_advancedSettings->ExposureLockOn())
                emit exposureStatusChanged(QCamera::Locked, QCamera::LockAcquired);
            else
                emit exposureStatusChanged(QCamera::Unlocked, QCamera::LockLost);
        }
        else
            emit exposureStatusChanged(QCamera::Unlocked, QCamera::LockLost);
    }
    else if (aEvent.iEventType == KUidECamEventCameraSettingAperture)
        emit apertureChanged();

    else if (aEvent.iEventType == KUidECamEventCameraSettingApertureRange)
        emit apertureRangeChanged();

    else if (aEvent.iEventType == KUidECamEventCameraSettingIsoRateType)
        emit isoSensitivityChanged();

    else if (aEvent.iEventType == KUidECamEventCameraSettingShutterSpeed)
        emit shutterSpeedChanged();

    else if (aEvent.iEventType == KUidECamEventCameraSettingExposureCompensationStep)
        emit evChanged();

    else if (aEvent.iEventType == KUidECamEventFlashReady)
        emit flashReady(true);

    else if (aEvent.iEventType == KUidECamEventFlashNotReady)
        emit flashReady(false);

    else if (aEvent.iEventType.iUid == KUidECamEventCameraSettingsOptimalFocusUidValue)
        emit focusStatusChanged(QCamera::Locked, QCamera::LockAcquired);

#else // S60 3.1 Platform
    Q_UNUSED(aEvent);
#endif // POST_31_PLATFORM
}

bool S60CameraSettings::isFlashReady()
{
    TBool isReady = false;
#ifdef POST_31_PLATFORM
    if (m_advancedSettings) {
        int flashErr = m_advancedSettings->IsFlashReady(isReady);
        if(flashErr != KErrNone) {
            if (flashErr != KErrNotSupported)
                emit error(QCamera::CameraError, tr("Unexpected error with flash."));
            return false;
        }
    }
    else
        emit error(QCamera::CameraError, tr("Unexpected camera error."));
#endif
    return isReady;
}

QCameraExposure::MeteringMode S60CameraSettings::meteringMode()
{
#ifdef POST_31_PLATFORM
    if (m_advancedSettings) {
        CCamera::CCameraAdvancedSettings::TMeteringMode mode = m_advancedSettings->MeteringMode();
        switch (mode) {
            case CCamera::CCameraAdvancedSettings::EMeteringModeCenterWeighted:
                return QCameraExposure::MeteringAverage;
            case CCamera::CCameraAdvancedSettings::EMeteringModeEvaluative:
                return QCameraExposure::MeteringMatrix;
            case CCamera::CCameraAdvancedSettings::EMeteringModeSpot:
                return QCameraExposure::MeteringSpot;

            default:
                return QCameraExposure::MeteringAverage;
        }
    }else {
        emit error(QCamera::CameraError, tr("Unexpected camera error."));
        return QCameraExposure::MeteringAverage;
    }
#else // S60 3.1 Platform
    return QCameraExposure::MeteringAverage;
#endif // POST_31_PLATFORM
}

void S60CameraSettings::setMeteringMode(QCameraExposure::MeteringMode mode)
{
#ifdef POST_31_PLATFORM
    if (m_advancedSettings) {
        switch(mode) {
            case QCameraExposure::MeteringAverage:
                m_advancedSettings->SetMeteringMode(CCamera::CCameraAdvancedSettings::EMeteringModeCenterWeighted);
                break;
            case QCameraExposure::MeteringMatrix:
                m_advancedSettings->SetMeteringMode(CCamera::CCameraAdvancedSettings::EMeteringModeEvaluative);
                break;
            case QCameraExposure::MeteringSpot:
                m_advancedSettings->SetMeteringMode(CCamera::CCameraAdvancedSettings::EMeteringModeSpot);
                break;
            default:
                break;
        }
    }
    else
        emit error(QCamera::CameraError, tr("Unexpected camera error."));
#else // S60 3.1
    Q_UNUSED(mode);
    emit error(QCamera::NotSupportedFeatureError, tr("Setting metering mode is not supported."));
#endif // POST_31_PLATFORM
}

bool S60CameraSettings::isMeteringModeSupported(QCameraExposure::MeteringMode mode)
{
#ifdef POST_31_PLATFORM
    TInt supportedModes = 0;

    if (m_advancedSettings) {
        supportedModes = m_advancedSettings->SupportedMeteringModes();
        if (supportedModes == 0)
            return false;

        switch (mode) {
            case QCameraExposure::MeteringMatrix:
                if (supportedModes & CCamera::CCameraAdvancedSettings::EMeteringModeEvaluative)
                    return true;
                else
                    return false;
            case QCameraExposure::MeteringAverage:
                if (supportedModes & CCamera::CCameraAdvancedSettings::EMeteringModeCenterWeighted)
                    return true;
                else
                    return false;
            case QCameraExposure::MeteringSpot:
                if (supportedModes & CCamera::CCameraAdvancedSettings::EMeteringModeSpot)
                    return true;
                else
                    return false;

            default:
                return false;
        }
    }
    else
        emit error(QCamera::CameraError, tr("Unexpected camera error."));
#else // S60 3.1
    Q_UNUSED(mode);
#endif // POST_31_PLATFORM

    return false;
}

int S60CameraSettings::isoSensitivity()
{
#ifdef POST_31_PLATFORM
    if (m_advancedSettings) {
        CCamera::CCameraAdvancedSettings::TISORateType isoRateType;
        TInt param = 0;
        TInt isoRate = 0;
        TRAPD(err, m_advancedSettings->GetISORateL(isoRateType, param, isoRate));
        if (err)
            return 0;
        if (isoRate != KErrNotFound)
            return isoRate;
    } else {
        emit error(QCamera::CameraError, tr("Unexpected camera error."));
    }
#endif // POST_31_PLATFORM
    return 0;
}

QList<int> S60CameraSettings::supportedIsoSensitivities()
{
    QList<int> isoSentitivities;
#ifdef POST_31_PLATFORM
    if (m_advancedSettings) {
        RArray<TInt> supportedIsoRates;
        CleanupClosePushL(supportedIsoRates);

        TRAPD(err, m_advancedSettings->GetSupportedIsoRatesL(supportedIsoRates));
        if (err != KErrNone) {
            if (err != KErrNotSupported) // Don's emit error if ISO is not supported
                emit error(QCamera::CameraError, tr("Failure while querying supported iso sensitivities."));
        } else {
            for (int i = 0; i < supportedIsoRates.Count(); ++i)
                isoSentitivities << supportedIsoRates[i];
        }
        CleanupStack::PopAndDestroy(); // RArray<TInt> supportedIsoRates
    } else {
        emit error(QCamera::CameraError, tr("Unexpected camera error."));
    }

    return isoSentitivities;
#else // S60 3.1 Platform
    return isoSentitivities;
#endif // POST_31_PLATFORM
}

void S60CameraSettings::setManualIsoSensitivity(int iso)
{
#ifdef POST_31_PLATFORM
    if (m_advancedSettings) {
        TRAPD(err, m_advancedSettings->SetISORateL(CCamera::CCameraAdvancedSettings::EISOManual, iso));
        if (err)
            emit error(QCamera::CameraError, tr("Setting manual iso sensitivity failed."));
        return;
    } else {
        emit error(QCamera::CameraError, tr("Unexpected camera error."));
    }
#else // S60 3.1 Platform
    Q_UNUSED(iso);
    emit error(QCamera::NotSupportedFeatureError, tr("Setting manual iso sensitivity is not supported."));
#endif // POST_31_PLATFORM
}

void S60CameraSettings::setAutoIsoSensitivity()
{
#ifdef POST_31_PLATFORM
    if (m_advancedSettings) {
        TRAPD(err, m_advancedSettings->SetISORateL(CCamera::CCameraAdvancedSettings::EISOAutoUnPrioritised, 0));
        if (err)
            emit error(QCamera::CameraError, tr("Setting auto iso sensitivity failed."));
        return;
    }
    else
        emit error(QCamera::CameraError, tr("Unexpected camera error."));
#else // S60 3.1 Platform
    emit error(QCamera::NotSupportedFeatureError, tr("Setting auto iso sensitivity is not supported."));
#endif // POST_31_PLATFORM
}

qreal S60CameraSettings::aperture()
{
#ifdef POST_31_PLATFORM
    if (m_advancedSettings)
        return qreal(m_advancedSettings->Aperture()) / KSymbianFineResolutionFactor;
    else
        emit error(QCamera::CameraError, tr("Unexpected camera error."));
    return 0;
#else // S60 3.1 Platform
    return 0;
#endif // POST_31_PLATFORM
}

QList<qreal> S60CameraSettings::supportedApertures()
{
    QList<qreal> apertures;

#ifdef POST_31_PLATFORM
    if (m_advancedSettings) {
        RArray<TInt> supportedApertures;
        TValueInfo info = ENotActive;

        TRAPD(err, m_advancedSettings->GetAperturesL(supportedApertures, info));
        if (err != KErrNone)
            if (err != KErrNotSupported)
                emit error(QCamera::CameraError, tr("Failure while querying supported apertures."));
        else {
            for (int i = 0; i < supportedApertures.Count(); i++) {
                qreal q = qreal(supportedApertures[i]) / KSymbianFineResolutionFactor;
                apertures.append(q);
            }
        }
        supportedApertures.Close();
    }
    else
        emit error(QCamera::CameraError, tr("Unexpected camera error."));
    return apertures;
#else // S60 3.1 Platform
    return apertures;
#endif // POST_31_PLATFORM
}

void S60CameraSettings::setManualAperture(qreal aperture)
{
#ifdef POST_31_PLATFORM
    if (m_advancedSettings) {
        int symbianAperture = (aperture * KSymbianFineResolutionFactor); // KSymbianFineResolutionFactor = 100
        m_advancedSettings->SetAperture(symbianAperture);
    }
    else
        emit error(QCamera::CameraError, tr("Unexpected camera error."));
#else // S60 3.1
    Q_UNUSED(aperture);
    emit error(QCamera::NotSupportedFeatureError, tr("Setting manual aperture is not supported."));
#endif // POST_31_PLATFORM
}

void S60CameraSettings::lockExposure(bool lock)
{
#ifdef POST_31_PLATFORM
    if (m_advancedSettings) {
        m_advancedSettings->SetExposureLockOn(lock);
        return;
    }
    else
        emit error(QCamera::CameraError, tr("Unexpected camera error."));
#else // S60 3.1
    Q_UNUSED(lock);
    emit error(QCamera::NotSupportedFeatureError, tr("Locking exposure is not supported."));
#endif // POST_31_PLATFORM
}

bool S60CameraSettings::isExposureLocked()
{
#ifdef POST_31_PLATFORM
    if (m_advancedSettings)
        return m_advancedSettings->ExposureLockOn();
    else
        emit error(QCamera::CameraError, tr("Unexpected camera error."));
#endif // POST_31_PLATFORM
    return false;
}

qreal S60CameraSettings::shutterSpeed()
{
#ifdef POST_31_PLATFORM
    if (m_advancedSettings) {
        qreal shutterSpeed = qreal(m_advancedSettings->ShutterSpeed()) / 1000000.0;
        return shutterSpeed; // In seconds
    } else {
        emit error(QCamera::CameraError, tr("Unexpected camera error."));
    }
    return 0;
#else // S60 3.1 Platform
    return 0;
#endif // POST_31_PLATFORM
}

QList<qreal> S60CameraSettings::supportedShutterSpeeds()
{
    QList<qreal> speeds;

#ifdef POST_31_PLATFORM
    if (m_advancedSettings) {
        RArray<TInt> supportedSpeeds;
        TValueInfo info = ENotActive;

        TRAPD(err, m_advancedSettings->GetShutterSpeedsL(supportedSpeeds, info));
        if (err != KErrNone)
            if (err != KErrNotSupported)
                emit error(QCamera::CameraError, tr("Failure while querying supported shutter speeds."));
        else {
            for (int i = 0; i < supportedSpeeds.Count(); i++) {
                qreal q = qreal(supportedSpeeds[i]) / 1000000.0;
                speeds.append(q); // In seconds
            }
        }
        supportedSpeeds.Close();
    }
    else
        emit error(QCamera::CameraError, tr("Unexpected camera error."));
    return speeds;
#else // S60 3.1 Platform
    return speeds;
#endif // POST_31_PLATFORM
}

void S60CameraSettings::setManualShutterSpeed(qreal speed)
{
#ifdef POST_31_PLATFORM
    if (m_advancedSettings) {
        TInt shutterSpeed = speed * 1000000; // From seconds to microseconds
        m_advancedSettings->SetShutterSpeed(shutterSpeed);
    } else {
        emit error(QCamera::CameraError, tr("Unexpected camera error."));
    }
#else // S60 3.1
    emit error(QCamera::NotSupportedFeatureError, tr("Setting manual shutter speed is not supported."));
    Q_UNUSED(speed);
#endif // POST_31_PLATFORM
}

void S60CameraSettings::setExposureCompensation(qreal ev)
{
#ifdef POST_31_PLATFORM
    if (m_advancedSettings) {
        TInt evStep = ev * KSymbianFineResolutionFactor;
        m_advancedSettings->SetExposureCompensationStep(evStep);
    } else {
        emit error(QCamera::CameraError, tr("Unexpected camera error."));
    }
#else // S60 3.1 Platform
    Q_UNUSED(ev);
    emit error(QCamera::NotSupportedFeatureError, tr("Setting exposure compensation is not supported."));
#endif // POST_31_PLATFORM
}

qreal S60CameraSettings::exposureCompensation()
{
#ifdef POST_31_PLATFORM
    if (m_advancedSettings) {
        TInt evStepSymbian = 0;
        m_advancedSettings->GetExposureCompensationStep(evStepSymbian);
        qreal evStep = evStepSymbian;
        evStep /= KSymbianFineResolutionFactor;
        return evStep;
    } else {
        emit error(QCamera::CameraError, tr("Unexpected camera error."));
    }
    return 0;
#else // S60 3.1 Platform
    return 0;
#endif // POST_31_PLATFORM
}

QList<qreal> S60CameraSettings::supportedExposureCompensationValues()
{
    QList<qreal> valueList;

#ifdef POST_31_PLATFORM
    if (m_advancedSettings) {
        RArray<TInt> evSteps;
        TValueInfo info;
        TRAPD(err, m_advancedSettings->GetExposureCompensationStepsL(evSteps, info));
        if (err) {
            if (err != KErrNotSupported)
                emit error(QCamera::CameraError, tr("Failure while querying supported exposure compensation values."));
            return valueList;
        }

        if (info == ENotActive || evSteps.Count() == 0) {
            // EV not supported, return empty list
            return valueList;
        }

        for (int i = 0; i < evSteps.Count(); ++i) {
            qreal appendValue = evSteps[i];
            appendValue /= KSymbianFineResolutionFactor;
            valueList.append(appendValue);
        }
    }
    else
        emit error(QCamera::CameraError, tr("Unexpected camera error."));
    return valueList;
#else // S60 3.1 Platform
    return valueList;
#endif // POST_31_PLATFORM
}

void S60CameraSettings::setSharpeningLevel(int value)
{
#ifdef POST_31_PLATFORM
    if (m_imageProcessingSettings && isSharpeningSupported())
        m_imageProcessingSettings->SetTransformationValue(KUidECamEventImageProcessingAdjustSharpness, value);
    else
        emit error(QCamera::NotSupportedFeatureError, tr("Setting sharpening level is not supported."));
#else // S60 3.1
    Q_UNUSED(value);
    emit error(QCamera::NotSupportedFeatureError, tr("Setting sharpening level is not supported."));
#endif // POST_31_PLATFORM
}

bool S60CameraSettings::isSharpeningSupported() const
{
#ifdef POST_31_PLATFORM
    if (m_imageProcessingSettings) {
        RArray<TUid> suppTransforms;
        TRAPD(err, m_imageProcessingSettings->GetSupportedTransformationsL(suppTransforms));
        if (err)
            return false;

        if (suppTransforms.Find(KUidECamEventImageProcessingAdjustSharpness))
            return true;
    }
    return false;
#else // S60 3.1 Platform
    return false;
#endif // POST_31_PLATFORM
}

int S60CameraSettings::sharpeningLevel() const
{
#ifdef POST_31_PLATFORM
    if (m_imageProcessingSettings && isSharpeningSupported())
        return m_imageProcessingSettings->TransformationValue(KUidECamEventImageProcessingAdjustSharpness);
    else
        return 0;
#else // S60 3.1 Platform
    return 0;
#endif // POST_31_PLATFORM
}

void S60CameraSettings::setSaturation(int value)
{
#ifdef POST_31_PLATFORM
    if (m_imageProcessingSettings) {
        RArray<TUid> suppTransforms;
        TRAPD(err, m_imageProcessingSettings->GetSupportedTransformationsL(suppTransforms));
        if (err)
            if (err != KErrNotSupported)
                emit error(QCamera::CameraError, tr("Failure while querying supported transformations."));

        if (suppTransforms.Find(KUidECamEventtImageProcessingAdjustSaturation))
            m_imageProcessingSettings->SetTransformationValue(KUidECamEventtImageProcessingAdjustSaturation, value == -1 ? 0 : value*2-100);
        else
            emit error(QCamera::NotSupportedFeatureError, tr("Setting saturation is not supported."));
    }
    else
        emit error(QCamera::NotSupportedFeatureError, tr("Setting saturation is not supported."));
#else // S60 3.1
    Q_UNUSED(value);
    emit error(QCamera::NotSupportedFeatureError, tr("Setting saturation is not supported."));
#endif // POST_31_PLATFORM
}

int S60CameraSettings::saturation()
{
#ifdef POST_31_PLATFORM
    if (m_imageProcessingSettings) {
        RArray<TUid> suppTransforms;
        TRAPD(err, m_imageProcessingSettings->GetSupportedTransformationsL(suppTransforms));
        if (err)
            if (err != KErrNotSupported)
                emit error(QCamera::CameraError, tr("Failure while querying supported transformations."));

        if (suppTransforms.Find(KUidECamEventtImageProcessingAdjustSaturation))
            return m_imageProcessingSettings->TransformationValue(KUidECamEventtImageProcessingAdjustSaturation);
    }
    return 0;
#else // S60 3.1 Platform
    return 0;
#endif // POST_31_PLATFORM
}

// End of file