Don't reuse file names
[harmattan/cameraplus] / lib / qtcamimagesettings.cpp
1 /*!
2  * This file is part of CameraPlus.
3  *
4  * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19  */
20
21 #include "qtcamimagesettings.h"
22 #include <QSharedData>
23 #include <QDebug>
24
25 class QtCamImageResolutionPrivate : public QSharedData {
26 public:
27   QString id;
28   QString name;
29   QSize capture;
30   QSize preview;
31   QSize viewfinder;
32   int fps;
33   int nightFps;
34   int megaPixels;
35   QString aspectRatio;
36 };
37
38 class QtCamImageSettingsPrivate : public QSharedData {
39 public:
40   QString id;
41   QString suffix;
42   QString profileName;
43   QString profilePath;
44   QList<QtCamImageResolution> resolutions;
45 };
46
47
48 QtCamImageResolution::QtCamImageResolution(const QString& id, const QString& name,
49                                            const QSize& capture, const QSize& preview,
50                                            const QSize& viewfinder, int fps, int nightFps,
51                                            int megaPixels, QString aspectRatio) :
52   d_ptr(new QtCamImageResolutionPrivate) {
53   d_ptr->id = id;
54   d_ptr->name = name;
55   d_ptr->capture = capture;
56   d_ptr->preview = preview;
57   d_ptr->viewfinder = viewfinder;
58   d_ptr->fps = fps;
59   d_ptr->nightFps = nightFps;
60   d_ptr->megaPixels = megaPixels;
61   d_ptr->aspectRatio = aspectRatio;
62 }
63
64 QtCamImageResolution::QtCamImageResolution(const QtCamImageResolution& other) :
65   d_ptr(other.d_ptr) {
66
67 }
68
69 QtCamImageResolution& QtCamImageResolution::operator=(const QtCamImageResolution& other) {
70   d_ptr = other.d_ptr;
71
72   return *this;
73 }
74
75 QtCamImageResolution::~QtCamImageResolution() {
76   // QSharedData will take care of reference counting.
77 }
78
79 QString QtCamImageResolution::id() const {
80   return d_ptr->id;
81 }
82
83 QString QtCamImageResolution::name() const {
84   return d_ptr->name;
85 }
86
87 QSize QtCamImageResolution::captureResolution() const {
88   return d_ptr->capture;
89 }
90
91 QSize QtCamImageResolution::viewfinderResolution() const {
92   return d_ptr->viewfinder;
93 }
94
95 QSize QtCamImageResolution::previewResolution() const {
96   return d_ptr->preview;
97 }
98
99 int QtCamImageResolution::frameRate() const {
100   return d_ptr->fps;
101 }
102
103 int QtCamImageResolution::nightFrameRate() const {
104   return d_ptr->nightFps;
105 }
106
107 int QtCamImageResolution::megaPixels() const {
108   return d_ptr->megaPixels;
109 }
110
111 QString QtCamImageResolution::aspectRatio() const {
112   return d_ptr->aspectRatio;
113 }
114
115 QtCamImageSettings::QtCamImageSettings(const QString& id, const QString& suffix,
116                                        const QString& profileName, const QString& profilePath,
117                                        const QList<QtCamImageResolution>& resolutions) :
118   d_ptr(new QtCamImageSettingsPrivate) {
119
120   d_ptr->id = id;
121   d_ptr->suffix = suffix;
122   d_ptr->profileName = profileName;
123   d_ptr->profilePath = profilePath;
124   d_ptr->resolutions = resolutions;
125 }
126
127 QtCamImageSettings::QtCamImageSettings(const QtCamImageSettings& other) :
128   d_ptr(other.d_ptr) {
129
130 }
131
132 QtCamImageSettings& QtCamImageSettings::operator=(const QtCamImageSettings& other) {
133   d_ptr = other.d_ptr;
134
135   return *this;
136 }
137
138 QtCamImageSettings::~QtCamImageSettings() {
139   // QSharedData will take care of reference counting.
140 }
141
142 QString QtCamImageSettings::id() const {
143   return d_ptr->id;
144 }
145
146 QString QtCamImageSettings::suffix() const {
147   return d_ptr->suffix;
148 }
149
150 QString QtCamImageSettings::profileName() const {
151   return d_ptr->profileName;
152 }
153
154 QString QtCamImageSettings::profilePath() const {
155   return d_ptr->profilePath;
156 }
157
158 QtCamImageResolution QtCamImageSettings::defaultResolution(const QString& aspectRatio) const {
159   if (d_ptr->resolutions.isEmpty()) {
160     return QtCamImageResolution(QString(), QString(),
161                                 QSize(), QSize(), QSize(),
162                                 -1, -1, -1, QString());
163   }
164
165   if (aspectRatio.isEmpty()) {
166     return d_ptr->resolutions[0];
167   }
168
169   foreach (const QtCamImageResolution& r, d_ptr->resolutions) {
170     if (r.aspectRatio() == aspectRatio) {
171       return r;
172     }
173   }
174
175   return d_ptr->resolutions[0];
176 }
177
178 QList<QtCamImageResolution> QtCamImageSettings::resolutions(const QString& aspectRatio) const {
179   if (aspectRatio.isEmpty()) {
180     return d_ptr->resolutions;
181   }
182
183   QList<QtCamImageResolution> res;
184
185   foreach (const QtCamImageResolution& r, d_ptr->resolutions) {
186     if (r.aspectRatio() == aspectRatio) {
187       res << r;
188     }
189   }
190
191   return res;
192 }
193
194 QStringList QtCamImageSettings::aspectRatios() const {
195   QStringList aspects;
196
197   foreach (const QtCamImageResolution& r, d_ptr->resolutions) {
198     if (aspects.indexOf(r.aspectRatio()) == -1) {
199       aspects << r.aspectRatio();
200     }
201   }
202
203   return aspects;
204 }