Revision fb27f368 pithos-macos/PithosSharingAccountsNode.m

b/pithos-macos/PithosSharingAccountsNode.m
2 2
//  PithosAccountNode.m
3 3
//  pithos-macos
4 4
//
5
// Copyright 2011-2012 GRNET S.A. All rights reserved.
5
// Copyright 2011-2013 GRNET S.A. All rights reserved.
6 6
//
7 7
// Redistribution and use in source and binary forms, with or
8 8
// without modification, are permitted provided that the following
......
46 46
#import "PithosActivityFacility.h"
47 47

  
48 48
@implementation PithosSharingAccountsNode
49
@synthesize pithos, sharingAccountsRequest;
49
@synthesize sharingAccountsRequest;
50 50

  
51 51
#pragma mark -
52 52
#pragma mark Object Lifecycle
53 53

  
54
- (id)initWithPithosAccountManager:(PithosAccount *)aPithosAccountManager andPithos:(ASIPithos *)aPithos {
54
- (id)initWithPithosAccountManager:(PithosAccount *)aPithosAccountManager {
55 55
    if ((self = [super initWithPithosAccountManager:aPithosAccountManager])) {
56
        pithos = aPithos;
57 56
        self.sharingAccount = @"";
58 57
    }
59 58
    return self;
......
64 63
}
65 64

  
66 65
#pragma mark -
67
#pragma mark Properties
66
#pragma mark Actions
68 67

  
69
- (void)setPithos:(ASIPithos *)aPithos {
70
    if (aPithos && ![aPithos isEqualTo:pithos]) {
71
        pithos = aPithos;
72
        url = nil;
73
        [sharingAccountsRequest clearDelegatesAndCancel];
74
        self.sharingAccountsRequest = nil;
75
        reset = YES;
76
    }
68
- (void)reset {
69
    [sharingAccountsRequest clearDelegatesAndCancel];
70
    self.sharingAccountsRequest = nil;
71
    children = nil;
72
    newChildren = nil;
73
    freshness = PithosNodeStateRefreshNeeded;
74
    forcedRefresh = YES;
75
    [self postChildrenUpdatedNotificationName];
76
    [self children];
77 77
}
78 78

  
79
#pragma mark -
80
#pragma mark Properties
81

  
79 82
- (NSString *)url {
80
    if (url == nil) 
81
        url = [[pithos.storageURLPrefix description] copy];
82
    return url;
83
    return @"@sharing accounts@";
83 84
}
84 85

  
85 86
- (NSArray *)children {
86 87
    @synchronized(self) {
87
        if (reset) {
88
            [sharingAccountsRequest clearDelegatesAndCancel];
89
            self.sharingAccountsRequest = nil;
90
            children = nil;
91
            newChildren = nil;
92
            freshness = PithosNodeStateRefreshNeeded;
93
            forcedRefresh = YES;
94
            reset = NO;
95
            [self postChildrenUpdatedNotificationName];
96
        }
97 88
        switch (freshness) {
98 89
            case PithosNodeStateFresh:
99 90
                break;
100 91
            case PithosNodeStateRefreshNeeded:
101 92
                freshness = PithosNodeStateRefreshing;
102
                self.sharingAccountsRequest = [ASIPithosRequest listSharingAccountsRequestWithPithos:pithos limit:0 marker:nil];
93
                self.sharingAccountsRequest = [ASIPithosRequest listSharingAccountsRequestWithPithos:pithosAccountManager.pithos limit:0 marker:nil];
103 94
                sharingAccountsRequest.delegate = self;
104 95
                sharingAccountsRequest.didFinishSelector = @selector(performRequestFinishedDelegateInBackground:);
105 96
                sharingAccountsRequest.didFailSelector = @selector(performRequestFailedDelegateInBackground:);
......
186 177
                    newChildren = [[NSMutableArray alloc] init];
187 178
                    NSMutableIndexSet *keptNodes = [NSMutableIndexSet indexSet];
188 179
                    for (ASIPithosAccount *account in sharingAccounts) {
189
                        if (![account.name isEqualToString:pithos.authUser]) {
190
                            PithosAccountNode *node = [[PithosAccountNode alloc] initWithPithosAccountManager:pithosAccountManager
191
                                                                                                    andPithos:pithos];
180
                        if (![account.name isEqualToString:pithosAccountManager.pithos.authUser]) {
181
                            PithosAccountNode *node = [[PithosAccountNode alloc] initWithPithosAccountManager:pithosAccountManager];
192 182
                            node.parent = self;
193 183
                            node.shared = shared;
194 184
                            node.sharingAccount = account.name;
......
226 216
                [self postChildrenUpdatedNotificationName];
227 217
            } else {
228 218
                // Do an additional request to fetch more objects
229
                self.sharingAccountsRequest = [ASIPithosRequest listSharingAccountsRequestWithPithos:pithos
219
                self.sharingAccountsRequest = [ASIPithosRequest listSharingAccountsRequestWithPithos:pithosAccountManager.pithos
230 220
                                                                                               limit:0
231 221
                                                                                              marker:[[someSharingAccounts lastObject] name]];
232 222
                sharingAccountsRequest.delegate = self;

Also available in: Unified diff