blob: b9aa20e4fb7e8c5cb7926779fb7a280b403ad992 [file] [log] [blame]
Stepan Salenikovich75a39172015-07-10 13:21:08 -04001/*
Stepan Salenikovichbe87d2c2016-01-25 14:14:34 -05002 * Copyright (C) 2015-2016 Savoir-faire Linux Inc.
Stepan Salenikovich75a39172015-07-10 13:21:08 -04003 * 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 Salenikovich75a39172015-07-10 13:21:08 -040018 */
19
20#include "accounts.h"
21
22#include <accountmodel.h>
Nicolas Jagerf71f8d82017-04-17 10:22:06 -040023#include <availableaccountmodel.h>
Stepan Salenikovich75a39172015-07-10 13:21:08 -040024
Nicolas Jager15a8b902017-03-21 07:53:06 -040025// LRC
26#include <QItemSelectionModel>
27
Stepan Salenikovich75a39172015-07-10 13:21:08 -040028/**
29 * returns TRUE if a RING account exists; FALSE otherwise
30 */
31gboolean
32has_ring_account()
33{
Guillaume Roguez5d1514b2015-10-22 15:55:31 -040034 return !AccountModel::instance().getAccountsByProtocol(Account::Protocol::RING).isEmpty();
Stepan Salenikovich75a39172015-07-10 13:21:08 -040035}
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 */
42void
43force_ring_display_name()
44{
Guillaume Roguez5d1514b2015-10-22 15:55:31 -040045 auto ringaccounts = AccountModel::instance().getAccountsByProtocol(Account::Protocol::RING);
Stepan Salenikovich75a39172015-07-10 13:21:08 -040046 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 Salenikovich30e134e2015-09-24 21:20:25 -040055
56/**
Nicolas Jager15a8b902017-03-21 07:53:06 -040057 * Returns the the user chosen account if it's a ring account, nullptr otherwise.
Stepan Salenikovich30e134e2015-09-24 21:20:25 -040058 */
59Account*
60get_active_ring_account()
61{
Nicolas Jagerf71f8d82017-04-17 10:22:06 -040062 const auto idx = AvailableAccountModel::instance().selectionModel()->currentIndex();
63 auto account = idx.data(static_cast<int>(Account::Role::Object)).value<Account*>();
64
Nicolas Jager15a8b902017-03-21 07:53:06 -040065 return (account && account->protocol() == Account::Protocol::RING) ? account : nullptr;
Stepan Salenikovich30e134e2015-09-24 21:20:25 -040066}