]> git.sesse.net Git - vlc/blob - plugins/beos/PlayListWindow.cpp
Some heavy changes today:
[vlc] / plugins / beos / PlayListWindow.cpp
1 /*****************************************************************************
2  * PlayListWindow.cpp: beos interface
3  *****************************************************************************
4  * Copyright (C) 1999, 2000, 2001 VideoLAN
5  * $Id: PlayListWindow.cpp,v 1.5 2001/12/30 07:09:54 sam Exp $
6  *
7  * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
8  *          Samuel Hocevar <sam@zoy.org>
9  *          Tony Castley <tony@castley.net>
10  *          Richard Shepherd <richard@rshepherd.demon.co.uk>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
25  *****************************************************************************/
26
27 /* System headers */
28 #include <InterfaceKit.h>
29 #include <StorageKit.h>
30 #include <string.h>
31
32 /* VLC headers */
33 extern "C"
34 {
35 #include <videolan/vlc.h>
36
37 #include "stream_control.h"
38 #include "input_ext-intf.h"
39
40 #include "interface.h"
41 #include "intf_playlist.h"
42 }
43
44 /* BeOS interface headers */
45 #include "InterfaceWindow.h"
46 #include "PlayListWindow.h"
47 #include "MsgVals.h"
48
49 /*****************************************************************************
50  * PlayListWindow
51  *****************************************************************************/
52
53 PlayListWindow::PlayListWindow( BRect frame, const char *name,
54                                   playlist_t *p_pl)
55     : BWindow( frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
56                 B_WILL_ACCEPT_FIRST_CLICK | B_ASYNCHRONOUS_CONTROLS )
57 {
58     SetName( "playlist" );
59     SetTitle(name);
60     p_playlist = p_pl;
61
62     /* set up the main menu */
63     BMenuBar *menu_bar;
64     menu_bar = new BMenuBar(BRect(0,0,0,0), "main menu");
65     AddChild( menu_bar );
66
67     BMenu *mFile;
68     /* Add the file Menu */
69     BMenuItem *mItem;
70     menu_bar->AddItem( mFile = new BMenu( "File" ) );
71     menu_bar->ResizeToPreferred();
72     mFile->AddItem( mItem = new BMenuItem( "Open File" B_UTF8_ELLIPSIS,
73                                            new BMessage(OPEN_FILE), 'O') );
74     
75     CDMenu *cd_menu = new CDMenu( "Open Disc" );
76     mFile->AddItem( cd_menu );
77     
78     BRect rect = Bounds();
79     rect.top += menu_bar->Bounds().IntegerHeight() + 1;
80     BView *p_view = new BView(rect, NULL, B_FOLLOW_ALL_SIDES, B_WILL_DRAW);
81     
82     p_listview = new BListView(rect, "PlayList", 
83                                     B_MULTIPLE_SELECTION_LIST);
84     for (int i=0; i < p_playlist->i_size; i++)
85     {
86         p_listview->AddItem(new BStringItem(p_playlist->p_item[i].psz_name)); 
87     }
88     p_view->AddChild(new BScrollView("scroll_playlist", p_listview,
89              B_FOLLOW_LEFT | B_FOLLOW_TOP, 0, false, true)); 
90              
91     AddChild(p_view);
92 }
93
94 PlayListWindow::~PlayListWindow()
95 {
96 }
97
98 /*****************************************************************************
99  * PlayListWindow::MessageReceived
100  *****************************************************************************/
101 void PlayListWindow::MessageReceived( BMessage * p_message )
102 {
103     Activate();
104
105     switch( p_message->what )
106     {
107     case OPEN_FILE:
108         if( file_panel )
109         {
110             file_panel->Show();
111             break;
112         }
113         file_panel = new BFilePanel();
114         file_panel->SetTarget( this );
115         file_panel->Show();
116         break;
117
118     case OPEN_DVD:
119         const char *psz_device;
120         char psz_source[ B_FILE_NAME_LENGTH + 4 ];
121         if( p_message->FindString("device", &psz_device) != B_ERROR )
122         {
123             snprintf( psz_source, B_FILE_NAME_LENGTH + 4,
124                       "dvd:%s", psz_device );
125             psz_source[ strlen(psz_source) ] = '\0';
126             intf_PlaylistAdd( p_playlist, PLAYLIST_END, (char*)psz_source );
127             p_listview->AddItem(new BStringItem((char*)psz_source));
128         }
129     case B_REFS_RECEIVED:
130     case B_SIMPLE_DATA:
131         {
132             entry_ref ref;
133             if( p_message->FindRef( "refs", &ref ) == B_OK )
134             {
135                 BPath path( &ref );
136                 intf_PlaylistAdd( p_playlist,
137                                   PLAYLIST_END, (char*)path.Path() );
138                 p_listview->AddItem(new BStringItem((char*)path.Path()));
139             }
140         }
141         break;
142     default:
143         BWindow::MessageReceived( p_message );
144         break;
145     }
146 }