AccountSelectionManager.mm 1.94 KB
Newer Older
1 2 3
/*
 *  Copyright (C) 2015-2017 Savoir-faire Linux Inc.
 *  Author: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
4 5
 *  Author: Olivier Soldano <olivier.soldano@savoirfairelinux.com>
 *  Author: Anthony Léonard <anthony.leonard@savoirfairelinux.com>
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
 */

// LRC
23 24
#import <api/newaccountmodel.h>
#import <api/account.h>
25 26 27

#import "AccountSelectionManager.h"

28 29 30 31 32
@implementation AccountSelectionManager {

    const lrc::api::NewAccountModel* accMdl_;

}
33 34 35

NSString* const savedUserAccountKey = @"savedUserSelectedAccountKey";

36 37 38
- (id) initWithAccountModel:(const lrc::api::NewAccountModel*) accMdl {
    accMdl_ = accMdl;
    return [self init];
39 40
}

41 42 43 44
- (void) saveAccountWithId:(NSString*)accId
{
    [[NSUserDefaults standardUserDefaults] setObject:accId forKey:savedUserAccountKey];
}
45

46 47 48 49
- (NSString*) getSavedAccountId
{
    return [[NSUserDefaults standardUserDefaults] stringForKey:savedUserAccountKey];
}
50

51 52 53 54 55 56 57 58 59 60 61
- (const lrc::api::account::Info&) savedAccount
{
    return accMdl_->getAccountInfo(std::string([[self getSavedAccountId] UTF8String]));
}

- (void) setSavedAccount:(const lrc::api::account::Info&) acc
{
    if (acc.profileInfo.type == lrc::api::profile::Type::INVALID)
        return;
    else
        saveAccountWithId:@(acc.id.c_str());
62 63 64
}

@end