Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

How to use native Maemo 5 contacts dialogs

From Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): N900
Compatibility
Platform(s): Maemo
Article
Keywords: Qt, Maemo
Created: gnuton (21 Jun 2010)
Last edited: hamishwillee (30 Apr 2013)

This article shows how to use native dialogs for displaying contact information on Maemo 5 devices. Note that at time of writing Qt Mobility contacts back-end allows contact management but does not allow the possibility of contact display using native dialogs. There is an outstanding bug for this functionality here: QTMOBILITY-223.

Contents

Source code

The QOssoAbookDialog class has several static methods that can be used to display Maemo5 native dialogs. Here how this class can be used:

#include "qossoabookdialog.h"
#include <QtGui>
 
int main (int argc, char **argv)
{
QApplication app(argc, argv);
 
QStringList IDs = QOssoABookDialog::contactChooser("Please select a contact");
qDebug() << "MY ID" << IDs;
foreach(QString id, IDs){
QOssoABookDialog::contactEditor(id);
}
 
return app.exec();
}

native.pro

QT       += core gui
 
TARGET = NativeDialogs
TEMPLATE = app
 
 
SOURCES += main.cpp\
qossoabookdialog.cpp
 
HEADERS += qossoabookdialog.h
 
FORMS +=
 
CONFIG += link_pkgconfig
PKGCONFIG += gtk+-2.0 libosso-abook-1.0

qossoabookdialog.h

#ifndef QOSSOABOOKDIALOG_H
#define QOSSOABOOKDIALOG_H
 
#include <libosso-abook/osso-abook.h>
 
#include <QObject>
#include <QStringList>
 
class QOssoABookDialog : public QObject
{
Q_OBJECT
public:
explicit QOssoABookDialog(QObject *parent = 0);
 
static QStringList contactChooser(const QString& windowTitle,
OssoABookCapsFlags caps = OSSO_ABOOK_CAPS_ALL,
OssoABookContactOrder order = OSSO_ABOOK_CONTACT_ORDER_NAME);
static void contactEditor(const QString& id);
 
private:
static OssoABookContact *lookup(const QString& id);
};
 
#endif // QOSSOABOOKDIALOG_H

qossoabookdialog.cpp

#include "qossoabookdialog.h"
#include <QDebug>
 
QOssoABookDialog::QOssoABookDialog(QObject *parent) :
QObject(parent)
{
}
 
QStringList QOssoABookDialog::contactChooser(const QString& windowTitle, OssoABookCapsFlags caps, OssoABookContactOrder order)
{
QStringList rtn;
GtkWidget* contactChooser = osso_abook_contact_chooser_new_with_capabilities (NULL, qPrintable(windowTitle), caps, order);
 
//Shows a modal dialog.
GList* contacts; // Do not free
if (gtk_dialog_run(GTK_DIALOG(contactChooser)) == GTK_RESPONSE_OK){
contacts = osso_abook_contact_chooser_get_selection(OSSO_ABOOK_CONTACT_CHOOSER(contactChooser));
while (contacts){
EContact* eContact = E_CONTACT(contacts->data);
const char* id = (const char*)e_contact_get_const(eContact, E_CONTACT_UID);
rtn << QString::fromLatin1(id);
contacts = contacts->next;
}
}
gtk_widget_destroy(contactChooser);
 
return rtn;
}
 
void QOssoABookDialog::contactEditor(const QString& id){
OssoABookContact* contact = QOssoABookDialog::lookup(id);
 
OssoABookContactEditorMode mode = (contact) ? OSSO_ABOOK_CONTACT_EDITOR_EDIT : OSSO_ABOOK_CONTACT_EDITOR_CREATE;
 
GtkWidget* contactEditor = osso_abook_contact_editor_new_with_contact(NULL, contact, mode);
gtk_dialog_run(GTK_DIALOG(contactEditor));
gtk_widget_destroy(contactEditor);
}
 
OssoABookContact* QOssoABookDialog::lookup(const QString& id){
GList* l = NULL; // Do not free
GError *error = NULL;
OssoABookAggregator* aggregator = NULL; // Do not free
 
aggregator = (OssoABookAggregator*) osso_abook_aggregator_get_default(&error);
if (error){
qWarning() << "error opening addressbook" << error->message;
g_error_free (error);
return NULL;
}
 
l = osso_abook_aggregator_lookup(aggregator,qPrintable(id));
 
return (OssoABookContact*) l->data;
}
This page was last modified on 30 April 2013, at 05:58.
41 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×