[Xfce4-commits] <postler:master> Local folders in Postler.Folders and no properties

Christian Dywan noreply at xfce.org
Sun Dec 26 04:50:01 CET 2010


Updating branch refs/heads/master
         to 8ca0c2c788af2ff2751830e2b90d70b92f7bd6dc (commit)
       from 0c80ea7f35b1420353511813d3798e68a2cacab8 (commit)

commit 8ca0c2c788af2ff2751830e2b90d70b92f7bd6dc
Author: Christian Dywan <christian at twotoasts.de>
Date:   Fri Dec 24 23:35:14 2010 +0100

    Local folders in Postler.Folders and no properties
    
    Any local folders shouldn't be saved and can't be removed
    or configured.

 postler/postler-accounts.vala |   31 +----------------------------
 postler/postler-folders.vala  |   42 +++++++++++++++++++++++++++++++++++-----
 2 files changed, 38 insertions(+), 35 deletions(-)

diff --git a/postler/postler-accounts.vala b/postler/postler-accounts.vala
index 8902c31..213990e 100644
--- a/postler/postler-accounts.vala
+++ b/postler/postler-accounts.vala
@@ -141,20 +141,13 @@ public class Postler.Accounts : GLib.Object {
         "/usr/local/share/certs/ca-root-nss.crt"
     };
 
-    public Accounts (string? location=null) {
-        if (location != null) {
-            this.location = location;
-            reload ();
-            return;
-        }
-
+    public Accounts () {
         unowned string config_dir = Environment.get_user_config_dir ();
         config_path = config_dir + "/" + Config.PACKAGE_NAME + "/";
         account_file = config_path + "accountrc";
 
         unowned string data_dir = Environment.get_user_data_dir ();
         data_path = data_dir + "/" + Config.PACKAGE_NAME + "/mail/";
-        /* TODO: Monitor accountrc file and emit a signal */
 
         foreach (unowned string file in root_certificate_files) {
             if (FileUtils.test (file, FileTest.EXISTS))
@@ -251,26 +244,6 @@ public class Postler.Accounts : GLib.Object {
 
     void reload () {
         infos = new GLib.List<AccountInfo> ();
-        var info = new AccountInfo ();
-        unowned string toplevel = Environment.get_variable ("MAILDIR");
-        if (toplevel != null && toplevel != "")
-            info.path = toplevel;
-        else {
-            string local_mail = Environment.get_home_dir () + "/Mail";
-            if (FileUtils.test (local_mail, FileTest.IS_DIR))
-                info.path = local_mail;
-            else {
-                local_mail = Environment.get_home_dir () + "/Maildir";
-                if (FileUtils.test (local_mail, FileTest.IS_DIR))
-                    info.path = local_mail;
-            }
-        }
-        if (info.path != null) {
-            info.name = _("Local");
-            info.type = AccountType.MAILDIR;
-            infos.prepend (info);
-        }
-
         keyfile = new GLib.KeyFile ();
         try {
             keyfile.load_from_file (account_file, 0);
@@ -283,7 +256,7 @@ public class Postler.Accounts : GLib.Object {
             try {
                 string name = keyfile.get_string (group, "name");
                 string type = keyfile.get_string (group, "type");
-                info = new AccountInfo ();
+                var info = new AccountInfo ();
                 info.name = name;
                 if (type == "maildir") {
                     info.type = AccountType.MAILDIR;
diff --git a/postler/postler-folders.vala b/postler/postler-folders.vala
index 658c8ba..c858d21 100644
--- a/postler/postler-folders.vala
+++ b/postler/postler-folders.vala
@@ -11,6 +11,7 @@
 
 public class Postler.Folders : Gtk.TreeView {
     Accounts accounts;
+    AccountInfo local_info;
     Gtk.TreeStore store;
 
     public Postler.Messages messages { get; set; }
@@ -40,6 +41,26 @@ public class Postler.Folders : Gtk.TreeView {
 
     public Folders (Accounts accounts) {
         this.accounts = accounts;
+
+        /* Local folders */
+        local_info = new AccountInfo ();
+        local_info.name = _("Local");
+        local_info.type = AccountType.MAILDIR;
+        local_info.path = null;
+        unowned string mail = Environment.get_variable ("MAILDIR");
+        if (mail != null && mail != "")
+            local_info.path = mail;
+        else {
+            string local_mail = Environment.get_home_dir () + "/Mail";
+            if (FileUtils.test (local_mail, FileTest.IS_DIR))
+                local_info.path = local_mail;
+            else {
+                local_mail = Environment.get_home_dir () + "/Maildir";
+                if (FileUtils.test (local_mail, FileTest.IS_DIR))
+                    local_info.path = local_mail;
+            }
+        }
+
         store = new Gtk.TreeStore (8,
             typeof (string), typeof (string), typeof (int), typeof (string),
             typeof (AccountInfo),
@@ -75,7 +96,9 @@ public class Postler.Folders : Gtk.TreeView {
     public bool populate () {
         store.clear ();
 
-        return populate_accounts (accounts.get_infos ());
+        var account_infos = accounts.get_infos ().copy ();
+        account_infos.prepend (local_info);
+        return populate_accounts (account_infos);
     }
 
     bool get_folder_iter (string location, Gtk.TreeIter account_iter,
@@ -102,7 +125,7 @@ public class Postler.Folders : Gtk.TreeView {
             num_accounts = count;
         else {
             foreach (unowned AccountInfo account_info in infos) {
-                if (account_info.type == AccountType.IMAP)
+                if (account_info.type != AccountType.SEARCH)
                     num_accounts++;
             }
         }
@@ -446,17 +469,22 @@ public class Postler.Folders : Gtk.TreeView {
         });
         menu.append (menuitem);
 
-        menu.append (new Gtk.SeparatorMenuItem ());
-
         bool is_account = false;
+        bool is_local = false;
         Gtk.TreeIter selected_iter;
         if (get_selection ().get_selected (null, out selected_iter)) {
             Gtk.TreeIter iter;
             if (!store.iter_parent (out iter, selected_iter))
                 is_account = true;
+
+            AccountInfo? account_info;
+            store.get (selected_iter, Columns.INFO, out account_info);
+            is_local = account_info == local_info;
         }
 
-        if (!is_account) {
+        if (!is_account && !is_local) {
+            menu.append (new Gtk.SeparatorMenuItem ());
+
             menuitem = new Gtk.MenuItem.with_mnemonic (_("_Use as..."));
             var use_as_menu = new Gtk.Menu ();
             for (int i = 1; i < FolderType.MAX; i++) {
@@ -494,7 +522,9 @@ public class Postler.Folders : Gtk.TreeView {
             });
             menu.append (menuitem);
         }
-        else {
+        else if (!is_local) {
+            menu.append (new Gtk.SeparatorMenuItem ());
+
             menuitem = new Gtk.MenuItem.with_mnemonic (_("_Remove Account"));
             menuitem.activate.connect ((menuitem) => {
                 Gtk.TreeIter iter;



More information about the Xfce4-commits mailing list