CallTreeItem.cpp 5.6 KB
Newer Older
1 2 3 4
/***************************************************************************
 *   Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).     *
 *   All rights reserved.                                                  *
 *   Contact: Nokia Corporation (qt-info@nokia.com)                        *
5 6
 *   Author : Mathieu Leduc-Hamel mathieu.leduc-hamel@savoirfairelinux.com *
 *            Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com>*
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

24
#include <QtCore/QStringList>
25

26 27
#include <klocale.h>
#include <kdebug.h>
28
#include <unistd.h>
29

30 31
#include "sflphone_const.h"
#include "CallTreeItem.h"
32

33 34 35
const char * CallTreeItem::callStateIcons[12] = {ICON_INCOMING, ICON_RINGING, ICON_CURRENT, ICON_DIALING, ICON_HOLD, ICON_FAILURE, ICON_BUSY, ICON_TRANSFER, ICON_TRANSF_HOLD, "", "", ICON_CONFERENCE};

CallTreeItem::CallTreeItem(QWidget *parent)
36
   : itemCall(0), QWidget(parent), init(false)
37
{
38
   
39
}
40

41
CallTreeItem::~CallTreeItem()
42
{
43
   
44 45
}

46
Call* CallTreeItem::call() const
47
{
48
   return itemCall;
49
}
50

51 52
void CallTreeItem::setCall(Call *call)
{
53
   itemCall = call;
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
   
   if (itemCall->isConference()) {
      if (!init) {
         labelHistoryPeerName = new QLabel("Conference",this);
         labelIcon = new QLabel("Icn",this);
         QHBoxLayout* mainLayout = new QHBoxLayout();
         mainLayout->addWidget(labelIcon);
         mainLayout->addWidget(labelHistoryPeerName);
         setLayout(mainLayout);
         init = true;
      }
      labelIcon->setPixmap(QPixmap(ICON_CONFERENCE));
      labelIcon->setVisible(true);
      labelHistoryPeerName->setVisible(true);
      return;
   }
70

71
   labelIcon = new QLabel();
72
   labelCallNumber2 = new QLabel(itemCall->getPeerPhoneNumber());
73 74
   labelTransferPrefix = new QLabel(i18n("Transfer to : "));
   labelTransferNumber = new QLabel();
75
   QSpacerItem* verticalSpacer = new QSpacerItem(16777215, 20, QSizePolicy::Expanding, QSizePolicy::Expanding);
76
   
77
   QHBoxLayout* mainLayout = new QHBoxLayout();
78 79
   mainLayout->setContentsMargins ( 3, 1, 2, 1);
   
80
   labelCodec = new QLabel(this);
81 82 83
   //labelCodec->setText("Codec: "+itemCall->getCurrentCodecName());

   labelSecure = new QLabel(this);
84
   
85
   mainLayout->setSpacing(4);
86
   QVBoxLayout* descr = new QVBoxLayout();
87 88
   descr->setMargin(1);
   descr->setSpacing(1);
89
   QHBoxLayout* transfer = new QHBoxLayout();
90 91 92
   transfer->setMargin(0);
   transfer->setSpacing(0);
   mainLayout->addWidget(labelIcon);
93
        
94 95 96 97 98 99
   if(! itemCall->getPeerName().isEmpty()) {
      labelPeerName = new QLabel(itemCall->getPeerName());
      descr->addWidget(labelPeerName);
   }

   descr->addWidget(labelCallNumber2);
100
   descr->addWidget(labelSecure);
101
   descr->addWidget(labelCodec);
102 103 104
   transfer->addWidget(labelTransferPrefix);
   transfer->addWidget(labelTransferNumber);
   descr->addLayout(transfer);
105
   descr->addItem(verticalSpacer);
106 107
   mainLayout->addLayout(descr);
   
108 109
   setLayout(mainLayout);
   setMinimumSize(QSize(50, 30));
110

111
   connect(itemCall, SIGNAL(changed()),
112
           this,     SLOT(updated()));
113

114
   updated();
115 116
}

117
void CallTreeItem::updated()
118
{
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
   call_state state = itemCall->getState();
   bool recording = itemCall->getRecording();
   if(state != CALL_STATE_OVER) {
      if(state == CALL_STATE_CURRENT && recording) {
         labelIcon->setPixmap(QPixmap(ICON_CURRENT_REC));
      }
      else {
         QString str = QString(callStateIcons[state]);
         labelIcon->setPixmap(QPixmap(str));
      }
      bool transfer = state == CALL_STATE_TRANSFER || state == CALL_STATE_TRANSF_HOLD;
      labelTransferPrefix->setVisible(transfer);
      labelTransferNumber->setVisible(transfer);

      if(!transfer) {
         labelTransferNumber->setText("");
      }
136
      labelTransferNumber->setText(itemCall->getTransferNumber());
137
      labelCallNumber2->setText(itemCall->getPeerPhoneNumber());
138
                
139 140 141
      if(state == CALL_STATE_DIALING) {
         labelCallNumber2->setText(itemCall->getCallNumber());
      }
142 143 144 145 146
      else {
         labelCodec->setText("Codec: "+itemCall->getCurrentCodecName());
         if (itemCall->isSecure())
            labelSecure->setText("⚷");
      }
147 148
   }
   else {
149
      qDebug() << "Updating item of call of state OVER. Doing nothing.";
150
   }
151
   
152
}
153

154 155
void CallTreeItem::setConference(bool value) {
   conference = value;
156 157 158
   labelIcon->setPixmap(QPixmap(ICON_CONFERENCE));
   //labelTransferNumber->setVisible(false);
   //labelTransferPrefix->setVisible(false);
159
}
160

161 162 163
bool CallTreeItem::isConference() {
   return conference;
}
164