[Rhythmbox-devel] [PATCH] Allow LIRC users to specify the magnitude of seek and volume deltas
- From: Bob Ham <rah settrans net>
- To: rhythmbox-devel gnome org
- Subject: [Rhythmbox-devel] [PATCH] Allow LIRC users to specify the magnitude of seek and volume deltas
- Date: Sun, 20 Jan 2013 01:07:06 +0000
The defaults of +20s/-10s seek and +10%/-10% volume are not very
usable. Adding optional parameters to the LIRC commands allows the
user to set the values to his/her liking and increases the utility of
the plugin massively.
Signed-off-by: Bob Ham <rah settrans net>
---
plugins/lirc/rb-lirc-plugin.c | 74 ++++++++++++++++++++++++++++++++++++----
1 files changed, 66 insertions(+), 8 deletions(-)
diff --git a/plugins/lirc/rb-lirc-plugin.c b/plugins/lirc/rb-lirc-plugin.c
index fc27c98..cb51787 100644
--- a/plugins/lirc/rb-lirc-plugin.c
+++ b/plugins/lirc/rb-lirc-plugin.c
@@ -94,6 +94,64 @@ rb_lirc_plugin_init (RBLircPlugin *plugin)
}
static gboolean
+read_parameter (const char *str, gdouble *value)
+{
+ gchar *loc, *check;
+ gdouble detected;
+
+ loc = strrchr(str, ' ');
+ if (loc == NULL) {
+ return FALSE;
+ }
+
+ ++loc;
+ detected = g_ascii_strtod(loc, &check);
+ if (errno != 0 || (detected == 0 && check == loc)) {
+ return FALSE;
+ }
+
+ *value = detected;
+ return TRUE;
+}
+
+static void
+rb_lirc_plugin_seek (RBLircPlugin *plugin,
+ char *str,
+ gint32 offset,
+ gboolean negate)
+{
+ gdouble value;
+ gboolean val_present;
+
+ val_present = read_parameter(str, &value);
+ if (val_present == TRUE) {
+ offset = value;
+ }
+
+ if (negate == TRUE) {
+ offset = -offset;
+ }
+
+ rb_shell_player_seek (plugin->shell_player, offset, NULL);
+}
+
+static void
+rb_lirc_plugin_set_volume_relative (RBLircPlugin *plugin,
+ char *str,
+ gboolean negate)
+{
+ gdouble offset = 0.1;
+
+ read_parameter(str, &offset);
+
+ if (negate == TRUE) {
+ offset = -offset;
+ }
+
+ rb_shell_player_set_volume_relative (plugin->shell_player, offset, NULL);
+}
+
+static gboolean
rb_lirc_plugin_read_code (GIOChannel *source,
GIOCondition condition,
RBLircPlugin *plugin)
@@ -151,14 +209,14 @@ rb_lirc_plugin_read_code (GIOChannel *source,
rb_shell_player_do_next (plugin->shell_player, NULL);
} else if (strcmp (str, RB_IR_COMMAND_PREVIOUS) == 0) {
rb_shell_player_do_previous (plugin->shell_player, NULL);
- } else if (strcmp (str, RB_IR_COMMAND_SEEK_FORWARD) == 0) {
- rb_shell_player_seek (plugin->shell_player, FFWD_OFFSET, NULL);
- } else if (strcmp (str, RB_IR_COMMAND_SEEK_BACKWARD) == 0) {
- rb_shell_player_seek (plugin->shell_player, -RWD_OFFSET, NULL);
- } else if (strcmp (str, RB_IR_COMMAND_VOLUME_UP) == 0) {
- rb_shell_player_set_volume_relative (plugin->shell_player, 0.1, NULL);
- } else if (strcmp (str, RB_IR_COMMAND_VOLUME_DOWN) == 0) {
- rb_shell_player_set_volume_relative (plugin->shell_player, -0.1, NULL);
+ } else if (strncmp (str, RB_IR_COMMAND_SEEK_FORWARD, strlen(RB_IR_COMMAND_SEEK_FORWARD)) == 0) {
+ rb_lirc_plugin_seek(plugin, str, FFWD_OFFSET, FALSE);
+ } else if (strncmp (str, RB_IR_COMMAND_SEEK_BACKWARD, strlen(RB_IR_COMMAND_SEEK_BACKWARD)) == 0) {
+ rb_lirc_plugin_seek(plugin, str, RWD_OFFSET, TRUE);
+ } else if (strncmp (str, RB_IR_COMMAND_VOLUME_UP, strlen(RB_IR_COMMAND_VOLUME_UP)) == 0) {
+ rb_lirc_plugin_set_volume_relative(plugin, str, FALSE);
+ } else if (strncmp (str, RB_IR_COMMAND_VOLUME_DOWN, strlen(RB_IR_COMMAND_VOLUME_DOWN)) == 0) {
+ rb_lirc_plugin_set_volume_relative(plugin, str, TRUE);
} else if (strcmp (str, RB_IR_COMMAND_MUTE) == 0) {
gboolean mute;
if (rb_shell_player_get_mute (plugin->shell_player, &mute, NULL)) {
--
1.7.2.5
[
Date Prev][Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]