Showing posts with label Documentation. Show all posts
Showing posts with label Documentation. Show all posts

24 March, 2011

GApplication in Cheese.

I have been working for the last few weeks on porting Cheese to GTK+3. I found some challenges along the way, and migrating from LibUnique to GApplication was definitely one of them, so I thought that this might deserve some special attention. New and more detailed documentation is now available, but I created a small flow chart just to have an overview of how GApplication works within a real application which is familiar to us.

 
Created using Graphviz (awesome tool!). 
First of all, I want to make it clear that this does not meant to be a guide or tutorial, it is just what I did and understood. It worked and I am happy to share it with you and I will be happier if it helps you to deal with GApplication in the future or even if I get some feedback on things which might be wrong :)). 

What problems did I face first? 
GApplication is new, the documentation was not as detailed as it is nowadays and it was the first time that I had ever used it. I never worked with LibUnique before either, and the terms primary instance, remote instance and local instance were new to me. So, what was that?
With some reading and bothering David King for a while, I discovered how everything worked together and what those terms meant. If you are as confused as I was, this might help you:
  • Primary instance: The very first instance of the program, that means, the first instance you run. Example: Run firefox for the first time and there you have a primary instance.
  • Local instance: The very last instance you run from a program, this is the last one you started working with. Example: In our example, the firefox instance you started, would be at the same time primary and local. If you start a new firefox instance, then the first one would still be the primary, and the second one would be the local.
  • Remote instance: Every instance of the same application that is not the primary one. Example: In our example, the second instance of firefox that you run would be the remote one.
Cheese works as a single instance, and with a single window for that instance. Every time Cheese is called from a terminal with command line arguments, those are handled  locally by the newly created instance, and here, GApplication::local_command_line() plays the main role. Every time g_application_run() is called, GApplication::local_command_line() is invoked. This function always runs in the local instance, which is the last instance you run.

By default, GApplication::local_command_line() tries to handle the command line in the primary instance, but since I wanted to be faithful to the original implementation, the purpose was to handle command line arguments locally, and for that, I needed to override the GApplication::local_command_line() function to make it return TRUE, and this is in essence what the diagram tries to explain.

This is how the main function looks like. (Cheese.Main inherits from GtkApplication which inherits from GApplication): 

public int main (string[] args)
{
    ...
   Cheese.Main app;
   app = new Cheese.Main ("org.gnome.Cheese",ApplicationFlags.FLAGS_NONE);
   app.activate.connect (app.on_app_activate);
   int status = app.run (args);
   return status; 
}

I hope this is helpful, in some way, to somebody. As you can see, the diagram starts on the app.run(args) call. You can check out the source code on git.gnome.org, and for a more colourful version, in my GitHub repository.

I wanted to take the opportunity to thank David King for his infinite patience and help during my work migrating Cheese to GTK+3, Jürg Billeter for being so responsive and helpful in every single issue I had with Vala, and Carlos Garnacho for helping me out with some GtkStyleContext problems.

Thanks to all of them for the help and to you for reading!

07 December, 2010

GNOME Development Documentation and Tools Hackfest 2010.

I spent the last 4 days attending the Gnome Development Documentation and Tools Hackfest, which was held at Openismus offices in Berlin. The venue was just the most convenient for the event, since with such weather (-15ºC one of the days), the days turned to be very productive... no one wanted to spend much time outside!.

Almost all the attendees arrived during Wednesday evening and to compensate their (most of them) long journeys, we had a great dinner at the Massai's African restaurant (courtesy of Openismus). Hard work started the day after.

We spent almost one day trying to make an agenda with the topics we would like to cover during the hackfest and finally focused on two main themes, the "GNOME developer platform" and the "developer stories" or put another way, "who is going to use GNOME and what for?". After this, we did some brainstorming on the way we wanted to make this possible and some ideas came out.

First, we realized after some discussion, that most of the people find it difficult to know how to get started working on GNOME, so one of the agreement points from the very beginning, was that a platform overview needs to be done. Here, questions such as 'where is 'x'?' and 'what is 'x' for?', among others, would be answered. We also want to do this in a way that is attractive for getting developers involved and convince managers that GNOME makes the difference. After some more discussion and work, the idea took form and now you can already see the results in the form of a screenshot.

An other idea that we decided to put into practice, was the initiative of writing  ten-minute introduction tutorials for various GNOME technologies (first in five target languages: C, C++, Python, Vala and Javascript) in order to show what kind of easy and amazing things one is able to do in a lunch break time period. I was involved in this team and my task was to create a very small simple image viewer GTK+ application in the C language (the tutorial is coming soon). For writing the documentation, we decided to use Mallard, so Schaun gave us a small and very useful introduction on it. You can see all the mini applications and some of the tutorials in the GNOME git repository. Please note that they haven’t been fully reviewed yet.

The hackfest went very nicely and the desire of being collaborative and helpful was present during the whole event. I am happy I was there and had the chance to meet all these people and be useful in a way. Thanks to everybody for comming, as well as to those who read in the planet GNOME that we were meeting, and just appeared by own iniciative in the office and joined us, like Konstantine or Clemens, which might join us at the Desktop Summit 2011 with some cool design thinking workshop again!!