From b049a9695a27b9ec00f5a032b2a81bb5954579a6 Mon Sep 17 00:00:00 2001 From: Artem Garmash Date: Mon, 1 Feb 2010 00:54:19 +0200 Subject: [PATCH] Show total SMSs, chat messages when widget is empty --- src/el-home-applet.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/src/el-home-applet.c b/src/el-home-applet.c index efbf69d..911f857 100644 --- a/src/el-home-applet.c +++ b/src/el-home-applet.c @@ -1093,6 +1093,45 @@ query_unread_events (RTComEl *el) return count; } +static gint +query_read_events (RTComEl *el, const gchar *service) +{ + sqlite3 *db; + sqlite3_stmt *stmt; + int ret; + gint count = -1; + + g_object_get (el, "db", &db, NULL); + + if (sqlite3_prepare_v2 (db, + "SELECT SUM(total_events) 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 -1; + } + if (sqlite3_bind_text (stmt, 1, service, -1, SQLITE_STATIC) != SQLITE_OK) { + g_error ("Failed to bind %s to SQL stmt", service); + goto DONE; + } + + while (SQLITE_BUSY == (ret = sqlite3_step (stmt))); + + if (ret == SQLITE_ROW) { + count = sqlite3_column_int (stmt, 0); + } + else { + g_error ("%s: error while executing SQL", G_STRFUNC); + } + + DONE: + sqlite3_finalize (stmt); + + return count; +} + static void read_event (ELHomeApplet *self) { @@ -1105,6 +1144,8 @@ read_event (ELHomeApplet *self) it = make_query (priv->eventlogger, -1); show_event (self, it); + if (it) g_object_unref (it); + if (priv->event_id >= 0) { start_aggregator (self); @@ -1128,8 +1169,18 @@ read_event (ELHomeApplet *self) gtk_widget_show (priv->icon); } } - - if (it) g_object_unref (it); + else { + gint n_sms_events = query_read_events (priv->eventlogger, + "RTCOM_EL_SERVICE_SMS"); + gint n_chat_events = query_read_events (priv->eventlogger, + "RTCOM_EL_SERVICE_CHAT"); + gchar *empty_text = g_strdup_printf ("SMSes %d, Chats %d", + n_sms_events, + n_chat_events); + gtk_label_set_text (GTK_LABEL (priv->empty), + empty_text); + g_free (empty_text); + } } static void -- 1.7.9.5