Added optional DataSource::GetName() to get a name for the data source.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30410 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2009-04-25 20:49:34 +00:00
parent 37ea725498
commit 602a9fe54d
2 changed files with 47 additions and 0 deletions

View File

@ -7,6 +7,8 @@
#include <new>
#include <String.h>
// #pragma mark - DataSource
@ -21,6 +23,13 @@ DataSource::~DataSource()
}
status_t
DataSource::GetName(BString& name)
{
return B_UNSUPPORTED;
}
// #pragma mark - FileDataSource
@ -53,6 +62,17 @@ PathDataSource::Init(const char* path)
}
status_t
PathDataSource::GetName(BString& name)
{
if (fPath.Path() == NULL)
return B_NO_INIT;
name = fPath.Path();
return B_OK;
}
status_t
PathDataSource::OpenFile(BFile& file)
{
@ -77,6 +97,24 @@ EntryRefDataSource::Init(const entry_ref* ref)
}
status_t
EntryRefDataSource::GetName(BString& name)
{
BEntry entry;
status_t error = entry.SetTo(&fRef);
if (error != B_OK)
return error;
BPath path;
error = entry.GetPath(&path);
if (error != B_OK)
return error;
name = path.Path();
return B_OK;
}
status_t
EntryRefDataSource::OpenFile(BFile& file)
{

View File

@ -10,12 +10,17 @@
#include <Path.h>
struct BString;
class DataSource {
public:
DataSource();
virtual ~DataSource();
virtual status_t CreateDataIO(BDataIO** _io) = 0;
virtual status_t GetName(BString& name);
};
@ -32,6 +37,8 @@ class PathDataSource : public FileDataSource {
public:
status_t Init(const char* path);
virtual status_t GetName(BString& name);
protected:
virtual status_t OpenFile(BFile& file);
@ -44,6 +51,8 @@ class EntryRefDataSource : public FileDataSource {
public:
status_t Init(const entry_ref* ref);
virtual status_t GetName(BString& name);
protected:
virtual status_t OpenFile(BFile& file);