BTRFS: Implement BTree::Path and change _Find.
[haiku.git] / src / apps / mediaplayer / ControllerView.cpp
blob9611df3b6e57d1e3e1c3287db33c3792a95350a8
1 /*
2 * Controller.cpp - Media Player for the Haiku Operating System
4 * Copyright (C) 2006 Marcus Overhagen <marcus@overhagen.de>
5 * Copyright (C) 2007 Stephan Aßmus <superstippi@gmx.de>
6 * Copyright (C) 2008-2009 Fredrik Modéen <[FirstName]@[LastName].se> (MIT ok)
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #include "ControllerView.h"
26 #include <Autolock.h>
27 #include <Message.h>
28 #include <stdio.h>
29 #include <string.h>
31 #include "Controller.h"
32 #include "Playlist.h"
33 #include "PlaylistObserver.h"
36 ControllerView::ControllerView(BRect frame, Controller* controller,
37 Playlist* playlist)
39 TransportControlGroup(frame, true, true, false),
40 fController(controller),
41 fPlaylist(playlist),
42 fPlaylistObserver(new PlaylistObserver(this))
44 fPlaylist->AddListener(fPlaylistObserver);
48 ControllerView::~ControllerView()
50 fPlaylist->RemoveListener(fPlaylistObserver);
51 delete fPlaylistObserver;
55 void
56 ControllerView::AttachedToWindow()
58 TransportControlGroup::AttachedToWindow();
62 void
63 ControllerView::Draw(BRect updateRect)
65 TransportControlGroup::Draw(updateRect);
69 void
70 ControllerView::MessageReceived(BMessage* message)
72 switch (message->what) {
73 case MSG_PLAYLIST_ITEM_ADDED:
74 case MSG_PLAYLIST_ITEM_REMOVED:
75 case MSG_PLAYLIST_ITEMS_SORTED:
76 case MSG_PLAYLIST_CURRENT_ITEM_CHANGED:
77 _CheckSkippable();
78 break;
80 case MSG_PLAYLIST_IMPORT_FAILED:
81 break;
83 default:
84 TransportControlGroup::MessageReceived(message);
89 // #pragma mark -
92 void
93 ControllerView::TogglePlaying()
95 BAutolock _(fPlaylist);
96 if (fPlaylist->CurrentItemIndex() == fPlaylist->CountItems() - 1
97 && Position() == 1.0) {
98 // Reached end of playlist and end of last item
99 // -> start again from the first item.
100 fPlaylist->SetCurrentItemIndex(0, true);
101 } else
102 fController->TogglePlaying();
106 void
107 ControllerView::Stop()
109 fController->Stop();
113 void
114 ControllerView::Rewind()
116 // TODO: make it so this function is called repeatedly
117 //printf("ControllerView::Rewind()\n");
121 void
122 ControllerView::Forward()
124 // TODO: make it so this function is called repeatedly
125 //printf("ControllerView::Forward()\n");
129 void
130 ControllerView::SkipBackward()
132 BAutolock _(fPlaylist);
133 int32 index = fPlaylist->CurrentItemIndex() - 1;
134 if (index < 0)
135 index = 0;
136 fPlaylist->SetCurrentItemIndex(index, true);
140 void
141 ControllerView::SkipForward()
143 BAutolock _(fPlaylist);
144 int32 index = fPlaylist->CurrentItemIndex() + 1;
145 if (index >= fPlaylist->CountItems())
146 index = fPlaylist->CountItems() - 1;
147 fPlaylist->SetCurrentItemIndex(index, true);
151 void
152 ControllerView::VolumeChanged(float value)
154 fController->SetVolume(value);
158 void
159 ControllerView::ToggleMute()
161 fController->ToggleMute();
165 void
166 ControllerView::PositionChanged(float value)
168 // 0.0 ... 1.0
169 fController->SetPosition(value);
173 // #pragma mark -
176 void
177 ControllerView::_CheckSkippable()
179 BAutolock _(fPlaylist);
181 bool canSkipNext, canSkipPrevious;
182 fPlaylist->GetSkipInfo(&canSkipPrevious, &canSkipNext);
183 SetSkippable(canSkipPrevious, canSkipNext);