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:
parent
09a4122e4c
commit
a637e3c53c
@ -3,6 +3,7 @@
|
||||
*
|
||||
* Copyright (C) 2006 Marcus Overhagen <marcus@overhagen.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
|
||||
* 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) 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
|
||||
* 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) 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
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@ -23,7 +24,10 @@
|
||||
#include <debugger.h>
|
||||
#include <new.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <String.h>
|
||||
#include <NodeInfo.h>
|
||||
#include <File.h>
|
||||
#include <Mime.h>
|
||||
|
||||
#include <Autolock.h>
|
||||
#include <Directory.h>
|
||||
@ -276,8 +280,8 @@ Playlist::AppendRefs(const BMessage* refsReceivedMessage, int32 appendIndex)
|
||||
Playlist* playlist = add ? &temporaryPlaylist : this;
|
||||
|
||||
entry_ref ref;
|
||||
for (int i = 0; refsReceivedMessage->FindRef("refs", i, &ref) == B_OK; i++)
|
||||
AppendToPlaylistRecursive(ref, playlist);
|
||||
for (int i = 0; refsReceivedMessage->FindRef("refs", i, &ref) == B_OK; i++)
|
||||
AppendToPlaylistRecursive(ref, playlist);
|
||||
|
||||
playlist->Sort();
|
||||
|
||||
@ -309,7 +313,13 @@ Playlist::AppendToPlaylistRecursive(const entry_ref& ref, Playlist* playlist)
|
||||
while (dir.GetNextRef(&subRef) == B_OK)
|
||||
AppendToPlaylistRecursive(subRef, playlist);
|
||||
} 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
|
||||
Playlist::_NotifyRefAdded(const entry_ref& ref, int32 index) const
|
||||
{
|
||||
|
@ -75,7 +75,7 @@ public:
|
||||
bool AddListener(Listener* listener);
|
||||
void RemoveListener(Listener* listener);
|
||||
|
||||
// support functions
|
||||
// support functions
|
||||
void AppendRefs(const BMessage* refsReceivedMessage,
|
||||
int32 appendIndex = -1);
|
||||
static void AppendToPlaylistRecursive(const entry_ref& ref,
|
||||
@ -83,6 +83,9 @@ public:
|
||||
|
||||
private:
|
||||
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,
|
||||
int32 index) const;
|
||||
|
Loading…
Reference in New Issue
Block a user