--- /dev/null
+#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();
+}
--- /dev/null
+#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
--- /dev/null
+#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;
+}
--- /dev/null
+#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
--- /dev/null
+#include <QDebug>
+
+#include "contactmanagerprivatestub.h"
+
+ContactManagerPrivate::ContactManagerPrivate(QObject *parent) :
+ QObject(parent)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+}
+
+void ContactManagerPrivate::requestContactGuids()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+}
--- /dev/null
+#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
#include "application.h"
#include "common.h"
+#include "contactmanager.h"
#include "error.h"
#include "facebookservice/facebookauthentication.h"
#include "gps/gpsposition.h"
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()
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__;
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()
class QTimer;
class Application;
+class ContactManager;
class FacebookAuthentication;
class FacebookCredentials;
class GeocodingService;
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
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
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 \
ui/routingpanel.h \
ui/routewaypointlistitem.h \
ui/routewaypointlistview.h \
- user/user.h
+ user/user.h \
+ engine/contactmanager.h \
+ ui/ossoabookdialog.h
QT += network \
webkit
gps/gpspositionprivate.cpp
HEADERS += network/networkhandlerprivatestub.h \
gps/gpspositionprivate.h
+ SOURCES += engine/contactmanagerprivatestub.cpp
+ HEADERS += engine/contactmanagerprivatestub.h
QT += maemo5
CONFIG += mobility
MOBILITY += location
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 \
HEADERS += gps/gpspositionprivatestub.h \
network/networkhandlerprivatestub.h \
engine/mceprivatestub.h
+ SOURCES += engine/contactmanagerprivatestub.cpp
+ HEADERS += engine/contactmanagerprivatestub.h
}
QT += maemo5
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)
return m_coordinates;
}
+QString FriendListItem::facebookId() const
+{
+ return m_facebookId;
+}
+
void FriendListItem::setAvatarImage(const QPixmap &image)
{
qDebug() << __PRETTY_FUNCTION__;
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__;
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);
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
*/
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
};
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)
#ifndef FRIENDLISTPANEL_H
#define FRIENDLISTPANEL_H
+#include <QHash>
#include <QWidget>
class QLabel;
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
return item;
}
+QHash<QString, ListItem *> ListView::listItems() const
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ return m_listItems;
+}
+
ListItem *ListView::selectedItem()
{
qDebug() << __PRETTY_FUNCTION__;
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
#include "userinfopanel.h"
#include "zoombuttonpanel.h"
+
#include "mainwindow.h"
// These MUST BE HERE, compiling for Maemo fails if moved
#include <QtGui/QX11Info>
#include <X11/Xatom.h>
#include <X11/Xlib.h>
+#include "ossoabookdialog.h"
#endif // Q_WS_MAEMO_5
MainWindow::MainWindow(QWidget *parent)
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()
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__;
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();
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
*
void refreshUserData();
/**
+ * @brief Requests contact dialog.
+ *
+ * @param facebookId contact's facebookId
+ */
+ void requestContactDialog(const QString &facebookId);
+
+ /**
* @brief Signal for requesting reverseGeo from SituareEngine
*
*/
--- /dev/null
+#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;
+}
--- /dev/null
+#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