commit b154fc91459ed84daaa570bc5383a8f6dea63717
Author: phantomjinx <[email protected]>
Date: Sun Feb 28 16:12:05 2010 +0000
Patch moving auto detection from hal to gio
- Support for both autotools and cmake
- Thanks to Nikias Bassen for the patch at tracker id: 2960423
- Reviewed and tested successfully with following:
-- ipod nano (1st gen)
-- ipod (5.5 gen)
CMakeLists.txt | 27 ++----
cmake/FindGIO.cmake | 3 +
cmake/FindGnomeVFS.cmake | 3 -
cmake/FindHAL.cmake | 3 -
configure.in | 52 +++-------
src/autodetection.c | 239 +++++++++++----------------------------------
src/display_itdb.c | 4 +-
7 files changed, 88 insertions(+), 243 deletions(-)
---
diff --git a/CMakeLists.txt b/CMakeLists.txt
index cdba280..c8cef0b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -20,8 +20,7 @@ option(USE_CLANG "Use clang instead of gcc to compile" OFF)
option(USE_LOCAL_DATA_FILES
"Use data files in the source directory when running" OFF)
option(WANT_CURL "Enable build with CURL" ON)
-option(WANT_GNOME_VFS "Enable build with GNOME VFS" ON)
-option(WANT_HAL "Enable build with HAL" ON)
+option(WANT_GIO "Enable build with GIO" ON)
option(WANT_LIBVORBISFILE "Enable build with libvorbisfile" ON)
option(WANT_FLAC "Enable build with FLAC" ON)
option(LINK_AS_NEEDED "Link with -Wl,--as-needed" ON)
@@ -58,23 +57,13 @@ if(WANT_CURL)
endif()
endif()
-if(WANT_GNOME_VFS)
- find_package(GnomeVFS)
- if(GNOME_VFS_FOUND)
- set(HAVE_GNOME_VFS 1)
- set(OPT_INCLUDES ${OPT_INCLUDES} ${GNOME_VFS_INCLUDE_DIRS})
- set(OPT_CFLAGS ${OPT_CFLAGS} ${GNOME_VFS_CFLAGS_OTHER})
- set(OPT_LIBS ${OPT_LIBS} ${GNOME_VFS_LDFLAGS})
- endif()
-endif()
-
-if(WANT_HAL)
- find_package(HAL)
- if(HAL_FOUND)
- set(HAVE_HAL 1)
- set(OPT_INCLUDES ${OPT_INCLUDES} ${HAL_INCLUDE_DIRS})
- set(OPT_CFLAGS ${OPT_CFLAGS} ${HAL_CFLAGS_OTHER})
- set(OPT_LIBS ${OPT_LIBS} ${HAL_LDFLAGS})
+if(WANT_GIO)
+ find_package(GIO)
+ if(GIO_FOUND)
+ set(HAVE_GIO 1)
+ set(OPT_INCLUDES ${OPT_INCLUDES} ${GIO_INCLUDE_DIRS})
+ set(OPT_CFLAGS ${OPT_CFLAGS} ${GIO_CFLAGS_OTHER})
+ set(OPT_LIBS ${OPT_LIBS} ${GIO_LDFLAGS})
endif()
endif()
diff --git a/cmake/FindGIO.cmake b/cmake/FindGIO.cmake
new file mode 100644
index 0000000..0d39c14
--- /dev/null
+++ b/cmake/FindGIO.cmake
@@ -0,0 +1,3 @@
+set(GIO_REQUIRED_VERSION 2.15.0)
+message("-- Checking for gio >= ${GIO_REQUIRED_VERSION}...")
+pkg_check_modules(GIO gio-2.0>=${GIO_REQUIRED_VERSION})
diff --git a/configure.in b/configure.in
index 9881d22..00f4200 100644
--- a/configure.in
+++ b/configure.in
@@ -41,7 +41,7 @@ fi
dnl check for required libs that are managed with pkg-config
PKG_CHECK_MODULES(GTK, gtk+-2.0 >= 2.8.0,, [AC_MSG_FAILURE([***
$GTK_PKG_ERRORS])])
-PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.8.0,, [AC_MSG_FAILURE([***
$GLIB_PKG_ERRORS])])
+PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.15.0,, [AC_MSG_FAILURE([***
$GLIB_PKG_ERRORS])])
PKG_CHECK_MODULES(GMODULE, gmodule-2.0,, [AC_MSG_FAILURE([***
$GMODULE_PKG_ERRORS])])
PKG_CHECK_MODULES(GTHREAD, gthread-2.0 >= 0.14.0,, [AC_MSG_FAILURE([***
$GTHREAD_PKG_ERRORS])])
PKG_CHECK_MODULES(LIBGLADE, libglade-2.0 >= 2.4.0,, [AC_MSG_FAILURE([***
$LIBGLADE_PKG_ERRORS])])
@@ -106,42 +106,23 @@ else
have_curl="*no -- will build without coverart download support"
fi
-dnl Check for gnome-vfs
-AC_ARG_WITH(gnome-vfs, AC_HELP_STRING([--without-gnome-vfs],[Disable
autodetection support]))
-if test "x$with_gnome_vfs" != "xno"; then
- PKG_CHECK_MODULES(GNOME_VFS, [gnome-vfs-2.0 >= 2.6.0], have_gnome_vfs=yes,
have_gnome_vfs=no)
- if test "x$with_gnome_vfs" = "xyes" -a "x$have_gnome_vfs" = "xno"; then
- AC_MSG_ERROR([gnome-vfs support explicitly requested but gnome-vfs
couldn't be found])
+dnl Check for gio
+AC_ARG_WITH(gio, AC_HELP_STRING([--without-gio],[Disable autodetection
support]))
+if test "x$with_gio" != "xno"; then
+ PKG_CHECK_MODULES(GIO, [gio-2.0 >= 2.15.0], have_gio=yes, have_gio=no)
+ if test "x$with_gio" = "xyes" -a "x$have_gio" = "xno"; then
+ AC_MSG_ERROR([gio support explicitly requested but gio could not be
found])
fi
fi
-AM_CONDITIONAL(HAVE_GNOME_VFS, test "x$have_gnome_vfs" = "xyes")
-if test "x$have_gnome_vfs" = "xyes"; then
- have_gnome_vfs="yes -- will build with automount support"
- AC_DEFINE(HAVE_GNOME_VFS, 1, [Define if you have gnome-vfs support])
- CPPFLAGS="$CPPFLAGS $GNOME_VFS_CFLAGS"
- CFLAGS="$CFLAGS $GNOME_VFS_CFLAGS"
- LIBS="$LIBS $GNOME_VFS_LIBS"
+AM_CONDITIONAL(HAVE_GIO, test "x$have_gio" = "xyes")
+if test "x$have_gio" = "xyes"; then
+ have_gio="yes -- will build with automount support"
+ AC_DEFINE(HAVE_GIO, 1, [Define if you have gio support])
+ CPPFLAGS="$CPPFLAGS $GIO_CFLAGS"
+ CFLAGS="$CFLAGS $GIO_CFLAGS"
+ LIBS="$LIBS $GIO_LIBS"
else
- have_gnome_vfs="*no -- will build without iPod autodetection support"
-fi
-
-dnl Check for HAL
-AC_ARG_WITH(hal, AC_HELP_STRING([--without-hal],[Disable HAL support]))
-if test "x$with_hal" != "xno"; then
- PKG_CHECK_MODULES(HAL, hal >= 0.5 hal < 0.6, have_hal=yes, have_hal=no)
- if test "x$with_hal" = "xyes" -a "x$have_hal" = "xno"; then
- AC_MSG_ERROR([HAL support explicitly requested but HAL couldn't be
found])
- fi
-fi
-AM_CONDITIONAL(HAVE_HAL, test "x$have_hal" = "xyes")
-if test "x$have_hal" = "xyes"; then
- have_hal="yes -- will build with HAL support"
- AC_DEFINE(HAVE_HAL, 1, [Define if you have HAL support])
- CPPFLAGS="$CPPFLAGS $HAL_CFLAGS"
- CFLAGS="$CFLAGS $HAL_CFLAGS"
- LIBS="$LIBS $HAL_LIBS"
-else
- have_hal="*no -- will build without HAL support"
+ have_gio="*no -- will build without iPod autodetection support"
fi
dnl Check for libvorbisfile
@@ -238,9 +219,8 @@ Configuration for $PACKAGE $VERSION :
Install path .........: $prefix
GTK2 version .........: `$PKG_CONFIG gtk+-2.0 --modversion`
GLib2/GThread version : `$PKG_CONFIG gthread-2.0 --modversion`
+ gio ..................: $have_gio
libgpod version ......: $libgpod_version
- gnome-vfs.............: $have_gnome_vfs
- hal...................: $have_hal
libcurl ..............: $have_curl
vorbisfile ...........: $have_ogg
FLAC .................: $have_flac
diff --git a/src/autodetection.c b/src/autodetection.c
index 9a961df..72328ab 100644
--- a/src/autodetection.c
+++ b/src/autodetection.c
@@ -34,14 +34,8 @@
#include <stdio.h>
#include <string.h>
-
-
-#ifdef HAVE_GNOME_VFS
-#include <libgnomevfs/gnome-vfs.h>
-#endif
-#ifdef HAVE_HAL
-#include <libhal.h>
-#include <dbus/dbus.h>
+#ifdef HAVE_GIO
+#include <gio/gio.h>
#endif
#undef DEBUG_AUTO
@@ -117,8 +111,7 @@ static iTunesDB *ad_find_repository_with_mountpoint (const
gchar *mountpoint)
-
-#ifdef HAVE_GNOME_VFS
+#ifdef HAVE_GIO
typedef struct _AutoDetect AutoDetect;
static gboolean ad_timeout_cb (gpointer data);
@@ -133,202 +126,84 @@ struct _AutoDetect
static AutoDetect *autodetect;
-
-#ifdef HAVE_HAL
-/* from rb-ipod-source.c (rhythmbox ipod plugin) */
-static gboolean
-hal_udi_is_ipod (const char *udi)
+/* adapted from rb-ipod-plugin.c (rhythmbox ipod plugin) */
+static gboolean ad_mount_is_ipod (GMount *mount)
{
- LibHalContext *ctx;
- DBusConnection *conn;
- char *parent_udi;
- char *parent_name;
- gboolean result;
- DBusError error;
- gboolean inited = FALSE;
-
- result = FALSE;
- dbus_error_init (&error);
-
- conn = NULL;
- parent_udi = NULL;
- parent_name = NULL;
-
- ctx = libhal_ctx_new ();
- if (ctx == NULL) {
- /* FIXME: should we return an error somehow so that we can
- * fall back to a check for iTunesDB presence instead ?
- */
- debug ("cannot connect to HAL");
- goto end;
- }
- conn = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
- if (conn == NULL || dbus_error_is_set (&error))
- goto end;
-
- libhal_ctx_set_dbus_connection (ctx, conn);
- if (!libhal_ctx_init (ctx, &error) || dbus_error_is_set (&error))
- goto end;
-
- inited = TRUE;
- parent_udi = libhal_device_get_property_string (ctx, udi,
- "info.parent", &error);
- if (parent_udi == NULL || dbus_error_is_set (&error))
- goto end;
-
- parent_name = libhal_device_get_property_string (ctx, parent_udi,
- "storage.model", &error);
- if (parent_name == NULL || dbus_error_is_set (&error))
- goto end;
-
- if (strcmp (parent_name, "iPod") == 0)
- result = TRUE;
-
-end:
- g_free (parent_udi);
- g_free (parent_name);
-
- if (dbus_error_is_set (&error)) {
- debug ("Error: %s\n", error.message);
- dbus_error_free (&error);
- dbus_error_init (&error);
- }
-
- if (ctx) {
- if (inited)
- libhal_ctx_shutdown (ctx, &error);
- libhal_ctx_free(ctx);
- }
-
- dbus_error_free (&error);
-
- return result;
-}
-#endif
-
-
-/* adapted from rb-ipod-source.c (rhythmbox ipod plugin) */
-static gchar *ad_get_itunes_dir (GnomeVFSVolume *volume)
-{
- gchar *mount_point_uri;
- gchar *result = NULL;
-
- mount_point_uri = gnome_vfs_volume_get_activation_uri (volume);
- if (mount_point_uri)
- {
+ gboolean result = FALSE;
+ GFile *root = g_mount_get_root (mount);
+ if (root != NULL) {
gchar *mount_point;
- mount_point = g_filename_from_uri (mount_point_uri, NULL, NULL);
- if (mount_point)
- {
- result = itdb_get_itunes_dir (mount_point);
+ mount_point = g_file_get_path(root);
+ if (mount_point != NULL) {
+ gchar *itunes_dir;
+ itunes_dir = itdb_get_itunes_dir(mount_point);
+ if (itunes_dir != NULL) {
+ result = g_file_test (itunes_dir, G_FILE_TEST_IS_DIR);
+ g_free (itunes_dir);
+ }
g_free (mount_point);
}
- g_free (mount_point_uri);
- }
- return result;
-}
-
-
-/* adapted from rb-ipod-source.c (rhythmbox ipod plugin) */
-static gboolean ad_volume_has_ipod_dir (GnomeVFSVolume *volume)
-{
- gchar *itunes_dir;
- gboolean result = FALSE;
-
- itunes_dir = ad_get_itunes_dir (volume);
-
- if (itunes_dir)
- {
- result = g_file_test (itunes_dir, G_FILE_TEST_EXISTS);
+ g_object_unref (root);
}
-
- g_free (itunes_dir);
-
return result;
}
-/* adapted from rb-ipod-source.c (rhythmbox ipod plugin) */
-static gboolean ad_volume_is_ipod (GnomeVFSVolume *volume)
-{
-#ifdef HAVE_HAL
- gchar *udi;
-#endif
- if (gnome_vfs_volume_get_volume_type (volume) !=
GNOME_VFS_VOLUME_TYPE_MOUNTPOINT)
- {
- return FALSE;
- }
-#ifdef HAVE_HAL
- udi = gnome_vfs_volume_get_hal_udi (volume);
- if (udi != NULL)
- {
- gboolean result;
- result = hal_udi_is_ipod (udi);
- g_free (udi);
- if (result == FALSE)
- {
- return FALSE;
- }
- }
-#endif
-
- return ad_volume_has_ipod_dir (volume);
-}
-
-
-
-static void ad_volume_mounted_cb (GnomeVFSVolumeMonitor *vfsvolumemonitor,
- GnomeVFSVolume *volume,
+static void ad_volume_mounted_cb (GVolumeMonitor *volumemonitor,
+ GMount *mount,
AutoDetect *ad)
{
- g_return_if_fail (volume && ad);
+ g_return_if_fail (mount && ad);
- if (ad_volume_is_ipod (volume))
+ printf("%s entered\n", __func__);
+ if (G_IS_MOUNT(mount) && ad_mount_is_ipod (mount))
{
- gchar *uri;
-
- uri = gnome_vfs_volume_get_activation_uri (volume);
-
- debug ("mounted iPod: '%s'\n", uri);
-
- g_mutex_lock (ad->mutex);
- ad->new_ipod_uris = g_list_prepend (ad->new_ipod_uris, uri);
- g_mutex_unlock (ad->mutex);
+ GFile *root;
+ root = g_mount_get_root (mount);
+ if (root) {
+ gchar *uri;
+ uri = g_file_get_path(root);
+ if (uri) {
+ debug ("mounted iPod: '%s'\n", uri);
+
+ g_mutex_lock (ad->mutex);
+ ad->new_ipod_uris = g_list_prepend (ad->new_ipod_uris, uri);
+ g_mutex_unlock (ad->mutex);
+ } else {
+ fprintf(stderr, "ERROR: could not get activation root!\n");
+ }
+ g_object_unref (root);
+ }
}
}
-
void autodetection_init ()
{
if (autodetect == NULL)
{
- GList *volumes, *gl;
+ GList *mounts, *gl;
- if (!gnome_vfs_init ())
- {
- gtkpod_warning (_("Could not initialize GnomeVFS\n"));
- g_return_if_reached ();
- }
+ static GOnce g_type_init_once = G_ONCE_INIT;
+ g_once (&g_type_init_once, (GThreadFunc)g_type_init, NULL);
autodetect = g_new0 (AutoDetect, 1);
autodetect->mutex = g_mutex_new ();
/* Check if an iPod is already mounted and add it to the list */
- volumes = gnome_vfs_volume_monitor_get_mounted_volumes (
- gnome_vfs_get_volume_monitor ());
+ mounts = g_volume_monitor_get_mounts ( g_volume_monitor_get() );
- for (gl=volumes; gl; gl=gl->next)
+ for (gl=mounts; gl; gl=gl->next)
{
- GnomeVFSVolume *volume = gl->data;
- g_return_if_fail (volume);
- ad_volume_mounted_cb (NULL, volume, autodetect);
- gnome_vfs_volume_unref (volume);
+ GMount *mount = gl->data;
+ g_return_if_fail (mount);
+ ad_volume_mounted_cb (NULL, mount, autodetect);
+ g_object_unref (mount);
}
- g_list_free (volumes);
+ g_list_free (mounts);
- g_signal_connect (G_OBJECT (gnome_vfs_get_volume_monitor ()),
- "volume-mounted",
+ g_signal_connect (G_OBJECT (g_volume_monitor_get()),
+ "mount_added",
G_CALLBACK (ad_volume_mounted_cb),
autodetect);
@@ -354,7 +229,7 @@ static gboolean ad_timeout_cb (gpointer data)
while (ad->new_ipod_uris)
{
- iTunesDB *itdb, *loaded_itdb = NULL;
+ iTunesDB *itdb = NULL, *loaded_itdb = NULL;
gchar *mountpoint;
struct itdbs_head *itdbs;
GList *gl = ad->new_ipod_uris;
@@ -366,11 +241,15 @@ static gboolean ad_timeout_cb (gpointer data)
g_return_val_if_fail (mount_uri, (gdk_threads_leave(),
release_widgets(), TRUE));
- mountpoint = g_filename_from_uri (mount_uri, NULL, NULL);
+ GFile *muri = g_file_parse_name (mount_uri);
+ mountpoint = g_file_get_path (muri);
+ g_object_unref (muri);
g_free (mount_uri);
- debug ("Mounted iPod at '%s'\n", mountpoint);
- itdb = ad_find_repository_with_mountpoint (mountpoint);
+ if (mountpoint) {
+ debug ("Mounted iPod at '%s'\n", mountpoint);
+ itdb = ad_find_repository_with_mountpoint (mountpoint);
+ }
itdbs = gp_get_itdbs_head (gtkpod_window);
g_return_val_if_fail (itdbs, (gdk_threads_leave(),
release_widgets(), TRUE));
@@ -447,7 +326,7 @@ static gboolean ad_timeout_cb (gpointer data)
}
#else
-/* No GNOME_VFS support */
+/* No GIO support */
void autodetection_init ()
{
diff --git a/src/display_itdb.c b/src/display_itdb.c
index 11bc95f..2a9af53 100644
--- a/src/display_itdb.c
+++ b/src/display_itdb.c
@@ -860,7 +860,7 @@ void init_data (GtkWidget *window)
{
/* databases have not been set up previously -- take care of
this */
-#ifndef HAVE_GNOME_VFS
+#ifndef HAVE_GIO
gchar *mountpoint;
#endif
gchar *filename;
@@ -880,7 +880,7 @@ void init_data (GtkWidget *window)
prefs_set_string ("itdb_1_filename", filename);
g_free (filename);
-#ifndef HAVE_GNOME_VFS
+#ifndef HAVE_GIO
/* iPod database -- only set up if autodetection is not active */
mountpoint = prefs_get_string ("initial_mountpoint");
filename = g_build_filename (cfgdir, "iTunesDB", NULL);
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
gtkpod-cvs2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2