'From OLPC2.0 of ''24 October 2006'' [latest update: #1468] on 27 July 2007 at 5:52:35 pm'! "Change Set: resumeFix-bf Date: 29 July 2007 Author: Bert Freudenberg Cross-published from olpc2.0 update 1469resumeFix-bf. "! !SugarDatastoreDirectory methodsFor: 'file directory' stamp: 'bf 7/27/2007 15:28'! readOnlyFileNamed: aName "aName contains the object id as last 36 chars before the extension" | id | id := (aName allButLast: self extension size) last: 36. ^SugarLauncher current getFile: id. ! ! !SugarLauncher methodsFor: 'dbus' stamp: 'bf 7/27/2007 15:12'! sendDBusMessage: aMessage "send aMessage synchronously, wait until a response comes back. Answer reply message, or raise an error if send failed or timed out" ^self sendDBusMessage: aMessage timeout: 20! ! !SugarLauncher methodsFor: 'dbus' stamp: 'bf 7/27/2007 15:17'! sendDBusMessage: aMessage onSuccess: successBlock onError: errorBlock "send aMessage asynchronously, evaluate successBlock or errorBlock with the reply message once a response comes back. Does not handle timeout!!" | replyCode | replyCode := dbus sendMessage: aMessage. handlers at: replyCode put: {successBlock. errorBlock}. WorldState addDeferredUIMessage: [Transcript cr; show: aMessage]. ! ! !SugarLauncher methodsFor: 'dbus' stamp: 'bf 7/27/2007 15:12'! sendDBusMessage: aMessage timeout: seconds "send aMessage synchronously, wait until a response comes back or timeout seconds have passed. Answer reply message, or raise an error if send failed or timed out" | milli sema reply | sema := Semaphore new. milli := (seconds * 1000) asInteger. milli > 0 ifTrue: [Delay timeoutSemaphore: sema afterMSecs: milli]. self sendDBusMessage: aMessage onSuccess: [:msg | reply := msg. sema signal] onError: [:err | reply := err. sema signal]. sema wait. reply ifNil: [^self error: 'dbus send timed out' translated]. reply isError ifTrue: [^self error: reply asString]. ^reply! ! !SugarLauncher methodsFor: 'datastore' stamp: 'bf 7/27/2007 16:55'! handleStream: tmpStream mimetype: mimetype titled: title "tmpStream was loaded from journal, is not a project, do something sensible" "this ignores the mimetype, we really should do better ..." [ [(ExternalDropHandler lookupExternalDropHandler: tmpStream) handle: tmpStream in: World dropEvent: ActiveHand lastEvent] ifError: [self inform: ('Cannot open {1}' translated withCRs format: {title})] ] ensure: [tmpStream close].! ! !SugarLauncher methodsFor: 'datastore' stamp: 'bf 7/27/2007 17:52'! resumeJournalEntry: id | props file title project mimetype | props := self getProperties: id. title := (props at: 'title' ifAbsent: ['untitled' translated]) utf8ToSqueak. mimetype := props at: 'mime_type' ifAbsent: ['']. mimetype isEmpty ifTrue: [^self welcome: '']. mimetype = 'application/x-squeak-project' ifFalse: [ WorldState addDeferredUIMessage: [ ActiveHand lastEvent position: World center. Utilities informUser: 'Opening journal entry' translated, String cr, (title copyReplaceAll: String lf with: String cr) during: [file := self getFile: id]. self handleStream: file mimetype: mimetype titled: title]. ^Project enterNew]. ProjectLoading showProgressBarDuring: [ Display fillWhite;forceToScreen. file := self getFile: id. "load project and close temp file (which will thus be deleted)" project := ProjectLoading loadName: ((title copyReplaceAll: '/' with: '\') contractTo: 64) stream: file fromDirectory: nil withProjectView: nil. file close. project projectParameterAt: #sugarId put: id. project enter]. ! ! !SugarLauncher methodsFor: 'presence' stamp: 'bf 7/27/2007 15:26'! buddiesFromDBus | reply buddiePathes | reply := self sendDBusMessage: (DBusMessageMethodCall destination: 'org.laptop.Sugar.Presence' path: '/org/laptop/Sugar/Presence' interface: 'org.laptop.Sugar.Presence' selector: 'GetBuddies'). buddiePathes := reply arguments first fromDBusArgument. ^buddiePathes collect: [:objPath | reply := self sendDBusMessage: (DBusMessageMethodCall destination: 'org.laptop.Sugar.Presence' path: objPath interface: 'org.laptop.Sugar.Presence.Buddy' selector: 'GetProperties'). SugarBuddy fromDictionary: reply arguments first fromDBusArgument]! ! SugarLauncher removeSelector: #handleStream:mimetype:! SugarLauncher removeSelector: #sendDBusMessage:timeoutSeconds:!