[Content] Attributes 'modifiedDate' and 'releaseDate' defined in 'Content' interface...
authorTomasz Iwanek <t.iwanek@samsung.com>
Mon, 27 Oct 2014 14:36:54 +0000 (15:36 +0100)
committerTomasz Iwanek <t.iwanek@samsung.com>
Tue, 18 Nov 2014 10:24:17 +0000 (11:24 +0100)
Add conversion from magic format to JS Date for given fields.

All mutators/accessor of ContentItem were adjusted to chromium convention.
Several minor fixes.

BUG=XWALK-2803

content/content_api.js
content/content_instance.cc
content/content_instance.h

index 0eacd99..1a2330a 100644 (file)
@@ -43,6 +43,12 @@ extension.setMessageListener(function(msg) {
   }
 });
 
+function parseDate(date) {
+  if (typeof(date) !== 'string' || date === '')
+    return null;
+  return new Date(date);
+}
+
 function Folder(uri, id, type, title) {
   Object.defineProperties(this, {
     'directoryURI': { writable: false, value: uri, enumerable: true },
@@ -63,15 +69,15 @@ function Content(editableAttributes, id, name, type, mimeType, title, contentURI
     'title': { writable: false, value: title, enumerable: true },
     'contentURI': { writable: false, value: contentURI, enumerable: true },
     'thumnailURIs': { writable: false, value: thumnailURIs, enumerable: true },
-    'releaseDate': { writable: false, value: releaseDate, enumerable: true },
-    'modifiedDate': { writable: false, value: modifiedDate, enumerable: true },
+    'releaseDate': { writable: false, value: parseDate(releaseDate), enumerable: true },
+    'modifiedDate': { writable: false, value: parseDate(modifiedDate), enumerable: true },
     'size': { writable: false, value: size, enumerable: true },
     'description': { writable: true, value: description, enumerable: true },
     'rating': { writable: true, value: rating, enumerable: true }
   });
 }
 
-function ContentAudio(obj, album, genres, artists, composer, copyright,
+function AudioContent(obj, album, genres, artists, composer, copyright,
     bitrate, trackNumber, duration) {
   Object.defineProperties(obj, {
     'album': { writable: false, value: album, enumerable: true },
@@ -85,7 +91,7 @@ function ContentAudio(obj, album, genres, artists, composer, copyright,
   });
 }
 
-function ContentImage(obj, geolocation, width, height, orientation) {
+function ImageContent(obj, geolocation, width, height, orientation) {
   Object.defineProperties(obj, {
     'geolocation': { writable: true, value: geolocation, enumerable: true },
     'width': { writable: false, value: width, enumerable: true },
@@ -94,7 +100,7 @@ function ContentImage(obj, geolocation, width, height, orientation) {
   });
 }
 
-function ContentVideo(obj, geolocation, album, artists, duration, width, height) {
+function VideoContent(obj, geolocation, album, artists, duration, width, height) {
   Object.defineProperties(obj, {
     'geolocation': { writable: true, value: geolocation, enumerable: true },
     'album': { writable: false, value: album, enumerable: true },
@@ -188,7 +194,7 @@ ContentManager.prototype.find = function(onsuccess, onerror, directoryId,
             content.rating);
 
         if (content.type == 'AUDIO') {
-          ContentAudio(jsonContent,
+          AudioContent(jsonContent,
               content.album,
               content.genres,
               content.artists,
@@ -199,14 +205,14 @@ ContentManager.prototype.find = function(onsuccess, onerror, directoryId,
               content.duration);
         } else if (content.type == 'IMAGE') {
           var geolocation = new tizen.SimpleCoordinates(content.latitude, content.longitude);
-          ContentImage(jsonContent,
+          ImageContent(jsonContent,
               geolocation,
               content.width,
               content.height,
               content.orientation);
         } else if (content.type == 'VIDEO') {
           var geolocation = new tizen.SimpleCoordinates(content.latitude, content.longitude);
-          ContentVideo(jsonContent,
+          VideoContent(jsonContent,
               geolocation,
               content.album,
               content.artists,
index 2014bb9..b048281 100644 (file)
@@ -9,6 +9,7 @@
 #include <media_filter.h>
 
 #include <assert.h>
+#include <time.h>
 
 #include <iostream>
 #include <fstream>
@@ -40,6 +41,25 @@ std::string getUriPath(const std::string uri) {
   else
     return "";
 }
+
+// Tizen video meta APIs return date format "%Y:%m:%d %H:%M:%S",
+// while standard JavaScript Date accept format as "%Y-%m-%d %H:%M:%S".
+// So we need this conversion function.
+std::string ConvertToJSDateString(const char* date) {
+  struct tm result;
+  if (strptime(date, "%Y:%m:%d %H:%M:%S", &result) == NULL) {
+    return "";
+  }
+
+  char output_date[20];
+  memset(output_date, 0, 20);
+  if (!strftime(output_date, 20, "%Y-%m-%d %H:%M:%S", &result)) {
+    return "";
+  }
+
+  return std::string(output_date);
+}
+
 }  // namespace
 
 unsigned ContentInstance::m_instanceCount = 0;
@@ -303,15 +323,15 @@ void ContentInstance::HandleFindReply(
     o[STR_ID] = picojson::value(item->id());
     o[STR_NAME] = picojson::value(item->name());
     o["type"] = picojson::value(item->type());
-    o["mimeType"] = picojson::value(item->mimeType());
+    o["mimeType"] = picojson::value(item->mime_type());
     o["title"] = picojson::value(item->title());
-    o["contentURI"] = picojson::value(item->contentURI());
+    o["contentURI"] = picojson::value(item->content_uri());
     picojson::value::array uris;
-    uris.push_back(picojson::value(item->thumbnailURIs()));
+    uris.push_back(picojson::value(item->thumbnail_uris()));
     o["thumbnailURIs"] = picojson::value(uris);
-    o["releaseDate"] = picojson::value(item->releaseDate());
+    o["releaseDate"] = picojson::value(item->release_date());
     o["modifiedDate"] =
-      picojson::value(item->modifiedDate());
+      picojson::value(item->modified_date());
     o["size"] = picojson::value(static_cast<double>(item->size()));
     o[STR_DESCRIPTION] = picojson::value(item->description());
     o[STR_RATING] = picojson::value(static_cast<double>(item->rating()));
@@ -330,7 +350,7 @@ void ContentInstance::HandleFindReply(
       o["copyright"] = picojson::value(item->copyright());
       o["bitrate"] = picojson::value(static_cast<double>(item->bitrate()));
       o["trackNumber"] = picojson::value(
-          static_cast<double>(item->trackNumber()));
+          static_cast<double>(item->track_number()));
       o["duration"] = picojson::value(static_cast<double>(item->duration()));
     } else if (item->type() == "IMAGE") {
       o["width"] = picojson::value(static_cast<double>(item->width()));
@@ -488,40 +508,40 @@ void ContentItem::init(media_info_h handle) {
   // even the return code is MEDIA_CONTENT_ERROR_NONE.
 
   if (media_info_get_media_id(handle, &pc) == MEDIA_CONTENT_ERROR_NONE && pc) {
-    setID(pc);
+    set_id(pc);
     free(pc);
   }
 
   if (media_info_get_mime_type(handle, &pc) == MEDIA_CONTENT_ERROR_NONE && pc) {
-    setMimeType(pc);
+    set_mime_type(pc);
     free(pc);
   }
 
   if (media_info_get_title(handle, &pc) == MEDIA_CONTENT_ERROR_NONE && pc) {
-    setTitle(pc);
+    set_title(pc);
     free(pc);
   }
 
   if (media_info_get_display_name(handle,
       &pc) == MEDIA_CONTENT_ERROR_NONE && pc) {
-    setName(pc);
+    set_name(pc);
     free(pc);
   }
 
   if (media_info_get_file_path(handle, &pc) == MEDIA_CONTENT_ERROR_NONE && pc) {
-    setContentURI(createUriFromLocalPath(pc));
+    set_content_uri(createUriFromLocalPath(pc));
     free(pc);
   }
 
   if (media_info_get_thumbnail_path(handle,
       &pc) == MEDIA_CONTENT_ERROR_NONE && pc) {
-    setThumbnailURIs(createUriFromLocalPath(pc));
+    set_thumbnail_uris(createUriFromLocalPath(pc));
     free(pc);
   }
 
   if (media_info_get_description(handle,
       &pc) == MEDIA_CONTENT_ERROR_NONE && pc) {
-    setDescription(pc);
+    set_description(pc);
     free(pc);
   }
 
@@ -529,36 +549,36 @@ void ContentItem::init(media_info_h handle) {
   if (media_info_get_modified_time(handle, &date) == MEDIA_CONTENT_ERROR_NONE) {
     char tmp[26];
     ctime_r(&date, tmp);
-    setModifiedDate(tmp);
+    set_modified_date(tmp);
   }
 
   int i = 0;
   if (media_info_get_rating(handle, &i) == MEDIA_CONTENT_ERROR_NONE)
-    setRating(i);
+    set_rating(i);
 
   unsigned long long ll; // NOLINT
   if (media_info_get_size(handle, &ll) == MEDIA_CONTENT_ERROR_NONE)
-    setSize(ll);
+    set_size(ll);
 
   media_content_type_e type;
   if (media_info_get_media_type(handle, &type) == MEDIA_CONTENT_ERROR_NONE) {
     if (type == MEDIA_CONTENT_TYPE_IMAGE) {
-      setType("IMAGE");
+      set_type("IMAGE");
 
       image_meta_h image;
       if (media_info_get_image(handle, &image) == MEDIA_CONTENT_ERROR_NONE) {
         if (image_meta_get_width(image, &i) == MEDIA_CONTENT_ERROR_NONE)
-          setWidth(i);
+          set_width(i);
 
         if (image_meta_get_height(image, &i) == MEDIA_CONTENT_ERROR_NONE)
-          setHeight(i);
+          set_height(i);
 
         double d;
         if (media_info_get_latitude(handle, &d) == MEDIA_CONTENT_ERROR_NONE)
-          setLatitude(d);
+          set_latitude(d);
 
        if (media_info_get_longitude(handle, &d) == MEDIA_CONTENT_ERROR_NONE)
-          setLongitude(d);
+          set_longitude(d);
 
         media_content_orientation_e orientation;
         if (image_meta_get_orientation(image, &orientation)
@@ -577,105 +597,106 @@ void ContentItem::init(media_info_h handle) {
             case 8: result = "ROTATE_270"; break;
             default: result = "Unknown"; break;
           }
-          setOrientation(result);
+          set_orientation(result);
         }
         image_meta_destroy(image);
       }
     } else if (type == MEDIA_CONTENT_TYPE_VIDEO) {
-      setType("VIDEO");
+      set_type("VIDEO");
 
       video_meta_h video;
       if (media_info_get_video(handle, &video) == MEDIA_CONTENT_ERROR_NONE) {
         if (video_meta_get_recorded_date(video,
             &pc) == MEDIA_CONTENT_ERROR_NONE && pc) {
-          setReleaseDate(pc);
+          set_release_date(ConvertToJSDateString(pc));
           free(pc);
         }
 
         if (video_meta_get_album(video,
             &pc) == MEDIA_CONTENT_ERROR_NONE && pc) {
-          setAlbum(pc);
+          set_album(pc);
           free(pc);
         }
 
         if (video_meta_get_artist(video,
             &pc) == MEDIA_CONTENT_ERROR_NONE && pc) {
-          setArtists(pc);
+          set_artists(pc);
           free(pc);
         }
 
         if (video_meta_get_width(video, &i) == MEDIA_CONTENT_ERROR_NONE) {
-          setWidth(i);
+          set_width(i);
         }
 
         if (video_meta_get_height(video, &i) == MEDIA_CONTENT_ERROR_NONE) {
-          setHeight(i);
+          set_height(i);
         }
 
         if (video_meta_get_duration(video, &i) == MEDIA_CONTENT_ERROR_NONE) {
-          setDuration(i);
+          set_duration(i);
         }
 
         double d;
         if (media_info_get_latitude(handle, &d) == MEDIA_CONTENT_ERROR_NONE)
-          setLatitude(d);
+          set_latitude(d);
 
         if (media_info_get_longitude(handle, &d) == MEDIA_CONTENT_ERROR_NONE)
-          setLongitude(d);
+          set_longitude(d);
 
         video_meta_destroy(video);
       }
-    } else if (type == MEDIA_CONTENT_TYPE_MUSIC) {
-      setType("AUDIO");
+    } else if (type == MEDIA_CONTENT_TYPE_MUSIC ||
+        type == MEDIA_CONTENT_TYPE_SOUND) {
+      set_type("AUDIO");
 
       audio_meta_h audio;
       if (media_info_get_audio(handle, &audio) == MEDIA_CONTENT_ERROR_NONE) {
         if (audio_meta_get_recorded_date(audio,
             &pc) == MEDIA_CONTENT_ERROR_NONE && pc) {
-          setReleaseDate(pc);
+          set_release_date(ConvertToJSDateString(pc));
           free(pc);
         }
 
         if (audio_meta_get_album(audio,
             &pc) == MEDIA_CONTENT_ERROR_NONE && pc) {
-          setAlbum(pc);
+          set_album(pc);
           free(pc);
         }
 
         if (audio_meta_get_artist(audio,
             &pc) == MEDIA_CONTENT_ERROR_NONE && pc) {
-          setArtists(pc);
+          set_artists(pc);
           free(pc);
         }
 
         if (audio_meta_get_composer(audio,
             &pc) == MEDIA_CONTENT_ERROR_NONE && pc) {
-          setComposer(pc);
+          set_composer(pc);
           free(pc);
         }
 
         if (audio_meta_get_duration(audio, &i) == MEDIA_CONTENT_ERROR_NONE)
-          setDuration(i);
+          set_duration(i);
 
         if (audio_meta_get_copyright(audio,
             &pc) == MEDIA_CONTENT_ERROR_NONE && pc) {
-          setCopyright(pc);
+          set_copyright(pc);
           free(pc);
         }
 
         if (audio_meta_get_track_num(audio,
             &pc) == MEDIA_CONTENT_ERROR_NONE && pc) {
           i = atoi(pc);
-          setTrackNumber(i);
+          set_track_number(i);
           free(pc);
         }
 
         if (audio_meta_get_bit_rate(audio, &i) == MEDIA_CONTENT_ERROR_NONE)
-          setBitrate(i);
+          set_bitrate(i);
       }
       audio_meta_destroy(audio);
     } else if (type == MEDIA_CONTENT_TYPE_OTHERS) {
-      setType("OTHER");
+      set_type("OTHER");
     }
   }
 }
index d530b6e..6b35d06 100644 (file)
@@ -96,7 +96,7 @@ class ContentFolder {
 
 class ContentItem {
  public:
-  ContentItem() : size_(0), rating_(0), bitrate_(0), trackNumber_(0),
+  ContentItem() : size_(0), rating_(0), bitrate_(0), track_number_(0),
       duration_(0), width_(0), height_(0), latitude_(DEFAULT_GEOLOCATION),
       longitude_(DEFAULT_GEOLOCATION) {
     editable_attributes_.push_back("name");
@@ -113,59 +113,59 @@ class ContentItem {
     return editable_attributes_;
   }
   const std::string& id() const { return id_; }
-  void setID(const std::string& id) { id_ = id; }
+  void set_id(const std::string& id) { id_ = id; }
   const std::string& name() const { return name_; }
-  void setName(const std::string& name) { name_ = name; }
+  void set_name(const std::string& name) { name_ = name; }
   const std::string& type() const { return type_; }
-  void setType(const std::string& type) { type_ = type;}
-  const std::string& mimeType() const { return mimeType_; }
-  void setMimeType(const std::string& mimeType) { mimeType_ = mimeType; }
+  void set_type(const std::string& type) { type_ = type;}
+  const std::string& mime_type() const { return mime_type_; }
+  void set_mime_type(const std::string& mime_type) { mime_type_ = mime_type; }
   const std::string& title() const { return title_; }
-  void setTitle(const std::string& title) { title_ = title;}
-  const std::string& contentURI() const { return contentURI_; }
-  void setContentURI(const std::string& uri) { contentURI_ = uri; }
-  const std::string& thumbnailURIs() const { return thumbnailURIs_; }
-  void setThumbnailURIs(const std::string& uris) { thumbnailURIs_ = uris; }
-  const std::string& releaseDate() const { return releaseDate_; }
-  void setReleaseDate(const std::string releaseDate) {
-    releaseDate_ = releaseDate; }
-  const std::string& modifiedDate() const { return modifiedDate_; }
-  void setModifiedDate(const std::string& modifiedDate) {
-    modifiedDate_ = modifiedDate; }
+  void set_title(const std::string& title) { title_ = title;}
+  const std::string& content_uri() const { return content_uri_; }
+  void set_content_uri(const std::string& uri) { content_uri_ = uri; }
+  const std::string& thumbnail_uris() const { return thumbnail_uris_; }
+  void set_thumbnail_uris(const std::string& uris) { thumbnail_uris_ = uris; }
+  const std::string& release_date() const { return release_date_; }
+  void set_release_date(const std::string release_date) {
+    release_date_ = release_date; }
+  const std::string& modified_date() const { return modified_date_; }
+  void set_modified_date(const std::string& modified_date) {
+    modified_date_ = modified_date; }
   uint64_t size() const { return size_; }
-  void setSize(const uint64_t size) { size_ = size; }
+  void set_size(const uint64_t size) { size_ = size; }
   const std::string& description() const { return description_; }
-  void setDescription(const std::string& desc) { description_ = desc; }
+  void set_description(const std::string& desc) { description_ = desc; }
   uint64_t rating() const { return rating_; }
-  void setRating(uint64_t rating) { rating_ = rating; }
+  void set_rating(uint64_t rating) { rating_ = rating; }
   // type = AUDIO and VIDEO
   const std::string& album() const { return album_; }
-  void setAlbum(const std::string& album) { album_ = album;}
+  void set_album(const std::string& album) { album_ = album;}
   const std::string& genres() const { return genres_; }
-  void setGenres(const std::string& genres) { genres_ = genres;}
+  void set_genres(const std::string& genres) { genres_ = genres;}
   const std::string& artists() const { return artists_; }
-  void setArtists(const std::string& artists) { artists_ = artists;}
+  void set_artists(const std::string& artists) { artists_ = artists;}
   const std::string& composer() const { return composer_; }
-  void setComposer(const std::string& composer) { composer_ = composer;}
+  void set_composer(const std::string& composer) { composer_ = composer;}
   const std::string& copyright() const { return copyright_; }
-  void setCopyright(const std::string& copyright) { copyright_ = copyright;}
-  uint64_t bitrate() const { return rating_; }
-  void setBitrate(uint64_t bitrate) { bitrate_ = bitrate; }
-  uint64_t trackNumber() const { return bitrate_; }
-  void setTrackNumber(uint64_t num) { trackNumber_ = num; }
+  void set_copyright(const std::string& copyright) { copyright_ = copyright;}
+  uint64_t bitrate() const { return bitrate_; }
+  void set_bitrate(uint64_t bitrate) { bitrate_ = bitrate; }
+  uint64_t track_number() const { return track_number_; }
+  void set_track_number(uint64_t num) { track_number_ = num; }
   int duration() const { return duration_; }
-  void setDuration(int duration) { duration_ = duration; }
+  void set_duration(int duration) { duration_ = duration; }
   // type = IMAGE
   uint64_t width() const { return width_; }
-  void setWidth(uint64_t width) { width_ = width; }
+  void set_width(uint64_t width) { width_ = width; }
   uint64_t height() const { return height_; }
-  void setHeight(uint64_t height) { height_ = height; }
+  void set_height(uint64_t height) { height_ = height; }
   const std::string& orientation() const { return orientation_; }
-  void setOrientation(const std::string& orintatin) {orientation_ = orintatin;}
+  void set_orientation(const std::string& orintatin) {orientation_ = orintatin;}
   double latitude() const { return latitude_; }
-  void setLatitude(double latitude) { latitude_ = latitude; }
+  void set_latitude(double latitude) { latitude_ = latitude; }
   double longitude() const { return longitude_; }
-  void setLongitude(double longitude) { longitude_ = longitude; }
+  void set_longitude(double longitude) { longitude_ = longitude; }
 
 #ifdef DEBUG_ITEM
   void print(void);
@@ -176,12 +176,12 @@ class ContentItem {
   std::string id_;
   std::string name_;
   std::string type_;
-  std::string mimeType_;
+  std::string mime_type_;
   std::string title_;
-  std::string contentURI_;
-  std::string thumbnailURIs_;
-  std::string releaseDate_;
-  std::string modifiedDate_;
+  std::string content_uri_;
+  std::string thumbnail_uris_;
+  std::string release_date_;
+  std::string modified_date_;
   uint64_t size_;
   std::string description_;
   uint64_t rating_;
@@ -193,7 +193,7 @@ class ContentItem {
   std::string composer_;
   std::string copyright_;
   uint64_t bitrate_;
-  uint16_t trackNumber_;
+  uint16_t track_number_;
   int duration_;
 
   // type = IMAGE