]> cgit.babelmonkeys.de Git - jubjub.git/blob - src/core/JubConfig.m
Add a zxcv-like CLI frontend
[jubjub.git] / src / core / JubConfig.m
1 #import "JubConfig.h"
2
3 @implementation JubConfig
4 @synthesize domain = _domain;
5 @synthesize server = _server;;
6 @synthesize username = _username;
7 @synthesize password = _password;
8 @synthesize frontend = _frontend;
9
10 - initWithFile: (OFString*)file
11 {
12         self = [super init];
13
14         @try {
15                 OFAutoreleasePool *pool = [OFAutoreleasePool new];
16                 OFXMLElement *element = [OFXMLElement elementWithFile: file];
17
18                 if (![element.name isEqual: @"config"] ||
19                     ![element.namespace isEqual: CONFIG_NS]) {
20                         // TODO: load default config
21                         [pool release];
22                         return self;
23                 }
24
25                 // TODO: Add error handling for missing elements
26                 of_log(@"Parsed file: %@", element);
27                 _domain = [[[element
28                     elementForName: @"domain"
29                          namespace: CONFIG_NS] stringValue] copy];
30                 _server = [[[element
31                     elementForName: @"server"
32                          namespace: CONFIG_NS] stringValue] copy];
33                 _username = [[[element
34                     elementForName: @"username"
35                          namespace: CONFIG_NS] stringValue] copy];
36                 _password = [[[element
37                     elementForName: @"password"
38                          namespace: CONFIG_NS] stringValue] copy];
39                 _frontend = [[[element
40                     elementForName: @"frontend"
41                          namespace: CONFIG_NS] stringValue] copy];
42
43
44                 [pool release];
45         } @catch (id e) {
46                 [self release];
47                 @throw e;
48         }
49
50         return self;
51 }
52
53 - (void)dealloc
54 {
55         [_domain release];
56         [_server release];
57         [_username release];
58         [_password release];
59         [_frontend release];
60
61         [super dealloc];
62 }
63 @end