Revision: 1937
          http://gtkpod.svn.sourceforge.net/gtkpod/?rev=1937&view=rev
Author:   tiffman
Date:     2008-01-26 08:10:27 -0800 (Sat, 26 Jan 2008)

Log Message:
-----------
src/itdb_chapterdata.c: file missed being added in previous checkin

Modified Paths:
--------------
    libgpod/trunk/ChangeLog

Added Paths:
-----------
    libgpod/trunk/src/itdb_chapterdata.c

Modified: libgpod/trunk/ChangeLog
===================================================================
--- libgpod/trunk/ChangeLog     2008-01-26 08:54:48 UTC (rev 1936)
+++ libgpod/trunk/ChangeLog     2008-01-26 16:10:27 UTC (rev 1937)
@@ -1,5 +1,10 @@
-2007-11-17  Jorg Schuler <jcsjcs at users.sourceforge.net>
+2008-01-26  Michael Tiffany <tiffman at users.sourceforge.net>
 
+        * src/itdb_chapterdata.c: file missed being added in
+       previous checkin
+
+2008-01-26  Jorg Schuler <jcsjcs at users.sourceforge.net>
+
         * src/itdb_track.c
        * src/itdb_itunesdb.c
        * src/itdb_chapterdata

Added: libgpod/trunk/src/itdb_chapterdata.c
===================================================================
--- libgpod/trunk/src/itdb_chapterdata.c                                (rev 0)
+++ libgpod/trunk/src/itdb_chapterdata.c        2008-01-26 16:10:27 UTC (rev 
1937)
@@ -0,0 +1,233 @@
+/* Time-stamp: <2007-03-21 17:30:57 jcs>
+|
+|  Copyright (C) 2002-2007 Jorg Schuler <jcsjcs at users sourceforge net>
+|  Part of the gtkpod project.
+| 
+|  URL: http://www.gtkpod.org/
+|  URL: http://gtkpod.sourceforge.net/
+|
+|  The code contained in this file is free software; you can redistribute
+|  it and/or modify it under the terms of the GNU Lesser General Public
+|  License as published by the Free Software Foundation; either version
+|  2.1 of the License, or (at your option) any later version.
+|
+|  This file is distributed in the hope that it will be useful,
+|  but WITHOUT ANY WARRANTY; without even the implied warranty of
+|  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+|  Lesser General Public License for more details.
+|
+|  You should have received a copy of the GNU Lesser General Public
+|  License along with this code; if not, write to the Free Software
+|  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+|
+|  iTunes and iPod are trademarks of Apple
+|
+|  This product is not supported/written/published by Apple!
+|
+|  $Id: itdb_chapterdata.c 1612 2007-06-29 16:02:00Z jcsjcs $
+*/
+
+#include <config.h>
+
+#include "itdb_device.h"
+#include "itdb_private.h"
+#include "itdb_endianness.h"
+#include <stdio.h>
+#include <string.h>
+#include <glib/gi18n-lib.h>
+
+
+/**
+ * itdb_chapterdata_new:
+ * 
+ * Creates a new #Itdb_Chapterdata 
+ *
+ * Return value: a new #Itdb_Chapterdata to be freed with 
itdb_chapterdata_free() when
+ * no longer needed
+ **/
+Itdb_Chapterdata *itdb_chapterdata_new (void)
+{
+    Itdb_Chapterdata *chapterdata = g_new0 (Itdb_Chapterdata, 1);
+    return chapterdata;
+}
+
+/**
+ * itdb_chapterdata_free:
+ * @chapterdata: an #Itdb_Chapterdata
+ *
+ * Frees memory used by @chapterdata
+ **/
+void itdb_chapterdata_free (Itdb_Chapterdata *chapterdata)
+{
+    g_return_if_fail (chapterdata);
+    itdb_chapterdata_remove_chapters (chapterdata);
+    g_free (chapterdata);
+}
+
+static GList *dup_chapters (GList *chapters)
+{
+    GList *it;
+    GList *result;
+    
+    g_return_val_if_fail (chapters, NULL);
+    result = NULL;
+    for (it = chapters; it != NULL; it = it->next)
+    {
+       Itdb_Chapter *new_chapter;
+       Itdb_Chapter *chapter;
+
+       chapter = (Itdb_Chapter *)(it->data);
+       g_return_val_if_fail (chapter, NULL);
+
+       new_chapter = itdb_chapter_duplicate (chapter);
+       
+       result = g_list_prepend (result, new_chapter);
+    }
+
+    return g_list_reverse (result);
+}
+
+/**
+ * itdb_chapterdata_duplicate:
+ * @chapterdata: an #Itdb_Chapterdata
+ *
+ * Duplicates @chapterdata
+ *
+ * Return value: a new copy of @chapterdata
+ **/
+Itdb_Chapterdata *itdb_chapterdata_duplicate (Itdb_Chapterdata *chapterdata)
+{
+    Itdb_Chapterdata *dup;
+    int numchapters;
+    g_return_val_if_fail (chapterdata, NULL);
+
+    dup = g_new0 (Itdb_Chapterdata, 1);
+
+    memcpy (dup, chapterdata, sizeof (Itdb_Chapterdata));
+
+    numchapters = g_list_length (chapterdata->chapters);
+    if (chapterdata->chapters)
+       dup->chapters = dup_chapters (chapterdata->chapters);
+    else
+       dup->chapters = NULL;
+
+    return dup;
+}
+
+/**
+ * itdb_chapterdata_remove_chapter:
+ * @chapterdata: an #Itdb_Chapterdata
+ * @chapeer: an #Itdb_Chapter
+ *
+ * Removes @chapter from @chapterdata. The memory used by @chapter is freed.
+ **/
+void
+itdb_chapterdata_remove_chapter (Itdb_Chapterdata *chapterdata, Itdb_Chapter 
*chapter)
+{
+    g_return_if_fail (chapterdata);
+    g_return_if_fail (chapter);
+
+    chapterdata->chapters = g_list_remove (chapterdata->chapters, chapter);
+    itdb_chapter_free (chapter);
+}
+
+/**
+ * itdb_chapterdata_remove_chapters:
+ * @chapterdata: an #Itdb_Chapterdata
+ *
+ * Removes all chapters from @chapterdata 
+ **/
+void
+itdb_chapterdata_remove_chapters (Itdb_Chapterdata *chapterdata)
+{
+    g_return_if_fail (chapterdata);
+
+    while (chapterdata->chapters)
+    {
+       Itdb_Chapter *chapter = chapterdata->chapters->data;
+       g_return_if_fail (chapter);
+       itdb_chapterdata_remove_chapter (chapterdata, chapter);
+    }
+}
+
+/**
+ * itdb_chapter_new:
+ * 
+ * Creates a new #Itdb_Chapter
+ *
+ * Return Value: newly allocated #Itdb_Chapter to be freed with 
itdb_chapter_free()
+ * after use
+ **/
+Itdb_Chapter *itdb_chapter_new (void)
+{
+    Itdb_Chapter *chapter = g_new0 (Itdb_Chapter, 1);
+    return chapter;
+}
+
+/** 
+ * itdb_chapter_free:
+ * @chapter: an #Itdb_Chapter
+ *
+ * Frees the memory used by @chapter
+ **/
+void itdb_chapter_free (Itdb_Chapter *chapter)
+{
+    g_return_if_fail (chapter);
+
+    g_free (chapter->chaptertitle);
+    g_free (chapter);
+}
+
+/** 
+ * itdb_chapter_duplicate:
+ * @chapter: an #Itdb_Chapter
+ *
+ * Duplicates the data contained in @chapter
+ *
+ * Return value: a newly allocated copy of @chapter to be freed with 
+ * itdb_chapter_free() after use
+ **/
+Itdb_Chapter *itdb_chapter_duplicate (Itdb_Chapter *chapter)
+{
+    Itdb_Chapter *new_chapter;
+
+    g_return_val_if_fail (chapter, NULL);
+
+    new_chapter = itdb_chapter_new ();
+    memcpy (new_chapter, chapter, sizeof (Itdb_Chapter));
+    new_chapter->chaptertitle = g_strdup (chapter->chaptertitle);
+ 
+    return new_chapter;
+}
+
+/**
+ * itdb_chapterdata_add_chapter
+ * @chapterdata: an #Itdb_Chapterdata
+ * @startpos: chapter start time in milliseconds
+ * @chaptertitle: chapter title
+ *
+ * Appends a chapter to existing chapters in @chapterdata.
+ *
+ * Return value: TRUE if the chapter could be successfully added, FALSE
+ * otherwise.
+ **/
+gboolean
+itdb_chapterdata_add_chapter (Itdb_Chapterdata *chapterdata,
+                             gint32 startpos,
+                             gchar *chaptertitle)
+{
+    Itdb_Chapter *chapter;
+
+    g_return_val_if_fail (chapterdata, FALSE);
+    g_return_val_if_fail (chaptertitle, FALSE);
+
+    chapter = itdb_chapter_new ();
+    if (startpos == 0)
+       chapter->startpos = 1; /* first chapter should have startpos of 1 */
+    else
+       chapter->startpos = startpos;
+    chapter->chaptertitle = g_strdup (chaptertitle);
+    chapterdata->chapters = g_list_append (chapterdata->chapters, chapter);
+
+    return TRUE;
+}


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
gtkpod-cvs2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2

Reply via email to