From 7992eb9f4b3b0b6f18e0bab1246c0e602f06dffe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Fri, 11 Jul 2008 14:13:10 +0000 Subject: [PATCH] Added methods for (un)archiving. (yet unused and untested.) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26380 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/mediaplayer/playlist/Playlist.cpp | 61 ++++++++++++++++++++-- src/apps/mediaplayer/playlist/Playlist.h | 14 +++-- 2 files changed, 66 insertions(+), 9 deletions(-) diff --git a/src/apps/mediaplayer/playlist/Playlist.cpp b/src/apps/mediaplayer/playlist/Playlist.cpp index 67aa8671f6..071739cb3e 100644 --- a/src/apps/mediaplayer/playlist/Playlist.cpp +++ b/src/apps/mediaplayer/playlist/Playlist.cpp @@ -24,15 +24,15 @@ #include #include #include -#include -#include -#include -#include #include #include +#include #include +#include +#include #include +#include #include "FileReadWrite.h" @@ -68,6 +68,59 @@ Playlist::~Playlist() } +// #pragma mark - archiving + + +static const char* kPathKey = "path"; + + +status_t +Playlist::UnArchive(const BMessage* archive) +{ + if (archive == NULL) + return B_BAD_VALUE; + + MakeEmpty(); + + BString path; + for (int32 i = 0; archive->FindString(kPathKey, i, &path) == B_OK; i++) { + BEntry entry(path.String(), false); + // don't follow links, we want to do that when opening files only + entry_ref ref; + if (entry.GetRef(&ref) != B_OK) + continue; + if (!AddRef(ref)) + return B_NO_MEMORY; + } + + return B_OK; +} + + +status_t +Playlist::Archive(BMessage* into) const +{ + if (into == NULL) + return B_BAD_VALUE; + + int32 count = fRefs.CountItems(); + for (int32 i = 0; i < count; i++) { + const entry_ref* ref = (entry_ref*)fRefs.ItemAtFast(i); + BPath path(ref); + if (path.InitCheck() != B_OK) + continue; + status_t ret = into->AddString(kPathKey, path.Path()); + if (ret != B_OK) + return ret; + } + + return B_OK; +} + + +// #pragma mark - list access + + void Playlist::MakeEmpty() { diff --git a/src/apps/mediaplayer/playlist/Playlist.h b/src/apps/mediaplayer/playlist/Playlist.h index b8962651c2..4cfb0b5233 100644 --- a/src/apps/mediaplayer/playlist/Playlist.h +++ b/src/apps/mediaplayer/playlist/Playlist.h @@ -48,25 +48,29 @@ public: public: Playlist(); ~Playlist(); - + // archiving + status_t UnArchive(const BMessage* archive); + status_t Archive(BMessage* into) const; + + // list functionality void MakeEmpty(); int32 CountItems() const; void Sort(); - + bool AddRef(const entry_ref& ref); bool AddRef(const entry_ref& ref, int32 index); entry_ref RemoveRef(int32 index, bool careAboutCurrentIndex = true); - + bool AdoptPlaylist(Playlist& other); bool AdoptPlaylist(Playlist& other, int32 index); - + int32 IndexOf(const entry_ref& ref) const; status_t GetRefAt(int32 index, entry_ref* ref) const; // bool HasRef(const entry_ref& ref) const; - + // navigating current ref void SetCurrentRefIndex(int32 index); int32 CurrentRefIndex() const;