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