blob: 3f88ae2a179ba17cb969139548f4afe0088fe604 [file] [log] [blame]
Anthony Léonard2fde81d2017-04-17 10:06:55 -04001/***************************************************************************
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
Anthony Léonardd47179c2017-03-28 10:39:10 -040020#include "contactrequestwidget.h"
21#include "ui_contactrequestwidget.h"
Anthony Léonard8c136442017-04-28 11:24:14 -040022#include "person.h"
23#include "pendingcontactrequestmodel.h"
24#include "itemdataroles.h"
25#include "globalinstances.h"
26#include "pixmapmanipulatordefault.h"
Anthony Léonardd47179c2017-03-28 10:39:10 -040027
28ContactRequestWidget::ContactRequestWidget(QWidget *parent) :
29 QWidget(parent),
30 ui(new Ui::ContactRequestWidget)
31{
32 ui->setupUi(this);
33}
34
35ContactRequestWidget::~ContactRequestWidget()
36{
37 delete ui;
38}
39
40void
Anthony Léonard8c136442017-04-28 11:24:14 -040041ContactRequestWidget::setCurrentContactRequest(const QModelIndex &current)
Anthony Léonardd47179c2017-03-28 10:39:10 -040042{
Anthony Léonard8c136442017-04-28 11:24:14 -040043 if (current.isValid()) {
44 auto bestId = current.data().value<QString>();
45 cr_ = current.data(static_cast<int>(Ring::Role::Object)).value<ContactRequest*>();
46 auto formattedName = current.model()->index(current.row(), PendingContactRequestModel::Columns::FORMATTED_NAME).data().value<QString>();
47 ui->nameLabel->setText(formattedName);
48 ui->bestIdLabel->setText(bestId);
49 auto photo = GlobalInstances::pixmapManipulator().contactPhoto(cr_->peer(), QSize(96, 96), false);
50
51 if(photo.isValid())
52 ui->pictureLabel->setPixmap(QPixmap::fromImage(photo.value<QImage>()));
53 } else {
54 cr_ = nullptr;
Anthony Léonardd47179c2017-03-28 10:39:10 -040055 }
56}
57
58void
59ContactRequestWidget::on_acceptCRButton_clicked()
60{
61 if (cr_ != nullptr) {
62 cr_->accept();
63 }
Anthony Léonard8c136442017-04-28 11:24:14 -040064 setCurrentContactRequest(QModelIndex());
Anthony Léonardd47179c2017-03-28 10:39:10 -040065 emit choiceMade();
66}
67
68void ContactRequestWidget::on_discardCRButton_clicked()
69{
70 if (cr_ != nullptr) {
71 cr_->discard();
72 }
Anthony Léonard8c136442017-04-28 11:24:14 -040073 setCurrentContactRequest(QModelIndex());
Anthony Léonardd47179c2017-03-28 10:39:10 -040074 emit choiceMade();
75}
Anthony Léonarddd9fb6a2017-04-26 10:25:48 -040076
77void ContactRequestWidget::on_blockCRButton_clicked()
78{
79 if (cr_ != nullptr) {
80 cr_->block();
81 }
Anthony Léonard8c136442017-04-28 11:24:14 -040082 setCurrentContactRequest(QModelIndex());
Anthony Léonarddd9fb6a2017-04-26 10:25:48 -040083 emit choiceMade();
84}