~ubuntu-branches/ubuntu/vivid/sflphone/vivid

« back to all changes in this revision

Viewing changes to kde/src/conf/dlgaccounts.cpp

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2013-06-30 11:40:56 UTC
  • mfrom: (4.1.18 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130630114056-0np50jkyqo6vnmii
Tags: 1.2.3-2
* changeset_r92d62cfc54732bbbcfff2b1d36c096b120b981a5.diff 
  - fixes automatic endian detection 
* Update Vcs: fixes vcs-field-not-canonical

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
 *   Copyright (C) 2009-2013 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 library is free software; you can redistribute it and/or          *
 
7
 *   modify it under the terms of the GNU Lesser General Public             *
 
8
 *   License as published by the Free Software Foundation; either           *
 
9
 *   version 2.1 of the License, or (at your option) any later version.     *
 
10
 *                                                                          *
 
11
 *   This library 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 GNU      *
 
14
 *   Lesser 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, see <http://www.gnu.org/licenses/>.  *
 
18
 ***************************************************************************/
 
19
#include "dlgaccounts.h"
 
20
 
 
21
//Qt
 
22
#include <QtCore/QString>
 
23
#include <qglobal.h>
 
24
#include <QtGui/QTableWidget>
 
25
#include <QtGui/QListWidgetItem>
 
26
#include <QtGui/QWidget>
 
27
 
 
28
//KDE
 
29
#include <KConfigDialog>
 
30
#include <KDebug>
 
31
#include <KStandardDirs>
 
32
#include <KInputDialog>
 
33
#include <KLocale>
 
34
 
 
35
//SFLPhone
 
36
#include "klib/configurationskeleton.h"
 
37
#include "conf/configurationdialog.h"
 
38
#include "lib/configurationmanager_interface_singleton.h"
 
39
#include "sflphoneview.h"
 
40
#include "lib/sflphone_const.h"
 
41
#include "lib/credentialmodel.h"
 
42
#include "lib/audiocodecmodel.h"
 
43
 
 
44
//OS
 
45
#ifdef Q_WS_WIN // MS Windows version
 
46
   #include <windows.h>
 
47
#endif
 
48
#ifdef Q_WS_X11
 
49
   #include <X11/XKBlib.h>
 
50
   #include <QX11Info>
 
51
#endif
 
52
 
 
53
///Constructor
 
54
DlgAccounts::DlgAccounts(KConfigDialog* parent)
 
55
 : QWidget(parent),m_IsLoading(false)
 
56
{
 
57
   m_IsLoading++;
 
58
   setupUi(this);
 
59
   button_accountUp->setIcon         ( KIcon( "go-up"       ) );
 
60
   button_accountDown->setIcon       ( KIcon( "go-down"     ) );
 
61
   m_pVCodecUpPB->setIcon            ( KIcon( "go-up"       ) );
 
62
   m_pVCodecDownPB->setIcon          ( KIcon( "go-down"     ) );
 
63
   button_accountAdd->setIcon        ( KIcon( "list-add"    ) );
 
64
   button_accountRemove->setIcon     ( KIcon( "list-remove" ) );
 
65
   button_add_credential->setIcon    ( KIcon( "list-add"    ) );
 
66
   button_remove_credential->setIcon ( KIcon( "list-remove" ) );
 
67
   button_audiocodecUp->setIcon      ( KIcon( "go-up"       ) );
 
68
   button_audiocodecDown->setIcon    ( KIcon( "go-down"     ) );
 
69
   listView_accountList->setModel(AccountList::getInstance());
 
70
 
 
71
   m_pInfoIconL->setPixmap(KIcon("dialog-information").pixmap(QSize(32,32)));
 
72
   label_message_icon->setPixmap(KIcon("dialog-information").pixmap(QSize(24,24)));
 
73
 
 
74
   m_pRingTonePath->setMode(KFile::File | KFile::ExistingOnly);
 
75
   m_pRingTonePath->lineEdit()->setObjectName("m_pRingTonePath");
 
76
   m_pRingTonePath->lineEdit()->setReadOnly(true);
 
77
 
 
78
   loadAccountList();
 
79
   accountListHasChanged = false;
 
80
 
 
81
   //SLOTS
 
82
   //                     SENDER                            SIGNAL                       RECEIVER              SLOT                          /
 
83
   /**/connect(edit1_alias,                       SIGNAL(textEdited(QString))            , this   , SLOT(changedAccountList())              );
 
84
   /**/connect(edit1_alias,                       SIGNAL(textEdited(QString))            , this   , SLOT(changeAlias(QString))              );
 
85
   /**/connect(edit2_protocol,                    SIGNAL(activated(int))                 , this   , SLOT(changedAccountList())              );
 
86
   /**/connect(edit3_server,                      SIGNAL(textEdited(QString))            , this   , SLOT(changedAccountList())              );
 
87
   /**/connect(edit4_user,                        SIGNAL(textEdited(QString))            , this   , SLOT(changedAccountList())              );
 
88
   /**/connect(edit4_user,                        SIGNAL(textEdited(QString))            , this   , SLOT(updateFirstCredential(QString))    );
 
89
   /**/connect(edit5_password,                    SIGNAL(textEdited(QString))            , this   , SLOT(changedAccountList())              );
 
90
   /**/connect(edit6_mailbox,                     SIGNAL(textEdited(QString))            , this   , SLOT(changedAccountList())              );
 
91
   /**/connect(m_pProxyLE,                        SIGNAL(textEdited(QString))            , this   , SLOT(changedAccountList())              );
 
92
   /**/connect(m_pProxyCK,                        SIGNAL(clicked(bool))                  , this   , SLOT(changedAccountList())              );
 
93
   /**/connect(m_pDTMFOverRTP,                    SIGNAL(clicked(bool))                  , this   , SLOT(changedAccountList())              );
 
94
   /**/connect(m_pDTMFOverSIP,                    SIGNAL(clicked(bool))                  , this   , SLOT(changedAccountList())              );
 
95
   /**/connect(m_pAutoAnswer,                     SIGNAL(clicked(bool))                  , this   , SLOT(changedAccountList())              );
 
96
   /**/connect(spinbox_regExpire,                 SIGNAL(valueChanged(int))              , this   , SLOT(changedAccountList())              );
 
97
   /**/connect(spinBox_pa_published_port,         SIGNAL(valueChanged(int))              , this   , SLOT(changedAccountList())              );
 
98
   /**/connect(comboBox_ni_local_address,         SIGNAL(currentIndexChanged(int))       , this   , SLOT(changedAccountList())              );
 
99
   /**/connect(spinBox_ni_local_port,             SIGNAL(valueChanged(int))              , this   , SLOT(changedAccountList())              );
 
100
   /**/connect(button_accountUp,                  SIGNAL(clicked())                      , this   , SLOT(changedAccountList())              );
 
101
   /**/connect(button_accountDown,                SIGNAL(clicked())                      , this   , SLOT(changedAccountList())              );
 
102
   /**/connect(button_accountAdd,                 SIGNAL(clicked())                      , this   , SLOT(otherAccountChanged())             );
 
103
   /**/connect(button_accountRemove,              SIGNAL(clicked())                      , this   , SLOT(otherAccountChanged())             );
 
104
   /**/connect(button_audiocodecDown,             SIGNAL(clicked())                      , this   , SLOT(changedAccountList())              );
 
105
   /**/connect(m_pDefaultAccount,                 SIGNAL(clicked(bool))                  , this   , SLOT(changedAccountList())              );
 
106
   /**/connect(checkbox_stun,                     SIGNAL(clicked(bool))                  , this   , SLOT(changedAccountList())              );
 
107
   /**/connect(button_audiocodecUp,               SIGNAL(clicked())                      , this   , SLOT(changedAccountList())              );
 
108
   /**/connect(lineEdit_pa_published_address,     SIGNAL(textEdited(QString))            , this   , SLOT(changedAccountList())              );
 
109
   /**/connect(lineEdit_pa_published_address,     SIGNAL(textEdited(QString))            , this   , SLOT(changedAccountList())              );
 
110
   /**/connect(edit_tls_private_key_password,     SIGNAL(textEdited(QString))            , this   , SLOT(changedAccountList())              );
 
111
   /**/connect(spinbox_tls_listener,              SIGNAL(valueChanged(int))              , this   , SLOT(changedAccountList())              );
 
112
   /**/connect(m_pBitrateSB,                      SIGNAL(valueChanged(int))              , this   , SLOT(changedAccountList())              );
 
113
   /**/connect(file_tls_authority,                SIGNAL(textChanged(QString))           , this   , SLOT(changedAccountList())              );
 
114
   /**/connect(file_tls_endpoint,                 SIGNAL(textChanged(QString))           , this   , SLOT(changedAccountList())              );
 
115
   /**/connect(file_tls_private_key,              SIGNAL(textChanged(QString))           , this   , SLOT(changedAccountList())              );
 
116
   /**/connect(combo_tls_method,                  SIGNAL(currentIndexChanged(int))       , this   , SLOT(changedAccountList())              );
 
117
   /**/connect(edit_tls_cipher,                   SIGNAL(textEdited(QString))            , this   , SLOT(changedAccountList())              );
 
118
   /**/connect(edit_tls_outgoing,                 SIGNAL(textEdited(QString))            , this   , SLOT(changedAccountList())              );
 
119
   /**/connect(spinbox_tls_timeout_sec,           SIGNAL(valueChanged(int))              , this   , SLOT(changedAccountList())              );
 
120
   /**/connect(spinbox_tls_timeout_msec,          SIGNAL(valueChanged(int))              , this   , SLOT(changedAccountList())              );
 
121
   /**/connect(check_tls_incoming,                SIGNAL(clicked(bool))                  , this   , SLOT(changedAccountList())              );
 
122
   /**/connect(check_tls_answer,                  SIGNAL(clicked(bool))                  , this   , SLOT(changedAccountList())              );
 
123
   /**/connect(check_tls_requier_cert,            SIGNAL(clicked(bool))                  , this   , SLOT(changedAccountList())              );
 
124
   /**/connect(group_security_tls,                SIGNAL(clicked(bool))                  , this   , SLOT(changedAccountList())              );
 
125
   /**/connect(radioButton_pa_same_as_local,      SIGNAL(clicked(bool))                  , this   , SLOT(changedAccountList())              );
 
126
   /**/connect(radioButton_pa_custom,             SIGNAL(clicked(bool))                  , this   , SLOT(changedAccountList())              );
 
127
   /**/connect(m_pRingtoneListLW,                 SIGNAL(currentRowChanged(int))         , this   , SLOT(changedAccountList())              );
 
128
   /**/connect(m_pUseCustomFileCK,                SIGNAL(clicked(bool))                  , this   , SLOT(changedAccountList())              );
 
129
   /**/connect(m_pCodecsLW,                       SIGNAL(itemChanged(QListWidgetItem*))  , this   , SLOT(changedAccountList())              );
 
130
   /**/connect(edit_credential_realm,             SIGNAL(textEdited(QString))            , this   , SLOT(changedAccountList())              );
 
131
   /**/connect(edit_credential_auth,              SIGNAL(textEdited(QString))            , this   , SLOT(changedAccountList())              );
 
132
   /**/connect(edit_credential_password,          SIGNAL(textEdited(QString))            , this   , SLOT(changedAccountList())              );
 
133
   /**/connect(m_pCodecsLW,                       SIGNAL(currentTextChanged(QString))    , this   , SLOT(loadVidCodecDetails(QString))      );
 
134
   ///**/connect(&configurationManager,             SIGNAL(accountsChanged())            , this   , SLOT(updateAccountStates()             ));
 
135
   /**/connect(edit_tls_private_key_password,     SIGNAL(textEdited(QString))            , this   , SLOT(changedAccountList())              );
 
136
   /**/connect(this,                              SIGNAL(updateButtons())                , parent , SLOT(updateButtons())                   );
 
137
   /**/connect(combo_security_STRP,               SIGNAL(currentIndexChanged(int))       , this   , SLOT(updateCombo(int))                  );
 
138
   /**/connect(button_add_credential,             SIGNAL(clicked())                      , this   , SLOT(addCredential())                   );
 
139
   /**/connect(button_remove_credential,          SIGNAL(clicked())                      , this   , SLOT(removeCredential())                );
 
140
   /**/connect(edit5_password,                    SIGNAL(textEdited(QString))            , this   , SLOT(main_password_field_changed())     );
 
141
   /**/connect(edit_credential_password,          SIGNAL(textEdited(QString))            , this   , SLOT(main_credential_password_changed()));
 
142
   /**/connect(button_audiocodecUp,               SIGNAL(clicked())                      , this   , SLOT(moveAudioCodecUp())                );
 
143
   /**/connect(button_audiocodecDown,             SIGNAL(clicked())                      , this   , SLOT(moveAudioCodecDown())              );
 
144
   /**/connect(m_pVCodecUpPB,                     SIGNAL(clicked())                      , this   , SLOT(moveVideoCodecUp())                );
 
145
   /**/connect(m_pVCodecDownPB,                   SIGNAL(clicked())                      , this   , SLOT(moveVideoCodecDown())              );
 
146
   /**/connect(AccountList::getInstance(),        SIGNAL(accountEnabledChanged(Account*)), this   , SLOT(otherAccountChanged())             );
 
147
   /**/connect(AccountList::getInstance(),        SIGNAL(accountStateChanged(Account*,QString)), this   , SLOT(updateStatusLabel(Account*)) );
 
148
   /*                                                                                                                                       */
 
149
 
 
150
   connect(listView_accountList->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(accountListChanged(QModelIndex,QModelIndex)) );
 
151
   connect(listView_accountList->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(updateAccountListCommands())                 );
 
152
 
 
153
 
 
154
   //Disable control
 
155
   connect(radioButton_pa_same_as_local,   SIGNAL(clicked(bool)) , this , SLOT(enablePublished()));
 
156
   connect(radioButton_pa_custom,          SIGNAL(clicked(bool)) , this , SLOT(enablePublished()));
 
157
 
 
158
 
 
159
   if (AccountList::getInstance()->index(0,0).isValid()) {
 
160
      listView_accountList->setCurrentIndex(AccountList::getInstance()->index(0,0));
 
161
      loadAccount(listView_accountList->currentIndex());
 
162
   }
 
163
   m_IsLoading--;
 
164
} //DlgAccounts
 
165
 
 
166
///Destructor
 
167
DlgAccounts::~DlgAccounts()
 
168
{
 
169
   //accountList->disconnect();
 
170
   //if (accountList) delete accountList;
 
171
}
 
172
 
 
173
///Save an account using the values from the widgets
 
174
void DlgAccounts::saveAccount(QModelIndex item)
 
175
{
 
176
   Account* account = AccountList::getInstance()->getAccountByModelIndex(item);
 
177
 
 
178
   if(!item.isValid()) {
 
179
      kDebug() << "Attempting to save details of an account from a NULL item";
 
180
      return;
 
181
   }
 
182
 
 
183
   if(!account) {
 
184
      kDebug() << "Attempting to save details of an unexisting account : " << (item.data(Qt::DisplayRole).toString());
 
185
      return;
 
186
   }
 
187
 
 
188
   //There is no point to save something that is unaltered, all it will cause is daemon corruption
 
189
   if (account->currentState() != NEW and account->currentState() != MODIFIED) {
 
190
      kDebug() << "Nothing to be saved";
 
191
      return;
 
192
   }
 
193
   m_IsLoading++;
 
194
   
 
195
   if (!m_pProxyCK->isChecked()) {
 
196
      m_pProxyLE->setText("");
 
197
   }
 
198
   
 
199
   QString protocolsTab[] = ACCOUNT_TYPES_TAB;
 
200
   
 
201
   //ACCOUNT DETAILS
 
202
   //                                                                     WIDGET VALUE                                     /
 
203
   /**/account->setAccountAlias                ( edit1_alias->text()                                                      );
 
204
   /**/account->setAccountType                 ( protocolsTab[edit2_protocol->currentIndex()]                             );
 
205
   /**/account->setAccountHostname             ( edit3_server->text()                                                     );
 
206
   /**/account->setAccountUsername             ( edit4_user->text()                                                       );
 
207
   /**/account->setAccountPassword             ( edit5_password->text()                                                   );
 
208
   /**/account->setAccountMailbox              ( edit6_mailbox->text()                                                    );
 
209
   /**/account->setAccountProxy                ( m_pProxyLE->text()                                                       );
 
210
   /**/account->setAccountEnabled              ( item.data(Qt::CheckStateRole).toBool()                                   );
 
211
   /**/account->setAccountRegistrationExpire   ( spinbox_regExpire->value()                                               );
 
212
   /**/                                                                                                                 /**/
 
213
   /*                                            Security                                                                 */
 
214
   /**/account->setTlsPassword                 ( edit_tls_private_key_password->text()                                    );
 
215
   /**/account->setTlsListenerPort             ( spinbox_tls_listener->value()                                            );
 
216
   /**/account->setTlsCaListFile               ( file_tls_authority->text()                                               );
 
217
   /**/account->setTlsCertificateFile          ( file_tls_endpoint->text()                                                );
 
218
   /**/account->setTlsPrivateKeyFile           ( file_tls_private_key->text()                                             );
 
219
   /**/account->setTlsMethod                   ( combo_tls_method->currentIndex()                                         );
 
220
   /**/account->setTlsCiphers                  ( edit_tls_cipher->text()                                                  );
 
221
   /**/account->setTlsServerName               ( edit_tls_outgoing->text()                                                );
 
222
   /**/account->setTlsNegotiationTimeoutSec    ( spinbox_tls_timeout_sec->value()                                         );
 
223
   /**/account->setTlsNegotiationTimeoutMsec   ( spinbox_tls_timeout_msec->value()                                        );
 
224
   ///**/account->setTlsMethod                   ( QString::number(combo_security_STRP->currentIndex())                   );
 
225
   /**/account->setTlsVerifyServer             ( check_tls_incoming->isChecked()                                          );
 
226
   /**/account->setTlsVerifyClient             ( check_tls_answer->isChecked()                                            );
 
227
   /**/account->setTlsRequireClientCertificate ( check_tls_requier_cert->isChecked()                                      );
 
228
   /**/account->setTlsEnable                   ( group_security_tls->isChecked()                                          );
 
229
   /**/account->setAccountDisplaySasOnce       ( checkbox_ZRTP_Ask_user->isChecked()                                      );
 
230
   /**/account->setAccountSrtpRtpFallback      ( checkbox_SDES_fallback_rtp->isChecked()                                  );
 
231
   /**/account->setAccountZrtpDisplaySas       ( checkbox_ZRTP_display_SAS->isChecked()                                   );
 
232
   /**/account->setAccountZrtpNotSuppWarning   ( checkbox_ZRTP_warn_supported->isChecked()                                );
 
233
   /**/account->setAccountZrtpHelloHash        ( checkbox_ZTRP_send_hello->isChecked()                                    );
 
234
   /**/account->setAccountSipStunEnabled       ( checkbox_stun->isChecked()                                               );
 
235
   /**/account->setPublishedSameAsLocal        ( radioButton_pa_same_as_local->isChecked()                                );
 
236
   /**/account->setAccountSipStunServer        ( line_stun->text()                                                        );
 
237
   /**/account->setPublishedPort               ( spinBox_pa_published_port->value()                                       );
 
238
   /**/account->setPublishedAddress            ( lineEdit_pa_published_address ->text()                                   );
 
239
   /**/account->setLocalPort                   ( spinBox_pa_published_port->value()                                       );
 
240
   /**/account->setLocalInterface              ( comboBox_ni_local_address->currentText()                                 );
 
241
   /**/account->setRingtoneEnabled             ( m_pEnableRingtoneGB->isChecked()                                         );
 
242
   /**/account->setRingtonePath                ( m_pRingTonePath->url().path()                                            );
 
243
   /**/account->setDTMFType                    ( m_pDTMFOverRTP->isChecked()?DtmfType::OverRtp:DtmfType::OverSip          );
 
244
   /**/account->setAutoAnswer                  ( m_pAutoAnswer->isChecked()                                               );
 
245
   //                                                                                                                      /
 
246
 
 
247
 
 
248
   if (m_pDefaultAccount->isChecked()) {
 
249
      ConfigurationSkeleton::setDefaultAccountId(account->getAccountId());
 
250
      AccountList::getInstance()->setDefaultAccount(account);
 
251
   }
 
252
 
 
253
   if (m_pRingtoneListLW->selectedItems().size() == 1 && m_pRingtoneListLW->currentIndex().isValid() ) {
 
254
      QListWidgetItem* selectedRingtone = m_pRingtoneListLW->currentItem();
 
255
      RingToneListItem* ringtoneWidget = qobject_cast<RingToneListItem*>(m_pRingtoneListLW->itemWidget(selectedRingtone));
 
256
      if (ringtoneWidget) {
 
257
         account->setRingtonePath(ringtoneWidget->m_Path);
 
258
      }
 
259
   }
 
260
 
 
261
   if (m_pCodecsLW->currentIndex().isValid())
 
262
      m_pCodecsLW->model()->setData(m_pCodecsLW->currentIndex(),m_pBitrateSB->value(),VideoCodecModel::BITRATE_ROLE);
 
263
   saveCredential();
 
264
   m_IsLoading--;
 
265
} //saveAccount
 
266
 
 
267
void DlgAccounts::cancel()
 
268
{
 
269
//    Account* account = AccountList::getInstance()->getAccountByModelIndex(listView_accountList->currentIndex());
 
270
//    if (account) {
 
271
//       account->performAction(CANCEL);
 
272
//    }
 
273
   const QVector<Account*> accs = AccountList::getInstance()->getAccounts();
 
274
   foreach (Account* a, accs) {
 
275
      if (a->currentState() == MODIFIED || a->currentState() == OUTDATED)
 
276
         a->performAction(CANCEL);
 
277
   }
 
278
}
 
279
 
 
280
///Load an account, set all field to the right value
 
281
void DlgAccounts::loadAccount(QModelIndex item)
 
282
{
 
283
   if(! item.isValid() ) {
 
284
      kDebug() << "Attempting to load details of an account from a NULL item (" << item.row() << ")";
 
285
      return;
 
286
   }
 
287
 
 
288
   Account* account = AccountList::getInstance()->getAccountByModelIndex(item);
 
289
   if(! account ) {
 
290
      kDebug() << "Attempting to load details of an unexisting account";
 
291
      return;
 
292
   }
 
293
   m_IsLoading++;
 
294
 
 
295
   edit1_alias->setText( account->getAccountAlias());
 
296
 
 
297
   QString protocolsTab[] = ACCOUNT_TYPES_TAB;
 
298
   QList<QString> * protocolsList = new QList<QString>();
 
299
   for(int i = 0 ; i < (int) (sizeof(protocolsTab) / sizeof(QString)) ; i++) {
 
300
      protocolsList->append(protocolsTab[i]);
 
301
   }
 
302
 
 
303
   QString accountName = account->getAccountType();
 
304
   int protocolIndex = protocolsList->indexOf(accountName);
 
305
   delete protocolsList;
 
306
 
 
307
 
 
308
   QModelIndex idx = account->getCredentialsModel()->index(0,0);
 
309
   disconnect(edit5_password, SIGNAL(textEdited(QString)), this , SLOT(main_password_field_changed()));
 
310
   if (idx.isValid() && !account->getAccountId().isEmpty()) {
 
311
      edit5_password->setText(account->getCredentialsModel()->data(idx,CredentialModel::PASSWORD_ROLE).toString());
 
312
   }
 
313
   else
 
314
      edit5_password->setText("");
 
315
   connect(edit5_password, SIGNAL(textEdited(QString)), this , SLOT(main_password_field_changed()));
 
316
 
 
317
   disconnect(this,SLOT(aliasChanged(QString)));
 
318
   connect(account,SIGNAL(aliasChanged(QString)),this,SLOT(aliasChanged(QString)));
 
319
 
 
320
   switch (account->getTlsMethod()) {
 
321
      case 0: //KEY_EXCHANGE_NONE
 
322
         checkbox_SDES_fallback_rtp->setVisible   ( false );
 
323
         checkbox_ZRTP_Ask_user->setVisible       ( false );
 
324
         checkbox_ZRTP_display_SAS->setVisible    ( false );
 
325
         checkbox_ZRTP_warn_supported->setVisible ( false );
 
326
         checkbox_ZTRP_send_hello->setVisible     ( false );
 
327
         break;
 
328
      case 1: //ZRTP
 
329
         checkbox_SDES_fallback_rtp->setVisible   ( false );
 
330
         checkbox_ZRTP_Ask_user->setVisible       ( true  );
 
331
         checkbox_ZRTP_display_SAS->setVisible    ( true  );
 
332
         checkbox_ZRTP_warn_supported->setVisible ( true  );
 
333
         checkbox_ZTRP_send_hello->setVisible     ( true  );
 
334
         break;
 
335
      case 2: //SDES
 
336
         checkbox_SDES_fallback_rtp->setVisible   ( true  );
 
337
         checkbox_ZRTP_Ask_user->setVisible       ( false );
 
338
         checkbox_ZRTP_display_SAS->setVisible    ( false );
 
339
         checkbox_ZRTP_warn_supported->setVisible ( false );
 
340
         checkbox_ZTRP_send_hello->setVisible     ( false );
 
341
         break;
 
342
   }
 
343
 
 
344
   //         WIDGET VALUE                                          VALUE                     /
 
345
   /**/edit2_protocol->setCurrentIndex          ( (protocolIndex < 0) ? 0 : protocolIndex    );
 
346
   /**/edit3_server->setText                    (  account->getAccountHostname             ());
 
347
   /**/edit4_user->setText                      (  account->getAccountUsername             ());
 
348
   /**/edit6_mailbox->setText                   (  account->getAccountMailbox              ());
 
349
   /**/m_pProxyLE->setText                      (  account->getAccountProxy                ());
 
350
   /**/checkbox_ZRTP_Ask_user->setChecked       (  account->isAccountDisplaySasOnce        ());
 
351
   /**/checkbox_SDES_fallback_rtp->setChecked   (  account->isAccountSrtpRtpFallback       ());
 
352
   /**/checkbox_ZRTP_display_SAS->setChecked    (  account->isAccountZrtpDisplaySas        ());
 
353
   /**/checkbox_ZRTP_warn_supported->setChecked (  account->isAccountZrtpNotSuppWarning    ());
 
354
   /**/checkbox_ZTRP_send_hello->setChecked     (  account->isAccountZrtpHelloHash         ());
 
355
   /**/checkbox_stun->setChecked                (  account->isAccountSipStunEnabled        ());
 
356
   /**/line_stun->setText                       (  account->getAccountSipStunServer        ());
 
357
   /**/spinbox_regExpire->setValue              (  account->getAccountRegistrationExpire   ());
 
358
   /**/radioButton_pa_same_as_local->setChecked (  account->isPublishedSameAsLocal         ());
 
359
   /**/radioButton_pa_custom->setChecked        ( !account->isPublishedSameAsLocal         ());
 
360
   /**/lineEdit_pa_published_address->setText   (  account->getPublishedAddress            ());
 
361
   /**/spinBox_pa_published_port->setValue      (  account->getPublishedPort               ());
 
362
   /*                                                  Security                             **/
 
363
   /**/edit_tls_private_key_password->setText   (  account->getTlsPassword                 ());
 
364
   /**/spinbox_tls_listener->setValue           (  account->getTlsListenerPort             ());
 
365
   /**/file_tls_authority->setText              (  account->getTlsCaListFile               ());
 
366
   /**/file_tls_endpoint->setText               (  account->getTlsCertificateFile          ());
 
367
   /**/file_tls_private_key->setText            (  account->getTlsPrivateKeyFile           ());
 
368
   /**/edit_tls_cipher->setText                 (  account->getTlsCiphers                  ());
 
369
   /**/edit_tls_outgoing->setText               (  account->getTlsServerName               ());
 
370
   /**/spinbox_tls_timeout_sec->setValue        (  account->getTlsNegotiationTimeoutSec    ());
 
371
   /**/spinbox_tls_timeout_msec->setValue       (  account->getTlsNegotiationTimeoutMsec   ());
 
372
   /**/check_tls_incoming->setChecked           (  account->isTlsVerifyServer              ());
 
373
   /**/check_tls_answer->setChecked             (  account->isTlsVerifyClient              ());
 
374
   /**/check_tls_requier_cert->setChecked       (  account->isTlsRequireClientCertificate  ());
 
375
   /**/group_security_tls->setChecked           (  account->isTlsEnable                    ());
 
376
   /**/combo_security_STRP->setCurrentIndex     (  account->getTlsMethod                   ());
 
377
   /**/m_pAutoAnswer->setChecked                (  account->isAutoAnswer                   ());
 
378
   /*                                                                                        */
 
379
 
 
380
   m_pDTMFOverRTP->setChecked(account->getDTMFType()==DtmfType::OverRtp);
 
381
   m_pDTMFOverSIP->setChecked(account->getDTMFType()==DtmfType::OverSip);
 
382
 
 
383
   edit_credential_realm    -> setText(QString());
 
384
   edit_credential_auth     -> setText(QString());
 
385
   edit_credential_password -> setText(QString());
 
386
   edit_credential_realm    -> setEnabled(false);
 
387
   edit_credential_auth     -> setEnabled(false);
 
388
   edit_credential_password -> setEnabled(false);
 
389
   m_pProxyCK               -> setChecked(m_pProxyLE->text().size());
 
390
   m_pProxyLE               -> setEnabled(m_pProxyCK->isChecked());
 
391
 
 
392
 
 
393
   disconnect(m_pDefaultAccount, SIGNAL(clicked(bool)) , this , SLOT(changedAccountList()) );
 
394
   m_pDefaultAccount->setChecked(account == AccountList::getInstance()->getDefaultAccount());
 
395
   connect(m_pDefaultAccount,    SIGNAL(clicked(bool)) , this , SLOT(changedAccountList()) );
 
396
 
 
397
 
 
398
   disconnect(list_credential->selectionModel(),SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(selectCredential(QModelIndex,QModelIndex))     );
 
399
   list_credential->setModel(account->getCredentialsModel());
 
400
   connect(list_credential->selectionModel()   ,SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(selectCredential(QModelIndex,QModelIndex))     );
 
401
 
 
402
   disconnect(list_audiocodec->selectionModel(),SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(selectedCodecChanged(QModelIndex,QModelIndex)) );
 
403
   disconnect(list_audiocodec->model()         ,SIGNAL(dataChanged(QModelIndex,QModelIndex)),    this, SLOT(changedAccountList())                          );
 
404
   list_audiocodec->setModel(account->getAudioCodecModel());
 
405
   connect(list_audiocodec->model()            ,SIGNAL(dataChanged(QModelIndex,QModelIndex)),    this, SLOT(changedAccountList())                          );
 
406
   connect(list_audiocodec->selectionModel()   ,SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(selectedCodecChanged(QModelIndex,QModelIndex)) );
 
407
 
 
408
   #ifdef ENABLE_VIDEO
 
409
   disconnect(m_pCodecsLW->selectionModel()    ,SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(loadVidCodecDetails(QModelIndex,QModelIndex))  );
 
410
   disconnect(m_pCodecsLW->model()             ,SIGNAL(dataChanged(QModelIndex,QModelIndex)),    this, SLOT(changedAccountList())                          );
 
411
   account->getVideoCodecModel()->reload();
 
412
   m_pCodecsLW->setModel(account->getVideoCodecModel());
 
413
   connect(m_pCodecsLW->model()                ,SIGNAL(dataChanged(QModelIndex,QModelIndex)),    this, SLOT(changedAccountList())                          );
 
414
   connect(m_pCodecsLW->selectionModel()       ,SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(loadVidCodecDetails(QModelIndex,QModelIndex))  );
 
415
   #endif
 
416
 
 
417
 
 
418
   if (account->getAccountAlias() == "IP2IP") {
 
419
      frame2_editAccounts->setTabEnabled( 0, false );
 
420
      frame2_editAccounts->setTabEnabled( 1, false );
 
421
      frame2_editAccounts->setTabEnabled( 2, true  );
 
422
      frame2_editAccounts->setTabEnabled( 3, false );
 
423
      frame2_editAccounts->setTabEnabled( 4, false );
 
424
      frame2_editAccounts->setTabEnabled( 5, true  );
 
425
   }
 
426
   else {
 
427
      frame2_editAccounts->setTabEnabled( 0, true );
 
428
      frame2_editAccounts->setTabEnabled( 1, true );
 
429
      frame2_editAccounts->setTabEnabled( 3, true );
 
430
      frame2_editAccounts->setTabEnabled( 4, true );
 
431
      frame2_editAccounts->setCurrentIndex(0);
 
432
   }
 
433
 
 
434
   m_pEnableRingtoneGB->setChecked(account->isRingtoneEnabled());
 
435
   QString ringtonePath = KStandardDirs::realFilePath(account->getRingtonePath());
 
436
   m_pRingTonePath->setUrl( ringtonePath );
 
437
 
 
438
 
 
439
   combo_tls_method->setCurrentIndex( account->getTlsMethod() );
 
440
   ConfigurationManagerInterface& configurationManager = ConfigurationManagerInterfaceSingleton::getInstance();
 
441
 
 
442
   m_pRingtoneListLW->clear();
 
443
   m_hRingtonePath = configurationManager.getRingtoneList();
 
444
   QMutableMapIterator<QString, QString> iter(m_hRingtonePath);
 
445
   bool found = false;
 
446
   while (iter.hasNext()) {
 
447
      iter.next();
 
448
      QListWidgetItem*  item        = new QListWidgetItem();
 
449
      RingToneListItem* item_widget = new RingToneListItem(iter.key(),iter.value());
 
450
      m_pRingtoneListLW->addItem      ( item              );
 
451
      m_pRingtoneListLW->setItemWidget( item, item_widget );
 
452
 
 
453
      if (KStandardDirs::realFilePath(iter.key()) == ringtonePath) {
 
454
         m_pUseCustomFileCK->setChecked( false );
 
455
         m_pRingTonePath->setDisabled  ( true  );
 
456
         item->setSelected             ( true  );
 
457
         found = true;
 
458
      }
 
459
   }
 
460
   m_pRingtoneListLW->setEnabled(!m_pUseCustomFileCK->isChecked());
 
461
   if (!found && !ringtonePath.isEmpty()) {
 
462
      m_pRingtoneListLW->setDisabled(true);
 
463
      m_pUseCustomFileCK->setChecked(true);
 
464
      m_pRingTonePath->setEnabled(true);
 
465
      
 
466
      m_pRingTonePath->setUrl( ringtonePath );
 
467
   }
 
468
 
 
469
   #ifndef ENABLE_VIDEO
 
470
   m_pVideoCodecGB->setVisible(false);
 
471
   #endif
 
472
 
 
473
   comboBox_ni_local_address->clear();
 
474
   QStringList interfaceList = configurationManager.getAllIpInterfaceByName();
 
475
   comboBox_ni_local_address->addItems(interfaceList);
 
476
 
 
477
   spinBox_ni_local_port->setValue(account->getLocalPort());
 
478
   if (comboBox_ni_local_address->findText(account->getLocalInterface()) >=0)
 
479
      comboBox_ni_local_address->setCurrentIndex(comboBox_ni_local_address->findText(account->getLocalInterface()));
 
480
   else //Just to be sure
 
481
      comboBox_ni_local_address->setCurrentIndex(0);
 
482
 
 
483
   if(protocolIndex == 0 || account->isNew()) { // if sip selected
 
484
      checkbox_stun->setChecked(account->isAccountSipStunEnabled());
 
485
      line_stun->setText( account->getAccountSipStunServer() );
 
486
      //checkbox_zrtp->setChecked(account->getAccountDetail(ACCOUNT_SRTP_ENABLED) == REGISTRATION_ENABLED_TRUE);
 
487
 
 
488
      tab_advanced->                setEnabled ( true                       );
 
489
      line_stun->                   setEnabled ( checkbox_stun->isChecked() );
 
490
      radioButton_pa_same_as_local->setDisabled( checkbox_stun->isChecked() );
 
491
      radioButton_pa_custom->       setDisabled( checkbox_stun->isChecked() );
 
492
   }
 
493
   else {
 
494
      checkbox_stun->setChecked(false);
 
495
      tab_advanced->setEnabled (false);
 
496
      line_stun->setText( account->getAccountSipStunServer() );
 
497
      //checkbox_zrtp->setChecked(false);
 
498
   }
 
499
 
 
500
   updateStatusLabel(account);
 
501
   enablePublished();
 
502
   frame2_editAccounts->setEnabled(true);
 
503
   m_IsLoading--;
 
504
   account->performAction(EDIT);
 
505
   emit updateButtons();
 
506
} //loadAccount
 
507
 
 
508
///Load an account
 
509
void DlgAccounts::loadAccountList()
 
510
{
 
511
   AccountList::getInstance()->updateAccounts();
 
512
   if (listView_accountList->model()->rowCount() > 0 && !listView_accountList->currentIndex().isValid())
 
513
      listView_accountList->setCurrentIndex(listView_accountList->model()->index(0,0));
 
514
   else
 
515
      frame2_editAccounts->setEnabled(listView_accountList->currentIndex().isValid());
 
516
}
 
517
 
 
518
///Called when one of the child widget is modified
 
519
void DlgAccounts::changedAccountList()
 
520
{
 
521
   if (!m_IsLoading) {
 
522
      Account* acc = AccountList::getInstance()->getAccountByModelIndex(listView_accountList->currentIndex());
 
523
      if (acc)
 
524
         acc->performAction(MODIFY);
 
525
      accountListHasChanged = true;
 
526
      emit updateButtons();
 
527
   }
 
528
}
 
529
 
 
530
void DlgAccounts::otherAccountChanged()
 
531
{
 
532
   accountListHasChanged = true;
 
533
   if (!m_IsLoading) {
 
534
      emit updateButtons();
 
535
   }
 
536
   updateStatusLabel(listView_accountList->currentIndex());
 
537
}
 
538
 
 
539
///Callback when the account change
 
540
void DlgAccounts::accountListChanged(QModelIndex current, QModelIndex previous)
 
541
{
 
542
   saveAccount(previous);
 
543
   Account* acc = AccountList::getInstance()->getAccountByModelIndex(previous);
 
544
   if (acc->currentState() == EDITING || acc->currentState() == OUTDATED)
 
545
      acc->performAction(CANCEL);
 
546
   loadAccount(current);
 
547
   //updateAccountListCommands();
 
548
}
 
549
 
 
550
///Move account up
 
551
void DlgAccounts::on_button_accountUp_clicked()
 
552
{
 
553
   QModelIndex index = listView_accountList->currentIndex();
 
554
   Account* acc = AccountList::getInstance()->getAccountByModelIndex(index);
 
555
   AccountList::getInstance()->accountUp(index.row());
 
556
   listView_accountList->setCurrentIndex(acc->getIndex());
 
557
}
 
558
 
 
559
///Move account down
 
560
void DlgAccounts::on_button_accountDown_clicked()
 
561
{
 
562
   QModelIndex index = listView_accountList->currentIndex();
 
563
   Account* acc = AccountList::getInstance()->getAccountByModelIndex(index);
 
564
   AccountList::getInstance()->accountDown(index.row());
 
565
   listView_accountList->setCurrentIndex(acc->getIndex());
 
566
}
 
567
 
 
568
///Add new account
 
569
void DlgAccounts::on_button_accountAdd_clicked()
 
570
{
 
571
   QString newAlias = i18n("New account%1",AccountList::getSimilarAliasIndex("New account"));
 
572
   AccountList::getInstance()->addAccount(newAlias);
 
573
   int r = listView_accountList->model()->rowCount() - 1;
 
574
   QModelIndex index = listView_accountList->model()->index(r,0);
 
575
   listView_accountList->setCurrentIndex(index);
 
576
 
 
577
   frame2_editAccounts->setEnabled(true);
 
578
   edit1_alias->setSelection(0,edit1_alias->text().size());
 
579
   edit1_alias->setFocus(Qt::OtherFocusReason);
 
580
} //on_button_accountAdd_clicked
 
581
 
 
582
///Remove selected account
 
583
void DlgAccounts::on_button_accountRemove_clicked()
 
584
{
 
585
   AccountList::getInstance()->removeAccount(listView_accountList->currentIndex());
 
586
   listView_accountList->setCurrentIndex(listView_accountList->model()->index(0,0));
 
587
}
 
588
 
 
589
///Update account list
 
590
void DlgAccounts::updateAccountListCommands()
 
591
{
 
592
   bool buttonsEnabled[4] = {true,true,true,true};
 
593
   if(! listView_accountList->currentIndex().isValid()) {
 
594
      buttonsEnabled[0]   = false;
 
595
      buttonsEnabled[1]   = false;
 
596
      buttonsEnabled[3]   = false;
 
597
   }
 
598
   else if(listView_accountList->currentIndex().row() == 0) {
 
599
      buttonsEnabled[0]   = false;
 
600
   }
 
601
   if(listView_accountList->currentIndex().row() == listView_accountList->model()->rowCount() - 1) {
 
602
      buttonsEnabled[1]   = false;
 
603
   }
 
604
 
 
605
   button_accountUp->setEnabled     ( buttonsEnabled[0] );
 
606
   button_accountDown->setEnabled   ( buttonsEnabled[1] );
 
607
   button_accountAdd->setEnabled    ( buttonsEnabled[2] );
 
608
   button_accountRemove->setEnabled ( buttonsEnabled[3] );
 
609
}
 
610
 
 
611
///Password changed
 
612
void DlgAccounts::main_password_field_changed()
 
613
{
 
614
   list_credential->model()->setData(list_credential->model()->index(0,0),edit5_password->text(),CredentialModel::PASSWORD_ROLE);
 
615
   #ifdef Q_WS_WIN // MS Windows version
 
616
      if (GetKeyState(VK_CAPITAL) == 1) {
 
617
   #endif
 
618
   #ifdef Q_WS_X11 // X11 version
 
619
      unsigned int n = 0;
 
620
      Display *d = QX11Info::display();
 
621
      XkbGetIndicatorState(d, XkbUseCoreKbd, &n);
 
622
      if ((n & 0x01) == 1) {
 
623
   #else
 
624
      //# error Platform not supported
 
625
      if (false) {
 
626
   #endif
 
627
      label_message->setText("<b>"+i18n("Warning, caps lock is turned on!")+"</b>");
 
628
      label_message_icon->setPixmap(KIcon("dialog-warning").pixmap(QSize(32,32)));
 
629
   }
 
630
   else {
 
631
      label_message->setText(i18n("Fields marked with \"*\" are compulsory and required"));
 
632
      label_message_icon->setPixmap(KIcon("dialog-information").pixmap(QSize(24,24)));
 
633
   }
 
634
}
 
635
 
 
636
///Credential changed
 
637
void DlgAccounts::main_credential_password_changed()
 
638
{
 
639
   if (list_credential->currentIndex().row() == 0) {
 
640
      edit5_password->setText(edit_credential_password->text());
 
641
   }
 
642
}
 
643
 
 
644
///Update the first credential
 
645
void DlgAccounts::updateFirstCredential(QString text)
 
646
{
 
647
   if (!m_IsLoading) {
 
648
      Account* acc = AccountList::getInstance()->getAccountByModelIndex(listView_accountList->currentIndex());
 
649
      acc->getCredentialsModel()->setData(acc->getCredentialsModel()->index(0,0),text, CredentialModel::NAME_ROLE);
 
650
      if (acc->getCredentialsModel()->index(0,0) == list_credential->currentIndex()) {
 
651
         edit_credential_auth->setText(text);
 
652
      }
 
653
   }
 
654
}
 
655
 
 
656
///Move codec up
 
657
void DlgAccounts::moveAudioCodecUp()
 
658
{
 
659
   if (((AudioCodecModel*) list_audiocodec->model())->moveUp(list_audiocodec->currentIndex()))
 
660
      list_audiocodec->setCurrentIndex(list_audiocodec->model()->index(list_audiocodec->currentIndex().row()-1,0));
 
661
}
 
662
 
 
663
///Move codec down
 
664
void DlgAccounts::moveAudioCodecDown()
 
665
{
 
666
   if (((AudioCodecModel*) list_audiocodec->model())->moveDown(list_audiocodec->currentIndex()))
 
667
      list_audiocodec->setCurrentIndex(list_audiocodec->model()->index(list_audiocodec->currentIndex().row()+1,0));
 
668
}
 
669
 
 
670
///Move video codec up
 
671
void DlgAccounts::moveVideoCodecUp()
 
672
{
 
673
   if (((VideoCodecModel*) m_pCodecsLW->model())->moveUp(m_pCodecsLW->currentIndex()))
 
674
      m_pCodecsLW->setCurrentIndex(m_pCodecsLW->model()->index(m_pCodecsLW->currentIndex().row()-1,0));
 
675
}
 
676
 
 
677
///Move video codec down
 
678
void DlgAccounts::moveVideoCodecDown()
 
679
{
 
680
   if (((VideoCodecModel*) m_pCodecsLW->model())->moveDown(m_pCodecsLW->currentIndex()))
 
681
      m_pCodecsLW->setCurrentIndex(m_pCodecsLW->model()->index(m_pCodecsLW->currentIndex().row()+1,0));
 
682
}
 
683
 
 
684
///Load the video codec list
 
685
void DlgAccounts::loadVidCodecDetails(const QModelIndex& current,const QModelIndex& previous)
 
686
{
 
687
   if (previous != current && previous.isValid()) {
 
688
      m_pCodecsLW->model()->setData(previous,m_pBitrateSB->value(),VideoCodecModel::BITRATE_ROLE);
 
689
   }
 
690
   
 
691
   int bitrate = m_pCodecsLW->model()->data(current,VideoCodecModel::BITRATE_ROLE).toInt();
 
692
   m_pBitrateSB->setValue(bitrate);
 
693
}
 
694
 
 
695
///Update account state
 
696
void DlgAccounts::updateAccountStates()
 
697
{
 
698
   kDebug() << "updateAccountStates";
 
699
   for (int i = 0; i < AccountList::getInstance()->size(); i++) {
 
700
      Account* current = AccountList::getInstance()->getAccountAt(i);
 
701
      current->updateState();
 
702
   }
 
703
   updateStatusLabel(listView_accountList->currentIndex());
 
704
}
 
705
 
 
706
///Update the status label to current account state
 
707
void DlgAccounts::updateStatusLabel(QModelIndex item)
 
708
{
 
709
   kDebug() << "MODEL index is" << item.row();
 
710
   if(!item.isValid())
 
711
      return;
 
712
   Account* account = AccountList::getInstance()->getAccountByModelIndex(item);
 
713
   if (account)
 
714
      updateStatusLabel(account);
 
715
}
 
716
 
 
717
///Update the status label to current account state
 
718
void DlgAccounts::updateStatusLabel(Account* account)
 
719
{
 
720
   if(!account || AccountList::getInstance()->getAccountByModelIndex(listView_accountList->currentIndex()) != account)
 
721
      return;
 
722
   QString status = account->getAccountRegistrationStatus();
 
723
   edit7_state->setText( "<FONT COLOR=\"" + account->getStateColorName() + "\">" + status + "</FONT>" );
 
724
}
 
725
 
 
726
///Have the account changed
 
727
bool DlgAccounts::hasChanged()
 
728
{
 
729
   return accountListHasChanged;
 
730
}
 
731
 
 
732
///Have all required fields completed?
 
733
bool DlgAccounts::hasIncompleteRequiredFields()
 
734
{
 
735
   Account* acc = AccountList::getInstance()->getAccountByModelIndex(listView_accountList->currentIndex());
 
736
   return acc && (acc->getAlias() != "IP2IP") && (edit1_alias->text().isEmpty() || edit3_server->text().isEmpty() || edit4_user->text().isEmpty() || edit5_password->text().isEmpty());
 
737
}
 
738
 
 
739
///Save settings
 
740
void DlgAccounts::updateSettings()
 
741
{
 
742
   if(accountListHasChanged) {
 
743
      if(listView_accountList->currentIndex().isValid()) {
 
744
         Account* acc = AccountList::getInstance()->getAccountByModelIndex(listView_accountList->currentIndex());
 
745
//          if (acc && acc->isNew()) { //Trying to save an account without ID work, but codecs and credential will be corrupted
 
746
//             acc->performAction(AccountEditAction::SAVE);
 
747
//          }
 
748
         saveAccount(listView_accountList->currentIndex());
 
749
         if (acc->currentState() == EDITING || acc->currentState() == OUTDATED)
 
750
            acc->performAction(CANCEL);
 
751
      }
 
752
 
 
753
      AccountList::getInstance()->save();
 
754
      accountListHasChanged = false;
 
755
   }
 
756
}
 
757
 
 
758
///Reload
 
759
void DlgAccounts::updateWidgets()
 
760
{
 
761
   loadAccountList();
 
762
   //toolButton_accountsApply->setEnabled(false);
 
763
   updateStatusLabel(listView_accountList->currentIndex());
 
764
   accountListHasChanged = false;
 
765
}
 
766
 
 
767
///The audio codec changed
 
768
void DlgAccounts::selectedCodecChanged(const QModelIndex& current,const QModelIndex& previous)
 
769
{
 
770
   Q_UNUSED(previous)
 
771
   label_bitrate_value->setText   ( list_audiocodec->model()->data(current,AudioCodecModel::BITRATE_ROLE)   .toString());
 
772
   label_frequency_value->setText ( list_audiocodec->model()->data(current,AudioCodecModel::SAMPLERATE_ROLE).toString());
 
773
}
 
774
 
 
775
///Select available security options for various methods
 
776
void DlgAccounts::updateCombo(int value)
 
777
{
 
778
   Q_UNUSED(value)
 
779
   switch (combo_security_STRP->currentIndex()) {
 
780
      case 0: //KEY_EXCHANGE_NONE
 
781
         checkbox_SDES_fallback_rtp->setVisible   ( false );
 
782
         checkbox_ZRTP_Ask_user->setVisible       ( false );
 
783
         checkbox_ZRTP_display_SAS->setVisible    ( false );
 
784
         checkbox_ZRTP_warn_supported->setVisible ( false );
 
785
         checkbox_ZTRP_send_hello->setVisible     ( false );
 
786
         break;
 
787
      case 1: //ZRTP
 
788
         checkbox_SDES_fallback_rtp->setVisible   ( false );
 
789
         checkbox_ZRTP_Ask_user->setVisible       ( true  );
 
790
         checkbox_ZRTP_display_SAS->setVisible    ( true  );
 
791
         checkbox_ZRTP_warn_supported->setVisible ( true  );
 
792
         checkbox_ZTRP_send_hello->setVisible     ( true  );
 
793
         break;
 
794
      case 2: //SDES
 
795
         checkbox_SDES_fallback_rtp->setVisible   ( true  );
 
796
         checkbox_ZRTP_Ask_user->setVisible       ( false );
 
797
         checkbox_ZRTP_display_SAS->setVisible    ( false );
 
798
         checkbox_ZRTP_warn_supported->setVisible ( false );
 
799
         checkbox_ZTRP_send_hello->setVisible     ( false );
 
800
         break;
 
801
   }
 
802
} //updateCombo
 
803
 
 
804
///Save the current credential
 
805
void DlgAccounts::saveCredential()
 
806
{
 
807
   QModelIndex index = listView_accountList->currentIndex();
 
808
   Account*    acc   = AccountList::getInstance()->getAccountByModelIndex(index);
 
809
   QModelIndex currentCredential = list_credential->currentIndex();
 
810
   if (currentCredential.isValid()) {
 
811
      acc->getCredentialsModel()->setData(currentCredential,edit_credential_auth->text()    , CredentialModel::NAME_ROLE     );
 
812
      acc->getCredentialsModel()->setData(currentCredential,edit_credential_password->text(), CredentialModel::PASSWORD_ROLE );
 
813
      acc->getCredentialsModel()->setData(currentCredential,edit_credential_realm->text()   , CredentialModel::REALM_ROLE    );
 
814
   }
 
815
 
 
816
   if (acc)
 
817
      acc->saveCredentials();
 
818
} //saveCredential
 
819
 
 
820
///Add a new credential
 
821
void DlgAccounts::addCredential()
 
822
{
 
823
   QModelIndex index = listView_accountList->currentIndex();
 
824
   Account*    acc   = AccountList::getInstance()->getAccountByModelIndex(index);
 
825
 
 
826
   QModelIndex idx = acc->getCredentialsModel()->addCredentials();
 
827
   list_credential->setCurrentIndex(idx);
 
828
} //addCredential
 
829
 
 
830
///Save and load a credential
 
831
void DlgAccounts::selectCredential(QModelIndex item, QModelIndex previous)
 
832
{
 
833
   list_credential->model()->setData(previous,edit_credential_auth->text()    , CredentialModel::NAME_ROLE     );
 
834
   list_credential->model()->setData(previous,edit_credential_password->text(), CredentialModel::PASSWORD_ROLE );
 
835
   list_credential->model()->setData(previous,edit_credential_realm->text()   , CredentialModel::REALM_ROLE    );
 
836
   
 
837
   edit_credential_realm->setText       ( list_credential->model()->data(item,CredentialModel::REALM_ROLE)    .toString());
 
838
   edit_credential_auth->setText        ( list_credential->model()->data(item,CredentialModel::NAME_ROLE)     .toString());
 
839
   edit_credential_password->setText    ( list_credential->model()->data(item,CredentialModel::PASSWORD_ROLE) .toString());
 
840
   
 
841
   edit_credential_realm->setEnabled    ( true );
 
842
   edit_credential_auth->setEnabled     ( true );
 
843
   edit_credential_password->setEnabled ( true );
 
844
//TODO
 
845
} //selectCredential
 
846
 
 
847
///Remove a credential
 
848
void DlgAccounts::removeCredential() {
 
849
   Account* acc = AccountList::getInstance()->getAccountByModelIndex(listView_accountList->currentIndex());
 
850
   acc->getCredentialsModel()->removeCredentials(list_credential->currentIndex());
 
851
   list_credential->setCurrentIndex(acc->getCredentialsModel()->index(0,0));
 
852
}
 
853
 
 
854
///Enable published
 
855
void DlgAccounts::enablePublished()
 
856
{
 
857
   lineEdit_pa_published_address->setDisabled(radioButton_pa_same_as_local->isChecked());
 
858
   spinBox_pa_published_port->setDisabled(radioButton_pa_same_as_local->isChecked());
 
859
}
 
860
 
 
861
///Force a new alias for the account
 
862
void DlgAccounts::aliasChanged(QString newAlias)
 
863
{
 
864
   if (newAlias != edit1_alias->text())
 
865
      edit1_alias->setText(newAlias);
 
866
}
 
867
 
 
868
///Force a new alias for the account
 
869
void DlgAccounts::changeAlias(QString newAlias)
 
870
{
 
871
   Account* acc = AccountList::getInstance()->getAccountByModelIndex(listView_accountList->currentIndex());
 
872
   if (acc && newAlias != acc->getAccountAlias())
 
873
      AccountList::getInstance()->setData(listView_accountList->currentIndex(),newAlias,Qt::EditRole);
 
874
//       acc->setAccountAlias(newAlias);
 
875
}
 
876
 
 
877
//#include <dlgaccount.moc>