-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathIncomingCallNotification.xaml.cs
96 lines (90 loc) · 3.38 KB
/
IncomingCallNotification.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
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Automation;
using System.Windows.Forms;
namespace FSClient {
/// <summary>
/// Interaction logic for IncomingCallNotifcation.xaml
/// </summary>
public partial class IncomingCallNotification : Window {
private static List<IncomingCallNotification> windows = new List<IncomingCallNotification>();
public IncomingCallNotification() {
this.InitializeComponent();
}
private Call call;
public static void ShowCallNotification(Call call) {
IncomingCallNotification notifier = new IncomingCallNotification();
notifier.call = call;
windows.Add(notifier);
notifier.Show();
}
private System.ComponentModel.PropertyChangedEventHandler prop_changed;
private void Window_Loaded(object sender, RoutedEventArgs e) {
PositionWindows();
lblCaller.Text = call.other_party_name + " - " + call.other_party_number;
Title = "FSClient Incoming Call " + lblCaller.Text;
prop_changed = new System.ComponentModel.PropertyChangedEventHandler(call_PropertyChanged);
call.PropertyChanged += prop_changed;
btnSendVoicemail.Visibility = call.CanSendToVoicemail() ? Visibility.Visible : Visibility.Hidden;
btnTransfer.ContextMenu = Broker.get_instance().XFERContextMenu();
btnTransfer.DataContext = call;
if (Broker.get_instance().IncomingKeyboardFocus)
DelayedFunction.DelayedCall("BubbleTop", MakeUsTop, 500);
Show();
Topmost = true;
}
private void MakeUsTop(){
Dispatcher.BeginInvoke((Action)(() => Utils.SetForegroundWindow(this)));
}
void call_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) {
if (e.PropertyName == "state") {
if (call.state != Call.CALL_STATE.Ringing)
close_us();
}
}
private static void PositionWindows() {
double top_offset = 0;
double left_offset = 0;
double window_height = 0;
bool is_first = true;
var mainForm = MainWindow.get_instance();
foreach (IncomingCallNotification window in windows) {
if (is_first) {
is_first = false;
System.Drawing.Rectangle workingArea = new System.Drawing.Rectangle(DpiUtil.ScaleIntX( mainForm.Left), DpiUtil.ScaleIntY(mainForm.Top), DpiUtil.ScaleIntX(mainForm.ActualWidth), DpiUtil.ScaleIntY(mainForm.ActualHeight));
workingArea = Screen.GetWorkingArea(workingArea);
left_offset = DpiUtil.DeScaleIntX( workingArea.Right) - window.ActualWidth;
top_offset = DpiUtil.DeScaleIntY(workingArea.Bottom) - window.ActualHeight;
window_height = window.ActualHeight;
}
window.Top = top_offset;
window.Left = left_offset;
top_offset -= window_height;
}
}
private void close_us() {
call.PropertyChanged -= prop_changed;
Hide();
windows.Remove(this);
PositionWindows();
Close();
}
private void btnCall_Click(object sender, RoutedEventArgs e) {
call.answer();
}
private void btnHangup_Click(object sender, RoutedEventArgs e) {
call.hangup();
}
private void btnSendVoicemail_Click(object sender, RoutedEventArgs e) {
call.SendToVoicemail();
}
private void btnTransfer_Click(object sender, RoutedEventArgs e) {
String res = InputBox.GetInput("Transfer To", "Enter a number to transfer to.", "");
if (String.IsNullOrEmpty(res))
return;
if (call != null)
call.Transfer(res);
}
}
}