[Xfce4-commits] <postler:master> Show total number of messages in light font

Christian Dywan noreply at xfce.org
Thu Jul 7 05:02:01 CEST 2011


Updating branch refs/heads/master
         to b0faca18cc0c60b4e7fe7c5be59cbffa6ede733d (commit)
       from 157916d0299af4bc003ad0af5e91eb7a9e63df22 (commit)

commit b0faca18cc0c60b4e7fe7c5be59cbffa6ede733d
Author: Christian Dywan <christian at twotoasts.de>
Date:   Thu Jul 7 00:06:14 2011 +0200

    Show total number of messages in light font

 postler/postler-bureau.vala  |    8 +++++---
 postler/postler-client.vala  |    4 ++--
 postler/postler-index.vala   |   21 ++++++++++++++-------
 postler/postler-service.vala |   14 +++++++-------
 4 files changed, 28 insertions(+), 19 deletions(-)

diff --git a/postler/postler-bureau.vala b/postler/postler-bureau.vala
index d48e805..956003f 100644
--- a/postler/postler-bureau.vala
+++ b/postler/postler-bureau.vala
@@ -496,9 +496,11 @@ public class Postler.Bureau : Gtk.Window {
 
     async void update_messages_label () {
         try {
-            /* FIXME: Show total number of messages */
-            int64 unread = yield client.unread_messages (messages.location);
-            messages_label.label = _("%d Unread").printf ((int)unread);
+            int64[] counts = yield client.unread_messages (messages.location);
+            int unread = (int)counts[0];
+            int total = (int)counts[1];
+            string markup = _("<span weight=\"light\">%d Messages</span>, %d Unread");
+            messages_label.set_markup (markup.printf (total, unread));
         } catch (GLib.Error error) {
             messages_label.label = error.message;
         }
diff --git a/postler/postler-client.vala b/postler/postler-client.vala
index adf30be..8b75e96 100644
--- a/postler/postler-client.vala
+++ b/postler/postler-client.vala
@@ -13,7 +13,7 @@ namespace Postler {
 
     [DBus (name = "org.elementary.Postler")]
     interface PostlerClient : Object {
-        public async abstract int64 unread_messages (string uri) throws IOError;
+        public async abstract int64[] unread_messages (string uri) throws IOError;
         public async abstract GLib.HashTable<string,Variant> get_message (string id,
             char flag) throws IOError;
         public async abstract string[] get_thread (string thread) throws IOError;
@@ -60,7 +60,7 @@ namespace Postler {
             } catch (GLib.Error error) { }
         }
 
-        public async int64 unread_messages (string uri) throws GLib.Error {
+        public async int64[] unread_messages (string uri) throws GLib.Error {
             return yield client.unread_messages (uri);
         }
 
diff --git a/postler/postler-index.vala b/postler/postler-index.vala
index 5a95b6b..0d0e0a5 100644
--- a/postler/postler-index.vala
+++ b/postler/postler-index.vala
@@ -255,11 +255,10 @@ namespace Postler {
             return folder;
         }
 
-        public int64 unread_messages (string folder) throws GLib.Error {
+        public int64[] unread_messages (string folder) throws GLib.Error {
             unowned string sql = """
-                SELECT COUNT (id) FROM
-                (SELECT DISTINCT id FROM messages
-                WHERE unread != 0 AND $FIELD LIKE ?2 $CASE)
+                SELECT unread, COUNT (*) FROM messages
+                WHERE $FIELD LIKE ?2 $CASE GROUP BY unread
                 """;
 
             if (statement_unread == null) {
@@ -271,15 +270,23 @@ namespace Postler {
             string search_value = search_statement (folder, sql, ref temporary_statement);
             unowned Sqlite.Statement statement = temporary_statement != null
                                                ? temporary_statement : statement_unread;
+            int result = Sqlite.ERROR;
             bool success = statement.bind_text (2, search_value, -1) == Sqlite.OK
-             && statement.step () == Sqlite.ROW;
+             && (row_or_done ((result = statement.step ())));
             if (!success) {
                 statement.reset ();
                 throw new GLib.FileError.FAILED (_("Failed to count unread messages: %s"), database.errmsg ());
             }
-            int64 count = statement.column_int64 (0);
+            int64 read = 0, unread = 0;
+            while (result == Sqlite.ROW) {
+                if (statement.column_int64 (0) == 0)
+                    read = statement.column_int64 (1);
+                else
+                    unread = statement.column_int64 (1);
+                result = statement.step ();
+            }
             statement.reset ();
-            return count;
+            return { unread, unread + read };
         }
 
         public Message get_message (string id) throws GLib.Error {
diff --git a/postler/postler-service.vala b/postler/postler-service.vala
index 8b8620a..7dc2e90 100644
--- a/postler/postler-service.vala
+++ b/postler/postler-service.vala
@@ -137,14 +137,14 @@ namespace Postler {
 
         void update_inbox_indicator (Indicate.Indicator item) {
             string path = "file://" + item.get_property ("url") + "/INBOX/%";
-            uint new_messages = 0;
+            int64 new_messages = 0;
 
             notify["unread"].connect ((object, pspec) => {
                 update_inbox_indicator (item);
             });
 
             try {
-                new_messages = (uint)unread_messages (path);
+                new_messages = unread_messages (path)[0];
             }
             catch (Error error) {
                 GLib.warning ("Indicator: %s", error.message);
@@ -189,12 +189,12 @@ namespace Postler {
         }
 
         bool badge_timer () {
-            uint new_messages = 0;
+            int64 new_messages = 0;
             try {
-                new_messages = (uint)unread_messages ("%/INBOX/%");
+                new_messages = unread_messages ("%/INBOX/%")[0];
             }
             catch (GLib.Error error) { }
-            dockitem.set_badge (new_messages);
+            dockitem.set_badge ((int)new_messages);
             return true;
         }
 
@@ -388,7 +388,7 @@ namespace Postler {
             }
         }
 
-        public int64 unread_messages (string uri) throws GLib.Error {
+        public int64[] unread_messages (string uri) throws GLib.Error {
              return index.unread_messages (uri);
         }
 
@@ -462,7 +462,7 @@ namespace Postler {
                             return;
                         }
                         try {
-                            if ((unread = unread_messages ("%/INBOX/%")) > 0) {
+                            if ((unread = unread_messages ("%/INBOX/%")[0]) > 0) {
                                 GLib.debug ("Done: %d new messages", (int)unread);
                                 Postler.App.send_notification (
                                     ngettext ("You have %d message",



More information about the Xfce4-commits mailing list