Build fixes for bmpx
[monky] / src / bmpx.c
index 9e12492..fb4076f 100644 (file)
@@ -1,4 +1,7 @@
-/* Conky, a system monitor, based on torsmo
+/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
+ * vim: ts=4 sw=4 noet ai cindent syntax=c
+ *
+ * Conky, a system monitor, based on torsmo
  *
  * Any original torsmo code is licensed under the BSD license
  *
@@ -6,7 +9,7 @@
  *
  * Please see COPYING for details
  *
- * Copyright (c) 2005-2007 Brenden Matthews, Philip Kovacs, et. al.
+ * Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al.
  *     (see AUTHORS)
  * All rights reserved.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
- * $Id$ */
+ */
+
+#include "config.h"
+#include "conky.h"
+#include "logging.h"
 
 #include <bmp/dbus.hh>
 #include <dbus/dbus-glib.h>
 
-#include <stdio.h>
-#include <string.h>
-
-#include "conky.h"
-
 #define DBUS_TYPE_G_STRING_VALUE_HASHTABLE \
        (dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE))
 
@@ -40,6 +42,8 @@ static DBusGProxy *remote_object;
 static int connected = 0;
 static char *unknown = "unknown";
 
+void fail(GError *error, struct information *);
+
 void update_bmpx()
 {
        GError *error = NULL;
@@ -53,15 +57,17 @@ void update_bmpx()
 
                bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
                if (bus == NULL) {
-                       ERR("BMPx error 1: %s\n", error->message);
-                       goto fail;
+                       NORM_ERR("BMPx error 1: %s\n", error->message);
+                       fail(error, current_info);
+                       return;
                }
 
                remote_object = dbus_g_proxy_new_for_name(bus, BMP_DBUS_SERVICE,
-                       BMP_DBUS_PATH, BMP_DBUS_INTERFACE);
+                               BMP_DBUS_PATH__BMP, BMP_DBUS_INTERFACE__BMP);
                if (!remote_object) {
-                       ERR("BMPx error 2: %s\n", error->message);
-                       goto fail;
+                       NORM_ERR("BMPx error 2: %s\n", error->message);
+                       fail(error, current_info);
+                       return;
                }
 
                connected = 1;
@@ -69,16 +75,17 @@ void update_bmpx()
 
        if (connected == 1) {
                if (dbus_g_proxy_call(remote_object, "GetCurrentTrack", &error,
-                               G_TYPE_INVALID, G_TYPE_INT, &current_track, G_TYPE_INVALID)) {
+                                       G_TYPE_INVALID, G_TYPE_INT, &current_track, G_TYPE_INVALID)) {
                } else {
-                       ERR("BMPx error 3: %s\n", error->message);
-                       goto fail;
+                       NORM_ERR("BMPx error 3: %s\n", error->message);
+                       fail(error, current_info);
+                       return;
                }
 
                if (dbus_g_proxy_call(remote_object, "GetMetadataForListItem", &error,
-                               G_TYPE_INT, current_track, G_TYPE_INVALID,
-                               DBUS_TYPE_G_STRING_VALUE_HASHTABLE, &metadata,
-                               G_TYPE_INVALID)) {
+                                       G_TYPE_INT, current_track, G_TYPE_INVALID,
+                                       DBUS_TYPE_G_STRING_VALUE_HASHTABLE, &metadata,
+                                       G_TYPE_INVALID)) {
                        if (current_info->bmpx.title) {
                                free(current_info->bmpx.title);
                                current_info->bmpx.title = 0;
@@ -104,32 +111,37 @@ void update_bmpx()
                        current_info->bmpx.uri =
                                g_value_get_string(g_hash_table_lookup(metadata, "location"));
                } else {
-                       ERR("BMPx error 4: %s\n", error->message);
-                       goto fail;
+                       NORM_ERR("BMPx error 4: %s\n", error->message);
+                       fail(error, current_info);
+                       return;
                }
 
                g_hash_table_destroy(metadata);
        } else {
-fail:
-               if (error) {
-                       g_error_free(error);
-               }
-               if (current_info->bmpx.title) {
-                       g_free(current_info->bmpx.title);
-                       current_info->bmpx.title = 0;
-               }
-               if (current_info->bmpx.artist) {
-                       g_free(current_info->bmpx.artist);
-                       current_info->bmpx.artist = 0;
-               }
-               if (current_info->bmpx.album) {
-                       g_free(current_info->bmpx.album);
-                       current_info->bmpx.album = 0;
-               }
-               current_info->bmpx.title = unknown;
-               current_info->bmpx.artist = unknown;
-               current_info->bmpx.album = unknown;
-               current_info->bmpx.bitrate = 0;
-               current_info->bmpx.track = 0;
+               fail(error, current_info);
+       }
+}
+
+void fail(GError *error, struct information *current_info)
+{
+       if (error) {
+               g_error_free(error);
+       }
+       if (current_info->bmpx.title) {
+               g_free(current_info->bmpx.title);
+               current_info->bmpx.title = 0;
+       }
+       if (current_info->bmpx.artist) {
+               g_free(current_info->bmpx.artist);
+               current_info->bmpx.artist = 0;
+       }
+       if (current_info->bmpx.album) {
+               g_free(current_info->bmpx.album);
+               current_info->bmpx.album = 0;
        }
+       current_info->bmpx.title = unknown;
+       current_info->bmpx.artist = unknown;
+       current_info->bmpx.album = unknown;
+       current_info->bmpx.bitrate = 0;
+       current_info->bmpx.track = 0;
 }