* I didn't like so much how the "Remove and Move into Trash" feature was
implemented. It didn't reuse existing code and didn't integrate well. No Undo/Redo except via Tracker, but not in the Playlist... some bugs as well (Remove had same shortcut as Randomize, Didn't maintain current playback item if last entry was removed) * I need to reenable the main window short cut though. This is only temporary. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30768 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -135,16 +135,6 @@ 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)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ 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);
|
||||||
|
|||||||
@@ -665,9 +665,7 @@ 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);
|
||||||
@@ -1369,14 +1367,15 @@ 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
|
// TODO: Reenable this and use Undo/Redo stack...
|
||||||
case 0x3e: //d for delete
|
// case 0x34: //delete button
|
||||||
case 0x2b: //t for Trash
|
// case 0x3e: //d for delete
|
||||||
if (modifiers() & B_COMMAND_KEY) {
|
// case 0x2b: //t for Trash
|
||||||
PostMessage(M_FILE_DELETE);
|
// if (modifiers() & B_COMMAND_KEY) {
|
||||||
return B_OK;
|
// PostMessage(M_FILE_DELETE);
|
||||||
}
|
// return B_OK;
|
||||||
break;
|
// }
|
||||||
|
// break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|||||||
@@ -627,7 +627,7 @@ DragSortableListView::ScrollTo(int32 index)
|
|||||||
|
|
||||||
// MoveItems
|
// MoveItems
|
||||||
void
|
void
|
||||||
DragSortableListView::MoveItems(BList& indices, int32 index)
|
DragSortableListView::MoveItems(const BList& indices, int32 index)
|
||||||
{
|
{
|
||||||
DeselectAll();
|
DeselectAll();
|
||||||
// we remove the items while we look at them, the insertion index is decreased
|
// we remove the items while we look at them, the insertion index is decreased
|
||||||
@@ -659,7 +659,7 @@ DragSortableListView::MoveItems(BList& indices, int32 index)
|
|||||||
|
|
||||||
// CopyItems
|
// CopyItems
|
||||||
void
|
void
|
||||||
DragSortableListView::CopyItems(BList& indices, int32 toIndex)
|
DragSortableListView::CopyItems(const BList& indices, int32 toIndex)
|
||||||
{
|
{
|
||||||
DeselectAll();
|
DeselectAll();
|
||||||
// by inserting the items after we copied all items first, we avoid
|
// by inserting the items after we copied all items first, we avoid
|
||||||
@@ -689,7 +689,7 @@ DragSortableListView::CopyItems(BList& indices, int32 toIndex)
|
|||||||
|
|
||||||
// RemoveItemList
|
// RemoveItemList
|
||||||
void
|
void
|
||||||
DragSortableListView::RemoveItemList(BList& indices)
|
DragSortableListView::RemoveItemList(const BList& indices)
|
||||||
{
|
{
|
||||||
int32 count = indices.CountItems();
|
int32 count = indices.CountItems();
|
||||||
for (int32 i = 0; i < count; i++) {
|
for (int32 i = 0; i < count; i++) {
|
||||||
@@ -698,11 +698,10 @@ DragSortableListView::RemoveItemList(BList& indices)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveSelected
|
// GetSelectedItems
|
||||||
void
|
void
|
||||||
DragSortableListView::RemoveSelected()
|
DragSortableListView::GetSelectedItems(BList& indices)
|
||||||
{
|
{
|
||||||
BList indices;
|
|
||||||
for (int32 i = 0; true; i++) {
|
for (int32 i = 0; true; i++) {
|
||||||
int32 index = CurrentSelection(i);
|
int32 index = CurrentSelection(i);
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
@@ -710,6 +709,14 @@ DragSortableListView::RemoveSelected()
|
|||||||
if (!indices.AddItem((void*)index))
|
if (!indices.AddItem((void*)index))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveSelected
|
||||||
|
void
|
||||||
|
DragSortableListView::RemoveSelected()
|
||||||
|
{
|
||||||
|
BList indices;
|
||||||
|
GetSelectedItems(indices);
|
||||||
|
|
||||||
DeselectAll();
|
DeselectAll();
|
||||||
|
|
||||||
|
|||||||
@@ -89,9 +89,11 @@ class DragSortableListView : public BListView {
|
|||||||
|
|
||||||
bool MouseWheelChanged(float x, float y);
|
bool MouseWheelChanged(float x, float y);
|
||||||
|
|
||||||
virtual void MoveItems(BList& indices, int32 toIndex);
|
virtual void MoveItems(const BList& indices, int32 toIndex);
|
||||||
virtual void CopyItems(BList& indices, int32 toIndex);
|
virtual void CopyItems(const BList& indices, int32 toIndex);
|
||||||
virtual void RemoveItemList(BList& indices);
|
virtual void RemoveItemList(const BList& indices);
|
||||||
|
|
||||||
|
void GetSelectedItems(BList& indices);
|
||||||
void RemoveSelected(); // uses RemoveItemList()
|
void RemoveSelected(); // uses RemoveItemList()
|
||||||
void RemoveAll(); // uses RemoveItemList()
|
void RemoveAll(); // uses RemoveItemList()
|
||||||
int32 CountSelectedItems() const;
|
int32 CountSelectedItems() const;
|
||||||
|
|||||||
@@ -288,18 +288,6 @@ 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
|
||||||
{
|
{
|
||||||
@@ -587,17 +575,6 @@ 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
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -68,9 +68,6 @@ 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);
|
||||||
|
|
||||||
@@ -103,8 +100,7 @@ private:
|
|||||||
static bool _IsTextPlaylist(const BString& mimeString);
|
static bool _IsTextPlaylist(const BString& mimeString);
|
||||||
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* ref);
|
||||||
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;
|
||||||
|
|||||||
@@ -367,7 +367,7 @@ PlaylistListView::KeyDown(const char* bytes, int32 numBytes)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PlaylistListView::MoveItems(BList& indices, int32 toIndex)
|
PlaylistListView::MoveItems(const BList& indices, int32 toIndex)
|
||||||
{
|
{
|
||||||
fCommandStack->Perform(new (nothrow) MovePLItemsCommand(fPlaylist,
|
fCommandStack->Perform(new (nothrow) MovePLItemsCommand(fPlaylist,
|
||||||
(int32*)indices.Items(), indices.CountItems(), toIndex));
|
(int32*)indices.Items(), indices.CountItems(), toIndex));
|
||||||
@@ -375,7 +375,7 @@ PlaylistListView::MoveItems(BList& indices, int32 toIndex)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PlaylistListView::CopyItems(BList& indices, int32 toIndex)
|
PlaylistListView::CopyItems(const BList& indices, int32 toIndex)
|
||||||
{
|
{
|
||||||
fCommandStack->Perform(new (nothrow) CopyPLItemsCommand(fPlaylist,
|
fCommandStack->Perform(new (nothrow) CopyPLItemsCommand(fPlaylist,
|
||||||
(int32*)indices.Items(), indices.CountItems(), toIndex));
|
(int32*)indices.Items(), indices.CountItems(), toIndex));
|
||||||
@@ -383,7 +383,7 @@ PlaylistListView::CopyItems(BList& indices, int32 toIndex)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PlaylistListView::RemoveItemList(BList& indices)
|
PlaylistListView::RemoveItemList(const BList& indices)
|
||||||
{
|
{
|
||||||
fCommandStack->Perform(new (nothrow) RemovePLItemsCommand(fPlaylist,
|
fCommandStack->Perform(new (nothrow) RemovePLItemsCommand(fPlaylist,
|
||||||
(int32*)indices.Items(), indices.CountItems()));
|
(int32*)indices.Items(), indices.CountItems()));
|
||||||
@@ -444,12 +444,12 @@ PlaylistListView::Randomize()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PlaylistListView::PermanentRemoveSelectedFile(bool permRemove)
|
PlaylistListView::RemoveSelectionToTrash()
|
||||||
{
|
{
|
||||||
BAutolock _(fPlaylist);
|
BList indices;
|
||||||
int32 index = fPlaylist->CurrentRefIndex();
|
GetSelectedItems(indices);
|
||||||
fPlaylist->SetCurrentRefIndex(index + 1);
|
fCommandStack->Perform(new (nothrow) RemovePLItemsCommand(fPlaylist,
|
||||||
fPlaylist->RemoveRefPermanent(index, permRemove);
|
(int32*)indices.Items(), indices.CountItems(), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -33,9 +33,9 @@ class PlaylistListView : public SimpleListView {
|
|||||||
virtual void KeyDown(const char* bytes, int32 numBytes);
|
virtual void KeyDown(const char* bytes, int32 numBytes);
|
||||||
|
|
||||||
// SimpleListView interface
|
// SimpleListView interface
|
||||||
virtual void MoveItems(BList& indices, int32 toIndex);
|
virtual void MoveItems(const BList& indices, int32 toIndex);
|
||||||
virtual void CopyItems(BList& indices, int32 toIndex);
|
virtual void CopyItems(const BList& indices, int32 toIndex);
|
||||||
virtual void RemoveItemList(BList& indices);
|
virtual void RemoveItemList(const BList& indices);
|
||||||
|
|
||||||
virtual void DrawListItem(BView* owner, int32 index,
|
virtual void DrawListItem(BView* owner, int32 index,
|
||||||
BRect frame) const;
|
BRect frame) const;
|
||||||
@@ -45,7 +45,7 @@ class PlaylistListView : public SimpleListView {
|
|||||||
int32 appendIndex);
|
int32 appendIndex);
|
||||||
|
|
||||||
void Randomize();
|
void Randomize();
|
||||||
void PermanentRemoveSelectedFile(bool permRemove);
|
void RemoveSelectionToTrash();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _FullSync();
|
void _FullSync();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2007-2008, Haiku. All rights reserved.
|
* Copyright 2007-2009, Haiku. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -46,18 +46,17 @@
|
|||||||
|
|
||||||
enum {
|
enum {
|
||||||
// file
|
// file
|
||||||
M_PLAYLIST_OPEN = 'open',
|
M_PLAYLIST_OPEN = 'open',
|
||||||
M_PLAYLIST_SAVE = 'save',
|
M_PLAYLIST_SAVE = 'save',
|
||||||
M_PLAYLIST_SAVE_AS = 'svas',
|
M_PLAYLIST_SAVE_AS = 'svas',
|
||||||
M_PLAYLIST_SAVE_RESULT = 'psrs',
|
M_PLAYLIST_SAVE_RESULT = 'psrs',
|
||||||
|
|
||||||
// edit
|
// edit
|
||||||
M_PLAYLIST_EMPTY = 'emty',
|
M_PLAYLIST_EMPTY = 'emty',
|
||||||
M_PLAYLIST_RANDOMIZE = 'rand',
|
M_PLAYLIST_RANDOMIZE = 'rand',
|
||||||
|
|
||||||
//
|
M_PLAYLIST_REMOVE = 'rmov',
|
||||||
M_PLAYLIST_DELETE_FILE = 'dlfi',
|
M_PLAYLIST_REMOVE_AND_PUT_INTO_TRASH = 'rmtr'
|
||||||
M_PLAYLIST_PER_DEL_FILE = 'pdfi'
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SPACE 5
|
#define SPACE 5
|
||||||
@@ -195,11 +194,11 @@ PlaylistWindow::MessageReceived(BMessage* message)
|
|||||||
case M_PLAYLIST_RANDOMIZE:
|
case M_PLAYLIST_RANDOMIZE:
|
||||||
fListView->Randomize();
|
fListView->Randomize();
|
||||||
break;
|
break;
|
||||||
case M_PLAYLIST_DELETE_FILE:
|
case M_PLAYLIST_REMOVE:
|
||||||
fListView->PermanentRemoveSelectedFile(false);
|
fListView->RemoveSelected();
|
||||||
break;
|
break;
|
||||||
case M_PLAYLIST_PER_DEL_FILE:
|
case M_PLAYLIST_REMOVE_AND_PUT_INTO_TRASH:
|
||||||
fListView->PermanentRemoveSelectedFile(true);
|
fListView->RemoveSelectionToTrash();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
BWindow::MessageReceived(message);
|
BWindow::MessageReceived(message);
|
||||||
@@ -208,35 +207,6 @@ 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 -
|
||||||
|
|
||||||
|
|
||||||
@@ -268,10 +238,10 @@ PlaylistWindow::_CreateMenu(BRect& frame)
|
|||||||
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->AddSeparatorItem();
|
||||||
editMenu->AddItem(new BMenuItem("Remove",
|
editMenu->AddItem(new BMenuItem("Remove (Del)",
|
||||||
new BMessage(M_PLAYLIST_DELETE_FILE), 'R'));
|
new BMessage(M_PLAYLIST_REMOVE)/*, B_DELETE, 0*/));
|
||||||
editMenu->AddItem(new BMenuItem("Remove Permanent",
|
editMenu->AddItem(new BMenuItem("Remove and Put into Trash",
|
||||||
new BMessage(M_PLAYLIST_PER_DEL_FILE), 'T', B_COMMAND_KEY));
|
new BMessage(M_PLAYLIST_REMOVE_AND_PUT_INTO_TRASH), 'T'));
|
||||||
editMenu->AddItem(new BMenuItem("Remove All",
|
editMenu->AddItem(new BMenuItem("Remove All",
|
||||||
new BMessage(M_PLAYLIST_EMPTY), 'N'));
|
new BMessage(M_PLAYLIST_EMPTY), 'N'));
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ 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);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2007, Haiku. All rights reserved.
|
* Copyright 2007-2009, Haiku. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -11,7 +11,12 @@
|
|||||||
#include <new>
|
#include <new>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <Alert.h>
|
||||||
#include <Autolock.h>
|
#include <Autolock.h>
|
||||||
|
#include <Directory.h>
|
||||||
|
#include <Entry.h>
|
||||||
|
#include <FindDirectory.h>
|
||||||
|
#include <Path.h>
|
||||||
|
|
||||||
#include "Playlist.h"
|
#include "Playlist.h"
|
||||||
|
|
||||||
@@ -20,12 +25,16 @@ using std::nothrow;
|
|||||||
|
|
||||||
|
|
||||||
RemovePLItemsCommand::RemovePLItemsCommand(Playlist* playlist,
|
RemovePLItemsCommand::RemovePLItemsCommand(Playlist* playlist,
|
||||||
const int32* indices, int32 count)
|
const int32* indices, int32 count, bool moveFilesToTrash)
|
||||||
: Command()
|
:
|
||||||
, fPlaylist(playlist)
|
Command(),
|
||||||
, fRefs(count > 0 ? new (nothrow) entry_ref[count] : NULL)
|
fPlaylist(playlist),
|
||||||
, fIndices(count > 0 ? new (nothrow) int32[count] : NULL)
|
fRefs(count > 0 ? new (nothrow) entry_ref[count] : NULL),
|
||||||
, fCount(count)
|
fNamesInTrash(NULL),
|
||||||
|
fIndices(count > 0 ? new (nothrow) int32[count] : NULL),
|
||||||
|
fCount(count),
|
||||||
|
fMoveFilesToTrash(moveFilesToTrash),
|
||||||
|
fMoveErrorShown(false)
|
||||||
{
|
{
|
||||||
if (!indices || !fPlaylist || !fRefs || !fIndices) {
|
if (!indices || !fPlaylist || !fRefs || !fIndices) {
|
||||||
// indicate a bad object state
|
// indicate a bad object state
|
||||||
@@ -36,6 +45,12 @@ RemovePLItemsCommand::RemovePLItemsCommand(Playlist* playlist,
|
|||||||
|
|
||||||
memcpy(fIndices, indices, fCount * sizeof(int32));
|
memcpy(fIndices, indices, fCount * sizeof(int32));
|
||||||
|
|
||||||
|
if (fMoveFilesToTrash) {
|
||||||
|
fNamesInTrash = new (nothrow) BString[count];
|
||||||
|
if (fNamesInTrash == NULL)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// init original entry indices
|
// init original entry indices
|
||||||
for (int32 i = 0; i < fCount; i++) {
|
for (int32 i = 0; i < fCount; i++) {
|
||||||
if (fPlaylist->GetRefAt(fIndices[i], &fRefs[i]) < B_OK) {
|
if (fPlaylist->GetRefAt(fIndices[i], &fRefs[i]) < B_OK) {
|
||||||
@@ -51,14 +66,17 @@ RemovePLItemsCommand::~RemovePLItemsCommand()
|
|||||||
{
|
{
|
||||||
delete[] fRefs;
|
delete[] fRefs;
|
||||||
delete[] fIndices;
|
delete[] fIndices;
|
||||||
|
delete[] fNamesInTrash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
RemovePLItemsCommand::InitCheck()
|
RemovePLItemsCommand::InitCheck()
|
||||||
{
|
{
|
||||||
if (!fPlaylist || !fRefs || !fIndices)
|
if (!fPlaylist || !fRefs || !fIndices
|
||||||
|
|| (fMoveFilesToTrash && !fNamesInTrash)) {
|
||||||
return B_NO_INIT;
|
return B_NO_INIT;
|
||||||
|
}
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,6 +99,71 @@ RemovePLItemsCommand::Perform()
|
|||||||
if (fPlaylist->CurrentRefIndex() == -1)
|
if (fPlaylist->CurrentRefIndex() == -1)
|
||||||
fPlaylist->SetCurrentRefIndex(lastRemovedIndex);
|
fPlaylist->SetCurrentRefIndex(lastRemovedIndex);
|
||||||
|
|
||||||
|
if (fMoveFilesToTrash) {
|
||||||
|
BString errorFiles;
|
||||||
|
status_t moveError = B_OK;
|
||||||
|
bool errorOnAllFiles = true;
|
||||||
|
char trashPath[B_PATH_NAME_LENGTH];
|
||||||
|
for (int32 i = 0; i < fCount; i++) {
|
||||||
|
status_t err = find_directory(B_TRASH_DIRECTORY, fRefs[i].device,
|
||||||
|
true /*create it*/, trashPath, B_PATH_NAME_LENGTH);
|
||||||
|
if (err != B_OK) {
|
||||||
|
fprintf(stderr, "failed to find Trash: %s\n", strerror(err));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
BEntry entry(&fRefs[i]);
|
||||||
|
err = entry.InitCheck();
|
||||||
|
if (err != B_OK) {
|
||||||
|
fprintf(stderr, "failed to init BEntry for %s: %s\n",
|
||||||
|
fRefs[i].name, strerror(err));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
BDirectory trashDir(trashPath);
|
||||||
|
if (err != B_OK) {
|
||||||
|
fprintf(stderr, "failed to init BDirectory for %s: %s\n",
|
||||||
|
trashPath, strerror(err));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find a unique name for the entry in the trash
|
||||||
|
fNamesInTrash[i] = fRefs[i].name;
|
||||||
|
int32 uniqueNameIndex = 1;
|
||||||
|
while (true) {
|
||||||
|
BEntry test(&trashDir, fNamesInTrash[i].String());
|
||||||
|
if (!test.Exists())
|
||||||
|
break;
|
||||||
|
fNamesInTrash[i] = fRefs[i].name;
|
||||||
|
fNamesInTrash[i] << ' ' << uniqueNameIndex;
|
||||||
|
uniqueNameIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Finally, move the entry into the trash
|
||||||
|
err = entry.MoveTo(&trashDir, fNamesInTrash[i].String());
|
||||||
|
if (err != B_OK) {
|
||||||
|
moveError = err;
|
||||||
|
if (errorFiles.Length() > 0)
|
||||||
|
errorFiles << ' ';
|
||||||
|
errorFiles << fRefs[i].name;
|
||||||
|
} else
|
||||||
|
errorOnAllFiles = false;
|
||||||
|
}
|
||||||
|
// Show an error alert if necessary
|
||||||
|
if (!fMoveErrorShown && moveError != B_OK) {
|
||||||
|
fMoveErrorShown = true;
|
||||||
|
BString message;
|
||||||
|
if (errorOnAllFiles)
|
||||||
|
message << "All ";
|
||||||
|
else
|
||||||
|
message << "Some ";
|
||||||
|
message << "files could not be moved into the Trash.\n\n";
|
||||||
|
message << "Error: " << strerror(moveError);
|
||||||
|
(new BAlert("Move Into Trash Error", message.String(),
|
||||||
|
"Ok", NULL, NULL, B_WIDTH_AS_USUAL,
|
||||||
|
B_WARNING_ALERT))->Go(NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,6 +175,51 @@ RemovePLItemsCommand::Undo()
|
|||||||
|
|
||||||
status_t ret = B_OK;
|
status_t ret = B_OK;
|
||||||
|
|
||||||
|
if (fMoveFilesToTrash) {
|
||||||
|
char trashPath[B_PATH_NAME_LENGTH];
|
||||||
|
for (int32 i = 0; i < fCount; i++) {
|
||||||
|
status_t err = find_directory(B_TRASH_DIRECTORY, fRefs[i].device,
|
||||||
|
false /*create it*/, trashPath, B_PATH_NAME_LENGTH);
|
||||||
|
if (err != B_OK) {
|
||||||
|
fprintf(stderr, "failed to find Trash: %s\n", strerror(err));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// construct the entry to the file in the trash
|
||||||
|
// TODO: BEntry(const BDirectory* directory, const char* path) is broken!
|
||||||
|
// BEntry entry(trashPath, fNamesInTrash[i].String());
|
||||||
|
BPath path(trashPath, fNamesInTrash[i].String());
|
||||||
|
BEntry entry(path.Path());
|
||||||
|
err = entry.InitCheck();
|
||||||
|
if (err != B_OK) {
|
||||||
|
fprintf(stderr, "failed to init BEntry for %s: %s\n",
|
||||||
|
fNamesInTrash[i].String(), strerror(err));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//entry.GetPath(&path);
|
||||||
|
//printf("moving '%s'\n", path.Path());
|
||||||
|
|
||||||
|
// construct the folder of the original entry_ref
|
||||||
|
node_ref nodeRef;
|
||||||
|
nodeRef.device = fRefs[i].device;
|
||||||
|
nodeRef.node = fRefs[i].directory;
|
||||||
|
BDirectory originalDir(&nodeRef);
|
||||||
|
|
||||||
|
if (err != B_OK) {
|
||||||
|
fprintf(stderr, "failed to init original BDirectory for "
|
||||||
|
"%s: %s\n", fRefs[i].name, strerror(err));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//path.SetTo(&originalDir, fRefs[i].name);
|
||||||
|
//printf("as '%s'\n", path.Path());
|
||||||
|
|
||||||
|
// Finally, move the entry back into the original folder
|
||||||
|
err = entry.MoveTo(&originalDir, fRefs[i].name);
|
||||||
|
if (err != B_OK)
|
||||||
|
ret = err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// remember currently playling ref in case we move it
|
// remember currently playling ref in case we move it
|
||||||
entry_ref currentRef;
|
entry_ref currentRef;
|
||||||
bool adjustCurrentRef = fPlaylist->GetRefAt(fPlaylist->CurrentRefIndex(),
|
bool adjustCurrentRef = fPlaylist->GetRefAt(fPlaylist->CurrentRefIndex(),
|
||||||
@@ -122,4 +250,7 @@ RemovePLItemsCommand::GetName(BString& name)
|
|||||||
name << "Remove Entries";
|
name << "Remove Entries";
|
||||||
else
|
else
|
||||||
name << "Remove Entry";
|
name << "Remove Entry";
|
||||||
|
|
||||||
|
if (fMoveFilesToTrash)
|
||||||
|
name << " into Trash";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2007, Haiku. All rights reserved.
|
* Copyright 2007-2009, Haiku. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -11,15 +11,16 @@
|
|||||||
|
|
||||||
#include "Command.h"
|
#include "Command.h"
|
||||||
|
|
||||||
class Playlist;
|
|
||||||
struct entry_ref;
|
struct entry_ref;
|
||||||
|
class Playlist;
|
||||||
|
|
||||||
class RemovePLItemsCommand : public Command {
|
class RemovePLItemsCommand : public Command {
|
||||||
public:
|
public:
|
||||||
RemovePLItemsCommand(
|
RemovePLItemsCommand(
|
||||||
Playlist* playlist,
|
Playlist* playlist,
|
||||||
const int32* indices,
|
const int32* indices,
|
||||||
int32 count);
|
int32 count,
|
||||||
|
bool moveFilesToTrash = false);
|
||||||
virtual ~RemovePLItemsCommand();
|
virtual ~RemovePLItemsCommand();
|
||||||
|
|
||||||
virtual status_t InitCheck();
|
virtual status_t InitCheck();
|
||||||
@@ -32,8 +33,11 @@ class RemovePLItemsCommand : public Command {
|
|||||||
private:
|
private:
|
||||||
Playlist* fPlaylist;
|
Playlist* fPlaylist;
|
||||||
entry_ref* fRefs;
|
entry_ref* fRefs;
|
||||||
|
BString* fNamesInTrash;
|
||||||
int32* fIndices;
|
int32* fIndices;
|
||||||
int32 fCount;
|
int32 fCount;
|
||||||
|
bool fMoveFilesToTrash;
|
||||||
|
bool fMoveErrorShown;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // REMOVE_PL_ITEMS_COMMAND_H
|
#endif // REMOVE_PL_ITEMS_COMMAND_H
|
||||||
|
|||||||
Reference in New Issue
Block a user