[moserial] Indent and format code



commit 183b985f583b187916d68071dbf46738a367b896
Author: Mictronics <github mictronics de>
Date:   Sat Apr 25 13:38:54 2020 +0200

    Indent and format code

 src/AutoScroll.vala            |   41 +-
 src/Config.vapi                |   19 +-
 src/DefaultPaths.vala          |   73 +-
 src/HexTextBuffer.vala         |  233 +++---
 src/InputParser.vala           |  221 +++--
 src/Main.vala                  |   72 +-
 src/MainWindow.vala            | 1751 ++++++++++++++++++++--------------------
 src/MoUtils.vala               |  162 ++--
 src/Preferences.vala           |  200 ++---
 src/PreferencesDialog.vala     |  255 +++---
 src/Profile.vala               |  176 ++--
 src/ReceiveChooserDialog.vala  |   72 +-
 src/ReceiveProgressDialog.vala |   67 +-
 src/RecordDialog.vala          |  117 ++-
 src/Rzwrapper.vala             |  420 +++++-----
 src/SendChooserDialog.vala     |   72 +-
 src/SendProgressDialog.vala    |   67 +-
 src/SerialConnection.vala      |  517 ++++++------
 src/SerialStreamRecorder.vala  |  156 ++--
 src/Settings.vala              |  242 +++---
 src/SettingsDialog.vala        |  409 +++++-----
 src/Szwrapper.vala             |  413 +++++-----
 src/XmodemFilenameDialog.vala  |   51 +-
 23 files changed, 2868 insertions(+), 2938 deletions(-)
---
diff --git a/src/AutoScroll.vala b/src/AutoScroll.vala
index 89bd648..6b3fc09 100644
--- a/src/AutoScroll.vala
+++ b/src/AutoScroll.vala
@@ -18,30 +18,29 @@
  */
 
 using Gtk;
-public class moserial.AutoScroll : GLib.Object
-{
-        public static void scroll (Gtk.Adjustment va)  {
-                va.value=va.upper-va.page_size;
-        }
+public class moserial.AutoScroll : GLib.Object {
+    public static void scroll (Gtk.Adjustment va) {
+        va.value = va.upper - va.page_size;
+    }
 
-        public static void doAutoScroll (Gtk.Adjustment va) {
-                if (va.value==va.upper-va.page_size) 
-                                va.changed.connect(scroll);
-                else
-                                va.changed.disconnect(scroll);        
-               }
+    public static void doAutoScroll (Gtk.Adjustment va) {
+        if (va.value == va.upper - va.page_size)
+            va.changed.connect (scroll);
+        else
+            va.changed.disconnect (scroll);
+    }
 
-        public static void setup(Gtk.Adjustment incomingAsciiVerticalAdjuster, Gtk.Adjustment 
incomingHexVerticalAdjuster, Gtk.Adjustment outgoingAsciiVerticalAdjuster, Gtk.Adjustment 
outgoingHexVerticalAdjuster) {
-                incomingAsciiVerticalAdjuster.changed.connect(scroll);
-                incomingAsciiVerticalAdjuster.value_changed.connect(doAutoScroll);
+    public static void setup (Gtk.Adjustment incomingAsciiVerticalAdjuster, Gtk.Adjustment 
incomingHexVerticalAdjuster, Gtk.Adjustment outgoingAsciiVerticalAdjuster, Gtk.Adjustment 
outgoingHexVerticalAdjuster) {
+        incomingAsciiVerticalAdjuster.changed.connect (scroll);
+        incomingAsciiVerticalAdjuster.value_changed.connect (doAutoScroll);
 
-                incomingHexVerticalAdjuster.changed.connect(scroll);
-                incomingHexVerticalAdjuster.value_changed.connect(doAutoScroll);
+        incomingHexVerticalAdjuster.changed.connect (scroll);
+        incomingHexVerticalAdjuster.value_changed.connect (doAutoScroll);
 
-                outgoingAsciiVerticalAdjuster.changed.connect(scroll);
-                outgoingAsciiVerticalAdjuster.value_changed.connect(doAutoScroll);
+        outgoingAsciiVerticalAdjuster.changed.connect (scroll);
+        outgoingAsciiVerticalAdjuster.value_changed.connect (doAutoScroll);
 
-                outgoingHexVerticalAdjuster.changed.connect(scroll);
-                outgoingHexVerticalAdjuster.value_changed.connect(doAutoScroll);
-        }
+        outgoingHexVerticalAdjuster.changed.connect (scroll);
+        outgoingHexVerticalAdjuster.value_changed.connect (doAutoScroll);
+    }
 }
diff --git a/src/Config.vapi b/src/Config.vapi
index db4846e..518be8b 100644
--- a/src/Config.vapi
+++ b/src/Config.vapi
@@ -1,11 +1,10 @@
-[CCode (cprefix="", lower_case_cprefix="", cheader_filename="config.h")]
-namespace Config
-{
-       public const string VERSION;
-       public const string UIROOT;
-       public const string GETTEXT_PACKAGE;
-       public const string PACKAGE_DATADIR;
-       public const string PACKAGE_LOCALEDIR;
-       public const string PACKAGE_NAME;
-       public const string PACKAGE_VERSION;
+[CCode (cprefix = "", lower_case_cprefix = "", cheader_filename = "config.h")]
+namespace Config {
+    public const string VERSION;
+    public const string UIROOT;
+    public const string GETTEXT_PACKAGE;
+    public const string PACKAGE_DATADIR;
+    public const string PACKAGE_LOCALEDIR;
+    public const string PACKAGE_NAME;
+    public const string PACKAGE_VERSION;
 }
diff --git a/src/DefaultPaths.vala b/src/DefaultPaths.vala
index 9c3cfb0..bf9f667 100644
--- a/src/DefaultPaths.vala
+++ b/src/DefaultPaths.vala
@@ -18,49 +18,48 @@
  */
 
 using GLib;
-public class DefaultPaths : GLib.Object
-{
-        public string? recordTo { get; set; }
-        public string? receiveTo {get; set; }
-        public string? sendFrom {get; set; }
+public class DefaultPaths : GLib.Object {
+    public string ? recordTo { get; set; }
+    public string ? receiveTo { get; set; }
+    public string ? sendFrom { get; set; }
 
-        public DefaultPaths (string? RecordTo, string? ReceiveTo, string? SendFrom) {
-                this.recordTo=RecordTo;
-                this.receiveTo=ReceiveTo;
-                this.sendFrom=SendFrom;
-        }
+    public DefaultPaths (string ? RecordTo, string ? ReceiveTo, string ? SendFrom) {
+        this.recordTo = RecordTo;
+        this.receiveTo = ReceiveTo;
+        this.sendFrom = SendFrom;
+    }
 
-        public void saveToProfile(Profile profile) {
-                if (recordTo != null)
-                        profile.keyFile.set_string("paths", "last_record_path", recordTo);
-                if (receiveTo != null)
-                        profile.keyFile.set_string("paths", "last_receive_path", receiveTo);
-                if (sendFrom != null)
-                        profile.keyFile.set_string("paths", "last_send_path", sendFrom);
-        }
+    public void saveToProfile (Profile profile) {
+        if (recordTo != null)
+            profile.keyFile.set_string ("paths", "last_record_path", recordTo);
+        if (receiveTo != null)
+            profile.keyFile.set_string ("paths", "last_receive_path", receiveTo);
+        if (sendFrom != null)
+            profile.keyFile.set_string ("paths", "last_send_path", sendFrom);
+    }
 
-        public static DefaultPaths loadFromProfile(Profile profile) {
-                string? RecordTo = null;
-                string? ReceiveTo = null;
-                string? SendFrom = null;
+    public static DefaultPaths loadFromProfile (Profile profile) {
+        string ? RecordTo = null;
+        string ? ReceiveTo = null;
+        string ? SendFrom = null;
 
-                RecordTo = getPath (profile, "paths", "last_record_path");
-                ReceiveTo = getPath (profile, "paths", "last_receive_path");
-                SendFrom = getPath (profile, "paths", "last_send_path");
+        RecordTo = getPath (profile, "paths", "last_record_path");
+        ReceiveTo = getPath (profile, "paths", "last_receive_path");
+        SendFrom = getPath (profile, "paths", "last_send_path");
 
-                return new DefaultPaths (RecordTo, ReceiveTo, SendFrom);
-        }
+        return new DefaultPaths (RecordTo, ReceiveTo, SendFrom);
+    }
 
-        public static string? getPath (Profile profile, string group, string key) {
-                string? path = null;
-                try {
-                        path = profile.keyFile.get_string(group, key);
-                        if (!MoUtils.fileExists(path))
-                                return null;
-                } catch (GLib.KeyFileError e) {
-                        //stdout.printf("%s\n", e.message);
-                }
-                return path;
+    public static string ? getPath (Profile profile, string group, string key) {
+        string ? path = null;
+        try {
+            path = profile.keyFile.get_string (group, key);
+            if (!MoUtils.fileExists (path))
+                return null;
+        } catch (GLib.KeyFileError e) {
+            // stdout.printf("%s\n", e.message);
         }
+        return path;
+    }
 }
 
diff --git a/src/HexTextBuffer.vala b/src/HexTextBuffer.vala
index 8ba4f6e..d73326d 100644
--- a/src/HexTextBuffer.vala
+++ b/src/HexTextBuffer.vala
@@ -20,130 +20,129 @@
 using Gtk;
 using GLib;
 
-public class moserial.HexTextBuffer : TextBuffer
-{
-       private TextMark nextHexMark;
-        private TextMark nextCharMark;
-        private TextTag addressTag;
-        private int hexBytes;
-        construct {
-               setup();
-               addressTag = this.create_tag("hex_address", "foreground", "#2020ff", null);
-               
-        }
-        public void applyPreferences(Preferences preferences) {
-               addressTag.foreground=preferences.highlightColor;
-        }
-        public void clear() {
-               this.delete_mark(nextHexMark);
-               this.delete_mark(nextCharMark);
-               this.set_text("", 0);
-               setup();
-        }
-        private void setup() {
-               TextIter nextHexIter;
-               TextIter nextCharIter;
-               this.get_end_iter(out nextHexIter);
-               nextHexMark = new TextMark("nextHex", true);
-               this.add_mark(nextHexMark, nextHexIter);
-               nextCharIter=nextHexIter;
-               nextCharMark = new TextMark("nextChar", true);
-               this.add_mark(nextCharMark, nextCharIter);
-               hexBytes=0;
-        }
-        public void add(uchar data) {
-               TextIter nextHexIter;
-               TextIter nextCharIter;
-               string incomingHexBuffer = "";
+public class moserial.HexTextBuffer : TextBuffer {
+    private TextMark nextHexMark;
+    private TextMark nextCharMark;
+    private TextTag addressTag;
+    private int hexBytes;
+    construct {
+        setup ();
+        addressTag = this.create_tag ("hex_address", "foreground", "#2020ff", null);
+    }
+    public void applyPreferences (Preferences preferences) {
+        addressTag.foreground = preferences.highlightColor;
+    }
+
+    public void clear () {
+        this.delete_mark (nextHexMark);
+        this.delete_mark (nextCharMark);
+        this.set_text ("", 0);
+        setup ();
+    }
 
-               // Every insert or delete operation invalidates TextIters and they must be recovered.
+    private void setup () {
+        TextIter nextHexIter;
+        TextIter nextCharIter;
+        this.get_end_iter (out nextHexIter);
+        nextHexMark = new TextMark ("nextHex", true);
+        this.add_mark (nextHexMark, nextHexIter);
+        nextCharIter = nextHexIter;
+        nextCharMark = new TextMark ("nextChar", true);
+        this.add_mark (nextCharMark, nextCharIter);
+        hexBytes = 0;
+    }
 
-               if((hexBytes % 16)==0 ){
-                               // Mark start
-                                TextIter startIter;
-                               this.get_iter_at_mark(out nextCharIter, nextCharMark);
-                               TextMark startMark = new TextMark("startMark", true);
-                               this.add_mark(startMark, nextCharIter);
+    public void add (uchar data) {
+        TextIter nextHexIter;
+        TextIter nextCharIter;
+        string incomingHexBuffer = "";
 
-                               // Insert offset info (hexBytes)
-                               this.insert(ref nextCharIter, "\n%08x".printf(hexBytes), 9);
-                               this.get_end_iter (out nextCharIter);   
+        // Every insert or delete operation invalidates TextIters and they must be recovered.
 
-                               // Format offset info
-                               this.get_iter_at_mark(out startIter, startMark);
-                               this.apply_tag_by_name("hex_address", startIter, nextCharIter);
-                               this.delete_mark(startMark);
+        if ((hexBytes % 16) == 0) {
+            // Mark start
+            TextIter startIter;
+            this.get_iter_at_mark (out nextCharIter, nextCharMark);
+            TextMark startMark = new TextMark ("startMark", true);
+            this.add_mark (startMark, nextCharIter);
 
-                               // Blank space
-                               this.insert(ref nextCharIter, " ", 1);
-                               this.get_end_iter (out nextCharIter);
+            // Insert offset info (hexBytes)
+            this.insert (ref nextCharIter, "\n%08x".printf (hexBytes), 9);
+            this.get_end_iter (out nextCharIter);
 
-                               // Save current position in nextHexMark
-                               this.delete_mark(nextHexMark);
-                               nextHexIter = nextCharIter;
-                               nextHexMark = new TextMark("nextHex", true);
-                               this.add_mark(nextHexMark, nextHexIter);
+            // Format offset info
+            this.get_iter_at_mark (out startIter, startMark);
+            this.apply_tag_by_name ("hex_address", startIter, nextCharIter);
+            this.delete_mark (startMark);
+
+            // Blank space
+            this.insert (ref nextCharIter, " ", 1);
+            this.get_end_iter (out nextCharIter);
+
+            // Save current position in nextHexMark
+            this.delete_mark (nextHexMark);
+            nextHexIter = nextCharIter;
+            nextHexMark = new TextMark ("nextHex", true);
+            this.add_mark (nextHexMark, nextHexIter);
+
+            // Put 51 blank spaces
+            this.insert (ref nextCharIter, "                                                   ", 51);
+            this.get_end_iter (out nextCharIter);
+            // Save current nextCharMark
+            this.delete_mark (nextCharMark);
+            nextCharMark = new TextMark ("nextChar", true);
+            this.add_mark (nextCharMark, nextCharIter);
+        } else if ((hexBytes % 8) == 0) {
+            // Every 8 characters put a separation of 2 spaces
+            this.get_iter_at_mark (out nextHexIter, nextHexMark);
+            this.insert (ref nextHexIter, "  ", 2);
+            this.get_iter_at_mark (out nextHexIter, nextHexMark);
+            nextHexIter.forward_chars (2);
+            // Save current nextHexMark
+            this.delete_mark (nextHexMark);
+            nextHexMark = new TextMark ("nextHex", true);
+            this.add_mark (nextHexMark, nextHexIter);
+            // Remove space to align chars
+            TextIter tempIter;
+            tempIter = nextHexIter;
+            tempIter.forward_chars (2);
+            this.delete (ref nextHexIter, ref tempIter);
+        }
+        // Put hex data at nextHexMark
+        this.get_iter_at_mark (out nextHexIter, nextHexMark);
+        incomingHexBuffer += "%02X ".printf (data);
+        this.insert (ref nextHexIter, incomingHexBuffer, (int) incomingHexBuffer.length);
 
-                               // Put 51 blank spaces
-                               this.insert(ref nextCharIter, "                                               
    ", 51);
-                               this.get_end_iter (out nextCharIter);
-                               // Save current nextCharMark
-                               this.delete_mark(nextCharMark);
-                               nextCharMark = new TextMark("nextChar", true);
-                               this.add_mark(nextCharMark, nextCharIter);
-                       }
-                        else if((hexBytes % 8)==0) {
-                               // Every 8 characters put a separation of 2 spaces
-                               this.get_iter_at_mark(out nextHexIter, nextHexMark);
-                               this.insert(ref nextHexIter, "  ", 2);
-                               this.get_iter_at_mark(out nextHexIter, nextHexMark);
-                               nextHexIter.forward_chars(2);
-                               // Save current nextHexMark
-                               this.delete_mark(nextHexMark);
-                               nextHexMark = new TextMark("nextHex", true);
-                               this.add_mark(nextHexMark, nextHexIter);
-                               // Remove space to align chars
-                               TextIter tempIter;
-                               tempIter = nextHexIter;
-                               tempIter.forward_chars(2);
-                               this.delete(ref nextHexIter, ref tempIter);
-                       }
-                       // Put hex data at nextHexMark
-                       this.get_iter_at_mark(out nextHexIter, nextHexMark);
-                        incomingHexBuffer += "%02X ".printf(data);
-                       this.insert(ref nextHexIter, incomingHexBuffer, (int)incomingHexBuffer.length);
+        this.get_iter_at_mark (out nextHexIter, nextHexMark);
+        nextHexIter.forward_chars (incomingHexBuffer.length);
+        // Save current nextHexMark
+        this.delete_mark (nextHexMark);
+        nextHexMark = new TextMark ("nextHex", true);
+        this.add_mark (nextHexMark, nextHexIter);
+        // Remove space to align chars
+        TextIter tempIter;
+        tempIter = nextHexIter;
+        tempIter.forward_chars (3);
+        this.delete (ref nextHexIter, ref tempIter);
+        incomingHexBuffer = "";
+        hexBytes++;
 
-                        this.get_iter_at_mark(out nextHexIter, nextHexMark);
-                        nextHexIter.forward_chars(incomingHexBuffer.length);
-                        // Save current nextHexMark
-                        this.delete_mark(nextHexMark);
-                        nextHexMark = new TextMark("nextHex", true);
-                        this.add_mark(nextHexMark, nextHexIter);
-                        // Remove space to align chars
-                        TextIter tempIter;
-                        tempIter = nextHexIter;
-                        tempIter.forward_chars(3);
-                       this.delete(ref nextHexIter, ref tempIter);
-                        incomingHexBuffer = "";
-                        hexBytes++;
-                        
-                        // Place character at nextCharMark
-                        this.get_iter_at_mark(out nextCharIter, nextCharMark);
-                        unichar c = "%c".printf(data).get_char();
-                        string s = "%c".printf(data);
-                        if (s.validate() && c.isprint()) {
-                               this.insert(ref nextCharIter, s, (int)s.length);
-                               this.get_iter_at_mark(out nextCharIter, nextCharMark);
-                               nextCharIter.forward_chars(s.length);
-                       }
-                        else {
-                               this.insert(ref nextCharIter, ".", 1);
-                               this.get_iter_at_mark(out nextCharIter, nextCharMark);
-                               nextCharIter.forward_chars(1);
-                       }
-                       // Save current nextCharMark
-                       this.delete_mark(nextCharMark);
-                        nextCharMark = new TextMark("nextChar", true);
-                        this.add_mark(nextCharMark, nextCharIter);
+        // Place character at nextCharMark
+        this.get_iter_at_mark (out nextCharIter, nextCharMark);
+        unichar c = "%c".printf (data).get_char ();
+        string s = "%c".printf (data);
+        if (s.validate () && c.isprint ()) {
+            this.insert (ref nextCharIter, s, (int) s.length);
+            this.get_iter_at_mark (out nextCharIter, nextCharMark);
+            nextCharIter.forward_chars (s.length);
+        } else {
+            this.insert (ref nextCharIter, ".", 1);
+            this.get_iter_at_mark (out nextCharIter, nextCharMark);
+            nextCharIter.forward_chars (1);
         }
+        // Save current nextCharMark
+        this.delete_mark (nextCharMark);
+        nextCharMark = new TextMark ("nextChar", true);
+        this.add_mark (nextCharMark, nextCharIter);
+    }
 }
diff --git a/src/InputParser.vala b/src/InputParser.vala
index fe5dfb6..f12884e 100644
--- a/src/InputParser.vala
+++ b/src/InputParser.vala
@@ -18,122 +18,121 @@
  */
 
 public errordomain HexParseError {
-       INVALID_INPUT;
+    INVALID_INPUT;
 }
-public class InputParser : GLib.Object
-{
-       /* We need this due to some strange Vala bug stopping us using string.replace in two different 
classes 
-          should look into it and possibly file a bug */
-       public static string statusReplace(string oldString) { 
-               return oldString.replace("\\r", "\\n");
-       }
-       
-       public static uchar[] parseHex(string s) throws HexParseError {
-               
-               long len = s.length;
-               uchar[] r=new uchar[(len+1)/2];
-               for(int x=0; x<(len+1)/2; x++) {
-                       unichar c;
-                       int i;
-                       int temp;
+public class InputParser : GLib.Object {
+    /* We need this due to some strange Vala bug stopping us using string.replace in two different classes
+       should look into it and possibly file a bug */
+    public static string statusReplace (string oldString) {
+        return oldString.replace ("\\r", "\\n");
+    }
 
-                       c=s.get_char();
+    public static uchar[] parseHex (string s) throws HexParseError {
 
-                       i=xtoi(c);
-                       if(i>15)
-                               throw new HexParseError.INVALID_INPUT(_("Invalid Input"));
+        long len = s.length;
+        uchar[] r = new uchar[(len + 1) / 2];
+        for (int x = 0; x < (len + 1) / 2; x++) {
+            unichar c;
+            int i;
+            int temp;
 
-                       if(len>1) {
-                               i*=16;
+            c = s.get_char ();
 
-                               s=s.next_char();
-                               c=s.get_char();
+            i = xtoi (c);
+            if (i > 15)
+                throw new HexParseError.INVALID_INPUT (_("Invalid Input"));
 
-                               temp=xtoi(c);
-                               if(temp>15)
-                                       throw new HexParseError.INVALID_INPUT(_("Invalid Input"));
-                               i+=temp;
-                       }
+            if (len > 1) {
+                i *= 16;
 
-                       s=s.next_char();
-                       r[x]=(uchar)i;
-               }
-               
-               return r;
-       }
-       
-       // There should be bindings to something in vala that can do this but there dosen't seem to be yet 
2009-01-31
-       private static uchar xtoi(unichar c) {
-               uchar i=16;     // an invalid positive result
-               switch(c){
-                       case '0':
-                       i=0;
-                       break;
-                       case '1':
-                       i=1;
-                       break;
-                       case '2':
-                       i=2;
-                       break;
-                       case '3':
-                       i=3;
-                       break;
-                       case '4':
-                       i=4;
-                       break;
-                       case '5':
-                       i=5;
-                       break;
-                       case '6':
-                       i=6;
-                       break;
-                       case '7':
-                       i=7;
-                       break;
-                       case '8':
-                       i=8;
-                       break;
-                       case '9':
-                       i=9;
-                       break;
-                       case 'a':
-                       i=10;
-                       break;
-                       case 'b':
-                       i=11;
-                       break;
-                       case 'c':
-                       i=12;
-                       break;
-                       case 'd':
-                       i=13;
-                       break;
-                       case 'e':
-                       i=14;
-                       break;
-                       case 'f':
-                       i=15;
-                       break;
-                       
-                       case 'A':
-                       i=10;
-                       break;
-                       case 'B':
-                       i=11;
-                       break;
-                       case 'C':
-                       i=12;
-                       break;
-                       case 'D':
-                       i=13;
-                       break;
-                       case 'E':
-                       i=14;
-                       break;
-                       case 'F':
-                       i=15;
-                       break;
-               }
-               return i;                               
-       }
+                s = s.next_char ();
+                c = s.get_char ();
+
+                temp = xtoi (c);
+                if (temp > 15)
+                    throw new HexParseError.INVALID_INPUT (_("Invalid Input"));
+                i += temp;
+            }
+
+            s = s.next_char ();
+            r[x] = (uchar) i;
+        }
+
+        return r;
+    }
+
+    // There should be bindings to something in vala that can do this but there dosen't seem to be yet 
2009-01-31
+    private static uchar xtoi (unichar c) {
+        uchar i = 16;           // an invalid positive result
+        switch (c) {
+            case '0':
+                i = 0;
+                break;
+            case '1':
+                i = 1;
+                break;
+            case '2':
+                i = 2;
+                break;
+            case '3':
+                i = 3;
+                break;
+            case '4':
+                i = 4;
+                break;
+            case '5':
+                i = 5;
+                break;
+            case '6':
+                i = 6;
+                break;
+            case '7':
+                i = 7;
+                break;
+            case '8':
+                i = 8;
+                break;
+            case '9':
+                i = 9;
+                break;
+            case 'a':
+                i = 10;
+                break;
+            case 'b':
+                i = 11;
+                break;
+            case 'c':
+                i = 12;
+                break;
+            case 'd':
+                i = 13;
+                break;
+            case 'e':
+                i = 14;
+                break;
+            case 'f':
+                i = 15;
+                break;
+
+            case 'A':
+                i = 10;
+                break;
+            case 'B':
+                i = 11;
+                break;
+            case 'C':
+                i = 12;
+                break;
+            case 'D':
+                i = 13;
+                break;
+            case 'E':
+                i = 14;
+                break;
+            case 'F':
+                i = 15;
+                break;
+        }
+        return i;
+    }
 }
diff --git a/src/Main.vala b/src/Main.vala
index 39e7ca6..c532acb 100644
--- a/src/Main.vala
+++ b/src/Main.vala
@@ -19,44 +19,44 @@
 
 using Gtk;
 
-class moserial.Main : GLib.Object
-{
-        static string profileFilename;
-        const OptionEntry[] options = {
-                { "profile", 'p', 0, OptionArg.FILENAME, out profileFilename, N_("Profile file to load"), 
"foo.conf" },
-                { null }
-        };
-        public void run() {
+class moserial.Main : GLib.Object {
+    static string profileFilename;
+    const OptionEntry[] options = {
+        { "profile", 'p', 0, OptionArg.FILENAME, out profileFilename, N_ ("Profile file to load"), 
"foo.conf" },
+        { null }
+    };
+    public void run () {
 
-                moserial.MainWindow mainWindow;
-                if(!(profileFilename==null) && (!GLib.Path.is_absolute(profileFilename)))
-                               profileFilename=GLib.Path.build_filename(GLib.Environment.get_current_dir(), 
profileFilename);
-                mainWindow = new moserial.MainWindow(profileFilename);
-                mainWindow.showWindow();
-        }
-        public static int main (string[] args) {
-                OptionContext context;
-                Gtk.init (ref args);
+        moserial.MainWindow mainWindow;
+        if (!(profileFilename == null) && (!GLib.Path.is_absolute (profileFilename)))
+            profileFilename = GLib.Path.build_filename (GLib.Environment.get_current_dir (), 
profileFilename);
+        mainWindow = new moserial.MainWindow (profileFilename);
+        mainWindow.showWindow ();
+    }
+
+    public static int main (string[] args) {
+        OptionContext context;
+        Gtk.init (ref args);
 
-                Intl.bindtextdomain(Config.GETTEXT_PACKAGE, Config.PACKAGE_LOCALEDIR);
-                Intl.bind_textdomain_codeset(Config.GETTEXT_PACKAGE, "UTF-8");
-                Intl.textdomain(Config.GETTEXT_PACKAGE);
+        Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.PACKAGE_LOCALEDIR);
+        Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
+        Intl.textdomain (Config.GETTEXT_PACKAGE);
 
-                context = new OptionContext(_("- moserial serial terminal"));
-                context.add_main_entries (options, null);
-                context.add_group (Gtk.get_option_group(true));
-                try {
-                        if (!context.parse (ref args)) {
-                                stdout.printf (_("Run '%s --help' to see a full list of available command 
line options.\n"), args[0]);
-                        } else {
-                                Main app = new Main();
-                                app.run();
-                                Gtk.main ();
-                        }
-                } catch (GLib.OptionError e) {
-                        stdout.printf ("%s\n", e.message);
-                        stdout.printf (_("Run '%s --help' to see a full list of available command line 
options.\n"), args[0]);
-                }
-                return 0;
+        context = new OptionContext (_("- moserial serial terminal"));
+        context.add_main_entries (options, null);
+        context.add_group (Gtk.get_option_group (true));
+        try {
+            if (!context.parse (ref args)) {
+                stdout.printf (_("Run '%s --help' to see a full list of available command line options.\n"), 
args[0]);
+            } else {
+                Main app = new Main ();
+                app.run ();
+                Gtk.main ();
+            }
+        } catch (GLib.OptionError e) {
+            stdout.printf ("%s\n", e.message);
+            stdout.printf (_("Run '%s --help' to see a full list of available command line options.\n"), 
args[0]);
         }
+        return 0;
+    }
 }
diff --git a/src/MainWindow.vala b/src/MainWindow.vala
index 13dd6c3..05873d3 100644
--- a/src/MainWindow.vala
+++ b/src/MainWindow.vala
@@ -20,924 +20,913 @@
 using Gtk;
 using Gdk;
 
-public class moserial.MainWindow : Gtk.Window //Have to extend Gtk.Winow to get signals working. Why?
+public class moserial.MainWindow : Gtk.Window // Have to extend Gtk.Winow to get signals working. Why?
 {
-        const string[] authors = {
-                "Michael J. Chudobiak <mjc svn gnome org>",
-                "marlodavampire",
-                null
-        };
-        const string translators = N_("translator-credits");
-        const string[] license = {
-                N_("moserial is free software: you can redistribute it and/or modify it under the terms of 
the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, 
or (at your option) any later version.\n"),
-                N_("moserial is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
General Public License for more details.\n"),
-                N_("You should have received a copy of the GNU General Public License along with this 
program.  If not, see <http://www.gnu.org/licenses/>.")
-        };
-
-        private Gtk.Window gtkWindow;
-        private SettingsDialog settingsDialog;
-        private ToolButton settingsButton;
-        private ToggleToolButton recordButton;
-        private Settings currentSettings;
-        private Preferences currentPreferences;
-       private DefaultPaths currentPaths;
-        private Statusbar statusbar;
-        private Statusbar bytecountbar;
-        private uint statusbarContext;
-        private uint bytecountbarContext;
-        private ToolButton send;
-        private SendProgressDialog sendProgressDialog;
-        private SendChooserDialog sendChooserDialog;
-        private ToolButton receive;
-        private ReceiveProgressDialog receiveProgressDialog;
-        private ReceiveChooserDialog receiveChooserDialog;
-        private RecordDialog recordDialog;
-        private PreferencesDialog preferencesDialog;
-        private SerialConnection serialConnection = new SerialConnection();
-        private TextView incomingHexTextView;
-        private TextView incomingAsciiTextView;
-        private TextView outgoingHexTextView;
-        private TextView outgoingAsciiTextView;
-
-        private ComboBox inputModeCombo;
-        private enum inputModeValues { ASCII, HEX }
-        private const string[] inputModeStrings = { GLib.N_("ASCII"), GLib.N_("HEX") };
-
-        private ComboBox lineEndModeCombo;
-
-        private ToggleToolButton connectButton;
-        private Label disconnectLabel;
-        private Label connectLabel;
-        private Label recordLabel;
-        private Label stopRecordingLabel;
-        private Paned paned;
-        private Notebook incoming_notebook;
-        private Notebook outgoing_notebook;
-        private HexTextBuffer incomingHexTextBuffer;
-        private HexTextBuffer outgoingHexTextBuffer;
-        private TextBuffer incomingAsciiTextBuffer;
-        private TextTag echoTag;
-        private TextBuffer outgoingAsciiTextBuffer;
-        private TextMark echoStartMark;
-        private XmodemFilenameDialog xmodemFilenameDialog;
-        private Gtk.Entry entry;
-        private Button sendButton;
-        private SerialStreamRecorder streamRecorder = new SerialStreamRecorder();
-        private bool recordDataReceived=false;
-        private uint recordTimeoutID=0;
-        private Rzwrapper rz;
-        private Szwrapper? sz;
-        private Profile profile;
-        public string? startupProfileFilename{get; construct; }
-        private string profileFilename=null;
-        private bool profileChanged=false;
-        private Gtk.ImageMenuItem cutMenuItem;
-        private Gtk.ImageMenuItem copyMenuItem;
-       private Adjustment va1;
-       private Adjustment va2;
-       private Adjustment va3;
-       private Adjustment va4;
-       private Gtk.AccelGroup ag;
-
-       private const string recentGroup = "moserial-configs";
-       private Gtk.RecentData recentData;
-
-        public MainWindow(string? profileFilename) {
-               GLib.Object(startupProfileFilename: profileFilename);
-        }
-        construct {
-                var builder = new Gtk.Builder.from_resource(Config.UIROOT + "mainwindow.ui");
-
-                //setup window
-                gtkWindow = (Gtk.Window)builder.get_object("window");
-               ag = (Gtk.AccelGroup)builder.get_object("accelgroup1");
-               gtkWindow.add_accel_group (ag);
-               
-                gtkWindow.destroy.connect(quitSave);
-                gtkWindow.delete_event.connect(deleteSaveSize);
-               gtkWindow.key_press_event.connect(keyPress);
-
-               //load defaults
-                profile=new Profile();
-                profile.load(null, gtkWindow);
-               currentSettings=Settings.loadFromProfile(profile);
-                int width = profile.getWindowWidth();
-                int height = profile.getWindowHeight();
-                int panedPosition = profile.getWindowPanedPosition();
-                if ((width>0) && (height>0))
-                        gtkWindow.resize (width, height);
-
-                //setup paned
-                paned = (Paned)builder.get_object("vpaned");
-                if (panedPosition>=-1)
-                        paned.set_position(panedPosition);
-               else
-                       paned.set_position(-1);
-
-                //setup menu items
-                Gtk.ImageMenuItem quit = (Gtk.ImageMenuItem)builder.get_object("menubar_quit");
-                quit.activate.connect(quitSizeSave);
-                Gtk.ImageMenuItem saveAs = (Gtk.ImageMenuItem)builder.get_object("menubar_save_settings_as");
-                saveAs.activate.connect(saveProfileAs);
-                Gtk.ImageMenuItem save = (Gtk.ImageMenuItem)builder.get_object("menubar_save_settings");
-                save.activate.connect(saveProfile);
-                Gtk.ImageMenuItem open = (Gtk.ImageMenuItem)builder.get_object("menubar_open_settings");
-                open.activate.connect(loadProfile);
-                copyMenuItem = (Gtk.ImageMenuItem)builder.get_object("menubar_copy");
-               copyMenuItem.activate.connect(this.copy);
-               Gtk.MenuItem editMenuItem = (Gtk.MenuItem)builder.get_object("menubar_edit");
-               editMenuItem.activate.connect(this.editMenu);
-               cutMenuItem = (Gtk.ImageMenuItem)builder.get_object("menubar_cut");
-               copyMenuItem.set_sensitive(false);
-               cutMenuItem.set_sensitive(false);
-               cutMenuItem.activate.connect(this.cut);
-               Gtk.ImageMenuItem pasteMenuItem = (Gtk.ImageMenuItem)builder.get_object("menubar_paste");
-               pasteMenuItem.activate.connect(this.paste);
-               Gtk.ImageMenuItem clearMenuItem = (Gtk.ImageMenuItem)builder.get_object("menubar_clear");
-               clearMenuItem.activate.connect(this.clear);
-               
-                //setup the Port Settings Dialog
-                settingsDialog = new SettingsDialog();
-                settingsDialog.updateSettings.connect(this.updateSettings);
-                settingsButton = (ToolButton)builder.get_object("toolbar_settings");
-                settingsButton.clicked.connect(this.showSettingsDialog);
-               settingsButton.set_tooltip_text (_("Port configuration"));
-
-                //setup the Help button
-                ToolButton helpButton = (ToolButton)builder.get_object("toolbar_help");
-                helpButton.clicked.connect(showHelpButton);
-               helpButton.set_tooltip_text (_("Read the manual"));
-
-                //setup the statusbar
-                statusbar = (Statusbar)builder.get_object("statusbar");
-                statusbarContext = statusbar.get_context_id("moserial port status");
-                statusbar.push(statusbarContext, currentSettings.getStatusbarString(false));
-
-                //setup the byte count bar
-                bytecountbar = (Statusbar)builder.get_object("bytecountbar");
-                bytecountbarContext = statusbar.get_context_id("moserial byte counts");
-                bytecountbar.push(bytecountbarContext, _("TX: 0, RX: 0"));
-
-                //setup the about dialog
-                Gtk.ImageMenuItem about = (Gtk.ImageMenuItem)builder.get_object("menubar_about");
-                about.activate.connect(showAboutDialog);
-
-                //setup send
-                sendProgressDialog = new SendProgressDialog();
-                sendChooserDialog = new SendChooserDialog();
-                send = (ToolButton)builder.get_object("toolbar_send");
-                send.clicked.connect(doSendChooser);
-               send.set_tooltip_text (_("Send a file"));
-                sendChooserDialog.startTransfer.connect(this.doSend);
-                sz = new Szwrapper(Szwrapper.Protocol.NULL, null, null);
-
-                //setup receive
-                receiveProgressDialog = new ReceiveProgressDialog();
-                receiveChooserDialog = new ReceiveChooserDialog();
-                receive = (ToolButton)builder.get_object("toolbar_receive");
-                receive.clicked.connect(doReceiveChooser);
-               receive.set_tooltip_text (_("Receive a file"));
-                receiveChooserDialog.startTransfer.connect(this.doReceive);
-                xmodemFilenameDialog = new XmodemFilenameDialog();
-                rz = new Rzwrapper(Rzwrapper.Protocol.NULL, null, null, null);
-
-
-                //setup recording
-                recordDialog = new RecordDialog();
-                recordButton = (ToggleToolButton)builder.get_object("toolbar_logging");
-                recordButton.toggled.connect(this.record);
-                recordButton.set_tooltip_text (_("Record sent and/or received data"));
-                recordDialog.stopRecording.connect(this.stopRecording);
-                recordDialog.startRecording.connect(this.startRecording);
-                recordLabel = (Label)builder.get_object("record_label");
-                stopRecordingLabel = (Label)builder.get_object("stop_recording_label");
-
-                //setup preferences
-                preferencesDialog = new PreferencesDialog();
-                preferencesDialog.updatePreferences.connect(this.updatePreferences);
-                ToolButton preferences = (ToolButton)builder.get_object("toolbar_preferences");
-                preferences.clicked.connect(this.showPreferencesDialog);
-               preferences.set_tooltip_text (_("Other preferences"));
-
-                //setup connectbutton
-                connectButton = (ToggleToolButton)builder.get_object("toolbar_connect");
-                connectButton.toggled.connect(this.connectButtonClick);
-               connectButton.set_tooltip_text (_("Open/close port"));
-                disconnectLabel = (Label)builder.get_object("disconnect_label");
-                connectLabel = (Label)builder.get_object("connect_label");
-
-                //setup help
-                Gtk.ImageMenuItem contents = (Gtk.ImageMenuItem)builder.get_object("menubar_contents");
-                contents.activate.connect(showHelpAction);
-
-                //setup incoming notebook
-                incoming_notebook = (Notebook)builder.get_object("incoming_notebook");
-
-                //setup outgoing notebook
-                outgoing_notebook = (Notebook)builder.get_object("outgoing_notebook");
-
-                //setup textBuffers;
-                incomingHexTextBuffer = new HexTextBuffer();
-                incomingAsciiTextBuffer = new TextBuffer(new TextTagTable());
-                outgoingHexTextBuffer = new HexTextBuffer();
-                outgoingAsciiTextBuffer = new TextBuffer(new TextTagTable());
-
-                echoTag = incomingAsciiTextBuffer.create_tag("echo", null);
-
-                incomingHexTextView = (TextView)builder.get_object("incoming_hex_textview");
-                incomingHexTextView.set_buffer(incomingHexTextBuffer);
-
-                incomingAsciiTextView = (TextView)builder.get_object("incoming_ascii_textview");
-                incomingAsciiTextView.set_buffer(incomingAsciiTextBuffer);
-
-                outgoingHexTextView = (TextView)builder.get_object("outgoing_hex_textview");
-                outgoingHexTextView.set_buffer(outgoingHexTextBuffer);
-
-                outgoingAsciiTextView = (TextView)builder.get_object("outgoing_ascii_textview");
-                outgoingAsciiTextView.set_buffer(outgoingAsciiTextBuffer);
-                
-                //setup scrolling
-                ScrolledWindow incomingAsciiScrolledWindow = 
(ScrolledWindow)builder.get_object("incoming_ascii_scrolledwindow");
-                va1 = incomingAsciiScrolledWindow.get_vadjustment();
-                       ScrolledWindow incomingHexScrolledWindow = 
(ScrolledWindow)builder.get_object("incoming_hex_scrolledwindow");
-                va2 = incomingHexScrolledWindow.get_vadjustment();
-                ScrolledWindow outgoingAsciiScrolledWindow = 
(ScrolledWindow)builder.get_object("outgoing_ascii_scrolledwindow");
-                va3 = outgoingAsciiScrolledWindow.get_vadjustment();
-                ScrolledWindow outgoingHexScrolledWindow = 
(ScrolledWindow)builder.get_object("outgoing_hex_scrolledwindow");
-                va4 = outgoingHexScrolledWindow.get_vadjustment();
-               AutoScroll.setup(va1, va2, va3, va4);
-               
-                //setup entry
-                sendButton = (Button)builder.get_object("send");
-                sendButton.clicked.connect(sendString);
-               sendButton.set_tooltip_text (_("Send the outgoing data now."));
-                entry = (Gtk.Entry)builder.get_object("entry");
-                entry.activate.connect(sendString);
-               entry.set_tooltip_text (_("Type outgoing data here. Press Enter or Send to send it."));
-
-                inputModeCombo = (ComboBox)builder.get_object("input_mode");
-               MoUtils.populateComboBox (inputModeCombo, inputModeStrings);
-                inputModeCombo.set_active(inputModeValues.ASCII);
-               inputModeCombo.changed.connect(inputModeChanged);
-
-                lineEndModeCombo = (ComboBox)builder.get_object("termination_mode");
-               MoUtils.populateComboBox (lineEndModeCombo, serialConnection.LineEndStrings);
-                lineEndModeCombo.set_active(SerialConnection.LineEnd.CRLF);
-                
-                //setup recent chooser
-               recentData.groups = {recentGroup};
-               recentData.app_name = GLib.Environment.get_application_name();
-               recentData.app_exec = GLib.Environment.get_prgname() + " %u";
-               recentData.mime_type = "text/plain";
-
-                RecentManager recentManager = RecentManager.get_default ();
-                RecentChooserMenu recentChooserMenu = new Gtk.RecentChooserMenu.for_manager(recentManager);
-                recentChooserMenu.item_activated.connect(recentItemOpen);
-                RecentFilter filter = new RecentFilter();
-                filter.add_group(recentGroup);
-                recentChooserMenu.add_filter(filter);
-                recentChooserMenu.set_show_numbers(true);
-               recentChooserMenu.show_not_found = false;
-                Gtk.MenuItem recentFileItem = (Gtk.MenuItem)builder.get_object("menubar_open_recent");
-                       recentFileItem.set_submenu(recentChooserMenu);
-
-                //load and apply preferences
-                currentPreferences = Preferences.loadFromProfile(profile);
-                       updatePreferences(null, currentPreferences);
-                       profileChanged=false;
-                       if(!(startupProfileFilename==null))
-                               loadProfileOnStartup(startupProfileFilename);
-
-               currentPaths = DefaultPaths.loadFromProfile(profile);
+    const string[] authors = {
+        "Michael J. Chudobiak <mjc svn gnome org>",
+        "marlodavampire",
+        null
+    };
+    const string translators = N_ ("translator-credits");
+    const string[] license = {
+        N_ ("moserial is free software: you can redistribute it and/or modify it under the terms of the GNU 
General Public License as published by the Free Software Foundation, either version 3 of the License, or (at 
your option) any later version.\n"),
+        N_ ("moserial is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public 
License for more details.\n"),
+        N_ ("You should have received a copy of the GNU General Public License along with this program.  If 
not, see <http://www.gnu.org/licenses/>.")
+    };
+
+    private Gtk.Window gtkWindow;
+    private SettingsDialog settingsDialog;
+    private ToolButton settingsButton;
+    private ToggleToolButton recordButton;
+    private Settings currentSettings;
+    private Preferences currentPreferences;
+    private DefaultPaths currentPaths;
+    private Statusbar statusbar;
+    private Statusbar bytecountbar;
+    private uint statusbarContext;
+    private uint bytecountbarContext;
+    private ToolButton send;
+    private SendProgressDialog sendProgressDialog;
+    private SendChooserDialog sendChooserDialog;
+    private ToolButton receive;
+    private ReceiveProgressDialog receiveProgressDialog;
+    private ReceiveChooserDialog receiveChooserDialog;
+    private RecordDialog recordDialog;
+    private PreferencesDialog preferencesDialog;
+    private SerialConnection serialConnection = new SerialConnection ();
+    private TextView incomingHexTextView;
+    private TextView incomingAsciiTextView;
+    private TextView outgoingHexTextView;
+    private TextView outgoingAsciiTextView;
+
+    private ComboBox inputModeCombo;
+    private enum inputModeValues { ASCII, HEX }
+    private const string[] inputModeStrings = { GLib.N_ ("ASCII"), GLib.N_ ("HEX") };
+
+    private ComboBox lineEndModeCombo;
+
+    private ToggleToolButton connectButton;
+    private Label disconnectLabel;
+    private Label connectLabel;
+    private Label recordLabel;
+    private Label stopRecordingLabel;
+    private Paned paned;
+    private Notebook incoming_notebook;
+    private Notebook outgoing_notebook;
+    private HexTextBuffer incomingHexTextBuffer;
+    private HexTextBuffer outgoingHexTextBuffer;
+    private TextBuffer incomingAsciiTextBuffer;
+    private TextTag echoTag;
+    private TextBuffer outgoingAsciiTextBuffer;
+    private TextMark echoStartMark;
+    private XmodemFilenameDialog xmodemFilenameDialog;
+    private Gtk.Entry entry;
+    private Button sendButton;
+    private SerialStreamRecorder streamRecorder = new SerialStreamRecorder ();
+    private bool recordDataReceived = false;
+    private uint recordTimeoutID = 0;
+    private Rzwrapper rz;
+    private Szwrapper ? sz;
+    private Profile profile;
+    public string ? startupProfileFilename { get; construct; }
+    private string profileFilename = null;
+    private bool profileChanged = false;
+    private Gtk.ImageMenuItem cutMenuItem;
+    private Gtk.ImageMenuItem copyMenuItem;
+    private Adjustment va1;
+    private Adjustment va2;
+    private Adjustment va3;
+    private Adjustment va4;
+    private Gtk.AccelGroup ag;
+
+    private const string recentGroup = "moserial-configs";
+    private Gtk.RecentData recentData;
+
+    public MainWindow (string ? profileFilename) {
+        GLib.Object (startupProfileFilename: profileFilename);
+    }
+    construct {
+        var builder = new Gtk.Builder.from_resource (Config.UIROOT + "mainwindow.ui");
+
+        // setup window
+        gtkWindow = (Gtk.Window)builder.get_object ("window");
+        ag = (Gtk.AccelGroup)builder.get_object ("accelgroup1");
+        gtkWindow.add_accel_group (ag);
+
+        gtkWindow.destroy.connect (quitSave);
+        gtkWindow.delete_event.connect (deleteSaveSize);
+        gtkWindow.key_press_event.connect (keyPress);
+
+        // load defaults
+        profile = new Profile ();
+        profile.load (null, gtkWindow);
+        currentSettings = Settings.loadFromProfile (profile);
+        int width = profile.getWindowWidth ();
+        int height = profile.getWindowHeight ();
+        int panedPosition = profile.getWindowPanedPosition ();
+        if ((width > 0) && (height > 0))
+            gtkWindow.resize (width, height);
+
+        // setup paned
+        paned = (Paned) builder.get_object ("vpaned");
+        if (panedPosition >= -1)
+            paned.set_position (panedPosition);
+        else
+            paned.set_position (-1);
+
+        // setup menu items
+        Gtk.ImageMenuItem quit = (Gtk.ImageMenuItem)builder.get_object ("menubar_quit");
+        quit.activate.connect (quitSizeSave);
+        Gtk.ImageMenuItem saveAs = (Gtk.ImageMenuItem)builder.get_object ("menubar_save_settings_as");
+        saveAs.activate.connect (saveProfileAs);
+        Gtk.ImageMenuItem save = (Gtk.ImageMenuItem)builder.get_object ("menubar_save_settings");
+        save.activate.connect (saveProfile);
+        Gtk.ImageMenuItem open = (Gtk.ImageMenuItem)builder.get_object ("menubar_open_settings");
+        open.activate.connect (loadProfile);
+        copyMenuItem = (Gtk.ImageMenuItem)builder.get_object ("menubar_copy");
+        copyMenuItem.activate.connect (this.copy);
+        Gtk.MenuItem editMenuItem = (Gtk.MenuItem)builder.get_object ("menubar_edit");
+        editMenuItem.activate.connect (this.editMenu);
+        cutMenuItem = (Gtk.ImageMenuItem)builder.get_object ("menubar_cut");
+        copyMenuItem.set_sensitive (false);
+        cutMenuItem.set_sensitive (false);
+        cutMenuItem.activate.connect (this.cut);
+        Gtk.ImageMenuItem pasteMenuItem = (Gtk.ImageMenuItem)builder.get_object ("menubar_paste");
+        pasteMenuItem.activate.connect (this.paste);
+        Gtk.ImageMenuItem clearMenuItem = (Gtk.ImageMenuItem)builder.get_object ("menubar_clear");
+        clearMenuItem.activate.connect (this.clear);
+
+        // setup the Port Settings Dialog
+        settingsDialog = new SettingsDialog ();
+        settingsDialog.updateSettings.connect (this.updateSettings);
+        settingsButton = (ToolButton) builder.get_object ("toolbar_settings");
+        settingsButton.clicked.connect (this.showSettingsDialog);
+        settingsButton.set_tooltip_text (_("Port configuration"));
+
+        // setup the Help button
+        ToolButton helpButton = (ToolButton) builder.get_object ("toolbar_help");
+        helpButton.clicked.connect (showHelpButton);
+        helpButton.set_tooltip_text (_("Read the manual"));
+
+        // setup the statusbar
+        statusbar = (Statusbar) builder.get_object ("statusbar");
+        statusbarContext = statusbar.get_context_id ("moserial port status");
+        statusbar.push (statusbarContext, currentSettings.getStatusbarString (false));
+
+        // setup the byte count bar
+        bytecountbar = (Statusbar) builder.get_object ("bytecountbar");
+        bytecountbarContext = statusbar.get_context_id ("moserial byte counts");
+        bytecountbar.push (bytecountbarContext, _("TX: 0, RX: 0"));
+
+        // setup the about dialog
+        Gtk.ImageMenuItem about = (Gtk.ImageMenuItem)builder.get_object ("menubar_about");
+        about.activate.connect (showAboutDialog);
+
+        // setup send
+        sendProgressDialog = new SendProgressDialog ();
+        sendChooserDialog = new SendChooserDialog ();
+        send = (ToolButton) builder.get_object ("toolbar_send");
+        send.clicked.connect (doSendChooser);
+        send.set_tooltip_text (_("Send a file"));
+        sendChooserDialog.startTransfer.connect (this.doSend);
+        sz = new Szwrapper (Szwrapper.Protocol.NULL, null, null);
+
+        // setup receive
+        receiveProgressDialog = new ReceiveProgressDialog ();
+        receiveChooserDialog = new ReceiveChooserDialog ();
+        receive = (ToolButton) builder.get_object ("toolbar_receive");
+        receive.clicked.connect (doReceiveChooser);
+        receive.set_tooltip_text (_("Receive a file"));
+        receiveChooserDialog.startTransfer.connect (this.doReceive);
+        xmodemFilenameDialog = new XmodemFilenameDialog ();
+        rz = new Rzwrapper (Rzwrapper.Protocol.NULL, null, null, null);
+
+
+        // setup recording
+        recordDialog = new RecordDialog ();
+        recordButton = (ToggleToolButton) builder.get_object ("toolbar_logging");
+        recordButton.toggled.connect (this.record);
+        recordButton.set_tooltip_text (_("Record sent and/or received data"));
+        recordDialog.stopRecording.connect (this.stopRecording);
+        recordDialog.startRecording.connect (this.startRecording);
+        recordLabel = (Label) builder.get_object ("record_label");
+        stopRecordingLabel = (Label) builder.get_object ("stop_recording_label");
+
+        // setup preferences
+        preferencesDialog = new PreferencesDialog ();
+        preferencesDialog.updatePreferences.connect (this.updatePreferences);
+        ToolButton preferences = (ToolButton) builder.get_object ("toolbar_preferences");
+        preferences.clicked.connect (this.showPreferencesDialog);
+        preferences.set_tooltip_text (_("Other preferences"));
+
+        // setup connectbutton
+        connectButton = (ToggleToolButton) builder.get_object ("toolbar_connect");
+        connectButton.toggled.connect (this.connectButtonClick);
+        connectButton.set_tooltip_text (_("Open/close port"));
+        disconnectLabel = (Label) builder.get_object ("disconnect_label");
+        connectLabel = (Label) builder.get_object ("connect_label");
+
+        // setup help
+        Gtk.ImageMenuItem contents = (Gtk.ImageMenuItem)builder.get_object ("menubar_contents");
+        contents.activate.connect (showHelpAction);
+
+        // setup incoming notebook
+        incoming_notebook = (Notebook) builder.get_object ("incoming_notebook");
+
+        // setup outgoing notebook
+        outgoing_notebook = (Notebook) builder.get_object ("outgoing_notebook");
+
+        // setup textBuffers;
+        incomingHexTextBuffer = new HexTextBuffer ();
+        incomingAsciiTextBuffer = new TextBuffer (new TextTagTable ());
+        outgoingHexTextBuffer = new HexTextBuffer ();
+        outgoingAsciiTextBuffer = new TextBuffer (new TextTagTable ());
+
+        echoTag = incomingAsciiTextBuffer.create_tag ("echo", null);
+
+        incomingHexTextView = (TextView) builder.get_object ("incoming_hex_textview");
+        incomingHexTextView.set_buffer (incomingHexTextBuffer);
+
+        incomingAsciiTextView = (TextView) builder.get_object ("incoming_ascii_textview");
+        incomingAsciiTextView.set_buffer (incomingAsciiTextBuffer);
+
+        outgoingHexTextView = (TextView) builder.get_object ("outgoing_hex_textview");
+        outgoingHexTextView.set_buffer (outgoingHexTextBuffer);
+
+        outgoingAsciiTextView = (TextView) builder.get_object ("outgoing_ascii_textview");
+        outgoingAsciiTextView.set_buffer (outgoingAsciiTextBuffer);
+
+        // setup scrolling
+        ScrolledWindow incomingAsciiScrolledWindow = (ScrolledWindow) builder.get_object 
("incoming_ascii_scrolledwindow");
+        va1 = incomingAsciiScrolledWindow.get_vadjustment ();
+        ScrolledWindow incomingHexScrolledWindow = (ScrolledWindow) builder.get_object 
("incoming_hex_scrolledwindow");
+        va2 = incomingHexScrolledWindow.get_vadjustment ();
+        ScrolledWindow outgoingAsciiScrolledWindow = (ScrolledWindow) builder.get_object 
("outgoing_ascii_scrolledwindow");
+        va3 = outgoingAsciiScrolledWindow.get_vadjustment ();
+        ScrolledWindow outgoingHexScrolledWindow = (ScrolledWindow) builder.get_object 
("outgoing_hex_scrolledwindow");
+        va4 = outgoingHexScrolledWindow.get_vadjustment ();
+        AutoScroll.setup (va1, va2, va3, va4);
+
+        // setup entry
+        sendButton = (Button) builder.get_object ("send");
+        sendButton.clicked.connect (sendString);
+        sendButton.set_tooltip_text (_("Send the outgoing data now."));
+        entry = (Gtk.Entry)builder.get_object ("entry");
+        entry.activate.connect (sendString);
+        entry.set_tooltip_text (_("Type outgoing data here. Press Enter or Send to send it."));
+
+        inputModeCombo = (ComboBox) builder.get_object ("input_mode");
+        MoUtils.populateComboBox (inputModeCombo, inputModeStrings);
+        inputModeCombo.set_active (inputModeValues.ASCII);
+        inputModeCombo.changed.connect (inputModeChanged);
+
+        lineEndModeCombo = (ComboBox) builder.get_object ("termination_mode");
+        MoUtils.populateComboBox (lineEndModeCombo, serialConnection.LineEndStrings);
+        lineEndModeCombo.set_active (SerialConnection.LineEnd.CRLF);
+
+        // setup recent chooser
+        recentData.groups = { recentGroup };
+        recentData.app_name = GLib.Environment.get_application_name ();
+        recentData.app_exec = GLib.Environment.get_prgname () + " %u";
+        recentData.mime_type = "text/plain";
+
+        RecentManager recentManager = RecentManager.get_default ();
+        RecentChooserMenu recentChooserMenu = new Gtk.RecentChooserMenu.for_manager (recentManager);
+        recentChooserMenu.item_activated.connect (recentItemOpen);
+        RecentFilter filter = new RecentFilter ();
+        filter.add_group (recentGroup);
+        recentChooserMenu.add_filter (filter);
+        recentChooserMenu.set_show_numbers (true);
+        recentChooserMenu.show_not_found = false;
+        Gtk.MenuItem recentFileItem = (Gtk.MenuItem)builder.get_object ("menubar_open_recent");
+        recentFileItem.set_submenu (recentChooserMenu);
+
+        // load and apply preferences
+        currentPreferences = Preferences.loadFromProfile (profile);
+        updatePreferences (null, currentPreferences);
+        profileChanged = false;
+        if (!(startupProfileFilename == null))
+            loadProfileOnStartup (startupProfileFilename);
+
+        currentPaths = DefaultPaths.loadFromProfile (profile);
+    }
+
+    private void applyProfile (string filename) {
+        if (profile.load (filename, gtkWindow)) {
+            profileFilename = filename;
+            ensureDisconnected ();
+            currentSettings = Settings.loadFromProfile (profile);
+            currentPreferences = Preferences.loadFromProfile (profile);
+            currentPaths = DefaultPaths.loadFromProfile (profile);
+            updatePreferences (null, currentPreferences);
+            statusbar.pop (statusbarContext);
+            statusbar.push (statusbarContext, currentSettings.getStatusbarString (false));
+            setWindowTitle (null);
+            profileChanged = false;
+            RecentManager recentManager = RecentManager.get_default ();
+            try {
+                recentManager.add_full (GLib.Filename.to_uri (filename), recentData);
+            } catch (GLib.ConvertError e) {
+                stdout.printf ("%s\n", e.message);
+            }
         }
+    }
 
-       private void applyProfile (string filename) {
-               if (profile.load(filename, gtkWindow)) {
-                       profileFilename = filename;
-                       ensureDisconnected();
-                       currentSettings = Settings.loadFromProfile(profile);
-                       currentPreferences = Preferences.loadFromProfile(profile);
-                       currentPaths = DefaultPaths.loadFromProfile(profile);
-                       updatePreferences(null, currentPreferences);
-                       statusbar.pop(statusbarContext);
-                       statusbar.push(statusbarContext, currentSettings.getStatusbarString(false));
-                       setWindowTitle(null);
-                       profileChanged=false;
-                       RecentManager recentManager = RecentManager.get_default ();
-                       try {
-                               recentManager.add_full(GLib.Filename.to_uri(filename), recentData);
-                       }
-                       catch (GLib.ConvertError e) {
-                               stdout.printf("%s\n", e.message);
-                       }
-               }
-       }
-
-       private void setWindowTitle (string? recordingFilename) {
-               var builder = new StringBuilder();
-               builder.append("moserial");
-               
-               if (profileFilename != null) {
-                       builder.append(" - ");
-                       builder.append(GLib.Path.get_basename(profileFilename));
-               }
-
-                if (recordingFilename != null) {
-                        builder.append(" - ");
-                        builder.append(GLib.Path.get_basename(recordingFilename));
-                }
+    private void setWindowTitle (string ? recordingFilename) {
+        var builder = new StringBuilder ();
+        builder.append ("moserial");
 
-               gtkWindow.set_title(builder.str);
-       }
-
-       private void recentItemOpen(RecentChooser r) {
-               try{
-                       applyProfile(GLib.Filename.from_uri(r.get_current_uri()));
-               }
-               catch (GLib.ConvertError e) {
-                       stdout.printf("%s\n", e.message);
-               }
-       }
-
-        private void insertBufferEnd (TextBuffer buf, string s) {
-                TextIter iter;
-               int i;
-               var builder = new StringBuilder();
-
-               for (i=0;i<s.length;i++) {
-                       unichar c = s.get_char();
-                       if (c.isprint() || c.isspace())
-                               builder.append_unichar(c);      
-                       s=s.next_char();
-               }
-
-                buf.get_end_iter(out iter);
-                buf.insert(ref iter, builder.str, (int)builder.str.length);
-        }
-
-        public void sendString(Widget w) {
-
-                if (!ensureConnected())
-                        return;
-
-                string s;
-                s=entry.get_text();
-                serialConnection.echoReference=s;
-
-                long len;
-                if (inputModeCombo.get_active()==inputModeValues.ASCII) {
-                        len = s.length;
-
-                        for (int x=0; x<len; x++) {
-                                serialConnection.sendByte((uchar)s.get_char());
-                                streamRecorder.writeOutgoing((uchar)s.get_char());
-                                outgoingHexTextBuffer.add((uchar)s.get_char());
-                                insertBufferEnd(outgoingAsciiTextBuffer, "%c".printf((uchar)s.get_char()));
-                                s=s.next_char();
-                        }
-
-                        string t = serialConnection.LineEndValues[lineEndModeCombo.get_active()];
-                        len = t.length;
-
-                        for (int x=0; x<len; x++) {
-                                serialConnection.sendByte((uchar)t.get_char());
-                                streamRecorder.writeOutgoing((uchar)t.get_char());
-                                outgoingHexTextBuffer.add((uchar)t.get_char());
-
-                                /* Just display the first byte of the terminator in the ASCII window,
-                                   so that CRLF doesn't cause two line advances. */
-                                if (x==0)
-                                        insertBufferEnd(outgoingAsciiTextBuffer, 
"%c".printf((uchar)t.get_char()));
-
-                                t=t.next_char();
-                        }
-
-                } else {
-                       try {
-                               uchar[] h = InputParser.parseHex(s);
-                               len = h.length;
-                               for (int x=0; x<len; x++) {
-                                       serialConnection.sendByte(h[x]);
-                                       streamRecorder.writeOutgoing(h[x]);
-                                       outgoingHexTextBuffer.add(h[x]);
-                                       insertBufferEnd(outgoingAsciiTextBuffer, "%c".printf(h[x]));
-                               }
-                       }
-                       catch (HexParseError e) {
-                               var errorDialog = new MessageDialog (gtkWindow, 
DialogFlags.DESTROY_WITH_PARENT, MessageType.ERROR, ButtonsType.CLOSE, "%s", e.message);
-                               errorDialog.run();
-                               errorDialog.destroy();
-                       }
-                }
-                bytecountbar.pop(bytecountbarContext);
-                bytecountbar.push(bytecountbarContext, serialConnection.getBytecountbarString());
-                entry.set_text("");
-
-                /* Start listening for an echo */
-                serialConnection.echoCompare="";
-                TextIter echoStartIter;
-                incomingAsciiTextBuffer.get_end_iter(out echoStartIter);
-                echoStartMark = incomingAsciiTextBuffer.create_mark ("echo",echoStartIter,true);
+        if (profileFilename != null) {
+            builder.append (" - ");
+            builder.append (GLib.Path.get_basename (profileFilename));
         }
 
-        private void doSendChooser(ToolButton button) {
-                if (!ensureConnected())
-                        return;
-                sendChooserDialog.show(currentPaths.sendFrom);
+        if (recordingFilename != null) {
+            builder.append (" - ");
+            builder.append (GLib.Path.get_basename (recordingFilename));
         }
 
-        private void doSend(SendChooserDialog dialog) {
-                Szwrapper.Protocol protocol;
-                string filename;
-                filename=dialog.filename;
-               currentPaths.sendFrom=MoUtils.getParentFolder(filename);
-                switch (dialog.protocolCombo.get_active()) {
-                case 0:
-                        protocol=Szwrapper.Protocol.XMODEM;
-                        break;
-                case 1:
-                        protocol=Szwrapper.Protocol.YMODEM;
-                        break;
-                case 2:
-                default:
-                        protocol=Szwrapper.Protocol.ZMODEM;
-                        break;
-                case 3:
-                       protocol=Szwrapper.Protocol.RAW;
-                       break;
-                }                      
-                sz = new Szwrapper(protocol, serialConnection, filename);
-                if(sz.running)
-               {
-                       sendProgressDialog.show();
-                       sz.updateStatus.connect(sendProgressDialog.updateStatus);
-                       sendProgressDialog.transferCanceled.connect(sz.transferCanceled);
-                       sz.transferComplete.connect(this.sendComplete);
-               }
-        }
+        gtkWindow.set_title (builder.str);
+    }
 
-        public void sendComplete(GLib.Object o) {
-               sz.updateStatus.disconnect(sendProgressDialog.updateStatus);
-               sendProgressDialog.transferCanceled.disconnect(sz.transferCanceled);
-                sendProgressDialog.hide();
+    private void recentItemOpen (RecentChooser r) {
+        try {
+            applyProfile (GLib.Filename.from_uri (r.get_current_uri ()));
+        } catch (GLib.ConvertError e) {
+            stdout.printf ("%s\n", e.message);
         }
-
-        private void doReceiveChooser(ToolButton button) {
-                if (!ensureConnected())
-                        return;
-
-                receiveChooserDialog.show(currentPaths.receiveTo);
+    }
+
+    private void insertBufferEnd (TextBuffer buf, string s) {
+        TextIter iter;
+        int i;
+        var builder = new StringBuilder ();
+
+        for (i = 0; i < s.length; i++) {
+            unichar c = s.get_char ();
+            if (c.isprint () || c.isspace ())
+                builder.append_unichar (c);
+            s = s.next_char ();
         }
 
-        private void doReceive(ReceiveChooserDialog dialog) {
-                string filename="";
-               currentPaths.receiveTo=dialog.path;
-                if (dialog.protocolCombo.get_active()==0) { //get the filename for xmodem
-                        xmodemFilenameDialog.show();
-                        filename = xmodemFilenameDialog.filename;
+        buf.get_end_iter (out iter);
+        buf.insert (ref iter, builder.str, (int) builder.str.length);
+    }
+
+    public void sendString (Widget w) {
+
+        if (!ensureConnected ())
+            return;
+
+        string s;
+        s = entry.get_text ();
+        serialConnection.echoReference = s;
+
+        long len;
+        if (inputModeCombo.get_active () == inputModeValues.ASCII) {
+            len = s.length;
+
+            for (int x = 0; x < len; x++) {
+                serialConnection.sendByte ((uchar) s.get_char ());
+                streamRecorder.writeOutgoing ((uchar) s.get_char ());
+                outgoingHexTextBuffer.add ((uchar) s.get_char ());
+                insertBufferEnd (outgoingAsciiTextBuffer, "%c".printf ((uchar) s.get_char ()));
+                s = s.next_char ();
+            }
+
+            string t = serialConnection.LineEndValues[lineEndModeCombo.get_active ()];
+            len = t.length;
+
+            for (int x = 0; x < len; x++) {
+                serialConnection.sendByte ((uchar) t.get_char ());
+                streamRecorder.writeOutgoing ((uchar) t.get_char ());
+                outgoingHexTextBuffer.add ((uchar) t.get_char ());
+
+                /* Just display the first byte of the terminator in the ASCII window,
+                   so that CRLF doesn't cause two line advances. */
+                if (x == 0)
+                    insertBufferEnd (outgoingAsciiTextBuffer, "%c".printf ((uchar) t.get_char ()));
+
+                t = t.next_char ();
+            }
+        } else {
+            try {
+                uchar[] h = InputParser.parseHex (s);
+                len = h.length;
+                for (int x = 0; x < len; x++) {
+                    serialConnection.sendByte (h[x]);
+                    streamRecorder.writeOutgoing (h[x]);
+                    outgoingHexTextBuffer.add (h[x]);
+                    insertBufferEnd (outgoingAsciiTextBuffer, "%c".printf (h[x]));
                 }
-                Rzwrapper.Protocol protocol;
-                switch (dialog.protocolCombo.get_active()) {
-                case 0:
-                        protocol=Rzwrapper.Protocol.XMODEM;
-                        break;
-                case 1:
-                        protocol=Rzwrapper.Protocol.YMODEM;
-                        break;
-                case 2:
-                default:
-                        protocol=Rzwrapper.Protocol.ZMODEM;
-                        break;
-                }
-                rz = new Rzwrapper(protocol, serialConnection, dialog.path, filename);
-                if(rz.running)
-                {
-                       receiveProgressDialog.show();
-                       rz.updateStatus.connect(receiveProgressDialog.updateStatus);
-                       receiveProgressDialog.transferCanceled.connect(rz.transferCanceled);
-                       rz.transferComplete.connect(this.receiveComplete);
-               }
+            } catch (HexParseError e) {
+                var errorDialog = new MessageDialog (gtkWindow, DialogFlags.DESTROY_WITH_PARENT, 
MessageType.ERROR, ButtonsType.CLOSE, "%s", e.message);
+                errorDialog.run ();
+                errorDialog.destroy ();
+            }
         }
-
-        public void receiveComplete(GLib.Object o) {
-                rz.updateStatus.disconnect(receiveProgressDialog.updateStatus);
-                receiveProgressDialog.transferCanceled.disconnect(rz.transferCanceled);
-                receiveProgressDialog.hide();
+        bytecountbar.pop (bytecountbarContext);
+        bytecountbar.push (bytecountbarContext, serialConnection.getBytecountbarString ());
+        entry.set_text ("");
+
+        /* Start listening for an echo */
+        serialConnection.echoCompare = "";
+        TextIter echoStartIter;
+        incomingAsciiTextBuffer.get_end_iter (out echoStartIter);
+        echoStartMark = incomingAsciiTextBuffer.create_mark ("echo", echoStartIter, true);
+    }
+
+    private void doSendChooser (ToolButton button) {
+        if (!ensureConnected ())
+            return;
+        sendChooserDialog.show (currentPaths.sendFrom);
+    }
+
+    private void doSend (SendChooserDialog dialog) {
+        Szwrapper.Protocol protocol;
+        string filename;
+        filename = dialog.filename;
+        currentPaths.sendFrom = MoUtils.getParentFolder (filename);
+        switch (dialog.protocolCombo.get_active ()) {
+            case 0:
+                protocol = Szwrapper.Protocol.XMODEM;
+                break;
+            case 1:
+                protocol = Szwrapper.Protocol.YMODEM;
+                break;
+            case 2:
+            default:
+                protocol = Szwrapper.Protocol.ZMODEM;
+                break;
+            case 3:
+                protocol = Szwrapper.Protocol.RAW;
+                break;
         }
-
-        public void record(ToggleToolButton button) {
-                if (button.get_active()) {
-                       if (!ensureConnected()) {
-                               button.set_active(false);
-                               return;
-                       }
-                        button.set_label_widget(stopRecordingLabel);
-                        recordDialog.show(currentPaths.recordTo);
-                } else {
-                        streamRecorder.close(currentPreferences.recordLaunch);
-                        button.set_label_widget(recordLabel);
-                       setWindowTitle(null);
-                       if (recordTimeoutID > 0) {
-                               GLib.Source.remove (recordTimeoutID);
-                               recordTimeoutID = 0;
-                       }
-                }
+        sz = new Szwrapper (protocol, serialConnection, filename);
+        if (sz.running) {
+            sendProgressDialog.show ();
+            sz.updateStatus.connect (sendProgressDialog.updateStatus);
+            sendProgressDialog.transferCanceled.connect (sz.transferCanceled);
+            sz.transferComplete.connect (this.sendComplete);
         }
-
-        public void stopRecording(moserial.RecordDialog dialog) {
-                recordButton.set_active(false); //this generates recordButton.clicked signal
+    }
+
+    public void sendComplete (GLib.Object o) {
+        sz.updateStatus.disconnect (sendProgressDialog.updateStatus);
+        sendProgressDialog.transferCanceled.disconnect (sz.transferCanceled);
+        sendProgressDialog.hide ();
+    }
+
+    private void doReceiveChooser (ToolButton button) {
+        if (!ensureConnected ())
+            return;
+
+        receiveChooserDialog.show (currentPaths.receiveTo);
+    }
+
+    private void doReceive (ReceiveChooserDialog dialog) {
+        string filename = "";
+        currentPaths.receiveTo = dialog.path;
+        if (dialog.protocolCombo.get_active () == 0) { // get the filename for xmodem
+            xmodemFilenameDialog.show ();
+            filename = xmodemFilenameDialog.filename;
         }
-
-        public void startRecording(moserial.RecordDialog dialog, string filename, 
moserial.SerialStreamRecorder.Direction direction) {
-                try {
-                        streamRecorder.open(filename, direction);
-                       currentPaths.recordTo=MoUtils.getParentFolder(filename);
-                        if (!ensureConnected())
-                                stopRecording(dialog);
-                       setWindowTitle(filename);
-                } catch (GLib.Error e) {
-                        var errorDialog = new MessageDialog (gtkWindow, DialogFlags.DESTROY_WITH_PARENT, 
MessageType.ERROR, ButtonsType.CLOSE, "%s: %s\n%s", _("Error: Could not open file"), filename, e.message);
-                        errorDialog.run();
-                        errorDialog.destroy();
-                        stopRecording(dialog);
-                }
+        Rzwrapper.Protocol protocol;
+        switch (dialog.protocolCombo.get_active ()) {
+            case 0:
+                protocol = Rzwrapper.Protocol.XMODEM;
+                break;
+            case 1:
+                protocol = Rzwrapper.Protocol.YMODEM;
+                break;
+            case 2:
+            default:
+                protocol = Rzwrapper.Protocol.ZMODEM;
+                break;
         }
-
-       public bool recordTimeout() {
-               recordButton.set_active(false);
-               return false;
-       }
-
-        public void showWindow() {
-                gtkWindow.show_all();
+        rz = new Rzwrapper (protocol, serialConnection, dialog.path, filename);
+        if (rz.running) {
+            receiveProgressDialog.show ();
+            rz.updateStatus.connect (receiveProgressDialog.updateStatus);
+            receiveProgressDialog.transferCanceled.connect (rz.transferCanceled);
+            rz.transferComplete.connect (this.receiveComplete);
         }
-
-        private void updateSettings(SettingsDialog d, Settings newSettings) {
-                currentSettings = newSettings;
-                statusbar.pop(statusbarContext);
-                statusbar.push(statusbarContext, currentSettings.getStatusbarString(false));
-                profileChanged=true;
+    }
+
+    public void receiveComplete (GLib.Object o) {
+        rz.updateStatus.disconnect (receiveProgressDialog.updateStatus);
+        receiveProgressDialog.transferCanceled.disconnect (rz.transferCanceled);
+        receiveProgressDialog.hide ();
+    }
+
+    public void record (ToggleToolButton button) {
+        if (button.get_active ()) {
+            if (!ensureConnected ()) {
+                button.set_active (false);
+                return;
+            }
+            button.set_label_widget (stopRecordingLabel);
+            recordDialog.show (currentPaths.recordTo);
+        } else {
+            streamRecorder.close (currentPreferences.recordLaunch);
+            button.set_label_widget (recordLabel);
+            setWindowTitle (null);
+            if (recordTimeoutID > 0) {
+                GLib.Source.remove (recordTimeoutID);
+                recordTimeoutID = 0;
+            }
         }
-        
-        private void updatePreferences(PreferencesDialog? d, Preferences newPreferences) {
-               currentPreferences = newPreferences;
-               string font;
-               if(currentPreferences.useSystemMonospaceFont)
-                       font=Preferences.getSystemDefaultMonospaceFont();
-               else
-                       font=currentPreferences.font;
-               incomingAsciiTextView.modify_font(Pango.FontDescription.from_string(font));
-               incomingAsciiTextView.modify_text(Gtk.StateType.NORMAL, 
Preferences.getGdkColor(currentPreferences.fontColor));
-               incomingAsciiTextView.modify_base(Gtk.StateType.NORMAL, 
Preferences.getGdkColor(currentPreferences.backgroundColor));
-               echoTag.foreground=currentPreferences.highlightColor;
-               
-               incomingHexTextView.modify_font(Pango.FontDescription.from_string(font));
-               incomingHexTextView.modify_text(Gtk.StateType.NORMAL, 
Preferences.getGdkColor(currentPreferences.fontColor));
-               incomingHexTextView.modify_base(Gtk.StateType.NORMAL, 
Preferences.getGdkColor(currentPreferences.backgroundColor));
-               incomingHexTextBuffer.applyPreferences(currentPreferences);
-               
-               outgoingAsciiTextView.modify_font(Pango.FontDescription.from_string(font));
-               outgoingAsciiTextView.modify_text(Gtk.StateType.NORMAL, 
Preferences.getGdkColor(currentPreferences.fontColor));
-               outgoingAsciiTextView.modify_base(Gtk.StateType.NORMAL, 
Preferences.getGdkColor(currentPreferences.backgroundColor));
-
-               outgoingHexTextView.modify_font(Pango.FontDescription.from_string(font));
-               outgoingHexTextView.modify_text(Gtk.StateType.NORMAL, 
Preferences.getGdkColor(currentPreferences.fontColor));
-               outgoingHexTextView.modify_base(Gtk.StateType.NORMAL, 
Preferences.getGdkColor(currentPreferences.backgroundColor));
-               outgoingHexTextBuffer.applyPreferences(currentPreferences);
-
-               entry.modify_font(Pango.FontDescription.from_string(font));
-               entry.modify_text(Gtk.StateType.NORMAL, 
Preferences.getGdkColor(currentPreferences.fontColor));
-               entry.modify_base(Gtk.StateType.NORMAL, 
Preferences.getGdkColor(currentPreferences.backgroundColor));
-
-               profileChanged=true;
+    }
+
+    public void stopRecording (moserial.RecordDialog dialog) {
+        recordButton.set_active (false); // this generates recordButton.clicked signal
+    }
+
+    public void startRecording (moserial.RecordDialog dialog, string filename, 
moserial.SerialStreamRecorder.Direction direction) {
+        try {
+            streamRecorder.open (filename, direction);
+            currentPaths.recordTo = MoUtils.getParentFolder (filename);
+            if (!ensureConnected ())
+                stopRecording (dialog);
+            setWindowTitle (filename);
+        } catch (GLib.Error e) {
+            var errorDialog = new MessageDialog (gtkWindow, DialogFlags.DESTROY_WITH_PARENT, 
MessageType.ERROR, ButtonsType.CLOSE, "%s: %s\n%s", _("Error: Could not open file"), filename, e.message);
+            errorDialog.run ();
+            errorDialog.destroy ();
+            stopRecording (dialog);
         }
-
-        private void showSettingsDialog(GLib.Object o) {
-                settingsDialog.show(currentSettings);
+    }
+
+    public bool recordTimeout () {
+        recordButton.set_active (false);
+        return false;
+    }
+
+    public void showWindow () {
+        gtkWindow.show_all ();
+    }
+
+    private void updateSettings (SettingsDialog d, Settings newSettings) {
+        currentSettings = newSettings;
+        statusbar.pop (statusbarContext);
+        statusbar.push (statusbarContext, currentSettings.getStatusbarString (false));
+        profileChanged = true;
+    }
+
+    private void updatePreferences (PreferencesDialog ? d, Preferences newPreferences) {
+        currentPreferences = newPreferences;
+        string font;
+        if (currentPreferences.useSystemMonospaceFont)
+            font = Preferences.getSystemDefaultMonospaceFont ();
+        else
+            font = currentPreferences.font;
+        incomingAsciiTextView.modify_font (Pango.FontDescription.from_string (font));
+        incomingAsciiTextView.modify_text (Gtk.StateType.NORMAL, Preferences.getGdkColor 
(currentPreferences.fontColor));
+        incomingAsciiTextView.modify_base (Gtk.StateType.NORMAL, Preferences.getGdkColor 
(currentPreferences.backgroundColor));
+        echoTag.foreground = currentPreferences.highlightColor;
+
+        incomingHexTextView.modify_font (Pango.FontDescription.from_string (font));
+        incomingHexTextView.modify_text (Gtk.StateType.NORMAL, Preferences.getGdkColor 
(currentPreferences.fontColor));
+        incomingHexTextView.modify_base (Gtk.StateType.NORMAL, Preferences.getGdkColor 
(currentPreferences.backgroundColor));
+        incomingHexTextBuffer.applyPreferences (currentPreferences);
+
+        outgoingAsciiTextView.modify_font (Pango.FontDescription.from_string (font));
+        outgoingAsciiTextView.modify_text (Gtk.StateType.NORMAL, Preferences.getGdkColor 
(currentPreferences.fontColor));
+        outgoingAsciiTextView.modify_base (Gtk.StateType.NORMAL, Preferences.getGdkColor 
(currentPreferences.backgroundColor));
+
+        outgoingHexTextView.modify_font (Pango.FontDescription.from_string (font));
+        outgoingHexTextView.modify_text (Gtk.StateType.NORMAL, Preferences.getGdkColor 
(currentPreferences.fontColor));
+        outgoingHexTextView.modify_base (Gtk.StateType.NORMAL, Preferences.getGdkColor 
(currentPreferences.backgroundColor));
+        outgoingHexTextBuffer.applyPreferences (currentPreferences);
+
+        entry.modify_font (Pango.FontDescription.from_string (font));
+        entry.modify_text (Gtk.StateType.NORMAL, Preferences.getGdkColor (currentPreferences.fontColor));
+        entry.modify_base (Gtk.StateType.NORMAL, Preferences.getGdkColor 
(currentPreferences.backgroundColor));
+
+        profileChanged = true;
+    }
+
+    private void showSettingsDialog (GLib.Object o) {
+        settingsDialog.show (currentSettings);
+    }
+
+    private void showPreferencesDialog (GLib.Object o) {
+        preferencesDialog.show (currentPreferences, recordButton.get_active ());
+    }
+
+    public bool ensureConnected () {
+        if (!connectButton.get_active ())
+            connectButton.set_active (true);
+        return connectButton.get_active ();
+    }
+
+    public void ensureDisconnected () {
+        if (connectButton.get_active ())
+            connectButton.set_active (false);
+    }
+
+    private bool startConnection () {
+        if (!(serialConnection.doConnect (currentSettings))) {
+            connectButton.set_active (false);
+            var dialog = new MessageDialog (gtkWindow, DialogFlags.DESTROY_WITH_PARENT, MessageType.ERROR, 
ButtonsType.CLOSE, "%s: %s", _("Error: Could not open device"), currentSettings.device);
+            dialog.run ();
+            dialog.destroy ();
+            return false;
         }
-        
-        private void showPreferencesDialog(GLib.Object o) {
-                preferencesDialog.show(currentPreferences, recordButton.get_active());
+        incomingHexTextBuffer.clear ();
+        incomingAsciiTextBuffer.set_text ("", 0);
+        outgoingHexTextBuffer.clear ();
+        outgoingAsciiTextBuffer.set_text ("", 0);
+
+        settingsButton.set_sensitive (false);
+        statusbar.pop (statusbarContext);
+        statusbar.push (statusbarContext, currentSettings.getStatusbarString (true));
+        serialConnection.newData.connect (this.updateIncoming);
+        connectButton.set_label_widget (disconnectLabel);
+        return true;
+    }
+
+    private void connectButtonClick (ToggleToolButton button) {
+        if (button.get_active ()) {
+            startConnection ();
+        } else {
+            settingsButton.set_sensitive (true);
+            serialConnection.doDisconnect ();
+            serialConnection.newData.disconnect (this.updateIncoming);
+            bytecountbar.pop (bytecountbarContext);
+            bytecountbar.push (bytecountbarContext, serialConnection.getBytecountbarString ());
+            // serialConnection = new SerialConnection();
+            statusbar.pop (statusbarContext);
+            statusbar.push (statusbarContext, currentSettings.getStatusbarString (false));
+            button.set_label_widget (connectLabel);
+
+            if (recordButton.get_active ())
+                recordButton.set_active (false);
         }
-
-       public bool ensureConnected () {
-                if (!connectButton.get_active())
-                        connectButton.set_active(true);
-                return connectButton.get_active();
-        }
-
-        public void ensureDisconnected () {
-                if (connectButton.get_active())
-                        connectButton.set_active(false);
-        }
-
-        private bool startConnection() {
-                if (!(serialConnection.doConnect(currentSettings))) {
-                        connectButton.set_active(false);
-                        var dialog = new MessageDialog (gtkWindow, DialogFlags.DESTROY_WITH_PARENT, 
MessageType.ERROR, ButtonsType.CLOSE, "%s: %s", _("Error: Could not open device"), currentSettings.device);
-                        dialog.run();
-                        dialog.destroy();
-                        return false;
+    }
+
+    private void updateIncoming (SerialConnection sc, uchar[] data, int size) {
+        if (rz.running) {
+            for (int x = 0; x < size; x++) {
+                rz.writeChar (data[x]);
+            }
+            rz.flush ();
+        } else if (sz.running) {
+            for (int x = 0; x < size; x++) {
+                sz.writeChar (data[x]);
+            }
+        } else {
+            for (int x = 0; x < size; x++) {
+
+                incomingHexTextBuffer.add (data[x]);
+
+                unichar c = "%c".printf (data[x]).get_char ();
+                string s = "%c".printf (data[x]);
+
+                /* Keep a record of any possible echo */
+                if (sc.echoCompare.length < sc.echoReference.length)
+                    sc.echoCompare += s;
+
+                if (s.validate () && (c.isprint () || c.isspace ())) {
+                    /* Ignore LF if last char was CR (CRLF terminator) */
+                    if (!(sc.lastRxCharWasCR && (c == '\n'))) {
+                        insertBufferEnd (incomingAsciiTextBuffer, s);
+                    }
+                } else
+                    ++sc.nonprintable;
+
+                sc.lastRxCharWasCR = (c == '\r');
+
+                /* Highlight any text that is an exact echo of the last transmission */
+                if (sc.echoCompare.length > 0 && (sc.echoCompare.length == sc.echoReference.length)) {
+                    if (sc.echoCompare == sc.echoReference) {
+                        TextIter echoStartIter;
+                        TextIter echoStopIter;
+                        incomingAsciiTextBuffer.get_iter_at_mark (out echoStartIter, echoStartMark);
+                        incomingAsciiTextBuffer.get_end_iter (out echoStopIter);
+                        incomingAsciiTextBuffer.apply_tag_by_name ("echo", echoStartIter, echoStopIter);
+                    }
+                    sc.echoCompare = "";
+                    sc.echoReference = "";
                 }
-                incomingHexTextBuffer.clear();
-                incomingAsciiTextBuffer.set_text("",0);
-                outgoingHexTextBuffer.clear();
-                outgoingAsciiTextBuffer.set_text("",0);
-
-                settingsButton.set_sensitive(false);
-                statusbar.pop(statusbarContext);
-                statusbar.push(statusbarContext, currentSettings.getStatusbarString(true));
-                serialConnection.newData.connect(this.updateIncoming);
-                connectButton.set_label_widget(disconnectLabel);
-                return true;
-        }
 
-        private void connectButtonClick(ToggleToolButton button) {
-                if (button.get_active()) {
-                        startConnection();
-                } else {
-                        settingsButton.set_sensitive(true);
-                        serialConnection.doDisconnect();
-                        serialConnection.newData.disconnect(this.updateIncoming);
-                        bytecountbar.pop(bytecountbarContext);
-                        bytecountbar.push(bytecountbarContext, serialConnection.getBytecountbarString());
-                        //serialConnection = new SerialConnection();
-                        statusbar.pop(statusbarContext);
-                        statusbar.push(statusbarContext, currentSettings.getStatusbarString(false));
-                        button.set_label_widget(connectLabel);
-
-                        if (recordButton.get_active())
-                                recordButton.set_active(false);
+                /* Auto-select hex view for binary data */
+                if ((sc.rx > 32) && (sc.nonprintable > 0) && (sc.rx / sc.nonprintable < 4) && 
!sc.forced_hex_view) {
+                    sc.forced_hex_view = true;
+                    incoming_notebook.set_current_page (1);
                 }
-        }
 
-       private void updateIncoming(SerialConnection sc, uchar[] data, int size) {
-                if (rz.running) {
-                        for (int x=0; x<size; x++) {
-                               rz.writeChar(data[x]);
-                        }
-                        rz.flush();
-                } else if (sz.running) {
-                        for (int x=0; x<size; x++) {
-                                sz.writeChar(data[x]);
-                        }
-                } else {
-                        for (int x=0; x<size; x++) {
-
-                                incomingHexTextBuffer.add(data[x]);
-
-                                unichar c = "%c".printf(data[x]).get_char();
-                                string s = "%c".printf(data[x]);
-
-                                /* Keep a record of any possible echo */
-                                if (sc.echoCompare.length < sc.echoReference.length)
-                                        sc.echoCompare += s;
-
-                                if (s.validate() && (c.isprint() || c.isspace())) {
-                                        /* Ignore LF if last char was CR (CRLF terminator) */
-                                        if (! (sc.lastRxCharWasCR && (c == '\n'))) {
-                                                insertBufferEnd(incomingAsciiTextBuffer, s);
-                                        }
-                                } else
-                                        ++sc.nonprintable;
-
-                                sc.lastRxCharWasCR = (c == '\r');
-
-                                /* Highlight any text that is an exact echo of the last transmission */
-                                if (sc.echoCompare.length > 0 && (sc.echoCompare.length == 
sc.echoReference.length)) {
-                                        if (sc.echoCompare == sc.echoReference) {
-                                                TextIter echoStartIter;
-                                                TextIter echoStopIter;
-                                                incomingAsciiTextBuffer.get_iter_at_mark (out echoStartIter, 
echoStartMark);
-                                                incomingAsciiTextBuffer.get_end_iter(out echoStopIter);
-                                                
incomingAsciiTextBuffer.apply_tag_by_name("echo",echoStartIter,echoStopIter);
-                                        }
-                                        sc.echoCompare="";
-                                        sc.echoReference="";
-                                }
-
-                                /* Auto-select hex view for binary data */
-                                if ((sc.rx > 32) && (sc.nonprintable > 0) && (sc.rx / sc.nonprintable < 4) 
&& !sc.forced_hex_view) {
-                                        sc.forced_hex_view = true;
-                                        incoming_notebook.set_current_page(1);
-                                }
-
-                               if(currentPreferences.enableTimeout && recordButton.get_active()) {
-                                       if (recordTimeoutID > 0)
-                                               GLib.Source.remove (recordTimeoutID);
-                                       if (currentPreferences.timeout > 0)
-                                               recordTimeoutID = 
GLib.Timeout.add_seconds(currentPreferences.timeout, recordTimeout);
-                               }
-
-                               recordDataReceived=true;
-                                bytecountbar.pop(bytecountbarContext);
-                                bytecountbar.push(bytecountbarContext, sc.getBytecountbarString());
-                        }
-                        streamRecorder.writeIncoming(data);
+                if (currentPreferences.enableTimeout && recordButton.get_active ()) {
+                    if (recordTimeoutID > 0)
+                        GLib.Source.remove (recordTimeoutID);
+                    if (currentPreferences.timeout > 0)
+                        recordTimeoutID = GLib.Timeout.add_seconds (currentPreferences.timeout, 
recordTimeout);
                 }
-        }
 
-       private void inputModeChanged (ComboBox inputModeCombo) {
-               if (inputModeCombo.get_active()==inputModeValues.HEX)
-                       outgoing_notebook.set_current_page(1);
-               else
-                       outgoing_notebook.set_current_page(0);
-       }
-
-       private void showHelpButton (ToolButton button) {
-               showHelp ();
-       }
-       
-       private void showHelpAction () {
-               showHelp ();
-       }
-
-        private void showHelp () {
-                try {
-                        show_uri_on_window(null, "help:moserial", Gdk.CURRENT_TIME);
-                } catch (GLib.Error e) {
-                        warning(_("Unable to display help file: %s"), e.message);
-                }
+                recordDataReceived = true;
+                bytecountbar.pop (bytecountbarContext);
+                bytecountbar.push (bytecountbarContext, sc.getBytecountbarString ());
+            }
+            streamRecorder.writeIncoming (data);
         }
-
-        private void showAboutDialog () {
-
-                string license_trans = _(license[0]) + "\n" + _(license[1]) + "\n" + _(license[2]);
-
-                show_about_dialog (gtkWindow,
-                                   "version", Config.VERSION,
-                                   "copyright", "Copyright © 2009-2018\nMichael J. Chudobiak\n<mjc svn gnome 
org>",
-                                   "comments", _("A serial terminal for the GNOME desktop, optimized for 
logging and file capture."),
-                                   "authors", authors,
-                                   "translator-credits", _(translators),
-                                   "logo-icon-name", "moserial",
-                                   "wrap-license", true,
-                                   "license", license_trans,
-                                   "website", "http://live.gnome.org/moserial";,
-                                   "website_label", "http://live.gnome.org/moserial";,
-                                   null);
+    }
+
+    private void inputModeChanged (ComboBox inputModeCombo) {
+        if (inputModeCombo.get_active () == inputModeValues.HEX)
+            outgoing_notebook.set_current_page (1);
+        else
+            outgoing_notebook.set_current_page (0);
+    }
+
+    private void showHelpButton (ToolButton button) {
+        showHelp ();
+    }
+
+    private void showHelpAction () {
+        showHelp ();
+    }
+
+    private void showHelp () {
+        try {
+            show_uri_on_window (null, "help:moserial", Gdk.CURRENT_TIME);
+        } catch (GLib.Error e) {
+            warning (_("Unable to display help file: %s"), e.message);
         }
-
-        private void quitSizeSave () {
-                windowSizeSave();
-                quitSave();
+    }
+
+    private void showAboutDialog () {
+
+        string license_trans = _(license[0]) + "\n" + _(license[1]) + "\n" + _(license[2]);
+
+        show_about_dialog (gtkWindow,
+                           "version", Config.VERSION,
+                           "copyright", "Copyright © 2009-2018\nMichael J. Chudobiak\n<mjc svn gnome org>",
+                           "comments", _("A serial terminal for the GNOME desktop, optimized for logging and 
file capture."),
+                           "authors", authors,
+                           "translator-credits", _(translators),
+                           "logo-icon-name", "moserial",
+                           "wrap-license", true,
+                           "license", license_trans,
+                           "website", "http://live.gnome.org/moserial";,
+                           "website_label", "http://live.gnome.org/moserial";,
+                           null);
+    }
+
+    private void quitSizeSave () {
+        windowSizeSave ();
+        quitSave ();
+    }
+
+    private bool deleteSaveSize () {
+        windowSizeSave ();
+        quitSave ();
+        Gtk.main_quit ();
+        return true;
+    }
+
+    private bool keyPress (Widget widget, EventKey key) {
+        if (key.keyval == Gdk.keyval_from_name ("Escape")) {
+            AutoScroll.scroll (va1);
+            AutoScroll.scroll (va2);
+            AutoScroll.scroll (va3);
+            AutoScroll.scroll (va4);
+            entry.grab_focus ();
+            entry.set_position (-1);
+            return true;
         }
 
-        private bool deleteSaveSize() {
-                windowSizeSave();
-                quitSave();
-                Gtk.main_quit();
-                return true;
+        return false;
+    }
+
+    private void windowSizeSave () {
+        int width = 0;
+        int height = 0;
+
+        int pos = paned.get_position ();
+        gtkWindow.get_size (out width, out height);
+        profile.saveWindowSize (width, height);
+        profile.saveWindowPanedPosition (pos);
+    }
+
+    private void quitSave () {
+        currentPreferences.saveToProfile (profile);
+        currentSettings.saveToProfile (profile);
+        currentPaths.saveToProfile (profile);
+        if (profileFilename != null) {
+            if (profileChanged) {
+                var dialog = new MessageDialog (gtkWindow, DialogFlags.DESTROY_WITH_PARENT, 
MessageType.QUESTION, ButtonsType.YES_NO, "%s", _("You have changed your setting or preferences. Do you want 
to save these changes to the loaded profile?"));
+                int response = dialog.run ();
+                if (response == Gtk.ResponseType.YES)
+                    saveProfile ();
+                dialog.destroy ();
+            } else {
+                /* Save the profile even if settings or preferences have not
+                   changed, to save the default file locations */
+                saveProfile ();
+            }
         }
-
-       private bool keyPress(Widget widget, EventKey key) {
-               if (key.keyval == Gdk.keyval_from_name ("Escape")) {
-                       AutoScroll.scroll (va1);
-                        AutoScroll.scroll (va2);
-                        AutoScroll.scroll (va3);
-                        AutoScroll.scroll (va4);
-                        entry.grab_focus();
-                        entry.set_position(-1);
-                       return true;
-               }
-
-               return false;
-       }
-
-        private void windowSizeSave () {
-                int width = 0;
-                int height = 0;
-
-                int pos = paned.get_position();
-                gtkWindow.get_size (out width, out height);
-                profile.saveWindowSize(width, height);
-                profile.saveWindowPanedPosition(pos);
+        profile.save (null, gtkWindow);
+        Gtk.main_quit ();
+    }
+
+    private void saveProfile () {
+        currentPreferences.saveToProfile (profile);
+        currentSettings.saveToProfile (profile);
+        currentPaths.saveToProfile (profile);
+        if (profileFilename == null)
+            saveProfileAs ();
+        if (profileFilename == null)
+            return;
+        profile.save (profileFilename, gtkWindow);
+        profileChanged = false;
+        RecentManager recentManager = RecentManager.get_default ();
+        try {
+            recentManager.add_full (GLib.Filename.to_uri (profileFilename), recentData);
+        } catch (GLib.ConvertError e) {
+            stdout.printf ("%s\n", e.message);
+        }
+    }
+
+    private void saveProfileAs () {
+        var dialog = new FileChooserDialog (null, gtkWindow, Gtk.FileChooserAction.SAVE);
+        dialog.add_buttons (Gtk.Stock.CANCEL, Gtk.ResponseType.CANCEL, Gtk.Stock.SAVE, 
Gtk.ResponseType.ACCEPT, null);
+        dialog.set_do_overwrite_confirmation (true);
+        dialog.set_local_only (false);
+        int response = dialog.run ();
+        if (response == Gtk.ResponseType.ACCEPT) {
+            profileFilename = dialog.get_filename ();
+        }
+        dialog.destroy ();
+        if (response == Gtk.ResponseType.ACCEPT)
+            saveProfile ();
+    }
+
+    private void loadProfileOnStartup (string profileFilename) {
+        applyProfile (profileFilename);
+    }
+
+    private void loadProfile () {
+        var dialog = new FileChooserDialog (null, gtkWindow, Gtk.FileChooserAction.OPEN);
+        dialog.add_buttons (Gtk.Stock.CANCEL, Gtk.ResponseType.CANCEL, Gtk.Stock.OPEN, 
Gtk.ResponseType.ACCEPT, null);
+        dialog.set_local_only (false);
+        int response = dialog.run ();
+        if (response == Gtk.ResponseType.ACCEPT) {
+            applyProfile (dialog.get_filename ());
         }
+        dialog.destroy ();
+    }
+
+    private void copy () {
+        if (gtkWindow.get_focus () == (Gtk.Widget)outgoingAsciiTextView || gtkWindow.get_focus () == 
(Gtk.Widget)incomingAsciiTextView || gtkWindow.get_focus () == (Gtk.Widget)outgoingHexTextView || 
gtkWindow.get_focus () == (Gtk.Widget)incomingHexTextView) {
+            TextView tv = (TextView) gtkWindow.get_focus ();
+            tv.buffer.copy_clipboard (Gtk.Clipboard.get (Gdk.SELECTION_CLIPBOARD));
+        } else if (gtkWindow.get_focus () == (Gtk.Widget)entry) {
+            entry.copy_clipboard ();
+        }
+    }
 
-        private void quitSave() {
-                currentPreferences.saveToProfile(profile);
-                currentSettings.saveToProfile(profile);
-               currentPaths.saveToProfile(profile);
-               if (profileFilename != null) {
-                       if (profileChanged) {
-                               var dialog = new MessageDialog (gtkWindow, DialogFlags.DESTROY_WITH_PARENT, 
MessageType.QUESTION, ButtonsType.YES_NO, "%s", _("You have changed your setting or preferences. Do you want 
to save these changes to the loaded profile?"));
-                               int response = dialog.run();
-                               if(response == Gtk.ResponseType.YES)
-                                       saveProfile();
-                               dialog.destroy();
-                       } else {
-                               /* Save the profile even if settings or preferences have not
-                                   changed, to save the default file locations */
-                               saveProfile();
-                       }
-                }
-                profile.save(null, gtkWindow);
-                Gtk.main_quit ();
+    private void cut () {
+        if (gtkWindow.get_focus () == (Gtk.Widget)entry) {
+            entry.cut_clipboard ();
         }
+    }
+
+    private void editMenu () {
+        if (gtkWindow.get_focus () == (Gtk.Widget)outgoingAsciiTextView || gtkWindow.get_focus () == 
(Gtk.Widget)incomingAsciiTextView || gtkWindow.get_focus () == (Gtk.Widget)outgoingHexTextView || 
gtkWindow.get_focus () == (Gtk.Widget)incomingHexTextView) {
+            cutMenuItem.set_sensitive (false);
+            TextView tv = (TextView) gtkWindow.get_focus ();
+            if (tv.buffer.has_selection)
+                copyMenuItem.set_sensitive (true);
+            else
+                copyMenuItem.set_sensitive (false);
+        } else if (gtkWindow.get_focus () == (Gtk.Widget)entry) {
+            if (entry.get_selection_bounds (null, null)) {
+                cutMenuItem.set_sensitive (true);
+                copyMenuItem.set_sensitive (true);
+            } else {
+                cutMenuItem.set_sensitive (false);
+                copyMenuItem.set_sensitive (false);
+            }
+        } else {
+            cutMenuItem.set_sensitive (false);
+            copyMenuItem.set_sensitive (false);
+        }
+    }
 
-       private void saveProfile () {
-                currentPreferences.saveToProfile(profile);
-                currentSettings.saveToProfile(profile);
-               currentPaths.saveToProfile(profile);
-               if(profileFilename==null)
-                       saveProfileAs();
-               if(profileFilename==null)
-                       return;
-               profile.save(profileFilename, gtkWindow);
-               profileChanged=false;
-               RecentManager recentManager = RecentManager.get_default ();
-               try {
-                       recentManager.add_full (GLib.Filename.to_uri(profileFilename), recentData);
-               }
-               catch (GLib.ConvertError e) {
-                       stdout.printf("%s\n", e.message);
-               }
-       }       
-
-       private void saveProfileAs () {
-                var dialog = new FileChooserDialog (null, gtkWindow, Gtk.FileChooserAction.SAVE);
-                dialog.add_buttons(Gtk.Stock.CANCEL, Gtk.ResponseType.CANCEL, Gtk.Stock.SAVE, 
Gtk.ResponseType.ACCEPT, null);
-                dialog.set_do_overwrite_confirmation(true);
-                dialog.set_local_only(false);
-               int response = dialog.run();
-               if(response == Gtk.ResponseType.ACCEPT) {
-                       profileFilename=dialog.get_filename();
-               }
-                dialog.destroy();
-                if(response == Gtk.ResponseType.ACCEPT)
-                       saveProfile();
-       }
-
-       private void loadProfileOnStartup(string profileFilename) {
-               applyProfile(profileFilename);
-       }
-
-       private void loadProfile() {
-                var dialog = new FileChooserDialog (null, gtkWindow, Gtk.FileChooserAction.OPEN);
-                dialog.add_buttons(Gtk.Stock.CANCEL, Gtk.ResponseType.CANCEL, Gtk.Stock.OPEN, 
Gtk.ResponseType.ACCEPT, null);
-                dialog.set_local_only(false);
-               int response = dialog.run();
-               if(response == Gtk.ResponseType.ACCEPT) {
-                       applyProfile(dialog.get_filename());
-               }
-                dialog.destroy();
-       }
-       
-       private void copy() {
-               if(gtkWindow.get_focus()==(Gtk.Widget)outgoingAsciiTextView || 
gtkWindow.get_focus()==(Gtk.Widget)incomingAsciiTextView || 
gtkWindow.get_focus()==(Gtk.Widget)outgoingHexTextView || 
gtkWindow.get_focus()==(Gtk.Widget)incomingHexTextView) {
-                       TextView tv = (TextView)gtkWindow.get_focus();
-                       tv.buffer.copy_clipboard(Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD));
-               }
-               else if(gtkWindow.get_focus()==(Gtk.Widget)entry) {
-                       entry.copy_clipboard();
-               }
-       }
-       
-       private void cut() {
-               if(gtkWindow.get_focus()==(Gtk.Widget)entry) {
-                       entry.cut_clipboard();
-               }
-       }
-       
-       private void editMenu() {
-               if(gtkWindow.get_focus()==(Gtk.Widget)outgoingAsciiTextView || 
gtkWindow.get_focus()==(Gtk.Widget)incomingAsciiTextView || 
gtkWindow.get_focus()==(Gtk.Widget)outgoingHexTextView || 
gtkWindow.get_focus()==(Gtk.Widget)incomingHexTextView) {
-                       cutMenuItem.set_sensitive(false);
-                       TextView tv = (TextView)gtkWindow.get_focus();
-                       if(tv.buffer.has_selection)
-                               copyMenuItem.set_sensitive(true);
-                       else
-                               copyMenuItem.set_sensitive(false);
-               }
-               else if(gtkWindow.get_focus()==(Gtk.Widget)entry){
-                       if(entry.get_selection_bounds(null, null)) {
-                               cutMenuItem.set_sensitive(true);
-                               copyMenuItem.set_sensitive(true);
-                       }
-                       else {
-                               cutMenuItem.set_sensitive(false);
-                               copyMenuItem.set_sensitive(false);
-                       }
-               }
-               else {
-                       cutMenuItem.set_sensitive(false);
-                       copyMenuItem.set_sensitive(false);
-               }
-       }
-       
-       private void paste() {
-               entry.paste_clipboard();
-               if (!entry.has_focus) {
-                       entry.grab_focus();
-                       entry.set_position(-1);
-               }
-       }
-
-       private void clear() {
-                incomingHexTextBuffer.clear();
-                incomingAsciiTextBuffer.set_text("",0);
-                outgoingHexTextBuffer.clear();
-                outgoingAsciiTextBuffer.set_text("",0);
-                entry.set_text("");
-       }
+    private void paste () {
+        entry.paste_clipboard ();
+        if (!entry.has_focus) {
+            entry.grab_focus ();
+            entry.set_position (-1);
+        }
+    }
+
+    private void clear () {
+        incomingHexTextBuffer.clear ();
+        incomingAsciiTextBuffer.set_text ("", 0);
+        outgoingHexTextBuffer.clear ();
+        outgoingAsciiTextBuffer.set_text ("", 0);
+        entry.set_text ("");
+    }
 }
 
diff --git a/src/MoUtils.vala b/src/MoUtils.vala
index 773475f..0f35d58 100644
--- a/src/MoUtils.vala
+++ b/src/MoUtils.vala
@@ -20,96 +20,92 @@
 using GLib;
 using Gtk;
 
-public class MoUtils : GLib.Object
-{
-       public static GLib.File newFile (string path) {
-               string uri;
-                if ("://" in path)
-                       uri = path;
-                else
-                        uri = "file://%s".printf(path);
-                return File.new_for_uri(uri);
-       }
+public class MoUtils : GLib.Object {
+    public static GLib.File newFile (string path) {
+        string uri;
+        if ("://" in path)
+            uri = path;
+        else
+            uri = "file://%s".printf (path);
+        return File.new_for_uri (uri);
+    }
 
-       public static bool fileExists (string path) {
-               GLib.File file=newFile(path);
-               return file.query_exists(null);
-       }
+    public static bool fileExists (string path) {
+        GLib.File file = newFile (path);
+        return file.query_exists (null);
+    }
 
-       public static int64 fileSize (string path) {
-               GLib.File file=newFile(path);
-               try {
-                       GLib.FileInfo info=file.query_info(FileAttribute.STANDARD_SIZE,0,null);
-                       return info.get_size();
-                } catch (GLib.Error e) {
-                        warning("%s", e.message);
-                }
-               return 0;
-       }
+    public static int64 fileSize (string path) {
+        GLib.File file = newFile (path);
+        try {
+            GLib.FileInfo info = file.query_info (FileAttribute.STANDARD_SIZE, 0, null);
+            return info.get_size ();
+        } catch (GLib.Error e) {
+            warning ("%s", e.message);
+        }
+        return 0;
+    }
+
+    public static string getParentFolder (string path) {
+        GLib.File file = newFile (path);
+        GLib.File parent = file.get_parent ();
+        return parent.get_parse_name ();
+    }
 
-        public static string getParentFolder (string path) {
-                GLib.File file=newFile(path);
-               GLib.File parent=file.get_parent();
-               return parent.get_parse_name();
+    public static string ? getKeyString (Profile profile, string group, string key) {
+        string ? result = null;
+        try {
+            result = profile.keyFile.get_string (group, key);
+        } catch (GLib.KeyFileError e) {
+            stdout.printf ("%s\n", e.message);
         }
-       
-       public static string? getKeyString (Profile profile, string group, string key) {
-               string? result=null;
-                try {
-                        result = profile.keyFile.get_string(group, key);
-                }
-                catch (GLib.KeyFileError e) {
-                        stdout.printf("%s\n", e.message);
-                }
-               return result;
-       }
+        return result;
+    }
 
-        public static int getKeyInteger (Profile profile, string group, string key, int default_val) {
-                int result=default_val;
-                try {
-                        result = profile.keyFile.get_integer(group, key);
-                }
-                catch (GLib.KeyFileError e) {
-                        stdout.printf("%s\n", e.message);
-                }
-               return result;
-       }
+    public static int getKeyInteger (Profile profile, string group, string key, int default_val) {
+        int result = default_val;
+        try {
+            result = profile.keyFile.get_integer (group, key);
+        } catch (GLib.KeyFileError e) {
+            stdout.printf ("%s\n", e.message);
+        }
+        return result;
+    }
 
-        public static bool getKeyBoolean (Profile profile, string group, string key, bool default_val) {
-                bool result=default_val;
-                try {
-                        result = profile.keyFile.get_boolean(group, key);
-                }
-                catch (GLib.KeyFileError e) {
-                        stdout.printf("%s\n", e.message);
-                }
-               return result;
-       }
+    public static bool getKeyBoolean (Profile profile, string group, string key, bool default_val) {
+        bool result = default_val;
+        try {
+            result = profile.keyFile.get_boolean (group, key);
+        } catch (GLib.KeyFileError e) {
+            stdout.printf ("%s\n", e.message);
+        }
+        return result;
+    }
 
-       public static string? getLastMessage (string? messages) {
-               string? message=null;
-               string? escaped=messages.escape("");
-               escaped=InputParser.statusReplace(escaped);
-               string[] splitMessages;
-               splitMessages = escaped.split("\\n", 20);
-               for(int x=0; x<GLib.strv_length(splitMessages); x++) {
-                       if(splitMessages[x].length > 5)
-                               message=splitMessages[x];
-               }
-               return message;
-       }
+    public static string ? getLastMessage (string ? messages) {
+        string ? message = null;
+        string ? escaped = messages.escape ("");
+        escaped = InputParser.statusReplace (escaped);
+        string[] splitMessages;
+        splitMessages = escaped.split ("\\n", 20);
+        for (int x = 0; x < GLib.strv_length (splitMessages); x++) {
+            if (splitMessages[x].length > 5)
+                message = splitMessages[x];
+        }
+        return message;
+    }
 
-       public static void populateComboBox (ComboBox Combo, string[] val_array) {
-                Gtk.ListStore Model = new Gtk.ListStore(1, typeof( string ));
-                foreach (string val_item in val_array) {
-                        TreeIter iter;
-                        Model.append(out iter);
-                        Model.set(iter, 0, _(val_item));
-                }
-                Combo.set_model(Model);
-                CellRenderer Cell = new CellRendererText();
-                Combo.pack_start( Cell, true );
-                Combo.set_attributes( Cell, "text", 0 );
-       }
+    public static void populateComboBox (ComboBox Combo, string[] val_array) {
+        Gtk.ListStore Model = new Gtk.ListStore (1, typeof (string));
+        foreach (string val_item in val_array) {
+            TreeIter iter;
+            Model.append (out iter);
+            Model.set (iter, 0, _(val_item));
+        }
+        Combo.set_model (Model);
+        CellRenderer Cell = new CellRendererText ();
+        Combo.pack_start (Cell, true);
+        Combo.set_attributes (Cell, "text", 0);
+    }
 }
 
diff --git a/src/Preferences.vala b/src/Preferences.vala
index 0666b14..e33deb6 100644
--- a/src/Preferences.vala
+++ b/src/Preferences.vala
@@ -18,107 +18,109 @@
  */
 
 using GLib;
-public class Preferences : GLib.Object
-{
-       public static bool DEFAULT_USE_SYSTEM_MONOSPACE_FONT=true;
-       public static string DEFAULT_FONT="Monospace 10";
-       public static string DEFAULT_FONT_COLOR="black";
-       public static string DEFAULT_BACKGROUND_COLOR="white";
-       public static string DEFAULT_HIGHLIGHT_COLOR="#2020ff";
-       public static bool DEFAULT_RECORD_LAUNCH=true;
-       
-       public bool useSystemMonospaceFont {get; construct;}
-       public string? font {get; construct;}
-       public string? fontColor {get; construct;}
-       public string? backgroundColor {get; construct;}
-       public string? highlightColor {get; construct;}
-       public bool recordLaunch {get; construct;}
-       public bool enableTimeout {get; construct;}
-       public int timeout {get; construct;}
-       
-       public Preferences (bool useSystemMonospaceFont, string? font, string? fontColor,string? 
backgroundColor,string? highlightColor, bool recordLaunch, bool enableTimeout, int timeout) {
-               GLib.Object(useSystemMonospaceFont: useSystemMonospaceFont,
-                       font: font, 
-                       recordLaunch: recordLaunch, 
-                       fontColor: fontColor, 
-                       backgroundColor: backgroundColor, 
-                       highlightColor: highlightColor, 
-                       enableTimeout: enableTimeout, 
-                       timeout: timeout);
-       }
-       construct {
-               if(font==null)
-                       font=DEFAULT_FONT;
-               if(fontColor==null)
-                       fontColor=DEFAULT_FONT_COLOR;
-               if(backgroundColor==null)
-                       backgroundColor=DEFAULT_BACKGROUND_COLOR;
-               if(highlightColor==null)
-                       highlightColor=DEFAULT_HIGHLIGHT_COLOR;
-       }
-       public static string getSystemDefaultMonospaceFont() {
+public class Preferences : GLib.Object {
+    public static bool DEFAULT_USE_SYSTEM_MONOSPACE_FONT = true;
+    public static string DEFAULT_FONT = "Monospace 10";
+    public static string DEFAULT_FONT_COLOR = "black";
+    public static string DEFAULT_BACKGROUND_COLOR = "white";
+    public static string DEFAULT_HIGHLIGHT_COLOR = "#2020ff";
+    public static bool DEFAULT_RECORD_LAUNCH = true;
 
-               var settings = new GLib.Settings ("org.gnome.desktop.interface");
-                string value = settings.get_string ("monospace-font-name");
+    public bool useSystemMonospaceFont { get; construct; }
+    public string ? font { get; construct; }
+    public string ? fontColor { get; construct; }
+    public string ? backgroundColor { get; construct; }
+    public string ? highlightColor { get; construct; }
+    public bool recordLaunch { get; construct; }
+    public bool enableTimeout { get; construct; }
+    public int timeout { get; construct; }
 
-               if (value == "") {
-                        warning(_("Unable to retrieve system font setting"));
-                        value = DEFAULT_FONT;
-                }
+    public Preferences (bool useSystemMonospaceFont, string ? font, string ? fontColor, string ? 
backgroundColor, string ? highlightColor, bool recordLaunch, bool enableTimeout, int timeout) {
+        GLib.Object (useSystemMonospaceFont: useSystemMonospaceFont,
+                     font: font,
+                     recordLaunch: recordLaunch,
+                     fontColor: fontColor,
+                     backgroundColor: backgroundColor,
+                     highlightColor: highlightColor,
+                     enableTimeout: enableTimeout,
+                     timeout: timeout);
+    }
 
-                return value;
-       }
-       public static Gdk.Color getGdkColor(string color) {
-               Gdk.Color c;
-               Gdk.Color.parse(color, out c);
-               return c;
-       }
-       public void toString() {
-               stdout.printf("useSystemMonospaceFont: ");
-               if(useSystemMonospaceFont)
-                       stdout.printf("true\n");
-               else
-                       stdout.printf("false\n");
-               stdout.printf("font: %s\n", font);
-               stdout.printf("fontColor: %s\n", fontColor);
-               stdout.printf("backgroundColor: %s\n", backgroundColor);
-               stdout.printf("highlightColor: %s\n", highlightColor);
-               stdout.printf("recordLaunch: ");
-               if(recordLaunch)
-                       stdout.printf("true\n");
-               else
-                       stdout.printf("false\n");
-               
-       }
-       public void saveToProfile(Profile profile) {
-               profile.keyFile.set_boolean("preferences", "use_system_monospace_font", 
useSystemMonospaceFont);
-               profile.keyFile.set_string("preferences", "font", font);
-               profile.keyFile.set_string("preferences", "font_color", fontColor);
-               profile.keyFile.set_string("preferences", "background_color", backgroundColor);
-               profile.keyFile.set_string("preferences", "highlight_color", highlightColor);
-               profile.keyFile.set_boolean("preferences", "record_launch", recordLaunch);
-               profile.keyFile.set_boolean("preferences", "enable_timeout", enableTimeout);
-               profile.keyFile.set_integer("preferences", "timeout", timeout);
-       }
-       public static Preferences loadFromProfile(Profile profile) {
-               bool useSystemMonospaceFont;
-               string? font=null;
-               string? fontColor=null;
-               string? backgroundColor=null;
-               string? highlightColor=null;
-               bool recordLaunch;
-               bool enableTimeout;
-               int timeout;
+    construct {
+        if (font == null)
+            font = DEFAULT_FONT;
+        if (fontColor == null)
+            fontColor = DEFAULT_FONT_COLOR;
+        if (backgroundColor == null)
+            backgroundColor = DEFAULT_BACKGROUND_COLOR;
+        if (highlightColor == null)
+            highlightColor = DEFAULT_HIGHLIGHT_COLOR;
+    }
+    public static string getSystemDefaultMonospaceFont () {
 
-               useSystemMonospaceFont = MoUtils.getKeyBoolean(profile, "preferences", 
"use_system_monospace_font", Preferences.DEFAULT_USE_SYSTEM_MONOSPACE_FONT);
-               font = MoUtils.getKeyString(profile, "preferences", "font");    
-               fontColor = MoUtils.getKeyString(profile, "preferences", "font_color");
-               backgroundColor = MoUtils.getKeyString(profile, "preferences", "background_color");
-               highlightColor = MoUtils.getKeyString(profile, "preferences", "highlight_color");
-               recordLaunch = MoUtils.getKeyBoolean(profile, "preferences", "record_launch", true);
-               enableTimeout = MoUtils.getKeyBoolean(profile, "preferences", "enable_timeout", false);
-               timeout = MoUtils.getKeyInteger(profile, "preferences", "timeout", 30);
-               return new Preferences (useSystemMonospaceFont, font, fontColor, backgroundColor, 
highlightColor, recordLaunch, enableTimeout, timeout);
-       
-       }
+        var settings = new GLib.Settings ("org.gnome.desktop.interface");
+        string value = settings.get_string ("monospace-font-name");
+
+        if (value == "") {
+            warning (_("Unable to retrieve system font setting"));
+            value = DEFAULT_FONT;
+        }
+
+        return value;
+    }
+
+    public static Gdk.Color getGdkColor (string color) {
+        Gdk.Color c;
+        Gdk.Color.parse (color, out c);
+        return c;
+    }
+
+    public void toString () {
+        stdout.printf ("useSystemMonospaceFont: ");
+        if (useSystemMonospaceFont)
+            stdout.printf ("true\n");
+        else
+            stdout.printf ("false\n");
+        stdout.printf ("font: %s\n", font);
+        stdout.printf ("fontColor: %s\n", fontColor);
+        stdout.printf ("backgroundColor: %s\n", backgroundColor);
+        stdout.printf ("highlightColor: %s\n", highlightColor);
+        stdout.printf ("recordLaunch: ");
+        if (recordLaunch)
+            stdout.printf ("true\n");
+        else
+            stdout.printf ("false\n");
+    }
+
+    public void saveToProfile (Profile profile) {
+        profile.keyFile.set_boolean ("preferences", "use_system_monospace_font", useSystemMonospaceFont);
+        profile.keyFile.set_string ("preferences", "font", font);
+        profile.keyFile.set_string ("preferences", "font_color", fontColor);
+        profile.keyFile.set_string ("preferences", "background_color", backgroundColor);
+        profile.keyFile.set_string ("preferences", "highlight_color", highlightColor);
+        profile.keyFile.set_boolean ("preferences", "record_launch", recordLaunch);
+        profile.keyFile.set_boolean ("preferences", "enable_timeout", enableTimeout);
+        profile.keyFile.set_integer ("preferences", "timeout", timeout);
+    }
+
+    public static Preferences loadFromProfile (Profile profile) {
+        bool useSystemMonospaceFont;
+        string ? font = null;
+        string ? fontColor = null;
+        string ? backgroundColor = null;
+        string ? highlightColor = null;
+        bool recordLaunch;
+        bool enableTimeout;
+        int timeout;
+
+        useSystemMonospaceFont = MoUtils.getKeyBoolean (profile, "preferences", "use_system_monospace_font", 
Preferences.DEFAULT_USE_SYSTEM_MONOSPACE_FONT);
+        font = MoUtils.getKeyString (profile, "preferences", "font");
+        fontColor = MoUtils.getKeyString (profile, "preferences", "font_color");
+        backgroundColor = MoUtils.getKeyString (profile, "preferences", "background_color");
+        highlightColor = MoUtils.getKeyString (profile, "preferences", "highlight_color");
+        recordLaunch = MoUtils.getKeyBoolean (profile, "preferences", "record_launch", true);
+        enableTimeout = MoUtils.getKeyBoolean (profile, "preferences", "enable_timeout", false);
+        timeout = MoUtils.getKeyInteger (profile, "preferences", "timeout", 30);
+        return new Preferences (useSystemMonospaceFont, font, fontColor, backgroundColor, highlightColor, 
recordLaunch, enableTimeout, timeout);
+    }
 }
diff --git a/src/PreferencesDialog.vala b/src/PreferencesDialog.vala
index 9728076..ea7ca84 100644
--- a/src/PreferencesDialog.vala
+++ b/src/PreferencesDialog.vala
@@ -18,139 +18,138 @@
  */
 
 using Gtk;
-public class moserial.PreferencesDialog : GLib.Object
-{
-        private Dialog dialog;
-        private Button cancelButton;
-        private Button okButton;
-        private CheckButton systemFont;
-        private FontButton fontButton;
-        private ColorButton fontColorButton;
-        private ColorButton backgroundColorButton;
-        private ColorButton highlightColorButton;
-        private CheckButton recordLaunch;
-        private CheckButton enableTimeout;
-        private SpinButton timeout;
-        public signal void updatePreferences(Preferences preferences);
-        construct {
-                var builder = new Gtk.Builder.from_resource(Config.UIROOT + "preferences.ui");
+public class moserial.PreferencesDialog : GLib.Object {
+    private Dialog dialog;
+    private Button cancelButton;
+    private Button okButton;
+    private CheckButton systemFont;
+    private FontButton fontButton;
+    private ColorButton fontColorButton;
+    private ColorButton backgroundColorButton;
+    private ColorButton highlightColorButton;
+    private CheckButton recordLaunch;
+    private CheckButton enableTimeout;
+    private SpinButton timeout;
+    public signal void updatePreferences (Preferences preferences);
 
-                dialog = (Dialog)builder.get_object("preferences_dialog");
-                okButton = (Button)builder.get_object("preferences_ok");
-                cancelButton = (Button)builder.get_object("preferences_cancel");
-                systemFont = (CheckButton)builder.get_object("preferences_use_system_font");
-                fontButton = (FontButton)builder.get_object("preferences_font_button");
-                fontColorButton = (ColorButton)builder.get_object("preferences_font_color_button");
-                backgroundColorButton = 
(ColorButton)builder.get_object("preferences_background_color_button");
-                highlightColorButton = (ColorButton)builder.get_object("preferences_highlight_color_button");
+    construct {
+        var builder = new Gtk.Builder.from_resource (Config.UIROOT + "preferences.ui");
 
-                recordLaunch = (CheckButton)builder.get_object("preferences_record_launch");
-               recordLaunch.set_tooltip_text (_("If this option is enabled, a recorded file will be opened 
immediately after it is saved, using the default application for the file type. The default application is 
defined by the desktop environment."));
+        dialog = (Dialog) builder.get_object ("preferences_dialog");
+        okButton = (Button) builder.get_object ("preferences_ok");
+        cancelButton = (Button) builder.get_object ("preferences_cancel");
+        systemFont = (CheckButton) builder.get_object ("preferences_use_system_font");
+        fontButton = (FontButton) builder.get_object ("preferences_font_button");
+        fontColorButton = (ColorButton) builder.get_object ("preferences_font_color_button");
+        backgroundColorButton = (ColorButton) builder.get_object ("preferences_background_color_button");
+        highlightColorButton = (ColorButton) builder.get_object ("preferences_highlight_color_button");
 
-                enableTimeout = (CheckButton)builder.get_object("preferences_record_enable_timeout");
-               enableTimeout.set_tooltip_text (_("If this option is enabled, recording will be automatically 
stopped after an adjustable period of inactivity after receiving some data. Moserial will wait indefinitely 
to record the first data byte before activating the inactivity timer."));
+        recordLaunch = (CheckButton) builder.get_object ("preferences_record_launch");
+        recordLaunch.set_tooltip_text (_("If this option is enabled, a recorded file will be opened 
immediately after it is saved, using the default application for the file type. The default application is 
defined by the desktop environment."));
 
-                timeout = (SpinButton)builder.get_object("preferences_record_timeout");
-               timeout.adjustment.lower = 0;
-               timeout.adjustment.upper = 600;
-               timeout.adjustment.step_increment = 1;
-                timeout.adjustment.page_increment = 60;
+        enableTimeout = (CheckButton) builder.get_object ("preferences_record_enable_timeout");
+        enableTimeout.set_tooltip_text (_("If this option is enabled, recording will be automatically 
stopped after an adjustable period of inactivity after receiving some data. Moserial will wait indefinitely 
to record the first data byte before activating the inactivity timer."));
 
-                systemFont.toggled.connect(this.systemFontToggled);
-                enableTimeout.toggled.connect(this.enableTimeoutToggled);
-                okButton.clicked.connect(ok);
-                cancelButton.clicked.connect(cancel);
-                dialog.delete_event.connect(hide);
-        }
-        public void ok(Button button) {
-               hide();
-               bool pSystemFont;
-               string pFont;
-               string pFontColor;
-               string pBackgroundColor;
-               string pHighlightColor;
-               bool pRecordLaunch;
-               bool pEnableTimeout;
-               int pTimeout;
-               if(systemFont.get_active())
-                       pSystemFont=true;
-               else
-                       pSystemFont=false;
-               pFont=fontButton.get_font_name();
-               Gdk.Color c;
-               fontColorButton.get_color(out c);
-               pFontColor=c.to_string();
-               backgroundColorButton.get_color(out c);
-               pBackgroundColor=c.to_string();
-               highlightColorButton.get_color(out c);
-               pHighlightColor=c.to_string();
-               if(recordLaunch.get_active())
-                       pRecordLaunch=true;
-               else
-                       pRecordLaunch=false;
-               if(enableTimeout.get_active())
-                       pEnableTimeout=true;
-               else
-                       pEnableTimeout=false;
-               pTimeout=(int)timeout.get_value();
-               Preferences preferences=new Preferences(pSystemFont, pFont, 
pFontColor,pBackgroundColor,pHighlightColor, pRecordLaunch, pEnableTimeout, pTimeout);
-               this.updatePreferences(preferences);
-        }
-        
-        public void show(Preferences preferences, bool recording) {
-               if(preferences.useSystemMonospaceFont) {
-                       fontButton.set_sensitive(false);
-                       systemFont.set_active(true);
-               }
-               else {
-                       fontButton.set_sensitive(true);
-                       systemFont.set_active(false);
-               }
-               fontButton.set_font_name(preferences.font);
-               fontColorButton.set_color(Preferences.getGdkColor(preferences.fontColor));
-               backgroundColorButton.set_color(Preferences.getGdkColor(preferences.backgroundColor));
-               highlightColorButton.set_color(Preferences.getGdkColor(preferences.highlightColor));
-               if(preferences.recordLaunch)
-                       recordLaunch.set_active(true);
-               else
-                       recordLaunch.set_active(false);
-               if(preferences.enableTimeout) {
-                       enableTimeout.set_active(true);
-                       timeout.set_sensitive(true);
-               }
-               else {
-                       enableTimeout.set_active(false);
-                       timeout.set_sensitive(false);
-               }
-                       if(recording) {
-                       enableTimeout.set_sensitive(false);
-                       timeout.set_sensitive(false);
-               }
-               else
-                       enableTimeout.set_sensitive(true);
-               timeout.set_value(preferences.timeout);                 
-                dialog.show_all();
-        }
-        public void cancel(Widget w) {
-                //currentPreferences=null;
-                hide();
-        }
-        public bool hide() {
-                dialog.hide();
-                return true;
-        }
-        public void systemFontToggled(ToggleButton button)
-        {
-               if(button.get_active())
-                       fontButton.set_sensitive(false);
-               else
-                       fontButton.set_sensitive(true);
+        timeout = (SpinButton) builder.get_object ("preferences_record_timeout");
+        timeout.adjustment.lower = 0;
+        timeout.adjustment.upper = 600;
+        timeout.adjustment.step_increment = 1;
+        timeout.adjustment.page_increment = 60;
+
+        systemFont.toggled.connect (this.systemFontToggled);
+        enableTimeout.toggled.connect (this.enableTimeoutToggled);
+        okButton.clicked.connect (ok);
+        cancelButton.clicked.connect (cancel);
+        dialog.delete_event.connect (hide);
+    }
+    public void ok (Button button) {
+        hide ();
+        bool pSystemFont;
+        string pFont;
+        string pFontColor;
+        string pBackgroundColor;
+        string pHighlightColor;
+        bool pRecordLaunch;
+        bool pEnableTimeout;
+        int pTimeout;
+        if (systemFont.get_active ())
+            pSystemFont = true;
+        else
+            pSystemFont = false;
+        pFont = fontButton.get_font_name ();
+        Gdk.Color c;
+        fontColorButton.get_color (out c);
+        pFontColor = c.to_string ();
+        backgroundColorButton.get_color (out c);
+        pBackgroundColor = c.to_string ();
+        highlightColorButton.get_color (out c);
+        pHighlightColor = c.to_string ();
+        if (recordLaunch.get_active ())
+            pRecordLaunch = true;
+        else
+            pRecordLaunch = false;
+        if (enableTimeout.get_active ())
+            pEnableTimeout = true;
+        else
+            pEnableTimeout = false;
+        pTimeout = (int) timeout.get_value ();
+        Preferences preferences = new Preferences (pSystemFont, pFont, pFontColor, pBackgroundColor, 
pHighlightColor, pRecordLaunch, pEnableTimeout, pTimeout);
+        this.updatePreferences (preferences);
+    }
+
+    public void show (Preferences preferences, bool recording) {
+        if (preferences.useSystemMonospaceFont) {
+            fontButton.set_sensitive (false);
+            systemFont.set_active (true);
+        } else {
+            fontButton.set_sensitive (true);
+            systemFont.set_active (false);
         }
-        public void enableTimeoutToggled(ToggleButton button)
-        {
-               if(button.get_active())
-                       timeout.set_sensitive(true);
-               else
-                       timeout.set_sensitive(false);
+        fontButton.set_font_name (preferences.font);
+        fontColorButton.set_color (Preferences.getGdkColor (preferences.fontColor));
+        backgroundColorButton.set_color (Preferences.getGdkColor (preferences.backgroundColor));
+        highlightColorButton.set_color (Preferences.getGdkColor (preferences.highlightColor));
+        if (preferences.recordLaunch)
+            recordLaunch.set_active (true);
+        else
+            recordLaunch.set_active (false);
+        if (preferences.enableTimeout) {
+            enableTimeout.set_active (true);
+            timeout.set_sensitive (true);
+        } else {
+            enableTimeout.set_active (false);
+            timeout.set_sensitive (false);
         }
+        if (recording) {
+            enableTimeout.set_sensitive (false);
+            timeout.set_sensitive (false);
+        } else
+            enableTimeout.set_sensitive (true);
+        timeout.set_value (preferences.timeout);
+        dialog.show_all ();
+    }
+
+    public void cancel (Widget w) {
+        // currentPreferences=null;
+        hide ();
+    }
+
+    public bool hide () {
+        dialog.hide ();
+        return true;
+    }
+
+    public void systemFontToggled (ToggleButton button) {
+        if (button.get_active ())
+            fontButton.set_sensitive (false);
+        else
+            fontButton.set_sensitive (true);
+    }
+
+    public void enableTimeoutToggled (ToggleButton button) {
+        if (button.get_active ())
+            timeout.set_sensitive (true);
+        else
+            timeout.set_sensitive (false);
+    }
 }
diff --git a/src/Profile.vala b/src/Profile.vala
index cba3024..52d4b8f 100644
--- a/src/Profile.vala
+++ b/src/Profile.vala
@@ -19,95 +19,101 @@
 
 using Gtk;
 
-public class Profile : GLib.Object
-{
-        public KeyFile keyFile;
-        construct {
-                keyFile = new KeyFile();
-        }
-        public void saveWindowSize(int w, int h) {
-                if (w>0)
-                        keyFile.set_integer("window", "width", w);
-                if (h>0)
-                        keyFile.set_integer("window", "height", h);
-        }
-        public void saveWindowPanedPosition(int pos) {
-                keyFile.set_integer("window", "paned_pos", pos);
-        }
-        public int getWindowPanedPosition() {
-                try {
-                        return keyFile.get_integer("window", "paned_pos");
-                } catch (GLib.KeyFileError e) {
-                        return -1;
-                }
-        }
-        public int getWindowWidth() {
-                try {
-                        return keyFile.get_integer("window", "width");
-                } catch (GLib.KeyFileError e) {
-                        return -1;
-                }
+public class Profile : GLib.Object {
+    public KeyFile keyFile;
+    construct {
+        keyFile = new KeyFile ();
+    }
+    public void saveWindowSize (int w, int h) {
+        if (w > 0)
+            keyFile.set_integer ("window", "width", w);
+        if (h > 0)
+            keyFile.set_integer ("window", "height", h);
+    }
+
+    public void saveWindowPanedPosition (int pos) {
+        keyFile.set_integer ("window", "paned_pos", pos);
+    }
+
+    public int getWindowPanedPosition () {
+        try {
+            return keyFile.get_integer ("window", "paned_pos");
+        } catch (GLib.KeyFileError e) {
+            return -1;
         }
-        public int getWindowHeight() {
-                try {
-                        return keyFile.get_integer("window", "height");
-                } catch (GLib.KeyFileError e) {
-                        return -1;
-                }
+    }
+
+    public int getWindowWidth () {
+        try {
+            return keyFile.get_integer ("window", "width");
+        } catch (GLib.KeyFileError e) {
+            return -1;
         }
-        public bool load(string? filename, Gtk.Window window) {
-                string f;
-                bool default_profile=false;
+    }
 
-                if (filename==null) {
-                        default_profile=true;
-                        f="%s/moserial.conf".printf(GLib.Environment.get_user_config_dir());
-                } else
-                        f=filename;
-                try {
-                        keyFile.load_from_file(f, GLib.KeyFileFlags.NONE);
-                        return true;
-                } catch (GLib.KeyFileError e) {
-                        stdout.printf("%s\n", e.message);
-                        /* try loading the non-broken parts of the profile - return true */
-                        return true;
-                } catch (GLib.FileError e) {
-                        if (!default_profile) {
-                                var errorDialog = new MessageDialog (window, 
DialogFlags.DESTROY_WITH_PARENT, MessageType.ERROR, ButtonsType.CLOSE, "%s: %s\n%s", _("Error: Could not open 
file"), filename, e.message);
-                                errorDialog.run();
-                                errorDialog.destroy();
-                        }
-                        return false;
-                }
+    public int getWindowHeight () {
+        try {
+            return keyFile.get_integer ("window", "height");
+        } catch (GLib.KeyFileError e) {
+            return -1;
         }
-        public void toString() {
-                size_t s;
-                stdout.printf("%s\n", keyFile.to_data(out s));
+    }
+
+    public bool load (string ? filename, Gtk.Window window) {
+        string f;
+        bool default_profile = false;
+
+        if (filename == null) {
+            default_profile = true;
+            f = "%s/moserial.conf".printf (GLib.Environment.get_user_config_dir ());
+        } else
+            f = filename;
+        try {
+            keyFile.load_from_file (f, GLib.KeyFileFlags.NONE);
+            return true;
+        } catch (GLib.KeyFileError e) {
+            stdout.printf ("%s\n", e.message);
+            /* try loading the non-broken parts of the profile - return true */
+            return true;
+        } catch (GLib.FileError e) {
+            if (!default_profile) {
+                var errorDialog = new MessageDialog (window, DialogFlags.DESTROY_WITH_PARENT, 
MessageType.ERROR, ButtonsType.CLOSE, "%s: %s\n%s", _("Error: Could not open file"), filename, e.message);
+                errorDialog.run ();
+                errorDialog.destroy ();
+            }
+            return false;
         }
-        public void save(string? filename, Gtk.Window window) {
-                GLib.File? file;
-                FileOutputStream? fos;
-                string f;
-               bool default_profile=false;
-                if (filename==null) {
-                       default_profile=true;
-                        f="%s/moserial.conf".printf(GLib.Environment.get_user_config_dir());
-               } else
-                        f=filename;
-                file = File.new_for_path(f);
-               try {
-                       size_t s;
-                       string data;
-                       fos = file.replace(null, false, GLib.FileCreateFlags.NONE, null);
-                       data = keyFile.to_data(out s);
-                       fos.write(data.data, null);
-               } catch (GLib.Error e) {
-                       stdout.printf("profile.save error: %s\n", e.message);   
-                        if (!default_profile) {
-                                var errorDialog = new MessageDialog (window, 
DialogFlags.DESTROY_WITH_PARENT, MessageType.ERROR, ButtonsType.CLOSE, "%s: %s\n%s", _("Error: Could not open 
file"), filename, e.message);
-                                errorDialog.run();
-                                errorDialog.destroy();
-                        }
-               }
+    }
+
+    public void toString () {
+        size_t s;
+        stdout.printf ("%s\n", keyFile.to_data (out s));
+    }
+
+    public void save (string ? filename, Gtk.Window window) {
+        GLib.File ? file;
+        FileOutputStream ? fos;
+        string f;
+        bool default_profile = false;
+        if (filename == null) {
+            default_profile = true;
+            f = "%s/moserial.conf".printf (GLib.Environment.get_user_config_dir ());
+        } else
+            f = filename;
+        file = File.new_for_path (f);
+        try {
+            size_t s;
+            string data;
+            fos = file.replace (null, false, GLib.FileCreateFlags.NONE, null);
+            data = keyFile.to_data (out s);
+            fos.write (data.data, null);
+        } catch (GLib.Error e) {
+            stdout.printf ("profile.save error: %s\n", e.message);
+            if (!default_profile) {
+                var errorDialog = new MessageDialog (window, DialogFlags.DESTROY_WITH_PARENT, 
MessageType.ERROR, ButtonsType.CLOSE, "%s: %s\n%s", _("Error: Could not open file"), filename, e.message);
+                errorDialog.run ();
+                errorDialog.destroy ();
+            }
         }
+    }
 }
diff --git a/src/ReceiveChooserDialog.vala b/src/ReceiveChooserDialog.vala
index b419c79..ba4bb16 100644
--- a/src/ReceiveChooserDialog.vala
+++ b/src/ReceiveChooserDialog.vala
@@ -18,49 +18,47 @@
  */
 
 using Gtk;
-public class moserial.ReceiveChooserDialog : GLib.Object
-{
-        private FileChooserDialog dialog;
-        public ComboBox protocolCombo;
-        public signal void startTransfer();
-        public string path;
+public class moserial.ReceiveChooserDialog : GLib.Object {
+    private FileChooserDialog dialog;
+    public ComboBox protocolCombo;
+    public signal void startTransfer ();
 
-        construct {
-                var builder = new Gtk.Builder.from_resource(Config.UIROOT + "receive_chooser.ui");
+    public string path;
 
-                dialog = (FileChooserDialog)builder.get_object("receive_chooser_dialog");
+    construct {
+        var builder = new Gtk.Builder.from_resource (Config.UIROOT + "receive_chooser.ui");
 
-                protocolCombo = (ComboBox)builder.get_object("receive_chooser_protocol");
-               MoUtils.populateComboBox (protocolCombo, Rzwrapper.ProtocolStrings);
+        dialog = (FileChooserDialog) builder.get_object ("receive_chooser_dialog");
 
-                dialog.delete_event.connect(hide);
-                dialog.add_buttons(Gtk.Stock.CANCEL, Gtk.ResponseType.CANCEL, Gtk.Stock.OK, 
Gtk.ResponseType.ACCEPT, null);
-                protocolCombo.set_active(Rzwrapper.Protocol.ZMODEM);
-                dialog.response.connect(response);
-        }
+        protocolCombo = (ComboBox) builder.get_object ("receive_chooser_protocol");
+        MoUtils.populateComboBox (protocolCombo, Rzwrapper.ProtocolStrings);
 
-        public void show(string? folder) {
-                if ((folder != null) && MoUtils.fileExists(folder))
-                        dialog.set_current_folder(folder);
-                dialog.run();
-        }
+        dialog.delete_event.connect (hide);
+        dialog.add_buttons (Gtk.Stock.CANCEL, Gtk.ResponseType.CANCEL, Gtk.Stock.OK, 
Gtk.ResponseType.ACCEPT, null);
+        protocolCombo.set_active (Rzwrapper.Protocol.ZMODEM);
+        dialog.response.connect (response);
+    }
 
-        public bool hide() {
-                dialog.hide();
-                return true;
-        }
+    public void show (string ? folder) {
+        if ((folder != null) && MoUtils.fileExists (folder))
+            dialog.set_current_folder (folder);
+        dialog.run ();
+    }
+
+    public bool hide () {
+        dialog.hide ();
+        return true;
+    }
 
-        private void response(Widget w, int r){
-               if(r == Gtk.ResponseType.CANCEL) {
-                       hide();
-               }
-               else if(r == Gtk.ResponseType.ACCEPT) {
-                       hide();
-                       path = dialog.get_current_folder();
-                       startTransfer();
-               }
-               else {
-                       //
-               }                       
+    private void response (Widget w, int r) {
+        if (r == Gtk.ResponseType.CANCEL) {
+            hide ();
+        } else if (r == Gtk.ResponseType.ACCEPT) {
+            hide ();
+            path = dialog.get_current_folder ();
+            startTransfer ();
+        } else {
+            //
         }
+    }
 }
diff --git a/src/ReceiveProgressDialog.vala b/src/ReceiveProgressDialog.vala
index 56bb90c..6d4ee86 100644
--- a/src/ReceiveProgressDialog.vala
+++ b/src/ReceiveProgressDialog.vala
@@ -18,41 +18,40 @@
  */
 
 using Gtk;
-public class moserial.ReceiveProgressDialog : GLib.Object
-{
-        private Dialog dialog;
-        private Button cancelButton;
-        private Gtk.Label status;
-        private ProgressBar progressBar;
-        public signal void transferCanceled();
-        construct {
-                var builder = new Gtk.Builder.from_resource(Config.UIROOT + "receive_progress.ui");
+public class moserial.ReceiveProgressDialog : GLib.Object {
+    private Dialog dialog;
+    private Button cancelButton;
+    private Gtk.Label status;
+    private ProgressBar progressBar;
+    public signal void transferCanceled ();
 
-                dialog = (Dialog)builder.get_object("receive_progress_dialog");
-                cancelButton = (Button)builder.get_object("receive_progress_cancel");
-                cancelButton.clicked.connect(this.cancel);
-                status = (Gtk.Label)builder.get_object("receive_statusbox");
-                progressBar = (ProgressBar)builder.get_object("receive_progressbar");
-                dialog.delete_event.connect(hide);
+    construct {
+        var builder = new Gtk.Builder.from_resource (Config.UIROOT + "receive_progress.ui");
 
-        }
-        public void show() {
-                dialog.show_all();
-                status.set_text("");
-        }
+        dialog = (Dialog) builder.get_object ("receive_progress_dialog");
+        cancelButton = (Button) builder.get_object ("receive_progress_cancel");
+        cancelButton.clicked.connect (this.cancel);
+        status = (Gtk.Label)builder.get_object ("receive_statusbox");
+        progressBar = (ProgressBar) builder.get_object ("receive_progressbar");
+        dialog.delete_event.connect (hide);
+    }
+    public void show () {
+        dialog.show_all ();
+        status.set_text ("");
+    }
 
-        public bool hide() {
-                dialog.hide();
-                return true;
-        }
-        
-        public void updateStatus(GLib.Object o, string newStatus) {
-               status.set_text(newStatus);
-               progressBar.pulse();
-        }
-        
-        public void cancel(GLib.Object o) {
-               //TODO: make canceling transfers actually work
-               transferCanceled();
-        }
+    public bool hide () {
+        dialog.hide ();
+        return true;
+    }
+
+    public void updateStatus (GLib.Object o, string newStatus) {
+        status.set_text (newStatus);
+        progressBar.pulse ();
+    }
+
+    public void cancel (GLib.Object o) {
+        // TODO: make canceling transfers actually work
+        transferCanceled ();
+    }
 }
diff --git a/src/RecordDialog.vala b/src/RecordDialog.vala
index ee68f81..ce3123c 100644
--- a/src/RecordDialog.vala
+++ b/src/RecordDialog.vala
@@ -18,71 +18,68 @@
  */
 
 using Gtk;
-public class moserial.RecordDialog : GLib.Object
-{
-        private FileChooserDialog dialog;
-        private Button cancelButton;
-        private ComboBox streamCombo;
-        public string fileName { get; private set;}
-        public signal void startRecording(string fileName, SerialStreamRecorder.Direction direction);
-        public signal void stopRecording();
-        public SerialStreamRecorder.Direction direction;
-        construct {
-                var builder = new Gtk.Builder.from_resource(Config.UIROOT + "record_dialog.ui");
+public class moserial.RecordDialog : GLib.Object {
+    private FileChooserDialog dialog;
+    private Button cancelButton;
+    private ComboBox streamCombo;
+    public string fileName { get; private set; }
+    public signal void startRecording (string fileName, SerialStreamRecorder.Direction direction);
+    public signal void stopRecording ();
 
-                dialog = (FileChooserDialog)builder.get_object("record_dialog");
-                cancelButton = (Button)builder.get_object("record_cancel");
+    public SerialStreamRecorder.Direction direction;
+    construct {
+        var builder = new Gtk.Builder.from_resource (Config.UIROOT + "record_dialog.ui");
 
-                streamCombo = (ComboBox)builder.get_object("record_stream");
-               MoUtils.populateComboBox (streamCombo, SerialStreamRecorder.DirectionStrings);
-                streamCombo.set_active(SerialStreamRecorder.Direction.INCOMING);
+        dialog = (FileChooserDialog) builder.get_object ("record_dialog");
+        cancelButton = (Button) builder.get_object ("record_cancel");
 
-                dialog.delete_event.connect(hide);
-                dialog.response.connect(response);
-                dialog.add_buttons(Gtk.Stock.CANCEL, Gtk.ResponseType.CANCEL, Gtk.Stock.SAVE, 
Gtk.ResponseType.ACCEPT, null);
-                dialog.set_do_overwrite_confirmation(true);
-               dialog.set_local_only(false);
+        streamCombo = (ComboBox) builder.get_object ("record_stream");
+        MoUtils.populateComboBox (streamCombo, SerialStreamRecorder.DirectionStrings);
+        streamCombo.set_active (SerialStreamRecorder.Direction.INCOMING);
 
-                fileName=null;
-        }
+        dialog.delete_event.connect (hide);
+        dialog.response.connect (response);
+        dialog.add_buttons (Gtk.Stock.CANCEL, Gtk.ResponseType.CANCEL, Gtk.Stock.SAVE, 
Gtk.ResponseType.ACCEPT, null);
+        dialog.set_do_overwrite_confirmation (true);
+        dialog.set_local_only (false);
 
-        public void show(string? folder) {
-               if ((folder != null) && MoUtils.fileExists(folder))
-                       dialog.set_current_folder(folder);
-                dialog.run();
-        }
+        fileName = null;
+    }
 
-        public bool hide() {
-                dialog.hide();
-                return true;
-        }
-        
-        private void response(Widget w, int r){
-               if(r == Gtk.ResponseType.CANCEL) {
-                       fileName=null;
-                       hide();
-                       stopRecording();
-               }
-               else if(r == Gtk.ResponseType.ACCEPT) {
-                       fileName=dialog.get_filename();
-                       switch(streamCombo.get_active())
-                       {
-                               case 0:
-                               default:
-                                       direction=SerialStreamRecorder.Direction.INCOMING;
-                                       break;
-                               case 1:
-                                       direction=SerialStreamRecorder.Direction.OUTGOING;
-                                       break;
-                               case 2:
-                                       direction=SerialStreamRecorder.Direction.BOTH;
-                                       break;
-                       }
-                       hide();
-                       startRecording(this.fileName, direction);
-               }
-               else {
-                       stopRecording();
-               }
+    public void show (string ? folder) {
+        if ((folder != null) && MoUtils.fileExists (folder))
+            dialog.set_current_folder (folder);
+        dialog.run ();
+    }
+
+    public bool hide () {
+        dialog.hide ();
+        return true;
+    }
+
+    private void response (Widget w, int r) {
+        if (r == Gtk.ResponseType.CANCEL) {
+            fileName = null;
+            hide ();
+            stopRecording ();
+        } else if (r == Gtk.ResponseType.ACCEPT) {
+            fileName = dialog.get_filename ();
+            switch (streamCombo.get_active ()) {
+                case 0:
+                default:
+                    direction = SerialStreamRecorder.Direction.INCOMING;
+                    break;
+                case 1:
+                    direction = SerialStreamRecorder.Direction.OUTGOING;
+                    break;
+                case 2:
+                    direction = SerialStreamRecorder.Direction.BOTH;
+                    break;
+            }
+            hide ();
+            startRecording (this.fileName, direction);
+        } else {
+            stopRecording ();
         }
+    }
 }
diff --git a/src/Rzwrapper.vala b/src/Rzwrapper.vala
index d98b4ea..02bcd3a 100644
--- a/src/Rzwrapper.vala
+++ b/src/Rzwrapper.vala
@@ -17,229 +17,211 @@
  *  along with moserial.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-//Class for communicating with the rz program
-public class moserial.Rzwrapper: GLib.Object
-{
-       public enum Protocol {XMODEM, YMODEM, ZMODEM, NULL}
-       public const string[] ProtocolStrings = { GLib.N_("Xmodem"),
-                                                 GLib.N_("Ymodem"),
-                                                  GLib.N_("Zmodem") };
-
-       public Protocol protocol {get; construct;}
-       public SerialConnection? sc {get; construct;}
-        private IOChannel IOChannelInput;
-        private IOChannel IOChannelOutput;
-        private IOChannel IOChannelError;
-        //int inputChannelId;
-       uint outputChannelId;
-        uint errorChannelId;
-        private GLib.Pid pid;
-        public signal void transferComplete();
-        public signal void updateStatus(string newStatus);
-        public bool running=false;
-        public string? path {get; construct;}
-        public string filename {get; construct;}
-       public Rzwrapper(Protocol? protocol, SerialConnection? sc, string? p, string? filename) {
-               Protocol pro = protocol;
-               GLib.Object(protocol: pro, 
-                       sc: sc, path: p, 
-                       filename: filename);
-       }
-       construct {
-               if(protocol==Protocol.NULL || path==null) {
-                       running=false;
-               }
-               else
-               {
-                       string[] argv;
-                       if(protocol==Protocol.XMODEM)
-                               argv = new string[4];
-                       else
-                               argv = new string[3];
-                       argv[0] = "rz";
-                       switch(protocol) {
-                               case Protocol.XMODEM:
-                                       argv[1] = "--xmodem";
-                                       break;
-                               case Protocol.YMODEM:
-                                       argv[1] = "--ymodem";
-                                       break;
-                               case Protocol.ZMODEM:
-                               default:
-                                       argv[1] = "--zmodem";
-                                       break;
-                       
-                       }
-                       argv[2] = "-vv";
-                       if(protocol==Protocol.XMODEM)
-                               argv[3]=filename;
-                       int output;
-                       int error;
-                       int input;
-                       //size_t bytesRead=0;
-                       //char[1000] m_buf = new char[1000];
-               
-                       try{
-                               Process.spawn_async_with_pipes(path, argv, null, SpawnFlags.SEARCH_PATH, 
null, out pid, out input, out output, out error);
-                               IOChannelOutput = new GLib.IOChannel.unix_new(output);
-                               IOChannelInput = new GLib.IOChannel.unix_new(input);
-                               IOChannelError = new GLib.IOChannel.unix_new(error);
-                               IOChannelOutput.set_encoding(null);
-                               IOChannelOutput.set_flags(GLib.IOFlags.NONBLOCK);
-                               IOChannelError.set_encoding(null);
-                               IOChannelError.set_flags(GLib.IOFlags.NONBLOCK);
-                               IOChannelInput.set_encoding(null);
-                               //IOChannelInput.set_flags(GLib.IOFlags.NONBLOCK);
-
-                               outputChannelId = IOChannelOutput.add_watch(GLib.IOCondition.IN, 
this.readBytes);
-                               errorChannelId = IOChannelError.add_watch(GLib.IOCondition.IN, 
this.readError);
-                               running=true;
-                       }
-                       catch(GLib.SpawnError e)
-                       {
-                               running=false;
-                               stdout.printf("spawn error: %s\n", e.message);
-                               var errorDialog = new Gtk.MessageDialog (null, 
Gtk.DialogFlags.DESTROY_WITH_PARENT, Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE, "%s", e.message);
-                               errorDialog.run();
-                               errorDialog.destroy();
-                       }
-                       catch (GLib.IOChannelError e){
-                               stdout.printf("readError() %s\n", e.message);
-                       }
-               }
-       }
-       public void writeChar(uchar byte) {
-               if(running)
-               {
-                       size_t bytesWritten;
-                       char[] b = new char[1];
-                       b[0] = (char)byte;
-                       try {
-                               if(running)
-                                       IOChannelInput.write_chars(b, out bytesWritten);
-                               //if(running)
-                               //      IOChannelInput.flush();
-                       }
-                       catch(GLib.IOChannelError e)
-                       {
-                               shutdown();
-                               stdout.printf("writeChar() %s\n", e.message);
-                       }
-                       catch(GLib.ConvertError e)
-                       {
-                               stdout.printf("%s\n", e.message);
-                       }
-               }
-       }
-       public void flush()
-       {
-               if(running)
-               {
-                       try {
-                               if(running)
-                                       IOChannelInput.flush();
-                       }
-                       catch(GLib.IOChannelError e)
-                       {
-                               shutdown();
-                               stdout.printf("flush() %s\n", e.message);
-                       }
-               }
-       }
-       private bool readError(GLib.IOChannel source, GLib.IOCondition condition) {
-                if(running) {
-                       char[] m_buf = new char[1000];
-                       string message="";
-                       string messages="";
-                       size_t bytesRead=0;
-                       if(!(condition == IOCondition.IN))
-                               return true;
-                       try {
-                               source.read_chars(m_buf, out bytesRead);
-                       }
-                       catch (ConvertError e)          {
-                               stdout.printf("readError() %s\n", e.message);
-                       }
-                       catch (GLib.IOChannelError e){
-                               stdout.printf("readError() %s\n", e.message);
-                       }
-                               
-                       for (int x=0; x<bytesRead; x++) {
-                               unichar c = m_buf[x];
-                               if(c.isprint() || c.isspace())
-                                       messages=messages+"%c".printf(m_buf[x]);
-                       }
-
-                       message = MoUtils.getLastMessage(messages);
-                       if(!(message==""))
-                               updateStatus(message);
-                       if(messages.index_of ("Transfer complete", 0) >= 0) {
-                               shutdown();
-                       }
-                       if(messages.index_of ("Transfer incomplete", 0) >= 0) {
-                               shutdown();
-                       }
-                       return true;
-               }
-               else
-                       return false;
+// Class for communicating with the rz program
+public class moserial.Rzwrapper : GLib.Object {
+    public enum Protocol { XMODEM, YMODEM, ZMODEM, NULL }
+    public const string[] ProtocolStrings = { GLib.N_ ("Xmodem"),
+                                              GLib.N_ ("Ymodem"),
+                                              GLib.N_ ("Zmodem") };
 
+    public Protocol protocol { get; construct; }
+    public SerialConnection ? sc { get; construct; }
+    private IOChannel IOChannelInput;
+    private IOChannel IOChannelOutput;
+    private IOChannel IOChannelError;
+    // int inputChannelId;
+    uint outputChannelId;
+    uint errorChannelId;
+    private GLib.Pid pid;
+    public signal void transferComplete ();
+    public signal void updateStatus (string newStatus);
+
+    public bool running = false;
+    public string ? path { get; construct; }
+    public string filename { get; construct; }
+    public Rzwrapper (Protocol ? protocol, SerialConnection ? sc, string ? p, string ? filename) {
+        Protocol pro = protocol;
+        GLib.Object (protocol: pro,
+                     sc: sc, path: p,
+                     filename: filename);
+    }
+    construct {
+        if (protocol == Protocol.NULL || path == null) {
+            running = false;
+        } else {
+            string[] argv;
+            if (protocol == Protocol.XMODEM)
+                argv = new string[4];
+            else
+                argv = new string[3];
+            argv[0] = "rz";
+            switch (protocol) {
+                case Protocol.XMODEM:
+                    argv[1] = "--xmodem";
+                    break;
+                case Protocol.YMODEM:
+                    argv[1] = "--ymodem";
+                    break;
+                case Protocol.ZMODEM:
+                default:
+                    argv[1] = "--zmodem";
+                    break;
+            }
+            argv[2] = "-vv";
+            if (protocol == Protocol.XMODEM)
+                argv[3] = filename;
+            int output;
+            int error;
+            int input;
+            // size_t bytesRead=0;
+            // char[1000] m_buf = new char[1000];
+
+            try {
+                Process.spawn_async_with_pipes (path, argv, null, SpawnFlags.SEARCH_PATH, null, out pid, out 
input, out output, out error);
+                IOChannelOutput = new GLib.IOChannel.unix_new (output);
+                IOChannelInput = new GLib.IOChannel.unix_new (input);
+                IOChannelError = new GLib.IOChannel.unix_new (error);
+                IOChannelOutput.set_encoding (null);
+                IOChannelOutput.set_flags (GLib.IOFlags.NONBLOCK);
+                IOChannelError.set_encoding (null);
+                IOChannelError.set_flags (GLib.IOFlags.NONBLOCK);
+                IOChannelInput.set_encoding (null);
+                // IOChannelInput.set_flags(GLib.IOFlags.NONBLOCK);
+
+                outputChannelId = IOChannelOutput.add_watch (GLib.IOCondition.IN, this.readBytes);
+                errorChannelId = IOChannelError.add_watch (GLib.IOCondition.IN, this.readError);
+                running = true;
+            } catch (GLib.SpawnError e) {
+                running = false;
+                stdout.printf ("spawn error: %s\n", e.message);
+                var errorDialog = new Gtk.MessageDialog (null, Gtk.DialogFlags.DESTROY_WITH_PARENT, 
Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE, "%s", e.message);
+                errorDialog.run ();
+                errorDialog.destroy ();
+            } catch (GLib.IOChannelError e) {
+                stdout.printf ("readError() %s\n", e.message);
+            }
         }
-        public void transferCanceled(GLib.Object o) {
-               //send cancel string to remote client and rz
-               
-               if(running) {
-                       updateStatus("canceled");
-                       for(int x=0;x<20;x++) {
-                               if(protocol==Protocol.ZMODEM) {
-                                       sc.sendByte('X'&037);
-                                       writeChar('X'&037);
-                               }
-                               else
-                                       sc.sendByte(0x18);
-                       }
-                       GLib.Timeout.add(2000, shutdown_timeout);
-               }
+    }
+    public void writeChar (uchar byte) {
+        if (running) {
+            size_t bytesWritten;
+            char[] b = new char[1];
+            b[0] = (char) byte;
+            try {
+                if (running)
+                    IOChannelInput.write_chars (b, out bytesWritten);
+                // if(running)
+                // IOChannelInput.flush();
+            } catch (GLib.IOChannelError e) {
+                shutdown ();
+                stdout.printf ("writeChar() %s\n", e.message);
+            } catch (GLib.ConvertError e) {
+                stdout.printf ("%s\n", e.message);
+            }
         }
-        private bool shutdown_timeout()
-        {
-               shutdown();
-               return false;
+    }
+
+    public void flush () {
+        if (running) {
+            try {
+                if (running)
+                    IOChannelInput.flush ();
+            } catch (GLib.IOChannelError e) {
+                shutdown ();
+                stdout.printf ("flush() %s\n", e.message);
+            }
         }
-        private void shutdown() {
-               if(running) {
-                       running=false;
-                       GLib.Source.remove(outputChannelId);
-                       GLib.Source.remove(errorChannelId);
-                       Process.close_pid(pid);
-                       transferComplete();
-               }
+    }
+
+    private bool readError (GLib.IOChannel source, GLib.IOCondition condition) {
+        if (running) {
+            char[] m_buf = new char[1000];
+            string message = "";
+            string messages = "";
+            size_t bytesRead = 0;
+            if (!(condition == IOCondition.IN))
+                return true;
+            try {
+                source.read_chars (m_buf, out bytesRead);
+            } catch (ConvertError e) {
+                stdout.printf ("readError() %s\n", e.message);
+            } catch (GLib.IOChannelError e) {
+                stdout.printf ("readError() %s\n", e.message);
+            }
+
+            for (int x = 0; x < bytesRead; x++) {
+                unichar c = m_buf[x];
+                if (c.isprint () || c.isspace ())
+                    messages = messages + "%c".printf (m_buf[x]);
+            }
+
+            message = MoUtils.getLastMessage (messages);
+            if (!(message == ""))
+                updateStatus (message);
+            if (messages.index_of ("Transfer complete", 0) >= 0) {
+                shutdown ();
+            }
+            if (messages.index_of ("Transfer incomplete", 0) >= 0) {
+                shutdown ();
+            }
+            return true;
+        } else
+            return false;
+    }
+
+    public void transferCanceled (GLib.Object o) {
+        // send cancel string to remote client and rz
+
+        if (running) {
+            updateStatus ("canceled");
+            for (int x = 0; x < 20; x++) {
+                if (protocol == Protocol.ZMODEM) {
+                    sc.sendByte ('X' & 037);
+                    writeChar ('X' & 037);
+                } else
+                    sc.sendByte (0x18);
+            }
+            GLib.Timeout.add (2000, shutdown_timeout);
         }
-        private bool readBytes(GLib.IOChannel source, GLib.IOCondition condition) {
-                if(running) {
-                       char[] m_buf = new char[1000];
-
-                       size_t bytesRead=0;
-                       if(!(condition == IOCondition.IN))
-                               return true;
-                       try {
-                               source.read_chars(m_buf, out bytesRead);
-                       }
-                       catch (ConvertError e)          {
-                               stdout.printf("readBytes() %s\n", e.message);
-                       }
-                       catch (GLib.IOChannelError e){
-                               stdout.printf("readError() %s\n", e.message);
-                       }
-                       for (int x=0; x<bytesRead; x++) {
-                               sc.sendByte(m_buf[x]);
-                               //sendByte(m_buf[x]);
-                               //outgoingHexTextBuffer.add(m_buf[x]);
-                       }
-               
-                       return true;
-                }
-                else
-                       return false;
+    }
+
+    private bool shutdown_timeout () {
+        shutdown ();
+        return false;
+    }
+
+    private void shutdown () {
+        if (running) {
+            running = false;
+            GLib.Source.remove (outputChannelId);
+            GLib.Source.remove (errorChannelId);
+            Process.close_pid (pid);
+            transferComplete ();
         }
+    }
+
+    private bool readBytes (GLib.IOChannel source, GLib.IOCondition condition) {
+        if (running) {
+            char[] m_buf = new char[1000];
+
+            size_t bytesRead = 0;
+            if (!(condition == IOCondition.IN))
+                return true;
+            try {
+                source.read_chars (m_buf, out bytesRead);
+            } catch (ConvertError e) {
+                stdout.printf ("readBytes() %s\n", e.message);
+            } catch (GLib.IOChannelError e) {
+                stdout.printf ("readError() %s\n", e.message);
+            }
+            for (int x = 0; x < bytesRead; x++) {
+                sc.sendByte (m_buf[x]);
+                // sendByte(m_buf[x]);
+                // outgoingHexTextBuffer.add(m_buf[x]);
+            }
+
+            return true;
+        } else
+            return false;
+    }
 }
diff --git a/src/SendChooserDialog.vala b/src/SendChooserDialog.vala
index 4b365d7..9828234 100644
--- a/src/SendChooserDialog.vala
+++ b/src/SendChooserDialog.vala
@@ -18,48 +18,46 @@
  */
 
 using Gtk;
-public class moserial.SendChooserDialog : GLib.Object
-{
-        private FileChooserDialog dialog;
-        public ComboBox protocolCombo;
-        public signal void startTransfer();
-        public string filename;
-        construct {
-                var builder = new Gtk.Builder.from_resource(Config.UIROOT + "send_chooser_dialog.ui");
+public class moserial.SendChooserDialog : GLib.Object {
+    private FileChooserDialog dialog;
+    public ComboBox protocolCombo;
+    public signal void startTransfer ();
 
-                dialog = (FileChooserDialog)builder.get_object("send_chooser_dialog");
+    public string filename;
+    construct {
+        var builder = new Gtk.Builder.from_resource (Config.UIROOT + "send_chooser_dialog.ui");
 
-                protocolCombo = (ComboBox)builder.get_object("send_chooser_protocol");
-               MoUtils.populateComboBox (protocolCombo, Szwrapper.ProtocolStrings);
+        dialog = (FileChooserDialog) builder.get_object ("send_chooser_dialog");
 
-                dialog.delete_event.connect(hide);
-                dialog.add_buttons(Gtk.Stock.CANCEL, Gtk.ResponseType.CANCEL, Gtk.Stock.OK, 
Gtk.ResponseType.ACCEPT, null);
-                protocolCombo.set_active(Szwrapper.Protocol.ZMODEM);
-                dialog.response.connect(response);
-        }
+        protocolCombo = (ComboBox) builder.get_object ("send_chooser_protocol");
+        MoUtils.populateComboBox (protocolCombo, Szwrapper.ProtocolStrings);
 
-        public void show(string? folder) {
-                if ((folder != null) && MoUtils.fileExists(folder))
-                        dialog.set_current_folder(folder);
-                dialog.run();
-        }
+        dialog.delete_event.connect (hide);
+        dialog.add_buttons (Gtk.Stock.CANCEL, Gtk.ResponseType.CANCEL, Gtk.Stock.OK, 
Gtk.ResponseType.ACCEPT, null);
+        protocolCombo.set_active (Szwrapper.Protocol.ZMODEM);
+        dialog.response.connect (response);
+    }
 
-        public bool hide() {
-                dialog.hide();
-                return true;
-        }
+    public void show (string ? folder) {
+        if ((folder != null) && MoUtils.fileExists (folder))
+            dialog.set_current_folder (folder);
+        dialog.run ();
+    }
+
+    public bool hide () {
+        dialog.hide ();
+        return true;
+    }
 
-        private void response(Widget w, int r){
-               if(r == Gtk.ResponseType.CANCEL) {
-                       hide();
-               }
-               else if(r == Gtk.ResponseType.ACCEPT) {
-                       hide();
-                       filename = dialog.get_filename();
-                       startTransfer();
-               }
-               else {
-                       //
-               }
+    private void response (Widget w, int r) {
+        if (r == Gtk.ResponseType.CANCEL) {
+            hide ();
+        } else if (r == Gtk.ResponseType.ACCEPT) {
+            hide ();
+            filename = dialog.get_filename ();
+            startTransfer ();
+        } else {
+            //
         }
+    }
 }
diff --git a/src/SendProgressDialog.vala b/src/SendProgressDialog.vala
index c0f2bd7..ae4238d 100644
--- a/src/SendProgressDialog.vala
+++ b/src/SendProgressDialog.vala
@@ -18,41 +18,40 @@
  */
 
 using Gtk;
-public class moserial.SendProgressDialog : GLib.Object
-{
-        private Dialog dialog;
-        private Button cancelButton;
-        private Gtk.Label status;
-        private ProgressBar progressBar;
-        public signal void transferCanceled();
-        construct {
-                var builder = new Gtk.Builder.from_resource(Config.UIROOT + "send_progress_dialog.ui");
+public class moserial.SendProgressDialog : GLib.Object {
+    private Dialog dialog;
+    private Button cancelButton;
+    private Gtk.Label status;
+    private ProgressBar progressBar;
+    public signal void transferCanceled ();
 
-                dialog = (Dialog)builder.get_object("send_progress_dialog");
-                cancelButton = (Button)builder.get_object("send_progress_cancel");
-                cancelButton.clicked.connect( this.cancel);
-                status = (Gtk.Label)builder.get_object("send_statusbox");
-                progressBar = (ProgressBar)builder.get_object("send_progressbar");
-                dialog.delete_event.connect(hide);
+    construct {
+        var builder = new Gtk.Builder.from_resource (Config.UIROOT + "send_progress_dialog.ui");
 
-        }
-        public void show() {
-                dialog.show_all();
-                status.set_text(_("Waiting for remote host"));
-        }
+        dialog = (Dialog) builder.get_object ("send_progress_dialog");
+        cancelButton = (Button) builder.get_object ("send_progress_cancel");
+        cancelButton.clicked.connect (this.cancel);
+        status = (Gtk.Label)builder.get_object ("send_statusbox");
+        progressBar = (ProgressBar) builder.get_object ("send_progressbar");
+        dialog.delete_event.connect (hide);
+    }
+    public void show () {
+        dialog.show_all ();
+        status.set_text (_("Waiting for remote host"));
+    }
 
-        public bool hide() {
-                dialog.hide();
-                return true;
-        }
-        
-        public void updateStatus(GLib.Object o, string newStatus) {
-               status.set_text(newStatus);
-               progressBar.pulse();
-        }
-        
-        public void cancel(GLib.Object o) {
-               //TODO: make canceling transfers actually work
-               transferCanceled();
-        }
+    public bool hide () {
+        dialog.hide ();
+        return true;
+    }
+
+    public void updateStatus (GLib.Object o, string newStatus) {
+        status.set_text (newStatus);
+        progressBar.pulse ();
+    }
+
+    public void cancel (GLib.Object o) {
+        // TODO: make canceling transfers actually work
+        transferCanceled ();
+    }
 }
diff --git a/src/SerialConnection.vala b/src/SerialConnection.vala
index f5025c0..d4788dc 100644
--- a/src/SerialConnection.vala
+++ b/src/SerialConnection.vala
@@ -20,277 +20,272 @@
 using Posix;
 using Linux;
 
-public class moserial.SerialConnection : GLib.Object
-{
-        private bool connected;
-       public ulong tx=0;
-       public ulong rx=0;
-       public ulong nonprintable=0;
-       public bool forced_hex_view=false;
-       public bool lastRxCharWasCR=false;
-
-       public string echoReference="";
-       public string echoCompare="";
-
-        private Posix.termios newtio;
-        private Posix.termios restoretio;
-        private int m_fd=-1;
-        private GLib.IOChannel IOChannelFd;
-        public signal void newData(uchar[] data, int size);
-        private  int flags=0;
-
-       public enum LineEnd{ CRLF, CR, LF, TAB, ESC, NONE }
-       public const string[] LineEndStrings = { GLib.N_("CR+LF end"), 
-                                                GLib.N_("CR end"), 
-                                                GLib.N_("LF end"), 
-                                                GLib.N_("TAB end"), 
-                                                GLib.N_("ESC end"), 
-                                                GLib.N_("No end") };
-       public const string[] LineEndValues = {"\r\n", "\r", "\n", "\t", "\x1b", ""}; 
-       public const int max_buf_size = 128;
-
-
-       uint? sourceId;
-       bool localEcho;
-        public bool doConnect (Settings settings) {
-
-                if (settings.accessMode==Settings.AccessMode.READWRITE)
-                        flags=Posix.O_RDWR;
-                else if (settings.accessMode==Settings.AccessMode.READONLY)
-                        flags=Posix.O_RDONLY;
-                else
-                        flags=Posix.O_WRONLY;
-
-                m_fd = Posix.open(settings.device, flags | Posix.O_NONBLOCK);
-                if (m_fd<0) {
-                        m_fd=-1;
-                        // TODO display error in gui
-                        return false;
-                }
-                Posix.tcflush(m_fd, Posix.TCIOFLUSH);
-
-                tcgetattr(m_fd, out restoretio);
-                applySettings(settings);
-                tcsetattr(m_fd, Posix.TCSANOW, newtio);
-
-                connected=true;
-
-                IOChannelFd = new GLib.IOChannel.unix_new(m_fd);
-                sourceId = IOChannelFd.add_watch(GLib.IOCondition.IN, this.readBytes);
-                localEcho=settings.localEcho;
-                return true;
-        }
-        
-        public void sendByte(uchar byte)
-        {
-               if(connected)
-               {
-                       uchar[] b = new uchar[1];
-                       b[0]=byte;
-                       size_t x = Posix.write(m_fd, b, 1);
-                       //Posix.tcdrain(m_fd);
-                       
-                       tx=tx+x;
-               }
-        }
-        
-        public void sendBytes(char[] bytes, size_t size)
-        {
-                if(connected)
-               {
-                       size_t x = Posix.write(m_fd, bytes, size);
-                       Posix.tcdrain(m_fd);
-                       tx=tx+x;
-               }
+public class moserial.SerialConnection : GLib.Object {
+    private bool connected;
+    public ulong tx = 0;
+    public ulong rx = 0;
+    public ulong nonprintable = 0;
+    public bool forced_hex_view = false;
+    public bool lastRxCharWasCR = false;
+
+    public string echoReference = "";
+    public string echoCompare = "";
+
+    private Posix.termios newtio;
+    private Posix.termios restoretio;
+    private int m_fd = -1;
+    private GLib.IOChannel IOChannelFd;
+    public signal void newData (uchar[] data, int size);
+
+    private int flags = 0;
+
+    public enum LineEnd { CRLF, CR, LF, TAB, ESC, NONE }
+    public const string[] LineEndStrings = { GLib.N_ ("CR+LF end"),
+                                             GLib.N_ ("CR end"),
+                                             GLib.N_ ("LF end"),
+                                             GLib.N_ ("TAB end"),
+                                             GLib.N_ ("ESC end"),
+                                             GLib.N_ ("No end") };
+    public const string[] LineEndValues = { "\r\n", "\r", "\n", "\t", "\x1b", "" };
+    public const int max_buf_size = 128;
+
+
+    uint ? sourceId;
+    bool localEcho;
+    public bool doConnect (Settings settings) {
+
+        if (settings.accessMode == Settings.AccessMode.READWRITE)
+            flags = Posix.O_RDWR;
+        else if (settings.accessMode == Settings.AccessMode.READONLY)
+            flags = Posix.O_RDONLY;
+        else
+            flags = Posix.O_WRONLY;
+
+        m_fd = Posix.open (settings.device, flags | Posix.O_NONBLOCK);
+        if (m_fd < 0) {
+            m_fd = -1;
+            // TODO display error in gui
+            return false;
         }
+        Posix.tcflush (m_fd, Posix.TCIOFLUSH);
 
-        public void doDisconnect () {
-               if(connected) {
-                       GLib.Source.remove(sourceId);
-                       sourceId = null;
-                       try {
-                       IOChannelFd.shutdown(true);
-                       }
-                       catch (GLib.IOChannelError e){
-                               warning("%s", e.message);
-                       }
-                       IOChannelFd=null;
-                       connected=false;
-                       forced_hex_view=false;
-                       lastRxCharWasCR=false;
-                       tx=rx=nonprintable=0;
-                       echoReference="";
-                       echoCompare="";
-                       tcsetattr(m_fd, Posix.TCSANOW, newtio);
-                       Posix.close(m_fd);
-               }
-        }
+        tcgetattr (m_fd, out restoretio);
+        applySettings (settings);
+        tcsetattr (m_fd, Posix.TCSANOW, newtio);
 
-        private bool readBytes(GLib.IOChannel source, GLib.IOCondition condition) {
-                uchar[] m_buf = new uchar[max_buf_size];
-                int bytesRead=(int)Posix.read(m_fd, m_buf, max_buf_size);
-               rx += (ulong) bytesRead;
+        connected = true;
 
-                while(Gtk.events_pending() || Gdk.events_pending())
-                        Gtk.main_iteration_do(false);
+        IOChannelFd = new GLib.IOChannel.unix_new (m_fd);
+        sourceId = IOChannelFd.add_watch (GLib.IOCondition.IN, this.readBytes);
+        localEcho = settings.localEcho;
+        return true;
+    }
 
-                if (bytesRead<0)
-                        return false;
+    public void sendByte (uchar byte) {
+        if (connected) {
+            uchar[] b = new uchar[1];
+            b[0] = byte;
+            size_t x = Posix.write (m_fd, b, 1);
+            // Posix.tcdrain(m_fd);
 
-                uchar[] sized_buf = new uchar[bytesRead];
-               for (int x=0; x<bytesRead; x++) {
-                       sized_buf[x] = m_buf[x];
-                }
+            tx = tx + x;
+        }
+    }
 
-                newData(sized_buf, bytesRead);
-                if(localEcho)
-                       sendBytes((char[])sized_buf, bytesRead);
-                return connected;
+    public void sendBytes (char[] bytes, size_t size) {
+        if (connected) {
+            size_t x = Posix.write (m_fd, bytes, size);
+            Posix.tcdrain (m_fd);
+            tx = tx + x;
+        }
+    }
+
+    public void doDisconnect () {
+        if (connected) {
+            GLib.Source.remove (sourceId);
+            sourceId = null;
+            try {
+                IOChannelFd.shutdown (true);
+            } catch (GLib.IOChannelError e) {
+                warning ("%s", e.message);
+            }
+            IOChannelFd = null;
+            connected = false;
+            forced_hex_view = false;
+            lastRxCharWasCR = false;
+            tx = rx = nonprintable = 0;
+            echoReference = "";
+            echoCompare = "";
+            tcsetattr (m_fd, Posix.TCSANOW, newtio);
+            Posix.close (m_fd);
         }
-       
-        private void applySettings(Settings settings) {
-                //BaudRate
-                uint baudRate = 0;
-                switch (settings.baudRate) {
-                case 300:
-                        baudRate=Posix.B300;
-                        break;
-                case 600:
-                        baudRate=Posix.B600;
-                        break;
-                case 1200:
-                        baudRate=Posix.B1200;
-                        break;
-                case 2400:
-                        baudRate=Posix.B2400;
-                        break;
-                case 4800:
-                        baudRate=Posix.B4800;
-                        break;
-                case 9600:
-                        baudRate=Posix.B9600;
-                        break;
-                case 19200:
-                        baudRate=Posix.B19200;
-                        break;
-                case 38400:
-                        baudRate=Posix.B38400;
-                        break;
-                case 57600:
-                        baudRate=Posix.B57600;
-                        break;
-                case 115200:
-                        baudRate=Posix.B115200;
-                        break;
-                case 230400:
-                        baudRate=Posix.B230400;
-                        break;
-                case 460800:
-                        baudRate=Linux.Termios.B460800;
-                        break;
-                case 576000:
-                        baudRate=Linux.Termios.B576000;
-                        break;
-                case 921600:
-                        baudRate=Linux.Termios.B921600;
-                        break;
-                case 1000000:
-                        baudRate=Linux.Termios.B1000000;
-                        break;
-                case 2000000:
-                        baudRate=Linux.Termios.B2000000;
-                        break;
-                }
-
-                Posix.cfsetospeed(ref newtio, baudRate);
-                Posix.cfsetispeed(ref newtio, baudRate);
-
-                //DataBits
-                int dataBits;
-                dataBits = settings.dataBits;
-                // We generate mark and space parity
-                if (settings.dataBits == 7 && (settings.parity==Settings.Parity.MARK || 
settings.parity==Settings.Parity.SPACE))
-                        dataBits=8;
-
-                switch (dataBits) {
-                case 5:
-                        newtio.c_cflag = (newtio.c_cflag & ~Posix.CSIZE) | Posix.CS5;
-                        break;
-                case 6:
-                        newtio.c_cflag = (newtio.c_cflag & ~Posix.CSIZE) | Posix.CS6;
-                        break;
-                case 7:
-                        newtio.c_cflag = (newtio.c_cflag & ~Posix.CSIZE) | Posix.CS7;
-                        break;
-                case 8:
-                default:
-                        newtio.c_cflag = (newtio.c_cflag & ~Posix.CSIZE) | Posix.CS8;
-                        break;
-                }
-                newtio.c_cflag |= Posix.CLOCAL | Posix.CREAD;
-
-                //Parity
-                newtio.c_cflag &= ~(Posix.PARENB | Posix.PARODD);
-                if (settings.parity==Settings.Parity.EVEN)
-                        newtio.c_cflag |= Posix.PARENB;
-                else if (settings.parity==Settings.Parity.ODD)
-                        newtio.c_cflag |= (Posix.PARENB | Posix.PARODD);
-
-                newtio.c_cflag &= ~Linux.Termios.CRTSCTS;
-
-
-                //Stop Bits
-                if (settings.stopBits==2)
-                        newtio.c_cflag |= Posix.CSTOPB;
-                else
-                        newtio.c_cflag &= ~Posix.CSTOPB;
-
-                //Input Settings
-                newtio.c_iflag = Posix.IGNBRK;
-
-                //Handshake
-                if (settings.handshake==Settings.Handshake.SOFTWARE || settings.handshake == 
Settings.Handshake.BOTH)
-                        newtio.c_iflag |= Posix.IXON | Posix.IXOFF;
-                else
-                        newtio.c_iflag &= ~(Posix.IXON | Posix.IXOFF | Posix.IXANY);
-
-                newtio.c_lflag = 0;
-                newtio.c_oflag = 0;
-
-                newtio.c_cc[Posix.VTIME]=1;
-                newtio.c_cc[Posix.VMIN]=1;
-       
-       
-               //Some other port settings from minicom.
-               
-//             newtio.c_iflag &= ~(IGNBRK | IGNCR | INLCR | ICRNL | IUCLC | IXANY | IXON | IXOFF | INPCK | 
ISTRIP);
-               //newtio.c_iflag &= ~(Posix.IGNBRK | Posix.IGNCR | Posix.InputMode.INLCR | 
Posix.InputMode.ICRNL | Posix.IXANY | Posix.IXON | Posix.IXOFF | Posix.INPCK | Posix.ISTRIP);
-               //newtio.c_iflag |= (Posix.BRKINT | Posix.IGNPAR);
-               //newtio.c_oflag &= ~Posix.OPOST;
-               //newtio.c_lflag &= ~(XCASE|ECHONL|NOFLSH);
-               newtio.c_lflag &= ~(Posix.ECHONL|Posix.NOFLSH);
-               //newtio.c_lflag &= ~(Posix.ICANON | Posix.ISIG | Posix.ECHO);
-               //newtio.c_cflag |= CREAD;
-               //newtio.c_cc[VTIME] = 5;
-
-                int mcs=0;
-                Posix.ioctl(m_fd, Linux.Termios.TIOCMGET, out mcs);
-                mcs |= Linux.Termios.TIOCM_RTS;
-                Posix.ioctl(m_fd, Linux.Termios.TIOCMSET, out mcs);
-
-                if (settings.handshake == Settings.Handshake.HARDWARE || settings.handshake == 
Settings.Handshake.BOTH)
-                        newtio.c_cflag |= Linux.Termios.CRTSCTS;
-                else
-                        newtio.c_cflag &= ~Linux.Termios.CRTSCTS;
+    }
+
+    private bool readBytes (GLib.IOChannel source, GLib.IOCondition condition) {
+        uchar[] m_buf = new uchar[max_buf_size];
+        int bytesRead = (int) Posix.read (m_fd, m_buf, max_buf_size);
+        rx += (ulong) bytesRead;
+
+        while (Gtk.events_pending () || Gdk.events_pending ())
+            Gtk.main_iteration_do (false);
+
+        if (bytesRead < 0)
+            return false;
+
+        uchar[] sized_buf = new uchar[bytesRead];
+        for (int x = 0; x < bytesRead; x++) {
+            sized_buf[x] = m_buf[x];
         }
 
-        public string getBytecountbarString() {
-                string r;
+        newData (sized_buf, bytesRead);
+        if (localEcho)
+            sendBytes ((char[]) sized_buf, bytesRead);
+        return connected;
+    }
+
+    private void applySettings (Settings settings) {
+        // BaudRate
+        uint baudRate = 0;
+        switch (settings.baudRate) {
+            case 300:
+                baudRate = Posix.B300;
+                break;
+            case 600:
+                baudRate = Posix.B600;
+                break;
+            case 1200:
+                baudRate = Posix.B1200;
+                break;
+            case 2400:
+                baudRate = Posix.B2400;
+                break;
+            case 4800:
+                baudRate = Posix.B4800;
+                break;
+            case 9600:
+                baudRate = Posix.B9600;
+                break;
+            case 19200:
+                baudRate = Posix.B19200;
+                break;
+            case 38400:
+                baudRate = Posix.B38400;
+                break;
+            case 57600:
+                baudRate = Posix.B57600;
+                break;
+            case 115200:
+                baudRate = Posix.B115200;
+                break;
+            case 230400:
+                baudRate = Posix.B230400;
+                break;
+            case 460800:
+                baudRate = Linux.Termios.B460800;
+                break;
+            case 576000:
+                baudRate = Linux.Termios.B576000;
+                break;
+            case 921600:
+                baudRate = Linux.Termios.B921600;
+                break;
+            case 1000000:
+                baudRate = Linux.Termios.B1000000;
+                break;
+            case 2000000:
+                baudRate = Linux.Termios.B2000000;
+                break;
+        }
 
-               if (nonprintable > 0)
-                       r = _("TX: %lu, RX: %lu (%lu unprintable)").printf(tx, rx, nonprintable);
-               else
-                       r = _("TX: %lu, RX: %lu").printf(tx, rx);
-                return r;
+        Posix.cfsetospeed (ref newtio, baudRate);
+        Posix.cfsetispeed (ref newtio, baudRate);
+
+        // DataBits
+        int dataBits;
+        dataBits = settings.dataBits;
+        // We generate mark and space parity
+        if (settings.dataBits == 7 && (settings.parity == Settings.Parity.MARK || settings.parity == 
Settings.Parity.SPACE))
+            dataBits = 8;
+
+        switch (dataBits) {
+            case 5:
+                newtio.c_cflag = (newtio.c_cflag & ~Posix.CSIZE) | Posix.CS5;
+                break;
+            case 6:
+                newtio.c_cflag = (newtio.c_cflag & ~Posix.CSIZE) | Posix.CS6;
+                break;
+            case 7:
+                newtio.c_cflag = (newtio.c_cflag & ~Posix.CSIZE) | Posix.CS7;
+                break;
+            case 8:
+            default:
+                newtio.c_cflag = (newtio.c_cflag & ~Posix.CSIZE) | Posix.CS8;
+                break;
         }
+        newtio.c_cflag |= Posix.CLOCAL | Posix.CREAD;
+
+        // Parity
+        newtio.c_cflag &= ~(Posix.PARENB | Posix.PARODD);
+        if (settings.parity == Settings.Parity.EVEN)
+            newtio.c_cflag |= Posix.PARENB;
+        else if (settings.parity == Settings.Parity.ODD)
+            newtio.c_cflag |= (Posix.PARENB | Posix.PARODD);
+
+        newtio.c_cflag &= ~Linux.Termios.CRTSCTS;
+
+
+        // Stop Bits
+        if (settings.stopBits == 2)
+            newtio.c_cflag |= Posix.CSTOPB;
+        else
+            newtio.c_cflag &= ~Posix.CSTOPB;
+
+        // Input Settings
+        newtio.c_iflag = Posix.IGNBRK;
+
+        // Handshake
+        if (settings.handshake == Settings.Handshake.SOFTWARE || settings.handshake == 
Settings.Handshake.BOTH)
+            newtio.c_iflag |= Posix.IXON | Posix.IXOFF;
+        else
+            newtio.c_iflag &= ~(Posix.IXON | Posix.IXOFF | Posix.IXANY);
+
+        newtio.c_lflag = 0;
+        newtio.c_oflag = 0;
+
+        newtio.c_cc[Posix.VTIME] = 1;
+        newtio.c_cc[Posix.VMIN] = 1;
+
+
+        // Some other port settings from minicom.
+
+// newtio.c_iflag &= ~(IGNBRK | IGNCR | INLCR | ICRNL | IUCLC | IXANY | IXON | IXOFF | INPCK | ISTRIP);
+        // newtio.c_iflag &= ~(Posix.IGNBRK | Posix.IGNCR | Posix.InputMode.INLCR | Posix.InputMode.ICRNL | 
Posix.IXANY | Posix.IXON | Posix.IXOFF | Posix.INPCK | Posix.ISTRIP);
+        // newtio.c_iflag |= (Posix.BRKINT | Posix.IGNPAR);
+        // newtio.c_oflag &= ~Posix.OPOST;
+        // newtio.c_lflag &= ~(XCASE|ECHONL|NOFLSH);
+        newtio.c_lflag &= ~(Posix.ECHONL | Posix.NOFLSH);
+        // newtio.c_lflag &= ~(Posix.ICANON | Posix.ISIG | Posix.ECHO);
+        // newtio.c_cflag |= CREAD;
+        // newtio.c_cc[VTIME] = 5;
+
+        int mcs = 0;
+        Posix.ioctl (m_fd, Linux.Termios.TIOCMGET, out mcs);
+        mcs |= Linux.Termios.TIOCM_RTS;
+        Posix.ioctl (m_fd, Linux.Termios.TIOCMSET, out mcs);
+
+        if (settings.handshake == Settings.Handshake.HARDWARE || settings.handshake == 
Settings.Handshake.BOTH)
+            newtio.c_cflag |= Linux.Termios.CRTSCTS;
+        else
+            newtio.c_cflag &= ~Linux.Termios.CRTSCTS;
+    }
+
+    public string getBytecountbarString () {
+        string r;
+
+        if (nonprintable > 0)
+            r = _("TX: %lu, RX: %lu (%lu unprintable)").printf (tx, rx, nonprintable);
+        else
+            r = _("TX: %lu, RX: %lu").printf (tx, rx);
+        return r;
+    }
 }
diff --git a/src/SerialStreamRecorder.vala b/src/SerialStreamRecorder.vala
index 27c1c7b..cf65d8e 100644
--- a/src/SerialStreamRecorder.vala
+++ b/src/SerialStreamRecorder.vala
@@ -20,87 +20,85 @@
 using Gtk;
 
 public class moserial.SerialStreamRecorder {
-       private GLib.File? file;
-       private string uri;
-       private bool isOpen=false;
-       private FileOutputStream? fos;
+    private GLib.File ? file;
+    private string uri;
+    private bool isOpen = false;
+    private FileOutputStream ? fos;
 
-       public enum Direction { INCOMING, OUTGOING, BOTH }
-       public const string[] DirectionStrings = { GLib.N_("Incoming"),
-                                                   GLib.N_("Outgoing"),
-                                                   GLib.N_("Incoming and Outgoing") };
+    public enum Direction { INCOMING, OUTGOING, BOTH }
+    public const string[] DirectionStrings = { GLib.N_ ("Incoming"),
+                                               GLib.N_ ("Outgoing"),
+                                               GLib.N_ ("Incoming and Outgoing") };
 
-       private Direction direction;
-       public void open (string filename, Direction direction) throws GLib.Error {
-               try {
-                       file = File.new_for_path(filename);
-                       fos = file.replace(null, false, GLib.FileCreateFlags.NONE, null);
-                       isOpen=true;
-                       uri = file.get_uri();
-                       this.direction=direction;
-               }
-               catch(GLib.Error e) {
-                       isOpen=false;
-                       file=null;
-                       fos=null;
-                       throw e;
-               }
-       }
-       private void write(uchar data) {
-               if(isOpen) {
-                       uchar[] o = new uchar[1];
-                       o[0]=data;
-                       try {
-                               fos.write(o, null);
-                       }
-                       catch(GLib.Error e) {
-                               stdout.printf(_("error: %s\n"), e.message);
-                       }
-               }
-       
-       }
-       private void write_array(uchar[] data) {
-               if(isOpen) {
-                       try {
-                               fos.write(data, null);
-                       }
-                       catch(GLib.Error e) {
-                               stdout.printf(_("error: %s\n"), e.message);
-                       }
-               }
-       
-       }
+    private Direction direction;
+    public void open (string filename, Direction direction) throws GLib.Error {
+        try {
+            file = File.new_for_path (filename);
+            fos = file.replace (null, false, GLib.FileCreateFlags.NONE, null);
+            isOpen = true;
+            uri = file.get_uri ();
+            this.direction = direction;
+        } catch (GLib.Error e) {
+            isOpen = false;
+            file = null;
+            fos = null;
+            throw e;
+        }
+    }
 
-       public void writeOutgoing(uchar data) {
-               if(isOpen && (direction==Direction.OUTGOING || direction==Direction.BOTH))
-                       write(data);
-       }
-       public void writeIncoming(uchar[] data) {
-               if(isOpen && (direction==Direction.INCOMING || direction==Direction.BOTH))
-                       write_array(data);
-       }
-       public void close (bool launch){
-               if(isOpen) {
-                       try {
-                               fos.flush(null);
-                               fos.close(null);
-                       }
-                       catch(GLib.Error e) {
-                               stdout.printf(_("error: %s\n"), e.message);
-                               // Error closing the file?
-                       }
+    private void write (uchar data) {
+        if (isOpen) {
+            uchar[] o = new uchar[1];
+            o[0] = data;
+            try {
+                fos.write (o, null);
+            } catch (GLib.Error e) {
+                stdout.printf (_("error: %s\n"), e.message);
+            }
+        }
+    }
 
-                       /* TODO: allow this feature to be enabled / disabled */
-                       if(launch && (MoUtils.fileSize(uri)>0)) {
-                               try {
-                                       show_uri_on_window(null, uri,  Gdk.CURRENT_TIME);
-                               } catch (GLib.Error e) {
-                                       warning(_("Unable to launch %s: %s"), uri, e.message);
-                               }
-                       }
-                       fos=null;
-                       file = null;
-                       isOpen=false;
-               }
-       }
+    private void write_array (uchar[] data) {
+        if (isOpen) {
+            try {
+                fos.write (data, null);
+            } catch (GLib.Error e) {
+                stdout.printf (_("error: %s\n"), e.message);
+            }
+        }
+    }
+
+    public void writeOutgoing (uchar data) {
+        if (isOpen && (direction == Direction.OUTGOING || direction == Direction.BOTH))
+            write (data);
+    }
+
+    public void writeIncoming (uchar[] data) {
+        if (isOpen && (direction == Direction.INCOMING || direction == Direction.BOTH))
+            write_array (data);
+    }
+
+    public void close (bool launch) {
+        if (isOpen) {
+            try {
+                fos.flush (null);
+                fos.close (null);
+            } catch (GLib.Error e) {
+                stdout.printf (_("error: %s\n"), e.message);
+                // Error closing the file?
+            }
+
+            /* TODO: allow this feature to be enabled / disabled */
+            if (launch && (MoUtils.fileSize (uri) > 0)) {
+                try {
+                    show_uri_on_window (null, uri, Gdk.CURRENT_TIME);
+                } catch (GLib.Error e) {
+                    warning (_("Unable to launch %s: %s"), uri, e.message);
+                }
+            }
+            fos = null;
+            file = null;
+            isOpen = false;
+        }
+    }
 }
diff --git a/src/Settings.vala b/src/Settings.vala
index 654977c..a923ac8 100644
--- a/src/Settings.vala
+++ b/src/Settings.vala
@@ -19,137 +19,133 @@
 
 using GLib;
 
-public class Settings : GLib.Object
-{
-        public enum Parity {NONE, ODD, EVEN, MARK, SPACE}
-       public const string[] ParityModeStrings = { GLib.N_("None"),
-                                                   GLib.N_("Odd"),
-                                                    GLib.N_("Even"),
-                                                    GLib.N_("Mark"),
-                                                    GLib.N_("Space") };
+public class Settings : GLib.Object {
+    public enum Parity { NONE, ODD, EVEN, MARK, SPACE }
+    public const string[] ParityModeStrings = { GLib.N_ ("None"),
+                                                GLib.N_ ("Odd"),
+                                                GLib.N_ ("Even"),
+                                                GLib.N_ ("Mark"),
+                                                GLib.N_ ("Space") };
 
-        public enum Handshake {NONE, HARDWARE, SOFTWARE, BOTH}
+    public enum Handshake { NONE, HARDWARE, SOFTWARE, BOTH }
 
-        public enum AccessMode {READWRITE, READONLY, WRITEONLY}
-       public const string[] AccessModeStrings = { GLib.N_("Read and Write"),
-                                                   GLib.N_("Read Only"),
-                                                   GLib.N_("Write Only") };
+    public enum AccessMode { READWRITE, READONLY, WRITEONLY }
+    public const string[] AccessModeStrings = { GLib.N_ ("Read and Write"),
+                                                GLib.N_ ("Read Only"),
+                                                GLib.N_ ("Write Only") };
 
-       public const string[] DataBitItems = { "5", "6", "7", "8" };
-       public const string[] StopBitItems = { "1", "2" };
-       public const string[] BaudRateItems = { "300", "600", "1200", "2400",
-                                               "4800", "9600", "19200",
-                                               "38400", "57600", "115200",
-                                               "230400", "460800", "576000",
-                                               "921600", "1000000", "2000000"
-                                                };
+    public const string[] DataBitItems = { "5", "6", "7", "8" };
+    public const string[] StopBitItems = { "1", "2" };
+    public const string[] BaudRateItems = { "300", "600", "1200", "2400",
+                                            "4800", "9600", "19200",
+                                            "38400", "57600", "115200",
+                                            "230400", "460800", "576000",
+                                            "921600", "1000000", "2000000" };
 
-        public static string DEFAULT_DEVICEFILE = "/dev/ttyS0";
-        public static int DEFAULT_BAUDRATE = 1200;
-        public static int DEFAULT_DATABITS = 8;
-        public static int DEFAULT_STOPBITS = 1;
-        public static Parity DEFAULT_PARITY = Parity.NONE;
-        public static Handshake DEFAULT_HANDSHAKE = Handshake.HARDWARE;
-        public static AccessMode DEFAULT_ACCESSMODE = AccessMode.READWRITE;
-        public static bool DEFAULT_LOCAL_ECHO = false;
-        public string? device {get; construct;}
-        public int baudRate {get; construct;}
-        public int dataBits {get; construct;}
-        public int stopBits {get; construct;}
-        public Parity parity {get; construct;}
-        public Handshake handshake {get; construct;}
-        public AccessMode accessMode {get; construct;}
-        public bool localEcho {get; construct;}
-        public Settings(string? device, int baudRate, int dataBits, int stopBits, Parity parity, Handshake 
handshake, AccessMode accessMode, bool localEcho) {
-               GLib.Object (device: device, 
-                       baudRate: baudRate, 
-                       dataBits: dataBits, 
-                       stopBits: stopBits, 
-                       parity: parity, 
-                       handshake: handshake, 
-                       accessMode: accessMode, 
-                       localEcho: localEcho);
+    public static string DEFAULT_DEVICEFILE = "/dev/ttyS0";
+    public static int DEFAULT_BAUDRATE = 1200;
+    public static int DEFAULT_DATABITS = 8;
+    public static int DEFAULT_STOPBITS = 1;
+    public static Parity DEFAULT_PARITY = Parity.NONE;
+    public static Handshake DEFAULT_HANDSHAKE = Handshake.HARDWARE;
+    public static AccessMode DEFAULT_ACCESSMODE = AccessMode.READWRITE;
+    public static bool DEFAULT_LOCAL_ECHO = false;
+    public string ? device { get; construct; }
+    public int baudRate { get; construct; }
+    public int dataBits { get; construct; }
+    public int stopBits { get; construct; }
+    public Parity parity { get; construct; }
+    public Handshake handshake { get; construct; }
+    public AccessMode accessMode { get; construct; }
+    public bool localEcho { get; construct; }
+    public Settings (string ? device, int baudRate, int dataBits, int stopBits, Parity parity, Handshake 
handshake, AccessMode accessMode, bool localEcho) {
+        GLib.Object (device: device,
+                     baudRate: baudRate,
+                     dataBits: dataBits,
+                     stopBits: stopBits,
+                     parity: parity,
+                     handshake: handshake,
+                     accessMode: accessMode,
+                     localEcho: localEcho);
+    }
 
-        }
-        construct {
-                if (device==null)
-                        device = DEFAULT_DEVICEFILE;
-                if (baudRate==0)
-                        baudRate = DEFAULT_BAUDRATE;
-                if (dataBits==0)
-                        dataBits = DEFAULT_DATABITS;
-                if (stopBits==0)
-                        stopBits = DEFAULT_STOPBITS;
-        }
+    construct {
+        if (device == null)
+            device = DEFAULT_DEVICEFILE;
+        if (baudRate == 0)
+            baudRate = DEFAULT_BAUDRATE;
+        if (dataBits == 0)
+            dataBits = DEFAULT_DATABITS;
+        if (stopBits == 0)
+            stopBits = DEFAULT_STOPBITS;
+    }
 
-        public string parityToChar() {
-                switch (parity) {
-                case Parity.NONE: {
-                       /* TRANSLATORS: first letter of "None", a serial port parity setting */
-                        return _("N");
-                }
-                case Parity.ODD: {
-                       /* TRANSLATORS: first letter of "Odd", a serial port parity setting */
-                        return _("O");
-                }
-                case Parity.EVEN: {
-                       /* TRANSLATORS: first letter of "Even", a serial port parity setting */
-                        return _("E");
-                }
-                case Parity.MARK: {
-                       /* TRANSLATORS: first letter of "Mark", a serial port parity setting */
-                        return _("M");
-                }
-                case Parity.SPACE: {
-                       /* TRANSLATORS: first letter of "Space", a serial port parity setting */
-                        return _("S");
-                }
-                }
-                return "?";
+    public string parityToChar () {
+        switch (parity) {
+            case Parity.NONE: {
+                /* TRANSLATORS: first letter of "None", a serial port parity setting */
+                return _("N");
+            }
+            case Parity.ODD: {
+                /* TRANSLATORS: first letter of "Odd", a serial port parity setting */
+                return _("O");
+            }
+            case Parity.EVEN: {
+                /* TRANSLATORS: first letter of "Even", a serial port parity setting */
+                return _("E");
+            }
+            case Parity.MARK: {
+                /* TRANSLATORS: first letter of "Mark", a serial port parity setting */
+                return _("M");
+            }
+            case Parity.SPACE: {
+                /* TRANSLATORS: first letter of "Space", a serial port parity setting */
+                return _("S");
+            }
         }
+        return "?";
+    }
 
-        public string getStatusbarString(bool open) {
-                string r;
-                r="%s".printf(device);
-                if (open)
-                        r=r+" "+_("OPEN")+" ";
-                else r=r+" "+_("CLOSED")+" ";
-                r=r+"%i,%i%s%i".printf(baudRate, dataBits, parityToChar(), stopBits);
-                return r;
-        }
-        
-        public void saveToProfile(Profile profile) {
-               profile.keyFile.set_string("port_settings", "device", device);
-               profile.keyFile.set_integer("port_settings", "baud_rate", baudRate);
-               profile.keyFile.set_integer("port_settings", "data_bits", dataBits);
-               profile.keyFile.set_integer("port_settings", "stop_bits", stopBits);
-               profile.keyFile.set_integer("port_settings", "parity", parity);
-               profile.keyFile.set_integer("port_settings", "handshake", handshake);
-               profile.keyFile.set_integer("port_settings", "access_mode", accessMode);
-               profile.keyFile.set_boolean("port_settings", "local_echo", localEcho);
-        }
-        
-        public static Settings loadFromProfile(Profile profile) {
-                       string? device=Settings.DEFAULT_DEVICEFILE;
-               int baudRate;
-               int dataBits;
-               int stopBits;
-               Parity parity;
-               Handshake handshake;
-               AccessMode accessMode;
-               bool localEcho;
+    public string getStatusbarString (bool open) {
+        string r;
+        r = "%s".printf (device);
+        if (open)
+            r = r + " " + _("OPEN") + " ";
+        else r = r + " " + _("CLOSED") + " ";
+        r = r + "%i,%i%s%i".printf (baudRate, dataBits, parityToChar (), stopBits);
+        return r;
+    }
+
+    public void saveToProfile (Profile profile) {
+        profile.keyFile.set_string ("port_settings", "device", device);
+        profile.keyFile.set_integer ("port_settings", "baud_rate", baudRate);
+        profile.keyFile.set_integer ("port_settings", "data_bits", dataBits);
+        profile.keyFile.set_integer ("port_settings", "stop_bits", stopBits);
+        profile.keyFile.set_integer ("port_settings", "parity", parity);
+        profile.keyFile.set_integer ("port_settings", "handshake", handshake);
+        profile.keyFile.set_integer ("port_settings", "access_mode", accessMode);
+        profile.keyFile.set_boolean ("port_settings", "local_echo", localEcho);
+    }
+
+    public static Settings loadFromProfile (Profile profile) {
+        string ? device = Settings.DEFAULT_DEVICEFILE;
+        int baudRate;
+        int dataBits;
+        int stopBits;
+        Parity parity;
+        Handshake handshake;
+        AccessMode accessMode;
+        bool localEcho;
 
-               device = MoUtils.getKeyString(profile, "port_settings", "device");      
-               baudRate = MoUtils.getKeyInteger(profile, "port_settings", "baud_rate", 
Settings.DEFAULT_BAUDRATE);
-               dataBits = MoUtils.getKeyInteger(profile, "port_settings", "data_bits", 
Settings.DEFAULT_DATABITS);
-               stopBits = MoUtils.getKeyInteger(profile, "port_settings", "stop_bits", 
Settings.DEFAULT_STOPBITS);
-               parity = (Settings.Parity)MoUtils.getKeyInteger(profile, "port_settings", "parity", 
Settings.DEFAULT_PARITY);
-               handshake = (Settings.Handshake)MoUtils.getKeyInteger(profile, "port_settings", "handshake", 
Settings.DEFAULT_HANDSHAKE);
-               accessMode = (Settings.AccessMode)MoUtils.getKeyInteger(profile, "port_settings", 
"access_mode", Settings.DEFAULT_ACCESSMODE);
-               localEcho = MoUtils.getKeyBoolean(profile, "port_settings", "local_echo", 
Settings.DEFAULT_LOCAL_ECHO);
+        device = MoUtils.getKeyString (profile, "port_settings", "device");
+        baudRate = MoUtils.getKeyInteger (profile, "port_settings", "baud_rate", Settings.DEFAULT_BAUDRATE);
+        dataBits = MoUtils.getKeyInteger (profile, "port_settings", "data_bits", Settings.DEFAULT_DATABITS);
+        stopBits = MoUtils.getKeyInteger (profile, "port_settings", "stop_bits", Settings.DEFAULT_STOPBITS);
+        parity = (Settings.Parity)MoUtils.getKeyInteger (profile, "port_settings", "parity", 
Settings.DEFAULT_PARITY);
+        handshake = (Settings.Handshake)MoUtils.getKeyInteger (profile, "port_settings", "handshake", 
Settings.DEFAULT_HANDSHAKE);
+        accessMode = (Settings.AccessMode)MoUtils.getKeyInteger (profile, "port_settings", "access_mode", 
Settings.DEFAULT_ACCESSMODE);
+        localEcho = MoUtils.getKeyBoolean (profile, "port_settings", "local_echo", 
Settings.DEFAULT_LOCAL_ECHO);
 
-               return new Settings(device, baudRate, dataBits, stopBits, parity, handshake, accessMode, 
localEcho);
-       
-       }
-        
+        return new Settings (device, baudRate, dataBits, stopBits, parity, handshake, accessMode, localEcho);
+    }
 }
diff --git a/src/SettingsDialog.vala b/src/SettingsDialog.vala
index 5c7a7a2..5ca7f71 100644
--- a/src/SettingsDialog.vala
+++ b/src/SettingsDialog.vala
@@ -20,220 +20,219 @@
 using Gtk;
 using GLib;
 
-public class moserial.SettingsDialog : GLib.Object
-{
-       // Does anyone have more than 32 serial ports?
-       const int max_devices = 32;
-
-        private Settings currentSettings;
-        private Dialog dialog;
-        private Button cancelButton;
-        private Button okButton;
-        private Settings settings;
-        private ComboBox deviceCombo;
-        private ComboBox baudRateCombo;
-        private ComboBox dataBitsCombo;
-        private ComboBox stopBitsCombo;
-        private ComboBox parityCombo;
-        private CheckButton hardwareHandshake;
-        private CheckButton softwareHandshake;
-        private ComboBox accessModeCombo;
-        private CheckButton localEcho;
-       private Gtk.ListStore deviceModel;
-        public signal void updateSettings(Settings settings);
-
-        construct {
-                var builder = new Gtk.Builder.from_resource(Config.UIROOT + "settings_dialog.ui");
-
-                dialog = (Dialog)builder.get_object("settings_dialog");
-                cancelButton = (Button)builder.get_object("settings_cancel_button");
-                okButton = (Button)builder.get_object("settings_ok_button");
-
-                baudRateCombo = (ComboBox)builder.get_object("settings_baud_rate");
-               MoUtils.populateComboBox (baudRateCombo, Settings.BaudRateItems);
-
-                dataBitsCombo = (ComboBox)builder.get_object("settings_data_bits");
-                MoUtils.populateComboBox (dataBitsCombo, Settings.DataBitItems);
-
-                stopBitsCombo = (ComboBox)builder.get_object("settings_stop_bits");
-                MoUtils.populateComboBox (stopBitsCombo, Settings.StopBitItems);
-
-                parityCombo = (ComboBox)builder.get_object("settings_parity");
-                MoUtils.populateComboBox (parityCombo, Settings.ParityModeStrings);
-
-                hardwareHandshake = (CheckButton)builder.get_object("settings_hardware_handshake");
-               hardwareHandshake.set_tooltip_text (_("Also known as RTS/CTS handshaking"));
-
-                softwareHandshake = (CheckButton)builder.get_object("settings_software_handshake");
-               softwareHandshake.set_tooltip_text (_("Also known as XON/XOFF handshaking"));
-
-                accessModeCombo = (ComboBox)builder.get_object("settings_open_for");
-               MoUtils.populateComboBox (accessModeCombo, Settings.AccessModeStrings);
-
-                localEcho = (CheckButton)builder.get_object("settings_local_echo");
-               localEcho.set_tooltip_text (_("Normally disabled"));
-
-                dialog.delete_event.connect(hide);
-                cancelButton.clicked.connect(this.cancel);
-                okButton.clicked.connect(this.ok);
-
-                deviceCombo = (ComboBox)builder.get_object("settings_device"); 
-                deviceModel = new Gtk.ListStore(1, typeof( string ));
-                deviceCombo.set_model(deviceModel);
-                CellRenderer deviceCell = new CellRendererText();
-                deviceCombo.pack_start( deviceCell, false );
-                deviceCombo.set_attributes( deviceCell, "text", 0 );
+public class moserial.SettingsDialog : GLib.Object {
+    // Does anyone have more than 32 serial ports?
+    const int max_devices = 32;
+
+    private Settings currentSettings;
+    private Dialog dialog;
+    private Button cancelButton;
+    private Button okButton;
+    private Settings settings;
+    private ComboBox deviceCombo;
+    private ComboBox baudRateCombo;
+    private ComboBox dataBitsCombo;
+    private ComboBox stopBitsCombo;
+    private ComboBox parityCombo;
+    private CheckButton hardwareHandshake;
+    private CheckButton softwareHandshake;
+    private ComboBox accessModeCombo;
+    private CheckButton localEcho;
+    private Gtk.ListStore deviceModel;
+    public signal void updateSettings (Settings settings);
+
+    construct {
+        var builder = new Gtk.Builder.from_resource (Config.UIROOT + "settings_dialog.ui");
+
+        dialog = (Dialog) builder.get_object ("settings_dialog");
+        cancelButton = (Button) builder.get_object ("settings_cancel_button");
+        okButton = (Button) builder.get_object ("settings_ok_button");
+
+        baudRateCombo = (ComboBox) builder.get_object ("settings_baud_rate");
+        MoUtils.populateComboBox (baudRateCombo, Settings.BaudRateItems);
+
+        dataBitsCombo = (ComboBox) builder.get_object ("settings_data_bits");
+        MoUtils.populateComboBox (dataBitsCombo, Settings.DataBitItems);
+
+        stopBitsCombo = (ComboBox) builder.get_object ("settings_stop_bits");
+        MoUtils.populateComboBox (stopBitsCombo, Settings.StopBitItems);
+
+        parityCombo = (ComboBox) builder.get_object ("settings_parity");
+        MoUtils.populateComboBox (parityCombo, Settings.ParityModeStrings);
+
+        hardwareHandshake = (CheckButton) builder.get_object ("settings_hardware_handshake");
+        hardwareHandshake.set_tooltip_text (_("Also known as RTS/CTS handshaking"));
+
+        softwareHandshake = (CheckButton) builder.get_object ("settings_software_handshake");
+        softwareHandshake.set_tooltip_text (_("Also known as XON/XOFF handshaking"));
+
+        accessModeCombo = (ComboBox) builder.get_object ("settings_open_for");
+        MoUtils.populateComboBox (accessModeCombo, Settings.AccessModeStrings);
+
+        localEcho = (CheckButton) builder.get_object ("settings_local_echo");
+        localEcho.set_tooltip_text (_("Normally disabled"));
+
+        dialog.delete_event.connect (hide);
+        cancelButton.clicked.connect (this.cancel);
+        okButton.clicked.connect (this.ok);
+
+        deviceCombo = (ComboBox) builder.get_object ("settings_device");
+        deviceModel = new Gtk.ListStore (1, typeof (string));
+        deviceCombo.set_model (deviceModel);
+        CellRenderer deviceCell = new CellRendererText ();
+        deviceCombo.pack_start (deviceCell, false);
+        deviceCombo.set_attributes (deviceCell, "text", 0);
+    }
+
+    private void populateDevices () {
+        List<string> deviceTypes = new List<string> ();
+        deviceTypes.append ("/dev/ttyS");
+        deviceTypes.append ("/dev/ttyUSB");
+        deviceTypes.append ("/dev/ttyACM");
+        deviceTypes.append ("/dev/rfcomm");
+        deviceTypes.append ("/dev/cuaU");
+        deviceTypes.append ("/dev/cua");
+
+        deviceModel.clear ();
+        TreeIter iter;
+
+        foreach (string devType in deviceTypes) {
+            for (int i = 0; i < max_devices; i++) {
+                string dev = "%s%d".printf (devType, i);
+                if (FileUtils.test (dev, FileTest.EXISTS)) {
+                    deviceModel.append (out iter);
+                    deviceModel.set (iter, 0, dev);
+                }
+            }
         }
-
-        private void populateDevices(){
-               List<string> deviceTypes = new List<string> ();
-               deviceTypes.append ("/dev/ttyS");
-               deviceTypes.append ("/dev/ttyUSB");
-                deviceTypes.append ("/dev/ttyACM");
-               deviceTypes.append ("/dev/rfcomm");
-               deviceTypes.append ("/dev/cuaU");
-               deviceTypes.append ("/dev/cua");
-
-               deviceModel.clear();
-                TreeIter iter;
-               
-               foreach (string devType in deviceTypes) {
-                       for (int i = 0; i < max_devices; i++) {
-                               string dev = "%s%d".printf(devType,i);
-                               if (FileUtils.test (dev, FileTest.EXISTS)) {
-                                       deviceModel.append(out iter);
-                                       deviceModel.set(iter, 0, dev);
-                               }
-                       }
-               }
+    }
+
+    public void show (Settings settings) {
+        populateDevices ();
+        this.currentSettings = settings;
+        loadSettings ();
+        dialog.show_all ();
+    }
+
+    // Load the current settings into the dialog
+    public void loadSettings () {
+        TreeModel t;
+        TreeIter ti;
+        bool success;
+
+        // Device
+        t = deviceCombo.get_model ();
+        success = t.get_iter_first (out ti);
+        while (success) {
+            Value str_data;
+            t.get_value (ti, 0, out str_data);
+            if (str_data.get_string () == currentSettings.device)
+                deviceCombo.set_active_iter (ti);
+            success = t.iter_next (ref ti);
         }
 
-        public void show(Settings settings) {
-               populateDevices();
-                this.currentSettings = settings;
-                loadSettings();
-                dialog.show_all();
+        // Baud Rate
+        t = baudRateCombo.get_model ();
+        success = t.get_iter_first (out ti);
+        while (success) {
+            Value str_data;
+            t.get_value (ti, 0, out str_data);
+            if (str_data.get_string () == "%i".printf (currentSettings.baudRate))
+                baudRateCombo.set_active_iter (ti);
+            success = t.iter_next (ref ti);
         }
 
-        // Load the current settings into the dialog
-        public void loadSettings() {
-                TreeModel t;
-                TreeIter ti;
-                bool success;
-                
-                //Device
-                t = deviceCombo.get_model();
-                success = t.get_iter_first(out ti);
-                while (success) {
-                        Value str_data;
-                        t.get_value(ti, 0, out str_data);
-                        if (str_data.get_string()==currentSettings.device)
-                                deviceCombo.set_active_iter(ti);
-                        success = t.iter_next (ref ti);
-                }
-
-                //Baud Rate
-                t = baudRateCombo.get_model();
-                success = t.get_iter_first(out ti);
-                while (success) {
-                        Value str_data;
-                        t.get_value(ti, 0, out str_data);
-                        if (str_data.get_string()=="%i".printf(currentSettings.baudRate))
-                                baudRateCombo.set_active_iter(ti);
-                        success = t.iter_next (ref ti);
-                }
-
-                //Data Bits
-                t = dataBitsCombo.get_model();
-                success = t.get_iter_first(out ti);
-                while (success) {
-                        Value str_data;
-                        t.get_value(ti, 0, out str_data);
-                        if (str_data.get_string()=="%i".printf(currentSettings.dataBits))
-                                dataBitsCombo.set_active_iter(ti);
-                        success = t.iter_next (ref ti);
-                }
-
-                //Stop Bits
-                t = stopBitsCombo.get_model();
-                success = t.get_iter_first(out ti);
-                while (success) {
-                        Value str_data;
-                        t.get_value(ti, 0, out str_data);
-                        if (str_data.get_string()=="%i".printf(currentSettings.stopBits))
-                                stopBitsCombo.set_active_iter(ti);
-                        success = t.iter_next (ref ti);
-                }
-
-               parityCombo.set_active((int)currentSettings.parity);
-               accessModeCombo.set_active((int)currentSettings.accessMode);
-
-                hardwareHandshake.set_active(false);
-                softwareHandshake.set_active(false);
-                if (currentSettings.handshake==Settings.Handshake.BOTH || 
currentSettings.handshake==Settings.Handshake.HARDWARE)
-                        hardwareHandshake.set_active(true);
-                if (currentSettings.handshake==Settings.Handshake.BOTH || 
currentSettings.handshake==Settings.Handshake.SOFTWARE)
-                        softwareHandshake.set_active(true);
-                if(currentSettings.localEcho)
-                       localEcho.set_active(true);
-                else
-                       localEcho.set_active(false);
+        // Data Bits
+        t = dataBitsCombo.get_model ();
+        success = t.get_iter_first (out ti);
+        while (success) {
+            Value str_data;
+            t.get_value (ti, 0, out str_data);
+            if (str_data.get_string () == "%i".printf (currentSettings.dataBits))
+                dataBitsCombo.set_active_iter (ti);
+            success = t.iter_next (ref ti);
         }
 
-        public bool hide () {
-                dialog.hide ();
-                return true;
+        // Stop Bits
+        t = stopBitsCombo.get_model ();
+        success = t.get_iter_first (out ti);
+        while (success) {
+            Value str_data;
+            t.get_value (ti, 0, out str_data);
+            if (str_data.get_string () == "%i".printf (currentSettings.stopBits))
+                stopBitsCombo.set_active_iter (ti);
+            success = t.iter_next (ref ti);
         }
 
-        public void cancel (Widget w) {
-                currentSettings=null;
-               dialog.hide ();
+        parityCombo.set_active ((int) currentSettings.parity);
+        accessModeCombo.set_active ((int) currentSettings.accessMode);
+
+        hardwareHandshake.set_active (false);
+        softwareHandshake.set_active (false);
+        if (currentSettings.handshake == Settings.Handshake.BOTH || currentSettings.handshake == 
Settings.Handshake.HARDWARE)
+            hardwareHandshake.set_active (true);
+        if (currentSettings.handshake == Settings.Handshake.BOTH || currentSettings.handshake == 
Settings.Handshake.SOFTWARE)
+            softwareHandshake.set_active (true);
+        if (currentSettings.localEcho)
+            localEcho.set_active (true);
+        else
+            localEcho.set_active (false);
+    }
+
+    public bool hide () {
+        dialog.hide ();
+        return true;
+    }
+
+    public void cancel (Widget w) {
+        currentSettings = null;
+        dialog.hide ();
+    }
+
+    public void ok (Widget w) {
+
+        string device;
+        int baudRate;
+        int dataBits;
+        int stopBits;
+        Settings.Parity parity;
+        Settings.Handshake handshake;
+        Settings.AccessMode accessMode;
+        bool pLocalEcho;
+
+        TreeModel t;
+        TreeIter iter;
+        bool success;
+
+        t = deviceCombo.get_model ();
+        success = deviceCombo.get_active_iter (out iter);
+        if (success) {
+            Value str_data;
+            t.get_value (iter, 0, out str_data);
+            device = str_data.get_string ();
+        } else {
+            device = Settings.DEFAULT_DEVICEFILE;
         }
 
-        public void ok (Widget w) {
-
-                string device;
-                int baudRate;
-                int dataBits;
-                int stopBits;
-                Settings.Parity parity;
-                Settings.Handshake handshake;
-                Settings.AccessMode accessMode;
-                bool pLocalEcho;
-
-               TreeModel t;
-               TreeIter iter;
-               bool success;
-
-                t = deviceCombo.get_model();
-                success = deviceCombo.get_active_iter (out iter);
-                if (success) {
-                        Value str_data;
-                        t.get_value(iter, 0, out str_data);
-                        device = str_data.get_string();
-                } else {
-                       device = Settings.DEFAULT_DEVICEFILE;
-               }
-               
-                baudRate = int.parse (Settings.BaudRateItems[baudRateCombo.get_active()]);
-                dataBits = int.parse (Settings.DataBitItems[dataBitsCombo.get_active()]);
-                stopBits = int.parse (Settings.StopBitItems[stopBitsCombo.get_active()]);
-
-                parity = (Settings.Parity)parityCombo.get_active();
-                accessMode = (Settings.AccessMode)accessModeCombo.get_active();
-
-                if (hardwareHandshake.get_active() && softwareHandshake.get_active())
-                        handshake=Settings.Handshake.BOTH;
-                else if (hardwareHandshake.get_active())
-                        handshake=Settings.Handshake.HARDWARE;
-                else if (softwareHandshake.get_active())
-                        handshake=Settings.Handshake.SOFTWARE;
-                else
-                        handshake=Settings.Handshake.NONE;
-               pLocalEcho = localEcho.get_active();
-                settings = new Settings(device, baudRate, dataBits, stopBits, parity, handshake, accessMode, 
pLocalEcho);
-                currentSettings = settings;
-                this.updateSettings(currentSettings);
-                dialog.hide ();
-        }
+        baudRate = int.parse (Settings.BaudRateItems[baudRateCombo.get_active ()]);
+        dataBits = int.parse (Settings.DataBitItems[dataBitsCombo.get_active ()]);
+        stopBits = int.parse (Settings.StopBitItems[stopBitsCombo.get_active ()]);
+
+        parity = (Settings.Parity)parityCombo.get_active ();
+        accessMode = (Settings.AccessMode)accessModeCombo.get_active ();
+
+        if (hardwareHandshake.get_active () && softwareHandshake.get_active ())
+            handshake = Settings.Handshake.BOTH;
+        else if (hardwareHandshake.get_active ())
+            handshake = Settings.Handshake.HARDWARE;
+        else if (softwareHandshake.get_active ())
+            handshake = Settings.Handshake.SOFTWARE;
+        else
+            handshake = Settings.Handshake.NONE;
+        pLocalEcho = localEcho.get_active ();
+        settings = new Settings (device, baudRate, dataBits, stopBits, parity, handshake, accessMode, 
pLocalEcho);
+        currentSettings = settings;
+        this.updateSettings (currentSettings);
+        dialog.hide ();
+    }
 }
diff --git a/src/Szwrapper.vala b/src/Szwrapper.vala
index 4b932bb..aa8334f 100644
--- a/src/Szwrapper.vala
+++ b/src/Szwrapper.vala
@@ -17,223 +17,206 @@
  *  along with moserial.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-//Class for communicating with the sz program
-public class moserial.Szwrapper: GLib.Object
-{
-       public enum Protocol {XMODEM, YMODEM, ZMODEM, RAW, NULL}
-        public const string[] ProtocolStrings = { GLib.N_("Xmodem"),
-                                                  GLib.N_("Ymodem"),
-                                                  GLib.N_("Zmodem"),
-                                                 GLib.N_("None (straight binary)") };
-
-       public Protocol protocol {get; construct;}
-       public SerialConnection? sc {get; construct;}
-        private IOChannel IOChannelInput;
-        private IOChannel IOChannelOutput;
-        private IOChannel IOChannelError;
-        //int inputChannelId;
-       uint outputChannelId;
-        uint errorChannelId;
-        private GLib.Pid pid;
-        public signal void transferComplete();
-        public signal void updateStatus(string newStatus);
-        public bool running=false;
-        
-        public string filename {get; construct;}
-       public Szwrapper(Protocol? protocol, SerialConnection? sc, string? filename) {
-               Protocol pro = protocol;
-               GLib.Object(protocol: pro, 
-                       sc: sc, 
-                       filename: filename);
-       }
-       construct {
-               if(protocol==Protocol.NULL || filename==null) {
-                       running=false;
-               }
-               else
-               {
-                       string[] argv;
-                       if(protocol == Protocol.RAW) {
-                               argv = new string[2];
-                               argv[0] = "cat";
-                               argv[1] = filename;
-                       }
-                       else {
-                               argv = new string[4];
-                               argv[0] = "sz";
-                               switch(protocol) {
-                                       case Protocol.XMODEM:
-                                               argv[1] = "--xmodem";
-                                               break;
-                                       case Protocol.YMODEM:
-                                               argv[1] = "--ymodem";
-                                               break;
-                                       case Protocol.ZMODEM:
-                                       default:
-                                               argv[1] = "--zmodem";
-                                               break;
-                       
-                               }
-                               argv[2] = "-vv";
-                               argv[3] = filename;
-                       }
-                       int output;
-                       int error;
-                       int input;
-                       //size_t bytesRead=0;
-                       //char[1000] m_buf = new char[1000];
-               
-                       try{
-                               Process.spawn_async_with_pipes(null, argv, null, SpawnFlags.SEARCH_PATH, 
null, out pid, out input, out output, out error);
-
-                               IOChannelOutput = new GLib.IOChannel.unix_new(output);
-                               IOChannelInput = new GLib.IOChannel.unix_new(input);
-                               IOChannelError = new GLib.IOChannel.unix_new(error);
-                               IOChannelOutput.set_encoding(null);
-                               IOChannelOutput.set_flags(GLib.IOFlags.NONBLOCK);
-                               IOChannelError.set_encoding(null);
-                               IOChannelError.set_flags(GLib.IOFlags.NONBLOCK);
-                               IOChannelInput.set_encoding(null);
-                               //IOChannelInput.set_flags(GLib.IOFlags.NONBLOCK);
-
-                               outputChannelId = IOChannelOutput.add_watch(GLib.IOCondition.IN, 
this.readBytes);
-                               errorChannelId = IOChannelError.add_watch(GLib.IOCondition.IN, 
this.readError);
-                               running=true;
-                       }
-               
-                       catch(GLib.SpawnError e)
-                       {
-                               running=false;
-                               stdout.printf("spawn error: %s\n", e.message);
-                               var errorDialog = new Gtk.MessageDialog (null, 
Gtk.DialogFlags.DESTROY_WITH_PARENT, Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE, "%s", e.message);
-                               errorDialog.run();
-                               errorDialog.destroy();
-                       }
-                       catch (GLib.IOChannelError e){
-                               stdout.printf("readError() %s\n", e.message);
-                       }
-               }
-       }
-       public void writeChar(uchar byte) {
-               if(running)
-               {
-                       size_t bytesWritten;
-                       char[] b = new char[1];
-                       b[0] = (char)byte;
-                       try {
-                               if(running)
-                                       IOChannelInput.write_chars(b, out bytesWritten);
-                               if(running)
-                                       IOChannelInput.flush();
-                       }
-                       catch(GLib.IOChannelError e)
-                       {
-                               shutdown();
-                               stdout.printf("writeChar() %s\n", e.message);
-                       }
-                       catch(GLib.ConvertError e)
-                       {
-                               stdout.printf("%s\n", e.message);
-                       }
-               }
-       }
-       private bool readError(GLib.IOChannel source, GLib.IOCondition condition) {
-                while(Gtk.events_pending() || Gdk.events_pending())
-                       Gtk.main_iteration_do(false);
-               if(running) {
-               
-                       char[] m_buf = new char[1000];
-                       string messages="";
-                       string message="";
-                       size_t bytesRead=0;
-                       if(!(condition == IOCondition.IN))
-                               return true;
-                       try {
-                               source.read_chars(m_buf, out bytesRead);
-                       }
-                       catch (ConvertError e)          {
-                               stdout.printf("%s\n", e.message);
-                       }
-                       catch (GLib.IOChannelError e){
-                               stdout.printf("readError() %s\n", e.message);
-                       }
-                       for (int x=0; x<bytesRead; x++) {
-                               unichar c = m_buf[x];
-                               if(c.isprint() || c.isspace())
-                                       messages=messages+"%c".printf(m_buf[x]);
-                       }
-                       message = MoUtils.getLastMessage(messages);
-                       if(!(message==""))
-                               updateStatus(message);
-                       if(messages.index_of ("Transfer complete", 0) >= 0) {
-                               GLib.Timeout.add(2000, shutdown_timeout); //Wait 2 seconds for for the final 
remote packet to get ackd
-                               //shutdown();
-                       }
-                       if(messages.index_of ("Transfer incomplete", 0) >= 0) {
-                               shutdown();
-                       }
-                       return true;
-               }
-               else
-                       return false;
-        }
- 
-        public void transferCanceled(GLib.Object o) {
-               //send cancel string to remote client and rz
-               
-               if(running) {
-                       updateStatus(_("canceled"));
-                       if(protocol==Protocol.XMODEM || protocol==Protocol.YMODEM || 
protocol==Protocol.ZMODEM) {
-                               for(int x=0;x<20;x++) {
-                                       if(protocol==Protocol.ZMODEM) {
-                                               sc.sendByte('X'&037);
-                                               writeChar('X'&037);
-                                       }
-                                       else
-                                               sc.sendByte(0x18);
-                               }
-                       }
-                       if(protocol==Protocol.XMODEM || protocol==Protocol.YMODEM || protocol==Protocol.RAW)
-                               shutdown();
-               }
+// Class for communicating with the sz program
+public class moserial.Szwrapper : GLib.Object {
+    public enum Protocol { XMODEM, YMODEM, ZMODEM, RAW, NULL }
+    public const string[] ProtocolStrings = { GLib.N_ ("Xmodem"),
+                                              GLib.N_ ("Ymodem"),
+                                              GLib.N_ ("Zmodem"),
+                                              GLib.N_ ("None (straight binary)") };
+
+    public Protocol protocol { get; construct; }
+    public SerialConnection ? sc { get; construct; }
+    private IOChannel IOChannelInput;
+    private IOChannel IOChannelOutput;
+    private IOChannel IOChannelError;
+    // int inputChannelId;
+    uint outputChannelId;
+    uint errorChannelId;
+    private GLib.Pid pid;
+    public signal void transferComplete ();
+    public signal void updateStatus (string newStatus);
+
+    public bool running = false;
+
+    public string filename { get; construct; }
+    public Szwrapper (Protocol ? protocol, SerialConnection ? sc, string ? filename) {
+        Protocol pro = protocol;
+        GLib.Object (protocol: pro,
+                     sc: sc,
+                     filename: filename);
+    }
+    construct {
+        if (protocol == Protocol.NULL || filename == null) {
+            running = false;
+        } else {
+            string[] argv;
+            if (protocol == Protocol.RAW) {
+                argv = new string[2];
+                argv[0] = "cat";
+                argv[1] = filename;
+            } else {
+                argv = new string[4];
+                argv[0] = "sz";
+                switch (protocol) {
+                    case Protocol.XMODEM:
+                        argv[1] = "--xmodem";
+                        break;
+                    case Protocol.YMODEM:
+                        argv[1] = "--ymodem";
+                        break;
+                    case Protocol.ZMODEM:
+                    default:
+                        argv[1] = "--zmodem";
+                        break;
+                }
+                argv[2] = "-vv";
+                argv[3] = filename;
+            }
+            int output;
+            int error;
+            int input;
+            // size_t bytesRead=0;
+            // char[1000] m_buf = new char[1000];
+
+            try {
+                Process.spawn_async_with_pipes (null, argv, null, SpawnFlags.SEARCH_PATH, null, out pid, out 
input, out output, out error);
+
+                IOChannelOutput = new GLib.IOChannel.unix_new (output);
+                IOChannelInput = new GLib.IOChannel.unix_new (input);
+                IOChannelError = new GLib.IOChannel.unix_new (error);
+                IOChannelOutput.set_encoding (null);
+                IOChannelOutput.set_flags (GLib.IOFlags.NONBLOCK);
+                IOChannelError.set_encoding (null);
+                IOChannelError.set_flags (GLib.IOFlags.NONBLOCK);
+                IOChannelInput.set_encoding (null);
+                // IOChannelInput.set_flags(GLib.IOFlags.NONBLOCK);
+
+                outputChannelId = IOChannelOutput.add_watch (GLib.IOCondition.IN, this.readBytes);
+                errorChannelId = IOChannelError.add_watch (GLib.IOCondition.IN, this.readError);
+                running = true;
+            } catch (GLib.SpawnError e) {
+                running = false;
+                stdout.printf ("spawn error: %s\n", e.message);
+                var errorDialog = new Gtk.MessageDialog (null, Gtk.DialogFlags.DESTROY_WITH_PARENT, 
Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE, "%s", e.message);
+                errorDialog.run ();
+                errorDialog.destroy ();
+            } catch (GLib.IOChannelError e) {
+                stdout.printf ("readError() %s\n", e.message);
+            }
         }
-        private bool shutdown_timeout()
-        {
-               shutdown();
-               return false;
+    }
+    public void writeChar (uchar byte) {
+        if (running) {
+            size_t bytesWritten;
+            char[] b = new char[1];
+            b[0] = (char) byte;
+            try {
+                if (running)
+                    IOChannelInput.write_chars (b, out bytesWritten);
+                if (running)
+                    IOChannelInput.flush ();
+            } catch (GLib.IOChannelError e) {
+                shutdown ();
+                stdout.printf ("writeChar() %s\n", e.message);
+            } catch (GLib.ConvertError e) {
+                stdout.printf ("%s\n", e.message);
+            }
         }
-        private void shutdown() {
-               if(running) {
-                       running=false;
-                       GLib.Source.remove(outputChannelId);
-                       GLib.Source.remove(errorChannelId);
-                       Process.close_pid(pid);
-                       transferComplete();
-               }
+    }
+
+    private bool readError (GLib.IOChannel source, GLib.IOCondition condition) {
+        while (Gtk.events_pending () || Gdk.events_pending ())
+            Gtk.main_iteration_do (false);
+        if (running) {
+
+            char[] m_buf = new char[1000];
+            string messages = "";
+            string message = "";
+            size_t bytesRead = 0;
+            if (!(condition == IOCondition.IN))
+                return true;
+            try {
+                source.read_chars (m_buf, out bytesRead);
+            } catch (ConvertError e) {
+                stdout.printf ("%s\n", e.message);
+            } catch (GLib.IOChannelError e) {
+                stdout.printf ("readError() %s\n", e.message);
+            }
+            for (int x = 0; x < bytesRead; x++) {
+                unichar c = m_buf[x];
+                if (c.isprint () || c.isspace ())
+                    messages = messages + "%c".printf (m_buf[x]);
+            }
+            message = MoUtils.getLastMessage (messages);
+            if (!(message == ""))
+                updateStatus (message);
+            if (messages.index_of ("Transfer complete", 0) >= 0) {
+                GLib.Timeout.add (2000, shutdown_timeout);                // Wait 2 seconds for for the 
final remote packet to get ackd
+                // shutdown();
+            }
+            if (messages.index_of ("Transfer incomplete", 0) >= 0) {
+                shutdown ();
+            }
+            return true;
+        } else
+            return false;
+    }
+
+    public void transferCanceled (GLib.Object o) {
+        // send cancel string to remote client and rz
+
+        if (running) {
+            updateStatus (_("canceled"));
+            if (protocol == Protocol.XMODEM || protocol == Protocol.YMODEM || protocol == Protocol.ZMODEM) {
+                for (int x = 0; x < 20; x++) {
+                    if (protocol == Protocol.ZMODEM) {
+                        sc.sendByte ('X' & 037);
+                        writeChar ('X' & 037);
+                    } else
+                        sc.sendByte (0x18);
+                }
+            }
+            if (protocol == Protocol.XMODEM || protocol == Protocol.YMODEM || protocol == Protocol.RAW)
+                shutdown ();
         }
-        private bool readBytes(GLib.IOChannel source, GLib.IOCondition condition) {
-               while(Gtk.events_pending() || Gdk.events_pending())
-                       Gtk.main_iteration_do(false);
-                if(running) {
-
-                       char[] m_buf = new char[1024];
-
-                       size_t bytesRead=0;
-                       if(!(condition == IOCondition.IN))
-                               return true;
-                       try {
-                               source.read_chars(m_buf, out bytesRead);
-                       }
-                       catch (ConvertError e) {
-                               stdout.printf("%s\n", e.message);
-                       }
-                       catch (GLib.IOChannelError e){
-                               stdout.printf("readError() %s\n", e.message);
-                       }
-                       sc.sendBytes(m_buf, bytesRead);
-                       return true;
-               }
-                else
-                       return false;
+    }
+
+    private bool shutdown_timeout () {
+        shutdown ();
+        return false;
+    }
+
+    private void shutdown () {
+        if (running) {
+            running = false;
+            GLib.Source.remove (outputChannelId);
+            GLib.Source.remove (errorChannelId);
+            Process.close_pid (pid);
+            transferComplete ();
         }
+    }
+
+    private bool readBytes (GLib.IOChannel source, GLib.IOCondition condition) {
+        while (Gtk.events_pending () || Gdk.events_pending ())
+            Gtk.main_iteration_do (false);
+        if (running) {
+
+            char[] m_buf = new char[1024];
+
+            size_t bytesRead = 0;
+            if (!(condition == IOCondition.IN))
+                return true;
+            try {
+                source.read_chars (m_buf, out bytesRead);
+            } catch (ConvertError e) {
+                stdout.printf ("%s\n", e.message);
+            } catch (GLib.IOChannelError e) {
+                stdout.printf ("readError() %s\n", e.message);
+            }
+            sc.sendBytes (m_buf, bytesRead);
+            return true;
+        } else
+            return false;
+    }
 }
diff --git a/src/XmodemFilenameDialog.vala b/src/XmodemFilenameDialog.vala
index 662bd9d..0761cd6 100644
--- a/src/XmodemFilenameDialog.vala
+++ b/src/XmodemFilenameDialog.vala
@@ -18,32 +18,31 @@
  */
 
 using Gtk;
-public class moserial.XmodemFilenameDialog : GLib.Object
-{
-        private Dialog dialog;
-       private Gtk.Entry xmodemFilename;
-       public string filename;
-       construct {
-               var builder = new Gtk.Builder.from_resource(Config.UIROOT + "xmodem_filename_dialog.ui");
+public class moserial.XmodemFilenameDialog : GLib.Object {
+    private Dialog dialog;
+    private Gtk.Entry xmodemFilename;
+    public string filename;
+    construct {
+        var builder = new Gtk.Builder.from_resource (Config.UIROOT + "xmodem_filename_dialog.ui");
 
-               dialog = (Dialog)builder.get_object("xmodem_filename_dialog");
-               xmodemFilename = (Gtk.Entry)builder.get_object("xmodem_filename");
-               dialog.delete_event.connect(hide);
-                dialog.response.connect(response);
-       }
-       public void show() {
-                dialog.run();
-        }
+        dialog = (Dialog) builder.get_object ("xmodem_filename_dialog");
+        xmodemFilename = (Gtk.Entry)builder.get_object ("xmodem_filename");
+        dialog.delete_event.connect (hide);
+        dialog.response.connect (response);
+    }
+    public void show () {
+        dialog.run ();
+    }
 
-        public bool hide() {
-                dialog.hide();
-                return true;
-        }
-        
-        private void response(Widget w, int r){
-               filename = xmodemFilename.get_text();
-               hide();
-               if(filename=="")
-                       filename="xmodem.file";
-        }
+    public bool hide () {
+        dialog.hide ();
+        return true;
+    }
+
+    private void response (Widget w, int r) {
+        filename = xmodemFilename.get_text ();
+        hide ();
+        if (filename == "")
+            filename = "xmodem.file";
+    }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]