'From etoys2.2 of 1 October 2007 [latest update: #1795] on 28 November 2007 at 10:54:03 am'! "Change Set: autoBuddy-yo-bf Date: 22 November 2007 Author: Bert Freudenberg Create buddy badges when someone joins the activity"! !SugarBuddy methodsFor: 'actions' stamp: 'yo 11/21/2007 13:23'! makeBadge | badge font ext | badge := EToySenderMorph new userName: nick userPicture: (self xoFormExtent: 61@53 background: Color veryVeryLightGray) userEmail: 'who@where.net' userIPAddress: ip; color: Color veryVeryLightGray; borderColor: Color gray. #( tellAFriend emailAddress startTelemorphic ipAddress checkOnAFriend ) do: [:ea | badge hideField: ea]. font := Preferences standardEToysFont. ext := (font widthOf: $m) + 2 @ font height. badge allMorphsDo: [:m | (m respondsTo: #font:) ifTrue: [m font: font]. (m class == SimpleButtonMorph) ifTrue: [m extent: ext]]. ^ badge.! ! !SugarBuddy methodsFor: 'actions' stamp: 'yo 11/21/2007 13:24'! openBadge ^ self makeBadge openInHand. ! ! !SugarBuddy class methodsFor: 'instance creation' stamp: 'yo 11/21/2007 13:24'! fromMesh | menu item | menu := MenuMorph new. (SugarLauncher current buddies asSortedCollection: [:a :b | a nick < b nick]) do: [:each | each isOwner ifFalse: [ menu add: each nick target: each selector: #openBadge. item := menu items last. item icon: (each xoFormExtent: (item height + 5) asPoint background: menu color)]]. menu popUpInWorld ! ! !SugarLauncher methodsFor: 'commands' stamp: 'yo 11/28/2007 10:47'! join "join a shared activity on startup" Utilities informUser: 'Joining activity ...' translated during: [ self joinSharedActivity. sharedActivity ifNotNil: [ SugarNavigatorBar current ifNotNilDo: [:bar | bar joinSharedActivity]]. self makeBadges. ]. ! ! !SugarLauncher methodsFor: 'commands' stamp: 'bf 11/23/2007 16:01'! share sharedActivity ifNotNil: [^self]. self enableSharedActivitySignals. sharedActivity := self shareActivityId: (parameters at: 'ACTIVITY_ID') bundleId: (parameters at: 'BUNDLE_ID') name: (self titleFromProject: Project current) squeakToUtf8 properties: Dictionary new. "due to bug 4660 we can't pass properties directly" self setSharedActivityProperties: ({'private' -> false} as: Dictionary).! ! !SugarLauncher methodsFor: 'dbus' stamp: 'bf 11/28/2007 17:48'! dbusMessageRegistry "automatically generated by (SugarLauncher compileDBusMessageRegistry)" ^#(#('org.laptop.Sugar.Presence.Activity' #(#('BuddyJoined' #handleBuddyJoined:) #('BuddyLeft' #handleBuddyLeft:))) #('org.freedesktop.DBus.Introspectable' #(#('Introspect' #handleDBusIntrospect:))) #('org.laptop.Activity' #(#('SetActive' #handleActivitySetActive:) #('TakeScreenshot' #handleTakeScreenshot:))))! ! !SugarLauncher methodsFor: 'dbus' stamp: 'bf 11/28/2007 17:44'! dbusSignalRegistry "If this method is changed, you need to run (SugarLauncher compileDBusMessageRegistry)" ^#( ('org.laptop.Sugar.Presence.Activity' ( ('BuddyJoined' handleBuddyJoined:) ('BuddyLeft' handleBuddyLeft:) ) ) )! ! !SugarLauncher methodsFor: 'dbus' stamp: 'bf 11/28/2007 18:48'! handleBuddyJoined: dbusSignal | buddyPath buddy | buddyPath := dbusSignal arguments first fromDBusArgument. buddy := self buddyFromPath: buddyPath. WorldState addDeferredUIMessage: [buddy makeBadge openInWorld]! ! !SugarLauncher methodsFor: 'dbus' stamp: 'bf 11/28/2007 18:49'! handleBuddyLeft: dbusSignal | buddyPath buddy | buddyPath := dbusSignal arguments first fromDBusArgument. buddy := self buddyFromPath: buddyPath. WorldState addDeferredUIMessage: [self inform: buddy nick, ' left']! ! !SugarLauncher methodsFor: 'presence' stamp: 'bf 11/28/2007 17:58'! buddyFromPath: buddyPath | reply | reply := self sendDBusMessage: (DBusMessageMethodCall destination: 'org.laptop.Sugar.Presence' path: buddyPath interface: 'org.laptop.Sugar.Presence.Buddy' selector: 'GetProperties'). ^SugarBuddy fromDictionary: reply arguments first fromDBusArgument ! ! !SugarLauncher methodsFor: 'presence' stamp: 'bf 11/28/2007 17:52'! enableSharedActivitySignals sharedActivity ifNil: [^self]. self dbusSignalRegistry do: [:interfaceSpec | interfaceSpec first = 'org.laptop.Sugar.Presence.Activity' ifTrue: [ interfaceSpec do: [:signalSpec | dbus addMatch: { #type. 'signal'. #path. sharedActivity. #interface. interfaceSpec first. #member. signalSpec first}]]]. ! ! !SugarLauncher methodsFor: 'presence' stamp: 'bf 11/28/2007 17:59'! getSharedActivityBuddies | reply buddiePathes | reply := self sendDBusMessage: (DBusMessageMethodCall destination: 'org.laptop.Sugar.Presence' path: sharedActivity interface: 'org.laptop.Sugar.Presence.Activity' selector: 'GetJoinedBuddies'). buddiePathes := reply arguments first fromDBusArgument. ^buddiePathes collect: [:objPath | self buddyFromPath: objPath]! ! !SugarLauncher methodsFor: 'presence' stamp: 'yo 11/28/2007 10:49'! makeBadges | container m | container _ Morph new. container layoutPolicy: TableLayout new. container color: Color orange muchLighter; listDirection: #leftToRight; hResizing: #shrinkWrap; vResizing: #shrinkWrap; cellInset: 10; layoutInset: 10. (self buddies asSortedCollection: [:a :b | a nick < b nick]) do: [:each | each isOwner ifFalse: [ m _ each makeBadge. container addMorph: m. ]. ]. container submorphs ifEmpty: [^ self]. container center: ActiveWorld center. container openInWorld. ! ! !SugarLauncher methodsFor: 'presence' stamp: 'bf 11/28/2007 18:00'! ownerFromDBus | reply ownerPath | reply := self sendDBusMessage: (DBusMessageMethodCall destination: 'org.laptop.Sugar.Presence' path: '/org/laptop/Sugar/Presence' interface: 'org.laptop.Sugar.Presence' selector: 'GetOwner'). ownerPath := reply arguments first fromDBusArgument. ^self buddyFromPath: ownerPath! ! !SugarLauncher class methodsFor: 'utilities' stamp: 'bf 11/28/2007 17:47'! compileDBusMessageRegistry "Whenever #introspect or #dbusSignalRegistry is changed, the registry needs to be updated" self compile: 'dbusMessageRegistry "automatically generated by (', self name,' compileDBusMessageRegistry)" ^', (self basicNew dbusSignalRegistry, ((XMLDOMParser parseDocumentFrom: self basicNew introspect readStream) elements first elements asArray collect: [:interface | {interface attributeAt: 'name'. interface elements asArray collect: [:method | {method attributeAt: 'name'. ((method elementAt: 'annotation') attributeAt: 'value') asSymbol}]}])) asString classified: 'dbus'! !