QUrl (mis)usage: appendix, avoid automatic cast from QString

As I was introducing in the former entry QUrl (mis)usage, the direct creation of a QUrl from a QString should be avoided in any software that is not trying to smartly guess what a user input should lead to.

So, going directly to the ham, to avoid mistakes due to automatic conversions from QString to QUrl, I encourage the usage of the QT_NO_URL_CAST_FROM_STRING macro. The only thing you have to do is adding a line to your qmake project file like this:

# Avoid automatic casts from QString to QUrl. Dangerous!!!
DEFINES += QT_NO_URL_CAST_FROM_STRING

Or add it directly to the compilation line, like this

g++ ... -DQT_NO_URL_CAST_FROM_STRING ...

As I was pointing in my previous post, the usage of QUrl::fromLocalFile(QString) and QUrl::fromEncoded(QByteArray, QUrl::StrictMode) is recommended when dealing with QString and QUrl, but committing mistakes is a human condition so it is pretty easy to end passing a QString as a parameter to some API expecting a QUrl, or assigning a QString to a QUrl with the “=” operator through the C++ automatic cast mechanism which is implemented in the QUrl class. That’s why forbidding these automatic casts in our code is of such importantance.

blog.andresgomez.org

I’ve just migrated my blog to a new domain, blog.andresgomez.org, and this is the first post I write on it.

I hope to extend it now more often and with more “unpolite thinking” entries 🙂 .


Acabo de migrar mi blog a un nuevo dominio, blog.andresgomez.org, y esta es la primera entrada que escribo en él.

Espero aumentar el número de entradas más a menudo y con un mayor número de “unpolite thinking” 🙂 .

QUrl (mis)usage

Lately, I’ve been developing some software which makes an intensive usage of QUrls as resource locators for local files. Nothing wrong here. QUrl is a powerful way of sharing the locations of those in an universal way. The problem is when you construct those QUrls from QStrings and you actually forget that QUrls are meant for much more than representing local file locations.

Authority chunks on an URL

Authority chunks on an URL

At the moment of writing this, QUrl documentation, although quite complete, could be much more explanatory. For example, it says that the recommended way for creating a QUrl from a QString is:


* When creating an URL QString from a QByteArray or a char*,
always use QString::fromUtf8().
* Favor the use of QUrl::fromEncoded() and QUrl::toEncoded()
instead of QUrl(string) and QUrl::toString() when converting
QUrl to/from string.

But this is explained in the documentation for QUrl::fromUserInput(), instead of in the Detailed Description [ 1 ].

What is important from this explanation is that it is not a matter of favor the use of QUrl::from/toEncoded() over QUrl::(from)toString() but, I would say, a must if you don’t want to end up with bogus corner cases.

Why would this happen? Well, as I was saying, QUrl is meant for much more than universally representing the location of a file so, here go the big tips:

  1. If you want to get the QUrl from a local file represented with a QString, use always QUrl::fromLocalFile ( const QString & localFile ) . Don’t use QUrl::QUrl ( const QString & url ) if you don’t want to end up with some problems. In the same way, get the path to the local file always with QUrl::toLocalFile().
  2. If you want to get a QUrl from a QString representing an URL, be sure that the QString is actually representing a percent encoded URL, as it should to be a valid URL, and always use QUrl::fromEncoded ( const QByteArray & input, ParsingMode parsingMode ), with QUrl::StrictMode as the QUrl::ParsingMode.
  3. If you want to get a QString representation of an URL from a QUrl use always QUrl::toEncoded ().

Bogus examples for each case:

Local file

/mypath/my#file.jpg

Correct:

QUrl myUrl = QUrl::fromLocalFile("/mypath/my#file.jpg")

Incorrect:

QUrl myUrl = QUrl("file:///mypath/my#file.jpg")

The problem here is the way QUrl will treat the “#” character in the second example. It will think, as it actually doesn’t have a way of guessing, that the character is delimiting the fragment part of the URL.

Fragment part on an URL

Fragment part on an URL

As a result, calling to:

myUrl.toLocalFile()

in the first case will result to:

/mypath/my#file.jpg

while in the second will be:

/mypath/my

Parsing mode

/mypath/my#file.jpg

(encoded) url representation:

file:///mypath/my%23file.jpg

Correct:

QUrl myUrl = QUrl::fromEncoded("file:///mypath/my%23file.jpg", QUrl::StrictMode)

Incorrect:

QUrl myUrl = QUrl::fromEncoded("file:///mypath/my%23file.jpg")

The problem here is the way QUrl will treat the “%23” encoding in the second example. Although it is not explicitly explained in the documentation [ 2 ], QUrl will use QUrl::TolerantMode as ParsingMode by default. Therefore, it will think that the input comes from an ignorant user which was actually trying to pass “file:///mypath/my#file.jpg”. Again, it will understand after converting back “%23” to “#”, that the character is delimiting the fragment part of the URL.

As a result, calling to:

myUrl.toLocalFile()

in the first case will result to:

/mypath/my#file.jpg

while in the second will be:

/mypath/my

Encoded usage

/mypath/my#file.jpg

(encoded) url representation:

file:///mypath/my%23file.jpg

(unencoded and wrong) url representation:

file:///mypath/my#file.jpg

Correct:

QUrl myUrl = QUrl::fromEncoded("file:///mypath/my%23file.jpg", QUrl::StrictMode)

Incorrect:

QUrl myUrl = QUrl("file:///mypath/my#file.jpg")

Here, we have another incarnation of the very same problem than the two examples above. QUrl will think, again, as it actually doesn’t have a way of guessing, that the character is delimiting the fragment part of the URL.

As a result, calling to:

myUrl.toLocalFile()

in the first case will result to:

/mypath/my#file.jpg

while in the second will be:

/mypath/my

Corollary:

The default behavior of QUrl is to provide an easy handling of URLs to the user of our programs, the end user, but not the user of QUrl, the developers. I find this quite awkward but, still, it is a decision of Qt people and, as developers, we only have to take this into account when writing our code.

These bogus URLs, which are to be corrected with the usage of the QUrl::TolerantMode ParsingMode, usually come from a text entry box “à là” browser location bar, but this use case is, actually, not so common when talking from the developer’s point of view. When dealing with URLs in our code we have to take into account what an URL is and how it should be formatted/encoded to be valid. Therefore, if I’m receiving a wrongly encoded URL I should go to the source code providing this URL and fix the problem there rather than trying to smartly guess which should be the proper URL. For example, in my software currently in development we use Tracker and I rely on it to feed my code with properly formatted URLs. If for some reason Tracker gives me a wrongly encoded one, the place for solving it is, actually, Tracker, and not my software. I should not and must not interpret what Tracker may have wanted to pass me, but open a bug in its bugzilla and provide as accurate information as I can to help them solve this issue.

Just so my friend Iván Frade doesn’t kill me, make notice that Tracker is, so far, perfectly dealing with URLs 🙂

Honored to share with you: 4 new partners at Igalia

Lately I’ve not been blogging that often. My daily work has lead me to be more involved in the coordination of development teams rather than in the development itself. Therefore, it becomes more difficult to talk about this or that GNOME related technology.

Even, early this week, I’ve been attending a Scrum Mastering course. Not that I’m a crazy fan of Scrum. As other Agile methodologies, it has pros and cons so, better you get what it works for you and forget about the rest. But that would be the subject for another post …

This post is about an event that happened at Igalia some days ago which maybe you already are aware of.

Four Igalians have joint the group of shareholders of the company and this is not something that happens every day.

Being already an owner myself, I’m really happy and honored of these 4 fellows having accepted the offer to get a part of my company:

    Alejandro Piñeiro, or API, as he is broader known, has been involved in GNOME related technologies for quite a lot. However, you may know him for his Accessibility work, mainly with Hildon, Clutter and Gnome Shell.
    Javier Muñoz is one of the Igalians in the shadow since, as an experienced sysadmin and team coordinator, has less opportunities to have some focus and receive congratulations. Not surprisingly, Igalia is able to run every day because of his restless effort 🙂

Personally, I think it is something logical to extend the sharing philosophy of the Free Software to the management and decisions taking processes of the company. Our greatest good is our staff and what they have been working for is exactly the same values for what the founders created Igalia 9 years ago, having into account our self imposed professional, internal and social responsibilities.

All, in all, I’m very happy today 🙂

Congrats, guys, I’m really honored of sharing with you!!!

Grub2 splash theme for Igalia

Igalia Grub2 splash

Following with the idea of creating a full theme for Igalia covering the whole artwork that is shown in a Gnome desktop. I’ve created a Debian package and a sample picture to place in the Grub2 splash, at the computer startup. I’ve uploaded it to a public Git repository which you can download with the following command:

$ git clone http://git.igalia.com/art/grub2-igalia-splashimages.git

You can create and install the Debian package with:

$ cd grub2-igalia-splashimages
$ dpkg-buildpackage -rfakeroot
...
$ dpkg -i ../grub2-igalia-splashimages*deb

In order to use any of the images in the package to show as Grub2 splash, you just have change a line like:

$ cat /etc/grub.d/05_debian_theme 
...
  for i in {/boot/grub,/usr/share/images/desktop-base}/moreblue-orbit-grub.{png,tga} ; do
...
  set color_normal=black/black
  set color_highlight=magenta/black
...

to

$ cat /etc/grub.d/05_debian_theme 
...
  for i in {/boot/grub,/usr/share/images/desktop-base,/usr/share/images/grub}/igalia_black.{png,tga} ; do
/some_file.tga
... 
  set color_normal=light-gray/black
  set color_highlight=white/black
... 

and run:

$  update-grub2

Grub splash theme for Igalia

Igalia Grub splash

Lately, some people at Igalia have been thinking about creating a full theme for the company covering the whole artwork that is shown in a Gnome desktop. With this in mind, I’ve been playing for a while in order to create some sample pictures to place in the Grub splash, at the computer startup. I’ve create my first serie of 3 images and I’ve uploaded them, and the material needed to create them, in a public Git repository which you can download with the following command:

$ git clone http://git.igalia.com/art/grub-theme-igalia.git

I’ve not created a Debian package to comfortable install them yet but, in the meanwhile, I suggest to make use of the “mini” version, which thumbnail you can see at the top of this post. Just compress the file with gzip (not really needed) and place it in the  your favorite directory for Grub splash images. For example:

$ gzip -c igalia-grub-splash-mini.xpm > /boot/grub/igalia-grub-splash-mini.xpm.gz

Then, you just have to select such splash image in the “menu.lst” grub file. Also, I recommend to modify the preferred background and foreground colors for the booting menu:

$ cat /boot/grub/menu.lst
...
splashimage=(hd0,0)/grub/igalia-grub-splash-mini.xpm.gz

foreground=8cb6d2
background=14418b

Ubuntu Usplash theme for Igalia revamped (a.k.a. Jaunty’s edition)

Jaunty Usplash 300x225

Following my post about the creation of an Usplash theme for Igalia, I’ve just revamped the package and artwork to the latest stable version of Ubuntu. Therefore, as always, helped by Juan, here you are the i386 package for Ubuntu Jaunty, or the source code from our brand new public Git repository, if you want to play with it, through the following command:

$ git clone http://git.igalia.com/art/usplash-theme-igalia.git

Igalia is yours

Igalos at 2008/06 summit

As you may know, Igalia is a singular company. Not only because it works on free software and their members are a bunch of geeks but because it works as a democracy with a flat structure. What actually does this mean? Well, briefing, every worker in Igalia has the right to end owning a part of the company after 4 years, and to take part on the decisions of the company pretty soon, just after 1 year, usually.

As a partner, owning a part of Igalia in the same conditions as the other company partners, but not a founding member, I’ve gone through the whole process, worker, worker with participation in assemblies and right to vote on decisions (we call them “prepartners” in Igalia) and, finally, partner. With this background I can, more or less, to give some advices to those that, like me, started to work in Igalia after its foundation.

What I would say to anyone who starts working in Igalia is that they feel Igalia as being of them as much as any other partner actually and legally is.

This is the most important thing and, actually, if everything goes well for both parts, as it usually goes, they will own Igalia in the end.

Igalos at 2008/10 summit

The reason is easy, anytime I talk to my friends or family about Igalia’s business model, the same subject rises up. “Yeah, yeah, this is quite romantic, but you are living in real world and for sure there should be someone who is taking advantage of your model to work less and earn as much as the others. That won’t work in the end.” In fact, reality gives us the reason. That is the way of thinking of someone who is used to the general business model with a hierarchy in the company, workers and bosses. What it happens in Igalia is that every Igalo or Igala is interested in the success of the company, at least, as much as any other partner, because they know that the success of the company is their success now and in the future. Indeed this is such in this way that sometimes workers tend to think that they have to work harder since they will feel ashamed if they can’t cope with the same work or expertise than other Igalos. Of course, this is not true since, in my honest opinion, Igalia can be quite proud of having one of the best staffs in the (Free) Software business, but I cannot be objective 😉 .

Even if sometimes I don’t agree with some of the ideas of my partners, I know that they are always thinking in the best for the company and I assume Igalia’s decisions as mine as soon as they are approved. In any case, it’s the common way that all the decisions are taken after debate and agreement better than going through a “cold” polling 🙂 .

So, because all of this, the Igalians have the possibility, and even the must to share their ideas or concerns about the way to enhance our company because every single member of this company acts and thinks in the best way to improve it.

May Igalia be with you 😉 .

Ubuntu usplash theme for Igalia

Usplash 300x225

As you may know, every now and then I try to convince myself that I have an idea about drawing or doing cool stuff 😉 . My last attempt, helped by Juan, has been an Usplash theme for Igalia, based on Hardy’s one for Ubuntu. You can download the proper i386 package for Ubuntu, or the source code from our public CVS repository, if you want to play with it, through the following command:

$ cvs -z3 -d :pserver:anonymous@cvs.igalia.com:/var/publiccvs co art/usplash-theme-igalia

Update: I almost forgot. If you have more than one Usplash theme installed you can select to use Igalia’s one with the following command:

$ update-usplash-theme usplash-theme-igalia

Update2: Thanks to Manuel, we have now an amd64 version for Ubuntu 🙂 .

A Coruña proposed to hold GUADEC and aKademy 2009

As this will be my first post at planet GNOME, first I would like to thank Jeff for giving me a place between all of you, and I will introduce briefly myself.

My name is Andres Gomez, I’ve been using free software for 8 years, and I’m a free software developer since 2003, when I joined Igalia. As most of my mates, I contributed to project Fisterra, a free software framework for developing enterprise applications, and I’ve been lately involved in some projects related to Maemo technologies.

Now the interesting part of the post 😉

As my mate Chema has published recently in his blog, people from GPUL, Igalia and University of A Coruña have presented a proposal to co-host GUADEC and aKademy next year in A Coruña. The intention was to show all the possibilities that our city and team have in order to organize such a great event to the community.

Foto nocturna de la bahía del Orzán desde el monte de San Pedro (Coruña)

The proposal’s main idea is:”We want to organize a conference by community people for community people“. Here, in A Coruña, we have the facilities, a passionate team and a lot of ideas after attending several conferences and organizing lots of events (DudesConf 2008, GUAdemy 2007, Guadec-ES 2005, …). We know how important the details are, as well as having second options in case the first one could eventually fail. The main goal is to invest a big effort in achieving that people can come here next year. Because of this, the main expense in our budget will go for helping people to attend the event through sponsoring as many people as possible. That will be feasible thanks to the contribution of the University and volunteers. They will provide, almost for free, all the basics needed to run these two conferences. Also, our regional government, Xunta de Galicia, has an important commitment with this proposal and great confidence in our work at every level. So here it is the final proposal:

BTW, if these events are finally going to be hold here, I will volunteer on them so I will be able to give you advices to visit this beautiful Galician city placed in the north-western coast of Spain 🙂 .