SafeDispatch/Safedispatch_4_0/PTTallSettingsForm.cs
2024-02-22 18:43:59 +02:00

217 lines
8.3 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using System.Collections;
using Telerik.WinControls.UI;
using SafeMobileLib;
namespace Safedispatch_4_0
{
public partial class PTTallSettingsForm : Telerik.WinControls.UI.RadForm
{
public SMdb_access smdbObj = null;
//voice device
public int selectedOUTDevice;
public string selectedOUTDeviceName = " ";
public int selectedINDevice;
public string selectedINDeviceName = " ";
public ArrayList soundOUTDevices;
public ArrayList soundINDevices;
private void setLanguage()
{
gbAudioSettings.Text = MainForm2.returnLNGString("audioSett");
lbDevices.Text = MainForm2.returnLNGString("SoundOut");
lbInputDev.Text = MainForm2.returnLNGString("SoundInput");
lbAssingKey.Text = MainForm2.returnLNGString("hotkey") + ":";
btnSaveRadioSettings.Text = MainForm2.returnLNGString("savesetting");
this.Text = MainForm2.returnLNGString("pttallset");
}
public PTTallSettingsForm()
{
InitializeComponent();
// set theme for the Message Box
RadMessageBox.SetThemeName("TelerikMetroBlue");
smdbObj = new SMdb_access(); soundOUTDevices = new ArrayList(); soundINDevices = new ArrayList();
//load sound settings
try
{
ArrayList tmpSound = smdbObj.GetSoundCards(0);
if (tmpSound.Count > 0)
{
selectedOUTDeviceName = tmpSound[0].ToString();
selectedINDeviceName = tmpSound[1].ToString();
if (tmpSound.Count > 2)
txAssingKey.Text = tmpSound[2].ToString();
else
txAssingKey.Text = "";
}
else
{
selectedOUTDeviceName = "";
selectedINDeviceName = "";
txAssingKey.Text = "";
}
MainForm2.KeyforPTTall = txAssingKey.Text;
txAssingKey.MaxLength = 1;
}
catch (Exception ex)
{
SM.Debug("Unable to load sound settings." + ex.ToString());
}
setLanguage();
iniVoiceComponents(listPlayBDevices, listRecBDevices);
switch (MainForm2.radioType)
{
case RADIOTYPE.HYT:
this.Icon = global::Dispatcher.Properties.Resources.HytSmall24;
this.BackColor = MainForm2.HyteraColor;
break;
case RADIOTYPE.HARRIS:
this.Icon = global::Dispatcher.Properties.Resources.HarrisSmall;
this.lbAssingKey.ForeColor = MainForm2.HarTextColor;
this.lbDevices.ForeColor = MainForm2.HarTextColor;
this.lbInputDev.ForeColor = MainForm2.HarTextColor;
this.gbAudioSettings.GroupBoxElement.ForeColor = MainForm2.HarTextColor;
break;
case RADIOTYPE.ATLAS:
this.Icon = global::Dispatcher.Properties.Resources.ATLICO32; //ATLASCHANGE
this.lbAssingKey.ForeColor = MainForm2.HarTextColor;
this.lbDevices.ForeColor = MainForm2.HarTextColor;
this.lbInputDev.ForeColor = MainForm2.HarTextColor;
this.gbAudioSettings.GroupBoxElement.ForeColor = MainForm2.HarTextColor;
break;
case RADIOTYPE.SIMOCO:
this.Icon = global::Dispatcher.Properties.Resources.simoco_dispatch_24;
break;
}
}
private void btnSaveRadioSettings_Click(object sender, EventArgs e)
{
try
{
smdbObj.SaveSoundCardinDB(0, ((RadListDataItem)listPlayBDevices.SelectedItem).Text, ((RadListDataItem)listRecBDevices.SelectedItem).Text, txAssingKey.Text);
if ((MainForm2.radioType == RADIOTYPE.HARRIS)||(MainForm2.radioType == RADIOTYPE.ATLAS)) ((RadLabel)RadMessageBox.Instance.Controls[1]).LabelElement.ForeColor = MainForm2.HarTextColor;
MainForm2.KeyforPTTall = txAssingKey.Text;
RadMessageBox.Show(MainForm2.returnLNGString("setting"));
this.Close();
}
catch (Exception ex)
{
SM.Debug("Unable to save settings in DB:" + ex.ToString());
}
}
public void iniVoiceComponents(RadListControl PlayDev, RadListControl RecDev)
{
// load default configuration
selectedOUTDevice = -1;
selectedINDevice = -1;
try
{
AudioDeviceName dName = new AudioDeviceName();
int i = 0;
foreach (String stDName in dName.getOutDevices())
{
RadListDataItem ci = new RadListDataItem(stDName.Trim());
PlayDev.Items.Add(ci);
sDevice dev;
dev.index = i;
dev.name = stDName.Trim();
soundOUTDevices.Add(dev);
i++;
}
i = 0;
foreach (String stDName in dName.getInDevices())
{
RadListDataItem ci = new RadListDataItem(stDName.Trim());
RecDev.Items.Add(ci);
sDevice dev;
dev.index = i;
dev.name = stDName.Trim();
soundINDevices.Add(dev);
i++;
}
if (PlayDev.Items.Count > 0)
{
if (selectedOUTDevice < PlayDev.Items.Count)
{
bool found = false;
foreach (sDevice dev in soundOUTDevices)
{
if (dev.name.Equals(selectedOUTDeviceName))
{
found = true;
SM.Debug("Sound Device OUT found on config file dev name: " + dev.name + " with index: " + dev.index);
PlayDev.SelectedIndex = dev.index;
selectedOUTDevice = dev.index;
}
}
if (!found)
{
PlayDev.SelectedIndex = 0;
selectedOUTDevice = 0;
}
}
else
{
PlayDev.SelectedIndex = 0;
selectedOUTDevice = 0;
}
}
if (RecDev.Items.Count > 0)
{
if (selectedINDevice < RecDev.Items.Count)
{
bool found = false;
foreach (sDevice dev in soundINDevices)
{
if (dev.name == selectedINDeviceName)
{
found = true;
SM.Debug("Sound Device IN found on config file dev name: " + dev.name + " with index: " + dev.index);
RecDev.SelectedIndex = dev.index;
selectedINDevice = dev.index;
}
}
if (!found)
{
RecDev.SelectedIndex = 0;
selectedINDevice = 0;
}
}
else
{
RecDev.SelectedIndex = 0;
selectedINDevice = 0;
}
}
}
catch (Exception ex)
{
SM.Debug("ERROR in voice ini : " + ex.ToString());
}
}
private void listPlayBDevices_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
{
}
}
}