From 800dae3414221aaac3725f9e4b5d40b5d56bad69 Mon Sep 17 00:00:00 2001 From: Alexander Yakushev Date: Tue, 2 Nov 2010 01:07:57 +0200 Subject: Minor fixes with characters escaping. Options still not fully operational. --- awesompd.lua | 53 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/awesompd.lua b/awesompd.lua index a12e52d..7afff96 100644 --- a/awesompd.lua +++ b/awesompd.lua @@ -98,6 +98,7 @@ end function awesompd:run() self:update_track() self:update_state() + self:check_playlists() awful.hooks.timer.register(1, function () self:update_widget() end) awful.hooks.timer.register(self.update_interval, function () self:update_track() end) end @@ -209,6 +210,12 @@ function awesompd:command_consume_toggle() end end +function awesompd:command_load_playlist(name) + return function() + self:command("load " .. name, function() self.recreate_menu = true end) + end +end + function awesompd:command_echo_prompt() return function() self:run_prompt("Sample text: ",function(s) @@ -235,7 +242,7 @@ function awesompd:command_show_menu() table.insert(new_menu, { "Playback", self:get_playback_menu() }) table.insert(new_menu, { "Options", self:get_options_menu() }) table.insert(new_menu, { "List", self:get_list_menu() }) - -- table.insert(new_menu, { "Playlists", self:get_playlists_menu() }) + table.insert(new_menu, { "Playlists", self:get_playlists_menu() }) end table.insert(new_menu, { "Servers", self:get_servers_menu() }) self.main_menu = awful.menu({ items = new_menu, @@ -258,11 +265,11 @@ function awesompd:get_playback_menu() table.insert(new_menu, { "Play\\Pause", self:command_toggle(), self.ICONS.PLAY_PAUSE }) if self.connected and self.status ~= "Stopped" then if self.current_number ~= 1 then - table.insert(new_menu, { "Prev: " .. self.list_array[self.current_number - 1], + table.insert(new_menu, { "Prev: " .. awesompd.protect_string(self.list_array[self.current_number - 1]), self:command_prev_track(), self.ICONS.PREV }) end if self.current_number ~= table.getn(self.list_array) then - table.insert(new_menu, { "Next: " .. self.list_array[self.current_number + 1], + table.insert(new_menu, { "Next: " .. awesompd.protect_string(self.list_array[self.current_number + 1]), self:command_next_track(), self.ICONS.NEXT }) end table.insert(new_menu, { "Stop", self:command_stop(), self.ICONS.STOP }) @@ -279,11 +286,11 @@ function awesompd:get_list_menu() local new_menu = {} if self.list_array then for i = 1, table.getn(self.list_array) do - new_menu[i] = {self.list_array[i], - self:command_play_specific(i), - self.current_number == i and - (self.status == "Playing" and self.ICONS.PLAY or self.ICONS.PAUSE) - or nil} + new_menu[i] = { awesompd.protect_string(self.list_array[i]), + self:command_play_specific(i), + self.current_number == i and + (self.status == "Playing" and self.ICONS.PLAY or self.ICONS.PAUSE) + or nil} end end self.recreate_list = false @@ -292,6 +299,24 @@ function awesompd:get_list_menu() return self.list_menu end +-- Returns the playlists menu. Menu consists of all files in the playlist folder. +function awesompd:get_playlists_menu() + if self.recreate_playlists then + local new_menu = {} + if table.getn(self.playlists_array) > 0 then + for i = 1, table.getn(self.playlists_array) do + new_menu[i] = { self.playlists_array[i], + self:command_load_playlist(self.playlists_array[i]) } + end + table.insert(new_menu, {"", ""}) -- This is a separator + end + table.insert(new_menu, { "Refresh", function() self:check_playlists() end }) + self.recreate_playlists = false + self.playlists_menu = new_menu + end + return self.playlists_menu +end + -- Returns the server menu. Menu consists of all servers specified by user during initialization. function awesompd:get_servers_menu() if self.recreate_servers then @@ -350,6 +375,11 @@ function awesompd:check_playlists() bus:close() if info ~= self.playlists_line then self.playlists_line = info + if string.len(info) > 0 then + self.playlists_array = self.split(info,"\n") + else + self.playlists_array = {} + end self.recreate_menu = true self.recreate_playlists = true end @@ -408,7 +438,6 @@ function awesompd:notify_state(state_changed) end function awesompd:wrap_output(text) --- local t = utf8replace(text, awesompd.ESCAPE_SYMBOL_MAPPING) return '| ' .. text .. ' |' end @@ -510,7 +539,7 @@ function awesompd:update_track() self.recreate_list = true end else - local new_track = utf8replace(info_ar[1], awesompd.ESCAPE_SYMBOL_MAPPING) + local new_track = awesompd.protect_string(info_ar[1]) if new_track ~= self.text then self.text = new_track self.to_notify = true @@ -577,3 +606,7 @@ function awesompd:run_prompt(welcome,hook) self.promptbox[mouse.screen].widget, hook) end + +function awesompd.protect_string(str) + return utf8replace(str, awesompd.ESCAPE_SYMBOL_MAPPING) +end -- cgit v1.2.3 From 81bf847c85fe5ace93f85fbeabc3e526dd5510ca Mon Sep 17 00:00:00 2001 From: Alexander Yakushev Date: Thu, 4 Nov 2010 17:17:35 +0200 Subject: New feature: playlists. Options fixed. Options are now implemented without creating an overhead. --- awesompd.lua | 81 +++++++++++++++++++++++++++++------------------------------- 1 file changed, 39 insertions(+), 42 deletions(-) diff --git a/awesompd.lua b/awesompd.lua index 7afff96..1746077 100644 --- a/awesompd.lua +++ b/awesompd.lua @@ -97,7 +97,7 @@ end -- Registers timers for the widget function awesompd:run() self:update_track() - self:update_state() +-- self:update_state() self:check_playlists() awful.hooks.timer.register(1, function () self:update_widget() end) awful.hooks.timer.register(self.update_interval, function () self:update_track() end) @@ -170,42 +170,42 @@ end function awesompd:command_volume_up() return function() - self:command("volume +5",self.update_state) + self:command("volume +5",self.update_track) self:notify_state(self.NOTIFY_VOLUME) end end function awesompd:command_volume_down() return function() - self:command("volume -5",self.update_state) + self:command("volume -5",self.update_track) self:notify_state(self.NOTIFY_VOLUME) end end function awesompd:command_random_toggle() return function() - self:command("random",self.update_state) + self:command("random",self.update_track) self:notify_state(self.NOTIFY_RANDOM) end end function awesompd:command_repeat_toggle() return function() - self:command("repeat",self.update_state) + self:command("repeat",self.update_track) self:notify_state(self.NOTIFY_REPEAT) end end function awesompd:command_single_toggle() return function() - self:command("single",self.update_state) + self:command("single",self.update_track) self:notify_state(self.NOTIFY_SINGLE) end end function awesompd:command_consume_toggle() return function() - self:command("consume",self.update_state) + self:command("consume",self.update_track) self:notify_state(self.NOTIFY_CONSUME) end end @@ -336,7 +336,7 @@ end function awesompd:get_options_menu() if self.recreate_options then local new_menu = {} - self:update_state() +-- self:update_state() table.insert(new_menu, { "Repeat", self:command_repeat_toggle(), self.state_repeat == "on" and self.ICONS.CHECK or nil}) table.insert(new_menu, { "Random", self:command_random_toggle(), @@ -346,9 +346,9 @@ function awesompd:get_options_menu() table.insert(new_menu, { "Consume", self:command_consume_toggle(), self.state_consume == "on" and self.ICONS.CHECK or nil}) self.options_menu = new_menu - self.recreate_options = false - return self.options_menu + self.recreate_options = false end + return self.options_menu end -- Checks if the current playlist has changed after the last check. @@ -395,7 +395,7 @@ function awesompd:change_server(server_number) self.recreate_playlists = true self.recreate_servers = true self:update_track() - self:update_state() +-- self:update_state() end -- /// End of menu generation functions /// @@ -529,6 +529,7 @@ function awesompd:update_track() self.connected = true self.recreate_menu = true end + self:update_state(info) if string.find(info_ar[1],"volume:") then self.text = "MPD stopped" if self.status ~= "Stopped" then @@ -565,40 +566,36 @@ function awesompd:update_track() end -function awesompd:update_state() - if self.connected then - local bus = io.popen(self:mpcquery()) - local info = bus:read("*all") - bus:close() - local info_ar = self.split(info,"\n") - state_string = info_ar[3] - if string.find(info_ar[1],"volume:") then - state_string = info_ar[1] - end - self.state_volume = self.find_pattern(state_string,"%d+%% ") - if string.find(state_string,"repeat: on") then - self.state_repeat = "on" - else - self.state_repeat = "off" - end - if string.find(state_string,"random: on") then - self.state_random = "on" - else - self.state_random = "off" - end - if string.find(state_string,"single: on") then - self.state_single = "on" - else - self.state_single = "off" - end - if string.find(state_string,"consume: on") then - self.state_consume = "on" - else - self.state_consume = "off" - end +function awesompd:update_state(state_string) + self.state_volume = self.find_pattern(state_string,"%d+%% ") + if string.find(state_string,"repeat: on") then + self.state_repeat = self:check_set_state(self.state_repeat, "on") + else + self.state_repeat = self:check_set_state(self.state_repeat, "off") + end + if string.find(state_string,"random: on") then + self.state_random = self:check_set_state(self.state_random, "on") + else + self.state_random = self:check_set_state(self.state_random, "off") + end + if string.find(state_string,"single: on") then + self.state_single = self:check_set_state(self.state_single, "on") + else + self.state_single = self:check_set_state(self.state_single, "off") + end + if string.find(state_string,"consume: on") then + self.state_consume = self:check_set_state(self.state_consume, "on") + else + self.state_consume = self:check_set_state(self.state_consume, "off") + end +end + +function awesompd:check_set_state(statevar, val) + if statevar ~= val then self.recreate_menu = true self.recreate_options = true end + return val end function awesompd:run_prompt(welcome,hook) -- cgit v1.2.3 From 66fcaca495eae424bd0613ffad1264c3bb865826 Mon Sep 17 00:00:00 2001 From: Alexander Yakushev Date: Thu, 4 Nov 2010 17:29:21 +0200 Subject: Playlist add\replace --- awesompd.lua | 14 ++++++++++++-- release | 3 --- 2 files changed, 12 insertions(+), 5 deletions(-) delete mode 100755 release diff --git a/awesompd.lua b/awesompd.lua index 1746077..6481dc9 100644 --- a/awesompd.lua +++ b/awesompd.lua @@ -216,6 +216,14 @@ function awesompd:command_load_playlist(name) end end +function awesompd:command_replace_playlist(name) + return function() + self:command("clear") + self:command("load " .. name) + self:command("play 1", self.update_track) + end +end + function awesompd:command_echo_prompt() return function() self:run_prompt("Sample text: ",function(s) @@ -305,8 +313,10 @@ function awesompd:get_playlists_menu() local new_menu = {} if table.getn(self.playlists_array) > 0 then for i = 1, table.getn(self.playlists_array) do - new_menu[i] = { self.playlists_array[i], - self:command_load_playlist(self.playlists_array[i]) } + local submenu = {} + submenu[1] = { "Add to current", self:command_load_playlist(self.playlists_array[i]) } + submenu[2] = { "Replace current", self:command_replace_playlist(self.playlists_array[i]) } + new_menu[i] = { self.playlists_array[i], submenu } end table.insert(new_menu, {"", ""}) -- This is a separator end diff --git a/release b/release deleted file mode 100755 index 6d3edbc..0000000 --- a/release +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -cp -f ~/work/projects/Lua/awesompd/awesompd.lua ~/.config/awesome/awesompd.lua -cp -f ~/work/projects/Lua/awesompd/utf8.lua ~/.config/awesome/utf8.lua \ No newline at end of file -- cgit v1.2.3 From da3707e4c53331e1618a911a88a65ff467ef8594 Mon Sep 17 00:00:00 2001 From: Alexander Yakushev Date: Thu, 4 Nov 2010 18:47:48 +0200 Subject: Reworked current playlist Now it displays at maximum 15 tracks before and 15 tracks after the current track. --- awesompd.lua | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/awesompd.lua b/awesompd.lua index 7d49bc0..ac864a9 100644 --- a/awesompd.lua +++ b/awesompd.lua @@ -293,12 +293,15 @@ function awesompd:get_list_menu() if self.recreate_list then local new_menu = {} if self.list_array then - for i = 1, table.getn(self.list_array) do - new_menu[i] = { awesompd.protect_string(self.list_array[i]), - self:command_play_specific(i), - self.current_number == i and - (self.status == "Playing" and self.ICONS.PLAY or self.ICONS.PAUSE) - or nil} + local total_count = table.getn(self.list_array) + local start_num = (self.current_number - 15 > 0) and self.current_number - 15 or 1 + local end_num = (self.current_number + 15 < total_count ) and self.current_number + 15 or total_count + for i = start_num, end_num do + table.insert(new_menu, { awesompd.protect_string(self.list_array[i]), + self:command_play_specific(i), + self.current_number == i and + (self.status == "Playing" and self.ICONS.PLAY or self.ICONS.PAUSE) + or nil} ) end end self.recreate_list = false @@ -306,7 +309,7 @@ function awesompd:get_list_menu() end return self.list_menu end - + -- Returns the playlists menu. Menu consists of all files in the playlist folder. function awesompd:get_playlists_menu() if self.recreate_playlists then -- cgit v1.2.3