patch by Fredrik Modéen:
* add filtering of files by mimetype when adding them to the playlist * some changes by myself (added Axel's suggestion to guess the mimetype in order to support other filesystems than BFS) Fredrik -> please have a look at our coding guidelines, also you have weird whitespaces in your patches... :-) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22662 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -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) 2007 Fredrik Modéen <[email protected]>
|
||||||
*
|
*
|
||||||
* 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
|
||||||
|
|||||||
@@ -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) 2007 Fredrik Modéen <[email protected]>
|
||||||
*
|
*
|
||||||
* 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
|
||||||
|
|||||||
@@ -3,6 +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) 2007 Fredrik Modéen <fredrik@modeen.se>
|
||||||
*
|
*
|
||||||
* 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
|
||||||
@@ -23,7 +24,10 @@
|
|||||||
#include <debugger.h>
|
#include <debugger.h>
|
||||||
#include <new.h>
|
#include <new.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <String.h>
|
||||||
|
#include <NodeInfo.h>
|
||||||
|
#include <File.h>
|
||||||
|
#include <Mime.h>
|
||||||
|
|
||||||
#include <Autolock.h>
|
#include <Autolock.h>
|
||||||
#include <Directory.h>
|
#include <Directory.h>
|
||||||
@@ -276,8 +280,8 @@ Playlist::AppendRefs(const BMessage* refsReceivedMessage, int32 appendIndex)
|
|||||||
Playlist* playlist = add ? &temporaryPlaylist : this;
|
Playlist* playlist = add ? &temporaryPlaylist : this;
|
||||||
|
|
||||||
entry_ref ref;
|
entry_ref ref;
|
||||||
for (int i = 0; refsReceivedMessage->FindRef("refs", i, &ref) == B_OK; i++)
|
for (int i = 0; refsReceivedMessage->FindRef("refs", i, &ref) == B_OK; i++)
|
||||||
AppendToPlaylistRecursive(ref, playlist);
|
AppendToPlaylistRecursive(ref, playlist);
|
||||||
|
|
||||||
playlist->Sort();
|
playlist->Sort();
|
||||||
|
|
||||||
@@ -309,7 +313,13 @@ Playlist::AppendToPlaylistRecursive(const entry_ref& ref, Playlist* playlist)
|
|||||||
while (dir.GetNextRef(&subRef) == B_OK)
|
while (dir.GetNextRef(&subRef) == B_OK)
|
||||||
AppendToPlaylistRecursive(subRef, playlist);
|
AppendToPlaylistRecursive(subRef, playlist);
|
||||||
} else if (entry.IsFile()) {
|
} else if (entry.IsFile()) {
|
||||||
playlist->AddRef(ref);
|
BString mimeString = _MIMEString(&ref);
|
||||||
|
if (_IsMediaFile(mimeString))
|
||||||
|
playlist->AddRef(ref);
|
||||||
|
else if (_IsPlaylist(mimeString)) {
|
||||||
|
printf("Playlist::AppendToPlaylistRecursive() - "
|
||||||
|
"TODO: implement playlist file loading\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -332,6 +342,47 @@ Playlist::playlist_cmp(const void *p1, const void *p2)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*static*/ bool
|
||||||
|
Playlist::_IsMediaFile(const BString& mimeString)
|
||||||
|
{
|
||||||
|
BMimeType superType;
|
||||||
|
BMimeType fileType(mimeString.String());
|
||||||
|
|
||||||
|
if (fileType.GetSupertype(&superType) != B_OK)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// TODO: some media files have other super types, I think
|
||||||
|
// for example ASF has "application" super type... so it would
|
||||||
|
// need special handling
|
||||||
|
return (superType == "audio" || superType == "video");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*static*/ bool
|
||||||
|
Playlist::_IsPlaylist(const BString& mimeString)
|
||||||
|
{
|
||||||
|
return mimeString.Compare("text/x-playlist") == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*static*/ BString
|
||||||
|
Playlist::_MIMEString(const entry_ref* ref)
|
||||||
|
{
|
||||||
|
BFile file(ref, B_READ_ONLY);
|
||||||
|
BNodeInfo nodeInfo(&file);
|
||||||
|
char mimeString[B_MIME_TYPE_LENGTH];
|
||||||
|
if (nodeInfo.GetType(mimeString) != B_OK) {
|
||||||
|
BMimeType type;
|
||||||
|
if (BMimeType::GuessMimeType(ref, &type) != B_OK)
|
||||||
|
return BString();
|
||||||
|
|
||||||
|
strlcpy(mimeString, type.Type(), B_MIME_TYPE_LENGTH);
|
||||||
|
nodeInfo.SetType(type.Type());
|
||||||
|
}
|
||||||
|
return BString(mimeString);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Playlist::_NotifyRefAdded(const entry_ref& ref, int32 index) const
|
Playlist::_NotifyRefAdded(const entry_ref& ref, int32 index) const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ public:
|
|||||||
bool AddListener(Listener* listener);
|
bool AddListener(Listener* listener);
|
||||||
void RemoveListener(Listener* listener);
|
void RemoveListener(Listener* listener);
|
||||||
|
|
||||||
// support functions
|
// support functions
|
||||||
void AppendRefs(const BMessage* refsReceivedMessage,
|
void AppendRefs(const BMessage* refsReceivedMessage,
|
||||||
int32 appendIndex = -1);
|
int32 appendIndex = -1);
|
||||||
static void AppendToPlaylistRecursive(const entry_ref& ref,
|
static void AppendToPlaylistRecursive(const entry_ref& ref,
|
||||||
@@ -83,6 +83,9 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
static int playlist_cmp(const void* p1, const void* p2);
|
static int playlist_cmp(const void* p1, const void* p2);
|
||||||
|
static bool _IsMediaFile(const BString& mimeString);
|
||||||
|
static bool _IsPlaylist(const BString& mimeString);
|
||||||
|
static BString _MIMEString(const entry_ref* entry);
|
||||||
|
|
||||||
void _NotifyRefAdded(const entry_ref& ref,
|
void _NotifyRefAdded(const entry_ref& ref,
|
||||||
int32 index) const;
|
int32 index) const;
|
||||||
|
|||||||
Reference in New Issue
Block a user