changeset 1241:cbd7a81ac8ea

merge again
author Cristi Magherusan <majeru@atheme-project.org>
date Thu, 12 Jul 2007 02:08:10 +0300
parents d4501b0e98b4 (current diff) 5d9fb703a7cc (diff)
children 5e41a7affccb
files
diffstat 1 files changed, 85 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/aosd/aosd_trigger.c	Thu Jul 12 02:07:09 2007 +0300
+++ b/src/aosd/aosd_trigger.c	Thu Jul 12 02:08:10 2007 +0300
@@ -26,6 +26,7 @@
 #include <audacious/playlist.h>
 #include <audacious/strings.h>
 #include <audacious/hook.h>
+#include <audacious/auddrct.h>
 
 
 extern aosd_cfg_t * global_config;
@@ -36,18 +37,22 @@
 {
   AOSD_TRIGGER_PB_START = 0,
   AOSD_TRIGGER_PB_TITLECHANGE = 1,
-  AOSD_TRIGGER_VOL_CHANGE = 2
+  AOSD_TRIGGER_VOL_CHANGE = 2,
+  AOSD_TRIGGER_PB_PAUSEON = 3,
+  AOSD_TRIGGER_PB_PAUSEOFF = 4
 };
 
 /* trigger codes array size */
-#define AOSD_TRIGGER_CODES_ARRAY_SIZE 3
+#define AOSD_TRIGGER_CODES_ARRAY_SIZE 5
 
 /* trigger codes array */
 gint aosd_trigger_codes[] =
 {
   AOSD_TRIGGER_PB_START,
   AOSD_TRIGGER_PB_TITLECHANGE,
-  AOSD_TRIGGER_VOL_CHANGE
+  AOSD_TRIGGER_VOL_CHANGE,
+  AOSD_TRIGGER_PB_PAUSEON,
+  AOSD_TRIGGER_PB_PAUSEOFF
 };
 
 /* prototypes of trigger functions */
@@ -57,6 +62,10 @@
 static void aosd_trigger_func_pb_titlechange_cb ( gpointer , gpointer );
 static void aosd_trigger_func_vol_change_onoff ( gboolean );
 static void aosd_trigger_func_vol_change_cb ( gpointer , gpointer );
+static void aosd_trigger_func_pb_pauseon_onoff ( gboolean );
+static void aosd_trigger_func_pb_pauseon_cb ( gpointer , gpointer );
+static void aosd_trigger_func_pb_pauseoff_onoff ( gboolean );
+static void aosd_trigger_func_pb_pauseoff_cb ( gpointer , gpointer );
 
 /* map trigger codes to trigger objects */
 aosd_trigger_t aosd_triggers[] =
@@ -76,7 +85,17 @@
   [AOSD_TRIGGER_VOL_CHANGE] = { N_("Volume Change") ,
                                 N_("Triggers OSD when volume is changed.") ,
                                 aosd_trigger_func_vol_change_onoff ,
-                                aosd_trigger_func_vol_change_cb }
+                                aosd_trigger_func_vol_change_cb },
+
+  [AOSD_TRIGGER_PB_PAUSEON] = { N_("Pause On") ,
+                                N_("Triggers OSD when playback is paused.") ,
+                                aosd_trigger_func_pb_pauseon_onoff ,
+                                aosd_trigger_func_pb_pauseon_cb },
+
+  [AOSD_TRIGGER_PB_PAUSEOFF] = { N_("Pause Off") ,
+                                 N_("Triggers OSD when playback is unpaused.") ,
+                                 aosd_trigger_func_pb_pauseoff_onoff ,
+                                 aosd_trigger_func_pb_pauseoff_cb }
 };
 
 
@@ -162,7 +181,7 @@
   PlaylistEntry *pl_entry = plentry_gp;
   if ( plentry_gp != NULL )
   {
-    gchar *title;
+    gchar *title, *utf8_title;
     if ( pl_entry->title != NULL )
     {
       /* if there is a proper title, use it */
@@ -175,7 +194,7 @@
       gint pos = playlist_get_position(active);
       title = playlist_get_songtitle(active, pos);
     }
-    gchar *utf8_title = aosd_trigger_utf8convert( title );
+    utf8_title = aosd_trigger_utf8convert( title );
     if ( g_utf8_validate( utf8_title , -1 , NULL ) == TRUE )
     {
       gchar *utf8_title_markup = g_markup_printf_escaped(
@@ -333,3 +352,63 @@
   }
   return;
 }
+
+
+static void
+aosd_trigger_func_pb_pauseon_onoff ( gboolean turn_on )
+{
+  if ( turn_on == TRUE )
+    hook_associate( "playback pause" , aosd_trigger_func_pb_pauseon_cb , NULL );
+  else
+    hook_dissociate( "playback pause" , aosd_trigger_func_pb_pauseon_cb );
+  return;
+}
+
+static void
+aosd_trigger_func_pb_pauseon_cb ( gpointer unused1 , gpointer unused2 )
+{
+  gchar *utf8_title_markup = g_markup_printf_escaped(
+    "<span font_desc='%s'>Paused</span>" , global_config->osd->text.fonts_name[0] );
+  aosd_osd_display( utf8_title_markup , global_config->osd , FALSE );
+  g_free( utf8_title_markup );
+  return;
+}
+
+
+static void
+aosd_trigger_func_pb_pauseoff_onoff ( gboolean turn_on )
+{
+  if ( turn_on == TRUE )
+    hook_associate( "playback unpause" , aosd_trigger_func_pb_pauseoff_cb , NULL );
+  else
+    hook_dissociate( "playback unpause" , aosd_trigger_func_pb_pauseoff_cb );
+  return;
+}
+
+static void
+aosd_trigger_func_pb_pauseoff_cb ( gpointer unused1 , gpointer unused2 )
+{
+  Playlist *active = playlist_get_active();
+  gint pos = playlist_get_position(active);
+  gchar *title, *utf8_title, *utf8_title_markup;
+  gint time_cur, time_tot;
+  gint time_cur_m, time_cur_s, time_tot_m, time_tot_s;
+
+  time_tot = playlist_get_songtime(active, pos) / 1000;
+  time_cur = audacious_drct_get_time() / 1000;
+  time_cur_s = time_cur % 60;
+  time_cur_m = (time_cur - time_cur_s) / 60;
+  time_tot_s = time_tot % 60;
+  time_tot_m = (time_tot - time_tot_s) / 60;
+
+  title = playlist_get_songtitle(active, pos);
+  utf8_title = aosd_trigger_utf8convert( title );
+  utf8_title_markup = g_markup_printf_escaped(
+    "<span font_desc='%s'>%s (%i:%02i/%i:%02i)</span>" ,
+    global_config->osd->text.fonts_name[0] , utf8_title , time_cur_m , time_cur_s , time_tot_m , time_tot_s );
+  aosd_osd_display( utf8_title_markup , global_config->osd , FALSE );
+  g_free( utf8_title_markup );
+  g_free( utf8_title );
+  g_free( title );
+  return;
+}