Olivier SOLDANO | 9b7e80d | 2017-05-04 16:06:01 -0400 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * Copyright (C) 2015-2017 by Savoir-faire Linux * |
| 3 | * Author: Olivier Soldano <olivier.soldano@savoirfairelinux.com> * |
| 4 | * * |
| 5 | * This program is free software; you can redistribute it and/or modify * |
| 6 | * it under the terms of the GNU General Public License as published by * |
| 7 | * the Free Software Foundation; either version 3 of the License, or * |
| 8 | * (at your option) any later version. * |
| 9 | * * |
| 10 | * This program is distributed in the hope that it will be useful, * |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 13 | * GNU General Public License for more details. * |
| 14 | * * |
| 15 | * You should have received a copy of the GNU General Public License * |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. * |
| 17 | **************************************************************************/ |
| 18 | |
| 19 | #include "deleteaccountdialog.h" |
| 20 | #include "ui_deleteaccountdialog.h" |
| 21 | |
| 22 | // LRC |
| 23 | #include "accountmodel.h" |
| 24 | #include "itemdataroles.h" |
| 25 | #include "account.h" |
| 26 | |
| 27 | DeleteAccountDialog::DeleteAccountDialog(const QModelIndex & idx, QWidget *parent) : |
| 28 | QDialog(parent), |
| 29 | ui(new Ui::DeleteAccountDialog), |
| 30 | index_(idx) |
| 31 | { |
Olivier SOLDANO | cc28a0d | 2017-07-21 13:53:31 -0400 | [diff] [blame] | 32 | setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); |
Olivier SOLDANO | 9b7e80d | 2017-05-04 16:06:01 -0400 | [diff] [blame] | 33 | ui->setupUi(this); |
| 34 | ui->accountAliasLabel->setText(AccountModel::instance().data(index_, Qt::DisplayRole).toString()); |
| 35 | auto ac = AccountModel::instance().getAccountByModelIndex(index_); |
| 36 | if (ac->protocol() == Account::Protocol::RING){ |
| 37 | ui->accountIdLabel->setAlignment(Qt::AlignCenter); |
| 38 | ui->accountIdLabel->setText((ac->registeredName().isEmpty())? ac->username(): ac->registeredName() + "\n" + ac->username()); |
| 39 | } else { |
| 40 | ui->warningLabel->hide(); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | DeleteAccountDialog::~DeleteAccountDialog() |
| 45 | { |
| 46 | delete ui; |
| 47 | } |
| 48 | |
| 49 | void DeleteAccountDialog::on_deleteCancelBtn_clicked() |
| 50 | { |
| 51 | close(); |
| 52 | } |
| 53 | |
| 54 | void DeleteAccountDialog::on_deleteAcceptBtn_clicked() |
| 55 | { |
| 56 | auto account = AccountModel::instance().getAccountByModelIndex(index_); |
| 57 | AccountModel::instance().remove(account); |
| 58 | AccountModel::instance().save(); |
| 59 | close(); |
| 60 | } |