forked from yohanson/astercti
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotificationFrame.cpp
182 lines (161 loc) · 5.34 KB
/
notificationFrame.cpp
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
#include <iostream>
#include <wx/event.h>
#include <wx/dcclient.h>
#include <wx/settings.h>
#include <wx/intl.h>
#include <wx/string.h>
#include <wx/display.h>
#include <wx/app.h>
#include <wx/process.h>
#include <wx/txtstrm.h>
#include "notificationFrame.h"
#include "controller.h"
const long notificationFrame::ID_HTMLWINDOW1 = wxNewId();
const long notificationFrame::ID_BUTTON1 = wxNewId();
void ExecCommand(wxString &cmd, wxArrayString &output)
{
wxProcess p;
p.Redirect();
wxExecute(cmd, wxEXEC_SYNC, &p);
wxInputStream *i = p.GetInputStream();
if(i)
{
wxTextInputStream t(*i, " \t", wxConvUTF8);
while(!i->Eof())
{
output.Add(t.ReadLine());
}
}
}
notificationFrame::notificationFrame(wxWindow* parent,wxWindowID id,const wxPoint& pos,const wxSize& size)
{
descr = "notify frame";
wxBoxSizer* BoxSizerButtons;
Create(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSTAY_ON_TOP|wxFRAME_NO_TASKBAR|wxFRAME_TOOL_WINDOW|wxNO_BORDER, _T("wxID_ANY"));
SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_INFOTEXT));
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_INFOBK));
BoxSizer1 = new wxBoxSizer(wxVERTICAL);
HtmlWindow1 = new wxHtmlWindow(this, ID_HTMLWINDOW1, wxDefaultPosition, wxSize(400,30), wxHW_SCROLLBAR_NEVER|wxHW_NO_SELECTION, _T("ID_HTMLWINDOW1"));
HtmlWindow1->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_INFOTEXT));
HtmlWindow1->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_INFOBK));
BoxSizer1->Add(HtmlWindow1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 1);
BoxSizerButtons = new wxBoxSizer(wxHORIZONTAL);
Button1 = new wxButton(this, ID_BUTTON1, wxT("Нет"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT, wxDefaultValidator, _T("ID_BUTTON1"));
BoxSizerButtons->Add(Button1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 1);
BoxSizer1->Add(BoxSizerButtons, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
SetSizer(BoxSizer1);
BoxSizer1->Fit(this);
BoxSizer1->SetSizeHints(this);
buttonsHeight = BoxSizerButtons->GetSize().GetHeight();
Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)¬ificationFrame::OnButton1Click);
Connect(wxEVT_PAINT,(wxObjectEventFunction)¬ificationFrame::OnPaint);
Bind(wxEVT_HTML_LINK_CLICKED, ¬ificationFrame::OnLinkClicked, this);
}
notificationFrame::~notificationFrame()
{
}
void notificationFrame::SetLookupCmd(std::string cmd) {
std::cout << "Lookup cmd: " << cmd << std::endl;
m_lookup_cmd = cmd;
}
void notificationFrame::OnPaint(wxPaintEvent& event)
{
wxPaintDC dc(this);
wxColor fg,bg,middle;
fg = wxSystemSettings::GetColour(wxSYS_COLOUR_INFOTEXT);
bg = wxSystemSettings::GetColour(wxSYS_COLOUR_INFOBK);
middle = wxColour((fg.Red()+bg.Red()*2)/3, (fg.Green()+bg.Green()*2)/3, (fg.Blue()+bg.Blue()*2)/3);
dc.SetPen(middle);
dc.SetBrush(*wxTRANSPARENT_BRUSH);
wxSize sz(GetSize());
dc.DrawRectangle(0, 0, sz.x, sz.y);
event.Skip();
}
void notificationFrame::OnButton1Click(wxCommandEvent& event)
{
m_controller->HangupChannel(m_current_channel);
}
void notificationFrame::OnLinkClicked(wxHtmlLinkEvent& event)
{
wxLaunchDefaultBrowser(event.GetLinkInfo().GetHref());
}
void notificationFrame::SetHtml(const wxString &s)
{
wxString bgcolor = wxSystemSettings::GetColour(wxSYS_COLOUR_INFOBK).GetAsString();
HtmlWindow1->SetPage("<body bgcolor='"+bgcolor+"'>"+s+"</body>");
int height = HtmlWindow1->GetInternalRepresentation()->GetHeight();
int width = HtmlWindow1->GetInternalRepresentation()->GetWidth();
BoxSizer1->SetItemMinSize(HtmlWindow1, width, height);
HtmlWindow1->Fit();
Fit();
wxDisplay display;
wxRect rect = display.GetClientArea();
wxSize size = GetSize();
Move(rect.GetBottomRight()-size-wxSize(0,4));
}
void notificationFrame::UpdateSize()
{
}
void notificationFrame::handleEvent(const AmiMessage &message)
{
bool is_channel_up = false;
wxString html = "";
std::string callerid = "";
try {
if (message.at("Event") == "Newstate")
{
if (message.at("ChannelStateDesc") == "Up"
|| message.at("ChannelStateDesc") == "Ring"
|| message.at("ChannelStateDesc") == "Ringing")
{
is_channel_up = true;
callerid = message.at("ConnectedLineNum");
if (callerid == m_controller->GetMyExten() && message.at("ChannelStateDesc") == "Ringing")
{
html = wxT("Снимите трубку для звонка на номер <b>") + message.at("ConnectedLineName") + "</b>";
SetHtml(html);
}
else
{
html = "Channel: " + message.at("Channel") + "<br>CallerID: " + message.at("ConnectedLineNum") + " (" + message.at("ConnectedLineName") + ")";
}
m_current_channel = message.at("Channel");
}
}
else if (message.at("Event") == "Hangup")
{
is_channel_up = false;
}
}
catch (std::out_of_range)
{
}
if (is_channel_up && !callerid.empty() && callerid != "<unknown>")
{
if (!m_lookup_cmd.empty())
{
SetHtml(html + "<br><img src='wait.gif'>");
Show();
wxArrayString output;
wxString cmd;
cmd.Printf(wxString(m_lookup_cmd), callerid);
ExecCommand(cmd, output);
wxString out = "";
for (auto iter : output)
{
std::cout << "String: " << iter << std::endl;
out += iter;
}
SetHtml(html+"<br />" + out);
std::cout << out << std::endl;
}
else
{
SetHtml(html);
}
Show();
}
else {
Hide();
}
}