ocarina: Show and hide the idle bar

I check the size of the idle queue during the timeout poll and then
enable the progress bar.  When the queue size reaches zero I hide the
bar again.

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2012-08-04 13:20:15 -04:00
parent fdecd7bbdf
commit 761842869e
8 changed files with 40 additions and 106 deletions

View File

@ -9,7 +9,7 @@ namespace libsaria
{
int size();
void run_task();
int run_task();
void queue_task(IdleTask *, bool);
void cancel_all(void *);
float progress();

View File

@ -19,6 +19,7 @@ void init_window();
void init_playlist();
/* status.cpp */
bool update_idle_bar(int);
void update_length_label(string &);
void update_status();
void init_status();

View File

@ -28,11 +28,11 @@ namespace libsaria
return idle_queue.size();
}
void idle::run_task()
int idle::run_task()
{
IdleTask *task;
if (size() == 0)
return;
return 0;
task = idle_queue.pop_front();
do_task(task);
if (size() == 0) {
@ -40,6 +40,7 @@ namespace libsaria
serviced = 0.0;
} else
serviced += 1.0;
return size();
}
/*

View File

@ -12,7 +12,6 @@ namespace ocarina
content = gtk_vbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(content), playlist_init(), TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(content), footer_init(), FALSE, FALSE, 0);
gtk_widget_show(content);
//window::set_content(content);

View File

@ -1,70 +0,0 @@
// Copyright (c) 2012 Bryan Schumaker
#include <ocarina/ocarina.h>
#include <ocarina/body.h>
#include <libsaria/audio.h>
#include <libsaria/deck.h>
static GtkWidget *notebook;
static GtkWidget *idle_progress;
static void add_page(string text, GtkWidget *page)
{
GtkWidget *label = gtk_label_new(text.c_str());
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), page, label);
gtk_container_child_set(GTK_CONTAINER(notebook), page, "tab-expand", TRUE, NULL);
gtk_container_child_set(GTK_CONTAINER(notebook), page, "tab-fill", TRUE, NULL);
gtk_widget_show(label);
}
namespace ocarina
{
GtkWidget *body::footer_init()
{
GtkWidget *footer = gtk_vbox_new(FALSE, 0);
GtkWidget *bottom_box = gtk_hbox_new(FALSE, 0);
notebook = gtk_notebook_new();
idle_progress = gtk_progress_bar_new();
gtk_rc_parse_string(
"style \"idle-progress-style\"\n"
"{\n"
" GtkProgressBar::min-horizontal-bar-height = 10\n"
" GtkProgressBar::min-horizontal-bar-width = 75\n"
"}\n"
"widget \"*.ocarina-idle-progress\" style \"idle-progress-style\"");
gtk_widget_set_name(idle_progress, "ocarina-idle-progress");
gtk_box_pack_start(GTK_BOX(bottom_box), idle_progress, FALSE, FALSE, 0);
gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook), GTK_POS_TOP);
g_object_set(notebook, "tab-border", 0, NULL);
gtk_box_pack_start(GTK_BOX(footer), notebook, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(footer), bottom_box, FALSE, FALSE, 0);
add_page("Now Playing", now_playing_page());
add_page("AutoPause", pause_page());
add_page("Library", library_page());
add_page("Settings", general_page());
gtk_widget_show(footer);
gtk_widget_show(notebook);
gtk_widget_show(bottom_box);
return footer;
};
void body::set_idle_progress(float progress)
{
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(idle_progress), progress);
gtk_widget_show(idle_progress);
}
void body::hide_idle_progress()
{
gtk_widget_hide(idle_progress);
}
}; /* Namespace: ocarina */

View File

@ -8,17 +8,8 @@
#include <ocarina/ocarina.h>
#include <ocarina/playlist.h>
/*#include <libsaria/libsaria.h>
#include <libsaria/idle.h>
#include <ocarina/playlist.h>
#include <ocarina/ocarina.h>
#include <ocarina/body.h>*/
static string lib_path;
static GtkBuilder *builder;
static bool using_idle = false;
static void find_exe_path(string &res)
{
@ -46,30 +37,10 @@ static void find_lib_path()
rstrip_word(exe); // ocarina-player
rstrip_word(exe); // bin/
lib_path = exe + "/lib/ocarina/";
lib_path = exe + "/lib/ocarina";
println("Lib directory? %s", lib_path.c_str());
}
static gboolean idle(gpointer data)
{
libsaria::idle::run_task();
using_idle = (libsaria::idle::size() != 0);
/* if (using_idle)
ocarina::body::set_idle_progress(libsaria::idle::progress());
else
ocarina::body::hide_idle_progress();*/
return using_idle;
}
static void idle_add()
{
if ((using_idle == false) && (libsaria::idle::size() > 0)) {
println("Adding idle callback");
g_idle_add(idle, NULL);
using_idle = true;
}
}
string lib_file(const string &path)
{
string res = lib_path + "/" + path;
@ -77,12 +48,27 @@ string lib_file(const string &path)
return res;
}
static gboolean ocarina_idle(gpointer data)
{
int size = libsaria::idle::run_task();
return update_idle_bar(size);
}
static void idle_add()
{
static int size = 0;
int cur = libsaria::idle::size();
if ((cur > 0) && (cur > size)) {
println("Adding idle callback");
g_idle_add(ocarina_idle, NULL);
size = cur;
}
}
static gboolean timeout_poll(gpointer data)
{
idle_add();
update_status();
/* ocarina::body::set_now_playing();
ocarina::body::update_controls();*/
return TRUE;
}

View File

@ -2,6 +2,7 @@
#include <ocarina/ocarina.h>
#include <libsaria/audio.h>
#include <libsaria/track.h>
#include <libsaria/idle.h>
static libsaria::Track *cur_track = NULL;
static GstState cur_state;
@ -87,6 +88,21 @@ static void slider_changed(GtkWidget *w, GtkScrollType s, gdouble v, gpointer d)
libsaria::audio::seek_to(v);
}
bool update_idle_bar(int size)
{
GtkWidget *idle = get_widget("IdleProgress");
if (size == 0) {
gtk_widget_hide(idle);
return false;
}
gtk_widget_show(idle);
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(idle),
libsaria::idle::progress());
return true;
}
void update_length_label(string &text)
{
GtkWidget *label = get_widget("LengthLabel");

View File

@ -441,6 +441,7 @@
<property name="can_focus">False</property>
<child>
<object class="GtkProgressBar" id="IdleProgress">
<property name="height_request">10</property>
<property name="can_focus">False</property>
</object>
<packing>