account.cpp 4.13 KB
Newer Older
yanmorin's avatar
 
yanmorin committed
1
/*
2
 *  Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011 Savoir-Faire Linux Inc.
3 4
 *
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
5
 *  Author: Alexandre Bourget <alexandre.bourget@savoirfairelinux.com>
yanmorin's avatar
 
yanmorin committed
6 7 8
 *
 *  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
9
 *  the Free Software Foundation; either version 3 of the License, or
yanmorin's avatar
 
yanmorin committed
10 11 12 13 14 15 16 17 18 19
 *  (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., 675 Mass Ave, Cambridge, MA 02139, USA.
20 21 22 23 24 25 26 27 28 29 30
 *
 *  Additional permission under GNU GPL version 3 section 7:
 *
 *  If you modify this program, or any covered work, by linking or
 *  combining it with the OpenSSL project's OpenSSL library (or a
 *  modified version of that library), containing parts covered by the
 *  terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
 *  grants you additional permission to convey the resulting work.
 *  Corresponding Source for a non-source form of such a combination
 *  shall include the source code for the parts of OpenSSL used as well
 *  as that of the covered work.
yanmorin's avatar
 
yanmorin committed
31
 */
32

yanmorin's avatar
 
yanmorin committed
33
#include "account.h"
34
#include "manager.h"
35
#include "dbus/configurationmanager.h"
36
#ifdef SFL_VIDEO
37
#include "video/video_endpoint.h"
38
#endif
yanmorin's avatar
 
yanmorin committed
39

40
Account::Account(const std::string &accountID, const std::string &type) :
41
    accountID_(accountID)
42 43 44
    , username_()
    , hostname_()
    , alias_()
45 46 47
    , enabled_(true)
    , type_(type)
    , registrationState_(Unregistered)
48 49 50 51
    , codecList_()
#ifdef SFL_VIDEO
    , videoCodecList_()
#endif
52
    , codecStr_()
53 54 55 56
    , ringtonePath_("/usr/share/sflphone/ringtones/konga.ul")
    , ringtoneEnabled_(true)
    , displayName_("")
    , userAgent_("SFLphone")
57
    , mailBox_()
Julien Bonjean's avatar
Julien Bonjean committed
58
{
59
    // Initialize the codec order, used when creating a new account
60
    loadDefaultCodecs();
yanmorin's avatar
 
yanmorin committed
61 62
}

Julien Bonjean's avatar
Julien Bonjean committed
63
Account::~Account()
64
{}
65

66
void Account::setRegistrationState(const RegistrationState &state)
Julien Bonjean's avatar
Julien Bonjean committed
67
{
Tristan Matthews's avatar
Tristan Matthews committed
68 69
    if (state != registrationState_) {
        registrationState_ = state;
Emmanuel Milou's avatar
Emmanuel Milou committed
70

Emmanuel Milou's avatar
Emmanuel Milou committed
71
        // Notify the client
72 73
        ConfigurationManager *c(Manager::instance().getDbusManager()->getConfigurationManager());
        c->registrationStateChanged(accountID_, registrationState_);
Emmanuel Milou's avatar
Emmanuel Milou committed
74
    }
Emmanuel Milou's avatar
Emmanuel Milou committed
75
}
Emmanuel Milou's avatar
Emmanuel Milou committed
76

77
void Account::loadDefaultCodecs()
Julien Bonjean's avatar
Julien Bonjean committed
78
{
79
    // Initialize codec
80 81 82 83 84 85 86 87
    std::vector<std::string> result;
    result.push_back("0");
    result.push_back("3");
    result.push_back("8");
    result.push_back("9");
    result.push_back("110");
    result.push_back("111");
    result.push_back("112");
88

89
    setActiveCodecs(result);
90 91
#ifdef SFL_VIDEO
    setActiveVideoCodecs(sfl_video::getCodecList());
92
#endif
93
}
94

95
#ifdef SFL_VIDEO
96
void Account::setActiveVideoCodecs(const std::vector<std::string> &list)
97
{
98
    videoCodecList_ = !list.empty() ? list : sfl_video::getCodecList();
99
}
100
#endif
101

102
void Account::setActiveCodecs(const std::vector <std::string> &list)
Julien Bonjean's avatar
Julien Bonjean committed
103
{
104
    // first clear the previously stored codecs
105
    codecList_.clear();
106

Emmanuel Milou's avatar
Emmanuel Milou committed
107
    // list contains the ordered payload of active codecs picked by the user for this account
108 109 110 111
    // we used the CodecOrder vector to save the order.
    for (std::vector<std::string>::const_iterator iter = list.begin(); iter != list.end();
            ++iter) {
        int payload = std::atoi(iter->c_str());
112
        codecList_.push_back(static_cast<int>(payload));
Emmanuel Milou's avatar
Emmanuel Milou committed
113 114
    }

115
    // update the codec string according to new codec selection
116
    codecStr_ = ManagerImpl::join_string(list);
Emmanuel Milou's avatar
Emmanuel Milou committed
117
}
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137

std::string Account::mapStateNumberToString(RegistrationState state)
{
    static const char * mapStateToChar[] = {
        "UNREGISTERED",
        "TRYING",
        "REGISTERED",
        "ERROR",
        "ERRORAUTH",
        "ERRORNETWORK",
        "ERRORHOST",
        "ERROREXISTSTUN",
        "ERRORCONFSTUN"
    };

    if (state > NumberOfStates)
        return "ERROR";

    return mapStateToChar[state];
}