-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathfilereq_beos.cpp
190 lines (154 loc) · 3.55 KB
/
filereq_beos.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
** Oricutron
** Copyright (C) 2009-2010 Peter Gordon
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation, version 2
** of the License.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
** BeOS file dialog
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <FilePanel.h>
#include <Looper.h>
#include <Messenger.h>
#include <Path.h>
extern "C" {
#include "system.h"
#include "6502.h"
#include "via.h"
#include "8912.h"
#include "disk.h"
#include "gui.h"
#include "monitor.h"
#include "6551.h"
#include "machine.h"
#include "filereq.h"
}
class PanelLooper : public BLooper {
public:
PanelLooper();
virtual ~PanelLooper();
virtual void MessageReceived(BMessage* message);
void Wait();
SDL_bool DoIt() const { return fDoIt; };
void GetRef(entry_ref &ref) const { ref = fRef; };
private:
sem_id fSem;
entry_ref fRef;
SDL_bool fDoIt;
};
PanelLooper::PanelLooper()
: BLooper("PanelLooper"),
fDoIt(SDL_FALSE)
{
fSem = create_sem(0, "PanelLooper lock");
}
PanelLooper::~PanelLooper()
{
delete_sem(fSem);
}
void
PanelLooper::MessageReceived(BMessage* message)
{
//message->PrintToStream();
switch (message->what) {
case B_SAVE_REQUESTED:
message->FindRef("refs", &fRef);
fDoIt = SDL_TRUE;
break;
case B_REFS_RECEIVED:
message->FindRef("refs", &fRef);
fDoIt = SDL_TRUE;
break;
case B_CANCEL:
default:
break;
}
release_sem(fSem);
}
void
PanelLooper::Wait()
{
acquire_sem(fSem);
}
SDL_bool init_filerequester( struct machine *oric )
{
return SDL_TRUE;
}
void shut_filerequester( struct machine *oric )
{
}
SDL_bool filerequester( struct machine *oric, char *title, char *path, char *fname, int type )
{
BFilePanel *panel;
PanelLooper *looper = new PanelLooper();
looper->Run();
SDL_bool ret;
char *pat;
bool dosavemode = false;
switch( type )
{
case FR_DISKSAVE:
dosavemode = true;
case FR_DISKLOAD:
pat = "*.dsk";
break;
// FIXME: Save TAP should be *.tap, save ORT should be *.ort, Load should be *.tap, *.ort, *.wav
case FR_TAPESAVETAP:
case FR_TAPESAVEORT:
dosavemode = true;
case FR_TAPELOAD:
pat = "*.tap";
break;
case FR_ROMS:
pat = "*.rom";
break;
case FR_SNAPSHOTSAVE:
dosavemode = true;
case FR_SNAPSHOTLOAD:
pat = "*.sna";
break;
case FR_KEYMAPPINGSAVE:
dosavemode = true;
case FR_KEYMAPPINGLOAD:
pat = "*.kma";
break;
default:
pat = NULL;
break;
}
//XXX: use RefFilter
panel = new BFilePanel(dosavemode ? B_SAVE_PANEL : B_OPEN_PANEL);
panel->SetTarget(BMessenger(looper));
if (path)
panel->SetPanelDirectory(path);
panel->Show();
looper->Wait();
ret = looper->DoIt();
entry_ref ref;
looper->GetRef(ref);
delete panel;
looper->Lock();
looper->Quit();
if (ret) {
BPath p(&ref);
strncpy( fname, p.Leaf(), 512 ); path[511] = 0;
p.GetParent(&p);
strncpy( path, p.Path(), 4096 ); path[4095] = 0;
}
return ret;
}