blob: bbc182ba4075f3b067fdaf6e02af379b665e05e3 [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>
23
Nicolas Jager15a8b902017-03-21 07:53:06 -040024// LRC
25#include <QItemSelectionModel>
26
Stepan Salenikovich75a39172015-07-10 13:21:08 -040027/**
28 * returns TRUE if a RING account exists; FALSE otherwise
29 */
30gboolean
31has_ring_account()
32{
Guillaume Roguez5d1514b2015-10-22 15:55:31 -040033 return !AccountModel::instance().getAccountsByProtocol(Account::Protocol::RING).isEmpty();
Stepan Salenikovich75a39172015-07-10 13:21:08 -040034}
35
36/**
37 * itterates through all existing accounts and make sure all RING accounts have
38 * a display name set; if a display name is empty, it is set to the alias of the
39 * account
40 */
41void
42force_ring_display_name()
43{
Guillaume Roguez5d1514b2015-10-22 15:55:31 -040044 auto ringaccounts = AccountModel::instance().getAccountsByProtocol(Account::Protocol::RING);
Stepan Salenikovich75a39172015-07-10 13:21:08 -040045 for (int i = 0; i < ringaccounts.size(); ++i) {
46 auto account = ringaccounts.at(i);
47 if (account->displayName().isEmpty()) {
48 g_debug("updating RING account display name to: %s", account->alias().toUtf8().constData());
49 account->setDisplayName(account->alias());
50 account << Account::EditAction::SAVE;
51 }
52 }
53}
Stepan Salenikovich30e134e2015-09-24 21:20:25 -040054
55/**
Nicolas Jager15a8b902017-03-21 07:53:06 -040056 * Returns the the user chosen account if it's a ring account, nullptr otherwise.
Stepan Salenikovich30e134e2015-09-24 21:20:25 -040057 */
58Account*
59get_active_ring_account()
60{
Nicolas Jager15a8b902017-03-21 07:53:06 -040061 auto account = AccountModel::instance().userChosenAccount();
62 return (account && account->protocol() == Account::Protocol::RING) ? account : nullptr;
Stepan Salenikovich30e134e2015-09-24 21:20:25 -040063}