[easytag/wip/taglib-mp4-cxx] Clean up GIO TagLib wrapper



commit ecacb00b57cbd524bbda7aeaadecfa9d420019fe
Author: David King <amigadave amigadave com>
Date:   Fri Apr 11 08:41:05 2014 +0100

    Clean up GIO TagLib wrapper

 src/gio_wrapper.cc |  203 ++++++++++++++++++++++++++++++++--------------------
 src/gio_wrapper.h  |    8 +-
 2 files changed, 128 insertions(+), 83 deletions(-)
---
diff --git a/src/gio_wrapper.cc b/src/gio_wrapper.cc
index 826a978..db18305 100644
--- a/src/gio_wrapper.cc
+++ b/src/gio_wrapper.cc
@@ -1,5 +1,5 @@
 /*
- *  EasyTAG - Tag editor for MP3 and Ogg Vorbis files
+ *  EasyTAG - Tag editor for audio files
  *  Copyright (C) 2014  Santtu Lakkala <inz inz fi>
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -33,77 +33,90 @@ GIO_InputStream::~GIO_InputStream ()
     g_object_unref (G_OBJECT (file));
 }
 
-TagLib::FileName GIO_InputStream::name () const
+TagLib::FileName
+GIO_InputStream::name () const
 {
     return TagLib::FileName (filename);
 }
 
-TagLib::ByteVector GIO_InputStream::readBlock (ulong length)
+TagLib::ByteVector
+GIO_InputStream::readBlock (ulong length)
 {
     TagLib::ByteVector rv (length, 0);
     rv = rv.mid (0, g_input_stream_read (G_INPUT_STREAM (stream),
-                                         (void *)rv.data (), length,
-                                         NULL, NULL));
+                                         (void *)rv.data (), length, NULL,
+                                         NULL));
 
     return rv;
 }
 
-void GIO_InputStream::writeBlock (TagLib::ByteVector const &data)
+void
+GIO_InputStream::writeBlock (TagLib::ByteVector const &data)
 {
-    g_warning ("Trying to write to read-only file!");
+    g_warning ("%s", "Trying to write to read-only file!");
 }
 
-void GIO_InputStream::insert (TagLib::ByteVector const &data, ulong start, ulong replace)
+void
+GIO_InputStream::insert (TagLib::ByteVector const &data, ulong start, ulong replace)
 {
-    g_warning ("Trying to write to read-only file!");
+    g_warning ("%s", "Trying to write to read-only file!");
 }
 
-void GIO_InputStream::removeBlock (ulong start, ulong length)
+void
+GIO_InputStream::removeBlock (ulong start, ulong length)
 {
-    g_warning ("Trying to write to read-only file!");
+    g_warning ("%s", "Trying to write to read-only file!");
 }
 
-bool GIO_InputStream::readOnly () const
+bool
+GIO_InputStream::readOnly () const
 {
     return true;
 }
 
-bool GIO_InputStream::isOpen () const
+bool
+GIO_InputStream::isOpen () const
 {
     return !!stream;
 }
 
-void GIO_InputStream::seek (long int offset, TagLib::IOStream::Position p)
+void
+GIO_InputStream::seek (long int offset, TagLib::IOStream::Position p)
 {
     GSeekType type;
-    switch (p) {
-    case TagLib::IOStream::Beginning:
-        type = G_SEEK_SET;
-        break;
-    case TagLib::IOStream::Current:
-        type = G_SEEK_CUR;
-        break;
-    case TagLib::IOStream::End:
-        type = G_SEEK_END;
-        break;
-    default:
-        g_warning ("Unknown seek");
-        return;
+
+    switch (p)
+    {
+        case TagLib::IOStream::Beginning:
+            type = G_SEEK_SET;
+            break;
+        case TagLib::IOStream::Current:
+            type = G_SEEK_CUR;
+            break;
+        case TagLib::IOStream::End:
+            type = G_SEEK_END;
+            break;
+        default:
+            g_warning ("Unknown seek");
+            return;
     }
 
     g_seekable_seek (G_SEEKABLE (stream), offset, type, NULL, NULL);
 }
 
-void GIO_InputStream::clear ()
+void
+GIO_InputStream::clear ()
 {
 }
 
-long int GIO_InputStream::tell () const
+long int
+GIO_InputStream::tell () const
 {
     return g_seekable_tell (G_SEEKABLE (stream));
 }
 
-long int GIO_InputStream::length ()
+long int
+GIO_InputStream::length ()
 {
     long rv;
     GFileInfo *info = g_file_input_stream_query_info (stream,
@@ -115,7 +128,8 @@ long int GIO_InputStream::length ()
     return rv;
 }
 
-void GIO_InputStream::truncate (long int length)
+void
+GIO_InputStream::truncate (long int length)
 {
     g_warning ("Trying to truncate read-only file");
 }
@@ -134,30 +148,34 @@ GIO_IOStream::~GIO_IOStream ()
     g_object_unref (G_OBJECT (file));
 }
 
-TagLib::FileName GIO_IOStream::name () const
+TagLib::FileName
+GIO_IOStream::name () const
 {
     return TagLib::FileName (filename);
 }
 
-TagLib::ByteVector GIO_IOStream::readBlock (ulong length)
+TagLib::ByteVector
+GIO_IOStream::readBlock (ulong length)
 {
     TagLib::ByteVector rv (length, 0);
     GInputStream *istream = g_io_stream_get_input_stream (G_IO_STREAM (stream));
-    rv = rv.mid (0, g_input_stream_read (istream,
-                                         (void *)rv.data (), length,
+    rv = rv.mid (0, g_input_stream_read (istream, (void *)rv.data (), length,
                                          NULL, NULL));
 
     return rv;
 }
 
-void GIO_IOStream::writeBlock (TagLib::ByteVector const &data)
+void
+GIO_IOStream::writeBlock (TagLib::ByteVector const &data)
 {
     GOutputStream *ostream = g_io_stream_get_output_stream (G_IO_STREAM (stream));
-    g_output_stream_write (ostream, data.data (), data.size (),
-                           NULL, NULL);
+    g_output_stream_write (ostream, data.data (), data.size (), NULL, NULL);
 }
 
-void GIO_IOStream::insert (TagLib::ByteVector const &data, ulong start, ulong replace)
+void
+GIO_IOStream::insert (TagLib::ByteVector const &data,
+                      ulong start,
+                      ulong replace)
 {
     if (data.size () == replace)
     {
@@ -174,34 +192,43 @@ void GIO_IOStream::insert (TagLib::ByteVector const &data, ulong start, ulong re
     }
 
     GFileIOStream *tstr;
-    GFile *tmp = g_file_new_tmp("easytag-XXXXXX", &tstr, NULL);
+    GFile *tmp = g_file_new_tmp ("easytag-XXXXXX", &tstr, NULL);
     char *buffer[4096];
     gsize r;
     GOutputStream *ostream = g_io_stream_get_output_stream (G_IO_STREAM (tstr));
     GInputStream *istream = g_io_stream_get_input_stream (G_IO_STREAM (stream));
 
     seek(0);
-    while (g_input_stream_read_all (istream, buffer, MIN(sizeof(buffer), start), &r,
-                                    NULL, NULL) && r > 0)
+
+    while (g_input_stream_read_all (istream, buffer,
+                                    MIN (sizeof (buffer), start), &r, NULL,
+                                    NULL) && r > 0)
     {
         gsize w;
         g_output_stream_write_all (ostream, buffer, r, &w, NULL, NULL);
+
         if (w != r)
-            g_warning ("Unable to write all bytes");
+        {
+            g_warning ("%s", "Unable to write all bytes");
+        }
+
         start -= r;
-        g_warning("Wrote %lu bytees of %lu: %.*s", r, start, (int)r, buffer);
+        g_warning ("Wrote %lu bytees of %lu: %.*s", r, start, (int)r, buffer);
     }
 
-    g_output_stream_write (ostream, data.data (), data.size (),
-                           NULL, NULL);
-    seek(replace, TagLib::IOStream::Current);
-    while (g_input_stream_read_all (istream, buffer, sizeof(buffer), &r,
+    g_output_stream_write (ostream, data.data (), data.size (), NULL, NULL);
+    seek (replace, TagLib::IOStream::Current);
+
+    while (g_input_stream_read_all (istream, buffer, sizeof (buffer), &r,
                                     NULL, NULL) && r > 0)
     {
         gsize w;
         g_output_stream_write_all (ostream, buffer, r, &w, NULL, NULL);
+
         if (w != r)
-            g_warning ("Unable to write all bytes");
+        {
+            g_warning ("%s", "Unable to write all bytes");
+        }
     }
 
     g_io_stream_close (G_IO_STREAM (tstr), NULL, NULL);
@@ -211,10 +238,12 @@ void GIO_IOStream::insert (TagLib::ByteVector const &data, ulong start, ulong re
     stream = g_file_open_readwrite (file, NULL, NULL);
 }
 
-void GIO_IOStream::removeBlock (ulong start, ulong len)
+void
+GIO_IOStream::removeBlock (ulong start, ulong len)
 {
-    if (start + len >= (ulong)length()) {
-        truncate(start);
+    if (start + len >= (ulong)length ())
+    {
+        truncate (start);
         return;
     }
 
@@ -222,61 +251,76 @@ void GIO_IOStream::removeBlock (ulong start, ulong len)
     gsize r;
     GInputStream *istream = g_io_stream_get_input_stream (G_IO_STREAM (stream));
     GOutputStream *ostream = g_io_stream_get_output_stream (G_IO_STREAM (stream));
-    seek(start + len);
-    while (g_input_stream_read_all (istream, buffer, sizeof(buffer), &r,
-                                    NULL, NULL) && r > 0) {
+    seek (start + len);
+
+    while (g_input_stream_read_all (istream, buffer, sizeof (buffer), &r, NULL,
+                                    NULL) && r > 0)
+    {
         gsize w;
-        seek(start);
+        seek (start);
         g_output_stream_write_all (ostream, buffer, r, &w, NULL, NULL);
+
         if (w != r)
-            g_warning("Unable to write all bytes");
+        {
+            g_warning ("%s", "Unable to write all bytes");
+        }
+
         start += r;
-        seek(start + len);
+        seek (start + len);
     }
-    truncate(start);
+
+    truncate (start);
 }
 
-bool GIO_IOStream::readOnly () const
+bool
+GIO_IOStream::readOnly () const
 {
     return !stream;
 }
 
-bool GIO_IOStream::isOpen () const
+bool
+GIO_IOStream::isOpen () const
 {
     return !!stream;
 }
 
-void GIO_IOStream::seek (long int offset, TagLib::IOStream::Position p)
+void
+GIO_IOStream::seek (long int offset, TagLib::IOStream::Position p)
 {
     GSeekType type;
-    switch (p) {
-    case TagLib::IOStream::Beginning:
-        type = G_SEEK_SET;
-        break;
-    case TagLib::IOStream::Current:
-        type = G_SEEK_CUR;
-        break;
-    case TagLib::IOStream::End:
-        type = G_SEEK_END;
-        break;
-    default:
-        g_warning ("Unknown seek");
-        return;
+
+    switch (p)
+    {
+        case TagLib::IOStream::Beginning:
+            type = G_SEEK_SET;
+            break;
+        case TagLib::IOStream::Current:
+            type = G_SEEK_CUR;
+            break;
+        case TagLib::IOStream::End:
+            type = G_SEEK_END;
+            break;
+        default:
+            g_warning ("Unknown seek");
+            return;
     }
 
     g_seekable_seek (G_SEEKABLE (stream), offset, type, NULL, NULL);
 }
 
-void GIO_IOStream::clear ()
+void
+GIO_IOStream::clear ()
 {
 }
 
-long int GIO_IOStream::tell () const
+long int
+GIO_IOStream::tell () const
 {
     return g_seekable_tell (G_SEEKABLE (stream));
 }
 
-long int GIO_IOStream::length ()
+long int
+GIO_IOStream::length ()
 {
     long rv;
     GFileInfo *info = g_file_io_stream_query_info (stream,
@@ -288,7 +332,8 @@ long int GIO_IOStream::length ()
     return rv;
 }
 
-void GIO_IOStream::truncate (long int length)
+void
+GIO_IOStream::truncate (long int length)
 {
     g_seekable_truncate (G_SEEKABLE (stream), length, NULL, NULL);
 }
diff --git a/src/gio_wrapper.h b/src/gio_wrapper.h
index c9ac088..d6f1b76 100644
--- a/src/gio_wrapper.h
+++ b/src/gio_wrapper.h
@@ -1,5 +1,5 @@
 /*
- *  EasyTAG - Tag editor for MP3 and Ogg Vorbis files
+ *  EasyTAG - Tag editor for audio files
  *  Copyright (C) 2014  Santtu Lakkala <inz inz fi>
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -17,8 +17,8 @@
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#ifndef GIO_WRAPPER_H
-#define GIO_WRAPPER_H
+#ifndef ET_GIO_WRAPPER_H_
+#define ET_GIO_WRAPPER_H_
 
 #include <tiostream.h>
 #include <gio/gio.h>
@@ -73,4 +73,4 @@ private:
     char *filename;
 };
 
-#endif
+#endif /* ET_GIO_WRAPPER_H_ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]