segunda-feira, 27 de janeiro de 2014

Now I have something really consistent!!

Me
A few days ago I was feeling a little discouraged: I worked in the code and was thinking that nothing was going on. But I continued to develop and suddenly things got very close to what was planned for the midterm delivery! I'm still in the middle of the way, but very happy with the outcome so far. So, I'm very motivated again! Enough talk about me and let's talk about what has been done.

What I did in the last days

Creating function to load / dump locations info
I was studying the files from GTG trying to understand how and where it saved user data. My goal was to save the locations that the user marked in the map. I tried to make a parser, but Parin told me to use an existing file in GTG to deal with save and load, more specifically two functions : _store_pickled_file and _load_pickled_file , which store locations (by converting object into a byte) and allow load this locations (by a byte being converteded in a object). It uses pickle - Python Object Seralization and it turns much more easy to manipulate the data. Thus, the ground is prepared for the next step, which is to add location to a task, and save them to be shown each time a task is opened .


Add / Remove location to/from the task
To develop this feature , the idea was to use the id of each location , which is unique, and get to identify them and save them in a file on disk. Thus, for each location entered, I should keep: name, latitude and longitude.
That gave me some problems: - The first task I add locations works ok, but the second, when a location is added to it, overwrites the first task's name and shows it's location plus previous tasks locations. It was wrong!

    Print with the bad bad behaviour >:/

To fix this,  I create a method to clean-up, and the list of locations and id of the task are setted as a empty list and a empty string, respectively.

    Different tasks and different locations being shown on it

Save the last location 
The purpose is save the user's last location. Thus, when the user is offline, the map could be oppened with latest user's location, facilitating the visualization.

    You are offline and that's your last location


Treat the user location differently than other markers
Here I had to deal with the initial location of the user in a different way from other locations, preventing this initial location to be deleted. The color of this initial location is red, to highlight on the map, and has a different logic: it is set only when the user is online. When the user is offline, it is shown in map. In the future I intend to change that label to something more beautiful.

Treat release button event instead of button press event
This change was made because of the following problem: when the user was setting a marker somewhere, the cursor was changing to drag cursor when it should remain the same hand-opened cursor.
LibChamplain does not handle the button-release-event when button-press-event
is being treated by geolocalized-tasks, keeping the cursor as a closed hand. If we treat the button-release-event, the behavior is according to what we expect.

Show the location description to its name
The last thing I did. I studied the code of gnome-maps and realized that it uses Gnome Geocode Reverse
to get the location name directly from the map. This is very powerful and very cool. You can set a location directly, and it returns the name of the place for you.
I was doing it synchronously, with geocode_reverse-code(). Parin warned me that this could be annoying for a user with slower internet connection and asked me to do this asynchronously (geocode_reverse-code-async).
Thus:

    It's legen...

    ....wait for it...

    ...dary!  ;-)



And final result in a gif



That's it for now. I'm working in the next steps of my planning. If you have any question, something to correct, ask to me, or comment :-)
See you in next post.

Nenhum comentário:

Postar um comentário