Anthony Léonard | 2fde81d | 2017-04-17 10:06:55 -0400 | [diff] [blame] | 1 | /*************************************************************************** |
| 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éonard | d47179c | 2017-03-28 10:39:10 -0400 | [diff] [blame] | 20 | #include "contactrequestwidget.h" |
| 21 | #include "ui_contactrequestwidget.h" |
Anthony Léonard | 8c13644 | 2017-04-28 11:24:14 -0400 | [diff] [blame^] | 22 | #include "person.h" |
| 23 | #include "pendingcontactrequestmodel.h" |
| 24 | #include "itemdataroles.h" |
| 25 | #include "globalinstances.h" |
| 26 | #include "pixmapmanipulatordefault.h" |
Anthony Léonard | d47179c | 2017-03-28 10:39:10 -0400 | [diff] [blame] | 27 | |
| 28 | ContactRequestWidget::ContactRequestWidget(QWidget *parent) : |
| 29 | QWidget(parent), |
| 30 | ui(new Ui::ContactRequestWidget) |
| 31 | { |
| 32 | ui->setupUi(this); |
| 33 | } |
| 34 | |
| 35 | ContactRequestWidget::~ContactRequestWidget() |
| 36 | { |
| 37 | delete ui; |
| 38 | } |
| 39 | |
| 40 | void |
Anthony Léonard | 8c13644 | 2017-04-28 11:24:14 -0400 | [diff] [blame^] | 41 | ContactRequestWidget::setCurrentContactRequest(const QModelIndex ¤t) |
Anthony Léonard | d47179c | 2017-03-28 10:39:10 -0400 | [diff] [blame] | 42 | { |
Anthony Léonard | 8c13644 | 2017-04-28 11:24:14 -0400 | [diff] [blame^] | 43 | 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éonard | d47179c | 2017-03-28 10:39:10 -0400 | [diff] [blame] | 55 | } |
| 56 | } |
| 57 | |
| 58 | void |
| 59 | ContactRequestWidget::on_acceptCRButton_clicked() |
| 60 | { |
| 61 | if (cr_ != nullptr) { |
| 62 | cr_->accept(); |
| 63 | } |
Anthony Léonard | 8c13644 | 2017-04-28 11:24:14 -0400 | [diff] [blame^] | 64 | setCurrentContactRequest(QModelIndex()); |
Anthony Léonard | d47179c | 2017-03-28 10:39:10 -0400 | [diff] [blame] | 65 | emit choiceMade(); |
| 66 | } |
| 67 | |
| 68 | void ContactRequestWidget::on_discardCRButton_clicked() |
| 69 | { |
| 70 | if (cr_ != nullptr) { |
| 71 | cr_->discard(); |
| 72 | } |
Anthony Léonard | 8c13644 | 2017-04-28 11:24:14 -0400 | [diff] [blame^] | 73 | setCurrentContactRequest(QModelIndex()); |
Anthony Léonard | d47179c | 2017-03-28 10:39:10 -0400 | [diff] [blame] | 74 | emit choiceMade(); |
| 75 | } |
Anthony Léonard | dd9fb6a | 2017-04-26 10:25:48 -0400 | [diff] [blame] | 76 | |
| 77 | void ContactRequestWidget::on_blockCRButton_clicked() |
| 78 | { |
| 79 | if (cr_ != nullptr) { |
| 80 | cr_->block(); |
| 81 | } |
Anthony Léonard | 8c13644 | 2017-04-28 11:24:14 -0400 | [diff] [blame^] | 82 | setCurrentContactRequest(QModelIndex()); |
Anthony Léonard | dd9fb6a | 2017-04-26 10:25:48 -0400 | [diff] [blame] | 83 | emit choiceMade(); |
| 84 | } |