changeset 4359:0becb809bdc9

moved most GUI-related functions from playback.c to ui_main_evlisteners.c this change enables basic, working headless mode in X!
author mf0102 <0102@gmx.at>
date Mon, 17 Mar 2008 23:47:24 +0100
parents 6478692415a0
children 313dd79a2d24
files src/audacious/playback.c src/audacious/playlist_evlisteners.c src/audacious/ui_main_evlisteners.c
diffstat 3 files changed, 114 insertions(+), 87 deletions(-) [+]
line wrap: on
line diff
--- a/src/audacious/playback.c	Mon Mar 17 23:52:19 2008 +0300
+++ b/src/audacious/playback.c	Mon Mar 17 23:47:24 2008 +0100
@@ -40,39 +40,18 @@
 #include <dirent.h>
 
 #include "configdb.h"
-
 #include "eventqueue.h"
 #include "hook.h"
 #include "input.h"
-#include "main.h"
 #include "output.h"
 #include "playlist.h"
 #include "pluginenum.h"
-#include "skin.h"
 #include "ui_equalizer.h"
-#include "ui_main.h"
-#include "ui_skinned_playstatus.h"
 #include "util.h"
-#include "visualization.h"
 
 #include "playback.h"
 #include "playback_evlisteners.h"
 
-static gint song_info_timeout_source = 0;
-static gint update_vis_timeout_source = 0;
-
-/* XXX: there has to be a better way than polling here! */
-static gboolean
-playback_update_vis_func(gpointer unused)
-{
-    if (!playback_get_playing())
-        return FALSE;
-
-    input_update_vis(playback_get_time());
-
-    return TRUE;
-}
-
 static gint
 playback_set_pb_ready(InputPlayback *playback)
 {
@@ -194,10 +173,6 @@
     if (playback_get_playing())
         playback_stop();
 
-    ui_vis_clear_data(mainwin_vis);
-    ui_svis_clear_data(mainwin_svis);
-    mainwin_disable_seekbar();
-
     entry = playlist_get_entry_to_play(playlist);
     g_return_if_fail(entry != NULL);
 #ifdef USE_DBUS
@@ -214,29 +189,6 @@
 //    }
 
     playlist_check_pos_current(playlist);
-    mainwin_update_song_info();
-
-    /* FIXME: use g_timeout_add_seconds when glib-2.14 is required */
-    song_info_timeout_source = g_timeout_add(1000,
-        (GSourceFunc) mainwin_update_song_info, NULL);
-
-    update_vis_timeout_source = g_timeout_add(10,
-        (GSourceFunc) playback_update_vis_func, NULL);
-
-    if (cfg.player_shaded) {
-        gtk_widget_show(mainwin_stime_min);
-        gtk_widget_show(mainwin_stime_sec);
-        gtk_widget_show(mainwin_sposition);
-    } else {
-        gtk_widget_show(mainwin_minus_num);
-        gtk_widget_show(mainwin_10min_num);
-        gtk_widget_show(mainwin_min_num);
-        gtk_widget_show(mainwin_10sec_num);
-        gtk_widget_show(mainwin_sec_num);
-        gtk_widget_show(mainwin_position);
-    }
-
-    vis_playback_start();
 
     hook_call("playback begin", entry);
 }
@@ -265,19 +217,12 @@
     else
         hook_call("playback unpause", NULL);
 
-    g_return_if_fail(mainwin_playstatus != NULL);
-
-    if (ip_data.paused) {
-        ui_skinned_playstatus_set_status(mainwin_playstatus, STATUS_PAUSE);
 #ifdef USE_DBUS
+    if (ip_data.paused)
         mpris_emit_status_change(mpris, MPRIS_STATUS_PAUSE);
-#endif
-    } else {
-        ui_skinned_playstatus_set_status(mainwin_playstatus, STATUS_PLAY);
-#ifdef USE_DBUS
+    else
         mpris_emit_status_change(mpris, MPRIS_STATUS_PLAY);
 #endif
-    }
 }
 
 void
@@ -309,10 +254,10 @@
         playback->set_pb_change(playback);
 
         if (playback->plugin->stop)
-	{
-	    plugin_set_current((Plugin *)(playback->plugin));
+        {
+            plugin_set_current((Plugin *)(playback->plugin));
             playback->plugin->stop(playback);
-	}
+        }
 
         if (playback->thread != NULL)
         {
@@ -320,7 +265,6 @@
             playback->thread = NULL;
         }
 
-        free_vis_data();
         ip_data.paused = FALSE;
 
         playback_free(playback);
@@ -332,13 +276,7 @@
 
     ip_data.playing = FALSE;
 
-    if (song_info_timeout_source)
-        g_source_remove(song_info_timeout_source);
-
-    vis_playback_stop();
-
-    g_return_if_fail(mainwin_playstatus != NULL);
-    ui_skinned_playstatus_set_buffering(mainwin_playstatus, FALSE);
+    hook_call("playback stop", NULL);
 }
 
 static void
@@ -443,9 +381,6 @@
         return FALSE;
     }
 
-    if (cfg.random_skin_on_play)
-        skin_set_random_skin();
-
     if (!entry->decoder)
     {
         ProbeResult *pr = input_check_file(entry->filename, FALSE);
@@ -484,6 +419,8 @@
     mpris_emit_status_change(mpris, MPRIS_STATUS_PLAY);
 #endif
 
+    hook_call("playback play file", NULL);
+
     return TRUE;
 }
 
@@ -524,7 +461,6 @@
     plugin_set_current((Plugin *)(playback->plugin));
     playback->plugin->seek(playback, time);
     playback->set_pb_change(playback);
-    free_vis_data();
     
     if (restore_pause)
     {
--- a/src/audacious/playlist_evlisteners.c	Mon Mar 17 23:52:19 2008 +0300
+++ b/src/audacious/playlist_evlisteners.c	Mon Mar 17 23:47:24 2008 +0100
@@ -20,23 +20,10 @@
 
 #include <glib.h>
 #include "hook.h"
-#include "playback.h"
 #include "playlist.h"
-#include "playlist_evmessages.h"
-#include "playlist_evlisteners.h"
-
-#include "ui_main.h"
 #include "ui_playlist.h"
 
-static void
-playlist_evlistener_playlist_info_change(gpointer hook_data, gpointer user_data)
-{
-     PlaylistEventInfoChange *msg = (PlaylistEventInfoChange *) hook_data;
-
-     mainwin_set_song_info(msg->bitrate, msg->samplerate, msg->channels);
-
-     g_free(msg);
-}
+#include "playlist_evlisteners.h"
 
 static void
 playlist_evlistener_playlistwin_update_list(gpointer hook_data, gpointer user_data)
@@ -48,6 +35,5 @@
 
 void playlist_evlistener_init(void)
 {
-     hook_associate("playlist info change", playlist_evlistener_playlist_info_change, NULL);
      hook_associate("playlistwin update list", playlist_evlistener_playlistwin_update_list, NULL);
 }
--- a/src/audacious/ui_main_evlisteners.c	Mon Mar 17 23:52:19 2008 +0300
+++ b/src/audacious/ui_main_evlisteners.c	Mon Mar 17 23:47:24 2008 +0100
@@ -26,12 +26,30 @@
 #include "playlist.h"
 #include "playlist_evmessages.h"
 #include "playlist_evlisteners.h"
+#include "visualization.h"
 
 #include "ui_main.h"
 #include "ui_equalizer.h"
+#include "ui_skinned_playstatus.h"
 #include "ui_skinned_textbox.h"
 #include "ui_playlist.h"
 
+static gint song_info_timeout_source = 0;
+static gint update_vis_timeout_source = 0;
+
+/* XXX: there has to be a better way than polling here! */
+/* also: where should this function go? should it stay here? --mf0102 */
+static gboolean
+update_vis_func(gpointer unused)
+{
+    if (!playback_get_playing())
+        return FALSE;
+
+    input_update_vis(playback_get_time());
+
+    return TRUE;
+}
+
 static void
 ui_main_evlistener_title_change(gpointer hook_data, gpointer user_data)
 {
@@ -76,6 +94,86 @@
     playback_initiate();
 }
 
+static void
+ui_main_evlistener_playback_begin(gpointer hook_data, gpointer user_data)
+{
+    ui_vis_clear_data(mainwin_vis);
+    ui_svis_clear_data(mainwin_svis);
+    mainwin_disable_seekbar();
+    mainwin_update_song_info();
+
+    /* FIXME: use g_timeout_add_seconds when glib-2.14 is required */
+    song_info_timeout_source = g_timeout_add(1000,
+        (GSourceFunc) mainwin_update_song_info, NULL);
+
+    if (cfg.player_shaded) {
+        gtk_widget_show(mainwin_stime_min);
+        gtk_widget_show(mainwin_stime_sec);
+        gtk_widget_show(mainwin_sposition);
+    } else {
+        gtk_widget_show(mainwin_minus_num);
+        gtk_widget_show(mainwin_10min_num);
+        gtk_widget_show(mainwin_min_num);
+        gtk_widget_show(mainwin_10sec_num);
+        gtk_widget_show(mainwin_sec_num);
+        gtk_widget_show(mainwin_position);
+    }
+
+    update_vis_timeout_source = g_timeout_add(10,
+    (GSourceFunc) update_vis_func, NULL);
+
+    vis_playback_start();
+
+    ui_skinned_playstatus_set_status(mainwin_playstatus, STATUS_PLAY);
+}
+
+static void
+ui_main_evlistener_playback_stop(gpointer hook_data, gpointer user_data)
+{
+    if (song_info_timeout_source)
+        g_source_remove(song_info_timeout_source);
+
+    vis_playback_stop();
+    free_vis_data();
+
+    ui_skinned_playstatus_set_buffering(mainwin_playstatus, FALSE);
+}
+
+static void
+ui_main_evlistener_playback_pause(gpointer hook_data, gpointer user_data)
+{
+    ui_skinned_playstatus_set_status(mainwin_playstatus, STATUS_PAUSE);
+}
+
+static void
+ui_main_evlistener_playback_unpause(gpointer hook_data, gpointer user_data)
+{
+    ui_skinned_playstatus_set_status(mainwin_playstatus, STATUS_PLAY);
+}
+
+static void
+ui_main_evlistener_playback_seek(gpointer hook_data, gpointer user_data)
+{
+    free_vis_data();
+}
+
+static void
+ui_main_evlistener_playback_play_file(gpointer hook_data, gpointer user_data)
+{
+    if (cfg.random_skin_on_play)
+        skin_set_random_skin();
+}
+
+static void
+ui_main_evlistener_playlist_info_change(gpointer hook_data, gpointer user_data)
+{
+     PlaylistEventInfoChange *msg = (PlaylistEventInfoChange *) hook_data;
+
+     mainwin_set_song_info(msg->bitrate, msg->samplerate, msg->channels);
+
+     g_free(msg);
+}
+
 void
 ui_main_evlistener_init(void)
 {
@@ -83,5 +181,12 @@
     hook_associate("hide seekbar", ui_main_evlistener_hide_seekbar, NULL);
     hook_associate("volume set", ui_main_evlistener_volume_change, NULL);
     hook_associate("playback initiate", ui_main_evlistener_playback_initiate, NULL);
+    hook_associate("playback begin", ui_main_evlistener_playback_begin, NULL);
+    hook_associate("playback stop", ui_main_evlistener_playback_stop, NULL);
+    hook_associate("playback pause", ui_main_evlistener_playback_pause, NULL);
+    hook_associate("playback unpause", ui_main_evlistener_playback_unpause, NULL);
+    hook_associate("playback seek", ui_main_evlistener_playback_seek, NULL);
+    hook_associate("playback play file", ui_main_evlistener_playback_play_file, NULL);
+    hook_associate("playlist info change", ui_main_evlistener_playlist_info_change, NULL);
 }