Stepan Salenikovich | 75a3917 | 2015-07-10 13:21:08 -0400 | [diff] [blame] | 1 | /* |
Stepan Salenikovich | be87d2c | 2016-01-25 14:14:34 -0500 | [diff] [blame] | 2 | * Copyright (C) 2015-2016 Savoir-faire Linux Inc. |
Stepan Salenikovich | 75a3917 | 2015-07-10 13:21:08 -0400 | [diff] [blame] | 3 | * Author: Stepan Salenikovich <stepan.salenikovich@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, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
Stepan Salenikovich | 75a3917 | 2015-07-10 13:21:08 -0400 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include "accounts.h" |
| 21 | |
| 22 | #include <accountmodel.h> |
Nicolas Jager | 1124172 | 2017-04-17 10:22:06 -0400 | [diff] [blame^] | 23 | #include <availableaccountmodel.h> |
Stepan Salenikovich | 75a3917 | 2015-07-10 13:21:08 -0400 | [diff] [blame] | 24 | |
Nicolas Jager | 15a8b90 | 2017-03-21 07:53:06 -0400 | [diff] [blame] | 25 | // LRC |
| 26 | #include <QItemSelectionModel> |
| 27 | |
Stepan Salenikovich | 75a3917 | 2015-07-10 13:21:08 -0400 | [diff] [blame] | 28 | /** |
| 29 | * returns TRUE if a RING account exists; FALSE otherwise |
| 30 | */ |
| 31 | gboolean |
| 32 | has_ring_account() |
| 33 | { |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 34 | return !AccountModel::instance().getAccountsByProtocol(Account::Protocol::RING).isEmpty(); |
Stepan Salenikovich | 75a3917 | 2015-07-10 13:21:08 -0400 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | /** |
| 38 | * itterates through all existing accounts and make sure all RING accounts have |
| 39 | * a display name set; if a display name is empty, it is set to the alias of the |
| 40 | * account |
| 41 | */ |
| 42 | void |
| 43 | force_ring_display_name() |
| 44 | { |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 45 | auto ringaccounts = AccountModel::instance().getAccountsByProtocol(Account::Protocol::RING); |
Stepan Salenikovich | 75a3917 | 2015-07-10 13:21:08 -0400 | [diff] [blame] | 46 | for (int i = 0; i < ringaccounts.size(); ++i) { |
| 47 | auto account = ringaccounts.at(i); |
| 48 | if (account->displayName().isEmpty()) { |
| 49 | g_debug("updating RING account display name to: %s", account->alias().toUtf8().constData()); |
| 50 | account->setDisplayName(account->alias()); |
| 51 | account << Account::EditAction::SAVE; |
| 52 | } |
| 53 | } |
| 54 | } |
Stepan Salenikovich | 30e134e | 2015-09-24 21:20:25 -0400 | [diff] [blame] | 55 | |
| 56 | /** |
Nicolas Jager | 15a8b90 | 2017-03-21 07:53:06 -0400 | [diff] [blame] | 57 | * Returns the the user chosen account if it's a ring account, nullptr otherwise. |
Stepan Salenikovich | 30e134e | 2015-09-24 21:20:25 -0400 | [diff] [blame] | 58 | */ |
| 59 | Account* |
| 60 | get_active_ring_account() |
| 61 | { |
Nicolas Jager | 1124172 | 2017-04-17 10:22:06 -0400 | [diff] [blame^] | 62 | const auto idx = AvailableAccountModel::instance().selectionModel()->currentIndex(); |
| 63 | auto account = idx.data(static_cast<int>(Account::Role::Object)).value<Account*>(); |
| 64 | |
Nicolas Jager | 15a8b90 | 2017-03-21 07:53:06 -0400 | [diff] [blame] | 65 | return (account && account->protocol() == Account::Protocol::RING) ? account : nullptr; |
Stepan Salenikovich | 30e134e | 2015-09-24 21:20:25 -0400 | [diff] [blame] | 66 | } |