samedi, décembre 20, 2008

appleremote02 (part 5)

"Play" works :-)

After searching the entire week (in my free time, mostly late in the evening), I finally found a way to fix the issue I mentionned in the previous entry ( appleremote02 part 4), ... and I finally get it working :-)

Of course, the changes I commited today are maybe not the best one, and I'm waiting for opinion(s), one people who accepts to QA my code, and maybe tell me whether something is wrong.

How does it work ?

When opening a presentation (in static mode) in Impress, it means we use Draw with another GUI. Our issue was, no event listener was running, and thus, the events sent through vcl ( kRemote* turned into MEDIA_COMMAND_something ) get lost. Just because the eventlistener only exists when Impress is in presentation mode. The idea was: implement a new event listener in sd, but more early, means in static mode, to be able to catch the "Play" event, the last one who was not working.

But what do exactly, and where ?

The only way I found to understand was to ask on IRC, and read the code (if you know better, please tell me). I firstly tried in sd/source/ui/unoidl, but it was not correct, and following the advice from Thorsten, I tried in sd/source/ui/app. Probably not perfect, but at least it works.

Everything is based on the use of macros (at preprocessor step). Following the existing example previously studied in slideshowimpl.cxx, I had to :

1) add a DECL_LINK() in the header, to declare a member function in a class that acts as a handler

2) set a handler using the LINK macro : after searching a while. I have choosen to use the sd/source/ui/app/sdmod1.cxx, in getState(), where a lot of things are initialized. The first choice was to set it in sd/source/ui/unoidl/unomodel.cxx, but the choice was probably wrong (at least too complicated), because I had no easy way to retrieve the frame and the shellview.

The LINK() adds the event listener.

3) Set an LINK_IMPL() acting as - sort of - "Callback", with the parameters passed in arguments by LINK().

The IMPL_LINK is the place where I put what do of the event. For instance, check, first whether we have sd running in Impress mode (the other mode is Draw mode), second whether there is a frame containing the presentation, and is focused .. and so on.

4) the most simple was to remove the previous hack to switch at runtime (using environment variables) between use F5 or not. Now, only the right way is used, of course.

Note: in sdmod1.cxx, I firstly believed I could factorize more the code, and this bad idea caused me a lot of pretty crashes before I understood I had two steps at some places, instead of only one. Until now, with the current status of appleremote02, no crash occured.

Other fixed items :

- did some modifications in the wiki page about Apple Remote Implementation
- commited the changes in the appleremote02 cws

Conclusions: I spent a lot of times on that, but I think I understood an important information in OpenOffice.org source code with the DECL() , LINK, LINK_IMPL() mechanism (that's why I try to describe it). Indeed, the scanner does use a similar mechanism, and I know have 90% of the information for the Image Capture implementation, that Valentin Janiaut started some times ago. Another good thing, is the entire changes, if accepted, are really portable : the first side effect will indeed be, it will work on Windows too !!

Last but not least: who helped me there ?
As usual Philipp Lohmann (for important theorical points**), Thorsten Behrens (for his great Impress knowledge) and Jonathan Winandy (from the Centrale Nantes Team) who agreed to build appleremote02 on Leopard on monday (and do some little tests), to confirm there is no obvious problem.

**e.g. Philipp confirmed me, that two event listeners can run together without clash, what I was not sure at all.


To do :

- code cleanup (remove some debug extra stuff e.g.)
- improve : add a removeEventListener somewhere ?
- track leaks ?
- build a clean set, based on appleremote02
- upload it and ask people for tests
- ask for other tests in Windows and Linux ?

Libellés : , , , , ,