1
#include "MainWidget.h"
3
#include "../../src/lib/sflphone_const.h"
4
#include "../../src/lib/callmanager_interface_singleton.h"
5
#include "../../src/lib/CallModel.h"
7
MainWidget::MainWidget() : Plasma::Frame(), m_mainLayout(0), frmCalls(0), frmContact(0), frmHistory(0),currentMode(CALL)
9
mainTabs = new Plasma::TabBar ( this );
10
frmCalls = new Plasma::Frame ( this );
11
callLayout = new QGraphicsLinearLayout ( Qt::Vertical );
12
callScrollArea = new Plasma::ScrollWidget ( this );
13
frmContact = new Plasma::Frame ( this );
14
contactScrollArea = new Plasma::ScrollWidget ( this );
15
frmHistory = new Plasma::Frame ( this );
16
historyLayout = new QGraphicsLinearLayout ( Qt::Vertical );
17
historyScrollArea = new Plasma::ScrollWidget ( this );
19
mainLayout()->addItem(mainTabs);
20
//connect(mainTabs, SIGNAL(currentChanged(int)), this, SLOT(modeChanged(int)));
22
frmCalls->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
23
frmCalls->setLayout(callLayout);
25
callScrollArea->setWidget(frmCalls);
27
frmContact->setText("Contact");
28
frmContact->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
30
contactScrollArea->setWidget(frmContact);
32
frmHistory->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
33
frmHistory->setLayout(historyLayout);
35
historyScrollArea->setWidget(frmHistory);
37
dialPage = new DialPage();
38
connect(dialPage, SIGNAL(call(QString)), this, SLOT(call(QString)));
40
QGraphicsLinearLayout* callTabLayout = new QGraphicsLinearLayout( Qt::Vertical );
41
QGraphicsLinearLayout* historyTabLayout = new QGraphicsLinearLayout( Qt::Vertical );
42
QGraphicsLinearLayout* contactTabLayout = new QGraphicsLinearLayout( Qt::Vertical );
43
QGraphicsLinearLayout* addTabLayout = new QGraphicsLinearLayout( Qt::Vertical );
45
callTabLayout->addItem ( callScrollArea );
46
historyTabLayout->addItem ( historyScrollArea );
47
contactTabLayout->addItem ( contactScrollArea );
48
addTabLayout->addItem(dialPage);
50
mainTabs->addTab( "Call" , callTabLayout );
51
mainTabs->addTab( "History" , historyTabLayout );
52
mainTabs->addTab( "Contact" , contactTabLayout );
53
mainTabs->addTab( KIcon("list-add") , "", addTabLayout );
55
//mainLayout()->addItem(callTabLayout);
57
//mainLayout()->addItem(callScrollArea);
58
//mainLayout()->addItem(historyScrollArea);
59
//mainLayout()->addItem(contactScrollArea);
61
initPos = frmCalls->pos();
63
frmCalls->setPos ( initPos );
64
frmHistory->setPos( initPos );
65
frmContact->setPos( initPos );
67
setMinimumSize(285,390);
70
void MainWidget::dataUpdated(const QString& source, const Plasma::DataEngine::Data& data)
72
if ((source == "calls") && (frmCalls)) {
73
QHash<QString, QVariant> value = data;
74
bool modified = false;
75
foreach(QVariant call, value) {
76
if (!callWidgetList[value.key(call)]) {
77
callWidgetList[ value.key(call) ] = new CallItem();
78
callWidgetList[ value.key(call) ]->setCallId(value.key(call));
79
callLayout->insertItem(0,callWidgetList[value.key(call)]);
80
mainTabs->setCurrentIndex(CALL);
83
callWidgetList[value.key(call)]->setCallerName(call.toHash() [ "Name" ].toString());
84
callWidgetList[value.key(call)]->setCallerNumber(call.toHash()[ "Number" ].toString());
85
callWidgetList[value.key(call)]->setState(call.toHash() [ "State" ].toInt());
87
if (call.toHash()["State"].toInt() == CALL_STATE_INCOMING) {
88
emit requierAttention();
91
topLevelItems[value.key(call)] = callWidgetList[value.key(call)];
95
// sflphoneEngine->connectSource("conferences", this,0/*Update only if something happen*/);
97
else if (source == "info") {
98
if (!data["Account"].isNull() || data["Account"].isValid())
99
currentAccountId = data["Account"].toString();
101
else if (source == "conferences") {
102
QHash<QString, QVariant> value = data;
103
foreach(QVariant call, value) {
104
qDebug() << "Painting conference: " << call;//.toHash();
105
if (!topLevelItems[value.key(call)]) {
106
topLevelItems[value.key(call)] = new ConferenceItem();
107
((ConferenceItem*) topLevelItems[value.key(call)])->setConfId(value.key(call));
108
callLayout->addItem((ConferenceItem*) topLevelItems[value.key(call)]);
109
mainTabs->setCurrentIndex(CALL);
111
QList<CallItem*> toSend;
112
foreach (QString callId, call.toStringList()) {
113
if (callWidgetList[callId]) {
114
toSend.push_back(callWidgetList[callId]);
115
callWidgetList[callId]->setParent(0);
116
if (topLevelItems[callId]) {
117
topLevelItems.remove(callId);
121
qDebug() << "Call not found";
123
((ConferenceItem*)topLevelItems[value.key(call)])->setCallList(toSend);
126
else if (source == "history") {
127
QHash<QString, QVariant> value = data;
128
for (QHash<QString, QVariant>::iterator i = value.begin(); i != value.end(); ++i) {
129
QString key = i.key();
130
//QHash<QString, CallItem*> historyWidgetList;
131
if ( ! historyWidgetList[key]) {
132
historyWidgetList[ i.key() ] = new CallItem();
133
historyWidgetList[ i.key() ]->setCallId(i.key());
134
historyLayout->addItem(historyWidgetList[i.key()]);
136
historyWidgetList[ i.key() ]->setCallerName(i.value().toHash() [ "Name" ].toString());
137
historyWidgetList[ i.key() ]->setCallerNumber(i.value().toHash() [ "Number" ].toString());
138
historyWidgetList[ i.key() ]->setDate(i.value().toHash() [ "Date" ].toInt()) ;
143
QGraphicsLinearLayout* MainWidget::mainLayout()
146
m_mainLayout = new QGraphicsLinearLayout(Qt::Vertical);
147
m_mainLayout->setContentsMargins(0, 0, 0, 0);
148
m_mainLayout->setSpacing(5);
149
setLayout(m_mainLayout);
154
void MainWidget::call(QString number)
157
// qDebug() << "Calling " << number << " with account " << currentAccountId << ", " << CallModelConvenience::getAccountList()->size() << " account registred";
158
// CallManagerInterface& callManager = CallManagerInterfaceSingleton::getInstance();
159
// callManager.placeCall(currentAccountId, CallModelConvenience::generateCallId(), number);