[moserial] first attempt at gtk3 migration



commit 598d00416b7f7ca9536236b1142206ae176a09d5
Author: Michael J. Chudobiak <mjc avtechpulse com>
Date:   Fri Aug 19 11:19:36 2011 -0400

    first attempt at gtk3 migration

 Makefile.am               |    2 +-
 configure.ac              |    4 +-
 data/glade/moserial.glade |   49 +--------
 data/glade/moserial.ui    |  279 +++------------------------------------------
 src/MainWindow.vala       |   44 ++++----
 src/MoUtils.vala          |   15 +++
 src/SerialConnection.vala |   43 ++------
 src/Settings.vala         |   20 ++++
 src/SettingsDialog.vala   |   53 ++++++---
 9 files changed, 123 insertions(+), 386 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 508bb88..9b9c188 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -50,7 +50,7 @@ moserial_SOURCES = \
 	$(NULL)
 
 src/moserial.vala.stamp: $(moserial_VALASOURCES)
-	$(VALAC) -C --pkg gtk+-2.0 --pkg gdk-2.0 --pkg gio-2.0 --pkg Config --pkg posix --pkg linux --vapidir src/ --basedir $(top_srcdir) $^
+	$(VALAC) -C --pkg gtk+-3.0 --pkg gdk-3.0 --pkg gio-2.0 --pkg Config --pkg posix --pkg linux --vapidir src/ --basedir $(top_srcdir) $^
 	touch $@
 
 moserial_LDADD = \
diff --git a/configure.ac b/configure.ac
index fc44030..1b5a046 100644
--- a/configure.ac
+++ b/configure.ac
@@ -27,11 +27,11 @@ AC_SUBST(CPPFLAGS)
 AC_SUBST(LDFLAGS)
 
 GLIB_REQUIRED=2.12.0
-GTK_REQUIRED=2.14.0
+GTK_REQUIRED=3.0.0
 
 PKG_CHECK_MODULES(MOSERIAL, glib-2.0 >= $GLIB_REQUIRED
 			    gobject-2.0 >= $GLIB_REQUIRED
-			    gtk+-2.0 >= $GTK_REQUIRED
+			    gtk+-3.0 >= $GTK_REQUIRED
                             gio-2.0)
 AC_SUBST(MOSERIAL_CFLAGS)
 AC_SUBST(MOSERIAL_LIBS)
diff --git a/data/glade/moserial.glade b/data/glade/moserial.glade
index 0b78114..31cb9ec 100644
--- a/data/glade/moserial.glade
+++ b/data/glade/moserial.glade
@@ -514,8 +514,6 @@
                 <child>
                   <widget class="GtkComboBox" id="input_mode">
                     <property name="visible">True</property>
-                    <property name="items" translatable="yes">ASCII
-HEX</property>
                   </widget>
                   <packing>
                     <property name="expand">False</property>
@@ -525,12 +523,6 @@ HEX</property>
                 <child>
                   <widget class="GtkComboBox" id="termination_mode">
                     <property name="visible">True</property>
-                    <property name="items" translatable="yes">CR+LF end
-CR end
-LF end
-TAB end
-ESC end
-No end</property>
                   </widget>
                   <packing>
                     <property name="expand">False</property>
@@ -558,7 +550,6 @@ No end</property>
               <widget class="GtkStatusbar" id="statusbar">
                 <property name="visible">True</property>
                 <property name="border_width">4</property>
-                <property name="has_resize_grip">False</property>
               </widget>
               <packing>
                 <property name="position">0</property>
@@ -620,9 +611,6 @@ No end</property>
                 <child>
                   <widget class="GtkComboBox" id="settings_open_for">
                     <property name="visible">True</property>
-                    <property name="items" translatable="yes">Read and Write
-Read Only
-Write Only</property>
                   </widget>
                   <packing>
                     <property name="left_attach">1</property>
@@ -675,11 +663,6 @@ Write Only</property>
                 <child>
                   <widget class="GtkComboBox" id="settings_parity">
                     <property name="visible">True</property>
-                    <property name="items" translatable="yes">None
-Odd
-Even
-Mark
-Space</property>
                   </widget>
                   <packing>
                     <property name="left_attach">1</property>
@@ -693,8 +676,6 @@ Space</property>
                 <child>
                   <widget class="GtkComboBox" id="settings_stop_bits">
                     <property name="visible">True</property>
-                    <property name="items" translatable="yes">1
-2</property>
                   </widget>
                   <packing>
                     <property name="left_attach">1</property>
@@ -708,10 +689,6 @@ Space</property>
                 <child>
                   <widget class="GtkComboBox" id="settings_data_bits">
                     <property name="visible">True</property>
-                    <property name="items" translatable="yes">5
-6
-7
-8</property>
                   </widget>
                   <packing>
                     <property name="left_attach">1</property>
@@ -725,22 +702,6 @@ Space</property>
                 <child>
                   <widget class="GtkComboBox" id="settings_baud_rate">
                     <property name="visible">True</property>
-                    <property name="items" translatable="yes">300
-600
-1200
-2400
-4800
-9600
-19200
-38400
-57600
-115200
-230400
-460800
-576000
-927600
-1000000
-2000000</property>
                   </widget>
                   <packing>
                     <property name="left_attach">1</property>
@@ -752,16 +713,8 @@ Space</property>
                   </packing>
                 </child>
                 <child>
-                  <widget class="GtkComboBoxEntry" id="settings_device">
+                  <widget class="GtkComboBox" id="settings_device">
                     <property name="visible">True</property>
-                    <property name="items" translatable="yes">/dev/ttyS0
-/dev/ttyS1
-/dev/ttyS2
-/dev/ttyS3
-/dev/ttyUSB0
-/dev/ttyUSB1
-/dev/ttyUSB2
-/dev/ttyUSB3</property>
                   </widget>
                   <packing>
                     <property name="left_attach">1</property>
diff --git a/data/glade/moserial.ui b/data/glade/moserial.ui
index e4ab03c..cc5f2c1 100644
--- a/data/glade/moserial.ui
+++ b/data/glade/moserial.ui
@@ -14,14 +14,17 @@
     </columns>
     <data>
       <row>
-        <col id="0" translatable="yes">ASCII</col>
+        <col id="0" translatable="yes">Incoming</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Outgoing</col>
       </row>
       <row>
-        <col id="0" translatable="yes">HEX</col>
+        <col id="0" translatable="yes">Incoming and Outgoing</col>
       </row>
     </data>
   </object>
-  <object class="GtkListStore" id="model10">
+  <object class="GtkListStore" id="model2">
     <columns>
       <column type="gchararray"/>
     </columns>
@@ -37,7 +40,7 @@
       </row>
     </data>
   </object>
-  <object class="GtkListStore" id="model11">
+  <object class="GtkListStore" id="model3">
     <columns>
       <column type="gchararray"/>
     </columns>
@@ -56,203 +59,6 @@
       </row>
     </data>
   </object>
-  <object class="GtkListStore" id="model2">
-    <columns>
-      <column type="gchararray"/>
-    </columns>
-    <data>
-      <row>
-        <col id="0" translatable="yes">CR+LF end</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">CR end</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">LF end</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">TAB end</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">ESC end</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">No end</col>
-      </row>
-    </data>
-  </object>
-  <object class="GtkListStore" id="model3">
-    <columns>
-      <column type="gchararray"/>
-    </columns>
-    <data>
-      <row>
-        <col id="0" translatable="yes">Read and Write</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Read Only</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Write Only</col>
-      </row>
-    </data>
-  </object>
-  <object class="GtkListStore" id="model4">
-    <columns>
-      <column type="gchararray"/>
-    </columns>
-    <data>
-      <row>
-        <col id="0" translatable="yes">None</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Odd</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Even</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Mark</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Space</col>
-      </row>
-    </data>
-  </object>
-  <object class="GtkListStore" id="model5">
-    <columns>
-      <column type="gchararray"/>
-    </columns>
-    <data>
-      <row>
-        <col id="0" translatable="yes">1</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">2</col>
-      </row>
-    </data>
-  </object>
-  <object class="GtkListStore" id="model6">
-    <columns>
-      <column type="gchararray"/>
-    </columns>
-    <data>
-      <row>
-        <col id="0" translatable="yes">5</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">6</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">7</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">8</col>
-      </row>
-    </data>
-  </object>
-  <object class="GtkListStore" id="model7">
-    <columns>
-      <column type="gchararray"/>
-    </columns>
-    <data>
-      <row>
-        <col id="0" translatable="yes">300</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">600</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">1200</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">2400</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">4800</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">9600</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">19200</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">38400</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">57600</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">115200</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">230400</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">460800</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">576000</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">927600</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">1000000</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">2000000</col>
-      </row>
-    </data>
-  </object>
-  <object class="GtkListStore" id="model8">
-    <columns>
-      <column type="gchararray"/>
-    </columns>
-    <data>
-      <row>
-        <col id="0" translatable="yes">/dev/ttyS0</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">/dev/ttyS1</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">/dev/ttyS2</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">/dev/ttyS3</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">/dev/ttyUSB0</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">/dev/ttyUSB1</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">/dev/ttyUSB2</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">/dev/ttyUSB3</col>
-      </row>
-    </data>
-  </object>
-  <object class="GtkListStore" id="model9">
-    <columns>
-      <column type="gchararray"/>
-    </columns>
-    <data>
-      <row>
-        <col id="0" translatable="yes">Incoming</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Outgoing</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Incoming and Outgoing</col>
-      </row>
-    </data>
-  </object>
   <object class="GtkUIManager" id="uimanager1">
     <child>
       <object class="GtkActionGroup" id="actiongroup1">
@@ -711,13 +517,6 @@
                 <child>
                   <object class="GtkComboBox" id="input_mode">
                     <property name="visible">True</property>
-                    <property name="model">model1</property>
-                    <child>
-                      <object class="GtkCellRendererText" id="renderer1"/>
-                      <attributes>
-                        <attribute name="text">0</attribute>
-                      </attributes>
-                    </child>
                   </object>
                   <packing>
                     <property name="expand">False</property>
@@ -727,13 +526,6 @@
                 <child>
                   <object class="GtkComboBox" id="termination_mode">
                     <property name="visible">True</property>
-                    <property name="model">model2</property>
-                    <child>
-                      <object class="GtkCellRendererText" id="renderer2"/>
-                      <attributes>
-                        <attribute name="text">0</attribute>
-                      </attributes>
-                    </child>
                   </object>
                   <packing>
                     <property name="expand">False</property>
@@ -761,7 +553,6 @@
               <object class="GtkStatusbar" id="statusbar">
                 <property name="visible">True</property>
                 <property name="border_width">4</property>
-                <property name="has_resize_grip">False</property>
               </object>
               <packing>
                 <property name="position">0</property>
@@ -823,13 +614,6 @@
                 <child>
                   <object class="GtkComboBox" id="settings_open_for">
                     <property name="visible">True</property>
-                    <property name="model">model3</property>
-                    <child>
-                      <object class="GtkCellRendererText" id="renderer3"/>
-                      <attributes>
-                        <attribute name="text">0</attribute>
-                      </attributes>
-                    </child>
                   </object>
                   <packing>
                     <property name="left_attach">1</property>
@@ -882,13 +666,6 @@
                 <child>
                   <object class="GtkComboBox" id="settings_parity">
                     <property name="visible">True</property>
-                    <property name="model">model4</property>
-                    <child>
-                      <object class="GtkCellRendererText" id="renderer4"/>
-                      <attributes>
-                        <attribute name="text">0</attribute>
-                      </attributes>
-                    </child>
                   </object>
                   <packing>
                     <property name="left_attach">1</property>
@@ -902,13 +679,6 @@
                 <child>
                   <object class="GtkComboBox" id="settings_stop_bits">
                     <property name="visible">True</property>
-                    <property name="model">model5</property>
-                    <child>
-                      <object class="GtkCellRendererText" id="renderer5"/>
-                      <attributes>
-                        <attribute name="text">0</attribute>
-                      </attributes>
-                    </child>
                   </object>
                   <packing>
                     <property name="left_attach">1</property>
@@ -922,13 +692,6 @@
                 <child>
                   <object class="GtkComboBox" id="settings_data_bits">
                     <property name="visible">True</property>
-                    <property name="model">model6</property>
-                    <child>
-                      <object class="GtkCellRendererText" id="renderer6"/>
-                      <attributes>
-                        <attribute name="text">0</attribute>
-                      </attributes>
-                    </child>
                   </object>
                   <packing>
                     <property name="left_attach">1</property>
@@ -942,13 +705,6 @@
                 <child>
                   <object class="GtkComboBox" id="settings_baud_rate">
                     <property name="visible">True</property>
-                    <property name="model">model7</property>
-                    <child>
-                      <object class="GtkCellRendererText" id="renderer7"/>
-                      <attributes>
-                        <attribute name="text">0</attribute>
-                      </attributes>
-                    </child>
                   </object>
                   <packing>
                     <property name="left_attach">1</property>
@@ -960,15 +716,8 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkComboBoxEntry" id="settings_device">
+                  <object class="GtkComboBox" id="settings_device">
                     <property name="visible">True</property>
-                    <property name="model">model8</property>
-                    <child>
-                      <object class="GtkCellRendererText" id="renderer8"/>
-                      <attributes>
-                        <attribute name="text">0</attribute>
-                      </attributes>
-                    </child>
                   </object>
                   <packing>
                     <property name="left_attach">1</property>
@@ -1368,9 +1117,9 @@
             <child>
               <object class="GtkComboBox" id="record_stream">
                 <property name="visible">True</property>
-                <property name="model">model9</property>
+                <property name="model">model1</property>
                 <child>
-                  <object class="GtkCellRendererText" id="renderer9"/>
+                  <object class="GtkCellRendererText" id="renderer1"/>
                   <attributes>
                     <attribute name="text">0</attribute>
                   </attributes>
@@ -1438,9 +1187,9 @@
             <child>
               <object class="GtkComboBox" id="receive_chooser_protocol">
                 <property name="visible">True</property>
-                <property name="model">model10</property>
+                <property name="model">model2</property>
                 <child>
-                  <object class="GtkCellRendererText" id="renderer10"/>
+                  <object class="GtkCellRendererText" id="renderer2"/>
                   <attributes>
                     <attribute name="text">0</attribute>
                   </attributes>
@@ -1580,9 +1329,9 @@
             <child>
               <object class="GtkComboBox" id="send_chooser_protocol">
                 <property name="visible">True</property>
-                <property name="model">model11</property>
+                <property name="model">model3</property>
                 <child>
-                  <object class="GtkCellRendererText" id="renderer11"/>
+                  <object class="GtkCellRendererText" id="renderer3"/>
                   <attributes>
                     <attribute name="text">0</attribute>
                   </attributes>
diff --git a/src/MainWindow.vala b/src/MainWindow.vala
index 6b832b7..8729a0f 100644
--- a/src/MainWindow.vala
+++ b/src/MainWindow.vala
@@ -59,8 +59,13 @@ public class moserial.MainWindow : Gtk.Window //Have to extend Gtk.Winow to get
         private TextView incomingAsciiTextView;
         private TextView outgoingHexTextView;
         private TextView outgoingAsciiTextView;
-        private ComboBox inputMode;
-        private ComboBox terminationMode;
+
+        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;
@@ -262,11 +267,15 @@ public class moserial.MainWindow : Gtk.Window //Have to extend Gtk.Winow to get
                 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."));
-                inputMode = (ComboBox)builder.get_object("input_mode");
-                inputMode.set_active(0);
-		inputMode.changed.connect(inputModeChanged);
-                terminationMode = (ComboBox)builder.get_object("termination_mode");
-                terminationMode.set_active(0);
+
+                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
                 RecentManager recentManager = RecentManager.get_default ();
@@ -372,7 +381,7 @@ public class moserial.MainWindow : Gtk.Window //Have to extend Gtk.Winow to get
                 serialConnection.echoReference=s;
 
                 long len;
-                if (inputMode.get_active()==0) {
+                if (inputModeCombo.get_active()==inputModeValues.ASCII) {
                         len = s.length;
 
                         for (int x=0; x<len; x++) {
@@ -383,7 +392,7 @@ public class moserial.MainWindow : Gtk.Window //Have to extend Gtk.Winow to get
                                 s=s.next_char();
                         }
 
-                        string t = serialConnection.getLineEnd(terminationMode.get_active());
+                        string t = serialConnection.LineEndValues[lineEndModeCombo.get_active()];
                         len = t.length;
 
                         for (int x=0; x<len; x++) {
@@ -724,11 +733,11 @@ public class moserial.MainWindow : Gtk.Window //Have to extend Gtk.Winow to get
                 }
         }
 
-	private void inputModeChanged (ComboBox inputMode) {
-		if (inputMode.get_active()==1)
-			outgoing_notebook.set_current_page(1); // HEX
+	private void inputModeChanged (ComboBox inputModeCombo) {
+		if (inputModeCombo.get_active()==inputModeValues.HEX)
+			outgoing_notebook.set_current_page(1);
 		else
-			outgoing_notebook.set_current_page(0); // ASCII
+			outgoing_notebook.set_current_page(0);
 	}
 
 	private void showHelpButton (ToolButton button) {
@@ -751,7 +760,6 @@ public class moserial.MainWindow : Gtk.Window //Have to extend Gtk.Winow to get
 
                 string license_trans = license[0] + "\n" + license[1] + "\n" + license[2];
 
-                AboutDialog.set_url_hook (url_hook);
                 show_about_dialog (gtkWindow,
                                    "version", Config.VERSION,
                                    "copyright", "Copyright  2009-2011\nMichael J. Chudobiak\n<mjc svn gnome org>",
@@ -765,14 +773,6 @@ public class moserial.MainWindow : Gtk.Window //Have to extend Gtk.Winow to get
                                    null);
         }
 
-        private void url_hook (AboutDialog about, string link) {
-                try {
-                        show_uri (null, link, Gdk.CURRENT_TIME);
-                } catch (GLib.Error e) {
-                        warning (_("Can't display a clickable URL: %s"), e.message);
-                }
-        }
-
         private void quitSizeSave () {
                 windowSizeSave();
                 quitSave();
diff --git a/src/MoUtils.vala b/src/MoUtils.vala
index 74ddb16..8c0912b 100644
--- a/src/MoUtils.vala
+++ b/src/MoUtils.vala
@@ -18,6 +18,8 @@
  */
 
 using GLib;
+using Gtk;
+
 public class MoUtils : GLib.Object
 {
 	public static GLib.File newFile (string path) {
@@ -96,5 +98,18 @@ public class MoUtils : GLib.Object
 		}
 		return message;
 	}
+
+	public static void populateComboBox (ComboBox Combo, string[] val_array) {
+                ListStore Model = new 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/SerialConnection.vala b/src/SerialConnection.vala
index 573edc6..d90fbe3 100644
--- a/src/SerialConnection.vala
+++ b/src/SerialConnection.vala
@@ -38,7 +38,17 @@ public class moserial.SerialConnection : GLib.Object
         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", ""}; 
+
+
 	uint? sourceId;
 	bool localEcho;
         public bool doConnect (Settings settings) {
@@ -93,39 +103,6 @@ public class moserial.SerialConnection : GLib.Object
 			tx=tx+x;
         	}
         }
-	public string getLineEnd(int e)
-	{
-		string s;
-
-		switch(e) {
-			case LineEnd.CR: {
-				s = "\r";
-				break;
-			}
-                        case LineEnd.LF: {
-                                s = "\n";
-                                break;
-                        }
-                        case LineEnd.CRLF: {
-                                s = "\r\n";
-                                break;
-                        }
-                        case LineEnd.TAB: {
-                                s = "\t";
-                                break;
-                        }
-                        case LineEnd.ESC: {
-                                s = "\x1b";
-                                break;
-                        }
-                        case LineEnd.NONE:
-			default: {
-				s = "";
-                                break;
-                        }
-		}
-		return s;
-	}
 
         public void doDisconnect () {
         	if(connected) {
diff --git a/src/Settings.vala b/src/Settings.vala
index ffb2b01..6ef83ef 100644
--- a/src/Settings.vala
+++ b/src/Settings.vala
@@ -22,8 +22,28 @@ 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 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 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",
+						"927600", "1000000", "2000000"
+						 };
+
         public static string DEFAULT_DEVICEFILE = "/dev/ttyS0";
         public static int DEFAULT_BAUDRATE = 1200;
         public static int DEFAULT_DATABITS = 8;
diff --git a/src/SettingsDialog.vala b/src/SettingsDialog.vala
index 003f3ab..54fd9c7 100644
--- a/src/SettingsDialog.vala
+++ b/src/SettingsDialog.vala
@@ -31,7 +31,7 @@ public class moserial.SettingsDialog : GLib.Object
         private Button cancelButton;
         private Button okButton;
         private Settings settings;
-        private ComboBoxEntry deviceCombo;
+        private ComboBox deviceCombo;
         private ComboBox baudRateCombo;
         private ComboBox dataBitsCombo;
         private ComboBox stopBitsCombo;
@@ -40,7 +40,7 @@ public class moserial.SettingsDialog : GLib.Object
         private CheckButton softwareHandshake;
         private ComboBox accessModeCombo;
         private CheckButton localEcho;
-	private ListStore ls;
+	private ListStore deviceModel;
         public signal void updateSettings(Settings settings);
         public SettingsDialog(Builder builder) {
 		GLib.Object(builder: builder);
@@ -52,9 +52,16 @@ public class moserial.SettingsDialog : GLib.Object
                 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"));
@@ -63,6 +70,7 @@ public class moserial.SettingsDialog : GLib.Object
 		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"));
@@ -71,10 +79,12 @@ public class moserial.SettingsDialog : GLib.Object
                 cancelButton.clicked.connect(this.cancel);
                 okButton.clicked.connect(this.ok);
 
-		ls = new ListStore(2, typeof(string), typeof(string));
-                deviceCombo = (ComboBoxEntry)builder.get_object("settings_device");	
-                deviceCombo.set_model(ls);
-                deviceCombo.set_text_column(1);
+                deviceCombo = (ComboBox)builder.get_object("settings_device");	
+                deviceModel = new 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(){
@@ -83,15 +93,15 @@ public class moserial.SettingsDialog : GLib.Object
 		deviceTypes.append ("/dev/ttyUSB");
 		deviceTypes.append ("/dev/rfcomm");
 
-		ls.clear();
+		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)) {
-		 			ls.append(out iter);
-        		        	ls.set(iter, 0, "", 1, dev, -1);
+		 			deviceModel.append(out iter);
+        		        	deviceModel.set(iter, 0, dev);
 				}
 			}
 		}
@@ -115,7 +125,7 @@ public class moserial.SettingsDialog : GLib.Object
                 success = t.get_iter_first(out ti);
                 while (success) {
                         Value str_data;
-                        t.get_value(ti, 1, out 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);
@@ -189,12 +199,25 @@ public class moserial.SettingsDialog : GLib.Object
                 Settings.Handshake handshake;
                 Settings.AccessMode accessMode;
                 bool pLocalEcho;
-                device = deviceCombo.get_active_text();
-                baudRate = int.parse (baudRateCombo.get_active_text());
-                dataBits = int.parse (dataBitsCombo.get_active_text());
-                stopBits = int.parse (stopBitsCombo.get_active_text());
 
-		/* Glade choices must be in same order as Settings enums */
+		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();
 



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