📄 playlist.cpp
字号:
/***************************************************************************** * playlist.cpp : wxWindows plugin for vlc ***************************************************************************** * Copyright (C) 2000-2005 VideoLAN * $Id: playlist.cpp 11236 2005-06-01 19:53:37Z courmisch $ * * Authors: Olivier Teuli鑢e <ipkiss@via.ecp.fr> * Cl閙ent Stenac <zorglub@videolan.org> * * This program is free software; you can redistribute it and/OR MODIFy * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#include <vlc/vlc.h>#include <vlc/intf.h>#include "wxwindows.h"#include "bitmaps/shuffle.xpm"#include "bitmaps/repeat.xpm"#include "bitmaps/loop.xpm"#include "bitmaps/type_unknown.xpm"#include "bitmaps/type_afile.xpm"#include "bitmaps/type_vfile.xpm"#include "bitmaps/type_net.xpm"#include "bitmaps/type_card.xpm"#include "bitmaps/type_disc.xpm"#include "bitmaps/type_cdda.xpm"#include "bitmaps/type_directory.xpm"#include "bitmaps/type_playlist.xpm"#include "bitmaps/type_node.xpm"#include <wx/dynarray.h>#include <wx/imaglist.h>#define HELP_SHUFFLE N_( "Shuffle" )#define HELP_LOOP N_( "Repeat All" )#define HELP_REPEAT N_( "Repeat One" )namespace wxvlc {/* Callback prototype */static int PlaylistChanged( vlc_object_t *, const char *, vlc_value_t, vlc_value_t, void * );static int PlaylistNext( vlc_object_t *, const char *, vlc_value_t, vlc_value_t, void * );static int ItemChanged( vlc_object_t *, const char *, vlc_value_t, vlc_value_t, void * );static int ItemAppended( vlc_object_t *p_this, const char *psz_variable, vlc_value_t oval, vlc_value_t nval, void *param );static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable, vlc_value_t oval, vlc_value_t nval, void *param );/***************************************************************************** * Event Table. *****************************************************************************//* IDs for the controls and the menu commands */enum{ /* menu items */ AddFile_Event = 1, AddDir_Event, AddMRL_Event, Close_Event, Open_Event, Save_Event, SortTitle_Event, RSortTitle_Event, Randomize_Event, DeleteSelection_Event, Random_Event, Loop_Event, Repeat_Event, PopupPlay_Event, PopupPlayThis_Event, PopupPreparse_Event, PopupSort_Event, PopupDel_Event, PopupInfo_Event, SearchText_Event, Search_Event, /* controls */ TreeCtrl_Event, Browse_Event, /* For export playlist */ /* custom events */ UpdateItem_Event, AppendItem_Event, RemoveItem_Event, MenuDummy_Event = wxID_HIGHEST + 999, FirstView_Event = wxID_HIGHEST + 1000, LastView_Event = wxID_HIGHEST + 1100, FirstSD_Event = wxID_HIGHEST + 2000, LastSD_Event = wxID_HIGHEST + 2100,};DEFINE_LOCAL_EVENT_TYPE( wxEVT_PLAYLIST );BEGIN_EVENT_TABLE(Playlist, wxFrame) EVT_SIZE(Playlist::OnSize) /* Menu events */ EVT_MENU(AddFile_Event, Playlist::OnAddFile) EVT_MENU(AddDir_Event, Playlist::OnAddDir) EVT_MENU(AddMRL_Event, Playlist::OnAddMRL) EVT_MENU(Close_Event, Playlist::OnMenuClose) EVT_MENU(Open_Event, Playlist::OnOpen) EVT_MENU(Save_Event, Playlist::OnSave) EVT_MENU(SortTitle_Event, Playlist::OnSort) EVT_MENU(RSortTitle_Event, Playlist::OnSort) EVT_MENU(Randomize_Event, Playlist::OnSort) EVT_MENU(DeleteSelection_Event, Playlist::OnDeleteSelection) EVT_MENU_OPEN( Playlist::OnMenuOpen ) EVT_MENU( -1, Playlist::OnMenuEvent ) EVT_TOOL(Random_Event, Playlist::OnRandom) EVT_TOOL(Repeat_Event, Playlist::OnRepeat) EVT_TOOL(Loop_Event, Playlist::OnLoop) /* Popup events */ EVT_MENU( PopupPlay_Event, Playlist::OnPopupPlay) EVT_MENU( PopupPlayThis_Event, Playlist::OnPopupPlay) EVT_MENU( PopupPreparse_Event, Playlist::OnPopupPreparse) EVT_MENU( PopupSort_Event, Playlist::OnPopupSort) EVT_MENU( PopupDel_Event, Playlist::OnPopupDel) EVT_MENU( PopupInfo_Event, Playlist::OnPopupInfo) /* Tree control events */ EVT_TREE_ITEM_ACTIVATED( TreeCtrl_Event, Playlist::OnActivateItem ) EVT_TREE_KEY_DOWN( -1, Playlist::OnKeyDown ) EVT_CONTEXT_MENU( Playlist::OnPopup ) /* Button events */ EVT_BUTTON( Search_Event, Playlist::OnSearch) EVT_BUTTON( Save_Event, Playlist::OnSave) /*EVT_TEXT( SearchText_Event, Playlist::OnSearchTextChange )*/ EVT_TEXT_ENTER( SearchText_Event, Playlist::OnSearch ) /* Custom events */ EVT_COMMAND(-1, wxEVT_PLAYLIST, Playlist::OnPlaylistEvent) /* Special events : we don't want to destroy the window when the user * clicks on (X) */ EVT_CLOSE(Playlist::OnClose)END_EVENT_TABLE()/***************************************************************************** * PlaylistItem class ****************************************************************************/class PlaylistItem : public wxTreeItemData{public: PlaylistItem( playlist_item_t *p_item ) : wxTreeItemData() { i_id = p_item->input.i_id; }protected: int i_id;friend class Playlist;};/***************************************************************************** * Constructor. *****************************************************************************/Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ): wxFrame( p_parent, -1, wxU(_("Playlist")), wxDefaultPosition, wxSize(500,300), wxDEFAULT_FRAME_STYLE ){ vlc_value_t val; /* Initializations */ p_intf = _p_intf; i_update_counter = 0; i_sort_mode = MODE_NONE; b_need_update = VLC_FALSE; p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); if( p_playlist == NULL ) { return; } SetIcon( *p_intf->p_sys->p_icon ); p_view_menu = NULL; p_sd_menu = SDMenu(); i_current_view = VIEW_CATEGORY; b_changed_view = VLC_FALSE; i_title_sorted = 0; i_group_sorted = 0; i_duration_sorted = 0; var_Create( p_intf, "random", VLC_VAR_BOOL | VLC_VAR_DOINHERIT ); var_Create( p_intf, "loop", VLC_VAR_BOOL | VLC_VAR_DOINHERIT ); var_Create( p_intf, "repeat", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );; /* Create our "Manage" menu */ wxMenu *manage_menu = new wxMenu; manage_menu->Append( AddFile_Event, wxU(_("&Simple Add File...")) ); manage_menu->Append( AddDir_Event, wxU(_("Add &Directory...")) ); manage_menu->Append( AddMRL_Event, wxU(_("&Add MRL...")) ); manage_menu->AppendSeparator(); manage_menu->Append( MenuDummy_Event, wxU(_("Services discovery")), p_sd_menu ); manage_menu->AppendSeparator(); manage_menu->Append( Open_Event, wxU(_("&Open Playlist...")) ); manage_menu->Append( Save_Event, wxU(_("&Save Playlist...")) ); manage_menu->AppendSeparator(); manage_menu->Append( Close_Event, wxU(_("&Close")) ); /* Create our "Sort" menu */ wxMenu *sort_menu = new wxMenu; sort_menu->Append( SortTitle_Event, wxU(_("Sort by &title")) ); sort_menu->Append( RSortTitle_Event, wxU(_("&Reverse sort by title")) ); sort_menu->AppendSeparator(); sort_menu->Append( Randomize_Event, wxU(_("&Shuffle Playlist")) ); /* Create our "Selection" menu */ wxMenu *selection_menu = new wxMenu; selection_menu->Append( DeleteSelection_Event, wxU(_("D&elete")) ); /* Create our "View" menu */ ViewMenu(); /* Append the freshly created menus to the menu bar */ wxMenuBar *menubar = new wxMenuBar(); menubar->Append( manage_menu, wxU(_("&Manage")) ); menubar->Append( sort_menu, wxU(_("S&ort")) ); menubar->Append( selection_menu, wxU(_("&Selection")) ); menubar->Append( p_view_menu, wxU(_("&View items") ) ); /* Attach the menu bar to the frame */ SetMenuBar( menubar ); /* Create the popup menu */ node_popup = new wxMenu; node_popup->Append( PopupPlay_Event, wxU(_("Play")) ); node_popup->Append( PopupPlayThis_Event, wxU(_("Play this branch")) ); node_popup->Append( PopupPreparse_Event, wxU(_("Preparse")) ); node_popup->Append( PopupSort_Event, wxU(_("Sort this branch")) ); node_popup->Append( PopupDel_Event, wxU(_("Delete")) ); node_popup->Append( PopupInfo_Event, wxU(_("Info")) ); item_popup = new wxMenu; item_popup->Append( PopupPlay_Event, wxU(_("Play")) ); item_popup->Append( PopupPreparse_Event, wxU(_("Preparse")) ); item_popup->Append( PopupDel_Event, wxU(_("Delete")) ); item_popup->Append( PopupInfo_Event, wxU(_("Info")) ); /* Create a panel to put everything in */ wxPanel *playlist_panel = new wxPanel( this, -1 ); playlist_panel->SetAutoLayout( TRUE ); /* Create the toolbar */ wxToolBar *toolbar = CreateToolBar( wxTB_HORIZONTAL | wxTB_FLAT ); /* Create the random tool */ toolbar->AddTool( Random_Event, wxT(""), wxBitmap(shuffle_on_xpm), wxBitmap(shuffle_on_xpm), wxITEM_CHECK, wxU(_(HELP_SHUFFLE) ) ); var_Get( p_intf, "random", &val ); toolbar->ToggleTool( Random_Event, val.b_bool ); /* Create the Loop tool */ toolbar->AddTool( Loop_Event, wxT(""), wxBitmap( loop_xpm), wxBitmap( loop_xpm), wxITEM_CHECK, wxU(_(HELP_LOOP ) ) ); var_Get( p_intf, "loop", &val ); toolbar->ToggleTool( Loop_Event, val.b_bool ); /* Create the Repeat one checkbox */ toolbar->AddTool( Repeat_Event, wxT(""), wxBitmap( repeat_xpm), wxBitmap( repeat_xpm), wxITEM_CHECK, wxU(_(HELP_REPEAT ) ) ); var_Get( p_intf, "repeat", &val ); toolbar->ToggleTool( Repeat_Event, val.b_bool ) ; /* Create the Search Textbox */ search_text = new wxTextCtrl( toolbar, SearchText_Event, wxT(""), wxDefaultPosition, wxSize(100, -1), wxTE_PROCESS_ENTER); /* Create the search button */ search_button = new wxButton( toolbar , Search_Event, wxU(_("Search")) ); toolbar->AddControl( new wxControl( toolbar, -1, wxDefaultPosition, wxSize(16, 16), wxBORDER_NONE ) ); toolbar->AddControl( search_text ); toolbar->AddControl( new wxControl( toolbar, -1, wxDefaultPosition, wxSize(5, 5), wxBORDER_NONE ) ); toolbar->AddControl( search_button ); search_button->SetDefault(); toolbar->Realize(); /* Create the tree */ treectrl = new wxTreeCtrl( playlist_panel, TreeCtrl_Event, wxDefaultPosition, wxDefaultSize, wxTR_HIDE_ROOT | wxTR_LINES_AT_ROOT| wxTR_NO_LINES | wxTR_HAS_BUTTONS | wxTR_TWIST_BUTTONS | wxTR_MULTIPLE | wxTR_EXTENDED ); /* Create image list */ wxImageList *p_images = new wxImageList( 16 , 16, TRUE ); /* FIXME: absolutely needs to be in the right order FIXME */ p_images->Add( wxIcon( type_unknown_xpm ) ); p_images->Add( wxIcon( type_afile_xpm ) ); p_images->Add( wxIcon( type_vfile_xpm ) ); p_images->Add( wxIcon( type_directory_xpm ) ); p_images->Add( wxIcon( type_disc_xpm ) ); p_images->Add( wxIcon( type_cdda_xpm ) ); p_images->Add( wxIcon( type_card_xpm ) ); p_images->Add( wxIcon( type_net_xpm ) ); p_images->Add( wxIcon( type_playlist_xpm ) ); p_images->Add( wxIcon( type_node_xpm ) ); treectrl->AssignImageList( p_images ); treectrl->AddRoot( wxU(_("root" )), -1, -1, NULL ); /* Reduce font size */ wxFont font= treectrl->GetFont(); font.SetPointSize(9); treectrl->SetFont( font ); wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL ); panel_sizer->Add( treectrl, 1, wxEXPAND | wxALL, 5 ); panel_sizer->Layout(); playlist_panel->SetSizerAndFit( panel_sizer ); int pi_widths[1] = { -1 }; statusbar = CreateStatusBar( 1 ); statusbar->SetStatusWidths( 1, pi_widths );#if wxUSE_DRAG_AND_DROP /* Associate drop targets with the playlist */ SetDropTarget( new DragAndDrop( p_intf, VLC_TRUE ) );#endif i_saved_id = -1; /* We want to be noticed of playlist changes */ /* Some global changes happened -> Rebuild all */ var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -