Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

PlayListWindow.cpp

00001 /*****************************************************************************
00002  * PlayListWindow.cpp: beos interface
00003  *****************************************************************************
00004  * Copyright (C) 1999, 2000, 2001 the VideoLAN team
00005  * $Id: PlayListWindow.cpp 12687 2005-09-26 15:03:39Z titer $
00006  *
00007  * Authors: Jean-Marc Dressler <[email protected]>
00008  *          Samuel Hocevar <[email protected]>
00009  *          Tony Castley <[email protected]>
00010  *          Richard Shepherd <[email protected]>
00011  *          Stephan Aßmus <[email protected]>
00012  *
00013  * This program is free software; you can redistribute it and/or modify
00014  * it under the terms of the GNU General Public License as published by
00015  * the Free Software Foundation; either version 2 of the License, or
00016  * (at your option) any later version.
00017  *
00018  * This program is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License
00024  * along with this program; if not, write to the Free Software
00025  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00026  *****************************************************************************/
00027 
00028 /* System headers */
00029 #include <InterfaceKit.h>
00030 #include <StorageKit.h>
00031 #include <string.h>
00032 
00033 /* VLC headers */
00034 #include <vlc/vlc.h>
00035 #include <vlc/intf.h>
00036 
00037 /* BeOS interface headers */
00038 #include "InterfaceWindow.h"
00039 #include "ListViews.h"
00040 #include "MsgVals.h"
00041 #include "PlayListWindow.h"
00042 
00043 enum
00044 {
00045     MSG_SELECT_ALL          = 'sall',
00046     MSG_SELECT_NONE         = 'none',
00047     MSG_RANDOMIZE           = 'rndm',
00048     MSG_SORT_REVERSE        = 'srtr',
00049     MSG_SORT_NAME           = 'srtn',
00050     MSG_SORT_PATH           = 'srtp',
00051     MSG_REMOVE              = 'rmov',
00052     MSG_REMOVE_ALL          = 'rmal',
00053 
00054     MSG_SELECTION_CHANGED   = 'slch',
00055     MSG_SET_DISPLAY         = 'stds',
00056 };
00057 
00058 
00059 /*****************************************************************************
00060  * PlayListWindow::PlayListWindow
00061  *****************************************************************************/
00062 PlayListWindow::PlayListWindow( BRect frame, const char* name,
00063                                 InterfaceWindow* mainWindow,
00064                                 intf_thread_t *p_interface )
00065     :   BWindow( frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
00066                  B_WILL_ACCEPT_FIRST_CLICK | B_ASYNCHRONOUS_CONTROLS ),
00067         fMainWindow( mainWindow )
00068 {
00069     char psz_tmp[1024];
00070 #define ADD_ELLIPSIS( a ) \
00071     memset( psz_tmp, 0, 1024 ); \
00072     snprintf( psz_tmp, 1024, "%s%s", a, B_UTF8_ELLIPSIS );
00073 
00074     p_intf = p_interface;
00075     
00076     SetName( _("playlist") );
00077 
00078     // set up the main menu bar
00079     fMenuBar = new BMenuBar( BRect(0.0, 0.0, frame.Width(), 15.0), "main menu",
00080                              B_FOLLOW_NONE, B_ITEMS_IN_ROW, false );
00081 
00082     AddChild( fMenuBar );
00083 
00084     // Add the File menu
00085     BMenu *fileMenu = new BMenu( _("File") );
00086     fMenuBar->AddItem( fileMenu );
00087     ADD_ELLIPSIS( _("Open File") );
00088     BMenuItem* item = new BMenuItem( psz_tmp, new BMessage( OPEN_FILE ), 'O' );
00089     item->SetTarget( fMainWindow );
00090     fileMenu->AddItem( item );
00091 
00092     CDMenu* cd_menu = new CDMenu( _("Open Disc") );
00093     fileMenu->AddItem( cd_menu );
00094 
00095     fileMenu->AddSeparatorItem();
00096     item = new BMenuItem( _("Close"),
00097                           new BMessage( B_QUIT_REQUESTED ), 'W' );
00098     fileMenu->AddItem( item );
00099 
00100     // Add the Edit menu
00101     BMenu *editMenu = new BMenu( _("Edit") );
00102     fMenuBar->AddItem( editMenu );
00103     fSelectAllMI = new BMenuItem( _("Select All"),
00104                                   new BMessage( MSG_SELECT_ALL ), 'A' );
00105     editMenu->AddItem( fSelectAllMI );
00106     fSelectNoneMI = new BMenuItem( _("Select None"),
00107                                    new BMessage( MSG_SELECT_NONE ), 'A', B_SHIFT_KEY );
00108     editMenu->AddItem( fSelectNoneMI );
00109 
00110     editMenu->AddSeparatorItem();
00111     fSortReverseMI = new BMenuItem( _("Sort Reverse"),
00112                                  new BMessage( MSG_SORT_REVERSE ), 'F' );
00113     editMenu->AddItem( fSortReverseMI );
00114     fSortNameMI = new BMenuItem( _("Sort by Name"),
00115                                  new BMessage( MSG_SORT_NAME ), 'N' );
00116 fSortNameMI->SetEnabled( false );
00117     editMenu->AddItem( fSortNameMI );
00118     fSortPathMI = new BMenuItem( _("Sort by Path"),
00119                                  new BMessage( MSG_SORT_PATH ), 'P' );
00120 fSortPathMI->SetEnabled( false );
00121     editMenu->AddItem( fSortPathMI );
00122     fRandomizeMI = new BMenuItem( _("Randomize"),
00123                                   new BMessage( MSG_RANDOMIZE ), 'R' );
00124 fRandomizeMI->SetEnabled( false );
00125     editMenu->AddItem( fRandomizeMI );
00126     editMenu->AddSeparatorItem();
00127     fRemoveMI = new BMenuItem( _("Remove"),
00128                           new BMessage( MSG_REMOVE ) );
00129     editMenu->AddItem( fRemoveMI );
00130     fRemoveAllMI = new BMenuItem( _("Remove All"),
00131                                   new BMessage( MSG_REMOVE_ALL ) );
00132     editMenu->AddItem( fRemoveAllMI );
00133 
00134     // Add View menu
00135     fViewMenu = new BMenu( _("View") );
00136     fMenuBar->AddItem( fViewMenu );
00137 
00138     fViewMenu->SetRadioMode( true );
00139     BMessage* message = new BMessage( MSG_SET_DISPLAY );
00140     message->AddInt32( "mode", DISPLAY_PATH );
00141     item = new BMenuItem( _("Path"), message );
00142     item->SetMarked( true );
00143     fViewMenu->AddItem( item );
00144 
00145     message = new BMessage( MSG_SET_DISPLAY );
00146     message->AddInt32( "mode", DISPLAY_NAME );
00147     item = new BMenuItem( _("Name"), message );
00148     fViewMenu->AddItem( item );
00149 
00150     // make menu bar resize to correct height
00151     float menuWidth, menuHeight;
00152     fMenuBar->GetPreferredSize( &menuWidth, &menuHeight );
00153     // don't change next line! it's a workarround!
00154     fMenuBar->ResizeTo( frame.Width(), menuHeight );
00155 
00156     frame = Bounds();
00157     frame.top += fMenuBar->Bounds().IntegerHeight() + 1;
00158     frame.right -= B_V_SCROLL_BAR_WIDTH;
00159 
00160     fListView = new PlaylistView( p_intf, frame, fMainWindow,
00161                                   new BMessage( MSG_SELECTION_CHANGED ) );
00162     fBackgroundView = new BScrollView( "playlist scrollview",
00163                                        fListView, B_FOLLOW_ALL_SIDES,
00164                                        0, false, true,
00165                                        B_NO_BORDER );
00166 
00167     AddChild( fBackgroundView );
00168 
00169     // be up to date
00170     UpdatePlaylist();
00171     FrameResized( Bounds().Width(), Bounds().Height() );
00172     SetSizeLimits( menuWidth * 1.5, menuWidth * 8.0,
00173                    menuHeight * 5.0, menuHeight * 50.0 );
00174 
00175     UpdatePlaylist( true );
00176     // start window thread in hidden state
00177     Hide();
00178     Show();
00179 }
00180 
00181 /*****************************************************************************
00182  * PlayListWindow::~PlayListWindow
00183  *****************************************************************************/
00184 PlayListWindow::~PlayListWindow()
00185 {
00186 }
00187 
00188 /*****************************************************************************
00189  * PlayListWindow::QuitRequested
00190  *****************************************************************************/
00191 bool
00192 PlayListWindow::QuitRequested()
00193 {
00194     Hide(); 
00195     return false;
00196 }
00197 
00198 /*****************************************************************************
00199  * PlayListWindow::MessageReceived
00200  *****************************************************************************/
00201 void
00202 PlayListWindow::MessageReceived( BMessage * p_message )
00203 {
00204     switch ( p_message->what )
00205     {
00206         case OPEN_DVD:
00207         case B_REFS_RECEIVED:
00208         case B_SIMPLE_DATA:
00209             // forward to interface window
00210             fMainWindow->PostMessage( p_message );
00211             break;
00212         case MSG_SELECT_ALL:
00213             fListView->Select( 0, fListView->CountItems() - 1 );
00214             break;
00215         case MSG_SELECT_NONE:
00216             fListView->DeselectAll();
00217             break;
00218         case MSG_RANDOMIZE:
00219             break;
00220         case MSG_SORT_REVERSE:
00221             fListView->SortReverse();
00222             break;
00223         case MSG_SORT_NAME:
00224             break;
00225         case MSG_SORT_PATH:
00226             break;
00227         case MSG_REMOVE:
00228             fListView->RemoveSelected();
00229             break;
00230         case MSG_REMOVE_ALL:
00231             fListView->Select( 0, fListView->CountItems() - 1 );
00232             fListView->RemoveSelected();
00233             break;
00234         case MSG_SELECTION_CHANGED:
00235             _CheckItemsEnableState();
00236             break;
00237         case MSG_SET_DISPLAY:
00238         {
00239             uint32 mode;
00240             if ( p_message->FindInt32( "mode", (int32*)&mode ) == B_OK )
00241                 SetDisplayMode( mode );
00242             break;
00243         }
00244         case B_MODIFIERS_CHANGED:
00245             fListView->ModifiersChanged();
00246             break;
00247         default:
00248             BWindow::MessageReceived( p_message );
00249             break;
00250     }
00251 }
00252 
00253 /*****************************************************************************
00254  * PlayListWindow::FrameResized
00255  *****************************************************************************/
00256 void
00257 PlayListWindow::FrameResized(float width, float height)
00258 {
00259     BRect r(Bounds());
00260     fMenuBar->MoveTo(r.LeftTop());
00261     fMenuBar->ResizeTo(r.Width(), fMenuBar->Bounds().Height());
00262     r.top += fMenuBar->Bounds().Height() + 1.0;
00263     fBackgroundView->MoveTo(r.LeftTop());
00264     // the "+ 1.0" is to make the scrollbar
00265     // be partly covered by the window border
00266     fBackgroundView->ResizeTo(r.Width() + 1.0, r.Height() + 1.0);
00267 }
00268 
00269 /*****************************************************************************
00270  * PlayListWindow::ReallyQuit
00271  *****************************************************************************/
00272 void
00273 PlayListWindow::ReallyQuit()
00274 {
00275     Lock();
00276     Hide();
00277     Quit();
00278 }
00279 
00280 /*****************************************************************************
00281  * PlayListWindow::UpdatePlaylist
00282  *****************************************************************************/
00283 void
00284 PlayListWindow::UpdatePlaylist( bool rebuild )
00285 {
00286     playlist_t * p_playlist;
00287 
00288     if( rebuild )
00289         fListView->RebuildList();
00290 
00291     p_playlist = (playlist_t *)
00292         vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
00293     fListView->SetCurrent( p_playlist->i_index );
00294     fListView->SetPlaying( p_playlist->status.i_status == PLAYLIST_RUNNING );
00295     vlc_object_release( p_playlist );
00296 
00297     _CheckItemsEnableState();
00298 }
00299 
00300 /*****************************************************************************
00301  * PlayListWindow::SetDisplayMode
00302  *****************************************************************************/
00303 void
00304 PlayListWindow::SetDisplayMode( uint32 mode )
00305 {
00306     if ( Lock() )
00307     {
00308         // propagate to list view
00309         fListView->SetDisplayMode( mode );
00310         // mark correct menu item
00311         for ( int32 i = 0; BMenuItem* item = fViewMenu->ItemAt( i ); i++ )
00312         {
00313             BMessage* message = item->Message();
00314             uint32 itemMode;
00315             if ( message
00316                  && message->FindInt32( "mode", (int32*)&itemMode ) == B_OK
00317                  && itemMode == mode )
00318             {
00319                 item->SetMarked( true );
00320                 break;
00321             }
00322         }
00323         Unlock();
00324     }
00325 }
00326 
00327 /*****************************************************************************
00328  * PlayListWindow::DisplayMode
00329  *****************************************************************************/
00330 uint32
00331 PlayListWindow::DisplayMode() const
00332 {
00333     return fListView->DisplayMode();
00334 }
00335 
00336 /*****************************************************************************
00337  * PlayListWindow::_CheckItemsEnableState
00338  *****************************************************************************/
00339 void
00340 PlayListWindow::_CheckItemsEnableState() const
00341 {
00342     // check if one item selected
00343     int32 test = fListView->CurrentSelection( 0 );
00344     bool enable1 = test >= 0;
00345     // check if at least two items selected
00346     test = fListView->CurrentSelection( 1 );
00347     bool enable2 = test >= 0;
00348     bool notEmpty = fListView->CountItems() > 0;
00349     _SetMenuItemEnabled( fSelectAllMI, notEmpty );
00350     _SetMenuItemEnabled( fSelectNoneMI, enable1 );
00351     _SetMenuItemEnabled( fSortReverseMI, enable2 );
00352 //  _SetMenuItemEnabled( fSortNameMI, enable2 );
00353 //  _SetMenuItemEnabled( fSortPathMI, enable2 );
00354 //  _SetMenuItemEnabled( fRandomizeMI, enable2 );
00355     _SetMenuItemEnabled( fRemoveMI, enable1 );
00356     _SetMenuItemEnabled( fRemoveAllMI, notEmpty );
00357 }
00358 
00359 /*****************************************************************************
00360  * PlayListWindow::_SetMenuItemEnabled
00361  *****************************************************************************/
00362 void
00363 PlayListWindow::_SetMenuItemEnabled( BMenuItem* item, bool enabled ) const
00364 {
00365     // this check should actally be done in BMenuItem::SetEnabled(), but it is not...
00366     if ( item->IsEnabled() != enabled )
00367         item->SetEnabled( enabled );
00368 }

Generated on Tue Dec 20 10:14:37 2005 for vlc-0.8.4a by  doxygen 1.4.2