September 18, 2010

David Talmage David Talmage
Lab Rat
51 posts

osso_abook_contact_chooser_select_contacts() usage with Qt

 

I’m developing a Qt program for the N900. It needs to select more than one contact at a time. I want to present a list of contacts with some contacts pre-selected. I can’t figure out how to show this in an OssoABookContactChooser. Can you help, please? Perhaps there is a better way than the one that I have chosen.

I started with the useful example at How to user native Maemo5 contacts dialogs [wiki.forum.nokia.com]. I changed it to permit multiple selections. I use osso_abook_contact_chooser_select_contacts() to tell it which ones I want selected when I show the dialog. When I show the dialog, there are no contacts already selected.

Here is a fragment of the code that I am using:

  1. // list of QString representations of contact UIDs
  2. // This is already populated for me and I can prove that the
  3. // strings in it represent valid contact UIDs.
  4. QStringList *selectedContacts = ...;
  5. GList *g = 0;
  6. GtkWidget* contactChooser = osso_abook_contact_chooser_new_with_capabilities (NULL, qPrintable(windowTitle), caps, order);
  7. osso_abook_contact_chooser_set_minimum_selection(OSSO_ABOOK_CONTACT_CHOOSER(contactChooser), lower_limit);
  8. osso_abook_contact_chooser_set_maximum_selection(OSSO_ABOOK_CONTACT_CHOOSER(contactChooser), upper_limit);
  9.  
  10. if (0 != selectedContacts) {
  11.     QString contact;
  12.     foreach (contact, *selectedContacts) {
  13.  
  14.           qDebug() << "Looking up " << contact;
  15.  
  16.           OssoABookContact *c = QOssoABookDialog::lookup(contact);
  17.           if (0 != c) {
  18.  
  19.                 qDebug() << "Found "
  20.                              << osso_abook_contact_get_uid(c)
  21.                              << " "
  22.                              << osso_abook_contact_get_display_name(c);
  23.                 g= g_list_prepend(g, c);
  24.           } else qDebug() << "Did not find " << contact;
  25.     }
  26.  
  27.     osso_abook_contact_chooser_select_contacts(OSSO_ABOOK_CONTACT_CHOOSER(contactChooser), g);
  28. }
  29.  
  30. //Shows a modal dialog.
  31. GList* contacts; // Do not free
  32. if (gtk_dialog_run(GTK_DIALOG(contactChooser)) == GTK_RESPONSE_OK){
  33.   ...
  34. }

4 replies

September 19, 2010

Benjamin Poulain Benjamin Poulain
Lab Rat
144 posts

You should ask the question on Maemo’s forums. They generally know a lot more than we do about the services.

September 19, 2010

Tobias Hunger Tobias Hunger
Hobby Entomologist
3373 posts

I think you will have more luck with this question on the Maemo forum: While it is possible to mix Gtk and Qt widgets it is nothing most people here have much experience with.

If you can not get the information you need from QtMobility (which has a contacts API IIRC), then you are better of with pure Gtk code in my opinion: Your application will be Maemo specific anyway, so why bother with the added complexity of mixing Gtk and Qt?

September 24, 2010

David Talmage David Talmage
Lab Rat
51 posts

As far as I can tell, QtMobility doesn’t provide a way to select contacts in a finger-friendly way. It only provides a way to manipulate contacts.

I am writing my application using Qt 4.7 because that’s what comes with QtCreator. This is my first foray into Qt programming and programming for the N900 phone.

If I want finger-friendly selection, I must either use the older Maemo functions or make my own out of raw Qt. I guess I could do the latter but I’d rather use the former for the time being because it should mean that I have to write much less code. Eventually, I will throw away the Maemo-specific things.

I thank the two of you, Tobias Hunger and Benjamin Poulain, for your advice. I am seeking an answer on the Maemo forum.

November 7, 2010

David Talmage David Talmage
Lab Rat
51 posts

There is an end to this story. I wrote my own finger-friendly Qt implementation of Maemo5’s native contact chooser. As far as I can tell, no Maemo5 developer ever used the native one in the way I want to use it. I’ll go so far as to say that the native one is broken.

Writing my own was harder than I expected but not impossible. I had some help from some Trolls at Qt Developer Days in San Francisco. I’m grateful for their eager, friendly help. Thanks to Martin, Benedikte, and Pierre.

 
  ‹‹ Which Symbian SDK is in the Nokia Qt SDK      Making Application Launcher Icon ››

You must log in to post a reply. Not a member yet? Register here!