1 /*****************************************************************************/
2 // Print to file transport add-on.
7 // This application and all source files used in its construction, except
8 // where noted, are licensed under the MIT License, and have been written
11 // Copyright (c) 2001,2002 OpenBeOS Project
13 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 /*****************************************************************************/
34 #include <StorageKit.h>
35 #include <SupportKit.h>
37 #include "FileSelector.h"
39 static BList
* gFiles
= NULL
;
41 status_t
AddFile(BFile
* file
);
42 status_t
RemoveFile();
44 static const int32 kStatusOk
= 'okok';
45 static const int32 kStatusCancel
= 'canc';
47 extern "C" _EXPORT
void exit_transport()
52 extern "C" _EXPORT BDataIO
* init_transport(BMessage
* msg
)
54 FileSelector
* selector
= new FileSelector();
56 if (selector
->Go(&ref
) != B_OK
) {
59 msg
->what
= kStatusCancel
;
61 // for backwards compatibility with BeOS R5 return an invalid BFile
62 BFile
*file
= new BFile();
67 BFile
*file
= new BFile(&ref
, B_WRITE_ONLY
| B_CREATE_FILE
| B_ERASE_FILE
);
68 if ( file
->InitCheck() != B_OK
) {
69 // invalid file selected
71 msg
->what
= kStatusCancel
;
77 // Print transport add-ons should set to 'okok' the message on success
78 msg
->what
= kStatusOk
;
82 msg
->AddString("path", path
.Path());
88 status_t
AddFile(BFile
* file
)
96 gFiles
->AddItem(file
);
101 status_t
RemoveFile()
106 int32 n
= gFiles
->CountItems();
107 for (int32 i
= 0; i
< n
; i
++)
108 delete (BFile
*)gFiles
->ItemAt(i
);