[Xfce4-commits] <postler:master> Use client API instead of monitors for folder list
Christian Dywan
noreply at xfce.org
Sat Jun 4 14:30:09 CEST 2011
Updating branch refs/heads/master
to 18fed6282bf95a83a03c2d331b58074e23aa99ee (commit)
from b03910de19acbd3a339609b7dbcb6302126e8d0f (commit)
commit 18fed6282bf95a83a03c2d331b58074e23aa99ee
Author: Christian Dywan <christian at twotoasts.de>
Date: Fri Jun 3 23:11:28 2011 +0200
Use client API instead of monitors for folder list
postler/postler-folders.vala | 88 +++++++++--------------------------------
1 files changed, 20 insertions(+), 68 deletions(-)
diff --git a/postler/postler-folders.vala b/postler/postler-folders.vala
index c737e85..09077cc 100644
--- a/postler/postler-folders.vala
+++ b/postler/postler-folders.vala
@@ -16,6 +16,7 @@ public class Postler.Folders : Gtk.TreeView {
Gtk.TreePath? selected_folder = null;
Gtk.TreePath? drop_folder = null;
int blink_counter = -1;
+ Postler.Client client = new Client ();
public Postler.Messages messages { get; set; }
public string? selected_location { get; private set; }
@@ -39,8 +40,6 @@ public class Postler.Folders : Gtk.TreeView {
LOCATION,
INFO,
TOPLEVEL_MONITOR,
- FOLDER_MONITOR,
- UNREAD_MONITOR,
FOLDER_TYPE
}
@@ -163,11 +162,10 @@ public class Postler.Folders : Gtk.TreeView {
}
}
- store = new Gtk.TreeStore (10,
+ store = new Gtk.TreeStore (8,
typeof (string), typeof (string), typeof (string),
typeof (int), typeof (string),
- typeof (AccountInfo), typeof (GLib.FileMonitor),
- typeof (GLib.FileMonitor), typeof (GLib.FileMonitor), typeof (FolderType));
+ typeof (AccountInfo), typeof (GLib.FileMonitor), typeof (FolderType));
set_model (store);
/* Column #0 is for padding only, that's why the expander is in #1 */
insert_column_with_data_func (-1, "", new Gtk.CellRendererPixbuf (),
@@ -210,14 +208,13 @@ public class Postler.Folders : Gtk.TreeView {
assert_not_reached ();
}
- async void unread_count_update (Gtk.TreeIter iter, File msg_dir, string label) {
+ async void unread_count_update (Gtk.TreeIter iter, string folder, string label) {
try {
- var client = new Client ();
- int64 unread = yield client.unread_messages (msg_dir.get_uri () + "%");
+ int64 unread = yield client.unread_messages ("%/" + folder + "/%");
string escaped = GLib.Markup.escape_text (label);
if (unread == 0)
store.set (iter, Columns.DISPLAY_NAME, "%s".printf (escaped));
- else if (msg_dir.get_path ().has_suffix ("INBOX/new"))
+ else if ("INBOX" in folder)
store.set (iter, Columns.DISPLAY_NAME,
"<b>%s (%d)</b>".printf (escaped, (int)unread));
else
@@ -225,34 +222,10 @@ public class Postler.Folders : Gtk.TreeView {
"%s (%d)".printf (escaped, (int)unread));
} catch (GLib.Error error) {
GLib.critical (_("Failed to monitor folder \"%s\": %s"),
- msg_dir.get_path (), error.message);
+ folder, error.message);
}
}
- void unread_monitor_changed (File msg_dir, string label) {
- string location = msg_dir.get_path ();
- location = location.slice (0, -4); /* - /new */
-
- Gtk.TreeIter account_iter;
- if (!store.iter_children (out account_iter, null))
- return;
- do {
- string existing_location;
- store.get (account_iter, Columns.LOCATION, out existing_location);
- if (existing_location == location) {
- unread_count_update (account_iter, msg_dir, label);
- break;
- }
- string account_location = existing_location.slice (0, - 6);
- if (location.has_prefix (account_location)) {
- Gtk.TreeIter iter;
- if (get_folder_iter (location, account_iter, out iter))
- unread_count_update (iter, msg_dir, label);
- break;
- }
- } while (store.iter_next (ref account_iter));
- }
-
public bool populate () {
store.clear ();
@@ -416,22 +389,21 @@ public class Postler.Folders : Gtk.TreeView {
continue;
if (name == "INBOX") {
- var msg_dir = folder_dir.resolve_relative_path (
- account_info.path + "/" + name + "/new");
- monitor = msg_dir.monitor_directory (0, null);
string label = account_info.display_name;
- monitor.changed.connect ((monitor, file, other, event) => {
- unread_monitor_changed (msg_dir, label);
+ /* FIXME: The client emits, the callback isn't called */
+ client.received.connect ((account, error_message) => {
+ unread_count_update (account_iter,
+ account_info.name + "/INBOX", label);
});
account_info.folders[FolderType.INBOX] = name;
store.set (account_iter,
Columns.ICON, STOCK_INBOX,
Columns.NAME, label,
- Columns.LOCATION, account_info.path + "/" + name,
- Columns.UNREAD_MONITOR, monitor,
+ Columns.LOCATION, account_info.path + "/INBOX",
Columns.FOLDER_TYPE, FolderType.INBOX);
- unread_count_update (account_iter, msg_dir, label);
+ unread_count_update (account_iter,
+ account_info.name + "/INBOX", label);
continue;
}
@@ -460,16 +432,14 @@ public class Postler.Folders : Gtk.TreeView {
Columns.ELLIPSIZE, Pango.EllipsizeMode.MIDDLE,
Columns.LOCATION, account_info.path + "/" + name,
Columns.INFO, account_info,
- Columns.FOLDER_MONITOR, monitor,
Columns.FOLDER_TYPE, folder.type);
- var msg_dir = folder_dir.resolve_relative_path (
- account_info.path + "/" + name + "/new");
- monitor = msg_dir.monitor_directory (0, null);
- monitor.changed.connect ((monitor, file, other, event) => {
- unread_monitor_changed (msg_dir, display_name);
+ /* FIXME: The client emits, the callback isn't called */
+ client.received.connect ((account, error_message) => {
+ unread_count_update (account_iter,
+ account_info.name + "/" + name, display_name);
});
- unread_count_update (folder_iter, msg_dir, display_name);
- store.set (folder_iter, Columns.UNREAD_MONITOR, monitor);
+ unread_count_update (folder_iter,
+ account_info.name + "/" + name, display_name);
}
/* Look for missing special folders or create them */
@@ -535,24 +505,6 @@ public class Postler.Folders : Gtk.TreeView {
if (location != null) {
messages.populate (location, account_info);
messages.grab_focus ();
- if (account_info.type == AccountType.SEARCH)
- return;
- try {
- var folder_dir = File.new_for_path (location + "/new");
- var enumerator = folder_dir.enumerate_children (
- FILE_ATTRIBUTE_STANDARD_NAME, 0);
- FileInfo file_info;
- while ((file_info = enumerator.next_file ()) != null) {
- var msg = File.new_for_path (
- location + "/new/" + file_info.get_name ());
- var destination = File.new_for_path (
- location + "/cur/" + file_info.get_name ());
- msg.move (destination, FileCopyFlags.NONE);
- }
- } catch (Error error) {
- GLib.warning (_("Failed to select folder \"%s\": %s"),
- location, error.message);
- }
}
else
messages.display_error (_("No messages were fetched yet"),
More information about the Xfce4-commits
mailing list