forked from bicomsystems/outcall2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContactDialog.cpp
102 lines (80 loc) · 2.82 KB
/
ContactDialog.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
#include "ui_contactdialog.h"
#include "ContactDialog.h"
#include "AsteriskManager.h"
#include "Global.h"
#include "Notifier.h"
ContactDialog::ContactDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::ContactDialog)
{
ui->setupUi(this);
connect(ui->callButton, &QPushButton::clicked, this, &ContactDialog::onCallButton);
connect(ui->cancelButton, &QPushButton::clicked, this, &ContactDialog::onCancelButton);
connect(g_Notifier, &Notifier::settingsChanged, this, &ContactDialog::onSettingsChange);
connect(ui->treeWidget, &QTreeWidget::itemDoubleClicked, this, &ContactDialog::onItemDoubleClicked);
QStringList extensions = global::getSettingKeys("extensions");
for (int i = 0; i < extensions.size(); ++i)
ui->extensionBox->addItem(extensions[i]);
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
}
ContactDialog::~ContactDialog()
{
delete ui;
}
void ContactDialog::setName(const QString &name)
{
ui->contactName->setText(name);
}
void ContactDialog::setNumbers(QHash<QString, QString> &numbers)
{
clearCallTree();
QList<QString> numList = numbers.keys();
for(int i = 0; i < numList.size(); ++i)
{
QString type = numList[i];
QString number = numbers.value(type);
QTreeWidgetItem *extensionItem = new QTreeWidgetItem(ui->treeWidget);
extensionItem->setText(1, type);
extensionItem->setText(0, number);
}
}
void ContactDialog::onCallButton()
{
QList<QTreeWidgetItem*> selectedItems = ui->treeWidget->selectedItems();
if (selectedItems.size())
{
QTreeWidgetItem *item = selectedItems.at(0);
const QString number = item->text(0);
const QString from = ui->extensionBox->currentText();
const QString protocol = global::getSettingsValue(from, "extensions").toString();
g_pAsteriskManager->originateCall(from, number, protocol, from);
QDialog::close();
}
}
void ContactDialog::onItemDoubleClicked(QTreeWidgetItem *item, int)
{
QString number = item->text(0);
const QString from = ui->extensionBox->currentText();
const QString protocol = global::getSettingsValue(from, "extensions").toString();
g_pAsteriskManager->originateCall(from, number, protocol, from);
QDialog::close();
}
void ContactDialog::onCancelButton()
{
QDialog::close();
}
void ContactDialog::onSettingsChange()
{
ui->extensionBox->clear();
QStringList extensions = global::getSettingKeys("extensions");
for (int i = 0; i < extensions.size(); ++i)
ui->extensionBox->addItem(extensions[i]);
}
void ContactDialog::clearCallTree()
{
int n = ui->treeWidget->topLevelItemCount();
for (int i = 0; i < n; ++i)
ui->treeWidget->takeTopLevelItem(i);
if (n > 0)
clearCallTree();
}