~ubuntu-branches/ubuntu/wily/sflphone/wily

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (1.1.11)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: package-import@ubuntu.com-20140128182336-3xenud1kbnwmf3mz
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C)  2013 by Savoir-Faire Linux                             *
 
3
 *   Author : Emmanuel Lepage Valle <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, see <http://www.gnu.org/licenses/>. *
 
17
 **************************************************************************/
 
18
#include "callviewtoolbar.h"
 
19
 
 
20
//Qt
 
21
#include <QtGui/QTreeView>
 
22
#include <QtGui/QHBoxLayout>
 
23
 
 
24
//KDE
 
25
#include <KDebug>
 
26
 
 
27
//SFLPhone
 
28
#include "sflphone.h"
 
29
#include "actioncollection.h"
 
30
#include "extendedaction.h"
 
31
#include <klib/tipmanager.h>
 
32
#include <lib/call.h>
 
33
#include <lib/useractionmodel.h>
 
34
#include <lib/callmodel.h>
 
35
 
 
36
CallViewToolbar::CallViewToolbar(QTreeView* parent) : OverlayToolbar(parent),m_pParent(parent)
 
37
{
 
38
   addAction( ActionCollection::instance()->holdAction()     ,static_cast<int>(UserActionModel::Action::HOLD)     );
 
39
   addAction( ActionCollection::instance()->unholdAction()   ,static_cast<int>(UserActionModel::Action::UNHOLD)   );
 
40
   addAction( ActionCollection::instance()->muteCaptureAction()     ,static_cast<int>(UserActionModel::Action::MUTE)     );
 
41
   addAction( ActionCollection::instance()->pickupAction()   ,static_cast<int>(UserActionModel::Action::PICKUP)   );
 
42
   addAction( ActionCollection::instance()->hangupAction()   ,static_cast<int>(UserActionModel::Action::HANGUP)   );
 
43
   addAction( ActionCollection::instance()->transferAction() ,static_cast<int>(UserActionModel::Action::TRANSFER) );
 
44
   addAction( ActionCollection::instance()->recordAction()   ,static_cast<int>(UserActionModel::Action::RECORD)   );
 
45
   addAction( ActionCollection::instance()->refuseAction()   ,static_cast<int>(UserActionModel::Action::REFUSE)   );
 
46
   addAction( ActionCollection::instance()->acceptAction()   ,static_cast<int>(UserActionModel::Action::ACCEPT)   );
 
47
}
 
48
 
 
49
CallViewToolbar::~CallViewToolbar()
 
50
{
 
51
   
 
52
}
 
53
 
 
54
void CallViewToolbar::updateState()
 
55
{
 
56
   QModelIndex index = m_pParent->selectionModel()->currentIndex();
 
57
   const int rowcount = CallModel::instance()->rowCount();
 
58
   if ((!m_pParent->selectionModel()->hasSelection() || !index.isValid()) && rowcount) {
 
59
      m_pParent->selectionModel()->setCurrentIndex(CallModel::instance()->index(0,0),QItemSelectionModel::SelectCurrent);
 
60
      index = m_pParent->selectionModel()->currentIndex();
 
61
   }
 
62
   if (rowcount && index.isValid() && (index.row() < rowcount || index.parent().isValid())) {
 
63
      Call* call = qvariant_cast<Call*>(index.data(Call::Role::Object));
 
64
      setVisible(true);
 
65
      TipManager* manager = qvariant_cast<TipManager*>(parentWidget()->property("tipManager"));
 
66
      manager->setBottomMargin(53);
 
67
      char act_counter = 0;
 
68
      for (int i = 0;i<static_cast<int>(UserActionModel::Action::COUNT);i++) {
 
69
         try {
 
70
            if (call && call->userActionModel()) {
 
71
               actionButton(i)->setVisible(call->userActionModel()->isActionEnabled(static_cast<UserActionModel::Action>(i)));
 
72
               act_counter += call->userActionModel()->isActionEnabled( static_cast<UserActionModel::Action>(i));
 
73
            }
 
74
         }
 
75
         catch (Call::State& state) {
 
76
            qDebug() << "OverlayToolbar is out of bound (state)" << state;
 
77
         }
 
78
         catch (UserActionModel::Action& btn) {
 
79
            kDebug() << "OverlayToolbar is out of bound (Action)" << (int)btn;
 
80
         }
 
81
         catch (...) {
 
82
            kDebug() << "OverlayToolbar is out of bound (Other)";
 
83
         }
 
84
      }
 
85
      if (!act_counter)
 
86
         setVisible(false);
 
87
   }
 
88
   else {
 
89
      setVisible(false);
 
90
      TipManager* manager = qvariant_cast<TipManager*>(parentWidget()->property("tipManager"));
 
91
      manager->setBottomMargin(0);
 
92
   }
 
93
   //Now set the top margin, this doesn't really belong anywhere, so why not here
 
94
   const int rows = CallModel::instance()->rowCount(QModelIndex());
 
95
   QModelIndex last = CallModel::instance()->index(rows-1,0);
 
96
   if (CallModel::instance()->rowCount(last) > 0)
 
97
      last = CallModel::instance()->index(CallModel::instance()->rowCount(last)-1,0,last);
 
98
   const QRect topMargin =  m_pParent->visualRect(last);
 
99
   TipManager* manager = qvariant_cast<TipManager*>(parentWidget()->property("tipManager"));
 
100
   manager->setTopMargin(topMargin.y()+topMargin.height());
 
101
} //updateState