From 4bfdb2d0d4621dad1a2212e673301e06e49122a4 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Sat, 17 Jan 2015 10:40:36 -0500 Subject: [PATCH] gui: Merge lib/plist.cpp back into gui/plist.cpp The lib/ experiment made the gui code a little more complicated than I was expecting, so I'm going to begin merging everything back into gui/ Signed-off-by: Anna Schumaker --- gui/playlist.cpp | 36 ++++++++++++++++++++++++++++++---- include/lib/plist.h | 21 -------------------- lib/plist.cpp | 47 --------------------------------------------- 3 files changed, 32 insertions(+), 72 deletions(-) delete mode 100644 include/lib/plist.h delete mode 100644 lib/plist.cpp diff --git a/gui/playlist.cpp b/gui/playlist.cpp index 827b566a..e63c4bc1 100644 --- a/gui/playlist.cpp +++ b/gui/playlist.cpp @@ -3,11 +3,23 @@ */ #include #include -#include #include +static Glib::ustring get_path(const Gtk::TreePath &); static bool find_cur_path(Gtk::TreePath &); +static void del_path_ids(const Gtk::TreePath &, std::vector &); + + +static class PlaylistColumns : public Gtk::TreeModelColumnRecord { +public: + Gtk::TreeModelColumn p_name; + + PlaylistColumns() + { + add(p_name); + } +} p_cols; class PlaylistTab : public Tab { @@ -34,7 +46,7 @@ public: return Tab :: on_key_press_event(key); if (find_cur_path(path)) { tab_selected_ids(ids); - plist :: del_path_ids(path, ids); + del_path_ids(path, ids); } return true; } @@ -45,11 +57,18 @@ static Gtk::ToggleButton *o_fav; static PlaylistTab *p_tab; static Gtk::TreeView *p_treeview; +static Glib::RefPtr p_list; /* * Sidebar code */ +static Glib::ustring get_path(const Gtk::TreePath &path) +{ + Gtk::TreeModel::Row row = *(p_list->get_iter(path)); + return row[p_cols.p_name]; +} + static bool find_cur_path(Gtk::TreePath &path) { Gtk::TreeViewColumn *col; @@ -57,11 +76,20 @@ static bool find_cur_path(Gtk::TreePath &path) return !path.empty(); } +static void del_path_ids(const Gtk::TreePath &path, + std::vector &ids) +{ + std::string name = get_path(path); + + for (unsigned int i = 0; i < ids.size(); i++) + playlist :: del(tags :: get_track(ids[i]), name); +} + static void on_playlist_cursor_changed() { Gtk::TreePath path; if (find_cur_path(path)) - plist :: select_path(path); + playlist :: select(get_path(path)); } static bool on_playlist_clicked(GdkEventButton *button) @@ -102,8 +130,8 @@ void on_track_loaded(Track *track) void init_playlist_tab() { - plist :: init(); p_tab = new PlaylistTab; + p_list = lib :: get_object("plist_list"); p_treeview = lib :: get_widget("plist_treeview"); p_treeview->signal_cursor_changed().connect(sigc::ptr_fun(on_playlist_cursor_changed)); diff --git a/include/lib/plist.h b/include/lib/plist.h deleted file mode 100644 index f51b86d0..00000000 --- a/include/lib/plist.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2014 (c) Anna Schumaker. - */ -#ifndef OCARINA_LIB_PLIST_H -#define OCARINA_LIB_PLIST_H - -#include -#include - -namespace plist -{ - - void init(); - - Glib::ustring get_path(const Gtk::TreePath &); - void select_path(const Gtk::TreePath &); - void del_path_ids(const Gtk::TreePath &, std::vector &); - -} - -#endif /* OCARINA_LIB_PLIST_H */ diff --git a/lib/plist.cpp b/lib/plist.cpp deleted file mode 100644 index c935666d..00000000 --- a/lib/plist.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2014 (c) Anna Schumaker. - */ -#include -#include -#include - - -class PlaylistColumns : public Gtk::TreeModelColumnRecord { -public: - Gtk::TreeModelColumn p_name; - - PlaylistColumns() - { - add(p_name); - } -}; - - -static PlaylistColumns p_cols; -static Glib::RefPtr p_list; - - -void plist :: init() -{ - p_list = lib :: get_object("plist_list"); -} - -Glib::ustring plist :: get_path(const Gtk::TreePath &path) -{ - Gtk::TreeModel::Row row = *(p_list->get_iter(path)); - return row[p_cols.p_name]; -} - -void plist :: select_path(const Gtk::TreePath &path) -{ - playlist :: select(get_path(path)); -} - -void plist :: del_path_ids(const Gtk::TreePath &path, - std::vector &ids) -{ - std::string name = plist :: get_path(path); - - for (unsigned int i = 0; i < ids.size(); i++) - playlist :: del(tags :: get_track(ids[i]), name); -}