Archive / / / / / TrackSlider.cc
2008-10-07 01:31:44 UTC
previous next
/* Echo Media Player * Copyright (C) 2008 Shane O'Connell * * [ The original file includes a copyright header in this location describing * the file as being released under the terms of the GNU General Public * License. It has been removed in order to display the file as part of the * archive. ] */ #include "TrackSlider.h" #include "../PlaybackManager.h" #include <iostream> #include <iomanip> using namespace std; TrackSlider::TrackSlider() { m_scale.set_draw_value(false); m_scale.set_sensitive(false); Gtk::Alignment* scale_align = Gtk::manage(new Gtk::Alignment()); scale_align->add(m_scale); scale_align->set(0.5, 1.0, 1.0, 1.0); pack_start(*scale_align); pack_start(m_label); set_size_request(100,0); PlaybackManager::signal_track_started().connect( sigc::mem_fun(*this, &TrackSlider::on_track_started)); PlaybackManager::signal_track_stopped().connect( sigc::mem_fun(*this, &TrackSlider::on_track_stopped)); } void TrackSlider::on_track_started(PlaySourceRef playlist, int index, bool was_paused) { m_scale.set_sensitive(true); // TODO deactivate the timeout signal if the slider isn't visible to save power m_timeout_connection = Glib::signal_timeout().connect( sigc::mem_fun(*this, &TrackSlider::on_timeout), 500); } void TrackSlider::on_track_stopped(PlaySourceRef playlist, int index, bool is_paused) { m_timeout_connection.disconnect(); if (!is_paused) { m_scale.set_value(0); m_scale.set_sensitive(false); m_label.set_text(""); } // TODO if we are stopping completely and not pausing, make the slider grey and disabled } bool TrackSlider::on_timeout() { int pos = PlaybackManager::get_track_position(); int length = PlaybackManager::get_track_length(); if (length > 0) { Glib::ustring label_text = Glib::ustring::compose("%1:%2 of %3:%4", (pos / 60000), Glib::ustring::format(setfill(L'0'), setw(2), (pos / 1000) % 60), (length / 60000), Glib::ustring::format(setfill(L'0'), setw(2), (length / 1000) % 60)); m_scale.set_range(0, length); m_scale.set_value(pos); m_label.set_text(label_text); } // TODO if length unknown, make the slider grey and disabled return true; }