aboutsummaryrefslogtreecommitdiff
path: root/QSThingsPlugin/Parsers/QSThingsAreasParser.m
blob: f147603720b6a9559935b5e990c6b3b1e47172d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#import "Constants.h"
#import "QSThingsAreasParser.h"
#import "SQLHelper.h"

@implementation QSThingsAreasParser
- (BOOL)validParserForPath:(NSString *)path {
  return [[path lastPathComponent] isEqualToString:@"main.sqlite"];
}

- (NSArray *)objectsFromPath:(NSString *)path withSettings:(NSDictionary *)settings {
  NSString *query = @"SELECT "
            "uuid, "
            "title "
            "FROM TMArea "
            "ORDER BY title;";
  
  NSArray *results = [SQLHelper executeSql:query onFile:path];
  
  NSMutableArray *objects = [NSMutableArray array];
  [results enumerateObjectsUsingBlock:^(NSDictionary *dictionary, NSUInteger i, BOOL *stop) {
    
    QSObject *newObject = [QSObject
        makeObjectWithIdentifier:[dictionary objectForKey:@"uuid"]];
    [newObject setObject:dictionary forType:kAreaType];
    [newObject setName:[dictionary objectForKey:@"title"]];
    [newObject setPrimaryType:kAreaType];
    
    [objects addObject:newObject];
  }];
  
  return objects;
}
@end