Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 1 | /*************************************************************************** |
Edric Milaret | bab169d | 2016-01-07 15:13:33 -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 | |
| 22 | #include "callmodel.h" |
| 23 | #include "phonedirectorymodel.h" |
| 24 | #include "recentmodel.h" |
| 25 | #include "contactmethod.h" |
| 26 | #include "person.h" |
| 27 | |
| 28 | CallUtilsDialog::CallUtilsDialog(QWidget* parent) : |
| 29 | QDialog(parent), |
| 30 | ui(new Ui::CallUtilsDialog), |
| 31 | confMode_(false), |
| 32 | smartListDelegate_(nullptr), |
| 33 | notCurrentProxyModel_(nullptr) |
| 34 | { |
| 35 | ui->setupUi(this); |
| 36 | |
| 37 | this->setWindowFlags(Qt::CustomizeWindowHint); |
| 38 | this->setWindowFlags(Qt::FramelessWindowHint | Qt::Popup); |
| 39 | } |
| 40 | |
| 41 | CallUtilsDialog::~CallUtilsDialog() |
| 42 | { |
| 43 | delete smartListDelegate_; |
| 44 | delete notCurrentProxyModel_; |
| 45 | delete ui; |
| 46 | } |
| 47 | |
| 48 | void |
| 49 | CallUtilsDialog::showEvent(QShowEvent* event) |
| 50 | { |
| 51 | Q_UNUSED(event) |
| 52 | |
| 53 | ui->numberBar->clear(); |
| 54 | if (not notCurrentProxyModel_) { |
| 55 | notCurrentProxyModel_ = new NotCurrentProxyModel(&RecentModel::instance()); |
| 56 | } |
| 57 | ui->contactView->setModel(notCurrentProxyModel_); |
| 58 | if (not smartListDelegate_) { |
| 59 | smartListDelegate_ = new SmartListDelegate(); |
| 60 | } |
| 61 | ui->contactView->setItemDelegate(smartListDelegate_); |
| 62 | } |
| 63 | |
| 64 | void CallUtilsDialog::removeProxyModel() |
| 65 | { |
| 66 | ui->contactView->setModel(nullptr); |
| 67 | } |
| 68 | |
| 69 | void CallUtilsDialog::closeEvent(QCloseEvent* event) |
| 70 | { |
| 71 | //This prevent a crash happening in Qt5.5 in QSortFilterProxyModel |
| 72 | Q_UNUSED(event) |
| 73 | removeProxyModel(); |
| 74 | } |
| 75 | |
| 76 | void |
Edric Milaret | 63c34b6 | 2016-01-15 11:52:47 -0500 | [diff] [blame] | 77 | CallUtilsDialog::on_doTransferButton_clicked() |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 78 | { |
| 79 | auto callList = CallModel::instance().getActiveCalls(); |
| 80 | for (auto c : callList) { |
| 81 | if (c->state() == Call::State::CURRENT) { |
| 82 | if (not ui->numberBar->text().isEmpty()) { |
| 83 | auto number = PhoneDirectoryModel::instance().getNumber(ui->numberBar->text()); |
| 84 | CallModel::instance().transfer(c, number); |
| 85 | } |
| 86 | removeProxyModel(); |
| 87 | this->close(); |
| 88 | return; |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | void |
| 94 | CallUtilsDialog::setConfMode(bool active) |
| 95 | { |
| 96 | confMode_ = active; |
Edric Milaret | 63c34b6 | 2016-01-15 11:52:47 -0500 | [diff] [blame] | 97 | ui->doTransferButton->setVisible(not active); |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 98 | ui->numberBar->setVisible(not active); |
| 99 | } |
| 100 | |
| 101 | void |
| 102 | CallUtilsDialog::on_contactView_doubleClicked(const QModelIndex& index) |
| 103 | { |
| 104 | removeProxyModel(); |
| 105 | if (not index.isValid()) |
| 106 | return; |
| 107 | auto realIdx = notCurrentProxyModel_->mapToSource(index); |
| 108 | if (not RecentModel::instance().hasActiveCall(realIdx)) { |
| 109 | ContactMethod* m = nullptr; |
| 110 | if (auto cm = realIdx.data(static_cast<int>(Call::Role::ContactMethod)).value<ContactMethod*>()) { |
| 111 | m = cm; |
| 112 | } else { |
| 113 | if (auto person = realIdx.data(static_cast<int>(Person::Role::Object)).value<Person*>()) { |
| 114 | m = person->phoneNumbers().first(); |
| 115 | } |
| 116 | } |
| 117 | if (confMode_) { |
| 118 | if (m && !RecentModel::instance().index(0, 0, realIdx).isValid()) { |
| 119 | Call* c = CallModel::instance().dialingCall(m, CallModel::instance().selectedCall()); |
| 120 | c->performAction(Call::Action::ACCEPT); |
| 121 | } |
| 122 | } else { |
| 123 | if (m) { |
| 124 | auto activeCall = CallModel::instance().selectedCall(); |
| 125 | CallModel::instance().transfer(activeCall, m); |
| 126 | } |
| 127 | } |
| 128 | } else { |
| 129 | auto activeCall = CallModel::instance().selectedCall(); |
| 130 | auto call = RecentModel::instance().getActiveCall(realIdx); |
| 131 | if (not confMode_) |
| 132 | CallModel::instance().attendedTransfer(activeCall, call); |
| 133 | else |
| 134 | CallModel::instance().createJoinOrMergeConferenceFromCall(activeCall, call); |
| 135 | } |
| 136 | this->close(); |
| 137 | } |