blob: f3c29b5ebd4975e72c138d3675e1afc13936a769 [file] [log] [blame]
Edric Milaret80e0b212015-10-16 10:07:43 -04001/***************************************************************************
Nicolas Jager0a9fc602016-03-11 18:35:42 -05002 * Copyright (C) 2015-2016 by Savoir-faire Linux *
Edric Milaret80e0b212015-10-16 10:07:43 -04003 * Author: Edric Ladent Milaret <edric.ladent-milaret@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
19#include "callutilsdialog.h"
20#include "ui_callutilsdialog.h"
21
Nicolas Jager0a9fc602016-03-11 18:35:42 -050022#include <QBitmap>
23#include <QPropertyAnimation>
24#include <QGraphicsOpacityEffect>
25#include <QScrollBar>
26
Edric Milaret80e0b212015-10-16 10:07:43 -040027#include "callmodel.h"
28#include "phonedirectorymodel.h"
29#include "recentmodel.h"
30#include "contactmethod.h"
31#include "person.h"
32
33CallUtilsDialog::CallUtilsDialog(QWidget* parent) :
34 QDialog(parent),
35 ui(new Ui::CallUtilsDialog),
36 confMode_(false),
37 smartListDelegate_(nullptr),
Nicolas Jager0a9fc602016-03-11 18:35:42 -050038 notCurrentProxyModel_(nullptr),
39 spikeMask_(new QPixmap(":/images/spikeMask.png"))
Edric Milaret80e0b212015-10-16 10:07:43 -040040{
41 ui->setupUi(this);
42
43 this->setWindowFlags(Qt::CustomizeWindowHint);
Nicolas Jager0a9fc602016-03-11 18:35:42 -050044 this->setWindowFlags(Qt::FramelessWindowHint | Qt::Popup | Qt::NoDropShadowWindowHint);
45
46 ui->spike->setMask(spikeMask_->mask());
47
48 effect_ = new QGraphicsOpacityEffect(this);
49 effect_->setOpacity(1.0);
50 setGraphicsEffect(effect_);
51 fadeAnim_ = new QPropertyAnimation(effect_, "opacity");
52 fadeAnim_->setDuration(fadeOverlayTime_);
53 fadeAnim_->setStartValue(0.0);
54 fadeAnim_->setEndValue(1.0);
55 fadeAnim_->setEasingCurve(QEasingCurve::InExpo);
56
57 ui->contactView->verticalScrollBar()->hide();
Edric Milaret80e0b212015-10-16 10:07:43 -040058}
59
60CallUtilsDialog::~CallUtilsDialog()
61{
Nicolas Jager0a9fc602016-03-11 18:35:42 -050062 delete effect_;
63 delete spikeMask_;
64 delete fadeAnim_;
Edric Milaret80e0b212015-10-16 10:07:43 -040065 delete smartListDelegate_;
66 delete notCurrentProxyModel_;
67 delete ui;
68}
69
70void
71CallUtilsDialog::showEvent(QShowEvent* event)
72{
73 Q_UNUSED(event)
74
75 ui->numberBar->clear();
76 if (not notCurrentProxyModel_) {
77 notCurrentProxyModel_ = new NotCurrentProxyModel(&RecentModel::instance());
78 }
79 ui->contactView->setModel(notCurrentProxyModel_);
80 if (not smartListDelegate_) {
81 smartListDelegate_ = new SmartListDelegate();
82 }
83 ui->contactView->setItemDelegate(smartListDelegate_);
Nicolas Jager0a9fc602016-03-11 18:35:42 -050084
85 emit(isVisible(true));
86
87 fadeAnim_->setDirection(QAbstractAnimation::Forward);
88 fadeAnim_->start();
Edric Milaret80e0b212015-10-16 10:07:43 -040089}
90
91void CallUtilsDialog::removeProxyModel()
92{
93 ui->contactView->setModel(nullptr);
94}
95
96void CallUtilsDialog::closeEvent(QCloseEvent* event)
97{
98 //This prevent a crash happening in Qt5.5 in QSortFilterProxyModel
99 Q_UNUSED(event)
100 removeProxyModel();
Nicolas Jager0a9fc602016-03-11 18:35:42 -0500101 emit(isVisible(false));
Edric Milaret80e0b212015-10-16 10:07:43 -0400102}
103
104void
Edric Milaret63c34b62016-01-15 11:52:47 -0500105CallUtilsDialog::on_doTransferButton_clicked()
Edric Milaret80e0b212015-10-16 10:07:43 -0400106{
107 auto callList = CallModel::instance().getActiveCalls();
108 for (auto c : callList) {
109 if (c->state() == Call::State::CURRENT) {
110 if (not ui->numberBar->text().isEmpty()) {
111 auto number = PhoneDirectoryModel::instance().getNumber(ui->numberBar->text());
112 CallModel::instance().transfer(c, number);
113 }
114 removeProxyModel();
115 this->close();
116 return;
117 }
118 }
119}
120
121void
122CallUtilsDialog::setConfMode(bool active)
123{
124 confMode_ = active;
Edric Milaret63c34b62016-01-15 11:52:47 -0500125 ui->doTransferButton->setVisible(not active);
Edric Milaret80e0b212015-10-16 10:07:43 -0400126 ui->numberBar->setVisible(not active);
127}
128
129void
130CallUtilsDialog::on_contactView_doubleClicked(const QModelIndex& index)
131{
132 removeProxyModel();
133 if (not index.isValid())
134 return;
135 auto realIdx = notCurrentProxyModel_->mapToSource(index);
136 if (not RecentModel::instance().hasActiveCall(realIdx)) {
137 ContactMethod* m = nullptr;
138 if (auto cm = realIdx.data(static_cast<int>(Call::Role::ContactMethod)).value<ContactMethod*>()) {
139 m = cm;
140 } else {
141 if (auto person = realIdx.data(static_cast<int>(Person::Role::Object)).value<Person*>()) {
142 m = person->phoneNumbers().first();
143 }
144 }
145 if (confMode_) {
146 if (m && !RecentModel::instance().index(0, 0, realIdx).isValid()) {
147 Call* c = CallModel::instance().dialingCall(m, CallModel::instance().selectedCall());
148 c->performAction(Call::Action::ACCEPT);
149 }
150 } else {
151 if (m) {
152 auto activeCall = CallModel::instance().selectedCall();
153 CallModel::instance().transfer(activeCall, m);
154 }
155 }
156 } else {
157 auto activeCall = CallModel::instance().selectedCall();
158 auto call = RecentModel::instance().getActiveCall(realIdx);
159 if (not confMode_)
160 CallModel::instance().attendedTransfer(activeCall, call);
161 else
162 CallModel::instance().createJoinOrMergeConferenceFromCall(activeCall, call);
163 }
164 this->close();
165}
Nicolas Jager0a9fc602016-03-11 18:35:42 -0500166
167void
168CallUtilsDialog::enterEvent(QEvent* event)
169{
170 Q_UNUSED(event);
171 ui->contactView->verticalScrollBar()->show();
172}
173
174void
175CallUtilsDialog::leaveEvent(QEvent* event)
176{
177 Q_UNUSED(event);
178 ui->contactView->verticalScrollBar()->hide();
179}