[Xfce4-commits] <postler:master> Refactor AccountSetup based on an AccountWidget

Christian Dywan noreply at xfce.org
Wed Dec 15 11:22:02 CET 2010


Updating branch refs/heads/master
         to d27d2e3a1c59931db1d033ce72501b935a3855fa (commit)
       from d9d339e0d44cffa103d3aed0234663d4d6b3d9f5 (commit)

commit d27d2e3a1c59931db1d033ce72501b935a3855fa
Author: Christian Dywan <christian at twotoasts.de>
Date:   Wed Dec 15 01:13:33 2010 +0100

    Refactor AccountSetup based on an AccountWidget

 postler/postler-accountsetup.vala |   94 ++++++++++++++++++++++--------------
 1 files changed, 57 insertions(+), 37 deletions(-)

diff --git a/postler/postler-accountsetup.vala b/postler/postler-accountsetup.vala
index c70b20b..46be912 100644
--- a/postler/postler-accountsetup.vala
+++ b/postler/postler-accountsetup.vala
@@ -9,13 +9,13 @@
  See the file COPYING for the full license text.
 */
 
-public class Postler.AccountSetup : Gtk.Dialog {
+public class Postler.AccountWidget : Gtk.VBox {
     Gtk.SizeGroup sizegroup;
     Gtk.Box content_area;
     Gtk.Box advanced_area;
 
     Gtk.Entry realname;
-    Gtk.Entry address;
+    public Gtk.Entry address;
     Gtk.Entry password;
     Gtk.Entry organization;
 
@@ -26,13 +26,20 @@ public class Postler.AccountSetup : Gtk.Dialog {
 
     AccountInfo info;
 
-    public signal void done (AccountInfo info);
-
-    private AccountSetup (AccountInfo info) {
-        this.info = info;
+    public AccountWidget (AccountInfo? account_info=null) {
+        if (account_info == null) {
+            info = new AccountInfo ();
+            info.type = AccountType.IMAP;
+            string realname = Environment.get_real_name ();
+            if (realname == "Unknown")
+                realname = "";
+            info.realname = realname.locale_to_utf8 (-1, null, null, null);
+        } else {
+            info = account_info;
+        }
 
         sizegroup = new Gtk.SizeGroup (Gtk.SizeGroupMode.HORIZONTAL);
-        content_area = get_content_area () as Gtk.Box;
+        content_area = new Gtk.VBox (false, 0);
 
         realname = new Gtk.Entry ();
         realname.text = info.realname ?? "";
@@ -66,9 +73,7 @@ public class Postler.AccountSetup : Gtk.Dialog {
         sender.text = info.send ?? "";
         add_label_entry (_("Sending Server"), sender, true);
         content_area.show_all ();
-
-        add_button (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL);
-        response.connect (responded);
+        pack_end (content_area, true, true, 0);
     }
 
     void add_label_entry (string text, Gtk.Entry entry, bool advanced=false) {
@@ -82,43 +87,58 @@ public class Postler.AccountSetup : Gtk.Dialog {
         sizegroup.add_widget (label);
         hbox.pack_start (label, false, false, 4);
         entry.activate.connect ((entry) => {
-            responded (Gtk.ResponseType.APPLY); });
+            apply (); });
         hbox.pack_start (entry, false, false, 4);
     }
 
+    public void apply () {
+        if (info.name == null)
+            info.name = address.text;
+        info.realname = realname.text;
+        info.address = address.text;
+        info.password = password.text;
+
+        info.organization = organization.text != "" ? organization.text : null;
+        info.receive = receiver.text != "" ? receiver.text : null;
+        info.username = username.text != "" ? username.text : null;
+        info.prefix = prefix.text != "" ? prefix.text : null;
+        info.send = sender.text != "" ? sender.text : null;
+        done (info);
+    }
+
+    public signal void done (AccountInfo info);
+}
+
+public class Postler.AccountSetup : Gtk.Dialog {
+    AccountWidget widget;
+
+    public signal void done (AccountInfo info);
+
+    private AccountSetup (AccountInfo? info=null) {
+        widget = new AccountWidget (info);
+        widget.done.connect ((info) => {
+            destroy ();
+        });
+        (get_content_area () as Gtk.Box).pack_start (widget, true, true, 0);
+        widget.show ();
+        add_button (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL);
+        response.connect (responded);
+    }
+
     void responded (int response) {
-        if (response == Gtk.ResponseType.APPLY) {
-            if (info.name == null)
-                info.name = address.text;
-            info.realname = realname.text;
-            info.address = address.text;
-            info.password = password.text;
-
-            info.organization = organization.text != "" ? organization.text : null;
-            info.receive = receiver.text != "" ? receiver.text : null;
-            info.username = username.text != "" ? username.text : null;
-            info.prefix = prefix.text != "" ? prefix.text : null;
-            info.send = sender.text != "" ? sender.text : null;
-            done (info);
-        }
+        if (response == Gtk.ResponseType.APPLY)
+            widget.apply ();
         destroy ();
     }
 
     public static AccountSetup new_account () {
-        var info = new AccountInfo ();
-        info.type = AccountType.IMAP;
-        string realname = Environment.get_real_name ();
-        if (realname == "Unknown")
-            realname = "";
-        info.realname = realname.locale_to_utf8 (-1, null, null, null);
-
-        var setup = new AccountSetup (info);
+        var setup = new AccountSetup ();
         setup.add_button (_("_Create Account"), Gtk.ResponseType.APPLY);
         setup.set_default_response (Gtk.ResponseType.APPLY);
         setup.set_response_sensitive (Gtk.ResponseType.APPLY, false);
-        setup.address.changed.connect ((editable) => {
+        setup.widget.address.changed.connect ((editable) => {
              setup.set_response_sensitive (Gtk.ResponseType.APPLY,
-                 setup.address.text.chr (-1, '@') != null);
+                 setup.widget.address.text.chr (-1, '@') != null);
         });
         setup.show ();
         return setup;
@@ -128,9 +148,9 @@ public class Postler.AccountSetup : Gtk.Dialog {
         var setup = new AccountSetup (info);
         setup.add_button (_("_Save Account"), Gtk.ResponseType.APPLY);
         setup.set_default_response (Gtk.ResponseType.APPLY);
-        setup.address.changed.connect ((editable) => {
+        setup.widget.address.changed.connect ((editable) => {
              setup.set_response_sensitive (Gtk.ResponseType.APPLY,
-                 setup.address.text.chr (-1, '@') != null);
+                 setup.widget.address.text.chr (-1, '@') != null);
         });
         setup.show ();
         return setup;



More information about the Xfce4-commits mailing list