Index: trunk/desktop/mainWindow.rbfrm
===================================================================
--- trunk/desktop/mainWindow.rbfrm	(revision 24)
+++ trunk/desktop/mainWindow.rbfrm	(revision 26)
@@ -2664,5 +2664,5 @@
       TextFont        =   "System"
       TextSize        =   0
-      Top             =   218
+      Top             =   282
       Underline       =   ""
       Visible         =   True
@@ -2694,4 +2694,62 @@
       TextSize        =   0
       Top             =   186
+      Underline       =   ""
+      Visible         =   True
+      Width           =   88
+   End
+   Begin PushButton PushButton_Import
+      AutoDeactivate  =   True
+      Bold            =   ""
+      Cancel          =   ""
+      Caption         =   "Import"
+      Default         =   ""
+      Enabled         =   True
+      Height          =   20
+      HelpTag         =   ""
+      Index           =   -2147483648
+      InitialParent   =   ""
+      Italic          =   ""
+      Left            =   20
+      LockBottom      =   ""
+      LockedInPosition=   False
+      LockLeft        =   ""
+      LockRight       =   ""
+      LockTop         =   ""
+      Scope           =   0
+      TabIndex        =   58
+      TabPanelIndex   =   0
+      TabStop         =   True
+      TextFont        =   "System"
+      TextSize        =   0
+      Top             =   218
+      Underline       =   ""
+      Visible         =   True
+      Width           =   88
+   End
+   Begin PushButton PushButton_Export
+      AutoDeactivate  =   True
+      Bold            =   ""
+      Cancel          =   ""
+      Caption         =   "Export"
+      Default         =   ""
+      Enabled         =   False
+      Height          =   20
+      HelpTag         =   ""
+      Index           =   -2147483648
+      InitialParent   =   ""
+      Italic          =   ""
+      Left            =   20
+      LockBottom      =   ""
+      LockedInPosition=   False
+      LockLeft        =   ""
+      LockRight       =   ""
+      LockTop         =   ""
+      Scope           =   0
+      TabIndex        =   59
+      TabPanelIndex   =   0
+      TabStop         =   True
+      TextFont        =   "System"
+      TextSize        =   0
+      Top             =   314
       Underline       =   ""
       Visible         =   True
@@ -3541,4 +3599,5 @@
 		Sub Change()
 		  ICSSerialPort1.setCarType(me.Text)
+		  ICSSerialPort1.setDefaultValues
 		  disableControls
 		  
@@ -3693,4 +3752,16 @@
 	#tag Event
 		Sub valuesChanged()
+		  //Update the screens with the new values
+		  updateAdvancedScreen
+		  updateCarScreen
+		End Sub
+	#tag EndEvent
+	#tag Event
+		Sub profileImported(profileName as string)
+		  PopupMenu_Profile.AddRow(profileName)
+		  
+		  //Make sure to switch to the new profile
+		  PopupMenu_Profile.ListIndex = PopupMenu_Profile.ListCount
+		  
 		  //Update the screens with the new values
 		  updateAdvancedScreen
@@ -3756,4 +3827,5 @@
 		    PushButton_SaveProfile.Enabled = true
 		    PushButton_Delete.Enabled = true
+		    PushButton_Export.Enabled = true
 		    ICSSerialPort1.loadProfile(me.Text)
 		  end if
@@ -3763,5 +3835,4 @@
 		Sub Open()
 		  dim s() as string
-		  dim i as integer
 		  
 		  s = ICSSerialPort1.listProfiles
@@ -3795,4 +3866,6 @@
 		    PushButton_SaveProfile.Enabled = False
 		    PushButton_Delete.Enabled = False
+		    PushButton_Export.Enabled = False
+		    
 		  end if
 		End Sub
@@ -3807,2 +3880,24 @@
 	#tag EndEvent
 #tag EndEvents
+#tag Events PushButton_Import
+	#tag Event
+		Sub Action()
+		  dim success as Boolean
+		  
+		  success = ICSSerialPort1.importProfile
+		  
+		  if success = false then
+		    MsgBox "Error importing profile"
+		  end if
+		End Sub
+	#tag EndEvent
+#tag EndEvents
+#tag Events PushButton_Export
+	#tag Event
+		Sub Action()
+		  if PopupMenu_Profile.Text <> "" then
+		    ICSSerialPort1.exportProfile(PopupMenu_Profile.Text)
+		  end if
+		End Sub
+	#tag EndEvent
+#tag EndEvents
Index: trunk/desktop/ICSSerialPort.rbbas
===================================================================
--- trunk/desktop/ICSSerialPort.rbbas	(revision 25)
+++ trunk/desktop/ICSSerialPort.rbbas	(revision 26)
@@ -455,7 +455,234 @@
 	#tag EndMethod
 
+	#tag Method, Flags = &h0
+		Sub exportProfile(theName as string)
+		  dim xml as XmlDocument
+		  dim root as XmlNode
+		  dim rootchild as XmlNode
+		  dim rs as RecordSet
+		  dim i as integer
+		  dim dlg as SaveAsDialog
+		  dim f as FolderItem
+		  
+		  dlg = New SaveAsDialog
+		  dlg.Title = "Export your profile"
+		  #if TargetLinux
+		    dlg.InitialDirectory = SpecialFolder.Home
+		  #else
+		    dlg.InitialDirectory = SpecialFolder.Documents
+		  #endif
+		  
+		  dlg.SuggestedFileName = "ics_"+theName+".xml"
+		  f = dlg.ShowModal()
+		  
+		  if f <> Nil then
+		    //Nothing to see here, move along
+		  else
+		    MsgBox "You must choose a file"
+		    Return
+		  end if
+		  
+		  //Find the record
+		  rs = fsicsdb.SQLSelect("SELECT * FROM carprofiles WHERE name= '"+theName+"'")
+		  
+		  if rs <> Nil then
+		    //We have a record, so do something
+		    
+		    //Create the root element of the XML file
+		    xml = New XmlDocument
+		    root = xml.AppendChild(xml.CreateElement("icsprofile"))
+		    
+		    //Itterate all available fields and write them to the xml document
+		    for i = 1 to rs.FieldCount
+		      if rs.IdxField(i).Name <> "" and rs.IdxField(i).StringValue<> "" then
+		        
+		        rootchild = root.AppendChild(xml.CreateElement(rs.IdxField(i).Name))
+		        rootchild.AppendChild(xml.CreateTextNode(rs.IdxField(i).StringValue))
+		      end if
+		    next
+		    
+		    //Write the document to a file
+		    xml.SaveXml(f)
+		  else
+		    MsgBox "No profile to export"
+		    Return
+		  end if
+		  
+		End Sub
+	#tag EndMethod
+
+	#tag Method, Flags = &h0
+		Function importProfile() As Boolean
+		  dim success as boolean
+		  dim dlg as OpenDialog
+		  dim f as FolderItem
+		  dim xdoc as XmlDocument
+		  dim root as XmlNode
+		  dim i as integer
+		  dim count as Integer
+		  dim item as string
+		  dim rec as DatabaseRecord
+		  dim theName as string
+		  
+		  rec = New DatabaseRecord
+		  success = False
+		  
+		  
+		  //Get the user to select a file
+		  dlg = New OpenDialog
+		  dlg.Title = "Select a profile to import"
+		  #if TargetLinux
+		    dlg.InitialDirectory = SpecialFolder.Home
+		  #else
+		    dlg.InitialDirectory = SpecialFolder.Documents
+		  #endif
+		  f = dlg.ShowModal()
+		  
+		  //If we have a valid file we need to read it as an xml file to process it
+		  //Items are individually specified to prevent the program from trying to insert columns that do not exist
+		  //All column names should match the database table
+		  
+		  if f <> nil then
+		    
+		    //Read the XML file
+		    xdoc = New XmlDocument(f)
+		    
+		    count = xdoc.DocumentElement.ChildCount
+		    
+		    for i = 0 to count - 1
+		      root = xdoc.DocumentElement.Child(i)
+		      
+		      item = root.FirstChild.Value
+		      
+		      select case root.Name
+		        
+		      case "name"
+		        theName = item
+		      case "cartype"
+		        carType = item
+		      case "byte01"
+		        byte01 = chrb(val(item))
+		      case "byte02"
+		        byte02 = chrb(val(item))
+		      case "byte03"
+		        byte03 = chrb(val(item))
+		      case "byte04"
+		        byte04 = chrb(val(item))
+		      case "byte05"
+		        byte05 = chrb(val(item))
+		      case "byte06"
+		        byte06 = chrb(val(item))
+		      case "byte07"
+		        byte07 = chrb(val(item))
+		      case "byte08"
+		        byte08 = chrb(val(item))
+		      case "byte09"
+		        byte09 = chrb(val(item))
+		      case "byte10"
+		        byte10 = chrb(val(item))
+		      case "byte11"
+		        byte11 = chrb(val(item))
+		      case "byte12"
+		        byte12 = chrb(val(item))
+		      case "byte13"
+		        byte13 = chrb(val(item))
+		      case "byte14"
+		        byte14 = chrb(val(item))
+		      case "byte15"
+		        byte15 = chrb(val(item))
+		      case "byte16"
+		        byte16 = chrb(val(item))
+		      case "byte17"
+		        byte17 = chrb(val(item))
+		      case "byte18"
+		        byte18 = chrb(val(item))
+		        
+		      end select
+		      
+		    next
+		    
+		  else
+		    //File not select we can stop
+		    success = False
+		    return success
+		  end if
+		  
+		  //Now check to make sure their is not an existing profile with this name
+		  dim rs as RecordSet
+		  
+		  rs = fsicsdb.SQLSelect("SELECT * FROM carprofiles WHERE name= '"+theName+"'")
+		  
+		  if rs <> Nil then
+		    
+		    if rs.RecordCount > 0 then
+		      //we have a duplicate record
+		      //we need to prompt the user about what to do
+		      dim d as New MessageDialog
+		      dim b as MessageDialogButton
+		      d.Icon = MessageDialog.GraphicCaution
+		      d.ActionButton.Caption = "Yes"
+		      d.CancelButton.Visible = True
+		      d.CancelButton.Caption = "No"
+		      d.Message = "A profile exists with this name, do you want to overwrite the existing profile?"
+		      b = d.ShowModal
+		      
+		      //Now determine what the user chose
+		      Select Case b
+		      case d.ActionButton
+		        //The user wants to overwrite the record so we can just save what we have
+		        saveProfile(theName)
+		        success = True
+		        //Values changed because of the overwrite
+		        valuesChanged()
+		      case d.CancelButton
+		        //The user chose not to overwrite the record, we need to come up with a new name
+		        //We will increment the number until we find a name not used or we hit 32 just in case an infinite loop would occur
+		        dim tempString as string
+		        dim tempName as string
+		        i = 0
+		        while rs.RecordCount > 0
+		          i = i + 1
+		          tempString = str(i)
+		          tempName = theName + tempString
+		          //Check to make sure we are not in an infinite looooooooop
+		          //If we are something went wrong
+		          if i > 31 then
+		            exit While
+		          end if
+		          rs = fsicsdb.SQLSelect("SELECT * FROM carprofiles WHERE name = '"+tempName+"'")
+		          
+		        wend
+		        //OK we have a unique name at this point
+		        theName = theName + tempString
+		        saveProfile(theName)
+		        success = True
+		        //new profile was imported
+		        profileImported(theName)
+		      end select
+		      
+		    else
+		      //No duplicate exists so we can just insert the record
+		      saveProfile(theName)
+		      success = True
+		      //new profile was imported
+		      profileImported(theName)
+		    end if
+		    //Close our record
+		    rs.Close
+		    
+		  end if
+		  
+		  Return success
+		  
+		End Function
+	#tag EndMethod
+
 
 	#tag Hook, Flags = &h0
 		Event valuesChanged()
+	#tag EndHook
+
+	#tag Hook, Flags = &h0
+		Event profileImported(profileName as string)
 	#tag EndHook
 
