-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
217 lines (182 loc) · 7.53 KB
/
MainWindow.xaml.cs
File metadata and controls
217 lines (182 loc) · 7.53 KB
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
213
214
215
216
217
using Siprix;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Navigation;
namespace SampleWpf;
public partial class MainWindow : Window
{
Siprix.ObjModel objModel_ = null!;
CallSwitchedControl switchedCallCtrl_ = null!;
CallRecentListControl callRecentListCtrl_ = null!;
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
//Initialize SDK
objModel_ = new();
objModel_.Initialize(App.Current.Dispatcher);
//Assign listener
objModel_.Calls.PropertyChanged += OnCalls_PropertyChanged;
objModel_.Calls.Collection.CollectionChanged += (_,_) => OnCalls_CollectionChanged();
//Set data context
lbSubscriptions.DataContext = objModel_.Subscriptions;
tbNetworkLost.DataContext = objModel_.Networks;
lbMessages.DataContext = objModel_.Messages;
cbMsgAccounts.DataContext = objModel_.Accounts;
lbAccounts.DataContext = objModel_.Accounts;
lbCalls.DataContext = objModel_.Calls;
tbLogs.DataContext = objModel_.Logs;
switchedCallCtrl_ = new CallSwitchedControl(objModel_);
switchedCallCtrl_.OnAddCall += CallAdd_Click;
CallsGrid.Children.Add(switchedCallCtrl_);
Grid.SetRow(switchedCallCtrl_, 1);
callRecentListCtrl_ = new CallRecentListControl(objModel_);
callRecentListCtrl_.OnCancel += CallAddCancel_Click;
CallsGrid.Children.Add(callRecentListCtrl_);
Grid.SetRowSpan(callRecentListCtrl_, 2);
Panel.SetZIndex(callRecentListCtrl_, 2);
OnCalls_CollectionChanged();
//Devices
objModel_.Devices.Load();
cbVideo.DataContext = objModel_.Devices;
cbRecord.DataContext = objModel_.Devices;
cbPlayback.DataContext = objModel_.Devices;
}
private void Window_Closed(object sender, EventArgs e)
{
//Uninitialize SDK
objModel_.UnInitialize();
}
private void OnCalls_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Siprix.CallsListModel.LastIncomingCallId))
{
//Switch tab to 'Calls' when received incoming call
if (mainTabCtrl.SelectedIndex != 1) {
mainTabCtrl.SelectedIndex = 1;
}
}
}
private void OnCalls_CollectionChanged()
{
bool callsListEmpty = (objModel_.Calls.Collection.Count == 0);
callRecentListCtrl_.Visibility = callsListEmpty ? Visibility.Visible : Visibility.Collapsed;
callRecentListCtrl_.SetDialogMode(!callsListEmpty);
switchedCallCtrl_.Visibility = callsListEmpty ? Visibility.Collapsed : Visibility.Visible;
}
private void CallAdd_Click()
{
callRecentListCtrl_.Visibility = Visibility.Visible;
}
private void CallAddCancel_Click()
{
callRecentListCtrl_.Visibility = Visibility.Collapsed;
}
private void AccountAdd_Click(object sender, RoutedEventArgs e)
{
AddAccountWindow wnd = new(objModel_);
wnd.ShowDialog();
}
private void SubscriptionAdd_Click(object sender, RoutedEventArgs e)
{
AddSubscriptionWindow wnd = new(objModel_);
wnd.ShowDialog();
}
private void AccountEdit_Click(object sender, RoutedEventArgs e)
{
if ((sender is not MenuItem mnu) || (mnu.Tag == null)) return;
uint accID = (uint)mnu.Tag;
Siprix.AccData? accData = objModel_.Accounts.GetData(accID);
if (accData == null) return;
AddAccountWindow wnd = new(objModel_, accData);
wnd.ShowDialog();
}
private void AccountDelete_Click(object sender, RoutedEventArgs e)
{
//Get selected
if(sender is not MenuItem mnu) return;
if (mnu?.DataContext is not Siprix.AccountModel acc) return;
//Confirm deleting
MessageBoxResult result = System.Windows.MessageBox.Show(this, "Confirm deleting account?", "Confirmation",
MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No);
if (result != MessageBoxResult.Yes) return;
//Delete
int err = objModel_.Accounts.Delete(acc);
if (err != Siprix.ErrorCode.kNoErr)
{
System.Windows.MessageBox.Show(this, objModel_.ErrorText(err), "Information",
MessageBoxButton.OK, MessageBoxImage.Information);
}
}
private void SubscriptionDelete_Click(object sender, RoutedEventArgs e)
{
//Get selected
if(sender is not MenuItem mnu) return;
if (mnu?.DataContext is not Siprix.SubscriptionModel subscr) return;
//Confirm deleting
MessageBoxResult result = System.Windows.MessageBox.Show(this, "Confirm deleting subscription?", "Confirmation",
MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No);
if (result != MessageBoxResult.Yes) return;
//Delete
int err = objModel_.Subscriptions.Delete(subscr);
if (err != Siprix.ErrorCode.kNoErr)
{
System.Windows.MessageBox.Show(this, objModel_.ErrorText(err), "Information",
MessageBoxButton.OK, MessageBoxImage.Information);
}
}
private void MessageSend_Click(object sender, RoutedEventArgs e)
{
//Check empty
if ((txMsgBody.Text.Length == 0) ||
(txMsgDestExt.Text.Length == 0) ||
(cbMsgAccounts.SelectedItem == null)) return;
//Get data from controls
Siprix.MsgData msgData = new();
msgData.ToExt = txMsgDestExt.Text;
msgData.FromAccId = ((Siprix.AccountModel)cbMsgAccounts.SelectedItem).ID;
msgData.Body = txMsgBody.Text;
//Try to send
objModel_.Messages.Send(msgData);
}
private void MessageDelete_Click(object sender, RoutedEventArgs e)
{
//Get selected
if (sender is not MenuItem mnu) return;
if (mnu?.DataContext is not Siprix.MessageModel msg) return;
//Confirm deleting
MessageBoxResult result = System.Windows.MessageBox.Show(this, "Confirm deleting message?", "Confirmation",
MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No);
if (result != MessageBoxResult.Yes) return;
//Delete
int err = objModel_.Messages.Delete(msg);
if (err != Siprix.ErrorCode.kNoErr)
{
System.Windows.MessageBox.Show(this, objModel_.ErrorText(err), "Information",
MessageBoxButton.OK, MessageBoxImage.Information);
}
}
private void ButtonMenu_Click(object sender, RoutedEventArgs e)
{
if (sender is not System.Windows.Controls.Button btn) return;
ContextMenu contextMenu = btn.ContextMenu;
if (contextMenu == null) return;
contextMenu.PlacementTarget = btn;
contextMenu.Placement = PlacementMode.Left;
contextMenu.HorizontalOffset = btn.ActualWidth;
contextMenu.IsOpen = true;
e.Handled = true;
}
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
{
var url = e.Uri.ToString();
Process.Start(new ProcessStartInfo(url)
{
UseShellExecute = true
});
}
}