X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fel-home-applet.c;h=0e683f92134dd5e7e40b1be54a2ce17e223d072e;hb=e1c98a8ad492feeea2c86f7cdb26d0c06cab2182;hp=03322fac2210a1d67a72b5e687f14c63a0e244c3;hpb=7418d5bd2760aaaf9de181baf9ee0961718fc151;p=conv-inbox diff --git a/src/el-home-applet.c b/src/el-home-applet.c index 03322fa..0e683f9 100644 --- a/src/el-home-applet.c +++ b/src/el-home-applet.c @@ -22,7 +22,7 @@ #include "config.h" #include "el-home-applet.h" - +#include #include #include #include @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include @@ -62,6 +62,11 @@ #define MESSAGE_HEIGHT (C_HEIGHT - HEADER_HEIGHT - FOOTER_HEIGHT) #define MESSAGE_WIDTH (C_WIDTH - 2*HILDON_MARGIN_DEFAULT) +#define AVATAR_SIZE HILDON_ICON_PIXEL_SIZE_THUMB + +#define AVATAR_X (C_WIDTH - AVATAR_SIZE - HILDON_MARGIN_DEFAULT) +#define AVATAR_Y 3*HILDON_MARGIN_HALF + #define BOX_RADIOUS 20 #define SCROLL_PERIOD 100 /* ms */ @@ -72,6 +77,10 @@ #define NOTIFICATION_UI_DBUS_PATH "/org/freedesktop/Telepathy/Client/NotificationUI" #define NOTIFICATION_UI_DBUS_IFACE "com.nokia.RtcomNotificationUi" +#define CONVERSATIONS_UI_DBUS_NAME "com.nokia.MessagingUI" +#define CONVERSATIONS_UI_DBUS_PATH "/com/nokia/MessagingUI" +#define CONVERSATIONS_UI_DBUS_IFACE "com.nokia.MessagingUI" + static const gchar *conv_services[] = {"RTCOM_EL_SERVICE_SMS", "RTCOM_EL_SERVICE_CHAT", NULL}; @@ -91,12 +100,15 @@ struct _ELHomeAppletPrivate RTComEl *eventlogger; GtkWidget *sender; - /* GtkWidget *icon; */ + GtkWidget *icon; GtkWidget *unread; GtkWidget *received; - GtkWidget *empty; GtkWidget *cut_message; - GtkWidget *avatar; + + /* empty view*/ + GtkWidget *empty; + GtkWidget *sms_total; + GtkWidget *chat_total; gchar *message; gint event_id; @@ -110,9 +122,11 @@ struct _ELHomeAppletPrivate float green; float blue; } active_color; - guint8 border_color[4]; PangoFontDescription *font_desc; + GdkPixbuf *avatar_pixbuf; + GdkPixbuf *presence_pixbuf; + guint idle_id; cairo_surface_t *message_surface; @@ -327,11 +341,6 @@ style_set_cb (GtkWidget *widget, priv->active_color.red = color.red/(float)G_MAXUINT16; priv->active_color.green = color.green/(float)G_MAXUINT16; priv->active_color.blue = color.blue/(float)G_MAXUINT16; - - priv->border_color[0] = color.red; - priv->border_color[1] = color.green; - priv->border_color[2] = color.blue; - priv->border_color[3] = 255; } } @@ -468,6 +477,43 @@ expose_event (GtkWidget *self, GdkEventExpose *event) cairo_pattern_destroy (grad); + /* draw avatar */ + if (priv->avatar_pixbuf) { + rounded_rectangle (cr, + AVATAR_X, -AVATAR_Y, + AVATAR_SIZE, AVATAR_SIZE, + BOX_RADIOUS, + ROUND_CORNER_ALL); + cairo_close_path (cr); + + gdk_cairo_set_source_pixbuf (cr, + priv->avatar_pixbuf, + AVATAR_X, + -AVATAR_Y); + cairo_fill_preserve (cr); + + cairo_set_source_rgba (cr, + priv->active_color.red, + priv->active_color.green, + priv->active_color.blue, + 1.0f); + cairo_stroke (cr); + } + if (priv->presence_pixbuf) { + guint x = C_WIDTH - HILDON_ICON_PIXEL_SIZE_XSMALL - HILDON_MARGIN_DEFAULT; + guint y = (HEADER_HEIGHT - HILDON_ICON_PIXEL_SIZE_XSMALL)/2; + + if (priv->avatar_pixbuf) + x -= AVATAR_SIZE + HILDON_MARGIN_DEFAULT; + + cairo_set_operator (cr, CAIRO_OPERATOR_OVER); + gdk_cairo_set_source_pixbuf (cr, + priv->presence_pixbuf, + x, + y); + cairo_paint (cr); + } + if (priv->message) { /* draw footer unread part bg */ rounded_rectangle (cr, @@ -538,44 +584,209 @@ expose_event (GtkWidget *self, GdkEventExpose *event) return GTK_WIDGET_CLASS (el_home_applet_parent_class)->expose_event (self, event); } +static void +resize_sender (ELHomeAppletPrivate *priv) +{ + guint width = C_WIDTH; + + if (priv->avatar_pixbuf) { + width -= AVATAR_SIZE + HILDON_MARGIN_DEFAULT; + } + + if (priv->presence_pixbuf) { + width -= HILDON_ICON_PIXEL_SIZE_XSMALL + HILDON_MARGIN_DEFAULT; + } + + gtk_widget_set_size_request (priv->sender, + width, + HILDON_ICON_PIXEL_SIZE_THUMB); +} static void -clean_state (ELHomeApplet *self) +update_presence_pixbuf (ELHomeApplet *self, + OssoABookPresence *presence) { ELHomeAppletPrivate *priv = self->priv; + const gchar *icon_name = osso_abook_presence_get_icon_name (presence); + gboolean resize = !!priv->presence_pixbuf ^ !!icon_name; /* logical via bit XOR */ - if (priv->message) { - g_free (priv->message); - priv->message = NULL; + if (priv->presence_pixbuf) { + g_object_unref (priv->presence_pixbuf); + priv->presence_pixbuf = NULL; } + g_warning ("presence %s", icon_name); + + if (icon_name) + priv->presence_pixbuf = gtk_icon_theme_load_icon + (gtk_icon_theme_get_default (), + icon_name, + HILDON_ICON_PIXEL_SIZE_XSMALL, + 0, NULL); + if (resize) + resize_sender (priv); + + gtk_widget_queue_draw (GTK_WIDGET (self)); +} + +static void +presence_updated (OssoABookPresence *presence, + GParamSpec *spec, + gpointer *user_data) +{ + ELHomeApplet *self = EL_HOME_APPLET(user_data); + + if (!OSSO_ABOOK_IS_CONTACT(self->priv->contact)) + return; + + update_presence_pixbuf (self, presence); +} + +static void +show_contact (ELHomeApplet *self) +{ + ELHomeAppletPrivate *priv = self->priv; + + gtk_label_set_text (GTK_LABEL (priv->sender), + osso_abook_contact_get_display_name (priv->contact)); + resize_sender (priv); + gtk_widget_queue_draw (GTK_WIDGET (self)); +} + +static void +resolve_contact (ELHomeApplet *self) +{ + ELHomeAppletPrivate *priv = self->priv; + GList *contacts = NULL; if (priv->contact_id) { - g_free (priv->contact_id); - priv->contact_id = NULL; + contacts = osso_abook_aggregator_lookup + (OSSO_ABOOK_AGGREGATOR (priv->aggregator), + priv->contact_id); } - if (priv->local_id) { - g_free (priv->local_id); - priv->local_id = NULL; + else if (priv->local_id && priv->remote_id) { + if (g_strcmp0 (priv->local_id, "ring/tel/ring" == 0)) { + contacts = osso_abook_aggregator_find_contacts_for_phone_number + (OSSO_ABOOK_AGGREGATOR (priv->aggregator), + priv->remote_id, + TRUE); + } + else { + McAccount *account; + account = osso_abook_account_manager_lookup_by_name + (NULL, + priv->local_id); + if (account) { + contacts = osso_abook_aggregator_find_contacts_for_im_contact + (OSSO_ABOOK_AGGREGATOR (priv->aggregator), + priv->remote_id, + account); + } + } } - if (priv->remote_id) { - g_free (priv->remote_id); - priv->remote_id = NULL; + + if (contacts && contacts->data) { + priv->contact = g_object_ref (OSSO_ABOOK_CONTACT (contacts->data)); + g_signal_connect (priv->contact, + "notify::presence-status", + G_CALLBACK (presence_updated), + self); + priv->avatar_pixbuf = osso_abook_avatar_get_image_scaled + (OSSO_ABOOK_AVATAR (priv->contact), + HILDON_ICON_PIXEL_SIZE_THUMB, + HILDON_ICON_PIXEL_SIZE_THUMB, + TRUE); + update_presence_pixbuf (self, + OSSO_ABOOK_PRESENCE (priv->contact)); + show_contact (self); } - if (priv->group_uid) { - g_free (priv->group_uid); - priv->group_uid = NULL; +} + +static void +contacts_added (OssoABookRoster *roster, + OssoABookContact **contacts, + gpointer userdata) +{ + ELHomeApplet *self = EL_HOME_APPLET (userdata); + ELHomeAppletPrivate *priv = self->priv; + + if (!priv->contact) + resolve_contact (self); +} + +static void +reset_contact (ELHomeApplet *self) +{ + ELHomeAppletPrivate *priv = self->priv; + + if (priv->avatar_pixbuf) { + g_object_unref (priv->avatar_pixbuf); + priv->avatar_pixbuf = NULL; + } + + if (priv->presence_pixbuf) { + g_object_unref (priv->presence_pixbuf); + priv->presence_pixbuf = NULL; } if (priv->contact) { + g_signal_handlers_disconnect_by_func (priv->contact, + presence_updated, + self); g_object_unref (priv->contact); priv->contact = NULL; } + + resize_sender (priv); +} + +static void +contacts_removed (OssoABookRoster *roster, + const gchar **ids, + gpointer userdata) +{ + ELHomeApplet *self = EL_HOME_APPLET (userdata); + ELHomeAppletPrivate *priv = self->priv; + + if (priv->contact) { + const gchar **contact_id; + const gchar *uid = osso_abook_contact_get_uid (priv->contact); + + for (contact_id = ids; *contact_id; contact_id++) { + if (strcmp (*contact_id, priv->contact_id) == 0) { + reset_contact (self); + + gtk_widget_queue_draw (GTK_WIDGET (self)); + return; + } + if (strcmp (*contact_id, uid) == 0) { + reset_contact (self); + resolve_contact (self); + gtk_widget_queue_draw (GTK_WIDGET (self)); + return; + } + } + } +} + +static void +clean_contact (ELHomeApplet *self) +{ + ELHomeAppletPrivate *priv = self->priv; + + reset_contact (self); + if (priv->aggregator) { if (priv->aggregator_ready_closure){ osso_abook_waitable_cancel (OSSO_ABOOK_WAITABLE (priv->aggregator), priv->aggregator_ready_closure); priv->aggregator_ready_closure = NULL; } + g_signal_handlers_disconnect_by_func (priv->aggregator, + contacts_added, + self); + g_signal_handlers_disconnect_by_func (priv->aggregator, + contacts_removed, + self); osso_abook_roster_stop (priv->aggregator); g_object_unref (priv->aggregator); priv->aggregator = NULL; @@ -583,6 +794,34 @@ clean_state (ELHomeApplet *self) } static void +clean_state (ELHomeApplet *self) +{ + ELHomeAppletPrivate *priv = self->priv; + + if (priv->message) { + g_free (priv->message); + priv->message = NULL; + } + + if (priv->contact_id) { + g_free (priv->contact_id); + priv->contact_id = NULL; + } + if (priv->local_id) { + g_free (priv->local_id); + priv->local_id = NULL; + } + if (priv->remote_id) { + g_free (priv->remote_id); + priv->remote_id = NULL; + } + if (priv->group_uid) { + g_free (priv->group_uid); + priv->group_uid = NULL; + } +} + +static void dispose (GObject *self) { ELHomeAppletPrivate *priv = EL_HOME_APPLET(self)->priv; @@ -602,6 +841,7 @@ dispose (GObject *self) } clean_state (EL_HOME_APPLET (self)); + clean_contact (EL_HOME_APPLET (self)); G_OBJECT_CLASS (el_home_applet_parent_class)->dispose (self); } @@ -617,9 +857,8 @@ aggregator_ready_cb (OssoABookWaitable *waitable, const GError *error, gpointer userdata) { - ELHomeApplet *self = EL_HOME_APPLET(userdata); + ELHomeApplet *self = EL_HOME_APPLET (userdata); ELHomeAppletPrivate *priv = self->priv; - GList *contacts = NULL; priv->aggregator_ready_closure = NULL; @@ -628,64 +867,25 @@ aggregator_ready_cb (OssoABookWaitable *waitable, return; } - if (priv->contact_id) { - contacts = osso_abook_aggregator_lookup - (OSSO_ABOOK_AGGREGATOR (priv->aggregator), - priv->contact_id); - } - else if (priv->local_id && priv->remote_id) { - if (g_strcmp0 (priv->local_id, "ring/tel/ring" == 0)) { - contacts = osso_abook_aggregator_find_contacts_for_phone_number - (OSSO_ABOOK_AGGREGATOR (priv->aggregator), - priv->remote_id, - TRUE); - } - else { - McAccount *account; - account = osso_abook_account_manager_lookup_by_name - (NULL, - priv->local_id); - if (account) { - contacts = osso_abook_aggregator_find_contacts_for_im_contact - (OSSO_ABOOK_AGGREGATOR (priv->aggregator), - priv->remote_id, - account); - } - } - } - - if (contacts && contacts->data) { - GdkPixbuf *avatar_image; - - priv->contact = g_object_ref (OSSO_ABOOK_CONTACT (contacts->data)); - gtk_label_set_text (GTK_LABEL (priv->sender), - osso_abook_contact_get_display_name (priv->contact)); + g_signal_connect (priv->aggregator, + "contacts-added", + G_CALLBACK (contacts_added), + self); + g_signal_connect (priv->aggregator, + "contacts-removed", + G_CALLBACK (contacts_removed), + self); - avatar_image = osso_abook_avatar_get_image_scaled /*rounded*/ - (OSSO_ABOOK_AVATAR (priv->contact), - HILDON_ICON_PIXEL_SIZE_THUMB, - HILDON_ICON_PIXEL_SIZE_THUMB, - TRUE); - /* -1, */ - /* priv->border_color); */ - - if (avatar_image) { - gtk_image_set_from_pixbuf (GTK_IMAGE (priv->avatar), - avatar_image); - gtk_widget_show (priv->avatar); - g_object_unref (avatar_image); - } - gtk_widget_queue_draw (GTK_WIDGET (self)); - } + resolve_contact (self); } static void -resolve_contact (ELHomeApplet *self) +start_aggregator (ELHomeApplet *self) { ELHomeAppletPrivate *priv = self->priv; EBookQuery *query = NULL; GError *error = NULL; - + g_warning ("%s rid %s lid %s", G_STRFUNC, priv->remote_id, priv->local_id); if (priv->local_id && priv->remote_id) { const gchar *vcard = osso_abook_account_manager_get_vcard_field (NULL, priv->local_id); @@ -696,7 +896,7 @@ resolve_contact (ELHomeApplet *self) else query = e_book_query_any_field_contains (priv->remote_id); } - + g_warning ("%s query %p", G_STRFUNC, query); if (query) { priv->aggregator = osso_abook_aggregator_new_with_query (NULL, query, @@ -712,6 +912,7 @@ resolve_contact (ELHomeApplet *self) } if (priv->aggregator) { + g_warning ("%s start aggr", G_STRFUNC); priv->aggregator_ready_closure = osso_abook_waitable_call_when_ready (OSSO_ABOOK_WAITABLE (priv->aggregator), aggregator_ready_cb, @@ -749,49 +950,52 @@ static void show_event (ELHomeApplet *self, RTComElIter *it) { ELHomeAppletPrivate *priv = self->priv; - gchar *remote = NULL; + const gchar *remote = NULL; gchar *received = NULL; - /* const gchar *icon_name = NULL; */ + GValueArray *event = NULL; if (it && rtcom_el_iter_first (it)) { - rtcom_el_iter_dup_string (it, "free-text", &priv->message); - if (priv->message) { - /* const gchar *service; */ - time_t received_t; - rtcom_el_iter_get_int (it, "id", &priv->event_id); - if (rtcom_el_iter_get_int (it, "start-time", (gint*)&received_t)) - received = format_time (received_t); + event = rtcom_el_iter_get_valuearray (it, + "id", + "start-time", + "local-uid", + "remote-uid", + "remote-name", + "remote-ebook-uid", + "free-text", + "group-uid", + NULL); + if (event) { + time_t received_t; +#define _VARR_DUP_STR(array, i) g_value_dup_string (g_value_array_get_nth ((array), (i))) + + priv->event_id = g_value_get_int (g_value_array_get_nth (event, 0)); + received_t = g_value_get_int (g_value_array_get_nth (event, 1)); + received = format_time (received_t); + priv->local_id = _VARR_DUP_STR (event, 2); + priv->remote_id = _VARR_DUP_STR (event, 3); + if (priv->remote_id && priv->remote_id[0]) { + remote = g_value_get_string (g_value_array_get_nth (event, 4)); + if (!remote) + remote = priv->remote_id; + priv->contact_id = _VARR_DUP_STR (event, 5); + } + else if (priv->remote_id) { + g_free (priv->remote_id); + priv->remote_id = NULL; + } - if (rtcom_el_iter_dup_string (it, "remote-uid", &priv->remote_id)) { - if (priv->remote_id && priv->remote_id[0]) { - if (!rtcom_el_iter_dup_string (it, "remote-name", &remote)) - remote = g_strdup (priv->remote_id); + priv->message = _VARR_DUP_STR (event, 6); + priv->group_uid = _VARR_DUP_STR (event, 7); - rtcom_el_iter_dup_string (it, "remote-ebook-uid", &priv->contact_id); - rtcom_el_iter_dup_string (it, "local-uid", &priv->local_id); - } - else if (priv->remote_id) { - g_free (priv->remote_id); - priv->remote_id = NULL; - } - } - rtcom_el_iter_dup_string (it, "group-uid", &priv->group_uid); -#if 0 - service = rtcom_el_iter_get_service (it); - if (!g_strcmp0 (service, "RTCOM_EL_SERVICE_SMS")) - icon_name = "chat_unread_sms"; - else if (!g_strcmp0 (service, "RTCOM_EL_SERVICE_CHAT")) - icon_name = "chat_unread_chat"; -#endif +#undef _VARR_DUP_STR } } else { priv->event_id = -1; } - gtk_widget_hide (priv->avatar); - if (priv->message) { gtk_widget_hide (priv->empty); } @@ -801,28 +1005,10 @@ show_event (ELHomeApplet *self, RTComElIter *it) gtk_label_set_text (GTK_LABEL (priv->received), received); -#if 0 - gtk_widget_hide (priv->avatar); - if (icon_name) { - const gchar *current_icon_name; - gtk_image_get_icon_name (GTK_IMAGE (priv->icon), - ¤t_icon_name, - NULL); - if (g_strcmp0 (current_icon_name, icon_name)) - gtk_image_set_from_icon_name (GTK_IMAGE (priv->icon), - icon_name, - HILDON_ICON_SIZE_FINGER); - gtk_widget_show (priv->icon); - } - else - gtk_widget_hide (priv->icon); -#endif - if (remote) gtk_label_set_text (GTK_LABEL (priv->sender), remote); else gtk_label_set_text (GTK_LABEL (priv->sender), priv->remote_id); - g_free (remote); stop_scroll_anim (priv); priv->scroll_offset = 0; @@ -831,6 +1017,9 @@ show_event (ELHomeApplet *self, RTComElIter *it) priv->message_surface = NULL; } + if (event) + g_value_array_free (event); + gtk_widget_hide (priv->cut_message); gtk_widget_queue_draw (GTK_WIDGET (self)); } @@ -912,18 +1101,135 @@ query_unread_events (RTComEl *el) return count; } +static gboolean +query_read_events (RTComEl *el, const gchar *service, gint *events, gint *conversations) +{ + sqlite3 *db; + sqlite3_stmt *stmt; + int ret; + gboolean result = TRUE; + + g_object_get (el, "db", &db, NULL); + + if (sqlite3_prepare_v2 (db, + "SELECT SUM(total_events), COUNT(group_uid) FROM GroupCache, Services " + "WHERE GroupCache.service_id=Services.id AND Services.name=?;", + -1, + &stmt, + NULL) != SQLITE_OK) { + g_error ("%s: can't compile SQL", G_STRFUNC); + return FALSE; + } + if (sqlite3_bind_text (stmt, 1, service, -1, SQLITE_STATIC) != SQLITE_OK) { + g_error ("Failed to bind %s to SQL stmt", service); + result = FALSE; + goto DONE; + } + + while (SQLITE_BUSY == (ret = sqlite3_step (stmt))); + + if (ret == SQLITE_ROW) { + *events = sqlite3_column_int (stmt, 0); + *conversations = sqlite3_column_int (stmt, 1); + } + else { + g_error ("%s: error while executing SQL", G_STRFUNC); + result = FALSE; + goto DONE; + } + + DONE: + sqlite3_finalize (stmt); + + return result; +} + static void read_event (ELHomeApplet *self) { ELHomeAppletPrivate *priv = self->priv; RTComElIter *it = NULL; + const gchar *icon_name = NULL; + gchar *remote_id; + gchar *local_id; + + remote_id = g_strdup (priv->remote_id); + local_id = g_strdup (priv->local_id); clean_state (self); it = make_query (priv->eventlogger, -1); show_event (self, it); - resolve_contact (self); + if (it) g_object_unref (it); + + if (priv->event_id >= 0) { + gboolean new_account = g_strcmp0 (priv->local_id, local_id); + + if (g_strcmp0 (priv->remote_id, remote_id) || new_account) { + clean_contact (self); + start_aggregator (self); + } + else { + show_contact (self); + } + + if (new_account) { + g_warning ("Update service icon"); + if (g_strcmp0 (priv->local_id, "ring/tel/ring") == 0) { + icon_name = "general_sms"; + } + else{ + McAccount *account; + account = osso_abook_account_manager_lookup_by_name (NULL, + priv->local_id); + if (account) { + McProfile *profile = mc_profile_lookup (mc_account_compat_get_profile (account)); + icon_name = mc_profile_get_icon_name (profile); + } + } + + if (icon_name) { + gtk_image_set_from_icon_name (GTK_IMAGE (priv->icon), + icon_name, + HILDON_ICON_SIZE_XSMALL); + gtk_widget_show (priv->icon); + } + else + gtk_widget_hide (priv->icon); + } + } + else { + gchar *text; + gint n_sms_events = 0, n_sms_convs = 0; + gint n_chat_events = 0, n_chat_convs = 0; + const gchar *fmt = "%d (%d)"; + + query_read_events (priv->eventlogger, + "RTCOM_EL_SERVICE_SMS", + &n_sms_events, &n_sms_convs); + query_read_events (priv->eventlogger, + "RTCOM_EL_SERVICE_CHAT", + &n_chat_events, &n_chat_convs); + + text = g_strdup_printf (fmt, n_sms_convs, n_sms_events); + gtk_label_set_markup (GTK_LABEL (priv->sms_total), text); + g_free (text); + + text = g_strdup_printf (fmt, n_chat_convs, n_chat_events); + gtk_label_set_markup (GTK_LABEL (priv->chat_total), text); + g_free (text); + + gtk_label_set_text (GTK_LABEL (priv->sender), + dgettext ("rtcom-messaging-ui", + "messaging_ap_conversations")); + + clean_contact (self); + gtk_widget_hide (priv->icon); + } + + g_free (local_id); + g_free (remote_id); } static void @@ -931,7 +1237,7 @@ remove_notification (ELHomeApplet *self) { ELHomeAppletPrivate *priv = self->priv; - DBusGConnection* conn; + DBusGConnection *conn; GError *error; DBusGProxy *proxy; GPtrArray *conv_structs; @@ -1007,6 +1313,38 @@ mark_as_read (ELHomeApplet *self) } static void +launch_conversations (ELHomeApplet *self) +{ + DBusConnection *conn; + DBusMessage *message; + DBusError error; + + dbus_error_init (&error); + conn = hd_home_plugin_item_get_dbus_connection (HD_HOME_PLUGIN_ITEM (self), + DBUS_BUS_SESSION, + &error); + if (!conn) { + if (dbus_error_is_set (&error)) { + g_error ("Failed to get dbus connection %s", error.message); + dbus_error_free (&error); + } + return; + } + + message = dbus_message_new_method_call (CONVERSATIONS_UI_DBUS_NAME, + CONVERSATIONS_UI_DBUS_PATH, + CONVERSATIONS_UI_DBUS_IFACE, + "top_application"); + dbus_message_set_no_reply (message, TRUE); + + if (dbus_connection_send (conn, message, NULL)) + dbus_connection_flush (conn); + dbus_message_unref (message); + + dbus_connection_close (conn); +} + +static void open_conversation (ELHomeApplet *self) { ELHomeAppletPrivate *priv = self->priv; @@ -1069,6 +1407,8 @@ read_new_event (ELHomeApplet *self) { ELHomeAppletPrivate *priv = self->priv; + g_warning ("read_new_event"); + read_event (self); priv->unread_count = query_unread_events (priv->eventlogger); update_unread_label (self); @@ -1082,7 +1422,7 @@ static void add_new_idle (ELHomeApplet *self) { ELHomeAppletPrivate *priv = self->priv; - + g_warning ("add_new_idle"); if (priv->idle_id) g_source_remove (priv->idle_id); priv->idle_id = g_idle_add ((GSourceFunc)read_new_event, @@ -1099,15 +1439,22 @@ new_event_cb (RTComEl *backend, const gchar *service, ELHomeApplet *self) { - const gchar** conv_service = conv_services; - - do { - if (!g_strcmp0 (*conv_service, service)) { - add_new_idle (self); - return; + g_warning ("%s %s %s %s", local_uid, remote_uid, remote_ebook_uid, service); + + if (service && service[0] != '\0') { + const gchar** conv_service = conv_services; + g_warning ("%s", service); + do { + g_warning ("%s", *conv_service); + if (!g_strcmp0 (*conv_service, service)) { + add_new_idle (self); + return; + } } + while(*++conv_service); } - while(++conv_service); + else + add_new_idle (self); } static gboolean @@ -1139,7 +1486,7 @@ button_press_event_cb (GtkWidget *widget, { ELHomeAppletPrivate *priv = self->priv; - if (priv->event_id > 0) { + if (priv->event_id >= 0) { if (event->y < CONTENT_OFFSET_Y_TOP + HEADER_HEIGHT) { if (priv->aggregator && osso_abook_waitable_is_ready @@ -1151,9 +1498,12 @@ button_press_event_cb (GtkWidget *widget, priv->active = SELECTED_FOOTER; else priv->active = SELECTED_BODY; - - gtk_widget_queue_draw (widget); } + else { + priv->active = SELECTED_BODY; + } + + gtk_widget_queue_draw (widget); return TRUE; } @@ -1220,8 +1570,12 @@ button_release_event_cb (GtkWidget *widget, switch (priv->active) { case SELECTED_BODY: - reset_scroll (self); - open_conversation (self); + if (priv->event_id >= 0) { + reset_scroll (self); + open_conversation (self); + } + else + launch_conversations (self); break; case SELECTED_HEADER: { GtkWidget *dialog = NULL; @@ -1291,6 +1645,7 @@ el_home_applet_init (ELHomeApplet *self) ELHomeAppletPrivate *priv; GtkWidget *event_box; GtkWidget *hbox, *vbox, *align, *footer; + GtkWidget *w; self->priv = EL_HOME_APPLET_GET_PRIVATE (self); priv = self->priv; @@ -1302,20 +1657,11 @@ el_home_applet_init (ELHomeApplet *self) 0.0f, 0.5f); hildon_helper_set_logical_font (priv->unread, "SmallSystemFont"); - /* gtk_widget_set_size_request (priv->unread, */ - /* -1, */ - /* HEADER_HEIGHT); */ -#if 0 - priv->icon = gtk_image_new_from_icon_name ("chat_unread_sms", - HILDON_ICON_SIZE_FINGER); + + priv->icon = gtk_image_new (); gtk_misc_set_alignment (GTK_MISC (priv->icon), 0.5f, 0.5f); -#endif - priv->avatar = gtk_image_new (); - gtk_misc_set_alignment (GTK_MISC (priv->avatar), - 0.5f, - 0.5f); priv->sender = gtk_label_new ("asdf asdf asdf asdf asdf"); gtk_misc_set_alignment (GTK_MISC (priv->sender), @@ -1326,14 +1672,38 @@ el_home_applet_init (ELHomeApplet *self) gtk_widget_set_name (priv->sender, "hildon-shadow-label"); hildon_helper_set_logical_font (priv->sender, "SystemFont"); gtk_widget_set_size_request (priv->sender, - -1, + C_WIDTH, HILDON_ICON_PIXEL_SIZE_THUMB); priv->message = g_strdup ("One two three four five six seven eight nine ten"); - /* TODO: l10n */ - priv->empty = gtk_label_new ("No new messages"); - gtk_widget_set_name (priv->empty, "hildon-shadow-label"); + /* construt empty table */ + priv->empty = gtk_fixed_new (); + + w = gtk_image_new_from_icon_name ("general_sms", HILDON_ICON_SIZE_FINGER); + gtk_fixed_put (GTK_FIXED (priv->empty), w, + 4*HILDON_MARGIN_DOUBLE, + 2*HILDON_MARGIN_DOUBLE); + + w = gtk_image_new_from_icon_name ("general_chat", HILDON_ICON_SIZE_FINGER); + gtk_fixed_put (GTK_FIXED (priv->empty), w, + 4*HILDON_MARGIN_DOUBLE, + 3*HILDON_MARGIN_DOUBLE + HILDON_ICON_PIXEL_SIZE_FINGER); + + priv->sms_total = gtk_label_new (NULL); + gtk_widget_set_name (priv->sms_total, "hildon-shadow-label"); + gtk_fixed_put (GTK_FIXED (priv->empty), priv->sms_total, + 5*HILDON_MARGIN_DOUBLE + HILDON_ICON_PIXEL_SIZE_FINGER, + 2*HILDON_MARGIN_DOUBLE + HILDON_MARGIN_HALF); + + priv->chat_total = gtk_label_new (NULL); + gtk_widget_set_name (priv->chat_total, "hildon-shadow-label"); + gtk_fixed_put (GTK_FIXED (priv->empty), priv->chat_total, + 5*HILDON_MARGIN_DOUBLE + HILDON_ICON_PIXEL_SIZE_FINGER, + 3*HILDON_MARGIN_DOUBLE + HILDON_MARGIN_HALF + HILDON_ICON_PIXEL_SIZE_FINGER); + + gtk_widget_show_all (GTK_WIDGET (priv->empty)); + gtk_widget_hide (GTK_WIDGET (priv->empty)); GTK_WIDGET_SET_FLAGS (priv->empty, GTK_NO_SHOW_ALL); priv->received = gtk_label_new ("aewf aewf aewf awef"); @@ -1353,13 +1723,12 @@ el_home_applet_init (ELHomeApplet *self) GTK_WIDGET_SET_FLAGS (priv->cut_message, GTK_NO_SHOW_ALL); hbox = gtk_hbox_new (FALSE, 0); - /* gtk_box_pack_start (GTK_BOX (hbox), priv->icon, FALSE, FALSE, 0); */ - gtk_box_pack_start (GTK_BOX (hbox), priv->sender, TRUE, TRUE, 0); - gtk_box_pack_start (GTK_BOX (hbox), priv->avatar, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (hbox), priv->sender, FALSE, FALSE, 0); footer = gtk_hbox_new (FALSE, HILDON_MARGIN_DEFAULT); gtk_box_pack_start (GTK_BOX (footer), priv->unread, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (footer), priv->cut_message, TRUE, TRUE, 0); + gtk_box_pack_end (GTK_BOX (footer), priv->icon, FALSE, FALSE, 0); gtk_box_pack_end (GTK_BOX (footer), priv->received, FALSE, FALSE, 0); vbox = gtk_vbox_new (FALSE, 0); @@ -1416,9 +1785,9 @@ el_home_applet_init (ELHomeApplet *self) G_CALLBACK (new_event_cb), self); - read_new_event (self); - osso_abook_init_with_name (PACKAGE, NULL); + + add_new_idle (self); #endif }