-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
125 lines (107 loc) · 4.35 KB
/
MainWindow.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
using Siprix;
using System.Diagnostics;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xml;
using System.Xml.Linq;
namespace SampleWpf
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
//Initialize SDK
Siprix.ObjModel.Instance.Initialize(App.Current.Dispatcher);
Siprix.ObjModel.Instance.Calls.PropertyChanged += onCalls_PropertyChanged;
//Set data context
tbNetworkLost.DataContext = Siprix.ObjModel.Instance.Networks;
lbAccounts.DataContext = Siprix.ObjModel.Instance.Accounts;
lbCalls.DataContext = Siprix.ObjModel.Instance.Calls;
tbLogs.DataContext = Siprix.ObjModel.Instance.Logs;
}
private void Window_Closed(object sender, EventArgs e)
{
//Uninitialize SDK
Siprix.ObjModel.Instance.UnInitialize();
}
private void onCalls_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(CallsListModel.LastIncomingCallId))
{
//Switch tab to 'Calls' when received incoming call
if (mainTabCtrl.SelectedIndex != 1) {
mainTabCtrl.SelectedIndex = 1;
}
}
}
private void AccountAdd_Click(object sender, RoutedEventArgs e)
{
AddAccountWindow wnd = new AddAccountWindow();
wnd.ShowDialog();
}
private void AccountEdit_Click(object sender, RoutedEventArgs e)
{
MenuItem? mnu = sender as MenuItem;
if ((mnu == null) || (mnu.Tag == null)) return;
uint accID = (uint)mnu.Tag;
AccData? accData = Siprix.ObjModel.Instance.Accounts.GetData(accID);
if (accData == null) return;
AddAccountWindow wnd = new AddAccountWindow(accData);
wnd.ShowDialog();
}
private void AccountDelete_Click(object sender, RoutedEventArgs e)
{
//Get selected
MenuItem? mnu = sender as MenuItem;
if ((mnu == null) || (mnu.Tag == null)) return;
uint accID = (uint)mnu.Tag;
//Confirm deleting
MessageBoxButton buttons = MessageBoxButton.YesNo;
MessageBoxImage icon = MessageBoxImage.Question;
MessageBoxResult defRes = MessageBoxResult.No;
MessageBoxResult result = System.Windows.MessageBox.Show(this, "Confirm deleting account?", "Confirmation", buttons, icon, defRes);
if (result != MessageBoxResult.Yes) return;
//Delete
int err = Siprix.ObjModel.Instance.Accounts.Delete(accID);
if (err != Module.kNoErr)
{
buttons = MessageBoxButton.OK;
icon = MessageBoxImage.Information;
System.Windows.MessageBox.Show(this, Siprix.ObjModel.Instance.ErrorText(err), "Information", buttons, icon);
}
}
private void ButtonMenu_Click(object sender, RoutedEventArgs e)
{
System.Windows.Controls.Button? btn = sender as System.Windows.Controls.Button;
if (btn == null) 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
});
}
}
}