[MediaContent] Support ebook format (#3374)
authorHaesu Gwon <haesu.gwon@samsung.com>
Mon, 6 Sep 2021 06:25:39 +0000 (15:25 +0900)
committerGitHub <noreply@github.com>
Mon, 6 Sep 2021 06:25:39 +0000 (15:25 +0900)
* [MediaContent] Support ebook format

src/Tizen.Content.MediaContent/Interop/Interop.BookInfo.cs [new file with mode: 0644]
src/Tizen.Content.MediaContent/Interop/Interop.MediaInfo.cs
src/Tizen.Content.MediaContent/Tizen.Content.MediaContent.csproj
src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/BookInfo.cs [new file with mode: 0644]
src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/Enums.cs
src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInfo.cs
src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInfoCommand.cs
src/Tizen.Multimedia/AssemblyAttrs.cs

diff --git a/src/Tizen.Content.MediaContent/Interop/Interop.BookInfo.cs b/src/Tizen.Content.MediaContent/Interop/Interop.BookInfo.cs
new file mode 100644 (file)
index 0000000..4bc192c
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Runtime.InteropServices;
+using Tizen.Content.MediaContent;
+
+internal static partial class Interop
+{
+    internal static partial class BookInfo
+    {
+        [DllImport(Libraries.MediaContent, EntryPoint = "book_meta_destroy")]
+        internal static extern MediaContentError Destroy(IntPtr handle);
+
+        [DllImport(Libraries.MediaContent, EntryPoint = "book_meta_get_media_id")]
+        internal static extern MediaContentError GetMediaId(IntPtr handle, out IntPtr mediaId);
+
+        [DllImport(Libraries.MediaContent, EntryPoint = "book_meta_get_subject")]
+        internal static extern MediaContentError GetSubject(IntPtr handle, out IntPtr subject);
+
+        [DllImport(Libraries.MediaContent, EntryPoint = "book_meta_get_author")]
+        internal static extern MediaContentError GetAuthor(IntPtr handle, out IntPtr author);
+
+        [DllImport(Libraries.MediaContent, EntryPoint = "book_meta_get_date")]
+        internal static extern MediaContentError GetDate(IntPtr handle, out IntPtr date);
+
+        [DllImport(Libraries.MediaContent, EntryPoint = "book_meta_get_publisher")]
+        internal static extern MediaContentError GetPublisher(IntPtr handle, out IntPtr publisher);
+
+        [DllImport(Libraries.MediaContent, EntryPoint = "book_meta_get_path_with_keyword")]
+        internal static extern MediaContentError GetPathByKeyword(string keyword, out IntPtr path, out uint length);
+    }
+}
index fe3bae0..89cfeb4 100644 (file)
@@ -81,6 +81,9 @@ internal static partial class Interop
         [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_audio")]
         internal static extern MediaContentError GetAudio(MediaInfoHandle handle, out IntPtr audioHandle);
 
+        [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_book")]
+        internal static extern MediaContentError GetBook(MediaInfoHandle handle, out IntPtr bookHandle);
+
         [DllImport(Libraries.MediaContent, EntryPoint = "media_info_get_media_id")]
         internal static extern MediaContentError GetMediaId(MediaInfoHandle mediaInformationHandle, out IntPtr mediaId);
 
index 7a96416..e404a79 100644 (file)
@@ -5,6 +5,7 @@
   </PropertyGroup>
 
   <ItemGroup>
+    <ProjectReference Include="..\Tizen.Multimedia\Tizen.Multimedia.csproj" />
     <ProjectReference Include="..\Tizen.System.Storage\Tizen.System.Storage.csproj" />
     <ProjectReference Include="..\Tizen\Tizen.csproj" />
     <ProjectReference Include="..\Tizen.Log\Tizen.Log.csproj" />
diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/BookInfo.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/BookInfo.cs
new file mode 100644 (file)
index 0000000..fbd8bf3
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Diagnostics;
+
+namespace Tizen.Content.MediaContent
+{
+    /// <summary>
+    /// Represents the book information for the media.
+    /// </summary>
+    /// <since_tizen> 9 </since_tizen>
+    public class BookInfo : MediaInfo
+    {
+        internal BookInfo(Interop.MediaInfoHandle handle) : base(handle)
+        {
+            IntPtr bookHandle = IntPtr.Zero;
+
+            try
+            {
+                Interop.MediaInfo.GetBook(handle, out bookHandle).ThrowIfError("Failed to retrieve data");
+
+                Debug.Assert(bookHandle != IntPtr.Zero);
+
+                Subject = InteropHelper.GetString(bookHandle, Interop.BookInfo.GetSubject);
+                Author = InteropHelper.GetString(bookHandle, Interop.BookInfo.GetAuthor);
+                DatePublished = InteropHelper.GetString(bookHandle, Interop.BookInfo.GetDate);
+                Publisher = InteropHelper.GetString(bookHandle, Interop.BookInfo.GetPublisher);
+            }
+            finally
+            {
+                Interop.BookInfo.Destroy(bookHandle).ThrowIfError("Failed to destroy book handle");
+            }
+        }
+
+        /// <summary>
+        /// Gets the subject of the book.
+        /// </summary>
+        /// <value>The subject.</value>
+        /// <since_tizen> 9 </since_tizen>
+        public string Subject { get; }
+
+        /// <summary>
+        /// Gets the author of the book.
+        /// </summary>
+        /// <value>The author.</value>
+        /// <since_tizen> 9 </since_tizen>
+        public string Author { get; }
+
+        /// <summary>
+        /// Gets the published date, formatted as a string.
+        /// </summary>
+        /// <value>The published date.</value>
+        /// <since_tizen> 9 </since_tizen>
+        public string DatePublished { get; }
+
+        /// <summary>
+        /// Gets the publisher of the book.
+        /// </summary>
+        /// <value>The publisher.</value>
+        /// <since_tizen> 9 </since_tizen>
+        public string Publisher { get; }
+    }
+}
index 5a5e19c..ea4bad1 100644 (file)
@@ -122,7 +122,14 @@ namespace Tizen.Content.MediaContent
         /// <summary>
         /// The type of other.
         /// </summary>
-        Other = 4
+        Other = 4,
+
+        /// <summary>
+        /// The type of book.
+        /// </summary>
+        /// <seealso cref="BookInfo"/>
+        /// <since_tizen> 9 </since_tizen>
+        Book = 5
     }
 
     /// <summary>
index c8301ad..1ad0158 100644 (file)
@@ -233,6 +233,9 @@ namespace Tizen.Content.MediaContent
 
                 case MediaType.Video:
                     return new VideoInfo(handle);
+
+                case MediaType.Book:
+                    return new BookInfo(handle);
             }
 
             return new MediaInfo(handle);
index 38f7d93..33e6891 100644 (file)
@@ -18,6 +18,7 @@ using System;
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
+using System.Runtime.InteropServices;
 using System.Threading;
 using System.Threading.Tasks;
 using Tizen.System;
@@ -472,6 +473,54 @@ namespace Tizen.Content.MediaContent
         }
 
         /// <summary>
+        /// Retrieves all matched ebook paths with given <paramref name="keyword"/>.
+        /// </summary>
+        /// <privilege>http://tizen.org/privilege/mediastorage</privilege>
+        /// <privilege>http://tizen.org/privilege/externalstorage</privilege>
+        /// <param name="keyword">The keyword to search.</param>
+        /// <returns>A list of ebook paths which contain <paramref name="keyword"/>.</returns>
+        /// <exception cref="ArgumentNullException"><paramref name="keyword"/> is null.</exception>
+        /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
+        /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception>
+        /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
+        /// <exception cref="UnauthorizedAccessException">The caller has no required privilege.</exception>
+        /// <since_tizen> 9 </since_tizen>
+        public MediaDataReader<string> SelectEbookPath(string keyword)
+        {
+            ValidateDatabase();
+
+            IntPtr path = IntPtr.Zero;
+            uint length = 0;
+
+            ValidationUtil.ValidateNotNullOrEmpty(keyword, nameof(keyword));
+
+            try
+            {
+                Interop.BookInfo.GetPathByKeyword(keyword, out path, out length).
+                    ThrowIfError("Failed to get path by keyword");
+
+                var list = new List<string>();
+                var current = path;
+                for (int i = 0; i < length; i++)
+                {
+                    list.Add(Marshal.PtrToStringAnsi(Marshal.ReadIntPtr(current)));
+                    current = (IntPtr)((long)current + Marshal.SizeOf(typeof(IntPtr)));
+                }
+
+                return new MediaDataReader<string>(list);
+            }
+            finally
+            {
+                var current = path;
+                for (int i = 0; i < length; i++)
+                {
+                    Tizen.Multimedia.LibcSupport.Free(Marshal.ReadIntPtr(current));
+                    current = (IntPtr)((long)current + Marshal.SizeOf(typeof(IntPtr)));
+                }
+            }
+        }
+
+        /// <summary>
         /// Deletes the media from the database.
         /// </summary>
         /// <privilege>http://tizen.org/privilege/content.write</privilege>
index 37a6060..51179d6 100644 (file)
@@ -19,6 +19,8 @@
 
 using System.Runtime.CompilerServices;
 
+[assembly: InternalsVisibleTo("Tizen.Content.MediaContent, " + PublicKey.Value)]
+
 [assembly: InternalsVisibleTo("Tizen.Multimedia.AudioIO, " + PublicKey.Value)]
 
 [assembly: InternalsVisibleTo("Tizen.Multimedia.Camera, " + PublicKey.Value)]