[easytag/wip/musicbrainz-dialog: 2/2] Add skeleton MusicBrainz query context



commit 78a42b0299894b2538d569a6f07b2bba81eeca3c
Author: David King <amigadave amigadave com>
Date:   Sun Nov 2 22:27:37 2014 +0000

    Add skeleton MusicBrainz query context

 Makefile.am              |    3 +
 README                   |    3 +-
 configure.ac             |   20 +++++++++-
 src/musicbrainz.c        |   93 ++++++++++++++++++++++++++++++++++++++++++++++
 src/musicbrainz.h        |   57 ++++++++++++++++++++++++++++
 src/musicbrainz_dialog.c |   37 +++++++++++++++++-
 src/musicbrainz_dialog.h |    6 +++
 7 files changed, 214 insertions(+), 5 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 4a71d28..94064bf 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -9,6 +9,7 @@ DISTCHECK_CONFIGURE_FLAGS = \
        --enable-man \
        --enable-mp3 \
        --enable-mp4 \
+       --enable-musicbrainz \
        --enable-nautilus-actions \
        --enable-speex \
        --enable-tests \
@@ -54,6 +55,7 @@ easytag_SOURCES = \
        src/log.c \
        src/main.c \
        src/misc.c \
+       src/musicbrainz.c \
        src/musicbrainz_dialog.c \
        src/picture.c \
        src/playlist_dialog.c \
@@ -107,6 +109,7 @@ easytag_headers = \
        src/load_files_dialog.h \
        src/log.h \
        src/misc.h \
+       src/musicbrainz.h \
        src/musicbrainz_dialog.h \
        src/picture.h \
        src/playlist_dialog.h \
diff --git a/README b/README
index 67448f9..1b56878 100644
--- a/README
+++ b/README
@@ -63,7 +63,8 @@ Installation
 * id3lib version greater than 3.7.12 (http://id3lib.sourceforge.net) (Recommended: id3lib-3.8.3) (if not 
deactivated by './configure --disable-id3v23')
 * flac (http://flac.sourceforge.net) (if not deactivated by './configure --disable-flac')
 * libogg and libvorbis (http://www.vorbis.com) (if not deactivated by './configure --disable-ogg')
-* libnautilus-extension (https://wiki.gnome.org/Apps/Nautilus) (if not deactivated by ./configure 
--disable-nautilus-actions')
+* libnautilus-extension (https://wiki.gnome.org/Apps/Nautilus) (if not deactivated by './configure 
--disable-nautilus-actions')
+* musicbrainz5 (https://wiki.musicbrainz.org/libmusicbrainz) (if not deactivated by './configure 
--disable-musicbrainz')
 * opus and opusfile (http://www.opus-codec.org/) (if not deactivated by './configure --disable-opus')
 * taglib (http://taglib.github.com/) (if not deactivated by './configure --disable-mp4')
 * wavpack (http://www.wavpack.com/) (if not deactivated by './configure --disable-wavpack')
diff --git a/configure.ac b/configure.ac
index acb37fc..865842f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -159,6 +159,8 @@ AC_ARG_ENABLE([wavpack],
 AC_ARG_ENABLE([nautilus_actions],
               [AS_HELP_STRING([--disable-nautilus-actions], [do not build the nautilus context menu actions 
(default=auto)])])
 
+AC_ARG_ENABLE([musicbrainz],
+              [AS_HELP_STRING([--disable-musicbrainz], [do not build MusicBrainz query support 
(default=auto)])])
 
 
 dnl -------------------------------
@@ -326,12 +328,27 @@ AS_IF([test "x$have_libnautilus_extension" = "xno"],
 
 AM_CONDITIONAL([ENABLE_NAUTILUS_ACTIONS], [test x"$have_libnautilus_extension" != x"no"])
 
+dnl ################################################
+dnl # MusicBrainz
+dnl ################################################
+dnl libmusicbrainz5
+MUSICBRAINZ_DEPS="libmusicbrainz5 >= 5.0"
+AS_IF([test "x$enable_musicbrainz" != "xno"],
+      [PKG_CHECK_EXISTS([$MUSICBRAINZ_DEPS], [have_musicbrainz=yes], [have_musicbrainz=no])],
+      [have_musicbrainz=no])
+
+AS_IF([test "x$have_musicbrainz" != "xno"],
+      [AC_DEFINE([ENABLE_MUSICBRAINZ], [], [Define for MusicBrainz support])],
+      [MUSICBRAINZ_DEPS=""
+       AS_IF([test "x$enable_musicbrainz" = "xyes"],
+             [AC_MSG_ERROR([musicbrainz support requested but required dependencies ($MUSICBRAINZ_DEPS) not 
found])])])
+
 dnl Check the pkg-config dependencies
 GIO_DEPS="gio-2.0 >= 2.32.0" dnl For g_file_new_tmp()
 GLIB_DEPRECATION_FLAGS="-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_32 
-DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_32"
 GTK_DEPS="gtk+-3.0 >= 3.4.0"
 GTK_DEPRECATION_FLAGS="-DGDK_VERSION_MIN_REQUIRED=GDK_VERSION_3_4 -DGDK_VERSION_MAX_ALLOWED=GDK_VERSION_3_4"
-PKG_CHECK_MODULES([EASYTAG], [$GIO_DEPS $GTK_DEPS $OPUS_DEPS $OGG_DEPS $SPEEX_DEPS $FLAC_DEPS $ID3TAG_DEPS 
$TAGLIB_DEPS $WAVPACK_DEPS])
+PKG_CHECK_MODULES([EASYTAG], [$GIO_DEPS $GTK_DEPS $OPUS_DEPS $OGG_DEPS $SPEEX_DEPS $FLAC_DEPS $ID3TAG_DEPS 
$TAGLIB_DEPS $MUSICBRAINZ_DEPS $WAVPACK_DEPS])
 
 dnl Check for winsock
 AC_SEARCH_LIBS([gethostbyname], [nsl socket], [],
@@ -421,6 +438,7 @@ echo FLAC file support .......: $have_flac
 echo MP4 file support ........: $have_taglib
 echo WavPack support .........: $have_wavpack
 echo NLS/gettext .............: $USE_NLS
+echo MusicBrainz search ......: $have_musicbrainz
 echo Nautilus actions ........: $have_libnautilus_extension
 echo Tests during make check .: $testing_utilities
 echo Install prefix ..........: $prefix
diff --git a/src/musicbrainz.c b/src/musicbrainz.c
new file mode 100644
index 0000000..133c841
--- /dev/null
+++ b/src/musicbrainz.c
@@ -0,0 +1,93 @@
+/* EasyTAG - tag editor for audio files
+ * Copyright (C) 2014  David King <amigadave amigadave com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program 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 General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 51
+ * Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include "config.h"
+
+#ifdef ENABLE_MUSICBRAINZ
+
+#include "musicbrainz.h"
+
+#include <glib/gi18n.h>
+#include <musicbrainz5/mb5_c.h>
+
+/* TODO: Use G_DEFINE_TYPE_WITH_PRIVATE. */
+G_DEFINE_TYPE (EtMusicbrainz, et_musicbrainz, G_TYPE_OBJECT)
+
+#define et_musicbrainz_get_instance_private(musicbrainz) (musicbrainz->priv)
+
+struct _EtMusicbrainzPrivate
+{
+    Mb5Query query;
+};
+
+static void
+et_musicbrainz_finalize (GObject *object)
+{
+    EtMusicbrainz *self;
+    EtMusicbrainzPrivate *priv;
+
+    self = ET_MUSICBRAINZ (object);
+    priv = et_musicbrainz_get_instance_private (self);
+
+    if (priv->query)
+    {
+        mb5_query_delete (priv->query);
+        priv->query = NULL;
+    }
+
+    G_OBJECT_CLASS (et_musicbrainz_parent_class)->finalize (object);
+}
+
+static void
+et_musicbrainz_init (EtMusicbrainz *self)
+{
+    EtMusicbrainzPrivate *priv;
+
+    priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, ET_TYPE_MUSICBRAINZ,
+                                                     EtMusicbrainzPrivate);
+
+    priv->query = mb5_query_new (PACKAGE_NAME "/" PACKAGE_VERSION " ( "
+                                 PACKAGE_URL " )", NULL, 0);
+}
+
+static void
+et_musicbrainz_class_init (EtMusicbrainzClass *klass)
+{
+    GObjectClass *gobject_class;
+
+    gobject_class = G_OBJECT_CLASS (klass);
+
+    gobject_class->finalize = et_musicbrainz_finalize;
+
+    g_type_class_add_private (klass, sizeof (EtMusicbrainzPrivate));
+}
+
+/*
+ * et_musicbrainz_dialog_new:
+ *
+ * Create a new EtMusicbrainz instance.
+ *
+ * Returns: a new #EtMusicbrainz
+ */
+EtMusicbrainz *
+et_musicbrainz_new (void)
+{
+    return g_object_new (ET_TYPE_MUSICBRAINZ, NULL);
+}
+
+#endif /* ENABLE_MUSICBRAINZ */
diff --git a/src/musicbrainz.h b/src/musicbrainz.h
new file mode 100644
index 0000000..4cab216
--- /dev/null
+++ b/src/musicbrainz.h
@@ -0,0 +1,57 @@
+/* EasyTAG - tag editor for audio files
+ * Copyright (C) 2014  David King <amigadave amigadave com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program 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 General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 51
+ * Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#ifndef ET_MUSICBRAINZ_H_
+#define ET_MUSICBRAINZ_H_
+
+#include "config.h"
+
+#ifdef ENABLE_MUSICBRAINZ
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define ET_TYPE_MUSICBRAINZ (et_musicbrainz_get_type ())
+#define ET_MUSICBRAINZ(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), ET_TYPE_MUSICBRAINZ, EtMusicbrainz))
+
+typedef struct _EtMusicbrainz EtMusicbrainz;
+typedef struct _EtMusicbrainzClass EtMusicbrainzClass;
+typedef struct _EtMusicbrainzPrivate EtMusicbrainzPrivate;
+
+struct _EtMusicbrainz
+{
+    /*< private >*/
+    GObject parent_instance;
+    EtMusicbrainzPrivate *priv;
+};
+
+struct _EtMusicbrainzClass
+{
+    /*< private >*/
+    GObjectClass parent_class;
+};
+
+GType et_musicbrainz_get_type (void);
+EtMusicbrainz *et_musicbrainz_new (void);
+
+G_END_DECLS
+
+#endif /* ENABLE_MUSICBRAINZ */
+
+#endif /* !ET_MUSICBRAINZ_H_ */
diff --git a/src/musicbrainz_dialog.c b/src/musicbrainz_dialog.c
index 1ecc1aa..5fe7144 100644
--- a/src/musicbrainz_dialog.c
+++ b/src/musicbrainz_dialog.c
@@ -19,10 +19,14 @@
 
 #include "config.h"
 
+#ifdef ENABLE_MUSICBRAINZ
+
 #include "musicbrainz_dialog.h"
 
 #include <glib/gi18n.h>
 
+#include "musicbrainz.h"
+
 /* TODO: Use G_DEFINE_TYPE_WITH_PRIVATE. */
 G_DEFINE_TYPE (EtMusicbrainzDialog, et_musicbrainz_dialog, GTK_TYPE_DIALOG)
 
@@ -32,7 +36,7 @@ static guint BOX_SPACING = 6;
 
 struct _EtMusicbrainzDialogPrivate
 {
-    gpointer unused;
+    EtMusicbrainz *mb;
 };
 
 static void
@@ -74,10 +78,29 @@ create_musicbrainz_dialog (EtMusicbrainzDialog *self)
 }
 
 static void
+et_musicbrainz_dialog_finalize (GObject *object)
+{
+    EtMusicbrainzDialog *self;
+    EtMusicbrainzDialogPrivate *priv;
+
+    self = ET_MUSICBRAINZ_DIALOG (object);
+    priv = et_musicbrainz_dialog_get_instance_private (self);
+
+    g_clear_object (&priv->mb);
+
+    G_OBJECT_CLASS (et_musicbrainz_dialog_parent_class)->finalize (object);
+}
+
+static void
 et_musicbrainz_dialog_init (EtMusicbrainzDialog *self)
 {
-    self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, ET_TYPE_MUSICBRAINZ_DIALOG,
-                                              EtMusicbrainzDialogPrivate);
+    EtMusicbrainzDialogPrivate *priv;
+
+    priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+                                                     ET_TYPE_MUSICBRAINZ_DIALOG,
+                                                     EtMusicbrainzDialogPrivate);
+
+    priv->mb = et_musicbrainz_new ();
 
     create_musicbrainz_dialog (self);
 }
@@ -85,6 +108,12 @@ et_musicbrainz_dialog_init (EtMusicbrainzDialog *self)
 static void
 et_musicbrainz_dialog_class_init (EtMusicbrainzDialogClass *klass)
 {
+    GObjectClass *gobject_class;
+
+    gobject_class = G_OBJECT_CLASS (klass);
+
+    gobject_class->finalize = et_musicbrainz_dialog_finalize;
+
     g_type_class_add_private (klass, sizeof (EtMusicbrainzDialogPrivate));
 }
 
@@ -103,3 +132,5 @@ et_musicbrainz_dialog_new (GtkWindow *parent)
     return g_object_new (ET_TYPE_MUSICBRAINZ_DIALOG, "transient-for", parent,
                          NULL);
 }
+
+#endif /* ENABLE_MUSICBRAINZ */
diff --git a/src/musicbrainz_dialog.h b/src/musicbrainz_dialog.h
index 39dff0c..baf62c1 100644
--- a/src/musicbrainz_dialog.h
+++ b/src/musicbrainz_dialog.h
@@ -20,6 +20,10 @@
 #ifndef ET_MUSICBRAINZ_DIALOG_H_
 #define ET_MUSICBRAINZ_DIALOG_H_
 
+#include "config.h"
+
+#ifdef ENABLE_MUSICBRAINZ
+
 #include <gtk/gtk.h>
 
 G_BEGIN_DECLS
@@ -49,4 +53,6 @@ EtMusicbrainzDialog *et_musicbrainz_dialog_new (GtkWindow *parent);
 
 G_END_DECLS
 
+#endif /* ENABLE_MUSICBRAINZ */
+
 #endif /* !ET_MUSICBRAINZ_DIALOG_H_ */


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