[Xfce4-commits] <postler:master> Ask whether to replace a saved search with the same name

Christian Dywan noreply at xfce.org
Thu Aug 4 03:20:06 CEST 2011


Updating branch refs/heads/master
         to f923f98e4e92736b1b61f364f4bc7c6cc76d4c18 (commit)
       from 8d82084836fd030b0c21ca57a7273e4376f2394a (commit)

commit f923f98e4e92736b1b61f364f4bc7c6cc76d4c18
Author: Christian Dywan <christian at twotoasts.de>
Date:   Wed Aug 3 23:22:49 2011 +0200

    Ask whether to replace a saved search with the same name
    
    Fixes: https://bugs.launchpad.net/postler/+bug/809655

 postler/postler-accounts.vala |    8 ++++++++
 postler/postler-bureau.vala   |   18 ++++++++++++++++++
 postler/postler-folders.vala  |   13 +++++++++++++
 3 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/postler/postler-accounts.vala b/postler/postler-accounts.vala
index 371c7b2..5247b03 100644
--- a/postler/postler-accounts.vala
+++ b/postler/postler-accounts.vala
@@ -430,6 +430,14 @@ public class Postler.Accounts : GLib.Object {
         delete_account (info);
     }
 
+    public AccountInfo? find (AccountInfo info) {
+        foreach (var account_info in infos) {
+            if (account_info.name == info.name)
+                return account_info;
+        }
+        return null;
+    }
+
     string? get_tool_configfile (string? send, AccountInfo info) throws GLib.FileError {
         unowned string cache_dir = Environment.get_user_cache_dir ();
         string cache_path = cache_dir + "/postler/mail";
diff --git a/postler/postler-bureau.vala b/postler/postler-bureau.vala
index c38372b..97e4ce7 100644
--- a/postler/postler-bureau.vala
+++ b/postler/postler-bureau.vala
@@ -217,6 +217,24 @@ public class Postler.Bureau : Gtk.Window {
         account_info.name = search.get_text ();
         account_info.type = AccountType.SEARCH;
         account_info.path = get_search_uri ();
+        AccountInfo? existing_info = accounts.find (account_info);
+        if (existing_info != null) {
+            var dialog = new Gtk.MessageDialog (this, 0,
+                Gtk.MessageType.WARNING, Gtk.ButtonsType.NONE,
+                _("A saved search with the name \"%s\" already exists."),
+                account_info.name);
+            dialog.format_secondary_text (
+                _("Do you want to replace the existing saved search?"));
+            dialog.add_buttons (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
+                _("_Replace"), Gtk.ResponseType.OK);
+            dialog.set_default_response (Gtk.ResponseType.CANCEL);
+            int response = dialog.run ();
+            dialog.destroy ();
+            if (response != Gtk.ResponseType.OK)
+                return;
+            accounts.remove_info (existing_info);
+        }
+
         accounts.add_info (account_info);
         search.set_text ("");
         folders.select_folder (account_info.path);
diff --git a/postler/postler-folders.vala b/postler/postler-folders.vala
index 7cf2daf..2b370c4 100644
--- a/postler/postler-folders.vala
+++ b/postler/postler-folders.vala
@@ -31,6 +31,19 @@ public class Postler.Folders : Gtk.Toolbar {
                 insert (search, get_n_items () - 1);
             }
         });
+        accounts.remove_info.connect_after ((info) => {
+            if (info.type != AccountType.SEARCH)
+                return;
+            foreach (var child in get_children ()) {
+                var button = child as Gtk.RadioToolButton;
+                if (button == null)
+                    continue;
+                if ((button.label_widget as Gtk.Label).label == info.name) {
+                    button.destroy ();
+                    break;
+                }
+            }
+        });
 
         populate ();
     }


More information about the Xfce4-commits mailing list