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,6 +48,10 @@ 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();