<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"><html><head><meta name="qrichtext" content="1" /><style type="text/css">p, li { white-space: pre-wrap; }</style></head><body style=" font-family:'Luxi Sans'; font-size:11pt; font-weight:400; font-style:normal;">Hi Bert,<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>After 3 weekend delay I got back today to FreeCell. I re-read the email thread and put together high level steps of how FreeCell's statistics state could be managed. I hope the steps are uderstandable, and realize architecturally it is not very nice, but a step.. <br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>Below, I am listing base code (additions and patches) that would plugin FreeCell into the workflow so that everything is in place where it's statistics state could be managed, serialized and stored in Datastore. Could you comment if the following would work as a first step to play with the Datastore stuff in FreeCell - Thanks. There are some questions at the end, and I appreciate any suggestions and alternatives :)<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p><p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>1) Patch SugarLauncher>>#startUp to call<br>
        self class allInstances do: [:ea| ea shutdown]. "is this neded?"<br>
        parameters at 'ACTIVITY_ID' ifPresent: [:activityId|<br>
                objectId := "todo get objectId".<br>
                "Make FreeCell and recover statistics from journal"<br>
                FreeCell class startUpInSugarForActivity: activityId object: objectId.<br>
                World windowEventHandler: self.<br>
        ].<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>        (A note: I realize you suggested to use FREECELL_ACTIVITY_ID and FREECELL_OBJECT_ID instead of ACTIVITY_ID and OBJECT_ID and then we would not have to patch SugarLauncher>>#startup, but it seems we probably need to patch some other SugarLauncher methods such as invite anyway, so I thought this could be ok)<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>2) Add method FreeCell class>>#startUpInSugarForActivity: activityId object: objectId<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p> which would perform the steps currently performed in the FreeCell.st doits:<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>        Project current flapsSurpressed: true.<br>
        World color: Color black.<br>
        FreeCell <br>
                instance <br>
                (recoverStatisticsOnSugarStartUpForActivity: activityId object: objectId)<br>
                openInWorld.<br>
        (... center and zoom to screen extent)<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>3) Add method FreeCell class>>#instance<br>
        FreeCellSingleton := FreeCell new. "just a class var"<br>
        ^ FreeCellSingleton.<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>4) Add method FreeCell>>#recoverStatisticsOnSugarStartUpForActivity: activityId object: objectId <br>
        this method is eventually called from patched SugarLauncher>>#startUp, and it would do:<br>
                - use activityId and objectId to read Datastore, and obtain value for key=serialized_statistics<br>
                - obtain sessionWins, sessionLosses, totalWins ... etc from serialized_statistics_value<br>
                - set the deserialized values on the FreeCellStatistics members. (This will need a simple setter of the statistics values)<br>
        <br>
5) Patch SugarLauncher>>#shutDown as follows:<br>
        activityId := parameters at: ACTIVITY_ID.<br>
        objectId := parameters at: OBJECT_ID.<br>
        freeCell := FreeCell instance.<br>
        freeCell #shutDownInSugarAsActivity: activityId object: objectId.<br>
        <br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>6) Add method FreeCell>>#shutDownInSugarAsActivity: activityId object: objectId <br>
        which would :<br>
                - serialize sessionWins, sessionLosses, totalWins ... etc to serialized_statistics_value<br>
                - put on Datastore, for activityId and objectId, an entry with key=serialized_statistics, value=serialized_statistics_value<br>
        <br>
7) Add method FreeCell>>#quit which would do:<br>
        Sugarlauncher current quit<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p><p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>8) Patch SugarLauncher>>#quit to call<br>
        self leaveSharedActivity. "is this needed?"<br>
        Smalltalk quitPrimitive. "i hope this calls shutDown?"<br>
        <br>
        FreeCell class startUpInSugar.<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>9) Export the changes to FreeCell.st. so it will contain roughtly:<br>
        - patches for:<br>
                - SugarLauncher>>#startUp <br>
                - SugarLauncher>>#shutDown <br>
                - SugarLauncher>>#quit<br>
                - FreeCell>>#quit<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>I did not run any of this .. this is my next step, but I wanted to run it by you for obvious problems, so:<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>Questions, comments and doubts:<br>
=============================<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>- Would this work in principal? I am especially not sure around handling the shutDown on quit.<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>- Are there better more elegant/reusable ways if someone else wants to do something similar to other Etoys activity (ZIP, Speach etc etc)?<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>- In step 6, what would be the mime type for the new datastore record, so it is associated with Etoys? There are Mime types listed in /usr/share/sugar/data/mime.defaults but it does not list Etoys...<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>- I need to check when etoys start SugarLauncher>>#startUp is performed when I click on a Journal FreeCell item, as startUp contains the FreeCell creation and initialization mechanism<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>- I cannot figure out which class puts the ACTIVITY_ID to AbstractLauncher>>member parameters, but that is not needed for the stuff above.<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>Thanks Milan<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>PS:<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>A few weeks ago I also investigated a way to make a Squeak based KDE4 Plasmoid ("applet" running in the Plasma container) and manage the Squeak Plasmoid only via DBus. It turns out that, for some likely misguided performance concerns, Plasmoids are not managed by their container via DBus, but rather internal Qt API. So what I thought would be neet is likely not possible without some sort of wrapper, and probably out of reach for practical time considerations, so I will ignore that part. (Maybe possible in gnome..)<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p><p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>=======================<br>
old part<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p><p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p><p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>On May 5, 2009, Bert Freudenberg wrote:<br>
> On 05.05.2009, at 07:27, Milan Zimmermann wrote:<br>
> > On May 4, 2009, Bert Freudenberg wrote:<br>
> > > On 04.05.2009, at 07:31, Milan Zimmermann wrote:<br>
> > > > Hi Bert,<br>
> > > ><br>
> > > > I finally did some investigation into Squeak interaction with<br>
> ><br>
> > DBus and<br>
> ><br>
> > > > Datastore. I went through the classes that implement the DBus and<br>
> > > > Datastore<br>
> > > > interaction. This is some great stuff! Among others, if I<br>
> ><br>
> > understand<br>
> ><br>
> > > > this correctly, your Squeak DBus client framework could, for<br>
> > > > example, allow to use Squeak to write a KDE or gnome panel applet?<br>
> > > > But that is an aside.<br>
> > ><br>
> > > Yes indeed.<br>
> ><br>
> > Very cool. I think such functionality could also add interest in<br>
> > Squeak... Would it makes sense to add Squeak to this list<br>
> ><br>
> > http://www.freedesktop.org/wiki/Software/DBusBindings<br>
> > ?<br>
><br>
> Yes. This would be the official page for it:<br>
><br>
> http://squeaksource.com/dbus.html<br>
><br>
> > > A fun way to explore it is to run Squeak on a regular KDE/<br>
> > > Gnome desktop and open the DBus Explorer from the World menu. You<br>
> ><br>
> > can,<br>
> ><br>
> > > for example, find the screen saver on the session bus and tell it to<br>
> > > blank the screen ...<br>
> ><br>
> > Or exiting any application :) This is worth a blog by itself.<br>
><br>
> Oh, nice idea. Announce it on squeak-dev, too. And maybe have your<br>
> blog (or the posts tagged with "squeak") added to planet.squeak.org ...<br>
><br>
> > World Menu -> Open -> DbusExplorer.<br>
> > Expand DBus sessionBus<br>
> > open KDE system konsole<br>
> > org.kde.konsole/konsole/MainWindow_1/actions/file_quit/<br>
> > com.Trolltech.QT.QAction.trigger<br>
> > yellow(middle or right)-click, select "invoke method"<br>
> > konsole gone<br>
> > Neat...<br>
><br>
> Hehe. Did you notice you can even invoke methods with arguments?<br>
><br>
> > > Well. IMHO we should *not* save the whole project to the Journal.<br>
> ><br>
> > This<br>
> ><br>
> > > is not supposed to be an Etoys activity, but a Squeak application.<br>
> ><br>
> > It<br>
> ><br>
> > > should only store and retrieve its relevant state. For starters I'd<br>
> > > only store the statistics, which is about 10 numbers.<br>
> ><br>
> > I did not think of saving only the state of the game, but it is<br>
> > definitely a better approach. Maybe I am missing something here<br>
> > though. For example, in Etoys, saving a project writes the whole<br>
> > project as a pr file - I assume .PR is some for of serialized<br>
> > everything in the project, not just what have changed.<br>
><br>
> Yes, it writes out pretty much everything reachable from "Project<br>
> current".<br>
><br>
> > When attempting to store only FreeCell's state, I have a few things<br>
> > to learn and understand:<br>
> > - without looking I am surptised FreeCell's state is only 10<br>
> > numbers, it seems that position of the cards must be more than that<br>
> > unless it's packed somehow - I will look<br>
><br>
> No, that is only the statistics. Not sure how useful it is to store<br>
> the entire state.<br>
><br>
> > - which objects represent the state stored<br>
> > - how to serialize it (well that should be relatively<br>
> > straightforward knowing the objects)<br>
> > - what method will write the serialized FreeCell state to Journal<br>
> > instead of<br>
> > SugarDatastoreDirectory>>#writeProjectinFileNamed:fromDirectory:<br>
><br>
> In FreeCell.st I patch SugarLauncher>>quit which normally would store<br>
> the project, so nothing is stored but the activity simply quits.<br>
><br>
> This is triggered either by pressing the stop button in the tool bar,<br>
> or by a #windowClose event the launcher receives because in its<br>
> #startUp method it registered itself for these events:<br>
><br>
>         World windowEventHandler: self.<br>
><br>
> So if we replace the SugarLauncher mechanism we should register these<br>
> events to be sent to FreeCell instead.<br>
><br>
> > - what does assign the "ownership" of that file on Journal as FreeCell<br>
><br>
> Just the meta data properties, in particular the "activity" property.<br>
> See<br>
><br>
> http://wiki.laptop.org/go/Low-level_Activity_API#Meta_Data<br>
><br>
> > - how to deserialize the state<br>
> > - how to import it back to the game<br>
> ><br>
> > > The regular Etoys Sugar startup happens in SugarLauncher>>startUp.<br>
> ><br>
> > yes<br>
> ><br>
> > > There it looks for the ACTIVITY_ID parameter to see if we are<br>
> ><br>
> > actually<br>
> ><br>
> > > running under Sugar, and an OBJECT_ID which is present if we are<br>
> > > resuming a Journal entry.<br>
> ><br>
> > yes<br>
> ><br>
> > > I think the best way would be to use different parameter names in<br>
> > > FreeCell.sh, perhaps FREECELL_ACTIVITY_ID and FREECELL_OBJECT_ID.<br>
> ><br>
> > Then<br>
> ><br>
> > > the Etoys logic would not kick off<br>
> ><br>
> > logic in SugarLauncher.startup?<br>
><br>
> Yes, because that looks for ACTIVITY_ID and OBJECT_ID.<br>
><br>
> > > and would not try to open the<br>
> > > object as project, but we could provide our own startup method<br>
> ><br>
> > that we<br>
> ><br>
> > > would simply call at the end of FreeCell.st.<br>
> ><br>
> > and load the state read from the Datastore/Journal?<br>
><br>
> Right, if the FREECELL_OBJECT_ID parameter is present it would hold<br>
> the object id to load.<br>
><br>
> > > > 4) Ability to start using the black Launcher ribbon on top, with<br>
> ><br>
> > the<br>
> ><br>
> > > > standard Etoys project name a project stop widget that would call<br>
> > > > the commands from 1 and 2. .<br>
> > ><br>
> > > Well if you look at the end of FreeCell.st you see the tool bar is<br>
> > > explicitly toggled off. Before re-enabling it we would have to<br>
> > > customize it (see class SugarNavigatorBar).<br>
> ><br>
> > Ah I thought the bar was SugarLauncher. Another thing to look at.<br>
><br>
> No, SugarLauncher is registered with the AutoStart class, just like<br>
> the ProjectLauncher which handles the regular Etoys startup (like<br>
> loading a project in the browser plugin etc.).<br>
><br>
> SugarLauncher handles all the Sugar-related session tasks - datastore,<br>
> collaboration, etc. It's not a pure launcher anymore and probably<br>
> should be factored into some more specific classes.<br>
><br>
> > I am actually quite excited about this - you did lots of great stuff<br>
> > there that deserves attention, use, and maybe we can do some<br>
> > marketing for it :) by having a few blogs and a small tutorial at<br>
> > some point. Long time ago I played with DCOP in KDE and Dbus is<br>
> > similar but that's not the point - The point is that apart from it's<br>
> > usefulness for Sugar, what you did can be also used for Squeak /<br>
> > Etoys applications to be integral part of KDE and Gnome desktops<br>
> > (perhaps even OS X - I am reading Dbus is ported there there but<br>
> > probably not integrated). I especially like the idea trying to write<br>
> > a KDE Panel applet in Squeak :)<br>
><br>
> Sounds like a fun thing to try, yes :)<br>
><br>
> - Bert -<br>
><br>
><br>
> _______________________________________________<br>
> Etoys mailing list<br>
> Etoys@lists.laptop.org<br>
> http://lists.laptop.org/listinfo/etoys<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p><p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p></body></html>