'From etoys4.0 of 9 October 2008 [latest update: #2310] on 16 September 2009 at 11:29:25 pm'! "Change Set: cacheCats-bf Date: 16 September 2009 Author: Bert Freudenberg Cache squeakland categories on file. Update after logging in to showcase"! !EToyProjectDetailsMorph methodsFor: 'utilities' stamp: 'bf 9/16/2009 19:01'! choicesFor: aSymbol "Answer the list of choices to offer for the given symbol, which will be subject, age, or region. Answer nil if the symbol provided is one without enumerated choices." aSymbol = #subject ifTrue: [^ self class subjectTriplets]. aSymbol = #age ifTrue: [^ self class ageTriplets]. aSymbol = #region ifTrue: [^ self class regionTriplets]. ^ nil! ! !EToyProjectDetailsMorph class methodsFor: 'as yet unclassified' stamp: 'bf 9/16/2009 18:42'! getFullInfoFor: aProject ifValid: aBlock expandedFormat: expandedFormat "Obtain project info for the project by putting up a dialog-box showing current values for the various project-info variables and allowing the user to change the data." | me | (me := self basicNew) expandedFormat: expandedFormat; project: aProject actionBlock: [ :x | aProject world setProperty: #ProjectDetails toValue: x. x at: 'projectname' ifPresent: [ :newName | aProject renameTo: newName. ]. me delete. aBlock value. ]; initialize; becomeModal; beSticky; openCenteredInWorld! ! !EToyProjectDetailsMorph class methodsFor: 'classification information' stamp: 'bf 9/16/2009 19:57'! cachedTripletsFor: aCategory "Load triplets from file, e.g. '.ageCatList-de.csv' for the 'age' category" | file | [ file := FileStream readOnlyFileNamed: (self tripletsFileNameFor: aCategory). [^self tripletsFrom: file contentsOfEntireFile] ensure: [file close]. ] ifError: []. ^nil ! ! !EToyProjectDetailsMorph class methodsFor: 'classification information' stamp: 'bf 9/16/2009 19:43'! tripletsFileNameFor: aCategory "self tripletsFileNameFor: #age" ^ '.', aCategory, 'CatList-', Locale current localeID printString, '.csv' ! ! !EToyProjectDetailsMorph class methodsFor: 'classification information' stamp: 'bf 9/16/2009 19:54'! tripletsFrom: csvString | result | [result := (self linesIn: (csvString copyReplaceAll: String lf with: String cr)) collect: [:l | self csvLineQuotedDecodedFor: l] ] on: Error do: [:ex | ^ nil]. (self validateCategoryTriplets: result) ifFalse: [^ nil]. ^result. ! ! !EToyProjectDetailsMorph class methodsFor: 'classification information' stamp: 'bf 9/16/2009 19:43'! tripletsUrlFor: aCategory "self tripletsUrlFor: #age" ^'http://squeakland.org/', aCategory, 'CatList?lang=', Locale current localeID printString! ! !EToyProjectDetailsMorph class methodsFor: 'classification information' stamp: 'bf 9/16/2009 23:00'! updateTripletsFor: aCategory "Fetch the age-range, subject, or region triplet files from the web site and cache them locally." | contents triplets file | contents := (HTTPSocket httpGet: (self tripletsUrlFor: aCategory) args: #() user: '' passwd: '') contents. triplets := self tripletsFrom: contents. triplets ifNotNil: [ self useTriplets: triplets for: aCategory. file := FileStream fileNamed: (self tripletsFileNameFor: aCategory). [file nextPutAll: contents] ensure: [file close]. ]. ! ! !EToyProjectDetailsMorph class methodsFor: 'classification information' stamp: 'bf 9/16/2009 22:49'! updateTripletsFromWebSite "Attempt to update the age-range, subject, and region triplets cache on file by looking for the latest versions on the web site." #(age subject region) do: [:cat | self updateTripletsFor: cat]! ! !EToyProjectDetailsMorph class methodsFor: 'classification information' stamp: 'bf 9/16/2009 23:24'! updateTripletsFromWebSiteInBackground [ [self updateTripletsFromWebSite] ifError: [] ] forkAt: Processor userBackgroundPriority named: 'Etoys category updater'! ! !EToyProjectDetailsMorph class methodsFor: 'class initialization' stamp: 'bf 9/16/2009 19:45'! initialize self startUp: true. Smalltalk addToStartUpList: self. ! ! !EToyProjectDetailsMorph class methodsFor: 'class initialization' stamp: 'bf 9/16/2009 19:25'! unload Smalltalk removeFromStartUpList: self! ! !EToyProjectDetailsMorph class methodsFor: 'classification accessing' stamp: 'bf 9/16/2009 19:48'! ageTriplets "Answer a list of the triplets characterizing the 'age' categories; each triplet is of the form ( )" ^ AgeTriplets ifNil: [ AgeTriplets := (self cachedTripletsFor: #age) ifNil: [self defaultAgeTriplets]]! ! !EToyProjectDetailsMorph class methodsFor: 'classification accessing' stamp: 'bf 9/16/2009 19:48'! regionTriplets "Answer a list of triplets of the form (numberCode stringCode englishName) for the regions." ^ RegionTriplets ifNil: [ RegionTriplets := (self cachedTripletsFor: #region) ifNil: [self defaultRegionTriplets]]! ! !EToyProjectDetailsMorph class methodsFor: 'classification accessing' stamp: 'bf 9/16/2009 19:49'! subjectTriplets "Answer a list of triplets characterizing the subjects in the current taxonomy." ^ SubjectTriplets ifNil: [ SubjectTriplets := (self cachedTripletsFor: #subject) ifNil: [self defaultSubjectTriplets]]! ! !EToyProjectDetailsMorph class methodsFor: 'classification accessing' stamp: 'bf 9/16/2009 22:54'! useTriplets: triplets for: aCategory aCategory = #age ifTrue: [AgeTriplets := triplets]. aCategory = #subject ifTrue: [SubjectTriplets := triplets]. aCategory = #region ifTrue: [RegionTriplets := triplets].! ! !EToyProjectDetailsMorph class methodsFor: 'system startup' stamp: 'bf 9/16/2009 19:50'! startUp: resuming resuming ifTrue: [ "Make sure we try cached versions" SubjectTriplets := AgeTriplets := RegionTriplets := nil. ]! ! !FileList2 methodsFor: 'private' stamp: 'bf 9/16/2009 23:25'! loginHit | s failed ret | loginDialog ifNotNil: [^ false]. s := ServerDirectory servers at: 'My Squeakland' ifAbsent: [^ false]. failed := [Utilities loggedIn: false. loginDialog := nil. s user: nil]. ret := true. loginDialog := EtoyDAVLoginMorph new. loginDialog loginAndDo: [:n :p | s ifNotNil: [ s user: n. s password: p. [s copy createPersonalDirectory: n] on: ProtocolClientError do: [:ex | "either directory already exists or could not create. Here, it is just eaten as the following test will tell us whether it can be read."]. [s entries] on: LoginFailedException do: [:ex | failed value. self inform: 'Login failed.'. ret := false]. ret ifTrue: [Utilities authorName: n. Utilities loggedIn: true]]. self updateLoginButtonAppearance. Utilities loggedIn ifTrue: [ self directory: directory. brevityState := #FileList. "self addPath: path." self changed: #fileList. self changed: #contents. self changed: #currentDirectorySelected. EToyProjectDetailsMorph updateTripletsFromWebSiteInBackground. ]. loginDialog := nil. true. ] ifCanceled: failed. ! ! EToyProjectDetailsMorph initialize! EToyProjectDetailsMorph class removeSelector: #webTripletsFor:! EToyProjectDetailsMorph removeSelector: #ageTriplets! EToyProjectDetailsMorph removeSelector: #regionTriplets! EToyProjectDetailsMorph removeSelector: #subjectTriplets! !EToyProjectDetailsMorph reorganize! ('expand' doExpand expandButton expandedFormat expandedFormat:) ('initialization' project:actionBlock: rebuild) ('project details' copyOutDetails fieldToDetailsMappings fillInDetails projectDetails:) ('utilities' choicesFor: doOK doPopUp:event:for: popUpEntryNamed: popUpEntryNamed:menuTitle: setInfoField:to:) !