~ubuntu-branches/ubuntu/raring/vice/raring

« back to all changes in this revision

Viewing changes to src/arch/unix/macosx/cocoa/dialog/recordhistorywindowcontroller.m

  • Committer: Bazaar Package Importer
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2009-03-31 00:37:15 UTC
  • mfrom: (1.2.2 upstream)
  • mto: This revision was merged to the branch mainline in revision 17.
  • Revision ID: james.westby@ubuntu.com-20090331003715-mzclchtl0dp7fcl0
Tags: upstream-2.1.dfsg
ImportĀ upstreamĀ versionĀ 2.1.dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * recordhistorywindowcontroller.m - record history
 
3
 *
 
4
 * Written by
 
5
 *  Christian Vogelgsang <chris@vogelgsang.org>
 
6
 *
 
7
 * This file is part of VICE, the Versatile Commodore Emulator.
 
8
 * See README for copyright notice.
 
9
 *
 
10
 *  This program is free software; you can redistribute it and/or modify
 
11
 *  it under the terms of the GNU General Public License as published by
 
12
 *  the Free Software Foundation; either version 2 of the License, or
 
13
 *  (at your option) any later version.
 
14
 *
 
15
 *  This program is distributed in the hope that it will be useful,
 
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
 *  GNU General Public License for more details.
 
19
 *
 
20
 *  You should have received a copy of the GNU General Public License
 
21
 *  along with this program; if not, write to the Free Software
 
22
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 
23
 *  02111-1307  USA.
 
24
 *
 
25
 */
 
26
 
 
27
#import "recordhistorywindowcontroller.h"
 
28
#import "viceapplication.h"
 
29
#import "vicenotifications.h"
 
30
 
 
31
@implementation RecordHistoryWindowController
 
32
 
 
33
-(id)init
 
34
{
 
35
    self = [super initWithWindowNibName:@"RecordHistory"];
 
36
    [self registerForResourceUpdate:@selector(updateResources:)];
 
37
    
 
38
    // register notifications
 
39
    [[NSNotificationCenter defaultCenter] addObserver:self
 
40
                                             selector:@selector(displayRecording:)
 
41
                                                 name:VICEDisplayRecordingNotification
 
42
                                               object:nil];
 
43
 
 
44
   [[NSNotificationCenter defaultCenter] addObserver:self
 
45
                                            selector:@selector(displayPlayback:)
 
46
                                                name:VICEDisplayPlaybackNotification
 
47
                                              object:nil];
 
48
 
 
49
   [[NSNotificationCenter defaultCenter] addObserver:self
 
50
                                            selector:@selector(displayEventTime:)
 
51
                                                name:VICEDisplayEventTimeNotification
 
52
                                              object:nil];
 
53
     
 
54
    return self;
 
55
}
 
56
 
 
57
-(void)windowDidLoad
 
58
{
 
59
    [super windowDidLoad];
 
60
    [recordingText setStringValue:@""];
 
61
    [playbackText setStringValue:@""];
 
62
    [timeText setStringValue:@""];
 
63
    [self setButtonState];
 
64
}
 
65
 
 
66
-(void)updateResources:(NSNotification *)notification
 
67
{
 
68
    NSString *workDir = [self getStringResource:@"EventSnapshotDir"];
 
69
    [workDirText setStringValue:workDir];
 
70
    
 
71
    int startMode = [self getIntResource:@"EventStartMode"];
 
72
    [startRecordPopup selectItemWithTag:startMode];
 
73
}
 
74
 
 
75
// ----- Notifications -----
 
76
 
 
77
-(void)displayPlayback:(NSNotification *)notification
 
78
{
 
79
    NSDictionary * dict = [notification userInfo];
 
80
    BOOL playback = [[dict objectForKey:@"playback"] boolValue];
 
81
    NSString *version = (NSString *)[dict objectForKey:@"version"];
 
82
    if(playback) { 
 
83
        [playbackText setStringValue:[NSString stringWithFormat:@"Playback: %@",version]];
 
84
    } else {
 
85
        [playbackText setStringValue:@""];
 
86
        [self setButtonState];
 
87
    }
 
88
}
 
89
 
 
90
-(void)displayRecording:(NSNotification *)notification
 
91
{
 
92
    NSDictionary * dict = [notification userInfo];
 
93
    BOOL recording = [[dict objectForKey:@"recording"] boolValue];
 
94
    [recordingText setStringValue:(recording ? @"Recording" : @"")];
 
95
    if(!recording)
 
96
        [self setButtonState];
 
97
}
 
98
 
 
99
-(void)displayEventTime:(NSNotification *)notification
 
100
{
 
101
    NSDictionary * dict = [notification userInfo];
 
102
    int curTime = [[dict objectForKey:@"time"] intValue];
 
103
    int totalTime = [[dict objectForKey:@"totalTime"] intValue];
 
104
    
 
105
    int curMin = curTime / 60;
 
106
    int curSec = curTime % 60;
 
107
    NSString *txt;
 
108
    if(totalTime!=0) {
 
109
        int totalMin = totalTime / 60;
 
110
        int totalSec = totalTime % 60;
 
111
        txt = [NSString stringWithFormat:@"Time %02d:%02d  Total Time %02d:%02d",
 
112
                curMin,curSec,totalMin,totalSec];
 
113
    } else {
 
114
        txt = [NSString stringWithFormat:@"Time %02d:%02d",
 
115
                curMin,curSec];    
 
116
    }
 
117
    [timeText setStringValue:txt];
 
118
}
 
119
 
 
120
// ----- Actions -----
 
121
 
 
122
-(void)setButtonState
 
123
{
 
124
    VICEMachineController *ctrl = [VICEApplication theMachineController];
 
125
    BOOL isRecording = [ctrl isRecordingHistory];
 
126
    BOOL isPlayingBack = [ctrl isPlayingBackHistory];
 
127
    BOOL isBusy = isRecording || isPlayingBack;
 
128
 
 
129
    [recordButton setEnabled:!isBusy];
 
130
    [playButton setEnabled:!isBusy];
 
131
    [stopButton setEnabled:isBusy];
 
132
        
 
133
    [setMilestoneButton setEnabled:isRecording];
 
134
    [resetMilestoneButton setEnabled:isRecording];
 
135
    
 
136
    [workDirText setEnabled:!isBusy];
 
137
    [workDirButton setEnabled:!isBusy];
 
138
    [startRecordPopup setEnabled:!isBusy];
 
139
}
 
140
 
 
141
-(IBAction)startRecord:(id)sender
 
142
{
 
143
    [[VICEApplication theMachineController] startRecordHistory];
 
144
    [self setButtonState];
 
145
}
 
146
 
 
147
-(IBAction)startPlayback:(id)sender
 
148
{
 
149
    [[VICEApplication theMachineController] startPlaybackHistory];
 
150
    [self setButtonState];
 
151
}
 
152
 
 
153
-(IBAction)stopRecordOrPlayback:(id)sender
 
154
{
 
155
    VICEMachineController *ctrl = [VICEApplication theMachineController];
 
156
    if([ctrl isRecordingHistory]) {
 
157
        [ctrl stopRecordHistory];
 
158
    } else if([ctrl isPlayingBackHistory]) {
 
159
        [ctrl stopPlaybackHistory];
 
160
    }
 
161
    [self setButtonState];
 
162
}
 
163
 
 
164
-(IBAction)setMilestone:(id)sender
 
165
{
 
166
    [[VICEApplication theMachineController] setRecordMilestone];
 
167
}
 
168
 
 
169
-(IBAction)resetMilestone:(id)sender
 
170
{
 
171
    [[VICEApplication theMachineController] resetRecordMilestone];
 
172
}
 
173
 
 
174
-(IBAction)enterWorkDir:(id)sender
 
175
{
 
176
    [self setStringResource:@"EventSnapshotDir" toValue:[sender stringValue]];
 
177
    [self updateResources:nil];
 
178
}
 
179
 
 
180
-(IBAction)pickWorkDir:(id)sender
 
181
{
 
182
    VICEAppController *appCtrl = [VICEApplication theAppController];
 
183
    NSString *path = [appCtrl pickDirectoryWithTitle:@"Record History"];
 
184
    if(path!=nil) {
 
185
        [self setStringResource:@"EventSnapshotDir" toValue:path];
 
186
        [self updateResources:nil];
 
187
    }
 
188
}
 
189
 
 
190
-(IBAction)pickStartRecord:(id)sender
 
191
{
 
192
    int mode = [[sender selectedItem] tag];
 
193
    [self setIntResource:@"EventStartMode" toValue:mode];
 
194
    [self updateResources:nil];
 
195
}
 
196
 
 
197
@end