Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 1 | /*************************************************************************** |
Nicolas Jager | 0a9fc60 | 2016-03-11 18:35:42 -0500 | [diff] [blame] | 2 | * Copyright (C) 2015-2016 by Savoir-faire Linux * |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 3 | * 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 Jager | 0a9fc60 | 2016-03-11 18:35:42 -0500 | [diff] [blame] | 22 | #include <QBitmap> |
| 23 | #include <QPropertyAnimation> |
| 24 | #include <QGraphicsOpacityEffect> |
| 25 | #include <QScrollBar> |
| 26 | |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 27 | #include "callmodel.h" |
| 28 | #include "phonedirectorymodel.h" |
| 29 | #include "recentmodel.h" |
| 30 | #include "contactmethod.h" |
| 31 | #include "person.h" |
| 32 | |
| 33 | CallUtilsDialog::CallUtilsDialog(QWidget* parent) : |
| 34 | QDialog(parent), |
| 35 | ui(new Ui::CallUtilsDialog), |
| 36 | confMode_(false), |
| 37 | smartListDelegate_(nullptr), |
Nicolas Jager | 0a9fc60 | 2016-03-11 18:35:42 -0500 | [diff] [blame] | 38 | notCurrentProxyModel_(nullptr), |
| 39 | spikeMask_(new QPixmap(":/images/spikeMask.png")) |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 40 | { |
| 41 | ui->setupUi(this); |
| 42 | |
| 43 | this->setWindowFlags(Qt::CustomizeWindowHint); |
Nicolas Jager | 0a9fc60 | 2016-03-11 18:35:42 -0500 | [diff] [blame] | 44 | 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 Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | CallUtilsDialog::~CallUtilsDialog() |
| 61 | { |
Nicolas Jager | 0a9fc60 | 2016-03-11 18:35:42 -0500 | [diff] [blame] | 62 | delete effect_; |
| 63 | delete spikeMask_; |
| 64 | delete fadeAnim_; |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 65 | delete smartListDelegate_; |
| 66 | delete notCurrentProxyModel_; |
| 67 | delete ui; |
| 68 | } |
| 69 | |
| 70 | void |
| 71 | CallUtilsDialog::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 Jager | 0a9fc60 | 2016-03-11 18:35:42 -0500 | [diff] [blame] | 84 | |
| 85 | emit(isVisible(true)); |
| 86 | |
| 87 | fadeAnim_->setDirection(QAbstractAnimation::Forward); |
| 88 | fadeAnim_->start(); |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | void CallUtilsDialog::removeProxyModel() |
| 92 | { |
| 93 | ui->contactView->setModel(nullptr); |
| 94 | } |
| 95 | |
| 96 | void CallUtilsDialog::closeEvent(QCloseEvent* event) |
| 97 | { |
| 98 | //This prevent a crash happening in Qt5.5 in QSortFilterProxyModel |
| 99 | Q_UNUSED(event) |
| 100 | removeProxyModel(); |
Nicolas Jager | 0a9fc60 | 2016-03-11 18:35:42 -0500 | [diff] [blame] | 101 | emit(isVisible(false)); |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | void |
Edric Milaret | 63c34b6 | 2016-01-15 11:52:47 -0500 | [diff] [blame] | 105 | CallUtilsDialog::on_doTransferButton_clicked() |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 106 | { |
| 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 | |
| 121 | void |
| 122 | CallUtilsDialog::setConfMode(bool active) |
| 123 | { |
| 124 | confMode_ = active; |
Edric Milaret | 63c34b6 | 2016-01-15 11:52:47 -0500 | [diff] [blame] | 125 | ui->doTransferButton->setVisible(not active); |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 126 | ui->numberBar->setVisible(not active); |
| 127 | } |
| 128 | |
| 129 | void |
| 130 | CallUtilsDialog::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 Jager | 0a9fc60 | 2016-03-11 18:35:42 -0500 | [diff] [blame] | 166 | |
| 167 | void |
| 168 | CallUtilsDialog::enterEvent(QEvent* event) |
| 169 | { |
| 170 | Q_UNUSED(event); |
| 171 | ui->contactView->verticalScrollBar()->show(); |
| 172 | } |
| 173 | |
| 174 | void |
| 175 | CallUtilsDialog::leaveEvent(QEvent* event) |
| 176 | { |
| 177 | Q_UNUSED(event); |
| 178 | ui->contactView->verticalScrollBar()->hide(); |
| 179 | } |