Archive / / / / / Echo.Controller.Actions.MainActions.vala
2008-11-28 05:35:41 UTC
previous next
/* vim: set noexpandtab tabstop=4 shiftwidth=4 nowrap textwidth=100 * * 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. ] */ using Echo.Controller.Tabs; using Echo.Core; using Echo.Database; using Echo.Interfaces; using Echo.UI; using Echo.UI.Preferences; using Echo.UI.Tabs; using Echo.UI.Widgets; public class Echo.Controller.Actions.MainActions : GLib.Object { private bool _fullscreen = false; public MainActions() { // File menu Services.ui().get_action("new-playlist").activate += this.on_new_playlist; //add_action("new-smart-playlist", "New _Smart Playlist"); //add_action("open-file", null, "gtk-open"); //add_action("open-url", "Open _URL"); Services.ui().get_action("refresh-libraries").activate += this.on_refresh_libraries; Services.ui().get_action("close").activate += this.on_close; Services.ui().get_action("quit").activate += this.on_quit; // Edit menu Services.ui().get_action("edit-preferences").activate += this.on_edit_preferences; // View menu ((Gtk.ToggleAction)Services.ui().get_action("view-browser")).activate += this.on_view_browser; Services.ui().get_action("view-fullscreen").activate += this.on_view_fullscreen; // Help menu //add_action("about", null, "gtk-about"); // Sources pane Services.ui().main_window.sources_pane.now_playing_opened += this.on_now_playing_opened; Services.ui().main_window.sources_pane.library_opened += this.on_library_opened; // Tab pane Services.ui().main_window.tab_pane.tab_removed += this.on_tab_removed; // Connect signals that update actions: Services.ui().main_window.window_state_event += (window, event) => { _fullscreen = ((event.new_window_state & Gdk.WindowState.FULLSCREEN) != 0); Services.ui().get_action("view-fullscreen").set("stock-id", (_fullscreen) ? "gtk-leave-fullscreen" : "gtk-fullscreen"); return false; }; } private void on_new_playlist(Gtk.Action action) { int playlist_num = 1; bool found_num = false; while (found_num == false) { found_num = true; foreach(ITab tab in Services.ui().main_window.tab_pane.tabs) { if (tab is PlaySourceTab && ((PlaySourceTab)tab).get_name() == "Playlist %d".printf(playlist_num)) { playlist_num++; found_num = false; break; } } } Services.ui().main_window.tab_pane.add_tab( PlaySourceTabController.create_tab(new Playlist("Playlist %d".printf(playlist_num)))); } private void on_refresh_libraries(Gtk.Action action) { foreach(Library library in Services.database().get_libraries()) { library.refresh_tracks(); } } private void on_close(Gtk.Action action) { Services.ui().main_window.hide(); } private void on_quit(Gtk.Action action) { Gtk.main_quit(); } private void on_edit_preferences(Gtk.Action action) { PreferencesWindow.create(Services.ui().main_window); } private void on_view_browser(Gtk.ToggleAction action) { Services.ui().main_window.browser_pane.visible = action.active; } private void on_view_fullscreen(Gtk.Action action) { if (_fullscreen) Services.ui().main_window.unfullscreen(); else Services.ui().main_window.fullscreen(); } private void on_now_playing_opened(SourcesPane sources_pane) { foreach(ITab tab in Services.ui().main_window.tab_pane.tabs) { if (tab is NowPlayingTab) { Services.ui().main_window.tab_pane.switch_to_tab(tab); return; } } Services.ui().main_window.tab_pane.add_tab(new NowPlayingTab()); } private void on_library_opened(SourcesPane sources_pane, Library library) { foreach(ITab tab in Services.ui().main_window.tab_pane.tabs) { if (tab is PlaySourceTab && ((PlaySourceTab)tab).source == (IPlaySource)library) { Services.ui().main_window.tab_pane.switch_to_tab(tab); return; } } Services.ui().main_window.tab_pane.add_tab(PlaySourceTabController.create_tab(library)); } private void on_tab_removed(TabPane tab_pane) { if (tab_pane.tabs.size == 0) Services.ui().main_window.tab_pane.add_tab(new NowPlayingTab()); } }