-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCallRecentListControl.xaml.cs
More file actions
162 lines (134 loc) · 4.98 KB
/
CallRecentListControl.xaml.cs
File metadata and controls
162 lines (134 loc) · 4.98 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
using System.Windows.Controls;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Media.Effects;
using System.Windows.Media;
namespace SampleWpf;
public partial class CallRecentListControl : UserControl
{
readonly Siprix.ObjModel objModel_;
readonly Siprix.DestData data_ = new();
public delegate void CancelHandler();
public event CancelHandler? OnCancel;
DropShadowEffect? modalShadowEffect_;
public CallRecentListControl(Siprix.ObjModel om)
{
InitializeComponent();
objModel_ = om;
lbCdrs.DataContext = om.Cdrs;
lbCdrs.SelectionChanged += CdrsList_SelectionChanged;
cbAccounts.DataContext = om.Accounts;
objModel_.Accounts.Collection.CollectionChanged += (_, _) => OnAccountsList_CollectionChanged();
OnAccountsList_CollectionChanged();
btnCancel.Visibility = Visibility.Collapsed;
txDestExt.TextChanged += (_,_) => DestExt_TextChanged();
DestExt_TextChanged();
}
private void OnAccountsList_CollectionChanged()
{
bool accountsExists = (objModel_.Accounts.Collection.Count != 0);
tbErrText.Visibility = accountsExists ? Visibility.Collapsed : Visibility.Visible;
btnAudioCall.IsEnabled = accountsExists;
btnVideoCall.IsEnabled = accountsExists;
cbAccounts.IsEnabled = accountsExists;
txDestExt.IsEnabled = accountsExists;
}
private void CdrsList_SelectionChanged(object? sender, SelectionChangedEventArgs e)
{
if (lbCdrs.SelectedItem is Siprix.CdrModel cdrModel)
{
txDestExt.Text = cdrModel.RemoteExt;
cbAccounts.SelectedItem = objModel_.Accounts.FindByUri(cdrModel.AccUri);
}
}
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;
}
void RecentCallDelete_Click(object sender, EventArgs e)
{
if (sender is not MenuItem mnu) return;
if (mnu?.DataContext is Siprix.CdrModel item)
objModel_.Cdrs.Delete(item);
}
void AddCall_Click(object sender, EventArgs e)
{
Invite(false);
}
void AddVideoCall_Click(object sender, EventArgs e)
{
Invite(true);
}
void Invite(bool withVideo)
{
//Check empty
if (string.IsNullOrEmpty(txDestExt.Text) ||
(cbAccounts.SelectedItem == null))
return;
//Get data from controls
data_.ToExt = txDestExt.Text;
data_.FromAccId = ((Siprix.AccountModel)cbAccounts.SelectedItem).ID;
data_.WithVideo = withVideo;
//Try to make call
int err = objModel_.Calls.Invite(data_);
if (err != Siprix.ErrorCode.kNoErr)
{
tbErrText.Text = objModel_.ErrorText(err);
tbErrText.Visibility = Visibility.Visible;
return;
}
txDestExt.Text = "";
OnCancel?.Invoke();
}
void Cancel_Click(object sender, EventArgs e)
{
OnCancel?.Invoke();
}
public void SetDialogMode(bool dialogMode)
{
btnCancel.Visibility = dialogMode ? Visibility.Visible : Visibility.Collapsed;
brdShadow.BorderThickness = new Thickness(dialogMode? 1: 0);
brdShadow.Margin = new Thickness(dialogMode ? 5 : 0);
brdShadow.Effect = dialogMode ? GetModalShadowEffect() : null;
}
private void DestExt_TextChanged()
{
btnVideoCall.IsEnabled = txDestExt.Text.Length!=0;
btnAudioCall.IsEnabled = txDestExt.Text.Length != 0;
}
public void ShowDialpad_Click(object sender, EventArgs e)
{
gridDtmf.Visibility = (gridDtmf.Visibility == Visibility.Visible) ?
Visibility.Collapsed : Visibility.Visible;
}
public void DtmfSend_Click(object sender, EventArgs e)
{
if (sender is System.Windows.Controls.Button btnSender)
txDestExt.Text += (string)btnSender.Content;
}
DropShadowEffect GetModalShadowEffect()
{
if (modalShadowEffect_ == null)
{
modalShadowEffect_ = new DropShadowEffect
{
Color = new Color { A = 255, R = 211, G = 211, B = 211 },
//Direction = 320,
//ShadowDepth = 0,
Opacity = 1
};
}
return modalShadowEffect_;
}
private void txDestExt_GotKeyboardFocus(object sender, System.Windows.Input.KeyboardFocusChangedEventArgs e)
{
gridDtmf.Visibility = Visibility.Collapsed;
}
}