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) 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
* modify it under the terms of the GNU General Public License
@@ -231,14 +231,14 @@ Controller::SetTo(const entry_ref &ref)
err = mf->InitCheck();
if (err != B_OK) {
printf("Controller::SetTo: initcheck failed\n");
//printf("Controller::SetTo: initcheck failed\n");
_NotifyFileChanged();
return err;
}
int trackcount = mf->CountTracks();
if (trackcount <= 0) {
printf("Controller::SetTo: trackcount %d\n", trackcount);
//printf("Controller::SetTo: trackcount %d\n", trackcount);
_NotifyFileChanged();
return B_MEDIA_NO_HANDLER;
}
@@ -248,15 +248,15 @@ Controller::SetTo(const entry_ref &ref)
media_format f;
err = t->EncodedFormat(&f);
if (err != B_OK) {
printf("Controller::SetTo: EncodedFormat failed for track index %d, error 0x%08lx (%s)\n",
i, err, strerror(err));
//printf("Controller::SetTo: EncodedFormat failed for track index %d, error 0x%08lx (%s)\n",
// i, err, strerror(err));
mf->ReleaseTrack(t);
continue;
}
if (t->Duration() <= 0) {
printf("Controller::SetTo: track index %d has no duration\n",i);
mf->ReleaseTrack(t);
//printf("Controller::SetTo: track index %d has no duration\n",i);
//mf->ReleaseTrack(t);
continue;
}
@@ -272,8 +272,8 @@ Controller::SetTo(const entry_ref &ref)
}
}
printf("Controller::SetTo: %d audio track, %d video track\n",
AudioTrackCount(), VideoTrackCount());
//printf("Controller::SetTo: %d audio track, %d video track\n",
// AudioTrackCount(), VideoTrackCount());
fMediaFile = mf;
mediaFileDeleter.Detach();
@@ -282,8 +282,8 @@ Controller::SetTo(const entry_ref &ref)
SelectVideoTrack(0);
if (fAudioTrackSupplier == NULL && fVideoTrackSupplier == NULL) {
printf("Controller::SetTo: no audio or video tracks found or "
"no decoders\n");
//printf("Controller::SetTo: no audio or video tracks found or "
// "no decoders\n");
_NotifyFileChanged();
delete fMediaFile;
fMediaFile = NULL;
@@ -453,8 +453,8 @@ Controller::SelectVideoTrack(int n)
fDuration = max_c(a, v);
fVideoFrameRate = fVideoTrackSupplier->Format().u.raw_video.field_rate;
if (fVideoFrameRate <= 0.0) {
printf("Controller::SelectVideoTrack(%d) - invalid video frame rate: %.1f\n", n,
fVideoFrameRate);
//printf("Controller::SelectVideoTrack(%d) - invalid video frame rate: %.1f\n", n,
// fVideoFrameRate);
fVideoFrameRate = 25.0;
}
@@ -486,7 +486,7 @@ Controller::CurrentVideoTrack()
void
Controller::Stop()
{
printf("Controller::Stop\n");
//printf("Controller::Stop\n");
BAutolock _(this);
@@ -500,7 +500,7 @@ Controller::Stop()
void
Controller::Play()
{
printf("Controller::Play\n");
//printf("Controller::Play\n");
BAutolock _(this);
@@ -512,7 +512,7 @@ Controller::Play()
void
Controller::Pause()
{
printf("Controller::Pause\n");
// printf("Controller::Pause\n");
BAutolock _(this);
@@ -525,7 +525,7 @@ Controller::Pause()
void
Controller::TogglePlaying()
{
printf("Controller::TogglePlaying\n");
// printf("Controller::TogglePlaying\n");
BAutolock _(this);
@@ -567,7 +567,7 @@ Controller::TimePosition()
void
Controller::SetVolume(float value)
{
printf("Controller::SetVolume %.4f\n", value);
// printf("Controller::SetVolume %.4f\n", value);
if (!Lock())
return;
+15 -7
View File
@@ -3,6 +3,7 @@
*
* Copyright (C) 2006 Marcus Overhagen <marcus@overhagen.de>
* Copyright (C) 2007 Stephan Aßmus <superstippi@gmx.de>
* Copyright (C) 2008-2009 Fredrik Modéen <[FirstName]@[LastName].se> (MIT ok)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -29,7 +30,6 @@
#include "Playlist.h"
#include "PlaylistObserver.h"
ControllerView::ControllerView(BRect frame, Controller* controller,
Playlist* playlist)
: TransportControlGroup(frame, true, true, false)
@@ -70,7 +70,7 @@ ControllerView::MessageReceived(BMessage *msg)
case MSG_PLAYLIST_REF_REMOVED:
case MSG_PLAYLIST_REFS_SORTED:
case MSG_PLAYLIST_CURRENT_REF_CHANGED:
CheckSkippable();
_CheckSkippable();
break;
default:
@@ -107,7 +107,7 @@ void
ControllerView::Rewind()
{
// TODO: make it so this function is called repeatedly
printf("ControllerView::Rewind()\n");
//printf("ControllerView::Rewind()\n");
}
@@ -115,7 +115,7 @@ void
ControllerView::Forward()
{
// 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
ControllerView::VolumeChanged(float value)
{
@@ -161,7 +171,7 @@ ControllerView::PositionChanged(float value)
void
ControllerView::CheckSkippable()
ControllerView::_CheckSkippable()
{
BAutolock _(fPlaylist);
@@ -169,5 +179,3 @@ ControllerView::CheckSkippable()
fPlaylist->GetSkipInfo(&canSkipPrevious, &canSkipNext);
SetSkippable(canSkipPrevious, canSkipNext);
}
+3 -1
View File
@@ -3,6 +3,7 @@
*
* Copyright (C) 2006 Marcus Overhagen <marcus@overhagen.de>
* Copyright (C) 2007 Stephan Aßmus <superstippi@gmx.de>
* Copyright (C) 2008-2009 Fredrik Modéen <[FirstName]@[LastName].se> (MIT ok)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -44,6 +45,7 @@ public:
virtual void Forward();
virtual void SkipBackward();
virtual void SkipForward();
virtual void SkipForwardAndDelete();
virtual void VolumeChanged(float value);
virtual void ToggleMute();
virtual void PositionChanged(float value);
@@ -54,7 +56,7 @@ private:
void Draw(BRect updateRect);
// ControllerView
void CheckSkippable();
void _CheckSkippable();
private:
Controller* fController;
+34 -27
View File
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006 Marcus Overhagen <marcus@overhagen.de>
* Copyright (C) 2007-2008 Stephan Aßmus <superstippi@gmx.de> (GPL->MIT ok)
* Copyright (C) 2007-2008 Fredrik Modéen <fredrik@modeen.se>
* Copyright (C) 2007-2009 Fredrik Modéen <[FirstName]@[LastName].se> (MIT ok)
*
* This program is free software; you can redistribute it and/or
* 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_END = 0x000fffff,
M_SET_PLAYLIST_POSITION
M_SET_PLAYLIST_POSITION,
M_FILE_DELETE
};
//#define printf(a...)
@@ -198,7 +200,7 @@ MainWin::MainWin()
MainWin::~MainWin()
{
printf("MainWin::~MainWin\n");
// printf("MainWin::~MainWin\n");
Settings::Default()->RemoveListener(&fGlobalSettingsListener);
fPlaylist->RemoveListener(fPlaylistObserver);
@@ -239,8 +241,8 @@ MainWin::FrameResized(float newWidth, float newHeight)
bool noMenu = fNoMenu || fIsFullscreen;
bool noControls = fNoControls || fIsFullscreen;
printf("FrameResized enter: newWidth %.0f, newHeight %.0f\n",
newWidth, newHeight);
// printf("FrameResized enter: newWidth %.0f, newHeight %.0f\n",
// newWidth, newHeight);
int maxVideoWidth = int(newWidth) + 1;
int maxVideoHeight = int(newHeight) + 1
@@ -264,7 +266,7 @@ MainWin::FrameResized(float newWidth, float newHeight)
if (maxVideoHeight == 0) {
bool hidden = fVideoView->IsHidden();
printf(" video view hidden: %d\n", hidden);
// printf(" video view hidden: %d\n", hidden);
if (!hidden)
fVideoView->Hide();
} else {
@@ -285,7 +287,7 @@ printf(" video view hidden: %d\n", hidden);
// y += fControlsHeight;
}
printf("FrameResized leave\n");
// printf("FrameResized leave\n");
}
@@ -570,9 +572,7 @@ MainWin::MessageReceived(BMessage *msg)
_ToggleFullscreen();
_ResizeWindow(400);
break;
/*
/*
case B_ACQUIRE_OVERLAY_LOCK:
printf("B_ACQUIRE_OVERLAY_LOCK\n");
fVideoView->OverlayLockAcquire();
@@ -582,10 +582,9 @@ MainWin::MessageReceived(BMessage *msg)
printf("B_RELEASE_OVERLAY_LOCK\n");
fVideoView->OverlayLockRelease();
break;
*/
case B_MOUSE_WHEEL_CHANGED:
{
printf("B_MOUSE_WHEEL_CHANGED\n");
float dx = msg->FindFloat("be:wheel_delta_x");
float dy = msg->FindFloat("be:wheel_delta_y");
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);
break;
}
*/
case M_SKIP_NEXT:
fControls->SkipForward();
break;
@@ -666,7 +665,9 @@ MainWin::MessageReceived(BMessage *msg)
// the global settings instance...
_AdoptGlobalSettings();
break;
case M_FILE_DELETE:
fControls->SkipForwardAndDelete();
break;
default:
// let BWindow handle the rest
BWindow::MessageReceived(msg);
@@ -837,7 +838,7 @@ MainWin::_RefsReceived(BMessage* msg)
void
MainWin::_SetupWindow()
{
printf("MainWin::_SetupWindow\n");
// printf("MainWin::_SetupWindow\n");
// Populate the track menus
_SetupTrackMenus();
// Enable both if a file was loaded
@@ -1261,10 +1262,10 @@ MainWin::_KeyDown(BMessage *msg)
uint32 key = msg->FindInt32("key");
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,
modifiers);
modifier);
switch (raw_char) {
case B_SPACE:
@@ -1279,14 +1280,14 @@ MainWin::_KeyDown(BMessage *msg)
break;
case B_ENTER: // Enter / Return
if (modifiers & B_COMMAND_KEY) {
if (modifier & B_COMMAND_KEY) {
PostMessage(M_TOGGLE_FULLSCREEN);
return B_OK;
} else
break;
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) {
PostMessage(M_TOGGLE_FULLSCREEN);
return B_OK;
@@ -1294,7 +1295,7 @@ MainWin::_KeyDown(BMessage *msg)
break;
case B_UP_ARROW:
if (modifiers & B_COMMAND_KEY) {
if (modifier & B_COMMAND_KEY) {
PostMessage(M_SKIP_NEXT);
} else {
PostMessage(M_VOLUME_UP);
@@ -1302,7 +1303,7 @@ MainWin::_KeyDown(BMessage *msg)
return B_OK;
case B_DOWN_ARROW:
if (modifiers & B_COMMAND_KEY) {
if (modifier & B_COMMAND_KEY) {
PostMessage(M_SKIP_PREV);
} else {
PostMessage(M_VOLUME_DOWN);
@@ -1310,7 +1311,7 @@ MainWin::_KeyDown(BMessage *msg)
return B_OK;
case B_RIGHT_ARROW:
if (modifiers & B_COMMAND_KEY) {
if (modifier & B_COMMAND_KEY) {
PostMessage(M_VOLUME_UP);
} else {
PostMessage(M_SKIP_NEXT);
@@ -1318,7 +1319,7 @@ MainWin::_KeyDown(BMessage *msg)
return B_OK;
case B_LEFT_ARROW:
if (modifiers & B_COMMAND_KEY) {
if (modifier & B_COMMAND_KEY) {
PostMessage(M_VOLUME_DOWN);
} else {
PostMessage(M_SKIP_PREV);
@@ -1336,17 +1337,15 @@ MainWin::_KeyDown(BMessage *msg)
switch (key) {
case 0x3a: // numeric keypad +
if ((modifiers & B_COMMAND_KEY) == 0) {
printf("if\n");
if ((modifier & B_COMMAND_KEY) == 0) {
PostMessage(M_VOLUME_UP);
return B_OK;
} else {
printf("else\n");
break;
}
case 0x25: // numeric keypad -
if ((modifiers & B_COMMAND_KEY) == 0) {
if ((modifier & B_COMMAND_KEY) == 0) {
PostMessage(M_VOLUME_DOWN);
return B_OK;
} else {
@@ -1370,6 +1369,14 @@ MainWin::_KeyDown(BMessage *msg)
case 0x48: // numeric keypad left arrow
PostMessage(M_SKIP_PREV);
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;
@@ -301,7 +301,7 @@ TransportControlGroup::_ExponentialToLinear(float db_in)
db = db * (fabs(kVolumeDbMin) / pow(fabs(kVolumeDbMin), (1.0 / kVolumeDbExpNegative)));
db = -db;
}
printf("_ExponentialToLinear %.4f => %.4f\n", db_in, db);
//printf("_ExponentialToLinear %.4f => %.4f\n", db_in, db);
return db;
}
+1 -1
View File
@@ -272,7 +272,7 @@ VideoNode::FormatChanged(const media_source &src,
fInput.format = format;
printf("VideoNode::FormatChanged leave\n");
//printf("VideoNode::FormatChanged leave\n");
return B_OK;
}
+29 -1
View File
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006 Marcus Overhagen <marcus@overhagen.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
* 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: 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() {}
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
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
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) 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
* modify it under the terms of the GNU General Public License
@@ -68,6 +68,9 @@ public:
entry_ref RemoveRef(int32 index,
bool careAboutCurrentIndex = true);
void RemoveRefPermanent(int32 index,
bool removeToTrash);
bool AdoptPlaylist(Playlist& other);
bool AdoptPlaylist(Playlist& other, int32 index);
@@ -101,6 +104,7 @@ private:
static bool _IsBinaryPlaylist(const BString& mimeString);
static bool _IsPlaylist(const BString& mimeString);
static BString _MIMEString(const entry_ref* entry);
void _DeleteEntry(const entry_ref* file);
void _NotifyRefAdded(const entry_ref& ref,
int32 index) const;
void _NotifyRefRemoved(int32 index) const;
@@ -255,6 +255,7 @@ PlaylistListView::AttachedToWindow()
void
PlaylistListView::MessageReceived(BMessage* message)
{
// message->PrintToStream();
switch (message->what) {
// PlaylistObserver messages
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 -
@@ -45,6 +45,7 @@ class PlaylistListView : public SimpleListView {
int32 appendIndex);
void Randomize();
void PermanentRemoveSelectedFile(bool permRemove);
private:
void _FullSync();
@@ -53,7 +53,11 @@ enum {
// edit
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
@@ -191,7 +195,12 @@ PlaylistWindow::MessageReceived(BMessage* message)
case M_PLAYLIST_RANDOMIZE:
fListView->Randomize();
break;
case M_PLAYLIST_DELETE_FILE:
fListView->PermanentRemoveSelectedFile(false);
break;
case M_PLAYLIST_PER_DEL_FILE:
fListView->PermanentRemoveSelectedFile(true);
break;
default:
BWindow::MessageReceived(message);
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 -
@@ -227,10 +265,16 @@ PlaylistWindow::_CreateMenu(BRect& frame)
fRedoMI = new BMenuItem("Redo", new BMessage(B_REDO), 'Z', B_SHIFT_KEY);
editMenu->AddItem(fRedoMI);
editMenu->AddSeparatorItem();
editMenu->AddItem(new BMenuItem("Make Empty",
new BMessage(M_PLAYLIST_EMPTY), 'N'));
editMenu->AddItem(new BMenuItem("Randomize",
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);
AddChild(menuBar);
@@ -36,11 +36,11 @@ public:
virtual bool QuitRequested();
virtual void MessageReceived(BMessage* message);
virtual void DispatchMessage(BMessage *msg, BHandler *handler);
private:
void _CreateMenu(BRect& frame);
void _ObjectChanged(const Notifier* object);
void _SavePlaylist(const BMessage* filePanelMessage);
void _SavePlaylist(const entry_ref& ref);
void _SavePlaylist(BEntry& origEntry,