1 /* 2 * Controller.cpp - Media Player for the Haiku Operating System 3 * 4 * Copyright (C) 2006 Marcus Overhagen <marcus@overhagen.de> 5 * Copyright (C) 2007 Stephan Aßmus <superstippi@gmx.de> 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * version 2 as published by the Free Software Foundation. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 * 20 */ 21 #include "ControllerView.h" 22 23 #include <Autolock.h> 24 #include <Message.h> 25 #include <stdio.h> 26 #include <string.h> 27 28 #include "Controller.h" 29 #include "Playlist.h" 30 #include "PlaylistObserver.h" 31 32 33 ControllerView::ControllerView(BRect frame, Controller* controller, 34 Playlist* playlist) 35 : TransportControlGroup(frame) 36 , fController(controller) 37 , fPlaylist(playlist) 38 , fPlaylistObserver(new PlaylistObserver(this)) 39 { 40 fPlaylist->AddListener(fPlaylistObserver); 41 } 42 43 44 ControllerView::~ControllerView() 45 { 46 fPlaylist->RemoveListener(fPlaylistObserver); 47 delete fPlaylistObserver; 48 } 49 50 51 void 52 ControllerView::AttachedToWindow() 53 { 54 TransportControlGroup::AttachedToWindow(); 55 } 56 57 58 void 59 ControllerView::Draw(BRect updateRect) 60 { 61 TransportControlGroup::Draw(updateRect); 62 } 63 64 65 void 66 ControllerView::MessageReceived(BMessage *msg) 67 { 68 switch (msg->what) { 69 case MSG_PLAYLIST_REF_ADDED: 70 case MSG_PLAYLIST_REF_REMOVED: 71 case MSG_PLAYLIST_REFS_SORTED: 72 case MSG_PLAYLIST_CURRENT_REF_CHANGED: 73 CheckSkippable(); 74 break; 75 76 default: 77 TransportControlGroup::MessageReceived(msg); 78 } 79 } 80 81 // #pragma mark - 82 83 84 uint32 85 ControllerView::EnabledButtons() 86 { 87 // TODO: superflous 88 return 0xffffffff; 89 } 90 91 92 void 93 ControllerView::TogglePlaying() 94 { 95 fController->TogglePlaying(); 96 } 97 98 99 void 100 ControllerView::Stop() 101 { 102 fController->Stop(); 103 } 104 105 106 void 107 ControllerView::Rewind() 108 { 109 // TODO: make it so this function is called repeatedly 110 printf("ControllerView::Rewind()\n"); 111 } 112 113 114 void 115 ControllerView::Forward() 116 { 117 // TODO: make it so this function is called repeatedly 118 printf("ControllerView::Forward()\n"); 119 } 120 121 122 void 123 ControllerView::SkipBackward() 124 { 125 BAutolock _(fPlaylist); 126 fPlaylist->SetCurrentRefIndex(fPlaylist->CurrentRefIndex() - 1); 127 } 128 129 130 void 131 ControllerView::SkipForward() 132 { 133 BAutolock _(fPlaylist); 134 fPlaylist->SetCurrentRefIndex(fPlaylist->CurrentRefIndex() + 1); 135 } 136 137 138 void 139 ControllerView::VolumeChanged(float value) 140 { 141 fController->SetVolume(value); 142 } 143 144 145 void 146 ControllerView::ToggleMute() 147 { 148 fController->ToggleMute(); 149 } 150 151 152 void 153 ControllerView::PositionChanged(float value) 154 { 155 // 0.0 ... 1.0 156 fController->SetPosition(value); 157 } 158 159 160 // #pragma mark - 161 162 163 void 164 ControllerView::CheckSkippable() 165 { 166 BAutolock _(fPlaylist); 167 168 bool canSkipNext, canSkipPrevious; 169 fPlaylist->GetSkipInfo(&canSkipPrevious, &canSkipNext); 170 SetSkippable(canSkipPrevious, canSkipNext); 171 } 172 173 174