blob: 24dd33c4642706ae9830a27306905325168e2a06 [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"
Anthony Léonarda3cc5f02017-05-04 14:57:50 -040026#include "availableaccountmodel.h"
Olivier SOLDANOdd878662017-03-27 16:00:06 -040027#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);
Anthony Léonard2fde81d2017-04-17 10:06:55 -040036 ui->peerContactID->setText("ContactID"); // TODO: Display RingID/Username
Olivier SOLDANOdd878662017-03-27 16:00:06 -040037}
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";
Anthony Léonarda3cc5f02017-05-04 14:57:50 -040067 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 }
Olivier SOLDANOdd878662017-03-27 16:00:06 -040072 }
Olivier SOLDANOdd878662017-03-27 16:00:06 -040073}