Revision cb6abe72 pithos-macos/PithosAccount.m

b/pithos-macos/PithosAccount.m
57 57
#pragma mark Object Lifecycle
58 58

  
59 59
+ (id)pithosAccount {
60
    PithosAccount *pithosAccount = [[[self alloc] init] autorelease];
60
    PithosAccount *pithosAccount = [[self alloc] init];
61 61
    pithosAccount.uniqueName = [NSString stringWithFormat:@"pithosAccount-%f", [NSDate timeIntervalSinceReferenceDate]];
62 62
    pithosAccount.syncSkipHidden = YES;
63 63
    pithosAccount.versionResource = @"v1";
......
65 65
    return pithosAccount;
66 66
}
67 67

  
68
- (void)dealloc {
69
    [sharingAccountsNode release];
70
    [accountNode release];
71
    [pithos release];
72
    [publicURLPrefix release];
73
    [loginURLPrefix release];
74
    [authURL release];
75
    [storageURLPrefix release];
76
    [authToken release];
77
    [authUser release];
78
    [publicResource release];
79
    [loginResource release];
80
    [versionResource release];
81
    [serverURL release];
82
    [syncDaemon release];
83
    [syncLastCompleted release];
84
    [syncAccountsDictionary release];
85
    [syncDirectoryPath release];
86
    [name release];
87
    [uniqueName release];
88
    [super dealloc];
89
}
90 68

  
91 69
- (NSString *)description {
92 70
    return [NSString stringWithFormat:@"uniqueName: %@, active: %d, name: %@, syncActive: %d, syncDirectoryPath: %@, syncAccountsDictionary: %@, syncSkipHidden: %d, syncLastCompleted: %@, serverURL: %@, versionResource: %@, loginResource: %@, publicResource: %@, authUser: %@, authToken: %@, storageURLPrefix: %@, authURL: %@, loginURLPrefix: %@, publicURLPrefix: %@", 
......
110 88

  
111 89
- (NSString *)name {
112 90
    if (![name length]) {
113
        [name release];
114 91
        NSDictionary *pithosAccountsDictionary = [(pithos_macosAppDelegate *)[[NSApplication sharedApplication] delegate] pithosAccountsDictionary];
115 92
        NSString *namePrefix = @"okeanos";
116 93
        NSUInteger nameSuffix = 1;
......
121 98
               [fileManager fileExistsAtPath:[documentsDirectoryPath stringByAppendingPathComponent:name]]) {
122 99
            name = [NSString stringWithFormat:@"%@%ld", namePrefix, ++nameSuffix];
123 100
        }
124
        [name retain];
125 101
    }
126 102
    return name;
127 103
}
......
131 107
    if (![self.name isEqualToString:aName] && [aName length] && ![pithosAccountsDictionary objectForKey:aName]) {
132 108
        [pithosAccountsDictionary setObject:self forKey:aName];
133 109
        [pithosAccountsDictionary removeObjectForKey:name];
134
        [name release];
135
        name = [aName retain];
110
        name = aName;
136 111
    }
137 112
}
138 113

  
......
151 126

  
152 127
- (NSString *)syncDirectoryPath {
153 128
    if (![syncDirectoryPath length]) {
154
        [syncDirectoryPath release];
155
        syncDirectoryPath = [[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] 
156
                              stringByAppendingPathComponent:self.name] retain];
129
        syncDirectoryPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] 
130
                              stringByAppendingPathComponent:self.name];
157 131
    }
158 132
    return syncDirectoryPath;
159 133
}
......
162 136
    if (![self.syncDirectoryPath isEqualToString:aSyncDirectoryPath] && [aSyncDirectoryPath length]) {
163 137
        BOOL isDirectory;
164 138
        if (![[NSFileManager defaultManager] fileExistsAtPath:aSyncDirectoryPath isDirectory:&isDirectory] || isDirectory) {
165
            [syncDirectoryPath release];
166
            syncDirectoryPath = [aSyncDirectoryPath retain];
139
            syncDirectoryPath = aSyncDirectoryPath;
167 140
        } else {
168 141
            return;
169 142
        }
170 143

  
171 144
        @synchronized(self) {
172 145
            resetSyncDaemonLocalState = YES;
173
            [syncLastCompleted release];
174 146
            syncLastCompleted = nil;
175 147
        }
176 148
    }
......
178 150

  
179 151
- (NSMutableDictionary *)syncAccountsDictionary {
180 152
    if (!syncAccountsDictionary) {
181
        syncAccountsDictionary = [[NSMutableDictionary dictionaryWithObject:[NSMutableDictionary dictionaryWithObject:[NSMutableSet set] 
153
        syncAccountsDictionary = [NSMutableDictionary dictionaryWithObject:[NSMutableDictionary dictionaryWithObject:[NSMutableSet set] 
182 154
                                                                                                               forKey:@"pithos"] 
183
                                                                     forKey:@""] retain];
155
                                                                     forKey:@""];
184 156
    }        
185 157
    return syncAccountsDictionary;
186 158
}
187 159

  
188 160
- (void)setSyncAccountsDictionary:(NSMutableDictionary *)aSyncAccountsDictionary {
189 161
    if (aSyncAccountsDictionary && ![self.syncAccountsDictionary isEqualToDictionary:aSyncAccountsDictionary]) {
190
        [syncAccountsDictionary release];
191 162
        syncAccountsDictionary = [[NSMutableDictionary alloc] initWithCapacity:[aSyncAccountsDictionary count]];
192 163
        for (NSString *accountName in aSyncAccountsDictionary) {
193 164
            NSDictionary *aSyncContainersDictionary = [aSyncAccountsDictionary objectForKey:accountName];
......
203 174
        
204 175
        @synchronized(self) {
205 176
            resetSyncDaemonLocalState = YES;
206
            [syncLastCompleted release];
207 177
            syncLastCompleted = nil;
208 178
        }
209 179
    }
......
211 181

  
212 182
- (NSDate *)syncLastCompleted {
213 183
    if (self.syncDaemon.lastCompletedSync && ![self.syncDaemon.lastCompletedSync isEqualToDate:syncLastCompleted]) {
214
        [syncLastCompleted release];
215 184
        syncLastCompleted = [self.syncDaemon.lastCompletedSync copy];
216 185
    }
217 186
    return syncLastCompleted;
......
232 201

  
233 202
- (NSString *)serverURL {
234 203
    if (![self urlIsValid:serverURL]) {
235
        [serverURL release];
236
        serverURL = [@"https://pithos.okeanos.grnet.gr" retain];
204
        serverURL = @"https://pithos.okeanos.grnet.gr";
237 205
    }
238 206
    return serverURL;
239 207
}
240 208

  
241 209
- (void)setServerURL:(NSString *)aServerURL {
242 210
    if (![self.serverURL isEqualToString:aServerURL] && [self urlIsValid:aServerURL]) {
243
        [serverURL release];
244
        serverURL = [aServerURL retain];
245
        [storageURLPrefix release];
211
        serverURL = aServerURL;
246 212
        storageURLPrefix = nil;
247
        [authURL release];
248 213
        authURL = nil;
249
        [publicURLPrefix release];
250 214
        publicURLPrefix = nil;
251
        [loginURLPrefix release];
252 215
        loginURLPrefix = nil;
253 216

  
254 217
        @synchronized(self) {
255 218
            updatePithos = YES;
256 219
            resetSyncDaemonLocalState = YES;
257
            [syncLastCompleted release];
258 220
            syncLastCompleted = nil;
259 221
        }
260 222
    }
......
262 224

  
263 225
- (void)setAuthUser:(NSString *)anAuthUser {
264 226
    if ([anAuthUser length] && ![anAuthUser isEqualToString:authUser]) {
265
        [authUser release];
266
        authUser = [anAuthUser retain];
227
        authUser = anAuthUser;
267 228
        
268 229
        @synchronized(self) {
269 230
            updatePithos = YES;
270 231
            resetSyncDaemonLocalState = YES;
271
            [syncLastCompleted release];
272 232
            syncLastCompleted = nil;
273 233

  
274 234
        }
......
277 237

  
278 238
- (void)setAuthToken:(NSString *)anAuthToken {
279 239
    if ([anAuthToken length] && ![anAuthToken isEqualToString:authToken]) {
280
        [authToken release];
281
        authToken = [anAuthToken retain];
240
        authToken = anAuthToken;
282 241
        
283 242
        @synchronized(self) {
284 243
            updatePithos = YES;
......
288 247

  
289 248
- (NSString *)storageURLPrefix {
290 249
    if (![self urlIsValid:storageURLPrefix]) {
291
        [storageURLPrefix release];
292 250
        if (versionResource)
293
            storageURLPrefix = [[self.serverURL stringByAppendingFormat:@"/%@", versionResource] retain];
251
            storageURLPrefix = [self.serverURL stringByAppendingFormat:@"/%@", versionResource];
294 252
        else
295 253
            storageURLPrefix = [self.serverURL copy];
296 254
    }
......
299 257

  
300 258
- (void)setStorageURLPrefix:(NSString *)aStorageURLPrefix {
301 259
    if (![self.storageURLPrefix isEqualToString:aStorageURLPrefix] && [self urlIsValid:aStorageURLPrefix]) {
302
        [storageURLPrefix release];
303
        storageURLPrefix = [aStorageURLPrefix retain];
260
        storageURLPrefix = aStorageURLPrefix;
304 261
    }
305 262
}
306 263

  
307 264
- (NSString *)authURL {
308 265
    if (![self urlIsValid:authURL]) {
309
        [authURL release];
310 266
        if (versionResource)
311
            authURL = [[self.serverURL stringByAppendingFormat:@"/%@", versionResource] retain];
267
            authURL = [self.serverURL stringByAppendingFormat:@"/%@", versionResource];
312 268
        else
313 269
            authURL = [self.serverURL copy];
314 270
    }
......
317 273

  
318 274
- (void)setAuthURL:(NSString *)anAuthURL {
319 275
    if (![self.authURL isEqualToString:anAuthURL] && [self urlIsValid:anAuthURL]) {
320
        [authURL release];
321
        authURL = [anAuthURL retain];
276
        authURL = anAuthURL;
322 277
    }
323 278
}
324 279

  
325 280
- (NSString *)publicURLPrefix {
326 281
    if (![self urlIsValid:publicURLPrefix]) {
327
        [publicURLPrefix release];
328 282
        if (publicResource)
329
            publicURLPrefix = [[self.serverURL stringByAppendingFormat:@"/%@", publicResource] retain];
283
            publicURLPrefix = [self.serverURL stringByAppendingFormat:@"/%@", publicResource];
330 284
        else
331 285
            publicURLPrefix = [self.serverURL copy];
332 286
    }
......
335 289

  
336 290
- (void)setPublicURLPrefix:(NSString *)aPublicURLPrefix {
337 291
    if (![self.publicURLPrefix isEqualToString:aPublicURLPrefix] && [self urlIsValid:aPublicURLPrefix]) {
338
        [publicURLPrefix release];
339
        publicURLPrefix = [aPublicURLPrefix retain];
292
        publicURLPrefix = aPublicURLPrefix;
340 293
    }
341 294
}
342 295

  
343 296
- (NSString *)loginURLPrefix {
344 297
    if (![self urlIsValid:loginURLPrefix]) {
345
        [loginURLPrefix release];
346 298
        if (loginResource)
347
            loginURLPrefix = [[self.serverURL stringByAppendingFormat:@"/%@", loginResource] retain];
299
            loginURLPrefix = [self.serverURL stringByAppendingFormat:@"/%@", loginResource];
348 300
        else
349 301
            loginURLPrefix = [self.serverURL copy];
350 302
    }
......
353 305

  
354 306
- (void)setLoginURLPrefix:(NSString *)aLoginURLPrefix {
355 307
    if (![self.loginURLPrefix isEqualToString:aLoginURLPrefix] && [self urlIsValid:aLoginURLPrefix]) {
356
        [loginURLPrefix release];
357
        loginURLPrefix = [aLoginURLPrefix retain];
308
        loginURLPrefix = aLoginURLPrefix;
358 309
    }
359 310
}
360 311

  
361 312
- (ASIPithos *)pithos {
362 313
    @synchronized(self) {
363 314
        if (!pithos || updatePithos) {
364
            [pithos release];
365
            pithos = [[ASIPithos pithos] retain];
315
            pithos = [ASIPithos pithos];
366 316
            pithos.authUser = authUser;
367 317
            pithos.authToken = authToken;
368 318
            pithos.storageURLPrefix = self.storageURLPrefix;
......
458 408
    if ((self = [super init])) {
459 409
        self.uniqueName = [decoder decodeObjectForKey:@"uniqueName"];
460 410
        self.active = [decoder decodeBoolForKey:@"active"];
461
        name = [[decoder decodeObjectForKey:@"name"] retain];
411
        name = [decoder decodeObjectForKey:@"name"];
462 412

  
463 413
        self.syncActive = [decoder decodeBoolForKey:@"syncActive"];
464 414
        self.syncDirectoryPath = [decoder decodeObjectForKey:@"syncDirectoryPath"];

Also available in: Unified diff