From 838a2e243d410b2e6c8dff3af6a4cf7cca0b8a4b Mon Sep 17 00:00:00 2001
From: Guillermo Bonvehi <gbonvehi@gmail.com>
Date: Mon, 6 Jan 2014 10:51:09 +0000
Subject: [PATCH] Added simple shortcuts to playlist
---
src/apps/mediaplayer/playlist/PlaylistListView.cpp | 91 +++++++++++++++++++++-
src/apps/mediaplayer/playlist/PlaylistListView.h | 3 +
2 files changed, 91 insertions(+), 3 deletions(-)
diff --git a/src/apps/mediaplayer/playlist/PlaylistListView.cpp b/src/apps/mediaplayer/playlist/PlaylistListView.cpp
index 940b5a2..c41fcbc 100644
a
|
b
|
PlaylistListView::KeyDown(const char* bytes, int32 numBytes)
|
359 | 359 | { |
360 | 360 | if (numBytes < 1) |
361 | 361 | return; |
| 362 | |
| 363 | BMessage* msg = Window()->CurrentMessage(); |
| 364 | uint32 modifier = msg->FindInt32("modifiers"); |
| 365 | |
| 366 | int32 count; |
| 367 | int32 index; |
| 368 | |
| 369 | switch(bytes[0]) { |
| 370 | case B_SPACE: |
| 371 | fController->TogglePlaying(); |
| 372 | break; |
| 373 | |
| 374 | case B_ENTER: |
| 375 | count = CountItems(); |
| 376 | if (count == 0) |
| 377 | break; |
| 378 | index = CurrentSelection(0); |
| 379 | if (index < 0) |
| 380 | break; |
| 381 | fPlaylist->SetCurrentItemIndex(index, true); |
| 382 | fController->Play(); |
| 383 | break; |
| 384 | |
| 385 | case B_ESCAPE: |
| 386 | fController->Stop(); |
| 387 | break; |
| 388 | |
| 389 | case B_RIGHT_ARROW: |
| 390 | if ((modifier & B_SHIFT_KEY) != 0) { |
| 391 | _Wind(30000000LL, 5); |
| 392 | } else { |
| 393 | _Wind(5000000LL, 1); |
| 394 | } |
| 395 | break; |
| 396 | |
| 397 | case B_LEFT_ARROW: |
| 398 | if ((modifier & B_SHIFT_KEY) != 0) { |
| 399 | _Wind(-30000000LL, -5); |
| 400 | } else { |
| 401 | _Wind(-5000000LL, -1); |
| 402 | } |
| 403 | break; |
| 404 | default: |
| 405 | DragSortableListView::KeyDown(bytes, numBytes); |
| 406 | } |
| 407 | } |
362 | 408 | |
363 | | if ((bytes[0] == B_BACKSPACE) || (bytes[0] == B_DELETE)) |
364 | | RemoveSelected(); |
365 | 409 | |
366 | | DragSortableListView::KeyDown(bytes, numBytes); |
| 410 | void |
| 411 | PlaylistListView::SkipBackward() |
| 412 | { |
| 413 | BAutolock _(fPlaylist); |
| 414 | int32 index = fPlaylist->CurrentItemIndex() - 1; |
| 415 | if (index < 0) |
| 416 | index = 0; |
| 417 | fPlaylist->SetCurrentItemIndex(index, true); |
| 418 | } |
| 419 | |
| 420 | |
| 421 | void |
| 422 | PlaylistListView::SkipForward() |
| 423 | { |
| 424 | BAutolock _(fPlaylist); |
| 425 | int32 index = fPlaylist->CurrentItemIndex() + 1; |
| 426 | if (index >= fPlaylist->CountItems()) |
| 427 | index = fPlaylist->CountItems() - 1; |
| 428 | fPlaylist->SetCurrentItemIndex(index, true); |
| 429 | } |
| 430 | |
| 431 | |
| 432 | void |
| 433 | PlaylistListView::_Wind(bigtime_t howMuch, int64 frames) |
| 434 | { |
| 435 | if (!fController->Lock()) |
| 436 | return; |
| 437 | |
| 438 | if (frames != 0 && !fController->IsPlaying()) { |
| 439 | int64 newFrame = fController->CurrentFrame() + frames; |
| 440 | fController->SetFramePosition(newFrame); |
| 441 | } else { |
| 442 | bigtime_t seekTime = fController->TimePosition() + howMuch; |
| 443 | if (seekTime < 0) { |
| 444 | SkipBackward(); |
| 445 | } else if (seekTime > fController->TimeDuration()) { |
| 446 | SkipForward(); |
| 447 | } else |
| 448 | fController->SetTimePosition(seekTime); |
| 449 | } |
| 450 | |
| 451 | fController->Unlock(); |
367 | 452 | } |
368 | 453 | |
369 | 454 | |
diff --git a/src/apps/mediaplayer/playlist/PlaylistListView.h b/src/apps/mediaplayer/playlist/PlaylistListView.h
index 7696a9b..dc2bf83 100644
a
|
b
|
public:
|
49 | 49 | void RemoveToTrash(int32 index); |
50 | 50 | void RemoveItemList(const BList& indices, |
51 | 51 | bool intoTrash); |
| 52 | virtual void SkipBackward(); |
| 53 | virtual void SkipForward(); |
52 | 54 | |
53 | 55 | private: |
54 | 56 | class Item; |
55 | 57 | |
| 58 | void _Wind(bigtime_t howMuch, int64 frames); |
56 | 59 | void _FullSync(); |
57 | 60 | void _AddItem(PlaylistItem* item, int32 index); |
58 | 61 | void _RemoveItem(int32 index); |