blob: e7a555ea91f2d2ed2b584031b72fdc32049c85f1 [file] [log] [blame]
Edric Milaret80e0b212015-10-16 10:07:43 -04001/***************************************************************************
Edric Milaretbab169d2016-01-07 15:13:33 -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
22#include "callmodel.h"
23#include "phonedirectorymodel.h"
24#include "recentmodel.h"
25#include "contactmethod.h"
26#include "person.h"
27
28CallUtilsDialog::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
41CallUtilsDialog::~CallUtilsDialog()
42{
43 delete smartListDelegate_;
44 delete notCurrentProxyModel_;
45 delete ui;
46}
47
48void
49CallUtilsDialog::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
64void CallUtilsDialog::removeProxyModel()
65{
66 ui->contactView->setModel(nullptr);
67}
68
69void CallUtilsDialog::closeEvent(QCloseEvent* event)
70{
71 //This prevent a crash happening in Qt5.5 in QSortFilterProxyModel
72 Q_UNUSED(event)
73 removeProxyModel();
74}
75
76void
Edric Milaret63c34b62016-01-15 11:52:47 -050077CallUtilsDialog::on_doTransferButton_clicked()
Edric Milaret80e0b212015-10-16 10:07:43 -040078{
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
93void
94CallUtilsDialog::setConfMode(bool active)
95{
96 confMode_ = active;
Edric Milaret63c34b62016-01-15 11:52:47 -050097 ui->doTransferButton->setVisible(not active);
Edric Milaret80e0b212015-10-16 10:07:43 -040098 ui->numberBar->setVisible(not active);
99}
100
101void
102CallUtilsDialog::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}