1
/***************************************************************************
2
* Copyright (C) 2013 by Savoir-Faire Linux *
3
* Author : Emmanuel Lepage Valle <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, see <http://www.gnu.org/licenses/>. *
17
**************************************************************************/
18
#include "callviewtoolbar.h"
21
#include <QtGui/QTreeView>
22
#include <QtGui/QHBoxLayout>
29
#include "actioncollection.h"
30
#include "extendedaction.h"
31
#include <klib/tipmanager.h>
33
#include <lib/useractionmodel.h>
34
#include <lib/callmodel.h>
36
CallViewToolbar::CallViewToolbar(QTreeView* parent) : OverlayToolbar(parent),m_pParent(parent)
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) );
49
CallViewToolbar::~CallViewToolbar()
54
void CallViewToolbar::updateState()
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();
62
if (rowcount && index.isValid() && (index.row() < rowcount || index.parent().isValid())) {
63
Call* call = qvariant_cast<Call*>(index.data(Call::Role::Object));
65
TipManager* manager = qvariant_cast<TipManager*>(parentWidget()->property("tipManager"));
66
manager->setBottomMargin(53);
68
for (int i = 0;i<static_cast<int>(UserActionModel::Action::COUNT);i++) {
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));
75
catch (Call::State& state) {
76
qDebug() << "OverlayToolbar is out of bound (state)" << state;
78
catch (UserActionModel::Action& btn) {
79
kDebug() << "OverlayToolbar is out of bound (Action)" << (int)btn;
82
kDebug() << "OverlayToolbar is out of bound (Other)";
90
TipManager* manager = qvariant_cast<TipManager*>(parentWidget()->property("tipManager"));
91
manager->setBottomMargin(0);
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());