From a637e3c53c976ebe3d2c7d1fe8792a1eaf1aae3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Mon, 22 Oct 2007 14:44:38 +0000 Subject: [PATCH] =?UTF-8?q?patch=20by=20Fredrik=20Mod=C3=A9en:=20*=20add?= =?UTF-8?q?=20filtering=20of=20files=20by=20mimetype=20when=20adding=20the?= =?UTF-8?q?m=20to=20the=20playlist=20*=20some=20changes=20by=20myself=20(a?= =?UTF-8?q?dded=20Axel's=20suggestion=20to=20guess=20the=20mimetype=20=20?= =?UTF-8?q?=20in=20order=20to=20support=20other=20filesystems=20than=20BFS?= =?UTF-8?q?)=20Fredrik=20->=20please=20have=20a=20look=20at=20our=20coding?= =?UTF-8?q?=20guidelines,=20also=20you=20have=20weird=20whitespaces=20in?= =?UTF-8?q?=20your=20patches...=20:-)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22662 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/mediaplayer/Controller.cpp | 1 + src/apps/mediaplayer/MainWin.cpp | 1 + src/apps/mediaplayer/playlist/Playlist.cpp | 59 ++++++++++++++++++++-- src/apps/mediaplayer/playlist/Playlist.h | 5 +- 4 files changed, 61 insertions(+), 5 deletions(-) diff --git a/src/apps/mediaplayer/Controller.cpp b/src/apps/mediaplayer/Controller.cpp index 9ade6e95c0..968ad7cf02 100644 --- a/src/apps/mediaplayer/Controller.cpp +++ b/src/apps/mediaplayer/Controller.cpp @@ -3,6 +3,7 @@ * * Copyright (C) 2006 Marcus Overhagen * Copyright (C) 2007 Stephan Aßmus + * Copyright (C) 2007 Fredrik Modéen * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/apps/mediaplayer/MainWin.cpp b/src/apps/mediaplayer/MainWin.cpp index d5c1f6a6d5..110b90f4c9 100644 --- a/src/apps/mediaplayer/MainWin.cpp +++ b/src/apps/mediaplayer/MainWin.cpp @@ -3,6 +3,7 @@ * * Copyright (C) 2006 Marcus Overhagen * Copyright (C) 2007 Stephan Aßmus + * Copyright (C) 2007 Fredrik Modéen * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/apps/mediaplayer/playlist/Playlist.cpp b/src/apps/mediaplayer/playlist/Playlist.cpp index 2e59f6fe02..2fe74fe03c 100644 --- a/src/apps/mediaplayer/playlist/Playlist.cpp +++ b/src/apps/mediaplayer/playlist/Playlist.cpp @@ -3,6 +3,7 @@ * * Copyright (C) 2006 Marcus Overhagen * Copyright (C) 2007 Stephan Aßmus + * Copyright (C) 2007 Fredrik Modéen * * 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 #include #include -#include +#include +#include +#include +#include #include #include @@ -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 { diff --git a/src/apps/mediaplayer/playlist/Playlist.h b/src/apps/mediaplayer/playlist/Playlist.h index f187e9122b..bf575df8e3 100644 --- a/src/apps/mediaplayer/playlist/Playlist.h +++ b/src/apps/mediaplayer/playlist/Playlist.h @@ -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;