This is a contents page for the N900 apps tutorial.
- Part 1: first steps in Hildon
- Part 2: packaging
- Part 3: touch selectors
- Part 4: the power of DBus
- More to come…
You can download the app so far from the maemo-extras repository, or from maemo.org.
This is a contents page for the N900 apps tutorial.
You can download the app so far from the maemo-extras repository, or from maemo.org.
Ever since the N900 was announced, I’ve had people ask me whether it’s difficult, or in some cases even possible, to write apps for it. Well, it is possible, and it’s pretty easy: let’s write a simple app together and you’ll see. We’ll make a basic client for the social bookmarking site reddit, and I’ll call it ræddit, because I have no imagination.
First, a bit of handwaving. I’m not here to teach you C, or Glib programming, or GTK programming. There are plenty of good tutorials about those already, and I’ll assume you know a bit about them. In keeping with this, we won’t be writing the client’s back end; we’ll just assume that there’s a Glib-friendly client library for reddit already in existence. Oh, look, a handy Glib-friendly client library just conveniently sprang into existence for us: source, headers.
Learn to love Scratchbox. If you’re doing any development for the N900, you’ll run into a cross-compiler toolkit called scratchbox. It’s packaged in most major distros, so install it before you go any further. There are two reasons you’d use scratchbox:
My First Compile. So first of all, let’s not bother with any of the graphical stuff, or with packaging. Let’s just write a program that dumps the contents of reddit’s front page out to standard output, and then let’s run it on your phone. Here’s a pretty minimal program to do that: raeddit-01.c. Put that in your scratchbox, along with the reddit client library linked to above, and at the scratchbox prompt type:
apt-get install libcurl3-dev libjson-glib-dev
gcc `pkg-config --cflags --libs glib-2.0 hildon-1 json-glib-1.0 libcurl dbus-glib-1` raeddit-01.c greddit.c -o raeddit-01
There are some extra libraries listed in the pkg-config statement which we’ll be needing later.
Caveat: You may currently find a difficulty getting the correct packages installed to compile against json-glib; as of the time of writing there was a version dependency problem in the Maemo repository between libjson-glib-dev and libjson-glib-1.0-0. I solved it in a rather ugly way by downloading the package directly and doing dpkg -i --force-depends libjson-glib-dev_0.6.2-5_armel.deb. Your mileage may vary. I hope they’ve fixed this by the time you read this. If not, you know what to do.
So anyway, you should now have a binary called raeddit-01.
Now, either find out your trusty N900’s wifi IP address, or hook it up via USB, in which case its IP address is 192.168.2.15. Give the command
scp raeddit-01 root@192.168.2.15:
(The default root password is well-known.) Your binary is now on the phone in the directory /root. Make sure the phone is connected to the Internet, fire up a terminal on the device, and type
/root/raeddit-01
If you see the current contents of reddit’s front page printed out on the terminal, you’re doing fine:
First steps into Hildon. So, now we have a very basic reddit client. Let’s think about making it pretty.
What we want is a series of buttons going down the page that look something like this:
Eventually we’ll need to make a custom widget for that, but fortunately there’s a standard Maemo widget called a HildonButton which holds two labels, a title and an optional subtitle, which is close enough to what we want for a basic tutorial. It looks like this:
We can just stick a bunch of these into a GtkVBox. But we also want the user to be able to flick through them with her finger, and there’s a specialised Maemo container widget to allow that: it’s called HildonPannableArea. So the GtkVBox will live inside one of those.
So here’s raeddit-02.c (diff to raeddit-01.c), which knows how to put up a window and fill it with buttons. The buttons don’t go anywhere, but at least we’re getting somewhere! Compile it, transfer it to the phone, and run it again:
Making the buttons into links. So next we need to make the buttons go to the various sites. Now, there’s two important things you have to consider when porting or building an app on the N900. One of them, which we’ve just mentioned, is that sometimes there are widgets which don’t exist on the desktop, because they work in ways which are better adapted to life on a phone. The other is that there’s a whole ecosystem of programs on the device with which we must play nicely. One such program is the web browser, and right now that’s exactly the program we need to talk to.
The polite way to ask the browser to show a particular page is by using a DBus call. Here’s raeddit-03.c (diff to raeddit-02.c), which knows how to do that. Compile it, transfer it to the phone, and run it again. I would show you a screenshot, but it looks just the same as the last version. And it works.
And now we have a first approximation to the program we wanted, which is at least good enough to call version 0.01!
Where can this go next?
Let me know where you’d like this series to go in future. I’m speaking only as a fascinated individual here, and I’d also welcome any corrections you have, as well as any questions about things I left unclear. If this whets your appetite, you can find out a lot more detail in the official developer guide, or the official porting guide.
It’s my last night in Helsinki, at least this time around, so I thought I’d do a bit more exploring. Helsinki on the ground never seems to bear much resemblance to the map. Streets seem to vanish and re-materialise again later. Daf had recommended a place called Dong Bei Hu for dinner. After some wandering, I found it, and asked for a table for one. The staff looked me up and down and said they were full; I don’t know whether I was too scruffy to eat there or whether they were actually full, or both. So I was a bit hungry, and wishing someone would hurry up and port Urbanspoon to the N900. (Yes, I know I could have used the website, but I would also have been wishing Urbanspoon covered Finland in the first place. And I had forgotten eat.fi. More fool me.)
But very soon, I found the cathedral, which made up for being hungry:
It’s rather large and very beautiful. I went inside, but it seemed rude to take pictures of that. There was a café in the crypt, but they close at 17:00, for some reason, just when people might be wanting to have dinner there.
On the way back, I went into an Indian restaurant but nobody came to help me and I left after a minute or so. Then I found a Chinese place called Tang Dynasty who were helpful, and I ate there.
After that I came back to the hotel and started coding. I have to be at the airport at five, so I’m planning to stay up. Unfortunately, the fire alarm went off: it wasn’t an actual fire, but I’m on the ninth floor and I’m too sensible to use the lifts, so it was a long walk. The fire brigade came and walked around: they wear black uniforms with the city arms on the back (a crowned boat).
I can finally tell you what I’ve spent the last year working on, and why I’ve been commuting back and forth to Helsinki. It’s a phone that runs Linux (a Debian-based distro called Maemo), and its name is the N900. I’ve been playing with it for months and I love it. Not only is it a phone and a Linux box in your pocket, it also runs robotfindskitten.
Day: Woke up, went to the gym, came back, worked, and ~plexq made us some rather good quesadillas. Fin made some lovely tag icons for marnanel.org to go along with the existing ones from rosequoll.
Theming: I would like to re-examine the Metacity theme format for GNOME 3. To this end, I’ve been working on CSS theming for Metacity. I have a reasonable first pass at it written, and several of the standard themes converted (and several more to do). But it occurs to me that the people who would like to create themes and the people who would be willing to download and compile several experimental libraries are not necessarily the same. To this end, I’ve created a wiki to demonstrate the system. If you write CSS on a page whose name begins with Borders: it will display as the result of rendering that CSS. There is a tour, which you should take first.
Please feel free to create your own themes, either from scratch or by making copies of the existing ones. I was going to finish off all the sample themes before announcing this, and also to make a theme wizard that would put together a theme for you from parts (to show how the system is well-adapted to use with editors), but I decided it was better to release early, release often.
Of course, now that I’ve announced this, it’s sure to be vandalised; I’ll try to keep an eye on it, but if you could revert any vandalism you see, I’d appreciate it. Let me know what you think of the system, either way.
Top fives: Ask me for my top five favourites of anything and I’ll try to give a sensible answer. So far I’ve been asked for cities, words, puddings, foods, beverages, heresies, books, and Tetris shapes. Since there are only seven Tetris shapes, that’s rather an easy question: the answer is all of them except “S” and “Z”.
When I was about fourteen my parents bought a PC to replace our ageing BBC Micro. There was an adventure game called Leisure Suit Larry which I had heard a lot about and was quite anxious to play. Once I had figured out how to win it, I set about cloning it, and in two years, with the help of my brother Mark who drew all the graphics, I produced a vaguely similar game about a Roman trying to escape Pompeii. It was released eighteen years ago next month. I’m not very proud of the code, though if I find a way of reading 5¼” disks I may open-source it. I’m not very proud of the story, either: I based the story around Roman farces, and though I thought it was quite funny when I was fifteen, the humour strikes me as juvenile and sexist now.
When I had done with that game, I wrote something better. This was Avalot, released sixteen years ago, where approximately the same cast of characters found themselves in the Middle Ages. I had no computer science training at the time, and was unaware of the concept of a virtual machine, but Avalot took several steps towards being a game program written on a general-purpose engine (the engine was called Avalanche). If I had had the opportunity to produce the planned third game of the series, it would presumably have been entirely abstracted. Avalot featured actual puzzles worthy of the name: I’m rather proud of the one about the onion. And I made some attempt to patch up the problems with the story which had been introduced in the first game, as well; Avalot’s wife had a little more to her personality than simply the nagging character from farce. It wasn’t perfect in the least, but it was light years ahead of the original game. Of course, by that time the standard of professional games had moved on, and Avalot looked dated even when it was released.
Both games were released as shareware, and neither made any appreciable amount of money. I think we all had dinner out once on the takings from the first game, and the second game didn’t even make that. But occasionally I still get fanmail.
Sometimes I wonder whether I should resurrect the Avvy franchise as Z-machine games, and whether that would give me a chance to finally fix the immaturity of the original code and of the original humour. I’m not sure, really.
Rio and I spent a good while today playing with Alice. We made a table with a button which, if pressed, would cause a yellow chicken to fly over and spin around. For her bedtime story I read her the first chapter of The Phoenix and the Carpet.
I should reiterate that, as I said at the time, I myself don’t think using WebKit in the window manager sounds like a good idea. Since someone had raised the idea, I thought it was worth discussing, and now it certainly has been discussed.
I was trying to typeset some of my work the other day (for some reason), and I noticed how odd it looks to set sonnets in a sans-serif font…
Further to my earlier post, there has been some more talk over at the Metacity blog about styling windows with CSS. There seem to be a few possible ways to implement this:
I was also concerned that using WebKit would not allow us to restrict the CSS, which is something we need to do a great deal:
Now someone from KDE says that this could be a great opportunity for cross-desktop interoperability: Metacity and Kwin could share theme formats. But apparently KWin already pulls in a WebKit dependency for other reasons, and the KDE person is planning to implement using WebKit anyway, and thinks that we should too.
I don’t know WebKit very well (and searching isn’t helping), but I thought some of you probably do. So what I would like to know is:
Does a good farmer neglect a crop he has planted?
Does a good teacher overlook even the most humble student?
Does a good father allow a single child to starve?
Does a good programmer refuse to maintain his code?— The Tao of Programming, 5.4
I like to make things. I like it a lot. It’s one of my favourite things in the world. I also like to maintain things: not quite as much, but still a lot. It’s fun as well as being a responsible thing to do.
The problem is this: the one leads inexorably to the other. If you spend thirty hours on a project, and you do it well enough that the project succeeds, you will spend three hundred hours maintaining it. Now, you only have so much time. If you spend a quarter of your time making things and the rest maintaining them, eventually you will have to stop making things in order to have enough time to maintain the things you have already made. You will have to take off the wizard’s hat and spend the rest of your life wearing only the cap of maintenance. And that’s a shame, because while maintaining things is fun, creating new things is more fun, and more like play; it would be a shame for it to vanish completely from your life. Note that I haven’t said I’m talking about software here. I am, partly, but it applies to other endeavours as well: I’m also thinking of fiction and poetry.
This whole line of thinking started the other day because the users of four of my old projects (very reasonably) started asking for certain fixes, at the same time as I had some ideas for new projects: I always have ideas for new projects, probably more ideas than I have years left in my life. I began to realise that not only did I not have time to work on any new projects in themselves, I wouldn’t have time to maintain them if I did.
This is also part of why I’m so excited both about gnome-shell and about the ideas which came up for Metacity at Gran Canaria; I’ve been only fixing bugs in Metacity, rather than adding new features, for over a year now. And perhaps that’s necessary; I like the idea of projects asymptotically approaching perfection. But it doesn’t solve the problem of decreasing creation opportunity over time.
So what are the solutions? There aren’t any good ones.
Is there a sustainable way to balance the desire to make new things with the ongoing responsibility to maintain them?
Photo © Jeff/Godfrey, cc-by-nc.
Most of what I do on Wikipedia is reverting vandalism, so I don’t want to introduce any more of it. But sometimes I daydream:
Or