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
|
/* $Id: MainWindow.cpp,v 1.19 2003/10/13 22:23:02 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 <Alert.h>
#include <Application.h>
#include <Screen.h>
#include "Manager.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 )
{
/* Init libhb & launch the manager thread */
fManager = new HBManager( true );
/* Add the scan view */
fScanView = new ScanView( fManager );
fRipView = new RipView( fManager );
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 );
delete fManager;
/* 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://beos.titer.org/handbrake/>\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;
while( !_this->fDie )
{
/* Update every 0.1 sec */
time = system_time();
_this->_UpdateInterface();
snooze( 100000 - ( system_time() - time ) );
}
}
void MainWindow::_UpdateInterface()
{
if( !fManager->NeedUpdate() )
{
return;
}
HBStatus status = fManager->GetStatus();
if( !Lock() )
{
fprintf( stderr, "Lock() failed\n" );
return;
}
switch( status.fMode )
{
case HB_MODE_UNDEF:
case HB_MODE_NEED_VOLUME:
break;
case HB_MODE_SCANNING:
case HB_MODE_INVALID_VOLUME:
fScanView->UpdateIntf( status );
break;
case HB_MODE_READY_TO_RIP:
RemoveChild( fScanView );
ResizeTo( fRipView->Bounds().Width(),
fRipView->Bounds().Height() );
AddChild( fRipView );
fRipView->UpdateIntf( status );
break;
case HB_MODE_ENCODING:
case HB_MODE_SUSPENDED:
case HB_MODE_DONE:
case HB_MODE_CANCELED:
case HB_MODE_ERROR:
fRipView->UpdateIntf( status );
break;
default:
break;
}
Unlock();
}
|