bin/pc: Mark non-returning function as void
[haiku.git] / src / add-ons / print / transports / print_to_file / print_transport.cpp
blob869512a51495388b62bb0fd831fcbb880bb966df
1 /*****************************************************************************/
2 // Print to file transport add-on.
3 //
4 // Author
5 // Philippe Houdoin
6 //
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
9 // and are:
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 /*****************************************************************************/
32 #include <stdio.h>
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()
49 RemoveFile();
52 extern "C" _EXPORT BDataIO * init_transport(BMessage * msg)
54 FileSelector * selector = new FileSelector();
55 entry_ref ref;
56 if (selector->Go(&ref) != B_OK) {
57 // dialog cancelled
58 if (msg)
59 msg->what = kStatusCancel;
61 // for backwards compatibility with BeOS R5 return an invalid BFile
62 BFile *file = new BFile();
63 AddFile(file);
64 return file;
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
70 if (msg)
71 msg->what = kStatusCancel;
72 AddFile(file);
73 return file;
76 if (msg) {
77 // Print transport add-ons should set to 'okok' the message on success
78 msg->what = kStatusOk;
80 BPath path;
81 path.SetTo(&ref);
82 msg->AddString("path", path.Path());
84 AddFile(file);
85 return file;
88 status_t AddFile(BFile * file)
90 if (file == NULL)
91 return B_ERROR;
93 if (gFiles == NULL)
94 gFiles = new BList();
96 gFiles->AddItem(file);
98 return B_OK;
101 status_t RemoveFile()
103 if (gFiles == NULL)
104 return B_OK;
106 int32 n = gFiles->CountItems();
107 for (int32 i = 0; i < n; i++)
108 delete (BFile*)gFiles->ItemAt(i);
110 delete gFiles;
111 gFiles = NULL;
112 return B_OK;