summaryrefslogtreecommitdiff
path: root/bindings/objc/src/SwordInstallSource.mm
diff options
context:
space:
mode:
Diffstat (limited to 'bindings/objc/src/SwordInstallSource.mm')
-rw-r--r--bindings/objc/src/SwordInstallSource.mm115
1 files changed, 40 insertions, 75 deletions
diff --git a/bindings/objc/src/SwordInstallSource.mm b/bindings/objc/src/SwordInstallSource.mm
index b1f71d3..6870b74 100644
--- a/bindings/objc/src/SwordInstallSource.mm
+++ b/bindings/objc/src/SwordInstallSource.mm
@@ -12,6 +12,8 @@
@interface SwordInstallSource ()
+@property (nonatomic) BOOL deleteSwInstallSource;
+
@end
@implementation SwordInstallSource
@@ -20,16 +22,8 @@
- (id)init {
self = [super init];
if(self) {
- temporarySource = NO;
-
- // at first we have no sword manager
- [self setSwordManager:nil];
-
- // init InstallMgr
swInstallSource = new sword::InstallSource("", "");
- if(swInstallSource == nil) {
- ALog(@"Could not init sword install source!");
- }
+ self.deleteSwInstallSource = YES;
}
return self;
@@ -38,8 +32,7 @@
- (id)initWithType:(NSString *)aType {
self = [self init];
if(self) {
- // set type
- swInstallSource->type = [aType cStringUsingEncoding:NSUTF8StringEncoding];
+ swInstallSource->type = [aType UTF8String];
}
return self;
@@ -49,72 +42,55 @@
- (id)initWithSource:(sword::InstallSource *)is {
self = [super init];
if(self) {
- temporarySource = YES;
-
- // at first we have no sword manager
- [self setSwordManager:nil];
-
swInstallSource = is;
+ self.deleteSwInstallSource = NO;
}
return self;
}
-- (void)finalize {
- if(temporarySource == NO) {
- //LogL(LOG_DEBUG, @"[SwordInstallSource -finalize] deleting swInstallSource");
- //delete swInstallSource;
- }
-
- [super finalize];
-}
-
- (void)dealloc {
- [swordManager release];
- [super dealloc];
-}
-
-- (void)setSwordManager:(SwordManager *)swManager {
- [swManager retain];
- [swordManager release];
- swordManager = swManager;
+ ALog(@"");
+ if(swInstallSource != NULL && self.deleteSwInstallSource) {
+ ALog(@"Deleting InstallSource");
+ delete swInstallSource;
+ }
}
-// accessors
- (NSString *)caption {
const char *str = swInstallSource->caption;
- return [[[NSString alloc] initWithCString:str encoding:NSUTF8StringEncoding] autorelease];
+ return [[NSString alloc] initWithCString:str encoding:NSUTF8StringEncoding];
}
- (void)setCaption:(NSString *)aCaption {
- swInstallSource->caption = [aCaption cStringUsingEncoding:NSUTF8StringEncoding];
+ swInstallSource->caption = [aCaption UTF8String];
}
- (NSString *)type {
const char *str = swInstallSource->type;
- return [[[NSString alloc] initWithCString:str encoding:NSUTF8StringEncoding] autorelease];
+ return [[NSString alloc] initWithCString:str encoding:NSUTF8StringEncoding];
}
- (void)setType:(NSString *)aType {
- swInstallSource->type = [aType cStringUsingEncoding:NSUTF8StringEncoding];
+ swInstallSource->type = [aType UTF8String];
}
- (NSString *)source {
const char *str = swInstallSource->source;
- return [[[NSString alloc] initWithCString:str encoding:NSUTF8StringEncoding] autorelease];
+ return [[NSString alloc] initWithCString:str encoding:NSUTF8StringEncoding];
}
- (void)setSource:(NSString *)aSource {
- swInstallSource->source = [aSource cStringUsingEncoding:NSUTF8StringEncoding];
+ swInstallSource->source = [aSource UTF8String];
}
- (NSString *)directory {
const char *str = swInstallSource->directory;
- return [[[NSString alloc] initWithCString:str encoding:NSUTF8StringEncoding] autorelease];
+ return [[NSString alloc] initWithCString:str encoding:NSUTF8StringEncoding];
}
- (void)setDirectory:(NSString *)aDir {
- swInstallSource->directory = [aDir cStringUsingEncoding:NSUTF8StringEncoding];
+ swInstallSource->directory = [aDir UTF8String];
}
- (BOOL)isLocalSource {
@@ -133,60 +109,49 @@
}
/** list all modules of this source */
-- (NSArray *)listModules {
- NSArray *ret = [NSArray array];
-
+- (NSDictionary *)allModules {
SwordManager *sm = [self swordManager];
if(sm) {
- ret = [sm listModules];
+ return [sm allModules];
} else {
ALog(@"Have nil SwordManager");
}
-
- return ret;
+ return nil;
}
- (NSArray *)listModulesForType:(ModuleType)aType {
- NSArray *ret = [NSArray array];
-
SwordManager *sm = [self swordManager];
if(sm) {
- ret = [sm modulesForType:aType];
+ return [sm modulesForType:aType];
} else {
ALog(@"Have nil SwordManager");
- }
-
- return ret;
+ }
+ return nil;
}
/** list module types */
- (NSArray *)listModuleTypes {
- NSArray *ret = [SwordManager moduleTypes];
- return ret;
+ return [SwordManager moduleTypes];
}
-// get associated SwordManager
- (SwordManager *)swordManager {
-
- if(swordManager == nil) {
+ // create SwordManager from the SWMgr of this source
+ sword::SWMgr *mgr;
+ if([self isLocalSource]) {
+ // create SwordManager from new SWMgr of path
+ mgr = new sword::SWMgr([[self directory] UTF8String], true, NULL, false, false);
+ } else {
// create SwordManager from the SWMgr of this source
- sword::SWMgr *mgr;
- if([[self source] isEqualToString:@"localhost"]) {
- // create SwordManager from new SWMgr of path
- mgr = new sword::SWMgr([[self directory] UTF8String], true, NULL, false, false);
- } else {
- // create SwordManager from the SWMgr of this source
- mgr = swInstallSource->getMgr();
- }
-
- if(mgr == nil) {
- ALog(@"Have a nil SWMgr!");
- } else {
- swordManager = [[SwordManager alloc] initWithSWMgr:mgr];
- }
+ mgr = swInstallSource->getMgr();
+ }
+
+ if(mgr == nil) {
+ ALog(@"Have a nil SWMgr!");
+ return nil;
+
+ } else {
+ return [[SwordManager alloc] initWithSWMgr:mgr];
}
-
- return swordManager;
}
/** low level API */