-
Notifications
You must be signed in to change notification settings - Fork 18
/
PlaceCallDialog.cpp
166 lines (133 loc) · 4.45 KB
/
PlaceCallDialog.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
#include "PlaceCallDialog.h"
#include "ui_placecalldialog.h"
#include "Global.h"
#include "ContactManager.h"
#include "SearchBox.h"
#include "AsteriskManager.h"
#include "Notifier.h"
#include <QHash>
PlaceCallDialog::PlaceCallDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::PlaceCallDialog)
{
ui->setupUi(this);
connect(ui->callButton, &QPushButton::clicked, this, &PlaceCallDialog::onCallButton);
connect(ui->cancelButton, &QPushButton::clicked, this, &PlaceCallDialog::onCancelButton);
connect(ui->searchLine, &SearchBox::selected, this, &PlaceCallDialog::onChangeContact);
connect(ui->treeWidget, &QTreeWidget::itemClicked, this, &PlaceCallDialog::onItemClicked);
connect(ui->treeWidget, &QTreeWidget::itemDoubleClicked, this, &PlaceCallDialog::onItemDoubleClicked);
connect(g_pContactManager, &ContactManager::contactsLoaded, this, &PlaceCallDialog::onContactsLoaded);
connect(g_Notifier, &Notifier::settingsChanged, this, &PlaceCallDialog::onSettingsChange);
void (QComboBox:: *sig)(const QString&) = &QComboBox::currentIndexChanged;
connect(ui->contactBox, sig, this, &PlaceCallDialog::onContactIndexChange);
QStringList extensions = global::getSettingKeys("extensions");
for (int i = 0; i < extensions.size(); ++i)
ui->fromBox->addItem(extensions[i]);
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
m_contacts = g_pContactManager->getContacts();
QStringList data;
foreach(Contact *contact, m_contacts)
{
data << contact->name;
ui->contactBox->addItem(contact->name);
}
ui->searchLine->setData(data);
}
PlaceCallDialog::~PlaceCallDialog()
{
delete ui;
}
void PlaceCallDialog::show()
{
ui->contactBox->setCurrentIndex(0);
ui->searchLine->clear();
QDialog::show();
}
void PlaceCallDialog::onCallButton()
{
if (!ui->phoneLine->text().isEmpty())
{
const QString number = ui->phoneLine->text();
const QString from = ui->fromBox->currentText();
const QString protocol = global::getSettingsValue(from, "extensions").toString();
g_pAsteriskManager->originateCall(from, number, protocol, from);
QDialog::close();
}
}
void PlaceCallDialog::onCancelButton()
{
QDialog::close();
}
void PlaceCallDialog::onChangeContact(QString name)
{
Contact *contact = g_pContactManager->findContact(name);
clearCallTree();
if (contact != NULL)
{
QList<QString> numbers = contact->numbers.keys();
QString number, type;
for (int i = 0; i < numbers.size(); ++i)
{
type = numbers[i];
number = contact->numbers.value(type);
QTreeWidgetItem *item = new QTreeWidgetItem(ui->treeWidget);
item->setText(0, number);
item->setText(1, type);
}
}
QTreeWidgetItem *firstItem = ui->treeWidget->topLevelItem(0);
if (firstItem)
{
firstItem->setSelected(true);
QString number = firstItem->text(0);
ui->phoneLine->setText(number);
}
else
{
ui->phoneLine->clear();
}
}
void PlaceCallDialog::onItemDoubleClicked(QTreeWidgetItem *item, int)
{
QString number = item->text(0);
const QString from = ui->fromBox->currentText();
const QString protocol = global::getSettingsValue(from, "extensions").toString();
g_pAsteriskManager->originateCall(from, number, protocol, from);
QDialog::close();
}
void PlaceCallDialog::onItemClicked(QTreeWidgetItem *item, int)
{
QString number = item->text(0);
ui->phoneLine->setText(number);
}
void PlaceCallDialog::onContactIndexChange(const QString &name)
{
ui->searchLine->setText(name);
onChangeContact(name);
}
void PlaceCallDialog::onContactsLoaded(QList<Contact *> &contacts)
{
QStringList data;
ui->contactBox->clear();
foreach(Contact *contact, contacts)
{
data << contact->name;
ui->contactBox->addItem(contact->name);
}
ui->searchLine->setData(data);
}
void PlaceCallDialog::clearCallTree()
{
int n = ui->treeWidget->topLevelItemCount();
for (int i = 0; i < n; ++i)
ui->treeWidget->takeTopLevelItem(i);
if (n > 0)
clearCallTree();
}
void PlaceCallDialog::onSettingsChange()
{
ui->fromBox->clear();
QStringList extensions = global::getSettingKeys("extensions");
for (int i = 0; i < extensions.size(); ++i)
ui->fromBox->addItem(extensions[i]);
}