Skip to content
Browse files

methods for reporting and tracking status

  • Loading branch information...
1 parent 31f20f7 commit 58a1b452f1328cc600446d833e17d046bfd176d1 Zachary Schneirov committed Jan 31, 2010
Showing with 79 additions and 8 deletions.
  1. +8 −1 SimplenoteEntryCollector.h
  2. +47 −1 SimplenoteEntryCollector.m
  3. +24 −6 SyncServiceSessionProtocol.h
View
9 SimplenoteEntryCollector.h
@@ -8,11 +8,13 @@
#import <Cocoa/Cocoa.h>
+#import "SyncServiceSessionProtocol.h"
+
@class NoteObject;
@class DeletedNoteObject;
@class SyncResponseFetcher;
-@interface SimplenoteEntryCollector : NSObject {
+@interface SimplenoteEntryCollector : NSObject <SyncServiceTask> {
NSArray *entriesToCollect;
NSMutableArray *entriesCollected, *entriesInError;
NSUInteger entryFinishedCount;
@@ -27,12 +29,17 @@
- (id)initWithEntriesToCollect:(NSArray*)wantedEntries authToken:(NSString*)anAuthToken email:(NSString*)anEmail;
+- (NSArray*)entriesToCollect;
- (NSArray*)entriesCollected;
- (NSArray*)entriesInError;
- (void)stop;
- (BOOL)collectionStarted;
+- (BOOL)collectionStoppedPrematurely;
+
+- (NSString*)localizedActionDescription;
+
- (void)startCollectingWithCallback:(SEL)aSEL collectionDelegate:(id)aDelegate;
- (SyncResponseFetcher*)fetcherForEntry:(id)anEntry;
View
48 SimplenoteEntryCollector.m
@@ -6,6 +6,7 @@
// Copyright 2009 Zachary Schneirov. All rights reserved.
//
+#import "GlobalPrefs.h"
#import "SimplenoteEntryCollector.h"
#import "SyncResponseFetcher.h"
#import "SimplenoteSession.h"
@@ -35,6 +36,10 @@ - (id)initWithEntriesToCollect:(NSArray*)wantedEntries authToken:(NSString*)anAu
return self;
}
+- (NSArray*)entriesToCollect {
+ return entriesToCollect;
+}
+
- (NSArray*)entriesCollected {
return entriesCollected;
}
@@ -46,6 +51,10 @@ - (BOOL)collectionStarted {
return entryFinishedCount != 0;
}
+- (BOOL)collectionStoppedPrematurely {
+ return stopped;
+}
+
- (void)setRepresentedObject:(id)anObject {
[representedObject autorelease];
representedObject = [anObject retain];
@@ -65,6 +74,19 @@ - (void)dealloc {
[super dealloc];
}
+- (NSString*)statusText {
+ return [NSString stringWithFormat:NSLocalizedString(@"Downloading %u of %u notes", @"status text when downloading a note from the remote sync server"),
+ entryFinishedCount, [entriesToCollect count]];
+}
+
+- (SyncResponseFetcher*)currentFetcher {
+ return currentFetcher;
+}
+
+- (NSString*)localizedActionDescription {
+ return NSLocalizedString(@"Downloading", nil);
+}
+
- (void)stop {
stopped = YES;
@@ -114,7 +136,7 @@ - (NSDictionary*)preparedDictionaryWithFetcher:(SyncResponseFetcher*)fetcher rec
if ([[fetcher representedObject] conformsToProtocol:@protocol(SynchronizedNote)]) [entry setObject:[fetcher representedObject] forKey:@"NoteObject"];
[entry setObject:bodyString forKey:@"content"];
- NSLog(@"fetched entry %@" , entry);
+ //NSLog(@"fetched entry %@" , entry);
return entry;
}
@@ -149,6 +171,7 @@ - (void)syncResponseFetcher:(SyncResponseFetcher*)fetcher receivedData:(NSData*)
@implementation SimplenoteEntryModifier
+//TODO:
//if modification or creation date is 0, set it to the most recent time as parsed from the HTTP response headers
//when updating notes, sync times will be set to 0 when they are older than the time of the last HTTP header date
//which will be stored in notePrefs as part of the simplenote service dict
@@ -227,6 +250,28 @@ - (SyncResponseFetcher*)fetcherForDeletingNote:(DeletedNoteObject*)aDeletedNote
return nil;
}
+- (NSString*)localizedActionDescription {
+ return (@selector(fetcherForCreatingNote:) == fetcherOpSEL ? NSLocalizedString(@"Creating", nil) :
+ (@selector(fetcherForUpdatingNote:) == fetcherOpSEL ? NSLocalizedString(@"Updating",nil) :
+ (@selector(fetcherForDeletingNote:) == fetcherOpSEL ? NSLocalizedString(@"Deleting", nil) : NSLocalizedString(@"Processing", nil)) ));
+}
+
+- (NSString*)statusText {
+ NSString *opName = [self localizedActionDescription];
+ if ([entriesToCollect count] == 1) {
+ NoteObject *aNote = [currentFetcher representedObject];
+ if ([aNote isKindOfClass:[NoteObject class]]) {
+ return [NSString stringWithFormat:NSLocalizedString(@"%@ quot%@quot...",@"example: Updating 'joe shmoe note'"), opName, titleOfNote(aNote)];
+ } else {
+ return NSLocalizedString(@"Deleting a note...", nil);
+ }
+ }
+ return [NSString stringWithFormat:NSLocalizedString(@"%@ %u of %u notes", @"Downloading/Creating/Updating/Deleting 5 of 10 notes"),
+ opName, entryFinishedCount, [entriesToCollect count]];
+}
+
+#if 0 /* allowing creation to complete will be of no use when the note's
+ delegate notationcontroller has closed its WAL and DB, and as it is unretained can cause a crash */
- (void)stop {
//cancel the current fetcher only if it is not a creator-fetcher; otherwise we risk it finishing without fully receiving notification of its sucess
if (@selector(fetcherForCreatingNote:) == fetcherOpSEL) {
@@ -236,6 +281,7 @@ - (void)stop {
[super stop];
}
}
+#endif
- (NSDictionary*)preparedDictionaryWithFetcher:(SyncResponseFetcher*)fetcher receivedData:(NSData*)data {
NSString *keyString = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
View
30 SyncServiceSessionProtocol.h
@@ -25,16 +25,25 @@
- (BOOL)remoteEntryWasMarkedDeleted:(NSDictionary*)remoteEntry;
+ (void)registerLocalModificationForNote:(id <SynchronizedNote>)aNote;
+- (NSString*)statusText;
+- (NSSet*)activeTasks;
- (void)stop;
+- (BOOL)isRunning;
+- (NSString*)lastError;
- (void)schedulePushForNote:(id <SynchronizedNote>)aNote;
+//any DB modifications that will trigger a push must be wrapped in suppress messages to the service
+//for added notes, this is done in the callback before actually adding them to allNotes
+//for updated notes this is done by the session itself, because it does the updating
+//for removed notes this is done right before actually removing them from allNotes (-removeNotes:)
- (void)suppressPushingForNotes:(NSArray*)notes;
- (void)stopSuppressingPushingForNotes:(NSArray*)notes;
+- (BOOL)startFetchingListForFullSyncManual;
- (BOOL)startFetchingListForFullSync;
-- (void)startCollectingAddedNotesWithEntries:(NSArray*)entries mergingWithNotes:(NSArray*)someNotes;
+- (void)startCollectingAddedNotesWithEntries:(NSArray*)entries mergingWithNotes:(NSArray*)notesToMerge;
- (void)startCollectingChangedNotesWithEntries:(NSArray*)entries;
- (void)startDeletingNotes:(NSArray*)notes;
@@ -44,18 +53,27 @@
- (void)setDelegate:(id)aDelegate;
- (id)delegate;
+- (BOOL)pushSyncServiceChanges;
+- (BOOL)hasUnsyncedChanges;
+
+@end
+
+@protocol SyncServiceTask
+
+- (NSString*)statusText;
+- (SyncResponseFetcher*)currentFetcher;
+
@end
@interface NSObject (SyncServiceSessionDelegate)
-//for showing the progress of various operations
-//- (void)syncResponseFetcherStarted:(SyncResponseFetcher*)fetcher forService:(id <SyncServiceSession>)syncSession;
-//- (void)syncResponseFetcherStopped:(SyncResponseFetcher*)fetcher forService:(id <SyncServiceSession>)syncSession;
+- (void)syncSessionProgressStarted:(id <SyncServiceSession>)syncSession;
+- (void)syncSession:(id <SyncServiceSession>)syncSession didStopWithError:(NSString*)errString;
- (void)syncSession:(id <SyncServiceSession>)syncSession receivedFullNoteList:(NSArray*)allEntries;
- (void)syncSession:(id <SyncServiceSession>)syncSession receivedAddedNotes:(NSArray*)addedNotes;
- (void)syncSession:(id <SyncServiceSession>)syncSession didModifyNotes:(NSArray*)changedNotes;
+- (void)syncSessionDidFinishRemoteModifications:(id <SyncServiceSession>)syncSession;
-- (void)syncSessionDidFinishRemoteModifications:(id <SyncServiceSession>)syncSession;
-@end
+@end

0 comments on commit 58a1b45

Please sign in to comment.
Something went wrong with that request. Please try again.