* return invalid BFile on cancellation for backwards compatibility with

BeOS R5.
* style changes.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21771 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Pfeiffer 2007-07-31 16:40:15 +00:00
parent 66486a1b7d
commit 3177724f8c

View File

@ -36,90 +36,78 @@
#include "FileSelector.h"
static BList * g_files_list = NULL;
static uint32 g_nb_files = 0;
static BList * gFiles = NULL;
status_t AddFile(BFile * file);
status_t RemoveFile();
static const int32 kStatusOk = 'okok';
static const int32 kStatusCancel = 'canc';
extern "C" _EXPORT void exit_transport()
{
printf("exit_transport\n");
RemoveFile();
}
extern "C" _EXPORT BDataIO * init_transport
(
BMessage * msg
)
extern "C" _EXPORT BDataIO * init_transport(BMessage * msg)
{
BFile * file;
FileSelector * selector;
FileSelector * selector = new FileSelector();
entry_ref ref;
printf("init_transport\n");
selector = new FileSelector();
if (selector->Go(&ref) != B_OK)
return NULL;
file = new BFile(&ref, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
if ( file->InitCheck() != B_OK ) {
if (selector->Go(&ref) != B_OK) {
// dialog cancelled
if (msg)
msg->what = 'canc'; // Indicates user cancel the panel...
delete file;
return NULL;
};
msg->what = kStatusCancel;
// for backwards compatibility with BeOS R5 return an invalid BFile
BFile *file = new BFile();
AddFile(file);
return file;
}
BPath path;
path.SetTo(&ref);
BFile *file = new BFile(&ref, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
if ( file->InitCheck() != B_OK ) {
// invalid file selected
if (msg)
msg->what = kStatusCancel;
AddFile(file);
return file;
}
if (msg) {
// Print transport add-ons should set to 'okok' the message on success
msg->what = 'okok';
msg->AddString("path", path.Path()); // Add path of new choosen file to transport message
msg->what = kStatusOk;
BPath path;
path.SetTo(&ref);
msg->AddString("path", path.Path());
}
AddFile(file);
return file;
}
status_t AddFile(BFile * file)
{
if (!file)
if (file == NULL)
return B_ERROR;
if (!g_files_list)
{
g_files_list = new BList();
g_nb_files = 0;
};
if (gFiles == NULL)
gFiles = new BList();
g_files_list->AddItem(file);
g_nb_files++;
printf("AddFile: %ld file transport(s) instanciated\n", g_nb_files);
gFiles->AddItem(file);
return B_OK;
}
status_t RemoveFile()
{
void * file;
int32 i;
g_nb_files--;
printf("RemoveFile: %ld file transport(s) still instanciated\n", g_nb_files);
if (g_nb_files)
if (gFiles == NULL)
return B_OK;
printf("RemoveFile: deleting files list...\n");
int32 n = gFiles->CountItems();
for (int32 i = 0; i < n; i++)
delete (BFile*)gFiles->ItemAt(i);
for (i = 0; (file = g_files_list->ItemAt(i)); i++)
delete (BFile*)file;
delete g_files_list;
delete gFiles;
gFiles = NULL;
return B_OK;
}