static void log_window_chats_get_messages (EmpathyLogWindow *window, const gchar *date_to_show) { TpAccount *account; gchar *chat_id; gboolean is_chatroom; const gchar *date; guint year_selected; guint year; guint month; guint month_selected; guint day; if (!log_window_chats_get_selected (window, &account, &chat_id, &is_chatroom)) { return; } g_signal_handlers_block_by_func (window->calendar_chats, log_window_calendar_chats_day_selected_cb, window); /* Either use the supplied date or get the last */ date = date_to_show; if (!date) { /* Get a list of dates and show them on the calendar */ tpl_log_manager_get_dates_async (window->log_manager, account, chat_id, is_chatroom, log_manager_got_dates_cb, (gpointer) window); /* signal unblocked at the end of the CB flow */ } else { sscanf (date, "%4d%2d%2d", &year, &month, &day); gtk_calendar_get_date (GTK_CALENDAR (window->calendar_chats), &year_selected, &month_selected, NULL); month_selected++; if (year != year_selected && month != month_selected) { day = 0; } gtk_calendar_select_day (GTK_CALENDAR (window->calendar_chats), day); g_signal_handlers_unblock_by_func (window->calendar_chats, log_window_calendar_chats_day_selected_cb, window); } if (date) { log_window_get_messages_for_date (window, date); } g_object_unref (account); g_free (chat_id); }
static void log_manager_got_dates_cb (GObject *manager, GAsyncResult *result, gpointer user_data) { EmpathyLogWindow *window = user_data; GList *dates; GList *l; guint year_selected; guint month_selected; gboolean day_selected = FALSE; GDate *date = NULL; GError *error = NULL; if (log_window == NULL) return; if (!tpl_log_manager_get_dates_finish (TPL_LOG_MANAGER (manager), result, &dates, &error)) { DEBUG ("Unable to retrieve messages' dates: %s. Aborting", error->message); empathy_chat_view_append_event (window->chatview_find, "Unable to retrieve messages' dates"); return; } for (l = dates; l; l = l->next) { GDate *d = l->data; gtk_calendar_get_date (GTK_CALENDAR (window->calendar_chats), &year_selected, &month_selected, NULL); month_selected++; if (!l->next) { date = d; } if (g_date_get_year (d) != year_selected || g_date_get_month (d) != month_selected) { continue; } DEBUG ("Marking date: %04u-%02u-%02u", g_date_get_year (d), g_date_get_month (d), g_date_get_day (d)); gtk_calendar_mark_day (GTK_CALENDAR (window->calendar_chats), g_date_get_day (d)); if (l->next) { continue; } day_selected = TRUE; gtk_calendar_select_day (GTK_CALENDAR (window->calendar_chats), g_date_get_day (d)); } if (!day_selected) { /* Unselect the day in the calendar */ gtk_calendar_select_day (GTK_CALENDAR (window->calendar_chats), 0); } g_signal_handlers_unblock_by_func (window->calendar_chats, log_window_calendar_chats_day_selected_cb, window); if (date != NULL) { /* Show messages of the most recent date */ log_window_get_messages_for_date (window, date); } g_list_foreach (dates, (GFunc) g_free, NULL); g_list_free (dates); }
static void log_manager_got_dates_cb (GObject *manager, GAsyncResult *result, gpointer user_data) { EmpathyLogWindow *window = user_data; GList *dates; GList *l; guint year_selected; guint year; guint month; guint month_selected; guint day; gboolean day_selected = FALSE; const gchar *date = NULL; GError *error = NULL; dates = tpl_log_manager_get_dates_async_finish (result, &error); if (error != NULL) { DEBUG ("Unable to retrieve messages' dates: %s. Aborting", error->message); empathy_chat_view_append_event (window->chatview_find, "Unable to retrieve messages' dates"); return; } for (l = dates; l; l = l->next) { const gchar *str; str = l->data; if (!str) { continue; } sscanf (str, "%4d%2d%2d", &year, &month, &day); gtk_calendar_get_date (GTK_CALENDAR (window->calendar_chats), &year_selected, &month_selected, NULL); month_selected++; if (!l->next) { date = str; } if (year != year_selected || month != month_selected) { continue; } DEBUG ("Marking date:'%s'", str); gtk_calendar_mark_day (GTK_CALENDAR (window->calendar_chats), day); if (l->next) { continue; } day_selected = TRUE; gtk_calendar_select_day (GTK_CALENDAR (window->calendar_chats), day); } if (!day_selected) { /* Unselect the day in the calendar */ gtk_calendar_select_day (GTK_CALENDAR (window->calendar_chats), 0); } g_signal_handlers_unblock_by_func (window->calendar_chats, log_window_calendar_chats_day_selected_cb, window); if (date) { log_window_get_messages_for_date (window, date); } g_list_foreach (dates, (GFunc) g_free, NULL); g_list_free (dates); }