[Goodies-commits] r7699 - in xfmpc/trunk: . src
Vincent Legout
vincent at xfce.org
Wed Jul 8 23:02:32 CEST 2009
Author: vincent
Date: 2009-07-08 21:02:32 +0000 (Wed, 08 Jul 2009)
New Revision: 7699
Modified:
xfmpc/trunk/ChangeLog
xfmpc/trunk/configure.in.in
xfmpc/trunk/src/Makefile.am
xfmpc/trunk/src/dbbrowser.c
xfmpc/trunk/src/dbbrowser.vala
xfmpc/trunk/src/interface.c
xfmpc/trunk/src/interface.vala
xfmpc/trunk/src/main-window.c
xfmpc/trunk/src/main-window.vala
xfmpc/trunk/src/mpdclient.c
xfmpc/trunk/src/mpdclient.h
xfmpc/trunk/src/mpdclient.vapi
xfmpc/trunk/src/xfmpc.h
Log:
Improve interaction with mpd
Manage mpd connection in main-window.vala rather than interface.vala. Clean the
interface when disconnected from mpd. In mpdclient, try to connect to mpd in a
thread. Add a new method reload () to mpdclient to clean the playlist and the
dbbrowser when xfmpc is disconnected.
Modified: xfmpc/trunk/ChangeLog
===================================================================
--- xfmpc/trunk/ChangeLog 2009-07-08 18:32:20 UTC (rev 7698)
+++ xfmpc/trunk/ChangeLog 2009-07-08 21:02:32 UTC (rev 7699)
@@ -1,3 +1,12 @@
+2009-07-08 Vincent Legout <vincent at legout.info>
+
+Improve interaction with mpd
+
+Manage mpd connection in main-window.vala rather than interface.vala. Clean the
+interface when disconnected from mpd. In mpdclient, try to connect to mpd in a
+thread. Add a new method reload () to mpdclient to clean the playlist and the
+dbbrowser when xfmpc is disconnected.
+
2009-07-04 Vincent Legout <vincent at legout.info>
Switch to the new signal connect syntax
Modified: xfmpc/trunk/configure.in.in
===================================================================
--- xfmpc/trunk/configure.in.in 2009-07-08 18:32:20 UTC (rev 7698)
+++ xfmpc/trunk/configure.in.in 2009-07-08 21:02:32 UTC (rev 7699)
@@ -60,6 +60,7 @@
dnl *** Check for required packages ***
dnl ***********************************
XDT_CHECK_PACKAGE([GTK], [gtk+-2.0], [2.12.0])
+XDT_CHECK_PACKAGE([GTHREAD], [gthread-2.0], [2.12.0])
XDT_CHECK_PACKAGE([LIBXFCEGUI4], [libxfcegui4-1.0], [4.4.0])
XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0], [4.4.0])
XDT_CHECK_PACKAGE([LIBMPD], [libmpd], [0.15.0])
Modified: xfmpc/trunk/src/Makefile.am
===================================================================
--- xfmpc/trunk/src/Makefile.am 2009-07-08 18:32:20 UTC (rev 7698)
+++ xfmpc/trunk/src/Makefile.am 2009-07-08 21:02:32 UTC (rev 7699)
@@ -36,13 +36,15 @@
@GTK_CFLAGS@ \
@LIBXFCEGUI4_CFLAGS@ \
@LIBXFCE4UTIL_CFLAGS@ \
- @LIBMPD_CFLAGS@
+ @LIBMPD_CFLAGS@ \
+ @GTHREAD_CFLAGS@
xfmpc_LDADD = \
@GTK_LIBS@ \
@LIBXFCEGUI4_LIBS@ \
@LIBXFCE4UTIL_LIBS@ \
- @LIBMPD_LIBS@
+ @LIBMPD_LIBS@ \
+ @GTHREAD_LIBS@
INCLUDES = \
-I${top_srcdir} \
Modified: xfmpc/trunk/src/dbbrowser.c
===================================================================
--- xfmpc/trunk/src/dbbrowser.c 2009-07-08 18:32:20 UTC (rev 7698)
+++ xfmpc/trunk/src/dbbrowser.c 2009-07-08 21:02:32 UTC (rev 7699)
@@ -181,19 +181,19 @@
i = 0;
_tmp0_ = NULL;
playlist = (_tmp0_ = XFMPC_PLAYLIST (g_object_get_data ((GObject*) self, "XfmpcPlaylist")), (_tmp0_ == NULL) ? NULL : g_object_ref (_tmp0_));
- if (!xfmpc_mpdclient_is_connected (self->priv->mpdclient)) {
+ if (self->priv->is_searching) {
filename = (g_free (filename), NULL);
basename = (g_free (basename), NULL);
(playlist == NULL) ? NULL : (playlist = (g_object_unref (playlist), NULL));
return;
}
- if (self->priv->is_searching) {
+ xfmpc_dbbrowser_clear (self);
+ if (!xfmpc_mpdclient_is_connected (self->priv->mpdclient)) {
filename = (g_free (filename), NULL);
basename = (g_free (basename), NULL);
(playlist == NULL) ? NULL : (playlist = (g_object_unref (playlist), NULL));
return;
}
- xfmpc_dbbrowser_clear (self);
if (!xfmpc_dbbrowser_wdir_is_root (self)) {
char* _tmp1_;
_tmp1_ = NULL;
Modified: xfmpc/trunk/src/dbbrowser.vala
===================================================================
--- xfmpc/trunk/src/dbbrowser.vala 2009-07-08 18:32:20 UTC (rev 7698)
+++ xfmpc/trunk/src/dbbrowser.vala 2009-07-08 21:02:32 UTC (rev 7699)
@@ -138,12 +138,12 @@
int i = 0;
Xfmpc.Playlist playlist = (Xfmpc.Playlist) get_data ("XfmpcPlaylist");
- if (!this.mpdclient.is_connected ())
- return;
if (this.is_searching)
return;
clear ();
+ if (!this.mpdclient.is_connected ())
+ return;
if (!this.wdir_is_root ()) {
filename = get_parent_wdir ();
Modified: xfmpc/trunk/src/interface.c
===================================================================
--- xfmpc/trunk/src/interface.c 2009-07-08 18:32:20 UTC (rev 7698)
+++ xfmpc/trunk/src/interface.c 2009-07-08 21:02:32 UTC (rev 7699)
@@ -71,7 +71,6 @@
GtkProgressBar* progress_bar;
GtkLabel* title;
GtkLabel* subtitle;
- gboolean refresh_title;
};
@@ -91,14 +90,13 @@
void xfmpc_interface_set_volume (XfmpcInterface* self, gint volume);
void xfmpc_interface_popup_volume (XfmpcInterface* self);
void xfmpc_interface_set_time (XfmpcInterface* self, gint time, gint time_total);
-static void xfmpc_interface_reconnect (XfmpcInterface* self);
-static gboolean xfmpc_interface_refresh (XfmpcInterface* self);
+void xfmpc_interface_clean (XfmpcInterface* self);
+void xfmpc_interface_update_title (XfmpcInterface* self);
static void xfmpc_interface_cb_song_changed (XfmpcInterface* self);
-static void xfmpc_interface_cb_stopped (XfmpcInterface* self);
-static gboolean _xfmpc_interface_refresh_gsource_func (gpointer self);
static void xfmpc_interface_cb_pp_changed (XfmpcInterface* self, gboolean is_playing);
static void xfmpc_interface_cb_time_changed (XfmpcInterface* self, gint time, gint total_time);
static void xfmpc_interface_cb_volume_changed (XfmpcInterface* self, gint volume);
+static void xfmpc_interface_cb_stopped (XfmpcInterface* self);
static void xfmpc_interface_cb_mpdclient_previous (XfmpcInterface* self);
static void xfmpc_interface_cb_mpdclient_next (XfmpcInterface* self);
XfmpcInterface* xfmpc_interface_new (void);
@@ -110,7 +108,6 @@
static void _xfmpc_interface_cb_mpdclient_next_gtk_button_clicked (GtkButton* _sender, gpointer self);
static void _xfmpc_interface_volume_changed_gtk_scale_button_value_changed (GtkScaleButton* _sender, double value, gpointer self);
static gboolean _xfmpc_interface_cb_progress_box_release_event_gtk_widget_button_release_event (GtkWidget* _sender, const GdkEventButton* event, gpointer self);
-static void _xfmpc_interface_reconnect_xfmpc_mpdclient_connected (XfmpcMpdclient* _sender, gpointer self);
static void _xfmpc_interface_cb_song_changed_xfmpc_mpdclient_song_changed (XfmpcMpdclient* _sender, gpointer self);
static void _xfmpc_interface_cb_pp_changed_xfmpc_mpdclient_pp_changed (XfmpcMpdclient* _sender, gboolean is_playing, gpointer self);
static void _xfmpc_interface_cb_time_changed_xfmpc_mpdclient_time_changed (XfmpcMpdclient* _sender, gint time, gint total_time, gpointer self);
@@ -238,67 +235,41 @@
}
-static gboolean xfmpc_interface_refresh (XfmpcInterface* self) {
- g_return_val_if_fail (self != NULL, FALSE);
- if (xfmpc_mpdclient_connect (self->priv->mpdclient) == FALSE) {
- g_warning ("interface.vala:208: Failed to connect to MPD");
- xfmpc_mpdclient_disconnect (self->priv->mpdclient);
- xfmpc_interface_set_pp (self, FALSE);
- xfmpc_interface_set_time (self, 0, 0);
- xfmpc_interface_set_volume (self, 0);
- xfmpc_interface_set_title (self, _ ("Not connected"));
- xfmpc_interface_set_subtitle (self, PACKAGE_STRING);
- g_timeout_add ((guint) 15000, (GSourceFunc) xfmpc_interface_reconnect, NULL);
- return FALSE;
- }
- xfmpc_mpdclient_update_status (self->priv->mpdclient);
- return TRUE;
+void xfmpc_interface_clean (XfmpcInterface* self) {
+ g_return_if_fail (self != NULL);
+ xfmpc_interface_set_pp (self, FALSE);
+ xfmpc_interface_set_time (self, 0, 0);
+ xfmpc_interface_set_volume (self, 0);
+ xfmpc_interface_set_title (self, _ ("Not connected"));
+ xfmpc_interface_set_subtitle (self, PACKAGE_STRING);
}
-static gboolean _xfmpc_interface_refresh_gsource_func (gpointer self) {
- return xfmpc_interface_refresh (self);
-}
-
-
-static void xfmpc_interface_reconnect (XfmpcInterface* self) {
+void xfmpc_interface_update_title (XfmpcInterface* self) {
g_return_if_fail (self != NULL);
- if (xfmpc_mpdclient_connect (self->priv->mpdclient) == FALSE) {
- return;
+ if (xfmpc_mpdclient_get_title (self->priv->mpdclient) != NULL) {
+ GString* text;
+ xfmpc_interface_set_title (self, xfmpc_mpdclient_get_title (self->priv->mpdclient));
+ /* subtitle "by \"artist\" from \"album\" (year)" */
+ text = g_string_new ("");
+ g_string_append_printf (text, _ ("by \"%s\" from \"%s\" (%s)"), xfmpc_mpdclient_get_artist (self->priv->mpdclient), xfmpc_mpdclient_get_album (self->priv->mpdclient), xfmpc_mpdclient_get_date (self->priv->mpdclient));
+ /* text = xfmpc_interface_get_subtitle (interface); to avoid "n/a" values, so far I don't care */
+ xfmpc_interface_set_subtitle (self, text->str);
+ (text == NULL) ? NULL : (text = (g_string_free (text, TRUE), NULL));
}
- /* Refresh title/subtitle (bug #4975) */
- self->priv->refresh_title = TRUE;
- if (xfmpc_mpdclient_is_playing (self->priv->mpdclient)) {
- xfmpc_interface_cb_song_changed (self);
- } else {
- xfmpc_interface_cb_stopped (self);
- }
- /* Return FALSE to kill the reconnection timeout and start a refresh timeout */
- g_timeout_add ((guint) 1000, _xfmpc_interface_refresh_gsource_func, self);
}
static void xfmpc_interface_cb_song_changed (XfmpcInterface* self) {
- GString* text;
g_return_if_fail (self != NULL);
- /* title */
- xfmpc_interface_set_title (self, xfmpc_mpdclient_get_title (self->priv->mpdclient));
- /* subtitle "by \"artist\" from \"album\" (year)" */
- text = g_string_new ("");
- g_string_append_printf (text, _ ("by \"%s\" from \"%s\" (%s)"), xfmpc_mpdclient_get_artist (self->priv->mpdclient), xfmpc_mpdclient_get_album (self->priv->mpdclient), xfmpc_mpdclient_get_date (self->priv->mpdclient));
- /* text = xfmpc_interface_get_subtitle (interface); to avoid "n/a" values, so far I don't care */
- xfmpc_interface_set_subtitle (self, text->str);
- (text == NULL) ? NULL : (text = (g_string_free (text, TRUE), NULL));
+ xfmpc_interface_update_title (self);
}
static void xfmpc_interface_cb_pp_changed (XfmpcInterface* self, gboolean is_playing) {
g_return_if_fail (self != NULL);
xfmpc_interface_set_pp (self, is_playing);
- if (self->priv->refresh_title) {
- xfmpc_interface_cb_song_changed (self);
- self->priv->refresh_title = FALSE;
- }
+ xfmpc_interface_cb_song_changed (self);
}
@@ -316,11 +287,7 @@
static void xfmpc_interface_cb_stopped (XfmpcInterface* self) {
g_return_if_fail (self != NULL);
- xfmpc_interface_set_pp (self, FALSE);
- xfmpc_interface_set_time (self, 0, 0);
- xfmpc_interface_set_title (self, _ ("Stopped"));
- xfmpc_interface_set_subtitle (self, PACKAGE_STRING);
- self->priv->refresh_title = TRUE;
+ xfmpc_interface_clean (self);
}
@@ -373,11 +340,6 @@
}
-static void _xfmpc_interface_reconnect_xfmpc_mpdclient_connected (XfmpcMpdclient* _sender, gpointer self) {
- xfmpc_interface_reconnect (self);
-}
-
-
static void _xfmpc_interface_cb_song_changed_xfmpc_mpdclient_song_changed (XfmpcMpdclient* _sender, gpointer self) {
xfmpc_interface_cb_song_changed (self);
}
@@ -512,14 +474,11 @@
g_signal_connect_object (self->priv->button_next, "clicked", (GCallback) _xfmpc_interface_cb_mpdclient_next_gtk_button_clicked, self, 0);
g_signal_connect_object ((GtkScaleButton*) self->priv->button_volume, "value-changed", (GCallback) _xfmpc_interface_volume_changed_gtk_scale_button_value_changed, self, 0);
g_signal_connect_object ((GtkWidget*) progress_box, "button-release-event", (GCallback) _xfmpc_interface_cb_progress_box_release_event_gtk_widget_button_release_event, self, 0);
- g_signal_connect_object (self->priv->mpdclient, "connected", (GCallback) _xfmpc_interface_reconnect_xfmpc_mpdclient_connected, self, 0);
g_signal_connect_object (self->priv->mpdclient, "song-changed", (GCallback) _xfmpc_interface_cb_song_changed_xfmpc_mpdclient_song_changed, self, 0);
g_signal_connect_object (self->priv->mpdclient, "pp-changed", (GCallback) _xfmpc_interface_cb_pp_changed_xfmpc_mpdclient_pp_changed, self, 0);
g_signal_connect_object (self->priv->mpdclient, "time-changed", (GCallback) _xfmpc_interface_cb_time_changed_xfmpc_mpdclient_time_changed, self, 0);
g_signal_connect_object (self->priv->mpdclient, "volume-changed", (GCallback) _xfmpc_interface_cb_volume_changed_xfmpc_mpdclient_volume_changed, self, 0);
g_signal_connect_object (self->priv->mpdclient, "stopped", (GCallback) _xfmpc_interface_cb_stopped_xfmpc_mpdclient_stopped, self, 0);
- /* === Timeout === */
- g_timeout_add ((guint) 1000, _xfmpc_interface_refresh_gsource_func, self);
(image == NULL) ? NULL : (image = (g_object_unref (image), NULL));
(adjustment == NULL) ? NULL : (adjustment = (g_object_unref (adjustment), NULL));
(progress_box == NULL) ? NULL : (progress_box = (g_object_unref (progress_box), NULL));
Modified: xfmpc/trunk/src/interface.vala
===================================================================
--- xfmpc/trunk/src/interface.vala 2009-07-08 18:32:20 UTC (rev 7698)
+++ xfmpc/trunk/src/interface.vala 2009-07-08 21:02:32 UTC (rev 7699)
@@ -33,7 +33,6 @@
private Gtk.ProgressBar progress_bar;
private Gtk.Label title;
private Gtk.Label subtitle;
- private bool refresh_title;
construct {
this.mpdclient = Xfmpc.Mpdclient.get ();
@@ -121,15 +120,11 @@
this.button_volume.value_changed.connect (volume_changed);
progress_box.button_release_event.connect (cb_progress_box_release_event);
- this.mpdclient.connected.connect (reconnect);
this.mpdclient.song_changed.connect (cb_song_changed);
this.mpdclient.pp_changed.connect (cb_pp_changed);
this.mpdclient.time_changed.connect (cb_time_changed);
this.mpdclient.volume_changed.connect (cb_volume_changed);
this.mpdclient.stopped.connect (cb_stopped);
-
- /* === Timeout === */
- Timeout.add (1000, refresh);
}
public void set_title (string title) {
@@ -203,62 +198,38 @@
this.progress_bar.set_fraction ((fraction <= 1.0) ? fraction : 1.0);
}
- private bool refresh () {
- if (this.mpdclient.connect () == false) {
- warning ("Failed to connect to MPD");
- this.mpdclient.disconnect ();
-
- set_pp (false);
- set_time (0, 0);
- set_volume (0);
- set_title (_("Not connected"));
- set_subtitle (Config.PACKAGE_STRING);
-
- GLib.Timeout.add (15000, (GLib.SourceFunc) reconnect);
- return false;
- }
-
- this.mpdclient.update_status ();
- return true;
+ public void clean () {
+ set_pp (false);
+ set_time (0, 0);
+ set_volume (0);
+ set_title (_("Not connected"));
+ set_subtitle (Config.PACKAGE_STRING);
}
- private void reconnect () {
- if (this.mpdclient.connect () == false)
- return;
+ public void update_title () {
+ if (this.mpdclient.get_title () != null) {
+ set_title (this.mpdclient.get_title ());
- /* Refresh title/subtitle (bug #4975) */
- this.refresh_title = true;
- if (this.mpdclient.is_playing ())
- cb_song_changed ();
- else
- cb_stopped ();
+ /* subtitle "by \"artist\" from \"album\" (year)" */
+ GLib.StringBuilder text = new GLib.StringBuilder ();
+ text.append_printf (_("by \"%s\" from \"%s\" (%s)"),
+ this.mpdclient.get_artist (),
+ this.mpdclient.get_album (),
+ this.mpdclient.get_date ());
- /* Return FALSE to kill the reconnection timeout and start a refresh timeout */
- GLib.Timeout.add (1000, refresh);
+ /* text = xfmpc_interface_get_subtitle (interface); to avoid "n/a" values, so far I don't care */
+ set_subtitle (text.str);
+ }
}
private void cb_song_changed () {
- /* title */
- set_title (this.mpdclient.get_title ());
-
- /* subtitle "by \"artist\" from \"album\" (year)" */
- GLib.StringBuilder text = new GLib.StringBuilder ();
- text.append_printf (_("by \"%s\" from \"%s\" (%s)"),
- this.mpdclient.get_artist (),
- this.mpdclient.get_album (),
- this.mpdclient.get_date ());
-
- /* text = xfmpc_interface_get_subtitle (interface); to avoid "n/a" values, so far I don't care */
- set_subtitle (text.str);
+ update_title ();
}
private void cb_pp_changed (bool is_playing) {
set_pp (is_playing);
- if (this.refresh_title) {
- cb_song_changed ();
- this.refresh_title = false;
- }
+ cb_song_changed ();
}
private void cb_time_changed (int time, int total_time) {
@@ -270,12 +241,7 @@
}
private void cb_stopped () {
- set_pp (false);
- set_time (0, 0);
- set_title (_("Stopped"));
- set_subtitle (Config.PACKAGE_STRING);
-
- this.refresh_title = true;
+ clean ();
}
private void cb_mpdclient_previous () {
Modified: xfmpc/trunk/src/main-window.c
===================================================================
--- xfmpc/trunk/src/main-window.c 2009-07-08 18:32:20 UTC (rev 7698)
+++ xfmpc/trunk/src/main-window.c 2009-07-08 21:02:32 UTC (rev 7699)
@@ -21,10 +21,10 @@
#include <glib-object.h>
#include <gtk/gtk.h>
#include <mpdclient.h>
+#include <stdlib.h>
+#include <string.h>
#include <gdk/gdk.h>
#include <glib/gi18n-lib.h>
-#include <stdlib.h>
-#include <string.h>
#include <config.h>
@@ -59,6 +59,16 @@
typedef struct _XfmpcInterface XfmpcInterface;
typedef struct _XfmpcInterfaceClass XfmpcInterfaceClass;
+#define XFMPC_TYPE_EXTENDED_INTERFACE (xfmpc_extended_interface_get_type ())
+#define XFMPC_EXTENDED_INTERFACE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XFMPC_TYPE_EXTENDED_INTERFACE, XfmpcExtendedInterface))
+#define XFMPC_EXTENDED_INTERFACE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XFMPC_TYPE_EXTENDED_INTERFACE, XfmpcExtendedInterfaceClass))
+#define XFMPC_IS_EXTENDED_INTERFACE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XFMPC_TYPE_EXTENDED_INTERFACE))
+#define XFMPC_IS_EXTENDED_INTERFACE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XFMPC_TYPE_EXTENDED_INTERFACE))
+#define XFMPC_EXTENDED_INTERFACE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XFMPC_TYPE_EXTENDED_INTERFACE, XfmpcExtendedInterfaceClass))
+
+typedef struct _XfmpcExtendedInterface XfmpcExtendedInterface;
+typedef struct _XfmpcExtendedInterfaceClass XfmpcExtendedInterfaceClass;
+
#define XFMPC_TYPE_STATUSBAR (xfmpc_statusbar_get_type ())
#define XFMPC_STATUSBAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XFMPC_TYPE_STATUSBAR, XfmpcStatusbar))
#define XFMPC_STATUSBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XFMPC_TYPE_STATUSBAR, XfmpcStatusbarClass))
@@ -69,16 +79,6 @@
typedef struct _XfmpcStatusbar XfmpcStatusbar;
typedef struct _XfmpcStatusbarClass XfmpcStatusbarClass;
-#define XFMPC_TYPE_EXTENDED_INTERFACE (xfmpc_extended_interface_get_type ())
-#define XFMPC_EXTENDED_INTERFACE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XFMPC_TYPE_EXTENDED_INTERFACE, XfmpcExtendedInterface))
-#define XFMPC_EXTENDED_INTERFACE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XFMPC_TYPE_EXTENDED_INTERFACE, XfmpcExtendedInterfaceClass))
-#define XFMPC_IS_EXTENDED_INTERFACE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XFMPC_TYPE_EXTENDED_INTERFACE))
-#define XFMPC_IS_EXTENDED_INTERFACE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XFMPC_TYPE_EXTENDED_INTERFACE))
-#define XFMPC_EXTENDED_INTERFACE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XFMPC_TYPE_EXTENDED_INTERFACE, XfmpcExtendedInterfaceClass))
-
-typedef struct _XfmpcExtendedInterface XfmpcExtendedInterface;
-typedef struct _XfmpcExtendedInterfaceClass XfmpcExtendedInterfaceClass;
-
struct _XfmpcMainWindow {
GtkWindow parent_instance;
XfmpcMainWindowPrivate * priv;
@@ -91,6 +91,8 @@
struct _XfmpcMainWindowPrivate {
XfmpcMpdclient* mpdclient;
XfmpcPreferences* preferences;
+ XfmpcInterface* interface;
+ XfmpcExtendedInterface* extended_interface;
GtkVBox* vbox;
GtkActionGroup* action_group;
GtkWidget* statusbar;
@@ -101,6 +103,8 @@
GType xfmpc_main_window_get_type (void);
GType xfmpc_preferences_get_type (void);
+GType xfmpc_interface_get_type (void);
+GType xfmpc_extended_interface_get_type (void);
#define XFMPC_MAIN_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), XFMPC_TYPE_MAIN_WINDOW, XfmpcMainWindowPrivate))
enum {
XFMPC_MAIN_WINDOW_DUMMY_PROPERTY
@@ -120,6 +124,11 @@
static void xfmpc_main_window_action_volume (XfmpcMainWindow* self);
static void _xfmpc_main_window_action_volume_gtk_action_callback (GtkAction* action, gpointer self);
#define XFMPC_MAIN_WINDOW_ui_string "\n<ui>\n <accelerator action=\"quit\" />\n <accelerator action=\"previous\" />\n <accelerator action=\"pp\" />\n <accelerator action=\"stop\" />\n <accelerator action=\"next\" />\n <accelerator action=\"volume\" />\n</ui>\n"
+void xfmpc_interface_clean (XfmpcInterface* self);
+GType xfmpc_statusbar_get_type (void);
+void xfmpc_statusbar_set_text (XfmpcStatusbar* self, const char* value);
+void xfmpc_interface_update_title (XfmpcInterface* self);
+static gboolean xfmpc_main_window_refresh (XfmpcMainWindow* self);
void xfmpc_preferences_set_last_window_state_sticky (XfmpcPreferences* self, gboolean value);
static gboolean xfmpc_main_window_cb_window_state_event (XfmpcMainWindow* self, const GdkEventWindowState* event);
static void xfmpc_main_window_close_window (XfmpcMainWindow* self);
@@ -128,13 +137,10 @@
void xfmpc_preferences_set_last_window_posy (XfmpcPreferences* self, gint value);
void xfmpc_preferences_set_last_window_width (XfmpcPreferences* self, gint value);
void xfmpc_preferences_set_last_window_height (XfmpcPreferences* self, gint value);
-GType xfmpc_interface_get_type (void);
void xfmpc_interface_pp_clicked (XfmpcInterface* self);
void xfmpc_interface_popup_volume (XfmpcInterface* self);
XfmpcStatusbar* xfmpc_statusbar_new (void);
XfmpcStatusbar* xfmpc_statusbar_construct (GType object_type);
-GType xfmpc_statusbar_get_type (void);
-void xfmpc_statusbar_set_text (XfmpcStatusbar* self, const char* value);
static void xfmpc_main_window_update_statusbar (XfmpcMainWindow* self);
static void xfmpc_main_window_cb_playlist_changed (XfmpcMainWindow* self);
gboolean xfmpc_preferences_get_show_statusbar (XfmpcPreferences* self);
@@ -154,9 +160,9 @@
XfmpcInterface* xfmpc_interface_construct (GType object_type);
XfmpcExtendedInterface* xfmpc_extended_interface_new (void);
XfmpcExtendedInterface* xfmpc_extended_interface_construct (GType object_type);
-GType xfmpc_extended_interface_get_type (void);
static void _xfmpc_main_window_cb_playlist_changed_xfmpc_mpdclient_playlist_changed (XfmpcMpdclient* _sender, gpointer self);
static void _xfmpc_main_window_cb_show_statusbar_changed_g_object_notify (GObject* _sender, GParamSpec* pspec, gpointer self);
+static gboolean _xfmpc_main_window_refresh_gsource_func (gpointer self);
static GObject * xfmpc_main_window_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
static gpointer xfmpc_main_window_parent_class = NULL;
static void xfmpc_main_window_finalize (GObject* obj);
@@ -200,6 +206,23 @@
}
+static gboolean xfmpc_main_window_refresh (XfmpcMainWindow* self) {
+ g_return_val_if_fail (self != NULL, FALSE);
+ if (xfmpc_mpdclient_is_connected (self->priv->mpdclient)) {
+ xfmpc_mpdclient_update_status (self->priv->mpdclient);
+ } else {
+ xfmpc_interface_clean (self->priv->interface);
+ xfmpc_mpdclient_reload (self->priv->mpdclient);
+ xfmpc_statusbar_set_text (XFMPC_STATUSBAR (self->priv->statusbar), "");
+ xfmpc_mpdclient_connect (self->priv->mpdclient);
+ if (xfmpc_mpdclient_is_connected (self->priv->mpdclient)) {
+ xfmpc_interface_update_title (self->priv->interface);
+ }
+ }
+ return TRUE;
+}
+
+
static gboolean xfmpc_main_window_cb_window_state_event (XfmpcMainWindow* self, const GdkEventWindowState* event) {
gboolean _tmp1_;
g_return_val_if_fail (self != NULL, FALSE);
@@ -273,13 +296,8 @@
static void xfmpc_main_window_action_pp (XfmpcMainWindow* self) {
- XfmpcInterface* _tmp0_;
- XfmpcInterface* interface;
g_return_if_fail (self != NULL);
- _tmp0_ = NULL;
- interface = (_tmp0_ = XFMPC_INTERFACE (g_object_get_data ((GObject*) self, "XfmpcInterface")), (_tmp0_ == NULL) ? NULL : g_object_ref (_tmp0_));
- xfmpc_interface_pp_clicked (interface);
- (interface == NULL) ? NULL : (interface = (g_object_unref (interface), NULL));
+ xfmpc_interface_pp_clicked (self->priv->interface);
}
@@ -296,13 +314,8 @@
static void xfmpc_main_window_action_volume (XfmpcMainWindow* self) {
- XfmpcInterface* _tmp0_;
- XfmpcInterface* interface;
g_return_if_fail (self != NULL);
- _tmp0_ = NULL;
- interface = (_tmp0_ = XFMPC_INTERFACE (g_object_get_data ((GObject*) self, "XfmpcInterface")), (_tmp0_ == NULL) ? NULL : g_object_ref (_tmp0_));
- xfmpc_interface_popup_volume (interface);
- (interface == NULL) ? NULL : (interface = (g_object_unref (interface), NULL));
+ xfmpc_interface_popup_volume (self->priv->interface);
}
@@ -421,6 +434,11 @@
}
+static gboolean _xfmpc_main_window_refresh_gsource_func (gpointer self) {
+ return xfmpc_main_window_refresh (self);
+}
+
+
static GObject * xfmpc_main_window_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
GObject * obj;
XfmpcMainWindowClass * klass;
@@ -437,12 +455,12 @@
GtkVBox* _tmp0_;
gboolean _tmp1_;
gboolean _tmp2_;
- XfmpcInterface* interface;
+ XfmpcInterface* _tmp3_;
GtkHSeparator* separator;
- XfmpcExtendedInterface* extended_interface;
- GtkUIManager* _tmp3_;
- GtkActionGroup* _tmp4_;
- GtkAccelGroup* _tmp5_;
+ XfmpcExtendedInterface* _tmp4_;
+ GtkUIManager* _tmp5_;
+ GtkActionGroup* _tmp6_;
+ GtkAccelGroup* _tmp7_;
GtkAccelGroup* accel_group;
self->priv->mpdclient = xfmpc_mpdclient_get ();
self->priv->preferences = xfmpc_preferences_get ();
@@ -479,21 +497,22 @@
gtk_window_stick ((GtkWindow*) self);
}
/* Interface */
- interface = g_object_ref_sink (xfmpc_interface_new ());
- g_object_set_data ((GObject*) self, "XfmpcInterface", interface);
- gtk_box_pack_start ((GtkBox*) self->priv->vbox, (GtkWidget*) interface, FALSE, FALSE, (guint) 4);
+ _tmp3_ = NULL;
+ self->priv->interface = (_tmp3_ = g_object_ref_sink (xfmpc_interface_new ()), (self->priv->interface == NULL) ? NULL : (self->priv->interface = (g_object_unref (self->priv->interface), NULL)), _tmp3_);
+ gtk_box_pack_start ((GtkBox*) self->priv->vbox, (GtkWidget*) self->priv->interface, FALSE, FALSE, (guint) 4);
/* Separator */
separator = g_object_ref_sink ((GtkHSeparator*) gtk_hseparator_new ());
gtk_box_pack_start ((GtkBox*) self->priv->vbox, (GtkWidget*) separator, FALSE, FALSE, (guint) 0);
/* ExtendedInterface */
- extended_interface = g_object_ref_sink (xfmpc_extended_interface_new ());
- gtk_box_pack_start ((GtkBox*) self->priv->vbox, (GtkWidget*) extended_interface, TRUE, TRUE, (guint) 0);
+ _tmp4_ = NULL;
+ self->priv->extended_interface = (_tmp4_ = g_object_ref_sink (xfmpc_extended_interface_new ()), (self->priv->extended_interface == NULL) ? NULL : (self->priv->extended_interface = (g_object_unref (self->priv->extended_interface), NULL)), _tmp4_);
+ gtk_box_pack_start ((GtkBox*) self->priv->vbox, (GtkWidget*) self->priv->extended_interface, TRUE, TRUE, (guint) 0);
/* Accelerators */
- _tmp3_ = NULL;
- self->priv->ui_manager = (_tmp3_ = gtk_ui_manager_new (), (self->priv->ui_manager == NULL) ? NULL : (self->priv->ui_manager = (g_object_unref (self->priv->ui_manager), NULL)), _tmp3_);
+ _tmp5_ = NULL;
+ self->priv->ui_manager = (_tmp5_ = gtk_ui_manager_new (), (self->priv->ui_manager == NULL) ? NULL : (self->priv->ui_manager = (g_object_unref (self->priv->ui_manager), NULL)), _tmp5_);
/* Action group */
- _tmp4_ = NULL;
- self->priv->action_group = (_tmp4_ = gtk_action_group_new ("XfmpcMainWindow"), (self->priv->action_group == NULL) ? NULL : (self->priv->action_group = (g_object_unref (self->priv->action_group), NULL)), _tmp4_);
+ _tmp6_ = NULL;
+ self->priv->action_group = (_tmp6_ = gtk_action_group_new ("XfmpcMainWindow"), (self->priv->action_group == NULL) ? NULL : (self->priv->action_group = (g_object_unref (self->priv->action_group), NULL)), _tmp6_);
gtk_action_group_add_actions (self->priv->action_group, XFMPC_MAIN_WINDOW_action_entries, G_N_ELEMENTS (XFMPC_MAIN_WINDOW_action_entries), self);
gtk_action_group_add_toggle_actions (self->priv->action_group, XFMPC_MAIN_WINDOW_toggle_action_entries, G_N_ELEMENTS (XFMPC_MAIN_WINDOW_toggle_action_entries), self);
gtk_ui_manager_insert_action_group (self->priv->ui_manager, self->priv->action_group, 0);
@@ -517,24 +536,22 @@
}
__finally0:
if (_inner_error_ != NULL) {
- (interface == NULL) ? NULL : (interface = (g_object_unref (interface), NULL));
(separator == NULL) ? NULL : (separator = (g_object_unref (separator), NULL));
- (extended_interface == NULL) ? NULL : (extended_interface = (g_object_unref (extended_interface), NULL));
g_critical ("file %s: line %d: uncaught error: %s", __FILE__, __LINE__, _inner_error_->message);
g_clear_error (&_inner_error_);
}
/* Accel group */
- _tmp5_ = NULL;
- accel_group = (_tmp5_ = gtk_ui_manager_get_accel_group (self->priv->ui_manager), (_tmp5_ == NULL) ? NULL : g_object_ref (_tmp5_));
+ _tmp7_ = NULL;
+ accel_group = (_tmp7_ = gtk_ui_manager_get_accel_group (self->priv->ui_manager), (_tmp7_ == NULL) ? NULL : g_object_ref (_tmp7_));
gtk_window_add_accel_group ((GtkWindow*) self, accel_group);
/* show-statusbar action */
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (gtk_action_group_get_action (self->priv->action_group, "view-statusbar")), xfmpc_preferences_get_show_statusbar (self->priv->preferences));
/* === Signals === */
g_signal_connect_object (self->priv->mpdclient, "playlist-changed", (GCallback) _xfmpc_main_window_cb_playlist_changed_xfmpc_mpdclient_playlist_changed, self, 0);
g_signal_connect_object ((GObject*) self->priv->preferences, "notify::show-statusbar", (GCallback) _xfmpc_main_window_cb_show_statusbar_changed_g_object_notify, self, 0);
- (interface == NULL) ? NULL : (interface = (g_object_unref (interface), NULL));
+ /* === Timeout === */
+ g_timeout_add ((guint) 1000, _xfmpc_main_window_refresh_gsource_func, self);
(separator == NULL) ? NULL : (separator = (g_object_unref (separator), NULL));
- (extended_interface == NULL) ? NULL : (extended_interface = (g_object_unref (extended_interface), NULL));
(accel_group == NULL) ? NULL : (accel_group = (g_object_unref (accel_group), NULL));
}
return obj;
@@ -557,6 +574,8 @@
static void xfmpc_main_window_finalize (GObject* obj) {
XfmpcMainWindow * self;
self = XFMPC_MAIN_WINDOW (obj);
+ (self->priv->interface == NULL) ? NULL : (self->priv->interface = (g_object_unref (self->priv->interface), NULL));
+ (self->priv->extended_interface == NULL) ? NULL : (self->priv->extended_interface = (g_object_unref (self->priv->extended_interface), NULL));
(self->priv->vbox == NULL) ? NULL : (self->priv->vbox = (g_object_unref (self->priv->vbox), NULL));
(self->priv->action_group == NULL) ? NULL : (self->priv->action_group = (g_object_unref (self->priv->action_group), NULL));
(self->priv->statusbar == NULL) ? NULL : (self->priv->statusbar = (g_object_unref (self->priv->statusbar), NULL));
Modified: xfmpc/trunk/src/main-window.vala
===================================================================
--- xfmpc/trunk/src/main-window.vala 2009-07-08 18:32:20 UTC (rev 7698)
+++ xfmpc/trunk/src/main-window.vala 2009-07-08 21:02:32 UTC (rev 7699)
@@ -26,6 +26,9 @@
private unowned Xfmpc.Mpdclient mpdclient;
private unowned Xfmpc.Preferences preferences;
+ private Xfmpc.Interface interface;
+ private Xfmpc.ExtendedInterface extended_interface;
+
private Gtk.VBox vbox;
private Gtk.ActionGroup action_group;
private Gtk.Widget statusbar;
@@ -80,17 +83,16 @@
stick ();
/* Interface */
- var interface = new Xfmpc.Interface ();
- set_data ("XfmpcInterface", interface);
- this.vbox.pack_start (interface, false, false, 4);
+ this.interface = new Xfmpc.Interface ();
+ this.vbox.pack_start (this.interface, false, false, 4);
/* Separator */
var separator = new Gtk.HSeparator ();
this.vbox.pack_start (separator, false, false, 0);
/* ExtendedInterface */
- var extended_interface = new Xfmpc.ExtendedInterface ();
- this.vbox.pack_start (extended_interface, true, true, 0);
+ this.extended_interface = new Xfmpc.ExtendedInterface ();
+ this.vbox.pack_start (this.extended_interface, true, true, 0);
/* Accelerators */
this.ui_manager = new Gtk.UIManager ();
@@ -116,8 +118,26 @@
/* === Signals === */
this.mpdclient.playlist_changed.connect (cb_playlist_changed);
this.preferences.notify["show-statusbar"].connect (cb_show_statusbar_changed);
+
+ /* === Timeout === */
+ Timeout.add (1000, refresh);
}
+ private bool refresh () {
+ if (this.mpdclient.is_connected ()) {
+ this.mpdclient.update_status ();
+ } else {
+ this.interface.clean ();
+ this.mpdclient.reload ();
+ ((Xfmpc.Statusbar) this.statusbar).text = "";
+ this.mpdclient.connect ();
+ if (this.mpdclient.is_connected ())
+ this.interface.update_title ();
+ }
+
+ return true;
+ }
+
private bool cb_window_state_event (Gdk.EventWindowState event) {
if (event.type != Gdk.EventType.WINDOW_STATE)
return false;
@@ -170,8 +190,7 @@
}
private void action_pp () {
- Xfmpc.Interface interface = (Xfmpc.Interface) get_data ("XfmpcInterface");
- interface.pp_clicked ();
+ this.interface.pp_clicked ();
}
private void action_stop () {
@@ -183,8 +202,7 @@
}
private void action_volume () {
- Xfmpc.Interface interface = (Xfmpc.Interface) get_data ("XfmpcInterface");
- interface.popup_volume ();
+ this.interface.popup_volume ();
}
private void action_statusbar (Action action) {
Modified: xfmpc/trunk/src/mpdclient.c
===================================================================
--- xfmpc/trunk/src/mpdclient.c 2009-07-08 18:32:20 UTC (rev 7698)
+++ xfmpc/trunk/src/mpdclient.c 2009-07-08 21:02:32 UTC (rev 7699)
@@ -98,6 +98,8 @@
guint port;
gchar *passwd;
gboolean env_cached;
+ gboolean connecting;
+ GMutex *mutex;
};
@@ -237,7 +239,12 @@
xfmpc_mpdclient_init (XfmpcMpdclient *mpdclient)
{
XfmpcMpdclientPrivate *priv = mpdclient->priv = GET_PRIVATE (mpdclient);
+
priv->mi = mpd_new_default ();
+
+ if (!g_thread_supported ()) g_thread_init (NULL);
+ priv->mutex = g_mutex_new ();
+
mpd_signal_connect_status_changed (priv->mi, (StatusChangedCallback)cb_status_changed, mpdclient);
}
@@ -248,6 +255,8 @@
XfmpcMpdclientPrivate *priv = XFMPC_MPDCLIENT (mpdclient)->priv;
mpd_free (priv->mi);
+ g_mutex_free (priv->mutex);
+
(*G_OBJECT_CLASS (parent_class)->finalize) (object);
}
@@ -319,24 +328,60 @@
}
}
+static gpointer
+xfmpc_mpdclient_connect_thread (XfmpcMpdclient *mpdclient)
+{
+ XfmpcMpdclientPrivate *priv = XFMPC_MPDCLIENT (mpdclient)->priv;
+ mpd_Connection *connection;
+
+ xfmpc_mpdclient_initenv (mpdclient);
+ mpd_set_hostname (priv->mi, priv->host);
+ mpd_set_port (priv->mi, priv->port);
+ mpd_set_password (priv->mi, (priv->passwd != NULL) ? priv->passwd : "");
+ mpd_set_connection_timeout (priv->mi, 5.0);
+
+ connection = mpd_newConnection (priv->host, priv->port, 5.0);
+ if (mpd_connect_real (priv->mi, connection))
+ g_warning (_("Failed to connect to MPD"));
+
+ priv->connecting = FALSE;
+
+ g_mutex_unlock (priv->mutex);
+
+ return NULL;
+}
+
gboolean
xfmpc_mpdclient_connect (XfmpcMpdclient *mpdclient)
{
XfmpcMpdclientPrivate *priv = XFMPC_MPDCLIENT (mpdclient)->priv;
+ GThread *thread;
+
if (xfmpc_mpdclient_is_connected (mpdclient))
return TRUE;
- xfmpc_mpdclient_initenv (mpdclient);
- mpd_set_hostname (priv->mi, priv->host);
- mpd_set_port (priv->mi, priv->port);
- mpd_set_password (priv->mi, (priv->passwd != NULL) ? priv->passwd : "");
-
- if (mpd_connect (priv->mi) != MPD_OK)
+ /* return FALSE if a we are already trying to connect to mpd */
+ if (!g_mutex_trylock (priv->mutex))
+ {
+ g_warning ("Already connecting to mpd");
return FALSE;
+ }
- mpd_send_password (priv->mi);
+ priv->connecting = TRUE;
+ thread = g_thread_create ((GThreadFunc) xfmpc_mpdclient_connect_thread,
+ mpdclient, TRUE, NULL);
+
+ while (priv->connecting)
+ {
+ while (gtk_events_pending ())
+ gtk_main_iteration ();
+ g_usleep (200000);
+ }
+
+ g_thread_join (thread);
+
g_signal_emit (mpdclient, signals[SIG_CONNECTED], 0);
return TRUE;
@@ -744,7 +789,7 @@
if (NULL != length)
*length = g_strdup_printf ("%d:%02d", data->song->time / 60, data->song->time % 60);
if (NULL != pos)
- *pos = data->song->pos;
+ *pos = data->song->pos;
*id = data->song->id;
}
@@ -879,6 +924,15 @@
+void
+xfmpc_mpdclient_reload (XfmpcMpdclient *mpdclient)
+{
+ g_signal_emit (mpdclient, signals[SIG_DATABASE_CHANGED], 0);
+ g_signal_emit (mpdclient, signals[SIG_PLAYLIST_CHANGED], 0);
+}
+
+
+
static gchar *
_get_formatted_name (mpd_Song *song)
{
Modified: xfmpc/trunk/src/mpdclient.h
===================================================================
--- xfmpc/trunk/src/mpdclient.h 2009-07-08 18:32:20 UTC (rev 7698)
+++ xfmpc/trunk/src/mpdclient.h 2009-07-08 21:02:32 UTC (rev 7699)
@@ -116,6 +116,8 @@
gchar **filename,
gchar **basename);
+void xfmpc_mpdclient_reload (XfmpcMpdclient *mpdclient);
+
XfmpcSongInfo * xfmpc_mpdclient_get_song_info (XfmpcMpdclient *mpdclient,
gint id);
Modified: xfmpc/trunk/src/mpdclient.vapi
===================================================================
--- xfmpc/trunk/src/mpdclient.vapi 2009-07-08 18:32:20 UTC (rev 7698)
+++ xfmpc/trunk/src/mpdclient.vapi 2009-07-08 21:02:32 UTC (rev 7699)
@@ -46,6 +46,7 @@
public bool set_volume (uchar volume);
public bool stop ();
public void update_status ();
+ public void reload ();
public virtual signal void connected ();
public virtual signal void song_changed ();
public virtual signal void pp_changed (bool is_playing);
Modified: xfmpc/trunk/src/xfmpc.h
===================================================================
--- xfmpc/trunk/src/xfmpc.h 2009-07-08 18:32:20 UTC (rev 7698)
+++ xfmpc/trunk/src/xfmpc.h 2009-07-08 21:02:32 UTC (rev 7699)
@@ -248,6 +248,8 @@
void xfmpc_interface_set_volume (XfmpcInterface* self, gint volume);
void xfmpc_interface_popup_volume (XfmpcInterface* self);
void xfmpc_interface_set_time (XfmpcInterface* self, gint time, gint time_total);
+void xfmpc_interface_clean (XfmpcInterface* self);
+void xfmpc_interface_update_title (XfmpcInterface* self);
XfmpcInterface* xfmpc_interface_new (void);
XfmpcInterface* xfmpc_interface_construct (GType object_type);
GType xfmpc_main_window_get_type (void);
More information about the Goodies-commits
mailing list