It's mostly directly from the maemo-examples and the abook example. I attached a short example and a pro file for it that uses pkg_config for it. It prints out the names in the address book. It needs to be run via run-standalone.sh.
-Tatu On Mon, Jul 6, 2009 at 11:14 AM, David Greaves <[email protected]> wrote: > Tatu, could you post a link to your code? I'm really interested in seeing > an > example of the addressbook connectivity. > > Also I came across this: > http://www.kdedevelopers.org/node/3878 > which may be useful. > > David > > Tatu Lahtela wrote: > > Ok talking to my self now :) > > > > Thanks Antonio, that QT library loading seemed to do the trick. I was > > able to access the data with the libebook c api, that osso api wasn't > > required. > > > -- > "Don't worry, you'll be fine; I saw it work in a cartoon once..." > -- Tatu Lahtela <[email protected]>
#include <QLibrary>
#include <QStringList>
#include <QDebug>
#include <libebook/e-book.h>
static QLibrary *qgconf_libgconf = 0;
/* Initialize the contact list connections and widgets */
QStringList createContactList()
{
EBook *book;
GError *error = NULL;
GList *g_contacts;
EBookQuery *query;
QStringList contacts;
/* Request a handle to the system-wide addressbook
* The book isn't opened yet. */
book = e_book_new_system_addressbook(&error);
if (!book) {
qDebug() << "Couldn't open addressbook: %s" << error->message;
g_error_free(error);
return contacts;
}
/* Open connection to the address book */
if (!e_book_open(book, FALSE, &error)) {
qDebug() << "Couldn't open addressbook: %s" << error->message;
g_error_free(error);
return contacts;
}
/* Create a query. This query matches any
* records in the book. */
query = e_book_query_any_field_contains("");
if (!e_book_get_contacts (book, query, &g_contacts, NULL)) {
qDebug() << "Couldn't get query results.\n";
return contacts;
}
if (g_contacts == 0) {
qDebug() << "no contacts";
} else {
do {
EContact* contact = (EContact*)(g_contacts->data);
EContactName* name = (EContactName*)e_contact_get(contact, E_CONTACT_NAME);
contacts.append(QString(e_contact_name_to_string(name)));
} while(g_contacts->next);
}
return contacts;
}
bool loadGConf()
{
g_type_init();
static volatile bool triedToLoadLibrary = false;
QLibrary *&lib = qgconf_libgconf;
if (triedToLoadLibrary)
return lib && lib->isLoaded();
qDebug() << "loading gconf";;
lib = new QLibrary(QLatin1String("gconf-2"));
triedToLoadLibrary = true;
if (lib->load() && lib->resolve("gconf_client_get_default")) {
qDebug() << "load successfull!";
return true;
} else {
qDebug() << "Load failed";
lib->unload();
delete lib;
lib = 0;
return false;
}
}
int main()
{
loadGConf();
qDebug() << "contacts found: ";
foreach(QString contact, createContactList()) {
qDebug() << contact;
}
return 0;
}
contacts.pro
Description: application/vnd.nokia.qt.qmakeprofile
_______________________________________________ maemo-developers mailing list [email protected] https://lists.maemo.org/mailman/listinfo/maemo-developers
