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
|
/* $Id: MainWindow.cpp,v 1.4 2003/11/09 21:35:06 titer Exp $
This file is part of the HandBrake source code.
Homepage: <http://handbrake.m0k.org/>.
It may be used under the terms of the GNU General Public License. */
#include <Alert.h>
#include <Application.h>
#include <Screen.h>
#include "MainWindow.h"
#include "ScanView.h"
#include "RipView.h"
MainWindow::MainWindow()
: BWindow( BRect( 0,0,10,10 ), "HandBrake " VERSION, B_TITLED_WINDOW,
B_NOT_RESIZABLE | B_NOT_ZOOMABLE )
{
fHandle = HBInit( 1, 0 );
/* Add the scan view */
fScanView = new ScanView( fHandle );
fRipView = new RipView( fHandle );
AddChild( fScanView );
/* Resize to fit */
ResizeTo( fScanView->Bounds().Width(), fScanView->Bounds().Height() );
BScreen screen;
MoveTo( ( screen.Frame().Width() - fRipView->Bounds().Width() ) / 2,
( screen.Frame().Height() - fRipView->Bounds().Height() ) / 2 );
/* Update the interface */
fDie = false;
fUpdateThread = spawn_thread( (int32 (*)(void *)) UpdateInterface,
"interface", B_DISPLAY_PRIORITY, this );
resume_thread( fUpdateThread );
}
bool MainWindow::QuitRequested()
{
/* Clean up */
fDie = true;
long exit_value;
wait_for_thread( fUpdateThread, &exit_value );
HBClose( &fHandle );
/* Stop the application */
be_app->PostMessage( B_QUIT_REQUESTED );
return true;
}
void MainWindow::MessageReceived( BMessage * message )
{
switch( message->what )
{
case B_ABOUT_REQUESTED:
{
BAlert * alert;
alert = new BAlert( "About HandBrake",
"HandBrake " VERSION "\n\n"
"by Eric Petit <titer@videolan.org>\n"
"Homepage : <http://handbrake.m0k.org/>\n\n"
"No, you don't want to know where this stupid app "
"name comes from.\n\n"
"Thanks to BGA for pointing out very cool bugs ;)",
"Woot !" );
alert->Go( NULL );
break;
}
case B_REFS_RECEIVED:
case SCAN_RADIO:
case SCAN_BROWSE_BUTTON:
case SCAN_OPEN:
fScanView->MessageReceived( message );
break;
case B_SAVE_REQUESTED:
case RIP_TITLE_POPUP:
case RIP_BITRATE_RADIO:
case RIP_TARGET_CONTROL:
case RIP_CROP_BUTTON:
case RIP_BROWSE_BUTTON:
case RIP_SUSPEND_BUTTON:
case RIP_RIP_BUTTON:
fRipView->MessageReceived( message );
break;
default:
BWindow::MessageReceived( message );
break;
}
}
void MainWindow::UpdateInterface( MainWindow * _this )
{
uint64_t time;
int64_t wait;
while( !_this->fDie )
{
/* Update every 0.1 sec */
time = system_time();
_this->_UpdateInterface();
wait = 100000 - ( system_time() - time );
if( wait > 0 )
{
snooze( wait );
}
}
}
void MainWindow::_UpdateInterface()
{
if( !Lock() )
{
fprintf( stderr, "Lock() failed\n" );
return;
}
int modeChanged;
HBStatus status;
modeChanged = HBGetStatus( fHandle, &status );
switch( status.mode )
{
case HB_MODE_UNDEF:
case HB_MODE_NEED_DEVICE:
break;
case HB_MODE_SCANNING:
case HB_MODE_INVALID_DEVICE:
fScanView->UpdateIntf( status, modeChanged );
break;
case HB_MODE_READY_TO_RIP:
if( !modeChanged )
break;
RemoveChild( fScanView );
ResizeTo( fRipView->Bounds().Width(),
fRipView->Bounds().Height() );
AddChild( fRipView );
fRipView->UpdateIntf( status, modeChanged );
break;
case HB_MODE_ENCODING:
case HB_MODE_PAUSED:
case HB_MODE_DONE:
case HB_MODE_CANCELED:
case HB_MODE_ERROR:
fRipView->UpdateIntf( status, modeChanged );
break;
default:
break;
}
Unlock();
}
|