source: trunk/SapphireImporterDataMenu.m @ 133

Revision 133, 6.1 KB checked in by gbooker, 7 years ago (diff)

Strings are localizable now, so it can be translated.

Line 
1//
2//  SapphireImporterDataMenu.m
3//  Sapphire
4//
5//  Created by pnmerrill on 6/24/07.
6//  Copyright 2007 __www.nanopi.net__. All rights reserved.
7//
8
9#import "SapphirePopulateDataMenu.h"
10#import <BackRow/BackRow.h>
11#import "SapphireMetaData.h"
12
13@interface SapphireImporterDataMenu (private)
14- (void)setText:(NSString *)theText;
15- (void)setFileProgress:(NSString *)updateFileProgress;
16- (void)resetUIElements;
17@end
18
19@implementation SapphireImporterDataMenu
20- (id) initWithScene: (BRRenderScene *) scene metaData:(SapphireDirectoryMetaData *)metaData
21{
22        if ( [super initWithScene: scene] == nil )
23        return ( nil );
24        meta = [metaData retain];
25        // Setup the Header Control with default contents
26        title = [[BRHeaderControl alloc] initWithScene: scene];
27        [title setTitle:BRLocalizedString(@"Populate Show Data", @"Do a file metadata import")];
28        NSRect frame = [[self masterLayer] frame];
29        frame.origin.y = frame.size.height * 0.80f;
30        frame.size.height = [[BRThemeInfo sharedTheme] listIconHeight];
31        [title setFrame: frame];
32       
33        // Setup the Header Control with default contents
34        frame.origin.y = frame.size.height * 0.80f;
35        frame.size.height = [[BRThemeInfo sharedTheme] listIconHeight];
36
37        // setup the button control
38        frame = [[self masterLayer] frame];
39        button = [[BRButtonControl alloc] initWithScene: scene masterLayerSize: frame.size];
40        [button setYPosition: frame.origin.y + (frame.size.height * (1.0f / 8.0f))];
41
42        // setup the text entry control
43        text = [[BRTextControl alloc] initWithScene: scene];
44        fileProgress = [[BRTextControl alloc] initWithScene: scene];
45        currentFile = [[BRTextControl alloc] initWithScene: scene];
46       
47        bar = [[BRProgressBarWidget alloc] initWithScene: scene];
48        frame = [[self masterLayer] frame];
49        frame.origin.y = frame.size.height * 5.0f / 16.0f;
50        frame.origin.x = frame.size.width / 6.0f;
51        frame.size.height = frame.size.height / 16.0f;
52        frame.size.width = frame.size.width * 2.0f / 3.0f;
53        [bar setFrame: frame] ;
54       
55        [self resetUIElements];
56       
57        // add controls
58
59        [self addControl: title];
60        [self addControl: text];
61        [self addControl: fileProgress] ;
62        [self addControl: currentFile] ;
63        [[self masterLayer] addSublayer:bar];
64        [self addControl: button];
65
66    return ( self );
67}
68
69- (void)setText:(NSString *)theText
70{
71        [text setTextAttributes:[[BRThemeInfo sharedTheme] paragraphTextAttributes]];
72        [text setText:theText];
73       
74        NSRect master = [[self masterLayer] frame];
75        [text setMaximumSize:NSMakeSize(master.size.width * 2.0f/3.0f, master.size.height * 0.4f)];
76        NSSize txtSize = [text renderedSize];
77       
78        NSRect frame;
79        frame.origin.x = (master.size.width - txtSize.width) * 0.5f;
80        frame.origin.y = (master.size.height * 0.4f - txtSize.height) + master.size.height * 0.3f/0.8f;
81        frame.size = txtSize;
82        [text setFrame:frame];
83}
84
85- (void)setFileProgress:(NSString *)theFileProgress
86{
87        [fileProgress setTextAttributes:[[BRThemeInfo sharedTheme] paragraphTextAttributes]];
88        [fileProgress setText:theFileProgress];
89       
90        NSRect master = [[self masterLayer] frame];
91        [fileProgress setMaximumSize:NSMakeSize(master.size.width * 1.0f/2.0f, master.size.height * 0.3f)];
92        NSSize progressSize = [fileProgress renderedSize];
93       
94        NSRect frame;
95        frame.origin.x =  (master.size.width) * 0.1f;
96        frame.origin.y = (master.size.height * 0.12f) ;
97        frame.size = progressSize;
98        [fileProgress setFrame:frame];
99}
100
101- (void)setCurrentFile:(NSString *)theCurrentFile
102{
103        [currentFile setTextAttributes:[[BRThemeInfo sharedTheme] paragraphTextAttributes]];
104        [currentFile setText:theCurrentFile];
105       
106        NSRect master = [[self masterLayer] frame];
107        [currentFile setMaximumSize:NSMakeSize(master.size.width * 9.0f/10.0f, master.size.height * 0.3f)];
108        NSSize currentFileSize = [currentFile renderedSize];
109       
110        NSRect frame;
111        frame.origin.x =  (master.size.width) * 0.1f;
112        frame.origin.y = (master.size.height * 0.09f) ;
113        frame.size = currentFileSize;
114        [currentFile setFrame:frame];
115}
116
117
118- (void) dealloc
119{
120        [title release];
121        [text release];
122        [fileProgress release] ;
123        [bar release];
124        [button release];
125        [meta release];
126        [importTimer invalidate];
127        [super dealloc];
128}
129
130- (void)getItems
131{
132}
133
134- (void)import
135{
136        [button setTitle:BRLocalizedString(@"Cancel Import", @"Cancel the import process")];
137        [button setAction:@selector(cancel)];
138        [self setFileProgress:BRLocalizedString(@"Initializing...", @"The import is starting")];
139        [[self scene] renderScene];
140        [self getItems];
141        updated = 0 ;
142        current = 0;
143        max = [importItems count];
144        importTimer = [NSTimer scheduledTimerWithTimeInterval:0.0f target:self selector:@selector(importNextItem:) userInfo:nil repeats:YES];
145}
146
147- (BOOL)doImport
148{
149        return NO;
150}
151
152- (void)setCompletionText
153{
154}
155
156- (void)importNextItem:(NSTimer *)timer
157{
158        current++ ;
159        [self setFileProgress:[NSString stringWithFormat:BRLocalizedString(@"File Progress: %0.0f / %0.0f", @"Import progress format, current and the max"), current, max,updated]];
160        if([self doImport])updated++;
161       
162        if(suspended)
163        {
164                current--;
165                return;
166        }
167       
168        [importItems removeObjectAtIndex:0];
169        [bar setPercentage:current/max * 100.0f];
170       
171        if(![importItems count])
172        {
173                [importTimer invalidate];
174                importTimer = nil;
175                [meta writeMetaData];
176                [button setHidden:YES];
177                [button setTarget:nil];
178                [title setTitle:BRLocalizedString(@"Import Complete", @"The import is complete")];
179                [self setFileProgress:[NSString stringWithFormat:BRLocalizedString(@"Updated %0.0f Entries.", @"Import complete format with number updated"), updated]];
180                [self setCurrentFile:@""];
181                [self setCompletionText];
182                [[self scene] renderScene];
183        }
184}
185
186- (void)cancel
187{
188        [importTimer invalidate];
189        importTimer = nil;
190        [self resetUIElements];
191        [meta writeMetaData];
192}
193
194- (void)pause
195{
196        suspended = YES;
197        [importTimer invalidate];
198        importTimer = nil;
199}
200
201- (void)resume
202{
203        suspended = NO;
204        importTimer = [NSTimer scheduledTimerWithTimeInterval:0.0f target:self selector:@selector(importNextItem:) userInfo:nil repeats:YES];
205}
206
207- (void)skipNextItem
208{
209        if([importItems count])
210                [importItems removeObjectAtIndex:0];
211}
212
213- (void)resetUIElements
214{
215        [self setFileProgress:@" "];
216        [self setCurrentFile:@" "] ;
217        [bar setPercentage:0.0f];
218        [button setTarget:self];
219        [button setAction: @selector(import)];
220        [button setHidden:NO];
221}
222
223- (void)wasPopped
224{
225        [self cancel];
226        [super wasPopped];
227}
228
229@end
Note: See TracBrowser for help on using the repository browser.