Changeset 26264

Show
Ignore:
Timestamp:
07/05/08 15:21:38 (5 months ago)
Author:
stippi
Message:

* Added "Randomize" feature to Playlist window (Edit menu). It randomizes

either the selected items, or the entire list if nothing is selected.

* Small cleanups here and there.

Location:
haiku/trunk/src/apps/mediaplayer
Files:
2 added
7 modified

Legend:

Unmodified
Added
Removed
  • haiku/trunk/src/apps/mediaplayer/Jamfile

    r26066 r26264  
    6262        PlaylistObserver.cpp 
    6363        PlaylistWindow.cpp 
     64        RandomizePLItemsCommand.cpp 
    6465        RemovePLItemsCommand.cpp 
    6566 
  • haiku/trunk/src/apps/mediaplayer/MainApp.cpp

    r25725 r26264  
    2929 
    3030#include <stdio.h> 
     31#include <stdlib.h> 
    3132#include <unistd.h> 
    3233 
     
    226227        EventQueue::CreateDefault(); 
    227228 
     229        srand(system_time()); 
     230 
    228231        gMainApp = new MainApp; 
    229232        gMainApp->Run(); 
  • haiku/trunk/src/apps/mediaplayer/playlist/MovePLItemsCommand.cpp

    r21317 r26264  
    4444        for (int32 i = 0; i < fCount; i++) { 
    4545                if (fPlaylist->GetRefAt(fIndices[i], &fRefs[i]) < B_OK) { 
     46                        // indicate a bad object state 
    4647                        delete[] fRefs; 
    4748                        fRefs = NULL; 
     
    6566MovePLItemsCommand::InitCheck() 
    6667{ 
    67         if (!fPlaylist || !fRefs || !fIndices) 
     68        if (!fRefs) 
    6869                return B_NO_INIT; 
    6970 
  • haiku/trunk/src/apps/mediaplayer/playlist/Playlist.h

    r24715 r26264  
    5353                        void                            MakeEmpty(); 
    5454                        int32                           CountItems() const; 
    55                          
     55 
    5656                        void                            Sort(); 
    5757                 
  • haiku/trunk/src/apps/mediaplayer/playlist/PlaylistListView.cpp

    r26142 r26264  
    2727#include "Playlist.h" 
    2828#include "PlaylistObserver.h" 
     29#include "RandomizePLItemsCommand.h" 
    2930#include "RemovePLItemsCommand.h" 
    3031 
     
    376377 
    377378 
     379void 
     380PlaylistListView::Randomize() 
     381{ 
     382        int32 count = CountItems(); 
     383        if (count == 0) 
     384                return; 
     385 
     386        BList indices; 
     387 
     388        // add current selection 
     389        count = 0; 
     390        while (true) { 
     391                int32 index = CurrentSelection(count); 
     392                if (index < 0) 
     393                        break; 
     394                if (!indices.AddItem((void*)index)) 
     395                        return; 
     396                count++; 
     397        } 
     398 
     399        // was anything selected? 
     400        if (count == 0) { 
     401                // no selection, simply add all items 
     402                count = CountItems(); 
     403                for (int32 i = 0; i < count; i++) { 
     404                        if (!indices.AddItem((void*)i)) 
     405                                return; 
     406                } 
     407        } 
     408 
     409        fCommandStack->Perform(new (nothrow) RandomizePLItemsCommand(fPlaylist, 
     410                (int32*)indices.Items(), indices.CountItems())); 
     411} 
     412 
     413 
    378414// #pragma mark - 
    379415 
  • haiku/trunk/src/apps/mediaplayer/playlist/PlaylistListView.h

    r21317 r26264  
    4545                                                                        int32 appendIndex); 
    4646 
     47                        void                            Randomize(); 
     48 
    4749 private: 
    4850                        void                            _FullSync(); 
  • haiku/trunk/src/apps/mediaplayer/playlist/PlaylistWindow.cpp

    r26144 r26264  
    3232 
    3333enum { 
    34         M_PLAYLIST_OPEN         = 'open', 
    35         M_PLAYLIST_SAVE         = 'save', 
    36         M_PLAYLIST_EMPTY        = 'emty' 
     34        // file 
     35        M_PLAYLIST_OPEN                 = 'open', 
     36        M_PLAYLIST_SAVE                 = 'save', 
     37 
     38        // edit 
     39        M_PLAYLIST_EMPTY                = 'emty', 
     40        M_PLAYLIST_RANDOMIZE    = 'rand' 
    3741}; 
    3842 
     
    145149                        fOpenPanel->Show(); 
    146150                        break;                                           
     151 
    147152                case M_PLAYLIST_EMPTY: 
    148153                        fListView->RemoveAll(); 
    149                         break;                                           
     154                        break; 
     155                case M_PLAYLIST_RANDOMIZE: 
     156                        fListView->Randomize(); 
     157                        break; 
     158 
    150159                default: 
    151160                        BWindow::MessageReceived(message); 
     
    181190        editMenu->AddItem(new BMenuItem("Make Empty", 
    182191                new BMessage(M_PLAYLIST_EMPTY), 'N')); 
     192        editMenu->AddItem(new BMenuItem("Randomize", 
     193                new BMessage(M_PLAYLIST_RANDOMIZE), 'R')); 
    183194        menuBar->AddItem(editMenu); 
    184195