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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
|
/* $Id: ScanView.cpp,v 1.4 2003/10/13 23:42:03 titer Exp $
This file is part of the HandBrake source code.
Homepage: <http://beos.titer.org/handbrake/>.
It may be used under the terms of the GNU General Public License. */
#include <fs_info.h>
#include <sys/ioctl.h>
#include <Box.h>
#include <Button.h>
#include <Directory.h>
#include <Drivers.h>
#include <FilePanel.h>
#include <MenuField.h>
#include <MenuItem.h>
#include <Path.h>
#include <PopUpMenu.h>
#include <Query.h>
#include <RadioButton.h>
#include <StringView.h>
#include <TextControl.h>
#include <VolumeRoster.h>
#include "Manager.h"
#include "ScanView.h"
ScanView::ScanView( HBManager * manager )
: BView( BRect( 0,0,400,190 ), NULL, B_FOLLOW_ALL, B_WILL_DRAW )
{
fManager = manager;
BRect r;
SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
r = BRect( 10, 10, Bounds().Width() - 10, 115 );
BBox * box = new BBox( r );
box->SetLabel( "Select source:" );
AddChild( box );
r = BRect( 10, 15, box->Bounds().Width() / 2, 35 );
fRadioDetected = new BRadioButton( r, NULL, "Detected volume:",
new BMessage( SCAN_RADIO ) );
box->AddChild( fRadioDetected );
r = BRect( box->Bounds().Width() / 2, 15,
box->Bounds().Width() - 10, 35 );
fPopUp = new BPopUpMenu( "" );
fField = new BMenuField( r, NULL, NULL, fPopUp, true );
fField->SetDivider( 0 );
box->AddChild( fField );
r = BRect( 10, 45, box->Bounds().Width() / 3, 65 );
fRadioFolder = new BRadioButton( r, NULL, "DVD folder:",
new BMessage( SCAN_RADIO ) );
box->AddChild( fRadioFolder );
r = BRect( box->Bounds().Width() / 3, 45,
box->Bounds().Width() - 10, 65 );
fFolderControl = new BTextControl( r, NULL, NULL, NULL, NULL );
box->AddChild( fFolderControl );
r = BRect( box->Bounds().Width() - 80, 70,
box->Bounds().Width() - 10, 95 );
fBrowseButton = new BButton( r, NULL, "Browse...",
new BMessage( SCAN_BROWSE_BUTTON ) );
box->AddChild( fBrowseButton );
fFilePanel = new BFilePanel( B_OPEN_PANEL, NULL,
NULL, B_DIRECTORY_NODE );
r = BRect( 10, 125, Bounds().Width() - 10, 145 );
fStatusString = new BStringView( r, NULL, NULL );
AddChild( fStatusString );
r = BRect( Bounds().Width() - 70, 155,
Bounds().Width() - 10, 175 );
fOpenButton = new BButton( r, NULL, "Open", new BMessage( SCAN_OPEN ) );
fOpenButton->MakeDefault( true );
AddChild( fOpenButton );
DetectVolumes();
}
void ScanView::MessageReceived( BMessage * message )
{
switch( message->what )
{
case SCAN_RADIO:
{
if( fRadioDetected->Value() )
{
fField->SetEnabled( true );
fFolderControl->SetEnabled( false );
fBrowseButton->SetEnabled( false );
fOpenButton->SetEnabled( fPopUp->CountItems() > 0 );
}
else
{
fField->SetEnabled( false );
fFolderControl->SetEnabled( true );
fBrowseButton->SetEnabled( true );
fOpenButton->SetEnabled( true );
}
break;
}
case SCAN_BROWSE_BUTTON:
{
fFilePanel->Show();
break;
}
case B_REFS_RECEIVED:
{
entry_ref ref;
if( message->FindRef( "refs", 0, &ref ) == B_OK )
{
BPath * path = new BPath( &ref );
fFolderControl->SetText( path->Path() );
}
break;
}
case SCAN_OPEN:
{
if( fRadioDetected->Value() )
{
fManager->ScanVolumes( (char*)
fPopUp->FindMarked()->Label() );
}
else
{
fManager->ScanVolumes( (char*) fFolderControl->Text() );
}
break;
}
default:
BView::MessageReceived( message );
}
}
void ScanView::UpdateIntf( HBStatus status )
{
switch( status.fMode )
{
case HB_MODE_SCANNING:
{
fRadioDetected->SetEnabled( false );
fRadioFolder->SetEnabled( false );
fField->SetEnabled( false );
fFolderControl->SetEnabled( false );
fBrowseButton->SetEnabled( false );
fOpenButton->SetEnabled( false );
char string[1024]; memset( string, 0, 1024 );
if( !status.fScannedTitle )
{
sprintf( string, "Opening %s...",
status.fScannedVolume );
}
else
{
sprintf( string, "Scanning %s, title %d...",
status.fScannedVolume, status.fScannedTitle );
}
fStatusString->SetText( string );
break;
}
case HB_MODE_INVALID_VOLUME:
{
fRadioDetected->SetEnabled( true );
fRadioFolder->SetEnabled( true );
if( fRadioDetected->Value() )
{
fField->SetEnabled( true );
fFolderControl->SetEnabled( false );
fBrowseButton->SetEnabled( false );
fOpenButton->SetEnabled( fPopUp->CountItems() > 0 );
}
else
{
fField->SetEnabled( false );
fFolderControl->SetEnabled( true );
fBrowseButton->SetEnabled( true );
fOpenButton->SetEnabled( true );
}
fStatusString->SetText( "Invalid volume." );
break;
}
default:
break;
}
}
void ScanView::DetectVolumes()
{
BVolumeRoster * roster = new BVolumeRoster();
BVolume * volume = new BVolume();
fs_info info;
int device;
device_geometry geometry;
/* Parse mounted volumes */
while( roster->GetNextVolume( volume ) == B_NO_ERROR )
{
/* open() and ioctl() for more informations */
fs_stat_dev( volume->Device(), &info );
if( ( device = open( info.device_name, O_RDONLY ) ) < 0 )
{
continue;
}
if( ioctl( device, B_GET_GEOMETRY, &geometry,
sizeof( geometry ) ) < 0 )
{
continue;
}
/* Get the volume name */
char volumeName[B_FILE_NAME_LENGTH];
volume->GetName( volumeName );
if( volume->IsReadOnly() && geometry.device_type == B_CD )
{
/* May be a DVD */
fPopUp->AddItem( new BMenuItem( info.device_name, NULL ) );
}
else if( geometry.device_type == B_DISK )
{
/* May be a hard drive. Look for VIDEO_TS folders on it */
BQuery * query = new BQuery();
if( query->SetVolume( volume ) != B_OK )
{
delete query;
continue;
}
if( query->SetPredicate( "name = VIDEO_TS.BUP" ) != B_OK )
{
delete query;
continue;
}
query->Fetch();
BEntry entry, parentEntry;
BPath path;
while( query->GetNextEntry( &entry ) == B_OK )
{
entry.GetParent( &parentEntry );
parentEntry.GetPath( &path );
fPopUp->AddItem( new BMenuItem( path.Path(), NULL ) );
}
delete query;
}
}
if( fPopUp->CountItems() > 0 )
{
fPopUp->ItemAt( 0 )->SetMarked( true );
fRadioDetected->SetValue( true );
fFolderControl->SetEnabled( false );
fBrowseButton->SetEnabled( false );
}
else
{
fRadioFolder->SetValue( true );
fField->SetEnabled( false );
}
}
|