diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-09-12 21:50:40 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-09-12 21:50:40 +0200 |
| commit | 182872c760d437556d606cc02c6b7c570667a715 (patch) | |
| tree | 11795bdb259445e5c3f8dd0177e9426ec77b0399 /QSThingsPlugin/Handlers/ThingsAreaHandler.m | |
| parent | 5870e5cf03ceaff7080174b573618631a413110e (diff) | |
Add children
Diffstat (limited to 'QSThingsPlugin/Handlers/ThingsAreaHandler.m')
| -rw-r--r-- | QSThingsPlugin/Handlers/ThingsAreaHandler.m | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/QSThingsPlugin/Handlers/ThingsAreaHandler.m b/QSThingsPlugin/Handlers/ThingsAreaHandler.m new file mode 100644 index 0000000..6619a0e --- /dev/null +++ b/QSThingsPlugin/Handlers/ThingsAreaHandler.m @@ -0,0 +1,124 @@ +#import "ThingsAreaHandler.h" + +NS_ASSUME_NONNULL_BEGIN + +@implementation ThingsAreaHandler + +- (BOOL)objectHasChildren:(QSObject *)object { + return YES; +} + +- (void)setQuickIconForObject:(QSObject *)object { + NSImage *baseImage = [QSResourceManager imageNamed:@"com.culturedcode.ThingsMac"]; + NSColor *color = [NSColor colorWithRed:0.478 green:0.702 blue:0.584 alpha:1.0]; + NSImage *imageWithBadge = [baseImage imageOfSize:NSMakeSize(512, 512) withSystemBadge:@"cube.circle" ofColor:color]; + + if (imageWithBadge) { + [object setIcon:imageWithBadge]; + } else { + [object setIcon:baseImage]; + } +} + +- (BOOL)loadChildrenForObject:(QSObject *)object { + NSDictionary *contents = [object objectForType:kAreaType]; + + if (!contents) { + NSLog(@"Malformed Things Task: No content."); + return NO; + } + + NSString *path = [contents objectForKey:@"path"]; + if (!path) { + NSLog(@"Malformed Things Task: No path."); + return NO; + } + + NSString *uuid = [contents objectForKey:@"uuid"]; + if (!uuid) { + NSLog(@"Malformed Things Task: No uuid."); + return NO; + } + + NSMutableArray *children = [NSMutableArray array]; + [children addObjectsFromArray:[self tagsForAreaIdentifiedBy:uuid usingDatabaseAt:path ]]; + [children addObjectsFromArray:[self tasksForAreaIdentifiedBy:uuid usingDatabaseAt:path ]]; + [children addObjectsFromArray:[self projectsForAreaIdentifiedBy:uuid usingDatabaseAt:path ]]; + + [object setChildren:children]; + return YES; +} + +- (NSArray *)tagsForAreaIdentifiedBy:(NSString *)uuid usingDatabaseAt:(NSString *)path { + NSString *query = [NSString stringWithFormat: @"SELECT " + "tag.uuid as uuid, " + "tag.title as title " + "FROM TMArea AS area " + "LEFT JOIN TMAreaTag as junction " + "ON junction.areas = area.uuid " + "LEFT JOIN TMTag as tag " + "ON junction.tags = tag.uuid " + "WHERE area.uuid = '%@' " + "AND tag.uuid IS NOT NULL " + "ORDER BY tag.title;", uuid]; + + NSArray *results = [SQLHelper executeSql:query onFile:path]; + NSMutableArray *objects = [NSMutableArray array]; + [results enumerateObjectsUsingBlock:^(NSDictionary *dictionary, NSUInteger i, BOOL *stop) { + [objects addObject:[ObjectHelper tagFromSQLResult:dictionary usingPath:path ]]; + }]; + + return objects; +} + +- (NSArray *)projectsForAreaIdentifiedBy:(NSString *)uuid usingDatabaseAt:(NSString *)path { + NSString *query = [NSString stringWithFormat: @"SELECT " + "uuid, " + "creationDate, " + "status, " + "title, " + "notes, " + "area " + "FROM TMTask " + "WHERE area = '%@' " + "AND type = 1 " + "AND trashed = 0 " + "AND status = 0 " + "ORDER BY title;", uuid]; + + NSArray *results = [SQLHelper executeSql:query onFile:path]; + NSMutableArray *objects = [NSMutableArray array]; + [results enumerateObjectsUsingBlock:^(NSDictionary *dictionary, NSUInteger i, BOOL *stop) { + [objects addObject:[ObjectHelper projectFromSQLResult:dictionary usingPath:path ]]; + }]; + + return objects; +} + +- (NSArray *)tasksForAreaIdentifiedBy:(NSString *)uuid usingDatabaseAt:(NSString *)path { + NSString *query = [NSString stringWithFormat: @"SELECT " + "uuid, " + "creationDate, " + "status, " + "title, " + "notes, " + "area " + "FROM TMTask " + "WHERE area = '%@' " + "AND type = 0 " + "AND trashed = 0 " + "AND status = 0 " + "ORDER BY title;", uuid]; + + NSArray *results = [SQLHelper executeSql:query onFile:path]; + NSMutableArray *objects = [NSMutableArray array]; + [results enumerateObjectsUsingBlock:^(NSDictionary *dictionary, NSUInteger i, BOOL *stop) { + [objects addObject:[ObjectHelper taskFromSQLResult:dictionary usingPath:path ]]; + }]; + + return objects; +} + +@end + +NS_ASSUME_NONNULL_END |