Making Maemo email client usable with GMail

HowTo, Igalia, Linux, Maemo (EN) 6 Comments »

I must admit, I wasn't using Maemo email client, because I did find it was simply unusable, at least with my GMail account.

I tried both POP3 and IMAP, but having about 25.000+ messages in my account, downloading just the headers was a job that the client simply couldn't manage.

Yesterday I knew about "recent mode" support in POP3, a functionality that GMail supports too. This mode allow you to download only last 30 days messages (in my case, no more than 1000)  so the client can manage them without any problem.

All you have to do to enable this mode is put the "recent:" string before the username. For example: if your username is "username@gmail.com" you have to write "recent:username@gmail.com". Important: this mode only works with POP3, not with IMAP.

To conclude, let me say thank you to the kind guy who let me discover this mode. Thank you Sergio! Now there is another thing I can do with my tablet!

Writing Python bindings of existing C libraries – (2) – A simple example of binding

HowTo, Igalia, Linux, Maemo (EN), Programmazione, Python 1 Comment »

Introduction

As I promised in the preceding post, I'll provide a very easy example of a python binding. Let's suppose we don't want to use the methods included in Python to sum two integer values and we want to do it in C and then call the add method from a python script. I'll write the complete source code first and then I'll explain all the parts of it.

Source Code

#include <Python.h>

static PyObject *foo_add(PyObject *self, PyObject *args)
{
	int a;
	int b;

	if (!PyArg_ParseTuple(args, "ii", &a, &b))
	{
		return NULL;
	}

	return Py_BuildValue("i", a + b);
}

static PyMethodDef foo_methods[] = {
	    { "add", (PyCFunction)foo_add, METH_VARARGS, NULL },
	    { NULL, NULL, 0, NULL }
};

PyMODINIT_FUNC initfoo()
{
	    Py_InitModule3("foo", foo_methods, "My first extension module.");
}

How it works

First of all we have to include Python.h in our C file. This allows us to write an extension for Python language. To be able to include this header, we must have the python development packages installed in our system. For example in Debian based distributions we can install them with this command:

sudo apt-get install python2.5-dev

Every module has at least three parts. In the first part we write methods we want to call from the final python module: in this case we have a method called foo_add where "foo" is the name of the module and "add" the name of the method. Every method is declared as static PyObject. The method does anything particular except calling PyArg_ParseTuple to validate the input (we'll discuss this later), adding the two passed numbers and returning the result.

In the second part we have something like a dictionary, defined as static PyMethodDef and called foo_methods (where "foo" again is the name of the module). For each method we want to expose in our python module, we have to add something like this:

{"add", (PyCFunction)foo_add, METH_VARARGS, NULL}

where "add" is the name of the method we want to be visible in our module, (PyCFunction)foo_add is a pointer to our foo_add method, implemented in the C module, METH_VARARGS means that we want to pass some parameters to the function and the last one would be the description of the method (we can leave it NULL if we want).

Third part allows us to register the defined method/s and the module:

Py_InitModule3("foo", foo_methods, "My first extension module.");

Parsing Parameters

The PyArg_ParseTuple function extracts arguments from the PyObject passed as parameter to the current method and follows almost the sscanf syntax to parse parameters (in this case we had "ii" for two integers). You can fin the complete reference here: http://docs.python.org/c-api/arg.html

Building and installing

To build the module, we have to be in the source directory and execute this command:

gcc -shared -I/usr/include/python2.5 foo.c -o foo.so

then we've to copy the generated module to the python's modules directory:

cp foo.so /usr/lib/python2.5/site-packages/

Testing our module

Testing the module is really easy. We've to start a python shell or create a python script with the following source code:

import foo
print foo.add(2, 3)

if all is working fine, the printed result should be 5

References

python2.5-dev
python2.5-dev

MAFW and Python: asking for developers feedback

Igalia, Linux, Maemo (EN), Programmazione, Python 4 Comments »

MAFW is a new multimedia framework that will be used in Fremantle.

The PyMaemo team is currently working on writing bindings for Python
language for this library and at the moment we've released a 0.1
version of python-mafw that you can install directly from Scratchbox
repository.

Not all the methods are implemented (you can manage the Registry and
the Playlist, but nothing more), because even if we're using codegen
to generate bindings (and it's helping us a lot), we've seen that at
least 30-40 methods have to be overridden by hand so it's taking us
more time than we expected and we're trying to organize how to
continue this work.

We would like to get feedback from python application developers and
also from C application developers that are currently using MAFW so we
can work on a "roadmap" that reflects what developers want:

  • What are the functionalities you're using in your application that you think they cannot miss in the Python binding?
  • Have you already started using MAFW or even better python-mafw to develop something?
  • What is the currently missing method/methods you would like to be implemented first?

Come on developers! We're waiting for your feedback :)

Writing Python bindings of existing C libraries – (1) – Introduction

HowTo, Igalia, Linux, Maemo (EN), Programmazione, Python 2 Comments »

This summer I'm having the pleasure of working in Igalia (a spanish free software company) for a couple of months and they assigned me to an interesting project: developing Python bindings for MAFW library (a Maemo multimedia library that will be used in Fremantle release).

Having the opportunity to work both with C (yes, Python bindings are almost C code) and Python (it's a good practice to write unittest of all implemented methods) it's a good way to improve my knowledges in both languages and since I wasn't able to find much documentation about these kind of things, I'm going to share my own experiences.

What is a Binding?

A binding is a Python module, written in C language, that allows Python developers to call functions from existing C libraries from their python applications. It's just like a "bridge" from C world to Python one.

Why writing bindings?

There are a couple of reasons to write python bindings instead of writing a library in python language from scratch.

First of all I don't think is good duplicating code, so if a library already exists and it's written in C, why writing it again in another language? There's no reason. A lot of code already exist in C world and all we have to do is to create a bridge with python world.

Another good reason, in particular when a C library doesn't exist yet, is the fact that python code is slower than C code for some tasks (for example multimedia codecs). In these cases is good to implement the core library in C language and then create a python binding for it.

Coming next

As the title of this post says, this is only an introduction to the subjects I'm going to write about. If you have any particular request about any argument you would like to read, please feel free to leave me a comment. Next posts will talk about these things:

  • A simple example of binding: I'll write a simple library in C language and I'll show how to create the relative python binding, providing complete source code and an example for python developers.
  • Building and installing python bindings with distutils: I'll explain how to use distutils to build and install the binding (using the well know method "python setup.py install").
  • Defining new types: this post will be about how to write new types in C language and being able to use them from python code.
  • Using codegen to write bindings: I'll explain how to use codegen utils to automate lot of tasks, to generate the most part of binding code and how to customize the generated code using overrides.

I officially joined the PyMaemo team

Igalia, Linux, Maemo (EN), Programmazione, Python 7 Comments »

This summer I'm working for 2 months at Igalia, a spanish free software company, and they assigned me the project of writing a Python binding for MAFW (a new multimedia library that will be included in Freemantle).

After few days I discovered that PyMaemo team was already working to it, so I asked to join them and they accepted me!

I really love Python language and since I think other developers love it too, I think we should provide good bindings for every library available in Maemo, so lot of developers can start writing their applications in this language.

I'll work to this project full time until the first week of september, so I hope to be able to learn a lot and to contribute as much as I can to this project.

If anyone else want to join PyMaemo team and help us to develop Python bindings, I think he will be welcome!

Registration to Maemo Summit 2009 open!

Linux, Maemo (EN) No Comments »

Maemo LogoRegistration for the Maemo Summit 2009 has been opened.

The summit will have free entrance, but registration is required to grant you food, drinks, a maemo.org shirt and a seat. Please register as soon as possible, so we can get a clear picture of how many people are expected.

The registration form also has an option for sponsorship requests. Details about sponsorship will be published later and requests will be evaluated after this. You can always change your registration entry at a later point in time if needed.

The event location details and a list of participants can be found here.

See you all in Amsterdam at Maemo Summit 2009!

Ridimensionare immagini automaticamente con un batch e ImageMagick

HowTo, Linux No Comments »

Spesso capita di dover compiere azioni noiose e ripetitive su delle immagini, come ad esempio ridimensionarle o salvarle in formati diversi da quello originale. Queste operazioni possono richiedere moltissimo tempo, soprattutto se abbiamo a che fare con una grande quantità di immagini.

Per chi usa Linux è disponibile però l'utility ImageMagick, che unita ad un pizzico di script in bash ci permette di risolvere agevolmente il problema.

Per prima cosa è necessario installare il tool sulla propria distribuzione. Su Ubuntu (o in qualsiasi altra distribuzione basata su Debian) procedere nella seguente maniera:

sudo apt-get install imagemagick

A questo punto basta posizionarsi nella cartella dove si trovano le immagini (vi consiglio di crearvi una copia a parte delle immagini da modificare, visto che lo script andra' a lavorare direttamente su quelle originali) ed eseguire un comando come questo:

find ./ -iname '*.JPG' -exec convert '{}' -resize '1024' '{}' \;

Questo comando convertirà tutte le immagini .JPG che trova in un formato di 1024 pixel di larghezza, mantenendo ovviamente le proporzioni dell'immagine originale.

Risolvere il crash all’avvio di Songbird su Ubuntu

HowTo, Linux, Ubuntu 3 Comments »

songbird_screenshot_0Se si prova a far girare la versione di Songbird scaricabile dal sito ufficiale su Ubuntu (ma il problema sembra riguardare anche altre distribuzioni visto che si tratta di un bug del driver Nvidia) si otterrà quasi sicuramente un crash dell'applicazione stessa.

Per risolvere il problema è sufficiente disinstallare un plugin (libvisual-0.4-plugins) utilizzando il seguente comando: sudo apt-get remove libvisual-0.4-plugins

Una nota negativa: questo bug è presente fin dalla versione 8.10 di Ubuntu... che aspettano a correggerlo invece di far ricorrere gli utenti a questi trucchetti?

Last.fm: the money music revolution!

Recensione 5 Comments »

lastfmNon c'è alcun errore nel titolo di questo post. Sebbene lo slogan originale di Last.fm fosse "The Social Music Revolution", ho voluto modificarlo in questo modo, per sottolineare il recente cambiamento di rotta di un servizio che fino a pochi giorni fa ritenevo uno dei migliori, se non il migliore, del suo genere.

Facciamo un passo indietro per spiegare cos'è Last.fm. Si tratta di un servizio che permette, una volta registrati, di condividere le canzoni che ascoltiamo (titolo e autore, non il file audio) in modo che si possa essere messi in contatto con altre persone che ascoltano i nostri gruppi preferiti oppure di ricevere suggerimenti su gruppi simili a quelli che ascoltiamo. Grazie a questa funzione ho avuto la possibilità di conoscere ed apprezzare gruppi musicali di cui prima ignoravo l'esistenza.

Oltre a permettere lo scrobbling (invio del titolo della canzone) e la creazione automatica di classifiche, il sito mette a disposizione moltissimi strumenti che hanno permesso la creazione di una vasta community musicale. La community, grazie a questi strumenti, ha arricchito il sito web di moltissimi dati importanti: un wiki con i dati dei gruppi musicali, i tag su ogni canzone, gruppi di discussione e la creazione di eventi e ritrovi. Last.fm è anche una "radio", ma in un modo un po' diverso rispetto a quello a cui siamo abituati.

Non esistono playlist valide per tutti gli utenti, ogni utente ha la propria playlist, in base ai brani ascoltati, ai gruppi simili ed ai suggerimenti degli amici. Oltre alle proprie playlista è inoltre possibile ascoltare quelle dei "vicini", degli amici e dei gruppi ai quali siamo iscritti. Se oggi Last.Fm è diventata quello che tutti vediamo, è in gran parte grazie al lavoro svolto dalla community musicale.

Che cosa è successo per portarmi alla decisione di eliminare il mio account, vecchio di 3 anni, con piu' di 30.000 brani ascoltati?

Circa un mese fa i vertici di Last.fm hanno deciso che entro poco tempo il servizio di radio in streaming sarebbee diventato a pagamento, a causa dell'aumento dei costi di licenza imposti dalle major. Per continuare ad ascoltare la radio si dovranno pagare 3€ al mese. Quello che ha scatenato l'ira di moltissimi utenti e che mi ha fatto prendere la decisione di disiscrivermi, è il fatto che USA, Inghilterra e Germania potranno continuare ad usufruire gratuitamente del servizio. Questa divisione in paesi di serie A e paesi di serie B non è piaciuta proprio a nessuno, basta guardare le centinaia di commenti che sono arrivati sul blog ufficiale di Last.fm.

Io mi associo al pensiero comune: se anche USA, Inghilterra e Germania pagassero, il costo potrebbe scendere a 1 o 2 euro al mese ed inoltre non ci sarebbero divisioni e/o discriminazioni a seconda del paese di provenienza. Avrei pagato volentier anche 3€/mese se non ci fossero state queste differenze. Perchè gli altri paesi devono pagare pochi privilegiati?

A mio parere Last.fm ha commesso un gravissimo errore facendo questa mossa e sono convinto che entro breve perderà moltissimi utenti smettendo inoltre di essere una community ricca di contenuti creati dagli utenti stessi. Staremo a vedere se ci saranno inversioni di rotta o se continueranno a seguire questa strada.

Come passare dalla modalità enduser alla modalità developer su Fonera 2

HowTo, Linux, Recensione No Comments »

Fino ad ora, i possessori di Fonera 2.0 che volevano passare alla modalità "developer" (e quindi avere anche l'accesso via SSH) dovevano flashare la fonera con un'apposita immagine, facendo uso del cavo seriale oppure della procedura con il cavo di rete che utilizza Redboot.

Da oggi è disponibile un nuovo plugin che permette di passare automaticamente alla modalità developer, basta andare (ad esempio) su questa pagina del router: http://192.168.0.105/luci/fon_devices/fon_plugins

La Fonera passerà a questo punto in modalità developer e dovremo effettuare due reboot affinchè SSH sia attivato. Non dimenticatevi ovviamente di aprire l'accesso SSH nella configurazione del firewall della Fonera. Accedendo via SSH, vi troverete davanti questi messaggi:

andy80@andy80-jaunty:~$ ssh root@192.168.0.105
The authenticity of host '192.168.0.105 (192.168.0.105)' can't be established.
RSA key fingerprint is e5:6e:fc:70:73:44:f6:cd:30:bd:ac:2d:53:d2:ab:a9.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.0.105' (RSA) to the list of known hosts.
root@192.168.0.105's password: 

BusyBox v1.11.1 (2009-04-17 12:45:57 CEST) built-in shell (ash)
Enter 'help' for a list of built-in commands.

                                        __
                                    _.-~  )
                         _..--~~~~,'   ,-/     _
                      .-'. . . .'   ,-','    ,' )
                    ,'. . . _   ,--~,-'__..-'  ,'
                  ,'. . .  (@)' ---~~~~      ,'
                 /. . . . '~~             ,-'
                /. . . . .             ,-'
               ; . . . .  - .        ,'
              : . . . .       _     /
             . . . . .          `-.:
            . . . ./  - .          )
           .  . . |  _____..---.._/ ____ Seal _
     ~---~~~~----~~~~             ~~                

                      Flipper                       

--------  Fonera 2.0 Firmware (v2.2.5.0) -----------
      * Based on OpenWrt - http://openwrt.org
      * Powered by FON - http://www.fon.com
----------------------------------------------------
root@Fonera:~# uname -a
Linux Fonera 2.6.26.2 #9 Tue Apr 21 11:32:31 CEST 2009 mips unknown
root@Fonera:~#

Cercherò prossimamente, nel caso ci sia interesse, di scrivere qualche post piu' approfondito su questa nuova Fonera, in modo da mostrare le caratteristiche di questo dispositivo.

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in