Merge lp:~schwann/gallery-app/gallery-photo-dependency-reduce into lp:gallery-app

Proposed by Günter Schwann
Status: Merged
Approved by: Günter Schwann
Approved revision: 694
Merged at revision: 693
Proposed branch: lp:~schwann/gallery-app/gallery-photo-dependency-reduce
Merge into: lp:gallery-app
Prerequisite: lp:~schwann/gallery-app/gallery-medialoader
Diff against target: 1056 lines (+316/-258)
28 files modified
src/album/CMakeLists.txt (+0/-2)
src/core/data-collection.h (+1/-1)
src/database/media-table.h (+2/-1)
src/event/CMakeLists.txt (+0/-2)
src/gallery-application.cpp (+3/-3)
src/gallery-manager.cpp (+31/-2)
src/gallery-manager.h (+1/-0)
src/media/CMakeLists.txt (+0/-2)
src/media/media-collection.cpp (+24/-42)
src/media/media-collection.h (+5/-8)
src/media/media-source.cpp (+3/-1)
src/media/media-source.h (+3/-3)
src/medialoader/CMakeLists.txt (+2/-6)
src/medialoader/gallery-standard-image-provider.cpp (+1/-2)
src/medialoader/gallery-standard-image-provider.h (+2/-1)
src/medialoader/photo-metadata.cpp (+0/-130)
src/medialoader/photo-metadata.h (+3/-38)
src/medialoader/preview-manager.cpp (+2/-4)
src/photo/CMakeLists.txt (+0/-2)
src/photo/photo-edit-state.h (+2/-1)
src/photo/photo.cpp (+8/-4)
src/photo/photo.h (+3/-1)
src/util/CMakeLists.txt (+2/-0)
src/util/orientation.cpp (+152/-0)
src/util/orientation.h (+63/-0)
tests/unittests/gallerystandardimageprovider/CMakeLists.txt (+1/-0)
tests/unittests/gallerystandardimageprovider/media-collection.h (+1/-1)
tests/unittests/gallerystandardimageprovider/tst_gallerystandardimageprovidertest.cpp (+1/-1)
To merge this branch: bzr merge lp:~schwann/gallery-app/gallery-photo-dependency-reduce
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Thomas Moenicke (community) Approve
Review via email: mp+167741@code.launchpad.net

Commit message

Remove many dependencies on photo

Description of the change

Remove many dependencies on photo.
When others depend on the base class MediaSource instead of Photo directly, it's easier to add the Video class.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
691. By Günter Schwann

Trunk merged

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
692. By Günter Schwann

Trunk merged

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
693. By Günter Schwann

trunk merged

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Thomas Moenicke (thomas-moenicke) wrote :

QStringList filenames = mediaDir.entryList(); should be const
Maybe while you are at touching the code, changing NULL to 0 would good

review: Approve
694. By Günter Schwann

Minor improvements of old (now moved) code

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/album/CMakeLists.txt'
--- src/album/CMakeLists.txt 2013-06-06 15:33:12 +0000
+++ src/album/CMakeLists.txt 2013-06-07 11:10:22 +0000
@@ -9,7 +9,6 @@
9 # FIXME resolve the circulate dependencies9 # FIXME resolve the circulate dependencies
10 ${gallery_src_SOURCE_DIR}/database10 ${gallery_src_SOURCE_DIR}/database
11 ${gallery_src_SOURCE_DIR}/media11 ${gallery_src_SOURCE_DIR}/media
12 ${gallery_src_SOURCE_DIR}/photo
13 ${gallery_src_SOURCE_DIR}/qml12 ${gallery_src_SOURCE_DIR}/qml
14 ${gallery_util_src_SOURCE_DIR}13 ${gallery_util_src_SOURCE_DIR}
15 ${CMAKE_BINARY_DIR}14 ${CMAKE_BINARY_DIR}
@@ -44,7 +43,6 @@
44 gallery-core43 gallery-core
45 gallery-database44 gallery-database
46 gallery-media45 gallery-media
47 gallery-photo
48 gallery-qml46 gallery-qml
49 gallery-util47 gallery-util
50 ${GSTLIB_LDFLAGS}48 ${GSTLIB_LDFLAGS}
5149
=== modified file 'src/core/data-collection.h'
--- src/core/data-collection.h 2013-06-06 16:02:25 +0000
+++ src/core/data-collection.h 2013-06-07 11:10:22 +0000
@@ -67,7 +67,7 @@
67 int Count() const;67 int Count() const;
6868
69 void Add(DataObject* object);69 void Add(DataObject* object);
70 void AddMany(const QSet<DataObject*>& objects);70 virtual void AddMany(const QSet<DataObject*>& objects);
7171
72 void Remove(DataObject* object);72 void Remove(DataObject* object);
73 void RemoveAt(int index);73 void RemoveAt(int index);
7474
=== modified file 'src/database/media-table.h'
--- src/database/media-table.h 2013-06-06 16:02:25 +0000
+++ src/database/media-table.h 2013-06-07 11:10:22 +0000
@@ -20,7 +20,8 @@
20#ifndef MEDIATABLE_H20#ifndef MEDIATABLE_H
21#define MEDIATABLE_H21#define MEDIATABLE_H
2222
23#include "photo-metadata.h"23// util
24#include "orientation.h"
2425
25#include <QObject>26#include <QObject>
2627
2728
=== modified file 'src/event/CMakeLists.txt'
--- src/event/CMakeLists.txt 2013-06-06 15:33:12 +0000
+++ src/event/CMakeLists.txt 2013-06-07 11:10:22 +0000
@@ -8,7 +8,6 @@
8 # because of circulate dependencies the sub project can't be used directly8 # because of circulate dependencies the sub project can't be used directly
9 # FIXME resolve the circulate dependencies9 # FIXME resolve the circulate dependencies
10 ${gallery_src_SOURCE_DIR}/media10 ${gallery_src_SOURCE_DIR}/media
11 ${gallery_src_SOURCE_DIR}/photo
12 ${gallery_util_src_SOURCE_DIR}11 ${gallery_util_src_SOURCE_DIR}
13 ${CMAKE_BINARY_DIR}12 ${CMAKE_BINARY_DIR}
14 ${GSTLIB_INCLUDE_DIRS}13 ${GSTLIB_INCLUDE_DIRS}
@@ -33,7 +32,6 @@
33target_link_libraries( ${GALLERY_EVENT_LIB}32target_link_libraries( ${GALLERY_EVENT_LIB}
34 gallery-core33 gallery-core
35 gallery-media34 gallery-media
36 gallery-photo
37 gallery-util35 gallery-util
38 ${GSTLIB_LDFLAGS}36 ${GSTLIB_LDFLAGS}
39 )37 )
4038
=== modified file 'src/gallery-application.cpp'
--- src/gallery-application.cpp 2013-06-06 16:02:25 +0000
+++ src/gallery-application.cpp 2013-06-07 11:10:22 +0000
@@ -223,8 +223,8 @@
223 */223 */
224void GalleryApplication::on_media_item_added(QFileInfo item_info)224void GalleryApplication::on_media_item_added(QFileInfo item_info)
225{225{
226 Photo* new_photo = Photo::Fetch(item_info);226 MediaSource* newMedia = Photo::Fetch(item_info);
227227
228 if (new_photo)228 if (newMedia)
229 GalleryManager::instance()->media_collection()->Add(new_photo);229 GalleryManager::instance()->media_collection()->Add(newMedia);
230}230}
231231
=== modified file 'src/gallery-manager.cpp'
--- src/gallery-manager.cpp 2013-06-06 16:02:25 +0000
+++ src/gallery-manager.cpp 2013-06-07 11:10:22 +0000
@@ -33,6 +33,7 @@
3333
34// media34// media
35#include "media-collection.h"35#include "media-collection.h"
36#include "photo.h"
36#include "preview-manager.h"37#include "preview-manager.h"
3738
38// qml39// qml
@@ -42,6 +43,8 @@
42// util43// util
43#include "resource.h"44#include "resource.h"
4445
46#include <exiv2/exiv2.hpp>
47
45GalleryManager* GalleryManager::gallery_mgr_ = NULL;48GalleryManager* GalleryManager::gallery_mgr_ = NULL;
4649
47/*!50/*!
@@ -94,8 +97,8 @@
94 resource_->get_rc_url("sql").path());97 resource_->get_rc_url("sql").path());
95 database_->get_media_table()->verify_files();98 database_->get_media_table()->verify_files();
96 default_template_ = new AlbumDefaultTemplate();99 default_template_ = new AlbumDefaultTemplate();
97 QDir mediaDir(resource_->picturesDirectory());100 media_collection_ = new MediaCollection();
98 media_collection_ = new MediaCollection(mediaDir);101 fillMediaCollection();
99 album_collection_ = new AlbumCollection();102 album_collection_ = new AlbumCollection();
100 event_collection_ = new EventCollection();103 event_collection_ = new EventCollection();
101104
@@ -171,3 +174,29 @@
171 // Verify previews for all existing added MediaSources174 // Verify previews for all existing added MediaSources
172 preview_manager_->onMediaAddedRemoved(&media_collection_->GetAsSet(), NULL);175 preview_manager_->onMediaAddedRemoved(&media_collection_->GetAsSet(), NULL);
173}176}
177
178/*!
179 * \brief GalleryManager::fillMediaCollection fills the MediaCollection with
180 * the content of the picture directory
181 */
182void GalleryManager::fillMediaCollection()
183{
184 Q_ASSERT(media_collection_);
185
186 QDir mediaDir(resource_->picturesDirectory());
187 mediaDir.setFilter(QDir::Files);
188 mediaDir.setSorting(QDir::Name);
189
190 QSet<DataObject*> photos;
191 const QStringList filenames = mediaDir.entryList();
192 foreach (const QString& filename, filenames) {
193 QFileInfo file(mediaDir, filename);
194 Photo *p = Photo::Load(file);
195 if (!p)
196 continue;
197
198 photos.insert(p);
199 }
200
201 media_collection_->AddMany(photos);
202}
174203
=== modified file 'src/gallery-manager.h'
--- src/gallery-manager.h 2013-06-06 16:02:25 +0000
+++ src/gallery-manager.h 2013-06-07 11:10:22 +0000
@@ -71,6 +71,7 @@
71 void operator=(const GalleryManager&);71 void operator=(const GalleryManager&);
7272
73 void initPreviewManager();73 void initPreviewManager();
74 void fillMediaCollection();
7475
75 static GalleryManager* gallery_mgr_;76 static GalleryManager* gallery_mgr_;
7677
7778
=== modified file 'src/media/CMakeLists.txt'
--- src/media/CMakeLists.txt 2013-06-07 11:10:22 +0000
+++ src/media/CMakeLists.txt 2013-06-07 11:10:22 +0000
@@ -10,7 +10,6 @@
10 ${gallery_src_SOURCE_DIR}/database10 ${gallery_src_SOURCE_DIR}/database
11 ${gallery_src_SOURCE_DIR}/event11 ${gallery_src_SOURCE_DIR}/event
12 ${gallery_src_SOURCE_DIR}/medialoader12 ${gallery_src_SOURCE_DIR}/medialoader
13 ${gallery_src_SOURCE_DIR}/photo
14 ${gallery_util_src_SOURCE_DIR}13 ${gallery_util_src_SOURCE_DIR}
15 ${CMAKE_BINARY_DIR}14 ${CMAKE_BINARY_DIR}
16 ${GSTLIB_INCLUDE_DIRS}15 ${GSTLIB_INCLUDE_DIRS}
@@ -39,7 +38,6 @@
39 gallery-database38 gallery-database
40 gallery-event39 gallery-event
41 gallery-medialoader40 gallery-medialoader
42 gallery-photo
43 gallery-util41 gallery-util
44 ${GSTLIB_LDFLAGS}42 ${GSTLIB_LDFLAGS}
45 )43 )
4644
=== modified file 'src/media/media-collection.cpp'
--- src/media/media-collection.cpp 2013-06-06 16:02:25 +0000
+++ src/media/media-collection.cpp 2013-06-07 11:10:22 +0000
@@ -18,14 +18,12 @@
18 */18 */
1919
20#include "media-collection.h"20#include "media-collection.h"
21#include "media-source.h"
2122
22// database23// database
23#include "database.h"24#include "database.h"
24#include "media-table.h"25#include "media-table.h"
2526
26// photo
27#include "photo.h"
28
29// src27// src
30#include "gallery-manager.h"28#include "gallery-manager.h"
3129
@@ -37,39 +35,11 @@
37 * \brief MediaCollection::MediaCollection35 * \brief MediaCollection::MediaCollection
38 * \param directory36 * \param directory
39 */37 */
40MediaCollection::MediaCollection(const QDir& directory)38MediaCollection::MediaCollection()
41 : SourceCollection("MediaCollection"), directory_(directory)39 : SourceCollection("MediaCollection")
42{40{
43 directory_.setFilter(QDir::Files);
44 directory_.setSorting(QDir::Name);
45
46 // By default, sort all media by its exposure date time, descending41 // By default, sort all media by its exposure date time, descending
47 SetComparator(ExposureDateTimeDescendingComparator);42 SetComparator(ExposureDateTimeDescendingComparator);
48
49 QSet<DataObject*> photos;
50 QStringList filenames = directory_.entryList();
51 QString filename;
52 foreach (filename, filenames) {
53 QFileInfo file(directory_, filename);
54
55 Photo *p = Photo::Load(file);
56 if (!p)
57 continue;
58
59 photos.insert(p);
60 id_map_.insert(p->get_id(), p);
61 }
62
63 AddMany(photos);
64}
65
66/*!
67 * \brief MediaCollection::directory
68 * \return
69 */
70const QDir& MediaCollection::directory() const
71{
72 return directory_;
73}43}
7444
75/*!45/*!
@@ -132,9 +102,9 @@
132 DataObject* o = i.next();102 DataObject* o = i.next();
133 id_map_.insert(qobject_cast<MediaSource*>(o)->get_id(), o);103 id_map_.insert(qobject_cast<MediaSource*>(o)->get_id(), o);
134104
135 Photo* p = qobject_cast<Photo*>(o);105 MediaSource* media = qobject_cast<MediaSource*>(o);
136 if (p != NULL) {106 if (media != 0) {
137 file_photo_map_.insert(p->file().absoluteFilePath(), p);107 m_filePhotoMap.insert(media->file().absoluteFilePath(), media);
138 }108 }
139 }109 }
140 }110 }
@@ -145,9 +115,8 @@
145 DataObject* o = i.next();115 DataObject* o = i.next();
146 MediaSource* media = qobject_cast<MediaSource*>(o);116 MediaSource* media = qobject_cast<MediaSource*>(o);
147117
148 Photo* p = qobject_cast<Photo*>(o);118 if (media != 0) {
149 if (p != NULL) {119 m_filePhotoMap.remove(media->file().absoluteFilePath());
150 file_photo_map_.remove(p->file().absoluteFilePath());
151 }120 }
152121
153 id_map_.remove(media->get_id());122 id_map_.remove(media->get_id());
@@ -168,7 +137,20 @@
168 * \param file_to_load137 * \param file_to_load
169 * \return138 * \return
170 */139 */
171Photo* MediaCollection::photoFromFileinfo(QFileInfo file_to_load)140MediaSource *MediaCollection::photoFromFileinfo(const QFileInfo& file_to_load)
172{141{
173 return file_photo_map_.value(file_to_load.absoluteFilePath(), NULL);142 return m_filePhotoMap.value(file_to_load.absoluteFilePath(), 0);
143}
144
145/*!
146 * \reimp
147 */
148void MediaCollection::AddMany(const QSet<DataObject *> &objects)
149{
150 foreach (DataObject* data, objects) {
151 MediaSource* media = qobject_cast<MediaSource*>(data);
152 id_map_.insert(media->get_id(), media);
153 }
154
155 DataCollection::AddMany(objects);
174}156}
175157
=== modified file 'src/media/media-collection.h'
--- src/media/media-collection.h 2013-06-06 16:02:25 +0000
+++ src/media/media-collection.h 2013-06-07 11:10:22 +0000
@@ -20,7 +20,7 @@
20#ifndef GALLERY_MEDIA_COLLECTION_H_20#ifndef GALLERY_MEDIA_COLLECTION_H_
21#define GALLERY_MEDIA_COLLECTION_H_21#define GALLERY_MEDIA_COLLECTION_H_
2222
23#include <QDir>23#include <QFileInfo>
24#include <QHash>24#include <QHash>
25#include <QSet>25#include <QSet>
2626
@@ -29,7 +29,6 @@
2929
30class DataObject;30class DataObject;
31class MediaSource;31class MediaSource;
32class Photo;
3332
34/*!33/*!
35 * \brief The MediaCollection class34 * \brief The MediaCollection class
@@ -39,16 +38,15 @@
39 Q_OBJECT38 Q_OBJECT
4039
41public:40public:
42 MediaCollection(const QDir& directory);41 MediaCollection();
4342
44 static bool ExposureDateTimeAscendingComparator(DataObject* a, DataObject* b);43 static bool ExposureDateTimeAscendingComparator(DataObject* a, DataObject* b);
45 static bool ExposureDateTimeDescendingComparator(DataObject* a, DataObject* b);44 static bool ExposureDateTimeDescendingComparator(DataObject* a, DataObject* b);
4645
47 const QDir& directory() const;
48
49 MediaSource* mediaForId(qint64 id);46 MediaSource* mediaForId(qint64 id);
47 MediaSource* photoFromFileinfo(const QFileInfo &file_to_load);
5048
51 Photo* photoFromFileinfo(QFileInfo file_to_load);49 virtual void AddMany(const QSet<DataObject*>& objects);
5250
53protected slots:51protected slots:
54 virtual void notify_contents_altered(const QSet<DataObject*>* added,52 virtual void notify_contents_altered(const QSet<DataObject*>* added,
@@ -57,9 +55,8 @@
57private:55private:
58 // Used by photoFromFileinfo() to prevent ourselves from accidentally56 // Used by photoFromFileinfo() to prevent ourselves from accidentally
59 // seeing a duplicate photo after an edit.57 // seeing a duplicate photo after an edit.
60 QHash<QString, Photo*> file_photo_map_;58 QHash<QString, MediaSource*> m_filePhotoMap;
6159
62 QDir directory_;
63 QHash<qint64, DataObject*> id_map_;60 QHash<qint64, DataObject*> id_map_;
64};61};
6562
6663
=== modified file 'src/media/media-source.cpp'
--- src/media/media-source.cpp 2013-06-06 16:02:25 +0000
+++ src/media/media-source.cpp 2013-06-07 11:10:22 +0000
@@ -150,8 +150,10 @@
150 * \param respect_orientation150 * \param respect_orientation
151 * \return151 * \return
152 */152 */
153QImage MediaSource::Image(bool respect_orientation)153QImage MediaSource::Image(bool respect_orientation, const QSize &scaleSize)
154{154{
155 Q_UNUSED(respect_orientation);
156 Q_UNUSED(scaleSize);
155 // QML data types cannot be abstract, so return a null image157 // QML data types cannot be abstract, so return a null image
156 return QImage();158 return QImage();
157}159}
158160
=== modified file 'src/media/media-source.h'
--- src/media/media-source.h 2013-06-06 16:02:25 +0000
+++ src/media/media-source.h 2013-06-07 11:10:22 +0000
@@ -23,8 +23,8 @@
23// core23// core
24#include "data-source.h"24#include "data-source.h"
2525
26// photo26// util
27#include "photo-metadata.h"27#include "orientation.h"
2828
29#include <QDate>29#include <QDate>
30#include <QDateTime>30#include <QDateTime>
@@ -93,7 +93,7 @@
93 QUrl thumbnail_path() const;93 QUrl thumbnail_path() const;
94 virtual QUrl gallery_thumbnail_path() const;94 virtual QUrl gallery_thumbnail_path() const;
9595
96 virtual QImage Image(bool respect_orientation = true);96 virtual QImage Image(bool respect_orientation = true, const QSize &scaleSize=QSize());
97 virtual Orientation orientation() const;97 virtual Orientation orientation() const;
98 virtual QDateTime exposure_date_time() const;98 virtual QDateTime exposure_date_time() const;
9999
100100
=== modified file 'src/medialoader/CMakeLists.txt'
--- src/medialoader/CMakeLists.txt 2013-06-07 11:10:22 +0000
+++ src/medialoader/CMakeLists.txt 2013-06-07 11:10:22 +0000
@@ -7,9 +7,6 @@
7 ${gallery_core_src_SOURCE_DIR}7 ${gallery_core_src_SOURCE_DIR}
8 # because of circulate dependencies the sub project can't be used directly8 # because of circulate dependencies the sub project can't be used directly
9 # FIXME resolve the circulate dependencies9 # FIXME resolve the circulate dependencies
10 ${gallery_src_SOURCE_DIR}/database
11 ${gallery_src_SOURCE_DIR}/event
12 ${gallery_src_SOURCE_DIR}/photo
13 ${gallery_src_SOURCE_DIR}/media10 ${gallery_src_SOURCE_DIR}/media
14 ${gallery_util_src_SOURCE_DIR}11 ${gallery_util_src_SOURCE_DIR}
15 ${CMAKE_BINARY_DIR}12 ${CMAKE_BINARY_DIR}
@@ -19,12 +16,14 @@
19set(gallery_medialoader_HDRS16set(gallery_medialoader_HDRS
20 gallery-standard-image-provider.h17 gallery-standard-image-provider.h
21 gallery-thumbnail-image-provider.h18 gallery-thumbnail-image-provider.h
19 photo-metadata.h
22 preview-manager.h20 preview-manager.h
23 )21 )
2422
25set(gallery_medialoader_SRCS23set(gallery_medialoader_SRCS
26 gallery-standard-image-provider.cpp24 gallery-standard-image-provider.cpp
27 gallery-thumbnail-image-provider.cpp25 gallery-thumbnail-image-provider.cpp
26 photo-metadata.cpp
28 preview-manager.cpp27 preview-manager.cpp
29 )28 )
3029
@@ -36,9 +35,6 @@
3635
37target_link_libraries( ${GALLERY_MEDIALOADER_LIB}36target_link_libraries( ${GALLERY_MEDIALOADER_LIB}
38 gallery-core37 gallery-core
39 gallery-database
40 gallery-event
41 gallery-photo
42 gallery-media38 gallery-media
43 gallery-util39 gallery-util
44 ${GSTLIB_LDFLAGS}40 ${GSTLIB_LDFLAGS}
4541
=== modified file 'src/medialoader/gallery-standard-image-provider.cpp'
--- src/medialoader/gallery-standard-image-provider.cpp 2013-06-06 16:02:25 +0000
+++ src/medialoader/gallery-standard-image-provider.cpp 2013-06-07 11:10:22 +0000
@@ -19,8 +19,7 @@
19 */19 */
2020
21#include "gallery-standard-image-provider.h"21#include "gallery-standard-image-provider.h"
2222#include "photo-metadata.h"
23// media
24#include "preview-manager.h"23#include "preview-manager.h"
2524
26#include <QDebug>25#include <QDebug>
2726
=== modified file 'src/medialoader/gallery-standard-image-provider.h'
--- src/medialoader/gallery-standard-image-provider.h 2013-06-06 16:02:25 +0000
+++ src/medialoader/gallery-standard-image-provider.h 2013-06-07 11:10:22 +0000
@@ -21,7 +21,8 @@
21#ifndef GALLERY_GALLERY_STANDARD_IMAGE_PROVIDER_H_21#ifndef GALLERY_GALLERY_STANDARD_IMAGE_PROVIDER_H_
22#define GALLERY_GALLERY_STANDARD_IMAGE_PROVIDER_H_22#define GALLERY_GALLERY_STANDARD_IMAGE_PROVIDER_H_
2323
24#include "photo-metadata.h"24// util
25#include "orientation.h"
2526
26#include <QFileInfo>27#include <QFileInfo>
27#include <QImage>28#include <QImage>
2829
=== renamed file 'src/photo/photo-metadata.cpp' => 'src/medialoader/photo-metadata.cpp'
--- src/photo/photo-metadata.cpp 2013-06-06 16:02:25 +0000
+++ src/medialoader/photo-metadata.cpp 2013-06-07 11:10:22 +0000
@@ -149,31 +149,6 @@
149}149}
150150
151/*!151/*!
152 * \brief PhotoMetadata::rotate_orientation
153 * \param orientation
154 * \param left
155 * \return
156 */
157Orientation PhotoMetadata::rotate_orientation(Orientation orientation, bool left)
158{
159 QVector<Orientation> sequence_a;
160 QVector<Orientation> sequence_b;
161 sequence_a <<
162 TOP_LEFT_ORIGIN << LEFT_BOTTOM_ORIGIN << BOTTOM_RIGHT_ORIGIN << RIGHT_TOP_ORIGIN;
163 sequence_b <<
164 TOP_RIGHT_ORIGIN << RIGHT_BOTTOM_ORIGIN << BOTTOM_LEFT_ORIGIN << LEFT_TOP_ORIGIN;
165
166 const QVector<Orientation>& sequence = (
167 sequence_a.contains(orientation) ? sequence_a : sequence_b);
168
169 int current = sequence.indexOf(orientation);
170 int jump = (left ? 1 : sequence.count() - 1);
171 int next = (current + jump) % sequence.count();
172
173 return sequence[next];
174}
175
176/*!
177 * \brief PhotoMetadata::orientation152 * \brief PhotoMetadata::orientation
178 * \return153 * \return
179 */154 */
@@ -260,108 +235,3 @@
260 return false;235 return false;
261 }236 }
262}237}
263
264/*!
265 * \brief OrientationCorrection::FromOrientation
266 * \param o
267 * \return
268 */
269OrientationCorrection OrientationCorrection::FromOrientation(Orientation o)
270{
271 double rotation_angle = 0.0;
272 double horizontal_scale_factor = 1.0;
273
274 switch (o) {
275 case TOP_RIGHT_ORIGIN:
276 horizontal_scale_factor = -1.0;
277 break;
278
279 case BOTTOM_RIGHT_ORIGIN:
280 rotation_angle = 180.0;
281 break;
282
283 case BOTTOM_LEFT_ORIGIN:
284 horizontal_scale_factor = -1.0;
285 rotation_angle = 180.0;
286 break;
287
288 case LEFT_TOP_ORIGIN:
289 horizontal_scale_factor = -1.0;
290 rotation_angle = -90.0;
291 break;
292
293 case RIGHT_TOP_ORIGIN:
294 rotation_angle = 90.0;
295 break;
296
297 case RIGHT_BOTTOM_ORIGIN:
298 horizontal_scale_factor = -1.0;
299 rotation_angle = 90.0;
300 break;
301
302 case LEFT_BOTTOM_ORIGIN:
303 rotation_angle = -90.0;
304 break;
305
306 default:
307 ; // do nothing
308 break;
309 }
310
311 return OrientationCorrection(rotation_angle, horizontal_scale_factor);
312}
313
314/*!
315 * \brief OrientationCorrection::Identity
316 * \return
317 */
318OrientationCorrection OrientationCorrection::Identity()
319{
320 return OrientationCorrection(0.0, 1.0);
321}
322
323/*!
324 * \brief OrientationCorrection::to_transform
325 * Returns the correction as a QTransform.
326 * \return Returns the correction as a QTransform.
327 */
328QTransform OrientationCorrection::to_transform() const
329{
330 QTransform result;
331 result.scale(horizontal_scale_factor_, 1.0);
332 result.rotate(rotation_angle_);
333
334 return result;
335}
336
337/*!
338 * \brief OrientationCorrection::is_flipped_from
339 * Returns whether the two orientations are flipped relative to each other.
340 * Ignores rotation_angle; only checks horizontal_scale_factor_.
341 * \param other
342 * \return
343 */
344bool OrientationCorrection::is_flipped_from(
345 const OrientationCorrection& other) const
346{
347 return (horizontal_scale_factor_ != other.horizontal_scale_factor_);
348}
349
350/*!
351 * \brief OrientationCorrection::get_normalized_rotation_difference
352 * Returns the rotation difference in degrees (this - other), normalized to
353 * 0, 90, 180, or 270. Ignores the horizontal_scale_factor_.
354 * \param other
355 * \return
356 */
357int OrientationCorrection::get_normalized_rotation_difference(
358 const OrientationCorrection& other) const
359{
360 int degrees_rotation = (int)rotation_angle_ - (int)other.rotation_angle_;
361 if (degrees_rotation < 0)
362 degrees_rotation += 360;
363
364 Q_ASSERT(degrees_rotation == 0 || degrees_rotation == 90 ||
365 degrees_rotation == 180 || degrees_rotation == 270);
366 return degrees_rotation;
367}
368238
=== renamed file 'src/photo/photo-metadata.h' => 'src/medialoader/photo-metadata.h'
--- src/photo/photo-metadata.h 2013-06-06 16:02:25 +0000
+++ src/medialoader/photo-metadata.h 2013-06-07 11:10:22 +0000
@@ -20,6 +20,9 @@
20#ifndef GALLERY_PHOTO_METADATA_H_20#ifndef GALLERY_PHOTO_METADATA_H_
21#define GALLERY_PHOTO_METADATA_H_21#define GALLERY_PHOTO_METADATA_H_
2222
23// util
24#include <orientation.h>
25
23#include <QDateTime>26#include <QDateTime>
24#include <QFileInfo>27#include <QFileInfo>
25#include <QObject>28#include <QObject>
@@ -29,42 +32,6 @@
2932
30#include <exiv2/exiv2.hpp>33#include <exiv2/exiv2.hpp>
3134
32enum Orientation {
33 MIN_ORIENTATION = 1,
34 TOP_LEFT_ORIGIN = 1,
35 TOP_RIGHT_ORIGIN = 2,
36 BOTTOM_RIGHT_ORIGIN = 3,
37 BOTTOM_LEFT_ORIGIN = 4,
38 LEFT_TOP_ORIGIN = 5,
39 RIGHT_TOP_ORIGIN = 6,
40 RIGHT_BOTTOM_ORIGIN = 7,
41 LEFT_BOTTOM_ORIGIN = 8,
42 MAX_ORIENTATION = 8
43};
44
45/*!
46 * \brief The OrientationCorrection struct
47 */
48class OrientationCorrection
49{
50public:
51 static OrientationCorrection FromOrientation(Orientation o);
52 static OrientationCorrection Identity();
53
54 const double rotation_angle_;
55 const double horizontal_scale_factor_;
56
57 QTransform to_transform() const;
58
59 bool is_flipped_from(const OrientationCorrection& other) const;
60 int get_normalized_rotation_difference(const OrientationCorrection& other) const;
61
62private:
63 OrientationCorrection(double rotation_angle, double horizontal_scale_factor)
64 : rotation_angle_(rotation_angle),
65 horizontal_scale_factor_(horizontal_scale_factor) { }
66};
67
68/*!35/*!
69 * \brief The PhotoMetadata class36 * \brief The PhotoMetadata class
70 */37 */
@@ -76,8 +43,6 @@
76 static PhotoMetadata* FromFile(const char* filepath);43 static PhotoMetadata* FromFile(const char* filepath);
77 static PhotoMetadata* FromFile(const QFileInfo& file);44 static PhotoMetadata* FromFile(const QFileInfo& file);
7845
79 static Orientation rotate_orientation(Orientation orientation, bool left);
80
81 QDateTime exposure_time() const;46 QDateTime exposure_time() const;
82 Orientation orientation() const;47 Orientation orientation() const;
83 QTransform orientation_transform() const;48 QTransform orientation_transform() const;
8449
=== modified file 'src/medialoader/preview-manager.cpp'
--- src/medialoader/preview-manager.cpp 2013-06-06 16:02:25 +0000
+++ src/medialoader/preview-manager.cpp 2013-06-07 11:10:22 +0000
@@ -21,9 +21,7 @@
2121
22// media22// media
23#include "media-collection.h"23#include "media-collection.h"
2424#include "media-source.h"
25// photo
26#include "photo.h"
2725
28#include <QCryptographicHash>26#include <QCryptographicHash>
29#include <QDir>27#include <QDir>
@@ -148,7 +146,7 @@
148146
149 QImage thumbMaster;147 QImage thumbMaster;
150 if (updateNeeded(file, QFileInfo(preview)) || regen) {148 if (updateNeeded(file, QFileInfo(preview)) || regen) {
151 Photo* photo = m_mediaCollection->photoFromFileinfo(file);149 MediaSource* photo = m_mediaCollection->photoFromFileinfo(file);
152 QSize previewSize(PREVIEW_SIZE, PREVIEW_SIZE);150 QSize previewSize(PREVIEW_SIZE, PREVIEW_SIZE);
153 QImage fullsized(photo->Image(true, previewSize));151 QImage fullsized(photo->Image(true, previewSize));
154 if (fullsized.isNull()) {152 if (fullsized.isNull()) {
155153
=== modified file 'src/photo/CMakeLists.txt'
--- src/photo/CMakeLists.txt 2013-06-07 11:10:22 +0000
+++ src/photo/CMakeLists.txt 2013-06-07 11:10:22 +0000
@@ -20,14 +20,12 @@
20 photo.h20 photo.h
21 photo-caches.h21 photo-caches.h
22 photo-edit-state.h22 photo-edit-state.h
23 photo-metadata.h
24 )23 )
2524
26set(gallery_photo_SRCS25set(gallery_photo_SRCS
27 photo.cpp26 photo.cpp
28 photo-caches.cpp27 photo-caches.cpp
29 photo-edit-state.cpp28 photo-edit-state.cpp
30 photo-metadata.cpp
31 )29 )
3230
33add_library(${GALLERY_PHOTO_LIB}31add_library(${GALLERY_PHOTO_LIB}
3432
=== modified file 'src/photo/photo-edit-state.h'
--- src/photo/photo-edit-state.h 2013-06-06 16:02:25 +0000
+++ src/photo/photo-edit-state.h 2013-06-07 11:10:22 +0000
@@ -20,7 +20,8 @@
20#ifndef GALLERY_PHOTO_EDIT_STATE_H_20#ifndef GALLERY_PHOTO_EDIT_STATE_H_
21#define GALLERY_PHOTO_EDIT_STATE_H_21#define GALLERY_PHOTO_EDIT_STATE_H_
2222
23#include "photo-metadata.h"23// util
24#include "orientation.h"
2425
25#include <QRect>26#include <QRect>
26#include <QVector4D>27#include <QVector4D>
2728
=== modified file 'src/photo/photo.cpp'
--- src/photo/photo.cpp 2013-06-06 16:02:25 +0000
+++ src/photo/photo.cpp 2013-06-07 11:10:22 +0000
@@ -31,9 +31,10 @@
31// media31// media
32#include "media-collection.h"32#include "media-collection.h"
3333
34// qml34// medialoader
35#include "gallery-standard-image-provider.h"35#include "gallery-standard-image-provider.h"
36#include "gallery-thumbnail-image-provider.h"36#include "gallery-thumbnail-image-provider.h"
37#include "photo-metadata.h"
3738
38// util39// util
39#include "imaging.h"40#include "imaging.h"
@@ -267,9 +268,12 @@
267{268{
268 GalleryManager* gallery_mgr = GalleryManager::instance();269 GalleryManager* gallery_mgr = GalleryManager::instance();
269270
270 Photo* p = gallery_mgr->media_collection()->photoFromFileinfo(file);271 Photo* p = 0;
271 if (p == NULL) {272 MediaSource* media = gallery_mgr->media_collection()->photoFromFileinfo(file);
273 if (media == 0) {
272 p = Load(file);274 p = Load(file);
275 } else {
276 p = qobject_cast<Photo*>(media);
273 }277 }
274278
275 return p;279 return p;
@@ -480,7 +484,7 @@
480void Photo::rotateRight()484void Photo::rotateRight()
481{485{
482 Orientation new_orientation =486 Orientation new_orientation =
483 PhotoMetadata::rotate_orientation(orientation(), false);487 OrientationCorrection::rotate_orientation(orientation(), false);
484488
485 QSize size = get_original_size(orientation());489 QSize size = get_original_size(orientation());
486490
487491
=== modified file 'src/photo/photo.h'
--- src/photo/photo.h 2013-06-06 16:02:25 +0000
+++ src/photo/photo.h 2013-06-07 11:10:22 +0000
@@ -24,11 +24,13 @@
2424
25#include "photo-caches.h"25#include "photo-caches.h"
26#include "photo-edit-state.h"26#include "photo-edit-state.h"
27#include "photo-metadata.h"
2827
29// media28// media
30#include "media-source.h"29#include "media-source.h"
3130
31// util
32#include "orientation.h"
33
32#include <QDateTime>34#include <QDateTime>
33#include <QStack>35#include <QStack>
3436
3537
=== modified file 'src/util/CMakeLists.txt'
--- src/util/CMakeLists.txt 2013-06-06 08:27:23 +0000
+++ src/util/CMakeLists.txt 2013-06-07 11:10:22 +0000
@@ -13,6 +13,7 @@
13 collections.h13 collections.h
14 command-line-parser.h14 command-line-parser.h
15 imaging.h15 imaging.h
16 orientation.h
16 resource.h17 resource.h
17 sharefile.h18 sharefile.h
18 variants.h19 variants.h
@@ -21,6 +22,7 @@
21set(gallery_util_SRCS22set(gallery_util_SRCS
22 command-line-parser.cpp23 command-line-parser.cpp
23 imaging.cpp24 imaging.cpp
25 orientation.cpp
24 resource.cpp26 resource.cpp
25 sharefile.cpp27 sharefile.cpp
26 )28 )
2729
=== added file 'src/util/orientation.cpp'
--- src/util/orientation.cpp 1970-01-01 00:00:00 +0000
+++ src/util/orientation.cpp 2013-06-07 11:10:22 +0000
@@ -0,0 +1,152 @@
1/*
2 * Copyright (C) 2011 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 version 3 as
6 * published by the Free Software Foundation.
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 * Authors:
17 * Lucas Beeler <lucas@yorba.org>
18 */
19
20#include <cstdio>
21
22#include "orientation.h"
23
24/*!
25 * \brief OrientationCorrection::FromOrientation
26 * \param o
27 * \return
28 */
29OrientationCorrection OrientationCorrection::FromOrientation(Orientation o)
30{
31 double rotation_angle = 0.0;
32 double horizontal_scale_factor = 1.0;
33
34 switch (o) {
35 case TOP_RIGHT_ORIGIN:
36 horizontal_scale_factor = -1.0;
37 break;
38
39 case BOTTOM_RIGHT_ORIGIN:
40 rotation_angle = 180.0;
41 break;
42
43 case BOTTOM_LEFT_ORIGIN:
44 horizontal_scale_factor = -1.0;
45 rotation_angle = 180.0;
46 break;
47
48 case LEFT_TOP_ORIGIN:
49 horizontal_scale_factor = -1.0;
50 rotation_angle = -90.0;
51 break;
52
53 case RIGHT_TOP_ORIGIN:
54 rotation_angle = 90.0;
55 break;
56
57 case RIGHT_BOTTOM_ORIGIN:
58 horizontal_scale_factor = -1.0;
59 rotation_angle = 90.0;
60 break;
61
62 case LEFT_BOTTOM_ORIGIN:
63 rotation_angle = -90.0;
64 break;
65
66 default:
67 ; // do nothing
68 break;
69 }
70
71 return OrientationCorrection(rotation_angle, horizontal_scale_factor);
72}
73
74/*!
75 * \brief OrientationCorrection::Identity
76 * \return
77 */
78OrientationCorrection OrientationCorrection::Identity()
79{
80 return OrientationCorrection(0.0, 1.0);
81}
82
83/*!
84 * \brief OrientationCorrection::rotate_orientation
85 * \param orientation
86 * \param left
87 * \return
88 */
89Orientation OrientationCorrection::rotate_orientation(Orientation orientation, bool left)
90{
91 QVector<Orientation> sequence_a;
92 QVector<Orientation> sequence_b;
93 sequence_a <<
94 TOP_LEFT_ORIGIN << LEFT_BOTTOM_ORIGIN << BOTTOM_RIGHT_ORIGIN << RIGHT_TOP_ORIGIN;
95 sequence_b <<
96 TOP_RIGHT_ORIGIN << RIGHT_BOTTOM_ORIGIN << BOTTOM_LEFT_ORIGIN << LEFT_TOP_ORIGIN;
97
98 const QVector<Orientation>& sequence = (
99 sequence_a.contains(orientation) ? sequence_a : sequence_b);
100
101 int current = sequence.indexOf(orientation);
102 int jump = (left ? 1 : sequence.count() - 1);
103 int next = (current + jump) % sequence.count();
104
105 return sequence[next];
106}
107
108/*!
109 * \brief OrientationCorrection::to_transform
110 * Returns the correction as a QTransform.
111 * \return Returns the correction as a QTransform.
112 */
113QTransform OrientationCorrection::to_transform() const
114{
115 QTransform result;
116 result.scale(horizontal_scale_factor_, 1.0);
117 result.rotate(rotation_angle_);
118
119 return result;
120}
121
122/*!
123 * \brief OrientationCorrection::is_flipped_from
124 * Returns whether the two orientations are flipped relative to each other.
125 * Ignores rotation_angle; only checks horizontal_scale_factor_.
126 * \param other
127 * \return
128 */
129bool OrientationCorrection::is_flipped_from(
130 const OrientationCorrection& other) const
131{
132 return (horizontal_scale_factor_ != other.horizontal_scale_factor_);
133}
134
135/*!
136 * \brief OrientationCorrection::get_normalized_rotation_difference
137 * Returns the rotation difference in degrees (this - other), normalized to
138 * 0, 90, 180, or 270. Ignores the horizontal_scale_factor_.
139 * \param other
140 * \return
141 */
142int OrientationCorrection::get_normalized_rotation_difference(
143 const OrientationCorrection& other) const
144{
145 int degrees_rotation = (int)rotation_angle_ - (int)other.rotation_angle_;
146 if (degrees_rotation < 0)
147 degrees_rotation += 360;
148
149 Q_ASSERT(degrees_rotation == 0 || degrees_rotation == 90 ||
150 degrees_rotation == 180 || degrees_rotation == 270);
151 return degrees_rotation;
152}
0153
=== added file 'src/util/orientation.h'
--- src/util/orientation.h 1970-01-01 00:00:00 +0000
+++ src/util/orientation.h 2013-06-07 11:10:22 +0000
@@ -0,0 +1,63 @@
1/*
2 * Copyright (C) 2011 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 version 3 as
6 * published by the Free Software Foundation.
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 * Authors:
17 * Lucas Beeler <lucas@yorba.org>
18 */
19
20#ifndef GALLERY_ORIENTATION_H_
21#define GALLERY_ORIENTATION_H_
22
23#include <QTransform>
24
25enum Orientation {
26 MIN_ORIENTATION = 1,
27 TOP_LEFT_ORIGIN = 1,
28 TOP_RIGHT_ORIGIN = 2,
29 BOTTOM_RIGHT_ORIGIN = 3,
30 BOTTOM_LEFT_ORIGIN = 4,
31 LEFT_TOP_ORIGIN = 5,
32 RIGHT_TOP_ORIGIN = 6,
33 RIGHT_BOTTOM_ORIGIN = 7,
34 LEFT_BOTTOM_ORIGIN = 8,
35 MAX_ORIENTATION = 8
36};
37
38/*!
39 * \brief The OrientationCorrection struct
40 */
41class OrientationCorrection
42{
43public:
44 static OrientationCorrection FromOrientation(Orientation o);
45 static OrientationCorrection Identity();
46 static Orientation rotate_orientation(Orientation orientation, bool left);
47
48 const double rotation_angle_;
49 const double horizontal_scale_factor_;
50
51 QTransform to_transform() const;
52
53 bool is_flipped_from(const OrientationCorrection& other) const;
54 int get_normalized_rotation_difference(const OrientationCorrection& other) const;
55
56private:
57 OrientationCorrection(double rotation_angle, double horizontal_scale_factor)
58 : rotation_angle_(rotation_angle),
59 horizontal_scale_factor_(horizontal_scale_factor) { }
60};
61
62
63#endif // GALLERY_ORIENTATION_H_
064
=== modified file 'tests/unittests/gallerystandardimageprovider/CMakeLists.txt'
--- tests/unittests/gallerystandardimageprovider/CMakeLists.txt 2013-06-07 11:10:22 +0000
+++ tests/unittests/gallerystandardimageprovider/CMakeLists.txt 2013-06-07 11:10:22 +0000
@@ -10,6 +10,7 @@
10 ${gallery_media_src_SOURCE_DIR}10 ${gallery_media_src_SOURCE_DIR}
11 ${gallery_medialoader_src_SOURCE_DIR}11 ${gallery_medialoader_src_SOURCE_DIR}
12 ${gallery_photo_src_SOURCE_DIR}12 ${gallery_photo_src_SOURCE_DIR}
13 ${gallery_util_src_SOURCE_DIR}
13 ${GSTLIB_INCLUDE_DIRS}14 ${GSTLIB_INCLUDE_DIRS}
14 )15 )
1516
1617
=== modified file 'tests/unittests/gallerystandardimageprovider/media-collection.h'
--- tests/unittests/gallerystandardimageprovider/media-collection.h 2013-06-06 06:43:50 +0000
+++ tests/unittests/gallerystandardimageprovider/media-collection.h 2013-06-07 11:10:22 +0000
@@ -22,7 +22,7 @@
22class MediaCollection22class MediaCollection
23{23{
24public:24public:
25 MediaCollection(const QDir& directory) {Q_UNUSED(directory);}25 MediaCollection() {}
26};26};
2727
28#endif28#endif
2929
=== modified file 'tests/unittests/gallerystandardimageprovider/tst_gallerystandardimageprovidertest.cpp'
--- tests/unittests/gallerystandardimageprovider/tst_gallerystandardimageprovidertest.cpp 2013-06-06 06:43:50 +0000
+++ tests/unittests/gallerystandardimageprovider/tst_gallerystandardimageprovidertest.cpp 2013-06-07 11:10:22 +0000
@@ -73,7 +73,7 @@
73 QFETCH(QString, id);73 QFETCH(QString, id);
74 QFETCH(QString, fileName);74 QFETCH(QString, fileName);
7575
76 MediaCollection mediaCollection(QDir("/home/user/Pictures"));76 MediaCollection mediaCollection;
77 PreviewManager previewManager("/home/user/thumbnails", &mediaCollection);77 PreviewManager previewManager("/home/user/thumbnails", &mediaCollection);
78 GalleryStandardImageProvider provider;78 GalleryStandardImageProvider provider;
79 provider.setPreviewManager(&previewManager);79 provider.setPreviewManager(&previewManager);

Subscribers

People subscribed via source and target branches