source: trunk/SapphirePopulateDataMenu.m @ 91

Revision 91, 5.9 KB checked in by pmerrill, 7 years ago (diff)

--File Name added to import screen

Line 
1//
2//  SapphirePopulateDataMenu.m
3//  Sapphire
4//
5//  Created by pnmerrill on 6/24/07.
6//  Copyright 2007 __MyCompanyName__. All rights reserved.
7//
8
9#import "SapphirePopulateDataMenu.h"
10#import <BackRow/BackRow.h>
11#import "SapphireMetaData.h"
12
13@interface SapphirePopulateDataMenu (private)
14- (void)setText:(NSString *)theText;
15- (void)setFileProgress:(NSString *)updateFileProgress;
16- (void)resetUIElements;
17@end
18
19@implementation SapphirePopulateDataMenu
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: @"Populate Show Data"];
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.05f;
96        frame.origin.y = (master.size.height * 0.1f - progressSize.height) ;
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.05f;
112        frame.origin.y = (master.size.height * 0.07f - currentFileSize.height) ;
113        frame.size = currentFileSize;
114        [currentFile setFrame:frame];
115}
116
117- (void) dealloc
118{
119        [title release];
120        [text release];
121        [fileProgress release] ;
122        [bar release];
123        [button release];
124        [meta release];
125        [importTimer invalidate];
126        [super dealloc];
127}
128
129- (void)import
130{
131        [button setTitle:@"Cancel Import"];
132        [button setAction:@selector(cancel)];
133        [self setFileProgress:@"Initializing..."];
134        [[self scene] renderScene];
135        importItems = [[meta subFileMetas] mutableCopy];
136        updated = 0 ;
137        current = 0;
138        max = [importItems count];
139        importTimer = [NSTimer scheduledTimerWithTimeInterval:0.0f target:self selector:@selector(importNextItem:) userInfo:nil repeats:YES];
140}
141
142- (void)importNextItem:(NSTimer *)timer
143{
144        SapphireFileMetaData *fileMeta = [importItems objectAtIndex:0];
145        NSString * fileName=[[fileMeta path] lastPathComponent] ;
146        current++ ;
147        [self setCurrentFile:[NSString stringWithFormat:@"Current File: %@",fileName]];
148        [self setFileProgress:[NSString stringWithFormat:@"File Progress: %0.0f / %0.0f", current, max,updated]];
149        if([fileMeta updateMetaData])updated++;
150       
151        [importItems removeObjectAtIndex:0];
152        [bar setPercentage:current/max * 100.0f];
153       
154        if(![importItems count])
155        {
156                [importTimer invalidate];
157                importTimer = nil;
158                [meta writeMetaData];
159                [button setHidden:YES];
160                [button setTarget:nil];
161                [title setTitle: @"Import Complete"];
162                [self setFileProgress:[NSString stringWithFormat:@"Updated %0.0f Entries.", updated]];
163                [self setCurrentFile:@""];
164                [self setText:@"Sapphire will continue to import new files as it encounters them.  You may initiate this import again at any time, and any new or changed files will be imported"];
165                [[self scene] renderScene];
166        }
167}
168
169- (void)cancel
170{
171        [importTimer invalidate];
172        importTimer = nil;
173        [self resetUIElements];
174        [meta writeMetaData];
175}
176
177- (void)resetUIElements
178{
179        [title setTitle: @"Populate Show Data"];
180        [self setText:@"This will populate Sapphire's Meta data.  This proceedure may take a while, but you may cancel at any time"];
181        [self setFileProgress:@" "];
182        [self setCurrentFile:@" "] ;
183        [bar setPercentage:0.0f];
184        [button setTitle: @"Import Meta Data"];
185        [button setTarget:self];
186        [button setAction: @selector(import)];
187        [button setHidden:NO];
188}
189
190- (void)wasPopped
191{
192        [self cancel];
193        [super wasPopped];
194}
195
196@end
Note: See TracBrowser for help on using the repository browser.