Adds the option to delete a file from Mediaplayer and move that file to Trash

Works both from main window and PlayList window.
Button that works are B_COMMAND + [delete | d | r] button.
It can be debated what shortcut to use but I needed this function :)
Same goes for the menu i Playlist window. Yell and Ill change :)

What not works are undo and  total undo in main window and total undo in Playlist
(total undo = undo files from trash as well as normal undo)

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30490 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Fredrik Modeen
2009-04-29 20:20:23 +00:00
parent d3b6c809b1
commit 9327db63a4
12 changed files with 167 additions and 62 deletions
+18 -18
View File
@@ -3,7 +3,7 @@
* *
* Copyright (C) 2006 Marcus Overhagen <[email protected]> * Copyright (C) 2006 Marcus Overhagen <[email protected]>
* Copyright (C) 2007-2008 Stephan Aßmus <[email protected]> (MIT Ok) * Copyright (C) 2007-2008 Stephan Aßmus <[email protected]> (MIT Ok)
* Copyright (C) 2007 Fredrik Modéen <[email protected]> * Copyright (C) 2007-2009 Fredrik Modéen <[FirstName]@[LastName].se> (MIT ok)
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@@ -231,14 +231,14 @@ Controller::SetTo(const entry_ref &ref)
err = mf->InitCheck(); err = mf->InitCheck();
if (err != B_OK) { if (err != B_OK) {
printf("Controller::SetTo: initcheck failed\n"); //printf("Controller::SetTo: initcheck failed\n");
_NotifyFileChanged(); _NotifyFileChanged();
return err; return err;
} }
int trackcount = mf->CountTracks(); int trackcount = mf->CountTracks();
if (trackcount <= 0) { if (trackcount <= 0) {
printf("Controller::SetTo: trackcount %d\n", trackcount); //printf("Controller::SetTo: trackcount %d\n", trackcount);
_NotifyFileChanged(); _NotifyFileChanged();
return B_MEDIA_NO_HANDLER; return B_MEDIA_NO_HANDLER;
} }
@@ -248,15 +248,15 @@ Controller::SetTo(const entry_ref &ref)
media_format f; media_format f;
err = t->EncodedFormat(&f); err = t->EncodedFormat(&f);
if (err != B_OK) { if (err != B_OK) {
printf("Controller::SetTo: EncodedFormat failed for track index %d, error 0x%08lx (%s)\n", //printf("Controller::SetTo: EncodedFormat failed for track index %d, error 0x%08lx (%s)\n",
i, err, strerror(err)); // i, err, strerror(err));
mf->ReleaseTrack(t); mf->ReleaseTrack(t);
continue; continue;
} }
if (t->Duration() <= 0) { if (t->Duration() <= 0) {
printf("Controller::SetTo: track index %d has no duration\n",i); //printf("Controller::SetTo: track index %d has no duration\n",i);
mf->ReleaseTrack(t); //mf->ReleaseTrack(t);
continue; continue;
} }
@@ -272,8 +272,8 @@ Controller::SetTo(const entry_ref &ref)
} }
} }
printf("Controller::SetTo: %d audio track, %d video track\n", //printf("Controller::SetTo: %d audio track, %d video track\n",
AudioTrackCount(), VideoTrackCount()); // AudioTrackCount(), VideoTrackCount());
fMediaFile = mf; fMediaFile = mf;
mediaFileDeleter.Detach(); mediaFileDeleter.Detach();
@@ -282,8 +282,8 @@ Controller::SetTo(const entry_ref &ref)
SelectVideoTrack(0); SelectVideoTrack(0);
if (fAudioTrackSupplier == NULL && fVideoTrackSupplier == NULL) { if (fAudioTrackSupplier == NULL && fVideoTrackSupplier == NULL) {
printf("Controller::SetTo: no audio or video tracks found or " //printf("Controller::SetTo: no audio or video tracks found or "
"no decoders\n"); // "no decoders\n");
_NotifyFileChanged(); _NotifyFileChanged();
delete fMediaFile; delete fMediaFile;
fMediaFile = NULL; fMediaFile = NULL;
@@ -453,8 +453,8 @@ Controller::SelectVideoTrack(int n)
fDuration = max_c(a, v); fDuration = max_c(a, v);
fVideoFrameRate = fVideoTrackSupplier->Format().u.raw_video.field_rate; fVideoFrameRate = fVideoTrackSupplier->Format().u.raw_video.field_rate;
if (fVideoFrameRate <= 0.0) { if (fVideoFrameRate <= 0.0) {
printf("Controller::SelectVideoTrack(%d) - invalid video frame rate: %.1f\n", n, //printf("Controller::SelectVideoTrack(%d) - invalid video frame rate: %.1f\n", n,
fVideoFrameRate); // fVideoFrameRate);
fVideoFrameRate = 25.0; fVideoFrameRate = 25.0;
} }
@@ -486,7 +486,7 @@ Controller::CurrentVideoTrack()
void void
Controller::Stop() Controller::Stop()
{ {
printf("Controller::Stop\n"); //printf("Controller::Stop\n");
BAutolock _(this); BAutolock _(this);
@@ -500,7 +500,7 @@ Controller::Stop()
void void
Controller::Play() Controller::Play()
{ {
printf("Controller::Play\n"); //printf("Controller::Play\n");
BAutolock _(this); BAutolock _(this);
@@ -512,7 +512,7 @@ Controller::Play()
void void
Controller::Pause() Controller::Pause()
{ {
printf("Controller::Pause\n"); // printf("Controller::Pause\n");
BAutolock _(this); BAutolock _(this);
@@ -525,7 +525,7 @@ Controller::Pause()
void void
Controller::TogglePlaying() Controller::TogglePlaying()
{ {
printf("Controller::TogglePlaying\n"); // printf("Controller::TogglePlaying\n");
BAutolock _(this); BAutolock _(this);
@@ -567,7 +567,7 @@ Controller::TimePosition()
void void
Controller::SetVolume(float value) Controller::SetVolume(float value)
{ {
printf("Controller::SetVolume %.4f\n", value); // printf("Controller::SetVolume %.4f\n", value);
if (!Lock()) if (!Lock())
return; return;
+15 -7
View File
@@ -3,6 +3,7 @@
* *
* Copyright (C) 2006 Marcus Overhagen <[email protected]> * Copyright (C) 2006 Marcus Overhagen <[email protected]>
* Copyright (C) 2007 Stephan Aßmus <[email protected]> * Copyright (C) 2007 Stephan Aßmus <[email protected]>
* Copyright (C) 2008-2009 Fredrik Modéen <[FirstName]@[LastName].se> (MIT ok)
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@@ -29,7 +30,6 @@
#include "Playlist.h" #include "Playlist.h"
#include "PlaylistObserver.h" #include "PlaylistObserver.h"
ControllerView::ControllerView(BRect frame, Controller* controller, ControllerView::ControllerView(BRect frame, Controller* controller,
Playlist* playlist) Playlist* playlist)
: TransportControlGroup(frame, true, true, false) : TransportControlGroup(frame, true, true, false)
@@ -70,7 +70,7 @@ ControllerView::MessageReceived(BMessage *msg)
case MSG_PLAYLIST_REF_REMOVED: case MSG_PLAYLIST_REF_REMOVED:
case MSG_PLAYLIST_REFS_SORTED: case MSG_PLAYLIST_REFS_SORTED:
case MSG_PLAYLIST_CURRENT_REF_CHANGED: case MSG_PLAYLIST_CURRENT_REF_CHANGED:
CheckSkippable(); _CheckSkippable();
break; break;
default: default:
@@ -107,7 +107,7 @@ void
ControllerView::Rewind() ControllerView::Rewind()
{ {
// TODO: make it so this function is called repeatedly // TODO: make it so this function is called repeatedly
printf("ControllerView::Rewind()\n"); //printf("ControllerView::Rewind()\n");
} }
@@ -115,7 +115,7 @@ void
ControllerView::Forward() ControllerView::Forward()
{ {
// TODO: make it so this function is called repeatedly // TODO: make it so this function is called repeatedly
printf("ControllerView::Forward()\n"); //printf("ControllerView::Forward()\n");
} }
@@ -135,6 +135,16 @@ ControllerView::SkipForward()
} }
void
ControllerView::SkipForwardAndDelete()
{
BAutolock _(fPlaylist);
int32 index = fPlaylist->CurrentRefIndex();
fPlaylist->SetCurrentRefIndex(index + 1);
fPlaylist->RemoveRefPermanent(index, true);
}
void void
ControllerView::VolumeChanged(float value) ControllerView::VolumeChanged(float value)
{ {
@@ -161,7 +171,7 @@ ControllerView::PositionChanged(float value)
void void
ControllerView::CheckSkippable() ControllerView::_CheckSkippable()
{ {
BAutolock _(fPlaylist); BAutolock _(fPlaylist);
@@ -169,5 +179,3 @@ ControllerView::CheckSkippable()
fPlaylist->GetSkipInfo(&canSkipPrevious, &canSkipNext); fPlaylist->GetSkipInfo(&canSkipPrevious, &canSkipNext);
SetSkippable(canSkipPrevious, canSkipNext); SetSkippable(canSkipPrevious, canSkipNext);
} }
+3 -1
View File
@@ -3,6 +3,7 @@
* *
* Copyright (C) 2006 Marcus Overhagen <[email protected]> * Copyright (C) 2006 Marcus Overhagen <[email protected]>
* Copyright (C) 2007 Stephan Aßmus <[email protected]> * Copyright (C) 2007 Stephan Aßmus <[email protected]>
* Copyright (C) 2008-2009 Fredrik Modéen <[FirstName]@[LastName].se> (MIT ok)
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@@ -44,6 +45,7 @@ public:
virtual void Forward(); virtual void Forward();
virtual void SkipBackward(); virtual void SkipBackward();
virtual void SkipForward(); virtual void SkipForward();
virtual void SkipForwardAndDelete();
virtual void VolumeChanged(float value); virtual void VolumeChanged(float value);
virtual void ToggleMute(); virtual void ToggleMute();
virtual void PositionChanged(float value); virtual void PositionChanged(float value);
@@ -54,7 +56,7 @@ private:
void Draw(BRect updateRect); void Draw(BRect updateRect);
// ControllerView // ControllerView
void CheckSkippable(); void _CheckSkippable();
private: private:
Controller* fController; Controller* fController;
+33 -26
View File
@@ -3,7 +3,7 @@
* *
* Copyright (C) 2006 Marcus Overhagen <[email protected]> * Copyright (C) 2006 Marcus Overhagen <[email protected]>
* Copyright (C) 2007-2008 Stephan Aßmus <[email protected]> (GPL->MIT ok) * Copyright (C) 2007-2008 Stephan Aßmus <[email protected]> (GPL->MIT ok)
* Copyright (C) 2007-2008 Fredrik Modéen <[email protected]> * Copyright (C) 2007-2009 Fredrik Modéen <[FirstName]@[LastName].se> (MIT ok)
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@@ -92,7 +92,9 @@ enum {
M_SELECT_VIDEO_TRACK = 0x00010000, M_SELECT_VIDEO_TRACK = 0x00010000,
M_SELECT_VIDEO_TRACK_END = 0x000fffff, M_SELECT_VIDEO_TRACK_END = 0x000fffff,
M_SET_PLAYLIST_POSITION M_SET_PLAYLIST_POSITION,
M_FILE_DELETE
}; };
//#define printf(a...) //#define printf(a...)
@@ -198,7 +200,7 @@ MainWin::MainWin()
MainWin::~MainWin() MainWin::~MainWin()
{ {
printf("MainWin::~MainWin\n"); // printf("MainWin::~MainWin\n");
Settings::Default()->RemoveListener(&fGlobalSettingsListener); Settings::Default()->RemoveListener(&fGlobalSettingsListener);
fPlaylist->RemoveListener(fPlaylistObserver); fPlaylist->RemoveListener(fPlaylistObserver);
@@ -239,8 +241,8 @@ MainWin::FrameResized(float newWidth, float newHeight)
bool noMenu = fNoMenu || fIsFullscreen; bool noMenu = fNoMenu || fIsFullscreen;
bool noControls = fNoControls || fIsFullscreen; bool noControls = fNoControls || fIsFullscreen;
printf("FrameResized enter: newWidth %.0f, newHeight %.0f\n", // printf("FrameResized enter: newWidth %.0f, newHeight %.0f\n",
newWidth, newHeight); // newWidth, newHeight);
int maxVideoWidth = int(newWidth) + 1; int maxVideoWidth = int(newWidth) + 1;
int maxVideoHeight = int(newHeight) + 1 int maxVideoHeight = int(newHeight) + 1
@@ -264,7 +266,7 @@ MainWin::FrameResized(float newWidth, float newHeight)
if (maxVideoHeight == 0) { if (maxVideoHeight == 0) {
bool hidden = fVideoView->IsHidden(); bool hidden = fVideoView->IsHidden();
printf(" video view hidden: %d\n", hidden); // printf(" video view hidden: %d\n", hidden);
if (!hidden) if (!hidden)
fVideoView->Hide(); fVideoView->Hide();
} else { } else {
@@ -285,7 +287,7 @@ printf(" video view hidden: %d\n", hidden);
// y += fControlsHeight; // y += fControlsHeight;
} }
printf("FrameResized leave\n"); // printf("FrameResized leave\n");
} }
@@ -570,9 +572,7 @@ MainWin::MessageReceived(BMessage *msg)
_ToggleFullscreen(); _ToggleFullscreen();
_ResizeWindow(400); _ResizeWindow(400);
break; break;
/* /*
case B_ACQUIRE_OVERLAY_LOCK: case B_ACQUIRE_OVERLAY_LOCK:
printf("B_ACQUIRE_OVERLAY_LOCK\n"); printf("B_ACQUIRE_OVERLAY_LOCK\n");
fVideoView->OverlayLockAcquire(); fVideoView->OverlayLockAcquire();
@@ -582,10 +582,9 @@ MainWin::MessageReceived(BMessage *msg)
printf("B_RELEASE_OVERLAY_LOCK\n"); printf("B_RELEASE_OVERLAY_LOCK\n");
fVideoView->OverlayLockRelease(); fVideoView->OverlayLockRelease();
break; break;
*/
case B_MOUSE_WHEEL_CHANGED: case B_MOUSE_WHEEL_CHANGED:
{ {
printf("B_MOUSE_WHEEL_CHANGED\n");
float dx = msg->FindFloat("be:wheel_delta_x"); float dx = msg->FindFloat("be:wheel_delta_x");
float dy = msg->FindFloat("be:wheel_delta_y"); float dy = msg->FindFloat("be:wheel_delta_y");
bool inv = modifiers() & B_COMMAND_KEY; bool inv = modifiers() & B_COMMAND_KEY;
@@ -595,7 +594,7 @@ MainWin::MessageReceived(BMessage *msg)
if (dy < -0.1) PostMessage(inv ? M_SKIP_NEXT : M_VOLUME_UP); if (dy < -0.1) PostMessage(inv ? M_SKIP_NEXT : M_VOLUME_UP);
break; break;
} }
*/
case M_SKIP_NEXT: case M_SKIP_NEXT:
fControls->SkipForward(); fControls->SkipForward();
break; break;
@@ -666,7 +665,9 @@ MainWin::MessageReceived(BMessage *msg)
// the global settings instance... // the global settings instance...
_AdoptGlobalSettings(); _AdoptGlobalSettings();
break; break;
case M_FILE_DELETE:
fControls->SkipForwardAndDelete();
break;
default: default:
// let BWindow handle the rest // let BWindow handle the rest
BWindow::MessageReceived(msg); BWindow::MessageReceived(msg);
@@ -837,7 +838,7 @@ MainWin::_RefsReceived(BMessage* msg)
void void
MainWin::_SetupWindow() MainWin::_SetupWindow()
{ {
printf("MainWin::_SetupWindow\n"); // printf("MainWin::_SetupWindow\n");
// Populate the track menus // Populate the track menus
_SetupTrackMenus(); _SetupTrackMenus();
// Enable both if a file was loaded // Enable both if a file was loaded
@@ -1261,10 +1262,10 @@ MainWin::_KeyDown(BMessage *msg)
uint32 key = msg->FindInt32("key"); uint32 key = msg->FindInt32("key");
uint32 raw_char = msg->FindInt32("raw_char"); uint32 raw_char = msg->FindInt32("raw_char");
uint32 modifiers = msg->FindInt32("modifiers"); uint32 modifier = msg->FindInt32("modifiers");
printf("key 0x%lx, raw_char 0x%lx, modifiers 0x%lx\n", key, raw_char, printf("key 0x%lx, raw_char 0x%lx, modifiers 0x%lx\n", key, raw_char,
modifiers); modifier);
switch (raw_char) { switch (raw_char) {
case B_SPACE: case B_SPACE:
@@ -1279,14 +1280,14 @@ MainWin::_KeyDown(BMessage *msg)
break; break;
case B_ENTER: // Enter / Return case B_ENTER: // Enter / Return
if (modifiers & B_COMMAND_KEY) { if (modifier & B_COMMAND_KEY) {
PostMessage(M_TOGGLE_FULLSCREEN); PostMessage(M_TOGGLE_FULLSCREEN);
return B_OK; return B_OK;
} else } else
break; break;
case B_TAB: case B_TAB:
if ((modifiers & (B_COMMAND_KEY | B_CONTROL_KEY | B_OPTION_KEY if ((modifier & (B_COMMAND_KEY | B_CONTROL_KEY | B_OPTION_KEY
| B_MENU_KEY)) == 0) { | B_MENU_KEY)) == 0) {
PostMessage(M_TOGGLE_FULLSCREEN); PostMessage(M_TOGGLE_FULLSCREEN);
return B_OK; return B_OK;
@@ -1294,7 +1295,7 @@ MainWin::_KeyDown(BMessage *msg)
break; break;
case B_UP_ARROW: case B_UP_ARROW:
if (modifiers & B_COMMAND_KEY) { if (modifier & B_COMMAND_KEY) {
PostMessage(M_SKIP_NEXT); PostMessage(M_SKIP_NEXT);
} else { } else {
PostMessage(M_VOLUME_UP); PostMessage(M_VOLUME_UP);
@@ -1302,7 +1303,7 @@ MainWin::_KeyDown(BMessage *msg)
return B_OK; return B_OK;
case B_DOWN_ARROW: case B_DOWN_ARROW:
if (modifiers & B_COMMAND_KEY) { if (modifier & B_COMMAND_KEY) {
PostMessage(M_SKIP_PREV); PostMessage(M_SKIP_PREV);
} else { } else {
PostMessage(M_VOLUME_DOWN); PostMessage(M_VOLUME_DOWN);
@@ -1310,7 +1311,7 @@ MainWin::_KeyDown(BMessage *msg)
return B_OK; return B_OK;
case B_RIGHT_ARROW: case B_RIGHT_ARROW:
if (modifiers & B_COMMAND_KEY) { if (modifier & B_COMMAND_KEY) {
PostMessage(M_VOLUME_UP); PostMessage(M_VOLUME_UP);
} else { } else {
PostMessage(M_SKIP_NEXT); PostMessage(M_SKIP_NEXT);
@@ -1318,7 +1319,7 @@ MainWin::_KeyDown(BMessage *msg)
return B_OK; return B_OK;
case B_LEFT_ARROW: case B_LEFT_ARROW:
if (modifiers & B_COMMAND_KEY) { if (modifier & B_COMMAND_KEY) {
PostMessage(M_VOLUME_DOWN); PostMessage(M_VOLUME_DOWN);
} else { } else {
PostMessage(M_SKIP_PREV); PostMessage(M_SKIP_PREV);
@@ -1336,17 +1337,15 @@ MainWin::_KeyDown(BMessage *msg)
switch (key) { switch (key) {
case 0x3a: // numeric keypad + case 0x3a: // numeric keypad +
if ((modifiers & B_COMMAND_KEY) == 0) { if ((modifier & B_COMMAND_KEY) == 0) {
printf("if\n");
PostMessage(M_VOLUME_UP); PostMessage(M_VOLUME_UP);
return B_OK; return B_OK;
} else { } else {
printf("else\n");
break; break;
} }
case 0x25: // numeric keypad - case 0x25: // numeric keypad -
if ((modifiers & B_COMMAND_KEY) == 0) { if ((modifier & B_COMMAND_KEY) == 0) {
PostMessage(M_VOLUME_DOWN); PostMessage(M_VOLUME_DOWN);
return B_OK; return B_OK;
} else { } else {
@@ -1370,6 +1369,14 @@ MainWin::_KeyDown(BMessage *msg)
case 0x48: // numeric keypad left arrow case 0x48: // numeric keypad left arrow
PostMessage(M_SKIP_PREV); PostMessage(M_SKIP_PREV);
return B_OK; return B_OK;
case 0x34: //delete button
case 0x3e: //d for delete
case 0x2b: //t for Trash
if (modifiers() & B_COMMAND_KEY) {
PostMessage(M_FILE_DELETE);
return B_OK;
}
break;
} }
return B_ERROR; return B_ERROR;
@@ -301,7 +301,7 @@ TransportControlGroup::_ExponentialToLinear(float db_in)
db = db * (fabs(kVolumeDbMin) / pow(fabs(kVolumeDbMin), (1.0 / kVolumeDbExpNegative))); db = db * (fabs(kVolumeDbMin) / pow(fabs(kVolumeDbMin), (1.0 / kVolumeDbExpNegative)));
db = -db; db = -db;
} }
printf("_ExponentialToLinear %.4f => %.4f\n", db_in, db); //printf("_ExponentialToLinear %.4f => %.4f\n", db_in, db);
return db; return db;
} }
+1 -1
View File
@@ -272,7 +272,7 @@ VideoNode::FormatChanged(const media_source &src,
fInput.format = format; fInput.format = format;
printf("VideoNode::FormatChanged leave\n"); //printf("VideoNode::FormatChanged leave\n");
return B_OK; return B_OK;
} }
+29 -1
View File
@@ -3,7 +3,7 @@
* *
* Copyright (C) 2006 Marcus Overhagen <marcus@overhagen.de> * Copyright (C) 2006 Marcus Overhagen <marcus@overhagen.de>
* Copyright (C) 2007 Stephan Aßmus <superstippi@gmx.de> * Copyright (C) 2007 Stephan Aßmus <superstippi@gmx.de>
* Copyright (C) 2008 Fredrik Modéen <fredrik@modeen.se> (I have no problem changing my things to MIT) * Copyright (C) 2008-2009 Fredrik Modéen <[FirstName]@[LastName].se> (MIT ok)
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@@ -40,6 +40,11 @@ using std::nothrow;
// TODO: using BList for objects is bad, replace it with a template // TODO: using BList for objects is bad, replace it with a template
// TODO: Remove this and use Tracker's Command.h once it is moved into the private headers
namespace BPrivate {
const uint32 kMoveToTrash = 'Ttrs';
}
Playlist::Listener::Listener() {} Playlist::Listener::Listener() {}
Playlist::Listener::~Listener() {} Playlist::Listener::~Listener() {}
void Playlist::Listener::RefAdded(const entry_ref& ref, int32 index) {} void Playlist::Listener::RefAdded(const entry_ref& ref, int32 index) {}
@@ -283,6 +288,18 @@ Playlist::RemoveRef(int32 index, bool careAboutCurrentIndex)
} }
void
Playlist::RemoveRefPermanent(int32 index, bool removeToTrash)
{
if (index != -1) {
entry_ref song = RemoveRef(index);
if(removeToTrash)
_DeleteEntry(&song);//Remove with tracker
}
}
int32 int32
Playlist::IndexOf(const entry_ref& _ref) const Playlist::IndexOf(const entry_ref& _ref) const
{ {
@@ -570,6 +587,17 @@ Playlist::_MIMEString(const entry_ref* ref)
} }
void
Playlist::_DeleteEntry(const entry_ref* file)
{
// Move entry_ref to Trash
BMessage trash(BPrivate::kMoveToTrash);
trash.AddRef("refs", file);
BMessenger("application/x-vnd.Be-TRAK").SendMessage(&trash);
}
void void
Playlist::_NotifyRefAdded(const entry_ref& ref, int32 index) const Playlist::_NotifyRefAdded(const entry_ref& ref, int32 index) const
{ {
+5 -1
View File
@@ -3,7 +3,7 @@
* *
* Copyright (C) 2006 Marcus Overhagen <marcus@overhagen.de> * Copyright (C) 2006 Marcus Overhagen <marcus@overhagen.de>
* Copyright (C) 2007 Stephan Aßmus <superstippi@gmx.de> * Copyright (C) 2007 Stephan Aßmus <superstippi@gmx.de>
* Copyright (C) 2008 Fredrik Modéen <fredrik@modeen.se> (I have no problem changing my things to MIT) * Copyright (C) 2008-2009 Fredrik Modéen <[FirstName]@[LastName].se> (MIT ok)
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@@ -68,6 +68,9 @@ public:
entry_ref RemoveRef(int32 index, entry_ref RemoveRef(int32 index,
bool careAboutCurrentIndex = true); bool careAboutCurrentIndex = true);
void RemoveRefPermanent(int32 index,
bool removeToTrash);
bool AdoptPlaylist(Playlist& other); bool AdoptPlaylist(Playlist& other);
bool AdoptPlaylist(Playlist& other, int32 index); bool AdoptPlaylist(Playlist& other, int32 index);
@@ -101,6 +104,7 @@ private:
static bool _IsBinaryPlaylist(const BString& mimeString); static bool _IsBinaryPlaylist(const BString& mimeString);
static bool _IsPlaylist(const BString& mimeString); static bool _IsPlaylist(const BString& mimeString);
static BString _MIMEString(const entry_ref* entry); static BString _MIMEString(const entry_ref* entry);
void _DeleteEntry(const entry_ref* file);
void _NotifyRefAdded(const entry_ref& ref, void _NotifyRefAdded(const entry_ref& ref,
int32 index) const; int32 index) const;
void _NotifyRefRemoved(int32 index) const; void _NotifyRefRemoved(int32 index) const;
@@ -255,6 +255,7 @@ PlaylistListView::AttachedToWindow()
void void
PlaylistListView::MessageReceived(BMessage* message) PlaylistListView::MessageReceived(BMessage* message)
{ {
// message->PrintToStream();
switch (message->what) { switch (message->what) {
// PlaylistObserver messages // PlaylistObserver messages
case MSG_PLAYLIST_REF_ADDED: { case MSG_PLAYLIST_REF_ADDED: {
@@ -442,6 +443,16 @@ PlaylistListView::Randomize()
} }
void
PlaylistListView::PermanentRemoveSelectedFile(bool permRemove)
{
BAutolock _(fPlaylist);
int32 index = fPlaylist->CurrentRefIndex();
fPlaylist->SetCurrentRefIndex(index + 1);
fPlaylist->RemoveRefPermanent(index, permRemove);
}
// #pragma mark - // #pragma mark -
@@ -45,6 +45,7 @@ class PlaylistListView : public SimpleListView {
int32 appendIndex); int32 appendIndex);
void Randomize(); void Randomize();
void PermanentRemoveSelectedFile(bool permRemove);
private: private:
void _FullSync(); void _FullSync();
@@ -53,7 +53,11 @@ enum {
// edit // edit
M_PLAYLIST_EMPTY = 'emty', M_PLAYLIST_EMPTY = 'emty',
M_PLAYLIST_RANDOMIZE = 'rand' M_PLAYLIST_RANDOMIZE = 'rand',
//
M_PLAYLIST_DELETE_FILE = 'dlfi',
M_PLAYLIST_PER_DEL_FILE = 'pdfi'
}; };
#define SPACE 5 #define SPACE 5
@@ -191,7 +195,12 @@ PlaylistWindow::MessageReceived(BMessage* message)
case M_PLAYLIST_RANDOMIZE: case M_PLAYLIST_RANDOMIZE:
fListView->Randomize(); fListView->Randomize();
break; break;
case M_PLAYLIST_DELETE_FILE:
fListView->PermanentRemoveSelectedFile(false);
break;
case M_PLAYLIST_PER_DEL_FILE:
fListView->PermanentRemoveSelectedFile(true);
break;
default: default:
BWindow::MessageReceived(message); BWindow::MessageReceived(message);
break; break;
@@ -199,6 +208,35 @@ PlaylistWindow::MessageReceived(BMessage* message)
} }
void
PlaylistWindow::DispatchMessage(BMessage *message, BHandler *handler)
{
if (message->what == B_KEY_DOWN) {
uint32 key = message->FindInt32("key");
switch (key) {
case 0x34: //delete button
case 0x3e: //d for delete
case 0x2b: //t for Trash
if (modifiers() & B_COMMAND_KEY) {
fListView->PermanentRemoveSelectedFile(true);
return;
}
break;
case 0x2a: //r for Remove
if (modifiers() & B_COMMAND_KEY) {
fListView->PermanentRemoveSelectedFile(false);
return;
}
break;
}
}
BWindow::DispatchMessage(message, handler);
}
// #pragma mark - // #pragma mark -
@@ -227,10 +265,16 @@ PlaylistWindow::_CreateMenu(BRect& frame)
fRedoMI = new BMenuItem("Redo", new BMessage(B_REDO), 'Z', B_SHIFT_KEY); fRedoMI = new BMenuItem("Redo", new BMessage(B_REDO), 'Z', B_SHIFT_KEY);
editMenu->AddItem(fRedoMI); editMenu->AddItem(fRedoMI);
editMenu->AddSeparatorItem(); editMenu->AddSeparatorItem();
editMenu->AddItem(new BMenuItem("Make Empty",
new BMessage(M_PLAYLIST_EMPTY), 'N'));
editMenu->AddItem(new BMenuItem("Randomize", editMenu->AddItem(new BMenuItem("Randomize",
new BMessage(M_PLAYLIST_RANDOMIZE), 'R')); new BMessage(M_PLAYLIST_RANDOMIZE), 'R'));
editMenu->AddSeparatorItem();
editMenu->AddItem(new BMenuItem("Remove",
new BMessage(M_PLAYLIST_DELETE_FILE), 'R'));
editMenu->AddItem(new BMenuItem("Remove Permanent",
new BMessage(M_PLAYLIST_PER_DEL_FILE), 'T', B_COMMAND_KEY));
editMenu->AddItem(new BMenuItem("Remove All",
new BMessage(M_PLAYLIST_EMPTY), 'N'));
menuBar->AddItem(editMenu); menuBar->AddItem(editMenu);
AddChild(menuBar); AddChild(menuBar);
@@ -36,11 +36,11 @@ public:
virtual bool QuitRequested(); virtual bool QuitRequested();
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
virtual void DispatchMessage(BMessage *msg, BHandler *handler);
private: private:
void _CreateMenu(BRect& frame); void _CreateMenu(BRect& frame);
void _ObjectChanged(const Notifier* object); void _ObjectChanged(const Notifier* object);
void _SavePlaylist(const BMessage* filePanelMessage); void _SavePlaylist(const BMessage* filePanelMessage);
void _SavePlaylist(const entry_ref& ref); void _SavePlaylist(const entry_ref& ref);
void _SavePlaylist(BEntry& origEntry, void _SavePlaylist(BEntry& origEntry,