X-Git-Url: http://git.maemo.org/git/?p=conv-inbox;a=blobdiff_plain;f=src%2Fel-home-applet.c;h=39fa0616bdcec66df73ee92aaa28c81972907ac5;hp=ab65dbc0716560fad753d3a5971f60defc4a3b5e;hb=HEAD;hpb=fe78a609a712a6f3db3348172dff0cd49c870a52 diff --git a/src/el-home-applet.c b/src/el-home-applet.c index ab65dbc..39fa061 100644 --- a/src/el-home-applet.c +++ b/src/el-home-applet.c @@ -25,8 +25,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -84,8 +86,8 @@ static const gchar *conv_services[] = {"RTCOM_EL_SERVICE_SMS", "RTCOM_EL_SERVICE_CHAT", NULL}; -static const gchar *conv_event_types[] = {"RTCOM_EL_EVENTTYPE_SMS_INBOUND", - "RTCOM_EL_EVENTTYPE_CHAT_INBOUND", +static const gchar *conv_event_types[] = {"RTCOM_EL_EVENTTYPE_SMS_MESSAGE", + "RTCOM_EL_EVENTTYPE_CHAT_MESSAGE", NULL}; typedef enum { @@ -141,8 +143,13 @@ struct _ELHomeAppletPrivate gchar *contact_id; gchar *remote_id; gchar *local_id; - gchar *group_uid; + gchar *channel; + int flags; OssoABookContact *contact; + + gboolean time_fmt_24h; + + guint init_timer; }; HD_DEFINE_PLUGIN_MODULE (ELHomeApplet, el_home_applet, HD_TYPE_HOME_PLUGIN_ITEM); @@ -151,8 +158,8 @@ const gchar* g_module_check_init (GModule *module); const gchar* g_module_check_init (GModule *module) { - g_module_make_resident (module); - return NULL; + g_module_make_resident (module); + return NULL; } static void @@ -437,7 +444,7 @@ expose_event (GtkWidget *self, GdkEventExpose *event) if (!priv->message) { rounded_rectangle (cr, 0, HEADER_HEIGHT, - C_WIDTH, C_HEIGHT, + C_WIDTH, C_HEIGHT - HEADER_HEIGHT, BOX_RADIOUS, ROUND_CORNER_BL | ROUND_CORNER_BR); cairo_close_path (cr); @@ -645,6 +652,8 @@ show_contact (ELHomeApplet *self) { ELHomeAppletPrivate *priv = self->priv; + g_return_if_fail (priv->contact); + gtk_label_set_text (GTK_LABEL (priv->sender), osso_abook_contact_get_display_name (priv->contact)); resize_sender (priv); @@ -713,7 +722,7 @@ contacts_added (OssoABookRoster *roster, } static void -reset_contact (ELHomeApplet *self) +reset_contact (ELHomeApplet *self, gboolean resize) { ELHomeAppletPrivate *priv = self->priv; @@ -735,7 +744,8 @@ reset_contact (ELHomeApplet *self) priv->contact = NULL; } - resize_sender (priv); + if (resize) + resize_sender (priv); } static void @@ -752,13 +762,13 @@ contacts_removed (OssoABookRoster *roster, for (contact_id = ids; *contact_id; contact_id++) { if (strcmp (*contact_id, priv->contact_id) == 0) { - reset_contact (self); + reset_contact (self, TRUE); gtk_widget_queue_draw (GTK_WIDGET (self)); return; } if (strcmp (*contact_id, uid) == 0) { - reset_contact (self); + reset_contact (self, TRUE); resolve_contact (self); gtk_widget_queue_draw (GTK_WIDGET (self)); return; @@ -768,11 +778,11 @@ contacts_removed (OssoABookRoster *roster, } static void -clean_contact (ELHomeApplet *self) +clean_contact (ELHomeApplet *self, gboolean resize) { ELHomeAppletPrivate *priv = self->priv; - reset_contact (self); + reset_contact (self, resize); if (priv->aggregator) { if (priv->aggregator_ready_closure){ @@ -814,9 +824,9 @@ clean_state (ELHomeApplet *self) g_free (priv->remote_id); priv->remote_id = NULL; } - if (priv->group_uid) { - g_free (priv->group_uid); - priv->group_uid = NULL; + if (priv->channel) { + g_free (priv->channel); + priv->channel = NULL; } } @@ -825,6 +835,11 @@ dispose (GObject *self) { ELHomeAppletPrivate *priv = EL_HOME_APPLET(self)->priv; + if (priv->init_timer) { + g_source_remove (priv->init_timer); + priv->init_timer = 0; + } + stop_scroll_anim (priv); if (priv->idle_id) { g_source_remove (priv->idle_id); @@ -840,7 +855,7 @@ dispose (GObject *self) } clean_state (EL_HOME_APPLET (self)); - clean_contact (EL_HOME_APPLET (self)); + clean_contact (EL_HOME_APPLET (self), FALSE); G_OBJECT_CLASS (el_home_applet_parent_class)->dispose (self); } @@ -921,25 +936,40 @@ start_aggregator (ELHomeApplet *self) } static gchar* -format_time (time_t t) +format_time (time_t t, gboolean time_fmt_24h) { - static const guint RESULT_SIZE = 32; + static const guint RESULT_SIZE = 64; time_t now; struct tm now_tm, t_tm; - const gchar *format = "%x %X"; + const gchar *time_format; gchar *result = g_malloc0 (RESULT_SIZE); now = time (NULL); localtime_r (&now, &now_tm); localtime_r (&t, &t_tm); + if (time_fmt_24h) + time_format = "wdgt_va_24h_time"; + else + time_format = now_tm.tm_hour > 11 ? + "wdgt_va_12h_time_pm": + "wdgt_va_12h_time_am"; + if ((now_tm.tm_year == t_tm.tm_year) && (now_tm.tm_mon == t_tm.tm_mon) && (now_tm.tm_mday == t_tm.tm_mday)) - format = "%X"; - - strftime (result, RESULT_SIZE, format, &t_tm); + strftime (result, + RESULT_SIZE, + dgettext ("hildon-libs", time_format), + &t_tm); + else { + gchar *full_format = g_strdup_printf ("%s %s", + dgettext ("hildon-libs", "wdgt_va_date"), + dgettext ("hildon-libs", time_format)); + strftime (result, RESULT_SIZE, full_format, &t_tm); + g_free (full_format); + } return result; } @@ -948,62 +978,44 @@ static void show_event (ELHomeApplet *self, RTComElIter *it) { ELHomeAppletPrivate *priv = self->priv; - const gchar *remote = NULL; + gchar *remote = NULL; gchar *received = NULL; - GValueArray *event = NULL; if (it && rtcom_el_iter_first (it)) { - - 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) { + time_t received_t; + + if (rtcom_el_iter_get_values (it, + "id", &priv->event_id, + "start-time", &received_t, + "local-uid", &priv->local_id, + "remote-uid", &priv->remote_id, + "remote-name", &remote, + "remote-ebook-uid", &priv->contact_id, + "free-text", &priv->message, + "channel", &priv->channel, + "flags", &priv->flags, + NULL)) { + received = format_time (received_t, priv->time_fmt_24h); + + if (priv->remote_id && !priv->remote_id[0]) { g_free (priv->remote_id); priv->remote_id = NULL; } - - priv->message = _VARR_DUP_STR (event, 6); - priv->group_uid = _VARR_DUP_STR (event, 7); - -#undef _VARR_DUP_STR } + else + priv->event_id = -1; } - else { + else priv->event_id = -1; - } - if (priv->message) { + if (priv->message) gtk_widget_hide (priv->empty); - } - else { + else gtk_widget_show (priv->empty); - } gtk_label_set_text (GTK_LABEL (priv->received), received); - if (remote) + if (remote && remote[0]) gtk_label_set_text (GTK_LABEL (priv->sender), remote); else gtk_label_set_text (GTK_LABEL (priv->sender), priv->remote_id); @@ -1015,11 +1027,10 @@ 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)); + + g_free (remote); } static RTComElIter* @@ -1038,6 +1049,7 @@ make_query (RTComEl *el, gint event_id) else { rtcom_el_query_prepare (query, "is-read", FALSE, RTCOM_EL_OP_EQUAL, + "outgoing", FALSE, RTCOM_EL_OP_EQUAL, "service", conv_services, RTCOM_EL_OP_IN_STRV, "event-type", conv_event_types, RTCOM_EL_OP_IN_STRV, NULL); @@ -1192,11 +1204,13 @@ read_event (ELHomeApplet *self) 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); + if (g_strcmp0 (priv->remote_id, remote_id) || + new_account || + !priv->contact) { + clean_contact (self, TRUE); start_aggregator (self); } - else { + else if (priv->contact) { show_contact (self); } @@ -1258,7 +1272,7 @@ read_event (ELHomeApplet *self) dgettext ("rtcom-messaging-ui", "messaging_ap_conversations")); - clean_contact (self); + clean_contact (self, TRUE); gtk_widget_hide (priv->icon); } @@ -1383,9 +1397,8 @@ open_conversation (ELHomeApplet *self) { ELHomeAppletPrivate *priv = self->priv; McAccount *account; - const gchar *persistent_id = NULL; - if (!((priv->remote_id || priv->group_uid) && priv->local_id)) + if (!((priv->remote_id || priv->channel) && priv->local_id)) return; account = osso_abook_account_manager_lookup_by_name (NULL, @@ -1393,21 +1406,18 @@ open_conversation (ELHomeApplet *self) if (!account) return; - if (priv->group_uid && - g_str_has_prefix (priv->group_uid, "group:")) { - persistent_id = strchr (priv->group_uid, '-'); - if (persistent_id) - persistent_id++; - } + if ((priv->flags & RTCOM_EL_FLAG_CHAT_GROUP) && + (priv->flags & RTCOM_EL_FLAG_CHAT_OPAQUE)) { + if (!priv->channel) + return; - if (persistent_id && persistent_id[0] != '\0') { GHashTable *properties = tp_asv_new (TP_IFACE_CHANNEL ".ChannelType", G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_TEXT, TP_IFACE_CHANNEL ".TargetHandleType", G_TYPE_UINT, TP_HANDLE_TYPE_NONE, RTCOM_TP_IFACE_CHANNEL_INTERFACE_PERSISTENT ".PersistentID", - G_TYPE_STRING, persistent_id, + G_TYPE_STRING, priv->channel, NULL); mc_account_channelrequest_ht (account, @@ -1419,13 +1429,23 @@ open_conversation (ELHomeApplet *self) g_hash_table_unref (properties); } - else if (priv->remote_id) { + else { McAccountChannelrequestData request; MC_ACCOUNT_CRD_INIT (&request); MC_ACCOUNT_CRD_SET (&request, channel_type, TP_IFACE_QUARK_CHANNEL_TYPE_TEXT); - MC_ACCOUNT_CRD_SET (&request, target_handle_type, TP_HANDLE_TYPE_CONTACT); - MC_ACCOUNT_CRD_SET (&request, target_id, priv->remote_id); + + if ((priv->flags & RTCOM_EL_FLAG_CHAT_ROOM) && + priv->channel) { + MC_ACCOUNT_CRD_SET (&request, target_handle_type, TP_HANDLE_TYPE_ROOM); + MC_ACCOUNT_CRD_SET (&request, target_id, priv->channel); + } + else if (priv->remote_id) { + MC_ACCOUNT_CRD_SET (&request, target_handle_type, TP_HANDLE_TYPE_CONTACT); + MC_ACCOUNT_CRD_SET (&request, target_id, priv->remote_id); + } + else + return; mc_account_channelrequest (account, &request, @@ -1442,7 +1462,12 @@ read_new_event (ELHomeApplet *self) ELHomeAppletPrivate *priv = self->priv; read_event (self); - priv->unread_count = query_unread_events (priv->eventlogger); + + if (priv->event_id >= 0) + priv->unread_count = query_unread_events (priv->eventlogger); + else + priv->unread_count = 0; + update_unread_label (self); priv->idle_id = 0; @@ -1485,6 +1510,28 @@ new_event_cb (RTComEl *backend, add_new_idle (self); } +static void +all_deleted_cb (RTComEl *backend, + const gchar *service, + ELHomeApplet *self) +{ + new_event_cb (backend, + 0, + NULL, + NULL, + NULL, + NULL, + service, + self); +} + +static void +refresh_hint_cb (RTComEl *backend, + ELHomeApplet *self) +{ + add_new_idle (self); +} + static gboolean scroll_anim_cb (ELHomeApplet *self) { @@ -1632,9 +1679,7 @@ button_release_event_cb (GtkWidget *widget, self); } else -#ifndef DEBUG_LAYOUT mark_as_read (self); -#endif break; default:; } @@ -1667,6 +1712,67 @@ leave_notify_event_cb (GtkWidget *widget, return FALSE; } +static gboolean +init_eventlogger (ELHomeApplet *self) +{ + ELHomeAppletPrivate *priv = self->priv; + + priv->eventlogger = rtcom_el_new (); + + /* check that db is initialized */ + gpointer *db = NULL; + g_object_get (priv->eventlogger, "db", &db, NULL); + if (!db) { + static int trial = 0; + + g_object_unref (priv->eventlogger); + priv->eventlogger = NULL; + + if (trial == 0) { + trial++; + priv->init_timer = g_timeout_add_seconds (5, + (GSourceFunc)init_eventlogger, + self); + return TRUE; /* return value doesn't matter */ + } + else if (trial < 5) { + trial++; + return TRUE; + } + else { + g_error ("Failed to init eventlogger"); + return FALSE; + } + } + + g_signal_connect (priv->eventlogger, + "new-event", + G_CALLBACK (new_event_cb), + self); + g_signal_connect (priv->eventlogger, + "event-updated", + G_CALLBACK (new_event_cb), + self); + g_signal_connect (priv->eventlogger, + "event-deleted", + G_CALLBACK (new_event_cb), + self); + g_signal_connect (priv->eventlogger, + "all-deleted", + G_CALLBACK (all_deleted_cb), + self); + g_signal_connect (priv->eventlogger, + "refresh-hint", + G_CALLBACK (refresh_hint_cb), + self); + + add_new_idle (self); + + priv->init_timer = 0; + + return FALSE; +} + static void el_home_applet_init (ELHomeApplet *self) { @@ -1674,13 +1780,14 @@ el_home_applet_init (ELHomeApplet *self) GtkWidget *event_box; GtkWidget *hbox, *vbox, *align, *footer; GtkWidget *w; + GConfClient *gconf; self->priv = EL_HOME_APPLET_GET_PRIVATE (self); priv = self->priv; gtk_widget_set_app_paintable (GTK_WIDGET (self), TRUE); - priv->unread = gtk_label_new ("12"); + priv->unread = gtk_label_new (NULL); gtk_misc_set_alignment (GTK_MISC (priv->unread), 0.0f, 0.5f); @@ -1691,7 +1798,7 @@ el_home_applet_init (ELHomeApplet *self) 0.5f, 0.5f); - priv->sender = gtk_label_new ("asdf asdf asdf asdf asdf"); + priv->sender = gtk_label_new (NULL); gtk_misc_set_alignment (GTK_MISC (priv->sender), 0.5f, 0.55f); @@ -1703,8 +1810,6 @@ el_home_applet_init (ELHomeApplet *self) C_WIDTH, HILDON_ICON_PIXEL_SIZE_THUMB); - priv->message = g_strdup ("One two three four five six seven eight nine ten"); - /* construt empty table */ priv->empty = gtk_fixed_new (); @@ -1734,7 +1839,7 @@ el_home_applet_init (ELHomeApplet *self) 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"); + priv->received = gtk_label_new (NULL); gtk_misc_set_alignment (GTK_MISC (priv->received), 1.0f, 0.5f); @@ -1802,21 +1907,16 @@ el_home_applet_init (ELHomeApplet *self) gtk_widget_show_all (GTK_WIDGET (event_box)); -#ifndef DEBUG_LAYOUT - priv->eventlogger = rtcom_el_new (); - g_signal_connect (priv->eventlogger, - "new-event", - G_CALLBACK (new_event_cb), - self); - g_signal_connect (priv->eventlogger, - "event-updated", - G_CALLBACK (new_event_cb), - self); osso_abook_init_with_name (PACKAGE, NULL); - add_new_idle (self); -#endif + gconf = gconf_client_get_default (); + priv->time_fmt_24h = gconf_client_get_bool (gconf, + "/apps/clock/time-format", + NULL); + g_object_unref (gconf); + + init_eventlogger (self); } static void @@ -1832,4 +1932,3 @@ el_home_applet_class_init (ELHomeAppletClass *klass) g_type_class_add_private (klass, sizeof (ELHomeAppletPrivate)); } -