From d669236d8282c4a509c16ae0082ebfcb0090ff22 Mon Sep 17 00:00:00 2001 From: Grant Paul Date: Fri, 18 Feb 2011 01:25:29 -0800 Subject: [PATCH] Factor out source discovery. --- MobileCydia.mm | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/MobileCydia.mm b/MobileCydia.mm index 4d9fe2e5..3d2e83db 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -1329,6 +1329,7 @@ typedef std::map< unsigned long, _H > SourceMap; - (pkgSourceList &) list; - (NSArray *) packages; - (NSArray *) sources; +- (Source *) sourceWithKey:(NSString *)key; - (void) reloadData; - (void) configure; @@ -3201,6 +3202,13 @@ static NSString *Warning_; return sources; } +- (Source *) sourceWithKey:(NSString *)key { + for (Source *source in [self sources]) { + if ([[source key] isEqualToString:key]) + return source; + } return nil; +} + - (bool) popErrorWithTitle:(NSString *)title { bool fatal(false); std::string message; @@ -7666,16 +7674,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) reloadData { - NSArray *sources = [database_ sources]; - for (Source *source in sources) { - if ([[source key] isEqual:key_]) { - source_ = source; - [key_ release]; - key_ = [[source key] retain]; - break; - } - } - + source_ = [database_ sourceWithKey:key_]; + [key_ release]; + key_ = [[source_ key] retain]; [self setObject:source_]; [super reloadData]; @@ -9007,13 +9008,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { controller = [[[SourcesController alloc] initWithDatabase:database_] autorelease]; [(SourcesController *)controller showAddSourcePrompt]; } else { - NSArray *sources = [database_ sources]; - for (Source *source in sources) { - if ([[source key] isEqual:argument]) { - controller = [[[SourceController alloc] initWithDatabase:database_ source:source] autorelease]; - break; - } - } + Source *source = [database_ sourceWithKey:argument]; + controller = [[[SourceController alloc] initWithDatabase:database_ source:source] autorelease]; } } -- 2.45.2