Added ContactManager class.
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Wed, 25 Aug 2010 12:13:52 +0000 (15:13 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Wed, 25 Aug 2010 12:13:52 +0000 (15:13 +0300)
19 files changed:
src/engine/contactmanager.cpp [new file with mode: 0644]
src/engine/contactmanager.h [new file with mode: 0644]
src/engine/contactmanagerprivate.cpp [new file with mode: 0644]
src/engine/contactmanagerprivate.h [new file with mode: 0644]
src/engine/contactmanagerprivatestub.cpp [new file with mode: 0644]
src/engine/contactmanagerprivatestub.h [new file with mode: 0644]
src/engine/engine.cpp
src/engine/engine.h
src/src.pro
src/ui/friendlistitem.cpp
src/ui/friendlistitem.h
src/ui/friendlistpanel.cpp
src/ui/friendlistpanel.h
src/ui/listview.cpp
src/ui/listview.h
src/ui/mainwindow.cpp
src/ui/mainwindow.h
src/ui/ossoabookdialog.cpp [new file with mode: 0644]
src/ui/ossoabookdialog.h [new file with mode: 0644]

diff --git a/src/engine/contactmanager.cpp b/src/engine/contactmanager.cpp
new file mode 100644 (file)
index 0000000..0e39bf3
--- /dev/null
@@ -0,0 +1,32 @@
+#include <QDebug>
+
+#if defined(Q_WS_MAEMO_5) & defined(ARMEL)
+#include "contactmanagerprivate.h"
+#else
+#include "contactmanagerprivatestub.h"
+#endif
+
+#include "contactmanager.h"
+
+ContactManager::ContactManager(QObject *parent)
+    : QObject(parent),
+      m_contactManagerPrivate(0)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_contactManagerPrivate = new ContactManagerPrivate(this);
+}
+
+QString ContactManager::contactGuid(const QString &facebookId) const
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    return m_contactManagerPrivate->contactGuid(facebookId);
+}
+
+void ContactManager::requestContactGuids()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_contactManagerPrivate->requestContactGuids();
+}
diff --git a/src/engine/contactmanager.h b/src/engine/contactmanager.h
new file mode 100644 (file)
index 0000000..f6f5a6f
--- /dev/null
@@ -0,0 +1,50 @@
+#ifndef CONTACTMANAGER_H
+#define CONTACTMANAGER_H
+
+#include <QObject>
+#include <QHash>
+
+class ContactManagerPrivate;
+
+class ContactManager : public QObject
+{
+    Q_OBJECT
+public:
+    /**
+    * @brief Friend class for ContactManagerPrivate.
+    */
+    friend class ContactManagerPrivate;
+
+    ContactManager(QObject *parent = 0);
+
+    /**
+    * @brief Returns contact's guid from contact's facebook ID.
+    *
+    * @param facebookId contact's facebook ID
+    * @return contact guid
+    */
+    QString contactGuid(const QString &facebookId) const;
+
+    /**
+    * @brief Requests contact guids.
+    *
+    * Guid is a globally unique ID of a contact, which can be used with
+    * other datastores.
+    */
+    void requestContactGuids();
+
+signals:
+    /**
+    * @brief Signal for contacts guids added.
+    *
+    * Contact guids has Facebook ID as key and Guid as value.. Guid is a globally
+    * unique ID of a contact, which can be used with other datastores.
+    * @param contactGuids list of contact guids
+    */
+    void contactsGuidsAdded(const QHash<QString, QString> &contactGuids);
+
+private:
+    ContactManagerPrivate *m_contactManagerPrivate; ///< ContactManagerPrivate
+};
+
+#endif // CONTACTMANAGER_H
diff --git a/src/engine/contactmanagerprivate.cpp b/src/engine/contactmanagerprivate.cpp
new file mode 100644 (file)
index 0000000..a6de189
--- /dev/null
@@ -0,0 +1,79 @@
+#include <QContact>
+#include <QContactGuid>
+#include <QContactManager>
+#include <QContactOnlineAccount>
+#include <QDebug>
+#include <QHash>
+#include <QList>
+#include <QStringList>
+
+#include "contactmanager.h"
+
+#include "contactmanagerprivate.h"
+
+QTM_USE_NAMESPACE
+
+ContactManagerPrivate::ContactManagerPrivate(QObject *parent)
+    : QObject(parent),
+      m_manager(0)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_parent = static_cast<ContactManager *>(parent);
+
+    const QString MAEMO5_MANAGER_NAME = "maemo5";
+
+    QStringList availableManagers = QContactManager::availableManagers();
+
+    if (availableManagers.contains(MAEMO5_MANAGER_NAME)) {
+        QMap<QString, QString> params;
+        QString managerUri = QContactManager::buildUri(MAEMO5_MANAGER_NAME, params);
+        m_manager = QContactManager::fromUri(managerUri);
+    }
+}
+
+QString ContactManagerPrivate::parseFacebookId(const QString &accountUri) const
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    const QString FACEBOOK_CHAT_URL = "@chat.facebook.com";
+    int facebookChatUrlIndex = accountUri.indexOf(FACEBOOK_CHAT_URL);
+    QString facebookId;
+
+    if (facebookChatUrlIndex != -1) {
+        facebookId = accountUri.left(facebookChatUrlIndex);
+        facebookId.remove("-");
+    }
+
+    return facebookId;
+}
+
+QString ContactManagerPrivate::contactGuid(const QString &facebookId) const
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    return m_contactGuids.value(facebookId);
+}
+
+void ContactManagerPrivate::requestContactGuids()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (!m_manager) {
+        qWarning() << "Manager is uninitialized";
+        return;
+    }
+
+    QHash<QString, QString> contactGuids;
+
+    foreach (QContact contact, m_manager->contacts()) {
+        QContactOnlineAccount account = contact.detail(QContactOnlineAccount::DefinitionName);
+        QString facebookId = parseFacebookId(account.accountUri());
+        QContactGuid contactGuid = contact.detail(QContactGuid::DefinitionName);
+
+        if (!facebookId.isEmpty())
+            contactGuids.insert(facebookId, contactGuid.guid());
+    }
+
+    m_contactGuids = contactGuids;
+}
diff --git a/src/engine/contactmanagerprivate.h b/src/engine/contactmanagerprivate.h
new file mode 100644 (file)
index 0000000..ef1a6b0
--- /dev/null
@@ -0,0 +1,49 @@
+#ifndef CONTACTMANAGERPRIVATE_H
+#define CONTACTMANAGERPRIVATE_H
+
+#include <QObject>
+
+#include <QContactManager>
+
+class ContactManager;
+
+QTM_USE_NAMESPACE
+
+class ContactManagerPrivate : public QObject
+{
+    Q_OBJECT
+public:
+    ContactManagerPrivate(QObject *parent = 0);
+
+    /**
+    * @brief Returns contact's guid from contact's facebook ID.
+    *
+    * @param facebookId contact's facebook ID
+    * @return contact guid
+    */
+    QString contactGuid(const QString &facebookId) const;
+
+    /**
+    * @brief Requests contact guids.
+    *
+    * Guid is a globally unique ID of a contact, which can be used with
+    * other datastores.
+    */
+    void requestContactGuids();
+
+private:
+    /**
+    * @brief Parses Facebook id from account URI.
+    *
+    * @param accountUri Accounts universal resource identifier.
+    * @return Facebook ID or empty if cannot parse the ID.
+    */
+    QString parseFacebookId(const QString &accountUri) const;
+
+private:
+    ContactManager *m_parent;   ///< Parent
+    QContactManager *m_manager; ///< Contact manager
+    QHash<QString, QString> m_contactGuids;
+};
+
+#endif // CONTACTMANAGERPRIVATE_H
diff --git a/src/engine/contactmanagerprivatestub.cpp b/src/engine/contactmanagerprivatestub.cpp
new file mode 100644 (file)
index 0000000..178cbc9
--- /dev/null
@@ -0,0 +1,14 @@
+#include <QDebug>
+
+#include "contactmanagerprivatestub.h"
+
+ContactManagerPrivate::ContactManagerPrivate(QObject *parent) :
+    QObject(parent)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+}
+
+void ContactManagerPrivate::requestContactGuids()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+}
diff --git a/src/engine/contactmanagerprivatestub.h b/src/engine/contactmanagerprivatestub.h
new file mode 100644 (file)
index 0000000..04815cf
--- /dev/null
@@ -0,0 +1,32 @@
+#ifndef CONTACTMANAGERPRIVATESTUB_H
+#define CONTACTMANAGERPRIVATESTUB_H
+
+#include <QObject>
+
+class ContactManagerPrivate : public QObject
+{
+    Q_OBJECT
+public:
+    ContactManagerPrivate(QObject *parent = 0);
+
+    /**
+    * @brief Returns contact's guid from contact's facebook ID.
+    *
+    * @param facebookId contact's facebook ID
+    * @return contact guid
+    */
+    QString contactGuid(const QString &facebookId) const;
+
+    /**
+    * @brief Requests contact guids.
+    *
+    * Guid is a globally unique ID of a contact, which can be used with
+    * other datastores.
+    *
+    * DOES NOTHING.
+    */
+    void requestContactGuids();
+
+};
+
+#endif // CONTACTMANAGERPRIVATESTUB_H
index 4b7b821..e541239 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "application.h"
 #include "common.h"
+#include "contactmanager.h"
 #include "error.h"
 #include "facebookservice/facebookauthentication.h"
 #include "gps/gpsposition.h"
@@ -132,6 +133,9 @@ SituareEngine::SituareEngine()
 
     m_mce = new MCE(this);
     connect(m_mce, SIGNAL(displayOff(bool)), this, SLOT(setPowerSaving(bool)));
+
+    m_contactManager = new ContactManager(this);
+    m_contactManager->requestContactGuids();
 }
 
 SituareEngine::~SituareEngine()
@@ -560,6 +564,16 @@ void SituareEngine::setPowerSaving(bool enabled)
         m_mapEngine->setAutoCentering(!enabled);
 }
 
+void SituareEngine::showContactDialog(const QString &facebookId)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    QString guid = m_contactManager->contactGuid(facebookId);
+
+    if (!guid.isEmpty())
+        m_ui->showContactDialog(guid);
+}
+
 void SituareEngine::signalsFromFacebookAuthenticator()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -683,6 +697,9 @@ void SituareEngine::signalsFromMainWindow()
 
     connect(m_ui, SIGNAL(routeTo(const GeoCoordinate&)),
             this, SLOT(routeTo(const GeoCoordinate&)));
+
+    connect(m_ui, SIGNAL(requestContactDialog(const QString &)),
+            this, SLOT(showContactDialog(const QString &)));
 }
 
 void SituareEngine::signalsFromMapEngine()
index 71bfc7a..089f383 100644 (file)
@@ -34,6 +34,7 @@
 class QTimer;
 
 class Application;
+class ContactManager;
 class FacebookAuthentication;
 class FacebookCredentials;
 class GeocodingService;
@@ -257,6 +258,14 @@ private slots:
     void routeTo(const GeoCoordinate &endPointCoordinates);
 
     /**
+    * @brief Shows contact dialog.
+    *
+    * Calls MainWindow showContactDialog with contact guid defined by contact's Facebook ID.
+    * @param facebookId contact's facebookId
+    */
+    void showContactDialog(const QString &facebookId);
+
+    /**
     * @brief Slot for setting auto centering state.
     *
     * Calls gps to send last known position
@@ -367,6 +376,7 @@ private:
 
     QTimer *m_automaticUpdateIntervalTimer; ///< Automatic update interval timer
 
+    ContactManager *m_contactManager;                ///< Instance of contact manager
     FacebookAuthentication *m_facebookAuthenticator; ///< Instance for facebook authenticator
     GeocodingService *m_geocodingService;            ///< Instance of the geocoding service
     GeoCoordinate m_lastUpdatedGPSPosition;          ///< Last updated GPS position
index 714164a..7aa5292 100644 (file)
@@ -78,7 +78,9 @@ SOURCES += main.cpp \
     ui/routingpanel.cpp \
     ui/routewaypointlistitem.cpp \
     ui/routewaypointlistview.cpp \
-    user/user.cpp
+    user/user.cpp \
+    engine/contactmanager.cpp \
+    ui/ossoabookdialog.cpp
 HEADERS += application.h \
     common.h \
     coordinates/geocoordinate.h \
@@ -154,7 +156,9 @@ HEADERS += application.h \
     ui/routingpanel.h \
     ui/routewaypointlistitem.h \
     ui/routewaypointlistview.h \
-    user/user.h
+    user/user.h \
+    engine/contactmanager.h \
+    ui/ossoabookdialog.h
 QT += network \
     webkit
 
@@ -165,6 +169,8 @@ simulator {
                gps/gpspositionprivate.cpp
     HEADERS += network/networkhandlerprivatestub.h \
                gps/gpspositionprivate.h
+    SOURCES += engine/contactmanagerprivatestub.cpp
+    HEADERS += engine/contactmanagerprivatestub.h
     QT += maemo5
     CONFIG += mobility
     MOBILITY += location
@@ -185,8 +191,12 @@ simulator {
                    gps/liblocationwrapper.h \
                    gps/geopositioninfo.h
         CONFIG += link_pkgconfig
-        PKGCONFIG += glib-2.0 liblocation mce
+        PKGCONFIG += glib-2.0 liblocation mce gtk+-2.0 libosso-abook-1.0
         LIBS += -llocation
+        SOURCES += engine/contactmanagerprivate.cpp
+        HEADERS += engine/contactmanagerprivate.h
+        CONFIG += mobility
+        MOBILITY += contacts
     } else {
         SOURCES += gps/gpspositionprivatestub.cpp \
                    network/networkhandlerprivatestub.cpp \
@@ -194,6 +204,8 @@ simulator {
         HEADERS += gps/gpspositionprivatestub.h \
                    network/networkhandlerprivatestub.h \
                    engine/mceprivatestub.h
+        SOURCES += engine/contactmanagerprivatestub.cpp
+        HEADERS += engine/contactmanagerprivatestub.h
     }
 
     QT += maemo5
@@ -214,6 +226,8 @@ simulator {
     HEADERS += gps/gpspositionprivatestub.h \
                network/networkhandlerprivatestub.h \
                engine/mceprivatestub.h
+    SOURCES += engine/contactmanagerprivatestub.cpp
+    HEADERS += engine/contactmanagerprivatestub.h
     message(QJson built in)
     message(Make sure you have QJson development headers installed)
     message(install headers with: sudo apt-get install libqjson-dev)
index ad48d3a..d84284e 100644 (file)
@@ -48,6 +48,11 @@ GeoCoordinate FriendListItem::coordinates() const
     return m_coordinates;
 }
 
+QString FriendListItem::facebookId() const
+{
+    return m_facebookId;
+}
+
 void FriendListItem::setAvatarImage(const QPixmap &image)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -85,6 +90,13 @@ void FriendListItem::setDistanceIcon(double value, const QString &unit)
     setData(DISTANCE_IMAGE_INDEX, distanceImage);
 }
 
+
+void FriendListItem::setFacebookId(const QString &facebookId)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_facebookId = facebookId;
+}
 void FriendListItem::setUserData(User *user)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -96,6 +108,8 @@ void FriendListItem::setUserData(User *user)
     setData(DISTANCE_TEXT_DISPLAY_INDEX, distanceText);
     setDistanceIcon(value, unit);
 
+    setFacebookId(user->userId());
+
     //Dummy value to get painter font metrics.
     QPixmap p = QPixmap(ICON_WIDTH, ICON_HEIGHT);
     QPainter painter(&p);
index ed16e4a..b1aa1a7 100644 (file)
@@ -60,6 +60,13 @@ public:
     GeoCoordinate coordinates() const;
 
     /**
+    * @brief Return's item's Facebook ID
+    *
+    * @return item's Facebook ID
+    */
+    QString facebookId() const;
+
+    /**
     * @brief Sets avatar image for this item.
     *
     * @param image image
@@ -91,10 +98,19 @@ private:
     */
     void setDistanceIcon(double value, const QString &unit);
 
+    /**
+    * @brief Sets item's Facebook ID
+    *
+    * @param facebookId item's Facebook ID
+    */
+    void setFacebookId(const QString &facebookId);
+
 /******************************************************************************
 * DATA MEMBERS
 ******************************************************************************/
 private:
+    QString m_facebookId;           ///< User's Facebook ID
+
     GeoCoordinate m_coordinates;    ///< User coordinates
 };
 
index b94329e..aa3a3aa 100644 (file)
@@ -238,8 +238,14 @@ void FriendListPanel::routeToSelectedFriend()
 
     FriendListItem *item = dynamic_cast<FriendListItem *>(m_friendListView->selectedItem());
 
-    if (item)
-        emit routeToFriend(item->coordinates());
+//    if (item)
+//        emit routeToFriend(item->coordinates());
+
+    if (item) {
+        QString facebookId = item->facebookId();
+        if (!facebookId.isEmpty())
+            emit requestContactDialog(facebookId);
+    }
 }
 
 void FriendListPanel::setFilteringLayoutVisibility(bool visible)
index 2d3bfdc..280e22a 100644 (file)
@@ -26,6 +26,7 @@
 #ifndef FRIENDLISTPANEL_H
 #define FRIENDLISTPANEL_H
 
+#include <QHash>
 #include <QWidget>
 
 class QLabel;
@@ -210,6 +211,13 @@ signals:
     void routeToFriend(const GeoCoordinate &coordinates);
 
     /**
+    * @brief Requests contact dialog.
+    *
+    * @param facebookId contact's facebookId
+    */
+    void requestContactDialog(const QString &facebookId);
+
+    /**
      * @brief Signal for requesting a panel to be opened
      *
      * @param widget Pointer to the widget that emitted the signal
index fdcea75..bf7190d 100644 (file)
@@ -222,6 +222,13 @@ ListItem *ListView::listItemAt(int index)
     return item;
 }
 
+QHash<QString, ListItem *> ListView::listItems() const
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    return m_listItems;
+}
+
 ListItem *ListView::selectedItem()
 {
     qDebug() << __PRETTY_FUNCTION__;
index 6da9b6b..f696a4a 100644 (file)
@@ -154,6 +154,14 @@ public:
     ListItem *listItemAt(int index);
 
     /**
+    * @brief Returns all list items.
+    *
+    * Item ID is key.
+    * @return list of ListItems
+    */
+    QHash<QString, ListItem *> listItems() const;
+
+    /**
     * @brief Returns selected ListItem.
     *
     * @return ListItem if there is selected, 0 otherwise
index b8b5093..85daf47 100644 (file)
@@ -50,6 +50,7 @@
 #include "userinfopanel.h"
 #include "zoombuttonpanel.h"
 
+
 #include "mainwindow.h"
 
 // These MUST BE HERE, compiling for Maemo fails if moved
@@ -58,6 +59,7 @@
 #include <QtGui/QX11Info>
 #include <X11/Xatom.h>
 #include <X11/Xlib.h>
+#include "ossoabookdialog.h"
 #endif // Q_WS_MAEMO_5
 
 MainWindow::MainWindow(QWidget *parent)
@@ -179,6 +181,9 @@ void MainWindow::buildFriendListPanel()
 
     connect(m_friendsListPanel, SIGNAL(routeToFriend(const GeoCoordinate&)),
             this, SIGNAL(routeTo(const GeoCoordinate&)));
+
+    connect(m_friendsListPanel, SIGNAL(requestContactDialog(const QString &)),
+            this, SIGNAL(requestContactDialog(const QString &)));
 }
 
 void MainWindow::buildFullScreenButton()
@@ -904,6 +909,15 @@ void MainWindow::setUsername(const QString &username)
     m_email = username;
 }
 
+void MainWindow::showContactDialog(const QString &guid)
+{
+    qDebug() << __PRETTY_FUNCTION__ << guid;
+
+#if defined(Q_WS_MAEMO_5) & defined(ARMEL)
+    OssoABookDialog::showContactDialog(guid);
+#endif
+}
+
 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
 {
     qDebug() << __PRETTY_FUNCTION__;
index 5c2776f..68b623a 100644 (file)
@@ -198,6 +198,14 @@ public slots:
     void setUsername(const QString &username);
 
     /**
+    * @brief Shows contact dialog.
+    *
+    * Shows contact dialog with contact's information.
+    * @param guid globally unique ID of a contact
+    */
+    void showContactDialog(const QString &guid);
+
+    /**
      * @brief Method to show panels
      */
     void showPanels();
@@ -442,6 +450,15 @@ signals:
     void centerToSceneCoordinates(const SceneCoordinate &coordinate);
 
     /**
+    * @brief Signal for contacts guids added.
+    *
+    * Contact guids has Facebook ID as key and Guid as value. Guid is a globally
+    * unique ID of a contact, which can be used with other datastores.
+    * @param contactGuids list of contact guids
+    */
+    void contactsGuidsAdded(const QHash<QString, QString> &contactGuids);
+
+    /**
     * @brief Signal when direction and distance from current map center point to current GPS
     *        location is changed
     *
@@ -558,6 +575,13 @@ signals:
     void refreshUserData();
 
     /**
+    * @brief Requests contact dialog.
+    *
+    * @param facebookId contact's facebookId
+    */
+    void requestContactDialog(const QString &facebookId);
+
+    /**
      * @brief Signal for requesting reverseGeo from SituareEngine
      *
      */
diff --git a/src/ui/ossoabookdialog.cpp b/src/ui/ossoabookdialog.cpp
new file mode 100644 (file)
index 0000000..f7d6846
--- /dev/null
@@ -0,0 +1,70 @@
+#include "ossoabookdialog.h"
+#include <QDebug>
+
+OssoABookDialog::OssoABookDialog(QObject *parent) :
+    QObject(parent)
+{
+}
+
+QStringList OssoABookDialog::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 OssoABookDialog::contactEditor(const QString& id){
+    OssoABookContact* contact = OssoABookDialog::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);
+}
+
+void OssoABookDialog::showContactDialog(const QString &id)
+{
+    OssoABookContact *contact = OssoABookDialog::lookup(id);
+    if (contact) {
+    //GtkWidget *contactDialog = osso_abook_touch_contact_starter_new_with_contact(NULL, contact);
+    GtkWidget *contactDialog = osso_abook_touch_contact_starter_dialog_new(NULL,
+        (OssoABookTouchContactStarter*)osso_abook_touch_contact_starter_new_with_contact(NULL,
+        contact));
+
+    gtk_widget_show_all(contactDialog);
+    gtk_dialog_run(GTK_DIALOG(contactDialog));
+    gtk_widget_destroy(contactDialog);
+    }
+}
+
+OssoABookContact* OssoABookDialog::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;
+}
diff --git a/src/ui/ossoabookdialog.h b/src/ui/ossoabookdialog.h
new file mode 100644 (file)
index 0000000..1c9a728
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef OSSOABOOKDIALOG_H
+#define OSSOABOOKDIALOG_H
+
+#include <QObject>
+#include <QStringList>
+
+#undef signals // Collides with GTK symbols
+#include <libosso-abook/osso-abook.h>
+
+class OssoABookDialog : public QObject
+{
+    Q_OBJECT
+public:
+    explicit OssoABookDialog(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);
+    static void showContactDialog(const QString &id);
+
+private:
+    static OssoABookContact *lookup(const QString& id);
+};
+
+#endif // OSSOABOOKDIALOG_H