|
|
@@ -36,7 +36,7 @@ int32
|
|
|
|
MMediaFilesManager::ReadPascalString(BFile &file, char **str)
|
|
|
|
MMediaFilesManager::ReadPascalString(BFile &file, char **str)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint32 len;
|
|
|
|
uint32 len;
|
|
|
|
*str=NULL;
|
|
|
|
*str = NULL;
|
|
|
|
if (file.Read(&len, 4) < 4)
|
|
|
|
if (file.Read(&len, 4) < 4)
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
if (len == 0)
|
|
|
|
if (len == 0)
|
|
|
@@ -55,7 +55,7 @@ int32
|
|
|
|
MMediaFilesManager::WritePascalString(BFile &file, const char *str)
|
|
|
|
MMediaFilesManager::WritePascalString(BFile &file, const char *str)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
if(str == NULL)
|
|
|
|
if (str == NULL)
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
uint32 len = strlen(str) + 1;
|
|
|
|
uint32 len = strlen(str) + 1;
|
|
|
|
if (file.Write(&len, 4) < 4)
|
|
|
|
if (file.Write(&len, 4) < 4)
|
|
|
@@ -76,7 +76,7 @@ MMediaFilesManager::LoadState()
|
|
|
|
CALLED();
|
|
|
|
CALLED();
|
|
|
|
status_t err = B_OK;
|
|
|
|
status_t err = B_OK;
|
|
|
|
BPath path;
|
|
|
|
BPath path;
|
|
|
|
if((err = find_directory(B_USER_SETTINGS_DIRECTORY, &path))!=B_OK)
|
|
|
|
if ((err = find_directory(B_USER_SETTINGS_DIRECTORY, &path)) != B_OK)
|
|
|
|
return err;
|
|
|
|
return err;
|
|
|
|
|
|
|
|
|
|
|
|
path.Append("Media/MMediaFilesManager");
|
|
|
|
path.Append("Media/MMediaFilesManager");
|
|
|
@@ -121,9 +121,9 @@ MMediaFilesManager::LoadState()
|
|
|
|
//TRACE(" %s: %s, volume: %f\n", key, val, *(float *)&vol);
|
|
|
|
//TRACE(" %s: %s, volume: %f\n", key, val, *(float *)&vol);
|
|
|
|
|
|
|
|
|
|
|
|
entry_ref ref;
|
|
|
|
entry_ref ref;
|
|
|
|
if(len>1) {
|
|
|
|
if (len > 1) {
|
|
|
|
BEntry entry(val);
|
|
|
|
BEntry entry(val);
|
|
|
|
if(entry.Exists())
|
|
|
|
if (entry.Exists())
|
|
|
|
entry.GetRef(&ref);
|
|
|
|
entry.GetRef(&ref);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SetRefFor(str, key, ref, false);
|
|
|
|
SetRefFor(str, key, ref, false);
|
|
|
@@ -145,7 +145,7 @@ MMediaFilesManager::SaveState()
|
|
|
|
CALLED();
|
|
|
|
CALLED();
|
|
|
|
status_t err = B_OK;
|
|
|
|
status_t err = B_OK;
|
|
|
|
BPath path;
|
|
|
|
BPath path;
|
|
|
|
if((err = find_directory(B_USER_SETTINGS_DIRECTORY, &path))!=B_OK)
|
|
|
|
if ((err = find_directory(B_USER_SETTINGS_DIRECTORY, &path)) != B_OK)
|
|
|
|
return err;
|
|
|
|
return err;
|
|
|
|
|
|
|
|
|
|
|
|
path.Append("Media/MMediaFilesManager");
|
|
|
|
path.Append("Media/MMediaFilesManager");
|
|
|
@@ -159,11 +159,11 @@ MMediaFilesManager::SaveState()
|
|
|
|
if (file.Write(&category_count, sizeof(uint32)) < (int32)sizeof(uint32))
|
|
|
|
if (file.Write(&category_count, sizeof(uint32)) < (int32)sizeof(uint32))
|
|
|
|
return B_ERROR;
|
|
|
|
return B_ERROR;
|
|
|
|
|
|
|
|
|
|
|
|
BString *type;
|
|
|
|
BString *type = NULL;
|
|
|
|
Map<BString, entry_ref> *map;
|
|
|
|
Map<BString, entry_ref> *map;
|
|
|
|
BString *item;
|
|
|
|
BString *item = NULL;
|
|
|
|
entry_ref *ref;
|
|
|
|
entry_ref *ref;
|
|
|
|
for (fRegistryMap->Rewind(); fRegistryMap->GetNext(&map); ) {
|
|
|
|
for (fRegistryMap->Rewind(); fRegistryMap->GetNext(&map);) {
|
|
|
|
fRegistryMap->GetCurrentKey(&type);
|
|
|
|
fRegistryMap->GetCurrentKey(&type);
|
|
|
|
|
|
|
|
|
|
|
|
WritePascalString(file, type->String());
|
|
|
|
WritePascalString(file, type->String());
|
|
|
@@ -194,11 +194,11 @@ MMediaFilesManager::Dump()
|
|
|
|
/* for each type, the registry map contains a map of item/entry_ref
|
|
|
|
/* for each type, the registry map contains a map of item/entry_ref
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
printf("MMediaFilesManager: registry map follows\n");
|
|
|
|
printf("MMediaFilesManager: registry map follows\n");
|
|
|
|
BString *type;
|
|
|
|
BString *type = NULL;
|
|
|
|
Map<BString, entry_ref> *map;
|
|
|
|
Map<BString, entry_ref> *map;
|
|
|
|
BString *item;
|
|
|
|
BString *item = NULL;
|
|
|
|
entry_ref *ref;
|
|
|
|
entry_ref *ref;
|
|
|
|
for (fRegistryMap->Rewind(); fRegistryMap->GetNext(&map); ) {
|
|
|
|
for (fRegistryMap->Rewind(); fRegistryMap->GetNext(&map);) {
|
|
|
|
fRegistryMap->GetCurrentKey(&type);
|
|
|
|
fRegistryMap->GetCurrentKey(&type);
|
|
|
|
|
|
|
|
|
|
|
|
for (map->Rewind(); map->GetNext(&ref);) {
|
|
|
|
for (map->Rewind(); map->GetNext(&ref);) {
|
|
|
@@ -218,17 +218,17 @@ status_t
|
|
|
|
MMediaFilesManager::RewindTypes(BString ***types, int32 *count)
|
|
|
|
MMediaFilesManager::RewindTypes(BString ***types, int32 *count)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
CALLED();
|
|
|
|
CALLED();
|
|
|
|
if(types==NULL || count == NULL)
|
|
|
|
if (types == NULL || count == NULL)
|
|
|
|
return B_BAD_VALUE;
|
|
|
|
return B_BAD_VALUE;
|
|
|
|
|
|
|
|
|
|
|
|
Map<BString, entry_ref> *map;
|
|
|
|
Map<BString, entry_ref> *map;
|
|
|
|
BString *type;
|
|
|
|
BString *type = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
*count = fRegistryMap->CountItems();
|
|
|
|
*count = fRegistryMap->CountItems();
|
|
|
|
*types = new BString*[*count];
|
|
|
|
*types = new BString*[*count];
|
|
|
|
int32 i=0;
|
|
|
|
int32 i = 0;
|
|
|
|
|
|
|
|
|
|
|
|
for (fRegistryMap->Rewind(); i<*count && fRegistryMap->GetNext(&map); i++) {
|
|
|
|
for (fRegistryMap->Rewind(); i < *count && fRegistryMap->GetNext(&map); i++) {
|
|
|
|
fRegistryMap->GetCurrentKey(&type);
|
|
|
|
fRegistryMap->GetCurrentKey(&type);
|
|
|
|
(*types)[i] = type;
|
|
|
|
(*types)[i] = type;
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -241,12 +241,12 @@ status_t
|
|
|
|
MMediaFilesManager::RewindRefs(const char* type, BString ***items, int32 *count)
|
|
|
|
MMediaFilesManager::RewindRefs(const char* type, BString ***items, int32 *count)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
CALLED();
|
|
|
|
CALLED();
|
|
|
|
if(type == NULL || items==NULL || count == NULL)
|
|
|
|
if (type == NULL || items == NULL || count == NULL)
|
|
|
|
return B_BAD_VALUE;
|
|
|
|
return B_BAD_VALUE;
|
|
|
|
|
|
|
|
|
|
|
|
Map<BString, entry_ref> *map;
|
|
|
|
Map<BString, entry_ref> *map = NULL;
|
|
|
|
entry_ref *ref;
|
|
|
|
entry_ref *ref;
|
|
|
|
BString *item;
|
|
|
|
BString *item = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
*count = 0;
|
|
|
|
*count = 0;
|
|
|
|
*items = NULL;
|
|
|
|
*items = NULL;
|
|
|
@@ -256,9 +256,9 @@ MMediaFilesManager::RewindRefs(const char* type, BString ***items, int32 *count)
|
|
|
|
|
|
|
|
|
|
|
|
*count = map->CountItems();
|
|
|
|
*count = map->CountItems();
|
|
|
|
*items = new BString*[*count];
|
|
|
|
*items = new BString*[*count];
|
|
|
|
int32 i=0;
|
|
|
|
int32 i = 0;
|
|
|
|
|
|
|
|
|
|
|
|
for (map->Rewind(); i<*count && map->GetNext(&ref); i++) {
|
|
|
|
for (map->Rewind(); i < *count && map->GetNext(&ref); i++) {
|
|
|
|
map->GetCurrentKey(&item);
|
|
|
|
map->GetCurrentKey(&item);
|
|
|
|
(*items)[i] = item;
|
|
|
|
(*items)[i] = item;
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -273,11 +273,11 @@ MMediaFilesManager::GetRefFor(const char *type,
|
|
|
|
entry_ref **out_ref)
|
|
|
|
entry_ref **out_ref)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
CALLED();
|
|
|
|
CALLED();
|
|
|
|
Map <BString, entry_ref> *map;
|
|
|
|
Map <BString, entry_ref> *map = NULL;
|
|
|
|
if(!fRegistryMap->Get(BString(type), &map))
|
|
|
|
if (!fRegistryMap->Get(BString(type), &map))
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
|
|
|
|
|
|
|
|
|
|
|
if(!map->Get(BString(item), out_ref))
|
|
|
|
if (!map->Get(BString(item), out_ref))
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
|
|
|
|
|
|
|
|
|
|
|
return B_OK;
|
|
|
|
return B_OK;
|
|
|
@@ -296,16 +296,16 @@ MMediaFilesManager::SetRefFor(const char *type,
|
|
|
|
itemString.Truncate(B_MEDIA_NAME_LENGTH);
|
|
|
|
itemString.Truncate(B_MEDIA_NAME_LENGTH);
|
|
|
|
BString typeString(type);
|
|
|
|
BString typeString(type);
|
|
|
|
Map <BString, entry_ref> *map;
|
|
|
|
Map <BString, entry_ref> *map;
|
|
|
|
if(!fRegistryMap->Get(typeString, &map)) {
|
|
|
|
if (!fRegistryMap->Get(typeString, &map)) {
|
|
|
|
map = new Map<BString, entry_ref>;
|
|
|
|
map = new Map<BString, entry_ref>;
|
|
|
|
fRegistryMap->Insert(typeString, *map);
|
|
|
|
fRegistryMap->Insert(typeString, *map);
|
|
|
|
fRegistryMap->Get(typeString, &map);
|
|
|
|
fRegistryMap->Get(typeString, &map);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(map->Has(itemString))
|
|
|
|
if (map->Has(itemString))
|
|
|
|
map->Remove(itemString);
|
|
|
|
map->Remove(itemString);
|
|
|
|
map->Insert(itemString, ref);
|
|
|
|
map->Insert(itemString, ref);
|
|
|
|
if(save)
|
|
|
|
if (save)
|
|
|
|
LaunchTimer();
|
|
|
|
LaunchTimer();
|
|
|
|
|
|
|
|
|
|
|
|
return B_OK;
|
|
|
|
return B_OK;
|
|
|
@@ -321,7 +321,7 @@ MMediaFilesManager::RemoveRefFor(const char *type,
|
|
|
|
BString itemString(item);
|
|
|
|
BString itemString(item);
|
|
|
|
BString typeString(type);
|
|
|
|
BString typeString(type);
|
|
|
|
Map <BString, entry_ref> *map;
|
|
|
|
Map <BString, entry_ref> *map;
|
|
|
|
if(fRegistryMap->Get(typeString, &map)) {
|
|
|
|
if (fRegistryMap->Get(typeString, &map)) {
|
|
|
|
map->Remove(itemString);
|
|
|
|
map->Remove(itemString);
|
|
|
|
map->Insert(itemString, *(new entry_ref));
|
|
|
|
map->Insert(itemString, *(new entry_ref));
|
|
|
|
LaunchTimer();
|
|
|
|
LaunchTimer();
|
|
|
@@ -338,7 +338,7 @@ MMediaFilesManager::RemoveItem(const char *type,
|
|
|
|
BString itemString(item);
|
|
|
|
BString itemString(item);
|
|
|
|
BString typeString(type);
|
|
|
|
BString typeString(type);
|
|
|
|
Map <BString, entry_ref> *map;
|
|
|
|
Map <BString, entry_ref> *map;
|
|
|
|
if(fRegistryMap->Get(typeString, &map)) {
|
|
|
|
if (fRegistryMap->Get(typeString, &map)) {
|
|
|
|
map->Remove(itemString);
|
|
|
|
map->Remove(itemString);
|
|
|
|
LaunchTimer();
|
|
|
|
LaunchTimer();
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -349,9 +349,9 @@ MMediaFilesManager::RemoveItem(const char *type,
|
|
|
|
void
|
|
|
|
void
|
|
|
|
MMediaFilesManager::LaunchTimer()
|
|
|
|
MMediaFilesManager::LaunchTimer()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(!fRunner)
|
|
|
|
if (!fRunner)
|
|
|
|
fRunner = new BMessageRunner(be_app,
|
|
|
|
fRunner = new BMessageRunner(be_app,
|
|
|
|
new BMessage(MMEDIAFILESMANAGER_SAVE_TIMER), 3 * 1000000, 1);
|
|
|
|
new BMessage(MMEDIAFILESMANAGER_SAVE_TIMER), 3 * 1000000LL, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|