blob: 8ac53bec20d7e8d14933c213c7d348df665d5a31 [file] [log] [blame]
Sébastien Blincba5b522018-12-10 12:48:36 -05001/***************************************************************************
2 * Copyright (C) 2015-2017 by Savoir-faire Linux *
3 * Author: Anthony Léonard <anthony.leonard@savoirfairelinux.com> *
4 * Author: Olivier Soldano <olivier.soldano@savoirfairelinux.com> *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 **************************************************************************/
19
20#include <QDebug>
21
22#include "sendcontactrequestwidget.h"
23#include "ui_sendcontactrequestwidget.h"
24#include "account.h"
25#include "accountmodel.h"
26#include "availableaccountmodel.h"
27#include "recentmodel.h"
28#include "contactmethod.h"
29#include "phonedirectorymodel.h"
30
31SendContactRequestWidget::SendContactRequestWidget(QWidget *parent) :
32 QWidget(parent),
33 ui(new Ui::SendContactRequestWidget)
34{
35 ui->setupUi(this);
36 ui->peerContactID->setText("ContactID"); // TODO: Display ID/Username
37}
38
39SendContactRequestWidget::~SendContactRequestWidget()
40{
41 disconnect(sendCRClickedConnection_);
42 delete ui;
43}
44
45void
46SendContactRequestWidget::setup(const QModelIndex& nodeIdx)
47{
48 auto cmVector = RecentModel::instance().getContactMethods(nodeIdx);
49 disconnect(sendCRClickedConnection_);
50 QString number = cmVector[0]->uri();
51 ui->peerContactID->setText(number);
52 sendCRClickedConnection_ = connect(ui->sendContactRequestButton, &QPushButton::clicked, [this,nodeIdx]() {
53 sendCR(nodeIdx);
54 });
55}
56
57void SendContactRequestWidget::sendCR(const QModelIndex& nodeIdx)
58{
59 auto cmVector = RecentModel::instance().getContactMethods(nodeIdx);
60 QString number = cmVector[0]->uri();
61 auto cm = PhoneDirectoryModel::instance().getNumber(number);
62
63 if(cm->account() != nullptr){
64 cm->account()->sendContactRequest(cm);
65 } else {
66 qDebug() << "no account linked to contact method";
67 auto idx = AvailableAccountModel::instance().selectionModel()->currentIndex();
68 if (idx.isValid()) {
69 cm->setAccount(idx.data(static_cast<int>(Ring::Role::Object)).value<Account*>());
70 cm->account()->sendContactRequest(cm);
71 }
72 }
73}