~ubuntu-branches/ubuntu/precise/sflphone/precise

« back to all changes in this revision

Viewing changes to kde/src/widgets/HistoryTreeItem.cpp

  • Committer: Package Import Robot
  • Author(s): Whoopie
  • Date: 2012-03-22 10:29:10 UTC
  • mfrom: (4.1.12 sid)
  • Revision ID: package-import@ubuntu.com-20120322102910-tb8hugi2su1tguwh
Tags: 1.0.2-1ubuntu1
* Apply some upstream patches to fix FTBFS (LP: #913018):
  - debian/patches/05_glib_includes.patch: fix glib includes.
  - debian/patches/06_use_XkbKeycodeToKeysym.patch: use 
    XkbKeycodeToKeysym instead of (deprecated) XKeycodeToKeysym.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Author : Mathieu Leduc-Hamel mathieu.leduc-hamel@savoirfairelinux.com *
 
3
 *            Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com>*
 
4
 *                                                                         *
 
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.                                   *
 
9
 *                                                                         *
 
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.                          *
 
14
 *                                                                         *
 
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
 **************************************************************************/
 
20
 
 
21
//Parent
 
22
#include "HistoryTreeItem.h"
 
23
 
 
24
//Qt
 
25
#include <QtCore/QStringList>
 
26
#include <QtGui/QGridLayout>
 
27
#include <QtGui/QMenu>
 
28
#include <QtGui/QLabel>
 
29
#include <QtGui/QSpacerItem>
 
30
 
 
31
//KDE
 
32
#include <KLocale>
 
33
#include <KDebug>
 
34
#include <KAction>
 
35
#include <KIcon>
 
36
 
 
37
//SFLPhone library
 
38
#include "lib/sflphone_const.h"
 
39
#include "lib/Contact.h"
 
40
#include "lib/Call.h"
 
41
 
 
42
//SFLPhone
 
43
#include "AkonadiBackend.h"
 
44
#include "SFLPhone.h"
 
45
#include "widgets/BookmarkDock.h"
 
46
 
 
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};
 
48
 
 
49
///Constructor
 
50
HistoryTreeItem::HistoryTreeItem(QWidget *parent ,QString phone)
 
51
   : QWidget(parent), m_pItemCall(0),m_pMenu(0)
 
52
{
 
53
   setContextMenuPolicy(Qt::CustomContextMenu);
 
54
 
 
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);
 
61
 
 
62
   m_pCallAgain->setShortcut    ( Qt::CTRL + Qt::Key_Enter       );
 
63
   m_pCallAgain->setText        ( i18n("Call Again")             );
 
64
   m_pCallAgain->setIcon        ( KIcon(ICON_DIALING)            );
 
65
 
 
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                           );
 
70
 
 
71
   m_pAddContact->setShortcut   ( Qt::CTRL + Qt::Key_E           );
 
72
   m_pAddContact->setText       ( i18n("Add Contact")            );
 
73
   m_pAddContact->setIcon       ( KIcon("contact-new")           );
 
74
 
 
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                           );
 
79
 
 
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                           );
 
84
 
 
85
   m_pBookmark->setShortcut     ( Qt::CTRL + Qt::Key_D           );
 
86
   m_pBookmark->setText         ( i18n("Bookmark")               );
 
87
   m_pBookmark->setIcon         ( KIcon("bookmarks")             );
 
88
 
 
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) ));
 
96
 
 
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 );
 
102
 
 
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);
 
106
 
 
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));
 
116
 
 
117
   if (!phone.isEmpty()) {
 
118
      getContactInfo(phone);
 
119
      m_pCallNumberL->setText(phone);
 
120
      m_PhoneNumber = phone;
 
121
   }
 
122
}
 
123
 
 
124
///Destructor
 
125
HistoryTreeItem::~HistoryTreeItem()
 
126
{
 
127
 
 
128
}
 
129
 
 
130
 
 
131
/*****************************************************************************
 
132
 *                                                                           *
 
133
 *                                  Mutator                                  *
 
134
 *                                                                           *
 
135
 ****************************************************************************/
 
136
 
 
137
///Return the call item
 
138
Call* HistoryTreeItem::call() const
 
139
{
 
140
   return m_pItemCall;
 
141
}
 
142
 
 
143
///The item have to be updated
 
144
void HistoryTreeItem::updated()
 
145
{
 
146
   if (!getContactInfo(m_pItemCall->getPeerPhoneNumber())) {
 
147
      if(! m_pItemCall->getPeerName().trimmed().isEmpty()) {
 
148
         m_pPeerNameL->setText("<b>"+m_pItemCall->getPeerName()+"</b>");
 
149
      }
 
150
   }
 
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));
 
156
      }
 
157
      else {
 
158
         QString str = QString(callStateIcons[state]);
 
159
         m_pIconL->setPixmap(QPixmap(str));
 
160
      }
 
161
      m_pCallNumberL->setText(m_pItemCall->getPeerPhoneNumber());
 
162
 
 
163
      if(state == CALL_STATE_DIALING) {
 
164
         m_pCallNumberL->setText(m_pItemCall->getCallNumber());
 
165
      }
 
166
   }
 
167
 
 
168
}
 
169
 
 
170
///Show the context menu
 
171
void HistoryTreeItem::showContext(const QPoint& pos)
 
172
{
 
173
   if (!m_pMenu) {
 
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     );
 
181
   }
 
182
   m_pMenu->exec(mapToGlobal(pos));
 
183
}
 
184
 
 
185
///Send an email
 
186
void HistoryTreeItem::sendEmail()
 
187
{
 
188
   //TODO
 
189
   kDebug() << "Sending email";
 
190
}
 
191
 
 
192
///Call the caller again
 
193
void HistoryTreeItem::callAgain()
 
194
{
 
195
   if (m_pItemCall) {
 
196
      kDebug() << "Calling "<< m_pItemCall->getPeerPhoneNumber();
 
197
   }
 
198
   SFLPhone::model()->addDialingCall(m_Name, SFLPhone::app()->model()->getCurrentAccountId())->setCallNumber(m_PhoneNumber);
 
199
}
 
200
 
 
201
///Copy the call
 
202
void HistoryTreeItem::copy()
 
203
{
 
204
   //TODO
 
205
   kDebug() << "Copying contact";
 
206
}
 
207
 
 
208
///Create a contact from those informations
 
209
void HistoryTreeItem::addContact()
 
210
{
 
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);
 
216
}
 
217
 
 
218
///Add this call number to an existing contact
 
219
void HistoryTreeItem::addToContact()
 
220
{
 
221
   //TODO
 
222
   kDebug() << "Adding to contact";
 
223
}
 
224
 
 
225
///Bookmark this contact
 
226
void HistoryTreeItem::bookmark()
 
227
{
 
228
   SFLPhone::app()->bookmarkDock()->addBookmark(m_PhoneNumber);
 
229
}
 
230
 
 
231
 
 
232
/*****************************************************************************
 
233
 *                                                                           *
 
234
 *                                  Setters                                  *
 
235
 *                                                                           *
 
236
 ****************************************************************************/
 
237
 
 
238
///Set the call to be handled by this item
 
239
void HistoryTreeItem::setCall(Call *call)
 
240
{
 
241
   m_pItemCall = call;
 
242
 
 
243
   if (m_pItemCall->isConference()) {
 
244
      m_pIconL->setVisible(true);
 
245
      return;
 
246
   }
 
247
 
 
248
   m_pCallNumberL->setText(m_pItemCall->getPeerPhoneNumber());
 
249
 
 
250
   m_pTimeL->setText(QDateTime::fromTime_t(m_pItemCall->getStartTimeStamp().toUInt()).toString());
 
251
 
 
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)+" ");
 
254
 
 
255
   connect(m_pItemCall , SIGNAL(changed())                          , this , SLOT(updated()           ));
 
256
   updated();
 
257
 
 
258
   m_TimeStamp   = m_pItemCall->getStartTimeStamp().toUInt();
 
259
   m_Duration    = dur;
 
260
   m_Name        = m_pItemCall->getPeerName();
 
261
   m_PhoneNumber = m_pItemCall->getPeerPhoneNumber();
 
262
}
 
263
 
 
264
///Set the index associed with this widget
 
265
void HistoryTreeItem::setItem(QTreeWidgetItem* item)
 
266
{
 
267
   m_pItem = item;
 
268
}
 
269
 
 
270
 
 
271
/*****************************************************************************
 
272
 *                                                                           *
 
273
 *                                  Getters                                  *
 
274
 *                                                                           *
 
275
 ****************************************************************************/
 
276
 
 
277
///Can a contact be associed with this call?
 
278
bool HistoryTreeItem::getContactInfo(QString phoneNumber)
 
279
{
 
280
   Contact* contact = AkonadiBackend::getInstance()->getContactByPhone(phoneNumber);
 
281
   if (contact) {
 
282
      if (contact->getPhoto() != NULL)
 
283
         m_pIconL->setPixmap(*contact->getPhoto());
 
284
      m_pPeerNameL->setText("<b>"+contact->getFormattedName()+"</b>");
 
285
   }
 
286
   else {
 
287
      m_pIconL->setPixmap(QPixmap(KIcon("user-identity").pixmap(QSize(48,48))));
 
288
      m_pPeerNameL->setText(i18n("<b>Unknow</b>"));
 
289
      return false;
 
290
   }
 
291
   return true;
 
292
}
 
293
 
 
294
///Return the time stamp
 
295
uint HistoryTreeItem::getTimeStamp()
 
296
{
 
297
   return m_TimeStamp;
 
298
}
 
299
 
 
300
///Return the duration
 
301
uint HistoryTreeItem::getDuration()
 
302
{
 
303
   return m_Duration;
 
304
}
 
305
 
 
306
///Return the caller name
 
307
QString HistoryTreeItem::getName()
 
308
{
 
309
   return m_Name;
 
310
}
 
311
 
 
312
///Return the caller peer number
 
313
QString HistoryTreeItem::getPhoneNumber()
 
314
{
 
315
   return m_PhoneNumber;
 
316
}
 
317
 
 
318
///Get the index item assiciated with this widget
 
319
QTreeWidgetItem* HistoryTreeItem::getItem()
 
320
{
 
321
   return m_pItem;
 
322
}
 
 
b'\\ No newline at end of file'