GNOME Break Timer: Week 2

I’m starting the third week of coding on my GSoC 2013 project, a new break timer application for GNOME. I spent the last two weeks working on an odd mix of little things. For the most part, my goal over that time was to make the gnome-break-timer project (previously brainbreak, still brainbreak in most places) nicer to work with. I’m a bit of a sucker for clean code, and, well…

By Manu Cornet, from Bonkers World
By Manu Cornet, from Bonkers World

So, to start off, I switched over to Automake from my old build system, which was using BuilDj and Waf. I’m still a big fan of those two, at least philosophically. In practice, Automake just seemed like a good choice because it’s familiar to people, and I really want to maintain a high bus factor for this project. This isn’t the sort of application that I would expect to have a continuous flow of regular contributors, so I think it’s important that someone can jump in and figure it out for without too many obstacles.

One interesting puzzle here was doing a convenience library with Automake and Vala. I started using convenience libraries for this project so I could strictly define different parts of the application. The idea is code at one level shouldn’t know anything about code above it, and we can formalize that by actually building these bits of code to separate objects that get linked together later. This also, conveniently, allows us to reuse the code that is common between the settings panel and the break timer daemon without needing to compile it twice. Not a big deal here, but I like it anyway.

I found lots of helpful information about doing convenience libraries with Automake, but Vala posed something of a problem because Automake doesn’t do everything for us with Vala (yet). I need to pass several extra flags to valac, both for the library and for the target that uses the library, and I need to do that without messing up build dependencies. I don’t want to run into cases where the build fails (or, worse, doesn’t fail!) until I run make clean. (For what it’s worth, the old build system with BuilDj and Waf figured this out wonderfully and generally rebuilt the thing about twice as fast as Automake, but I also hadn’t set up localization or config.h, so I guess that’s kind of moot). I checked out how some projects like Deja Dup were doing convenience libraries, and I came up with a handy reusable pattern:

Makefile.am for the rather unhelpfully named “common” module:

M_CPPFLAGS = $(BRAINBREAK_CFLAGS) \
	-include $(CONFIG_HEADER)

noinst_LTLIBRARIES = \
	libcommon.la

libcommon_la_SOURCES = \
	NaturalTime.vala \
	SessionStatus.vala \
	...

libcommon_la_LIBADD = \
	$(BRAINBREAK_LIBS)

libcommon_la_VALAFLAGS = \
	--pkg gio-2.0 \
	--library common \
	--vapi common.vapi \
	-H common.h

junk_files = \
	$(libcommon_la_SOURCES:.vala=.c) \
	libcommon_la_vala.stamp

dist-hook:
	cd $(distdir) && rm -f $(junk_files)

CLEANFILES = \
	$(junk_files) \
	common.vapi \
	common.h

Makefile.am for some code that uses that module:

AM_CPPFLAGS = $(BRAINBREAK_CFLAGS) \
	-include $(CONFIG_HEADER) \
	-I $(top_srcdir)/common

SUBDIRS = 

bin_PROGRAMS = \
	brainbreak-settings

brainbreak_settings_SOURCES = \
	ApplicationPanel.vala \
	BreakPanel.vala \
	BreakType.vala \
	main.vala \
	...

brainbreak_settings_VALAFLAGS = \
	--pkg gtk+-3.0 \
	$(top_srcdir)/common/common.vapi

brainbreak_settings_LDADD = \
	$(BRAINBREAK_LIBS) \
	$(top_srcdir)/common/libcommon.la

brainbreak_settings_vala.stamp: \
	$(top_srcdir)/common/libcommon_la_vala.stamp

junk_files = \
	$(brainbreak_settings_SOURCES:.vala=.c) \
	brainbreak_settings_vala.stamp

dist-hook:
	cd $(distdir) && rm -f $(junk_files)

CLEANFILES = \
	$(junk_files)

Of course, I also rewrote a bunch of stuff which had been thrown together a little too hastily. I knew I would need to rewrite a lot of code, but I wanted to get the “rewrite and start over” bug out of my system in the beginning, and I think it worked. Allan Day already came up with some lovely mockups that I could start with, so I used those to guide me in choosing what needed work. As I worked through implementing different bits of his “take a break” UI, I noticed some aspects that would have been quite difficult with the design I had earlier. I squished and pulled things accordingly, giving the UI code a little more power and knowledge, and getting rid of needlessly arcane kinds of “reusable” code. But that’s all a little boring.

I’m really excited for the next bit. I will be working on a beautiful new Break Settings application, complete with GtkHeaderBar and (hopefully) a non-ridiculous time input widget. I’ll post some pictures and a new download soon!

My GSOC 2013 project: a new break timer application for GNOME

A little while ago, my proposal was accepted for Google Summer of Code 2013. So, this summer I will be working with Jasper St. Pierre and the GNOME project on a shiny new break timer application. We’re going to spend some time filling out the wiki page for the new break timer design, and from mid-June to mid-September I will try to implement it as well as I can.

A break timer application is pretty well what it says on the tin. It’s an application that can monitor your computer use and remind you to take a break every now and then. Things get a little tricky when we start thinking about how to make that sort of application effective. Among other things, gauging how much someone is using the computer is kind of fiddly, and people don’t really enjoy being interrupted all the time. If it’s done well, though, I think anyone can benefit from this type of application. Taking regular breaks isn’t just healthy for the body: it can keep your mind happy, too.

I’m excited about this project for a few reasons. First, I have been meaning to get involved with GNOME for a while, and I’m expecting to touch a few different projects in order to produce something seamless. This is also an itch I have wanted to scratch — I really want a good, shiny and new “take a break” app for a variety of reasons — and it’s an opportunity to tie up a loose end from a while ago. I actually already started on a new break timer app, but I never quite reached a releasable product. With my project this summer, I’m going to be starting with (some of) what I already made, which will allow me to iterate efficiently and, I hope, to create something beautiful and releasable by the deadline.

For the time being, I thought it might be fun to actually share the other one I keep mentioning, which has the strange working title “Brain Break”. It isn’t perfect, but if you’re interested in a take a break app made for GNOME 3 (and yes, that includes Unity), that uses GTK+3 and real desktop notifications (and not the old system tray), perhaps you will like it? I made it because I thought the existing options for break timer software were getting a little old, but also because those options didn’t really work for me: when there was a Skip or Postpone button, I got into the habit of pressing it as soon as I could. (I’m a computer nerd. Workarounds are my middle name). When there wasn’t, I would get angry at the software for interrupting me and I got into the habit of disabling it proactively (and then forgetting to turn it back on).

Brain Break doesn’t have a Postpone button or a Skip button, but it makes up for it with a “Take a break” overlay that blocks your screen without blocking input. So, you can finish that one last thing without needing to postpone or skip the break (or, for that matter, lose your train of thought). Because there’s no easy way to make the “Take a break” overlay go away, Break Break is hard to ignore, but it tries to be nice about it.

Brain Break is probably ready to use. I’ve been using it for ages, and I like it, at least. It’s on Launchpad at launchpad.net/brainbreak. If you’re using Ubuntu, you can install it very easily from its PPA, launchpad.net/~brainbreak/+archive/daily. Just open a terminal and run sudo add-apt-repository ppa:brainbreak/daily, then sudo apt-get update; sudo apt-get install brainbreak.

Brain Break's "take a break" screen is gentle, but hard to miss
Brain Break’s “take a break” screen is gentle, but hard to miss
Brain Break's settings tool
Use the break settings panel to set specific break times, or disable them for an hour

The new break timer app probably won’t be the same as Brain Break, but in order to make the new one as awesome as possible, maybe there’s something to learn from Brain Break? Please, try it out, and share your thoughts in the comments! You might like it, and either way I would love some feedback to get ideas flowing.

Reposted from June 11, with apologies to Planet Ubuntu. Hi there, Planet GNOME!

Harvest + GSoC week 12

Well, I managed my last-minute merge request for Summer of Code 2010, and with that done it is time for my last GSoC 2010 blog post!

I am really glad I did this. It’s taught me a lot about myself (having never done a project in this fashion before) and I’m happy with how it turned out. GSoC was a nice change of pace and I hope to keep this up for a while!

(Hamster still says I’m a slacker. I need to convince it otherwise)

So, here are the results of some recent tinkering:

First, of course: new font! It requests the delightful UbuntuBeta font first and borrows some conventions from the Ubuntu Web guidelines.
Daniel added help text to the opportunity list filters. He gave each one a tooltip with a nice explanation.
There’s now a permalink for every source package, a nice Edit button for each opportunity, and some other small visual tweaks. Just little stuff like that.

Previously, every opportunity in Harvest had a text box labelled “Comment” that saved to a single database field. The idea was someone could fill it in with useful information for other Harvest users. It felt sort of like Launchpad’s Whiteboard feature in Blueprints.

I decided that implementation would encourage very complex comments. That’s a problem because Harvest aggregates other stuff. There’s a good chance whatever it links to will have its own comment system. I wanted to differentiate Harvest’s comments so they would never be seen as alternatives to whatever is in a referenced bug tracker. Instead, these should be, from top to bottom, specifically for small pointers.

So, we played with it and I added Notes (which is apparently the least commonly implemented synonym of Comments). Notes are little messages you can add to opportunities. Each note is basically a text field limited to 250 characters. No special formatting and no newlines. When I write one, I think of IRC.

The feature isn’t as quick to find as I’d like (there’s an app bug report for that), but it’ll be good to see how people use Harvest before adding more stuff. There are probably all sorts of cool things that could be done, so I’d love to know in the comments here if you have an idea!

(…And I can’t believe I haven’t done this yet)
Thank you to Daniel for being a great mentor! I can confirm the rumours are true: he is an excellent guy. I’ve really enjoyed working with him.

I didn’t quite get to everything I wanted for GSoC (and I have to admit I got carried away with design trivialities this week), but now we’re just a few small pieces away from a spectacular tool for Ubuntu developers. After a bit of a coding / remembering last year’s math course break, I’ll be back helping with some more of those bits. It’s going to be fun!

Here’s a completely unrelated bit of good news: I learned that UDS-N is now short for UDS-Natty, and I miraculously have no exams anywhere near late October ;)
So, assuming I can find a narwhal and convince it I am indeed smart and fashionable, I’m totally hoping to get there, meet people, learn lots of stuff and wax lyrical about Harvest, slideshows and release notes (as I do). Should be fun!

Harvest + GSoC week 9!

The past week, unfortunately, hasn’t been very productive for me. Still, I have a few things to show!

I did a bunch of cleanup (again) and I toyed with animations for a while. There is now an animation (and a loading indicator) when new results are retrieved for the filters. One philosophy I have found myself following is that this UI that never, ever blocks on a task. So, no matter what is happening, you should always be able to click the same buttons you could before.
(On a related note, I’ve been very excited about Blender lately).

Turns out non-modal design has an interesting impact as far as loading indicators are concerned. I wanted this indicator to be totally unobtrusive, but also obvious. So, as soon as someone starts adjusting filters, they can see that Harvest is waiting, then loading results.

It’s a little bubble that appears from the top of the results and is always visible at the top of the screen as the user scrolls. Conveniently enough, the existing results are all pushed away to make room for it. That was an accident at first, but really it makes the slide in a bit more pronounced and it means it doesn’t overlap anything you may have been looking at. (And even if it does, you can fix that by scrolling up).

Pretty simple :)

I made a quick video to show how this is all working:

The other thing I tried doing was to have the Javascript interface record its state in the location so it can be bookmarked and navigated through in the browser history (with the Back and Forward buttons).

I learned a lot of terrifying things, since I’ve never done that before.

Of course, the first terrifying thing is that you can’t change any part of the URL except the part after #, which never gets sent to the server. Well, you can change the other parts, but when you do it redirects to the given URL. That’s a good thing, but it does make life a little difficult for me :)

So, what we need to do is change location.hash to describe the current state, just like we do with the query strings sent to the server. There also needs to be an event handler watching for that change. With those two bits in place, that event handler is called whenever the user presses the Back button or loads the page from a bookmark, and it can apply the given state.

There are piles of jQuery plugins for this job. Two stood out above the pack: Asual’s impressively professional looking jQuery Address, and Ben Alman’s deliciously silly sounding jQuery BBQ. After some pondering and licking my lips, I went with jQuery BBQ.

BBQ is very clever in its simplicity. It uses the existing jQuery.param stuff to generate a query string the usual way, then it puts that in the hash part of the url instead of the ? part. It adds a “deparam” function to deserialize those query strings, a browser-agnostic hashchange event, a few helper functions, a bunch of documentation, and that’s it.

Unfortunately, even with jQuery BBQ, my work got really loopy here. In short, there are a lot of variables to deal with already and adding more almost exploded my brain.
(That was no doubt strengthened by a brief interlude at the family cottage, where I regressed to glorious redneckism and finally unlearned PHP)

So, unfortunately, I’m going to hold off on that for now. I could have planned the Javascript stuff much better, and getting BBQ working smoothly is likely a rewrite away. It may be a bad idea anyway. If someone shares a link that has #querystring instead of ?querystring, that link won’t work for anyone who has Javascript disabled. Instead, I’ll probably go the Google Maps approach, offering a “Permalink” button but never editing the URL in operation.

Next up: nicely formatted package details, and editing opportunities!

Harvest stuff for GSoC: Week 7!

Time for my bi-weekly Harvest update! Everything this time went into the gsoc-client-stuff branch.

The first thing I learned (well, decided) is that YUI has incredibly dense, loopy and uncool documentation. I guess different people are compatible with different kinds of docs. As I read the YUI stuff I just couldn’t keep it all straight for some reason. Its landing page leads off in many directions: there’s an API reference that was written and designed to put me to sleep, an Examples section that doesn’t bother to link to the API reference (but is more pleasantly written), and a lot of extra listings in between.

All I could think about was how much I preferred JQuery’s docs. So, I dropped YUI for JQuery and nothing has exploded. In fact, it’s all gone wonderfully.

JQuery has a considerably simpler core than YUI, but there is lots of functionality in little self-contained plugins. Some of these are official parts of the project, others are external things linked from the plugin repository. (Granted, lots of redundancy there). It’s a different approach — YUI is richer from the start — but for me, JQuery wins by being so much easier to take in at a glance. That, and its documentation is a lot prettier. Instead of your boring automatically generated list of docstrings attached to function names, they have a beautifully presented web app. There are no frustrating stubs; everything I may think to use is there and explained in detail. And it’s a single destination. One page to learn everything there is to know about each bit of functionality in JQuery, including examples. Pretty cool.
JQuery, I promise I will always love you :)

I also learned about doing object-oriented Javascript. This one surprised me. I have used Javascript for lots of small jobs before, but I have never used it with anything big. I realized Javascript doesn’t have the class keyword I have come to love, but after some learning I am back to thinking it’s a pretty cool scripting language. That is mainly thanks to an excellent blog post by Stoyan Stefanov, all about doing classes in Javascript. Everything is an object, so of course we don’t need a class keyword! (Apparently we’re getting one some time this century, though, if everyone is nice to it).

Making something that feels like a class is a bit of a hack, but it works elegantly in the end. It’s really just a function, and we put other functions and things inside it for methods and properties. I’m doing them like this:function Filter (dom_node) { var filter = this; this.get_value_serialized = function () { return null; }}

To create an instance we use Javascript’s new keyword and write out the function as usual (including its parameters). The this keyword can’t be trusted if we are using callback functions, because each function is given its own version based on what object it is being called with. (If it’s via a reference to a function stored somewhere else, things get messy). On the other hand, anything inside Filter can see that filter variable we created at the top, as well as the dom_node parameter.

Those variables pointing at functions, of course, can be really easily reassigned to point at different functions. Lots of power here. For fancier stuff, including multiple inheritance (yes, it gets crazier), Mike Koss has an excellent article. In my case, I decided not to go into that. (Well, okay, I chickened out then called it a decision). Proper subclasses might make my code look smarter, but in this case that whole chunk barely needs to do anything anyway, so I’m fine how it is.

With that all out of the way, I worked on a really fun list of new stuff!

I have Harvest using XHR in a few different places now. XHR is a wonderful thing that lets us directly request new data for our page and handle it through Javascript. It means, if you want to select a bunch of filters, you can do it without flooding our server with each one.

When a filter’s value is changed, it posts the query parameter that change represents to the global Results object. (Some goodies here: if you change the value of a filter in a positive way, that filter is selected implicitly). Instead of instantly yapping at the server, the Results object stores the parameter it receives in an object (dictionary style) and starts (or restarts) its timer. When the timer finishes, it uses JQuery’s $.get function to request new results for the selected filters, passing the function its dictionary of new parameters. (JQuery magically turns that into a querystring for us, so if something weird happens and everyone decides to use something else, Harvest will still work).

The result surprised me. I’m still not doing much to limit the number of results, but even with a query that returns the most packages possible (around 3700 at once) the whole thing feels a lot quicker than it did. Funny…

The next one is expanding packages. When the user clicks a package, we send another http request asking for that package’s details. We get a snippet of HTML back from the server, throw it in the right element and reveal it with an animation. (Did I mention I love JQuery?).

By the way, I worked on the visual design for packages. Any comments? Thoughts on the arbitrary green highlight?

I don’t trust http requests going on unchecked. So, as is the convention, I added little “loading” indicators (from the very helpful and sickeningly popular ajaxload.info). It was really distracting to have these appear all the time, though, so I played with it and now the indicators will slowly fade in. A loading indicator should only become obvious if there is a long operation going on. If everything is normal and the operation is nearly instant, the indicator stays out of the way.

I went two whole days without an Internet connection this week (oh, the humanity!), so I was thinking about people with similar predicaments. It sucks when an application decides it wants to download something and keeps on trying and trying, oblivious to my repeated attempts to convince it I have no connection. JQuery’s $.get function returns an object to control the http request, so I store that using the $.data method:package_node.data('xhr', xhr);Later, if someone tries to collapse a package that was still loading its details before expanding, we can do something like:package_node.data('xhr').abort();We give $.get a callback function that is run when the request is finished — be it successful, an error from the server, or an abort. So, cleanup (like removing the loading indicator) can all be done there.

The Django debug-toolbar only kicks in when we load a whole new page inheriting from the base template, so I had to try something new to gauge performance. In this case I found a cool bit of middleware at DjangoSnippets.org. It adds a header for every page Django creates, saying how long it took to generate. It isn’t much information, but it helps! What I like here is it doesn’t edit the page at all and it’s a really small bit of code; it is as unobtrusive as possible. The data is always visible with a tool like Firebug or Webkit’s web inspector (or telnet, if you’re crazy). It is super easy to present this with Javascript, too:time_header = xhr.getResponseHeader('X-Django-Request-Time')if (time_header) { $('#requeststats').html('Results generated in '+parseFloat(time_header).toFixed(2) + ' seconds');}

And that is that! There is lots of polish left to do for next week, and a strange headache of a merge conflict to resolve. Assuming bzr doesn’t eat anyone’s work, things are really picking up!

Harvest GSoC project: week 5!

The last two weeks of my Harvest project have gone really well. It isn’t flashy and exciting and earth-shattering (yet), but I’m happy with it.

First of all, my branch now has Packages and Opportunities filters. I implemented a bunch of each, and they are resolved in order. First Harvest runs the package filters, then it filters the opportunities that belong to those packages, then it hides packages that have no visible opportunities after all that filtering.

After a long period of me obsessively poking things, Daniel talked me into making a merge request for my branch (to lp:harvest). He and James W gave it some really thorough code review, which has been a huge help! Now it all feels tidier and a little more justified, so I can use the code I wrote without that constant temptation to rewrite it.

At this point, performance is much improved. Details are only shown for one package at a time, so the incredibly long waits (and self-destructs) have gone away.

In addition, the filter system consistently does 4 SQL queries no matter what is being searched for. Of course, that doesn’t say it’s running as well as it can, but it does mean the system is more orderly. It only hits the database once for each type of data. (One query for package sets, one for opportunity lists, one for relevant source packages, one for relevant opportunities). This puts more thorough optimization within reach.

Rather than trying to optimizing things for eternity, I’m off to something completely different for now: fancy Javascript to load new content in line with the page! The idea is a big query will still have a visible wait (always will!), but a complete page won’t need to be created each time; just the specific results, with a nice spinner while they’re loaded. Less jumping around, quicker and more fun.

For the first step, I have to admit I got a little carried away and started redoing the base template from scratch. (It should save me some time, really. The Javascript will be attached to some kind of DOM tree and I don’t want to fiddle with that twice). Still an early WIP, but I think this looks quite pretty :)

I am starting with a prototype written in straight HTML; no Django template markup yet. It’s helping me straighten my thoughts for how the filters’ render() functions should link together. The interface is taller than I would like, so I will need to do something to collapse the Choice filters when they aren’t being used. Oh, and we don’t seem to have a logo. Still, the gist of it is there.

Next for me is figuring out YUI and making that filter interface on the left interactive. Really exciting! Javascript toolkits are amazingly fun to use.

Speaking of web design, I decided I didn’t like my nearly-stock Blogger template anymore so I spent way too long redesigning it (while cursing Blogger for being an awful platform to make templates with). What do you think?