diff --git a/ocarina/Sconscript b/ocarina/Sconscript deleted file mode 100644 index eeb88135..00000000 --- a/ocarina/Sconscript +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/python -from config import * - -env.ParseConfig('pkg-config --cflags --libs gtk+-2.0') -env.ParseConfig('pkg-config --cflags --libs gmodule-export-2.0') - - -def script(target, source, env): - f = open(str(target[0]), 'w') - for line in open(str(source[0])): - line = line.replace("%DEBUG", str(DEBUG)) - f.write(line) - f.close() - os.chmod(str(target[0]), 0755) - - -extra_files = [ - ("ocarina.xml", "../lib/ocarina/ocarina.xml", copy), - ("images/random.png", "../lib/ocarina/random.png", copy), - ("images/ocarina.png", "../lib/ocarina/ocarina.png", copy), - ("images/thumbs_up.png", "../lib/ocarina/thumbs_up.png", copy), - ("images/thumbs_down.png", "../lib/ocarina/thumbs_down.png", copy), - ("scripts/ocarina", "../bin/ocarina", script), - ("scripts/ocarina-completion.bash", "../lib/ocarina/ocarina-completion.bash", copy), - ("../bin/ocarina", "../ocarina.bin", symlink), -] - -build = [env.Program("../bin/ocarina-player", libsaria + get_cpp_files())] -for (src, dst, func) in extra_files: - build.append(env.Command(dst, src, func)) - -env.Alias("ocarina", build) -Return('build') diff --git a/ocarina/images/dice.png b/ocarina/images/dice.png deleted file mode 100644 index 61c76841..00000000 Binary files a/ocarina/images/dice.png and /dev/null differ diff --git a/ocarina/images/ocarina.png b/ocarina/images/ocarina.png deleted file mode 100644 index 9e4da83b..00000000 Binary files a/ocarina/images/ocarina.png and /dev/null differ diff --git a/ocarina/images/random.png b/ocarina/images/random.png deleted file mode 100644 index c67eb31a..00000000 Binary files a/ocarina/images/random.png and /dev/null differ diff --git a/ocarina/images/thumbs_down.png b/ocarina/images/thumbs_down.png deleted file mode 100644 index 714dcf88..00000000 Binary files a/ocarina/images/thumbs_down.png and /dev/null differ diff --git a/ocarina/images/thumbs_up.png b/ocarina/images/thumbs_up.png deleted file mode 100644 index fb0c61b4..00000000 Binary files a/ocarina/images/thumbs_up.png and /dev/null differ diff --git a/ocarina/library.cpp b/ocarina/library.cpp deleted file mode 100644 index a9eff373..00000000 --- a/ocarina/library.cpp +++ /dev/null @@ -1,147 +0,0 @@ -// Copyright (c) 2012 Bryan Schumaker -#include -#include "ocarina.h" - -static inline GtkListStore *get_list() -{ - return GTK_LIST_STORE(get_object("LibraryList")); -} - -static bool find_iter(libsaria::library::Path *path, GtkTreeIter *iter) -{ - libsaria::library::Path *list_path; - - /* get_iter_first() return FALSE if the liststore is empty */ - if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(get_list()), iter)) - return false; - - do { - gtk_tree_model_get(GTK_TREE_MODEL(get_list()), iter, 0, &list_path, -1); - if (list_path == path) - return true; - } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(get_list()), iter)); - - return false; -} - -static libsaria::library::Path *find_path(gchar *path) -{ - GtkTreeIter iter; - libsaria::library::Path *lib_path = NULL; - - if (!gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(get_list()), &iter, path)) - return NULL; - gtk_tree_model_get(GTK_TREE_MODEL(get_list()), &iter, 0, &lib_path, -1); - return lib_path; -} - -static libsaria::library::Path *get_selected_path(GtkWidget *treeview) -{ - GtkTreeIter iter; - GtkTreeModel *model = GTK_TREE_MODEL(get_list()); - GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); - libsaria::library::Path *path; - - if (!gtk_tree_selection_get_selected(sel, &model, &iter)) - return NULL; - gtk_tree_model_get(model, &iter, 0, &path, -1); - return path; -} - -static void path_updated(libsaria::library::Path *path) -{ - GtkTreeIter iter; - if (!find_iter(path, &iter)) - return; - - gtk_list_store_set(get_list(), &iter, - 1, path->visible, - 2, path->path.c_str(), - 3, path->tracks.size(), - -1); -} - -static void path_added(libsaria::library::Path *path) -{ - GtkTreeIter iter; - println("Path added: " + path->path); - gtk_list_store_append(get_list(), &iter); - gtk_list_store_set(get_list(), &iter, - 0, path, - 1, path->visible, - 2, path->path.c_str(), - 3, path->tracks.size(), - -1); -} - -static void path_removed(libsaria::library::Path *path) -{ - GtkTreeIter iter; - if (!find_iter(path, &iter)) - return; - gtk_list_store_remove(get_list(), &iter); -} - -void notify_library(notify_t event, libsaria::library::Path *path) -{ - switch (event) { - case PATH_ADDED: - path_added(path); - break; - case PATH_DELETED: - path_removed(path); - break; - case PATH_UPDATED: - path_updated(path); - default: - break; - } -} - -static void add_library(GtkWidget *b, gpointer d) -{ - string dir = run_chooser("DirectoryChooser"); - if (dir != "") { - println("Scanning dir: " + dir); - libsaria::library::add_path(dir); - } -} - -static void path_toggled(GtkCellRendererToggle *toggle, gchar *path, gpointer d) -{ - libsaria::library::Path *lib_path = find_path(path); - if (!path) - return; - - if (gtk_cell_renderer_toggle_get_active(toggle)) - libsaria::library::show_path(lib_path); - else - libsaria::library::hide_path(lib_path); -} - -static gboolean key_pressed(GtkWidget *treeview, GdkEvent *event, gpointer data) -{ - libsaria::library::Path *path; - string key = gdk_keyval_name(event->key.keyval); - println("Library settings handling key press: " + key); - - path = get_selected_path(treeview); - if (!path) - return FALSE; - - if (key == "Delete") - libsaria::library::delete_path(path); - else if (key == "plus" || key == "KP_Add") - add_library(NULL, NULL); - else - return FALSE; - return TRUE; -} - -void init_library() -{ - connect_signal("AddLibrary", "clicked", G_CALLBACK(add_library), NULL); - connect_signal("UpdateLibraries", "clicked", G_CALLBACK(libsaria::library::update_all), NULL); - connect_signal("LibraryToggle", "toggled", G_CALLBACK(path_toggled), NULL); - connect_signal("LibraryView", "key-press-event", G_CALLBACK(key_pressed), NULL); -} diff --git a/ocarina/notify.cpp b/ocarina/notify.cpp deleted file mode 100644 index 75b368d5..00000000 --- a/ocarina/notify.cpp +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) 2012 Bryan Schumaker. -#include -#include "ocarina.h" - -static void idle_add() -{ - if (libsaria::idle::size() == 1) { - println("Adding idle callback"); - g_idle_add(ocarina_idle, NULL); - } -} - -void on_notify(notify_t event, void *data) -{ - /* TODO: Array of function pointers */ - switch (event) { - case IDLE_ADD: - idle_add(); - break; - case TRACK_CHANGED: - update_labels((libsaria::Track *)data); - break; - case PATH_ADDED: - case PATH_DELETED: - case PATH_UPDATED: - notify_library(event, (libsaria::library::Path *)data); - break; - case PLAYING: - case PAUSED: - update_buttons(event); - break; - case PAUSE_TYPE: - update_autopause_type((AutoPauseType *)data); - break; - case PAUSE_COUNT: - update_autopause_count((unsigned int *)data); - break; - case PLAYLIST_NEW: - case PLAYLIST_DELETE: - case PLAYLIST_RENUMBER: - case PLAYLIST_CHANGED: - update_tabs(event, (libsaria::Playlist *)data); - break; - case PLAYLIST_ADD: - case PLAYLIST_RM: - case PLAYLIST_UPDATE: - case PLAYLIST_GOTO: - update_playlist(event, (libsaria::PlaylistNotification *)data); - default: - break; - } -} diff --git a/ocarina/ocarina.cpp b/ocarina/ocarina.cpp deleted file mode 100644 index 86c74306..00000000 --- a/ocarina/ocarina.cpp +++ /dev/null @@ -1,174 +0,0 @@ -// Copyright (c) 2011 Bryan Schumaker -#include -#include -#include -#include -#include -#include - -#include "ocarina.h" - -static string lib_path; -static GtkBuilder *builder; -static GtkWidget *ban_button; -static GtkWidget *yes_image; -static GtkWidget *no_image; - -static void find_exe_path(string &res) -{ - char buf[1024]; - ssize_t len = readlink("/proc/self/exe", buf, sizeof(buf) -1); - if (len != -1) - res = string(buf); -} - -static void rstrip_word(string &path) -{ - unsigned int index = path.rfind("/"); - if (index != string::npos) - path = path.substr(0, index); -} - -static void find_lib_path() -{ - string exe; - - find_exe_path(exe); - if (exe == "") - return; - - rstrip_word(exe); // ocarina-player - rstrip_word(exe); // bin/ - - lib_path = exe + "/lib/ocarina"; - println("Lib directory? %s", lib_path.c_str()); -} - -string lib_file(const string &path) -{ - string res = lib_path + "/" + path; - println("Expanding to path: " + res); - return res; -} - -gboolean ocarina_idle(gpointer data) -{ - int size = libsaria::idle::run_task(); - return update_idle_bar(size); -} - -static gboolean timeout_poll(gpointer data) -{ - update_progress(); - return TRUE; -} - -GObject *get_object(const string &name) -{ - /* TODO: Figure out GtkNotebook action area in GtkBuilder */ - if (name == "BanButton") - return G_OBJECT(ban_button); - else if (name == "YesImage") - return G_OBJECT(yes_image); - else if (name == "NoImage") - return G_OBJECT(no_image); - return gtk_builder_get_object(builder, name.c_str()); -} - -GtkWidget *get_widget(const string &name) -{ - GtkWidget *widget = GTK_WIDGET(get_object(name)); - if (!widget) - println(name + " is not a widget!"); - return widget; -} - -void connect_signal(const string &name, const string &signal, GCallback func, void *data) -{ - GObject *widget = get_object(name); - if (widget) - g_signal_connect(widget, signal.c_str(), func, data); -} - -string run_chooser(const string &name) -{ - char *file; - string filename = ""; - GtkWidget *chooser = get_widget(name); - - if (gtk_dialog_run(GTK_DIALOG(chooser)) == GTK_RESPONSE_OK) { - file = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(chooser)); - filename = file; - g_free(file); - } - gtk_widget_hide(chooser); - return filename; -} - -static void init_widgets() -{ - ban_button = gtk_toggle_button_new(); - yes_image = gtk_image_new_from_file(lib_file("thumbs_up.png").c_str()); - no_image = gtk_image_new_from_file(lib_file("thumbs_down.png").c_str()); - gtk_button_set_image(GTK_BUTTON(ban_button), yes_image); - - /* Prevent widgets from being destroyed when toggling banned button */ - g_object_ref(yes_image); - g_object_ref(no_image); -} - -static void init(int argc, char **argv) -{ - gtk_init(&argc, &argv); - - builder = gtk_builder_new(); - gtk_builder_add_from_file(builder, lib_file("ocarina.xml").c_str(), NULL); - - /* Set up small button style */ - gtk_rc_parse_string( - "style \"small-button-style\"\n" - "{\n" - " GtkButton::inner-border = {0,0,0,0}\n" - "}\n" - "widget \"*.ocarina-small-button\" style \"small-button-style\""); - - /* Initialize widgets static to this file */ - init_widgets(); - - /* Other setup */ - init_window(); - init_library(); - init_tabs(); - init_playlist(); - init_status(); - init_pipe(); - - /* Connect signals */ - connect_signal("PlayButton", "clicked", libsaria::audio::play, NULL); - connect_signal("PauseButton", "clicked", libsaria::audio::pause, NULL); - connect_signal("StopButton", "clicked", libsaria::audio::stop, NULL); - connect_signal("PrevButton", "clicked", libsaria::deck::prev, NULL); - connect_signal("NextButton", "clicked", libsaria::deck::next, NULL); - - /* Show any widgets that need showing */ - gtk_timeout_add(250, timeout_poll, NULL); -} - -int main(int argc, char **argv) -{ - struct libsaria::initdata ls_init = { - argc, - argv, - on_notify, /* notification handler */ - }; - println("Ocarina " + vers_str()); - find_lib_path(); - - libsaria::init(&ls_init); - init(argc, argv); - - gtk_main(); - libsaria::quit(); - - return 0; -} diff --git a/ocarina/ocarina.h b/ocarina/ocarina.h deleted file mode 100644 index 83d071b1..00000000 --- a/ocarina/ocarina.h +++ /dev/null @@ -1,88 +0,0 @@ -#ifndef OCARINA_H -#define OCARINA_H - -#include -#include -#include -#include - -#include -#include -using namespace std; - -enum ExtraWidgets { - NO_EXTRA_WIDGETS = 0, - CLOSE_BUTTON = (1 << 0), - DISABLE_BUTTON = (1 << 1), - RANDOM_BUTTON = (1 << 2), - SORT_BUTTON = (1 << 3), -}; - -struct PlaylistWidgets { - libsaria::Playlist *playlist; - GtkListStore *liststore; - GtkBox *page_box; - GtkBox *tab_box; - GtkTreeView *treeview; - GtkTreeModel *filter; - GtkLabel *size_label; - GtkLabel *page_label; - GtkEntry *entry; - GtkToggleButton *disable; - GtkToggleButton *random; - GtkToggleButton *sort; - set *filter_text; -}; - -/* library.cpp */ -void notify_library(notify_t, libsaria::library::Path *); -void init_library(); - -/* notify.cpp */ -void on_notify(notify_t, void *); - -/* ocarina.cpp */ -string lib_file(const string &); -gboolean ocarina_idle(gpointer); -GObject *get_object(const string &); -GtkWidget *get_widget(const string &); -void connect_signal(const string &, const string &, GCallback, void *); -string run_chooser(const string &); - -/* pipe.cpp */ -void init_pipe(); - -/* playlist.cpp */ -void update_playlist(notify_t, libsaria::PlaylistNotification *); -bool playlist_key_pressed(GtkTreeView *treeview, string &); -void setup_widgets(struct PlaylistWidgets *, libsaria::Playlist *); -void setup_playlist_page(struct PlaylistWidgets *, int); -void init_playlist(); - -/* status.cpp */ -bool update_idle_bar(int); -void update_length_label(libsaria::Playlist *); -void update_labels(libsaria::Track *); -void update_buttons(notify_t); -void update_progress(); -void update_autopause_type(AutoPauseType *); -void update_autopause_count(unsigned int *); -void init_status(); - -/* tabs.cpp */ -struct PlaylistWidgets *find_playlist_widgets(libsaria::Playlist *); -struct PlaylistWidgets *current_widgets(); -libsaria::Playlist *current_playlist(); -bool playlist_entry_focused(); -void playlist_focus_entry(); -bool playlist_key_press(string &); -void playlist_focus_treeview(); -void playlist_switch_to(string &); -void playlist_switch_to_n(unsigned int); -void init_tabs(); -void update_tabs(notify_t, libsaria::Playlist *); - -/* window.cpp */ -void init_window(); - -#endif diff --git a/ocarina/ocarina.xml b/ocarina/ocarina.xml deleted file mode 100644 index 03df1cd4..00000000 --- a/ocarina/ocarina.xml +++ /dev/null @@ -1,897 +0,0 @@ - - - - - - - False - 5 - Choose a directory - GtkFileChooserDialog - dialog - select-folder - False - - - True - False - 2 - - - True - False - end - - - gtk-cancel - False - True - True - True - True - - - False - False - 0 - - - - - gtk-open - False - True - True - True - True - - - False - False - 1 - - - - - False - True - end - 0 - - - - - - - - - DirectoryCancelButton - DirectoryOpenButton - - - - False - 5 - Choose a file - GtkFileChooserDialog - dialog - - - True - False - 2 - - - True - False - end - - - gtk-cancel - False - True - True - True - True - - - False - False - 0 - - - - - gtk-open - False - True - True - True - True - - - False - False - 1 - - - - - False - True - end - 0 - - - - - - - - - FileCancelButton - FileOpenButton - - - - - - - - - - - - - - - - True - False - 900 - 600 - - - True - False - - - True - True - left - True - 0 - 0 - 0 - - - True - True - 0 - - - - - True - False - - - True - False - - - False - True - 0 - - - - - True - True - 0 - False - left - - - True - True - 1 - - - - - True - False - - - False - True - 2 - - - - - False - True - True - True - 0 - - - True - False - 0 - 0 - gtk-media-play - 1 - - - - - False - False - 3 - - - - - False - True - True - 0 - 0 - - - True - False - 0 - 0 - gtk-media-pause - 1 - - - - - False - False - 4 - - - - - False - True - True - True - 0 - 0 - - - True - False - gtk-media-stop - 1 - - - - - False - False - 5 - - - - - False - True - True - True - 0 - 0 - - - True - False - 0 - 0 - gtk-media-previous - 1 - - - - - False - False - 6 - - - - - False - True - True - True - 0 - 0 - - - True - False - gtk-media-next - 1 - - - - - False - False - 7 - - - - - False - True - 1 - - - - - True - False - True - - - True - True - automatic - never - - - True - False - etched-in - - - True - False - - - True - False - 0 - <span size='xx-large'> </span> - True - - - True - False - 0 - - - - - True - False - 0 - 0 - <span size='x-large'> </span> - True - - - True - False - 1 - - - - - True - False - 0 - 0 - <span size='x-large'> </span> - True - - - True - False - 2 - - - - - - - - - True - True - 0 - - - - - True - True - left - - - True - False - - - No automatic pause - False - True - True - False - True - True - - - True - True - 0 - - - - - True - False - - - Pause after - False - True - True - False - True - NoPause - - - False - False - 0 - - - - - True - True - - True - False - False - True - True - PauseAdjustment - - - False - False - 1 - - - - - True - False - songs - - - False - False - 2 - - - - - True - True - 1 - - - - - - - True - False - AutoPause - - - False - - - - - True - False - - - True - True - automatic - automatic - - - True - True - LibraryList - False - False - - - On - - - - 1 - - - - - - - Path - True - - - - 2 - - - - - - - Size - - - - 3 - - - - - - - - - True - True - 0 - - - - - True - False - - - False - True - True - True - 0 - 0 - - - True - False - gtk-add - 1 - - - - - False - False - 0 - - - - - False - True - True - True - 0 - 0 - - - True - False - gtk-refresh - 1 - - - - - False - False - 1 - - - - - False - False - 1 - - - - - 1 - - - - - True - False - Library - - - 1 - False - - - - - True - False - - - Show list recently played songs - False - True - True - False - True - True - - - False - False - 0 - - - - - Show list of banned songs - False - True - True - False - 0.54000002145767212 - True - True - - - False - False - 1 - - - - - - - - 2 - - - - - True - False - Settings - - - 2 - False - - - - - True - True - 1 - - - - - False - True - 2 - - - - - True - False - - - 10 - False - - - False - False - 0 - - - - - True - False - 1 - - - True - True - 1 - - - - - False - False - 3 - - - - - - - 256 - 1 - 10 - - - True - False - - - False - True - False - New queue (front) - True - - - - - False - True - False - New set (front) - True - - - - - False - True - False - - - - - False - True - False - New queue (back) - True - - - - - False - True - False - New set (back) - True - - - - - False - True - False - - - - - False - True - False - Add to playlist 0 - True - - - - - False - True - False - Add to playlist 1 - True - - - - - False - True - False - Add to playlist 2 - True - - - - - False - True - False - Add to playlist 3 - True - - - - - False - True - False - Add to playlist 4 - True - - - - - False - True - False - Add to playlist 5 - True - - - - - False - True - False - Add to playlist 6 - True - - - - - False - True - False - Add to playlist 7 - True - - - - - False - True - False - Add to playlist 8 - True - - - - - False - True - False - Add to playlist 9 - True - - - - diff --git a/ocarina/pipe.cpp b/ocarina/pipe.cpp deleted file mode 100644 index 590d4d3a..00000000 --- a/ocarina/pipe.cpp +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) Bryan Schumaker 2012. -#include -#include -#include - -#include -#include -using namespace std; - -static GIOChannel *pipe_in; - -static void pipe_read_text(GIOChannel *source, string &text) -{ - gchar *str = NULL; - GError *error = NULL; - gsize size, end; - - g_io_channel_read_line(source, &str, &size, &end, &error); - - text = str; - /* Strip newline character */ - text = text.substr(0, text.size() - 1); - - /* g_io_channel_read_line allocates memory */ - g_free(str); -} - -static gboolean pipe_read(GIOChannel *source, GIOCondition condition, gpointer data) -{ - string text; - pipe_read_text(source, text); - libsaria::run_cmd(text); - return TRUE; -} - -void init_pipe() -{ - GError *error = NULL; - string pipe = libsaria::app::pipe_file(); - if (pipe == "") - return; - - pipe_in = g_io_channel_new_file(pipe.c_str(), "r+", &error); - if (!pipe_in) - return; - g_io_add_watch(pipe_in, G_IO_IN, pipe_read, NULL); -} diff --git a/ocarina/playlist.cpp b/ocarina/playlist.cpp deleted file mode 100644 index 0e2d80ea..00000000 --- a/ocarina/playlist.cpp +++ /dev/null @@ -1,578 +0,0 @@ -// Copyright (c) 2012 Bryan Schumaker -#include -#include -#include -#include -#include -#include "ocarina.h" - -static GType types[] = { - G_TYPE_POINTER, // libsaria::Track * - G_TYPE_UINT, // Track number - G_TYPE_STRING, // Title - G_TYPE_STRING, // Length - G_TYPE_STRING, // Artist - G_TYPE_STRING, // Album - G_TYPE_UINT, // Year - G_TYPE_UINT, // Count - G_TYPE_STRING, // Last played - G_TYPE_STRING, // Filepath -}; - -static string formatted(string str) -{ - char *escaped = g_markup_escape_text(str.c_str(), -1); - string ret = escaped; - g_free(escaped); - return ret; -} - -static void update_track(libsaria::Track *track, GtkListStore *liststore, - GtkTreeIter *iter) -{ - gtk_list_store_set(liststore, iter, - 0, track, - 1, track->track, - 2, track->title.c_str(), - 3, track->lenstr.c_str(), - 4, track->artist.c_str(), - 5, track->album.c_str(), - 6, track->year, - 7, track->count, - 8, track->get_last_played().c_str(), - 9, formatted(track->filepath).c_str(), - -1); -} - -static void playlist_add(libsaria::Playlist *plist, libsaria::Track *track, - unsigned int index) -{ - GtkTreeIter iter; - struct PlaylistWidgets *widgets = find_playlist_widgets(plist); - if (!widgets) - return; - - gtk_list_store_insert(widgets->liststore, &iter, index); - update_track(track, widgets->liststore, &iter); -} - -static void playlist_rm(libsaria::Playlist *plist, unsigned int index) -{ - GtkTreeIter iter; - PlaylistWidgets *widgets = find_playlist_widgets(plist); - gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(widgets->liststore), &iter, NULL, index); - gtk_list_store_remove(widgets->liststore, &iter); - update_length_label(current_playlist()); -} - -static void playlist_update(libsaria::Playlist *plist, libsaria::Track *track, - unsigned int index) -{ - GtkTreeIter iter; - PlaylistWidgets *widgets = find_playlist_widgets(plist); - gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(widgets->liststore), &iter, NULL, index); - update_track(track, widgets->liststore, &iter); -} - -static void set_playlist_size(libsaria::Playlist *plist) -{ - char buf[11]; - struct PlaylistWidgets *widgets = find_playlist_widgets(plist); - if (!widgets) - return; - - sprintf(buf, "%u", plist->get_size()); - gtk_label_set_text(widgets->size_label, buf); - update_length_label(current_playlist()); -} - -static void playlist_goto_index(libsaria::Playlist *playlist, unsigned int index) -{ - GtkTreeIter iter; - GtkTreePath *path; - struct PlaylistWidgets *widgets = find_playlist_widgets(playlist); - GtkTreeModel *model = GTK_TREE_MODEL(widgets->liststore); - - gtk_tree_model_get_iter_first(model, &iter); - path = gtk_tree_model_get_path(model, &iter); - for (unsigned int i = 0; i < index; i++) - gtk_tree_path_next(path); - - gtk_tree_view_set_cursor(widgets->treeview, path, NULL, FALSE); - gtk_tree_path_free(path); -} - -void update_playlist(notify_t event, libsaria::PlaylistNotification *data) -{ - if (event == PLAYLIST_ADD) { - playlist_add(data->plist, data->track, data->index); - set_playlist_size(data->plist); - } else if (event == PLAYLIST_RM) { - playlist_rm(data->plist, data->index); - set_playlist_size(data->plist); - } else if (event == PLAYLIST_UPDATE) - playlist_update(data->plist, data->track, data->index); - else if (event == PLAYLIST_GOTO) - playlist_goto_index(data->plist, data->index); -} - -static gboolean is_visible(GtkTreeModel *model, GtkTreeIter *iter, gpointer data) -{ - libsaria::Track *track; - struct PlaylistWidgets *widgets = (struct PlaylistWidgets *)data; - - if (widgets->filter_text == NULL) - return true; - - gtk_tree_model_get(model, iter, 0, &track, -1); - return track->is_visible(widgets->filter_text); -} - -static void do_filter(GtkWidget *entry, gpointer data) -{ - struct PlaylistWidgets *widgets = (struct PlaylistWidgets *)data; - string text = gtk_entry_get_text(GTK_ENTRY(entry)); - widgets->filter_text = libsaria::format_text(text); - - gtk_tree_model_filter_refilter(GTK_TREE_MODEL_FILTER(widgets->filter)); -} - -static void track_selected(GtkWidget *treeview, GtkTreePath *path, - GtkTreeViewColumn *col, gpointer data) -{ - GtkTreeIter iter; - GtkTreeModel *model; - libsaria::Track *track; - - model = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview)); - gtk_tree_model_get_iter(model, &iter, path); - gtk_tree_model_get(model, &iter, 0, &track, -1); - track->load(true); -} - -static void do_tree_path_prev(GtkTreePath *path) -{ - gtk_tree_path_prev(path); -} - -static void do_move_cursor(GtkTreeView *treeview, void path_next(GtkTreePath *)) -{ - GtkTreePath *path, *scroll; - - gtk_widget_grab_focus(GTK_WIDGET(treeview)); - gtk_tree_view_get_cursor(treeview, &path, NULL); - if (path == NULL) - return; - - path_next(path); - scroll = gtk_tree_path_copy(path); - - for (unsigned int i = 0; i < 2; i++) - path_next(scroll); - - gtk_tree_view_scroll_to_cell(treeview, scroll, NULL, FALSE, 0, 0); - gtk_tree_view_set_cursor(treeview, path, NULL, FALSE); - - gtk_tree_path_free(path); - gtk_tree_path_free(scroll); -} - -static void move_cursor(GtkTreeView *treeview, const string &key) -{ - if (key == "j") - do_move_cursor(treeview, gtk_tree_path_next); - else - do_move_cursor(treeview, do_tree_path_prev); -} - -static void selected_foreach_list(GtkTreeModel *model, GtkTreePath *path, - GtkTreeIter *iter, gpointer data) -{ - libsaria::Track *track; - list *tracks = (list *)data; - gtk_tree_model_get(model, iter, 0, &track, -1); - tracks->push_back(track); -} - -static void list_selected_tracks(GtkTreeView *treeview, list *tracks) -{ - GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview); - gtk_tree_selection_selected_foreach(selection, selected_foreach_list, tracks); -} - -static void selected_foreach_index(GtkTreeModel *model, GtkTreePath *path, - GtkTreeIter *iter, gpointer data) -{ - list *indices = (list *)data; - unsigned int *index = (unsigned int *)gtk_tree_path_get_indices(path); - indices->push_back(*index); -} - -static void list_selected_indices(GtkTreeView *treeview, list *indices) -{ - GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview); - gtk_tree_selection_selected_foreach(selection, selected_foreach_index, indices); -} - -static void new_playlist(const string &key, GtkTreeView *treeview, bool front) -{ - list tracks; - unsigned int flags = PL_NONE; - - list_selected_tracks(treeview, &tracks); - if (tracks.size() == 0) - return; - - if (key == "s" || key == "S") - flags |= PL_SORTED | PL_RANDOM; - libsaria::deck::new_playlist(tracks, flags, front); -} - -static bool add_to_playlist(GtkTreeView *treeview, int n) -{ - list tracks; - libsaria::Playlist *playlist; - - list_selected_tracks(treeview, &tracks); - if (tracks.size() == 0) - return false; - - playlist = libsaria::deck::get_playlist(n); - if (playlist) - playlist->push_back(tracks); - return true; -} - -static void ban_selected(GtkTreeView *treeview, bool state) -{ - list tracks; - list::iterator it; - - list_selected_tracks(treeview, &tracks); - for (it = tracks.begin(); it != tracks.end(); it++) - (*it)->set_banned(state); -} - -static void delete_from_playlist(GtkTreeView *treeview) -{ - list indices; - libsaria::Playlist *playlist = current_playlist(); - - if (playlist == libsaria::library::get_playlist() || playlist == libsaria::ban::get_banned_plist()) { - ban_selected(treeview, playlist == libsaria::library::get_playlist()); - return; - } - - list_selected_indices(treeview, &indices); - - if (indices.back() == (playlist->get_size() - 1)) - move_cursor(treeview, "k"); - else - move_cursor(treeview, "j"); - - playlist->remove_indices(indices); - libsaria::deck::garbage_collect(); -} - -static bool on_escape_key(GtkTreeView *treeview) -{ - GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview); - if (gtk_tree_selection_count_selected_rows(selection) == 0) - return false; - gtk_tree_selection_unselect_all(selection); - return true; -} - -static void on_return_key(GtkTreeView *treeview) -{ - GtkTreePath *path; - GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview); - if (gtk_tree_selection_count_selected_rows(selection) == 0) - return; - gtk_tree_view_get_cursor(treeview, &path, NULL); - gtk_tree_view_row_activated(treeview, path, NULL); - gtk_tree_path_free(path); -} - -bool playlist_key_pressed(GtkTreeView *treeview, string &key) -{ - if (key == "j" || key == "k") - move_cursor(treeview, key); - else if (key == "s" || key == "q") - new_playlist(key, treeview, false); - else if (key == "S" || key == "Q") - new_playlist(key, treeview, true); - else if (key >= "0" && key <= "9") - return add_to_playlist(treeview, atoi(key.c_str())); - else if (key == "Delete" || key == "d") - delete_from_playlist(treeview); - else if (key == "Return") - on_return_key(treeview); - else if (key == "Escape") - return on_escape_key(treeview); - else - return false; - return true; -} - -static void on_menu_item(GtkWidget *item, gpointer data) -{ - struct PlaylistWidgets *widgets = current_widgets(); - if (item == get_widget("MenuQueueFront")) - new_playlist("Q", widgets->treeview, true); - else if (item == get_widget("MenuQueueBack")) - new_playlist("q", widgets->treeview, false); - else if (item == get_widget("MenuSetFront")) - new_playlist("S", widgets->treeview, true); - else if (item == get_widget("MenuSetBack")) - new_playlist("s", widgets->treeview, false); - else if (item == get_widget("AddPlaylist0")) - add_to_playlist(widgets->treeview, 0); - else if (item == get_widget("AddPlaylist1")) - add_to_playlist(widgets->treeview, 1); - else if (item == get_widget("AddPlaylist2")) - add_to_playlist(widgets->treeview, 2); - else if (item == get_widget("AddPlaylist3")) - add_to_playlist(widgets->treeview, 3); - else if (item == get_widget("AddPlaylist4")) - add_to_playlist(widgets->treeview, 4); - else if (item == get_widget("AddPlaylist5")) - add_to_playlist(widgets->treeview, 5); - else if (item == get_widget("AddPlaylist6")) - add_to_playlist(widgets->treeview, 6); - else if (item == get_widget("AddPlaylist7")) - add_to_playlist(widgets->treeview, 7); - else if (item == get_widget("AddPlaylist8")) - add_to_playlist(widgets->treeview, 8); - else if (item == get_widget("AddPlaylist9")) - add_to_playlist(widgets->treeview, 9); -} - -static gboolean entry_keypress(GtkEntry *entry, GdkEvent *event, gpointer data) -{ - string key = gdk_keyval_name(event->key.keyval); - if (key == "Return") { - playlist_focus_treeview(); - return TRUE; - } - return FALSE; -} - -static void show_menu_widget(const string &name, unsigned int plist_num, - unsigned int deck_size) -{ - if (plist_num < deck_size) - gtk_widget_show(get_widget(name)); - else - gtk_widget_hide(get_widget(name)); -} - -static void on_click(GtkTreeView *treeview, GdkEvent *event, gpointer data) -{ - unsigned int deck_size = libsaria::deck::size(); - - if (event->button.button != 3) - return; - - show_menu_widget("MenuQueueBack", deck_size, 10); - show_menu_widget("MenuQueueFront", deck_size, 10); - show_menu_widget("MenuSetBack", deck_size, 10); - show_menu_widget("MenuSetFront", deck_size, 10); - show_menu_widget("MenuNewSep", deck_size, 10); - - if (deck_size > 0 && deck_size < 10) - gtk_widget_show(get_widget("MenuAddSep")); - else - gtk_widget_hide(get_widget("MenuAddSep")); - - show_menu_widget("AddPlaylist0", 0, deck_size); - show_menu_widget("AddPlaylist1", 1, deck_size); - show_menu_widget("AddPlaylist2", 2, deck_size); - show_menu_widget("AddPlaylist3", 3, deck_size); - show_menu_widget("AddPlaylist4", 4, deck_size); - show_menu_widget("AddPlaylist5", 5, deck_size); - show_menu_widget("AddPlaylist6", 6, deck_size); - show_menu_widget("AddPlaylist7", 7, deck_size); - show_menu_widget("AddPlaylist8", 8, deck_size); - show_menu_widget("AddPlaylist9", 9, deck_size); - - gtk_menu_popup(GTK_MENU(get_widget("PlaylistMenu")), NULL, NULL, NULL, NULL, event->button.button, event->button.time); -} - -static void playlist_close(GtkWidget *button, gpointer data) -{ - struct libsaria::Playlist *playlist = (libsaria::Playlist *)data; - libsaria::deck::delete_playlist(playlist); -} - -static void playlist_disable(GtkToggleButton *button, gpointer data) -{ - struct libsaria::Playlist *playlist = (libsaria::Playlist *)data; - playlist->set_flag(PL_DISABLED, gtk_toggle_button_get_active(button)); -} - -static void playlist_random(GtkToggleButton *button, gpointer data) -{ - struct libsaria::Playlist *playlist = (libsaria::Playlist *)data; - if (playlist == libsaria::library::get_playlist()) - libsaria::library::set_random(gtk_toggle_button_get_active(button)); - else - playlist->set_flag(PL_RANDOM, gtk_toggle_button_get_active(button)); -} - -static void playlist_sort(GtkToggleButton *button, gpointer data) -{ - struct libsaria::Playlist *playlist = (libsaria::Playlist *)data; - playlist->set_flag(PL_SORTED, gtk_toggle_button_get_active(button)); -} - -void setup_widgets(struct PlaylistWidgets *widgets, libsaria::Playlist *playlist) -{ - unsigned int num_columns = sizeof(types) / sizeof(GType); - GtkTreeSelection *selection; - - widgets->playlist = playlist; - widgets->liststore = gtk_list_store_newv(num_columns, types); - widgets->page_box = GTK_BOX(gtk_vbox_new(FALSE, 0)); - widgets->treeview = GTK_TREE_VIEW(gtk_tree_view_new()); - widgets->filter = gtk_tree_model_filter_new( - GTK_TREE_MODEL(widgets->liststore), NULL); - widgets->size_label = GTK_LABEL(gtk_label_new("0")); - widgets->page_label = GTK_LABEL(gtk_label_new("")); - widgets->entry = GTK_ENTRY(gtk_entry_new()); - widgets->filter_text = NULL; - - selection = gtk_tree_view_get_selection(widgets->treeview); - gtk_tree_selection_set_mode(selection,GTK_SELECTION_MULTIPLE); - - gtk_tree_view_set_model(widgets->treeview, widgets->filter); - gtk_tree_view_set_rules_hint(widgets->treeview, TRUE); - gtk_tree_view_set_enable_search(widgets->treeview, FALSE); - gtk_tree_view_set_tooltip_column(widgets->treeview, 9); - - gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(widgets->filter), - is_visible, widgets, NULL); - - g_signal_connect(widgets->treeview, "row-activated", G_CALLBACK(track_selected), NULL); - g_signal_connect(widgets->treeview, "button-release-event", G_CALLBACK(on_click), NULL); - g_signal_connect(widgets->entry, "changed", G_CALLBACK(do_filter), widgets); - g_signal_connect(widgets->entry, "key-press-event", G_CALLBACK(entry_keypress), widgets); -} - -static GtkWidget *setup_close_button(struct PlaylistWidgets *widgets) -{ - GtkWidget *close = gtk_button_new(); - GtkWidget *image = gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU); - - gtk_button_set_image(GTK_BUTTON(close), image); - gtk_button_set_relief(GTK_BUTTON(close), GTK_RELIEF_NONE); - gtk_widget_set_name(close, "ocarina-small-button"); - g_signal_connect(close, "clicked", G_CALLBACK(playlist_close), widgets->playlist); - - return close; -} - -static GtkWidget *setup_disable_button(struct PlaylistWidgets *widgets) -{ - GtkWidget *image = gtk_image_new_from_stock(GTK_STOCK_YES, GTK_ICON_SIZE_MENU); - widgets->disable = GTK_TOGGLE_BUTTON(gtk_toggle_button_new()); - - gtk_button_set_image(GTK_BUTTON(widgets->disable), image); - gtk_widget_set_name(GTK_WIDGET(widgets->disable), "ocarina-small-button"); - g_signal_connect(GTK_WIDGET(widgets->disable), "toggled", G_CALLBACK(playlist_disable), widgets->playlist); - - return GTK_WIDGET(widgets->disable); -} - -static GtkWidget *setup_random_button(struct PlaylistWidgets *widgets) -{ - GtkWidget *image = gtk_image_new_from_file(lib_file("random.png").c_str()); - widgets->random = GTK_TOGGLE_BUTTON(gtk_toggle_button_new()); - - gtk_button_set_image(GTK_BUTTON(widgets->random), image); - gtk_widget_set_name(GTK_WIDGET(widgets->random), "ocarina-small-button"); - gtk_toggle_button_set_active(widgets->random, widgets->playlist->check_flag(PL_RANDOM)); - g_signal_connect(GTK_WIDGET(widgets->random), "toggled", G_CALLBACK(playlist_random), widgets->playlist); - - return GTK_WIDGET(widgets->random); -} - -static GtkWidget *setup_sort_button(struct PlaylistWidgets *widgets) -{ - GtkWidget *image = gtk_image_new_from_stock(GTK_STOCK_SORT_ASCENDING, GTK_ICON_SIZE_MENU); - widgets->sort = GTK_TOGGLE_BUTTON(gtk_toggle_button_new()); - - gtk_button_set_image(GTK_BUTTON(widgets->sort), image); - gtk_widget_set_name(GTK_WIDGET(widgets->sort), "ocarina-small-button"); - gtk_toggle_button_set_active(widgets->sort, widgets->playlist->check_flag(PL_SORTED)); - g_signal_connect(GTK_WIDGET(widgets->sort), "toggled", G_CALLBACK(playlist_sort), widgets->playlist); - - return GTK_WIDGET(widgets->sort); -} - -static void add_column(GtkTreeView *treeview, const string &title, int index, - GtkTreeViewColumnSizing sizing, unsigned int fixed_width) -{ - GtkCellRenderer *cell = gtk_cell_renderer_text_new(); - GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes( - title.c_str(), cell, "text", index, NULL); - gtk_tree_view_column_set_resizable(column, TRUE); - gtk_tree_view_column_set_sizing(column, sizing); - gtk_tree_view_column_set_fixed_width(column, fixed_width); - gtk_tree_view_column_set_min_width(column, 1); - gtk_tree_view_column_set_max_width(column, 700); - gtk_tree_view_append_column(treeview, column); -} - -void setup_playlist_page(struct PlaylistWidgets *widgets, int flags) -{ - GtkWidget *top_box = gtk_hbox_new(FALSE, 0); - GtkWidget *window = gtk_scrolled_window_new(NULL, NULL); - - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(window), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - - if (flags & CLOSE_BUTTON) - gtk_box_pack_start(GTK_BOX(top_box), setup_close_button(widgets), FALSE, FALSE, 0); - gtk_box_pack_start(GTK_BOX(top_box), GTK_WIDGET(widgets->entry), TRUE, TRUE, 0); - if (flags & RANDOM_BUTTON) - gtk_box_pack_start(GTK_BOX(top_box), setup_random_button(widgets), FALSE, FALSE, 0); - if (flags & SORT_BUTTON) - gtk_box_pack_start(GTK_BOX(top_box), setup_sort_button(widgets), FALSE, FALSE, 0); - if (flags & DISABLE_BUTTON) - gtk_box_pack_start(GTK_BOX(top_box), setup_disable_button(widgets), FALSE, FALSE, 0); - - gtk_box_pack_start(widgets->page_box, top_box, FALSE, FALSE, 0); - gtk_box_pack_start(widgets->page_box, window, TRUE, TRUE, 0); - - gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(widgets->treeview)); - add_column(widgets->treeview, "#", 1, GTK_TREE_VIEW_COLUMN_FIXED, 20); - add_column(widgets->treeview, "Title", 2, GTK_TREE_VIEW_COLUMN_FIXED, 300); - add_column(widgets->treeview, "Length", 3, GTK_TREE_VIEW_COLUMN_GROW_ONLY, 1); - add_column(widgets->treeview, "Artist", 4, GTK_TREE_VIEW_COLUMN_FIXED, 125); - add_column(widgets->treeview, "Album", 5, GTK_TREE_VIEW_COLUMN_FIXED, 125); - add_column(widgets->treeview, "Year", 6, GTK_TREE_VIEW_COLUMN_GROW_ONLY, 1); - add_column(widgets->treeview, "Count", 7, GTK_TREE_VIEW_COLUMN_GROW_ONLY, 1); - add_column(widgets->treeview, "Played", 8, GTK_TREE_VIEW_COLUMN_GROW_ONLY, 1); - - gtk_widget_show_all(GTK_WIDGET(widgets->page_box)); -} - -void init_playlist() -{ - connect_signal("MenuQueueFront", "activate", G_CALLBACK(on_menu_item), NULL); - connect_signal("MenuSetFront", "activate", G_CALLBACK(on_menu_item), NULL); - connect_signal("MenuQueueBack", "activate", G_CALLBACK(on_menu_item), NULL); - connect_signal("MenuSetBack", "activate", G_CALLBACK(on_menu_item), NULL); - connect_signal("AddPlaylist0", "activate", G_CALLBACK(on_menu_item), NULL); - connect_signal("AddPlaylist1", "activate", G_CALLBACK(on_menu_item), NULL); - connect_signal("AddPlaylist2", "activate", G_CALLBACK(on_menu_item), NULL); - connect_signal("AddPlaylist3", "activate", G_CALLBACK(on_menu_item), NULL); - connect_signal("AddPlaylist4", "activate", G_CALLBACK(on_menu_item), NULL); - connect_signal("AddPlaylist5", "activate", G_CALLBACK(on_menu_item), NULL); - connect_signal("AddPlaylist6", "activate", G_CALLBACK(on_menu_item), NULL); - connect_signal("AddPlaylist7", "activate", G_CALLBACK(on_menu_item), NULL); - connect_signal("AddPlaylist8", "activate", G_CALLBACK(on_menu_item), NULL); - connect_signal("AddPlaylist9", "activate", G_CALLBACK(on_menu_item), NULL); -} diff --git a/ocarina/scripts/ocarina b/ocarina/scripts/ocarina deleted file mode 100644 index a6e4ef62..00000000 --- a/ocarina/scripts/ocarina +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash - -APPDIR="$HOME/.ocarina" -if [ "%DEBUG" == "True" ]; then - APPDIR="$APPDIR-debug" -fi - -function write_to_pipe -{ - pipe=$APPDIR/pipe - if [ -p $pipe ]; then - echo "$*" > $pipe - fi -} - -case $1 in -next|pause|play|prev|stop|toggle) - write_to_pipe $1 - exit 0 - ;; -esac - -cmd=`which ocarina-$1 2>/dev/null` -args="${@: +2}" -if [ "$cmd" ]; then - $cmd "$args" -else - cmd=`readlink -f $0` - `dirname $cmd`/ocarina-player "$*" -fi diff --git a/ocarina/scripts/ocarina-completion.bash b/ocarina/scripts/ocarina-completion.bash deleted file mode 100644 index 9dc258e5..00000000 --- a/ocarina/scripts/ocarina-completion.bash +++ /dev/null @@ -1,18 +0,0 @@ - -_ocarina() -{ - COMPREPLY=() - cur="${COMP_WORDS[COMP_CWORD]}" - cmd="${COMP_WORDS[1]}" - - if [ $COMP_CWORD -eq 1 ]; then - opts=`compgen -c "ocarina-" | awk -F "-" '{print $2}'` - opts="$opts next pause play prev stop toggle" - fi - - COMPREPLY=($(compgen -W "${opts}" -- ${cur})) - return 0 - -} - -complete -F _ocarina ocarina diff --git a/ocarina/status.cpp b/ocarina/status.cpp deleted file mode 100644 index d1729917..00000000 --- a/ocarina/status.cpp +++ /dev/null @@ -1,203 +0,0 @@ -// Copyright (c) 2012 Bryan Schumaker -#include -#include -#include -#include -#include -#include -#include -#include "ocarina.h" - -#include -using namespace std; - -static void set_label(const string &name, const string &text, const string &size) -{ - GtkWidget *label = get_widget(name); - if (!label) - return; - - if (size == "") { - gtk_label_set_text(GTK_LABEL(label), text.c_str()); - } else { - char *escaped = g_markup_escape_text(text.c_str(), -1); - string markup = "" + escaped + ""; - gtk_label_set_markup(GTK_LABEL(label), markup.c_str()); - g_free(escaped); - } -} - -void update_labels(libsaria::Track *track) -{ - set_label("TitleLabel", track->title, "xx-large"); - set_label("ArtistLabel", track->artist, "x-large"); - set_label("AlbumLabel", track->album, "x-large"); - set_label("DurLabel", track->lenstr, ""); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(get_widget("BanButton")), - track->banned); -} - -void update_buttons(notify_t event) -{ - GtkWidget *play, *pause; - - play = get_widget("PlayButton"); - pause = get_widget("PauseButton"); - - if (event == PLAYING) { - gtk_widget_show(pause); - gtk_widget_hide(play); - } else { - gtk_widget_show(play); - gtk_widget_hide(pause); - } -} - -void update_progress() -{ - GtkWidget *label = get_widget("PosLabel"); - GtkWidget *progress = get_widget("TrackProgress"); - gint64 pos = libsaria::audio::position(); - gint64 dur = libsaria::audio::duration() + 1; - - gtk_label_set_text(GTK_LABEL(label), libsaria::audio::posstr().c_str()); - - /* - * This happens when gstreamer's "about-to-finish" signal - * is emitted and we queue up a shorter song before the - * pipeline finishes. - */ - if (pos > dur) - pos = 0; - gtk_range_set_range(GTK_RANGE(progress), 0, dur); - gtk_range_set_value(GTK_RANGE(progress), pos); -} - -static void slider_changed(GtkWidget *w, GtkScrollType s, gdouble v, gpointer d) -{ - libsaria::audio::seek_to(v); -} - -void update_autopause_type(AutoPauseType *type) -{ - GtkWidget *button; - if (*type == PS_NONE) - button = get_widget("NoPause"); - else - button = get_widget("PauseAfterN"); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), true); -} - -void update_autopause_count(unsigned int *count) -{ - gtk_spin_button_set_value(GTK_SPIN_BUTTON(get_widget("PauseCounter")), *count); -} - -static void toggle_pause(GtkWidget *b, gpointer d) -{ - if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b))) - return; - - if (b == get_widget("NoPause")) - libsaria::deck::set_pause_type(PS_NONE, 0); - else { - unsigned short count = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(get_widget("PauseCounter"))); - libsaria::deck::set_pause_type(PS_AFTER_N, count); - } -} - -static void counter_changed(GtkWidget *b, GtkScrollType *s, gpointer d) -{ - unsigned short count = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(get_widget("PauseCounter"))); - libsaria::deck::set_pause_type(PS_AFTER_N, count); -} - -static void toggle_ban(GtkWidget *b, gpointer d) -{ - libsaria::Track *cur = libsaria::current_track(); - GtkWidget *ban = get_widget("BanButton"); - bool banned = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ban)); - if (banned) - gtk_button_set_image(GTK_BUTTON(ban), get_widget("NoImage")); - else - gtk_button_set_image(GTK_BUTTON(ban), get_widget("YesImage")); - - if (cur->banned == banned) - return; - - cur->set_banned(banned); - if (banned) - libsaria::deck::next(); -} - -static void toggle_playlist(GtkToggleButton *button, gpointer data) -{ - libsaria::Playlist *plist = (libsaria::Playlist *)data; - struct PlaylistWidgets *widgets = find_playlist_widgets(plist); - bool show = gtk_toggle_button_get_active(button); - - if (show) - gtk_widget_show(GTK_WIDGET(widgets->page_box)); - else - gtk_widget_hide(GTK_WIDGET(widgets->page_box)); - - if (GTK_WIDGET(button) == get_widget("ShowRecent")) - libsaria::prefs::set("ocarina.showrecent", show); - else if (GTK_WIDGET(button) == get_widget("ShowBanned")) - libsaria::prefs::set("ocarina.showbanned", show); -} - -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(libsaria::Playlist *playlist) -{ - stringstream stream; - unsigned int size = playlist->get_size(); - GtkWidget *label = get_widget("LengthLabel"); - if (!label) - return; - - stream << size << " song"; - if (size != 1) - stream << "s"; - if (size != 0) - stream << ": " << libsaria::length_string(playlist->get_length()); - gtk_label_set_text(GTK_LABEL(label), stream.str().c_str()); -} - -void init_plist_visible_button(const string &button_name, const string &pref, - libsaria::Playlist *plist) -{ - bool show = libsaria::prefs::init(pref, true); - GtkToggleButton *button = GTK_TOGGLE_BUTTON(get_widget(button_name)); - - gtk_toggle_button_set_active(button, show); - connect_signal(button_name, "toggled", G_CALLBACK(toggle_playlist), plist); - toggle_playlist(button, (void *)plist); -} - -void init_status() -{ - connect_signal("TrackProgress", "change-value", G_CALLBACK(slider_changed), NULL); - connect_signal("NoPause", "toggled", G_CALLBACK(toggle_pause), NULL); - connect_signal("PauseAfterN", "toggled", G_CALLBACK(toggle_pause), NULL); - connect_signal("PauseCounter", "value-changed", G_CALLBACK(counter_changed), NULL); - connect_signal("BanButton", "toggled", G_CALLBACK(toggle_ban), NULL); - connect_signal("ShowBanned", "toggled", G_CALLBACK(toggle_playlist), libsaria::ban::get_banned_plist()); - - init_plist_visible_button("ShowRecent", "ocarina.showrecent", libsaria::deck::get_recent_plist()); - init_plist_visible_button("ShowBanned", "ocarina.showbanned", libsaria::ban::get_banned_plist()); -} diff --git a/ocarina/tabs.cpp b/ocarina/tabs.cpp deleted file mode 100644 index d57a6180..00000000 --- a/ocarina/tabs.cpp +++ /dev/null @@ -1,283 +0,0 @@ -// Copyright (c) 2011 Bryan Schumaker -#include -#include -#include -#include -#include - -#include "ocarina.h" - -#include -using namespace std; - -static GtkNotebook *tabs; -static PlaylistWidgets library_widgets; -static PlaylistWidgets recent_widgets; -static PlaylistWidgets banned_widgets; -static list dynamic_widgets; - -struct PlaylistWidgets *find_page_widgets(GtkWidget *page) -{ - list::iterator it; - for (it = dynamic_widgets.begin(); it != dynamic_widgets.end(); it++) { - if (GTK_WIDGET((*it)->page_box) == page) - return *it; - } - return NULL; -} - -struct PlaylistWidgets *find_playlist_widgets(libsaria::Playlist *plist) -{ - list::iterator it; - - if (plist == library_widgets.playlist) - return &library_widgets; - else if (plist == recent_widgets.playlist) - return &recent_widgets; - else if (plist == banned_widgets.playlist) - return &banned_widgets; - - for (it = dynamic_widgets.begin(); it != dynamic_widgets.end(); it++) { - if ((*it)->playlist == plist) - return *it; - } - return NULL; -} - -static struct PlaylistWidgets *find_nth_widgets(unsigned int n) -{ - unsigned int size = dynamic_widgets.size(); - - /* Dynamic playlists */ - if (n < size) - return find_playlist_widgets(libsaria::deck::get_playlist(n)); - - switch (n - size) { - case 0: - return &library_widgets; - case 1: - return &recent_widgets; - case 2: - return &banned_widgets; - } - return NULL; -} - -struct PlaylistWidgets *current_widgets() -{ - return find_nth_widgets(gtk_notebook_get_current_page(tabs)); -} - -libsaria::Playlist *current_playlist() -{ - return current_widgets()->playlist; -} - -void playlist_switch_to(string &key) -{ - unsigned int size = dynamic_widgets.size(); - - if (key == "l") - gtk_notebook_set_current_page(tabs, size); - else if (key == "r") - gtk_notebook_set_current_page(tabs, size + 1); - else if (key == "b") - gtk_notebook_set_current_page(tabs, size + 2); -} - -void playlist_switch_to_n(unsigned int n) -{ - unsigned int size = dynamic_widgets.size(); - if (size <= n) - return; - gtk_notebook_set_current_page(tabs, n); -} - -bool playlist_entry_focused() -{ - return gtk_widget_is_focus(GTK_WIDGET(current_widgets()->entry)); -} - -void playlist_focus_entry() -{ - gtk_widget_grab_focus(GTK_WIDGET(current_widgets()->entry)); -} - -bool playlist_key_press(string &key) -{ - GtkTreeView *treeview = current_widgets()->treeview; - if (gtk_widget_is_focus(GTK_WIDGET(treeview))) - return playlist_key_pressed(treeview, key); - return false; -} - -void playlist_focus_treeview() -{ - GtkTreePath *path; - GtkTreeView *treeview = current_widgets()->treeview; - - gtk_widget_grab_focus(GTK_WIDGET(treeview)); - gtk_tree_view_get_cursor(treeview, &path, NULL); - if (path == NULL) - return; - gtk_tree_view_set_cursor(treeview, path, NULL, FALSE); - gtk_tree_path_free(path); -} - -static void on_switch_page(GtkNotebook *tabs, gpointer page, - unsigned int page_num, gpointer data) -{ - struct PlaylistWidgets *widgets = find_nth_widgets(page_num); - update_length_label(widgets->playlist); -} - -static void on_page_reordered(GtkWidget *notebook, GtkWidget *page, guint num, gpointer d) -{ - struct PlaylistWidgets *widgets = find_page_widgets(page); - unsigned int n = libsaria::deck::move_playlist(widgets->playlist, num); - if (n != num) - gtk_notebook_reorder_child(tabs, page, n); -} - -static void on_click_open(GtkWidget *b, gpointer d) -{ - string file = run_chooser("FileChooser"); - if (file != "") { - println("Playing file: " + file); - libsaria::play_outside_song(file); - } -} - -static void init_tab_action() -{ - GtkWidget *box = gtk_vbox_new(FALSE, 0); - GtkWidget *img = gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_BUTTON); - GtkWidget *open = gtk_button_new(); - - gtk_button_set_image(GTK_BUTTON(open), img); - g_signal_connect(open, "clicked", G_CALLBACK(on_click_open), NULL); - - gtk_box_pack_start(GTK_BOX(box), open, false, false, 0); - gtk_box_pack_start(GTK_BOX(box), get_widget("BanButton"), false, false, 0); - gtk_widget_show_all(box); - gtk_notebook_set_action_widget(tabs, box, GTK_PACK_END); -} - -static void add_page(GtkWidget *page, GtkWidget *tab_label, int page_num) -{ - gtk_notebook_insert_page(tabs, page, tab_label, page_num); -} - -static void make_tab_label(const string &name, struct PlaylistWidgets *widgets) -{ - GtkWidget *box = gtk_vbox_new(FALSE, 0); - GtkWidget *label = gtk_label_new(name.c_str()); - widgets->tab_box = GTK_BOX(gtk_hbox_new(FALSE, 0)); - - gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.0); - gtk_misc_set_alignment(GTK_MISC(widgets->size_label), 1.0, 0.0); - - gtk_box_pack_start(widgets->tab_box, GTK_WIDGET(widgets->page_label), FALSE, FALSE, 0); - gtk_box_pack_start(widgets->tab_box, box, TRUE, TRUE, 0); - - gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0); - gtk_box_pack_start(GTK_BOX(box), GTK_WIDGET(widgets->size_label), FALSE, FALSE, 0); - - gtk_widget_show_all(GTK_WIDGET(widgets->tab_box)); -} - -static void init_page(const string &name, struct PlaylistWidgets *widgets, - libsaria::Playlist *playlist, int page_num, unsigned int flags) -{ - setup_widgets(widgets, playlist); - setup_playlist_page(widgets, flags); - make_tab_label(name, widgets); - add_page(GTK_WIDGET(widgets->page_box), GTK_WIDGET(widgets->tab_box), page_num); -} - -void init_tabs() -{ - tabs = GTK_NOTEBOOK(get_widget("PlaylistTabs")); - init_tab_action(); - - init_page("Library", &library_widgets, libsaria::library::get_playlist(), -1, RANDOM_BUTTON); - init_page("Recent", &recent_widgets, libsaria::deck::get_recent_plist(), -1, NO_EXTRA_WIDGETS); - init_page("Banned", &banned_widgets, libsaria::ban::get_banned_plist(), -1, NO_EXTRA_WIDGETS); - - connect_signal("PlaylistTabs", "switch-page", G_CALLBACK(on_switch_page), NULL); - connect_signal("PlaylistTabs", "page-reordered", G_CALLBACK(on_page_reordered), NULL); -} - -static void new_playlist(libsaria::Playlist *playlist) -{ - struct PlaylistWidgets *widgets = new struct PlaylistWidgets; - dynamic_widgets.push_back(widgets); - init_page("Playlist", widgets, playlist, - libsaria::deck::get_playlist_index(playlist), - CLOSE_BUTTON | DISABLE_BUTTON | RANDOM_BUTTON | SORT_BUTTON); - gtk_notebook_set_tab_reorderable(tabs, GTK_WIDGET(widgets->page_box), true); -} - -static void delete_playlist(libsaria::Playlist *playlist) -{ - struct PlaylistWidgets *widgets = find_playlist_widgets(playlist); - int page_num = gtk_notebook_page_num(tabs, GTK_WIDGET(widgets->page_box)); - int cur_page = gtk_notebook_get_current_page(tabs); - - if (cur_page == page_num) - gtk_notebook_set_current_page(tabs, cur_page + 1); - - dynamic_widgets.remove(widgets); - delete widgets; - gtk_notebook_remove_page(tabs, page_num); -} - -static void renumber_playlist(libsaria::Playlist *playlist) -{ - stringstream s; - struct PlaylistWidgets *widgets = find_playlist_widgets(playlist); - s << "" << playlist->get_number() << " "; - gtk_label_set_markup(widgets->page_label, s.str().c_str()); - gtk_notebook_reorder_child(tabs, GTK_WIDGET(widgets->page_box), - playlist->get_number()); -} - -static void disable_playlist(libsaria::Playlist *playlist) -{ - bool enabled = !playlist->check_flag(PL_DISABLED); - struct PlaylistWidgets *widgets = find_playlist_widgets(playlist); - - if (widgets) { - gtk_toggle_button_set_active(widgets->disable, !enabled); - gtk_widget_set_sensitive(GTK_WIDGET(widgets->treeview), enabled); - gtk_widget_set_sensitive(GTK_WIDGET(widgets->tab_box), enabled); - } -} - -static void random_playlist(libsaria::Playlist *playlist) -{ - struct PlaylistWidgets *widgets = find_playlist_widgets(playlist); - if (widgets) - gtk_toggle_button_set_active(widgets->random, playlist->check_flag(PL_RANDOM)); -} - -static void sort_playlist(libsaria::Playlist *playlist) -{ - struct PlaylistWidgets *widgets = find_playlist_widgets(playlist); - if (widgets) - gtk_toggle_button_set_active(widgets->sort, playlist->check_flag(PL_SORTED)); -} - -void update_tabs(notify_t event, libsaria::Playlist *playlist) -{ - if (event == PLAYLIST_NEW) - new_playlist(playlist); - else if (event == PLAYLIST_DELETE) - delete_playlist(playlist); - else if (event == PLAYLIST_CHANGED) { - disable_playlist(playlist); - random_playlist(playlist); - sort_playlist(playlist); - } else if (event == PLAYLIST_RENUMBER) - renumber_playlist(playlist); -} diff --git a/ocarina/window.cpp b/ocarina/window.cpp deleted file mode 100644 index bfbbcd44..00000000 --- a/ocarina/window.cpp +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright (c) 2011 Bryan Schumaker -#include -#include -#include -#include "ocarina.h" - -static int old_w, old_h; -static bool ignore_configure_event = false; - -static gboolean configure(GtkWidget *widget, GdkEvent *event, gpointer data) -{ - int w = event->configure.width; - int h = event->configure.height; - int cur_w = libsaria::prefs::get("ocarina.window.w"); - int cur_h = libsaria::prefs::get("ocarina.window.h"); - - if (ignore_configure_event == true) { - ignore_configure_event = false; - return FALSE; - } - - if (w != cur_w) - libsaria::prefs::set("ocarina.window.w", w); - if (h != cur_h) - libsaria::prefs::set("ocarina.window.h", h); - return FALSE; -} - -static void window_state(GtkWidget *widget, GdkEvent *event, gpointer data) -{ - bool maximized = libsaria::prefs::get("ocarina.window.maximized"); - - if (!(event->window_state.changed_mask & GDK_WINDOW_STATE_MAXIMIZED)) - return; - - maximized = event->window_state.new_window_state & GDK_WINDOW_STATE_MAXIMIZED; - - println("Maximization changed to: %d", maximized); - libsaria::prefs::set("ocarina.window.maximized", maximized); - ignore_configure_event = true; - if (maximized) { - println("Restoring old (w,h): (%d, %d)", old_w, old_h); - libsaria::prefs::set("ocarina.window.w", old_w); - libsaria::prefs::set("ocarina.window.h", old_h); - } -} - -static gboolean key_pressed(GtkWindow *window, GdkEvent *event, gpointer data) -{ - string key = gdk_keyval_name(event->key.keyval); - if (key.substr(0, 3) == "KP_") - key = key.substr(3); - - if (playlist_key_press(key)) - return TRUE; - - if (key == "Escape") { - gtk_window_set_focus(window, NULL); - return TRUE; - } - - if (playlist_entry_focused()) - return FALSE; - - /* - * TODO: something for banning / unbanning songs - * something for incrementing / decrementing the pause after N count - */ - if (key == "b" || key == "l" || key == "r") { - playlist_switch_to(key); - gtk_window_set_focus(window, NULL); - } else if (key == "j" || key == "k") - playlist_focus_treeview(); - else if (key >= "0" && key <= "9") - playlist_switch_to_n(atoi(key.c_str())); - else if (key == "n") - libsaria::deck::next(); - else if (key == "N") - libsaria::deck::prev(); - else if (key == "slash") - playlist_focus_entry(); - else if (key == "space") - libsaria::audio::toggle_play(); - else if (key == "Return") - playlist_focus_treeview(); - else { - println("Unhandled key: " + key); - return FALSE; - } - return TRUE; -} - -void init_window() -{ - GtkWindow *window = GTK_WINDOW(get_widget("MainWindow")); - - gtk_window_set_title(window, ("Ocarina " + vers_str()).c_str()); - gtk_window_set_icon_from_file(window, lib_file("ocarina.png").c_str(), NULL); - - old_h = libsaria::prefs::init("ocarina.window.h", 600); - old_w = libsaria::prefs::init("ocarina.window.w", 900); - gtk_window_resize(window, old_w, old_h); - if (libsaria::prefs::init("ocarina.window.maximized", false) == true) - gtk_window_maximize(window); - - connect_signal("MainWindow", "destroy", gtk_main_quit, NULL); - connect_signal("MainWindow", "configure-event", G_CALLBACK(configure), NULL); - connect_signal("MainWindow", "window-state-event", G_CALLBACK(window_state), NULL); - connect_signal("MainWindow", "key-press-event", G_CALLBACK(key_pressed), NULL); -}