~noskcaj/ubuntu/saucy/sflphone/merge-1.2.3-2

« back to all changes in this revision

Viewing changes to kde/src/lib/Account.cpp

  • Committer: Package Import Robot
  • Author(s): Francois Marier
  • Date: 2012-02-18 21:47:09 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20120218214709-6362d71gqdsdkrj5
Tags: 1.0.2-1
* New upstream release
  - remove logging patch (applied upstream)
  - update s390 patch since it was partially applied upstream
* Include the Evolution plugin as a separate binary package

* Fix compilation issues on SH4 (closes: #658987)
* Merge Ubuntu's binutils-gold linking fix

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2009 by Savoir-Faire Linux                              *
 
3
 *   Author : Jérémy Quentin <jeremy.quentin@savoirfairelinux.com>         *
 
4
 *            Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com>*
 
5
 *                                                                         *
 
6
 *   This program is free software; you can redistribute it and/or modify  *
 
7
 *   it under the terms of the GNU General Public License as published by  *
 
8
 *   the Free Software Foundation; either version 3 of the License, or     *
 
9
 *   (at your option) any later version.                                   *
 
10
 *                                                                         *
 
11
 *   This program is distributed in the hope that it will be useful,       *
 
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
14
 *   GNU General Public License for more details.                          *
 
15
 *                                                                         *
 
16
 *   You should have received a copy of the GNU General Public License     *
 
17
 *   along with this program; if not, write to the                         *
 
18
 *   Free Software Foundation, Inc.,                                       *
 
19
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 
20
 ***************************************************************************/
 
21
 
 
22
//Parent
 
23
#include "Account.h"
 
24
 
 
25
//Qt
 
26
#include <QtCore/QDebug>
 
27
#include <QtCore/QString>
 
28
 
 
29
//SFLPhone
 
30
#include "sflphone_const.h"
 
31
 
 
32
//SFLPhone lib
 
33
#include "configurationmanager_interface_singleton.h"
 
34
 
 
35
///Match state name to user readable string
 
36
const QString& account_state_name(const QString& s)
 
37
{
 
38
   static const QString registered             = "Registered"               ;
 
39
   static const QString notRegistered          = "Not Registered"           ;
 
40
   static const QString trying                 = "Trying..."                ;
 
41
   static const QString error                  = "Error"                    ;
 
42
   static const QString authenticationFailed   = "Authentication Failed"    ;
 
43
   static const QString networkUnreachable     = "Network unreachable"      ;
 
44
   static const QString hostUnreachable        = "Host unreachable"         ;
 
45
   static const QString stunConfigurationError = "Stun configuration error" ;
 
46
   static const QString stunServerInvalid      = "Stun server invalid"      ;
 
47
   static const QString invalid                = "Invalid"                  ;
 
48
   
 
49
   if(s == QString(ACCOUNT_STATE_REGISTERED)       )
 
50
      return registered             ;
 
51
   if(s == QString(ACCOUNT_STATE_UNREGISTERED)     )
 
52
      return notRegistered          ;
 
53
   if(s == QString(ACCOUNT_STATE_TRYING)           )
 
54
      return trying                 ;
 
55
   if(s == QString(ACCOUNT_STATE_ERROR)            )
 
56
      return error                  ;
 
57
   if(s == QString(ACCOUNT_STATE_ERROR_AUTH)       )
 
58
      return authenticationFailed   ;
 
59
   if(s == QString(ACCOUNT_STATE_ERROR_NETWORK)    )
 
60
      return networkUnreachable     ;
 
61
   if(s == QString(ACCOUNT_STATE_ERROR_HOST)       )
 
62
      return hostUnreachable        ;
 
63
   if(s == QString(ACCOUNT_STATE_ERROR_CONF_STUN)  )
 
64
      return stunConfigurationError ;
 
65
   if(s == QString(ACCOUNT_STATE_ERROR_EXIST_STUN) )
 
66
      return stunServerInvalid      ;
 
67
   return invalid                   ;
 
68
}
 
69
 
 
70
///Constructors
 
71
Account::Account():m_pAccountId(NULL),m_pAccountDetails(NULL)
 
72
{
 
73
}
 
74
 
 
75
///Build an account from it'id
 
76
Account* Account::buildExistingAccountFromId(const QString& _accountId)
 
77
{
 
78
   qDebug() << "Building an account from id: " << _accountId;
 
79
   ConfigurationManagerInterface& configurationManager = ConfigurationManagerInterfaceSingleton::getInstance();
 
80
   Account* a = new Account();
 
81
   a->m_pAccountId = new QString(_accountId);
 
82
   MapStringString* aDetails = new MapStringString(configurationManager.getAccountDetails(_accountId).value());
 
83
   
 
84
   if (!aDetails->count()) {
 
85
      qDebug() << "Account not found";
 
86
      return NULL;
 
87
   }
 
88
   a->m_pAccountDetails = aDetails;
 
89
   return a;
 
90
}
 
91
 
 
92
///Build an account from it's name / alias
 
93
Account* Account::buildNewAccountFromAlias(const QString& alias)
 
94
{
 
95
   qDebug() << "Building an account from alias: " << alias;
 
96
   Account* a = new Account();
 
97
   a->m_pAccountDetails = new MapStringString();
 
98
   a->setAccountDetail(ACCOUNT_ALIAS,alias);
 
99
   return a;
 
100
}
 
101
 
 
102
///Destructor
 
103
Account::~Account()
 
104
{
 
105
   delete m_pAccountId;
 
106
}
 
107
 
 
108
 
 
109
/*****************************************************************************
 
110
 *                                                                           *
 
111
 *                                  Getters                                  *
 
112
 *                                                                           *
 
113
 ****************************************************************************/
 
114
 
 
115
///IS this account new
 
116
bool Account::isNew() const
 
117
{
 
118
   return (m_pAccountId == NULL);
 
119
}
 
120
 
 
121
///Get this account ID
 
122
const QString& Account::getAccountId() const
 
123
{
 
124
   if (isNew())
 
125
      qDebug() << "Error : getting AccountId of a new account.";
 
126
   if (!m_pAccountId) {
 
127
      qDebug() << "Account not configured";
 
128
      return EMPTY_STRING; //WARNING May explode
 
129
   }
 
130
   
 
131
   return *m_pAccountId; 
 
132
}
 
133
 
 
134
///Get this account details
 
135
const MapStringString& Account::getAccountDetails() const
 
136
{
 
137
   return *m_pAccountDetails;
 
138
}
 
139
 
 
140
///Get current state
 
141
const QString& Account::getStateName(const QString& state) const
 
142
{
 
143
   return (const QString&)account_state_name(state);
 
144
}
 
145
 
 
146
///Get an account detail
 
147
const QString& Account::getAccountDetail(const QString& param) const
 
148
{
 
149
   if (!m_pAccountDetails) {
 
150
      qDebug() << "The account list is not set";
 
151
      return EMPTY_STRING; //May crash, but better than crashing now
 
152
   }
 
153
   if (m_pAccountDetails->find(param) != m_pAccountDetails->end())
 
154
      return (*m_pAccountDetails)[param];
 
155
   else {
 
156
      qDebug() << "Account details not found, there is " << m_pAccountDetails->count() << " details available";
 
157
      return EMPTY_STRING;
 
158
   }
 
159
}
 
160
 
 
161
///Get the alias
 
162
const QString& Account::getAlias() const
 
163
{
 
164
   return getAccountDetail(ACCOUNT_ALIAS);
 
165
}
 
166
 
 
167
///Is this account enabled
 
168
bool Account::isEnabled() const
 
169
{
 
170
   return (getAccountDetail(ACCOUNT_ENABLED) == ACCOUNT_ENABLED_TRUE);
 
171
}
 
172
 
 
173
///Is this account registered
 
174
bool Account::isRegistered() const
 
175
{
 
176
   return (getAccountDetail(ACCOUNT_STATUS) == ACCOUNT_STATE_REGISTERED);
 
177
}
 
178
 
 
179
 
 
180
/*****************************************************************************
 
181
 *                                                                           *
 
182
 *                                  Setters                                  *
 
183
 *                                                                           *
 
184
 ****************************************************************************/
 
185
 
 
186
///Set account details
 
187
void Account::setAccountDetails(const MapStringString& m)
 
188
{
 
189
   *m_pAccountDetails = m;
 
190
}
 
191
 
 
192
///Set a specific detail
 
193
void Account::setAccountDetail(const QString& param, const QString& val)
 
194
{
 
195
   (*m_pAccountDetails)[param] = val;
 
196
}
 
197
 
 
198
///Set the account id
 
199
void Account::setAccountId(const QString& id)
 
200
{
 
201
   qDebug() << "Setting accountId = " << m_pAccountId;
 
202
   if (! isNew())
 
203
      qDebug() << "Error : setting AccountId of an existing account.";
 
204
   m_pAccountId = new QString(id);
 
205
}
 
206
 
 
207
///Set account enabled
 
208
void Account::setEnabled(bool checked)
 
209
{
 
210
   setAccountDetail(ACCOUNT_ENABLED, checked ? ACCOUNT_ENABLED_TRUE : ACCOUNT_ENABLED_FALSE);
 
211
}
 
212
 
 
213
/*****************************************************************************
 
214
 *                                                                           *
 
215
 *                                  Mutator                                  *
 
216
 *                                                                           *
 
217
 ****************************************************************************/
 
218
 
 
219
///Update the account
 
220
void Account::updateState()
 
221
{
 
222
   if(! isNew()) {
 
223
      ConfigurationManagerInterface & configurationManager = ConfigurationManagerInterfaceSingleton::getInstance();
 
224
      MapStringString details = configurationManager.getAccountDetails(getAccountId()).value();
 
225
      QString status = details[ACCOUNT_STATUS];
 
226
      setAccountDetail(ACCOUNT_STATUS, status); //Update -internal- object state
 
227
   }
 
228
}
 
229
 
 
230
/*****************************************************************************
 
231
 *                                                                           *
 
232
 *                                 Operator                                  *
 
233
 *                                                                           *
 
234
 ****************************************************************************/
 
235
 
 
236
///Are both account the same
 
237
bool Account::operator==(const Account& a)const
 
238
{
 
239
   return *m_pAccountId == *a.m_pAccountId;
 
240
}
 
241
 
 
242