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
This commit is contained in:
Stephan Aßmus 2008-07-11 14:13:10 +00:00
parent ea1b25f5d1
commit 7992eb9f4b
2 changed files with 66 additions and 9 deletions

View File

@ -24,15 +24,15 @@
#include <debugger.h> #include <debugger.h>
#include <new.h> #include <new.h>
#include <stdio.h> #include <stdio.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>
#include <File.h>
#include <Message.h> #include <Message.h>
#include <Mime.h>
#include <NodeInfo.h>
#include <Path.h> #include <Path.h>
#include <String.h>
#include "FileReadWrite.h" #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 void
Playlist::MakeEmpty() Playlist::MakeEmpty()
{ {

View File

@ -48,25 +48,29 @@ public:
public: public:
Playlist(); Playlist();
~Playlist(); ~Playlist();
// archiving
status_t UnArchive(const BMessage* archive);
status_t Archive(BMessage* into) const;
// list functionality // list functionality
void MakeEmpty(); void MakeEmpty();
int32 CountItems() const; int32 CountItems() const;
void Sort(); void Sort();
bool AddRef(const entry_ref& ref); bool AddRef(const entry_ref& ref);
bool AddRef(const entry_ref& ref, int32 index); bool AddRef(const entry_ref& ref, int32 index);
entry_ref RemoveRef(int32 index, entry_ref RemoveRef(int32 index,
bool careAboutCurrentIndex = true); bool careAboutCurrentIndex = true);
bool AdoptPlaylist(Playlist& other); bool AdoptPlaylist(Playlist& other);
bool AdoptPlaylist(Playlist& other, int32 index); bool AdoptPlaylist(Playlist& other, int32 index);
int32 IndexOf(const entry_ref& ref) const; int32 IndexOf(const entry_ref& ref) const;
status_t GetRefAt(int32 index, entry_ref* ref) const; status_t GetRefAt(int32 index, entry_ref* ref) const;
// bool HasRef(const entry_ref& ref) const; // bool HasRef(const entry_ref& ref) const;
// navigating current ref // navigating current ref
void SetCurrentRefIndex(int32 index); void SetCurrentRefIndex(int32 index);
int32 CurrentRefIndex() const; int32 CurrentRefIndex() const;