From: Tilman Sauerbeck Date: Sat, 11 Mar 2006 19:44:09 +0000 (+0000) Subject: Initial commit. X-Git-Tag: snett-0.0.1 X-Git-Url: http://git.code-monkey.de/?p=snett.git;a=commitdiff_plain;h=20a59e99a83be8c5de5b1c63be4676b08ec2a1d9 Initial commit. --- 20a59e99a83be8c5de5b1c63be4676b08ec2a1d9 diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..5864b3d --- /dev/null +++ b/AUTHORS @@ -0,0 +1 @@ +Tilman Sauerbeck (tilman at code-monkey de) diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..77ff64a --- /dev/null +++ b/COPYING @@ -0,0 +1,20 @@ +Copyright (c) 2006 Tilman Sauerbeck (tilman at code-monkey de) + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..7d06ba7 --- /dev/null +++ b/Rakefile @@ -0,0 +1,33 @@ +require "rake/packagetask" +require "rake/contrib/sshpublisher" + +PKG_NAME = "snett" +PKG_VERSION = File.read("bin/snett"). + match(/^\s*VERSION = \"(.*)\"\s$/).captures.first + +task :install do + destdir = ENV["DESTDIR"] || "" + prefix = ENV["PREFIX"] || "/usr/local" + + ddir = destdir + prefix + "/bin" + + FileUtils::Verbose.mkdir_p(ddir) unless File.directory?(ddir) + FileUtils::Verbose.install("bin/snett", ddir, :mode => 0755) + + ddir = destdir + prefix + "/share/snett" + + FileUtils::Verbose.mkdir_p(ddir) unless File.directory?(ddir) + FileUtils::Verbose.install(Dir["data/*"], ddir, :mode => 0644) +end + +Rake::PackageTask.new(PKG_NAME, PKG_VERSION) do |t| + t.need_tar_gz = true + t.package_files.include("[A-Z]*", "bin/snett", "data/logo*") +end + +task :publish => [:package] do + Rake::SshFilePublisher. + new("code-monkey.de", ".", + "pkg", "#{PKG_NAME}-#{PKG_VERSION}.tar.gz"). + upload +end diff --git a/bin/snett b/bin/snett new file mode 100755 index 0000000..ff053df --- /dev/null +++ b/bin/snett @@ -0,0 +1,277 @@ +#!/usr/bin/env ruby + +# vim:syn=ruby +# +# Copyright (c) 2006 Tilman Sauerbeck (tilman at code-monkey de) +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +require "gtk2" +require "xmmsclient" +require "xmmsclient_glib" +require "singleton" +require "pp" + +PKG_NAME = "snett" +DATADIR = "/usr/local/share/#{PKG_NAME}/" +SIZE = 64 + +class Gtk::MenuItem + def set_callback(meth, args = []) + args.unshift(meth) + + signal_connect("button_release_event") do + Snett::Snett.instance.xmms.send(*args) + false + end + end +end + +class XmmsClient::XmmsClient + def playback_next + playlist_set_next_rel(1).notifier { playback_tickle } + end + + def playback_prev + playlist_set_next_rel(-1).notifier { playback_tickle } + end +end + +module Snett + VERSION = "0.0.1" + + class Snett < Gtk::Window + attr_reader :icon, :xmms + + include Singleton + + def initialize + super(Gtk::Window::TOPLEVEL) + + @menu = nil + @tooltips = Gtk::Tooltips.new + + @xmms = XmmsClient::XmmsClient.new(PKG_NAME) + @xmms.connect(ENV["XMMS_PATH"]) + @xmms.add_to_glib_mainloop + + @broadcasts = [] + + self.set_title(PKG_NAME) + + signal_connect("destroy") do + @broadcasts.each { |bc| bc.disconnect } + + Gtk.main_quit + end + + self.resizable = false + self.decorated = false + + @icon = Gdk::Pixbuf.new(DATADIR + "logo#{SIZE}.png") + + self.resize(@icon.width, @icon.height) + + #self.colormap = self.screen.rgba_colormap + + pixmap, mask = @icon.render_pixmap_and_mask(self.colormap, 255) + self.shape_combine_mask(mask, 0, 0) + + # load icon and put it in an eventbox + event_box = Gtk::EventBox.new.add(Gtk::Image.new(@icon)) + event_box.events = Gdk::Event::BUTTON_PRESS_MASK | + Gdk::Event::BUTTON_RELEASE_MASK + + event_box.signal_connect("button_release_event") do |_, event| + menu.popup(event) if event.button == 3 + false + end + + event_box.signal_connect("button_press_event") do |_, event| + if event.button == 1 + x, y = Gdk::Display.default.pointer[1, 2] + self.begin_move_drag(event.button, x, y, event.time) + end + + false + end + + @broadcasts << @xmms.broadcast_playback_current_id + @broadcasts.last.notifier(&method(:on_playback_current_id)) + + @xmms.playback_current_id. + notifier(&method(:on_playback_current_id)) + + add(event_box) + end + + private + def menu + @menu ||= Menu.new + end + + def on_playback_current_id(res) + return if res.value.zero? + + @xmms.medialib_get_info(res.value). + notifier(&method(:on_mlib_get_info)) + end + + def on_mlib_get_info(res) + info = res.value[:server] + + s = "%s - %s" % [info[:artist], info[:title]] + @tooltips.set_tip(self, s, nil) + end + end + + class Menu < Gtk::Menu + def initialize + super + + [ + [Gtk::Stock::MEDIA_PLAY, :playback_start], + [Gtk::Stock::MEDIA_PAUSE, :playback_pause], + [Gtk::Stock::MEDIA_STOP, :playback_stop] + ].each do |(stock, meth)| + item = Gtk::ImageMenuItem.new(stock) + item.set_callback(meth) + + append(item) + end + + append(Gtk::SeparatorMenuItem.new) + + [ + [Gtk::Stock::MEDIA_NEXT, :playback_next], + [Gtk::Stock::MEDIA_PREVIOUS, :playback_prev] + ].each do |(stock, meth)| + item = Gtk::ImageMenuItem.new(stock) + item.set_callback(meth) + + append(item) + end + + append(Gtk::SeparatorMenuItem.new) + + [ + [Gtk::Stock::OPEN, "Load playlist...", :load], + [Gtk::Stock::ADD, "Append playlist...", :append] + ].each do |(stock, text, sym)| + item = Gtk::ImageMenuItem.new(text) + item.image = Gtk::Image.new(stock, Gtk::IconSize::MENU) + + item.signal_connect("button_release_event") do + PlaylistDialog.new(sym).show_all + false + end + + append(item) + end + + item = Gtk::ImageMenuItem.new(Gtk::Stock::CLEAR) + item.set_callback(:playlist_clear) + + append(item) + + append(Gtk::SeparatorMenuItem.new) + + item = Gtk::ImageMenuItem.new(Gtk::Stock::ABOUT) + item.signal_connect("button_release_event") do + props = { + "name" => PKG_NAME, + "version" => VERSION, + "copyright" => "(c) 2006 Tilman Sauerbeck", + "logo" => Gdk::Pixbuf.new(DATADIR + "logo128.png") + } + + Gtk::AboutDialog.show(Snett.instance, props) + false + end + + append(item) + + item = Gtk::ImageMenuItem.new(Gtk::Stock::QUIT) + item.signal_connect("button_release_event") do + Snett.instance.signal_emit("destroy") + false + end + + append(item) + + show_all + end + + def popup(event) + super(nil, nil, event.button, event.time) + end + end + + class PlaylistDialog < Gtk::Dialog + def initialize(mode) + super("Playlists", Snett.instance, + Gtk::Dialog::DESTROY_WITH_PARENT | Gtk::Dialog::MODAL, + [Gtk::Stock::OK, Gtk::Dialog::RESPONSE_ACCEPT], + [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_REJECT]) + + @mode = mode + + signal_connect("response") do |_, id| + on_ok if id == Gtk::Dialog::RESPONSE_ACCEPT + destroy + end + + @store = Gtk::ListStore.new(String) + + @view = Gtk::TreeView.new(@store) + renderer = Gtk::CellRendererText.new + + col = Gtk::TreeViewColumn.new("Name", renderer, :text => 0) + @view.append_column(col) + + vbox.add(@view) + + Snett.instance.xmms.medialib_playlists_list. + notifier(&method(:on_playlists_list)) + end + + private + def on_playlists_list(res) + res.value.sort.each do |list| + next if list[0, 1] == "_" + + @store.append[0] = list + end + end + + def on_ok + selection = @view.selection + iter = selection.selected + return if iter.nil? + + Snett.instance.xmms.playlist_clear if @mode == :load + Snett.instance.xmms.medialib_playlist_load(iter[0]) + end + end +end + +Gtk.init +Snett::Snett.instance.show_all +Gtk.main diff --git a/data/logo.svg b/data/logo.svg new file mode 100644 index 0000000..0bf779a --- /dev/null +++ b/data/logo.svg @@ -0,0 +1,262 @@ + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/logo128.png b/data/logo128.png new file mode 100644 index 0000000..571a87f Binary files /dev/null and b/data/logo128.png differ diff --git a/data/logo32.png b/data/logo32.png new file mode 100644 index 0000000..b0c5096 Binary files /dev/null and b/data/logo32.png differ diff --git a/data/logo64.png b/data/logo64.png new file mode 100644 index 0000000..80cea9c Binary files /dev/null and b/data/logo64.png differ