2008-10-06 17:14: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 "TabPane.h"
#include "LibraryTab.h"
#include "PlaylistTab.h"
#include <iostream>
using namespace std;
TabPane::TabPane()
{
popup_enable();
set_scrollable(true);
//set_show_border(true);
//append_page(*Gtk::manage(new Gtk::HBox()), "Now Playing");
open_tab(m_now_playing_tab, "Now Playing", "applications-multimedia");
}
void TabPane::open_now_playing()
{
set_current_page(page_num(m_now_playing_tab));
}
void TabPane::open_library(LibraryRef library)
{
for (list<boost::shared_ptr<LibraryTab> >::iterator iter = m_library_tabs.begin();
iter != m_library_tabs.end(); iter++ ) {
if ((*iter)->get_library() == library) {
set_current_page(page_num(**iter));
return;
}
}
m_library_tabs.push_back(LibraryTab::create(library));
open_tab(*m_library_tabs.back(),
m_library_tabs.back()->get_tab_name(),
m_library_tabs.back()->get_tab_icon());
}
void TabPane::add_playlist_from_uri(const std::string& uri)
{
m_playlist_tabs.push_back(PlaylistTab::create_from_uri(uri));
open_tab(*m_playlist_tabs.back(), m_playlist_tabs.back()->get_tab_name(), "");
}
void TabPane::add_blank_playlist()
{
int untitled_num = 1;
Glib::ustring name;
while (true) {
bool use_num = true;
name = Glib::ustring::compose("Untitled %1", untitled_num);
for (list<boost::shared_ptr<PlaylistTab> >::iterator iter = m_playlist_tabs.begin();
iter != m_playlist_tabs.end(); iter++)
if ((*iter)->get_tab_name() == name) {
use_num = false;
break;
}
if (use_num)
break;
untitled_num++;
}
m_playlist_tabs.push_back(PlaylistTab::create_blank(name));
open_tab(*m_playlist_tabs.back(), m_playlist_tabs.back()->get_tab_name(), "");
}
void TabPane::open_tab(Gtk::Widget& child, const Glib::ustring& title, const Glib::ustring& icon_name)
{
Gtk::HBox* label = Gtk::manage(new Gtk::HBox());
Gtk::HBox* menu_label = Gtk::manage(new Gtk::HBox());
try {
Glib::RefPtr<Gdk::Pixbuf> icon = Gtk::IconTheme::get_default()->load_icon(icon_name, 16);
label->pack_start(*Gtk::manage(new Gtk::Image(icon)), Gtk::PACK_SHRINK);
label->set_spacing(4);
menu_label->pack_start(*Gtk::manage(new Gtk::Image(icon)), Gtk::PACK_SHRINK);
menu_label->set_spacing(4);
} catch (Glib::Error &e) {}
label->pack_start(*Gtk::manage(new Gtk::Label(title)), Gtk::PACK_SHRINK);
label->show_all();
menu_label->pack_start(*Gtk::manage(new Gtk::Label(title)), Gtk::PACK_SHRINK);
menu_label->show_all();
Gtk::EventBox* label_eventbox = Gtk::manage(new Gtk::EventBox());
label_eventbox->signal_button_release_event().connect(
sigc::bind(sigc::mem_fun(*this, &TabPane::on_tab_click), &child));
label_eventbox->add(*label);
append_page(child, *label_eventbox, *menu_label);
//set_tab_label_packing(child, true, true, Gtk::PACK_START);
set_tab_reorderable(child, true);
show_all_children(true);
set_current_page(page_num(child));
}
bool TabPane::on_tab_click(GdkEventButton* event, Gtk::Widget* child)
{
if (event->button == 2) {
if (child == &m_now_playing_tab)
return false;
for (list<boost::shared_ptr<PlaylistTab> >::iterator iter = m_playlist_tabs.begin();
iter != m_playlist_tabs.end(); iter++) {
if (iter->get() == child) {
remove_page(*child);
m_playlist_tabs.erase(iter);
return true;
}
}
for (list<boost::shared_ptr<LibraryTab> >::iterator iter = m_library_tabs.begin();
iter != m_library_tabs.end(); iter++) {
if (iter->get() == child) {
remove_page(*child);
m_library_tabs.erase(iter);
return true;
}
}
}
return false;
}