Commit 00d1fec0 authored by gbillock@chromium.org's avatar gbillock@chromium.org

[MediaGalleries] iPhoto: Add original file field to the parser. Dedupe album names.

Review URL: https://codereview.chromium.org/52093003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@233368 0039d316-1c4b-4281-b951-d872f2087c98
parent 802a24c7
......@@ -11,9 +11,12 @@ Photo::Photo()
: id(0) {
}
Photo::Photo(uint64 id, const base::FilePath& location)
Photo::Photo(uint64 id,
const base::FilePath& location,
const base::FilePath& original_location)
: id(id),
location(location) {
location(location),
original_location(original_location) {
}
bool Photo::operator<(const Photo& other) const {
......
......@@ -18,11 +18,14 @@ namespace parser {
struct Photo {
Photo();
Photo(uint64 id, const base::FilePath& location);
Photo(uint64 id,
const base::FilePath& location,
const base::FilePath& original_location);
bool operator<(const Photo& other) const;
uint64 id;
base::FilePath location;
base::FilePath original_location;
};
typedef std::set<uint64> Album;
......
......@@ -19,9 +19,8 @@ namespace {
struct PhotoInfo {
uint64 id;
std::string guid;
base::FilePath location;
std::string type;
base::FilePath original_location;
};
struct AlbumInfo {
......@@ -43,11 +42,8 @@ bool GetPhotoInfoFromDict(XmlReader* reader, PhotoInfo* result) {
if (!reader->Read())
return false;
bool found_guid = false;
bool found_location = false;
bool found_type = false;
while (reader->Depth() >= dict_content_depth &&
!(found_guid && found_location && found_type)) {
while (reader->Depth() >= dict_content_depth) {
if (!iapps::SeekToNodeAtCurrentDepth(reader, "key"))
break;
std::string found_key;
......@@ -55,19 +51,7 @@ bool GetPhotoInfoFromDict(XmlReader* reader, PhotoInfo* result) {
break;
DCHECK_EQ(dict_content_depth, reader->Depth());
if (found_key == "GUID") {
if (found_guid)
break;
if (!iapps::ReadString(reader, &result->guid))
break;
found_guid = true;
} else if (found_key == "MediaType") {
if (found_type)
break;
if (!iapps::ReadString(reader, &result->type))
break;
found_type = true;
} else if (found_key == "ImagePath") {
if (found_key == "ImagePath") {
if (found_location)
break;
std::string value;
......@@ -75,6 +59,11 @@ bool GetPhotoInfoFromDict(XmlReader* reader, PhotoInfo* result) {
break;
result->location = base::FilePath(value);
found_location = true;
} else if (found_key == "OriginalPath") {
std::string value;
if (!iapps::ReadString(reader, &value))
break;
result->original_location = base::FilePath(value);
} else {
if (!iapps::SkipToNextElement(reader))
break;
......@@ -229,7 +218,8 @@ bool ParseAllPhotos(XmlReader* reader,
break;
}
parser::Photo photo(photo_info.id, photo_info.location);
parser::Photo photo(photo_info.id, photo_info.location,
photo_info.original_location);
all_photos->insert(photo);
}
......@@ -286,10 +276,15 @@ bool IPhotoLibraryParser::Parse(const std::string& library_xml) {
if (GetAlbumInfoFromDict(&reader, &album_info)) {
parser::Album album;
album = album_info.photo_ids;
// Strip / from album name.
// Strip / from album name and dedupe any collisions.
std::string name;
ReplaceChars(album_info.name, "//", " ", &name);
library_.albums[name] = album;
if (!ContainsKey(library_.albums, name)) {
library_.albums[name] = album;
} else {
library_.albums[name+"("+base::Uint64ToString(album_info.id)+")"] =
album;
}
}
}
} else if (found_key == "Master Image List") {
......
......@@ -42,18 +42,26 @@
" </dict>"
#define SIMPLE_PHOTO(id, guid, path, caption) \
" <key>" #id "</key>" \
" <dict>" \
" <key>MediaType</key>" \
" <string>Image</string>" \
" <key>Caption</key>" \
" <string>" caption "</string>" \
" <key>GUID</key>" \
" <string>" #guid "</string>" \
" <key>ImagePath</key>" \
" <string>" path "</string>" \
" <key>ThumbPath</key>" \
" <string>" path "</string>" \
" <key>" #id "</key>" \
" <dict>" \
" <key>MediaType</key>" \
" <string>Image</string>" \
" <key>Caption</key>" \
" <string>" caption "</string>" \
" <key>GUID</key>" \
" <string>" #guid "</string>" \
" <key>ModDateAsTimerInterval</key>" \
" <string>386221543.0000</string>" \
" <key>DateAsTimerInterval</key>" \
" <string>386221543.0000</string>" \
" <key>DateAsTimerIntervalGMT</key>" \
" <string>385123456.00</string>" \
" <key>ImagePath</key>" \
" <string>" path "</string>" \
" <key>OriginalPath</key>" \
" <string>/original" path "</string>" \
" <key>ThumbPath</key>" \
" <string>" path "</string>" \
" </dict>"
#define SIMPLE_FOOTER() \
......@@ -99,6 +107,7 @@ namespace {
void ComparePhoto(const parser::Photo& a, const parser::Photo& b) {
EXPECT_EQ(a.id, b.id);
EXPECT_EQ(a.location.value(), b.location.value());
EXPECT_EQ(a.original_location.value(), b.original_location.value());
}
void CompareAlbum(const parser::Album& a, const parser::Album& b) {
......@@ -152,9 +161,11 @@ class IPhotoLibraryParserTest : public testing::Test {
CompareLibrary(expected_library_, parser.library());
}
void AddExpectedPhoto(uint32 id, const std::string& location,
void AddExpectedPhoto(uint32 id,
const std::string& location,
const std::string& album) {
parser::Photo photo(id, base::FilePath::FromUTF8Unsafe(location));
parser::Photo photo(id, base::FilePath::FromUTF8Unsafe(location),
base::FilePath::FromUTF8Unsafe("/original" + location));
if (!album.empty())
expected_library_.albums[album].insert(id);
expected_library_.all_photos.insert(photo);
......@@ -287,6 +298,27 @@ TEST_F(IPhotoLibraryParserTest, MalformedSyntax) {
SIMPLE_FOOTER());
}
TEST_F(IPhotoLibraryParserTest, DuplicateAlbumNames) {
AddExpectedPhoto(1, "/dir/PhotoA1.jpg", "Album 1");
AddExpectedPhoto(2, "/dir/PhotoA2.jpg", "Album 1");
AddExpectedPhoto(3, "/dir/PhotoA3.jpg", "Album 1(11)");
AddExpectedPhoto(4, "/dir/PhotoB1.jpg", "Album 1(11)");
TestParser(
true,
SIMPLE_HEADER()
ALBUMS_HEADER()
SIMPLE_ALBUM(10, "Album 1", 1, 2)
SIMPLE_ALBUM(11, "Album 1", 3, 4)
ALBUMS_FOOTER()
IMAGE_LIST_HEADER()
SIMPLE_PHOTO(1, 1, "/dir/PhotoA1.jpg", "Photo 1")
SIMPLE_PHOTO(2, 2, "/dir/PhotoA2.jpg", "Photo 2")
SIMPLE_PHOTO(3, 3, "/dir/PhotoA3.jpg", "Photo 3")
SIMPLE_PHOTO(4, 4, "/dir/PhotoB1.jpg", "Photo 4")
IMAGE_LIST_FOOTER()
SIMPLE_FOOTER());
}
} // namespace
} // namespace iphoto
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment