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
1=== modified file 'src/album/CMakeLists.txt'
2--- src/album/CMakeLists.txt 2013-06-06 15:33:12 +0000
3+++ src/album/CMakeLists.txt 2013-06-07 11:10:22 +0000
4@@ -9,7 +9,6 @@
5 # FIXME resolve the circulate dependencies
6 ${gallery_src_SOURCE_DIR}/database
7 ${gallery_src_SOURCE_DIR}/media
8- ${gallery_src_SOURCE_DIR}/photo
9 ${gallery_src_SOURCE_DIR}/qml
10 ${gallery_util_src_SOURCE_DIR}
11 ${CMAKE_BINARY_DIR}
12@@ -44,7 +43,6 @@
13 gallery-core
14 gallery-database
15 gallery-media
16- gallery-photo
17 gallery-qml
18 gallery-util
19 ${GSTLIB_LDFLAGS}
20
21=== modified file 'src/core/data-collection.h'
22--- src/core/data-collection.h 2013-06-06 16:02:25 +0000
23+++ src/core/data-collection.h 2013-06-07 11:10:22 +0000
24@@ -67,7 +67,7 @@
25 int Count() const;
26
27 void Add(DataObject* object);
28- void AddMany(const QSet<DataObject*>& objects);
29+ virtual void AddMany(const QSet<DataObject*>& objects);
30
31 void Remove(DataObject* object);
32 void RemoveAt(int index);
33
34=== modified file 'src/database/media-table.h'
35--- src/database/media-table.h 2013-06-06 16:02:25 +0000
36+++ src/database/media-table.h 2013-06-07 11:10:22 +0000
37@@ -20,7 +20,8 @@
38 #ifndef MEDIATABLE_H
39 #define MEDIATABLE_H
40
41-#include "photo-metadata.h"
42+// util
43+#include "orientation.h"
44
45 #include <QObject>
46
47
48=== modified file 'src/event/CMakeLists.txt'
49--- src/event/CMakeLists.txt 2013-06-06 15:33:12 +0000
50+++ src/event/CMakeLists.txt 2013-06-07 11:10:22 +0000
51@@ -8,7 +8,6 @@
52 # because of circulate dependencies the sub project can't be used directly
53 # FIXME resolve the circulate dependencies
54 ${gallery_src_SOURCE_DIR}/media
55- ${gallery_src_SOURCE_DIR}/photo
56 ${gallery_util_src_SOURCE_DIR}
57 ${CMAKE_BINARY_DIR}
58 ${GSTLIB_INCLUDE_DIRS}
59@@ -33,7 +32,6 @@
60 target_link_libraries( ${GALLERY_EVENT_LIB}
61 gallery-core
62 gallery-media
63- gallery-photo
64 gallery-util
65 ${GSTLIB_LDFLAGS}
66 )
67
68=== modified file 'src/gallery-application.cpp'
69--- src/gallery-application.cpp 2013-06-06 16:02:25 +0000
70+++ src/gallery-application.cpp 2013-06-07 11:10:22 +0000
71@@ -223,8 +223,8 @@
72 */
73 void GalleryApplication::on_media_item_added(QFileInfo item_info)
74 {
75- Photo* new_photo = Photo::Fetch(item_info);
76+ MediaSource* newMedia = Photo::Fetch(item_info);
77
78- if (new_photo)
79- GalleryManager::instance()->media_collection()->Add(new_photo);
80+ if (newMedia)
81+ GalleryManager::instance()->media_collection()->Add(newMedia);
82 }
83
84=== modified file 'src/gallery-manager.cpp'
85--- src/gallery-manager.cpp 2013-06-06 16:02:25 +0000
86+++ src/gallery-manager.cpp 2013-06-07 11:10:22 +0000
87@@ -33,6 +33,7 @@
88
89 // media
90 #include "media-collection.h"
91+#include "photo.h"
92 #include "preview-manager.h"
93
94 // qml
95@@ -42,6 +43,8 @@
96 // util
97 #include "resource.h"
98
99+#include <exiv2/exiv2.hpp>
100+
101 GalleryManager* GalleryManager::gallery_mgr_ = NULL;
102
103 /*!
104@@ -94,8 +97,8 @@
105 resource_->get_rc_url("sql").path());
106 database_->get_media_table()->verify_files();
107 default_template_ = new AlbumDefaultTemplate();
108- QDir mediaDir(resource_->picturesDirectory());
109- media_collection_ = new MediaCollection(mediaDir);
110+ media_collection_ = new MediaCollection();
111+ fillMediaCollection();
112 album_collection_ = new AlbumCollection();
113 event_collection_ = new EventCollection();
114
115@@ -171,3 +174,29 @@
116 // Verify previews for all existing added MediaSources
117 preview_manager_->onMediaAddedRemoved(&media_collection_->GetAsSet(), NULL);
118 }
119+
120+/*!
121+ * \brief GalleryManager::fillMediaCollection fills the MediaCollection with
122+ * the content of the picture directory
123+ */
124+void GalleryManager::fillMediaCollection()
125+{
126+ Q_ASSERT(media_collection_);
127+
128+ QDir mediaDir(resource_->picturesDirectory());
129+ mediaDir.setFilter(QDir::Files);
130+ mediaDir.setSorting(QDir::Name);
131+
132+ QSet<DataObject*> photos;
133+ const QStringList filenames = mediaDir.entryList();
134+ foreach (const QString& filename, filenames) {
135+ QFileInfo file(mediaDir, filename);
136+ Photo *p = Photo::Load(file);
137+ if (!p)
138+ continue;
139+
140+ photos.insert(p);
141+ }
142+
143+ media_collection_->AddMany(photos);
144+}
145
146=== modified file 'src/gallery-manager.h'
147--- src/gallery-manager.h 2013-06-06 16:02:25 +0000
148+++ src/gallery-manager.h 2013-06-07 11:10:22 +0000
149@@ -71,6 +71,7 @@
150 void operator=(const GalleryManager&);
151
152 void initPreviewManager();
153+ void fillMediaCollection();
154
155 static GalleryManager* gallery_mgr_;
156
157
158=== modified file 'src/media/CMakeLists.txt'
159--- src/media/CMakeLists.txt 2013-06-07 11:10:22 +0000
160+++ src/media/CMakeLists.txt 2013-06-07 11:10:22 +0000
161@@ -10,7 +10,6 @@
162 ${gallery_src_SOURCE_DIR}/database
163 ${gallery_src_SOURCE_DIR}/event
164 ${gallery_src_SOURCE_DIR}/medialoader
165- ${gallery_src_SOURCE_DIR}/photo
166 ${gallery_util_src_SOURCE_DIR}
167 ${CMAKE_BINARY_DIR}
168 ${GSTLIB_INCLUDE_DIRS}
169@@ -39,7 +38,6 @@
170 gallery-database
171 gallery-event
172 gallery-medialoader
173- gallery-photo
174 gallery-util
175 ${GSTLIB_LDFLAGS}
176 )
177
178=== modified file 'src/media/media-collection.cpp'
179--- src/media/media-collection.cpp 2013-06-06 16:02:25 +0000
180+++ src/media/media-collection.cpp 2013-06-07 11:10:22 +0000
181@@ -18,14 +18,12 @@
182 */
183
184 #include "media-collection.h"
185+#include "media-source.h"
186
187 // database
188 #include "database.h"
189 #include "media-table.h"
190
191-// photo
192-#include "photo.h"
193-
194 // src
195 #include "gallery-manager.h"
196
197@@ -37,39 +35,11 @@
198 * \brief MediaCollection::MediaCollection
199 * \param directory
200 */
201-MediaCollection::MediaCollection(const QDir& directory)
202- : SourceCollection("MediaCollection"), directory_(directory)
203+MediaCollection::MediaCollection()
204+ : SourceCollection("MediaCollection")
205 {
206- directory_.setFilter(QDir::Files);
207- directory_.setSorting(QDir::Name);
208-
209 // By default, sort all media by its exposure date time, descending
210 SetComparator(ExposureDateTimeDescendingComparator);
211-
212- QSet<DataObject*> photos;
213- QStringList filenames = directory_.entryList();
214- QString filename;
215- foreach (filename, filenames) {
216- QFileInfo file(directory_, filename);
217-
218- Photo *p = Photo::Load(file);
219- if (!p)
220- continue;
221-
222- photos.insert(p);
223- id_map_.insert(p->get_id(), p);
224- }
225-
226- AddMany(photos);
227-}
228-
229-/*!
230- * \brief MediaCollection::directory
231- * \return
232- */
233-const QDir& MediaCollection::directory() const
234-{
235- return directory_;
236 }
237
238 /*!
239@@ -132,9 +102,9 @@
240 DataObject* o = i.next();
241 id_map_.insert(qobject_cast<MediaSource*>(o)->get_id(), o);
242
243- Photo* p = qobject_cast<Photo*>(o);
244- if (p != NULL) {
245- file_photo_map_.insert(p->file().absoluteFilePath(), p);
246+ MediaSource* media = qobject_cast<MediaSource*>(o);
247+ if (media != 0) {
248+ m_filePhotoMap.insert(media->file().absoluteFilePath(), media);
249 }
250 }
251 }
252@@ -145,9 +115,8 @@
253 DataObject* o = i.next();
254 MediaSource* media = qobject_cast<MediaSource*>(o);
255
256- Photo* p = qobject_cast<Photo*>(o);
257- if (p != NULL) {
258- file_photo_map_.remove(p->file().absoluteFilePath());
259+ if (media != 0) {
260+ m_filePhotoMap.remove(media->file().absoluteFilePath());
261 }
262
263 id_map_.remove(media->get_id());
264@@ -168,7 +137,20 @@
265 * \param file_to_load
266 * \return
267 */
268-Photo* MediaCollection::photoFromFileinfo(QFileInfo file_to_load)
269-{
270- return file_photo_map_.value(file_to_load.absoluteFilePath(), NULL);
271+MediaSource *MediaCollection::photoFromFileinfo(const QFileInfo& file_to_load)
272+{
273+ return m_filePhotoMap.value(file_to_load.absoluteFilePath(), 0);
274+}
275+
276+/*!
277+ * \reimp
278+ */
279+void MediaCollection::AddMany(const QSet<DataObject *> &objects)
280+{
281+ foreach (DataObject* data, objects) {
282+ MediaSource* media = qobject_cast<MediaSource*>(data);
283+ id_map_.insert(media->get_id(), media);
284+ }
285+
286+ DataCollection::AddMany(objects);
287 }
288
289=== modified file 'src/media/media-collection.h'
290--- src/media/media-collection.h 2013-06-06 16:02:25 +0000
291+++ src/media/media-collection.h 2013-06-07 11:10:22 +0000
292@@ -20,7 +20,7 @@
293 #ifndef GALLERY_MEDIA_COLLECTION_H_
294 #define GALLERY_MEDIA_COLLECTION_H_
295
296-#include <QDir>
297+#include <QFileInfo>
298 #include <QHash>
299 #include <QSet>
300
301@@ -29,7 +29,6 @@
302
303 class DataObject;
304 class MediaSource;
305-class Photo;
306
307 /*!
308 * \brief The MediaCollection class
309@@ -39,16 +38,15 @@
310 Q_OBJECT
311
312 public:
313- MediaCollection(const QDir& directory);
314+ MediaCollection();
315
316 static bool ExposureDateTimeAscendingComparator(DataObject* a, DataObject* b);
317 static bool ExposureDateTimeDescendingComparator(DataObject* a, DataObject* b);
318
319- const QDir& directory() const;
320-
321 MediaSource* mediaForId(qint64 id);
322+ MediaSource* photoFromFileinfo(const QFileInfo &file_to_load);
323
324- Photo* photoFromFileinfo(QFileInfo file_to_load);
325+ virtual void AddMany(const QSet<DataObject*>& objects);
326
327 protected slots:
328 virtual void notify_contents_altered(const QSet<DataObject*>* added,
329@@ -57,9 +55,8 @@
330 private:
331 // Used by photoFromFileinfo() to prevent ourselves from accidentally
332 // seeing a duplicate photo after an edit.
333- QHash<QString, Photo*> file_photo_map_;
334+ QHash<QString, MediaSource*> m_filePhotoMap;
335
336- QDir directory_;
337 QHash<qint64, DataObject*> id_map_;
338 };
339
340
341=== modified file 'src/media/media-source.cpp'
342--- src/media/media-source.cpp 2013-06-06 16:02:25 +0000
343+++ src/media/media-source.cpp 2013-06-07 11:10:22 +0000
344@@ -150,8 +150,10 @@
345 * \param respect_orientation
346 * \return
347 */
348-QImage MediaSource::Image(bool respect_orientation)
349+QImage MediaSource::Image(bool respect_orientation, const QSize &scaleSize)
350 {
351+ Q_UNUSED(respect_orientation);
352+ Q_UNUSED(scaleSize);
353 // QML data types cannot be abstract, so return a null image
354 return QImage();
355 }
356
357=== modified file 'src/media/media-source.h'
358--- src/media/media-source.h 2013-06-06 16:02:25 +0000
359+++ src/media/media-source.h 2013-06-07 11:10:22 +0000
360@@ -23,8 +23,8 @@
361 // core
362 #include "data-source.h"
363
364-// photo
365-#include "photo-metadata.h"
366+// util
367+#include "orientation.h"
368
369 #include <QDate>
370 #include <QDateTime>
371@@ -93,7 +93,7 @@
372 QUrl thumbnail_path() const;
373 virtual QUrl gallery_thumbnail_path() const;
374
375- virtual QImage Image(bool respect_orientation = true);
376+ virtual QImage Image(bool respect_orientation = true, const QSize &scaleSize=QSize());
377 virtual Orientation orientation() const;
378 virtual QDateTime exposure_date_time() const;
379
380
381=== modified file 'src/medialoader/CMakeLists.txt'
382--- src/medialoader/CMakeLists.txt 2013-06-07 11:10:22 +0000
383+++ src/medialoader/CMakeLists.txt 2013-06-07 11:10:22 +0000
384@@ -7,9 +7,6 @@
385 ${gallery_core_src_SOURCE_DIR}
386 # because of circulate dependencies the sub project can't be used directly
387 # FIXME resolve the circulate dependencies
388- ${gallery_src_SOURCE_DIR}/database
389- ${gallery_src_SOURCE_DIR}/event
390- ${gallery_src_SOURCE_DIR}/photo
391 ${gallery_src_SOURCE_DIR}/media
392 ${gallery_util_src_SOURCE_DIR}
393 ${CMAKE_BINARY_DIR}
394@@ -19,12 +16,14 @@
395 set(gallery_medialoader_HDRS
396 gallery-standard-image-provider.h
397 gallery-thumbnail-image-provider.h
398+ photo-metadata.h
399 preview-manager.h
400 )
401
402 set(gallery_medialoader_SRCS
403 gallery-standard-image-provider.cpp
404 gallery-thumbnail-image-provider.cpp
405+ photo-metadata.cpp
406 preview-manager.cpp
407 )
408
409@@ -36,9 +35,6 @@
410
411 target_link_libraries( ${GALLERY_MEDIALOADER_LIB}
412 gallery-core
413- gallery-database
414- gallery-event
415- gallery-photo
416 gallery-media
417 gallery-util
418 ${GSTLIB_LDFLAGS}
419
420=== modified file 'src/medialoader/gallery-standard-image-provider.cpp'
421--- src/medialoader/gallery-standard-image-provider.cpp 2013-06-06 16:02:25 +0000
422+++ src/medialoader/gallery-standard-image-provider.cpp 2013-06-07 11:10:22 +0000
423@@ -19,8 +19,7 @@
424 */
425
426 #include "gallery-standard-image-provider.h"
427-
428-// media
429+#include "photo-metadata.h"
430 #include "preview-manager.h"
431
432 #include <QDebug>
433
434=== modified file 'src/medialoader/gallery-standard-image-provider.h'
435--- src/medialoader/gallery-standard-image-provider.h 2013-06-06 16:02:25 +0000
436+++ src/medialoader/gallery-standard-image-provider.h 2013-06-07 11:10:22 +0000
437@@ -21,7 +21,8 @@
438 #ifndef GALLERY_GALLERY_STANDARD_IMAGE_PROVIDER_H_
439 #define GALLERY_GALLERY_STANDARD_IMAGE_PROVIDER_H_
440
441-#include "photo-metadata.h"
442+// util
443+#include "orientation.h"
444
445 #include <QFileInfo>
446 #include <QImage>
447
448=== renamed file 'src/photo/photo-metadata.cpp' => 'src/medialoader/photo-metadata.cpp'
449--- src/photo/photo-metadata.cpp 2013-06-06 16:02:25 +0000
450+++ src/medialoader/photo-metadata.cpp 2013-06-07 11:10:22 +0000
451@@ -149,31 +149,6 @@
452 }
453
454 /*!
455- * \brief PhotoMetadata::rotate_orientation
456- * \param orientation
457- * \param left
458- * \return
459- */
460-Orientation PhotoMetadata::rotate_orientation(Orientation orientation, bool left)
461-{
462- QVector<Orientation> sequence_a;
463- QVector<Orientation> sequence_b;
464- sequence_a <<
465- TOP_LEFT_ORIGIN << LEFT_BOTTOM_ORIGIN << BOTTOM_RIGHT_ORIGIN << RIGHT_TOP_ORIGIN;
466- sequence_b <<
467- TOP_RIGHT_ORIGIN << RIGHT_BOTTOM_ORIGIN << BOTTOM_LEFT_ORIGIN << LEFT_TOP_ORIGIN;
468-
469- const QVector<Orientation>& sequence = (
470- sequence_a.contains(orientation) ? sequence_a : sequence_b);
471-
472- int current = sequence.indexOf(orientation);
473- int jump = (left ? 1 : sequence.count() - 1);
474- int next = (current + jump) % sequence.count();
475-
476- return sequence[next];
477-}
478-
479-/*!
480 * \brief PhotoMetadata::orientation
481 * \return
482 */
483@@ -260,108 +235,3 @@
484 return false;
485 }
486 }
487-
488-/*!
489- * \brief OrientationCorrection::FromOrientation
490- * \param o
491- * \return
492- */
493-OrientationCorrection OrientationCorrection::FromOrientation(Orientation o)
494-{
495- double rotation_angle = 0.0;
496- double horizontal_scale_factor = 1.0;
497-
498- switch (o) {
499- case TOP_RIGHT_ORIGIN:
500- horizontal_scale_factor = -1.0;
501- break;
502-
503- case BOTTOM_RIGHT_ORIGIN:
504- rotation_angle = 180.0;
505- break;
506-
507- case BOTTOM_LEFT_ORIGIN:
508- horizontal_scale_factor = -1.0;
509- rotation_angle = 180.0;
510- break;
511-
512- case LEFT_TOP_ORIGIN:
513- horizontal_scale_factor = -1.0;
514- rotation_angle = -90.0;
515- break;
516-
517- case RIGHT_TOP_ORIGIN:
518- rotation_angle = 90.0;
519- break;
520-
521- case RIGHT_BOTTOM_ORIGIN:
522- horizontal_scale_factor = -1.0;
523- rotation_angle = 90.0;
524- break;
525-
526- case LEFT_BOTTOM_ORIGIN:
527- rotation_angle = -90.0;
528- break;
529-
530- default:
531- ; // do nothing
532- break;
533- }
534-
535- return OrientationCorrection(rotation_angle, horizontal_scale_factor);
536-}
537-
538-/*!
539- * \brief OrientationCorrection::Identity
540- * \return
541- */
542-OrientationCorrection OrientationCorrection::Identity()
543-{
544- return OrientationCorrection(0.0, 1.0);
545-}
546-
547-/*!
548- * \brief OrientationCorrection::to_transform
549- * Returns the correction as a QTransform.
550- * \return Returns the correction as a QTransform.
551- */
552-QTransform OrientationCorrection::to_transform() const
553-{
554- QTransform result;
555- result.scale(horizontal_scale_factor_, 1.0);
556- result.rotate(rotation_angle_);
557-
558- return result;
559-}
560-
561-/*!
562- * \brief OrientationCorrection::is_flipped_from
563- * Returns whether the two orientations are flipped relative to each other.
564- * Ignores rotation_angle; only checks horizontal_scale_factor_.
565- * \param other
566- * \return
567- */
568-bool OrientationCorrection::is_flipped_from(
569- const OrientationCorrection& other) const
570-{
571- return (horizontal_scale_factor_ != other.horizontal_scale_factor_);
572-}
573-
574-/*!
575- * \brief OrientationCorrection::get_normalized_rotation_difference
576- * Returns the rotation difference in degrees (this - other), normalized to
577- * 0, 90, 180, or 270. Ignores the horizontal_scale_factor_.
578- * \param other
579- * \return
580- */
581-int OrientationCorrection::get_normalized_rotation_difference(
582- const OrientationCorrection& other) const
583-{
584- int degrees_rotation = (int)rotation_angle_ - (int)other.rotation_angle_;
585- if (degrees_rotation < 0)
586- degrees_rotation += 360;
587-
588- Q_ASSERT(degrees_rotation == 0 || degrees_rotation == 90 ||
589- degrees_rotation == 180 || degrees_rotation == 270);
590- return degrees_rotation;
591-}
592
593=== renamed file 'src/photo/photo-metadata.h' => 'src/medialoader/photo-metadata.h'
594--- src/photo/photo-metadata.h 2013-06-06 16:02:25 +0000
595+++ src/medialoader/photo-metadata.h 2013-06-07 11:10:22 +0000
596@@ -20,6 +20,9 @@
597 #ifndef GALLERY_PHOTO_METADATA_H_
598 #define GALLERY_PHOTO_METADATA_H_
599
600+// util
601+#include <orientation.h>
602+
603 #include <QDateTime>
604 #include <QFileInfo>
605 #include <QObject>
606@@ -29,42 +32,6 @@
607
608 #include <exiv2/exiv2.hpp>
609
610-enum Orientation {
611- MIN_ORIENTATION = 1,
612- TOP_LEFT_ORIGIN = 1,
613- TOP_RIGHT_ORIGIN = 2,
614- BOTTOM_RIGHT_ORIGIN = 3,
615- BOTTOM_LEFT_ORIGIN = 4,
616- LEFT_TOP_ORIGIN = 5,
617- RIGHT_TOP_ORIGIN = 6,
618- RIGHT_BOTTOM_ORIGIN = 7,
619- LEFT_BOTTOM_ORIGIN = 8,
620- MAX_ORIENTATION = 8
621-};
622-
623-/*!
624- * \brief The OrientationCorrection struct
625- */
626-class OrientationCorrection
627-{
628-public:
629- static OrientationCorrection FromOrientation(Orientation o);
630- static OrientationCorrection Identity();
631-
632- const double rotation_angle_;
633- const double horizontal_scale_factor_;
634-
635- QTransform to_transform() const;
636-
637- bool is_flipped_from(const OrientationCorrection& other) const;
638- int get_normalized_rotation_difference(const OrientationCorrection& other) const;
639-
640-private:
641- OrientationCorrection(double rotation_angle, double horizontal_scale_factor)
642- : rotation_angle_(rotation_angle),
643- horizontal_scale_factor_(horizontal_scale_factor) { }
644-};
645-
646 /*!
647 * \brief The PhotoMetadata class
648 */
649@@ -76,8 +43,6 @@
650 static PhotoMetadata* FromFile(const char* filepath);
651 static PhotoMetadata* FromFile(const QFileInfo& file);
652
653- static Orientation rotate_orientation(Orientation orientation, bool left);
654-
655 QDateTime exposure_time() const;
656 Orientation orientation() const;
657 QTransform orientation_transform() const;
658
659=== modified file 'src/medialoader/preview-manager.cpp'
660--- src/medialoader/preview-manager.cpp 2013-06-06 16:02:25 +0000
661+++ src/medialoader/preview-manager.cpp 2013-06-07 11:10:22 +0000
662@@ -21,9 +21,7 @@
663
664 // media
665 #include "media-collection.h"
666-
667-// photo
668-#include "photo.h"
669+#include "media-source.h"
670
671 #include <QCryptographicHash>
672 #include <QDir>
673@@ -148,7 +146,7 @@
674
675 QImage thumbMaster;
676 if (updateNeeded(file, QFileInfo(preview)) || regen) {
677- Photo* photo = m_mediaCollection->photoFromFileinfo(file);
678+ MediaSource* photo = m_mediaCollection->photoFromFileinfo(file);
679 QSize previewSize(PREVIEW_SIZE, PREVIEW_SIZE);
680 QImage fullsized(photo->Image(true, previewSize));
681 if (fullsized.isNull()) {
682
683=== modified file 'src/photo/CMakeLists.txt'
684--- src/photo/CMakeLists.txt 2013-06-07 11:10:22 +0000
685+++ src/photo/CMakeLists.txt 2013-06-07 11:10:22 +0000
686@@ -20,14 +20,12 @@
687 photo.h
688 photo-caches.h
689 photo-edit-state.h
690- photo-metadata.h
691 )
692
693 set(gallery_photo_SRCS
694 photo.cpp
695 photo-caches.cpp
696 photo-edit-state.cpp
697- photo-metadata.cpp
698 )
699
700 add_library(${GALLERY_PHOTO_LIB}
701
702=== modified file 'src/photo/photo-edit-state.h'
703--- src/photo/photo-edit-state.h 2013-06-06 16:02:25 +0000
704+++ src/photo/photo-edit-state.h 2013-06-07 11:10:22 +0000
705@@ -20,7 +20,8 @@
706 #ifndef GALLERY_PHOTO_EDIT_STATE_H_
707 #define GALLERY_PHOTO_EDIT_STATE_H_
708
709-#include "photo-metadata.h"
710+// util
711+#include "orientation.h"
712
713 #include <QRect>
714 #include <QVector4D>
715
716=== modified file 'src/photo/photo.cpp'
717--- src/photo/photo.cpp 2013-06-06 16:02:25 +0000
718+++ src/photo/photo.cpp 2013-06-07 11:10:22 +0000
719@@ -31,9 +31,10 @@
720 // media
721 #include "media-collection.h"
722
723-// qml
724+// medialoader
725 #include "gallery-standard-image-provider.h"
726 #include "gallery-thumbnail-image-provider.h"
727+#include "photo-metadata.h"
728
729 // util
730 #include "imaging.h"
731@@ -267,9 +268,12 @@
732 {
733 GalleryManager* gallery_mgr = GalleryManager::instance();
734
735- Photo* p = gallery_mgr->media_collection()->photoFromFileinfo(file);
736- if (p == NULL) {
737+ Photo* p = 0;
738+ MediaSource* media = gallery_mgr->media_collection()->photoFromFileinfo(file);
739+ if (media == 0) {
740 p = Load(file);
741+ } else {
742+ p = qobject_cast<Photo*>(media);
743 }
744
745 return p;
746@@ -480,7 +484,7 @@
747 void Photo::rotateRight()
748 {
749 Orientation new_orientation =
750- PhotoMetadata::rotate_orientation(orientation(), false);
751+ OrientationCorrection::rotate_orientation(orientation(), false);
752
753 QSize size = get_original_size(orientation());
754
755
756=== modified file 'src/photo/photo.h'
757--- src/photo/photo.h 2013-06-06 16:02:25 +0000
758+++ src/photo/photo.h 2013-06-07 11:10:22 +0000
759@@ -24,11 +24,13 @@
760
761 #include "photo-caches.h"
762 #include "photo-edit-state.h"
763-#include "photo-metadata.h"
764
765 // media
766 #include "media-source.h"
767
768+// util
769+#include "orientation.h"
770+
771 #include <QDateTime>
772 #include <QStack>
773
774
775=== modified file 'src/util/CMakeLists.txt'
776--- src/util/CMakeLists.txt 2013-06-06 08:27:23 +0000
777+++ src/util/CMakeLists.txt 2013-06-07 11:10:22 +0000
778@@ -13,6 +13,7 @@
779 collections.h
780 command-line-parser.h
781 imaging.h
782+ orientation.h
783 resource.h
784 sharefile.h
785 variants.h
786@@ -21,6 +22,7 @@
787 set(gallery_util_SRCS
788 command-line-parser.cpp
789 imaging.cpp
790+ orientation.cpp
791 resource.cpp
792 sharefile.cpp
793 )
794
795=== added file 'src/util/orientation.cpp'
796--- src/util/orientation.cpp 1970-01-01 00:00:00 +0000
797+++ src/util/orientation.cpp 2013-06-07 11:10:22 +0000
798@@ -0,0 +1,152 @@
799+/*
800+ * Copyright (C) 2011 Canonical Ltd
801+ *
802+ * This program is free software: you can redistribute it and/or modify
803+ * it under the terms of the GNU General Public License version 3 as
804+ * published by the Free Software Foundation.
805+ *
806+ * This program is distributed in the hope that it will be useful,
807+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
808+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
809+ * GNU General Public License for more details.
810+ *
811+ * You should have received a copy of the GNU General Public License
812+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
813+ *
814+ * Authors:
815+ * Lucas Beeler <lucas@yorba.org>
816+ */
817+
818+#include <cstdio>
819+
820+#include "orientation.h"
821+
822+/*!
823+ * \brief OrientationCorrection::FromOrientation
824+ * \param o
825+ * \return
826+ */
827+OrientationCorrection OrientationCorrection::FromOrientation(Orientation o)
828+{
829+ double rotation_angle = 0.0;
830+ double horizontal_scale_factor = 1.0;
831+
832+ switch (o) {
833+ case TOP_RIGHT_ORIGIN:
834+ horizontal_scale_factor = -1.0;
835+ break;
836+
837+ case BOTTOM_RIGHT_ORIGIN:
838+ rotation_angle = 180.0;
839+ break;
840+
841+ case BOTTOM_LEFT_ORIGIN:
842+ horizontal_scale_factor = -1.0;
843+ rotation_angle = 180.0;
844+ break;
845+
846+ case LEFT_TOP_ORIGIN:
847+ horizontal_scale_factor = -1.0;
848+ rotation_angle = -90.0;
849+ break;
850+
851+ case RIGHT_TOP_ORIGIN:
852+ rotation_angle = 90.0;
853+ break;
854+
855+ case RIGHT_BOTTOM_ORIGIN:
856+ horizontal_scale_factor = -1.0;
857+ rotation_angle = 90.0;
858+ break;
859+
860+ case LEFT_BOTTOM_ORIGIN:
861+ rotation_angle = -90.0;
862+ break;
863+
864+ default:
865+ ; // do nothing
866+ break;
867+ }
868+
869+ return OrientationCorrection(rotation_angle, horizontal_scale_factor);
870+}
871+
872+/*!
873+ * \brief OrientationCorrection::Identity
874+ * \return
875+ */
876+OrientationCorrection OrientationCorrection::Identity()
877+{
878+ return OrientationCorrection(0.0, 1.0);
879+}
880+
881+/*!
882+ * \brief OrientationCorrection::rotate_orientation
883+ * \param orientation
884+ * \param left
885+ * \return
886+ */
887+Orientation OrientationCorrection::rotate_orientation(Orientation orientation, bool left)
888+{
889+ QVector<Orientation> sequence_a;
890+ QVector<Orientation> sequence_b;
891+ sequence_a <<
892+ TOP_LEFT_ORIGIN << LEFT_BOTTOM_ORIGIN << BOTTOM_RIGHT_ORIGIN << RIGHT_TOP_ORIGIN;
893+ sequence_b <<
894+ TOP_RIGHT_ORIGIN << RIGHT_BOTTOM_ORIGIN << BOTTOM_LEFT_ORIGIN << LEFT_TOP_ORIGIN;
895+
896+ const QVector<Orientation>& sequence = (
897+ sequence_a.contains(orientation) ? sequence_a : sequence_b);
898+
899+ int current = sequence.indexOf(orientation);
900+ int jump = (left ? 1 : sequence.count() - 1);
901+ int next = (current + jump) % sequence.count();
902+
903+ return sequence[next];
904+}
905+
906+/*!
907+ * \brief OrientationCorrection::to_transform
908+ * Returns the correction as a QTransform.
909+ * \return Returns the correction as a QTransform.
910+ */
911+QTransform OrientationCorrection::to_transform() const
912+{
913+ QTransform result;
914+ result.scale(horizontal_scale_factor_, 1.0);
915+ result.rotate(rotation_angle_);
916+
917+ return result;
918+}
919+
920+/*!
921+ * \brief OrientationCorrection::is_flipped_from
922+ * Returns whether the two orientations are flipped relative to each other.
923+ * Ignores rotation_angle; only checks horizontal_scale_factor_.
924+ * \param other
925+ * \return
926+ */
927+bool OrientationCorrection::is_flipped_from(
928+ const OrientationCorrection& other) const
929+{
930+ return (horizontal_scale_factor_ != other.horizontal_scale_factor_);
931+}
932+
933+/*!
934+ * \brief OrientationCorrection::get_normalized_rotation_difference
935+ * Returns the rotation difference in degrees (this - other), normalized to
936+ * 0, 90, 180, or 270. Ignores the horizontal_scale_factor_.
937+ * \param other
938+ * \return
939+ */
940+int OrientationCorrection::get_normalized_rotation_difference(
941+ const OrientationCorrection& other) const
942+{
943+ int degrees_rotation = (int)rotation_angle_ - (int)other.rotation_angle_;
944+ if (degrees_rotation < 0)
945+ degrees_rotation += 360;
946+
947+ Q_ASSERT(degrees_rotation == 0 || degrees_rotation == 90 ||
948+ degrees_rotation == 180 || degrees_rotation == 270);
949+ return degrees_rotation;
950+}
951
952=== added file 'src/util/orientation.h'
953--- src/util/orientation.h 1970-01-01 00:00:00 +0000
954+++ src/util/orientation.h 2013-06-07 11:10:22 +0000
955@@ -0,0 +1,63 @@
956+/*
957+ * Copyright (C) 2011 Canonical Ltd
958+ *
959+ * This program is free software: you can redistribute it and/or modify
960+ * it under the terms of the GNU General Public License version 3 as
961+ * published by the Free Software Foundation.
962+ *
963+ * This program is distributed in the hope that it will be useful,
964+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
965+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
966+ * GNU General Public License for more details.
967+ *
968+ * You should have received a copy of the GNU General Public License
969+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
970+ *
971+ * Authors:
972+ * Lucas Beeler <lucas@yorba.org>
973+ */
974+
975+#ifndef GALLERY_ORIENTATION_H_
976+#define GALLERY_ORIENTATION_H_
977+
978+#include <QTransform>
979+
980+enum Orientation {
981+ MIN_ORIENTATION = 1,
982+ TOP_LEFT_ORIGIN = 1,
983+ TOP_RIGHT_ORIGIN = 2,
984+ BOTTOM_RIGHT_ORIGIN = 3,
985+ BOTTOM_LEFT_ORIGIN = 4,
986+ LEFT_TOP_ORIGIN = 5,
987+ RIGHT_TOP_ORIGIN = 6,
988+ RIGHT_BOTTOM_ORIGIN = 7,
989+ LEFT_BOTTOM_ORIGIN = 8,
990+ MAX_ORIENTATION = 8
991+};
992+
993+/*!
994+ * \brief The OrientationCorrection struct
995+ */
996+class OrientationCorrection
997+{
998+public:
999+ static OrientationCorrection FromOrientation(Orientation o);
1000+ static OrientationCorrection Identity();
1001+ static Orientation rotate_orientation(Orientation orientation, bool left);
1002+
1003+ const double rotation_angle_;
1004+ const double horizontal_scale_factor_;
1005+
1006+ QTransform to_transform() const;
1007+
1008+ bool is_flipped_from(const OrientationCorrection& other) const;
1009+ int get_normalized_rotation_difference(const OrientationCorrection& other) const;
1010+
1011+private:
1012+ OrientationCorrection(double rotation_angle, double horizontal_scale_factor)
1013+ : rotation_angle_(rotation_angle),
1014+ horizontal_scale_factor_(horizontal_scale_factor) { }
1015+};
1016+
1017+
1018+#endif // GALLERY_ORIENTATION_H_
1019
1020=== modified file 'tests/unittests/gallerystandardimageprovider/CMakeLists.txt'
1021--- tests/unittests/gallerystandardimageprovider/CMakeLists.txt 2013-06-07 11:10:22 +0000
1022+++ tests/unittests/gallerystandardimageprovider/CMakeLists.txt 2013-06-07 11:10:22 +0000
1023@@ -10,6 +10,7 @@
1024 ${gallery_media_src_SOURCE_DIR}
1025 ${gallery_medialoader_src_SOURCE_DIR}
1026 ${gallery_photo_src_SOURCE_DIR}
1027+ ${gallery_util_src_SOURCE_DIR}
1028 ${GSTLIB_INCLUDE_DIRS}
1029 )
1030
1031
1032=== modified file 'tests/unittests/gallerystandardimageprovider/media-collection.h'
1033--- tests/unittests/gallerystandardimageprovider/media-collection.h 2013-06-06 06:43:50 +0000
1034+++ tests/unittests/gallerystandardimageprovider/media-collection.h 2013-06-07 11:10:22 +0000
1035@@ -22,7 +22,7 @@
1036 class MediaCollection
1037 {
1038 public:
1039- MediaCollection(const QDir& directory) {Q_UNUSED(directory);}
1040+ MediaCollection() {}
1041 };
1042
1043 #endif
1044
1045=== modified file 'tests/unittests/gallerystandardimageprovider/tst_gallerystandardimageprovidertest.cpp'
1046--- tests/unittests/gallerystandardimageprovider/tst_gallerystandardimageprovidertest.cpp 2013-06-06 06:43:50 +0000
1047+++ tests/unittests/gallerystandardimageprovider/tst_gallerystandardimageprovidertest.cpp 2013-06-07 11:10:22 +0000
1048@@ -73,7 +73,7 @@
1049 QFETCH(QString, id);
1050 QFETCH(QString, fileName);
1051
1052- MediaCollection mediaCollection(QDir("/home/user/Pictures"));
1053+ MediaCollection mediaCollection;
1054 PreviewManager previewManager("/home/user/thumbnails", &mediaCollection);
1055 GalleryStandardImageProvider provider;
1056 provider.setPreviewManager(&previewManager);

Subscribers

People subscribed via source and target branches