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> *
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. *
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. *
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"
22
#include <QtCore/QString>
24
#include <QtGui/QTableWidget>
25
#include <QtGui/QListWidgetItem>
26
#include <QtGui/QWidget>
29
#include <KConfigDialog>
31
#include <KStandardDirs>
32
#include <KInputDialog>
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"
45
#ifdef Q_WS_WIN // MS Windows version
49
#include <X11/XKBlib.h>
54
DlgAccounts::DlgAccounts(KConfigDialog* parent)
55
: QWidget(parent),m_IsLoading(false)
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());
71
m_pInfoIconL->setPixmap(KIcon("dialog-information").pixmap(QSize(32,32)));
72
label_message_icon->setPixmap(KIcon("dialog-information").pixmap(QSize(24,24)));
74
m_pRingTonePath->setMode(KFile::File | KFile::ExistingOnly);
75
m_pRingTonePath->lineEdit()->setObjectName("m_pRingTonePath");
76
m_pRingTonePath->lineEdit()->setReadOnly(true);
79
accountListHasChanged = false;
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*)) );
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()) );
155
connect(radioButton_pa_same_as_local, SIGNAL(clicked(bool)) , this , SLOT(enablePublished()));
156
connect(radioButton_pa_custom, SIGNAL(clicked(bool)) , this , SLOT(enablePublished()));
159
if (AccountList::getInstance()->index(0,0).isValid()) {
160
listView_accountList->setCurrentIndex(AccountList::getInstance()->index(0,0));
161
loadAccount(listView_accountList->currentIndex());
167
DlgAccounts::~DlgAccounts()
169
//accountList->disconnect();
170
//if (accountList) delete accountList;
173
///Save an account using the values from the widgets
174
void DlgAccounts::saveAccount(QModelIndex item)
176
Account* account = AccountList::getInstance()->getAccountByModelIndex(item);
178
if(!item.isValid()) {
179
kDebug() << "Attempting to save details of an account from a NULL item";
184
kDebug() << "Attempting to save details of an unexisting account : " << (item.data(Qt::DisplayRole).toString());
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";
195
if (!m_pProxyCK->isChecked()) {
196
m_pProxyLE->setText("");
199
QString protocolsTab[] = ACCOUNT_TYPES_TAB;
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() );
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() );
248
if (m_pDefaultAccount->isChecked()) {
249
ConfigurationSkeleton::setDefaultAccountId(account->getAccountId());
250
AccountList::getInstance()->setDefaultAccount(account);
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);
261
if (m_pCodecsLW->currentIndex().isValid())
262
m_pCodecsLW->model()->setData(m_pCodecsLW->currentIndex(),m_pBitrateSB->value(),VideoCodecModel::BITRATE_ROLE);
267
void DlgAccounts::cancel()
269
// Account* account = AccountList::getInstance()->getAccountByModelIndex(listView_accountList->currentIndex());
271
// account->performAction(CANCEL);
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);
280
///Load an account, set all field to the right value
281
void DlgAccounts::loadAccount(QModelIndex item)
283
if(! item.isValid() ) {
284
kDebug() << "Attempting to load details of an account from a NULL item (" << item.row() << ")";
288
Account* account = AccountList::getInstance()->getAccountByModelIndex(item);
290
kDebug() << "Attempting to load details of an unexisting account";
295
edit1_alias->setText( account->getAccountAlias());
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]);
303
QString accountName = account->getAccountType();
304
int protocolIndex = protocolsList->indexOf(accountName);
305
delete protocolsList;
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());
314
edit5_password->setText("");
315
connect(edit5_password, SIGNAL(textEdited(QString)), this , SLOT(main_password_field_changed()));
317
disconnect(this,SLOT(aliasChanged(QString)));
318
connect(account,SIGNAL(aliasChanged(QString)),this,SLOT(aliasChanged(QString)));
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 );
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 );
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 );
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 ());
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 ());
380
m_pDTMFOverRTP->setChecked(account->getDTMFType()==DtmfType::OverRtp);
381
m_pDTMFOverSIP->setChecked(account->getDTMFType()==DtmfType::OverSip);
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());
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()) );
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)) );
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)) );
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)) );
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 );
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);
434
m_pEnableRingtoneGB->setChecked(account->isRingtoneEnabled());
435
QString ringtonePath = KStandardDirs::realFilePath(account->getRingtonePath());
436
m_pRingTonePath->setUrl( ringtonePath );
439
combo_tls_method->setCurrentIndex( account->getTlsMethod() );
440
ConfigurationManagerInterface& configurationManager = ConfigurationManagerInterfaceSingleton::getInstance();
442
m_pRingtoneListLW->clear();
443
m_hRingtonePath = configurationManager.getRingtoneList();
444
QMutableMapIterator<QString, QString> iter(m_hRingtonePath);
446
while (iter.hasNext()) {
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 );
453
if (KStandardDirs::realFilePath(iter.key()) == ringtonePath) {
454
m_pUseCustomFileCK->setChecked( false );
455
m_pRingTonePath->setDisabled ( true );
456
item->setSelected ( true );
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);
466
m_pRingTonePath->setUrl( ringtonePath );
470
m_pVideoCodecGB->setVisible(false);
473
comboBox_ni_local_address->clear();
474
QStringList interfaceList = configurationManager.getAllIpInterfaceByName();
475
comboBox_ni_local_address->addItems(interfaceList);
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);
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);
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() );
494
checkbox_stun->setChecked(false);
495
tab_advanced->setEnabled (false);
496
line_stun->setText( account->getAccountSipStunServer() );
497
//checkbox_zrtp->setChecked(false);
500
updateStatusLabel(account);
502
frame2_editAccounts->setEnabled(true);
504
account->performAction(EDIT);
505
emit updateButtons();
509
void DlgAccounts::loadAccountList()
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));
515
frame2_editAccounts->setEnabled(listView_accountList->currentIndex().isValid());
518
///Called when one of the child widget is modified
519
void DlgAccounts::changedAccountList()
522
Account* acc = AccountList::getInstance()->getAccountByModelIndex(listView_accountList->currentIndex());
524
acc->performAction(MODIFY);
525
accountListHasChanged = true;
526
emit updateButtons();
530
void DlgAccounts::otherAccountChanged()
532
accountListHasChanged = true;
534
emit updateButtons();
536
updateStatusLabel(listView_accountList->currentIndex());
539
///Callback when the account change
540
void DlgAccounts::accountListChanged(QModelIndex current, QModelIndex previous)
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();
551
void DlgAccounts::on_button_accountUp_clicked()
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());
560
void DlgAccounts::on_button_accountDown_clicked()
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());
569
void DlgAccounts::on_button_accountAdd_clicked()
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);
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
582
///Remove selected account
583
void DlgAccounts::on_button_accountRemove_clicked()
585
AccountList::getInstance()->removeAccount(listView_accountList->currentIndex());
586
listView_accountList->setCurrentIndex(listView_accountList->model()->index(0,0));
589
///Update account list
590
void DlgAccounts::updateAccountListCommands()
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;
598
else if(listView_accountList->currentIndex().row() == 0) {
599
buttonsEnabled[0] = false;
601
if(listView_accountList->currentIndex().row() == listView_accountList->model()->rowCount() - 1) {
602
buttonsEnabled[1] = false;
605
button_accountUp->setEnabled ( buttonsEnabled[0] );
606
button_accountDown->setEnabled ( buttonsEnabled[1] );
607
button_accountAdd->setEnabled ( buttonsEnabled[2] );
608
button_accountRemove->setEnabled ( buttonsEnabled[3] );
612
void DlgAccounts::main_password_field_changed()
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) {
618
#ifdef Q_WS_X11 // X11 version
620
Display *d = QX11Info::display();
621
XkbGetIndicatorState(d, XkbUseCoreKbd, &n);
622
if ((n & 0x01) == 1) {
624
//# error Platform not supported
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)));
631
label_message->setText(i18n("Fields marked with \"*\" are compulsory and required"));
632
label_message_icon->setPixmap(KIcon("dialog-information").pixmap(QSize(24,24)));
636
///Credential changed
637
void DlgAccounts::main_credential_password_changed()
639
if (list_credential->currentIndex().row() == 0) {
640
edit5_password->setText(edit_credential_password->text());
644
///Update the first credential
645
void DlgAccounts::updateFirstCredential(QString text)
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);
657
void DlgAccounts::moveAudioCodecUp()
659
if (((AudioCodecModel*) list_audiocodec->model())->moveUp(list_audiocodec->currentIndex()))
660
list_audiocodec->setCurrentIndex(list_audiocodec->model()->index(list_audiocodec->currentIndex().row()-1,0));
664
void DlgAccounts::moveAudioCodecDown()
666
if (((AudioCodecModel*) list_audiocodec->model())->moveDown(list_audiocodec->currentIndex()))
667
list_audiocodec->setCurrentIndex(list_audiocodec->model()->index(list_audiocodec->currentIndex().row()+1,0));
670
///Move video codec up
671
void DlgAccounts::moveVideoCodecUp()
673
if (((VideoCodecModel*) m_pCodecsLW->model())->moveUp(m_pCodecsLW->currentIndex()))
674
m_pCodecsLW->setCurrentIndex(m_pCodecsLW->model()->index(m_pCodecsLW->currentIndex().row()-1,0));
677
///Move video codec down
678
void DlgAccounts::moveVideoCodecDown()
680
if (((VideoCodecModel*) m_pCodecsLW->model())->moveDown(m_pCodecsLW->currentIndex()))
681
m_pCodecsLW->setCurrentIndex(m_pCodecsLW->model()->index(m_pCodecsLW->currentIndex().row()+1,0));
684
///Load the video codec list
685
void DlgAccounts::loadVidCodecDetails(const QModelIndex& current,const QModelIndex& previous)
687
if (previous != current && previous.isValid()) {
688
m_pCodecsLW->model()->setData(previous,m_pBitrateSB->value(),VideoCodecModel::BITRATE_ROLE);
691
int bitrate = m_pCodecsLW->model()->data(current,VideoCodecModel::BITRATE_ROLE).toInt();
692
m_pBitrateSB->setValue(bitrate);
695
///Update account state
696
void DlgAccounts::updateAccountStates()
698
kDebug() << "updateAccountStates";
699
for (int i = 0; i < AccountList::getInstance()->size(); i++) {
700
Account* current = AccountList::getInstance()->getAccountAt(i);
701
current->updateState();
703
updateStatusLabel(listView_accountList->currentIndex());
706
///Update the status label to current account state
707
void DlgAccounts::updateStatusLabel(QModelIndex item)
709
kDebug() << "MODEL index is" << item.row();
712
Account* account = AccountList::getInstance()->getAccountByModelIndex(item);
714
updateStatusLabel(account);
717
///Update the status label to current account state
718
void DlgAccounts::updateStatusLabel(Account* account)
720
if(!account || AccountList::getInstance()->getAccountByModelIndex(listView_accountList->currentIndex()) != account)
722
QString status = account->getAccountRegistrationStatus();
723
edit7_state->setText( "<FONT COLOR=\"" + account->getStateColorName() + "\">" + status + "</FONT>" );
726
///Have the account changed
727
bool DlgAccounts::hasChanged()
729
return accountListHasChanged;
732
///Have all required fields completed?
733
bool DlgAccounts::hasIncompleteRequiredFields()
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());
740
void DlgAccounts::updateSettings()
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);
748
saveAccount(listView_accountList->currentIndex());
749
if (acc->currentState() == EDITING || acc->currentState() == OUTDATED)
750
acc->performAction(CANCEL);
753
AccountList::getInstance()->save();
754
accountListHasChanged = false;
759
void DlgAccounts::updateWidgets()
762
//toolButton_accountsApply->setEnabled(false);
763
updateStatusLabel(listView_accountList->currentIndex());
764
accountListHasChanged = false;
767
///The audio codec changed
768
void DlgAccounts::selectedCodecChanged(const QModelIndex& current,const QModelIndex& 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());
775
///Select available security options for various methods
776
void DlgAccounts::updateCombo(int 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 );
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 );
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 );
804
///Save the current credential
805
void DlgAccounts::saveCredential()
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 );
817
acc->saveCredentials();
820
///Add a new credential
821
void DlgAccounts::addCredential()
823
QModelIndex index = listView_accountList->currentIndex();
824
Account* acc = AccountList::getInstance()->getAccountByModelIndex(index);
826
QModelIndex idx = acc->getCredentialsModel()->addCredentials();
827
list_credential->setCurrentIndex(idx);
830
///Save and load a credential
831
void DlgAccounts::selectCredential(QModelIndex item, QModelIndex previous)
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 );
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());
841
edit_credential_realm->setEnabled ( true );
842
edit_credential_auth->setEnabled ( true );
843
edit_credential_password->setEnabled ( true );
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));
855
void DlgAccounts::enablePublished()
857
lineEdit_pa_published_address->setDisabled(radioButton_pa_same_as_local->isChecked());
858
spinBox_pa_published_port->setDisabled(radioButton_pa_same_as_local->isChecked());
861
///Force a new alias for the account
862
void DlgAccounts::aliasChanged(QString newAlias)
864
if (newAlias != edit1_alias->text())
865
edit1_alias->setText(newAlias);
868
///Force a new alias for the account
869
void DlgAccounts::changeAlias(QString newAlias)
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);
877
//#include <dlgaccount.moc>