1
/***************************************************************************
2
* Author : Mathieu Leduc-Hamel mathieu.leduc-hamel@savoirfairelinux.com *
3
* Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com>*
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 3 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
**************************************************************************/
22
#include "HistoryTreeItem.h"
25
#include <QtCore/QStringList>
26
#include <QtGui/QGridLayout>
27
#include <QtGui/QMenu>
28
#include <QtGui/QLabel>
29
#include <QtGui/QSpacerItem>
38
#include "lib/sflphone_const.h"
39
#include "lib/Contact.h"
43
#include "AkonadiBackend.h"
45
#include "widgets/BookmarkDock.h"
47
const char * HistoryTreeItem::callStateIcons[12] = {ICON_INCOMING, ICON_RINGING, ICON_CURRENT, ICON_DIALING, ICON_HOLD, ICON_FAILURE, ICON_BUSY, ICON_TRANSFER, ICON_TRANSF_HOLD, "", "", ICON_CONFERENCE};
50
HistoryTreeItem::HistoryTreeItem(QWidget *parent ,QString phone)
51
: QWidget(parent), m_pItemCall(0),m_pMenu(0)
53
setContextMenuPolicy(Qt::CustomContextMenu);
55
m_pCallAgain = new KAction(this);
56
m_pAddContact = new KAction(this);
57
m_pCopy = new KAction(this);
58
m_pEmail = new KAction(this);
59
m_pAddToContact = new KAction(this);
60
m_pBookmark = new KAction(this);
62
m_pCallAgain->setShortcut ( Qt::CTRL + Qt::Key_Enter );
63
m_pCallAgain->setText ( i18n("Call Again") );
64
m_pCallAgain->setIcon ( KIcon(ICON_DIALING) );
66
m_pAddToContact->setShortcut ( Qt::CTRL + Qt::Key_E );
67
m_pAddToContact->setText ( i18n("Add Number to Contact") );
68
m_pAddToContact->setIcon ( KIcon("list-resource-add") );
69
m_pAddToContact->setDisabled ( true );
71
m_pAddContact->setShortcut ( Qt::CTRL + Qt::Key_E );
72
m_pAddContact->setText ( i18n("Add Contact") );
73
m_pAddContact->setIcon ( KIcon("contact-new") );
75
m_pCopy->setShortcut ( Qt::CTRL + Qt::Key_C );
76
m_pCopy->setText ( i18n("Copy") );
77
m_pCopy->setIcon ( KIcon("edit-copy") );
78
m_pCopy->setDisabled ( true );
80
m_pEmail->setShortcut ( Qt::CTRL + Qt::Key_M );
81
m_pEmail->setText ( i18n("Send Email") );
82
m_pEmail->setIcon ( KIcon("mail-message-new") );
83
m_pEmail->setDisabled ( true );
85
m_pBookmark->setShortcut ( Qt::CTRL + Qt::Key_D );
86
m_pBookmark->setText ( i18n("Bookmark") );
87
m_pBookmark->setIcon ( KIcon("bookmarks") );
89
connect(m_pCallAgain , SIGNAL(triggered()) , this , SLOT(callAgain() ));
90
connect(m_pAddContact , SIGNAL(triggered()) , this , SLOT(addContact() ));
91
connect(m_pCopy , SIGNAL(triggered()) , this , SLOT(copy() ));
92
connect(m_pEmail , SIGNAL(triggered()) , this , SLOT(sendEmail() ));
93
connect(m_pAddToContact , SIGNAL(triggered()) , this , SLOT(addToContact() ));
94
connect(m_pBookmark , SIGNAL(triggered()) , this , SLOT(bookmark() ));
95
connect(this , SIGNAL(customContextMenuRequested(QPoint)) , this , SLOT(showContext(QPoint) ));
97
m_pIconL = new QLabel( this );
98
m_pPeerNameL = new QLabel( this );
99
m_pCallNumberL = new QLabel( this );
100
m_pDurationL = new QLabel( this );
101
m_pTimeL = new QLabel( this );
103
m_pIconL->setMinimumSize(70,48);
104
m_pIconL->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
105
QSpacerItem* verticalSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding);
107
QGridLayout* mainLayout = new QGridLayout(this);
108
mainLayout->addWidget ( m_pIconL,0,0,4,1 );
109
mainLayout->addWidget ( m_pPeerNameL,0,1 );
110
mainLayout->addWidget ( m_pCallNumberL,1,1 );
111
mainLayout->addWidget ( m_pTimeL,2,1 );
112
mainLayout->addItem ( verticalSpacer,3,1 );
113
mainLayout->addWidget ( m_pDurationL,0,2,4,1 );
114
setLayout(mainLayout);
115
setMinimumSize(QSize(50, 30));
117
if (!phone.isEmpty()) {
118
getContactInfo(phone);
119
m_pCallNumberL->setText(phone);
120
m_PhoneNumber = phone;
125
HistoryTreeItem::~HistoryTreeItem()
131
/*****************************************************************************
135
****************************************************************************/
137
///Return the call item
138
Call* HistoryTreeItem::call() const
143
///The item have to be updated
144
void HistoryTreeItem::updated()
146
if (!getContactInfo(m_pItemCall->getPeerPhoneNumber())) {
147
if(! m_pItemCall->getPeerName().trimmed().isEmpty()) {
148
m_pPeerNameL->setText("<b>"+m_pItemCall->getPeerName()+"</b>");
151
call_state state = m_pItemCall->getState();
152
bool recording = m_pItemCall->getRecording();
153
if(state != CALL_STATE_OVER) {
154
if(state == CALL_STATE_CURRENT && recording) {
155
m_pIconL->setPixmap(QPixmap(ICON_CURRENT_REC));
158
QString str = QString(callStateIcons[state]);
159
m_pIconL->setPixmap(QPixmap(str));
161
m_pCallNumberL->setText(m_pItemCall->getPeerPhoneNumber());
163
if(state == CALL_STATE_DIALING) {
164
m_pCallNumberL->setText(m_pItemCall->getCallNumber());
170
///Show the context menu
171
void HistoryTreeItem::showContext(const QPoint& pos)
174
m_pMenu = new QMenu(this);
175
m_pMenu->addAction( m_pCallAgain );
176
m_pMenu->addAction( m_pAddContact );
177
m_pMenu->addAction( m_pAddToContact );
178
m_pMenu->addAction( m_pCopy );
179
m_pMenu->addAction( m_pEmail );
180
m_pMenu->addAction( m_pBookmark );
182
m_pMenu->exec(mapToGlobal(pos));
186
void HistoryTreeItem::sendEmail()
189
kDebug() << "Sending email";
192
///Call the caller again
193
void HistoryTreeItem::callAgain()
196
kDebug() << "Calling "<< m_pItemCall->getPeerPhoneNumber();
198
SFLPhone::model()->addDialingCall(m_Name, SFLPhone::app()->model()->getCurrentAccountId())->setCallNumber(m_PhoneNumber);
202
void HistoryTreeItem::copy()
205
kDebug() << "Copying contact";
208
///Create a contact from those informations
209
void HistoryTreeItem::addContact()
211
kDebug() << "Adding contact";
212
Contact* aContact = new Contact();
213
aContact->setPhoneNumbers(PhoneNumbers() << new Contact::PhoneNumber(m_PhoneNumber, "Home"));
214
aContact->setFormattedName(m_Name);
215
AkonadiBackend::getInstance()->addNewContact(aContact);
218
///Add this call number to an existing contact
219
void HistoryTreeItem::addToContact()
222
kDebug() << "Adding to contact";
225
///Bookmark this contact
226
void HistoryTreeItem::bookmark()
228
SFLPhone::app()->bookmarkDock()->addBookmark(m_PhoneNumber);
232
/*****************************************************************************
236
****************************************************************************/
238
///Set the call to be handled by this item
239
void HistoryTreeItem::setCall(Call *call)
243
if (m_pItemCall->isConference()) {
244
m_pIconL->setVisible(true);
248
m_pCallNumberL->setText(m_pItemCall->getPeerPhoneNumber());
250
m_pTimeL->setText(QDateTime::fromTime_t(m_pItemCall->getStartTimeStamp().toUInt()).toString());
252
int dur = m_pItemCall->getStopTimeStamp().toInt() - m_pItemCall->getStartTimeStamp().toInt();
253
m_pDurationL->setText(QString("%1").arg(dur/3600,2)+":"+QString("%1").arg((dur%3600)/60,2)+":"+QString("%1").arg((dur%3600)%60,2)+" ");
255
connect(m_pItemCall , SIGNAL(changed()) , this , SLOT(updated() ));
258
m_TimeStamp = m_pItemCall->getStartTimeStamp().toUInt();
260
m_Name = m_pItemCall->getPeerName();
261
m_PhoneNumber = m_pItemCall->getPeerPhoneNumber();
264
///Set the index associed with this widget
265
void HistoryTreeItem::setItem(QTreeWidgetItem* item)
271
/*****************************************************************************
275
****************************************************************************/
277
///Can a contact be associed with this call?
278
bool HistoryTreeItem::getContactInfo(QString phoneNumber)
280
Contact* contact = AkonadiBackend::getInstance()->getContactByPhone(phoneNumber);
282
if (contact->getPhoto() != NULL)
283
m_pIconL->setPixmap(*contact->getPhoto());
284
m_pPeerNameL->setText("<b>"+contact->getFormattedName()+"</b>");
287
m_pIconL->setPixmap(QPixmap(KIcon("user-identity").pixmap(QSize(48,48))));
288
m_pPeerNameL->setText(i18n("<b>Unknow</b>"));
294
///Return the time stamp
295
uint HistoryTreeItem::getTimeStamp()
300
///Return the duration
301
uint HistoryTreeItem::getDuration()
306
///Return the caller name
307
QString HistoryTreeItem::getName()
312
///Return the caller peer number
313
QString HistoryTreeItem::getPhoneNumber()
315
return m_PhoneNumber;
318
///Get the index item assiciated with this widget
319
QTreeWidgetItem* HistoryTreeItem::getItem()
b'\\ No newline at end of file'