[Xfce4-commits] <postler:master> Monitor and re-populate account folders for changes
Christian Dywan
noreply at xfce.org
Wed Jun 16 20:50:02 CEST 2010
Updating branch refs/heads/master
to d475cea6d42ba8775cc210c5d0a5c8050d7f1f35 (commit)
from f6ea97056529c58913f255139e8b165bba6787e2 (commit)
commit d475cea6d42ba8775cc210c5d0a5c8050d7f1f35
Author: Christian Dywan <christian at twotoasts.de>
Date: Tue Jun 15 23:53:07 2010 +0200
Monitor and re-populate account folders for changes
postler/postler-folders.vala | 66 +++++++++++++++++++++++++++++++++++-------
1 files changed, 55 insertions(+), 11 deletions(-)
diff --git a/postler/postler-folders.vala b/postler/postler-folders.vala
index 59c1b54..fee9652 100644
--- a/postler/postler-folders.vala
+++ b/postler/postler-folders.vala
@@ -40,13 +40,14 @@ public class Postler.Folders : Gtk.TreeView {
enum Columns {
ICON,
NAME,
- LOCATION
+ LOCATION,
+ INFO
}
public Folders (Accounts accounts) {
this.accounts = accounts;
- store = new Gtk.TreeStore (3,
- typeof (string), typeof (string), typeof (string));
+ store = new Gtk.TreeStore (4,
+ typeof (string), typeof (string), typeof (string), typeof (AccountInfo));
set_model (store);
insert_column_with_attributes (-1, "Icon",
new Gtk.CellRendererPixbuf (), "stock-id", Columns.ICON, null);
@@ -85,8 +86,11 @@ public class Postler.Folders : Gtk.TreeView {
unread_monitors = {};
unread_monitors_count = 0;
- /* TODO: Monitor folders for changes */
- unowned GLib.List<AccountInfo> infos = accounts.get_infos ();
+
+ return populate_accounts (accounts.get_infos ());
+ }
+
+ public bool populate_accounts (GLib.List<AccountInfo> infos) {
/* foreach (unowned AccountInfo account_info in infos) { */
for (unowned GLib.List<AccountInfo> info_iter = infos;
info_iter != null; info_iter = info_iter.next) {
@@ -96,23 +100,61 @@ public class Postler.Folders : Gtk.TreeView {
store.insert_with_values (null, null, -1,
Columns.ICON, STOCK_FOLDER_SAVED_SEARCH,
Columns.NAME, account_info.name,
+ Columns.INFO, account_info,
Columns.LOCATION, account_info.path, -1);
continue;
}
try {
Gtk.TreeIter account_iter;
- store.insert_with_values (out account_iter, null, -1,
- Columns.ICON, Gtk.STOCK_DIRECTORY,
- Columns.NAME, account_info.name,
- Columns.LOCATION, null, -1);
+ bool existing_iter = false;
+ if (store.iter_children (out account_iter, null)) {
+ do {
+ AccountInfo other_info;
+ store.get (account_iter,
+ Columns.INFO, out other_info,
+ -1);
+ if (account_info == other_info) {
+ existing_iter = true;
+ break;
+ }
+ } while (store.iter_next (ref account_iter));
+ }
+ if (existing_iter) {
+ store.set (account_iter,
+ Columns.ICON, Gtk.STOCK_DIRECTORY,
+ Columns.LOCATION, null,
+ -1);
+ Gtk.TreeIter iter;
+ while (store.iter_children (out iter, account_iter))
+ store.remove (iter);
+ }
+ else
+ store.insert_with_values (out account_iter, null, -1,
+ Columns.ICON, Gtk.STOCK_DIRECTORY,
+ Columns.NAME, account_info.name,
+ Columns.LOCATION, null,
+ Columns.INFO, account_info,
+ -1);
+
var folder_dir = File.new_for_path (account_info.path);
var folder_enumerator = folder_dir.enumerate_children (
FILE_ATTRIBUTE_STANDARD_NAME, 0, null);
FileInfo info;
while ((info = folder_enumerator.next_file (null)) != null) {
- Gtk.TreeIter folder_iter;
string name = info.get_name ();
+ /* FIXME: Handle duplicate or obsolete unread monitor */
+ var account_dir = folder_dir.resolve_relative_path (name);
+ unread_monitors += account_dir.monitor_directory (0, null);
+ unread_monitors_count++;
+ unread_monitors[unread_monitors_count - 1].changed.connect (
+ (monitor, file, other, event) => {
+ var account_infos = new GLib.List<AccountInfo> ();
+ account_infos.prepend (account_info);
+ populate_accounts (account_infos);
+ });
+
+ Gtk.TreeIter folder_iter;
if (name == "INBOX") {
var msg_dir = folder_dir.resolve_relative_path (
account_info.path + "/" + name + "/new");
@@ -146,7 +188,9 @@ public class Postler.Folders : Gtk.TreeView {
store.insert_with_values (out folder_iter, account_iter, -1,
Columns.ICON, stock_id,
Columns.NAME, localized_name ?? name,
- Columns.LOCATION, account_info.path + "/" + name, -1);
+ Columns.LOCATION, account_info.path + "/" + name,
+ Columns.INFO, account_info,
+ -1);
var status_dir = folder_dir.resolve_relative_path (name);
var new_dir = status_dir.resolve_relative_path ("new");
if (!new_dir.query_exists (null))
More information about the Xfce4-commits
mailing list