Skip to content

Commit

Permalink
no crytical
Browse files Browse the repository at this point in the history
  • Loading branch information
chamspan committed Oct 22, 2013
1 parent bc67e8e commit 8c96048
Showing 6 changed files with 597 additions and 264 deletions.
Original file line number Diff line number Diff line change
@@ -9,11 +9,11 @@
continueAfterRunningActions = "No"
isPathRelative = "1"
filePath = "RSSCue/RCPreferencesController.m"
timestampString = "404145294.638812"
timestampString = "404155568.219929"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "50"
endingLineNumber = "50"
startingLineNumber = "64"
endingLineNumber = "64"
landmarkName = "-updateInfoText"
landmarkType = "5">
</FileBreakpoint>
2 changes: 1 addition & 1 deletion RSSCue/RCFeedsPool.h
Original file line number Diff line number Diff line change
@@ -18,5 +18,5 @@
-(RCFeed *) feedForUUID:(NSString *)uuid;
-(void) addFeedByUUID:(NSString*)uuid;
-(void) removeFeedByUUID:(NSString*)uuid;
-(void) updateFeedByUUID:(NSString*)uuid;
-(void) restartFeedByUUID:(NSString*)uuid;
@end
33 changes: 21 additions & 12 deletions RSSCue/RCFeedsPool.m
Original file line number Diff line number Diff line change
@@ -26,23 +26,28 @@ + (RCFeedsPool*)sharedPool{
return _sharedPool;
}

-(void) addFeed:(RCFeed *)feed withConfig:(NSDictionary *)config {
NSTimeInterval interval=[[config objectForKey:@"interval"] doubleValue];
if (interval<10) interval=10; //precaution
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:interval
target:self
selector:@selector(runFeed:)
userInfo:[NSDictionary dictionaryWithObject:feed forKey:@"feed"]
repeats:YES];
[_timers setObject:timer forKey:feed.uuid];
NSLog(@"Feed %@ added to the schedule",feed.name);
};

-(void) addFeedByConfig:(NSDictionary *)config {
if (NO==[[config valueForKey:@"enabled"] boolValue]) {
return;
}
NSString *uuid=[config valueForKey:@"uuid"];
NSAssert(uuid!=nil, @"UUID must not be nill\n%@", config);
RCFeed* feed=[[[RCFeed alloc] initWithUUID:uuid andDelegate:self] autorelease];
NSLog(@"Feed %@ started",feed.name);

[feed run];
NSTimeInterval interval=[[config objectForKey:@"interval"] doubleValue];
if (interval<10) interval=10; //precaution
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:interval
target:self
selector:@selector(runFeed:)
userInfo:[NSDictionary dictionaryWithObject:feed forKey:@"feed"]
repeats:YES];
[_timers setObject:timer forKey:uuid];
[self addFeed:feed withConfig:config];
};

-(void) addFeedByUUID:(NSString*)uuid {
@@ -56,13 +61,17 @@ -(void) removeFeedByUUID:(NSString*)uuid{
RCFeed *feed=[[[timer userInfo] objectForKey:@"feed"] retain];
[timer invalidate];
[_timers removeObjectForKey:uuid];
NSLog(@"Feed %@ removed",feed.name);
NSLog(@"Feed %@ removed from the schedule",feed.name);
[feed release];
};

-(void) updateFeedByUUID:(NSString*)uuid{
-(void) restartFeedByUUID:(NSString*)uuid{
RCFeed *feed=[[self feedForUUID:uuid] retain];
NSDictionary * config=[NSUserDefaults configForFeedByUUID:uuid];
NSAssert(config!=nil, @"Attempt to add a feed with no configuraiton, uuid=%@",uuid);
[self removeFeedByUUID:uuid];
[self addFeedByUUID:uuid];
[self addFeed:feed withConfig:config];
[feed release];
}

-(void)launchAll{
11 changes: 10 additions & 1 deletion RSSCue/RCPreferencesController.h
Original file line number Diff line number Diff line change
@@ -17,9 +17,18 @@
@property (assign) IBOutlet NSSegmentedControl *buttons;
@property (assign) IBOutlet NSTextField *info;
@property (assign) IBOutlet NSProgressIndicator *progress;
@property (retain) NSString* login;
@property (retain) NSString* password;

- (IBAction)addRemoveFeed:(id)sender;
- (IBAction)save:(id)sender;
- (void) updateInfoText;

- (void)controlTextDidEndEditing:(NSNotification *)aNotification;

@property (assign) IBOutlet NSTextField *fieldURL;
@property (assign) IBOutlet NSTextField *fieldLogin;
@property (assign) IBOutlet NSTextField *fieldPassword;
@property (assign) IBOutlet NSStepper *stepperInterval;
@property (assign) IBOutlet NSStepper *stepperMax;

@end
35 changes: 34 additions & 1 deletion RSSCue/RCPreferencesController.m
Original file line number Diff line number Diff line change
@@ -11,13 +11,27 @@
#import "NSUserDefaults+FeedConfig.h"

@implementation RCPreferencesController
@synthesize fieldURL;
@synthesize fieldLogin;
@synthesize fieldPassword;
@synthesize stepperInterval;
@synthesize stepperMax;
@synthesize progress;
@synthesize info;

@synthesize login;
@synthesize password;

@synthesize feedsArrayController;
@synthesize buttons=_buttons;

#pragma mark utilities
- (NSDictionary *)selectedConfig{
NSArray * selection=[feedsArrayController selectedObjects];
NSDictionary * config=[selection count]>0?[selection objectAtIndex:0]:nil;
return config;
}

- (void) setControlsEnabled {
unsigned long c=[[feedsArrayController selectedObjects] count];
[self.buttons setEnabled:c>0 forSegment:1];
@@ -75,6 +89,9 @@ - (void) updateInfoText {
[self.info setStringValue:[NSString stringWithFormat:@"%@\nURL: %@\nTotal number of entries: %@\nNumber of shown entries: %@\nLast fetch: %@\n%@",title,link,total,reported, lastFetchTxt,summary]];
}

- (IBAction)restartSelectedFeed:(id)sender {
}



#pragma mark Initialization
@@ -95,14 +112,21 @@ - (void)windowDidLoad
}
- (void) awakeFromNib {
[feedsArrayController addObserver:self forKeyPath:@"selection" options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld) context:nil];
/*
[feedsArrayController addObserver:self forKeyPath:@"selection.interval" options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld) context:nil];
[feedsArrayController addObserver:self forKeyPath:@"selection.url" options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld) context:nil];
[feedsArrayController addObserver:self forKeyPath:@"selection.enabled" options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld) context:nil];*/
[feedsArrayController addObserver:self forKeyPath:@"login" options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld) context:nil];
[feedsArrayController addObserver:self forKeyPath:@"password" options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld) context:nil];

[self setControlsEnabled];
[self updateInfoText];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(feedUpdated:)
name:@"feedUpdate" object:nil];
}

#pragma mark Controls observers
#pragma mark Controls observers & delegators

- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if ([keyPath isEqualToString:@"selection"]){
@@ -111,6 +135,15 @@ - (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(
}
}

- (void)controlTextDidEndEditing:(NSNotification *)aNotification {
NSTextField* f=[aNotification object];
if (f==self.fieldLogin||f==self.fieldURL||f==self.fieldPassword){
NSString* uuid=[[self selectedConfig] objectForKey:@"uuid"];
[[RCFeedsPool sharedPool] restartFeedByUUID:uuid];
}
// NSLog(@"%@",[[aNotification userInfo] valueForKey:@"NSFieldEditor"] );
}

#pragma mark *** Buttons ***
- (IBAction)addRemoveFeed:(id)sender {
NSInteger button=[sender selectedSegment];
Loading
Oops, something went wrong.

0 comments on commit 8c96048

Please sign in to comment.