]> git.sesse.net Git - vlc/blob - plugins/beos/PlayListWindow.cpp
a3082b41c379a6990f0487e9042eaab2c6ee72a3
[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.6 2002/06/01 08:54:08 tcastley 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 "MsgVals.h"
47 #include "PlayListWindow.h"
48
49 /*****************************************************************************
50  * PlayListWindow
51  *****************************************************************************/
52 PlayListWindow *PlayListWindow::getPlayList( BRect frame, const char *name,
53                                   playlist_t *p_pl)
54 {
55     static PlayListWindow *one_playlist;
56     if (one_playlist == NULL)
57     {
58        one_playlist = new PlayListWindow(frame, name, p_pl);
59     }
60     return one_playlist;
61 }
62
63 PlayListWindow::PlayListWindow( BRect frame, const char *name,
64                                   playlist_t *p_pl)
65     : BWindow( frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
66                 B_WILL_ACCEPT_FIRST_CLICK | B_ASYNCHRONOUS_CONTROLS )
67 {
68     SetName( "playlist" );
69     SetTitle(name);
70     p_playlist = p_pl;
71
72     /* set up the main menu */
73     BMenuBar *menu_bar;
74     menu_bar = new BMenuBar(BRect(0,0,0,0), "main menu");
75     AddChild( menu_bar );
76
77     BMenu *mFile;
78     /* Add the file Menu */
79     BMenuItem *mItem;
80     menu_bar->AddItem( mFile = new BMenu( "File" ) );
81     menu_bar->ResizeToPreferred();
82     mFile->AddItem( mItem = new BMenuItem( "Open File" B_UTF8_ELLIPSIS,
83                                            new BMessage(OPEN_FILE), 'O') );
84     
85     CDMenu *cd_menu = new CDMenu( "Open Disc" );
86     mFile->AddItem( cd_menu );
87     
88     BRect rect = Bounds();
89     rect.top += menu_bar->Bounds().IntegerHeight() + 1;
90     BView *p_view = new BView(rect, NULL, B_FOLLOW_ALL_SIDES, B_WILL_DRAW);
91     
92     p_listview = new BListView(rect, "PlayList", 
93                                     B_MULTIPLE_SELECTION_LIST);
94     for (int i=0; i < p_playlist->i_size; i++)
95     {
96         p_listview->AddItem(new BStringItem(p_playlist->p_item[i].psz_name)); 
97     }
98     p_view->AddChild(new BScrollView("scroll_playlist", p_listview,
99              B_FOLLOW_LEFT | B_FOLLOW_TOP, 0, false, true)); 
100              
101     AddChild(p_view);
102 }
103
104 PlayListWindow::~PlayListWindow()
105 {
106 }
107
108 /*****************************************************************************
109  * PlayListWindow::MessageReceived
110  *****************************************************************************/
111 void PlayListWindow::MessageReceived( BMessage * p_message )
112 {
113     Activate();
114
115     switch( p_message->what )
116     {
117     case OPEN_FILE:
118         if( file_panel )
119         {
120             file_panel->Show();
121             break;
122         }
123         file_panel = new BFilePanel();
124         file_panel->SetTarget( this );
125         file_panel->Show();
126         break;
127
128     case OPEN_DVD:
129         const char *psz_device;
130         char psz_source[ B_FILE_NAME_LENGTH + 4 ];
131         if( p_message->FindString("device", &psz_device) != B_ERROR )
132         {
133             snprintf( psz_source, B_FILE_NAME_LENGTH + 4,
134                       "dvd:%s", psz_device );
135             psz_source[ strlen(psz_source) ] = '\0';
136             intf_PlaylistAdd( p_playlist, PLAYLIST_END, (char*)psz_source );
137             p_listview->AddItem(new BStringItem((char*)psz_source));
138         }
139     case B_REFS_RECEIVED:
140     case B_SIMPLE_DATA:
141         {
142             entry_ref ref;
143             if( p_message->FindRef( "refs", &ref ) == B_OK )
144             {
145                 BPath path( &ref );
146                 intf_PlaylistAdd( p_playlist,
147                                   PLAYLIST_END, (char*)path.Path() );
148                 p_listview->AddItem(new BStringItem((char*)path.Path()));
149             }
150         }
151         break;
152     default:
153         BWindow::MessageReceived( p_message );
154         break;
155     }
156 }
157
158 bool PlayListWindow::QuitRequested()
159 {
160     Hide(); 
161     return false;
162 }
163
164 void PlayListWindow::ReallyQuit()
165 {
166     Hide(); 
167     Lock();
168     Quit();
169 }