blob: 79d66cc7c1af6a52544e233a087495097ba79b79 [file] [log] [blame]
Olivier SOLDANO47aa97f2017-04-04 10:40:00 -04001/***************************************************************************
Anthony Léonard2fde81d2017-04-17 10:06:55 -04002 * Copyright (C) 2015-2017 by Savoir-faire Linux *
Olivier SOLDANO47aa97f2017-04-04 10:40:00 -04003 * 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
Olivier SOLDANOdd878662017-03-27 16:00:06 -040020#include <QDebug>
21
22#include "sendcontactrequestwidget.h"
23#include "ui_sendcontactrequestwidget.h"
24#include "account.h"
25#include "accountmodel.h"
26#include "recentmodel.h"
27#include "contactmethod.h"
28#include "phonedirectorymodel.h"
29
30SendContactRequestWidget::SendContactRequestWidget(QWidget *parent) :
31 QWidget(parent),
32 ui(new Ui::SendContactRequestWidget)
33{
34 ui->setupUi(this);
Anthony Léonard2fde81d2017-04-17 10:06:55 -040035 ui->peerContactID->setText("ContactID"); // TODO: Display RingID/Username
Olivier SOLDANOdd878662017-03-27 16:00:06 -040036}
37
38SendContactRequestWidget::~SendContactRequestWidget()
39{
40 disconnect(sendCRClickedConnection_);
41 delete ui;
42}
43
44void
45SendContactRequestWidget::setup(const QModelIndex& nodeIdx)
46{
47 auto cmVector = RecentModel::instance().getContactMethods(nodeIdx);
48 disconnect(sendCRClickedConnection_);
49 QString number = cmVector[0]->uri();
50 ui->peerContactID->setText(number);
51 sendCRClickedConnection_ = connect(ui->sendContactRequestButton, &QPushButton::clicked, [this,nodeIdx]() {
52 sendCR(nodeIdx);
53 });
54}
55
56void SendContactRequestWidget::sendCR(const QModelIndex& nodeIdx)
57{
58 auto cmVector = RecentModel::instance().getContactMethods(nodeIdx);
59 QString number = cmVector[0]->uri();
60 auto cm = PhoneDirectoryModel::instance().getNumber(number);
61
62 if(cm->account() != nullptr){
63 cm->account()->sendContactRequest(cm);
64 } else {
65 qDebug() << "no account linked to contact method";
66 cm->setAccount(AccountModel::instance().userChosenAccount());
67 cm->account()->sendContactRequest(cm);
68 }
69 //emit sendCRclicked();
70}