-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathOptions.xaml.cs
212 lines (196 loc) · 10 KB
/
Options.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using static FSClient.Broker;
using WF=System.Windows.Forms;
namespace FSClient {
/// <summary>
/// Interaction logic for Options.xaml
/// </summary>
public partial class Options : Window {
public Options() {
InitializeComponent();
}
private Broker broker = Broker.get_instance();
private void Window_Loaded(object sender, RoutedEventArgs e) {
GuiOptions = new List<ComboOption>();
GuiOptions.Add(new ComboOption { key = "All",name = "Calls, Dialpad and Accounts"});
GuiOptions.Add(new ComboOption { key = "Calls", name = "Calls and Dialpad" });
GuiOptions.Add(new ComboOption { key = "Accounts", name = "Dialpad and Accounts" });
GuiOptions.Add(new ComboOption { key = "Dialpad", name = "Dialpad Only" });
comboGUIStartup.ItemsSource = GuiOptions;
themes = new List<ComboOption>();
themes.Add(new ComboOption {key="Steel",name="Steel" });
themes.Add(new ComboOption { key = "RoyalBlue", name = "Royal Blue" });
themes.Add(new ComboOption { key = "Black", name = "Black" });
themes.Add(new ComboOption { key = "White", name = "White" });
comboTheme.ItemsSource = themes;
IncomingCallOptions = new List<ComboOption>();
IncomingCallOptions.Add(new ComboOption { key = "None", name = "Do Nothing" });
IncomingCallOptions.Add(new ComboOption { key = "Front", name = "Bring To Front" });
IncomingCallOptions.Add(new ComboOption { key = "FrontKeyboard", name = "Bring To Front & Keyboard Focus" });
comboOnIncomingCall.ItemsSource = IncomingCallOptions;
load_devices(true);
}
private class ComboOption{
public string name;
public string key;
public override string ToString() {
return name;
}
}
private List<ComboOption> GuiOptions;
private List<ComboOption> themes;
private List<ComboOption> IncomingCallOptions;
private void load_devices(bool from_settings) {
PortAudio.AudioDevice[] devices = broker.audio_devices;
comboSpeakerInput.ItemsSource = comboHeadsetInput.ItemsSource = (from d in devices where d.inputs > 0 select d).ToArray();
comboRingDevice.ItemsSource = comboSpeakerOutput.ItemsSource = comboHeadsetOutput.ItemsSource = (from d in devices where d.outputs > 0 select d).ToArray();
string old_selected_item = comboHeadsetDevice.SelectedItem as string;
comboHeadsetDevice.Items.Clear();
comboHeadsetDevice.Items.Add("None");
foreach (string headset in broker.AvailableHeadsets())
comboHeadsetDevice.Items.Add(headset);
comboHeadsetDevice.SelectedItem = old_selected_item;
if (from_settings) {
comboHeadsetInput.SelectedItem = broker.HeadsetInDev;
comboHeadsetOutput.SelectedItem = broker.HeadsetOutDev;
comboSpeakerInput.SelectedItem = broker.SpeakerInDev;
comboSpeakerOutput.SelectedItem = broker.SpeakerOutDev;
comboRingDevice.SelectedItem = broker.RingDev;
chkIncomingBalloons.IsChecked = broker.IncomingBalloons;
string incoming_key = "None";
if (broker.IncomingTopMost)
incoming_key = broker.IncomingKeyboardFocus ? "FrontKeyboard" : "Front";
comboOnIncomingCall.SelectedItem = (from g in IncomingCallOptions where g.key == incoming_key select g).FirstOrDefault();
if (comboOnIncomingCall.SelectedIndex == -1)
comboOnIncomingCall.SelectedIndex = 1;
chkClearDTMFS.IsChecked = broker.ClearDTMFS;
chkUseNumbers.IsChecked = broker.UseNumberOnlyInput;
chkUpdatesOnStart.IsChecked = broker.CheckForUpdates != "Never";
chkNAT.IsChecked = broker.UPNPNAT;
txtRecordingPath.Text = broker.recordings_folder;
chkDirectSip.IsChecked = broker.DirectSipDial;
chkAlwaysOnTopDuringCall.IsChecked = broker.AlwaysOnTopDuringCall;
SetHotKeyFormFromSetting(GLOBAL_HOT_KEY_TYPE.Focus, chkGlobalAlt, chkGlobalCntrl, chkGlobalShift, chkGlobalWin, txtHotKey);
SetHotKeyFormFromSetting(GLOBAL_HOT_KEY_TYPE.End, chkGlobalEndAlt, chkGlobalEndCntrl, chkGlobalEndShift, chkGlobalEndWin, txtHotKeyEnd);
SetHotKeyFormFromSetting(GLOBAL_HOT_KEY_TYPE.Answer, chkGlobalAnsAlt, chkGlobalAnsCntrl, chkGlobalAnsShift, chkGlobalAnsWin, txtHotKeyAns);
SetHotKeyFormFromSetting(GLOBAL_HOT_KEY_TYPE.Mute, chkGlobalMuteAlt, chkGlobalMuteCntrl, chkGlobalMuteShift, chkGlobalMuteWin, txtHotKeyMute);
comboGUIStartup.SelectedItem = (from g in GuiOptions where g.key == broker.GUIStartup select g).FirstOrDefault();
if (comboGUIStartup.SelectedIndex == -1)
comboGUIStartup.SelectedIndex = 0;
comboTheme.SelectedItem = (from g in themes where g.key == broker.theme select g).FirstOrDefault();
if (comboTheme.SelectedIndex == -1)
comboTheme.SelectedIndex = 0;
comboHeadsetDevice.SelectedItem = broker.ActiveHeadset();
if (comboHeadsetDevice.SelectedIndex == -1)
comboHeadsetDevice.SelectedIndex = 0;
}
}
private void SetHotKeyFormFromSetting(GLOBAL_HOT_KEY_TYPE type, CheckBox alt_box, CheckBox cntrl_box, CheckBox shift_box, CheckBox win_box, TextBox txt_box) {
var setting = broker.GetHotKeySetting(type);
alt_box.IsChecked = setting.modifiers.HasFlag(UnManaged.KeyModifier.Alt);
shift_box.IsChecked = setting.modifiers.HasFlag(UnManaged.KeyModifier.Shift);
cntrl_box.IsChecked = setting.modifiers.HasFlag(UnManaged.KeyModifier.Ctrl);
win_box.IsChecked = setting.modifiers.HasFlag(UnManaged.KeyModifier.Win);
var key_char = setting.key.ToString();
if (setting.key == System.Windows.Input.Key.None)
key_char = "";
key_char = key_char.Replace("NumPad", "").Replace("Oem", "");
if (key_char.Length == 2)
key_char = key_char.Replace("D", "");
if (key_char.Length > 1)
key_char = "";
txt_box.Text = key_char;
}
private void SaveSettings() {
PortAudio.AudioDevice indev = comboHeadsetInput.SelectedItem as PortAudio.AudioDevice;
PortAudio.AudioDevice outdev = comboHeadsetOutput.SelectedItem as PortAudio.AudioDevice;
broker.SetHeadsetDevs(indev == null ? "" : indev.name, outdev == null ? "" : outdev.name);
indev = comboSpeakerInput.SelectedItem as PortAudio.AudioDevice;
outdev = comboSpeakerOutput.SelectedItem as PortAudio.AudioDevice;
broker.SetSpeakerDevs(indev == null ? "" : indev.name, outdev == null ? "" : outdev.name);
outdev = comboRingDevice.SelectedItem as PortAudio.AudioDevice;
broker.SetRingDev(outdev == null ? "" : outdev.name);
broker.IncomingBalloons = chkIncomingBalloons.IsChecked == true;
string incoming_key = (comboOnIncomingCall.SelectedItem as ComboOption).key;
if (incoming_key == "None")
broker.IncomingKeyboardFocus = broker.IncomingTopMost = false;
else{
broker.IncomingTopMost = true;
broker.IncomingKeyboardFocus = (incoming_key == "FrontKeyboard");
}
broker.ClearDTMFS = chkClearDTMFS.IsChecked == true;
broker.UPNPNAT = chkNAT.IsChecked == true;
broker.DirectSipDial = chkDirectSip.IsChecked == true;
broker.AlwaysOnTopDuringCall = chkAlwaysOnTopDuringCall.IsChecked == true;
broker.UseNumberOnlyInput = chkUseNumbers.IsChecked == true;
broker.recordings_folder = txtRecordingPath.Text;
broker.CheckForUpdates = chkUpdatesOnStart.IsChecked == true ? "OnStart" : "Never";
broker.GUIStartup = (comboGUIStartup.SelectedItem as ComboOption).key;
broker.theme = (comboTheme.SelectedItem as ComboOption).key;
SetHotKeyFromWindow(GLOBAL_HOT_KEY_TYPE.Focus, chkGlobalAlt, chkGlobalCntrl, chkGlobalShift, chkGlobalWin, txtHotKey);
SetHotKeyFromWindow(GLOBAL_HOT_KEY_TYPE.End, chkGlobalEndAlt, chkGlobalEndCntrl, chkGlobalEndShift, chkGlobalEndWin, txtHotKeyEnd);
SetHotKeyFromWindow(GLOBAL_HOT_KEY_TYPE.Answer, chkGlobalAnsAlt, chkGlobalAnsCntrl, chkGlobalAnsShift, chkGlobalAnsWin, txtHotKeyAns);
SetHotKeyFromWindow(GLOBAL_HOT_KEY_TYPE.Mute, chkGlobalMuteAlt, chkGlobalMuteCntrl, chkGlobalMuteShift, chkGlobalMuteWin, txtHotKeyMute);
broker.SetActiveHeadset(comboHeadsetDevice.SelectedItem as string);
broker.SaveSettings();
}
private void SetHotKeyFromWindow(GLOBAL_HOT_KEY_TYPE type, CheckBox alt_box, CheckBox cntrl_box, CheckBox shift_box, CheckBox win_box, TextBox txt_box) {
System.Windows.Input.Key hot_key = System.Windows.Input.Key.None;
var hot_key_modifier = UnManaged.KeyModifier.None;
if (alt_box.IsChecked == true)
hot_key_modifier |= UnManaged.KeyModifier.Alt;
if (cntrl_box.IsChecked == true)
hot_key_modifier |= UnManaged.KeyModifier.Ctrl;
if (shift_box.IsChecked == true)
hot_key_modifier |= UnManaged.KeyModifier.Shift;
if (win_box.IsChecked == true)
hot_key_modifier |= UnManaged.KeyModifier.Win;
if (!String.IsNullOrWhiteSpace(txt_box.Text)) {
var key = txt_box.Text.ToUpper();
if (key[0] >= 0 && key[0] <= 9)
key = "D" + key;
Enum.TryParse<System.Windows.Input.Key>(key, out hot_key);
}
broker.SetHotKey(type, new Broker.HotKeySetting { modifiers = hot_key_modifier, key = hot_key });
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
}
private void btnSave_Click(object sender, RoutedEventArgs e) {
SaveSettings();
DialogResult = true;
Close();
}
private void btnCancel_Click(object sender, RoutedEventArgs e) {
DialogResult = false;
Close();
}
private void btnReloadDevices_Click(object sender, RoutedEventArgs e) {
broker.reload_audio_devices(false, false);
load_devices(false);
}
private void btnSofiaSettings_Click(object sender, RoutedEventArgs e) {
broker.edit_sofia();
}
private void btnEventSocketSettings_Click(object sender, RoutedEventArgs e){
broker.edit_event_socket();
}
private void btnConferenceSettings_Click(object sender, RoutedEventArgs e) {
broker.edit_conference();
}
private void btnPluginSettings_Click(object sender, RoutedEventArgs e){
broker.edit_plugins();
}
private void btnPathBrowse_Click(object sender, RoutedEventArgs e) {
WF.FolderBrowserDialog dlg = new WF.FolderBrowserDialog();
dlg.SelectedPath = txtRecordingPath.Text;
WF.DialogResult res = dlg.ShowDialog();
if (res != System.Windows.Forms.DialogResult.OK)
return;
txtRecordingPath.Text = dlg.SelectedPath;
}
}
}