MonthMay 2010

Vala, GTKBuilder and Autoconnecting Signal Handlers

Note: I’m not an expert on Vala, GTK+, or anything else for that matter. If I am off base someplace, comment.

I spent quite a some time today trying to get GTKBuilder to automagically connect all my signals to their handlers. I tripped up at a few places, and so recording them here for posterity.

  1. If you are using instance methods (like most of us are), you’ve to decorate your handler function with the attribute [CCode (instance_pos=-1)]. This makes sure that the function is passed the this pointer as last argument, rather than first. You’ve to do this because Builder.connect_signals passes the instance as last parameter (user_data), and by aligning your this pointer with user_data, you make sure the correct instance is called.

  2. Make sure your handler function signature matches what is expected. Ignore the user_data parameter of most signals – it is used internally by Builder.connect_signals (see above point).

  3. Make sure you pass --pkg gmodule-2.0 to your valac. If you’re using Autotools, this means you pass it to VALAFLAGS.

  4. sure your C compiler is called with -dynamic-export. I’m told this enabled support for dlopen in the binary produced.

  5. Mangle your names properly. Cheese.MainWindow.on_quit() becomes cheese_main_window_on_quit on C, and that is what GTKBuilder expects. If you are not sure how your function name is mangled by valac, checkout the generated .c file.

If you do all these 5 things right and you’re still having trouble, turn up on #vala at irc.gimp.net and ask the helpful folks there :)

Cheese GSoC Report – Week 1

First week of official coding is over. What do I have to show for it?

  1. Moved code from Github to GNOME Git (Thanks fargiolas!)
  2. Learnt how to use GTKBuilder, and how to autoconnect signals to vala callback functions.
  3. Learnt some of the intricacies of Gtk+ Layouts (They still have a lot to teach me!)
  4. Got a very basic version of the basic Cheese window up and running.
  5. Learnt how to embed Clutter into the Gtk+ base of Cheese.

So far so good. I don’t quite like the pace of my work – I should be going faster. Hopefully I won’t be feeling like this at the end of next week :)

By next week, I hope to have accomplished…

  1. Pixel perfect UI, replicating exactly what is in cheese right now (except for the viewport, ofcourse)
  2. Vala bindings (.vapi files, basically) for libcheese
  3. Thumbnail View finished (either wrap and use current code, steal some some other project or write my own)
  4. Basic work on modifying libcheese to support video output to a ClutterTexture

GSoC is primarily about learning, so what have I learnt so far?

  1. git is a powerful tool, provided you do not fight it (thanks fargiolas!)
  2. Just because code works, doesn’t mean it is good enough! (thanks _ke!)
  3. When you are stuck, STOP AND ASK FOR DIRECTIONS! (thanks fargiolas!)

GSoC Milestones – Vala Build using AutoTools

I’m using a RTM List to track my milestones for this my GSoC this year. I’ll be making a blog post for each item ticked off that list, to share what I’ve learnt in my journey from n00b to someone whose code is good enough to be included in GNOME. This is part 1 in the series, where I tell you about autotools

My GSoC project involves, moving major parts (UI) of Cheese to a new language – Vala. Vala is more an extremely glorious C preprocessor than a language of its own – it just translates down to GObject based C code, rather than bytecode/objectcode. The syntax is very C#ish – I was using csharp-mode in emacs to code vala till I got bored enough to download vala-mode. It’s got closures – haven’t used them yet, here is to hoping they’re real closures. It has tons of libraries – it takes a few (minutes|hours) to write a binding for any C library, so many bindings already exist. You don’t lose speed – Vala is compiled down to C code. It also has one of Java’s suckiest features – Checked Exceptions. The documentation is non existent – you’ve to pretty much read through the bindings, or the original C library’s documentation to get anything done. And not many people know such a language exists (Kausik for example – but he also didn’t know you could output pdf from latex, so I don’t think his opinion counts :D)

Cheese uses autotools for building. I had to tweak their script to make it build my Vala code as well. I’ve never worked with any of the autotools stuff before – I didn’t even know .ac stood for autoconf and .am stood for automake. No big deal – Google knows it all and will tell you for free. I JFGI and found a bunch of articles about using autotools to successfully build vala projects. After reading this monstrous (180+ slides, but ~500 pages) Autotools presentation (which is actually very, very good, btw), I had a working build script. It built my single cheese.vala file that did nothing but run a loop and wait to be terminated. It had a place where I could add more .vala files and they should (should) be included in the build. It was hackish, but like most hacks, it worked. On My Machine(tm).

Nowhere else. Turned out my script wasn’t working at all – just faking it to me. I had initially tested out valac (the vala compiler), which had produced a .c file. Since make was supposed to produce the same file, and it wasn’t stale (I hadn’t touched my cheese.vala), it just proceeded to compiling the .c files with gcc. The Vala part of the build script wasn’t being executed at all. Removing the .c file told me that my hackish script hadn’t worked at all.

After banging my head for a while to figure out why it wasn’t working, I finally landed up on the official autotools docs. Autotools had added native vala support. The hack I found was not necessary.

facepalm

Moral of the Story: RTFM comes first, not JFGI.

Anyway, I rewrote the build script to be much more cleaner in a couple of minutes. And it worked.

Build systems are actually a lot of fun once you get the hang of it. A black screen with fast scrolling green text cryptic to everyone else but totally sensible to you is incredibly attractive, no? :)

GSoC Milestone 0 – What does my project do?

I’m using a RTM List to track my milestones for this my GSoC this year. I’ll be making a blog post for each item ticked off that list, to share what I’ve learnt in my journey from n00b to someone whose code is good enough to be included in GNOME. This is part 0 in the series, where I tell you what my project is all about and how Cheese is going to become awesomer.

So, what exactly does my proposal mean for Cheese?

  1. Moving the UI to Vala (from C)
  2. Move display bits from GTK+ to clutter
  3. Implement Live Preview to show people how applying an effect will look before applying it
  4. Implement loadable effects so you aren’t stuck with just 12 preloaded effects.

I’m told that the scope is kinda too big for 3 months – but I’m sure that with careful planning (hah!), around 40 hours of work a week (haha!), lots of time away from college (hahaha!) I can do this stuff :)

I’m keeping my code in a github repo, so watch that for code updates. And will be updating this blog at the completion of every milestone, so subscribe if you haven’t :)

Note: My exams are still going on. Won’t be coding much till they end (May 19th).

My First Accepted Patch!

As part of my GSoC preparations, I wrote a few patches for Cheese. One of them (a one liner to fix a crash) has made it to GNOME 2.30.1 – the other two (1 and 2) are slightly more significant and involve UI changes, and so will be integrated later.

Free beer to everyone who can catch me in a bar! Free Pepsi/Sprite/Egg Puff to anyone who can catch me in the College Stores ;)

P.S. Obligatory thanks to _ke and fargiolas for guiding me through the difficult bits :)

GSoC 2010 – The Beginning

I mentioned this in passing in my earlier post, and was tweeting about it quite furiously – I’ve been selected to work on Cheese for this year’s Google Summer of Code :D

Link to my, uhm, cheesy proposal

What Now?

Getting accepted doesn’t mean shit. Actually finishing whatever I was supposed to within 3 months does mean something – especially since I’ve taken on quite a bit of stuff to do (Move to new language + 2 new features). I’m quite the n00b – first time I’ll be doing just one thing over 3 months. Will be setting up a way of monitoring progress (probably via set milestones) soon enough. Will keep this place posted :)

Also, say Hi to my mentor daniel siegel. Him and fellow cheese-dev Flippio Argiolas, who were extremely helpful in getting my proposal whipped into shape (It’s a gist, so you can see how it eveolved over time).

The Oscar acceptance style blog post will be turned in once the three months are over and the newer, improved Cheese is accepted as good enough :D

© 2017 Yuvi Panda

Theme by Anders NorenUp ↑