From ab83223e1b5c7d34855d091e0c868462bd9452d1 Mon Sep 17 00:00:00 2001 From: Lubos Dolezel Date: Tue, 2 Jun 2015 19:32:25 +0200 Subject: Twinkle now compiles with Qt4 uic, but crashes at runtime (due to GUI calls from outside the main thread) --- src/gui/CMakeLists.txt | 48 +- src/gui/addresscardform.cpp | 96 + src/gui/addresscardform.h | 24 + src/gui/addresscardform.ui.h | 73 - src/gui/authenticationform.cpp | 68 + src/gui/authenticationform.h | 21 + src/gui/authenticationform.ui | 2 +- src/gui/authenticationform.ui.h | 44 - src/gui/buddyform.cpp | 180 ++ src/gui/buddyform.h | 41 + src/gui/buddyform.ui | 2 +- src/gui/buddyform.ui.h | 153 -- src/gui/buddylistview.cpp | 18 +- src/gui/diamondcardprofileform.cpp | 184 ++ src/gui/diamondcardprofileform.h | 46 + src/gui/diamondcardprofileform.ui.h | 154 -- src/gui/freedesksystray.cpp | 154 -- src/gui/freedesksystray.h | 95 - src/gui/getaddressform.cpp | 266 ++ src/gui/getaddressform.h | 35 + src/gui/getaddressform.ui.h | 259 -- src/gui/gui.cpp | 25 +- src/gui/gui.h | 6 +- src/gui/historyform.cpp | 393 +++ src/gui/historyform.h | 45 + src/gui/historyform.ui.h | 362 --- src/gui/historylistview.cpp | 8 +- src/gui/inviteform.cpp | 167 ++ src/gui/inviteform.h | 39 + src/gui/inviteform.ui.h | 155 -- src/gui/messageform.cpp | 657 +++++ src/gui/messageform.h | 75 + src/gui/messageform.ui | 4 +- src/gui/messageform.ui.h | 623 ----- src/gui/messageformview.h | 4 +- src/gui/mphoneform.cpp | 3161 ++++++++++++++++++++++++ src/gui/mphoneform.h | 206 ++ src/gui/mphoneform.ui | 4587 +++++++++++++++++++---------------- src/gui/mphoneform.ui.h | 3131 ------------------------ src/gui/redirectform.cpp | 177 ++ src/gui/redirectform.h | 58 + src/gui/redirectform.ui | 6 +- src/gui/redirectform.ui.h | 159 -- src/gui/selectnicform.cpp | 120 + src/gui/selectnicform.h | 30 + src/gui/selectnicform.ui | 2 +- src/gui/selectnicform.ui.h | 91 - src/gui/selectprofileform.cpp | 675 ++++++ src/gui/selectprofileform.h | 61 + src/gui/selectprofileform.ui.h | 633 ----- src/gui/selectuserform.cpp | 166 ++ src/gui/selectuserform.h | 39 + src/gui/selectuserform.ui.h | 138 -- src/gui/sendfileform.cpp | 133 + src/gui/sendfileform.h | 33 + src/gui/sendfileform.ui | 2 +- src/gui/sendfileform.ui.h | 106 - src/gui/srvredirectform.cpp | 423 ++++ src/gui/srvredirectform.h | 63 + src/gui/srvredirectform.ui | 18 +- src/gui/srvredirectform.ui.h | 391 --- src/gui/syssettingsform.cpp | 528 ++++ src/gui/syssettingsform.h | 53 + src/gui/syssettingsform.ui | 16 +- src/gui/syssettingsform.ui.h | 491 ---- src/gui/termcapform.cpp | 135 ++ src/gui/termcapform.h | 40 + src/gui/termcapform.ui | 2 +- src/gui/termcapform.ui.h | 101 - src/gui/transferform.cpp | 229 ++ src/gui/transferform.h | 52 + src/gui/transferform.ui | 2 +- src/gui/transferform.ui.h | 198 -- src/gui/twinklesystray.cpp | 38 - src/gui/twinklesystray.h | 47 - src/gui/userprofileform.cpp | 1507 ++++++++++++ src/gui/userprofileform.h | 79 + src/gui/userprofileform.ui | 58 +- src/gui/userprofileform.ui.h | 1461 ----------- src/gui/wizardform.cpp | 297 +++ src/gui/wizardform.h | 44 + src/gui/wizardform.ui.h | 265 -- 82 files changed, 13254 insertions(+), 11524 deletions(-) create mode 100644 src/gui/addresscardform.cpp create mode 100644 src/gui/addresscardform.h delete mode 100644 src/gui/addresscardform.ui.h create mode 100644 src/gui/authenticationform.cpp create mode 100644 src/gui/authenticationform.h delete mode 100644 src/gui/authenticationform.ui.h create mode 100644 src/gui/buddyform.cpp create mode 100644 src/gui/buddyform.h delete mode 100644 src/gui/buddyform.ui.h create mode 100644 src/gui/diamondcardprofileform.cpp create mode 100644 src/gui/diamondcardprofileform.h delete mode 100644 src/gui/diamondcardprofileform.ui.h delete mode 100644 src/gui/freedesksystray.cpp delete mode 100644 src/gui/freedesksystray.h create mode 100644 src/gui/getaddressform.cpp create mode 100644 src/gui/getaddressform.h delete mode 100644 src/gui/getaddressform.ui.h create mode 100644 src/gui/historyform.cpp create mode 100644 src/gui/historyform.h delete mode 100644 src/gui/historyform.ui.h create mode 100644 src/gui/inviteform.cpp create mode 100644 src/gui/inviteform.h delete mode 100644 src/gui/inviteform.ui.h create mode 100644 src/gui/messageform.cpp create mode 100644 src/gui/messageform.h delete mode 100644 src/gui/messageform.ui.h create mode 100644 src/gui/mphoneform.cpp create mode 100644 src/gui/mphoneform.h delete mode 100644 src/gui/mphoneform.ui.h create mode 100644 src/gui/redirectform.cpp create mode 100644 src/gui/redirectform.h delete mode 100644 src/gui/redirectform.ui.h create mode 100644 src/gui/selectnicform.cpp create mode 100644 src/gui/selectnicform.h delete mode 100644 src/gui/selectnicform.ui.h create mode 100644 src/gui/selectprofileform.cpp create mode 100644 src/gui/selectprofileform.h delete mode 100644 src/gui/selectprofileform.ui.h create mode 100644 src/gui/selectuserform.cpp create mode 100644 src/gui/selectuserform.h delete mode 100644 src/gui/selectuserform.ui.h create mode 100644 src/gui/sendfileform.cpp create mode 100644 src/gui/sendfileform.h delete mode 100644 src/gui/sendfileform.ui.h create mode 100644 src/gui/srvredirectform.cpp create mode 100644 src/gui/srvredirectform.h delete mode 100644 src/gui/srvredirectform.ui.h create mode 100644 src/gui/syssettingsform.cpp create mode 100644 src/gui/syssettingsform.h delete mode 100644 src/gui/syssettingsform.ui.h create mode 100644 src/gui/termcapform.cpp create mode 100644 src/gui/termcapform.h delete mode 100644 src/gui/termcapform.ui.h create mode 100644 src/gui/transferform.cpp create mode 100644 src/gui/transferform.h delete mode 100644 src/gui/transferform.ui.h delete mode 100644 src/gui/twinklesystray.cpp delete mode 100644 src/gui/twinklesystray.h create mode 100644 src/gui/userprofileform.cpp create mode 100644 src/gui/userprofileform.h delete mode 100644 src/gui/userprofileform.ui.h create mode 100644 src/gui/wizardform.cpp create mode 100644 src/gui/wizardform.h delete mode 100644 src/gui/wizardform.ui.h (limited to 'src/gui') diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 16d1c3a..5879488 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -43,8 +43,6 @@ qt4_wrap_cpp(twinkle_MOC numberconversionform.h getprofilenameform.h historylistview.h - freedesksystray.h - twinklesystray.h address_finder.h qt_translator.h core_strings.h @@ -55,15 +53,56 @@ qt4_wrap_cpp(twinkle_MOC buddylistview.h textbrowsernoautolink.h twinkleapplication.h + + mphoneform.h + inviteform.h + getaddressform.h + termcapform.h + redirectform.h + messageform.h + srvredirectform.h + userprofileform.h + transferform.h + syssettingsform.h + historyform.h + selectuserform.h + selectprofileform.h + buddyform.h + diamondcardprofileform.h + addresscardform.h + authenticationform.h + selectnicform.h + sendfileform.h + wizardform.h ) set(TWINKLE_GUI-SRCS + mphoneform.cpp + inviteform.cpp + getaddressform.cpp + redirectform.cpp + termcapform.cpp + messageform.cpp + srvredirectform.cpp + userprofileform.cpp + transferform.cpp + syssettingsform.cpp + historyform.cpp + selectuserform.cpp + selectprofileform.cpp + buddyform.cpp + diamondcardprofileform.cpp + addresscardform.cpp + authenticationform.cpp + selectnicform.cpp + sendfileform.cpp + wizardform.cpp + address_finder.cpp addresslistviewitem.cpp buddylistview.cpp deregisterform.cpp dtmfform.cpp - freedesksystray.cpp getprofilenameform.cpp gui.cpp historylistview.cpp @@ -72,7 +111,6 @@ set(TWINKLE_GUI-SRCS messageformview.cpp numberconversionform.cpp twinkleapplication.cpp - twinklesystray.cpp yesnodialog.cpp $ @@ -98,6 +136,6 @@ add_executable(twinkle ${TWINKLE_GUI-SRCS}) target_link_libraries(twinkle -lpthread -lresolv ${LibMagic_LIBRARY} ${LIBXML2_LIBRARIES} ${Readline_LIBRARY} ${ILBC_LIBRARIES} ${SPEEX_LIBRARIES} ${ZRTPCPP_LIBRARIES} ${CCRTP_LIBRARIES} ${COMMONCPP_LIBRARIES} ${UCOMMON_LIBRARIES} ${LIBSNDFILE_LIBRARY} - ${Boost_LIBRARIES} ${QT_LIBRARIES}) + ${Boost_LIBRARIES} Qt4::QtGui Qt4::Qt3Support) install(TARGETS twinkle DESTINATION bin) diff --git a/src/gui/addresscardform.cpp b/src/gui/addresscardform.cpp new file mode 100644 index 0000000..6dcae68 --- /dev/null +++ b/src/gui/addresscardform.cpp @@ -0,0 +1,96 @@ +/* + Copyright (C) 2005-2009 Michel de Boer + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "gui.h" +#include "addresscardform.h" + +/* + * Constructs a AddressCardForm as a child of 'parent', with the + * name 'name' and widget flags set to 'f'. + * + * The dialog will by default be modeless, unless you set 'modal' to + * true to construct a modal dialog. + */ +AddressCardForm::AddressCardForm(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl) + : QDialog(parent, name, modal, fl) +{ + setupUi(this); + +} + +/* + * Destroys the object and frees any allocated resources + */ +AddressCardForm::~AddressCardForm() +{ + // no need to delete child widgets, Qt does it all for us +} + +/* + * Sets the strings of the subwidgets using the current + * language. + */ +void AddressCardForm::languageChange() +{ + retranslateUi(this); +} + + +int AddressCardForm::exec(t_address_card &card) { + firstNameLineEdit->setText(card.name_first.c_str()); + infixNameLineEdit->setText(card.name_infix.c_str()); + lastNameLineEdit->setText(card.name_last.c_str()); + phoneLineEdit->setText(card.sip_address.c_str()); + remarkLineEdit->setText(card.remark.c_str()); + + int retval = QDialog::exec(); + + if (retval == QDialog::Accepted) { + card.name_first = firstNameLineEdit->text().stripWhiteSpace().ascii(); + card.name_infix = infixNameLineEdit->text().stripWhiteSpace().ascii(); + card.name_last = lastNameLineEdit->text().stripWhiteSpace().ascii(); + card.sip_address = phoneLineEdit->text().stripWhiteSpace().ascii(); + card.remark = remarkLineEdit->text().stripWhiteSpace().ascii(); + } + + return retval; +} + +void AddressCardForm::validate() +{ + QString firstName = firstNameLineEdit->text().stripWhiteSpace(); + QString infixName = infixNameLineEdit->text().stripWhiteSpace(); + QString lastName = lastNameLineEdit->text().stripWhiteSpace(); + QString phone = phoneLineEdit->text().stripWhiteSpace(); + + if (firstName.isEmpty() && infixName.isEmpty() && lastName.isEmpty()) { + ((t_gui *)ui)->cb_show_msg(this, + tr("You must fill in a name.").ascii(), MSG_CRITICAL); + firstNameLineEdit->setFocus(); + return; + } + + if (phone.isEmpty()) { + ((t_gui *)ui)->cb_show_msg(this, + tr("You must fill in a phone number or SIP address.").ascii(), MSG_CRITICAL); + phoneLineEdit->setFocus(); + return; + } + + accept(); +} diff --git a/src/gui/addresscardform.h b/src/gui/addresscardform.h new file mode 100644 index 0000000..391219c --- /dev/null +++ b/src/gui/addresscardform.h @@ -0,0 +1,24 @@ +#ifndef ADDRESSCARDFORM_H +#define ADDRESSCARDFORM_H +#include "address_book.h" +#include "ui_addresscardform.h" + +class AddressCardForm : public QDialog, public Ui::AddressCardForm +{ + Q_OBJECT + +public: + AddressCardForm(QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WindowFlags fl = 0); + ~AddressCardForm(); + + virtual int exec( t_address_card & card ); + +public slots: + virtual void validate(); + +protected slots: + virtual void languageChange(); + +}; + +#endif diff --git a/src/gui/addresscardform.ui.h b/src/gui/addresscardform.ui.h deleted file mode 100644 index f6ff3f6..0000000 --- a/src/gui/addresscardform.ui.h +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** ui.h extension file, included from the uic-generated form implementation. -** -** If you want to add, delete, or rename functions or slots, use -** Qt Designer to update this file, preserving your code. -** -** You should not define a constructor or destructor in this file. -** Instead, write your code in functions called init() and destroy(). -** These will automatically be called by the form's constructor and -** destructor. -*****************************************************************************/ - -/* - Copyright (C) 2005-2009 Michel de Boer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -int AddressCardForm::exec(t_address_card &card) { - firstNameLineEdit->setText(card.name_first.c_str()); - infixNameLineEdit->setText(card.name_infix.c_str()); - lastNameLineEdit->setText(card.name_last.c_str()); - phoneLineEdit->setText(card.sip_address.c_str()); - remarkLineEdit->setText(card.remark.c_str()); - - int retval = QDialog::exec(); - - if (retval == QDialog::Accepted) { - card.name_first = firstNameLineEdit->text().stripWhiteSpace().ascii(); - card.name_infix = infixNameLineEdit->text().stripWhiteSpace().ascii(); - card.name_last = lastNameLineEdit->text().stripWhiteSpace().ascii(); - card.sip_address = phoneLineEdit->text().stripWhiteSpace().ascii(); - card.remark = remarkLineEdit->text().stripWhiteSpace().ascii(); - } - - return retval; -} - -void AddressCardForm::validate() -{ - QString firstName = firstNameLineEdit->text().stripWhiteSpace(); - QString infixName = infixNameLineEdit->text().stripWhiteSpace(); - QString lastName = lastNameLineEdit->text().stripWhiteSpace(); - QString phone = phoneLineEdit->text().stripWhiteSpace(); - - if (firstName.isEmpty() && infixName.isEmpty() && lastName.isEmpty()) { - ((t_gui *)ui)->cb_show_msg(this, - tr("You must fill in a name.").ascii(), MSG_CRITICAL); - firstNameLineEdit->setFocus(); - return; - } - - if (phone.isEmpty()) { - ((t_gui *)ui)->cb_show_msg(this, - tr("You must fill in a phone number or SIP address.").ascii(), MSG_CRITICAL); - phoneLineEdit->setFocus(); - return; - } - - accept(); -} diff --git a/src/gui/authenticationform.cpp b/src/gui/authenticationform.cpp new file mode 100644 index 0000000..df34a6e --- /dev/null +++ b/src/gui/authenticationform.cpp @@ -0,0 +1,68 @@ +/* + Copyright (C) 2005-2009 Michel de Boer + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "authenticationform.h" +/* + * Constructs a AuthenticationForm as a child of 'parent', with the + * name 'name' and widget flags set to 'f'. + * + * The dialog will by default be modeless, unless you set 'modal' to + * true to construct a modal dialog. + */ +AuthenticationForm::AuthenticationForm(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl) + : QDialog(parent, name, modal, fl) +{ + setupUi(this); + +} + +/* + * Destroys the object and frees any allocated resources + */ +AuthenticationForm::~AuthenticationForm() +{ + // no need to delete child widgets, Qt does it all for us +} + +/* + * Sets the strings of the subwidgets using the current + * language. + */ +void AuthenticationForm::languageChange() +{ + retranslateUi(this); +} + + +int AuthenticationForm::exec(t_user *user_config, const QString &realm, QString &username, + QString &password) +{ + int retval; + + profileValueTextLabel->setText(user_config->get_profile_name().c_str()); + userValueTextLabel->setText(user_config->get_display_uri().c_str()); + realmTextLabel->setText(realm); + usernameLineEdit->setText(username); + passwordLineEdit->setText(password); + if (!username.isEmpty()) passwordLineEdit->setFocus(); + retval = QDialog::exec(); + username = usernameLineEdit->text(); + password = passwordLineEdit->text(); + + return retval; +} diff --git a/src/gui/authenticationform.h b/src/gui/authenticationform.h new file mode 100644 index 0000000..70b4a93 --- /dev/null +++ b/src/gui/authenticationform.h @@ -0,0 +1,21 @@ +#ifndef AUTHENTICATIONFORM_H +#define AUTHENTICATIONFORM_H +#include "user.h" +#include "ui_authenticationform.h" + +class AuthenticationForm : public QDialog, public Ui::AuthenticationForm +{ + Q_OBJECT + +public: + AuthenticationForm(QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WindowFlags fl = 0); + ~AuthenticationForm(); + + virtual int exec( t_user * user_config, const QString & realm, QString & username, QString & password ); + +protected slots: + virtual void languageChange(); + +}; + +#endif diff --git a/src/gui/authenticationform.ui b/src/gui/authenticationform.ui index 1fdfffc..dde4191 100644 --- a/src/gui/authenticationform.ui +++ b/src/gui/authenticationform.ui @@ -25,7 +25,7 @@ - password.png + :/icons/images/password.png false diff --git a/src/gui/authenticationform.ui.h b/src/gui/authenticationform.ui.h deleted file mode 100644 index a2e0905..0000000 --- a/src/gui/authenticationform.ui.h +++ /dev/null @@ -1,44 +0,0 @@ -/**************************************************************************** -** ui.h extension file, included from the uic-generated form implementation. -** -** If you wish to add, delete or rename functions or slots use -** Qt Designer which will update this file, preserving your code. Create an -** init() function in place of a constructor, and a destroy() function in -** place of a destructor. -*****************************************************************************/ -/* - Copyright (C) 2005-2009 Michel de Boer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - - -int AuthenticationForm::exec(t_user *user_config, const QString &realm, QString &username, - QString &password) -{ - int retval; - - profileValueTextLabel->setText(user_config->get_profile_name().c_str()); - userValueTextLabel->setText(user_config->get_display_uri().c_str()); - realmTextLabel->setText(realm); - usernameLineEdit->setText(username); - passwordLineEdit->setText(password); - if (!username.isEmpty()) passwordLineEdit->setFocus(); - retval = QDialog::exec(); - username = usernameLineEdit->text(); - password = passwordLineEdit->text(); - - return retval; -} diff --git a/src/gui/buddyform.cpp b/src/gui/buddyform.cpp new file mode 100644 index 0000000..a8ae059 --- /dev/null +++ b/src/gui/buddyform.cpp @@ -0,0 +1,180 @@ +/* + Copyright (C) 2005-2009 Michel de Boer + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "gui.h" +#include "sockets/url.h" +#include "buddylistview.h" +#include "audits/memman.h" +#include "buddyform.h" +/* + * Constructs a BuddyForm as a child of 'parent', with the + * name 'name' and widget flags set to 'f'. + * + * The dialog will by default be modeless, unless you set 'modal' to + * true to construct a modal dialog. + */ +BuddyForm::BuddyForm(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl) + : QDialog(parent, name, modal, fl) +{ + setupUi(this); + + init(); +} + +/* + * Destroys the object and frees any allocated resources + */ +BuddyForm::~BuddyForm() +{ + destroy(); + // no need to delete child widgets, Qt does it all for us +} + +/* + * Sets the strings of the subwidgets using the current + * language. + */ +void BuddyForm::languageChange() +{ + retranslateUi(this); +} + + +void BuddyForm::init() +{ + getAddressForm = 0; +} + +void BuddyForm::destroy() +{ + if (getAddressForm) { + MEMMAN_DELETE(getAddressForm); + delete getAddressForm; + } +} + +void BuddyForm::showNew(t_buddy_list &_buddy_list, Q3ListViewItem *_profileItem) +{ + user_config = _buddy_list.get_user_profile(); + edit_mode = false; + buddy_list = &_buddy_list; + profileItem = _profileItem; + + QDialog::show(); +} + +void BuddyForm::showEdit(t_buddy &buddy) +{ + user_config = buddy.get_user_profile(); + edit_mode = true; + edit_buddy = &buddy; + buddy_list = edit_buddy->get_buddy_list(); + + nameLineEdit->setText(buddy.get_name().c_str()); + phoneLineEdit->setText(buddy.get_sip_address().c_str()); + subscribeCheckBox->setChecked(buddy.get_may_subscribe_presence()); + + phoneLineEdit->setEnabled(false); + phoneTextLabel->setEnabled(false); + addressToolButton->hide(); + + QDialog::show(); +} + +void BuddyForm::validate() +{ + QString name = nameLineEdit->text().stripWhiteSpace(); + QString address = phoneLineEdit->text().stripWhiteSpace(); + + if (name.isEmpty()) { + ((t_gui *)ui)->cb_show_msg(this, + tr("You must fill in a name.").ascii(), MSG_CRITICAL); + nameLineEdit->setFocus(); + return; + } + + string dest = ui->expand_destination(user_config, address.ascii()); + t_url dest_url(dest); + if (!dest_url.is_valid()) { + ((t_gui *)ui)->cb_show_msg(this, + tr("Invalid phone.").ascii(), MSG_CRITICAL); + phoneLineEdit->setFocus(); + return; + } + + if (edit_mode) { + // Edit existing buddy + bool must_subscribe = false; + bool must_unsubscribe = false; + + if (edit_buddy->get_may_subscribe_presence() != subscribeCheckBox->isChecked()) + { + if (subscribeCheckBox->isChecked()) { + must_subscribe = true;; + } else { + must_unsubscribe = true; + } + } + + edit_buddy->set_name(nameLineEdit->text().stripWhiteSpace().ascii()); + edit_buddy->set_sip_address(phoneLineEdit->text().stripWhiteSpace().ascii()); + edit_buddy->set_may_subscribe_presence(subscribeCheckBox->isChecked()); + + if (must_subscribe) edit_buddy->subscribe_presence(); + if (must_unsubscribe) edit_buddy->unsubscribe_presence(); + } else { + // Add a new buddy + t_buddy buddy; + buddy.set_name(nameLineEdit->text().stripWhiteSpace().ascii()); + buddy.set_sip_address(phoneLineEdit->text().stripWhiteSpace().ascii()); + buddy.set_may_subscribe_presence(subscribeCheckBox->isChecked()); + + t_buddy *new_buddy = buddy_list->add_buddy(buddy); + new BuddyListViewItem(profileItem, new_buddy); + new_buddy->subscribe_presence(); + } + + string err_msg; + if (!buddy_list->save(err_msg)) { + QString msg = tr("Failed to save buddy list: %1").arg(err_msg.c_str()); + ((t_gui *)ui)->cb_show_msg(this, msg.ascii(), MSG_CRITICAL); + } + + accept(); +} + +void BuddyForm::showAddressBook() +{ + if (!getAddressForm) { + getAddressForm = new GetAddressForm( + this, "select address", true); + MEMMAN_NEW(getAddressForm); + } + + connect(getAddressForm, + SIGNAL(address(const QString &, const QString &)), + this, SLOT(selectedAddress(const QString &, const QString &))); + + getAddressForm->show(); +} + +void BuddyForm::selectedAddress(const QString &name, const QString &phone) +{ + nameLineEdit->setText(name); + phoneLineEdit->setText(phone); +} diff --git a/src/gui/buddyform.h b/src/gui/buddyform.h new file mode 100644 index 0000000..0df335f --- /dev/null +++ b/src/gui/buddyform.h @@ -0,0 +1,41 @@ +#ifndef BUDDYFORM_H +#define BUDDYFORM_H +#include "getaddressform.h" +#include "presence/buddy.h" +#include +#include "user.h" +#include "ui_buddyform.h" + +class BuddyForm : public QDialog, public Ui::BuddyForm +{ + Q_OBJECT + +public: + BuddyForm(QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WindowFlags fl = 0); + ~BuddyForm(); + +public slots: + virtual void showNew( t_buddy_list & _buddy_list, Q3ListViewItem * _profileItem ); + virtual void showEdit( t_buddy & buddy ); + virtual void validate(); + virtual void showAddressBook(); + virtual void selectedAddress( const QString & name, const QString & phone ); + +protected slots: + virtual void languageChange(); + +private: + GetAddressForm *getAddressForm; + t_user *user_config; + bool edit_mode; + t_buddy_list *buddy_list; + t_buddy *edit_buddy; + Q3ListViewItem *profileItem; + + void init(); + void destroy(); + +}; + + +#endif diff --git a/src/gui/buddyform.ui b/src/gui/buddyform.ui index 27e596d..5ad5bff 100644 --- a/src/gui/buddyform.ui +++ b/src/gui/buddyform.ui @@ -44,7 +44,7 @@ - kontact_contacts.png + :/icons/images/kontact_contacts.png Address book diff --git a/src/gui/buddyform.ui.h b/src/gui/buddyform.ui.h deleted file mode 100644 index 5326302..0000000 --- a/src/gui/buddyform.ui.h +++ /dev/null @@ -1,153 +0,0 @@ -/**************************************************************************** -** ui.h extension file, included from the uic-generated form implementation. -** -** If you want to add, delete, or rename functions or slots, use -** Qt Designer to update this file, preserving your code. -** -** You should not define a constructor or destructor in this file. -** Instead, write your code in functions called init() and destroy(). -** These will automatically be called by the form's constructor and -** destructor. -*****************************************************************************/ - -/* - Copyright (C) 2005-2009 Michel de Boer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -void BuddyForm::init() -{ - getAddressForm = 0; -} - -void BuddyForm::destroy() -{ - if (getAddressForm) { - MEMMAN_DELETE(getAddressForm); - delete getAddressForm; - } -} - -void BuddyForm::showNew(t_buddy_list &_buddy_list, Q3ListViewItem *_profileItem) -{ - user_config = _buddy_list.get_user_profile(); - edit_mode = false; - buddy_list = &_buddy_list; - profileItem = _profileItem; - - QDialog::show(); -} - -void BuddyForm::showEdit(t_buddy &buddy) -{ - user_config = buddy.get_user_profile(); - edit_mode = true; - edit_buddy = &buddy; - buddy_list = edit_buddy->get_buddy_list(); - - nameLineEdit->setText(buddy.get_name().c_str()); - phoneLineEdit->setText(buddy.get_sip_address().c_str()); - subscribeCheckBox->setChecked(buddy.get_may_subscribe_presence()); - - phoneLineEdit->setEnabled(false); - phoneTextLabel->setEnabled(false); - addressToolButton->hide(); - - QDialog::show(); -} - -void BuddyForm::validate() -{ - QString name = nameLineEdit->text().stripWhiteSpace(); - QString address = phoneLineEdit->text().stripWhiteSpace(); - - if (name.isEmpty()) { - ((t_gui *)ui)->cb_show_msg(this, - tr("You must fill in a name.").ascii(), MSG_CRITICAL); - nameLineEdit->setFocus(); - return; - } - - string dest = ui->expand_destination(user_config, address.ascii()); - t_url dest_url(dest); - if (!dest_url.is_valid()) { - ((t_gui *)ui)->cb_show_msg(this, - tr("Invalid phone.").ascii(), MSG_CRITICAL); - phoneLineEdit->setFocus(); - return; - } - - if (edit_mode) { - // Edit existing buddy - bool must_subscribe = false; - bool must_unsubscribe = false; - - if (edit_buddy->get_may_subscribe_presence() != subscribeCheckBox->isChecked()) - { - if (subscribeCheckBox->isChecked()) { - must_subscribe = true;; - } else { - must_unsubscribe = true; - } - } - - edit_buddy->set_name(nameLineEdit->text().stripWhiteSpace().ascii()); - edit_buddy->set_sip_address(phoneLineEdit->text().stripWhiteSpace().ascii()); - edit_buddy->set_may_subscribe_presence(subscribeCheckBox->isChecked()); - - if (must_subscribe) edit_buddy->subscribe_presence(); - if (must_unsubscribe) edit_buddy->unsubscribe_presence(); - } else { - // Add a new buddy - t_buddy buddy; - buddy.set_name(nameLineEdit->text().stripWhiteSpace().ascii()); - buddy.set_sip_address(phoneLineEdit->text().stripWhiteSpace().ascii()); - buddy.set_may_subscribe_presence(subscribeCheckBox->isChecked()); - - t_buddy *new_buddy = buddy_list->add_buddy(buddy); - new BuddyListViewItem(profileItem, new_buddy); - new_buddy->subscribe_presence(); - } - - string err_msg; - if (!buddy_list->save(err_msg)) { - QString msg = tr("Failed to save buddy list: %1").arg(err_msg.c_str()); - ((t_gui *)ui)->cb_show_msg(this, msg.ascii(), MSG_CRITICAL); - } - - accept(); -} - -void BuddyForm::showAddressBook() -{ - if (!getAddressForm) { - getAddressForm = new GetAddressForm( - this, "select address", true); - MEMMAN_NEW(getAddressForm); - } - - connect(getAddressForm, - SIGNAL(address(const QString &, const QString &)), - this, SLOT(selectedAddress(const QString &, const QString &))); - - getAddressForm->show(); -} - -void BuddyForm::selectedAddress(const QString &name, const QString &phone) -{ - nameLineEdit->setText(name); - phoneLineEdit->setText(phone); -} diff --git a/src/gui/buddylistview.cpp b/src/gui/buddylistview.cpp index 083c8b0..092169f 100644 --- a/src/gui/buddylistview.cpp +++ b/src/gui/buddylistview.cpp @@ -33,22 +33,22 @@ void AbstractBLVItem::set_icon(t_presence_state::t_basic_state state) { switch (state) { case t_presence_state::ST_BASIC_UNKNOWN: - setPixmap(0, qPixmapFromMimeSource("presence_unknown.png")); + setPixmap(0, QPixmap(":/icons/images/presence_unknown.png")); break; case t_presence_state::ST_BASIC_CLOSED: - setPixmap(0, qPixmapFromMimeSource("presence_offline.png")); + setPixmap(0, QPixmap(":/icons/images/presence_offline.png")); break; case t_presence_state::ST_BASIC_OPEN: - setPixmap(0, qPixmapFromMimeSource("presence_online.png")); + setPixmap(0, QPixmap(":/icons/images/presence_online.png")); break; case t_presence_state::ST_BASIC_FAILED: - setPixmap(0, qPixmapFromMimeSource("presence_failed.png")); + setPixmap(0, QPixmap(":/icons/images/presence_failed.png")); break; case t_presence_state::ST_BASIC_REJECTED: - setPixmap(0, qPixmapFromMimeSource("presence_rejected.png")); + setPixmap(0, QPixmap(":/icons/images/presence_rejected.png")); break; default: - setPixmap(0, qPixmapFromMimeSource("presence_unknown.png")); + setPixmap(0, QPixmap(":/icons/images/presence_unknown.png")); break; } } @@ -76,7 +76,7 @@ void BuddyListViewItem::set_icon(void) { tip += Q3StyleSheet::escape(ui->format_sip_address(user_config, buddy->get_name(), t_url(url_str)).c_str()).replace(' ', " "); if (!buddy->get_may_subscribe_presence()) { - setPixmap(0, qPixmapFromMimeSource("buddy.png")); + setPixmap(0, QPixmap(":/icons/images/buddy.png")); } else { QString failure; t_presence_state::t_basic_state basic_state = buddy-> @@ -171,7 +171,7 @@ void BLViewUserItem::set_icon(void) { switch (presence_epa->get_epa_state()) { case t_presence_epa::EPA_UNPUBLISHED: tip += qApp->translate("BuddyList", "not published"); - setPixmap(0, qPixmapFromMimeSource("penguin-small.png")); + setPixmap(0, QPixmap(":/icons/images/penguin-small.png")); break; case t_presence_epa::EPA_FAILED: tip += qApp->translate("BuddyList", "failed to publish"); @@ -179,7 +179,7 @@ void BLViewUserItem::set_icon(void) { if (!failure.isEmpty()) { tip += QString(" (%1)").arg(failure); } - setPixmap(0, qPixmapFromMimeSource("presence_failed.png")); + setPixmap(0, QPixmap(":/icons/images/presence_failed.png")); break; case t_presence_epa::EPA_PUBLISHED: basic_state = presence_epa->get_basic_state(); diff --git a/src/gui/diamondcardprofileform.cpp b/src/gui/diamondcardprofileform.cpp new file mode 100644 index 0000000..f989045 --- /dev/null +++ b/src/gui/diamondcardprofileform.cpp @@ -0,0 +1,184 @@ +//Added by qt3to4: +#include +#include + +/* + Copyright (C) 2005-2009 Michel de Boer + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include +#include +#include "gui.h" +#include "diamondcard.h" +#include "getprofilenameform.h" +#include "audits/memman.h" +#include "diamondcardprofileform.h" +/* + * Constructs a DiamondcardProfileForm as a child of 'parent', with the + * name 'name' and widget flags set to 'f'. + * + * The dialog will by default be modeless, unless you set 'modal' to + * true to construct a modal dialog. + */ +DiamondcardProfileForm::DiamondcardProfileForm(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl) + : QDialog(parent, name, modal, fl) +{ + setupUi(this); + + init(); +} + +/* + * Destroys the object and frees any allocated resources + */ +DiamondcardProfileForm::~DiamondcardProfileForm() +{ + destroy(); + // no need to delete child widgets, Qt does it all for us +} + +/* + * Sets the strings of the subwidgets using the current + * language. + */ +void DiamondcardProfileForm::languageChange() +{ + retranslateUi(this); +} + + +void DiamondcardProfileForm::init() +{ + user_config = NULL; + destroy_user_config = false; + + QRegExp rxNoSpace("\\S*"); + accountIdLineEdit->setValidator(new QRegExpValidator(rxNoSpace, this)); + pinCodeLineEdit->setValidator(new QRegExpValidator(rxNoSpace, this)); +} + +void DiamondcardProfileForm::destroy() +{ + destroyOldUserConfig(); +} + +void DiamondcardProfileForm::destroyOldUserConfig() +{ + if (user_config && destroy_user_config) { + MEMMAN_DELETE(user_config); + delete user_config; + } + user_config = NULL; +} + +// Show the form +void DiamondcardProfileForm::show(t_user *user) +{ + destroyOldUserConfig(); + + if (user) { + user_config = user; + destroy_user_config = false; + } else { + user_config = new t_user(); + MEMMAN_NEW(user_config); + destroy_user_config = true; + } + QDialog::show(); +} + +// Modal execution +int DiamondcardProfileForm::exec(t_user *user) +{ + destroyOldUserConfig(); + user_config = user; + destroy_user_config = false; + return QDialog::exec(); +} + +void DiamondcardProfileForm::validate() +{ + if (accountIdLineEdit->text().isEmpty()) { + ((t_gui *)ui)->cb_show_msg(this, tr("Fill in your account ID.").ascii(), + MSG_CRITICAL); + accountIdLineEdit->setFocus(); + return; + } + + if (pinCodeLineEdit->text().isEmpty()) { + ((t_gui *)ui)->cb_show_msg(this, tr("Fill in your PIN code.").ascii(), + MSG_CRITICAL); + pinCodeLineEdit->setFocus(); + return; + } + + QString profileName("Diamondcard-"); + profileName.append(accountIdLineEdit->text()); + QString filename(profileName); + filename.append(USER_FILE_EXT); + + // Create a new user config + while (!user_config->set_config(filename.ascii())) { + ((t_gui *)ui)->cb_show_msg(this, + tr("A user profile with name %1 already exists.").arg(profileName).ascii(), + MSG_WARNING); + + // Ask user for a profile name + GetProfileNameForm getProfileNameForm(this, "get profile name", true); + if (!getProfileNameForm.execNewName()) return; + + profileName = getProfileNameForm.getProfileName(); + filename = profileName; + filename.append(USER_FILE_EXT); + } + + diamondcard_set_user_config(*user_config, + nameLineEdit->text().ascii(), + accountIdLineEdit->text().ascii(), + pinCodeLineEdit->text().ascii()); + + string error_msg; + if (!user_config->write_config(user_config->get_filename(), error_msg)) { + // Failed to write config file + ((t_gui *)ui)->cb_show_msg(this, error_msg, MSG_CRITICAL); + return; + } + + emit newDiamondcardProfile(user_config->get_filename().c_str()); + emit success(); + accept(); +} + +// Handle mouse clicks on labels. +void DiamondcardProfileForm::mouseReleaseEvent(QMouseEvent *e) +{ + if (e->button() == Qt::LeftButton && e->type() == QEvent::MouseButtonRelease) { + processLeftMouseButtonRelease(e); + } else { + e->ignore(); + } +} + +void DiamondcardProfileForm::processLeftMouseButtonRelease(QMouseEvent *e) +{ + if (signUpTextLabel->hasMouse()) { + string url = diamondcard_url(DC_ACT_SIGNUP, "", ""); + ((t_gui *)ui)->open_url_in_browser(url.c_str()); + } else { + e->ignore(); + } +} diff --git a/src/gui/diamondcardprofileform.h b/src/gui/diamondcardprofileform.h new file mode 100644 index 0000000..48224c9 --- /dev/null +++ b/src/gui/diamondcardprofileform.h @@ -0,0 +1,46 @@ +#ifndef DIAMONDCARDPROFILEFORM_H +#define DIAMONDCARDPROFILEFORM_H +#include +#include +#include "user.h" +#include "ui_diamondcardprofileform.h" + +class DiamondcardProfileForm : public QDialog, public Ui::DiamondcardProfileForm +{ + Q_OBJECT + +public: + DiamondcardProfileForm(QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WindowFlags fl = 0); + ~DiamondcardProfileForm(); + + virtual int exec( t_user * user ); + +public slots: + virtual void destroyOldUserConfig(); + virtual void show( t_user * user ); + virtual void validate(); + virtual void mouseReleaseEvent( QMouseEvent * e ); + virtual void processLeftMouseButtonRelease( QMouseEvent * e ); + +signals: + void success(); + void newDiamondcardProfile(const QString&); + +protected slots: + virtual void languageChange(); + +private: + t_user *user_config; + bool destroy_user_config; + QLineEdit *accountIdLineEdit; + QLineEdit *pinCodeLineEdit; + QLineEdit *nameLineEdit; + QLabel *signUpTextLabel; + + void init(); + void destroy(); + +}; + + +#endif diff --git a/src/gui/diamondcardprofileform.ui.h b/src/gui/diamondcardprofileform.ui.h deleted file mode 100644 index 90c7c5e..0000000 --- a/src/gui/diamondcardprofileform.ui.h +++ /dev/null @@ -1,154 +0,0 @@ -//Added by qt3to4: -#include -#include -/**************************************************************************** -** ui.h extension file, included from the uic-generated form implementation. -** -** If you want to add, delete, or rename functions or slots, use -** Qt Designer to update this file, preserving your code. -** -** You should not define a constructor or destructor in this file. -** Instead, write your code in functions called init() and destroy(). -** These will automatically be called by the form's constructor and -** destructor. -*****************************************************************************/ - -/* - Copyright (C) 2005-2009 Michel de Boer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -void DiamondcardProfileForm::init() -{ - user_config = NULL; - destroy_user_config = false; - - QRegExp rxNoSpace("\\S*"); - accountIdLineEdit->setValidator(new QRegExpValidator(rxNoSpace, this)); - pinCodeLineEdit->setValidator(new QRegExpValidator(rxNoSpace, this)); -} - -void DiamondcardProfileForm::destroy() -{ - destroyOldUserConfig(); -} - -void DiamondcardProfileForm::destroyOldUserConfig() -{ - if (user_config && destroy_user_config) { - MEMMAN_DELETE(user_config); - delete user_config; - } - user_config = NULL; -} - -// Show the form -void DiamondcardProfileForm::show(t_user *user) -{ - destroyOldUserConfig(); - - if (user) { - user_config = user; - destroy_user_config = false; - } else { - user_config = new t_user(); - MEMMAN_NEW(user_config); - destroy_user_config = true; - } - QDialog::show(); -} - -// Modal execution -int DiamondcardProfileForm::exec(t_user *user) -{ - destroyOldUserConfig(); - user_config = user; - destroy_user_config = false; - return QDialog::exec(); -} - -void DiamondcardProfileForm::validate() -{ - if (accountIdLineEdit->text().isEmpty()) { - ((t_gui *)ui)->cb_show_msg(this, tr("Fill in your account ID.").ascii(), - MSG_CRITICAL); - accountIdLineEdit->setFocus(); - return; - } - - if (pinCodeLineEdit->text().isEmpty()) { - ((t_gui *)ui)->cb_show_msg(this, tr("Fill in your PIN code.").ascii(), - MSG_CRITICAL); - pinCodeLineEdit->setFocus(); - return; - } - - QString profileName("Diamondcard-"); - profileName.append(accountIdLineEdit->text()); - QString filename(profileName); - filename.append(USER_FILE_EXT); - - // Create a new user config - while (!user_config->set_config(filename.ascii())) { - ((t_gui *)ui)->cb_show_msg(this, - tr("A user profile with name %1 already exists.").arg(profileName).ascii(), - MSG_WARNING); - - // Ask user for a profile name - GetProfileNameForm getProfileNameForm(this, "get profile name", true); - if (!getProfileNameForm.execNewName()) return; - - profileName = getProfileNameForm.getProfileName(); - filename = profileName; - filename.append(USER_FILE_EXT); - } - - diamondcard_set_user_config(*user_config, - nameLineEdit->text().ascii(), - accountIdLineEdit->text().ascii(), - pinCodeLineEdit->text().ascii()); - - string error_msg; - if (!user_config->write_config(user_config->get_filename(), error_msg)) { - // Failed to write config file - ((t_gui *)ui)->cb_show_msg(this, error_msg, MSG_CRITICAL); - return; - } - - emit newDiamondcardProfile(user_config->get_filename().c_str()); - emit success(); - accept(); -} - -// Handle mouse clicks on labels. -void DiamondcardProfileForm::mouseReleaseEvent(QMouseEvent *e) -{ - if (e->button() == Qt::LeftButton && e->type() == QEvent::MouseButtonRelease) { - processLeftMouseButtonRelease(e); - } else { - e->ignore(); - } -} - -void DiamondcardProfileForm::processLeftMouseButtonRelease(QMouseEvent *e) -{ - if (signUpTextLabel->hasMouse()) { - string url = diamondcard_url(DC_ACT_SIGNUP, "", ""); - ((t_gui *)ui)->open_url_in_browser(url.c_str()); - } else { - e->ignore(); - } -} diff --git a/src/gui/freedesksystray.cpp b/src/gui/freedesksystray.cpp deleted file mode 100644 index 6812cbe..0000000 --- a/src/gui/freedesksystray.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004 by Emil Stoyanov * - * emosto@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -// 2006 Modified by Michel de Boer - -#include "freedesksystray.h" -//Added by qt3to4: -#include -#include -#include -#include -#include - -#include - -FreeDeskSysTray::FreeDeskSysTray ( QWidget *pParent , const char *pszName ) - : QLabel(pParent, pszName, Qt::WMouseNoMask | Qt::WRepaintNoErase | Qt::WType_TopLevel | - Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_StaysOnTop) -{ - mainWindow = pParent; - trayMenu = new Q3PopupMenu(this); -} - -void FreeDeskSysTray::dock () -{ - trayMenu->insertSeparator(); - trayMenu->insertItem(tr("Show/Hide"), this, SLOT(slotMenuItemShow())) ; - - QIcon quitIcon(qPixmapFromMimeSource("exit.png")); - trayMenu->insertItem(quitIcon, tr("Quit"), this, SLOT(slotMenuItemQuit())) ; - - Display *dpy = QPaintDevice::x11AppDisplay(); - WId trayWin = winId(); - - // System Tray Protocol Specification from freedesktop.org - Screen *screen = XDefaultScreenOfDisplay(dpy); - int iScreen = XScreenNumberOfScreen(screen); - char szAtom[32]; - snprintf(szAtom, sizeof(szAtom), "_NET_SYSTEM_TRAY_S%d", iScreen); - Atom selectionAtom = XInternAtom(dpy, szAtom, false); - XGrabServer(dpy); - Window managerWin = XGetSelectionOwner(dpy, selectionAtom); - XSelectInput(dpy, managerWin, StructureNotifyMask); - XUngrabServer(dpy); - XFlush(dpy); - XEvent ev; - memset(&ev, 0, sizeof(ev)); - ev.xclient.type = ClientMessage; - ev.xclient.window = managerWin; - ev.xclient.message_type = XInternAtom(dpy, "_NET_SYSTEM_TRAY_OPCODE", true); - ev.xclient.format = 32; - ev.xclient.data.l[0] = CurrentTime; - ev.xclient.data.l[1] = SYSTEM_TRAY_REQUEST_DOCK; - ev.xclient.data.l[2] = trayWin; - ev.xclient.data.l[3] = 0; - ev.xclient.data.l[4] = 0; - XSendEvent(dpy, managerWin, false, NoEventMask, &ev); - XSync(dpy, false); - - Atom trayAtom; - WId forWin = mainWindow ? mainWindow->topLevelWidget()->winId() : QX11Info::appRootWindow(); - trayAtom = XInternAtom(dpy, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false); - XChangeProperty(dpy, trayWin, trayAtom, XA_WINDOW, 32, PropModeReplace, (unsigned char *) &forWin, 1); - - setMinimumSize(22, 22); - setBackgroundMode(Qt::X11ParentRelative); - - // because of GNOME - needs a wait of at least 50-100 ms, otherwise width=1 - // KDocker solves the problem so (bug?) - QTimer::singleShot(500, this, SLOT(show())); - -} - -void FreeDeskSysTray::undock () -{ - XUnmapWindow(QPaintDevice::x11AppDisplay(), winId()); - hide(); -} - -FreeDeskSysTray::~FreeDeskSysTray () -{} - -void FreeDeskSysTray::mousePressEvent ( QMouseEvent *pMouseEvent ) -{ - if (!QLabel::rect().contains(pMouseEvent->pos())) - return; - - switch (pMouseEvent->button()) - { - - case Qt::LeftButton: - slotMenuItemShow(); - break; - - case Qt::RightButton: - showContextMenu(pMouseEvent->globalPos()); - break; - - default: - break; - } -} - -Q3PopupMenu *FreeDeskSysTray::contextMenu() -{ - return trayMenu; -} - - void FreeDeskSysTray::setPixmap(const QPixmap& pixmap) -{ - QLabel::setPixmap(pixmap); - repaint(true); -} - -void FreeDeskSysTray::showContextMenu(const QPoint& position) -{ - trayMenu->popup(position,0); -} - -void FreeDeskSysTray::slotMenuItemShow() { - -// mainWindowGeometry = mainWindow->geometry(); -// windowPos = mainWindow->frameGeometry().topLeft(); - - if (mainWindow->isVisible()) { - //mainWindow->setGeometry(mainWindowGeometry); - mainWindow->close(); - } else { -// mainWindow->move( windowPos ); // restore position - mainWindow->show(); - } - -} - -void FreeDeskSysTray::slotMenuItemQuit() { - emit quitSelected(); -} diff --git a/src/gui/freedesksystray.h b/src/gui/freedesksystray.h deleted file mode 100644 index c6a479e..0000000 --- a/src/gui/freedesksystray.h +++ /dev/null @@ -1,95 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004 by Emil Stoyanov * - * emosto@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -// 2006 Modified by Michel de Boer - -#ifndef FREEDESKSYSTEMTRAY_H -#define FREEDESKTSYSTEMTRAY_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -//Added by qt3to4: -#include - -#include -#include -#include -#include - -#include -#include - - -// System Tray Protocol Specification opcodes. -#define SYSTEM_TRAY_REQUEST_DOCK 0 -#define SYSTEM_TRAY_BEGIN_MESSAGE 1 -#define SYSTEM_TRAY_CANCEL_MESSAGE 2 - - -class FreeDeskSysTray : public QLabel -{ - Q_OBJECT - -public: - - FreeDeskSysTray(QWidget *pParent = 0, const char *pszName = 0); - ~FreeDeskSysTray(); - - void showContextMenu(const QPoint& position); - void dock (); - void undock (); - Q3PopupMenu *contextMenu(); - void setPixmap(const QPixmap& pixmap); - -public: - - QWidget * mainWindow; - Q3PopupMenu * trayMenu; - -protected: - - void mousePressEvent(QMouseEvent *); - -public slots: - - void slotMenuItemShow(); - void slotMenuItemQuit(); - -signals: - - void quitSelected(); - -private: - QRect mainWindowGeometry; - QPoint windowPos; -}; - -// ifndef FREEDESKSYSTEMTRAY_H -#endif diff --git a/src/gui/getaddressform.cpp b/src/gui/getaddressform.cpp new file mode 100644 index 0000000..ec350e4 --- /dev/null +++ b/src/gui/getaddressform.cpp @@ -0,0 +1,266 @@ +/* + Copyright (C) 2005-2009 Michel de Boer + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "getaddressform.h" +#include +#include "sys_settings.h" +#include "gui.h" +#include "address_book.h" +#include "addresslistviewitem.h" +#include "addresscardform.h" +#define TAB_KABC 0 +#define TAB_LOCAL 1 + +#ifdef HAVE_KDE +#include +#include +#include +#include +#include + +#define ABOOK ((KABC::AddressBook *)addrBook) + +// Column numbers +#define AB_COL_NAME 0 +#define AB_COL_PHONE 2 +#endif + +GetAddressForm::GetAddressForm(QWidget *parent, const char *name, bool modal) + : QDialog(parent, name, modal) +{ + setupUi(this); + init(); +} + +GetAddressForm::~GetAddressForm() +{ + // destroy(); +} + +void GetAddressForm::init() +{ +#ifdef HAVE_KDE + addrBook = (void *)KABC::StdAddressBook::self(false); + loadAddresses(); + + connect(ABOOK, + SIGNAL(addressBookChanged(AddressBook *)), + this, SLOT(loadAddresses())); + + sipOnlyCheckBox->setChecked(sys_config->get_ab_show_sip_only()); +#else + addressTabWidget->setTabEnabled(tabKABC, false); + addressTabWidget->setCurrentPage(TAB_LOCAL); +#endif + loadLocalAddresses(); +} + +void GetAddressForm::reload() +{ +#ifdef HAVE_KDE + ABOOK->disconnect(); + KABC::StdAddressBook::close(); + addrBook = (void *)KABC::StdAddressBook::self(false); + loadAddresses(); + + connect(ABOOK, + SIGNAL(addressBookChanged(AddressBook *)), + this, SLOT(loadAddresses())); +#endif +} + +void GetAddressForm::show() +{ + QDialog::show(); + +#ifdef HAVE_KDE + if (addressListView->childCount() == 0) { + if (localListView->childCount() == 0) { + QMessageBox::information(this, PRODUCT_NAME, tr( + "

" + "You seem not to have any contacts with a phone number " + "in KAddressBook, KDE's address book application. " + "Twinkle retrieves all contacts with a phone number from " + "KAddressBook. To manage your contacts you have to " + "use KAddressBook." + "

" + "As an alternative you may use Twinkle's local address book." + "

")); + } else { + addressTabWidget->setCurrentPage(TAB_LOCAL); + } + } +#endif +} + +void GetAddressForm::loadAddresses() +{ +#ifdef HAVE_KDE + // Explicit loading of address book is not needed as it is + // automatically loaded. + // if (!ABOOK->load()) return; + + addressListView->clear(); + for (KABC::AddressBook::Iterator i = ABOOK->begin(); i != ABOOK->end(); i++) + { + KABC::PhoneNumber::List phoneNrs = i->phoneNumbers(); + for (KABC::PhoneNumber::List::iterator j = phoneNrs.begin(); + j != phoneNrs.end(); j++) + { + QString phone = (*j).number(); + if (!sys_config->get_ab_show_sip_only() || + phone.startsWith("sip:")) + { + new Q3ListViewItem(addressListView, i->realName(), + (*j).typeLabel(), phone); + } + } + } + + Q3ListViewItem *first = addressListView->firstChild(); + if (first) addressListView->setSelected(first, true); +#endif +} + +void GetAddressForm::loadLocalAddresses() +{ + localListView->clear(); + const list &address_list = ab_local->get_address_list(); + + for(list::const_iterator i = address_list.begin(); i != address_list.end(); i++) + { + new AddressListViewItem(localListView, *i); + } + + Q3ListViewItem *first = localListView->firstChild(); + if (first) localListView->setSelected(first, true); +} + +void GetAddressForm::selectAddress() +{ + if (addressTabWidget->currentPageIndex() == TAB_KABC) { + selectKABCAddress(); + } else { + selectLocalAddress(); + } +} + +void GetAddressForm::selectKABCAddress() +{ +#ifdef HAVE_KDE + Q3ListViewItem *item = addressListView->selectedItem(); + if (item) { + QString name(item->text(AB_COL_NAME)); + QString phone(item->text(AB_COL_PHONE)); + phone = phone.stripWhiteSpace(); + + emit address(name, phone); + + // Signal display name and url combined. + t_display_url du(t_url(phone.ascii()), name.ascii()); + emit address(du.encode().c_str()); + } + + accept(); +#endif +} + +void GetAddressForm::selectLocalAddress() +{ + AddressListViewItem *item = dynamic_cast( + localListView->selectedItem()); + if (item) { + t_address_card card = item->getAddressCard(); + emit(card.get_display_name().c_str(), card.sip_address.c_str()); + + // Signal display name and url combined. + t_display_url du(t_url(card.sip_address), card.get_display_name()); + emit address(du.encode().c_str()); + } + + accept(); +} + +void GetAddressForm::toggleSipOnly(bool on) +{ +#ifdef HAVE_KDE + string msg; + + sys_config->set_ab_show_sip_only(on); + + // Ignore write failures. If for some reason the system config + // could not be written, then this settings is lost after exiting Twinkle. + // No need to bother the user at this point. + (void)sys_config->write_config(msg); + + loadAddresses(); +#endif +} + +void GetAddressForm::addLocalAddress() +{ + t_address_card card; + AddressCardForm f; + if (f.exec(card)) { + ab_local->add_address(card); + new AddressListViewItem(localListView, card); + + string error_msg; + if (!ab_local->save(error_msg)) { + ui->cb_show_msg(error_msg, MSG_CRITICAL); + } + } +} + +void GetAddressForm::deleteLocalAddress() +{ + AddressListViewItem *item = dynamic_cast( + localListView->selectedItem()); + if (item) { + t_address_card card = item->getAddressCard(); + if (ab_local->del_address(card)) { + delete item; + + string error_msg; + if (!ab_local->save(error_msg)) { + ui->cb_show_msg(error_msg, MSG_CRITICAL); + } + } + } +} + +void GetAddressForm::editLocalAddress() +{ + AddressListViewItem *item = dynamic_cast( + localListView->selectedItem()); + if (!item) return; + + t_address_card oldCard = item->getAddressCard(); + t_address_card newCard = oldCard; + AddressCardForm f; + if (f.exec(newCard)) { + if (ab_local->update_address(oldCard, newCard)) { + item->update(newCard); + + string error_msg; + if (!ab_local->save(error_msg)) { + ui->cb_show_msg(error_msg, MSG_CRITICAL); + } + } + } +} diff --git a/src/gui/getaddressform.h b/src/gui/getaddressform.h new file mode 100644 index 0000000..c55ce06 --- /dev/null +++ b/src/gui/getaddressform.h @@ -0,0 +1,35 @@ +#ifndef GETADDRESSFORM_UI_H +#define GETADDRESSFORM_UI_H +#include "ui_getaddressform.h" +#include "user.h" + +class GetAddressForm : public QDialog, public Ui::GetAddressForm +{ +Q_OBJECT +public: + GetAddressForm(QWidget *parent, const char *name, bool modal); + ~GetAddressForm(); +private: + void init(); + // void destroy(); +public slots: + void reload(); + void show(); + void loadAddresses(); + void loadLocalAddresses(); + void selectAddress(); + void selectKABCAddress(); + void selectLocalAddress(); + void toggleSipOnly( bool on ); + void addLocalAddress(); + void deleteLocalAddress(); + void editLocalAddress(); + +signals: + void address(const QString &, const QString &); + void address(const QString &); +private: + void *addrBook; +}; + +#endif diff --git a/src/gui/getaddressform.ui.h b/src/gui/getaddressform.ui.h deleted file mode 100644 index 251e90d..0000000 --- a/src/gui/getaddressform.ui.h +++ /dev/null @@ -1,259 +0,0 @@ -/**************************************************************************** -** ui.h extension file, included from the uic-generated form implementation. -** -** If you want to add, delete, or rename functions or slots, use -** Qt Designer to update this file, preserving your code. -** -** You should not define a constructor or destructor in this file. -** Instead, write your code in functions called init() and destroy(). -** These will automatically be called by the form's constructor and -** destructor. -*****************************************************************************/ - -/* - Copyright (C) 2005-2009 Michel de Boer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -#define TAB_KABC 0 -#define TAB_LOCAL 1 - -#ifdef HAVE_KDE -#include -#include -#include -#include -#include - -#define ABOOK ((KABC::AddressBook *)addrBook) - -// Column numbers -#define AB_COL_NAME 0 -#define AB_COL_PHONE 2 -#endif - -void GetAddressForm::init() -{ -#ifdef HAVE_KDE - addrBook = (void *)KABC::StdAddressBook::self(false); - loadAddresses(); - - connect(ABOOK, - SIGNAL(addressBookChanged(AddressBook *)), - this, SLOT(loadAddresses())); - - sipOnlyCheckBox->setChecked(sys_config->get_ab_show_sip_only()); -#else - addressTabWidget->setTabEnabled(tabKABC, false); - addressTabWidget->setCurrentPage(TAB_LOCAL); -#endif - loadLocalAddresses(); -} - -void GetAddressForm::reload() -{ -#ifdef HAVE_KDE - ABOOK->disconnect(); - KABC::StdAddressBook::close(); - addrBook = (void *)KABC::StdAddressBook::self(false); - loadAddresses(); - - connect(ABOOK, - SIGNAL(addressBookChanged(AddressBook *)), - this, SLOT(loadAddresses())); -#endif -} - -void GetAddressForm::show() -{ - QDialog::show(); - -#ifdef HAVE_KDE - if (addressListView->childCount() == 0) { - if (localListView->childCount() == 0) { - QMessageBox::information(this, PRODUCT_NAME, tr( - "

" - "You seem not to have any contacts with a phone number " - "in KAddressBook, KDE's address book application. " - "Twinkle retrieves all contacts with a phone number from " - "KAddressBook. To manage your contacts you have to " - "use KAddressBook." - "

" - "As an alternative you may use Twinkle's local address book." - "

")); - } else { - addressTabWidget->setCurrentPage(TAB_LOCAL); - } - } -#endif -} - -void GetAddressForm::loadAddresses() -{ -#ifdef HAVE_KDE - // Explicit loading of address book is not needed as it is - // automatically loaded. - // if (!ABOOK->load()) return; - - addressListView->clear(); - for (KABC::AddressBook::Iterator i = ABOOK->begin(); i != ABOOK->end(); i++) - { - KABC::PhoneNumber::List phoneNrs = i->phoneNumbers(); - for (KABC::PhoneNumber::List::iterator j = phoneNrs.begin(); - j != phoneNrs.end(); j++) - { - QString phone = (*j).number(); - if (!sys_config->get_ab_show_sip_only() || - phone.startsWith("sip:")) - { - new Q3ListViewItem(addressListView, i->realName(), - (*j).typeLabel(), phone); - } - } - } - - Q3ListViewItem *first = addressListView->firstChild(); - if (first) addressListView->setSelected(first, true); -#endif -} - -void GetAddressForm::loadLocalAddresses() -{ - localListView->clear(); - const list &address_list = ab_local->get_address_list(); - - for(list::const_iterator i = address_list.begin(); i != address_list.end(); i++) - { - new AddressListViewItem(localListView, *i); - } - - Q3ListViewItem *first = localListView->firstChild(); - if (first) localListView->setSelected(first, true); -} - -void GetAddressForm::selectAddress() -{ - if (addressTabWidget->currentPageIndex() == TAB_KABC) { - selectKABCAddress(); - } else { - selectLocalAddress(); - } -} - -void GetAddressForm::selectKABCAddress() -{ -#ifdef HAVE_KDE - Q3ListViewItem *item = addressListView->selectedItem(); - if (item) { - QString name(item->text(AB_COL_NAME)); - QString phone(item->text(AB_COL_PHONE)); - phone = phone.stripWhiteSpace(); - - emit address(name, phone); - - // Signal display name and url combined. - t_display_url du(t_url(phone.ascii()), name.ascii()); - emit address(du.encode().c_str()); - } - - accept(); -#endif -} - -void GetAddressForm::selectLocalAddress() -{ - AddressListViewItem *item = dynamic_cast( - localListView->selectedItem()); - if (item) { - t_address_card card = item->getAddressCard(); - emit(card.get_display_name().c_str(), card.sip_address.c_str()); - - // Signal display name and url combined. - t_display_url du(t_url(card.sip_address), card.get_display_name()); - emit address(du.encode().c_str()); - } - - accept(); -} - -void GetAddressForm::toggleSipOnly(bool on) -{ -#ifdef HAVE_KDE - string msg; - - sys_config->set_ab_show_sip_only(on); - - // Ignore write failures. If for some reason the system config - // could not be written, then this settings is lost after exiting Twinkle. - // No need to bother the user at this point. - (void)sys_config->write_config(msg); - - loadAddresses(); -#endif -} - -void GetAddressForm::addLocalAddress() -{ - t_address_card card; - AddressCardForm f; - if (f.exec(card)) { - ab_local->add_address(card); - new AddressListViewItem(localListView, card); - - string error_msg; - if (!ab_local->save(error_msg)) { - ui->cb_show_msg(error_msg, MSG_CRITICAL); - } - } -} - -void GetAddressForm::deleteLocalAddress() -{ - AddressListViewItem *item = dynamic_cast( - localListView->selectedItem()); - if (item) { - t_address_card card = item->getAddressCard(); - if (ab_local->del_address(card)) { - delete item; - - string error_msg; - if (!ab_local->save(error_msg)) { - ui->cb_show_msg(error_msg, MSG_CRITICAL); - } - } - } -} - -void GetAddressForm::editLocalAddress() -{ - AddressListViewItem *item = dynamic_cast( - localListView->selectedItem()); - if (!item) return; - - t_address_card oldCard = item->getAddressCard(); - t_address_card newCard = oldCard; - AddressCardForm f; - if (f.exec(newCard)) { - if (ab_local->update_address(oldCard, newCard)) { - item->update(newCard); - - string error_msg; - if (!ab_local->save(error_msg)) { - ui->cb_show_msg(error_msg, MSG_CRITICAL); - } - } - } -} diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index eda1293..c6a95d3 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -49,12 +49,11 @@ #include "sockets/interfaces.h" #include "threads/thread.h" #include "audits/memman.h" -#include "ui_authenticationform.h" -#include "ui_mphoneform.h" -#include "ui_selectnicform.h" -#include "ui_selectprofileform.h" +#include "authenticationform.h" +#include "mphoneform.h" +#include "selectnicform.h" +#include "selectprofileform.h" #include "messageformview.h" -#include "twinklesystray.h" #include "util.h" #include "address_finder.h" #include "yesnodialog.h" @@ -98,14 +97,14 @@ QString str2html(const QString &s) void setDisabledIcon(QAction *action, const QString &icon) { QIcon i = action->iconSet(); - i.setPixmap(qPixmapFromMimeSource(icon), + i.setPixmap(QPixmap(icon), QIcon::Automatic, QIcon::Disabled); action->setIconSet(i); } void setDisabledIcon(QToolButton *toolButton, const QString &icon) { QIcon i = toolButton->iconSet(); - i.setPixmap(qPixmapFromMimeSource(icon), + i.setPixmap(QPixmap(icon), QIcon::Automatic, QIcon::Disabled); toolButton->setIconSet(i); } @@ -891,7 +890,7 @@ string t_gui::select_network_intf(void) { item = i->name.c_str(); item.append(':').append(i->get_ip_addr().c_str()); sf->nicListBox->insertItem( - qPixmapFromMimeSource("kcmpci16.png"), + QPixmap(":/icons/images/kcmpci16.png"), item); } @@ -1515,12 +1514,12 @@ void t_gui::cb_register_inprog(t_user *user_config, t_register_type register_typ // Do not report registration refreshments if (phone->get_is_registered(user_config)) break; mainWindow->statRegLabel->setPixmap( - qPixmapFromMimeSource("gear.png")); + QPixmap(":/icons/images/gear.png")); break; case REG_DEREGISTER: case REG_DEREGISTER_ALL: mainWindow->statRegLabel->setPixmap( - qPixmapFromMimeSource("gear.png")); + QPixmap(":/icons/images/gear.png")); break; case REG_QUERY: emit mw_display_header(); @@ -1602,7 +1601,7 @@ void t_gui::cb_notify_call(int line, const QString &from_party, const QString &o QPixmap pm; Q3Frame::Shape photoFrameShape = Q3Frame::NoFrame; if (photo.isNull()) { - pm = qPixmapFromMimeSource("twinkle32.png"); + pm = QPixmap(":/icons/images/twinkle32.png"); } else { pm.convertFromImage(photo); photoFrameShape = Q3Frame::Box; @@ -1656,12 +1655,12 @@ void t_gui::cb_notify_call(int line, const QString &from_party, const QString &o // Answer and reject buttons Q3HBox *buttonBox = new Q3HBox(vb); - QIcon iconAnswer(qPixmapFromMimeSource("answer.png")); + QIcon iconAnswer(QPixmap(":/icons/images/answer.png")); QPushButton *pbAnswer = new QPushButton(iconAnswer, qApp->translate("SysTrayPopup", "Answer"), buttonBox); QObject::connect(pbAnswer, SIGNAL(clicked()), mainWindow, SLOT(phoneAnswerFromSystrayPopup())); - QIcon iconReject(qPixmapFromMimeSource("reject.png")); + QIcon iconReject(QPixmap(":/icons/images/reject.png")); QPushButton *pbReject = new QPushButton(iconReject, qApp->translate("SysTrayPopup", "Reject"), buttonBox); QObject::connect(pbReject, SIGNAL(clicked()), diff --git a/src/gui/gui.h b/src/gui/gui.h index 955a875..9c0cb3b 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -25,7 +25,7 @@ #include "userintf.h" #include "im/msg_session.h" -#include "ui_messageform.h" +#include "messageform.h" #include "qaction.h" #include "qcombobox.h" @@ -43,9 +43,7 @@ using namespace std; // Forward declaration -namespace Ui { class MphoneForm; -} // Length of redial list in combo boxes #define SIZE_REDIAL_LIST 10 @@ -67,7 +65,7 @@ void setDisabledIcon(QToolButton *toolButton, const QString &icon); class t_gui : public QObject, public t_userintf { Q_OBJECT private: - Ui::MphoneForm *mainWindow; + MphoneForm *mainWindow; // List of active instant messaging session. list messageSessions; diff --git a/src/gui/historyform.cpp b/src/gui/historyform.cpp new file mode 100644 index 0000000..690faf0 --- /dev/null +++ b/src/gui/historyform.cpp @@ -0,0 +1,393 @@ +//Added by qt3to4: +#include +#include +#include + +/* + Copyright (C) 2005-2009 Michel de Boer + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "call_history.h" +#include "util.h" +#include "gui.h" +#include "q3listview.h" +#include "historylistview.h" +#include "qicon.h" +#include "audits/memman.h" +#include "historyform.h" +/* + * Constructs a HistoryForm as a child of 'parent', with the + * name 'name' and widget flags set to 'f'. + * + * The dialog will by default be modeless, unless you set 'modal' to + * true to construct a modal dialog. + */ +HistoryForm::HistoryForm(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl) + : QDialog(parent, name, modal, fl) +{ + setupUi(this); + + init(); +} + +/* + * Destroys the object and frees any allocated resources + */ +HistoryForm::~HistoryForm() +{ + destroy(); + // no need to delete child widgets, Qt does it all for us +} + +/* + * Sets the strings of the subwidgets using the current + * language. + */ +void HistoryForm::languageChange() +{ + retranslateUi(this); +} + + +void HistoryForm::init() +{ + historyListView->setSorting(HISTCOL_TIMESTAMP, false); + historyListView->setColumnWidthMode(HISTCOL_FROMTO, Q3ListView::Manual); + historyListView->setColumnWidth(HISTCOL_FROMTO, 200); + historyListView->setColumnWidthMode(HISTCOL_SUBJECT, Q3ListView::Manual); + historyListView->setColumnWidth(HISTCOL_SUBJECT, 200); + + inCheckBox->setChecked(true); + outCheckBox->setChecked(true); + successCheckBox->setChecked(true); + missedCheckBox->setChecked(true); + profileCheckBox->setChecked(true); + + timeLastViewed = phone->get_startup_time(); + + QIcon inviteIcon(QPixmap(":/icons/images/invite.png")); + QIcon deleteIcon(QPixmap(":/icons/images/editdelete.png")); + histPopupMenu = new Q3PopupMenu(this); + MEMMAN_NEW(histPopupMenu); + + itemCall = histPopupMenu->insertItem(inviteIcon, tr("Call..."), this, SLOT(call())); + histPopupMenu->insertItem(deleteIcon, tr("Delete"), this, SLOT(deleteEntry())); +} + +void HistoryForm::destroy() +{ + MEMMAN_DELETE(histPopupMenu); + delete histPopupMenu; +} + +void HistoryForm::loadHistory() +{ + // Create list of all active profile names + QStringList profile_name_list; + listuser_list = phone->ref_users(); + for (list::iterator i = user_list.begin(); i != user_list.end(); i++) { + profile_name_list.append((*i)->get_profile_name().c_str()); + } + + // Fill the history table + unsigned long numberOfCalls = 0; + unsigned long totalCallDuration = 0; + unsigned long totalConversationDuration = 0; + historyListView->clear(); + list history; + call_history->get_history(history); + for (list::iterator i = history.begin(); i != history.end(); i++) { + if (i->direction == t_call_record::DIR_IN && !inCheckBox->isChecked()) { + continue; + } + if (i->direction == t_call_record::DIR_OUT && !outCheckBox->isChecked()) { + continue; + } + if (i->invite_resp_code < 300 && !successCheckBox->isChecked()) { + continue; + } + if (i->invite_resp_code >= 300 && !missedCheckBox->isChecked()) { + continue; + } + if (!profile_name_list.contains(i->user_profile.c_str()) && + profileCheckBox->isChecked()) + { + continue; + } + + numberOfCalls++; + + // Calculate total duration + totalCallDuration += i->time_end - i->time_start; + if (i->time_answer != 0) { + totalConversationDuration += i->time_end - i->time_answer; + } + + t_user *user_config = phone->ref_user_profile(i->user_profile); + + // If the user profile is not active, then use the + // first user profile for formatting + if (!user_config) { + user_config = phone->ref_users().front(); + } + + new HistoryListViewItem(historyListView, + *i, user_config, timeLastViewed); + } + + numberCallsValueTextLabel->setText(QString().setNum(numberOfCalls)); + + // Total call duration formatting + QString durationText = duration2str(totalCallDuration).c_str(); + durationText += " ("; + durationText += tr("conversation"); + durationText += ": "; + durationText += duration2str(totalConversationDuration).c_str(); + durationText += ")"; + totalDurationValueTextLabel->setText(durationText); + + // Make the first entry the selected entry. + Q3ListViewItem *first = historyListView->firstChild(); + if (first) { + historyListView->setSelected(first, true); + showCallDetails(first); + } else { + cdrTextEdit->clear(); + } +} + +// Update history when triggered by a call back function on the user +// interface. +void HistoryForm::update() +{ + // There is no need to update the history when the window is + // hidden. + if (isShown()) loadHistory(); +} + +void HistoryForm::show() +{ + if (isShown()) { + raise(); + setActiveWindow(); + return; + } + + loadHistory(); + QDialog::show(); + raise(); +} + +void HistoryForm::closeEvent( QCloseEvent *e ) +{ + struct timeval t; + + gettimeofday(&t, NULL); + timeLastViewed = t.tv_sec; + + // If Twinkle is terminated while the history window is + // shown, then the call_history object is destroyed, before this + // window is closed. + if (call_history) { + call_history->clear_num_missed_calls(); + } + QDialog::closeEvent(e); +} + +void HistoryForm::showCallDetails(Q3ListViewItem *item) +{ + QString s; + + t_call_record cr = ((HistoryListViewItem *)item)->get_call_record(); + cdrTextEdit->clear(); + + t_user *user_config = phone->ref_user_profile(cr.user_profile); + // If the user profile is not active, then use the + // first user profile for formatting + if (!user_config) { + user_config = phone->ref_users().front(); + } + + s = ""; + + // Left column: header names + s += ""; + + // Right column: values + s += ""; + + s += "
"; + s += tr("Call start:") + "
"; + s += tr("Call answer:") + "
"; + s += tr("Call end:") + "
"; + s += tr("Call duration:") + "
"; + s += tr("Direction:") + "
"; + s += tr("From:") + "
"; + s += tr("To:") + "
"; + if (cr.reply_to_uri.is_valid()) s += tr("Reply to:") + "
"; + if (cr.referred_by_uri.is_valid()) s += tr("Referred by:") + "
"; + s += tr("Subject:") + "
"; + s += tr("Released by:") + "
"; + s += tr("Status:") + "
"; + if (!cr.far_end_device.empty()) s += tr("Far end device:") + "
"; + s += tr("User profile:"); + s += "
"; + s += time2str(cr.time_start, "%d %b %Y %H:%M:%S").c_str(); + s += "
"; + if (cr.time_answer != 0) { + s += time2str(cr.time_answer, "%d %b %Y %H:%M:%S").c_str(); + } + s += "
"; + s += time2str(cr.time_end, "%d %b %Y %H:%M:%S").c_str(); + s += "
"; + + s += duration2str((unsigned long)(cr.time_end - cr.time_start)).c_str(); + if (cr.time_answer != 0) { + s += " ("; + s += tr("conversation"); + s += ": "; + s += duration2str((unsigned long)(cr.time_end - cr.time_answer)).c_str(); + s += ")"; + } + s += "
"; + + s += cr.get_direction().c_str(); + s += "
"; + s += str2html(ui->format_sip_address(user_config, cr.from_display, cr.from_uri).c_str()); + if (cr.from_organization != "") { + s += ", "; + s += str2html(cr.from_organization.c_str()); + } + s += "
"; + s += str2html(ui->format_sip_address(user_config, cr.to_display, cr.to_uri).c_str()); + if (cr.to_organization != "") { + s += ", "; + s += str2html(cr.to_organization.c_str()); + } + s += "
"; + if (cr.reply_to_uri.is_valid()) { + s += str2html(ui->format_sip_address(user_config, + cr.reply_to_display, cr.reply_to_uri).c_str()); + s += "
"; + } + if (cr.referred_by_uri.is_valid()) { + s += str2html(ui->format_sip_address(user_config, + cr.referred_by_display, cr.referred_by_uri).c_str()); + s += "
"; + } + s += str2html(cr.subject.c_str()); + s += "
"; + s += cr.get_rel_cause().c_str(); + s += "
"; + s += int2str(cr.invite_resp_code).c_str(); + s += ' '; + s += str2html(cr.invite_resp_reason.c_str()); + s += "
"; + if (!cr.far_end_device.empty()) { + s += str2html(cr.far_end_device.c_str()); + s += "
"; + } + s += str2html(cr.user_profile.c_str()); + s += "
"; + + cdrTextEdit->setText(s); +} + +void HistoryForm::popupMenu(Q3ListViewItem *item, const QPoint &pos) +{ + if (!item) return; + + HistoryListViewItem *histItem = dynamic_cast(item); + if (!histItem) return; + + t_call_record cr = histItem->get_call_record(); + + // An anonymous caller cannot be called + bool canCall = !(cr.direction == t_call_record::DIR_IN && + cr.from_uri.encode() == ANONYMOUS_URI); + + histPopupMenu->setItemEnabled(itemCall, canCall); + histPopupMenu->popup(pos); +} + +void HistoryForm::call(Q3ListViewItem *item) +{ + if (!item) return; + + HistoryListViewItem *histItem = (HistoryListViewItem *)item; + t_call_record cr = histItem->get_call_record(); + + t_user *user_config = phone->ref_user_profile(cr.user_profile); + // If the user profile is not active, then use the first profile + if (!user_config) { + user_config = phone->ref_users().front(); + } + + // Determine subject + QString subject; + if (cr.direction == t_call_record::DIR_IN) { + if (!cr.subject.empty()) { + if (cr.subject.substr(0, tr("Re:").length()) != tr("Re:").ascii()) { + subject = tr("Re:").append(" "); + subject += cr.subject.c_str(); + } else { + subject = cr.subject.c_str(); + } + } + } else { + subject = cr.subject.c_str(); + } + + // Send call signal + if (cr.direction == t_call_record::DIR_IN && cr.reply_to_uri.is_valid()) { + // Call to the Reply-To contact + emit call(user_config, + ui->format_sip_address(user_config, + cr.reply_to_display, cr.reply_to_uri).c_str(), + subject, false); + } else { + // For incoming calls, call to the From contact + // For outgoing calls, call to the To contact + bool hide_user = false; + if (cr.direction == t_call_record::DIR_OUT && + cr.from_uri.encode() == ANONYMOUS_URI) + { + hide_user = true; + } + emit call(user_config, item->text(HISTCOL_FROMTO), subject, hide_user); + } +} + +void HistoryForm::call(void) +{ + Q3ListViewItem *item = historyListView->currentItem(); + if (item) call(item); +} + +void HistoryForm::deleteEntry(void) +{ + Q3ListViewItem *item = historyListView->currentItem(); + HistoryListViewItem *histItem = dynamic_cast(item); + if (!histItem) return; + + call_history->delete_call_record(histItem->get_call_record().get_id()); +} + +void HistoryForm::clearHistory() +{ + call_history->clear(); +} diff --git a/src/gui/historyform.h b/src/gui/historyform.h new file mode 100644 index 0000000..6de4fc5 --- /dev/null +++ b/src/gui/historyform.h @@ -0,0 +1,45 @@ +#ifndef HISTORYFORM_H +#define HISTORYFORM_H +#include "phone.h" +#include +#include "user.h" +#include "ui_historyform.h" + +class HistoryForm : public QDialog, public Ui::HistoryForm +{ + Q_OBJECT + +public: + HistoryForm(QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WindowFlags fl = 0); + ~HistoryForm(); + +public slots: + virtual void loadHistory(); + virtual void update(); + virtual void show(); + virtual void closeEvent( QCloseEvent * e ); + virtual void showCallDetails( Q3ListViewItem * item ); + virtual void popupMenu( Q3ListViewItem * item, const QPoint & pos ); + virtual void call( Q3ListViewItem * item ); + virtual void call( void ); + virtual void deleteEntry( void ); + virtual void clearHistory(); + +signals: + void call(t_user *, const QString &, const QString &, bool); + +protected slots: + virtual void languageChange(); + +private: + time_t timeLastViewed; + Q3PopupMenu *histPopupMenu; + int itemCall; + + void init(); + void destroy(); + +}; + + +#endif diff --git a/src/gui/historyform.ui.h b/src/gui/historyform.ui.h deleted file mode 100644 index 72823d7..0000000 --- a/src/gui/historyform.ui.h +++ /dev/null @@ -1,362 +0,0 @@ -//Added by qt3to4: -#include -#include -#include -/**************************************************************************** -** ui.h extension file, included from the uic-generated form implementation. -** -** If you want to add, delete, or rename functions or slots, use -** Qt Designer to update this file, preserving your code. -** -** You should not define a constructor or destructor in this file. -** Instead, write your code in functions called init() and destroy(). -** These will automatically be called by the form's constructor and -** destructor. -*****************************************************************************/ - -/* - Copyright (C) 2005-2009 Michel de Boer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -void HistoryForm::init() -{ - historyListView->setSorting(HISTCOL_TIMESTAMP, false); - historyListView->setColumnWidthMode(HISTCOL_FROMTO, Q3ListView::Manual); - historyListView->setColumnWidth(HISTCOL_FROMTO, 200); - historyListView->setColumnWidthMode(HISTCOL_SUBJECT, Q3ListView::Manual); - historyListView->setColumnWidth(HISTCOL_SUBJECT, 200); - - inCheckBox->setChecked(true); - outCheckBox->setChecked(true); - successCheckBox->setChecked(true); - missedCheckBox->setChecked(true); - profileCheckBox->setChecked(true); - - timeLastViewed = phone->get_startup_time(); - - QIcon inviteIcon(qPixmapFromMimeSource("invite.png")); - QIcon deleteIcon(qPixmapFromMimeSource("editdelete.png")); - histPopupMenu = new Q3PopupMenu(this); - MEMMAN_NEW(histPopupMenu); - - itemCall = histPopupMenu->insertItem(inviteIcon, tr("Call..."), this, SLOT(call())); - histPopupMenu->insertItem(deleteIcon, tr("Delete"), this, SLOT(deleteEntry())); -} - -void HistoryForm::destroy() -{ - MEMMAN_DELETE(histPopupMenu); - delete histPopupMenu; -} - -void HistoryForm::loadHistory() -{ - // Create list of all active profile names - QStringList profile_name_list; - listuser_list = phone->ref_users(); - for (list::iterator i = user_list.begin(); i != user_list.end(); i++) { - profile_name_list.append((*i)->get_profile_name().c_str()); - } - - // Fill the history table - unsigned long numberOfCalls = 0; - unsigned long totalCallDuration = 0; - unsigned long totalConversationDuration = 0; - historyListView->clear(); - list history; - call_history->get_history(history); - for (list::iterator i = history.begin(); i != history.end(); i++) { - if (i->direction == t_call_record::DIR_IN && !inCheckBox->isChecked()) { - continue; - } - if (i->direction == t_call_record::DIR_OUT && !outCheckBox->isChecked()) { - continue; - } - if (i->invite_resp_code < 300 && !successCheckBox->isChecked()) { - continue; - } - if (i->invite_resp_code >= 300 && !missedCheckBox->isChecked()) { - continue; - } - if (!profile_name_list.contains(i->user_profile.c_str()) && - profileCheckBox->isChecked()) - { - continue; - } - - numberOfCalls++; - - // Calculate total duration - totalCallDuration += i->time_end - i->time_start; - if (i->time_answer != 0) { - totalConversationDuration += i->time_end - i->time_answer; - } - - t_user *user_config = phone->ref_user_profile(i->user_profile); - - // If the user profile is not active, then use the - // first user profile for formatting - if (!user_config) { - user_config = phone->ref_users().front(); - } - - new HistoryListViewItem(historyListView, - *i, user_config, timeLastViewed); - } - - numberCallsValueTextLabel->setText(QString().setNum(numberOfCalls)); - - // Total call duration formatting - QString durationText = duration2str(totalCallDuration).c_str(); - durationText += " ("; - durationText += tr("conversation"); - durationText += ": "; - durationText += duration2str(totalConversationDuration).c_str(); - durationText += ")"; - totalDurationValueTextLabel->setText(durationText); - - // Make the first entry the selected entry. - Q3ListViewItem *first = historyListView->firstChild(); - if (first) { - historyListView->setSelected(first, true); - showCallDetails(first); - } else { - cdrTextEdit->clear(); - } -} - -// Update history when triggered by a call back function on the user -// interface. -void HistoryForm::update() -{ - // There is no need to update the history when the window is - // hidden. - if (isShown()) loadHistory(); -} - -void HistoryForm::show() -{ - if (isShown()) { - raise(); - setActiveWindow(); - return; - } - - loadHistory(); - QDialog::show(); - raise(); -} - -void HistoryForm::closeEvent( QCloseEvent *e ) -{ - struct timeval t; - - gettimeofday(&t, NULL); - timeLastViewed = t.tv_sec; - - // If Twinkle is terminated while the history window is - // shown, then the call_history object is destroyed, before this - // window is closed. - if (call_history) { - call_history->clear_num_missed_calls(); - } - QDialog::closeEvent(e); -} - -void HistoryForm::showCallDetails(Q3ListViewItem *item) -{ - QString s; - - t_call_record cr = ((HistoryListViewItem *)item)->get_call_record(); - cdrTextEdit->clear(); - - t_user *user_config = phone->ref_user_profile(cr.user_profile); - // If the user profile is not active, then use the - // first user profile for formatting - if (!user_config) { - user_config = phone->ref_users().front(); - } - - s = ""; - - // Left column: header names - s += ""; - - // Right column: values - s += ""; - - s += "
"; - s += tr("Call start:") + "
"; - s += tr("Call answer:") + "
"; - s += tr("Call end:") + "
"; - s += tr("Call duration:") + "
"; - s += tr("Direction:") + "
"; - s += tr("From:") + "
"; - s += tr("To:") + "
"; - if (cr.reply_to_uri.is_valid()) s += tr("Reply to:") + "
"; - if (cr.referred_by_uri.is_valid()) s += tr("Referred by:") + "
"; - s += tr("Subject:") + "
"; - s += tr("Released by:") + "
"; - s += tr("Status:") + "
"; - if (!cr.far_end_device.empty()) s += tr("Far end device:") + "
"; - s += tr("User profile:"); - s += "
"; - s += time2str(cr.time_start, "%d %b %Y %H:%M:%S").c_str(); - s += "
"; - if (cr.time_answer != 0) { - s += time2str(cr.time_answer, "%d %b %Y %H:%M:%S").c_str(); - } - s += "
"; - s += time2str(cr.time_end, "%d %b %Y %H:%M:%S").c_str(); - s += "
"; - - s += duration2str((unsigned long)(cr.time_end - cr.time_start)).c_str(); - if (cr.time_answer != 0) { - s += " ("; - s += tr("conversation"); - s += ": "; - s += duration2str((unsigned long)(cr.time_end - cr.time_answer)).c_str(); - s += ")"; - } - s += "
"; - - s += cr.get_direction().c_str(); - s += "
"; - s += str2html(ui->format_sip_address(user_config, cr.from_display, cr.from_uri).c_str()); - if (cr.from_organization != "") { - s += ", "; - s += str2html(cr.from_organization.c_str()); - } - s += "
"; - s += str2html(ui->format_sip_address(user_config, cr.to_display, cr.to_uri).c_str()); - if (cr.to_organization != "") { - s += ", "; - s += str2html(cr.to_organization.c_str()); - } - s += "
"; - if (cr.reply_to_uri.is_valid()) { - s += str2html(ui->format_sip_address(user_config, - cr.reply_to_display, cr.reply_to_uri).c_str()); - s += "
"; - } - if (cr.referred_by_uri.is_valid()) { - s += str2html(ui->format_sip_address(user_config, - cr.referred_by_display, cr.referred_by_uri).c_str()); - s += "
"; - } - s += str2html(cr.subject.c_str()); - s += "
"; - s += cr.get_rel_cause().c_str(); - s += "
"; - s += int2str(cr.invite_resp_code).c_str(); - s += ' '; - s += str2html(cr.invite_resp_reason.c_str()); - s += "
"; - if (!cr.far_end_device.empty()) { - s += str2html(cr.far_end_device.c_str()); - s += "
"; - } - s += str2html(cr.user_profile.c_str()); - s += "
"; - - cdrTextEdit->setText(s); -} - -void HistoryForm::popupMenu(Q3ListViewItem *item, const QPoint &pos) -{ - if (!item) return; - - HistoryListViewItem *histItem = dynamic_cast(item); - if (!histItem) return; - - t_call_record cr = histItem->get_call_record(); - - // An anonymous caller cannot be called - bool canCall = !(cr.direction == t_call_record::DIR_IN && - cr.from_uri.encode() == ANONYMOUS_URI); - - histPopupMenu->setItemEnabled(itemCall, canCall); - histPopupMenu->popup(pos); -} - -void HistoryForm::call(Q3ListViewItem *item) -{ - if (!item) return; - - HistoryListViewItem *histItem = (HistoryListViewItem *)item; - t_call_record cr = histItem->get_call_record(); - - t_user *user_config = phone->ref_user_profile(cr.user_profile); - // If the user profile is not active, then use the first profile - if (!user_config) { - user_config = phone->ref_users().front(); - } - - // Determine subject - QString subject; - if (cr.direction == t_call_record::DIR_IN) { - if (!cr.subject.empty()) { - if (cr.subject.substr(0, tr("Re:").length()) != tr("Re:").ascii()) { - subject = tr("Re:").append(" "); - subject += cr.subject.c_str(); - } else { - subject = cr.subject.c_str(); - } - } - } else { - subject = cr.subject.c_str(); - } - - // Send call signal - if (cr.direction == t_call_record::DIR_IN && cr.reply_to_uri.is_valid()) { - // Call to the Reply-To contact - emit call(user_config, - ui->format_sip_address(user_config, - cr.reply_to_display, cr.reply_to_uri).c_str(), - subject, false); - } else { - // For incoming calls, call to the From contact - // For outgoing calls, call to the To contact - bool hide_user = false; - if (cr.direction == t_call_record::DIR_OUT && - cr.from_uri.encode() == ANONYMOUS_URI) - { - hide_user = true; - } - emit call(user_config, item->text(HISTCOL_FROMTO), subject, hide_user); - } -} - -void HistoryForm::call(void) -{ - Q3ListViewItem *item = historyListView->currentItem(); - if (item) call(item); -} - -void HistoryForm::deleteEntry(void) -{ - Q3ListViewItem *item = historyListView->currentItem(); - HistoryListViewItem *histItem = dynamic_cast(item); - if (!histItem) return; - - call_history->delete_call_record(histItem->get_call_record().get_id()); -} - -void HistoryForm::clearHistory() -{ - call_history->clear(); -} diff --git a/src/gui/historylistview.cpp b/src/gui/historylistview.cpp index 575801c..666f3ac 100644 --- a/src/gui/historylistview.cpp +++ b/src/gui/historylistview.cpp @@ -41,13 +41,13 @@ HistoryListViewItem::HistoryListViewItem( Q3ListView * parent, const t_call_reco // Set direction icon setPixmap(HISTCOL_DIRECTION, (cr.direction == t_call_record::DIR_IN ? - qPixmapFromMimeSource("1leftarrow-yellow.png") : - qPixmapFromMimeSource("1rightarrow.png"))); + QPixmap(":/icons/images/1leftarrow-yellow.png") : + QPixmap(":/icons/images/1rightarrow.png"))); // Set status icon setPixmap(HISTCOL_STATUS, (cr.invite_resp_code < 300 ? - qPixmapFromMimeSource("ok.png") : - qPixmapFromMimeSource("cancel.png"))); + QPixmap(":/icons/images/ok.png") : + QPixmap(":/icons/images/cancel.png"))); } void HistoryListViewItem::paintCell(QPainter *painter, const QColorGroup &cg, diff --git a/src/gui/inviteform.cpp b/src/gui/inviteform.cpp new file mode 100644 index 0000000..0ec1ddd --- /dev/null +++ b/src/gui/inviteform.cpp @@ -0,0 +1,167 @@ +#include "inviteform.h" +//Added by qt3to4: +#include +#include "gui.h" +#include "util.h" +#include "audits/memman.h" +#include "sys_settings.h" +#include +#include + +/* + Copyright (C) 2005-2009 Michel de Boer + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +InviteForm::InviteForm(QWidget *parent, const char *name, bool modal) + : QDialog(parent, name, modal) +{ + setupUi(this); + init(); +} + +InviteForm::~InviteForm() +{ + destroy(); +} + +void InviteForm::init() +{ + getAddressForm = 0; + + // Set toolbutton icons for disabled options. + setDisabledIcon(addressToolButton, ":/icons/images/kontact_contacts-disabled.png"); + + // A QComboBox accepts a new line through copy/paste. + QRegExp rxNoNewLine("[^\\n\\r]*"); + inviteComboBox->setValidator(new QRegExpValidator(rxNoNewLine, this)); +} + +void InviteForm::destroy() +{ + if (getAddressForm) { + MEMMAN_DELETE(getAddressForm); + delete getAddressForm; + } +} + +void InviteForm::clear() +{ + inviteComboBox->clearEdit(); + subjectLineEdit->clear(); + hideUserCheckBox->setChecked(false); + inviteComboBox->setFocus(); +} + +void InviteForm::show(t_user *user_config, const QString &dest, const QString &subject, + bool anonymous) +{ + ((t_gui *)ui)->fill_user_combo(fromComboBox); + + // Select from user + if (user_config) { + for (int i = 0; i < fromComboBox->count(); i++) { + if (fromComboBox->text(i) == + user_config->get_profile_name().c_str()) + { + fromComboBox->setCurrentItem(i); + break; + } + } + } + + inviteComboBox->setEditText(dest); + subjectLineEdit->setText(subject); + hideUserCheckBox->setChecked(anonymous); + QDialog::show(); +} + +void InviteForm::validate() +{ + string display, dest_str; + t_user *from_user = phone->ref_user_profile( + fromComboBox->currentText().ascii()); + + ui->expand_destination(from_user, + inviteComboBox->currentText().stripWhiteSpace().ascii(), + display, dest_str); + t_url dest(dest_str); + + if (dest.is_valid()) { + addToInviteComboBox(inviteComboBox->currentText()); + emit raw_destination(inviteComboBox->currentText()); + emit destination(from_user, display.c_str(), dest, subjectLineEdit->text(), + hideUserCheckBox->isChecked()); + accept(); + } else { + inviteComboBox->setFocus(); + inviteComboBox->lineEdit()->selectAll(); + } +} + +// Add a destination to the history list of inviteComboBox +void InviteForm::addToInviteComboBox(const QString &destination) +{ + inviteComboBox->insertItem(destination, 0); + if (inviteComboBox->count() > SIZE_REDIAL_LIST) { + inviteComboBox->removeItem(inviteComboBox->count() - 1); + } +} + + +void InviteForm::reject() +{ + // Unseize the line + ((t_gui *)ui)->action_unseize(); + QDialog::reject(); +} + +void InviteForm::closeEvent(QCloseEvent *) +{ + reject(); +} + +void InviteForm::showAddressBook() +{ + if (!getAddressForm) { + getAddressForm = new GetAddressForm( + this, "select address", true); + MEMMAN_NEW(getAddressForm); + } + + connect(getAddressForm, + SIGNAL(address(const QString &)), + this, SLOT(selectedAddress(const QString &))); + + getAddressForm->show(); +} + +void InviteForm::selectedAddress(const QString &address) +{ + inviteComboBox->setEditText(address); +} + +void InviteForm::warnHideUser(void) { + // Warn only once + if (!sys_config->get_warn_hide_user()) return; + + QString msg = tr("Not all SIP providers support identity hiding. Make sure your SIP provider " + "supports it if you really need it."); + ((t_gui *)ui)->cb_show_msg(this, msg.ascii(), MSG_WARNING); + + // Do not warn again + sys_config->set_warn_hide_user(false); +} diff --git a/src/gui/inviteform.h b/src/gui/inviteform.h new file mode 100644 index 0000000..337667b --- /dev/null +++ b/src/gui/inviteform.h @@ -0,0 +1,39 @@ +#ifndef INVITEFORM_UI_H +#define INVITEFORM_UI_H +#include "ui_inviteform.h" +#include "sockets/url.h" +#include "getaddressform.h" +#include "user.h" +#include "phone.h" +#include + +class t_phone; +extern t_phone *phone; + +class InviteForm : public QDialog, public Ui::InviteForm +{ + Q_OBJECT +public: + InviteForm(QWidget *parent, const char *name, bool modal); + ~InviteForm(); +public slots: + void clear(); + void show( t_user * user_config, const QString & dest, const QString & subject, bool anonymous ); + void validate(); + void addToInviteComboBox( const QString & destination ); + void reject(); + void closeEvent( QCloseEvent * ); + void showAddressBook(); + void selectedAddress( const QString & address ); + void warnHideUser( void ); +signals: + void destination(t_user *, const QString &, const t_url &, const QString &, bool); + void raw_destination(const QString &); +private: + void init(); + void destroy(); + + GetAddressForm *getAddressForm; +}; + +#endif diff --git a/src/gui/inviteform.ui.h b/src/gui/inviteform.ui.h deleted file mode 100644 index 5f3a9bc..0000000 --- a/src/gui/inviteform.ui.h +++ /dev/null @@ -1,155 +0,0 @@ -//Added by qt3to4: -#include -/**************************************************************************** -** ui.h extension file, included from the uic-generated form implementation. -** -** If you wish to add, delete or rename functions or slots use -** Qt Designer which will update this file, preserving your code. Create an -** init() function in place of a constructor, and a destroy() function in -** place of a destructor. -*****************************************************************************/ -/* - Copyright (C) 2005-2009 Michel de Boer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -void InviteForm::init() -{ - getAddressForm = 0; - - // Set toolbutton icons for disabled options. - setDisabledIcon(addressToolButton, "kontact_contacts-disabled.png"); - - // A QComboBox accepts a new line through copy/paste. - QRegExp rxNoNewLine("[^\\n\\r]*"); - inviteComboBox->setValidator(new QRegExpValidator(rxNoNewLine, this)); -} - -void InviteForm::destroy() -{ - if (getAddressForm) { - MEMMAN_DELETE(getAddressForm); - delete getAddressForm; - } -} - -void InviteForm::clear() -{ - inviteComboBox->clearEdit(); - subjectLineEdit->clear(); - hideUserCheckBox->setChecked(false); - inviteComboBox->setFocus(); -} - -void InviteForm::show(t_user *user_config, const QString &dest, const QString &subject, - bool anonymous) -{ - ((t_gui *)ui)->fill_user_combo(fromComboBox); - - // Select from user - if (user_config) { - for (int i = 0; i < fromComboBox->count(); i++) { - if (fromComboBox->text(i) == - user_config->get_profile_name().c_str()) - { - fromComboBox->setCurrentItem(i); - break; - } - } - } - - inviteComboBox->setEditText(dest); - subjectLineEdit->setText(subject); - hideUserCheckBox->setChecked(anonymous); - QDialog::show(); -} - -void InviteForm::validate() -{ - string display, dest_str; - t_user *from_user = phone->ref_user_profile( - fromComboBox->currentText().ascii()); - - ui->expand_destination(from_user, - inviteComboBox->currentText().stripWhiteSpace().ascii(), - display, dest_str); - t_url dest(dest_str); - - if (dest.is_valid()) { - addToInviteComboBox(inviteComboBox->currentText()); - emit raw_destination(inviteComboBox->currentText()); - emit destination(from_user, display.c_str(), dest, subjectLineEdit->text(), - hideUserCheckBox->isChecked()); - accept(); - } else { - inviteComboBox->setFocus(); - inviteComboBox->lineEdit()->selectAll(); - } -} - -// Add a destination to the history list of inviteComboBox -void InviteForm::addToInviteComboBox(const QString &destination) -{ - inviteComboBox->insertItem(destination, 0); - if (inviteComboBox->count() > SIZE_REDIAL_LIST) { - inviteComboBox->removeItem(inviteComboBox->count() - 1); - } -} - - -void InviteForm::reject() -{ - // Unseize the line - ((t_gui *)ui)->action_unseize(); - QDialog::reject(); -} - -void InviteForm::closeEvent(QCloseEvent *) -{ - reject(); -} - -void InviteForm::showAddressBook() -{ - if (!getAddressForm) { - getAddressForm = new GetAddressForm( - this, "select address", true); - MEMMAN_NEW(getAddressForm); - } - - connect(getAddressForm, - SIGNAL(address(const QString &)), - this, SLOT(selectedAddress(const QString &))); - - getAddressForm->show(); -} - -void InviteForm::selectedAddress(const QString &address) -{ - inviteComboBox->setEditText(address); -} - -void InviteForm::warnHideUser(void) { - // Warn only once - if (!sys_config->get_warn_hide_user()) return; - - QString msg = tr("Not all SIP providers support identity hiding. Make sure your SIP provider " - "supports it if you really need it."); - ((t_gui *)ui)->cb_show_msg(this, msg.ascii(), MSG_WARNING); - - // Do not warn again - sys_config->set_warn_hide_user(false); -} diff --git a/src/gui/messageform.cpp b/src/gui/messageform.cpp new file mode 100644 index 0000000..ad801be --- /dev/null +++ b/src/gui/messageform.cpp @@ -0,0 +1,657 @@ + + +/* + Copyright (C) 2005-2009 Michel de Boer + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifdef HAVE_KDE +#include +#include +#include +#include +#include +#else +#include "utils/mime_database.h" +//Added by qt3to4: +#include +#include +#include +#include +#include +#include +#endif + +#include "gui.h" +#include "sockets/url.h" +#include +#include "audits/memman.h" +#include "util.h" +#include +#include +#include +#include "utils/file_utils.h" +#include +#include "sendfileform.h" +#include +#include +#include "messageform.h" + + +using namespace utils; + +/** Maximum width for an inline image */ +#define MAX_WIDTH_IMG_INLINE 400 + +/** Maximum height for an inline image */ +#define MAX_HEIGHT_IMG_INLINE 400 + +#define IMG_SCALE_FACTOR(width, height) (std::min( float(MAX_WIDTH_IMG_INLINE) / (width), float(MAX_HEIGHT_IMG_INLINE) / (height) ) ) + +MessageForm::MessageForm(QWidget* parent, const char* name, Qt::WindowFlags fl) + : Q3MainWindow(parent, name, fl) +{ + setupUi(this); + + (void)statusBar(); + init(); +} + +/* + * Destroys the object and frees any allocated resources + */ +MessageForm::~MessageForm() +{ + destroy(); + // no need to delete child widgets, Qt does it all for us +} + +/* + * Sets the strings of the subwidgets using the current + * language. + */ +void MessageForm::languageChange() +{ + retranslateUi(this); +} + + +void MessageForm::init() +{ + setWindowFlags(windowFlags() | Qt::WDestructiveClose); + + _getAddressForm = 0; + _remotePartyComplete = false; + + // Add label to display size of typed message + _msgSizeLabel = new QLabel(this); + statusBar()->addWidget(_msgSizeLabel); + showMessageSize(); + + // Set toolbutton icons for disabled options. + setDisabledIcon(addressToolButton, "kontact_contacts-disabled.png"); + + attachmentPopupMenu = new Q3PopupMenu(this); + MEMMAN_NEW(attachmentPopupMenu); + + connect(attachmentPopupMenu, SIGNAL(activated(int)), + this, SLOT(attachmentPopupActivated(int))); + + _serviceMap = NULL; + _saveAsDialog = NULL; + + _isComposingLabel = NULL; + + // When the user edits the message, the composition indication + // will be set to active. + connect(msgLineEdit, SIGNAL(textChanged(const QString &)), + this, SLOT(setLocalComposingIndicationActive())); +} + +void MessageForm::destroy() +{ + if (_getAddressForm) { + MEMMAN_DELETE(_getAddressForm); + delete _getAddressForm; + } + + MEMMAN_DELETE(attachmentPopupMenu); + delete attachmentPopupMenu; + +#ifdef HAVE_KDE + vector *serviceMap = (vector *)_serviceMap; + if (serviceMap) { + MEMMAN_DELETE(serviceMap); + delete serviceMap; + } +#endif + + if (_saveAsDialog) { + MEMMAN_DELETE(_saveAsDialog); + delete _saveAsDialog; + } + + if (_isComposingLabel) { + MEMMAN_DELETE(_isComposingLabel); + delete _isComposingLabel; + } +} + +void MessageForm::closeEvent(QCloseEvent *e) +{ + MEMMAN_DELETE(this); // destructive close + Q3MainWindow::closeEvent(e); +} + + +void MessageForm::show() +{ + if (toLineEdit->text().isEmpty()) { + sendFileAction->setEnabled(false); + toLineEdit->setFocus(); + } else { + // Once a message session has been created, the + // source and destination cannot be changed anymore. + fromComboBox->setEnabled(false); + toLineEdit->setEnabled(false); + addressToolButton->setEnabled(false); + sendFileAction->setEnabled(true); + msgLineEdit->setFocus(); + } + + Q3MainWindow::show(); +} + +void MessageForm::selectUserConfig(t_user *user_config) +{ + for (int i = 0; i < fromComboBox->count(); i++) { + if (fromComboBox->text(i) == + user_config->get_profile_name().c_str()) + { + fromComboBox->setCurrentItem(i); + break; + } + } +} + +void MessageForm::showAddressBook() +{ + if (!_getAddressForm) { + _getAddressForm = new GetAddressForm( + this, "select address", true); + MEMMAN_NEW(_getAddressForm); + } + + connect(_getAddressForm, + SIGNAL(address(const QString &)), + this, SLOT(selectedAddress(const QString &))); + + _getAddressForm->show(); +} + +void MessageForm::selectedAddress(const QString &address) +{ + toLineEdit->setText(address); +} + +/** + * Check if there is a valid sender and receiver. If so, then set the sender + * and receiver addresses in the message session object. + */ +bool MessageForm::updateMessageSession() +{ + string display, dest_str; + t_user *from_user = phone->ref_user_profile( + fromComboBox->currentText().ascii()); + if (!from_user) { + // The user profile is not active anymore + fromComboBox->setFocus(); + return false; + } + + ui->expand_destination(from_user, toLineEdit->text().stripWhiteSpace().ascii(), + display, dest_str); + t_url dest(dest_str); + + if (!dest.is_valid()) { + toLineEdit->setFocus(); + toLineEdit->selectAll(); + return false; + } + + _msgSession->set_user(from_user); + _msgSession->set_remote_party(t_display_url(dest, display)); + + setRemotePartyCaption(); + + return true; +} + +/** + * Determine if a message can be sent, i.e. there is a valid sender and + * receiver. If a message can be sent, then lock the sender and receiver. + * @return True if message can be sent, false otherwise. + */ +bool MessageForm::prepareSendMessage() { + if (toLineEdit->text().isEmpty()) { + // No recipient selected. + return false; + } + + if (toLineEdit->isEnabled()) { + if (!updateMessageSession()) { + // No valid sender and receiver. + return false; + } + + // Once a message session has been created, the + // source and destination cannot be changed anymore. + fromComboBox->setEnabled(false); + toLineEdit->setEnabled(false); + addressToolButton->setEnabled(false); + + } + + return true; +} + +/** Send a text message */ +void MessageForm::sendMessage() { + if (msgLineEdit->text().isEmpty()) { + // Nothing to send + return; + } + + if (!prepareSendMessage()) { + return; + } + + _msgSession->send_msg(msgLineEdit->text().ascii(), im::TXT_PLAIN); +} + +/** + * Send a file. + * @param filename [in] Name of file to send. + * @param subject [in] Subject to set in the message. + */ +void MessageForm::sendFile(const QString &filename, const QString &subject) { + if (!prepareSendMessage()) { + return; + } + + t_media media("application/octet-stream"); + +#ifdef HAVE_KDE + // Get mime type for the attachment + KMimeType::Ptr pMime = KMimeType::findByURL(filename); + media = t_media(pMime->name().ascii()); +#else + string mime_type = mime_database->get_mimetype(filename.ascii()); + if (!mime_type.empty()) { + media = t_media(mime_type); + } +#endif + + _msgSession->send_file(filename.ascii(), media, subject.ascii()); +} + +/** + * Add a message to the converstation broswer. + * @param msg [in] The message to add. + * @param name [in] The name of the sender of the message. + */ +void MessageForm::addMessage(const im::t_msg &msg, const QString &name) +{ + QString s = ""; + + // Timestamp and name of sender + if (msg.direction == im::MSG_DIR_IN) s += ""; + s += time2str(msg.timestamp, "%H:%M:%S ").c_str(); + s += Q3StyleSheet::escape(name); + if (msg.direction == im::MSG_DIR_IN) s += ""; + s += ""; + + // Subject + if (!msg.subject.empty()) { + s += "
"; + s += ""; + s += "Subject: "; + s += ""; + s += msg.subject.c_str(); + } + + // Text message + if (!msg.message.empty()) { + s += "
"; + if (msg.format == im::TXT_HTML) { + s += msg.message.c_str(); + } else { + s += Q3StyleSheet::escape(msg.message.c_str()); + } + } + + // Attachment + if (msg.has_attachment) { + s += "
"; + s += ""; + + bool show_attachment_inline = false; + bool scale_image = false; + int scaled_width = 0, scaled_height = 0; + + if (msg.attachment_media.type == "image") { + // Show image inline if possible + QPixmap image (msg.attachment_filename.c_str()); + if (!image.isNull()) { + show_attachment_inline = true; + if (image.width() > MAX_WIDTH_IMG_INLINE && + image.height() > MAX_HEIGHT_IMG_INLINE) + { + // Shrink image + scaled_width = int(image.width() * IMG_SCALE_FACTOR(image.width(), image.height())); + scaled_height = int(image.height() * IMG_SCALE_FACTOR(image.width(), image.height())); + scale_image = true; + } + } + } + + s += ""; + s+= "
"; + + s += msg.attachment_save_as_name.c_str(); + + s += "
"; + + if (scale_image) { + s += "
"; + s += ""; + s += tr("image size is scaled down in preview"); + s += ""; + } + + // Store the association between the tempory file name of the + // save attachment and the suggested save-as file name. When + // the user clicks on the attachment, only the temporary file name + // is available. Through this association the suggested file name + // can be retrieved. + _filenameMap[msg.attachment_filename] = msg.attachment_save_as_name; + } + + conversationBrowser->append(s); +} + +void MessageForm::displayError(const QString &errorMsg) +{ + QString s = ""; + s += ""; + s += tr("Delivery failure").ascii(); + s += ": "; + s += Q3StyleSheet::escape(errorMsg); + s += ""; + + conversationBrowser->append(s); +} + +void MessageForm::displayDeliveryNotification(const QString ¬ification) +{ + QString s = ""; + s += ""; + s += tr("Delivery notification").ascii(); + s += ": "; + s += Q3StyleSheet::escape(notification); + s += ""; + + conversationBrowser->append(s); +} + +void MessageForm::setRemotePartyCaption(void) { + if (!_msgSession) return; + t_user *user = _msgSession->get_user(); + t_display_url remote_party = _msgSession->get_remote_party(); + setCaption(ui->format_sip_address(user, + remote_party.display, remote_party.url).c_str()); +} + +void MessageForm::showAttachmentPopupMenu(const QString &attachment) { +#ifdef HAVE_KDE + vector *serviceMap = (vector *)_serviceMap; + + if (serviceMap) { + MEMMAN_DELETE(serviceMap); + delete serviceMap; + } + serviceMap = new vector; + MEMMAN_NEW(serviceMap); + _serviceMap = (void *)serviceMap; +#endif + + int id = 0; // Identity of popup menu item + + // Store attachment. When the user selects an attachment we still + // know which attachment was clicked. + clickedAttachment = attachment; + + attachmentPopupMenu->clear(); + + QIcon saveIcon(QPixmap(":/icons/images/save_as.png")); + attachmentPopupMenu->insertItem(saveIcon, "Save as...", id++); + +#ifdef HAVE_KDE + // Get mime type for the attachment + KMimeType::Ptr pMime = KMimeType::findByURL(attachment); + + // Get applications that can open the mime type + KServiceTypeProfile::OfferList services = KServiceTypeProfile::offers( + pMime->name(), "Application"); + + KServiceTypeProfile::OfferList::ConstIterator it; + for (it = services.begin(); it != services.end(); ++it) { + KService::Ptr service = (*it).service(); + serviceMap->push_back(service); + QString menuText = tr("Open with %1...").arg(service->name()); + QPixmap pixmap = service->pixmap(KIcon::Small); + QIcon iconSet; + iconSet.setPixmap(pixmap, QIcon::Small); + attachmentPopupMenu->insertItem(iconSet, menuText, id++); + } + + QIcon openIcon(QPixmap(":/icons/images/fileopen.png")); + attachmentPopupMenu->insertItem(openIcon, tr("Open with..."), id++); +#endif + + attachmentPopupMenu->popup(QCursor::pos()); +} + +void MessageForm::attachmentPopupActivated(int id) { +#ifdef HAVE_KDE + vector *serviceMap = (vector *)_serviceMap; + assert(serviceMap); +#endif + + if (id == 0) { +#ifdef HAVE_KDE + KFileDialog *d = new KFileDialog(QString::null, QString::null, this, 0, true); + MEMMAN_NEW(d); + d->setOperationMode(KFileDialog::Saving); + + connect(d, SIGNAL(okClicked()), this, + SLOT(saveAttachment())); +#else + Q3FileDialog *d = new Q3FileDialog(QString::null, QString::null, this, 0, true); + MEMMAN_NEW(d); + d->setMode(Q3FileDialog::AnyFile); + + connect(d, SIGNAL(fileSelected(const QString &)), this, + SLOT(saveAttachment())); +#endif + d->setSelection(_filenameMap[clickedAttachment.ascii()].c_str()); + d->setCaption(tr("Save attachment as...")); + + if (_saveAsDialog) { + MEMMAN_DELETE(_saveAsDialog); + delete _saveAsDialog; + } + _saveAsDialog = d; + + d->show(); +#ifdef HAVE_KDE + } else if (id > serviceMap->size()) { + KURL::List urls; + urls << clickedAttachment; + KRun::displayOpenWithDialog(urls, false); + } else { + KURL::List urls; + urls << clickedAttachment; + KRun::run(*serviceMap->at(id-1), urls); +#endif + } +} + +void MessageForm::saveAttachment() { +#ifdef HAVE_KDE + KFileDialog *d = dynamic_cast(_saveAsDialog); +#else + Q3FileDialog *d = dynamic_cast(_saveAsDialog); +#endif + QString filename = d->selectedFile(); + + if (QFile::exists(filename)) { + bool overwrite = ((t_gui *)ui)->cb_ask_msg(this, + tr("File already exists. Do you want to overwrite this file?").ascii(), + MSG_WARNING); + + if (!overwrite) return; + } + + if (!filecopy(clickedAttachment.ascii(), filename.ascii())) { + ((t_gui *)ui)->cb_show_msg(this, tr("Failed to save attachment.").ascii(), + MSG_CRITICAL); + } +} + +/** Choose a file to send */ +void MessageForm::chooseFileToSend() +{ + // Indicate that a message is being composed. + setLocalComposingIndicationActive(); + + SendFileForm *form = new SendFileForm(); + MEMMAN_NEW(form); + // Form will auto destruct itself on close. + + connect(form, SIGNAL(selected(const QString &, const QString &)), + this, SLOT(sendFile(const QString &, const QString &))); + + form->show(); +} + +/** + * Show an is-composing indication in the status bar. + * @param name [in] The name of the sender of the message. + */ +void MessageForm::setComposingIndication(const QString &name) +{ + + if (!_isComposingLabel) { + _isComposingLabel = new QLabel(NULL); + MEMMAN_NEW(_isComposingLabel); + + _isComposingLabel->setText(tr("%1 is typing a message.").arg(name)); + _isComposingLabel->setFrameStyle(Q3Frame::NoFrame | Q3Frame::Plain); + statusBar()->addWidget(_isComposingLabel); + } +} + +/** Clear an is-composing indication from the status bar. */ +void MessageForm::clearComposingIndication() +{ + if (_isComposingLabel) { + statusBar()->removeWidget(_isComposingLabel); + statusBar()->clear(); + + MEMMAN_DELETE(_isComposingLabel); + delete _isComposingLabel; + _isComposingLabel = NULL; + } +} + +/** Set the local composition indication to active. */ +void MessageForm::setLocalComposingIndicationActive() +{ + _msgSession->set_local_composing_state(im::COMPOSING_STATE_ACTIVE); +} + +void MessageForm::keyPressEvent(QKeyEvent *e) +{ + switch (e->key()) { + case Qt::Key_Return: + case Qt::Key_Enter: + if (sendPushButton->isEnabled()) { + sendPushButton->animateClick(); + } + break; + default: + e->ignore(); + } +} + +void MessageForm::toAddressChanged(const QString &address) +{ + sendFileAction->setEnabled(!address.isEmpty()); +} + +/** Show the size of the typed message */ +void MessageForm::showMessageSize() +{ + uint len = msgLineEdit->text().length(); + + QString s(tr("Size")); + s += ": "; + s += QString().setNum(len); + + _msgSizeLabel->setText(s); +} diff --git a/src/gui/messageform.h b/src/gui/messageform.h new file mode 100644 index 0000000..8cf9037 --- /dev/null +++ b/src/gui/messageform.h @@ -0,0 +1,75 @@ +#ifndef MESSAGEFORM_H +#define MESSAGEFORM_H +#include +#include "getaddressform.h" +#include "im/msg_session.h" +#include "phone.h" +#include +#include +#include +#include "textbrowsernoautolink.h" +#include "user.h" +#include "ui_messageform.h" +#include + +class t_phone; +extern t_phone *phone; + +class MessageForm : public Q3MainWindow, public Ui::MessageForm +{ + Q_OBJECT + +public: + MessageForm(QWidget* parent = 0, const char* name = 0, Qt::WindowFlags fl = Qt::WType_TopLevel); + ~MessageForm(); + + virtual bool updateMessageSession(); + virtual bool prepareSendMessage(); + +public slots: + virtual void closeEvent( QCloseEvent * e ); + virtual void show(); + virtual void selectUserConfig( t_user * user_config ); + virtual void showAddressBook(); + virtual void selectedAddress( const QString & address ); + virtual void sendMessage(); + virtual void sendFile( const QString & filename, const QString & subject ); + virtual void addMessage( const im::t_msg & msg, const QString & name ); + virtual void displayError( const QString & errorMsg ); + virtual void displayDeliveryNotification( const QString & notification ); + virtual void setRemotePartyCaption( void ); + virtual void showAttachmentPopupMenu( const QString & attachment ); + virtual void attachmentPopupActivated( int id ); + virtual void saveAttachment(); + virtual void chooseFileToSend(); + virtual void setComposingIndication( const QString & name ); + virtual void clearComposingIndication(); + virtual void setLocalComposingIndicationActive(); + virtual void keyPressEvent( QKeyEvent * e ); + virtual void toAddressChanged( const QString & address ); + virtual void showMessageSize(); + +protected: + im::t_msg_session *_msgSession; + +protected slots: + virtual void languageChange(); + +private: + QDialog *_saveAsDialog; + map _filenameMap; + bool _remotePartyComplete; + GetAddressForm *_getAddressForm; + Q3PopupMenu *attachmentPopupMenu; + QString clickedAttachment; + void *_serviceMap; + QLabel *_isComposingLabel; + QLabel *_msgSizeLabel; + + void init(); + void destroy(); + +}; + + +#endif diff --git a/src/gui/messageform.ui b/src/gui/messageform.ui index bddcb03..7c77067 100644 --- a/src/gui/messageform.ui +++ b/src/gui/messageform.ui @@ -61,7 +61,7 @@ F10
- kontact_contacts.png + :/icons/images/kontact_contacts.png Address book @@ -146,7 +146,7 @@ sendFileAction - attach.png + :/icons/images/attach.png Send file... diff --git a/src/gui/messageform.ui.h b/src/gui/messageform.ui.h deleted file mode 100644 index 8d0b016..0000000 --- a/src/gui/messageform.ui.h +++ /dev/null @@ -1,623 +0,0 @@ -/**************************************************************************** -** ui.h extension file, included from the uic-generated form implementation. -** -** If you want to add, delete, or rename functions or slots, use -** Qt Designer to update this file, preserving your code. -** -** You should not define a constructor or destructor in this file. -** Instead, write your code in functions called init() and destroy(). -** These will automatically be called by the form's constructor and -** destructor. -*****************************************************************************/ - -/* - Copyright (C) 2005-2009 Michel de Boer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -#ifdef HAVE_KDE -#include -#include -#include -#include -#include -#else -#include "utils/mime_database.h" -//Added by qt3to4: -#include -#include -#include -#include -#include -#include -#endif - -using namespace utils; - -/** Maximum width for an inline image */ -#define MAX_WIDTH_IMG_INLINE 400 - -/** Maximum height for an inline image */ -#define MAX_HEIGHT_IMG_INLINE 400 - -#define IMG_SCALE_FACTOR(width, height) (std::min( float(MAX_WIDTH_IMG_INLINE) / (width), float(MAX_HEIGHT_IMG_INLINE) / (height) ) ) - -void MessageForm::init() -{ - setWindowFlags(windowFlags() | Qt::WDestructiveClose); - - _getAddressForm = 0; - _remotePartyComplete = false; - - // Add label to display size of typed message - _msgSizeLabel = new QLabel(this); - statusBar()->addWidget(_msgSizeLabel); - showMessageSize(); - - // Set toolbutton icons for disabled options. - setDisabledIcon(addressToolButton, "kontact_contacts-disabled.png"); - - attachmentPopupMenu = new Q3PopupMenu(this); - MEMMAN_NEW(attachmentPopupMenu); - - connect(attachmentPopupMenu, SIGNAL(activated(int)), - this, SLOT(attachmentPopupActivated(int))); - - _serviceMap = NULL; - _saveAsDialog = NULL; - - _isComposingLabel = NULL; - - // When the user edits the message, the composition indication - // will be set to active. - connect(msgLineEdit, SIGNAL(textChanged(const QString &)), - this, SLOT(setLocalComposingIndicationActive())); -} - -void MessageForm::destroy() -{ - if (_getAddressForm) { - MEMMAN_DELETE(_getAddressForm); - delete _getAddressForm; - } - - MEMMAN_DELETE(attachmentPopupMenu); - delete attachmentPopupMenu; - -#ifdef HAVE_KDE - vector *serviceMap = (vector *)_serviceMap; - if (serviceMap) { - MEMMAN_DELETE(serviceMap); - delete serviceMap; - } -#endif - - if (_saveAsDialog) { - MEMMAN_DELETE(_saveAsDialog); - delete _saveAsDialog; - } - - if (_isComposingLabel) { - MEMMAN_DELETE(_isComposingLabel); - delete _isComposingLabel; - } -} - -void MessageForm::closeEvent(QCloseEvent *e) -{ - MEMMAN_DELETE(this); // destructive close - Q3MainWindow::closeEvent(e); -} - - -void MessageForm::show() -{ - if (toLineEdit->text().isEmpty()) { - sendFileAction->setEnabled(false); - toLineEdit->setFocus(); - } else { - // Once a message session has been created, the - // source and destination cannot be changed anymore. - fromComboBox->setEnabled(false); - toLineEdit->setEnabled(false); - addressToolButton->setEnabled(false); - sendFileAction->setEnabled(true); - msgLineEdit->setFocus(); - } - - Q3MainWindow::show(); -} - -void MessageForm::selectUserConfig(t_user *user_config) -{ - for (int i = 0; i < fromComboBox->count(); i++) { - if (fromComboBox->text(i) == - user_config->get_profile_name().c_str()) - { - fromComboBox->setCurrentItem(i); - break; - } - } -} - -void MessageForm::showAddressBook() -{ - if (!_getAddressForm) { - _getAddressForm = new GetAddressForm( - this, "select address", true); - MEMMAN_NEW(_getAddressForm); - } - - connect(_getAddressForm, - SIGNAL(address(const QString &)), - this, SLOT(selectedAddress(const QString &))); - - _getAddressForm->show(); -} - -void MessageForm::selectedAddress(const QString &address) -{ - toLineEdit->setText(address); -} - -/** - * Check if there is a valid sender and receiver. If so, then set the sender - * and receiver addresses in the message session object. - */ -bool MessageForm::updateMessageSession() -{ - string display, dest_str; - t_user *from_user = phone->ref_user_profile( - fromComboBox->currentText().ascii()); - if (!from_user) { - // The user profile is not active anymore - fromComboBox->setFocus(); - return false; - } - - ui->expand_destination(from_user, toLineEdit->text().stripWhiteSpace().ascii(), - display, dest_str); - t_url dest(dest_str); - - if (!dest.is_valid()) { - toLineEdit->setFocus(); - toLineEdit->selectAll(); - return false; - } - - _msgSession->set_user(from_user); - _msgSession->set_remote_party(t_display_url(dest, display)); - - setRemotePartyCaption(); - - return true; -} - -/** - * Determine if a message can be sent, i.e. there is a valid sender and - * receiver. If a message can be sent, then lock the sender and receiver. - * @return True if message can be sent, false otherwise. - */ -bool MessageForm::prepareSendMessage() { - if (toLineEdit->text().isEmpty()) { - // No recipient selected. - return false; - } - - if (toLineEdit->isEnabled()) { - if (!updateMessageSession()) { - // No valid sender and receiver. - return false; - } - - // Once a message session has been created, the - // source and destination cannot be changed anymore. - fromComboBox->setEnabled(false); - toLineEdit->setEnabled(false); - addressToolButton->setEnabled(false); - - } - - return true; -} - -/** Send a text message */ -void MessageForm::sendMessage() { - if (msgLineEdit->text().isEmpty()) { - // Nothing to send - return; - } - - if (!prepareSendMessage()) { - return; - } - - _msgSession->send_msg(msgLineEdit->text().ascii(), im::TXT_PLAIN); -} - -/** - * Send a file. - * @param filename [in] Name of file to send. - * @param subject [in] Subject to set in the message. - */ -void MessageForm::sendFile(const QString &filename, const QString &subject) { - if (!prepareSendMessage()) { - return; - } - - t_media media("application/octet-stream"); - -#ifdef HAVE_KDE - // Get mime type for the attachment - KMimeType::Ptr pMime = KMimeType::findByURL(filename); - media = t_media(pMime->name().ascii()); -#else - string mime_type = mime_database->get_mimetype(filename.ascii()); - if (!mime_type.empty()) { - media = t_media(mime_type); - } -#endif - - _msgSession->send_file(filename.ascii(), media, subject.ascii()); -} - -/** - * Add a message to the converstation broswer. - * @param msg [in] The message to add. - * @param name [in] The name of the sender of the message. - */ -void MessageForm::addMessage(const im::t_msg &msg, const QString &name) -{ - QString s = ""; - - // Timestamp and name of sender - if (msg.direction == im::MSG_DIR_IN) s += ""; - s += time2str(msg.timestamp, "%H:%M:%S ").c_str(); - s += Q3StyleSheet::escape(name); - if (msg.direction == im::MSG_DIR_IN) s += ""; - s += ""; - - // Subject - if (!msg.subject.empty()) { - s += "
"; - s += ""; - s += "Subject: "; - s += ""; - s += msg.subject.c_str(); - } - - // Text message - if (!msg.message.empty()) { - s += "
"; - if (msg.format == im::TXT_HTML) { - s += msg.message.c_str(); - } else { - s += Q3StyleSheet::escape(msg.message.c_str()); - } - } - - // Attachment - if (msg.has_attachment) { - s += "
"; - s += ""; - - bool show_attachment_inline = false; - bool scale_image = false; - int scaled_width = 0, scaled_height = 0; - - if (msg.attachment_media.type == "image") { - // Show image inline if possible - QPixmap image (msg.attachment_filename.c_str()); - if (!image.isNull()) { - show_attachment_inline = true; - if (image.width() > MAX_WIDTH_IMG_INLINE && - image.height() > MAX_HEIGHT_IMG_INLINE) - { - // Shrink image - scaled_width = int(image.width() * IMG_SCALE_FACTOR(image.width(), image.height())); - scaled_height = int(image.height() * IMG_SCALE_FACTOR(image.width(), image.height())); - scale_image = true; - } - } - } - - s += ""; - s+= "
"; - - s += msg.attachment_save_as_name.c_str(); - - s += "
"; - - if (scale_image) { - s += "
"; - s += ""; - s += tr("image size is scaled down in preview"); - s += ""; - } - - // Store the association between the tempory file name of the - // save attachment and the suggested save-as file name. When - // the user clicks on the attachment, only the temporary file name - // is available. Through this association the suggested file name - // can be retrieved. - _filenameMap[msg.attachment_filename] = msg.attachment_save_as_name; - } - - conversationBrowser->append(s); -} - -void MessageForm::displayError(const QString &errorMsg) -{ - QString s = ""; - s += ""; - s += tr("Delivery failure").ascii(); - s += ": "; - s += Q3StyleSheet::escape(errorMsg); - s += ""; - - conversationBrowser->append(s); -} - -void MessageForm::displayDeliveryNotification(const QString ¬ification) -{ - QString s = ""; - s += ""; - s += tr("Delivery notification").ascii(); - s += ": "; - s += Q3StyleSheet::escape(notification); - s += ""; - - conversationBrowser->append(s); -} - -void MessageForm::setRemotePartyCaption(void) { - if (!_msgSession) return; - t_user *user = _msgSession->get_user(); - t_display_url remote_party = _msgSession->get_remote_party(); - setCaption(ui->format_sip_address(user, - remote_party.display, remote_party.url).c_str()); -} - -void MessageForm::showAttachmentPopupMenu(const QString &attachment) { -#ifdef HAVE_KDE - vector *serviceMap = (vector *)_serviceMap; - - if (serviceMap) { - MEMMAN_DELETE(serviceMap); - delete serviceMap; - } - serviceMap = new vector; - MEMMAN_NEW(serviceMap); - _serviceMap = (void *)serviceMap; -#endif - - int id = 0; // Identity of popup menu item - - // Store attachment. When the user selects an attachment we still - // know which attachment was clicked. - clickedAttachment = attachment; - - attachmentPopupMenu->clear(); - - QIcon saveIcon(qPixmapFromMimeSource("save_as.png")); - attachmentPopupMenu->insertItem(saveIcon, "Save as...", id++); - -#ifdef HAVE_KDE - // Get mime type for the attachment - KMimeType::Ptr pMime = KMimeType::findByURL(attachment); - - // Get applications that can open the mime type - KServiceTypeProfile::OfferList services = KServiceTypeProfile::offers( - pMime->name(), "Application"); - - KServiceTypeProfile::OfferList::ConstIterator it; - for (it = services.begin(); it != services.end(); ++it) { - KService::Ptr service = (*it).service(); - serviceMap->push_back(service); - QString menuText = tr("Open with %1...").arg(service->name()); - QPixmap pixmap = service->pixmap(KIcon::Small); - QIcon iconSet; - iconSet.setPixmap(pixmap, QIcon::Small); - attachmentPopupMenu->insertItem(iconSet, menuText, id++); - } - - QIcon openIcon(qPixmapFromMimeSource("fileopen.png")); - attachmentPopupMenu->insertItem(openIcon, tr("Open with..."), id++); -#endif - - attachmentPopupMenu->popup(QCursor::pos()); -} - -void MessageForm::attachmentPopupActivated(int id) { -#ifdef HAVE_KDE - vector *serviceMap = (vector *)_serviceMap; - assert(serviceMap); -#endif - - if (id == 0) { -#ifdef HAVE_KDE - KFileDialog *d = new KFileDialog(QString::null, QString::null, this, 0, true); - MEMMAN_NEW(d); - d->setOperationMode(KFileDialog::Saving); - - connect(d, SIGNAL(okClicked()), this, - SLOT(saveAttachment())); -#else - Q3FileDialog *d = new Q3FileDialog(QString::null, QString::null, this, 0, true); - MEMMAN_NEW(d); - d->setMode(Q3FileDialog::AnyFile); - - connect(d, SIGNAL(fileSelected(const QString &)), this, - SLOT(saveAttachment())); -#endif - d->setSelection(_filenameMap[clickedAttachment.ascii()].c_str()); - d->setCaption(tr("Save attachment as...")); - - if (_saveAsDialog) { - MEMMAN_DELETE(_saveAsDialog); - delete _saveAsDialog; - } - _saveAsDialog = d; - - d->show(); -#ifdef HAVE_KDE - } else if (id > serviceMap->size()) { - KURL::List urls; - urls << clickedAttachment; - KRun::displayOpenWithDialog(urls, false); - } else { - KURL::List urls; - urls << clickedAttachment; - KRun::run(*serviceMap->at(id-1), urls); -#endif - } -} - -void MessageForm::saveAttachment() { -#ifdef HAVE_KDE - KFileDialog *d = dynamic_cast(_saveAsDialog); -#else - Q3FileDialog *d = dynamic_cast(_saveAsDialog); -#endif - QString filename = d->selectedFile(); - - if (QFile::exists(filename)) { - bool overwrite = ((t_gui *)ui)->cb_ask_msg(this, - tr("File already exists. Do you want to overwrite this file?").ascii(), - MSG_WARNING); - - if (!overwrite) return; - } - - if (!filecopy(clickedAttachment.ascii(), filename.ascii())) { - ((t_gui *)ui)->cb_show_msg(this, tr("Failed to save attachment.").ascii(), - MSG_CRITICAL); - } -} - -/** Choose a file to send */ -void MessageForm::chooseFileToSend() -{ - // Indicate that a message is being composed. - setLocalComposingIndicationActive(); - - SendFileForm *form = new SendFileForm(); - MEMMAN_NEW(form); - // Form will auto destruct itself on close. - - connect(form, SIGNAL(selected(const QString &, const QString &)), - this, SLOT(sendFile(const QString &, const QString &))); - - form->show(); -} - -/** - * Show an is-composing indication in the status bar. - * @param name [in] The name of the sender of the message. - */ -void MessageForm::setComposingIndication(const QString &name) -{ - - if (!_isComposingLabel) { - _isComposingLabel = new QLabel(NULL); - MEMMAN_NEW(_isComposingLabel); - - _isComposingLabel->setText(tr("%1 is typing a message.").arg(name)); - _isComposingLabel->setFrameStyle(Q3Frame::NoFrame | Q3Frame::Plain); - statusBar()->addWidget(_isComposingLabel); - } -} - -/** Clear an is-composing indication from the status bar. */ -void MessageForm::clearComposingIndication() -{ - if (_isComposingLabel) { - statusBar()->removeWidget(_isComposingLabel); - statusBar()->clear(); - - MEMMAN_DELETE(_isComposingLabel); - delete _isComposingLabel; - _isComposingLabel = NULL; - } -} - -/** Set the local composition indication to active. */ -void MessageForm::setLocalComposingIndicationActive() -{ - _msgSession->set_local_composing_state(im::COMPOSING_STATE_ACTIVE); -} - -void MessageForm::keyPressEvent(QKeyEvent *e) -{ - switch (e->key()) { - case Qt::Key_Return: - case Qt::Key_Enter: - if (sendPushButton->isEnabled()) { - sendPushButton->animateClick(); - } - break; - default: - e->ignore(); - } -} - -void MessageForm::toAddressChanged(const QString &address) -{ - sendFileAction->setEnabled(!address.isEmpty()); -} - -/** Show the size of the typed message */ -void MessageForm::showMessageSize() -{ - uint len = msgLineEdit->text().length(); - - QString s(tr("Size")); - s += ": "; - s += QString().setNum(len); - - _msgSizeLabel->setText(s); -} diff --git a/src/gui/messageformview.h b/src/gui/messageformview.h index a5c547e..64c62c3 100644 --- a/src/gui/messageformview.h +++ b/src/gui/messageformview.h @@ -19,12 +19,12 @@ #ifndef _MESSAGEFORMVIEW_H #define _MESSAGEFORMVIEW_H -#include "ui_messageform.h" +#include "messageform.h" #include "im/msg_session.h" #include "patterns/observer.h" -class MessageFormView : public Ui::MessageForm, patterns::t_observer +class MessageFormView : public MessageForm, patterns::t_observer { Q_OBJECT private: diff --git a/src/gui/mphoneform.cpp b/src/gui/mphoneform.cpp new file mode 100644 index 0000000..74c9b71 --- /dev/null +++ b/src/gui/mphoneform.cpp @@ -0,0 +1,3161 @@ +/**************************************************************************** +** ui.h extension file, included from the uic-generated form implementation. +** +** If you wish to add, delete or rename functions or slots use +** Qt Designer which will update this file, pres:erving your code. Ceate an +** init() function in place of a constructor, and a destroy() function in +** place of a destructor. +*****************************************************************************/ +/* + Copyright (C) 2005-2009 Michel de Boer + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +#include "mphoneform.h" +#include "twinkle_config.h" +//Added by qt3to4: +#include +#include +#include +#include +#include +#include +#include +#include +#include "../audits/memman.h" +#include "user.h" +#include +#include +#include +#include "gui.h" +#include +#include +#include +#include "audits/memman.h" +#include "line.h" +#include "stun/stun_transaction.h" +#include "log.h" +#include +#include "util.h" +#include +#include +#include +#include +#include +#include "buddyform.h" +#include "diamondcardprofileform.h" + + +// Time (s) that the conversation timer of a line should stay visible after +// a call has ended +#define HIDE_LINE_TIMER_AFTER 5 + +MphoneForm::MphoneForm(QWidget* parent, const char * name, Qt::WindowFlags f) + : Q3MainWindow(parent, name, f) +{ + setupUi(this); + init(); +} + +MphoneForm::~MphoneForm() +{ + destroy(); +} + +void MphoneForm::init() +{ + // Forms + dtmfForm = 0; + inviteForm = 0; + redirectForm = 0; + transferForm = 0; + termCapForm = 0; + srvRedirectForm = 0; + userProfileForm = 0; + sysSettingsForm = 0; + logViewForm = 0; + historyForm = 0; + selectUserForm = 0; + selectProfileForm = 0; + getAddressForm = 0; + sysTray = 0; + + // Popup menu for a single buddy + QIcon inviteIcon(QPixmap(":/icons/images/invite.png")); + QIcon messageIcon(QPixmap(":/icons/images/message.png")); + QIcon editIcon(QPixmap(":/icons/images/edit16.png")); + QIcon deleteIcon(QPixmap(":/icons/images/editdelete.png")); + buddyPopupMenu = new Q3PopupMenu(this); + MEMMAN_NEW(buddyPopupMenu); + buddyPopupMenu->insertItem(inviteIcon, tr("&Call..."), this, SLOT(doCallBuddy())); + buddyPopupMenu->insertItem(messageIcon, tr("Instant &message..."), this, SLOT(doMessageBuddy())); + buddyPopupMenu->insertItem(editIcon, tr("&Edit..."), this, SLOT(doEditBuddy())); + buddyPopupMenu->insertItem(deleteIcon, tr("&Delete"), this, SLOT(doDeleteBuddy())); + + // Change availibility sub popup menu + changeAvailabilityPopupMenu = new Q3PopupMenu(this); + MEMMAN_NEW(changeAvailabilityPopupMenu); + QIcon availOnlineIcon(QPixmap(":/icons/images/presence_online.png")); + QIcon availOfflineIcon(QPixmap(":/icons/images/presence_offline.png")); + changeAvailabilityPopupMenu->insertItem(availOfflineIcon, tr("O&ffline"), this, + SLOT(doAvailabilityOffline())); + changeAvailabilityPopupMenu->insertItem(availOnlineIcon, tr("&Online"), this, + SLOT(doAvailabilityOnline())); + + // Popup menu for a buddy list (click on profile name) + QIcon changeAvailabilityIcon(QPixmap(":/icons/images/presence_online.png")); + QIcon addIcon(QPixmap(":/icons/images/buddy.png")); + buddyListPopupMenu = new Q3PopupMenu(this); + MEMMAN_NEW(buddyListPopupMenu); + buddyListPopupMenu->insertItem(changeAvailabilityIcon, tr("&Change availability"), + changeAvailabilityPopupMenu); + buddyListPopupMenu->insertItem(addIcon, tr("&Add buddy..."), this, SLOT(doAddBuddy())); + + // ToDo: Tool tip for buddy list + + // Line timers + lineTimer1 = 0; + lineTimer2 = 0; + timer1TextLabel->hide(); + timer2TextLabel->hide(); + + // Timer to hide the conversation timer after a conversation has ended. + hideLineTimer1 = new QTimer(this); + MEMMAN_NEW(hideLineTimer1); + hideLineTimer2 = new QTimer(this); + MEMMAN_NEW(hideLineTimer2); + connect(hideLineTimer1, SIGNAL(timeout()), timer1TextLabel, SLOT(hide())); + connect(hideLineTimer2, SIGNAL(timeout()), timer2TextLabel, SLOT(hide())); + + // Attach the MWI flash slot to the MWI flash timer + connect(&tmrFlashMWI, SIGNAL(timeout()), this, SLOT(flashMWI())); + + // Set toolbar icons for disabled options. + setDisabledIcon(callInvite, "invite-disabled.png"); + setDisabledIcon(callAnswer, "answer-disabled.png"); + setDisabledIcon(callBye, "bye-disabled.png"); + setDisabledIcon(callReject, "reject-disabled.png"); + setDisabledIcon(callRedirect, "redirect-disabled.png"); + setDisabledIcon(callTransfer, "transfer-disabled.png"); + setDisabledIcon(callHold, "hold-disabled.png"); + setDisabledIcon(callConference, "conf-disabled.png"); + setDisabledIcon(callMute, "mute-disabled.png"); + setDisabledIcon(callDTMF, "dtmf-disabled.png"); + setDisabledIcon(callRedial, "redial-disabled.png"); + + // Set tool button icons for disabled options + setDisabledIcon(addressToolButton, "kontact_contacts-disabled.png"); + + // Some text labels on the main window are implemented as QLineEdit + // objects as these do not automatically resize when a text set with setText + // does not fit. The background of a QLineEdit is static however, it does not + // automatically take a background color passed by the -bg parameter. + // Set the background color of these QLineEdit objects here. + from1Label->setPaletteBackgroundColor(paletteBackgroundColor()); + to1Label->setPaletteBackgroundColor(paletteBackgroundColor()); + subject1Label->setPaletteBackgroundColor(paletteBackgroundColor()); + from2Label->setPaletteBackgroundColor(paletteBackgroundColor()); + to2Label->setPaletteBackgroundColor(paletteBackgroundColor()); + subject2Label->setPaletteBackgroundColor(paletteBackgroundColor()); + + // A QComboBox accepts a new line through copy/paste. + QRegExp rxNoNewLine("[^\\n\\r]*"); + callComboBox->setValidator(new QRegExpValidator(rxNoNewLine, this)); + + if (sys_config->get_gui_use_systray()) { + // Create system tray icon + sysTray = new QSystemTrayIcon(this); + + sysTray->setIcon( + QPixmap(":/icons/images/sys_idle_dis.png")); + sysTray->setToolTip(PRODUCT_NAME); + + // Add items to the system tray menu + QMenu *menu; + + menu = new QMenu(this); + sysTray->setContextMenu(menu); + + // Call menu + callInvite->addTo(menu); + callAnswer->addTo(menu); + callBye->addTo(menu); + callReject->addTo(menu); + callRedirect->addTo(menu); + callTransfer->addTo(menu); + callHold->addTo(menu); + callConference->addTo(menu); + callMute->addTo(menu); + callDTMF->addTo(menu); + callRedial->addTo(menu); + + menu->insertSeparator(); + + // Messaging + actionSendMsg->addTo(menu); + + menu->insertSeparator(); + + // Line activation + actgrActivateLine->addTo(menu); + + menu->insertSeparator(); + + // Service menu + serviceDnd->addTo(menu); + serviceRedirection->addTo(menu); + serviceAutoAnswer->addTo(menu); + servicesVoice_mailAction->addTo(menu); + + menu->insertSeparator(); + + // View menu + viewCall_HistoryAction->addTo(menu); + + menu->insertSeparator(); + + // Diamondcard menu + menu->insertItem("Diamondcard", Diamondcard); + + // Exit application when user selects Quit from the tray menu + connect(sysTray, SIGNAL(quitSelected()), + this, SLOT(fileExit())); + + sysTray->show(); + } +} + +void MphoneForm::destroy() +{ + if (dtmfForm) { + MEMMAN_DELETE(dtmfForm); + delete dtmfForm; + } + if (inviteForm) { + MEMMAN_DELETE(inviteForm); + delete inviteForm; + } + if (redirectForm) { + MEMMAN_DELETE(redirectForm); + delete redirectForm; + } + if (termCapForm) { + MEMMAN_DELETE(termCapForm); + delete termCapForm; + } + if (srvRedirectForm) { + MEMMAN_DELETE(srvRedirectForm); + delete srvRedirectForm; + } + if (userProfileForm) { + MEMMAN_DELETE(userProfileForm); + delete userProfileForm; + } + if (transferForm) { + MEMMAN_DELETE(transferForm); + delete transferForm; + } + if (sysSettingsForm) { + MEMMAN_DELETE(sysSettingsForm); + delete sysSettingsForm; + } + if (logViewForm) { + if (logViewForm->isShown()) logViewForm->close(); + MEMMAN_DELETE(logViewForm); + delete logViewForm; + } + if (historyForm) { + if (historyForm->isShown()) historyForm->close(); + MEMMAN_DELETE(historyForm); + delete historyForm; + } + if (selectUserForm) { + MEMMAN_DELETE(selectUserForm); + delete selectUserForm; + } + if (selectProfileForm) { + MEMMAN_DELETE(selectProfileForm); + delete selectProfileForm; + } + if (getAddressForm) { + MEMMAN_DELETE(getAddressForm); + delete getAddressForm; + } + if (sysTray) { + MEMMAN_DELETE(sysTray); + delete sysTray; + } + + if (lineTimer1) { + MEMMAN_DELETE(lineTimer1); + delete lineTimer1; + } + if (lineTimer2) { + MEMMAN_DELETE(lineTimer2); + delete lineTimer2; + } + MEMMAN_DELETE(hideLineTimer1); + delete hideLineTimer1; + MEMMAN_DELETE(hideLineTimer2); + delete hideLineTimer2; + MEMMAN_DELETE(buddyPopupMenu); + delete buddyPopupMenu; + MEMMAN_DELETE(changeAvailabilityPopupMenu); + delete changeAvailabilityPopupMenu; + MEMMAN_DELETE(buddyListPopupMenu); + delete buddyListPopupMenu; +} + +QString MphoneForm::lineSubstate2str( int line) { + QString reason; + + t_call_info call_info = phone->get_call_info(line); + + switch(phone->get_line_substate(line)) { + case LSSUB_IDLE: + return tr("idle"); + case LSSUB_SEIZED: + return tr("dialing"); + case LSSUB_OUTGOING_PROGRESS: + reason = call_info.last_provisional_reason.c_str(); + if (reason == "") { + return tr("attempting call, please wait"); + } + return reason; + case LSSUB_INCOMING_PROGRESS: + return QString("") + tr("incoming call") + ""; + case LSSUB_ANSWERING: + return tr("establishing call, please wait"); + case LSSUB_ESTABLISHED: + if (phone->has_line_media(line)) { + return tr("established"); + } else { + return tr("established (waiting for media)"); + } + break; + case LSSUB_RELEASING: + return tr("releasing call, please wait"); + default: + return tr("unknown state"); + } +} + +void MphoneForm::closeEvent( QCloseEvent *e ) +{ + if (sysTray && sys_config->get_gui_hide_on_close()) { + hide(); + } else { + fileExit(); + } +} + +void MphoneForm::fileExit() +{ + hide(); + QApplication::exit(0); +} + +// Append a string to the display window +void MphoneForm::display( const QString &s ) +{ + displayContents.push_back(s); + if (displayContents.size() > 100) { + displayContents.pop_front(); + } + + displayTextEdit->setText(displayContents.join("\n")); + + // Set cursor position at the end of text + displayTextEdit->setCursorPosition(displayTextEdit->paragraphs() - 1, 0); +} + +// Print message header on display +void MphoneForm::displayHeader() +{ + display(""); + display(current_time2str("%a %H:%M:%S").c_str()); +} + +// Update the conversation timer +void MphoneForm::showLineTimer(int line) +{ + struct timeval t; + gettimeofday(&t, NULL); + + QLabel *timerLabel; + + if (line == 0) { + timerLabel = timer1TextLabel; + } else { + timerLabel = timer2TextLabel; + } + + // Calculate duration of call + t_call_record cr = phone->get_call_hist(line); + unsigned long duration = t.tv_sec - cr.time_answer; + + timerLabel->setText(timer2str(duration).c_str()); +} + +void MphoneForm::showLineTimer1() +{ + showLineTimer(0); +} + +void MphoneForm::showLineTimer2() +{ + showLineTimer(1); +} + +// Update visibility of the conversation timer for a line +// Initialize the timer for a new established call. +void MphoneForm::updateLineTimer(int line) +{ + QLabel *timerLabel; + QTimer **timer; + QTimer *hideLineTimer; + + if (line == 0) { + timerLabel = timer1TextLabel; + timer = &lineTimer1; + hideLineTimer = hideLineTimer1; + } else { + timerLabel = timer2TextLabel; + timer = &lineTimer2; + hideLineTimer = hideLineTimer2; + } + + t_line_substate line_substate = phone->get_line_substate(line); + + // Stop hide timer if necessary + switch(line_substate) { + case LSSUB_IDLE: + case LSSUB_RELEASING: + // Timer can be shown as long as line is idle or releasing. + break; + default: + // The timer showing the call duration should only stay + // for a few seconds as long as the line is idle or being + // released. + // If a new call arrives on the line, the hide timer should + // be stopped, otherwise the timer of the new call will + // automatically disappear. + if (hideLineTimer->isActive()) { + hideLineTimer->stop(); + if (*timer == NULL) timerLabel->hide(); + } + break; + } + + switch(line_substate) { + case LSSUB_ESTABLISHED: + // Initialize and show call duration timer + if (*timer == NULL) { + timerLabel->setText(timer2str(0).c_str()); + timerLabel->show(); + *timer = new QTimer(this); + MEMMAN_NEW(*timer); + + if (line == 0) { + connect(*timer, SIGNAL(timeout()), this, + SLOT(showLineTimer1())); + } else { + connect(*timer, SIGNAL(timeout()), this, + SLOT(showLineTimer2())); + } + + // Update timer every 1s + (*timer)->start(1000, false); + } + break; + default: + // Hide call duration timer + if (*timer != NULL) { + // Hide the timer after a few seconds + hideLineTimer->start(HIDE_LINE_TIMER_AFTER * 1000, true); + (*timer)->stop(); + MEMMAN_DELETE(*timer); + *timer = NULL; + } + break; + } +} + +void MphoneForm::updateLineEncryptionState(int line) +{ + QLabel *cryptLabel, *sasLabel; + if (line == 0) { + cryptLabel = crypt1Label; + sasLabel = line1SasLabel; + } else { + cryptLabel = crypt2Label; + sasLabel = line2SasLabel; + } + + t_audio_session *as = phone->get_line(line)->get_audio_session(); + if (as && phone->is_line_encrypted(line)) { + string zrtp_sas = as->get_zrtp_sas(); + bool zrtp_sas_confirmed = as->get_zrtp_sas_confirmed(); + string srtp_cipher_mode = as->get_srtp_cipher_mode(); + + QToolTip::remove(cryptLabel); + QString toolTip = tr("Voice is encrypted") + " ("; + toolTip.append(srtp_cipher_mode.c_str()).append(")"); + + if (!zrtp_sas.empty()) { + // Set tool tip on encryption icon + toolTip.append("\nSAS = "); + toolTip.append(zrtp_sas.c_str()); + + // Show SAS + sasLabel->setText(zrtp_sas.c_str()); + sasLabel->show(); + } else { + sasLabel->hide(); + } + + if (!zrtp_sas_confirmed) { + toolTip.append("\n").append(tr("Click to confirm SAS.")); + cryptLabel->setFrameStyle(Q3Frame::Panel | Q3Frame::Raised); + cryptLabel->setPixmap( + QPixmap(":/icons/images/encrypted.png")); + } else { + toolTip.append("\n").append(tr("Click to clear SAS verification.")); + cryptLabel->setFrameStyle(Q3Frame::NoFrame); + cryptLabel->setPixmap( + QPixmap(":/icons/images/encrypted_verified.png")); + } + + QToolTip::add(cryptLabel, toolTip); + cryptLabel->show(); + } else { + cryptLabel->hide(); + sasLabel->hide(); + } +} + +void MphoneForm::updateLineStatus(int line) +{ + QString state; + bool on_hold; // indicates if a line is put on-hold + bool in_conference; // indicates if a line is in a conference + bool is_muted; // indicates is a line is muted + t_refer_state refer_state; // indicates if a call transfer is in progress + bool is_transfer_consult; // indicates if the call is a consultation + bool to_be_transferred; // indicates if the line is to be transferred after consultation + t_call_info call_info; + unsigned short dummy; + + QLabel *statLabel, *holdLabel, *muteLabel, *confLabel, *referLabel, *statusTextLabel; + + if (line == 0) { + statLabel = line1StatLabel; + holdLabel = line1HoldLabel; + muteLabel = line1MuteLabel; + confLabel = line1ConfLabel; + referLabel = line1ReferLabel; + statusTextLabel = status1TextLabel; + } else { + statLabel = line2StatLabel; + holdLabel = line2HoldLabel; + muteLabel = line2MuteLabel; + confLabel = line2ConfLabel; + referLabel = line2ReferLabel; + statusTextLabel = status2TextLabel; + } + + state = lineSubstate2str(line); + on_hold = phone->is_line_on_hold(line); + if (on_hold) { + holdLabel->show(); + } else { + holdLabel->hide(); + } + in_conference = phone->part_of_3way(line); + if (in_conference) { + confLabel->show(); + } else { + confLabel->hide(); + } + is_muted = phone->is_line_muted(line); + if (is_muted) { + muteLabel->show(); + } else { + muteLabel->hide(); + } + refer_state = phone->get_line_refer_state(line); + is_transfer_consult = phone->is_line_transfer_consult(line, dummy); + to_be_transferred = phone->line_to_be_transferred(line, dummy); + if (refer_state != REFST_NULL || is_transfer_consult || to_be_transferred) { + QString toolTip; + QToolTip::remove(referLabel); + referLabel->show(); + if (is_transfer_consult) { + referLabel->setPixmap( + QPixmap(":/icons/images/consult-xfer.png")); + toolTip = tr("Transfer consultation"); + } else { + referLabel->setPixmap( + QPixmap(":/icons/images/cf.png")); + toolTip = tr("Transferring call"); + } + QToolTip::add(referLabel, toolTip); + } else { + referLabel->hide(); + } + + statusTextLabel->setText(state); + + t_line_substate line_substate; + line_substate = phone->get_line_substate(line); + switch (line_substate) { + case LSSUB_IDLE: + ((t_gui *)ui)->clearLineFields(line); + statLabel->hide(); + break; + case LSSUB_SEIZED: + case LSSUB_OUTGOING_PROGRESS: + statLabel->setPixmap(QPixmap(":/icons/images/stat_outgoing.png")); + statLabel->show(); + break; + case LSSUB_INCOMING_PROGRESS: + statLabel->setPixmap(QPixmap(":/icons/images/stat_ringing.png")); + statLabel->show(); + break; + case LSSUB_ANSWERING: + statLabel->setPixmap(QPixmap(":/icons/images/gear.png")); + statLabel->show(); + break; + case LSSUB_ESTABLISHED: + if (phone->has_line_media(line)) { + statLabel->setPixmap(qPixmapFromMimeSource( + "stat_established.png")); + } else { + statLabel->setPixmap(qPixmapFromMimeSource( + "stat_established_nomedia.png")); + } + statLabel->show(); + break; + case LSSUB_RELEASING: + statLabel->setPixmap(QPixmap(":/icons/images/gear.png")); + statLabel->show(); + break; + default: + statLabel->hide(); + break; + } + + updateLineEncryptionState(line); + updateLineTimer(line); +} + +// Update line state and enable/disable buttons depending on state +void MphoneForm::updateState() +{ + QString state; + int line, other_line; + bool on_hold; // indicates if a line is put on-hold + bool in_conference; // indicates if a line is in a conference + bool is_muted; // indicates is a line is muted + t_refer_state refer_state; // indicates if a call transfer is in progress + bool is_transfer_consult; // indicates if the call is a consultation + bool to_be_transferred; // indicates if the line is to be transferred after consultation + bool has_media; // indicates if a media stream is present + t_call_info call_info; + unsigned short dummy; + + // Update status of line 1 + updateLineStatus(0); + + // Update status of line 2 + updateLineStatus(1); + + // Disable/enable controls depending on the active line state + t_line_substate line_substate; + line = phone->get_active_line(); + line_substate = phone->get_line_substate(line); + on_hold = phone->is_line_on_hold(line); + in_conference = phone->part_of_3way(line); + is_muted = phone->is_line_muted(line); + refer_state = phone->get_line_refer_state(line); + is_transfer_consult = phone->is_line_transfer_consult(line, dummy); + to_be_transferred = phone->line_to_be_transferred(line, dummy); + has_media = phone->has_line_media(line); + other_line = (line == 0 ? 1 : 0); + call_info = phone->get_call_info(line); + t_user *user_config = phone->get_line_user(line); + + // The active line may change when one of the parties in a conference + // releases the call. If this happens, then update the state of the + // line radio buttons. + if (line == 0 && line2RadioButton->isOn()) + { + line1RadioButton->setChecked(true); + } else if (line == 1 && line1RadioButton->isOn()) + { + line2RadioButton->setChecked(true); + } + + // Same logic for the activate line menu items + if (line == 0 && actionLine2->isOn()) + { + actionLine1->setOn(true); + } else if (line == 1 && actionLine1->isOn()) + { + actionLine2->setOn(true); + } + + switch(line_substate) { + case LSSUB_IDLE: + enableCallOptions(true); + callAnswer->setEnabled(false); + callBye->setEnabled(false); + callReject->setEnabled(false); + callRedirect->setEnabled(false); + callTransfer->setEnabled(false); + callHold->setEnabled(false); + callConference->setEnabled(false); + callMute->setEnabled(false); + callDTMF->setEnabled(false); + callRedial->setEnabled(ui->can_redial()); + break; + case LSSUB_OUTGOING_PROGRESS: + enableCallOptions(false); + callAnswer->setEnabled(false); + callBye->setEnabled(true); + callReject->setEnabled(false); + callRedirect->setEnabled(false); + + if (is_transfer_consult && user_config->get_allow_transfer_consultation_inprog()) { + callTransfer->setEnabled(true); + } else { + callTransfer->setEnabled(false); + } + + callHold->setEnabled(false); + callConference->setEnabled(false); + callMute->setEnabled(false); + callDTMF->setEnabled(call_info.dtmf_supported); + callRedial->setEnabled(false); + break; + case LSSUB_INCOMING_PROGRESS: + enableCallOptions(false); + callAnswer->setEnabled(true); + callBye->setEnabled(false); + callReject->setEnabled(true); + callRedirect->setEnabled(true); + callTransfer->setEnabled(false); + callHold->setEnabled(false); + callConference->setEnabled(false); + callMute->setEnabled(false); + callDTMF->setEnabled(call_info.dtmf_supported); + callRedial->setEnabled(false); + break; + case LSSUB_ESTABLISHED: + enableCallOptions(false); + callInvite->setEnabled(false); + callAnswer->setEnabled(false); + callBye->setEnabled(true); + callReject->setEnabled(false); + callRedirect->setEnabled(false); + + if (in_conference) { + callTransfer->setEnabled(false); + callHold->setEnabled(false); + callConference->setEnabled(false); + callDTMF->setEnabled(false); + } else { + callTransfer->setEnabled(has_media && + call_info.refer_supported && + refer_state == REFST_NULL && + !to_be_transferred); + callHold->setEnabled(has_media); + callDTMF->setEnabled(call_info.dtmf_supported); + + if (phone->get_line_substate(other_line) == + LSSUB_ESTABLISHED) + { + // If one of the lines is transferring a call, then a + // conference cannot be setup. + if (refer_state != REFST_NULL || + phone->get_line_refer_state(other_line) != REFST_NULL) + { + callConference->setEnabled(false); + } else { + callConference->setEnabled(has_media); + } + } else { + callConference->setEnabled(false); + } + } + + callMute->setEnabled(true); + callRedial->setEnabled(false); + break; + case LSSUB_SEIZED: + case LSSUB_ANSWERING: + case LSSUB_RELEASING: + // During dialing, answering and call release no other actions are + // possible + enableCallOptions(false); + callAnswer->setEnabled(false); + callBye->setEnabled(false); + callReject->setEnabled(false); + callRedirect->setEnabled(false); + callTransfer->setEnabled(false); + callHold->setEnabled(false); + callConference->setEnabled(false); + callMute->setEnabled(false); + callDTMF->setEnabled(false); + callRedial->setEnabled(false); + break; + default: + enableCallOptions(true); + callAnswer->setEnabled(true); + callBye->setEnabled(true); + callReject->setEnabled(true); + callRedirect->setEnabled(true); + callTransfer->setEnabled(true); + callHold->setEnabled(true); + callConference->setEnabled(false); + callMute->setEnabled(true); + callDTMF->setEnabled(true); + callRedial->setEnabled(ui->can_redial()); + } + + // Set hold action in correct state + callHold->setOn(on_hold); + + // Set mute action in correct state + callMute->setOn(is_muted); + + // Set transfer action in correct state + callTransfer->setOn(is_transfer_consult); + + // Hide redirect form if it is still visible, but not applicable anymore + if (!callRedirect->isEnabled() && redirectForm && + redirectForm->isVisible()) + { + redirectForm->hide(); + } + + // Hide transfer form if it is still visible, but not applicable anymore + if (!callTransfer->isEnabled() && transferForm && + transferForm->isVisible()) + { + transferForm->hide(); + } + + // Hide DTMF form if it is still visible, but not applicable anymore + if (!callDTMF->isEnabled() && dtmfForm && + dtmfForm->isVisible()) + { + dtmfForm->hide(); + } + + // Set last called address in the redial tool tip + t_url last_url; + string last_display; + string last_subject; + t_user *last_user; + bool hide_user; + if (callRedial->isEnabled() && + ui->get_last_call_info(last_url, last_display, last_subject, &last_user, hide_user)) + { + QString s = ""; + s += tr("Repeat last call"); + s += "
"; + s += ""; + + s += ""; + + if (!last_subject.empty()) { + s.append(""; + } + + if (hide_user) { + s.append(""; + } + + s += "
"; + s += tr("User:").append(""); + s += last_user->get_profile_name().c_str(); + s.append("
").append(tr("Call:")).append(""); + s += ui->format_sip_address(last_user, + last_display, last_url).c_str(); + s += "
").append(tr("Subject:")).append(""); + s += last_subject.c_str(); + s += "
").append(tr("Hide identity")); + s += "
"; + callRedial->setToolTip(s); + } else { + callRedial->setToolTip(tr("Repeat last call")); + } + callRedial->setStatusTip(tr("Repeat last call")); + + updateSysTrayStatus(); +} + +// Update registration status +void MphoneForm::updateRegStatus() +{ + size_t num_registered = 0; + size_t num_failed = 0; + QString toolTip = ""; + toolTip.append(tr("Registration status:")); + toolTip.append("
"); + toolTip.append(""); + + // Count number of succesful and failed registrations. + // Determine tool tip showing registration details for all users. + listuser_list = phone->ref_users(); + for (list::iterator i = user_list.begin(); i != user_list.end(); i++) { + toolTip.append(""); + } + toolTip.append("
"); + toolTip.append((*i)->get_profile_name().c_str()); + toolTip.append(""); + if (phone->get_is_registered(*i)) { + num_registered++; + toolTip.append(tr("Registered")); + } else if (phone->get_last_reg_failed(*i)) { + num_failed++; + toolTip.append(tr("Failed")); + } else { + toolTip.append(tr("Not registered").replace(' ', " ")); + } + toolTip.append("

"); + toolTip.append(""); + toolTip.append(tr("Click to show registrations.").replace(' ', " ")); + toolTip.append(""); + + // Set registration status + if (num_registered == user_list.size()) { + // All users are registered + statRegLabel->setPixmap(QPixmap(":/icons/images/twinkle16.png")); + } else if (num_failed == user_list.size()) { + // All users failed to register + statRegLabel->setPixmap(QPixmap(":/icons/images/reg_failed.png")); + } else if (num_registered > 0) { + // Some users are registered + statRegLabel->setPixmap(qPixmapFromMimeSource( + "twinkle16.png")); + } else if (num_failed > 0) { + // Some users failed, none are registered + statRegLabel->setPixmap(QPixmap(":/icons/images/reg_failed.png")); + } else { + // No users are registered, no users failed + statRegLabel->setPixmap(QPixmap(":/icons/images/twinkle16-disabled.png")); + } + + // Set tool tip with detailed info. + QToolTip::remove(statRegLabel); + + if (num_registered > 0 || num_failed > 0) { + QToolTip::add(statRegLabel, toolTip); + } else { + QToolTip::add(statRegLabel, tr("No users are registered.")); + } + + updateSysTrayStatus(); +} + +// Create a status message based on the number of waiting messages. +// On return, msg_waiting will indicate if the MWI indicator should show +// waiting messages. +QString MphoneForm::getMWIStatus(const t_mwi &mwi, bool &msg_waiting) const +{ + QString status; + msg_waiting = false; + t_msg_summary summary = mwi.get_voice_msg_summary(); + + if (summary.newmsgs > 0 && summary.oldmsgs > 0) { + if (summary.oldmsgs == 1) { + status = tr("%1 new, 1 old message"). + arg(summary.newmsgs); + } else { + status = tr("%1 new, %2 old messages"). + arg(summary.newmsgs). + arg(summary.oldmsgs); + } + msg_waiting = true; + } else if (summary.newmsgs > 0 && summary.oldmsgs == 0) { + if (summary.newmsgs == 1) { + status = tr("1 new message"); + } else { + status = tr("%1 new messages"). + arg(summary.newmsgs); + } + msg_waiting = true; + } else if (summary.oldmsgs > 0) { + if (summary.oldmsgs == 1) { + status = tr("1 old message"); + } else { + status = tr("%1 old messages"). + arg(summary.oldmsgs); + } + } else { + if (mwi.get_msg_waiting()) { + status = tr("Messages waiting"); + msg_waiting = true; + } else { + status = tr("No messages"); + } + } + + return status.replace(' ', " "); +} + +// Flash the MWI icon +void MphoneForm::flashMWI() +{ + if (mwiFlashStatus) { + mwiFlashStatus = false; + statMWILabel->setPixmap(qPixmapFromMimeSource( + "mwi_none16.png")); + } else { + mwiFlashStatus = true; + statMWILabel->setPixmap(qPixmapFromMimeSource( + "mwi_new16.png")); + } +} + +// Update MWI +void MphoneForm::updateMwi() +{ + bool mwi_known = false; + bool mwi_new_msgs = false; + bool mwi_failure = false; + + // Determine tool tip + QString toolTip = tr("Voice mail status:").append("\n"); + toolTip.append("
"); + listuser_list = phone->ref_users(); + for (list::iterator i = user_list.begin(); i != user_list.end(); i++) { + toolTip.append(""); + } + + toolTip.append("
"); + toolTip.append((*i)->get_profile_name().c_str()); + t_mwi mwi = phone->get_mwi(*i); + toolTip.append(""); + if (phone->is_mwi_subscribed(*i)) { + if (mwi.get_status() == t_mwi::MWI_KNOWN) { + bool new_msgs; + QString status = getMWIStatus(mwi, new_msgs); + toolTip.append(status); + mwi_known = true; + mwi_new_msgs |= new_msgs; + } else if (mwi.get_status() == t_mwi::MWI_FAILED) { + toolTip.append(tr("Failure")); + mwi_failure = true; + } else { + toolTip.append(tr("Unknown")); + } + } else { + if ((*i)->get_mwi_sollicited()) { + if (mwi.get_status() == t_mwi::MWI_FAILED) { + toolTip.append(tr("Failure")); + mwi_failure = true; + } else { + toolTip.append(tr("Unknown")); + } + } else { + // Unsollicited MWI + if (mwi.get_status() == t_mwi::MWI_KNOWN) { + bool new_msgs; + QString status = getMWIStatus(mwi, new_msgs); + toolTip.append(status); + mwi_known = true; + mwi_new_msgs |= new_msgs; + } else { + toolTip.append(tr("Unknown")); + } + } + } + toolTip.append("

"); + toolTip.append(""); + toolTip.append(tr("Click to access voice mail.").replace(' ', " ")); + toolTip.append(""); + + // Set MWI icon + if (mwi_new_msgs) { + statMWILabel->setPixmap(qPixmapFromMimeSource( + "mwi_new16.png")); + mwiFlashStatus = true; + + // Start the flash MWI timer to flash the indicator + tmrFlashMWI.start(1000); + } else if (mwi_failure) { + tmrFlashMWI.stop(); + statMWILabel->setPixmap(qPixmapFromMimeSource( + "mwi_failure16.png")); + } else if (mwi_known) { + tmrFlashMWI.stop(); + statMWILabel->setPixmap(qPixmapFromMimeSource( + "mwi_none16.png")); + } else { + tmrFlashMWI.stop(); + statMWILabel->setPixmap(qPixmapFromMimeSource( + "mwi_none16_dis.png")); + } + + // Set tool tip + QToolTip::remove(statMWILabel); + QToolTip::add(statMWILabel, toolTip); + + updateSysTrayStatus(); +} + +// Update active services status +void MphoneForm::updateServicesStatus() +{ + size_t num_dnd = 0; + size_t num_cf = 0; + size_t num_auto_answer = 0; + QString tipDnd = ""; + tipDnd += tr("Do not disturb active for:").replace(' ', " "); + tipDnd += "
\n"; + QString tipCf = ""; + tipCf += tr("Redirection active for:").replace(' ', " "); + tipCf += "
\n
"; + QString tipAa = ""; + tipAa += tr("Auto answer active for:").replace(' ', " "); + tipAa += "
\n
"; + + // Calculate number of services active. + // Determine tool tips with detailed service status for all users. + listuser_list = phone->ref_users(); + for (list::iterator i = user_list.begin(); i != user_list.end(); i++) { + if (phone->ref_service(*i)->is_dnd_active()) { + num_dnd++; + tipDnd.append(""); + } + if (phone->ref_service(*i)->is_cf_active()) { + num_cf++; + tipCf.append(""); + } + if (phone->ref_service(*i)->is_auto_answer_active()) { + num_auto_answer++; + tipAa.append(""); + } + } + + QString footer = ""; + footer += tr("Click to activate/deactivate").replace(' ', " "); + footer += ""; + + tipDnd.append("
"); + tipDnd.append((*i)->get_profile_name().c_str()); + tipDnd.append("
"); + tipCf.append((*i)->get_profile_name().c_str()); + tipCf.append("
"); + tipAa.append((*i)->get_profile_name().c_str()); + tipAa.append("

"); + tipDnd.append(footer); + tipCf.append("
"); + tipCf.append(footer); + tipAa.append("
"); + tipAa.append(footer); + + // Set service status + if (num_dnd == user_list.size()) { + // All users enabled dnd + statDndLabel->setPixmap(QPixmap(":/icons/images/cancel.png")); + } else if (num_dnd > 0) { + // Some users enabled dnd + statDndLabel->setPixmap(QPixmap(":/icons/images/cancel.png")); + } else { + // No users enabeld dnd + statDndLabel->setPixmap(QPixmap(":/icons/images/cancel-disabled.png")); + } + + if (num_cf == user_list.size()) { + // All users enabled redirecton + statCfLabel->setPixmap(QPixmap(":/icons/images/cf.png")); + } else if (num_cf > 0) { + // Some users enabled redirection + statCfLabel->setPixmap(QPixmap(":/icons/images/cf.png")); + } else { + // No users enabled redirection + statCfLabel->setPixmap(QPixmap(":/icons/images/cf-disabled.png")); + } + + if (num_auto_answer == user_list.size()) { + // All users enabled auto answer + statAaLabel->setPixmap(QPixmap(":/icons/images/auto_answer.png")); + } else if (num_auto_answer > 0) { + // Some users enabled auto answer + statAaLabel->setPixmap(qPixmapFromMimeSource( + "auto_answer.png")); + } else { + // No users enabeld auto answer + statAaLabel->setPixmap(qPixmapFromMimeSource( + "auto_answer-disabled.png")); + } + + // Set tool tip with detailed info for multiple users. + QToolTip::remove(statDndLabel); + QToolTip::remove(statCfLabel); + QToolTip::remove(statAaLabel); + + QString clickToActivate(""); + clickToActivate += tr("Click to activate").replace(' ', " "); + clickToActivate += ""; + if (num_dnd > 0) { + QToolTip::add(statDndLabel, tipDnd); + } else { + QString status("

"); + status += tr("Do not disturb is not active.").replace(' ', " "); + status += "

"; + status += clickToActivate; + QToolTip::add(statDndLabel, status); + } + + if (num_cf > 0) { + QToolTip::add(statCfLabel, tipCf); + } else { + QString status("

"); + status += tr("Redirection is not active.").replace(' ', " "); + status += "

"; + status += clickToActivate; + QToolTip::add(statCfLabel, status); + } + + if (num_auto_answer > 0) { + QToolTip::add(statAaLabel, tipAa); + } else { + QString status("

"); + status += tr("Auto answer is not active.").replace(' ', " "); + status += "

"; + status += clickToActivate; + QToolTip::add(statAaLabel, status); + } + + updateSysTrayStatus(); +} + +void MphoneForm::updateMissedCallStatus(int num_missed_calls) +{ + QToolTip::remove(statMissedLabel); + + QString clickDetails(""); + clickDetails += tr("Click to see call history for details.").replace(' ', " "); + clickDetails += ""; + if (num_missed_calls == 0) { + statMissedLabel->setPixmap(QPixmap(":/icons/images/missed-disabled.png")); + QString status("

"); + status += tr("You have no missed calls.").replace(' ', " "); + status += "

"; + status += clickDetails; + QToolTip::add(statMissedLabel, status); + } else { + statMissedLabel->setPixmap( + QPixmap(":/icons/images/missed.png")); + + QString tip("

"); + if (num_missed_calls == 1) { + tip += tr("You missed 1 call.").replace(' ', " "); + } else { + tip += tr("You missed %1 calls.").arg(num_missed_calls). + replace(' ', " "); + } + tip += "

"; + tip += clickDetails; + QToolTip::add(statMissedLabel, tip); + } + + updateSysTrayStatus(); +} + +// Update system tray status +void MphoneForm::updateSysTrayStatus() +{ + QString icon_name; + bool cf_active = false; + bool dnd_active = false; + bool auto_answer_active = false; + bool multi_services = false; + int num_services; + bool msg_waiting = false; + + if (!sysTray) return; + + // Get status of active line + int line = phone->get_active_line(); + t_line_substate line_substate = phone->get_line_substate(line); + + list user_list = phone->ref_users(); + + switch(line_substate) { + case LSSUB_IDLE: + case LSSUB_SEIZED: + // Determine MWI and service status + user_list = phone->ref_users(); + for (list::iterator i = user_list.begin(); i != user_list.end(); i++) { + t_mwi mwi = phone->get_mwi(*i); + if (mwi.get_status() == t_mwi::MWI_KNOWN && + mwi.get_msg_waiting() && + mwi.get_voice_msg_summary().newmsgs > 0) + { + msg_waiting = true; + } else if (phone->ref_service(*i)->multiple_services_active()) { + multi_services = true; + } else { + if (phone->ref_service(*i)->is_dnd_active()) { + dnd_active = true; + } + if (phone->ref_service(*i)->is_cf_active()) { + cf_active = true; + } + if (phone->ref_service(*i)->is_auto_answer_active()) { + auto_answer_active = true; + } + } + } + + // If there are messages waiting, then show MWI icon + if (msg_waiting) { + icon_name = "sys_mwi"; + break; + } + + // If there are missed calls, then show the missed call icon + if (call_history->get_num_missed_calls() > 0) { + icon_name = "sys_missed"; + break; + } + + // If a service is active, then show the service icon + num_services = (dnd_active ? 1 : 0) + (cf_active ? 1 : 0) + + (auto_answer_active ? 1 : 0); + + if (multi_services || num_services > 1) { + icon_name = "sys_services"; + } else if (dnd_active) { + icon_name = "sys_dnd"; + } else if (cf_active) { + icon_name = "sys_redir"; + } else if (auto_answer_active) { + icon_name = "sys_auto_ans"; + } else { + // No service is active, show the idle icon + if (icon_name.isEmpty()) icon_name = "sys_idle"; + } + + break; + case LSSUB_ESTABLISHED: + if (phone->is_line_on_hold(line)) { + icon_name = "sys_hold"; + } else if (phone->is_line_muted(line)) { + icon_name = "sys_mute"; + } else if (phone->is_line_encrypted(line)) { + t_audio_session *as = phone->get_line(line)->get_audio_session(); + if (as && as->get_zrtp_sas_confirmed()) { + icon_name = "sys_encrypted_verified"; + } else { + icon_name = "sys_encrypted"; + } + } else { + icon_name = "sys_busy_estab"; + } + break; + default: + // Line is in a busy transient state + icon_name = "sys_busy_trans"; + } + + // Based on the registration status use the active or disabled version + // of the icon. + bool registered = false; + for (list::iterator i = user_list.begin(); i != user_list.end(); i++) { + if (phone->get_is_registered(*i)) { + registered = true; + break; + } + } + + if (registered) { + icon_name += ".png"; + } else { + icon_name += "_dis.png"; + } + + sysTray->setIcon(qPixmapFromMimeSource(icon_name)); +} + +// Update menu status based on the number of active users +void MphoneForm::updateMenuStatus() +{ + // Some menu options should be toggle actions when there is only + // 1 user active, but they should be normal actions when there are + // multiple users. + disconnect(serviceDnd, 0, 0, 0); + disconnect(serviceAutoAnswer, 0, 0, 0); + if (phone->ref_users().size() == 1) { + t_service *srv = phone->ref_service(phone->ref_users().front()); + + serviceDnd->setToggleAction(true); + serviceDnd->setOn(srv->is_dnd_active()); + connect(serviceDnd, SIGNAL(toggled(bool)), + this, SLOT(srvDnd(bool))); + + serviceAutoAnswer->setToggleAction(true); + serviceAutoAnswer->setOn(srv->is_auto_answer_active()); + connect(serviceAutoAnswer, SIGNAL(toggled(bool)), + this, SLOT(srvAutoAnswer(bool))); + } else { + serviceDnd->setOn(false); + serviceDnd->setToggleAction(false); + connect(serviceDnd, SIGNAL(activated()), + this, SLOT(srvDnd())); + + serviceAutoAnswer->setOn(false); + serviceAutoAnswer->setToggleAction(false); + connect(serviceAutoAnswer, SIGNAL(activated()), + this, SLOT(srvAutoAnswer())); + } + + updateDiamondcardMenu(); +} + +void MphoneForm::updateDiamondcardMenu() +{ + // If one Diamondcard user is active, then create actions in the Diamondcard + // main menu for recharging, call history, etc. These actions will show the + // Diamondcard web page. + // If multiple Diamondcard users are active then create a submenu of each + // Diamondcard action. In each submenu create an item for each user. + // When a user item is clicked, the web page for the action and that user is + // shown. + list diamondcard_users = diamondcard_get_users(phone); + + // Menu item identifiers + static int rechargeId = -1; + static int balanceHistoryId = -1; + static int callHistoryId = -1; + static int adminCenterId = -1; + + // Sub menu's + static Q3PopupMenu *rechargeMenu = NULL; + static Q3PopupMenu *balanceHistoryMenu = NULL; + static Q3PopupMenu *callHistoryMenu = NULL; + static Q3PopupMenu *adminCenterMenu = NULL; + + // Clear old menu + removeDiamondcardAction(rechargeId); + removeDiamondcardAction(balanceHistoryId); + removeDiamondcardAction(callHistoryId); + removeDiamondcardAction(adminCenterId); + removeDiamondcardMenu(rechargeMenu); + removeDiamondcardMenu(balanceHistoryMenu); + removeDiamondcardMenu(callHistoryMenu); + removeDiamondcardMenu(adminCenterMenu); + + if (diamondcard_users.size() <= 1) + { + rechargeId = Diamondcard->insertItem(tr("Recharge..."), this, SLOT(DiamondcardRecharge(int))); + Diamondcard->setItemParameter(rechargeId, 0); + balanceHistoryId = Diamondcard->insertItem(tr("Balance history..."), this, SLOT(DiamondcardBalanceHistory(int))); + Diamondcard->setItemParameter(balanceHistoryId, 0); + callHistoryId = Diamondcard->insertItem(tr("Call history..."), this, SLOT(DiamondcardCallHistory(int))); + Diamondcard->setItemParameter(callHistoryId, 0); + adminCenterId = Diamondcard->insertItem(tr("Admin center..."), this, SLOT(DiamondcardAdminCenter(int))); + Diamondcard->setItemParameter(adminCenterId, 0); + + // Disable actions as there is no active Diamondcard users. + if (diamondcard_users.empty()) { + Diamondcard->setItemEnabled(rechargeId, false); + Diamondcard->setItemEnabled(balanceHistoryId, false); + Diamondcard->setItemEnabled(callHistoryId, false); + Diamondcard->setItemEnabled(adminCenterId, false); + } + } + else + { + rechargeMenu = new Q3PopupMenu(this); + balanceHistoryMenu = new Q3PopupMenu(this); + callHistoryMenu = new Q3PopupMenu(this); + adminCenterMenu = new Q3PopupMenu(this); + // No MEMMAN registration as the popup menu may be automatically + // deleted by Qt on application close down. This would show up as + // a memory leak in MEMMAN. + + // Insert a menu item for each Diamondcard user. + int idx = 0; + for (list::const_iterator it = diamondcard_users.begin(); + it != diamondcard_users.end(); ++it) + { + int menuId; + t_user *user = *it; + + // Set the index in the user list as parameter to the menu item. + // When the menu item gets clicked, then the receiver of the signal + // received this parameter and can use it as an index in the user list + // to find the user. + + menuId = rechargeMenu->insertItem(user->get_profile_name().c_str(), this, + SLOT(DiamondcardRecharge(int))); + rechargeMenu->setItemParameter(menuId, idx); + menuId = balanceHistoryMenu->insertItem(user->get_profile_name().c_str(), this, + SLOT(DiamondcardBalanceHistory(int))); + balanceHistoryMenu->setItemParameter(menuId, idx); + menuId = callHistoryMenu->insertItem(user->get_profile_name().c_str(), this, + SLOT(DiamondcardCallHistory(int))); + callHistoryMenu->setItemParameter(menuId, idx); + menuId = adminCenterMenu->insertItem(user->get_profile_name().c_str(), this, + SLOT(DiamondcardAdminCenter(int))); + adminCenterMenu->setItemParameter(menuId, idx); + + ++idx; + } + + // Add the Diamondcard popup menus to the main Diamondcard menu. + Diamondcard->insertItem(tr("Recharge"), rechargeMenu); + Diamondcard->insertItem(tr("Balance history"), balanceHistoryMenu); + Diamondcard->insertItem(tr("Call history"), callHistoryMenu); + Diamondcard->insertItem(tr("Admin center"), adminCenterMenu); + } +} + +void MphoneForm::removeDiamondcardAction(int &id) +{ + if (id != -1) { + Diamondcard->removeItem(id); + id = -1; + } +} + +void MphoneForm::removeDiamondcardMenu(Q3PopupMenu* &menu) +{ + if (menu) { + delete menu; + menu = NULL; + } +} + +void MphoneForm::phoneRegister() +{ + t_gui *gui = (t_gui *)ui; + list user_list = phone->ref_users(); + + if (user_list.size() > 1) { + if (selectUserForm) { + MEMMAN_DELETE(selectUserForm); + delete (selectUserForm); + } + + selectUserForm = new SelectUserForm(this, "register", true); + MEMMAN_NEW(selectUserForm); + + connect(selectUserForm, SIGNAL(selection(list)), this, + SLOT(do_phoneRegister(list))); + selectUserForm->show(SELECT_REGISTER); + } else { + gui->action_register(user_list); + } +} + +void MphoneForm::do_phoneRegister(list user_list) +{ + ((t_gui *)ui)->action_register(user_list); +} + +void MphoneForm::phoneDeregister() +{ + t_gui *gui = (t_gui *)ui; + list user_list = phone->ref_users(); + + if (user_list.size() > 1) { + if (selectUserForm) { + MEMMAN_DELETE(selectUserForm); + delete (selectUserForm); + } + + selectUserForm = new SelectUserForm(this, "deregister", true); + MEMMAN_NEW(selectUserForm); + + connect(selectUserForm, SIGNAL(selection(list)), this, + SLOT(do_phoneDeregister(list))); + selectUserForm->show(SELECT_DEREGISTER); + } else { + gui->action_deregister(user_list, false); + } +} + +void MphoneForm::do_phoneDeregister(list user_list) +{ + ((t_gui *)ui)->action_deregister(user_list, false); +} + +void MphoneForm::phoneDeregisterAll() +{ + t_gui *gui = (t_gui *)ui; + list user_list = phone->ref_users(); + + if (user_list.size() > 1) { + if (selectUserForm) { + MEMMAN_DELETE(selectUserForm); + delete (selectUserForm); + } + + selectUserForm = new SelectUserForm(this, "deregister all", true); + MEMMAN_NEW(selectUserForm); + + connect(selectUserForm, SIGNAL(selection(list)), this, + SLOT(do_phoneDeregisterAll(list))); + selectUserForm->show(SELECT_DEREGISTER_ALL); + } else { + gui->action_deregister(user_list, true); + } +} + +void MphoneForm::do_phoneDeregisterAll(list user_list) +{ + ((t_gui *)ui)->action_deregister(user_list, true); +} + +void MphoneForm::phoneShowRegistrations() +{ + list user_list = phone->ref_users(); + ((t_gui *)ui)->action_show_registrations(user_list); +} + + +// Show the semi-modal invite window +void MphoneForm::phoneInvite(t_user * user_config, + const QString &dest, const QString &subject, bool anonymous) +{ + // Seize the line, so no incoming call can take the line + if (!((t_gui *)ui)->action_seize()) return; + + if (inviteForm) { + inviteForm->clear(); + } else { + inviteForm = new InviteForm(this, "invite", true); + MEMMAN_NEW(inviteForm); + + // Initialize the destination history list + for (int i = callComboBox->count() - 1; i >= 0; i--) { + inviteForm->addToInviteComboBox(callComboBox->text(i)); + } + + connect(inviteForm, + SIGNAL(destination(t_user *, const QString &, const t_url &, + const QString &, bool)), + this, + SLOT(do_phoneInvite(t_user *, const QString &, + const t_url &, const QString &, bool))); + + connect(inviteForm, SIGNAL(raw_destination(const QString &)), + this, SLOT(addToCallComboBox(const QString &))); + } + + inviteForm->show(user_config, dest, subject, anonymous); + updateState(); +} + +void MphoneForm::phoneInvite(const QString &dest, const QString &subject, bool anonymous) +{ + t_user *user = phone->ref_user_profile(userComboBox->currentText().ascii()); + if (!user) { + log_file->write_report("Cannot find user profile.", + "MphoneForm::phoneInvite", + LOG_NORMAL, LOG_CRITICAL); + return; + } + phoneInvite(user, dest, subject, anonymous); +} + +void MphoneForm::phoneInvite() +{ + t_user *user = phone->ref_user_profile(userComboBox->currentText().ascii()); + if (!user) { + log_file->write_report("Cannot find user profile.", + "MphoneForm::phoneInvite", + LOG_NORMAL, LOG_CRITICAL); + return; + } + phoneInvite(user, "", "", false); +} + +// Execute the invite action. This slot is connected to the destination +// signal of the invite window. +void MphoneForm::do_phoneInvite(t_user *user_config, const QString &display, + const t_url &destination, const QString &subject, + bool anonymous) +{ + ((t_gui *)ui)->action_invite(user_config, destination, display.ascii(), subject.ascii(), + anonymous); + updateState(); +} + +// Redial last call +void MphoneForm::phoneRedial(void) +{ + t_url url; + string display, subject; + t_user *user_config; + bool hide_user; + + if (!ui->get_last_call_info(url, display, subject, &user_config, hide_user)) return; + ((t_gui *)ui)->action_invite(user_config, url, display, subject, hide_user); + updateState(); +} + + +void MphoneForm::phoneAnswer() +{ + ((t_gui *)ui)->action_answer(); + updateState(); +} + +// A call can be answered from the systray popup. The user may have +// switched lines, the systray popup answer button should answer the +// correct line. +void MphoneForm::phoneAnswerFromSystrayPopup() +{ +#ifdef HAVE_KDE + unsigned short line = ((t_gui *)ui)->get_line_sys_tray_popup(); + unsigned short active_line = phone->get_active_line(); + + if (line != active_line) { + ((t_gui *)ui)->action_activate_line(line); + } + + ((t_gui *)ui)->action_answer(); + updateState(); +#endif +} + +void MphoneForm::phoneBye() +{ + ((t_gui *)ui)->action_bye(); + updateState(); +} + + +void MphoneForm::phoneReject() +{ + ((t_gui *)ui)->action_reject(); + updateState(); +} + +// A call can be rejected from the systray popup. The user may have +// switched lines, the systray popup reject button should answer the +// correct line. +void MphoneForm::phoneRejectFromSystrayPopup() +{ +#ifdef HAVE_KDE + unsigned short line = ((t_gui *)ui)->get_line_sys_tray_popup(); + ((t_gui *)ui)->action_reject(line); + updateState(); +#endif +} + + +// Show the semi-modal redirect form +void MphoneForm::phoneRedirect(const list &contacts) +{ + int active_line = phone->get_active_line(); + t_user *user_config = phone->get_line_user(active_line); + + if (redirectForm) { + MEMMAN_DELETE(redirectForm); + delete (redirectForm); + } + + redirectForm = new RedirectForm(this, "redirect", true); + MEMMAN_NEW(redirectForm); + connect(redirectForm, SIGNAL(destinations(const list &)), + this, SLOT(do_phoneRedirect(const list &))); + + redirectForm->show(user_config, contacts); +} + +void MphoneForm::phoneRedirect() +{ + const list l; + phoneRedirect(l); +} + +// Execute the redirect action. +void MphoneForm::do_phoneRedirect(const list &destinations) +{ + ((t_gui *)ui)->action_redirect(destinations); + updateState(); +} + +// Show the semi-modal call transfer window +void MphoneForm::phoneTransfer(const string &dest, t_transfer_type transfer_type) +{ + int active_line = phone->get_active_line(); + t_user *user_config = phone->get_line_user(active_line); + + // Hold the call if setting in user profile indicates call hold + if (user_config->get_referrer_hold()) { + phoneHold(true); + } + + if (transferForm) { + MEMMAN_DELETE(transferForm); + delete transferForm; + } + + transferForm = new TransferForm(this, "transfer", true); + MEMMAN_NEW(transferForm); + connect(transferForm, SIGNAL(destination(const t_display_url &, t_transfer_type)), + this, SLOT(do_phoneTransfer(const t_display_url &, t_transfer_type))); + + if (dest.empty() && transfer_type == TRANSFER_BASIC) { + // Let form pick a default transfer type based on the current + // call status. + transferForm->show(user_config); + } else { + // Set passed destination and transfer type in form + transferForm->show(user_config, dest, transfer_type); + } + updateState(); +} + +void MphoneForm::phoneTransfer() +{ + unsigned short active_line = phone->get_active_line(); + unsigned short dummy; + + if (phone->is_line_transfer_consult(active_line, dummy)) { + do_phoneTransferLine(); + } else { + phoneTransfer("", TRANSFER_BASIC); + } +} + +// Execute the transfer action. This slot is connected to the destination +// signal of the transfer window. +void MphoneForm::do_phoneTransfer(const t_display_url &destination, + t_transfer_type transfer_type) +{ + unsigned short active_line; + unsigned short other_line; + + switch (transfer_type) { + case TRANSFER_BASIC: + ((t_gui *)ui)->action_refer(destination.url, destination.display); + break; + case TRANSFER_CONSULT: + ((t_gui *)ui)->action_setup_consultation_call( + destination.url, destination.display); + break; + case TRANSFER_OTHER_LINE: + active_line = phone->get_active_line(); + other_line = (active_line == 0 ? 1 : 0); + + if (phone->get_line_substate(other_line) == LSSUB_ESTABLISHED) { + ((t_gui *)ui)->action_refer(active_line, other_line); + } else { + // The other line was released while the user was entering + // the refer-target. + t_user *user_config = phone->get_line_user(active_line); + if (user_config->get_referrer_hold()) { + phoneHold(false); + } + } + break; + default: + assert(false); + } + + updateState(); +} + +// Transfer the remote party on the held line to the remote party on the +// active line. +void MphoneForm::do_phoneTransferLine() +{ + unsigned short active_line = phone->get_active_line(); + unsigned short line_to_be_transferred; + + if (!phone->is_line_transfer_consult(active_line, line_to_be_transferred)) { + // Somehow the line is not a consultation call. + updateState(); + return; + } + + ((t_gui *)ui)->action_refer(line_to_be_transferred, active_line); + updateState(); +} + +void MphoneForm::phoneHold(bool on) +{ + if (on) { + ((t_gui *)ui)->action_hold(); + } else { + ((t_gui *)ui)->action_retrieve(); + } + + updateState(); +} + +void MphoneForm::phoneConference() +{ + ((t_gui *)ui)->action_conference(); + updateState(); +} + +void MphoneForm::phoneMute(bool on) +{ + ((t_gui *)ui)->action_mute(on); + updateState(); +} + +void MphoneForm::phoneTermCap(const QString &dest) +{ + // In-dialog OPTIONS request + int line = phone->get_active_line(); + if (phone->get_line_substate(line) == LSSUB_ESTABLISHED) { + ((t_gui *)ui)->action_options(); + return; + } + + // Out-of-dialog OPTIONS request + if (termCapForm) { + MEMMAN_DELETE(termCapForm); + delete (termCapForm); + } + + termCapForm = new TermCapForm(this, "termcap", true); + MEMMAN_NEW(termCapForm); + connect(termCapForm, SIGNAL(destination(t_user *, const t_url &)), + this, SLOT(do_phoneTermCap(t_user *, const t_url &))); + + t_user *user = phone->ref_user_profile(userComboBox->currentText().ascii()); + if (!user) { + log_file->write_report("Cannot find user profile.", + "MphoneForm::phoneTermcap", + LOG_NORMAL, LOG_CRITICAL); + return; + } + termCapForm->show(user, dest); +} + +void MphoneForm::phoneTermCap() +{ + phoneTermCap(""); +} + +void MphoneForm::do_phoneTermCap(t_user *user_config, const t_url &destination) +{ + ((t_gui *)ui)->action_options(user_config, destination); +} + +void MphoneForm::phoneDTMF() +{ + if (!dtmfForm) { + dtmfForm = new DtmfForm(this); + MEMMAN_NEW(dtmfForm); + connect(dtmfForm, SIGNAL(digits(const QString &)), + this, SLOT(sendDTMF(const QString &))); + } + + dtmfForm->show(); +} + +void MphoneForm::sendDTMF(const QString &digits) +{ + ((t_gui *)ui)->action_dtmf(digits.ascii()); +} + +void MphoneForm::startMessageSession(void) +{ + t_user *user = phone->ref_user_profile(userComboBox->currentText().ascii()); + if (!user) { + log_file->write_report("Cannot find user profile.", + "MphoneForm::startMessageSession", + LOG_NORMAL, LOG_CRITICAL); + return; + } + + im::t_msg_session *session = new im::t_msg_session(user); + MEMMAN_NEW(session); + ((t_gui *)ui)->addMessageSession(session); + MessageFormView *messageFormView = new MessageFormView(NULL, session); + MEMMAN_NEW(messageFormView); + messageFormView->show(); +} + +void MphoneForm::startMessageSession(t_buddy *buddy) +{ + t_user *user_config = buddy->get_user_profile(); + t_url dest_url(ui->expand_destination(user_config, buddy->get_sip_address())); + if (!dest_url.is_valid()) return; + string display = buddy->get_name(); + + // Find an existing session + im::t_msg_session *session = ((t_gui *)ui)->getMessageSession(user_config, dest_url, display); + if (!session) { + // There is no session yet, create one. + session = new im::t_msg_session(user_config, t_display_url(dest_url, display)); + MEMMAN_NEW(session); + ((t_gui *)ui)->addMessageSession(session); + MessageFormView *view = new MessageFormView(NULL, session); + MEMMAN_NEW(view); + view->show(); + } +} + +void MphoneForm::phoneConfirmZrtpSas(int line) +{ + ((t_gui *)ui)->action_confirm_zrtp_sas(line); + updateState(); +} + +void MphoneForm::phoneConfirmZrtpSas() +{ + ((t_gui *)ui)->action_confirm_zrtp_sas(); + updateState(); +} + +void MphoneForm::phoneResetZrtpSasConfirmation(int line) +{ + ((t_gui *)ui)->action_reset_zrtp_sas_confirmation(line); + updateState(); +} + +void MphoneForm::phoneResetZrtpSasConfirmation() +{ + ((t_gui *)ui)->action_reset_zrtp_sas_confirmation(); + updateState(); +} + +void MphoneForm::phoneEnableZrtp(bool on) +{ + if (on) { + ((t_gui *)ui)->action_enable_zrtp(); + } else { + ((t_gui *)ui)->action_zrtp_request_go_clear(); + } + + updateState(); +} + +void MphoneForm::phoneZrtpGoClearOk(unsigned short line) +{ + ((t_gui *)ui)->action_zrtp_go_clear_ok(line); + updateState(); +} + +// Radio button for line 1 changed state +void MphoneForm::line1rbChangedState( bool on ) +{ + // If the radio button is switched off, then return, the toggle + // on the other line will handle the action + if (!on) return; + + ((t_gui *)ui)->action_activate_line(0); +} + +void MphoneForm::line2rbChangedState( bool on ) +{ + // If the radio button is switched off, then return, the toggle + // on the other line will handle the action + if (!on) return; + + ((t_gui *)ui)->action_activate_line(1); +} + +void MphoneForm::actionLine1Toggled( bool on) +{ + if (!on) return; + ((t_gui *)ui)->action_activate_line(0); +} + +void MphoneForm::actionLine2Toggled( bool on) +{ + if (!on) return; + ((t_gui *)ui)->action_activate_line(1); +} + +// Enable/disable dnd when there is 1 user active +void MphoneForm::srvDnd( bool on ) +{ + ((t_gui *)ui)->srv_dnd(phone->ref_users(), on); + updateServicesStatus(); +} + +// Enable/disable dnd when there are multiple users active +void MphoneForm::srvDnd() +{ + if (selectUserForm) { + MEMMAN_DELETE(selectUserForm); + delete (selectUserForm); + } + + selectUserForm = new SelectUserForm(this, "dnd", true); + MEMMAN_NEW(selectUserForm); + + connect(selectUserForm, SIGNAL(selection(list)), this, + SLOT(do_srvDnd_enable(list))); + connect(selectUserForm, SIGNAL(not_selected(list)), this, + SLOT(do_srvDnd_disable(list))); + + selectUserForm->show(SELECT_DND); +} + +void MphoneForm::do_srvDnd_enable(list user_list) { + ((t_gui *)ui)->srv_dnd(user_list, true); + updateServicesStatus(); +} + +void MphoneForm::do_srvDnd_disable(list user_list) { + ((t_gui *)ui)->srv_dnd(user_list, false); + updateServicesStatus(); +} + +// Enable/disable auto answer when there is 1 user active +void MphoneForm::srvAutoAnswer( bool on ) +{ + ((t_gui *)ui)->srv_auto_answer(phone->ref_users(), on); + updateServicesStatus(); +} + +// Enable/disable auto answer when there are multiple users active +void MphoneForm::srvAutoAnswer() +{ + if (selectUserForm) { + MEMMAN_DELETE(selectUserForm); + delete (selectUserForm); + } + + selectUserForm = new SelectUserForm(this, "auto answer", true); + MEMMAN_NEW(selectUserForm); + + connect(selectUserForm, SIGNAL(selection(list)), this, + SLOT(do_srvAutoAnswer_enable(list))); + connect(selectUserForm, SIGNAL(not_selected(list)), this, + SLOT(do_srvAutoAnswer_disable(list))); + + selectUserForm->show(SELECT_AUTO_ANSWER); +} + +void MphoneForm::do_srvAutoAnswer_enable(list user_list) { + ((t_gui *)ui)->srv_auto_answer(user_list, true); + updateServicesStatus(); +} + +void MphoneForm::do_srvAutoAnswer_disable(list user_list) { + ((t_gui *)ui)->srv_auto_answer(user_list, false); + updateServicesStatus(); +} + +void MphoneForm::srvRedirect() +{ + if (!srvRedirectForm) { + srvRedirectForm = new SrvRedirectForm(this, "call redirection", true); + MEMMAN_NEW(srvRedirectForm); + connect(srvRedirectForm, + SIGNAL(destinations(t_user *, + const list &, + const list &, + const list &)), + this, + SLOT(do_srvRedirect(t_user *, + const list &, + const list &, + const list &))); + } + + srvRedirectForm->show(); +} + +void MphoneForm::do_srvRedirect(t_user *user_config, + const list &always, + const list &busy, + const list &noanswer) +{ + // Redirection always + if (always.empty()) { + ((t_gui *)ui)->srv_disable_cf(user_config, CF_ALWAYS); + } else { + ((t_gui *)ui)->srv_enable_cf(user_config, CF_ALWAYS, always); + } + + // Redirection busy + if (busy.empty()) { + ((t_gui *)ui)->srv_disable_cf(user_config, CF_BUSY); + } else { + ((t_gui *)ui)->srv_enable_cf(user_config, CF_BUSY, busy); + } + + // Redirection no answer + if (noanswer.empty()) { + ((t_gui *)ui)->srv_disable_cf(user_config, CF_NOANSWER); + } else { + ((t_gui *)ui)->srv_enable_cf(user_config, CF_NOANSWER, noanswer); + } + + updateServicesStatus(); +} + + +void MphoneForm::about() +{ + QString s = sys_config->about(true).c_str(); + + QMessageBox mbAbout(PRODUCT_NAME, s.replace(' ', " "), + QMessageBox::Information, + QMessageBox::Ok | QMessageBox::Default, + QMessageBox::NoButton, QMessageBox::NoButton); + mbAbout.setIconPixmap(QPixmap(":/icons/images/twinkle48.png")); + mbAbout.exec(); +} + +void MphoneForm::aboutQt() +{ + QMessageBox::aboutQt(this, PRODUCT_NAME); +} + +void MphoneForm::manual() +{ + ((t_gui *)ui)->open_url_in_browser("http://www.twinklephone.com"); +} + +void MphoneForm::editUserProfile() +{ + if (!userProfileForm) { + userProfileForm = new UserProfileForm(this, "user profile", true); + MEMMAN_NEW(userProfileForm); + + connect(userProfileForm, + SIGNAL(authCredentialsChanged(t_user *, const string&)), + this, + SLOT(updateAuthCache(t_user *, const string&))); + + connect(userProfileForm, + SIGNAL(stunServerChanged(t_user *)), + this, + SLOT(updateStunSettings(t_user *))); + + // MWI settings change triggers an unsubscribe + connect(userProfileForm, + SIGNAL(mwiChangeUnsubscribe(t_user *)), + this, + SLOT(unsubscribeMWI(t_user *))); + + // MWI settings change triggers a subscribe + connect(userProfileForm, + SIGNAL(mwiChangeSubscribe(t_user *)), + this, + SLOT(subscribeMWI(t_user *))); + } + + userProfileForm->show(phone->ref_users(), + userComboBox->currentText()); +} + +void MphoneForm::editSysSettings() +{ + if (!sysSettingsForm) { + sysSettingsForm = new SysSettingsForm(this, "system settings", true); + MEMMAN_NEW(sysSettingsForm); + connect(sysSettingsForm, SIGNAL(sipUdpPortChanged()), + this, SLOT(updateSipUdpPort())); + connect(sysSettingsForm, SIGNAL(rtpPortChanged()), + this, SLOT(updateRtpPorts())); + } + + sysSettingsForm->show(); +} + +void MphoneForm::selectProfile() +{ + if (!selectProfileForm) { + selectProfileForm = new SelectProfileForm(this, "select profile", true); + MEMMAN_NEW(selectProfileForm); + connect(selectProfileForm, SIGNAL(selection(const list &)), + this, SLOT(newUsers(const list &))); + connect(selectProfileForm, SIGNAL(profileRenamed()), + this, SLOT(updateUserComboBox())); + connect(selectProfileForm, SIGNAL(profileRenamed()), + this, SLOT(populateBuddyList())); + } + + selectProfileForm->showForm(this); +} + +// A new set of users has been selected. +// Remove users from the current user set that are not in the selection. +// Add users from the selection that are not in the current set of users. +void MphoneForm::newUsers(const list &profiles) +{ + string error_msg; + + // NOTE: First users must be removed. It could be that a + // user profile of an active was renamed. In this case, the user + // with the old profile name is first removed and then added again. + + list user_list = phone->ref_users(); + + // Remove current users that are not selected anymore. + for (list::iterator i = user_list.begin(); i != user_list.end(); i++) { + if (std::find(profiles.begin(), profiles.end(), + (*i)->get_filename().c_str()) == profiles.end()) + { + // User is not selected anymore. + // Unsubscribe MWI + if (phone->is_mwi_subscribed(*i)) { + phone->pub_unsubscribe_mwi(*i); + } + + // Unpublish presence of user + phone->pub_unpublish_presence(*i); + + // Unsubscribe presence + phone->pub_unsubscribe_presence(*i); + + // Deregister user + if (phone->get_is_registered(*i)) { + phone->pub_registration(*i, REG_DEREGISTER); + } + + log_file->write_header("MphoneForm::newUsers"); + log_file->write_raw("Stop user profile: "); + log_file->write_raw((*i)->get_profile_name()); + log_file->write_endl(); + log_file->write_footer(); + phone->remove_phone_user(*(*i)); + } + } + + // Determine which users to add + list add_profile_list; + for (list::const_iterator i = profiles.begin(); i != profiles.end(); i++) { + QString profile = (*i).c_str(); + // Strip off the .cfg extension + profile.truncate(profile.length() - 4); + + if (!phone->ref_user_profile(profile.ascii())) { + add_profile_list.push_back(*i); + } + } + + // Add new phone users + Q3ProgressDialog progress(tr("Starting user profiles..."), "Abort", add_profile_list.size(), this, + "starting user profiles", true); + progress.setCaption(PRODUCT_NAME); + progress.setMinimumDuration(200); + int progressStep = 0; + for (list::iterator i = add_profile_list.begin(); i != add_profile_list.end(); i++) { + progress.setProgress(progressStep); + qApp->processEvents(); + + if (progress.wasCancelled()) { + log_file->write_report("User aborted startup of new users.", + "MphoneForm::newUsers"); + break; + } + + t_user user_config; + + // Read user configuration + if (user_config.read_config(*i, error_msg)) { + t_user *dup_user; + + log_file->write_header("MphoneForm::newUsers"); + log_file->write_raw("Run user profile: "); + log_file->write_raw(user_config.get_profile_name()); + log_file->write_endl(); + log_file->write_footer(); + + if (phone->add_phone_user(user_config, &dup_user)) + { + // NAT discovery + if (!phone->stun_discover_nat(&user_config, error_msg)) + { + // Warn user that the STUN settings will not work. + ((t_gui *)ui)->cb_show_msg(this, error_msg, + MSG_WARNING); + } + + // Register at startup + if (user_config.get_register_at_startup()) { + phone->pub_registration(&user_config, + REG_REGISTER, + DUR_REGISTRATION(&user_config)); + } else { + // No registration needed, initialize extensions now. + phone->init_extensions(&user_config); + } + + // Extension initialization will be done after + // registration succeeded. + } else { + error_msg = tr("The following profiles are both for user %1").arg(user_config.get_name().c_str()).ascii(); + error_msg += '@'; + error_msg += user_config.get_domain(); + error_msg += ":\n\n"; + error_msg += user_config.get_profile_name(); + error_msg += "\n"; + error_msg += dup_user->get_profile_name(); + error_msg += "\n\n"; + error_msg += tr("You can only run multiple profiles for different users.").ascii(); + + log_file->write_report(error_msg, + "MphoneForm::newUsers", + LOG_NORMAL, LOG_WARNING); + ui->cb_display_msg(error_msg, MSG_WARNING); + } + } else { + log_file->write_report(error_msg, + "MphoneForm::newUsers", + LOG_NORMAL, LOG_CRITICAL); + ui->cb_display_msg(error_msg, MSG_CRITICAL); + } + + progressStep++; + } + progress.setProgress(add_profile_list.size()); + + populateBuddyList(); + updateUserComboBox(); + updateRegStatus(); + updateMwi(); + updateServicesStatus(); + updateSysTrayStatus(); + updateMenuStatus(); + updateState(); + + call_history->clear_num_missed_calls(); +} + +void MphoneForm::updateUserComboBox() +{ + QString current_user; + + if (userComboBox->count() == 0) { + // The last used profile + current_user = sys_config->get_last_used_profile().c_str(); + } else { + // Keep the current active profile + current_user = userComboBox->currentText(); + } + + ((t_gui *)ui)->fill_user_combo(userComboBox); + + // If previous selected user is still active, make it the current user + for (int i = 0; i < userComboBox->count(); i++) { + if (userComboBox->text(i) == current_user) { + userComboBox->setCurrentItem(i); + } + } +} + +void MphoneForm::updateSipUdpPort() +{ + ((t_gui *)ui)->cb_show_msg(sysSettingsForm, + tr("You have changed the SIP UDP port. This setting will only become "\ + "active when you restart Twinkle.").ascii(), + MSG_INFO); +} + +void MphoneForm::updateRtpPorts() +{ + phone->init_rtp_ports(); +} + +void MphoneForm::updateStunSettings(t_user *user_config) +{ + string s; + if (!phone->stun_discover_nat(user_config, s)) { + // Warn user that the STUN settings will not work. + ((t_gui *)ui)->cb_show_msg(this, s, MSG_WARNING); + } + + if (!user_config->get_use_stun()) { + // Disable STUN + phone->disable_stun(user_config); + } + + // Synchronize the sending of NAT keep alives with the user profile settings. + phone->sync_nat_keepalive(user_config); +} + +void MphoneForm::updateAuthCache(t_user *user_config, const string &realm) +{ + phone->remove_cached_credentials(user_config, realm); +} + +void MphoneForm::unsubscribeMWI(t_user *user_config) +{ + phone->pub_unsubscribe_mwi(user_config); +} + +void MphoneForm::subscribeMWI(t_user *user_config) +{ + phone->pub_subscribe_mwi(user_config); +} + +void MphoneForm::viewLog() +{ + if (!logViewForm) { + logViewForm = new LogViewForm(NULL); + MEMMAN_NEW(logViewForm); + } + + logViewForm->show(); +} + +void MphoneForm::updateLog(bool log_zapped) +{ + if (logViewForm) logViewForm->update(log_zapped); +} + +void MphoneForm::viewHistory() +{ + if (!historyForm) { + historyForm = new HistoryForm(NULL); + MEMMAN_NEW(historyForm); + } + + connect(historyForm, + SIGNAL(call(t_user *, const QString &, const QString &, bool)), this, + SLOT(phoneInvite(t_user *, const QString &, const QString &, bool))); + + historyForm->show(); +} + +void MphoneForm::updateCallHistory() +{ + if (historyForm) historyForm->update(); +} + +QSystemTrayIcon *MphoneForm::getSysTray() +{ + return sysTray; +} + +// Execute call directly from the main window (press call button) +void MphoneForm::quickCall() +{ + string display, dest_str; + + t_user *from_user = phone->ref_user_profile( + userComboBox->currentText().ascii()); + if (!from_user) { + log_file->write_report("Cannot find user profile.", + "MphoneForm::quickCall", + LOG_NORMAL, LOG_CRITICAL); + return; + } + + ui->expand_destination(from_user, + callComboBox->currentText().stripWhiteSpace().ascii(), + display, dest_str); + t_url dest(dest_str); + + if (dest.is_valid()) { + QString destination = callComboBox->currentText(); + addToCallComboBox(destination); + if (inviteForm) inviteForm->addToInviteComboBox(destination); + callComboBox->setFocus(); + do_phoneInvite(from_user, display.c_str(), dest, "", false); + } +} + +// Add a destination to the list of callComboBox +void MphoneForm::addToCallComboBox(const QString &destination) +{ + // Remove duplicate entries + for (int i = callComboBox->count() - 1; i >= 0; i--) { + if (callComboBox->text(i) == destination) { + callComboBox->removeItem(i); + } + } + + // Add entry + callComboBox->insertItem(destination, 0); + callComboBox->setCurrentItem(0); + + // Remove last entry is list exceeds maximum size + if (callComboBox->count() > SIZE_REDIAL_LIST) { + callComboBox->removeItem(callComboBox->count() - 1); + } + + // Clearing the edit line must be done here as this function is + // also called when a call is made through the inviteForm. + // The insertItem puts the text also in the edit field. So it must + // be cleared here. + callComboBox->clearEdit(); +} + +void MphoneForm::showAddressBook() +{ + if (!getAddressForm) { + getAddressForm = new GetAddressForm( + this, "select address", true); + MEMMAN_NEW(getAddressForm); + } + + connect(getAddressForm, + SIGNAL(address(const QString &)), + this, SLOT(selectedAddress(const QString &))); + + getAddressForm->show(); +} + +void MphoneForm::selectedAddress(const QString &address) +{ + callComboBox->setEditText(address); +} + +// Enable/disable the various call widgets +void MphoneForm::enableCallOptions(bool enable) +{ + // Enable/disable widgets + callInvite->setEnabled(enable); + callPushButton->setEnabled(enable); + callComboBox->setEnabled(enable); + addressToolButton->setEnabled(enable); + + // Set focus on callComboBox + if (enable) { + callComboBox->setFocus(); + } +} + +void MphoneForm::keyPressEvent(QKeyEvent *e) +{ + if (callPushButton->isEnabled()) { + // Quick dial + switch (e->key()) { + case Qt::Key_Return: + case Qt::Key_Enter: + quickCall(); + break; + default: + e->ignore(); + } + } else if (callDTMF->isEnabled()) { + // DTMF keys + switch (e->key()) { + case Qt::Key_1: + sendDTMF("1"); + break; + case Qt::Key_2: + case Qt::Key_A: + case Qt::Key_B: + case Qt::Key_C: + sendDTMF("2"); + break; + case Qt::Key_3: + case Qt::Key_D: + case Qt::Key_E: + case Qt::Key_F: + sendDTMF("3"); + break; + case Qt::Key_4: + case Qt::Key_G: + case Qt::Key_H: + case Qt::Key_I: + sendDTMF("4"); + break; + case Qt::Key_5: + case Qt::Key_J: + case Qt::Key_K: + case Qt::Key_L: + sendDTMF("5"); + break; + case Qt::Key_6: + case Qt::Key_M: + case Qt::Key_N: + case Qt::Key_O: + sendDTMF("6"); + break; + case Qt::Key_7: + case Qt::Key_P: + case Qt::Key_Q: + case Qt::Key_R: + case Qt::Key_S: + sendDTMF("7"); + break; + case Qt::Key_8: + case Qt::Key_T: + case Qt::Key_U: + case Qt::Key_V: + sendDTMF("8"); + break; + case Qt::Key_9: + case Qt::Key_W: + case Qt::Key_X: + case Qt::Key_Y: + case Qt::Key_Z: + sendDTMF("9"); + break; + case Qt::Key_0: + case Qt::Key_Space: + sendDTMF("0"); + break; + case Qt::Key_Asterisk: + sendDTMF("*"); + break; + case Qt::Key_NumberSign: + sendDTMF("#"); + break; + default: + e->ignore(); + } + } else { + e->ignore(); + } +} + +// QLabels do not have mouse click events. I want the status labels +// to be clickable however. Explicitly check here if a status label has +// been clicked. +void MphoneForm::mouseReleaseEvent(QMouseEvent *e) +{ + if (e->button() == Qt::LeftButton && e->type() == QEvent::MouseButtonRelease) { + processLeftMouseButtonRelease(e); + } else if (e->button() == Qt::RightButton && e->type() == QEvent::MouseButtonRelease) { + processRightMouseButtonRelease(e); + } else { + e->ignore(); + } +} + +void MphoneForm::processLeftMouseButtonRelease(QMouseEvent *e) +{ + if (statAaLabel->hasMouse()) { + if (phone->ref_users().size() == 1) { + bool enable = !serviceAutoAnswer->isOn(); + srvAutoAnswer(enable); + serviceAutoAnswer->setOn(enable); + } else { + srvAutoAnswer(); + } + } else if (statDndLabel->hasMouse()) { + if (phone->ref_users().size() == 1) { + bool enable = !serviceDnd->isOn(); + srvDnd(enable); + serviceDnd->setOn(enable); + } else { + srvDnd(); + } + } else if (statCfLabel->hasMouse()) { + srvRedirect(); + } else if (statMWILabel->hasMouse()) { + popupMenuVoiceMail(e->globalPos()); + } else if (statMissedLabel->hasMouse()) { + // Open the history form, when the user clicks on the + // missed calls indication. + viewHistory(); + } else if (statRegLabel->hasMouse()) { + // Fetch registration status + phoneShowRegistrations(); + } else if (crypt1Label->hasMouse()) { + processCryptLabelClick(0); + } else if (crypt2Label->hasMouse()) { + processCryptLabelClick(1); + } else { + e->ignore(); + } +} + +void MphoneForm::processRightMouseButtonRelease(QMouseEvent *e) +{ + e->ignore(); +} + +void MphoneForm::processCryptLabelClick(int line) +{ + t_audio_session *as = phone->get_line(line)->get_audio_session(); + if (!as) return; + + if (as->get_zrtp_sas_confirmed()) { + phoneResetZrtpSasConfirmation(line); + } else { + phoneConfirmZrtpSas(line); + } +} + +// Show popup menu to access voice mail +void MphoneForm::popupMenuVoiceMail(const QPoint &pos) +{ + Q3PopupMenu menu(this); + QIcon vmIcon(QPixmap(":/icons/images/mwi_none16.png")); + vmIcon.setPixmap(QPixmap(":/icons/images/mwi_none16_dis.png"), + QIcon::Automatic, QIcon::Disabled); + + listuser_list = phone->ref_users(); + map vm; + for (list::iterator i = user_list.begin(); i != user_list.end(); ++i) { + QString address = (*i)->get_mwi_vm_address().c_str(); + QString entry = (*i)->get_profile_name().c_str(); + entry += " - "; + if (address.isEmpty()) { + entry += tr("not provisioned"); + } else { + entry += address; + } + + int id = menu.insertItem(vmIcon, entry); + if (address.isEmpty()) { + menu.setItemEnabled(id, false); + } + + vm.insert(make_pair(id, *i)); + } + + int selected; + + // If multiple profiles are active, then show the popup menu. + // If one profile is active, then call voice mail immediately. + if (user_list.size() > 1) { + selected = menu.exec(pos); + if (selected == -1) return; + } else { + if (vm.begin()->second->get_mwi_vm_address().empty()) { + ui->cb_show_msg( + tr("You must provision your voice mail address in your " + "user profile, before you can access it.").ascii(), + MSG_INFO); + return; + } + selected = vm.begin()->first; + } + + // Call can only be made if line is idle + int line = phone->get_active_line(); + if (phone->get_line_state(line) == LS_BUSY) { + ui->cb_show_msg(tr("The line is busy. Cannot access voice mail.").ascii(), + MSG_WARNING); + return; + } + + t_user *selectedUser = vm[selected]; + string display, dest_str; + ui->expand_destination(selectedUser, + selectedUser->get_mwi_vm_address(), + display, dest_str); + t_url dest(dest_str); + + if (dest.is_valid()) { + QString destination = selectedUser->get_mwi_vm_address().c_str(); + addToCallComboBox(destination); + if (inviteForm) inviteForm->addToInviteComboBox(destination); + callComboBox->setFocus(); + do_phoneInvite(selectedUser, display.c_str(), dest, "", false); + } else { + QString msg(tr("The voice mail address %1 is an invalid address. " + "Please provision a valid address in your user profile.")); + ui->cb_show_msg(msg.arg(selectedUser->get_mwi_vm_address().c_str()).ascii(), + MSG_CRITICAL); + } +} + +void MphoneForm::popupMenuVoiceMail(void) +{ + popupMenuVoiceMail(QCursor::pos()); +} + +void MphoneForm::showDisplay(bool on) +{ + if (on) { + displayGroupBox->show(); + } else { + int hDisplay = displayGroupBox->height(); + displayGroupBox->hide(); + + if (hDisplay < minimumHeight()) { + setMinimumHeight(minimumHeight() - hDisplay); + } + resize(width(), minimumHeight()); + } + + viewDisplay = on; + viewDisplayAction->setOn(on); +} + +void MphoneForm::showBuddyList(bool on) +{ + if (on) { + buddyListView->show(); + } else { + buddyListView->hide(); + } + + viewBuddyList = on; + viewBuddyListAction->setOn(on); +} + +void MphoneForm::showCompactLineStatus(bool on) +{ + if (on) { + int hLabels = fromhead1Label->height() + + tohead1Label->height() + + subjecthead1Label->height() + + fromhead2Label->height() + + tohead2Label->height() + + subjecthead2Label->height(); + + fromhead1Label->hide(); + tohead1Label->hide(); + subjecthead1Label->hide(); + from1Label->hide(); + to1Label->hide(); + subject1Label->hide(); + photo1Label->hide(); + fromhead2Label->hide(); + tohead2Label->hide(); + subjecthead2Label->hide(); + from2Label->hide(); + to2Label->hide(); + subject2Label->hide(); + photo2Label->hide(); + + if (hLabels < minimumHeight()) { + setMinimumHeight(minimumHeight() - hLabels); + } + resize(width(), minimumHeight()); + } else { + fromhead1Label->show(); + tohead1Label->show(); + subjecthead1Label->show(); + from1Label->show(); + to1Label->show(); + subject1Label->show(); + fromhead2Label->show(); + tohead2Label->show(); + subjecthead2Label->show(); + from2Label->show(); + to2Label->show(); + subject2Label->show(); + } + + viewCompactLineStatus = on; + //viewCompactLineStatusAction->setOn(on); +} + +bool MphoneForm::getViewDisplay() +{ + return viewDisplay; +} + +bool MphoneForm::getViewBuddyList() +{ + return viewBuddyList; +} + +bool MphoneForm::getViewCompactLineStatus() +{ + return viewCompactLineStatus; +} + +void MphoneForm::populateBuddyList() +{ + buddyListView->clear(); + + list user_list = phone->ref_users(); + for (list::iterator i = user_list.begin(); i != user_list.end(); ++i) { + t_presence_epa *epa = phone->ref_presence_epa(*i); + if (!epa) continue; + + BLViewUserItem *profileItem = new BLViewUserItem(buddyListView, epa); + t_buddy_list *buddy_list = phone->ref_buddy_list(*i); + + list *buddies = buddy_list->get_records(); + for (list::iterator bit = buddies->begin(); bit != buddies->end(); ++bit) { + QString name = bit->get_name().c_str(); + new BuddyListViewItem(profileItem, &(*bit)); + } + + profileItem->setOpen(true); + } +} + +void MphoneForm::showBuddyListPopupMenu(Q3ListViewItem *item, const QPoint &pos) +{ + if (!item) return; + + BuddyListViewItem *buddyItem = dynamic_cast(item); + if (buddyItem) { + buddyPopupMenu->popup(pos); + } else { + buddyListPopupMenu->popup(pos); + } +} + +void MphoneForm::doCallBuddy() +{ + Q3ListViewItem *qitem = buddyListView->currentItem(); + BuddyListViewItem *item = dynamic_cast(qitem); + if (!item) return; + + t_buddy *buddy = item->get_buddy(); + t_user *user_config = buddy->get_user_profile(); + + phoneInvite(user_config, buddy->get_sip_address().c_str(), "", false); +} + +void MphoneForm::doMessageBuddy(Q3ListViewItem *qitem) +{ + BuddyListViewItem *item = dynamic_cast(qitem); + if (!item) return; + + t_buddy *buddy = item->get_buddy(); + + startMessageSession(buddy); +} + +void MphoneForm::doMessageBuddy() +{ + Q3ListViewItem *item = buddyListView->currentItem(); + doMessageBuddy(item); +} + +void MphoneForm::doEditBuddy() +{ + Q3ListViewItem *qitem = buddyListView->currentItem(); + BuddyListViewItem *item = dynamic_cast(qitem); + if (!item) return; + + t_buddy *buddy = item->get_buddy(); + + BuddyForm *form = new BuddyForm(this, "new_buddy", true, Qt::WDestructiveClose); + // Do not call MEMMAN as this form will be deleted automatically. + form->showEdit(*buddy); +} + +void MphoneForm::doDeleteBuddy() +{ + Q3ListViewItem *qitem = buddyListView->currentItem(); + BuddyListViewItem *item = dynamic_cast(qitem); + if (!item) return; + + t_buddy *buddy = item->get_buddy(); + t_buddy_list *buddy_list = buddy->get_buddy_list(); + + // Delete the list item before deleting the buddy as + // deleting the item will detach the item from the buddy. + delete item; + + if (buddy->is_presence_terminated()) { + buddy_list->del_buddy(*buddy); + } else { + buddy->unsubscribe_presence(true); + } + + string err_msg; + if (!buddy_list->save(err_msg)) { + QString msg = tr("Failed to save buddy list: %1").arg(err_msg.c_str()); + ((t_gui *)ui)->cb_show_msg(this, msg.ascii(), MSG_CRITICAL); + } +} + +void MphoneForm::doAddBuddy() +{ + Q3ListViewItem *qitem = buddyListView->currentItem(); + BLViewUserItem *item = dynamic_cast(qitem); + if (!item) return; + + t_phone_user *pu = item->get_presence_epa()->get_phone_user(); + if (!pu) return; + t_buddy_list *buddy_list = pu->get_buddy_list(); + if (!buddy_list) return; + + BuddyForm *form = new BuddyForm(this, "new_buddy", true, Qt::WDestructiveClose); + // Do not call MEMMAN as this form will be deleted automatically. + form->showNew(*buddy_list, item); +} + +void MphoneForm::doAvailabilityOffline() +{ + Q3ListViewItem *qitem = buddyListView->currentItem(); + BLViewUserItem *item = dynamic_cast(qitem); + if (!item) return; + + t_phone_user *pu = item->get_presence_epa()->get_phone_user(); + if (!pu) return; + + pu->publish_presence(t_presence_state::ST_BASIC_CLOSED); +} + +void MphoneForm::doAvailabilityOnline() +{ + Q3ListViewItem *qitem = buddyListView->currentItem(); + BLViewUserItem *item = dynamic_cast(qitem); + if (!item) return; + + t_phone_user *pu = item->get_presence_epa()->get_phone_user(); + if (!pu) return; + + pu->publish_presence(t_presence_state::ST_BASIC_OPEN); +} + +void MphoneForm::DiamondcardSignUp() +{ + DiamondcardProfileForm *f = new DiamondcardProfileForm(this, "select profile", true, + Qt::WDestructiveClose); + + connect(f, SIGNAL(newDiamondcardProfile(const QString&)), + this, SLOT(newDiamondcardUser(const QString &))); + + f->show(NULL); +} + +void MphoneForm::newDiamondcardUser(const QString &filename) +{ + list profileFilenames; + list users = phone->ref_users(); + + for (list::const_iterator it = users.begin(); it != users.end(); ++it) { + t_user *user = *it; + profileFilenames.push_back(user->get_filename()); + } + + profileFilenames.push_back(filename.ascii()); + newUsers(profileFilenames); +} + +void MphoneForm::DiamondcardAction(t_dc_action action, int userIdx) +{ + list diamondcard_users = diamondcard_get_users(phone); + vector v(diamondcard_users.begin(), diamondcard_users.end()); + + if (userIdx < 0 || (unsigned int)userIdx >= v.size()) return; + + t_user *user = v[userIdx]; + QString url(diamondcard_url(action, user->get_name(), user->get_auth_pass()).c_str()); + ((t_gui *)ui)->open_url_in_browser(url); +} + +void MphoneForm::DiamondcardRecharge(int userIdx) +{ + DiamondcardAction(DC_ACT_RECHARGE, userIdx); +} + +void MphoneForm::DiamondcardBalanceHistory(int userIdx) +{ + DiamondcardAction(DC_ACT_BALANCE_HISTORY, userIdx); +} + +void MphoneForm::DiamondcardCallHistory(int userIdx) +{ + DiamondcardAction(DC_ACT_CALL_HISTORY, userIdx); +} + +void MphoneForm::DiamondcardAdminCenter(int userIdx) +{ + DiamondcardAction(DC_ACT_ADMIN_CENTER, userIdx); +} diff --git a/src/gui/mphoneform.h b/src/gui/mphoneform.h new file mode 100644 index 0000000..23adacb --- /dev/null +++ b/src/gui/mphoneform.h @@ -0,0 +1,206 @@ +#ifndef MPHONEFORM_UI_H +#define MPHONEFORM_UI_H +#include +#include "ui_mphoneform.h" +#include "phone.h" +#include "dtmfform.h" +#include "inviteform.h" +#include "redirectform.h" +#include "termcapform.h" +#include "srvredirectform.h" +#include "userprofileform.h" +#include "transferform.h" +#include "syssettingsform.h" +#include "logviewform.h" +#include "historyform.h" +#include "selectuserform.h" +#include "selectprofileform.h" +#include +#include +#include +#include +#include "im/msg_session.h" +#include "messageformview.h" +#include "buddylistview.h" +#include "diamondcard.h" + +class t_phone; +extern t_phone *phone; + +class MphoneForm : public Q3MainWindow, public Ui::MphoneForm +{ +Q_OBJECT +public: + MphoneForm(QWidget* parent, const char * name, Qt::WindowFlags f); + ~MphoneForm(); + +public: + QString getMWIStatus( const t_mwi & mwi, bool & msg_waiting ) const; + QSystemTrayIcon * getSysTray(); + bool getViewDisplay(); + bool getViewBuddyList(); + bool getViewCompactLineStatus(); +public slots: + void closeEvent( QCloseEvent * e ); + void fileExit(); + void display( const QString & s ); + void displayHeader(); + void showLineTimer( int line ); + void showLineTimer1(); + void showLineTimer2(); + void updateLineTimer( int line ); + void updateLineEncryptionState( int line ); + void updateLineStatus( int line ); + void updateState(); + void updateRegStatus(); + void flashMWI(); + void updateMwi(); + void updateServicesStatus(); + void updateMissedCallStatus( int num_missed_calls ); + void updateSysTrayStatus(); + void updateMenuStatus(); + void updateDiamondcardMenu(); + void removeDiamondcardAction( int & id ); + void removeDiamondcardMenu( Q3PopupMenu * & menu ); + void phoneRegister(); + void do_phoneRegister( list user_list ); + void phoneDeregister(); + void do_phoneDeregister( list user_list ); + void phoneDeregisterAll(); + void do_phoneDeregisterAll( list user_list ); + void phoneShowRegistrations(); + void phoneInvite( t_user * user_config, const QString & dest, const QString & subject, bool anonymous ); + void phoneInvite( const QString & dest, const QString & subject, bool anonymous ); + void phoneInvite(); + void do_phoneInvite( t_user * user_config, const QString & display, const t_url & destination, const QString & subject, bool anonymous ); + void phoneRedial( void ); + void phoneAnswer(); + void phoneAnswerFromSystrayPopup(); + void phoneBye(); + void phoneReject(); + void phoneRejectFromSystrayPopup(); + void phoneRedirect( const list & contacts ); + void phoneRedirect(); + void do_phoneRedirect( const list & destinations ); + void phoneTransfer( const string & dest, t_transfer_type transfer_type ); + void phoneTransfer(); + void do_phoneTransfer( const t_display_url & destination, t_transfer_type transfer_type ); + void do_phoneTransferLine(); + void phoneHold( bool on ); + void phoneConference(); + void phoneMute( bool on ); + void phoneTermCap( const QString & dest ); + void phoneTermCap(); + void do_phoneTermCap( t_user * user_config, const t_url & destination ); + void phoneDTMF(); + void sendDTMF( const QString & digits ); + void startMessageSession( void ); + void startMessageSession( t_buddy * buddy ); + void phoneConfirmZrtpSas( int line ); + void phoneConfirmZrtpSas(); + void phoneResetZrtpSasConfirmation( int line ); + void phoneResetZrtpSasConfirmation(); + void phoneEnableZrtp( bool on ); + void phoneZrtpGoClearOk( unsigned short line ); + void line1rbChangedState( bool on ); + void line2rbChangedState( bool on ); + void actionLine1Toggled( bool on ); + void actionLine2Toggled( bool on ); + void srvDnd( bool on ); + void srvDnd(); + void do_srvDnd_enable( list user_list ); + void do_srvDnd_disable( list user_list ); + void srvAutoAnswer( bool on ); + void srvAutoAnswer(); + void do_srvAutoAnswer_enable( list user_list ); + void do_srvAutoAnswer_disable( list user_list ); + void srvRedirect(); + void do_srvRedirect( t_user * user_config, const list & always, const list & busy, const list & noanswer ); + void about(); + void aboutQt(); + void manual(); + void editUserProfile(); + void editSysSettings(); + void selectProfile(); + void newUsers( const list & profiles ); + void updateUserComboBox(); + void updateSipUdpPort(); + void updateRtpPorts(); + void updateStunSettings( t_user * user_config ); + void updateAuthCache( t_user * user_config, const string & realm ); + void unsubscribeMWI( t_user * user_config ); + void subscribeMWI( t_user * user_config ); + void viewLog(); + void updateLog( bool log_zapped ); + void viewHistory(); + void updateCallHistory(); + void quickCall(); + void addToCallComboBox( const QString & destination ); + void showAddressBook(); + void selectedAddress( const QString & address ); + void enableCallOptions( bool enable ); + void keyPressEvent( QKeyEvent * e ); + void mouseReleaseEvent( QMouseEvent * e ); + void processLeftMouseButtonRelease( QMouseEvent * e ); + void processRightMouseButtonRelease( QMouseEvent * e ); + void processCryptLabelClick( int line ); + void popupMenuVoiceMail( const QPoint & pos ); + void popupMenuVoiceMail( void ); + void showDisplay( bool on ); + void showBuddyList( bool on ); + void showCompactLineStatus( bool on ); + void populateBuddyList(); + void showBuddyListPopupMenu( Q3ListViewItem * item, const QPoint & pos ); + void doCallBuddy(); + void doMessageBuddy( Q3ListViewItem * qitem ); + void doMessageBuddy(); + void doEditBuddy(); + void doDeleteBuddy(); + void doAddBuddy(); + void doAvailabilityOffline(); + void doAvailabilityOnline(); + void DiamondcardSignUp(); + void newDiamondcardUser( const QString & filename ); + void DiamondcardAction( t_dc_action action, int userIdx ); + void DiamondcardRecharge( int userIdx ); + void DiamondcardBalanceHistory( int userIdx ); + void DiamondcardCallHistory( int userIdx ); + void DiamondcardAdminCenter( int userIdx ); + +private: + void init(); + void destroy(); + QString lineSubstate2str( int line ); + +private: + QTimer tmrFlashMWI; + GetAddressForm *getAddressForm; + SelectProfileForm *selectProfileForm; + SelectUserForm *selectUserForm; + HistoryForm *historyForm; + TransferForm *transferForm; + UserProfileForm *userProfileForm; + SrvRedirectForm *srvRedirectForm; + TermCapForm *termCapForm; + RedirectForm *redirectForm; + InviteForm *inviteForm; + DtmfForm *dtmfForm; + SysSettingsForm *sysSettingsForm; + QStringList displayContents; + LogViewForm *logViewForm; + QSystemTrayIcon *sysTray; + QTimer *lineTimer1; + QTimer *lineTimer2; + QTimer *hideLineTimer1; + QTimer *hideLineTimer2; + bool viewDisplay; + bool viewCompactLineStatus; + bool mwiFlashStatus; + Q3PopupMenu *buddyPopupMenu; + Q3PopupMenu *buddyListPopupMenu; + Q3PopupMenu *changeAvailabilityPopupMenu; + bool viewBuddyList; + +}; + +#endif diff --git a/src/gui/mphoneform.ui b/src/gui/mphoneform.ui index 00b3290..cdaad13 100644 --- a/src/gui/mphoneform.ui +++ b/src/gui/mphoneform.ui @@ -1,2129 +1,2500 @@ - - - - - MphoneForm - - - true - - - - 0 - 0 - 739 - 693 - - - - - 5 - 5 - 0 - 0 - - - - - 714 - 693 - - - - Twinkle - - - twinkle16.png - - - false - - - false - - - true - - - - - - - Qt::Horizontal + + MphoneForm + + + true + + + + 0 + 0 + 739 + 693 + + + + + 0 + 0 + + + + + 714 + 693 + + + + Twinkle + + + false + + + false + + + true + + + + + 0 + 0 + 485 + 354 + + + + + + + Qt::Horizontal + + + + + 150 + 0 + + + + + 0 + 0 + + + + You can create a separate buddy list for each user profile. You can only see availability of your buddies and publish your own availability if your provider offers a presence server. + + + true + + + + + + + + + + &Call: - + + false + + + callComboBox + + + + + + + - - 7 - 7 - 150 - 0 - + + 0 + 0 + - - - 0 - 0 - + + The address that you want to call. This can be a full SIP address like <b>sip:example@example.com</b> or just the user part or telephone number of the full address. When you do not specify a full address, then Twinkle will complete the address by using the domain value of your user profile. + + + true + + + 10 + + + QComboBox::NoInsert + + + true - - true + + + + + + Qt::TabFocus - - Q3ListView::LastColumn + + Address book - - You can create a separate buddy list for each user profile. You can only see availability of your buddies and publish your own availability if your provider offers a presence server. + + Select an address from the address book. - - - Buddy list + + + + + + :/icons/images/kontact_contacts.png:/icons/images/kontact_contacts.png + + + F10 + + + + + + + Dial the address. + + + Dial + + + true + + + + + + + + + &User: + + + false + + + userComboBox + + + + + + + + + + 0 + 0 + + + + The user that will make the call. + + + + + + + + + + 0 + 0 + - - false + + false - - false + + + + + + + 0 + 0 + + + + false + + + + + + + + 0 + 0 + + + + false - + + + + + + + 0 + 0 + + + + false + + + + + + + + 0 + 0 + + + + false + + + + + + + + 0 + 0 + + + + false + + + + + + + + + + + + + + 0 + 0 + + + + Display + + + + + + + 0 + 0 + + + + + + + true + - + + + + + + + + + 0 + 0 + + + + Line status + + + true + + + + + + + + + + + 0 + 0 + + + + Click to switch to line 1. + + + Line &1: + + + Alt+1 + + + true + + + + + + + + 0 + 0 + + + + From: + + + false + + + 21 + + + + + + + + 0 + 0 + + + + To: + + + false + + + 21 + + + + + + + + 0 + 0 + + + + Subject: + + + false + + + 21 + + + + + + - - - - - - &Call: - - - callComboBox - - - false - - - - - - - - - - 3 - 0 - 0 - 0 - - - - true - - - 10 - - - QComboBox::NoInsert - - - true - - - The address that you want to call. This can be a full SIP address like <b>sip:example@example.com</b> or just the user part or telephone number of the full address. When you do not specify a full address, then Twinkle will complete the address by using the domain value of your user profile. - - - - - - - Qt::TabFocus - - - - - - F10 - - - kontact_contacts.png - - - Address book - - - Select an address from the address book. - - - - - - - Dial - - - true - - - Dial the address. - - - - - - - - - &User: - - - userComboBox - - - false - - - - - - - - - - 3 - 0 - 0 - 0 - - - - The user that will make the call. - - - - - - - - - - 0 - 0 - 0 - 0 - - - - false - - - - - - - - 0 - 0 - 0 - 0 - - - - false - - - - - - - - 0 - 0 - 0 - 0 - - - - false - - - - - - - - 0 - 0 - 0 - 0 - - - - false - - - - - - - - 0 - 0 - 0 - 0 - - - - false - - - - - - - - 0 - 0 - 0 - 0 - - - - false - - - - - - - - - - - - - - 5 - 5 - 0 - 0 - - - - Display - - - - - - - 7 - 3 - 0 - 0 - - - - Q3ScrollView::AlwaysOn - - - Qt::PlainText - - - - - - Q3TextEdit::NoWrap - - - true - - - Q3TextEdit::AutoAll - - - - + + + + + + + 0 + 0 + + + + false + + + + + + + + 0 + 0 + + + + idle + + + Qt::RichText + + + false + + + + + + + + 0 + 0 + + + + false + + + + + + + + 0 + 0 + + + + false + + + + + + + + 0 + 0 + + + + false + - - - - - - 5 - 5 - 0 - 0 - - - - Line status - - - true - - - - - - - - - - - 0 - 0 - 0 - 0 - - - - Line &1: - - - Alt+1 - - - true - - - Click to switch to line 1. - - - - - - - - 0 - 5 - 0 - 0 - - - - From: - - - 21 - - - false - - - - - - - - 0 - 5 - 0 - 0 - - - - To: - - - 21 - - - false - - - - - - - - 0 - 5 - 0 - 0 - - - - Subject: - - - 21 - - - false - - - - - - - - - - - - - - 0 - 5 - 0 - 0 - - - - false - - - - - - - - 5 - 5 - 0 - 0 - - - - idle - - - Qt::RichText - - - false - - - - - - - - 0 - 5 - 0 - 0 - - - - false - - - - - - - - 0 - 5 - 0 - 0 - - - - false - - - - - - - - 0 - 5 - 0 - 0 - - - - false - - - - - - - - 0 - 5 - 0 - 0 - - - - false - - - - - - - - 0 - 5 - 0 - 0 - - - - false - - - - - - - - 0 - 5 - 0 - 0 - - - - sas - - - Short authentication string - - - false - - - - - - - - 0 - 5 - 0 - 0 - - - - g711a/g711a - - - Qt::AlignVCenter|Qt::AlignRight - - - Audio codec - - - false - - - - - - - - 0 - 5 - 0 - 0 - - - - - Courier New - - - - 0:00:00 - - - Call duration - - - false - - - - - - - - - Qt::NoFocus - - - sip:from - - - true - - - - - - - Qt::NoFocus - - - sip:to - - - true - - - - - - - Qt::NoFocus - - - subject - - - true - - - - - - - - - - 0 - 0 - 0 - 0 - - - - - 70 - 98 - - - - - 70 - 98 - - - - QFrame::Box - - - photo - - - false - - - - - - - - - - - - - - 0 - 0 - 0 - 0 - - - - Line &2: - - - Alt+2 - - - Click to switch to line 2. - - - - - - - - 0 - 5 - 0 - 0 - - - - From: - - - 21 - - - false - - - - - - - - 0 - 5 - 0 - 0 - - - - To: - - - 21 - - - false - - - - - - - - 0 - 5 - 0 - 0 - - - - Subject: - - - 21 - - - false - - - - - - - - - - - - - - 0 - 5 - 0 - 0 - - - - false - - - - - - - - 5 - 5 - 0 - 0 - - - - idle - - - Qt::RichText - - - false - - - - - - - - 0 - 5 - 0 - 0 - - - - false - - - - - - - - 0 - 5 - 0 - 0 - - - - false - - - - - - - - 0 - 5 - 0 - 0 - - - - false - - - - - - - - 0 - 5 - 0 - 0 - - - - false - - - - - - - - 0 - 5 - 0 - 0 - - - - false - - - - - - - - 0 - 5 - 0 - 0 - - - - sas - - - Short authentication string - - - false - - - - - - - - 0 - 5 - 0 - 0 - - - - g711a/g711a - - - Qt::AlignVCenter|Qt::AlignRight - - - Audio codec - - - false - - - - - - - - 0 - 5 - 0 - 0 - - - - - Courier New - - - - 0:00:00 - - - Call duration - - - false - - - - - - - - - Qt::NoFocus - - - sip:from - - - true - - - - - - - Qt::NoFocus - - - sip:to - - - true - - - - - - - Qt::NoFocus - - - subject - - - true - - - - - - - - - - 0 - 0 - 0 - 0 - - - - - 70 - 98 - - - - - 70 - 98 - - - - QFrame::Box - - - photo - - - false - - - - - - + + + + + + 0 + 0 + + + + false + - + + + + + + 0 + 0 + + + + false + + + + + + + + 0 + 0 + + + + Short authentication string + + + sas + + + false + + + + + + + + 0 + 0 + + + + Audio codec + + + g711a/g711a + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + false + + + + + + + + 0 + 0 + + + + + Courier New + + + + Call duration + + + 0:00:00 + + + false + + + + + + + + + Qt::NoFocus + + + sip:from + + + true + + + + + + + Qt::NoFocus + + + sip:to + + + true + + + + + + + Qt::NoFocus + + + subject + + + true + + + - - + + + + + + 0 + 0 + + + + + 70 + 98 + + + + + 70 + 98 + + + + QFrame::Box + + + photo + + + false + + + + + + + + + + + + + + 0 + 0 + + + + Click to switch to line 2. + + + Line &2: + + + Alt+2 + + + + + + + + 0 + 0 + + + + From: + + + false + + + 21 + + + + + + + + 0 + 0 + + + + To: + + + false + + + 21 + + + + + + + + 0 + 0 + + + + Subject: + + + false + + + 21 + + + + + + + + + + + + + + 0 + 0 + + + + false + + + + + + + + 0 + 0 + + + + idle + + + Qt::RichText + + + false + + + + + + + + 0 + 0 + + + + false + + + + + + + + 0 + 0 + + + + false + + + + + + + + 0 + 0 + + + + false + + + + + + + + 0 + 0 + + + + false + + + + + + + + 0 + 0 + + + + false + + + + + + + + 0 + 0 + + + + Short authentication string + + + sas + + + false + + + + + + + + 0 + 0 + + + + Audio codec + + + g711a/g711a + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + false + + + + + + + + 0 + 0 + + + + + Courier New + + + + Call duration + + + 0:00:00 + + + false + + + + + + + + + Qt::NoFocus + + + sip:from + + + true + + + + + + + Qt::NoFocus + + + sip:to + + + true + + + + + + + Qt::NoFocus + + + subject + + + true + + + + + + + + + + 0 + 0 + + + + + 70 + 98 + + + + + 70 + 98 + + + + QFrame::Box + + + photo + + + false + + + + + + + - - - - - false - - - true - - - true - - - true - - - Call Toolbar - - - - - - - - - - - - - - - - - - &File - - - - - - - - &Edit - - - - - - - C&all - - - - Activate line - - - - - - - - - - - - - - - - - - - + - - - &Message - - - - - - &Registration - - - - - - - - - &Services - - - - - - - - - &View - - - - - - - - - Diamondcard - - - - - - &Help - - - - - - - - - - - - - - - - - + + + + + + + + 0 + 0 + 100 + 30 + + + + false + + + true + + + true + + + true + + + Call Toolbar + + + + + + + + + + + + + + + + + + 0 + 0 + 0 + 0 + + + + + &File + + + + + + + + &Edit + + + + + + + C&all + + + + Activate line + + + - - - fileExitAction - - - exit.png - - - Quit - - - &Quit - - - Ctrl+Q - - - - - helpAboutAction - - - twinkle16.png - - - About Twinkle - - - &About Twinkle - - - - - - - - callInvite - - - invite.png - - - Call - - - &Call... - - - Call someone - - - F5 - - - - - callAnswer - - - answer.png - - - Answer - - - &Answer - - - Answer incoming call - - - F6 - - - - - callBye - - - bye.png - - - Bye - - - &Bye - - - Release call - - - Esc - - - - - callReject - - - reject.png - - - Reject - - - &Reject - - - Reject incoming call - - - F8 - - - - - callHold - - - true - - - hold.png - - - Hold - - - &Hold - - - Put a call on hold, or retrieve a held call - - - - - callRedirect - - - redirect.png - - - Redirect - - - R&edirect... - - - Redirect incoming call without answering - - - - - callDTMF - - - dtmf.png - - - Dtmf - - - &Dtmf... - - - Open keypad to enter digits for voice menu's - - - - - regRegister - - - twinkle16.png - - - Register - - - &Register - - - - - regDeregister - - - twinkle16-disabled.png - - - Deregister - - - &Deregister - - - Deregister this device - - - - - regShow - - - reg-query.png - - - Show registrations - - - &Show registrations - - - - - callTermCap - - - Terminal capabilities - - - &Terminal capabilities... - - - Request terminal capabilities from someone - - - - - serviceDnd - - - true - - - cancel.png - - - Do not disturb - - - &Do not disturb - - - - - serviceRedirection - - - cf.png - - - Call redirection - - - Call &redirection... - - - - - callRedial - - - redial.png - - - Redial - - - &Redial - - - Repeat last call - - - F12 - - - - - helpAboutQtAction - - - qt-logo.png - - - About Qt - - - About &Qt - - - - - editUserProfileAction - - - penguin-small.png - - - User profile - - - &User profile... - - - - - callConference - - - conf.png - - - Conf - - - &Conference - - - Join two calls in a 3-way conference - - - - - callMute - - - true - - - mute.png - - - Mute - - - &Mute - - - Mute a call - - - - - callTransfer - - - true - - - transfer.png - - - Xfer - - - Trans&fer... - - - Transfer call - - - - - editSysSettingsAction - - - settings.png - - - System settings - - - &System settings... - - - - - registrationAction - - - - - - - - - - - regDeregisterAll - - - twinkle16-disabled.png - - - Deregister all - - - Deregister &all - - - Deregister all your registered devices - - - - - serviceAutoAnswer - - - true - - - auto_answer.png - - - Auto answer - - - &Auto answer - - - - - viewLogAction - - - log_small.png - - - Log - - - &Log... - - - - - viewCall_HistoryAction - - - missed.png - - - Call history - - - Call &history... - - - F9 - - - - - fileChangeUserAction - - - penguin-small.png - - - Change user ... - - - &Change user ... - - - Activate or de-activate users - - - - - helpWhats_ThisAction - - - contexthelp.png - - - What's This? - - - What's &This? - - - Shift+F1 - - - - - callActivate_LineAction - - - false - - - Activate line - - - Activate line - - - - - viewDisplayAction - - - true - - - true - - - Display - - - &Display - - - - - servicesVoice_mailAction - - - mwi_none16.png - - - Voice mail - - - &Voice mail - - - Access voice mail - - - F11 - - - - - actionSendMsg - - - message.png - - - Msg - - - Instant &message... - - - Instant message - - - - - viewBuddyListAction - - - true - - - true - - - Buddy list - - - &Buddy list - - - Buddy list - - - - - helpManualAction - - - Manual - - - &Manual - - - - - diamondcardSign_upAction - - - Sign up - - - &Sign up... - - - Sign up - - - - - - actionLine1 - - - true - - - true - - - Line 1 - - - - - actionLine2 - - - true - - - Line 2 - - - - actgrActivateLine - - + + + + + + + + + + + + + + + + + + + &Message + + + + + + &Registration + + + + + + + + + &Services + + + + + + + + + &View + + + + + + + + + Diamondcard + + + + + + &Help + + + + + + + + + + + + + + + + + - - qPixmapFromMimeSource - - callComboBox - addressToolButton - callPushButton - displayTextEdit - line1RadioButton - line2RadioButton - userComboBox - from1Label - subject1Label - to1Label - subject2Label - from2Label - to2Label - - - phone.h - ui_dtmfform.h - ui_inviteform.h - ui_redirectform.h - ui_termcapform.h - ui_srvredirectform.h - ui_userprofileform.h - ui_transferform.h - ui_syssettingsform.h - ui_logviewform.h - ui_historyform.h - ui_selectuserform.h - ui_selectprofileform.h - qevent.h - twinklesystray.h - im/msg_session.h - messageformview.h - buddylistview.h - diamondcard.h - - - - helpWhats_ThisAction - activated() - MphoneForm - whatsThis() - - - addressToolButton - clicked() - MphoneForm - showAddressBook() - - - callPushButton - clicked() - MphoneForm - quickCall() - - - fileChangeUserAction - activated() - MphoneForm - selectProfile() - - - viewCall_HistoryAction - activated() - MphoneForm - viewHistory() - - - viewLogAction - activated() - MphoneForm - viewLog() - - - regDeregisterAll - activated() - MphoneForm - phoneDeregisterAll() - - - editSysSettingsAction - activated() - MphoneForm - editSysSettings() - - - callMute - toggled(bool) - MphoneForm - phoneMute(bool) - - - callConference - activated() - MphoneForm - phoneConference() - - - editUserProfileAction - activated() - MphoneForm - editUserProfile() - - - helpAboutQtAction - activated() - MphoneForm - aboutQt() - - - helpAboutAction - activated() - MphoneForm - about() - - - callRedial - activated() - MphoneForm - phoneRedial() - - - serviceRedirection - activated() - MphoneForm - srvRedirect() - - - regShow - activated() - MphoneForm - phoneShowRegistrations() - - - regDeregister - activated() - MphoneForm - phoneDeregister() - - - regRegister - activated() - MphoneForm - phoneRegister() - - - callHold - toggled(bool) - MphoneForm - phoneHold(bool) - - - callReject - activated() - MphoneForm - phoneReject() - - - callRedirect - activated() - MphoneForm - phoneRedirect() - - - callInvite - activated() - MphoneForm - phoneInvite() - - - callDTMF - activated() - MphoneForm - phoneDTMF() - - - callBye - activated() - MphoneForm - phoneBye() - - - callAnswer - activated() - MphoneForm - phoneAnswer() - - - callTermCap - activated() - MphoneForm - phoneTermCap() - - - line2RadioButton - toggled(bool) - MphoneForm - line2rbChangedState(bool) - - - line1RadioButton - toggled(bool) - MphoneForm - line1rbChangedState(bool) - - - fileExitAction - activated() - MphoneForm - fileExit() - - - actionLine1 - toggled(bool) - MphoneForm - actionLine1Toggled(bool) - - - actionLine2 - toggled(bool) - MphoneForm - actionLine2Toggled(bool) - - - viewDisplayAction - toggled(bool) - MphoneForm - showDisplay(bool) - - - callTransfer - activated() - MphoneForm - phoneTransfer() - - - servicesVoice_mailAction - activated() - MphoneForm - popupMenuVoiceMail() - - - actionSendMsg - activated() - MphoneForm - startMessageSession() - - - buddyListView - rightButtonPressed(Q3ListViewItem*,QPoint,int) - MphoneForm - showBuddyListPopupMenu(Q3ListViewItem*,QPoint) - - - buddyListView - doubleClicked(Q3ListViewItem*) - MphoneForm - doMessageBuddy(Q3ListViewItem*) - - - viewBuddyListAction - toggled(bool) - MphoneForm - showBuddyList(bool) - - - helpManualAction - activated() - MphoneForm - manual() - - - diamondcardSign_upAction - activated() - MphoneForm - DiamondcardSignUp() - - + + + + :/icons/images/exit.png:/icons/images/exit.png + + + &Quit + + + Quit + + + Ctrl+Q + + + fileExitAction + + + + + + :/icons/images/twinkle16.png:/icons/images/twinkle16.png + + + &About Twinkle + + + About Twinkle + + + + + + helpAboutAction + + + + + + :/icons/images/invite.png:/icons/images/invite.png + + + &Call... + + + Call + + + Call someone + + + F5 + + + callInvite + + + + + + :/icons/images/answer.png:/icons/images/answer.png + + + &Answer + + + Answer + + + Answer incoming call + + + F6 + + + callAnswer + + + + + + :/icons/images/bye.png:/icons/images/bye.png + + + &Bye + + + Bye + + + Release call + + + Esc + + + callBye + + + + + + :/icons/images/reject.png:/icons/images/reject.png + + + &Reject + + + Reject + + + Reject incoming call + + + F8 + + + callReject + + + + + true + + + + :/icons/images/hold.png:/icons/images/hold.png + + + &Hold + + + Hold + + + Put a call on hold, or retrieve a held call + + + callHold + + + + + + :/icons/images/redirect.png:/icons/images/redirect.png + + + R&edirect... + + + Redirect + + + Redirect incoming call without answering + + + callRedirect + + + + + + :/icons/images/dtmf.png:/icons/images/dtmf.png + + + &Dtmf... + + + Dtmf + + + Open keypad to enter digits for voice menu's + + + callDTMF + + + + + + :/icons/images/twinkle16.png:/icons/images/twinkle16.png + + + &Register + + + Register + + + regRegister + + + + + + :/icons/images/twinkle16-disabled.png:/icons/images/twinkle16-disabled.png + + + &Deregister + + + Deregister + + + Deregister this device + + + regDeregister + + + + + + :/icons/images/reg-query.png:/icons/images/reg-query.png + + + &Show registrations + + + Show registrations + + + regShow + + + + + &Terminal capabilities... + + + Terminal capabilities + + + Request terminal capabilities from someone + + + callTermCap + + + + + true + + + + :/icons/images/cancel.png:/icons/images/cancel.png + + + &Do not disturb + + + Do not disturb + + + serviceDnd + + + + + + :/icons/images/cf.png:/icons/images/cf.png + + + Call &redirection... + + + Call redirection + + + serviceRedirection + + + + + + :/icons/images/redial.png:/icons/images/redial.png + + + &Redial + + + Redial + + + Repeat last call + + + F12 + + + callRedial + + + + + + :/icons/images/qt-logo.png:/icons/images/qt-logo.png + + + About &Qt + + + About Qt + + + helpAboutQtAction + + + + + + :/icons/images/penguin-small.png:/icons/images/penguin-small.png + + + &User profile... + + + User profile + + + editUserProfileAction + + + + + + :/icons/images/conference.png:/icons/images/conference.png + + + &Conference + + + Conf + + + Join two calls in a 3-way conference + + + callConference + + + + + true + + + + :/icons/images/mute.png:/icons/images/mute.png + + + &Mute + + + Mute + + + Mute a call + + + callMute + + + + + true + + + + :/icons/images/transfer.png:/icons/images/transfer.png + + + Trans&fer... + + + Xfer + + + Transfer call + + + callTransfer + + + + + + :/icons/images/settings.png:/icons/images/settings.png + + + &System settings... + + + System settings + + + editSysSettingsAction + + + + + + + + + + + registrationAction + + + + + + :/icons/images/twinkle16-disabled.png:/icons/images/twinkle16-disabled.png + + + Deregister &all + + + Deregister all + + + Deregister all your registered devices + + + regDeregisterAll + + + + + true + + + + :/icons/images/auto_answer.png:/icons/images/auto_answer.png + + + &Auto answer + + + Auto answer + + + serviceAutoAnswer + + + + + + :/icons/images/log_small.png:/icons/images/log_small.png + + + &Log... + + + Log + + + viewLogAction + + + + + + :/icons/images/missed.png:/icons/images/missed.png + + + Call &history... + + + Call history + + + F9 + + + viewCall_HistoryAction + + + + + + :/icons/images/penguin-small.png:/icons/images/penguin-small.png + + + &Change user ... + + + Change user ... + + + Activate or de-activate users + + + fileChangeUserAction + + + + + + :/icons/images/contexthelp.png:/icons/images/contexthelp.png + + + What's &This? + + + What's This? + + + Shift+F1 + + + helpWhats_ThisAction + + + + + false + + + Activate line + + + Activate line + + + callActivate_LineAction + + + + + true + + + true + + + &Display + + + Display + + + viewDisplayAction + + + + + + :/icons/images/mwi_none16.png:/icons/images/mwi_none16.png + + + &Voice mail + + + Voice mail + + + Access voice mail + + + F11 + + + servicesVoice_mailAction + + + + + + :/icons/images/message.png:/icons/images/message.png + + + Instant &message... + + + Msg + + + Instant message + + + actionSendMsg + + + + + true + + + true + + + &Buddy list + + + Buddy list + + + Buddy list + + + viewBuddyListAction + + + + + &Manual + + + Manual + + + helpManualAction + + + + + &Sign up... + + + Sign up + + + Sign up + + + diamondcardSign_upAction + + + + + + true + + + true + + + Line 1 + + + actionLine1 + + + + + true + + + Line 2 + + + actionLine2 + + + + actgrActivateLine + + + + + qPixmapFromMimeSource + + + Q3MainWindow + QWidget +
q3mainwindow.h
+ 1 +
+ + Q3ListView + QWidget +
q3listview.h
+
+ + Q3GroupBox + QWidget +
q3groupbox.h
+
+ + Q3TextEdit + QWidget +
q3textedit.h
+
+ + Q3ButtonGroup + QWidget +
q3buttongroup.h
+
+ + Q3ToolBar + QWidget +
q3toolbar.h
+
+
+ + callComboBox + addressToolButton + callPushButton + displayTextEdit + line1RadioButton + line2RadioButton + userComboBox + from1Label + subject1Label + to1Label + subject2Label + from2Label + to2Label + + + phone.h + ui_dtmfform.h + ui_inviteform.h + ui_redirectform.h + ui_termcapform.h + ui_srvredirectform.h + ui_userprofileform.h + ui_transferform.h + ui_syssettingsform.h + ui_logviewform.h + ui_historyform.h + ui_selectuserform.h + ui_selectprofileform.h + qevent.h + im/msg_session.h + messageformview.h + buddylistview.h + diamondcard.h + + + + + + + helpWhats_ThisAction + activated() + MphoneForm + whatsThis() + + + -1 + -1 + + + 20 + 20 + + + + + addressToolButton + clicked() + MphoneForm + showAddressBook() + + + 20 + 20 + + + 20 + 20 + + + + + callPushButton + clicked() + MphoneForm + quickCall() + + + 20 + 20 + + + 20 + 20 + + + + + fileChangeUserAction + activated() + MphoneForm + selectProfile() + + + -1 + -1 + + + 20 + 20 + + + + + viewCall_HistoryAction + activated() + MphoneForm + viewHistory() + + + -1 + -1 + + + 20 + 20 + + + + + viewLogAction + activated() + MphoneForm + viewLog() + + + -1 + -1 + + + 20 + 20 + + + + + regDeregisterAll + activated() + MphoneForm + phoneDeregisterAll() + + + -1 + -1 + + + 20 + 20 + + + + + editSysSettingsAction + activated() + MphoneForm + editSysSettings() + + + -1 + -1 + + + 20 + 20 + + + + + callMute + toggled(bool) + MphoneForm + phoneMute(bool) + + + -1 + -1 + + + 20 + 20 + + + + + callConference + activated() + MphoneForm + phoneConference() + + + -1 + -1 + + + 20 + 20 + + + + + editUserProfileAction + activated() + MphoneForm + editUserProfile() + + + -1 + -1 + + + 20 + 20 + + + + + helpAboutQtAction + activated() + MphoneForm + aboutQt() + + + -1 + -1 + + + 20 + 20 + + + + + helpAboutAction + activated() + MphoneForm + about() + + + -1 + -1 + + + 20 + 20 + + + + + callRedial + activated() + MphoneForm + phoneRedial() + + + -1 + -1 + + + 20 + 20 + + + + + serviceRedirection + activated() + MphoneForm + srvRedirect() + + + -1 + -1 + + + 20 + 20 + + + + + regShow + activated() + MphoneForm + phoneShowRegistrations() + + + -1 + -1 + + + 20 + 20 + + + + + regDeregister + activated() + MphoneForm + phoneDeregister() + + + -1 + -1 + + + 20 + 20 + + + + + regRegister + activated() + MphoneForm + phoneRegister() + + + -1 + -1 + + + 20 + 20 + + + + + callHold + toggled(bool) + MphoneForm + phoneHold(bool) + + + -1 + -1 + + + 20 + 20 + + + + + callReject + activated() + MphoneForm + phoneReject() + + + -1 + -1 + + + 20 + 20 + + + + + callRedirect + activated() + MphoneForm + phoneRedirect() + + + -1 + -1 + + + 20 + 20 + + + + + callInvite + activated() + MphoneForm + phoneInvite() + + + -1 + -1 + + + 20 + 20 + + + + + callDTMF + activated() + MphoneForm + phoneDTMF() + + + -1 + -1 + + + 20 + 20 + + + + + callBye + activated() + MphoneForm + phoneBye() + + + -1 + -1 + + + 20 + 20 + + + + + callAnswer + activated() + MphoneForm + phoneAnswer() + + + -1 + -1 + + + 20 + 20 + + + + + callTermCap + activated() + MphoneForm + phoneTermCap() + + + -1 + -1 + + + 20 + 20 + + + + + line2RadioButton + toggled(bool) + MphoneForm + line2rbChangedState(bool) + + + 20 + 20 + + + 20 + 20 + + + + + line1RadioButton + toggled(bool) + MphoneForm + line1rbChangedState(bool) + + + 20 + 20 + + + 20 + 20 + + + + + fileExitAction + activated() + MphoneForm + fileExit() + + + -1 + -1 + + + 20 + 20 + + + + + actionLine1 + toggled(bool) + MphoneForm + actionLine1Toggled(bool) + + + -1 + -1 + + + 20 + 20 + + + + + actionLine2 + toggled(bool) + MphoneForm + actionLine2Toggled(bool) + + + -1 + -1 + + + 20 + 20 + + + + + viewDisplayAction + toggled(bool) + MphoneForm + showDisplay(bool) + + + -1 + -1 + + + 20 + 20 + + + + + callTransfer + activated() + MphoneForm + phoneTransfer() + + + -1 + -1 + + + 20 + 20 + + + + + servicesVoice_mailAction + activated() + MphoneForm + popupMenuVoiceMail() + + + -1 + -1 + + + 20 + 20 + + + + + actionSendMsg + activated() + MphoneForm + startMessageSession() + + + -1 + -1 + + + 20 + 20 + + + + + buddyListView + rightButtonPressed(Q3ListViewItem*,QPoint,int) + MphoneForm + showBuddyListPopupMenu(Q3ListViewItem*,QPoint) + + + 20 + 20 + + + 20 + 20 + + + + + buddyListView + doubleClicked(Q3ListViewItem*) + MphoneForm + doMessageBuddy(Q3ListViewItem*) + + + 20 + 20 + + + 20 + 20 + + + + + viewBuddyListAction + toggled(bool) + MphoneForm + showBuddyList(bool) + + + -1 + -1 + + + 20 + 20 + + + + + helpManualAction + activated() + MphoneForm + manual() + + + -1 + -1 + + + 20 + 20 + + + + + diamondcardSign_upAction + activated() + MphoneForm + DiamondcardSignUp() + + + -1 + -1 + + + 20 + 20 + + + +
diff --git a/src/gui/mphoneform.ui.h b/src/gui/mphoneform.ui.h deleted file mode 100644 index 9a2a0d7..0000000 --- a/src/gui/mphoneform.ui.h +++ /dev/null @@ -1,3131 +0,0 @@ -/**************************************************************************** -** ui.h extension file, included from the uic-generated form implementation. -** -** If you wish to add, delete or rename functions or slots use -** Qt Designer which will update this file, pres:erving your code. Ceate an -** init() function in place of a constructor, and a destroy() function in -** place of a destructor. -*****************************************************************************/ -/* - Copyright (C) 2005-2009 Michel de Boer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -#include "twinkle_config.h" -#include "twinklesystray.h" -//Added by qt3to4: -#include -#include -#include -#include -#include -#include -#include -#include - -// Time (s) that the conversation timer of a line should stay visible after -// a call has ended -#define HIDE_LINE_TIMER_AFTER 5 - -void MphoneForm::init() -{ - // Forms - dtmfForm = 0; - inviteForm = 0; - redirectForm = 0; - transferForm = 0; - termCapForm = 0; - srvRedirectForm = 0; - userProfileForm = 0; - sysSettingsForm = 0; - logViewForm = 0; - historyForm = 0; - selectUserForm = 0; - selectProfileForm = 0; - getAddressForm = 0; - sysTray = 0; - - // Popup menu for a single buddy - QIcon inviteIcon(qPixmapFromMimeSource("invite.png")); - QIcon messageIcon(qPixmapFromMimeSource("message.png")); - QIcon editIcon(qPixmapFromMimeSource("edit16.png")); - QIcon deleteIcon(qPixmapFromMimeSource("editdelete.png")); - buddyPopupMenu = new Q3PopupMenu(this); - MEMMAN_NEW(buddyPopupMenu); - buddyPopupMenu->insertItem(inviteIcon, tr("&Call..."), this, SLOT(doCallBuddy())); - buddyPopupMenu->insertItem(messageIcon, tr("Instant &message..."), this, SLOT(doMessageBuddy())); - buddyPopupMenu->insertItem(editIcon, tr("&Edit..."), this, SLOT(doEditBuddy())); - buddyPopupMenu->insertItem(deleteIcon, tr("&Delete"), this, SLOT(doDeleteBuddy())); - - // Change availibility sub popup menu - changeAvailabilityPopupMenu = new Q3PopupMenu(this); - MEMMAN_NEW(changeAvailabilityPopupMenu); - QIcon availOnlineIcon(qPixmapFromMimeSource("presence_online.png")); - QIcon availOfflineIcon(qPixmapFromMimeSource("presence_offline.png")); - changeAvailabilityPopupMenu->insertItem(availOfflineIcon, tr("O&ffline"), this, - SLOT(doAvailabilityOffline())); - changeAvailabilityPopupMenu->insertItem(availOnlineIcon, tr("&Online"), this, - SLOT(doAvailabilityOnline())); - - // Popup menu for a buddy list (click on profile name) - QIcon changeAvailabilityIcon(qPixmapFromMimeSource("presence_online.png")); - QIcon addIcon(qPixmapFromMimeSource("buddy.png")); - buddyListPopupMenu = new Q3PopupMenu(this); - MEMMAN_NEW(buddyListPopupMenu); - buddyListPopupMenu->insertItem(changeAvailabilityIcon, tr("&Change availability"), - changeAvailabilityPopupMenu); - buddyListPopupMenu->insertItem(addIcon, tr("&Add buddy..."), this, SLOT(doAddBuddy())); - - // ToDo: Tool tip for buddy list - - // Line timers - lineTimer1 = 0; - lineTimer2 = 0; - timer1TextLabel->hide(); - timer2TextLabel->hide(); - - // Timer to hide the conversation timer after a conversation has ended. - hideLineTimer1 = new QTimer(this); - MEMMAN_NEW(hideLineTimer1); - hideLineTimer2 = new QTimer(this); - MEMMAN_NEW(hideLineTimer2); - connect(hideLineTimer1, SIGNAL(timeout()), timer1TextLabel, SLOT(hide())); - connect(hideLineTimer2, SIGNAL(timeout()), timer2TextLabel, SLOT(hide())); - - // Attach the MWI flash slot to the MWI flash timer - connect(&tmrFlashMWI, SIGNAL(timeout()), this, SLOT(flashMWI())); - - // Set toolbar icons for disabled options. - setDisabledIcon(callInvite, "invite-disabled.png"); - setDisabledIcon(callAnswer, "answer-disabled.png"); - setDisabledIcon(callBye, "bye-disabled.png"); - setDisabledIcon(callReject, "reject-disabled.png"); - setDisabledIcon(callRedirect, "redirect-disabled.png"); - setDisabledIcon(callTransfer, "transfer-disabled.png"); - setDisabledIcon(callHold, "hold-disabled.png"); - setDisabledIcon(callConference, "conf-disabled.png"); - setDisabledIcon(callMute, "mute-disabled.png"); - setDisabledIcon(callDTMF, "dtmf-disabled.png"); - setDisabledIcon(callRedial, "redial-disabled.png"); - - // Set tool button icons for disabled options - setDisabledIcon(addressToolButton, "kontact_contacts-disabled.png"); - - // Some text labels on the main window are implemented as QLineEdit - // objects as these do not automatically resize when a text set with setText - // does not fit. The background of a QLineEdit is static however, it does not - // automatically take a background color passed by the -bg parameter. - // Set the background color of these QLineEdit objects here. - from1Label->setPaletteBackgroundColor(paletteBackgroundColor()); - to1Label->setPaletteBackgroundColor(paletteBackgroundColor()); - subject1Label->setPaletteBackgroundColor(paletteBackgroundColor()); - from2Label->setPaletteBackgroundColor(paletteBackgroundColor()); - to2Label->setPaletteBackgroundColor(paletteBackgroundColor()); - subject2Label->setPaletteBackgroundColor(paletteBackgroundColor()); - - // A QComboBox accepts a new line through copy/paste. - QRegExp rxNoNewLine("[^\\n\\r]*"); - callComboBox->setValidator(new QRegExpValidator(rxNoNewLine, this)); - - if (sys_config->get_gui_use_systray()) { - // Create system tray icon - sysTray = new t_twinkle_sys_tray(this, "twinkle_sys_tray"); - MEMMAN_NEW(sysTray); - sysTray->setPixmap( - qPixmapFromMimeSource("sys_idle_dis.png")); - sysTray->setCaption(PRODUCT_NAME); - QToolTip::add(sysTray, PRODUCT_NAME); - - // Add items to the system tray menu -#ifdef HAVE_KDE - KPopupMenu *menu; -#else - Q3PopupMenu *menu; -#endif - menu = sysTray->contextMenu(); - - // Call menu - callInvite->addTo(menu); - callAnswer->addTo(menu); - callBye->addTo(menu); - callReject->addTo(menu); - callRedirect->addTo(menu); - callTransfer->addTo(menu); - callHold->addTo(menu); - callConference->addTo(menu); - callMute->addTo(menu); - callDTMF->addTo(menu); - callRedial->addTo(menu); - - menu->insertSeparator(); - - // Messaging - actionSendMsg->addTo(menu); - - menu->insertSeparator(); - - // Line activation - actgrActivateLine->addTo(menu); - - menu->insertSeparator(); - - // Service menu - serviceDnd->addTo(menu); - serviceRedirection->addTo(menu); - serviceAutoAnswer->addTo(menu); - servicesVoice_mailAction->addTo(menu); - - menu->insertSeparator(); - - // View menu - viewCall_HistoryAction->addTo(menu); - - menu->insertSeparator(); - - // Diamondcard menu - menu->insertItem("Diamondcard", Diamondcard); - - // Exit application when user selects Quit from the tray menu - connect(sysTray, SIGNAL(quitSelected()), - this, SLOT(fileExit())); - - sysTray->dock(); - sysTray->show(); - } -} - -void MphoneForm::destroy() -{ - if (dtmfForm) { - MEMMAN_DELETE(dtmfForm); - delete dtmfForm; - } - if (inviteForm) { - MEMMAN_DELETE(inviteForm); - delete inviteForm; - } - if (redirectForm) { - MEMMAN_DELETE(redirectForm); - delete redirectForm; - } - if (termCapForm) { - MEMMAN_DELETE(termCapForm); - delete termCapForm; - } - if (srvRedirectForm) { - MEMMAN_DELETE(srvRedirectForm); - delete srvRedirectForm; - } - if (userProfileForm) { - MEMMAN_DELETE(userProfileForm); - delete userProfileForm; - } - if (transferForm) { - MEMMAN_DELETE(transferForm); - delete transferForm; - } - if (sysSettingsForm) { - MEMMAN_DELETE(sysSettingsForm); - delete sysSettingsForm; - } - if (logViewForm) { - if (logViewForm->isShown()) logViewForm->close(); - MEMMAN_DELETE(logViewForm); - delete logViewForm; - } - if (historyForm) { - if (historyForm->isShown()) historyForm->close(); - MEMMAN_DELETE(historyForm); - delete historyForm; - } - if (selectUserForm) { - MEMMAN_DELETE(selectUserForm); - delete selectUserForm; - } - if (selectProfileForm) { - MEMMAN_DELETE(selectProfileForm); - delete selectProfileForm; - } - if (getAddressForm) { - MEMMAN_DELETE(getAddressForm); - delete getAddressForm; - } - if (sysTray) { - MEMMAN_DELETE(sysTray); - delete sysTray; - } - - if (lineTimer1) { - MEMMAN_DELETE(lineTimer1); - delete lineTimer1; - } - if (lineTimer2) { - MEMMAN_DELETE(lineTimer2); - delete lineTimer2; - } - MEMMAN_DELETE(hideLineTimer1); - delete hideLineTimer1; - MEMMAN_DELETE(hideLineTimer2); - delete hideLineTimer2; - MEMMAN_DELETE(buddyPopupMenu); - delete buddyPopupMenu; - MEMMAN_DELETE(changeAvailabilityPopupMenu); - delete changeAvailabilityPopupMenu; - MEMMAN_DELETE(buddyListPopupMenu); - delete buddyListPopupMenu; -} - -QString MphoneForm::lineSubstate2str( int line) { - QString reason; - - t_call_info call_info = phone->get_call_info(line); - - switch(phone->get_line_substate(line)) { - case LSSUB_IDLE: - return tr("idle"); - case LSSUB_SEIZED: - return tr("dialing"); - case LSSUB_OUTGOING_PROGRESS: - reason = call_info.last_provisional_reason.c_str(); - if (reason == "") { - return tr("attempting call, please wait"); - } - return reason; - case LSSUB_INCOMING_PROGRESS: - return QString("") + tr("incoming call") + ""; - case LSSUB_ANSWERING: - return tr("establishing call, please wait"); - case LSSUB_ESTABLISHED: - if (phone->has_line_media(line)) { - return tr("established"); - } else { - return tr("established (waiting for media)"); - } - break; - case LSSUB_RELEASING: - return tr("releasing call, please wait"); - default: - return tr("unknown state"); - } -} - -void MphoneForm::closeEvent( QCloseEvent *e ) -{ - if (sysTray && sys_config->get_gui_hide_on_close()) { - hide(); - } else { - fileExit(); - } -} - -void MphoneForm::fileExit() -{ - hide(); - QApplication::exit(0); -} - -// Append a string to the display window -void MphoneForm::display( const QString &s ) -{ - displayContents.push_back(s); - if (displayContents.size() > 100) { - displayContents.pop_front(); - } - - displayTextEdit->setText(displayContents.join("\n")); - - // Set cursor position at the end of text - displayTextEdit->setCursorPosition(displayTextEdit->paragraphs() - 1, 0); -} - -// Print message header on display -void MphoneForm::displayHeader() -{ - display(""); - display(current_time2str("%a %H:%M:%S").c_str()); -} - -// Update the conversation timer -void MphoneForm::showLineTimer(int line) -{ - struct timeval t; - gettimeofday(&t, NULL); - - QLabel *timerLabel; - - if (line == 0) { - timerLabel = timer1TextLabel; - } else { - timerLabel = timer2TextLabel; - } - - // Calculate duration of call - t_call_record cr = phone->get_call_hist(line); - unsigned long duration = t.tv_sec - cr.time_answer; - - timerLabel->setText(timer2str(duration).c_str()); -} - -void MphoneForm::showLineTimer1() -{ - showLineTimer(0); -} - -void MphoneForm::showLineTimer2() -{ - showLineTimer(1); -} - -// Update visibility of the conversation timer for a line -// Initialize the timer for a new established call. -void MphoneForm::updateLineTimer(int line) -{ - QLabel *timerLabel; - QTimer **timer; - QTimer *hideLineTimer; - - if (line == 0) { - timerLabel = timer1TextLabel; - timer = &lineTimer1; - hideLineTimer = hideLineTimer1; - } else { - timerLabel = timer2TextLabel; - timer = &lineTimer2; - hideLineTimer = hideLineTimer2; - } - - t_line_substate line_substate = phone->get_line_substate(line); - - // Stop hide timer if necessary - switch(line_substate) { - case LSSUB_IDLE: - case LSSUB_RELEASING: - // Timer can be shown as long as line is idle or releasing. - break; - default: - // The timer showing the call duration should only stay - // for a few seconds as long as the line is idle or being - // released. - // If a new call arrives on the line, the hide timer should - // be stopped, otherwise the timer of the new call will - // automatically disappear. - if (hideLineTimer->isActive()) { - hideLineTimer->stop(); - if (*timer == NULL) timerLabel->hide(); - } - break; - } - - switch(line_substate) { - case LSSUB_ESTABLISHED: - // Initialize and show call duration timer - if (*timer == NULL) { - timerLabel->setText(timer2str(0).c_str()); - timerLabel->show(); - *timer = new QTimer(this); - MEMMAN_NEW(*timer); - - if (line == 0) { - connect(*timer, SIGNAL(timeout()), this, - SLOT(showLineTimer1())); - } else { - connect(*timer, SIGNAL(timeout()), this, - SLOT(showLineTimer2())); - } - - // Update timer every 1s - (*timer)->start(1000, false); - } - break; - default: - // Hide call duration timer - if (*timer != NULL) { - // Hide the timer after a few seconds - hideLineTimer->start(HIDE_LINE_TIMER_AFTER * 1000, true); - (*timer)->stop(); - MEMMAN_DELETE(*timer); - *timer = NULL; - } - break; - } -} - -void MphoneForm::updateLineEncryptionState(int line) -{ - QLabel *cryptLabel, *sasLabel; - if (line == 0) { - cryptLabel = crypt1Label; - sasLabel = line1SasLabel; - } else { - cryptLabel = crypt2Label; - sasLabel = line2SasLabel; - } - - t_audio_session *as = phone->get_line(line)->get_audio_session(); - if (as && phone->is_line_encrypted(line)) { - string zrtp_sas = as->get_zrtp_sas(); - bool zrtp_sas_confirmed = as->get_zrtp_sas_confirmed(); - string srtp_cipher_mode = as->get_srtp_cipher_mode(); - - QToolTip::remove(cryptLabel); - QString toolTip = tr("Voice is encrypted") + " ("; - toolTip.append(srtp_cipher_mode.c_str()).append(")"); - - if (!zrtp_sas.empty()) { - // Set tool tip on encryption icon - toolTip.append("\nSAS = "); - toolTip.append(zrtp_sas.c_str()); - - // Show SAS - sasLabel->setText(zrtp_sas.c_str()); - sasLabel->show(); - } else { - sasLabel->hide(); - } - - if (!zrtp_sas_confirmed) { - toolTip.append("\n").append(tr("Click to confirm SAS.")); - cryptLabel->setFrameStyle(Q3Frame::Panel | Q3Frame::Raised); - cryptLabel->setPixmap( - qPixmapFromMimeSource("encrypted.png")); - } else { - toolTip.append("\n").append(tr("Click to clear SAS verification.")); - cryptLabel->setFrameStyle(Q3Frame::NoFrame); - cryptLabel->setPixmap( - qPixmapFromMimeSource("encrypted_verified.png")); - } - - QToolTip::add(cryptLabel, toolTip); - cryptLabel->show(); - } else { - cryptLabel->hide(); - sasLabel->hide(); - } -} - -void MphoneForm::updateLineStatus(int line) -{ - QString state; - bool on_hold; // indicates if a line is put on-hold - bool in_conference; // indicates if a line is in a conference - bool is_muted; // indicates is a line is muted - t_refer_state refer_state; // indicates if a call transfer is in progress - bool is_transfer_consult; // indicates if the call is a consultation - bool to_be_transferred; // indicates if the line is to be transferred after consultation - t_call_info call_info; - unsigned short dummy; - - QLabel *statLabel, *holdLabel, *muteLabel, *confLabel, *referLabel, *statusTextLabel; - - if (line == 0) { - statLabel = line1StatLabel; - holdLabel = line1HoldLabel; - muteLabel = line1MuteLabel; - confLabel = line1ConfLabel; - referLabel = line1ReferLabel; - statusTextLabel = status1TextLabel; - } else { - statLabel = line2StatLabel; - holdLabel = line2HoldLabel; - muteLabel = line2MuteLabel; - confLabel = line2ConfLabel; - referLabel = line2ReferLabel; - statusTextLabel = status2TextLabel; - } - - state = lineSubstate2str(line); - on_hold = phone->is_line_on_hold(line); - if (on_hold) { - holdLabel->show(); - } else { - holdLabel->hide(); - } - in_conference = phone->part_of_3way(line); - if (in_conference) { - confLabel->show(); - } else { - confLabel->hide(); - } - is_muted = phone->is_line_muted(line); - if (is_muted) { - muteLabel->show(); - } else { - muteLabel->hide(); - } - refer_state = phone->get_line_refer_state(line); - is_transfer_consult = phone->is_line_transfer_consult(line, dummy); - to_be_transferred = phone->line_to_be_transferred(line, dummy); - if (refer_state != REFST_NULL || is_transfer_consult || to_be_transferred) { - QString toolTip; - QToolTip::remove(referLabel); - referLabel->show(); - if (is_transfer_consult) { - referLabel->setPixmap( - qPixmapFromMimeSource("consult-xfer.png")); - toolTip = tr("Transfer consultation"); - } else { - referLabel->setPixmap( - qPixmapFromMimeSource("cf.png")); - toolTip = tr("Transferring call"); - } - QToolTip::add(referLabel, toolTip); - } else { - referLabel->hide(); - } - - statusTextLabel->setText(state); - - t_line_substate line_substate; - line_substate = phone->get_line_substate(line); - switch (line_substate) { - case LSSUB_IDLE: - ((t_gui *)ui)->clearLineFields(line); - statLabel->hide(); - break; - case LSSUB_SEIZED: - case LSSUB_OUTGOING_PROGRESS: - statLabel->setPixmap(qPixmapFromMimeSource("stat_outgoing.png")); - statLabel->show(); - break; - case LSSUB_INCOMING_PROGRESS: - statLabel->setPixmap(qPixmapFromMimeSource("stat_ringing.png")); - statLabel->show(); - break; - case LSSUB_ANSWERING: - statLabel->setPixmap(qPixmapFromMimeSource("gear.png")); - statLabel->show(); - break; - case LSSUB_ESTABLISHED: - if (phone->has_line_media(line)) { - statLabel->setPixmap(qPixmapFromMimeSource( - "stat_established.png")); - } else { - statLabel->setPixmap(qPixmapFromMimeSource( - "stat_established_nomedia.png")); - } - statLabel->show(); - break; - case LSSUB_RELEASING: - statLabel->setPixmap(qPixmapFromMimeSource("gear.png")); - statLabel->show(); - break; - default: - statLabel->hide(); - break; - } - - updateLineEncryptionState(line); - updateLineTimer(line); -} - -// Update line state and enable/disable buttons depending on state -void MphoneForm::updateState() -{ - QString state; - int line, other_line; - bool on_hold; // indicates if a line is put on-hold - bool in_conference; // indicates if a line is in a conference - bool is_muted; // indicates is a line is muted - t_refer_state refer_state; // indicates if a call transfer is in progress - bool is_transfer_consult; // indicates if the call is a consultation - bool to_be_transferred; // indicates if the line is to be transferred after consultation - bool has_media; // indicates if a media stream is present - t_call_info call_info; - unsigned short dummy; - - // Update status of line 1 - updateLineStatus(0); - - // Update status of line 2 - updateLineStatus(1); - - // Disable/enable controls depending on the active line state - t_line_substate line_substate; - line = phone->get_active_line(); - line_substate = phone->get_line_substate(line); - on_hold = phone->is_line_on_hold(line); - in_conference = phone->part_of_3way(line); - is_muted = phone->is_line_muted(line); - refer_state = phone->get_line_refer_state(line); - is_transfer_consult = phone->is_line_transfer_consult(line, dummy); - to_be_transferred = phone->line_to_be_transferred(line, dummy); - has_media = phone->has_line_media(line); - other_line = (line == 0 ? 1 : 0); - call_info = phone->get_call_info(line); - t_user *user_config = phone->get_line_user(line); - - // The active line may change when one of the parties in a conference - // releases the call. If this happens, then update the state of the - // line radio buttons. - if (line == 0 && line2RadioButton->isOn()) - { - line1RadioButton->setChecked(true); - } else if (line == 1 && line1RadioButton->isOn()) - { - line2RadioButton->setChecked(true); - } - - // Same logic for the activate line menu items - if (line == 0 && actionLine2->isOn()) - { - actionLine1->setOn(true); - } else if (line == 1 && actionLine1->isOn()) - { - actionLine2->setOn(true); - } - - switch(line_substate) { - case LSSUB_IDLE: - enableCallOptions(true); - callAnswer->setEnabled(false); - callBye->setEnabled(false); - callReject->setEnabled(false); - callRedirect->setEnabled(false); - callTransfer->setEnabled(false); - callHold->setEnabled(false); - callConference->setEnabled(false); - callMute->setEnabled(false); - callDTMF->setEnabled(false); - callRedial->setEnabled(ui->can_redial()); - break; - case LSSUB_OUTGOING_PROGRESS: - enableCallOptions(false); - callAnswer->setEnabled(false); - callBye->setEnabled(true); - callReject->setEnabled(false); - callRedirect->setEnabled(false); - - if (is_transfer_consult && user_config->get_allow_transfer_consultation_inprog()) { - callTransfer->setEnabled(true); - } else { - callTransfer->setEnabled(false); - } - - callHold->setEnabled(false); - callConference->setEnabled(false); - callMute->setEnabled(false); - callDTMF->setEnabled(call_info.dtmf_supported); - callRedial->setEnabled(false); - break; - case LSSUB_INCOMING_PROGRESS: - enableCallOptions(false); - callAnswer->setEnabled(true); - callBye->setEnabled(false); - callReject->setEnabled(true); - callRedirect->setEnabled(true); - callTransfer->setEnabled(false); - callHold->setEnabled(false); - callConference->setEnabled(false); - callMute->setEnabled(false); - callDTMF->setEnabled(call_info.dtmf_supported); - callRedial->setEnabled(false); - break; - case LSSUB_ESTABLISHED: - enableCallOptions(false); - callInvite->setEnabled(false); - callAnswer->setEnabled(false); - callBye->setEnabled(true); - callReject->setEnabled(false); - callRedirect->setEnabled(false); - - if (in_conference) { - callTransfer->setEnabled(false); - callHold->setEnabled(false); - callConference->setEnabled(false); - callDTMF->setEnabled(false); - } else { - callTransfer->setEnabled(has_media && - call_info.refer_supported && - refer_state == REFST_NULL && - !to_be_transferred); - callHold->setEnabled(has_media); - callDTMF->setEnabled(call_info.dtmf_supported); - - if (phone->get_line_substate(other_line) == - LSSUB_ESTABLISHED) - { - // If one of the lines is transferring a call, then a - // conference cannot be setup. - if (refer_state != REFST_NULL || - phone->get_line_refer_state(other_line) != REFST_NULL) - { - callConference->setEnabled(false); - } else { - callConference->setEnabled(has_media); - } - } else { - callConference->setEnabled(false); - } - } - - callMute->setEnabled(true); - callRedial->setEnabled(false); - break; - case LSSUB_SEIZED: - case LSSUB_ANSWERING: - case LSSUB_RELEASING: - // During dialing, answering and call release no other actions are - // possible - enableCallOptions(false); - callAnswer->setEnabled(false); - callBye->setEnabled(false); - callReject->setEnabled(false); - callRedirect->setEnabled(false); - callTransfer->setEnabled(false); - callHold->setEnabled(false); - callConference->setEnabled(false); - callMute->setEnabled(false); - callDTMF->setEnabled(false); - callRedial->setEnabled(false); - break; - default: - enableCallOptions(true); - callAnswer->setEnabled(true); - callBye->setEnabled(true); - callReject->setEnabled(true); - callRedirect->setEnabled(true); - callTransfer->setEnabled(true); - callHold->setEnabled(true); - callConference->setEnabled(false); - callMute->setEnabled(true); - callDTMF->setEnabled(true); - callRedial->setEnabled(ui->can_redial()); - } - - // Set hold action in correct state - callHold->setOn(on_hold); - - // Set mute action in correct state - callMute->setOn(is_muted); - - // Set transfer action in correct state - callTransfer->setOn(is_transfer_consult); - - // Hide redirect form if it is still visible, but not applicable anymore - if (!callRedirect->isEnabled() && redirectForm && - redirectForm->isVisible()) - { - redirectForm->hide(); - } - - // Hide transfer form if it is still visible, but not applicable anymore - if (!callTransfer->isEnabled() && transferForm && - transferForm->isVisible()) - { - transferForm->hide(); - } - - // Hide DTMF form if it is still visible, but not applicable anymore - if (!callDTMF->isEnabled() && dtmfForm && - dtmfForm->isVisible()) - { - dtmfForm->hide(); - } - - // Set last called address in the redial tool tip - t_url last_url; - string last_display; - string last_subject; - t_user *last_user; - bool hide_user; - if (callRedial->isEnabled() && - ui->get_last_call_info(last_url, last_display, last_subject, &last_user, hide_user)) - { - QString s = ""; - s += tr("Repeat last call"); - s += "
"; - s += ""; - - s += ""; - - if (!last_subject.empty()) { - s.append(""; - } - - if (hide_user) { - s.append(""; - } - - s += "
"; - s += tr("User:").append(""); - s += last_user->get_profile_name().c_str(); - s.append("
").append(tr("Call:")).append(""); - s += ui->format_sip_address(last_user, - last_display, last_url).c_str(); - s += "
").append(tr("Subject:")).append(""); - s += last_subject.c_str(); - s += "
").append(tr("Hide identity")); - s += "
"; - callRedial->setToolTip(s); - } else { - callRedial->setToolTip(tr("Repeat last call")); - } - callRedial->setStatusTip(tr("Repeat last call")); - - updateSysTrayStatus(); -} - -// Update registration status -void MphoneForm::updateRegStatus() -{ - size_t num_registered = 0; - size_t num_failed = 0; - QString toolTip = ""; - toolTip.append(tr("Registration status:")); - toolTip.append("
"); - toolTip.append(""); - - // Count number of succesful and failed registrations. - // Determine tool tip showing registration details for all users. - listuser_list = phone->ref_users(); - for (list::iterator i = user_list.begin(); i != user_list.end(); i++) { - toolTip.append(""); - } - toolTip.append("
"); - toolTip.append((*i)->get_profile_name().c_str()); - toolTip.append(""); - if (phone->get_is_registered(*i)) { - num_registered++; - toolTip.append(tr("Registered")); - } else if (phone->get_last_reg_failed(*i)) { - num_failed++; - toolTip.append(tr("Failed")); - } else { - toolTip.append(tr("Not registered").replace(' ', " ")); - } - toolTip.append("

"); - toolTip.append(""); - toolTip.append(tr("Click to show registrations.").replace(' ', " ")); - toolTip.append(""); - - // Set registration status - if (num_registered == user_list.size()) { - // All users are registered - statRegLabel->setPixmap(qPixmapFromMimeSource("twinkle16.png")); - } else if (num_failed == user_list.size()) { - // All users failed to register - statRegLabel->setPixmap(qPixmapFromMimeSource("reg_failed.png")); - } else if (num_registered > 0) { - // Some users are registered - statRegLabel->setPixmap(qPixmapFromMimeSource( - "twinkle16.png")); - } else if (num_failed > 0) { - // Some users failed, none are registered - statRegLabel->setPixmap(qPixmapFromMimeSource("reg_failed.png")); - } else { - // No users are registered, no users failed - statRegLabel->setPixmap(qPixmapFromMimeSource("twinkle16-disabled.png")); - } - - // Set tool tip with detailed info. - QToolTip::remove(statRegLabel); - - if (num_registered > 0 || num_failed > 0) { - QToolTip::add(statRegLabel, toolTip); - } else { - QToolTip::add(statRegLabel, tr("No users are registered.")); - } - - updateSysTrayStatus(); -} - -// Create a status message based on the number of waiting messages. -// On return, msg_waiting will indicate if the MWI indicator should show -// waiting messages. -QString MphoneForm::getMWIStatus(const t_mwi &mwi, bool &msg_waiting) const -{ - QString status; - msg_waiting = false; - t_msg_summary summary = mwi.get_voice_msg_summary(); - - if (summary.newmsgs > 0 && summary.oldmsgs > 0) { - if (summary.oldmsgs == 1) { - status = tr("%1 new, 1 old message"). - arg(summary.newmsgs); - } else { - status = tr("%1 new, %2 old messages"). - arg(summary.newmsgs). - arg(summary.oldmsgs); - } - msg_waiting = true; - } else if (summary.newmsgs > 0 && summary.oldmsgs == 0) { - if (summary.newmsgs == 1) { - status = tr("1 new message"); - } else { - status = tr("%1 new messages"). - arg(summary.newmsgs); - } - msg_waiting = true; - } else if (summary.oldmsgs > 0) { - if (summary.oldmsgs == 1) { - status = tr("1 old message"); - } else { - status = tr("%1 old messages"). - arg(summary.oldmsgs); - } - } else { - if (mwi.get_msg_waiting()) { - status = tr("Messages waiting"); - msg_waiting = true; - } else { - status = tr("No messages"); - } - } - - return status.replace(' ', " "); -} - -// Flash the MWI icon -void MphoneForm::flashMWI() -{ - if (mwiFlashStatus) { - mwiFlashStatus = false; - statMWILabel->setPixmap(qPixmapFromMimeSource( - "mwi_none16.png")); - } else { - mwiFlashStatus = true; - statMWILabel->setPixmap(qPixmapFromMimeSource( - "mwi_new16.png")); - } -} - -// Update MWI -void MphoneForm::updateMwi() -{ - bool mwi_known = false; - bool mwi_new_msgs = false; - bool mwi_failure = false; - - // Determine tool tip - QString toolTip = tr("Voice mail status:").append("\n"); - toolTip.append("
"); - listuser_list = phone->ref_users(); - for (list::iterator i = user_list.begin(); i != user_list.end(); i++) { - toolTip.append(""); - } - - toolTip.append("
"); - toolTip.append((*i)->get_profile_name().c_str()); - t_mwi mwi = phone->get_mwi(*i); - toolTip.append(""); - if (phone->is_mwi_subscribed(*i)) { - if (mwi.get_status() == t_mwi::MWI_KNOWN) { - bool new_msgs; - QString status = getMWIStatus(mwi, new_msgs); - toolTip.append(status); - mwi_known = true; - mwi_new_msgs |= new_msgs; - } else if (mwi.get_status() == t_mwi::MWI_FAILED) { - toolTip.append(tr("Failure")); - mwi_failure = true; - } else { - toolTip.append(tr("Unknown")); - } - } else { - if ((*i)->get_mwi_sollicited()) { - if (mwi.get_status() == t_mwi::MWI_FAILED) { - toolTip.append(tr("Failure")); - mwi_failure = true; - } else { - toolTip.append(tr("Unknown")); - } - } else { - // Unsollicited MWI - if (mwi.get_status() == t_mwi::MWI_KNOWN) { - bool new_msgs; - QString status = getMWIStatus(mwi, new_msgs); - toolTip.append(status); - mwi_known = true; - mwi_new_msgs |= new_msgs; - } else { - toolTip.append(tr("Unknown")); - } - } - } - toolTip.append("

"); - toolTip.append(""); - toolTip.append(tr("Click to access voice mail.").replace(' ', " ")); - toolTip.append(""); - - // Set MWI icon - if (mwi_new_msgs) { - statMWILabel->setPixmap(qPixmapFromMimeSource( - "mwi_new16.png")); - mwiFlashStatus = true; - - // Start the flash MWI timer to flash the indicator - tmrFlashMWI.start(1000); - } else if (mwi_failure) { - tmrFlashMWI.stop(); - statMWILabel->setPixmap(qPixmapFromMimeSource( - "mwi_failure16.png")); - } else if (mwi_known) { - tmrFlashMWI.stop(); - statMWILabel->setPixmap(qPixmapFromMimeSource( - "mwi_none16.png")); - } else { - tmrFlashMWI.stop(); - statMWILabel->setPixmap(qPixmapFromMimeSource( - "mwi_none16_dis.png")); - } - - // Set tool tip - QToolTip::remove(statMWILabel); - QToolTip::add(statMWILabel, toolTip); - - updateSysTrayStatus(); -} - -// Update active services status -void MphoneForm::updateServicesStatus() -{ - size_t num_dnd = 0; - size_t num_cf = 0; - size_t num_auto_answer = 0; - QString tipDnd = ""; - tipDnd += tr("Do not disturb active for:").replace(' ', " "); - tipDnd += "
\n"; - QString tipCf = ""; - tipCf += tr("Redirection active for:").replace(' ', " "); - tipCf += "
\n
"; - QString tipAa = ""; - tipAa += tr("Auto answer active for:").replace(' ', " "); - tipAa += "
\n
"; - - // Calculate number of services active. - // Determine tool tips with detailed service status for all users. - listuser_list = phone->ref_users(); - for (list::iterator i = user_list.begin(); i != user_list.end(); i++) { - if (phone->ref_service(*i)->is_dnd_active()) { - num_dnd++; - tipDnd.append(""); - } - if (phone->ref_service(*i)->is_cf_active()) { - num_cf++; - tipCf.append(""); - } - if (phone->ref_service(*i)->is_auto_answer_active()) { - num_auto_answer++; - tipAa.append(""); - } - } - - QString footer = ""; - footer += tr("Click to activate/deactivate").replace(' ', " "); - footer += ""; - - tipDnd.append("
"); - tipDnd.append((*i)->get_profile_name().c_str()); - tipDnd.append("
"); - tipCf.append((*i)->get_profile_name().c_str()); - tipCf.append("
"); - tipAa.append((*i)->get_profile_name().c_str()); - tipAa.append("

"); - tipDnd.append(footer); - tipCf.append("
"); - tipCf.append(footer); - tipAa.append("
"); - tipAa.append(footer); - - // Set service status - if (num_dnd == user_list.size()) { - // All users enabled dnd - statDndLabel->setPixmap(qPixmapFromMimeSource("cancel.png")); - } else if (num_dnd > 0) { - // Some users enabled dnd - statDndLabel->setPixmap(qPixmapFromMimeSource("cancel.png")); - } else { - // No users enabeld dnd - statDndLabel->setPixmap(qPixmapFromMimeSource("cancel-disabled.png")); - } - - if (num_cf == user_list.size()) { - // All users enabled redirecton - statCfLabel->setPixmap(qPixmapFromMimeSource("cf.png")); - } else if (num_cf > 0) { - // Some users enabled redirection - statCfLabel->setPixmap(qPixmapFromMimeSource("cf.png")); - } else { - // No users enabled redirection - statCfLabel->setPixmap(qPixmapFromMimeSource("cf-disabled.png")); - } - - if (num_auto_answer == user_list.size()) { - // All users enabled auto answer - statAaLabel->setPixmap(qPixmapFromMimeSource("auto_answer.png")); - } else if (num_auto_answer > 0) { - // Some users enabled auto answer - statAaLabel->setPixmap(qPixmapFromMimeSource( - "auto_answer.png")); - } else { - // No users enabeld auto answer - statAaLabel->setPixmap(qPixmapFromMimeSource( - "auto_answer-disabled.png")); - } - - // Set tool tip with detailed info for multiple users. - QToolTip::remove(statDndLabel); - QToolTip::remove(statCfLabel); - QToolTip::remove(statAaLabel); - - QString clickToActivate(""); - clickToActivate += tr("Click to activate").replace(' ', " "); - clickToActivate += ""; - if (num_dnd > 0) { - QToolTip::add(statDndLabel, tipDnd); - } else { - QString status("

"); - status += tr("Do not disturb is not active.").replace(' ', " "); - status += "

"; - status += clickToActivate; - QToolTip::add(statDndLabel, status); - } - - if (num_cf > 0) { - QToolTip::add(statCfLabel, tipCf); - } else { - QString status("

"); - status += tr("Redirection is not active.").replace(' ', " "); - status += "

"; - status += clickToActivate; - QToolTip::add(statCfLabel, status); - } - - if (num_auto_answer > 0) { - QToolTip::add(statAaLabel, tipAa); - } else { - QString status("

"); - status += tr("Auto answer is not active.").replace(' ', " "); - status += "

"; - status += clickToActivate; - QToolTip::add(statAaLabel, status); - } - - updateSysTrayStatus(); -} - -void MphoneForm::updateMissedCallStatus(int num_missed_calls) -{ - QToolTip::remove(statMissedLabel); - - QString clickDetails(""); - clickDetails += tr("Click to see call history for details.").replace(' ', " "); - clickDetails += ""; - if (num_missed_calls == 0) { - statMissedLabel->setPixmap(qPixmapFromMimeSource("missed-disabled.png")); - QString status("

"); - status += tr("You have no missed calls.").replace(' ', " "); - status += "

"; - status += clickDetails; - QToolTip::add(statMissedLabel, status); - } else { - statMissedLabel->setPixmap( - qPixmapFromMimeSource("missed.png")); - - QString tip("

"); - if (num_missed_calls == 1) { - tip += tr("You missed 1 call.").replace(' ', " "); - } else { - tip += tr("You missed %1 calls.").arg(num_missed_calls). - replace(' ', " "); - } - tip += "

"; - tip += clickDetails; - QToolTip::add(statMissedLabel, tip); - } - - updateSysTrayStatus(); -} - -// Update system tray status -void MphoneForm::updateSysTrayStatus() -{ - QString icon_name; - bool cf_active = false; - bool dnd_active = false; - bool auto_answer_active = false; - bool multi_services = false; - int num_services; - bool msg_waiting = false; - - if (!sysTray) return; - - // Get status of active line - int line = phone->get_active_line(); - t_line_substate line_substate = phone->get_line_substate(line); - - list user_list = phone->ref_users(); - - switch(line_substate) { - case LSSUB_IDLE: - case LSSUB_SEIZED: - // Determine MWI and service status - user_list = phone->ref_users(); - for (list::iterator i = user_list.begin(); i != user_list.end(); i++) { - t_mwi mwi = phone->get_mwi(*i); - if (mwi.get_status() == t_mwi::MWI_KNOWN && - mwi.get_msg_waiting() && - mwi.get_voice_msg_summary().newmsgs > 0) - { - msg_waiting = true; - } else if (phone->ref_service(*i)->multiple_services_active()) { - multi_services = true; - } else { - if (phone->ref_service(*i)->is_dnd_active()) { - dnd_active = true; - } - if (phone->ref_service(*i)->is_cf_active()) { - cf_active = true; - } - if (phone->ref_service(*i)->is_auto_answer_active()) { - auto_answer_active = true; - } - } - } - - // If there are messages waiting, then show MWI icon - if (msg_waiting) { - icon_name = "sys_mwi"; - break; - } - - // If there are missed calls, then show the missed call icon - if (call_history->get_num_missed_calls() > 0) { - icon_name = "sys_missed"; - break; - } - - // If a service is active, then show the service icon - num_services = (dnd_active ? 1 : 0) + (cf_active ? 1 : 0) + - (auto_answer_active ? 1 : 0); - - if (multi_services || num_services > 1) { - icon_name = "sys_services"; - } else if (dnd_active) { - icon_name = "sys_dnd"; - } else if (cf_active) { - icon_name = "sys_redir"; - } else if (auto_answer_active) { - icon_name = "sys_auto_ans"; - } else { - // No service is active, show the idle icon - if (icon_name.isEmpty()) icon_name = "sys_idle"; - } - - break; - case LSSUB_ESTABLISHED: - if (phone->is_line_on_hold(line)) { - icon_name = "sys_hold"; - } else if (phone->is_line_muted(line)) { - icon_name = "sys_mute"; - } else if (phone->is_line_encrypted(line)) { - t_audio_session *as = phone->get_line(line)->get_audio_session(); - if (as && as->get_zrtp_sas_confirmed()) { - icon_name = "sys_encrypted_verified"; - } else { - icon_name = "sys_encrypted"; - } - } else { - icon_name = "sys_busy_estab"; - } - break; - default: - // Line is in a busy transient state - icon_name = "sys_busy_trans"; - } - - // Based on the registration status use the active or disabled version - // of the icon. - bool registered = false; - for (list::iterator i = user_list.begin(); i != user_list.end(); i++) { - if (phone->get_is_registered(*i)) { - registered = true; - break; - } - } - - if (registered) { - icon_name += ".png"; - } else { - icon_name += "_dis.png"; - } - - sysTray->setPixmap(qPixmapFromMimeSource(icon_name)); -} - -// Update menu status based on the number of active users -void MphoneForm::updateMenuStatus() -{ - // Some menu options should be toggle actions when there is only - // 1 user active, but they should be normal actions when there are - // multiple users. - disconnect(serviceDnd, 0, 0, 0); - disconnect(serviceAutoAnswer, 0, 0, 0); - if (phone->ref_users().size() == 1) { - t_service *srv = phone->ref_service(phone->ref_users().front()); - - serviceDnd->setToggleAction(true); - serviceDnd->setOn(srv->is_dnd_active()); - connect(serviceDnd, SIGNAL(toggled(bool)), - this, SLOT(srvDnd(bool))); - - serviceAutoAnswer->setToggleAction(true); - serviceAutoAnswer->setOn(srv->is_auto_answer_active()); - connect(serviceAutoAnswer, SIGNAL(toggled(bool)), - this, SLOT(srvAutoAnswer(bool))); - } else { - serviceDnd->setOn(false); - serviceDnd->setToggleAction(false); - connect(serviceDnd, SIGNAL(activated()), - this, SLOT(srvDnd())); - - serviceAutoAnswer->setOn(false); - serviceAutoAnswer->setToggleAction(false); - connect(serviceAutoAnswer, SIGNAL(activated()), - this, SLOT(srvAutoAnswer())); - } - - updateDiamondcardMenu(); -} - -void MphoneForm::updateDiamondcardMenu() -{ - // If one Diamondcard user is active, then create actions in the Diamondcard - // main menu for recharging, call history, etc. These actions will show the - // Diamondcard web page. - // If multiple Diamondcard users are active then create a submenu of each - // Diamondcard action. In each submenu create an item for each user. - // When a user item is clicked, the web page for the action and that user is - // shown. - list diamondcard_users = diamondcard_get_users(phone); - - // Menu item identifiers - static int rechargeId = -1; - static int balanceHistoryId = -1; - static int callHistoryId = -1; - static int adminCenterId = -1; - - // Sub menu's - static Q3PopupMenu *rechargeMenu = NULL; - static Q3PopupMenu *balanceHistoryMenu = NULL; - static Q3PopupMenu *callHistoryMenu = NULL; - static Q3PopupMenu *adminCenterMenu = NULL; - - // Clear old menu - removeDiamondcardAction(rechargeId); - removeDiamondcardAction(balanceHistoryId); - removeDiamondcardAction(callHistoryId); - removeDiamondcardAction(adminCenterId); - removeDiamondcardMenu(rechargeMenu); - removeDiamondcardMenu(balanceHistoryMenu); - removeDiamondcardMenu(callHistoryMenu); - removeDiamondcardMenu(adminCenterMenu); - - if (diamondcard_users.size() <= 1) - { - rechargeId = Diamondcard->insertItem(tr("Recharge..."), this, SLOT(DiamondcardRecharge(int))); - Diamondcard->setItemParameter(rechargeId, 0); - balanceHistoryId = Diamondcard->insertItem(tr("Balance history..."), this, SLOT(DiamondcardBalanceHistory(int))); - Diamondcard->setItemParameter(balanceHistoryId, 0); - callHistoryId = Diamondcard->insertItem(tr("Call history..."), this, SLOT(DiamondcardCallHistory(int))); - Diamondcard->setItemParameter(callHistoryId, 0); - adminCenterId = Diamondcard->insertItem(tr("Admin center..."), this, SLOT(DiamondcardAdminCenter(int))); - Diamondcard->setItemParameter(adminCenterId, 0); - - // Disable actions as there is no active Diamondcard users. - if (diamondcard_users.empty()) { - Diamondcard->setItemEnabled(rechargeId, false); - Diamondcard->setItemEnabled(balanceHistoryId, false); - Diamondcard->setItemEnabled(callHistoryId, false); - Diamondcard->setItemEnabled(adminCenterId, false); - } - } - else - { - rechargeMenu = new Q3PopupMenu(this); - balanceHistoryMenu = new Q3PopupMenu(this); - callHistoryMenu = new Q3PopupMenu(this); - adminCenterMenu = new Q3PopupMenu(this); - // No MEMMAN registration as the popup menu may be automatically - // deleted by Qt on application close down. This would show up as - // a memory leak in MEMMAN. - - // Insert a menu item for each Diamondcard user. - int idx = 0; - for (list::const_iterator it = diamondcard_users.begin(); - it != diamondcard_users.end(); ++it) - { - int menuId; - t_user *user = *it; - - // Set the index in the user list as parameter to the menu item. - // When the menu item gets clicked, then the receiver of the signal - // received this parameter and can use it as an index in the user list - // to find the user. - - menuId = rechargeMenu->insertItem(user->get_profile_name().c_str(), this, - SLOT(DiamondcardRecharge(int))); - rechargeMenu->setItemParameter(menuId, idx); - menuId = balanceHistoryMenu->insertItem(user->get_profile_name().c_str(), this, - SLOT(DiamondcardBalanceHistory(int))); - balanceHistoryMenu->setItemParameter(menuId, idx); - menuId = callHistoryMenu->insertItem(user->get_profile_name().c_str(), this, - SLOT(DiamondcardCallHistory(int))); - callHistoryMenu->setItemParameter(menuId, idx); - menuId = adminCenterMenu->insertItem(user->get_profile_name().c_str(), this, - SLOT(DiamondcardAdminCenter(int))); - adminCenterMenu->setItemParameter(menuId, idx); - - ++idx; - } - - // Add the Diamondcard popup menus to the main Diamondcard menu. - Diamondcard->insertItem(tr("Recharge"), rechargeMenu); - Diamondcard->insertItem(tr("Balance history"), balanceHistoryMenu); - Diamondcard->insertItem(tr("Call history"), callHistoryMenu); - Diamondcard->insertItem(tr("Admin center"), adminCenterMenu); - } -} - -void MphoneForm::removeDiamondcardAction(int &id) -{ - if (id != -1) { - Diamondcard->removeItem(id); - id = -1; - } -} - -void MphoneForm::removeDiamondcardMenu(Q3PopupMenu* &menu) -{ - if (menu) { - delete menu; - menu = NULL; - } -} - -void MphoneForm::phoneRegister() -{ - t_gui *gui = (t_gui *)ui; - list user_list = phone->ref_users(); - - if (user_list.size() > 1) { - if (selectUserForm) { - MEMMAN_DELETE(selectUserForm); - delete (selectUserForm); - } - - selectUserForm = new SelectUserForm(this, "register", true); - MEMMAN_NEW(selectUserForm); - - connect(selectUserForm, SIGNAL(selection(list)), this, - SLOT(do_phoneRegister(list))); - selectUserForm->show(SELECT_REGISTER); - } else { - gui->action_register(user_list); - } -} - -void MphoneForm::do_phoneRegister(list user_list) -{ - ((t_gui *)ui)->action_register(user_list); -} - -void MphoneForm::phoneDeregister() -{ - t_gui *gui = (t_gui *)ui; - list user_list = phone->ref_users(); - - if (user_list.size() > 1) { - if (selectUserForm) { - MEMMAN_DELETE(selectUserForm); - delete (selectUserForm); - } - - selectUserForm = new SelectUserForm(this, "deregister", true); - MEMMAN_NEW(selectUserForm); - - connect(selectUserForm, SIGNAL(selection(list)), this, - SLOT(do_phoneDeregister(list))); - selectUserForm->show(SELECT_DEREGISTER); - } else { - gui->action_deregister(user_list, false); - } -} - -void MphoneForm::do_phoneDeregister(list user_list) -{ - ((t_gui *)ui)->action_deregister(user_list, false); -} - -void MphoneForm::phoneDeregisterAll() -{ - t_gui *gui = (t_gui *)ui; - list user_list = phone->ref_users(); - - if (user_list.size() > 1) { - if (selectUserForm) { - MEMMAN_DELETE(selectUserForm); - delete (selectUserForm); - } - - selectUserForm = new SelectUserForm(this, "deregister all", true); - MEMMAN_NEW(selectUserForm); - - connect(selectUserForm, SIGNAL(selection(list)), this, - SLOT(do_phoneDeregisterAll(list))); - selectUserForm->show(SELECT_DEREGISTER_ALL); - } else { - gui->action_deregister(user_list, true); - } -} - -void MphoneForm::do_phoneDeregisterAll(list user_list) -{ - ((t_gui *)ui)->action_deregister(user_list, true); -} - -void MphoneForm::phoneShowRegistrations() -{ - list user_list = phone->ref_users(); - ((t_gui *)ui)->action_show_registrations(user_list); -} - - -// Show the semi-modal invite window -void MphoneForm::phoneInvite(t_user * user_config, - const QString &dest, const QString &subject, bool anonymous) -{ - // Seize the line, so no incoming call can take the line - if (!((t_gui *)ui)->action_seize()) return; - - if (inviteForm) { - inviteForm->clear(); - } else { - inviteForm = new InviteForm(this, "invite", true); - MEMMAN_NEW(inviteForm); - - // Initialize the destination history list - for (int i = callComboBox->count() - 1; i >= 0; i--) { - inviteForm->addToInviteComboBox(callComboBox->text(i)); - } - - connect(inviteForm, - SIGNAL(destination(t_user *, const QString &, const t_url &, - const QString &, bool)), - this, - SLOT(do_phoneInvite(t_user *, const QString &, - const t_url &, const QString &, bool))); - - connect(inviteForm, SIGNAL(raw_destination(const QString &)), - this, SLOT(addToCallComboBox(const QString &))); - } - - inviteForm->show(user_config, dest, subject, anonymous); - updateState(); -} - -void MphoneForm::phoneInvite(const QString &dest, const QString &subject, bool anonymous) -{ - t_user *user = phone->ref_user_profile(userComboBox->currentText().ascii()); - if (!user) { - log_file->write_report("Cannot find user profile.", - "MphoneForm::phoneInvite", - LOG_NORMAL, LOG_CRITICAL); - return; - } - phoneInvite(user, dest, subject, anonymous); -} - -void MphoneForm::phoneInvite() -{ - t_user *user = phone->ref_user_profile(userComboBox->currentText().ascii()); - if (!user) { - log_file->write_report("Cannot find user profile.", - "MphoneForm::phoneInvite", - LOG_NORMAL, LOG_CRITICAL); - return; - } - phoneInvite(user, "", "", false); -} - -// Execute the invite action. This slot is connected to the destination -// signal of the invite window. -void MphoneForm::do_phoneInvite(t_user *user_config, const QString &display, - const t_url &destination, const QString &subject, - bool anonymous) -{ - ((t_gui *)ui)->action_invite(user_config, destination, display.ascii(), subject.ascii(), - anonymous); - updateState(); -} - -// Redial last call -void MphoneForm::phoneRedial(void) -{ - t_url url; - string display, subject; - t_user *user_config; - bool hide_user; - - if (!ui->get_last_call_info(url, display, subject, &user_config, hide_user)) return; - ((t_gui *)ui)->action_invite(user_config, url, display, subject, hide_user); - updateState(); -} - - -void MphoneForm::phoneAnswer() -{ - ((t_gui *)ui)->action_answer(); - updateState(); -} - -// A call can be answered from the systray popup. The user may have -// switched lines, the systray popup answer button should answer the -// correct line. -void MphoneForm::phoneAnswerFromSystrayPopup() -{ -#ifdef HAVE_KDE - unsigned short line = ((t_gui *)ui)->get_line_sys_tray_popup(); - unsigned short active_line = phone->get_active_line(); - - if (line != active_line) { - ((t_gui *)ui)->action_activate_line(line); - } - - ((t_gui *)ui)->action_answer(); - updateState(); -#endif -} - -void MphoneForm::phoneBye() -{ - ((t_gui *)ui)->action_bye(); - updateState(); -} - - -void MphoneForm::phoneReject() -{ - ((t_gui *)ui)->action_reject(); - updateState(); -} - -// A call can be rejected from the systray popup. The user may have -// switched lines, the systray popup reject button should answer the -// correct line. -void MphoneForm::phoneRejectFromSystrayPopup() -{ -#ifdef HAVE_KDE - unsigned short line = ((t_gui *)ui)->get_line_sys_tray_popup(); - ((t_gui *)ui)->action_reject(line); - updateState(); -#endif -} - - -// Show the semi-modal redirect form -void MphoneForm::phoneRedirect(const list &contacts) -{ - int active_line = phone->get_active_line(); - t_user *user_config = phone->get_line_user(active_line); - - if (redirectForm) { - MEMMAN_DELETE(redirectForm); - delete (redirectForm); - } - - redirectForm = new RedirectForm(this, "redirect", true); - MEMMAN_NEW(redirectForm); - connect(redirectForm, SIGNAL(destinations(const list &)), - this, SLOT(do_phoneRedirect(const list &))); - - redirectForm->show(user_config, contacts); -} - -void MphoneForm::phoneRedirect() -{ - const list l; - phoneRedirect(l); -} - -// Execute the redirect action. -void MphoneForm::do_phoneRedirect(const list &destinations) -{ - ((t_gui *)ui)->action_redirect(destinations); - updateState(); -} - -// Show the semi-modal call transfer window -void MphoneForm::phoneTransfer(const string &dest, t_transfer_type transfer_type) -{ - int active_line = phone->get_active_line(); - t_user *user_config = phone->get_line_user(active_line); - - // Hold the call if setting in user profile indicates call hold - if (user_config->get_referrer_hold()) { - phoneHold(true); - } - - if (transferForm) { - MEMMAN_DELETE(transferForm); - delete transferForm; - } - - transferForm = new TransferForm(this, "transfer", true); - MEMMAN_NEW(transferForm); - connect(transferForm, SIGNAL(destination(const t_display_url &, t_transfer_type)), - this, SLOT(do_phoneTransfer(const t_display_url &, t_transfer_type))); - - if (dest.empty() && transfer_type == TRANSFER_BASIC) { - // Let form pick a default transfer type based on the current - // call status. - transferForm->show(user_config); - } else { - // Set passed destination and transfer type in form - transferForm->show(user_config, dest, transfer_type); - } - updateState(); -} - -void MphoneForm::phoneTransfer() -{ - unsigned short active_line = phone->get_active_line(); - unsigned short dummy; - - if (phone->is_line_transfer_consult(active_line, dummy)) { - do_phoneTransferLine(); - } else { - phoneTransfer("", TRANSFER_BASIC); - } -} - -// Execute the transfer action. This slot is connected to the destination -// signal of the transfer window. -void MphoneForm::do_phoneTransfer(const t_display_url &destination, - t_transfer_type transfer_type) -{ - unsigned short active_line; - unsigned short other_line; - - switch (transfer_type) { - case TRANSFER_BASIC: - ((t_gui *)ui)->action_refer(destination.url, destination.display); - break; - case TRANSFER_CONSULT: - ((t_gui *)ui)->action_setup_consultation_call( - destination.url, destination.display); - break; - case TRANSFER_OTHER_LINE: - active_line = phone->get_active_line(); - other_line = (active_line == 0 ? 1 : 0); - - if (phone->get_line_substate(other_line) == LSSUB_ESTABLISHED) { - ((t_gui *)ui)->action_refer(active_line, other_line); - } else { - // The other line was released while the user was entering - // the refer-target. - t_user *user_config = phone->get_line_user(active_line); - if (user_config->get_referrer_hold()) { - phoneHold(false); - } - } - break; - default: - assert(false); - } - - updateState(); -} - -// Transfer the remote party on the held line to the remote party on the -// active line. -void MphoneForm::do_phoneTransferLine() -{ - unsigned short active_line = phone->get_active_line(); - unsigned short line_to_be_transferred; - - if (!phone->is_line_transfer_consult(active_line, line_to_be_transferred)) { - // Somehow the line is not a consultation call. - updateState(); - return; - } - - ((t_gui *)ui)->action_refer(line_to_be_transferred, active_line); - updateState(); -} - -void MphoneForm::phoneHold(bool on) -{ - if (on) { - ((t_gui *)ui)->action_hold(); - } else { - ((t_gui *)ui)->action_retrieve(); - } - - updateState(); -} - -void MphoneForm::phoneConference() -{ - ((t_gui *)ui)->action_conference(); - updateState(); -} - -void MphoneForm::phoneMute(bool on) -{ - ((t_gui *)ui)->action_mute(on); - updateState(); -} - -void MphoneForm::phoneTermCap(const QString &dest) -{ - // In-dialog OPTIONS request - int line = phone->get_active_line(); - if (phone->get_line_substate(line) == LSSUB_ESTABLISHED) { - ((t_gui *)ui)->action_options(); - return; - } - - // Out-of-dialog OPTIONS request - if (termCapForm) { - MEMMAN_DELETE(termCapForm); - delete (termCapForm); - } - - termCapForm = new TermCapForm(this, "termcap", true); - MEMMAN_NEW(termCapForm); - connect(termCapForm, SIGNAL(destination(t_user *, const t_url &)), - this, SLOT(do_phoneTermCap(t_user *, const t_url &))); - - t_user *user = phone->ref_user_profile(userComboBox->currentText().ascii()); - if (!user) { - log_file->write_report("Cannot find user profile.", - "MphoneForm::phoneTermcap", - LOG_NORMAL, LOG_CRITICAL); - return; - } - termCapForm->show(user, dest); -} - -void MphoneForm::phoneTermCap() -{ - phoneTermCap(""); -} - -void MphoneForm::do_phoneTermCap(t_user *user_config, const t_url &destination) -{ - ((t_gui *)ui)->action_options(user_config, destination); -} - -void MphoneForm::phoneDTMF() -{ - if (!dtmfForm) { - dtmfForm = new DtmfForm(this); - MEMMAN_NEW(dtmfForm); - connect(dtmfForm, SIGNAL(digits(const QString &)), - this, SLOT(sendDTMF(const QString &))); - } - - dtmfForm->show(); -} - -void MphoneForm::sendDTMF(const QString &digits) -{ - ((t_gui *)ui)->action_dtmf(digits.ascii()); -} - -void MphoneForm::startMessageSession(void) -{ - t_user *user = phone->ref_user_profile(userComboBox->currentText().ascii()); - if (!user) { - log_file->write_report("Cannot find user profile.", - "MphoneForm::startMessageSession", - LOG_NORMAL, LOG_CRITICAL); - return; - } - - im::t_msg_session *session = new im::t_msg_session(user); - MEMMAN_NEW(session); - ((t_gui *)ui)->addMessageSession(session); - MessageFormView *messageFormView = new MessageFormView(NULL, session); - MEMMAN_NEW(messageFormView); - messageFormView->show(); -} - -void MphoneForm::startMessageSession(t_buddy *buddy) -{ - t_user *user_config = buddy->get_user_profile(); - t_url dest_url(ui->expand_destination(user_config, buddy->get_sip_address())); - if (!dest_url.is_valid()) return; - string display = buddy->get_name(); - - // Find an existing session - im::t_msg_session *session = ((t_gui *)ui)->getMessageSession(user_config, dest_url, display); - if (!session) { - // There is no session yet, create one. - session = new im::t_msg_session(user_config, t_display_url(dest_url, display)); - MEMMAN_NEW(session); - ((t_gui *)ui)->addMessageSession(session); - MessageFormView *view = new MessageFormView(NULL, session); - MEMMAN_NEW(view); - view->show(); - } -} - -void MphoneForm::phoneConfirmZrtpSas(int line) -{ - ((t_gui *)ui)->action_confirm_zrtp_sas(line); - updateState(); -} - -void MphoneForm::phoneConfirmZrtpSas() -{ - ((t_gui *)ui)->action_confirm_zrtp_sas(); - updateState(); -} - -void MphoneForm::phoneResetZrtpSasConfirmation(int line) -{ - ((t_gui *)ui)->action_reset_zrtp_sas_confirmation(line); - updateState(); -} - -void MphoneForm::phoneResetZrtpSasConfirmation() -{ - ((t_gui *)ui)->action_reset_zrtp_sas_confirmation(); - updateState(); -} - -void MphoneForm::phoneEnableZrtp(bool on) -{ - if (on) { - ((t_gui *)ui)->action_enable_zrtp(); - } else { - ((t_gui *)ui)->action_zrtp_request_go_clear(); - } - - updateState(); -} - -void MphoneForm::phoneZrtpGoClearOk(unsigned short line) -{ - ((t_gui *)ui)->action_zrtp_go_clear_ok(line); - updateState(); -} - -// Radio button for line 1 changed state -void MphoneForm::line1rbChangedState( bool on ) -{ - // If the radio button is switched off, then return, the toggle - // on the other line will handle the action - if (!on) return; - - ((t_gui *)ui)->action_activate_line(0); -} - -void MphoneForm::line2rbChangedState( bool on ) -{ - // If the radio button is switched off, then return, the toggle - // on the other line will handle the action - if (!on) return; - - ((t_gui *)ui)->action_activate_line(1); -} - -void MphoneForm::actionLine1Toggled( bool on) -{ - if (!on) return; - ((t_gui *)ui)->action_activate_line(0); -} - -void MphoneForm::actionLine2Toggled( bool on) -{ - if (!on) return; - ((t_gui *)ui)->action_activate_line(1); -} - -// Enable/disable dnd when there is 1 user active -void MphoneForm::srvDnd( bool on ) -{ - ((t_gui *)ui)->srv_dnd(phone->ref_users(), on); - updateServicesStatus(); -} - -// Enable/disable dnd when there are multiple users active -void MphoneForm::srvDnd() -{ - if (selectUserForm) { - MEMMAN_DELETE(selectUserForm); - delete (selectUserForm); - } - - selectUserForm = new SelectUserForm(this, "dnd", true); - MEMMAN_NEW(selectUserForm); - - connect(selectUserForm, SIGNAL(selection(list)), this, - SLOT(do_srvDnd_enable(list))); - connect(selectUserForm, SIGNAL(not_selected(list)), this, - SLOT(do_srvDnd_disable(list))); - - selectUserForm->show(SELECT_DND); -} - -void MphoneForm::do_srvDnd_enable(list user_list) { - ((t_gui *)ui)->srv_dnd(user_list, true); - updateServicesStatus(); -} - -void MphoneForm::do_srvDnd_disable(list user_list) { - ((t_gui *)ui)->srv_dnd(user_list, false); - updateServicesStatus(); -} - -// Enable/disable auto answer when there is 1 user active -void MphoneForm::srvAutoAnswer( bool on ) -{ - ((t_gui *)ui)->srv_auto_answer(phone->ref_users(), on); - updateServicesStatus(); -} - -// Enable/disable auto answer when there are multiple users active -void MphoneForm::srvAutoAnswer() -{ - if (selectUserForm) { - MEMMAN_DELETE(selectUserForm); - delete (selectUserForm); - } - - selectUserForm = new SelectUserForm(this, "auto answer", true); - MEMMAN_NEW(selectUserForm); - - connect(selectUserForm, SIGNAL(selection(list)), this, - SLOT(do_srvAutoAnswer_enable(list))); - connect(selectUserForm, SIGNAL(not_selected(list)), this, - SLOT(do_srvAutoAnswer_disable(list))); - - selectUserForm->show(SELECT_AUTO_ANSWER); -} - -void MphoneForm::do_srvAutoAnswer_enable(list user_list) { - ((t_gui *)ui)->srv_auto_answer(user_list, true); - updateServicesStatus(); -} - -void MphoneForm::do_srvAutoAnswer_disable(list user_list) { - ((t_gui *)ui)->srv_auto_answer(user_list, false); - updateServicesStatus(); -} - -void MphoneForm::srvRedirect() -{ - if (!srvRedirectForm) { - srvRedirectForm = new SrvRedirectForm(this, "call redirection", true); - MEMMAN_NEW(srvRedirectForm); - connect(srvRedirectForm, - SIGNAL(destinations(t_user *, - const list &, - const list &, - const list &)), - this, - SLOT(do_srvRedirect(t_user *, - const list &, - const list &, - const list &))); - } - - srvRedirectForm->show(); -} - -void MphoneForm::do_srvRedirect(t_user *user_config, - const list &always, - const list &busy, - const list &noanswer) -{ - // Redirection always - if (always.empty()) { - ((t_gui *)ui)->srv_disable_cf(user_config, CF_ALWAYS); - } else { - ((t_gui *)ui)->srv_enable_cf(user_config, CF_ALWAYS, always); - } - - // Redirection busy - if (busy.empty()) { - ((t_gui *)ui)->srv_disable_cf(user_config, CF_BUSY); - } else { - ((t_gui *)ui)->srv_enable_cf(user_config, CF_BUSY, busy); - } - - // Redirection no answer - if (noanswer.empty()) { - ((t_gui *)ui)->srv_disable_cf(user_config, CF_NOANSWER); - } else { - ((t_gui *)ui)->srv_enable_cf(user_config, CF_NOANSWER, noanswer); - } - - updateServicesStatus(); -} - - -void MphoneForm::about() -{ - QString s = sys_config->about(true).c_str(); - - QMessageBox mbAbout(PRODUCT_NAME, s.replace(' ', " "), - QMessageBox::Information, - QMessageBox::Ok | QMessageBox::Default, - QMessageBox::NoButton, QMessageBox::NoButton); - mbAbout.setIconPixmap(qPixmapFromMimeSource("twinkle48.png")); - mbAbout.exec(); -} - -void MphoneForm::aboutQt() -{ - QMessageBox::aboutQt(this, PRODUCT_NAME); -} - -void MphoneForm::manual() -{ - ((t_gui *)ui)->open_url_in_browser("http://www.twinklephone.com"); -} - -void MphoneForm::editUserProfile() -{ - if (!userProfileForm) { - userProfileForm = new UserProfileForm(this, "user profile", true); - MEMMAN_NEW(userProfileForm); - - connect(userProfileForm, - SIGNAL(authCredentialsChanged(t_user *, const string&)), - this, - SLOT(updateAuthCache(t_user *, const string&))); - - connect(userProfileForm, - SIGNAL(stunServerChanged(t_user *)), - this, - SLOT(updateStunSettings(t_user *))); - - // MWI settings change triggers an unsubscribe - connect(userProfileForm, - SIGNAL(mwiChangeUnsubscribe(t_user *)), - this, - SLOT(unsubscribeMWI(t_user *))); - - // MWI settings change triggers a subscribe - connect(userProfileForm, - SIGNAL(mwiChangeSubscribe(t_user *)), - this, - SLOT(subscribeMWI(t_user *))); - } - - userProfileForm->show(phone->ref_users(), - userComboBox->currentText()); -} - -void MphoneForm::editSysSettings() -{ - if (!sysSettingsForm) { - sysSettingsForm = new SysSettingsForm(this, "system settings", true); - MEMMAN_NEW(sysSettingsForm); - connect(sysSettingsForm, SIGNAL(sipUdpPortChanged()), - this, SLOT(updateSipUdpPort())); - connect(sysSettingsForm, SIGNAL(rtpPortChanged()), - this, SLOT(updateRtpPorts())); - } - - sysSettingsForm->show(); -} - -void MphoneForm::selectProfile() -{ - if (!selectProfileForm) { - selectProfileForm = new SelectProfileForm(this, "select profile", true); - MEMMAN_NEW(selectProfileForm); - connect(selectProfileForm, SIGNAL(selection(const list &)), - this, SLOT(newUsers(const list &))); - connect(selectProfileForm, SIGNAL(profileRenamed()), - this, SLOT(updateUserComboBox())); - connect(selectProfileForm, SIGNAL(profileRenamed()), - this, SLOT(populateBuddyList())); - } - - selectProfileForm->showForm(this); -} - -// A new set of users has been selected. -// Remove users from the current user set that are not in the selection. -// Add users from the selection that are not in the current set of users. -void MphoneForm::newUsers(const list &profiles) -{ - string error_msg; - - // NOTE: First users must be removed. It could be that a - // user profile of an active was renamed. In this case, the user - // with the old profile name is first removed and then added again. - - list user_list = phone->ref_users(); - - // Remove current users that are not selected anymore. - for (list::iterator i = user_list.begin(); i != user_list.end(); i++) { - if (std::find(profiles.begin(), profiles.end(), - (*i)->get_filename().c_str()) == profiles.end()) - { - // User is not selected anymore. - // Unsubscribe MWI - if (phone->is_mwi_subscribed(*i)) { - phone->pub_unsubscribe_mwi(*i); - } - - // Unpublish presence of user - phone->pub_unpublish_presence(*i); - - // Unsubscribe presence - phone->pub_unsubscribe_presence(*i); - - // Deregister user - if (phone->get_is_registered(*i)) { - phone->pub_registration(*i, REG_DEREGISTER); - } - - log_file->write_header("MphoneForm::newUsers"); - log_file->write_raw("Stop user profile: "); - log_file->write_raw((*i)->get_profile_name()); - log_file->write_endl(); - log_file->write_footer(); - phone->remove_phone_user(*(*i)); - } - } - - // Determine which users to add - list add_profile_list; - for (list::const_iterator i = profiles.begin(); i != profiles.end(); i++) { - QString profile = (*i).c_str(); - // Strip off the .cfg extension - profile.truncate(profile.length() - 4); - - if (!phone->ref_user_profile(profile.ascii())) { - add_profile_list.push_back(*i); - } - } - - // Add new phone users - Q3ProgressDialog progress(tr("Starting user profiles..."), "Abort", add_profile_list.size(), this, - "starting user profiles", true); - progress.setCaption(PRODUCT_NAME); - progress.setMinimumDuration(200); - int progressStep = 0; - for (list::iterator i = add_profile_list.begin(); i != add_profile_list.end(); i++) { - progress.setProgress(progressStep); - qApp->processEvents(); - - if (progress.wasCancelled()) { - log_file->write_report("User aborted startup of new users.", - "MphoneForm::newUsers"); - break; - } - - t_user user_config; - - // Read user configuration - if (user_config.read_config(*i, error_msg)) { - t_user *dup_user; - - log_file->write_header("MphoneForm::newUsers"); - log_file->write_raw("Run user profile: "); - log_file->write_raw(user_config.get_profile_name()); - log_file->write_endl(); - log_file->write_footer(); - - if (phone->add_phone_user(user_config, &dup_user)) - { - // NAT discovery - if (!phone->stun_discover_nat(&user_config, error_msg)) - { - // Warn user that the STUN settings will not work. - ((t_gui *)ui)->cb_show_msg(this, error_msg, - MSG_WARNING); - } - - // Register at startup - if (user_config.get_register_at_startup()) { - phone->pub_registration(&user_config, - REG_REGISTER, - DUR_REGISTRATION(&user_config)); - } else { - // No registration needed, initialize extensions now. - phone->init_extensions(&user_config); - } - - // Extension initialization will be done after - // registration succeeded. - } else { - error_msg = tr("The following profiles are both for user %1").arg(user_config.get_name().c_str()).ascii(); - error_msg += '@'; - error_msg += user_config.get_domain(); - error_msg += ":\n\n"; - error_msg += user_config.get_profile_name(); - error_msg += "\n"; - error_msg += dup_user->get_profile_name(); - error_msg += "\n\n"; - error_msg += tr("You can only run multiple profiles for different users.").ascii(); - - log_file->write_report(error_msg, - "MphoneForm::newUsers", - LOG_NORMAL, LOG_WARNING); - ui->cb_display_msg(error_msg, MSG_WARNING); - } - } else { - log_file->write_report(error_msg, - "MphoneForm::newUsers", - LOG_NORMAL, LOG_CRITICAL); - ui->cb_display_msg(error_msg, MSG_CRITICAL); - } - - progressStep++; - } - progress.setProgress(add_profile_list.size()); - - populateBuddyList(); - updateUserComboBox(); - updateRegStatus(); - updateMwi(); - updateServicesStatus(); - updateSysTrayStatus(); - updateMenuStatus(); - updateState(); - - call_history->clear_num_missed_calls(); -} - -void MphoneForm::updateUserComboBox() -{ - QString current_user; - - if (userComboBox->count() == 0) { - // The last used profile - current_user = sys_config->get_last_used_profile().c_str(); - } else { - // Keep the current active profile - current_user = userComboBox->currentText(); - } - - ((t_gui *)ui)->fill_user_combo(userComboBox); - - // If previous selected user is still active, make it the current user - for (int i = 0; i < userComboBox->count(); i++) { - if (userComboBox->text(i) == current_user) { - userComboBox->setCurrentItem(i); - } - } -} - -void MphoneForm::updateSipUdpPort() -{ - ((t_gui *)ui)->cb_show_msg(sysSettingsForm, - tr("You have changed the SIP UDP port. This setting will only become "\ - "active when you restart Twinkle.").ascii(), - MSG_INFO); -} - -void MphoneForm::updateRtpPorts() -{ - phone->init_rtp_ports(); -} - -void MphoneForm::updateStunSettings(t_user *user_config) -{ - string s; - if (!phone->stun_discover_nat(user_config, s)) { - // Warn user that the STUN settings will not work. - ((t_gui *)ui)->cb_show_msg(this, s, MSG_WARNING); - } - - if (!user_config->get_use_stun()) { - // Disable STUN - phone->disable_stun(user_config); - } - - // Synchronize the sending of NAT keep alives with the user profile settings. - phone->sync_nat_keepalive(user_config); -} - -void MphoneForm::updateAuthCache(t_user *user_config, const string &realm) -{ - phone->remove_cached_credentials(user_config, realm); -} - -void MphoneForm::unsubscribeMWI(t_user *user_config) -{ - phone->pub_unsubscribe_mwi(user_config); -} - -void MphoneForm::subscribeMWI(t_user *user_config) -{ - phone->pub_subscribe_mwi(user_config); -} - -void MphoneForm::viewLog() -{ - if (!logViewForm) { - logViewForm = new LogViewForm(NULL); - MEMMAN_NEW(logViewForm); - } - - logViewForm->show(); -} - -void MphoneForm::updateLog(bool log_zapped) -{ - if (logViewForm) logViewForm->update(log_zapped); -} - -void MphoneForm::viewHistory() -{ - if (!historyForm) { - historyForm = new HistoryForm(NULL); - MEMMAN_NEW(historyForm); - } - - connect(historyForm, - SIGNAL(call(t_user *, const QString &, const QString &, bool)), this, - SLOT(phoneInvite(t_user *, const QString &, const QString &, bool))); - - historyForm->show(); -} - -void MphoneForm::updateCallHistory() -{ - if (historyForm) historyForm->update(); -} - -t_twinkle_sys_tray *MphoneForm::getSysTray() -{ - return sysTray; -} - -// Execute call directly from the main window (press call button) -void MphoneForm::quickCall() -{ - string display, dest_str; - - t_user *from_user = phone->ref_user_profile( - userComboBox->currentText().ascii()); - if (!from_user) { - log_file->write_report("Cannot find user profile.", - "MphoneForm::quickCall", - LOG_NORMAL, LOG_CRITICAL); - return; - } - - ui->expand_destination(from_user, - callComboBox->currentText().stripWhiteSpace().ascii(), - display, dest_str); - t_url dest(dest_str); - - if (dest.is_valid()) { - QString destination = callComboBox->currentText(); - addToCallComboBox(destination); - if (inviteForm) inviteForm->addToInviteComboBox(destination); - callComboBox->setFocus(); - do_phoneInvite(from_user, display.c_str(), dest, "", false); - } -} - -// Add a destination to the list of callComboBox -void MphoneForm::addToCallComboBox(const QString &destination) -{ - // Remove duplicate entries - for (int i = callComboBox->count() - 1; i >= 0; i--) { - if (callComboBox->text(i) == destination) { - callComboBox->removeItem(i); - } - } - - // Add entry - callComboBox->insertItem(destination, 0); - callComboBox->setCurrentItem(0); - - // Remove last entry is list exceeds maximum size - if (callComboBox->count() > SIZE_REDIAL_LIST) { - callComboBox->removeItem(callComboBox->count() - 1); - } - - // Clearing the edit line must be done here as this function is - // also called when a call is made through the inviteForm. - // The insertItem puts the text also in the edit field. So it must - // be cleared here. - callComboBox->clearEdit(); -} - -void MphoneForm::showAddressBook() -{ - if (!getAddressForm) { - getAddressForm = new GetAddressForm( - this, "select address", true); - MEMMAN_NEW(getAddressForm); - } - - connect(getAddressForm, - SIGNAL(address(const QString &)), - this, SLOT(selectedAddress(const QString &))); - - getAddressForm->show(); -} - -void MphoneForm::selectedAddress(const QString &address) -{ - callComboBox->setEditText(address); -} - -// Enable/disable the various call widgets -void MphoneForm::enableCallOptions(bool enable) -{ - // Enable/disable widgets - callInvite->setEnabled(enable); - callPushButton->setEnabled(enable); - callComboBox->setEnabled(enable); - addressToolButton->setEnabled(enable); - - // Set focus on callComboBox - if (enable) { - callComboBox->setFocus(); - } -} - -void MphoneForm::keyPressEvent(QKeyEvent *e) -{ - if (callPushButton->isEnabled()) { - // Quick dial - switch (e->key()) { - case Qt::Key_Return: - case Qt::Key_Enter: - quickCall(); - break; - default: - e->ignore(); - } - } else if (callDTMF->isEnabled()) { - // DTMF keys - switch (e->key()) { - case Qt::Key_1: - sendDTMF("1"); - break; - case Qt::Key_2: - case Qt::Key_A: - case Qt::Key_B: - case Qt::Key_C: - sendDTMF("2"); - break; - case Qt::Key_3: - case Qt::Key_D: - case Qt::Key_E: - case Qt::Key_F: - sendDTMF("3"); - break; - case Qt::Key_4: - case Qt::Key_G: - case Qt::Key_H: - case Qt::Key_I: - sendDTMF("4"); - break; - case Qt::Key_5: - case Qt::Key_J: - case Qt::Key_K: - case Qt::Key_L: - sendDTMF("5"); - break; - case Qt::Key_6: - case Qt::Key_M: - case Qt::Key_N: - case Qt::Key_O: - sendDTMF("6"); - break; - case Qt::Key_7: - case Qt::Key_P: - case Qt::Key_Q: - case Qt::Key_R: - case Qt::Key_S: - sendDTMF("7"); - break; - case Qt::Key_8: - case Qt::Key_T: - case Qt::Key_U: - case Qt::Key_V: - sendDTMF("8"); - break; - case Qt::Key_9: - case Qt::Key_W: - case Qt::Key_X: - case Qt::Key_Y: - case Qt::Key_Z: - sendDTMF("9"); - break; - case Qt::Key_0: - case Qt::Key_Space: - sendDTMF("0"); - break; - case Qt::Key_Asterisk: - sendDTMF("*"); - break; - case Qt::Key_NumberSign: - sendDTMF("#"); - break; - default: - e->ignore(); - } - } else { - e->ignore(); - } -} - -// QLabels do not have mouse click events. I want the status labels -// to be clickable however. Explicitly check here if a status label has -// been clicked. -void MphoneForm::mouseReleaseEvent(QMouseEvent *e) -{ - if (e->button() == Qt::LeftButton && e->type() == QEvent::MouseButtonRelease) { - processLeftMouseButtonRelease(e); - } else if (e->button() == Qt::RightButton && e->type() == QEvent::MouseButtonRelease) { - processRightMouseButtonRelease(e); - } else { - e->ignore(); - } -} - -void MphoneForm::processLeftMouseButtonRelease(QMouseEvent *e) -{ - if (statAaLabel->hasMouse()) { - if (phone->ref_users().size() == 1) { - bool enable = !serviceAutoAnswer->isOn(); - srvAutoAnswer(enable); - serviceAutoAnswer->setOn(enable); - } else { - srvAutoAnswer(); - } - } else if (statDndLabel->hasMouse()) { - if (phone->ref_users().size() == 1) { - bool enable = !serviceDnd->isOn(); - srvDnd(enable); - serviceDnd->setOn(enable); - } else { - srvDnd(); - } - } else if (statCfLabel->hasMouse()) { - srvRedirect(); - } else if (statMWILabel->hasMouse()) { - popupMenuVoiceMail(e->globalPos()); - } else if (statMissedLabel->hasMouse()) { - // Open the history form, when the user clicks on the - // missed calls indication. - viewHistory(); - } else if (statRegLabel->hasMouse()) { - // Fetch registration status - phoneShowRegistrations(); - } else if (crypt1Label->hasMouse()) { - processCryptLabelClick(0); - } else if (crypt2Label->hasMouse()) { - processCryptLabelClick(1); - } else { - e->ignore(); - } -} - -void MphoneForm::processRightMouseButtonRelease(QMouseEvent *e) -{ - e->ignore(); -} - -void MphoneForm::processCryptLabelClick(int line) -{ - t_audio_session *as = phone->get_line(line)->get_audio_session(); - if (!as) return; - - if (as->get_zrtp_sas_confirmed()) { - phoneResetZrtpSasConfirmation(line); - } else { - phoneConfirmZrtpSas(line); - } -} - -// Show popup menu to access voice mail -void MphoneForm::popupMenuVoiceMail(const QPoint &pos) -{ - Q3PopupMenu menu(this); - QIcon vmIcon(qPixmapFromMimeSource("mwi_none16.png")); - vmIcon.setPixmap(qPixmapFromMimeSource("mwi_none16_dis.png"), - QIcon::Automatic, QIcon::Disabled); - - listuser_list = phone->ref_users(); - map vm; - for (list::iterator i = user_list.begin(); i != user_list.end(); ++i) { - QString address = (*i)->get_mwi_vm_address().c_str(); - QString entry = (*i)->get_profile_name().c_str(); - entry += " - "; - if (address.isEmpty()) { - entry += tr("not provisioned"); - } else { - entry += address; - } - - int id = menu.insertItem(vmIcon, entry); - if (address.isEmpty()) { - menu.setItemEnabled(id, false); - } - - vm.insert(make_pair(id, *i)); - } - - int selected; - - // If multiple profiles are active, then show the popup menu. - // If one profile is active, then call voice mail immediately. - if (user_list.size() > 1) { - selected = menu.exec(pos); - if (selected == -1) return; - } else { - if (vm.begin()->second->get_mwi_vm_address().empty()) { - ui->cb_show_msg( - tr("You must provision your voice mail address in your " - "user profile, before you can access it.").ascii(), - MSG_INFO); - return; - } - selected = vm.begin()->first; - } - - // Call can only be made if line is idle - int line = phone->get_active_line(); - if (phone->get_line_state(line) == LS_BUSY) { - ui->cb_show_msg(tr("The line is busy. Cannot access voice mail.").ascii(), - MSG_WARNING); - return; - } - - t_user *selectedUser = vm[selected]; - string display, dest_str; - ui->expand_destination(selectedUser, - selectedUser->get_mwi_vm_address(), - display, dest_str); - t_url dest(dest_str); - - if (dest.is_valid()) { - QString destination = selectedUser->get_mwi_vm_address().c_str(); - addToCallComboBox(destination); - if (inviteForm) inviteForm->addToInviteComboBox(destination); - callComboBox->setFocus(); - do_phoneInvite(selectedUser, display.c_str(), dest, "", false); - } else { - QString msg(tr("The voice mail address %1 is an invalid address. " - "Please provision a valid address in your user profile.")); - ui->cb_show_msg(msg.arg(selectedUser->get_mwi_vm_address().c_str()).ascii(), - MSG_CRITICAL); - } -} - -void MphoneForm::popupMenuVoiceMail(void) -{ - popupMenuVoiceMail(QCursor::pos()); -} - -void MphoneForm::showDisplay(bool on) -{ - if (on) { - displayGroupBox->show(); - } else { - int hDisplay = displayGroupBox->height(); - displayGroupBox->hide(); - - if (hDisplay < minimumHeight()) { - setMinimumHeight(minimumHeight() - hDisplay); - } - resize(width(), minimumHeight()); - } - - viewDisplay = on; - viewDisplayAction->setOn(on); -} - -void MphoneForm::showBuddyList(bool on) -{ - if (on) { - buddyListView->show(); - } else { - buddyListView->hide(); - } - - viewBuddyList = on; - viewBuddyListAction->setOn(on); -} - -void MphoneForm::showCompactLineStatus(bool on) -{ - if (on) { - int hLabels = fromhead1Label->height() + - tohead1Label->height() + - subjecthead1Label->height() + - fromhead2Label->height() + - tohead2Label->height() + - subjecthead2Label->height(); - - fromhead1Label->hide(); - tohead1Label->hide(); - subjecthead1Label->hide(); - from1Label->hide(); - to1Label->hide(); - subject1Label->hide(); - photo1Label->hide(); - fromhead2Label->hide(); - tohead2Label->hide(); - subjecthead2Label->hide(); - from2Label->hide(); - to2Label->hide(); - subject2Label->hide(); - photo2Label->hide(); - - if (hLabels < minimumHeight()) { - setMinimumHeight(minimumHeight() - hLabels); - } - resize(width(), minimumHeight()); - } else { - fromhead1Label->show(); - tohead1Label->show(); - subjecthead1Label->show(); - from1Label->show(); - to1Label->show(); - subject1Label->show(); - fromhead2Label->show(); - tohead2Label->show(); - subjecthead2Label->show(); - from2Label->show(); - to2Label->show(); - subject2Label->show(); - } - - viewCompactLineStatus = on; - //viewCompactLineStatusAction->setOn(on); -} - -bool MphoneForm::getViewDisplay() -{ - return viewDisplay; -} - -bool MphoneForm::getViewBuddyList() -{ - return viewBuddyList; -} - -bool MphoneForm::getViewCompactLineStatus() -{ - return viewCompactLineStatus; -} - -void MphoneForm::populateBuddyList() -{ - buddyListView->clear(); - - list user_list = phone->ref_users(); - for (list::iterator i = user_list.begin(); i != user_list.end(); ++i) { - t_presence_epa *epa = phone->ref_presence_epa(*i); - if (!epa) continue; - - BLViewUserItem *profileItem = new BLViewUserItem(buddyListView, epa); - t_buddy_list *buddy_list = phone->ref_buddy_list(*i); - - list *buddies = buddy_list->get_records(); - for (list::iterator bit = buddies->begin(); bit != buddies->end(); ++bit) { - QString name = bit->get_name().c_str(); - new BuddyListViewItem(profileItem, &(*bit)); - } - - profileItem->setOpen(true); - } -} - -void MphoneForm::showBuddyListPopupMenu(Q3ListViewItem *item, const QPoint &pos) -{ - if (!item) return; - - BuddyListViewItem *buddyItem = dynamic_cast(item); - if (buddyItem) { - buddyPopupMenu->popup(pos); - } else { - buddyListPopupMenu->popup(pos); - } -} - -void MphoneForm::doCallBuddy() -{ - Q3ListViewItem *qitem = buddyListView->currentItem(); - BuddyListViewItem *item = dynamic_cast(qitem); - if (!item) return; - - t_buddy *buddy = item->get_buddy(); - t_user *user_config = buddy->get_user_profile(); - - phoneInvite(user_config, buddy->get_sip_address().c_str(), "", false); -} - -void MphoneForm::doMessageBuddy(Q3ListViewItem *qitem) -{ - BuddyListViewItem *item = dynamic_cast(qitem); - if (!item) return; - - t_buddy *buddy = item->get_buddy(); - - startMessageSession(buddy); -} - -void MphoneForm::doMessageBuddy() -{ - Q3ListViewItem *item = buddyListView->currentItem(); - doMessageBuddy(item); -} - -void MphoneForm::doEditBuddy() -{ - Q3ListViewItem *qitem = buddyListView->currentItem(); - BuddyListViewItem *item = dynamic_cast(qitem); - if (!item) return; - - t_buddy *buddy = item->get_buddy(); - - BuddyForm *form = new BuddyForm(this, "new_buddy", true, Qt::WDestructiveClose); - // Do not call MEMMAN as this form will be deleted automatically. - form->showEdit(*buddy); -} - -void MphoneForm::doDeleteBuddy() -{ - Q3ListViewItem *qitem = buddyListView->currentItem(); - BuddyListViewItem *item = dynamic_cast(qitem); - if (!item) return; - - t_buddy *buddy = item->get_buddy(); - t_buddy_list *buddy_list = buddy->get_buddy_list(); - - // Delete the list item before deleting the buddy as - // deleting the item will detach the item from the buddy. - delete item; - - if (buddy->is_presence_terminated()) { - buddy_list->del_buddy(*buddy); - } else { - buddy->unsubscribe_presence(true); - } - - string err_msg; - if (!buddy_list->save(err_msg)) { - QString msg = tr("Failed to save buddy list: %1").arg(err_msg.c_str()); - ((t_gui *)ui)->cb_show_msg(this, msg.ascii(), MSG_CRITICAL); - } -} - -void MphoneForm::doAddBuddy() -{ - Q3ListViewItem *qitem = buddyListView->currentItem(); - BLViewUserItem *item = dynamic_cast(qitem); - if (!item) return; - - t_phone_user *pu = item->get_presence_epa()->get_phone_user(); - if (!pu) return; - t_buddy_list *buddy_list = pu->get_buddy_list(); - if (!buddy_list) return; - - BuddyForm *form = new BuddyForm(this, "new_buddy", true, Qt::WDestructiveClose); - // Do not call MEMMAN as this form will be deleted automatically. - form->showNew(*buddy_list, item); -} - -void MphoneForm::doAvailabilityOffline() -{ - Q3ListViewItem *qitem = buddyListView->currentItem(); - BLViewUserItem *item = dynamic_cast(qitem); - if (!item) return; - - t_phone_user *pu = item->get_presence_epa()->get_phone_user(); - if (!pu) return; - - pu->publish_presence(t_presence_state::ST_BASIC_CLOSED); -} - -void MphoneForm::doAvailabilityOnline() -{ - Q3ListViewItem *qitem = buddyListView->currentItem(); - BLViewUserItem *item = dynamic_cast(qitem); - if (!item) return; - - t_phone_user *pu = item->get_presence_epa()->get_phone_user(); - if (!pu) return; - - pu->publish_presence(t_presence_state::ST_BASIC_OPEN); -} - -void MphoneForm::DiamondcardSignUp() -{ - DiamondcardProfileForm *f = new DiamondcardProfileForm(this, "select profile", true, - Qt::WDestructiveClose); - - connect(f, SIGNAL(newDiamondcardProfile(const QString&)), - this, SLOT(newDiamondcardUser(const QString &))); - - f->show(NULL); -} - -void MphoneForm::newDiamondcardUser(const QString &filename) -{ - list profileFilenames; - list users = phone->ref_users(); - - for (list::const_iterator it = users.begin(); it != users.end(); ++it) { - t_user *user = *it; - profileFilenames.push_back(user->get_filename()); - } - - profileFilenames.push_back(filename.ascii()); - newUsers(profileFilenames); -} - -void MphoneForm::DiamondcardAction(t_dc_action action, int userIdx) -{ - list diamondcard_users = diamondcard_get_users(phone); - vector v(diamondcard_users.begin(), diamondcard_users.end()); - - if (userIdx < 0 || (unsigned int)userIdx >= v.size()) return; - - t_user *user = v[userIdx]; - QString url(diamondcard_url(action, user->get_name(), user->get_auth_pass()).c_str()); - ((t_gui *)ui)->open_url_in_browser(url); -} - -void MphoneForm::DiamondcardRecharge(int userIdx) -{ - DiamondcardAction(DC_ACT_RECHARGE, userIdx); -} - -void MphoneForm::DiamondcardBalanceHistory(int userIdx) -{ - DiamondcardAction(DC_ACT_BALANCE_HISTORY, userIdx); -} - -void MphoneForm::DiamondcardCallHistory(int userIdx) -{ - DiamondcardAction(DC_ACT_CALL_HISTORY, userIdx); -} - -void MphoneForm::DiamondcardAdminCenter(int userIdx) -{ - DiamondcardAction(DC_ACT_ADMIN_CENTER, userIdx); -} diff --git a/src/gui/redirectform.cpp b/src/gui/redirectform.cpp new file mode 100644 index 0000000..7f47eb5 --- /dev/null +++ b/src/gui/redirectform.cpp @@ -0,0 +1,177 @@ +#include "redirectform.h" +//Added by qt3to4: +#include + +/* + Copyright (C) 2005-2009 Michel de Boer + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "audits/memman.h" +#include "gui.h" + +RedirectForm::RedirectForm(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl) + : QDialog(parent, name, modal, fl) +{ + setupUi(this); + init(); +} + +RedirectForm::~RedirectForm() +{ + destroy(); +} + +/* + * Sets the strings of the subwidgets using the current + * language. + */ +void RedirectForm::languageChange() +{ + retranslateUi(this); +} + +void RedirectForm::init() +{ + // Keeps track of which address book tool button is clicked. + nrAddressBook = 0; + + getAddressForm = 0; + + // Set toolbutton icons for disabled options. + QIcon i; + i = address1ToolButton->iconSet(); + i.setPixmap(QPixmap(":/icons/images/kontact_contacts-disabled.png"), + QIcon::Automatic, QIcon::Disabled); + address1ToolButton->setIconSet(i); + address2ToolButton->setIconSet(i); + address3ToolButton->setIconSet(i); +} + +void RedirectForm::destroy() +{ + if (getAddressForm) { + MEMMAN_DELETE(getAddressForm); + delete getAddressForm; + } +} + +void RedirectForm::show(t_user *user, const list &contacts) +{ + user_config = user; + + int num = 0; + for (list::const_iterator i = contacts.begin(); + i != contacts.end(); i++, num++) + { + if (num == 0) contact1LineEdit->setText(i->c_str()); + if (num == 1) contact2LineEdit->setText(i->c_str()); + if (num == 2) contact3LineEdit->setText(i->c_str()); + } + + QDialog::show(); +} + +void RedirectForm::validate() +{ + t_display_url destination; + list dest_list; + + // 1st choice destination + ui->expand_destination(user_config, contact1LineEdit->text().stripWhiteSpace().ascii(), + destination); + if (destination.is_valid()) { + dest_list.push_back(destination); + } else { + contact1LineEdit->selectAll(); + return; + } + + // 2nd choice destination + if (!contact2LineEdit->text().isEmpty()) { + ui->expand_destination(user_config, + contact2LineEdit->text().stripWhiteSpace().ascii(), destination); + if (destination.is_valid()) { + dest_list.push_back(destination); + } else { + contact2LineEdit->selectAll(); + return; + } + } + + // 3rd choice destination + if (!contact3LineEdit->text().isEmpty()) { + ui->expand_destination(user_config, + contact3LineEdit->text().stripWhiteSpace().ascii(), destination); + if (destination.is_valid()) { + dest_list.push_back(destination); + } else { + contact3LineEdit->selectAll(); + return; + } + } + + emit destinations(dest_list); + accept(); +} + +void RedirectForm::showAddressBook() +{ + if (!getAddressForm) { + getAddressForm = new GetAddressForm( + this, "select address", true); + MEMMAN_NEW(getAddressForm); + } + + connect(getAddressForm, + SIGNAL(address(const QString &)), + this, SLOT(selectedAddress(const QString &))); + + getAddressForm->show(); +} + +void RedirectForm::showAddressBook1() +{ + nrAddressBook = 1; + showAddressBook(); +} + +void RedirectForm::showAddressBook2() +{ + nrAddressBook = 2; + showAddressBook(); +} + +void RedirectForm::showAddressBook3() +{ + nrAddressBook = 3; + showAddressBook(); +} + +void RedirectForm::selectedAddress(const QString &address) +{ + switch(nrAddressBook) { + case 1: + contact1LineEdit->setText(address); + break; + case 2: + contact2LineEdit->setText(address); + break; + case 3: + contact3LineEdit->setText(address); + break; + } +} diff --git a/src/gui/redirectform.h b/src/gui/redirectform.h new file mode 100644 index 0000000..583e4ff --- /dev/null +++ b/src/gui/redirectform.h @@ -0,0 +1,58 @@ +#ifndef REDIRECTFORM_UI_H +#define REDIRECTFORM_UI_H +#include "ui_redirectform.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "getaddressform.h" +#include "sockets/url.h" +#include "user.h" + + +class RedirectForm : public QDialog, public Ui::RedirectForm +{ + Q_OBJECT + +public: + RedirectForm(QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WindowFlags fl = 0); + ~RedirectForm(); + +public slots: + virtual void show( t_user * user, const list & contacts ); + virtual void validate(); + virtual void showAddressBook(); + virtual void showAddressBook1(); + virtual void showAddressBook2(); + virtual void showAddressBook3(); + virtual void selectedAddress( const QString & address ); + +signals: + void destinations(const list &); + +protected slots: + virtual void languageChange(); + +private: + GetAddressForm *getAddressForm; + int nrAddressBook; + t_user *user_config; + + void init(); + void destroy(); + +}; + + +#endif diff --git a/src/gui/redirectform.ui b/src/gui/redirectform.ui index b0c5311..2f5f619 100644 --- a/src/gui/redirectform.ui +++ b/src/gui/redirectform.ui @@ -103,7 +103,7 @@ F10
- kontact_contacts.png + :/icons/images/kontact_contacts.png Address book @@ -125,7 +125,7 @@ F12 - kontact_contacts.png + :/icons/images/kontact_contacts.png Address book @@ -147,7 +147,7 @@ F11 - kontact_contacts.png + :/icons/images/kontact_contacts.png Address book diff --git a/src/gui/redirectform.ui.h b/src/gui/redirectform.ui.h deleted file mode 100644 index d787dbf..0000000 --- a/src/gui/redirectform.ui.h +++ /dev/null @@ -1,159 +0,0 @@ -//Added by qt3to4: -#include -/**************************************************************************** -** ui.h extension file, included from the uic-generated form implementation. -** -** If you wish to add, delete or rename functions or slots use -** Qt Designer which will update this file, preserving your code. Create an -** init() function in place of a constructor, and a destroy() function in -** place of a destructor. -*****************************************************************************/ -/* - Copyright (C) 2005-2009 Michel de Boer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -void RedirectForm::init() -{ - // Keeps track of which address book tool button is clicked. - nrAddressBook = 0; - - getAddressForm = 0; - - // Set toolbutton icons for disabled options. - QIcon i; - i = address1ToolButton->iconSet(); - i.setPixmap(qPixmapFromMimeSource("kontact_contacts-disabled.png"), - QIcon::Automatic, QIcon::Disabled); - address1ToolButton->setIconSet(i); - address2ToolButton->setIconSet(i); - address3ToolButton->setIconSet(i); -} - -void RedirectForm::destroy() -{ - if (getAddressForm) { - MEMMAN_DELETE(getAddressForm); - delete getAddressForm; - } -} - -void RedirectForm::show(t_user *user, const list &contacts) -{ - user_config = user; - - int num = 0; - for (list::const_iterator i = contacts.begin(); - i != contacts.end(); i++, num++) - { - if (num == 0) contact1LineEdit->setText(i->c_str()); - if (num == 1) contact2LineEdit->setText(i->c_str()); - if (num == 2) contact3LineEdit->setText(i->c_str()); - } - - QDialog::show(); -} - -void RedirectForm::validate() -{ - t_display_url destination; - list dest_list; - - // 1st choice destination - ui->expand_destination(user_config, contact1LineEdit->text().stripWhiteSpace().ascii(), - destination); - if (destination.is_valid()) { - dest_list.push_back(destination); - } else { - contact1LineEdit->selectAll(); - return; - } - - // 2nd choice destination - if (!contact2LineEdit->text().isEmpty()) { - ui->expand_destination(user_config, - contact2LineEdit->text().stripWhiteSpace().ascii(), destination); - if (destination.is_valid()) { - dest_list.push_back(destination); - } else { - contact2LineEdit->selectAll(); - return; - } - } - - // 3rd choice destination - if (!contact3LineEdit->text().isEmpty()) { - ui->expand_destination(user_config, - contact3LineEdit->text().stripWhiteSpace().ascii(), destination); - if (destination.is_valid()) { - dest_list.push_back(destination); - } else { - contact3LineEdit->selectAll(); - return; - } - } - - emit destinations(dest_list); - accept(); -} - -void RedirectForm::showAddressBook() -{ - if (!getAddressForm) { - getAddressForm = new GetAddressForm( - this, "select address", true); - MEMMAN_NEW(getAddressForm); - } - - connect(getAddressForm, - SIGNAL(address(const QString &)), - this, SLOT(selectedAddress(const QString &))); - - getAddressForm->show(); -} - -void RedirectForm::showAddressBook1() -{ - nrAddressBook = 1; - showAddressBook(); -} - -void RedirectForm::showAddressBook2() -{ - nrAddressBook = 2; - showAddressBook(); -} - -void RedirectForm::showAddressBook3() -{ - nrAddressBook = 3; - showAddressBook(); -} - -void RedirectForm::selectedAddress(const QString &address) -{ - switch(nrAddressBook) { - case 1: - contact1LineEdit->setText(address); - break; - case 2: - contact2LineEdit->setText(address); - break; - case 3: - contact3LineEdit->setText(address); - break; - } -} diff --git a/src/gui/selectnicform.cpp b/src/gui/selectnicform.cpp new file mode 100644 index 0000000..735542b --- /dev/null +++ b/src/gui/selectnicform.cpp @@ -0,0 +1,120 @@ +//Added by qt3to4: +#include +/* + Copyright (C) 2005-2009 Michel de Boer + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "gui.h" +#include +#include "sys_settings.h" +#include "selectnicform.h" +/* + * Constructs a SelectNicForm as a child of 'parent', with the + * name 'name' and widget flags set to 'f'. + * + * The dialog will by default be modeless, unless you set 'modal' to + * true to construct a modal dialog. + */ +SelectNicForm::SelectNicForm(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl) + : QDialog(parent, name, modal, fl) +{ + setupUi(this); + + init(); +} + +/* + * Destroys the object and frees any allocated resources + */ +SelectNicForm::~SelectNicForm() +{ + // no need to delete child widgets, Qt does it all for us +} + +/* + * Sets the strings of the subwidgets using the current + * language. + */ +void SelectNicForm::languageChange() +{ + retranslateUi(this); +} + + +void SelectNicForm::init() +{ + idxDefault = -1; +} + +void SelectNicForm::setAsDefault(bool setIp) +{ +#if 0 + // DEPRECATED + // Only show the information when the default button is + // pressed for the first time. + if (idxDefault == -1) { + QMessageBox::information(this, PRODUCT_NAME, tr( + "If you want to remove or " + "change the default at a later time, you can do that " + "via the system settings.")); + } + + // Store current index as the changeItem method also changes + // the current index as a side effect. + int idxNewDefault = nicListBox->currentItem(); + + // Restore pixmap of the old default + if (idxDefault != -1) { + nicListBox->changeItem( + QPixmap(":/icons/images/kcmpci16.png"), + nicListBox->text(idxDefault), + idxDefault); + } + + // Set pixmap of the default + idxDefault = idxNewDefault; + nicListBox->changeItem( + QPixmap(":/icons/images/twinkle16.png"), + nicListBox->text(idxDefault), + idxDefault); + + // Write default to system settings + int pos = nicListBox->currentText().findRev(':'); + if (setIp) { + sys_config->set_start_user_host(nicListBox->currentText().mid(pos + 1).ascii()); + sys_config->set_start_user_nic(""); + } else { + sys_config->set_start_user_nic(nicListBox->currentText().left(pos).ascii()); + sys_config->set_start_user_host(""); + } + string error_msg; + if (!sys_config->write_config(error_msg)) { + // Failed to write config file + ((t_gui *)ui)->cb_show_msg(this, error_msg, MSG_CRITICAL); + } +#endif +} + +void SelectNicForm::setAsDefaultIp() +{ + setAsDefault(true); +} + +void SelectNicForm::setAsDefaultNic() +{ + setAsDefault(false); +} diff --git a/src/gui/selectnicform.h b/src/gui/selectnicform.h new file mode 100644 index 0000000..f926ed3 --- /dev/null +++ b/src/gui/selectnicform.h @@ -0,0 +1,30 @@ +#ifndef SELECTNICFORM_H +#define SELECTNICFORM_H +#include +#include "ui_selectnicform.h" + +class SelectNicForm : public QDialog, public Ui::SelectNicForm +{ + Q_OBJECT + +public: + SelectNicForm(QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WindowFlags fl = 0); + ~SelectNicForm(); + +public slots: + virtual void setAsDefault( bool setIp ); + virtual void setAsDefaultIp(); + virtual void setAsDefaultNic(); + +protected slots: + virtual void languageChange(); + +private: + int idxDefault; + + void init(); + +}; + + +#endif diff --git a/src/gui/selectnicform.ui b/src/gui/selectnicform.ui index c6aee9b..d915d44 100644 --- a/src/gui/selectnicform.ui +++ b/src/gui/selectnicform.ui @@ -23,7 +23,7 @@ - kcmpci.png + :/icons/images/kcmpci.png false diff --git a/src/gui/selectnicform.ui.h b/src/gui/selectnicform.ui.h deleted file mode 100644 index 020a0ce..0000000 --- a/src/gui/selectnicform.ui.h +++ /dev/null @@ -1,91 +0,0 @@ -//Added by qt3to4: -#include -/**************************************************************************** -** ui.h extension file, included from the uic-generated form implementation. -** -** If you wish to add, delete or rename functions or slots use -** Qt Designer which will update this file, preserving your code. Create an -** init() function in place of a constructor, and a destroy() function in -** place of a destructor. -*****************************************************************************/ -/* - Copyright (C) 2005-2009 Michel de Boer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -void SelectNicForm::init() -{ - idxDefault = -1; -} - -void SelectNicForm::setAsDefault(bool setIp) -{ -#if 0 - // DEPRECATED - // Only show the information when the default button is - // pressed for the first time. - if (idxDefault == -1) { - QMessageBox::information(this, PRODUCT_NAME, tr( - "If you want to remove or " - "change the default at a later time, you can do that " - "via the system settings.")); - } - - // Store current index as the changeItem method also changes - // the current index as a side effect. - int idxNewDefault = nicListBox->currentItem(); - - // Restore pixmap of the old default - if (idxDefault != -1) { - nicListBox->changeItem( - qPixmapFromMimeSource("kcmpci16.png"), - nicListBox->text(idxDefault), - idxDefault); - } - - // Set pixmap of the default - idxDefault = idxNewDefault; - nicListBox->changeItem( - qPixmapFromMimeSource("twinkle16.png"), - nicListBox->text(idxDefault), - idxDefault); - - // Write default to system settings - int pos = nicListBox->currentText().findRev(':'); - if (setIp) { - sys_config->set_start_user_host(nicListBox->currentText().mid(pos + 1).ascii()); - sys_config->set_start_user_nic(""); - } else { - sys_config->set_start_user_nic(nicListBox->currentText().left(pos).ascii()); - sys_config->set_start_user_host(""); - } - string error_msg; - if (!sys_config->write_config(error_msg)) { - // Failed to write config file - ((t_gui *)ui)->cb_show_msg(this, error_msg, MSG_CRITICAL); - } -#endif -} - -void SelectNicForm::setAsDefaultIp() -{ - setAsDefault(true); -} - -void SelectNicForm::setAsDefaultNic() -{ - setAsDefault(false); -} diff --git a/src/gui/selectprofileform.cpp b/src/gui/selectprofileform.cpp new file mode 100644 index 0000000..d72ece2 --- /dev/null +++ b/src/gui/selectprofileform.cpp @@ -0,0 +1,675 @@ +//Added by qt3to4: +#include +/* + Copyright (C) 2005-2009 Michel de Boer + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include +#include "user.h" +#include +#include +#include "protocol.h" +#include "gui.h" +#include "userprofileform.h" +#include "getprofilenameform.h" +#include "audits/memman.h" +#include "wizardform.h" +#include "syssettingsform.h" +#include +#include "service.h" +#include "presence/buddy.h" +#include "diamondcardprofileform.h" +#include "selectprofileform.h" +/* + * Constructs a SelectProfileForm as a child of 'parent', with the + * name 'name' and widget flags set to 'f'. + * + * The dialog will by default be modeless, unless you set 'modal' to + * true to construct a modal dialog. + */ +SelectProfileForm::SelectProfileForm(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl) + : QDialog(parent, name, modal, fl) +{ + setupUi(this); + + init(); +} + +/* + * Destroys the object and frees any allocated resources + */ +SelectProfileForm::~SelectProfileForm() +{ + destroy(); + // no need to delete child widgets, Qt does it all for us +} + +/* + * Sets the strings of the subwidgets using the current + * language. + */ +void SelectProfileForm::languageChange() +{ + retranslateUi(this); +} + + +void SelectProfileForm::init() +{ + user_config = 0; +} + +void SelectProfileForm::destroy() +{ + if (user_config) { + MEMMAN_DELETE(user_config); + delete user_config; + } +} + +// The exec() method is called at startup +int SelectProfileForm::execForm() +{ + mainWindow = 0; + profileListView->clear(); + defaultSet = false; // no default has been set + + // Get list of all profiles + QStringList profiles; + QString error; + if (!SelectProfileForm::getUserProfiles(profiles, error)) { + QMessageBox::critical(this, PRODUCT_NAME, error); + return QDialog::Rejected; + } + + // If there are no profiles then the user has to create one + if (profiles.isEmpty()) { + QMessageBox::information(this, PRODUCT_NAME, tr( + ""\ + "Before you can use Twinkle, you must create a user "\ + "profile.
Click OK to create a profile.")); + + int newProfileMethod = QMessageBox::question(this, PRODUCT_NAME, tr( + ""\ + "You can use the profile editor to create a profile. "\ + "With the profile editor you can change many settings "\ + "to tune the SIP protocol, RTP and many other things.

"\ + "Alternatively you can use the wizard to quickly setup a "\ + "user profile. The wizard asks you only a few essential "\ + "settings. If you create a user profile with the wizard you "\ + "can still edit the full profile with the profile editor at a later "\ + "time.

"\ + "You can create a Diamondcard account to make worldwide "\ + "calls to regular and cell phones and send SMS messages.

"\ + "Choose what method you wish to use."), + tr("&Wizard"), tr("&Profile editor"), tr("&Diamondcard")); + + switch (newProfileMethod) { + case 0: + wizardProfile(true); + break; + case 1: + newProfile(true); + break; + case 2: + diamondcardProfile(true); + break; + default: + return QDialog::Rejected; + } + + if (profileListView->childCount() == 0) { + // No profile has been created. + return QDialog::Rejected; + } + + // Select the created profile + Q3CheckListItem *item = (Q3CheckListItem *)profileListView->currentItem(); + QString profile = item->text(); + profile.append(USER_FILE_EXT); + selectedProfiles.clear(); + selectedProfiles.push_back(profile.ascii()); + + QMessageBox::information(this, PRODUCT_NAME, tr( + ""\ + "Next you may adjust the system settings. "\ + "You can change these settings always at a later time."\ + "

"\ + "Click OK to view and adjust the system settings.")); + + SysSettingsForm f(this, "system settings", true); + f.exec(); + + return QDialog::Accepted; + } + + fillProfileListView(profiles); + sysPushButton->show(); + runPushButton->setFocus(); + + // Show the modal dialog + return QDialog::exec(); +} + +// The showForm() method is called from File menu when Twinkle is running. +// The execForm() method cannot be used as it will block the Qt event loop. +// NOTE: the method show() is not re-implemented as Qt calls this method +// from exec() internally. +void SelectProfileForm::showForm(Q3MainWindow *_mainWindow) +{ + mainWindow = _mainWindow; + profileListView->clear(); + defaultSet = false; + + // Get list of all profiles + QStringList profiles; + QString error; + if (!SelectProfileForm::getUserProfiles(profiles, error)) { + QMessageBox::critical(this, PRODUCT_NAME, error); + return; + } + + // Initialize profile list view + fillProfileListView(profiles); + Q3ListViewItemIterator j(profileListView); + while (j.current()) { + Q3CheckListItem *item = (Q3CheckListItem *)j.current(); + QString profile = item->text(); + + // Set pixmap of default profile + list l = sys_config->get_start_user_profiles(); + if (std::find(l.begin(), l.end(), profile.ascii()) != l.end()) + { + item->setPixmap(0, QPixmap(":/icons/images/twinkle16.png")); + defaultSet = true; + } + + // Tick check box of active profile + if (phone->ref_user_profile(profile.ascii())) { + item->setOn(true); + } + + j++; + } + + sysPushButton->hide(); + runPushButton->setText("&OK"); + runPushButton->setFocus(); + QDialog::show(); +} + +void SelectProfileForm::runProfile() +{ + selectedProfiles.clear(); + Q3ListViewItemIterator i(profileListView, Q3ListViewItemIterator::Checked); + while (i.current()) { + Q3CheckListItem *item = (Q3CheckListItem *)i.current(); + QString profile =item->text(); + profile.append(USER_FILE_EXT); + selectedProfiles.push_back(profile.ascii()); + i++; + } + + if (selectedProfiles.empty()) { + QMessageBox::warning(this, PRODUCT_NAME, tr( + "You did not select any user profile to run.\n"\ + "Please select a profile.")); + return; + } + + // This signal will be caught when Twinkle is running. + // At startup the selectedProfiles attribute is read. + emit selection(selectedProfiles); + + accept(); +} + +void SelectProfileForm::editProfile() +{ + Q3CheckListItem *item = (Q3CheckListItem *)profileListView->currentItem(); + QString profile = item->text(); + + // If the profile to edit is currently active, then edit the in-memory + // user profile owned by the t_phone_user object + if (mainWindow) { + t_user *active_user = phone->ref_user_profile(profile.ascii()); + if (active_user) { + list user_list; + user_list.push_back(active_user); + UserProfileForm *f = new UserProfileForm(this, + "edit user profile", true, + Qt::WDestructiveClose); + + connect(f, SIGNAL(authCredentialsChanged(t_user *, const string&)), + mainWindow, + SLOT(updateAuthCache(t_user *, const string&))); + + connect(f, SIGNAL(stunServerChanged(t_user *)), + mainWindow, SLOT(updateStunSettings(t_user *))); + + f->show(user_list, ""); + return; + } + } + + // Edit the user profile from disk. + profile.append(USER_FILE_EXT); + + // Read selected config file + string error_msg; + + if (user_config) { + MEMMAN_DELETE(user_config); + delete user_config; + } + user_config = new t_user(); + MEMMAN_NEW(user_config); + + if (!user_config->read_config(profile.ascii(), error_msg)) { + ((t_gui *)ui)->cb_show_msg(this, error_msg, MSG_WARNING); + return; + } + + // Show the edit user profile form (modal dialog) + list user_list; + user_list.push_back(user_config); + UserProfileForm *f = new UserProfileForm(this, "edit user profile", true, + Qt::WDestructiveClose); + f->show(user_list, ""); +} + +void SelectProfileForm::newProfile() +{ + newProfile(false); +} + +void SelectProfileForm::newProfile(bool exec_mode) +{ + // Ask user for a profile name + GetProfileNameForm getProfileNameForm(this, "get profile name", true); + if (!getProfileNameForm.execNewName()) return; + + // Create file name + QString profile = getProfileNameForm.getProfileName(); + QString filename = profile; + filename.append(USER_FILE_EXT); + + // Create a new user config + if (user_config) { + MEMMAN_DELETE(user_config); + delete user_config; + } + user_config = new t_user(); + MEMMAN_NEW(user_config); + user_config->set_config(filename.ascii()); + + // Show the edit user profile form (modal dialog) + list user_list; + user_list.push_back(user_config); + UserProfileForm *f = new UserProfileForm(this, "edit user profile", true, + Qt::WDestructiveClose); + connect(f, SIGNAL(success()), this, SLOT(newProfileCreated())); + + if (exec_mode) { + f->exec(user_list, ""); + } else { + f->show(user_list, ""); + } +} + +void SelectProfileForm::newProfileCreated() +{ + // New profile created + // Add the new profile to the profile list box + Q3CheckListItem *item = new Q3CheckListItem(profileListView, + user_config->get_profile_name().c_str(), + Q3CheckListItem::CheckBox); + item->setPixmap(0, QPixmap(":/icons/images/penguin-small.png")); + + // Make the new profile the selected profile + // Do not change this without changing the exec method. + // When there are no profiles, the exec methods relies on the + // fact that afer creation of the profile it is selected. + profileListView->setSelected(item, true); + + // Enable buttons that act on a profile + editPushButton->setEnabled(true); + deletePushButton->setEnabled(true); + renamePushButton->setEnabled(true); + defaultPushButton->setEnabled(true); + runPushButton->setEnabled(true); +} + +void SelectProfileForm::deleteProfile() +{ + Q3CheckListItem *item = (Q3CheckListItem *)profileListView->currentItem(); + QString profile = item->text(); + QString msg = tr("Are you sure you want to delete profile '%1'?").arg(profile); + QMessageBox *mb = new QMessageBox(tr("Delete profile"), msg, + QMessageBox::Warning, + QMessageBox::Yes, + QMessageBox::No, + QMessageBox::NoButton, + this); + MEMMAN_NEW(mb); + if (mb->exec() == QMessageBox::Yes) { + // Delete file + QDir d = QDir::home(); + d.cd(USER_DIR); + QString filename = profile; + filename.append(USER_FILE_EXT); + QString fullname = d.filePath(filename); + if (!QFile::remove(fullname)) { + // Failed to delete file + QMessageBox::critical(this, PRODUCT_NAME, + tr("Failed to delete profile.")); + } else { + // Delete possible backup of the profile + QString backupname = fullname; + backupname.append("~"); + (void)QFile::remove(backupname); + + // Delete service files + filename = profile; + filename.append(SVC_FILE_EXT); + fullname = d.filePath(filename); + (void)QFile::remove(fullname); + fullname.append("~"); + (void)QFile::remove(fullname); + + // Delete profile from list of default profiles in + // system settings + list l = sys_config->get_start_user_profiles(); + if (std::find(l.begin(), l.end(), profile.ascii()) != l.end()) { + l.remove(profile.ascii()); + sys_config->set_start_user_profiles(l); + + string error_msg; + if (!sys_config->write_config(error_msg)) { + // Failed to write config file + ((t_gui *)ui)->cb_show_msg(this, + error_msg, MSG_CRITICAL); + } + } + + // Delete profile from profile list box + Q3CheckListItem *item = (Q3CheckListItem *)profileListView-> + currentItem(); + delete item; + if (profileListView->childCount() == 0) { + // There are no profiles anymore + // Disable buttons that act on a profile + editPushButton->setEnabled(false); + deletePushButton->setEnabled(false); + renamePushButton->setEnabled(false); + defaultPushButton->setEnabled(false); + runPushButton->setEnabled(false); + } else { + profileListView->setSelected(profileListView-> + firstChild(), true); + } + } + } + + MEMMAN_DELETE(mb); + delete mb; +} + +void SelectProfileForm::renameProfile() +{ + Q3CheckListItem *item = (Q3CheckListItem *)profileListView->currentItem(); + QString oldProfile = item->text(); + + // Ask user for a new profile name + GetProfileNameForm getProfileNameForm(this, "get profile name", true); + if (!getProfileNameForm.execRename(oldProfile)) return; + + // Create file name for the new profile + QString newProfile = getProfileNameForm.getProfileName(); + QString newFilename = newProfile; + newFilename.append(USER_FILE_EXT); + + // Create file name for the old profile + QString oldFilename = oldProfile; + oldFilename.append(USER_FILE_EXT); + + // Rename the file + QDir d = QDir::home(); + d.cd(USER_DIR); + if (!d.rename(oldFilename, newFilename)) { + // Failed to delete file + QMessageBox::critical(this, PRODUCT_NAME, + tr("Failed to rename profile.")); + } else { + // If there is a backup of the profile, rename it too. + QString oldBackupFilename = oldFilename; + oldBackupFilename.append("~"); + QString oldBackupFullname = d.filePath(oldBackupFilename); + if (QFile::exists(oldBackupFullname)) { + QString newBackupFilename = newFilename; + newBackupFilename.append("~"); + d.rename(oldBackupFilename, newBackupFilename); + } + + // Rename service files + oldFilename = oldProfile; + oldFilename.append(SVC_FILE_EXT); + QString oldFullname = d.filePath(oldFilename); + if (QFile::exists(oldFullname)) { + newFilename = newProfile; + newFilename.append(SVC_FILE_EXT); + d.rename(oldFilename, newFilename); + } + + // Rename service backup file + oldFilename.append("~"); + oldFullname = d.filePath(oldFilename); + if (QFile::exists(oldFullname)) { + newFilename.append("~"); + d.rename(oldFilename, newFilename); + } + + // Rename buddy list file + oldFilename = oldProfile; + oldFilename.append(BUDDY_FILE_EXT); + oldFullname = d.filePath(oldFilename); + if (QFile::exists(oldFullname)) { + newFilename = newProfile; + newFilename.append(BUDDY_FILE_EXT); + d.rename(oldFilename, newFilename); + } + + // Rename profile in list of default profiles in + // system settings + list l = sys_config->get_start_user_profiles(); + if (std::find(l.begin(), l.end(), oldProfile.ascii()) != l.end()) + { + std::replace(l.begin(), l.end(), oldProfile.ascii(), newProfile.ascii()); + sys_config->set_start_user_profiles(l); + + string error_msg; + if (!sys_config->write_config(error_msg)) { + // Failed to write config file + ((t_gui *)ui)->cb_show_msg(this, + error_msg, MSG_CRITICAL); + } + } + + emit profileRenamed(); + + // Change profile name in the list box + Q3CheckListItem *item = (Q3CheckListItem *)profileListView->currentItem(); + item->setText(0, newProfile); + } +} + +void SelectProfileForm::setAsDefault() +{ + // Only show the information when the default button is + // pressed for the first time. + if (!defaultSet) { + QMessageBox::information(this, PRODUCT_NAME, tr( + "

" + "If you want to remove or " + "change the default at a later time, you can do that " + "via the system settings." + "

")); + } + + defaultSet = true; + + // Restore all pixmaps + Q3ListViewItemIterator i(profileListView); + while (i.current()) { + i.current()->setPixmap(0, QPixmap(":/icons/images/penguin-small.png")); + i++; + } + + // Set pixmap of the default profiles. + // Set default profiles in system settings. + list l; + Q3ListViewItemIterator j(profileListView, Q3ListViewItemIterator::Checked); + while (j.current()) { + Q3CheckListItem *item = (Q3CheckListItem *)j.current(); + item->setPixmap(0, QPixmap(":/icons/images/twinkle16.png")); + l.push_back(item->text().ascii()); + j++; + } + sys_config->set_start_user_profiles(l); + + // Write default to system settings + string error_msg; + if (!sys_config->write_config(error_msg)) { + // Failed to write config file + ((t_gui *)ui)->cb_show_msg(this, error_msg, MSG_CRITICAL); + } +} + +void SelectProfileForm::wizardProfile() +{ + wizardProfile(false); +} + +void SelectProfileForm::wizardProfile(bool exec_mode) +{ + // Ask user for a profile name + GetProfileNameForm getProfileNameForm(this, "get profile name", true); + if (!getProfileNameForm.execNewName()) return; + + // Create file name + QString profile = getProfileNameForm.getProfileName(); + QString filename = profile; + filename.append(USER_FILE_EXT); + + // Create a new user config + if (user_config) { + MEMMAN_DELETE(user_config); + delete user_config; + } + user_config = new t_user(); + MEMMAN_NEW(user_config); + user_config->set_config(filename.ascii()); + + // Show the wizard form (modal dialog) + WizardForm *f = new WizardForm(this, "wizard", true, Qt::WDestructiveClose); + connect(f, SIGNAL(success()), this, SLOT(newProfileCreated())); + + if (exec_mode) { + f->exec(user_config); + } else { + f->show(user_config); + } +} + +void SelectProfileForm::diamondcardProfile() +{ + diamondcardProfile(false); +} + +void SelectProfileForm::diamondcardProfile(bool exec_mode) +{ + // Create a new user config + if (user_config) { + MEMMAN_DELETE(user_config); + delete user_config; + } + user_config = new t_user(); + MEMMAN_NEW(user_config); + + // Show the diamondcard profile form (modal dialog) + DiamondcardProfileForm *f = new DiamondcardProfileForm(this, "diamondcard", + true, Qt::WDestructiveClose); + connect(f, SIGNAL(success()), this, SLOT(newProfileCreated())); + + if (exec_mode) { + f->exec(user_config); + } else { + f->show(user_config); + } +} + + +void SelectProfileForm::sysSettings() +{ + SysSettingsForm *f = new SysSettingsForm(this, "system settings", true, + Qt::WDestructiveClose); + f->show(); +} + +// Get a list of all profiles. Returns false if there is an error. +bool SelectProfileForm::getUserProfiles(QStringList &profiles, QString &error) +{ + // Find the .twinkle directory in HOME + QDir d = QDir::home(); + if (!d.cd(USER_DIR)) { + error = tr("Cannot find .twinkle directory in your home directory."); + return false; + } + + // Select all config files + QString filterName = "*"; + filterName.append(USER_FILE_EXT); + d.setFilter(QDir::Files); + d.setNameFilter(filterName); + d.setSorting(QDir::Name | QDir::IgnoreCase); + profiles = d.entryList(); + + return true; +} + +void SelectProfileForm::fillProfileListView(const QStringList &profiles) +{ + // Put the profiles in the profile list view + for (QStringList::ConstIterator i = profiles.begin(); i != profiles.end(); i++) { + // Strip off the user file extension + QString profile = *i; + profile.truncate(profile.length() - strlen(USER_FILE_EXT)); + Q3CheckListItem *item = new Q3CheckListItem( + profileListView, profile, Q3CheckListItem::CheckBox); + item->setPixmap(0, QPixmap(":/icons/images/penguin-small.png")); + } + + // Highlight the first profile + profileListView->setSelected(profileListView->firstChild(), true); +} + +void SelectProfileForm::toggleItem(Q3ListViewItem *item) +{ + Q3CheckListItem *checkItem = (Q3CheckListItem *)item; + checkItem->setOn(!checkItem->isOn()); +} + diff --git a/src/gui/selectprofileform.h b/src/gui/selectprofileform.h new file mode 100644 index 0000000..81c2be5 --- /dev/null +++ b/src/gui/selectprofileform.h @@ -0,0 +1,61 @@ +#ifndef SELECTPROFILEFORM_H +#define SELECTPROFILEFORM_H +class t_phone; +extern t_phone *phone; + +#include +#include +#include "phone.h" +#include +#include "ui_selectprofileform.h" + +class SelectProfileForm : public QDialog, public Ui::SelectProfileForm +{ + Q_OBJECT + +public: + SelectProfileForm(QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WindowFlags fl = 0); + ~SelectProfileForm(); + + std::list selectedProfiles; + + virtual int execForm(); + static bool getUserProfiles( QStringList & profiles, QString & error ); + +public slots: + virtual void showForm( Q3MainWindow * _mainWindow ); + virtual void runProfile(); + virtual void editProfile(); + virtual void newProfile(); + virtual void newProfile( bool exec_mode ); + virtual void newProfileCreated(); + virtual void deleteProfile(); + virtual void renameProfile(); + virtual void setAsDefault(); + virtual void wizardProfile(); + virtual void wizardProfile( bool exec_mode ); + virtual void diamondcardProfile(); + virtual void diamondcardProfile( bool exec_mode ); + virtual void sysSettings(); + virtual void fillProfileListView( const QStringList & profiles ); + virtual void toggleItem( Q3ListViewItem * item ); + +signals: + void selection(const list &); + void profileRenamed(); + +protected slots: + virtual void languageChange(); + +private: + bool defaultSet; + t_user *user_config; + Q3MainWindow *mainWindow; + + void init(); + void destroy(); + +}; + + +#endif diff --git a/src/gui/selectprofileform.ui.h b/src/gui/selectprofileform.ui.h deleted file mode 100644 index dcdc338..0000000 --- a/src/gui/selectprofileform.ui.h +++ /dev/null @@ -1,633 +0,0 @@ -//Added by qt3to4: -#include -/**************************************************************************** -** ui.h extension file, included from the uic-generated form implementation. -** -** If you wish to add, delete or rename functions or slots use -** Qt Designer which will update this file, preserving your code. Create an -** init() function in place of a constructor, and a destroy() function in -** place of a destructor. -*****************************************************************************/ -/* - Copyright (C) 2005-2009 Michel de Boer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -void SelectProfileForm::init() -{ - user_config = 0; -} - -void SelectProfileForm::destroy() -{ - if (user_config) { - MEMMAN_DELETE(user_config); - delete user_config; - } -} - -// The exec() method is called at startup -int SelectProfileForm::execForm() -{ - mainWindow = 0; - profileListView->clear(); - defaultSet = false; // no default has been set - - // Get list of all profiles - QStringList profiles; - QString error; - if (!SelectProfileForm::getUserProfiles(profiles, error)) { - QMessageBox::critical(this, PRODUCT_NAME, error); - return QDialog::Rejected; - } - - // If there are no profiles then the user has to create one - if (profiles.isEmpty()) { - QMessageBox::information(this, PRODUCT_NAME, tr( - ""\ - "Before you can use Twinkle, you must create a user "\ - "profile.
Click OK to create a profile.")); - - int newProfileMethod = QMessageBox::question(this, PRODUCT_NAME, tr( - ""\ - "You can use the profile editor to create a profile. "\ - "With the profile editor you can change many settings "\ - "to tune the SIP protocol, RTP and many other things.

"\ - "Alternatively you can use the wizard to quickly setup a "\ - "user profile. The wizard asks you only a few essential "\ - "settings. If you create a user profile with the wizard you "\ - "can still edit the full profile with the profile editor at a later "\ - "time.

"\ - "You can create a Diamondcard account to make worldwide "\ - "calls to regular and cell phones and send SMS messages.

"\ - "Choose what method you wish to use."), - tr("&Wizard"), tr("&Profile editor"), tr("&Diamondcard")); - - switch (newProfileMethod) { - case 0: - wizardProfile(true); - break; - case 1: - newProfile(true); - break; - case 2: - diamondcardProfile(true); - break; - default: - return QDialog::Rejected; - } - - if (profileListView->childCount() == 0) { - // No profile has been created. - return QDialog::Rejected; - } - - // Select the created profile - Q3CheckListItem *item = (Q3CheckListItem *)profileListView->currentItem(); - QString profile = item->text(); - profile.append(USER_FILE_EXT); - selectedProfiles.clear(); - selectedProfiles.push_back(profile.ascii()); - - QMessageBox::information(this, PRODUCT_NAME, tr( - ""\ - "Next you may adjust the system settings. "\ - "You can change these settings always at a later time."\ - "

"\ - "Click OK to view and adjust the system settings.")); - - SysSettingsForm f(this, "system settings", true); - f.exec(); - - return QDialog::Accepted; - } - - fillProfileListView(profiles); - sysPushButton->show(); - runPushButton->setFocus(); - - // Show the modal dialog - return QDialog::exec(); -} - -// The showForm() method is called from File menu when Twinkle is running. -// The execForm() method cannot be used as it will block the Qt event loop. -// NOTE: the method show() is not re-implemented as Qt calls this method -// from exec() internally. -void SelectProfileForm::showForm(Q3MainWindow *_mainWindow) -{ - mainWindow = _mainWindow; - profileListView->clear(); - defaultSet = false; - - // Get list of all profiles - QStringList profiles; - QString error; - if (!SelectProfileForm::getUserProfiles(profiles, error)) { - QMessageBox::critical(this, PRODUCT_NAME, error); - return; - } - - // Initialize profile list view - fillProfileListView(profiles); - Q3ListViewItemIterator j(profileListView); - while (j.current()) { - Q3CheckListItem *item = (Q3CheckListItem *)j.current(); - QString profile = item->text(); - - // Set pixmap of default profile - list l = sys_config->get_start_user_profiles(); - if (std::find(l.begin(), l.end(), profile.ascii()) != l.end()) - { - item->setPixmap(0, qPixmapFromMimeSource("twinkle16.png")); - defaultSet = true; - } - - // Tick check box of active profile - if (phone->ref_user_profile(profile.ascii())) { - item->setOn(true); - } - - j++; - } - - sysPushButton->hide(); - runPushButton->setText("&OK"); - runPushButton->setFocus(); - QDialog::show(); -} - -void SelectProfileForm::runProfile() -{ - selectedProfiles.clear(); - Q3ListViewItemIterator i(profileListView, Q3ListViewItemIterator::Checked); - while (i.current()) { - Q3CheckListItem *item = (Q3CheckListItem *)i.current(); - QString profile =item->text(); - profile.append(USER_FILE_EXT); - selectedProfiles.push_back(profile.ascii()); - i++; - } - - if (selectedProfiles.empty()) { - QMessageBox::warning(this, PRODUCT_NAME, tr( - "You did not select any user profile to run.\n"\ - "Please select a profile.")); - return; - } - - // This signal will be caught when Twinkle is running. - // At startup the selectedProfiles attribute is read. - emit selection(selectedProfiles); - - accept(); -} - -void SelectProfileForm::editProfile() -{ - Q3CheckListItem *item = (Q3CheckListItem *)profileListView->currentItem(); - QString profile = item->text(); - - // If the profile to edit is currently active, then edit the in-memory - // user profile owned by the t_phone_user object - if (mainWindow) { - t_user *active_user = phone->ref_user_profile(profile.ascii()); - if (active_user) { - list user_list; - user_list.push_back(active_user); - UserProfileForm *f = new UserProfileForm(this, - "edit user profile", true, - Qt::WDestructiveClose); - - connect(f, SIGNAL(authCredentialsChanged(t_user *, const string&)), - mainWindow, - SLOT(updateAuthCache(t_user *, const string&))); - - connect(f, SIGNAL(stunServerChanged(t_user *)), - mainWindow, SLOT(updateStunSettings(t_user *))); - - f->show(user_list, ""); - return; - } - } - - // Edit the user profile from disk. - profile.append(USER_FILE_EXT); - - // Read selected config file - string error_msg; - - if (user_config) { - MEMMAN_DELETE(user_config); - delete user_config; - } - user_config = new t_user(); - MEMMAN_NEW(user_config); - - if (!user_config->read_config(profile.ascii(), error_msg)) { - ((t_gui *)ui)->cb_show_msg(this, error_msg, MSG_WARNING); - return; - } - - // Show the edit user profile form (modal dialog) - list user_list; - user_list.push_back(user_config); - UserProfileForm *f = new UserProfileForm(this, "edit user profile", true, - Qt::WDestructiveClose); - f->show(user_list, ""); -} - -void SelectProfileForm::newProfile() -{ - newProfile(false); -} - -void SelectProfileForm::newProfile(bool exec_mode) -{ - // Ask user for a profile name - GetProfileNameForm getProfileNameForm(this, "get profile name", true); - if (!getProfileNameForm.execNewName()) return; - - // Create file name - QString profile = getProfileNameForm.getProfileName(); - QString filename = profile; - filename.append(USER_FILE_EXT); - - // Create a new user config - if (user_config) { - MEMMAN_DELETE(user_config); - delete user_config; - } - user_config = new t_user(); - MEMMAN_NEW(user_config); - user_config->set_config(filename.ascii()); - - // Show the edit user profile form (modal dialog) - list user_list; - user_list.push_back(user_config); - UserProfileForm *f = new UserProfileForm(this, "edit user profile", true, - Qt::WDestructiveClose); - connect(f, SIGNAL(success()), this, SLOT(newProfileCreated())); - - if (exec_mode) { - f->exec(user_list, ""); - } else { - f->show(user_list, ""); - } -} - -void SelectProfileForm::newProfileCreated() -{ - // New profile created - // Add the new profile to the profile list box - Q3CheckListItem *item = new Q3CheckListItem(profileListView, - user_config->get_profile_name().c_str(), - Q3CheckListItem::CheckBox); - item->setPixmap(0, qPixmapFromMimeSource("penguin-small.png")); - - // Make the new profile the selected profile - // Do not change this without changing the exec method. - // When there are no profiles, the exec methods relies on the - // fact that afer creation of the profile it is selected. - profileListView->setSelected(item, true); - - // Enable buttons that act on a profile - editPushButton->setEnabled(true); - deletePushButton->setEnabled(true); - renamePushButton->setEnabled(true); - defaultPushButton->setEnabled(true); - runPushButton->setEnabled(true); -} - -void SelectProfileForm::deleteProfile() -{ - Q3CheckListItem *item = (Q3CheckListItem *)profileListView->currentItem(); - QString profile = item->text(); - QString msg = tr("Are you sure you want to delete profile '%1'?").arg(profile); - QMessageBox *mb = new QMessageBox(tr("Delete profile"), msg, - QMessageBox::Warning, - QMessageBox::Yes, - QMessageBox::No, - QMessageBox::NoButton, - this); - MEMMAN_NEW(mb); - if (mb->exec() == QMessageBox::Yes) { - // Delete file - QDir d = QDir::home(); - d.cd(USER_DIR); - QString filename = profile; - filename.append(USER_FILE_EXT); - QString fullname = d.filePath(filename); - if (!QFile::remove(fullname)) { - // Failed to delete file - QMessageBox::critical(this, PRODUCT_NAME, - tr("Failed to delete profile.")); - } else { - // Delete possible backup of the profile - QString backupname = fullname; - backupname.append("~"); - (void)QFile::remove(backupname); - - // Delete service files - filename = profile; - filename.append(SVC_FILE_EXT); - fullname = d.filePath(filename); - (void)QFile::remove(fullname); - fullname.append("~"); - (void)QFile::remove(fullname); - - // Delete profile from list of default profiles in - // system settings - list l = sys_config->get_start_user_profiles(); - if (std::find(l.begin(), l.end(), profile.ascii()) != l.end()) { - l.remove(profile.ascii()); - sys_config->set_start_user_profiles(l); - - string error_msg; - if (!sys_config->write_config(error_msg)) { - // Failed to write config file - ((t_gui *)ui)->cb_show_msg(this, - error_msg, MSG_CRITICAL); - } - } - - // Delete profile from profile list box - Q3CheckListItem *item = (Q3CheckListItem *)profileListView-> - currentItem(); - delete item; - if (profileListView->childCount() == 0) { - // There are no profiles anymore - // Disable buttons that act on a profile - editPushButton->setEnabled(false); - deletePushButton->setEnabled(false); - renamePushButton->setEnabled(false); - defaultPushButton->setEnabled(false); - runPushButton->setEnabled(false); - } else { - profileListView->setSelected(profileListView-> - firstChild(), true); - } - } - } - - MEMMAN_DELETE(mb); - delete mb; -} - -void SelectProfileForm::renameProfile() -{ - Q3CheckListItem *item = (Q3CheckListItem *)profileListView->currentItem(); - QString oldProfile = item->text(); - - // Ask user for a new profile name - GetProfileNameForm getProfileNameForm(this, "get profile name", true); - if (!getProfileNameForm.execRename(oldProfile)) return; - - // Create file name for the new profile - QString newProfile = getProfileNameForm.getProfileName(); - QString newFilename = newProfile; - newFilename.append(USER_FILE_EXT); - - // Create file name for the old profile - QString oldFilename = oldProfile; - oldFilename.append(USER_FILE_EXT); - - // Rename the file - QDir d = QDir::home(); - d.cd(USER_DIR); - if (!d.rename(oldFilename, newFilename)) { - // Failed to delete file - QMessageBox::critical(this, PRODUCT_NAME, - tr("Failed to rename profile.")); - } else { - // If there is a backup of the profile, rename it too. - QString oldBackupFilename = oldFilename; - oldBackupFilename.append("~"); - QString oldBackupFullname = d.filePath(oldBackupFilename); - if (QFile::exists(oldBackupFullname)) { - QString newBackupFilename = newFilename; - newBackupFilename.append("~"); - d.rename(oldBackupFilename, newBackupFilename); - } - - // Rename service files - oldFilename = oldProfile; - oldFilename.append(SVC_FILE_EXT); - QString oldFullname = d.filePath(oldFilename); - if (QFile::exists(oldFullname)) { - newFilename = newProfile; - newFilename.append(SVC_FILE_EXT); - d.rename(oldFilename, newFilename); - } - - // Rename service backup file - oldFilename.append("~"); - oldFullname = d.filePath(oldFilename); - if (QFile::exists(oldFullname)) { - newFilename.append("~"); - d.rename(oldFilename, newFilename); - } - - // Rename buddy list file - oldFilename = oldProfile; - oldFilename.append(BUDDY_FILE_EXT); - oldFullname = d.filePath(oldFilename); - if (QFile::exists(oldFullname)) { - newFilename = newProfile; - newFilename.append(BUDDY_FILE_EXT); - d.rename(oldFilename, newFilename); - } - - // Rename profile in list of default profiles in - // system settings - list l = sys_config->get_start_user_profiles(); - if (std::find(l.begin(), l.end(), oldProfile.ascii()) != l.end()) - { - std::replace(l.begin(), l.end(), oldProfile.ascii(), newProfile.ascii()); - sys_config->set_start_user_profiles(l); - - string error_msg; - if (!sys_config->write_config(error_msg)) { - // Failed to write config file - ((t_gui *)ui)->cb_show_msg(this, - error_msg, MSG_CRITICAL); - } - } - - emit profileRenamed(); - - // Change profile name in the list box - Q3CheckListItem *item = (Q3CheckListItem *)profileListView->currentItem(); - item->setText(0, newProfile); - } -} - -void SelectProfileForm::setAsDefault() -{ - // Only show the information when the default button is - // pressed for the first time. - if (!defaultSet) { - QMessageBox::information(this, PRODUCT_NAME, tr( - "

" - "If you want to remove or " - "change the default at a later time, you can do that " - "via the system settings." - "

")); - } - - defaultSet = true; - - // Restore all pixmaps - Q3ListViewItemIterator i(profileListView); - while (i.current()) { - i.current()->setPixmap(0, qPixmapFromMimeSource("penguin-small.png")); - i++; - } - - // Set pixmap of the default profiles. - // Set default profiles in system settings. - list l; - Q3ListViewItemIterator j(profileListView, Q3ListViewItemIterator::Checked); - while (j.current()) { - Q3CheckListItem *item = (Q3CheckListItem *)j.current(); - item->setPixmap(0, qPixmapFromMimeSource("twinkle16.png")); - l.push_back(item->text().ascii()); - j++; - } - sys_config->set_start_user_profiles(l); - - // Write default to system settings - string error_msg; - if (!sys_config->write_config(error_msg)) { - // Failed to write config file - ((t_gui *)ui)->cb_show_msg(this, error_msg, MSG_CRITICAL); - } -} - -void SelectProfileForm::wizardProfile() -{ - wizardProfile(false); -} - -void SelectProfileForm::wizardProfile(bool exec_mode) -{ - // Ask user for a profile name - GetProfileNameForm getProfileNameForm(this, "get profile name", true); - if (!getProfileNameForm.execNewName()) return; - - // Create file name - QString profile = getProfileNameForm.getProfileName(); - QString filename = profile; - filename.append(USER_FILE_EXT); - - // Create a new user config - if (user_config) { - MEMMAN_DELETE(user_config); - delete user_config; - } - user_config = new t_user(); - MEMMAN_NEW(user_config); - user_config->set_config(filename.ascii()); - - // Show the wizard form (modal dialog) - WizardForm *f = new WizardForm(this, "wizard", true, Qt::WDestructiveClose); - connect(f, SIGNAL(success()), this, SLOT(newProfileCreated())); - - if (exec_mode) { - f->exec(user_config); - } else { - f->show(user_config); - } -} - -void SelectProfileForm::diamondcardProfile() -{ - diamondcardProfile(false); -} - -void SelectProfileForm::diamondcardProfile(bool exec_mode) -{ - // Create a new user config - if (user_config) { - MEMMAN_DELETE(user_config); - delete user_config; - } - user_config = new t_user(); - MEMMAN_NEW(user_config); - - // Show the diamondcard profile form (modal dialog) - DiamondcardProfileForm *f = new DiamondcardProfileForm(this, "diamondcard", - true, Qt::WDestructiveClose); - connect(f, SIGNAL(success()), this, SLOT(newProfileCreated())); - - if (exec_mode) { - f->exec(user_config); - } else { - f->show(user_config); - } -} - - -void SelectProfileForm::sysSettings() -{ - SysSettingsForm *f = new SysSettingsForm(this, "system settings", true, - Qt::WDestructiveClose); - f->show(); -} - -// Get a list of all profiles. Returns false if there is an error. -bool SelectProfileForm::getUserProfiles(QStringList &profiles, QString &error) -{ - // Find the .twinkle directory in HOME - QDir d = QDir::home(); - if (!d.cd(USER_DIR)) { - error = tr("Cannot find .twinkle directory in your home directory."); - return false; - } - - // Select all config files - QString filterName = "*"; - filterName.append(USER_FILE_EXT); - d.setFilter(QDir::Files); - d.setNameFilter(filterName); - d.setSorting(QDir::Name | QDir::IgnoreCase); - profiles = d.entryList(); - - return true; -} - -void SelectProfileForm::fillProfileListView(const QStringList &profiles) -{ - // Put the profiles in the profile list view - for (QStringList::ConstIterator i = profiles.begin(); i != profiles.end(); i++) { - // Strip off the user file extension - QString profile = *i; - profile.truncate(profile.length() - strlen(USER_FILE_EXT)); - Q3CheckListItem *item = new Q3CheckListItem( - profileListView, profile, Q3CheckListItem::CheckBox); - item->setPixmap(0, qPixmapFromMimeSource("penguin-small.png")); - } - - // Highlight the first profile - profileListView->setSelected(profileListView->firstChild(), true); -} - -void SelectProfileForm::toggleItem(Q3ListViewItem *item) -{ - Q3CheckListItem *checkItem = (Q3CheckListItem *)item; - checkItem->setOn(!checkItem->isOn()); -} - diff --git a/src/gui/selectuserform.cpp b/src/gui/selectuserform.cpp new file mode 100644 index 0000000..0a0af5a --- /dev/null +++ b/src/gui/selectuserform.cpp @@ -0,0 +1,166 @@ +/* + Copyright (C) 2005-2009 Michel de Boer + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include +#include +#include +#include + +#include +#include "selectuserform.h" +/* + * Constructs a SelectUserForm as a child of 'parent', with the + * name 'name' and widget flags set to 'f'. + * + * The dialog will by default be modeless, unless you set 'modal' to + * true to construct a modal dialog. + */ +SelectUserForm::SelectUserForm(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl) + : QDialog(parent, name, modal, fl) +{ + setupUi(this); + + init(); +} + +/* + * Destroys the object and frees any allocated resources + */ +SelectUserForm::~SelectUserForm() +{ + // no need to delete child widgets, Qt does it all for us +} + +/* + * Sets the strings of the subwidgets using the current + * language. + */ +void SelectUserForm::languageChange() +{ + retranslateUi(this); +} + + +void SelectUserForm::init() +{ + // Disable sorting + userListView->setSorting(-1); +} + +void SelectUserForm::show(t_select_purpose purpose) +{ + QString title, msg_purpose; + + // Set dialog caption and purpose + title = PRODUCT_NAME; + title += " - "; + switch (purpose) { + case SELECT_REGISTER: + title.append(tr("Register")); + msg_purpose = tr("Select users that you want to register."); + break; + case SELECT_DEREGISTER: + title.append(tr("Deregister")); + msg_purpose = tr("Select users that you want to deregister."); + break; + case SELECT_DEREGISTER_ALL: + title.append(tr("Deregister all devices")); + msg_purpose = tr("Select users for which you want to deregister all devices."); + break; + case SELECT_DND: + title.append(tr("Do not disturb")); + msg_purpose = tr("Select users for which you want to enable 'do not disturb'."); + break; + case SELECT_AUTO_ANSWER: + title.append(tr("Auto answer")); + msg_purpose = tr("Select users for which you want to enable 'auto answer'."); + break; + default: + assert(false); + } + setCaption(title); + purposeTextLabel->setText(msg_purpose); + + // Fill list view + list user_list = phone->ref_users(); + for (list::reverse_iterator i = user_list.rbegin(); i != user_list.rend(); i++) { + Q3CheckListItem *item = new Q3CheckListItem(userListView, + (*i)->get_profile_name().c_str(), Q3CheckListItem::CheckBox); + + switch (purpose) { + case SELECT_DND: + item->setOn(phone->ref_service(*i)->is_dnd_active()); + break; + case SELECT_AUTO_ANSWER: + item->setOn(phone->ref_service(*i)->is_auto_answer_active()); + break; + default: + break; + } + } + + QDialog::show(); +} + +void SelectUserForm::validate() +{ + list selected_list, not_selected_list; + + Q3ListViewItemIterator i(userListView); + while (i.current()) { + Q3CheckListItem *item = (Q3CheckListItem *)(i.current()); + if (item->isOn()) { + selected_list.push_back(phone-> + ref_user_profile(item->text().ascii())); + } else { + not_selected_list.push_back(phone-> + ref_user_profile(item->text().ascii())); + } + i++; + } + + emit (selection(selected_list)); + emit (not_selected(not_selected_list)); + accept(); +} + +void SelectUserForm::selectAll() +{ + Q3ListViewItemIterator i(userListView); + while (i.current()) { + Q3CheckListItem *item = (Q3CheckListItem *)(i.current()); + item->setOn(true); + i++; + } +} + +void SelectUserForm::clearAll() +{ + Q3ListViewItemIterator i(userListView); + while (i.current()) { + Q3CheckListItem *item = (Q3CheckListItem *)(i.current()); + item->setOn(false); + i++; + } +} + +void SelectUserForm::toggle(Q3ListViewItem *item) +{ + Q3CheckListItem *checkItem = (Q3CheckListItem *)item; + checkItem->setOn(!checkItem->isOn()); +} diff --git a/src/gui/selectuserform.h b/src/gui/selectuserform.h new file mode 100644 index 0000000..898dbbf --- /dev/null +++ b/src/gui/selectuserform.h @@ -0,0 +1,39 @@ +#ifndef SELECTUSERFORM_H +#define SELECTUSERFORM_H +class t_phone; +extern t_phone *phone; + +#include "gui.h" +#include "phone.h" +#include "user.h" +#include "ui_selectuserform.h" + +class SelectUserForm : public QDialog, public Ui::SelectUserForm +{ + Q_OBJECT + +public: + SelectUserForm(QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WindowFlags fl = 0); + ~SelectUserForm(); + +public slots: + virtual void show( t_select_purpose purpose ); + virtual void validate(); + virtual void selectAll(); + virtual void clearAll(); + virtual void toggle( Q3ListViewItem * item ); + +signals: + void selection(list); + void not_selected(list); + +protected slots: + virtual void languageChange(); + +private: + void init(); + +}; + + +#endif diff --git a/src/gui/selectuserform.ui.h b/src/gui/selectuserform.ui.h deleted file mode 100644 index 61b1fa6..0000000 --- a/src/gui/selectuserform.ui.h +++ /dev/null @@ -1,138 +0,0 @@ -/**************************************************************************** -** ui.h extension file, included from the uic-generated form implementation. -** -** If you want to add, delete, or rename functions or slots, use -** Qt Designer to update this file, preserving your code. -** -** You should not define a constructor or destructor in this file. -** Instead, write your code in functions called init() and destroy(). -** These will automatically be called by the form's constructor and -** destructor. -*****************************************************************************/ - -/* - Copyright (C) 2005-2009 Michel de Boer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -void SelectUserForm::init() -{ - // Disable sorting - userListView->setSorting(-1); -} - -void SelectUserForm::show(t_select_purpose purpose) -{ - QString title, msg_purpose; - - // Set dialog caption and purpose - title = PRODUCT_NAME; - title += " - "; - switch (purpose) { - case SELECT_REGISTER: - title.append(tr("Register")); - msg_purpose = tr("Select users that you want to register."); - break; - case SELECT_DEREGISTER: - title.append(tr("Deregister")); - msg_purpose = tr("Select users that you want to deregister."); - break; - case SELECT_DEREGISTER_ALL: - title.append(tr("Deregister all devices")); - msg_purpose = tr("Select users for which you want to deregister all devices."); - break; - case SELECT_DND: - title.append(tr("Do not disturb")); - msg_purpose = tr("Select users for which you want to enable 'do not disturb'."); - break; - case SELECT_AUTO_ANSWER: - title.append(tr("Auto answer")); - msg_purpose = tr("Select users for which you want to enable 'auto answer'."); - break; - default: - assert(false); - } - setCaption(title); - purposeTextLabel->setText(msg_purpose); - - // Fill list view - list user_list = phone->ref_users(); - for (list::reverse_iterator i = user_list.rbegin(); i != user_list.rend(); i++) { - Q3CheckListItem *item = new Q3CheckListItem(userListView, - (*i)->get_profile_name().c_str(), Q3CheckListItem::CheckBox); - - switch (purpose) { - case SELECT_DND: - item->setOn(phone->ref_service(*i)->is_dnd_active()); - break; - case SELECT_AUTO_ANSWER: - item->setOn(phone->ref_service(*i)->is_auto_answer_active()); - break; - default: - break; - } - } - - QDialog::show(); -} - -void SelectUserForm::validate() -{ - list selected_list, not_selected_list; - - Q3ListViewItemIterator i(userListView); - while (i.current()) { - Q3CheckListItem *item = (Q3CheckListItem *)(i.current()); - if (item->isOn()) { - selected_list.push_back(phone-> - ref_user_profile(item->text().ascii())); - } else { - not_selected_list.push_back(phone-> - ref_user_profile(item->text().ascii())); - } - i++; - } - - emit (selection(selected_list)); - emit (not_selected(not_selected_list)); - accept(); -} - -void SelectUserForm::selectAll() -{ - Q3ListViewItemIterator i(userListView); - while (i.current()) { - Q3CheckListItem *item = (Q3CheckListItem *)(i.current()); - item->setOn(true); - i++; - } -} - -void SelectUserForm::clearAll() -{ - Q3ListViewItemIterator i(userListView); - while (i.current()) { - Q3CheckListItem *item = (Q3CheckListItem *)(i.current()); - item->setOn(false); - i++; - } -} - -void SelectUserForm::toggle(Q3ListViewItem *item) -{ - Q3CheckListItem *checkItem = (Q3CheckListItem *)item; - checkItem->setOn(!checkItem->isOn()); -} diff --git a/src/gui/sendfileform.cpp b/src/gui/sendfileform.cpp new file mode 100644 index 0000000..e212579 --- /dev/null +++ b/src/gui/sendfileform.cpp @@ -0,0 +1,133 @@ +/* + Copyright (C) 2005-2009 Michel de Boer + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifdef HAVE_KDE +#include +#endif + +#include "audits/memman.h" +#include "gui.h" +#include +#include +#include "sendfileform.h" +/* + * Constructs a SendFileForm as a child of 'parent', with the + * name 'name' and widget flags set to 'f'. + * + * The dialog will by default be modeless, unless you set 'modal' to + * true to construct a modal dialog. + */ +SendFileForm::SendFileForm(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl) + : QDialog(parent, name, modal, fl) +{ + setupUi(this); + + init(); +} + +/* + * Destroys the object and frees any allocated resources + */ +SendFileForm::~SendFileForm() +{ + destroy(); + // no need to delete child widgets, Qt does it all for us +} + +/* + * Sets the strings of the subwidgets using the current + * language. + */ +void SendFileForm::languageChange() +{ + retranslateUi(this); +} + + +void SendFileForm::init() +{ + setWindowFlags(windowFlags() | Qt::WDestructiveClose); + _chooseFileDialog = NULL; +} + +void SendFileForm::destroy() +{ + // Auto destruct window + MEMMAN_DELETE(this); + + if (_chooseFileDialog) { + MEMMAN_DELETE(_chooseFileDialog); + delete _chooseFileDialog; + } +} + +/** Signal the selected information to an observer. */ +void SendFileForm::signalSelectedInfo() +{ + if (!QFile::exists(fileLineEdit->text())) { + ((t_gui *)ui)->cb_show_msg(this, tr("File does not exist.").ascii(), MSG_WARNING); + return; + } + + emit selected(fileLineEdit->text(), subjectLineEdit->text()); + accept(); +} + +/** Choose a file from a file dialog. */ +void SendFileForm::chooseFile() +{ +#ifdef HAVE_KDE + KFileDialog *d = new KFileDialog(QString::null, QString::null, this, 0, true); + MEMMAN_NEW(d); + + d->setOperationMode(KFileDialog::Other); + connect(d, SIGNAL(okClicked()), this, SLOT(setFilename())); +#else + Q3FileDialog *d = new Q3FileDialog(QString::null, QString::null, this, 0, true); + MEMMAN_NEW(d); + + connect(d, SIGNAL(fileSelected(const QString &)), this, SLOT(setFilename())); +#endif + d->setCaption(tr("Send file...")); + + if (_chooseFileDialog) { + MEMMAN_DELETE(_chooseFileDialog); + delete _chooseFileDialog; + } + _chooseFileDialog = d; + + d->show(); +} + +/** + * Set the filename value. + * @param filename [in] The value to set. + */ +void SendFileForm::setFilename() +{ + QString filename; +#ifdef HAVE_KDE + KFileDialog *d = dynamic_cast(_chooseFileDialog); + filename = d->selectedFile(); +#else + Q3FileDialog *d = dynamic_cast(_chooseFileDialog); + filename = d->selectedFile(); +#endif + + fileLineEdit->setText(filename); +} diff --git a/src/gui/sendfileform.h b/src/gui/sendfileform.h new file mode 100644 index 0000000..6601ad2 --- /dev/null +++ b/src/gui/sendfileform.h @@ -0,0 +1,33 @@ +#ifndef SENDFILEFORM_H +#define SENDFILEFORM_H +#include "ui_sendfileform.h" + +class SendFileForm : public QDialog, public Ui::SendFileForm +{ + Q_OBJECT + +public: + SendFileForm(QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WindowFlags fl = 0); + ~SendFileForm(); + +public slots: + virtual void signalSelectedInfo(); + virtual void chooseFile(); + virtual void setFilename(); + +signals: + void selected(const QString &filename, const QString &subject); + +protected slots: + virtual void languageChange(); + +private: + QDialog *_chooseFileDialog; + + void init(); + void destroy(); + +}; + + +#endif diff --git a/src/gui/sendfileform.ui b/src/gui/sendfileform.ui index 6224c89..8ba2cce 100644 --- a/src/gui/sendfileform.ui +++ b/src/gui/sendfileform.ui @@ -28,7 +28,7 @@
- fileopen.png + :/icons/images/fileopen.png Select file to send. diff --git a/src/gui/sendfileform.ui.h b/src/gui/sendfileform.ui.h deleted file mode 100644 index aff6273..0000000 --- a/src/gui/sendfileform.ui.h +++ /dev/null @@ -1,106 +0,0 @@ -/**************************************************************************** -** ui.h extension file, included from the uic-generated form implementation. -** -** If you want to add, delete, or rename functions or slots, use -** Qt Designer to update this file, preserving your code. -** -** You should not define a constructor or destructor in this file. -** Instead, write your code in functions called init() and destroy(). -** These will automatically be called by the form's constructor and -** destructor. -*****************************************************************************/ - -/* - Copyright (C) 2005-2009 Michel de Boer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -#ifdef HAVE_KDE -#include -#endif - -void SendFileForm::init() -{ - setWindowFlags(windowFlags() | Qt::WDestructiveClose); - _chooseFileDialog = NULL; -} - -void SendFileForm::destroy() -{ - // Auto destruct window - MEMMAN_DELETE(this); - - if (_chooseFileDialog) { - MEMMAN_DELETE(_chooseFileDialog); - delete _chooseFileDialog; - } -} - -/** Signal the selected information to an observer. */ -void SendFileForm::signalSelectedInfo() -{ - if (!QFile::exists(fileLineEdit->text())) { - ((t_gui *)ui)->cb_show_msg(this, tr("File does not exist.").ascii(), MSG_WARNING); - return; - } - - emit selected(fileLineEdit->text(), subjectLineEdit->text()); - accept(); -} - -/** Choose a file from a file dialog. */ -void SendFileForm::chooseFile() -{ -#ifdef HAVE_KDE - KFileDialog *d = new KFileDialog(QString::null, QString::null, this, 0, true); - MEMMAN_NEW(d); - - d->setOperationMode(KFileDialog::Other); - connect(d, SIGNAL(okClicked()), this, SLOT(setFilename())); -#else - Q3FileDialog *d = new Q3FileDialog(QString::null, QString::null, this, 0, true); - MEMMAN_NEW(d); - - connect(d, SIGNAL(fileSelected(const QString &)), this, SLOT(setFilename())); -#endif - d->setCaption(tr("Send file...")); - - if (_chooseFileDialog) { - MEMMAN_DELETE(_chooseFileDialog); - delete _chooseFileDialog; - } - _chooseFileDialog = d; - - d->show(); -} - -/** - * Set the filename value. - * @param filename [in] The value to set. - */ -void SendFileForm::setFilename() -{ - QString filename; -#ifdef HAVE_KDE - KFileDialog *d = dynamic_cast(_chooseFileDialog); - filename = d->selectedFile(); -#else - Q3FileDialog *d = dynamic_cast(_chooseFileDialog); - filename = d->selectedFile(); -#endif - - fileLineEdit->setText(filename); -} diff --git a/src/gui/srvredirectform.cpp b/src/gui/srvredirectform.cpp new file mode 100644 index 0000000..4d95643 --- /dev/null +++ b/src/gui/srvredirectform.cpp @@ -0,0 +1,423 @@ +//Added by qt3to4: +#include + +/* + Copyright (C) 2005-2009 Michel de Boer + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "phone.h" +#include +#include +#include "gui.h" +#include "audits/memman.h" +#include "srvredirectform.h" + +/* + * Constructs a SrvRedirectForm as a child of 'parent', with the + * name 'name' and widget flags set to 'f'. + * + * The dialog will by default be modeless, unless you set 'modal' to + * true to construct a modal dialog. + */ +SrvRedirectForm::SrvRedirectForm(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl) + : QDialog(parent, name, modal, fl) +{ + setupUi(this); + + init(); +} + +/* + * Destroys the object and frees any allocated resources + */ +SrvRedirectForm::~SrvRedirectForm() +{ + destroy(); + // no need to delete child widgets, Qt does it all for us +} + +/* + * Sets the strings of the subwidgets using the current + * language. + */ +void SrvRedirectForm::languageChange() +{ + retranslateUi(this); +} + +void SrvRedirectForm::init() +{ + cfAlwaysGroupBox->setEnabled(false); + cfBusyGroupBox->setEnabled(false); + cfNoanswerGroupBox->setEnabled(false); + + // Keeps track of which address book tool button is clicked. + nrAddressBook = 0; + + getAddressForm = 0; + + // Set toolbutton icons for disabled options. + QIcon i; + i = addrAlways1ToolButton->iconSet(); + i.setPixmap(QPixmap(":/icons/images/kontact_contacts-disabled.png"), + QIcon::Automatic, QIcon::Disabled); + addrAlways1ToolButton->setIconSet(i); + addrAlways2ToolButton->setIconSet(i); + addrAlways3ToolButton->setIconSet(i); + addrBusy1ToolButton->setIconSet(i); + addrBusy2ToolButton->setIconSet(i); + addrBusy3ToolButton->setIconSet(i); + addrNoanswer1ToolButton->setIconSet(i); + addrNoanswer2ToolButton->setIconSet(i); + addrNoanswer3ToolButton->setIconSet(i); +} + +void SrvRedirectForm::destroy() +{ + if (getAddressForm) { + MEMMAN_DELETE(getAddressForm); + delete getAddressForm; + } +} + +void SrvRedirectForm::show() +{ + current_user_idx = -1; + ((t_gui *)ui)->fill_user_combo(userComboBox); + userComboBox->setEnabled(userComboBox->count() > 1); + current_user = phone->ref_users().front(); + current_user_idx = 0; + populate(); + + QDialog::show(); +} + +void SrvRedirectForm::populate() +{ + t_service *srv = phone->ref_service(current_user); + bool cf_active; + list dest_list; + int field; + + // Call forwarding unconditional + cf_active = srv->get_cf_active(CF_ALWAYS, dest_list); + cfAlwaysDst1LineEdit->clear(); + cfAlwaysDst2LineEdit->clear(); + cfAlwaysDst3LineEdit->clear(); + cfAlwaysCheckBox->setChecked(cf_active); + if (cf_active) { + field = 1; + for (list::iterator i = dest_list.begin(); i != dest_list.end(); i++) { + if (field == 1) cfAlwaysDst1LineEdit->setText(i->encode().c_str()); + if (field == 2) cfAlwaysDst2LineEdit->setText(i->encode().c_str()); + if (field == 3) cfAlwaysDst3LineEdit->setText(i->encode().c_str()); + field++; + } + } + + // Call forwarding busy + cf_active = srv->get_cf_active(CF_BUSY, dest_list); + cfBusyDst1LineEdit->clear(); + cfBusyDst2LineEdit->clear(); + cfBusyDst3LineEdit->clear(); + cfBusyCheckBox->setChecked(cf_active); + if (cf_active) { + field = 1; + for (list::iterator i = dest_list.begin(); i != dest_list.end(); i++) { + if (field == 1) cfBusyDst1LineEdit->setText(i->encode().c_str()); + if (field == 2) cfBusyDst2LineEdit->setText(i->encode().c_str()); + if (field == 3) cfBusyDst3LineEdit->setText(i->encode().c_str()); + field++; + } + } + + // Call forwarding no answer + cf_active = srv->get_cf_active(CF_NOANSWER, dest_list); + cfNoanswerDst1LineEdit->clear(); + cfNoanswerDst2LineEdit->clear(); + cfNoanswerDst3LineEdit->clear(); + cfNoanswerCheckBox->setChecked(cf_active); + if (cf_active) { + field = 1; + for (list::iterator i = dest_list.begin(); i != dest_list.end(); i++) { + if (field == 1) cfNoanswerDst1LineEdit->setText(i->encode().c_str()); + if (field == 2) cfNoanswerDst2LineEdit->setText(i->encode().c_str()); + if (field == 3) cfNoanswerDst3LineEdit->setText(i->encode().c_str()); + field++; + } + } +} + +void SrvRedirectForm::validate() +{ + if (validateValues()) { + accept(); + } else { + ((t_gui *)ui)->cb_show_msg(this, + tr("You have entered an invalid destination.").ascii(), + MSG_WARNING); + } +} + +bool SrvRedirectForm::validateValues() +{ + list cfDestAlways, cfDestBusy, cfDestNoanswer; + bool valid = false; + + // Redirect unconditional + valid = validate(cfAlwaysCheckBox->isChecked(), + cfAlwaysDst1LineEdit, cfAlwaysDst2LineEdit, cfAlwaysDst3LineEdit, + cfDestAlways); + if (!valid) { + cfTabWidget->setCurrentPage(0); + return false; + } + + // Redirect busy + valid = validate(cfBusyCheckBox->isChecked(), + cfBusyDst1LineEdit, cfBusyDst2LineEdit, cfBusyDst3LineEdit, + cfDestBusy); + if (!valid) { + cfTabWidget->setCurrentPage(1); + return false; + } + + // Redirect no answer + valid = validate(cfNoanswerCheckBox->isChecked(), + cfNoanswerDst1LineEdit, cfNoanswerDst2LineEdit, + cfNoanswerDst3LineEdit, + cfDestNoanswer); + if (!valid) { + cfTabWidget->setCurrentPage(2); + return false; + } + + emit destinations(current_user, cfDestAlways, cfDestBusy, cfDestNoanswer); + return true; +} + + +// Validate 3 destinations if cf_active is true. +// Returns true when all destinations are valid (first must be set, others may be empty) +// dest_list containst the encoded destinations when valid. +// If cf_active is false then the 3 destinations will be cleared. +bool SrvRedirectForm::validate(bool cf_active, + QLineEdit *dst1, QLineEdit *dst2, QLineEdit *dst3, + list &dest_list) +{ + t_display_url destination; + + dest_list.clear(); + + if (!cf_active) { + dst1->clear(); + dst2->clear(); + dst3->clear(); + return true; + } + + // 1st choice destination + ui->expand_destination(current_user, dst1->text().stripWhiteSpace().ascii(), destination); + if (destination.is_valid()) { + dest_list.push_back(destination); + } else { + dst1->selectAll(); + return false; + } + + // 2nd choice destination + if (!dst2->text().isEmpty()) { + ui->expand_destination(current_user, + dst2->text().stripWhiteSpace().ascii(), destination); + if (destination.is_valid()) { + dest_list.push_back(destination); + } else { + dst2->selectAll(); + return false; + } + } + + // 3rd choice destination + if (!dst3->text().isEmpty()) { + ui->expand_destination(current_user, + dst3->text().stripWhiteSpace().ascii(), destination); + if (destination.is_valid()) { + dest_list.push_back(destination); + } else { + dst3->selectAll(); + return false; + } + } + + return true; +} + +void SrvRedirectForm::toggleAlways(bool on) +{ + if (on) { + cfAlwaysGroupBox->setEnabled(true); + } else { + cfAlwaysGroupBox->setEnabled(false); + } +} + +void SrvRedirectForm::toggleBusy(bool on) +{ + if (on) { + cfBusyGroupBox->setEnabled(true); + } else { + cfBusyGroupBox->setEnabled(false); + } +} + +void SrvRedirectForm::toggleNoanswer(bool on) +{ + if (on) { + cfNoanswerGroupBox->setEnabled(true); + } else { + cfNoanswerGroupBox->setEnabled(false); + } +} + +void SrvRedirectForm::changedUser(const QString &user_profile) +{ + if (current_user_idx == -1) { + // Initializing combo box + return; + } + + t_user *new_user = phone->ref_user_profile(user_profile.ascii()); + if (!new_user) { + userComboBox->setCurrentItem(current_user_idx); + return; + } + + if (!validateValues()) { + userComboBox->setCurrentItem(current_user_idx); + ((t_gui *)ui)->cb_show_msg(this, + tr("You have entered an invalid destination.").ascii(), + MSG_WARNING); + return; + } + + // Change current user + current_user_idx = userComboBox->currentItem(); + current_user = new_user; + populate(); +} + +void SrvRedirectForm::showAddressBook() +{ + if (!getAddressForm) { + getAddressForm = new GetAddressForm( + this, "select address", true); + MEMMAN_NEW(getAddressForm); + } + + connect(getAddressForm, + SIGNAL(address(const QString &)), + this, SLOT(selectedAddress(const QString &))); + + getAddressForm->show(); +} + +void SrvRedirectForm::showAddressBook1() +{ + nrAddressBook = 1; + showAddressBook(); +} + +void SrvRedirectForm::showAddressBook2() +{ + nrAddressBook = 2; + showAddressBook(); +} + +void SrvRedirectForm::showAddressBook3() +{ + nrAddressBook = 3; + showAddressBook(); +} + +void SrvRedirectForm::showAddressBook4() +{ + nrAddressBook = 4; + showAddressBook(); +} + +void SrvRedirectForm::showAddressBook5() +{ + nrAddressBook = 5; + showAddressBook(); +} + +void SrvRedirectForm::showAddressBook6() +{ + nrAddressBook = 6; + showAddressBook(); +} + +void SrvRedirectForm::showAddressBook7() +{ + nrAddressBook = 7; + showAddressBook(); +} + +void SrvRedirectForm::showAddressBook8() +{ + nrAddressBook = 8; + showAddressBook(); +} + +void SrvRedirectForm::showAddressBook9() +{ + nrAddressBook = 9; + showAddressBook(); +} + +void SrvRedirectForm::selectedAddress(const QString &address) +{ + switch(nrAddressBook) { + case 1: + cfAlwaysDst1LineEdit->setText(address); + break; + case 2: + cfAlwaysDst2LineEdit->setText(address); + break; + case 3: + cfAlwaysDst3LineEdit->setText(address); + break; + case 4: + cfBusyDst1LineEdit->setText(address); + break; + case 5: + cfBusyDst2LineEdit->setText(address); + break; + case 6: + cfBusyDst3LineEdit->setText(address); + break; + case 7: + cfNoanswerDst1LineEdit->setText(address); + break; + case 8: + cfNoanswerDst2LineEdit->setText(address); + break; + case 9: + cfNoanswerDst3LineEdit->setText(address); + break; + } +} diff --git a/src/gui/srvredirectform.h b/src/gui/srvredirectform.h new file mode 100644 index 0000000..7ddaef6 --- /dev/null +++ b/src/gui/srvredirectform.h @@ -0,0 +1,63 @@ +#ifndef SRVREDIRECTFORM_H +#define SRVREDIRECTFORM_H +#include +#include "getaddressform.h" +#include "phone.h" +#include +#include "sockets/url.h" +#include "user.h" +#include "ui_srvredirectform.h" + +class t_phone; +extern t_phone *phone; + +class SrvRedirectForm : public QDialog, public Ui::SrvRedirectForm +{ + Q_OBJECT + +public: + SrvRedirectForm(QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WindowFlags fl = 0); + ~SrvRedirectForm(); + + virtual bool validateValues(); + virtual bool validate( bool cf_active, QLineEdit * dst1, QLineEdit * dst2, QLineEdit * dst3, list & dest_list ); + +public slots: + virtual void show(); + virtual void populate(); + virtual void validate(); + virtual void toggleAlways( bool on ); + virtual void toggleBusy( bool on ); + virtual void toggleNoanswer( bool on ); + virtual void changedUser( const QString & user_display_uri ); + virtual void showAddressBook(); + virtual void showAddressBook1(); + virtual void showAddressBook2(); + virtual void showAddressBook3(); + virtual void showAddressBook4(); + virtual void showAddressBook5(); + virtual void showAddressBook6(); + virtual void showAddressBook7(); + virtual void showAddressBook8(); + virtual void showAddressBook9(); + virtual void selectedAddress( const QString & address ); + +signals: + void destinations(t_user *, const list &always, const list &busy, const list &noanswer); + +protected slots: + virtual void languageChange(); + +private: + int nrAddressBook; + GetAddressForm *getAddressForm; + t_user *current_user; + int current_user_idx; + + void init(); + void destroy(); + +}; + + +#endif diff --git a/src/gui/srvredirectform.ui b/src/gui/srvredirectform.ui index 1af6ccd..07efe07 100644 --- a/src/gui/srvredirectform.ui +++ b/src/gui/srvredirectform.ui @@ -173,7 +173,7 @@ F10 - kontact_contacts.png + :/icons/images/kontact_contacts.png Address book @@ -192,7 +192,7 @@ F11 - kontact_contacts.png + :/icons/images/kontact_contacts.png Address book @@ -214,7 +214,7 @@ F12 - kontact_contacts.png + :/icons/images/kontact_contacts.png Address book @@ -331,7 +331,7 @@ - kontact_contacts.png + :/icons/images/kontact_contacts.png Address book @@ -347,7 +347,7 @@ - kontact_contacts.png + :/icons/images/kontact_contacts.png Address book @@ -363,7 +363,7 @@ - kontact_contacts.png + :/icons/images/kontact_contacts.png Address book @@ -480,7 +480,7 @@ - kontact_contacts.png + :/icons/images/kontact_contacts.png Address book @@ -496,7 +496,7 @@ - kontact_contacts.png + :/icons/images/kontact_contacts.png Address book @@ -512,7 +512,7 @@ - kontact_contacts.png + :/icons/images/kontact_contacts.png Address book diff --git a/src/gui/srvredirectform.ui.h b/src/gui/srvredirectform.ui.h deleted file mode 100644 index 47bc0eb..0000000 --- a/src/gui/srvredirectform.ui.h +++ /dev/null @@ -1,391 +0,0 @@ -//Added by qt3to4: -#include -/**************************************************************************** -** ui.h extension file, included from the uic-generated form implementation. -** -** If you wish to add, delete or rename functions or slots use -** Qt Designer which will update this file, preserving your code. Create an -** init() function in place of a constructor, and a destroy() function in -** place of a destructor. -*****************************************************************************/ -/* - Copyright (C) 2005-2009 Michel de Boer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - - -void SrvRedirectForm::init() -{ - cfAlwaysGroupBox->setEnabled(false); - cfBusyGroupBox->setEnabled(false); - cfNoanswerGroupBox->setEnabled(false); - - // Keeps track of which address book tool button is clicked. - nrAddressBook = 0; - - getAddressForm = 0; - - // Set toolbutton icons for disabled options. - QIcon i; - i = addrAlways1ToolButton->iconSet(); - i.setPixmap(qPixmapFromMimeSource("kontact_contacts-disabled.png"), - QIcon::Automatic, QIcon::Disabled); - addrAlways1ToolButton->setIconSet(i); - addrAlways2ToolButton->setIconSet(i); - addrAlways3ToolButton->setIconSet(i); - addrBusy1ToolButton->setIconSet(i); - addrBusy2ToolButton->setIconSet(i); - addrBusy3ToolButton->setIconSet(i); - addrNoanswer1ToolButton->setIconSet(i); - addrNoanswer2ToolButton->setIconSet(i); - addrNoanswer3ToolButton->setIconSet(i); -} - -void SrvRedirectForm::destroy() -{ - if (getAddressForm) { - MEMMAN_DELETE(getAddressForm); - delete getAddressForm; - } -} - -void SrvRedirectForm::show() -{ - current_user_idx = -1; - ((t_gui *)ui)->fill_user_combo(userComboBox); - userComboBox->setEnabled(userComboBox->count() > 1); - current_user = phone->ref_users().front(); - current_user_idx = 0; - populate(); - - QDialog::show(); -} - -void SrvRedirectForm::populate() -{ - t_service *srv = phone->ref_service(current_user); - bool cf_active; - list dest_list; - int field; - - // Call forwarding unconditional - cf_active = srv->get_cf_active(CF_ALWAYS, dest_list); - cfAlwaysDst1LineEdit->clear(); - cfAlwaysDst2LineEdit->clear(); - cfAlwaysDst3LineEdit->clear(); - cfAlwaysCheckBox->setChecked(cf_active); - if (cf_active) { - field = 1; - for (list::iterator i = dest_list.begin(); i != dest_list.end(); i++) { - if (field == 1) cfAlwaysDst1LineEdit->setText(i->encode().c_str()); - if (field == 2) cfAlwaysDst2LineEdit->setText(i->encode().c_str()); - if (field == 3) cfAlwaysDst3LineEdit->setText(i->encode().c_str()); - field++; - } - } - - // Call forwarding busy - cf_active = srv->get_cf_active(CF_BUSY, dest_list); - cfBusyDst1LineEdit->clear(); - cfBusyDst2LineEdit->clear(); - cfBusyDst3LineEdit->clear(); - cfBusyCheckBox->setChecked(cf_active); - if (cf_active) { - field = 1; - for (list::iterator i = dest_list.begin(); i != dest_list.end(); i++) { - if (field == 1) cfBusyDst1LineEdit->setText(i->encode().c_str()); - if (field == 2) cfBusyDst2LineEdit->setText(i->encode().c_str()); - if (field == 3) cfBusyDst3LineEdit->setText(i->encode().c_str()); - field++; - } - } - - // Call forwarding no answer - cf_active = srv->get_cf_active(CF_NOANSWER, dest_list); - cfNoanswerDst1LineEdit->clear(); - cfNoanswerDst2LineEdit->clear(); - cfNoanswerDst3LineEdit->clear(); - cfNoanswerCheckBox->setChecked(cf_active); - if (cf_active) { - field = 1; - for (list::iterator i = dest_list.begin(); i != dest_list.end(); i++) { - if (field == 1) cfNoanswerDst1LineEdit->setText(i->encode().c_str()); - if (field == 2) cfNoanswerDst2LineEdit->setText(i->encode().c_str()); - if (field == 3) cfNoanswerDst3LineEdit->setText(i->encode().c_str()); - field++; - } - } -} - -void SrvRedirectForm::validate() -{ - if (validateValues()) { - accept(); - } else { - ((t_gui *)ui)->cb_show_msg(this, - tr("You have entered an invalid destination.").ascii(), - MSG_WARNING); - } -} - -bool SrvRedirectForm::validateValues() -{ - list cfDestAlways, cfDestBusy, cfDestNoanswer; - bool valid = false; - - // Redirect unconditional - valid = validate(cfAlwaysCheckBox->isChecked(), - cfAlwaysDst1LineEdit, cfAlwaysDst2LineEdit, cfAlwaysDst3LineEdit, - cfDestAlways); - if (!valid) { - cfTabWidget->setCurrentPage(0); - return false; - } - - // Redirect busy - valid = validate(cfBusyCheckBox->isChecked(), - cfBusyDst1LineEdit, cfBusyDst2LineEdit, cfBusyDst3LineEdit, - cfDestBusy); - if (!valid) { - cfTabWidget->setCurrentPage(1); - return false; - } - - // Redirect no answer - valid = validate(cfNoanswerCheckBox->isChecked(), - cfNoanswerDst1LineEdit, cfNoanswerDst2LineEdit, - cfNoanswerDst3LineEdit, - cfDestNoanswer); - if (!valid) { - cfTabWidget->setCurrentPage(2); - return false; - } - - emit destinations(current_user, cfDestAlways, cfDestBusy, cfDestNoanswer); - return true; -} - - -// Validate 3 destinations if cf_active is true. -// Returns true when all destinations are valid (first must be set, others may be empty) -// dest_list containst the encoded destinations when valid. -// If cf_active is false then the 3 destinations will be cleared. -bool SrvRedirectForm::validate(bool cf_active, - QLineEdit *dst1, QLineEdit *dst2, QLineEdit *dst3, - list &dest_list) -{ - t_display_url destination; - - dest_list.clear(); - - if (!cf_active) { - dst1->clear(); - dst2->clear(); - dst3->clear(); - return true; - } - - // 1st choice destination - ui->expand_destination(current_user, dst1->text().stripWhiteSpace().ascii(), destination); - if (destination.is_valid()) { - dest_list.push_back(destination); - } else { - dst1->selectAll(); - return false; - } - - // 2nd choice destination - if (!dst2->text().isEmpty()) { - ui->expand_destination(current_user, - dst2->text().stripWhiteSpace().ascii(), destination); - if (destination.is_valid()) { - dest_list.push_back(destination); - } else { - dst2->selectAll(); - return false; - } - } - - // 3rd choice destination - if (!dst3->text().isEmpty()) { - ui->expand_destination(current_user, - dst3->text().stripWhiteSpace().ascii(), destination); - if (destination.is_valid()) { - dest_list.push_back(destination); - } else { - dst3->selectAll(); - return false; - } - } - - return true; -} - -void SrvRedirectForm::toggleAlways(bool on) -{ - if (on) { - cfAlwaysGroupBox->setEnabled(true); - } else { - cfAlwaysGroupBox->setEnabled(false); - } -} - -void SrvRedirectForm::toggleBusy(bool on) -{ - if (on) { - cfBusyGroupBox->setEnabled(true); - } else { - cfBusyGroupBox->setEnabled(false); - } -} - -void SrvRedirectForm::toggleNoanswer(bool on) -{ - if (on) { - cfNoanswerGroupBox->setEnabled(true); - } else { - cfNoanswerGroupBox->setEnabled(false); - } -} - -void SrvRedirectForm::changedUser(const QString &user_profile) -{ - if (current_user_idx == -1) { - // Initializing combo box - return; - } - - t_user *new_user = phone->ref_user_profile(user_profile.ascii()); - if (!new_user) { - userComboBox->setCurrentItem(current_user_idx); - return; - } - - if (!validateValues()) { - userComboBox->setCurrentItem(current_user_idx); - ((t_gui *)ui)->cb_show_msg(this, - tr("You have entered an invalid destination.").ascii(), - MSG_WARNING); - return; - } - - // Change current user - current_user_idx = userComboBox->currentItem(); - current_user = new_user; - populate(); -} - -void SrvRedirectForm::showAddressBook() -{ - if (!getAddressForm) { - getAddressForm = new GetAddressForm( - this, "select address", true); - MEMMAN_NEW(getAddressForm); - } - - connect(getAddressForm, - SIGNAL(address(const QString &)), - this, SLOT(selectedAddress(const QString &))); - - getAddressForm->show(); -} - -void SrvRedirectForm::showAddressBook1() -{ - nrAddressBook = 1; - showAddressBook(); -} - -void SrvRedirectForm::showAddressBook2() -{ - nrAddressBook = 2; - showAddressBook(); -} - -void SrvRedirectForm::showAddressBook3() -{ - nrAddressBook = 3; - showAddressBook(); -} - -void SrvRedirectForm::showAddressBook4() -{ - nrAddressBook = 4; - showAddressBook(); -} - -void SrvRedirectForm::showAddressBook5() -{ - nrAddressBook = 5; - showAddressBook(); -} - -void SrvRedirectForm::showAddressBook6() -{ - nrAddressBook = 6; - showAddressBook(); -} - -void SrvRedirectForm::showAddressBook7() -{ - nrAddressBook = 7; - showAddressBook(); -} - -void SrvRedirectForm::showAddressBook8() -{ - nrAddressBook = 8; - showAddressBook(); -} - -void SrvRedirectForm::showAddressBook9() -{ - nrAddressBook = 9; - showAddressBook(); -} - -void SrvRedirectForm::selectedAddress(const QString &address) -{ - switch(nrAddressBook) { - case 1: - cfAlwaysDst1LineEdit->setText(address); - break; - case 2: - cfAlwaysDst2LineEdit->setText(address); - break; - case 3: - cfAlwaysDst3LineEdit->setText(address); - break; - case 4: - cfBusyDst1LineEdit->setText(address); - break; - case 5: - cfBusyDst2LineEdit->setText(address); - break; - case 6: - cfBusyDst3LineEdit->setText(address); - break; - case 7: - cfNoanswerDst1LineEdit->setText(address); - break; - case 8: - cfNoanswerDst2LineEdit->setText(address); - break; - case 9: - cfNoanswerDst3LineEdit->setText(address); - break; - } -} diff --git a/src/gui/syssettingsform.cpp b/src/gui/syssettingsform.cpp new file mode 100644 index 0000000..a6b940c --- /dev/null +++ b/src/gui/syssettingsform.cpp @@ -0,0 +1,528 @@ +//Added by qt3to4: +#include +#include +#include +#include "gui.h" +#include "sockets/interfaces.h" +#include "selectprofileform.h" +#include +#include "audits/memman.h" +#include +#include +#include +#include +#include "twinkle_config.h" +#include +#include +#include "syssettingsform.h" +/* + * Constructs a SysSettingsForm as a child of 'parent', with the + * name 'name' and widget flags set to 'f'. + * + * The dialog will by default be modeless, unless you set 'modal' to + * true to construct a modal dialog. + */ +SysSettingsForm::SysSettingsForm(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl) + : QDialog(parent, name, modal, fl) +{ + setupUi(this); + + init(); +} + +/* + * Destroys the object and frees any allocated resources + */ +SysSettingsForm::~SysSettingsForm() +{ + // no need to delete child widgets, Qt does it all for us +} + +/* + * Sets the strings of the subwidgets using the current + * language. + */ +void SysSettingsForm::languageChange() +{ + retranslateUi(this); +} + + +/* + Copyright (C) 2005-2009 Michel de Boer + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +// Indices of categories in the category list box +#define idxCatGeneral 0 +#define idxCatAudio 1 +#define idxCatRingtones 2 +#define idxCatAddressBook 3 +#define idxCatNetwork 4 +#define idxCatLog 5 + +void SysSettingsForm::init() +{ + // Set toolbutton icons for disabled options. + QIcon i; + i = openRingtoneToolButton->iconSet(); + i.setPixmap(QPixmap(":/icons/images/fileopen-disabled.png"), + QIcon::Automatic, QIcon::Disabled); + openRingtoneToolButton->setIconSet(i); + i = openRingbackToolButton->iconSet(); + i.setPixmap(QPixmap(":/icons/images/fileopen-disabled.png"), + QIcon::Automatic, QIcon::Disabled); + openRingbackToolButton->setIconSet(i); + + QRegExp rxNumber("[0-9]+"); + maxUdpSizeLineEdit->setValidator(new QRegExpValidator(rxNumber, this)); + maxTcpSizeLineEdit->setValidator(new QRegExpValidator(rxNumber, this)); +} + +void SysSettingsForm::showCategory( int index ) +{ + if (index == idxCatGeneral) { + settingsWidgetStack->raiseWidget(pageGeneral); + } else if (index == idxCatAudio) { + settingsWidgetStack->raiseWidget(pageAudio); + } else if (index == idxCatRingtones) { + settingsWidgetStack->raiseWidget(pageRingtones); + } else if (index == idxCatAddressBook) { + settingsWidgetStack->raiseWidget(pageAddressBook); + } else if (index == idxCatNetwork) { + settingsWidgetStack->raiseWidget(pageNetwork); + } else if (index == idxCatLog) { + settingsWidgetStack->raiseWidget(pageLog); + } +} + +string SysSettingsForm::comboItem2audio_dev(QString item, QLineEdit *qleOther, bool playback) +{ + if (item == QString("ALSA: ") + DEV_OTHER) { + if (qleOther->text().isEmpty()) return ""; + return (QString(PFX_ALSA) + qleOther->text()).ascii(); + } + + if (item == QString("OSS: ") + DEV_OTHER) { + if (qleOther->text().isEmpty()) return ""; + return (QString(PFX_OSS) + qleOther->text()).ascii(); + } + + list &list_audio_dev = (playback ? + list_audio_playback_dev : list_audio_capture_dev); + + for (list::iterator i = list_audio_dev.begin(); + i != list_audio_dev.end(); i++) + { + if (i->get_description() == item.ascii()) { + return i->get_settings_value(); + } + } + + return ""; +} + +void SysSettingsForm::populateComboBox(QComboBox *cb, const QString &s) +{ + for (int i = 0; i < cb->count(); i++) { + if (cb->text(i) == s) { + cb->setCurrentItem(i); + return; + } + } +} + +void SysSettingsForm::populate() +{ + QString msg; + int idx; + + // Select the Audio category + categoryListBox->setSelected(idxCatGeneral, true); + settingsWidgetStack->raiseWidget(pageGeneral); + + // Set focus on first field + categoryListBox->setFocus(); + + // Audio settings + list_audio_playback_dev = sys_config->get_audio_devices(true); + list_audio_capture_dev = sys_config->get_audio_devices(false); + ringtoneComboBox->clear(); + speakerComboBox->clear(); + micComboBox->clear(); + bool devRingtoneFound = false; + bool devSpeakerFound = false; + bool devMicFound = false; + + // Playback devices + idx = 0; + for (list::iterator i = list_audio_playback_dev.begin(); + i != list_audio_playback_dev.end(); i++, idx++) { + string item = i->get_description(); + ringtoneComboBox->insertItem(QString(item.c_str())); + speakerComboBox->insertItem(QString(item.c_str())); + + // Select audio device + if (sys_config->get_dev_ringtone().device == i->device) { + ringtoneComboBox->setCurrentItem(idx); + otherRingtoneLineEdit->clear(); + devRingtoneFound = true; + } + if (sys_config->get_dev_speaker().device == i->device) { + speakerComboBox->setCurrentItem(idx); + otherSpeakerLineEdit->clear(); + devSpeakerFound = true; + } + + // Determine index for other non-standard device + if (i->device == DEV_OTHER) { + if (i->type == t_audio_device::ALSA) { + idxOtherPlaybackDevAlsa = idx; + } else { + idxOtherPlaybackDevOss = idx; + } + } + } + + // Check for non-standard audio devices + if (!devRingtoneFound) { + t_audio_device dev = sys_config->get_dev_ringtone(); + otherRingtoneLineEdit->setText(dev.device.c_str()); + ringtoneComboBox->setCurrentItem( + (dev.type == t_audio_device::ALSA ? idxOtherPlaybackDevAlsa : idxOtherPlaybackDevOss)); + } + if (!devSpeakerFound) { + t_audio_device dev = sys_config->get_dev_speaker(); + otherSpeakerLineEdit->setText(dev.device.c_str()); + speakerComboBox->setCurrentItem( + (dev.type == t_audio_device::ALSA ? idxOtherPlaybackDevAlsa : idxOtherPlaybackDevOss)); + } + + // Capture device + idx = 0; + for (list::iterator i = list_audio_capture_dev.begin(); + i != list_audio_capture_dev.end(); i++, idx++) { + string item = i->get_description(); + micComboBox->insertItem(QString(item.c_str())); + + // Select audio device + if (sys_config->get_dev_mic().device == i->device) { + micComboBox->setCurrentItem(idx); + otherMicLineEdit->clear(); + devMicFound = true; + } + + // Determine index for other non-standard device + if (i->device == DEV_OTHER) { + if (i->type == t_audio_device::ALSA) { + idxOtherCaptureDevAlsa = idx; + } else { + idxOtherCaptureDevOss = idx; + } + } + } + + // Check for non-standard audio devices + if (!devMicFound) { + t_audio_device dev = sys_config->get_dev_mic(); + otherMicLineEdit->setText(dev.device.c_str()); + micComboBox->setCurrentItem( + (dev.type == t_audio_device::ALSA ? idxOtherCaptureDevAlsa : idxOtherCaptureDevOss)); + } + + // Enable/disable line edit for non-standard device + devRingtoneSelected(ringtoneComboBox->currentItem()); + devSpeakerSelected(speakerComboBox->currentItem()); + devMicSelected(micComboBox->currentItem()); + + validateAudioCheckBox->setChecked(sys_config->get_validate_audio_dev()); + + populateComboBox(ossFragmentComboBox, + QString::number(sys_config->get_oss_fragment_size())); + populateComboBox(alsaPlayPeriodComboBox, + QString::number(sys_config->get_alsa_play_period_size())); + populateComboBox(alsaCapturePeriodComboBox, + QString::number(sys_config->get_alsa_capture_period_size())); + + // Log settings + logMaxSizeSpinBox->setValue(sys_config->get_log_max_size()); + logDebugCheckBox->setChecked(sys_config->get_log_show_debug()); + logSipCheckBox->setChecked(sys_config->get_log_show_sip()); + logStunCheckBox->setChecked(sys_config->get_log_show_stun()); + logMemoryCheckBox->setChecked(sys_config->get_log_show_memory()); + + // General settings + guiUseSystrayCheckBox->setChecked(sys_config->get_gui_use_systray()); + guiHideCheckBox->setChecked(sys_config->get_gui_hide_on_close()); + guiHideCheckBox->setEnabled(sys_config->get_gui_use_systray()); + + // Call history + histSizeSpinBox->setValue(sys_config->get_ch_max_size()); + + // Auto show on incoming call + autoShowCheckBox->setChecked(sys_config->get_gui_auto_show_incoming()); + autoShowTimeoutSpinBox->setValue(sys_config->get_gui_auto_show_timeout()); + + // Services + callWaitingCheckBox->setChecked(sys_config->get_call_waiting()); + hangupBothCheckBox->setChecked(sys_config->get_hangup_both_3way()); + + // Startup settings + startHiddenCheckBox->setChecked(sys_config->get_start_hidden()); + + QStringList profiles; + if (!SelectProfileForm::getUserProfiles(profiles, msg)) { + ((t_gui *)ui)->cb_show_msg(this, msg.ascii(), MSG_CRITICAL); + } + profileListView->clear(); + for (QStringList::Iterator i = profiles.begin(); i != profiles.end(); i++) { + // Strip off the .cfg suffix + QString profile = *i; + profile.truncate(profile.length() - 4); + Q3CheckListItem *item = new Q3CheckListItem(profileListView, + profile, Q3CheckListItem::CheckBox); + item->setPixmap(0, QPixmap(":/icons/images/penguin-small.png")); + + list l = sys_config->get_start_user_profiles(); + if (std::find(l.begin(), l.end(), profile.ascii()) != l.end()) + { + item->setOn(true); + } + } + + // Web browser command + browserLineEdit->setText(sys_config->get_gui_browser_cmd().c_str()); + + // Network settings + sipUdpPortSpinBox->setValue(sys_config->get_config_sip_port()); + rtpPortSpinBox->setValue(sys_config->get_rtp_port()); + + maxUdpSizeLineEdit->setText(QString::number(sys_config->get_sip_max_udp_size())); + maxTcpSizeLineEdit->setText(QString::number(sys_config->get_sip_max_tcp_size())); + + // Ring tone settings + playRingtoneCheckBox->setChecked(sys_config->get_play_ringtone()); + defaultRingtoneRadioButton->setChecked(sys_config->get_ringtone_file().empty()); + customRingtoneRadioButton->setChecked(!sys_config->get_ringtone_file().empty()); + ringtoneLineEdit->setText(sys_config->get_ringtone_file().c_str()); + defaultRingtoneRadioButton->setEnabled(sys_config->get_play_ringtone()); + customRingtoneRadioButton->setEnabled(sys_config->get_play_ringtone()); + ringtoneLineEdit->setEnabled(!sys_config->get_ringtone_file().empty()); + openRingtoneToolButton->setEnabled(!sys_config->get_ringtone_file().empty()); + + playRingbackCheckBox->setChecked(sys_config->get_play_ringback()); + defaultRingbackRadioButton->setChecked(sys_config->get_ringback_file().empty()); + customRingbackRadioButton->setChecked(!sys_config->get_ringback_file().empty()); + ringbackLineEdit->setText(sys_config->get_ringback_file().c_str()); + defaultRingbackRadioButton->setEnabled(sys_config->get_play_ringback()); + customRingbackRadioButton->setEnabled(sys_config->get_play_ringback()); + ringbackLineEdit->setEnabled(!sys_config->get_ringback_file().empty()); + openRingbackToolButton->setEnabled(!sys_config->get_ringback_file().empty()); + + // Address book settings + abLookupNameCheckBox->setChecked(sys_config->get_ab_lookup_name()); + abOverrideDisplayCheckBox->setChecked(sys_config->get_ab_override_display()); + abOverrideDisplayCheckBox->setEnabled(sys_config->get_ab_lookup_name()); + abLookupPhotoCheckBox->setChecked(sys_config->get_ab_lookup_photo()); +} + +void SysSettingsForm::validate() +{ + bool conversion_ok = false; + unsigned short sip_max_udp_size = maxUdpSizeLineEdit->text().toUShort(&conversion_ok); + if (!conversion_ok) sip_max_udp_size = sys_config->get_sip_max_udp_size(); + + unsigned long sip_max_tcp_size = maxTcpSizeLineEdit->text().toULong(&conversion_ok); + if (!conversion_ok) sip_max_tcp_size = sys_config->get_sip_max_tcp_size(); + + // Audio + string dev; + dev = comboItem2audio_dev(ringtoneComboBox->currentText(), otherRingtoneLineEdit, true); + if (dev != "") sys_config->set_dev_ringtone(sys_config->audio_device(dev)); + dev = comboItem2audio_dev(speakerComboBox->currentText(), otherSpeakerLineEdit, true); + if (dev != "") sys_config->set_dev_speaker(sys_config->audio_device(dev)); + dev = comboItem2audio_dev(micComboBox->currentText(), otherMicLineEdit, false); + if (dev != "") sys_config->set_dev_mic(sys_config->audio_device(dev)); + + sys_config->set_validate_audio_dev(validateAudioCheckBox->isChecked()); + + sys_config->set_oss_fragment_size( + ossFragmentComboBox->currentText().toInt()); + sys_config->set_alsa_play_period_size( + alsaPlayPeriodComboBox->currentText().toInt()); + sys_config->set_alsa_capture_period_size( + alsaCapturePeriodComboBox->currentText().toInt()); + + // Log + sys_config->set_log_max_size(logMaxSizeSpinBox->value()); + sys_config->set_log_show_debug(logDebugCheckBox->isChecked()); + sys_config->set_log_show_sip(logSipCheckBox->isChecked()); + sys_config->set_log_show_stun(logStunCheckBox->isChecked()); + sys_config->set_log_show_memory(logMemoryCheckBox->isChecked()); + + // General + sys_config->set_gui_use_systray(guiUseSystrayCheckBox->isChecked()); + sys_config->set_gui_hide_on_close(guiHideCheckBox->isChecked()); + + // Auto show on incoming call + sys_config->set_gui_auto_show_incoming(autoShowCheckBox->isChecked()); + sys_config->set_gui_auto_show_timeout(autoShowTimeoutSpinBox->value()); + + // Call history + sys_config->set_ch_max_size(histSizeSpinBox->value()); + + // Services + sys_config->set_call_waiting(callWaitingCheckBox->isChecked()); + sys_config->set_hangup_both_3way(hangupBothCheckBox->isChecked()); + + // Startup + sys_config->set_start_hidden(startHiddenCheckBox->isChecked() && + guiUseSystrayCheckBox->isChecked()); + + list start_user_profiles; + Q3ListViewItemIterator i(profileListView, Q3ListViewItemIterator::Checked); + while (i.current()) { + Q3CheckListItem *item = (Q3CheckListItem *)i.current(); + start_user_profiles.push_back(item->text().ascii()); + i++; + } + sys_config->set_start_user_profiles(start_user_profiles); + + // Web browser command + sys_config->set_gui_browser_cmd(browserLineEdit->text().stripWhiteSpace().ascii()); + + // Network + if (sys_config->get_config_sip_port() != sipUdpPortSpinBox->value()) { + sys_config->set_config_sip_port(sipUdpPortSpinBox->value()); + emit sipUdpPortChanged(); + } + if (sys_config->get_rtp_port() != rtpPortSpinBox->value()) { + sys_config->set_rtp_port(rtpPortSpinBox->value()); + emit rtpPortChanged(); + } + sys_config->set_sip_max_udp_size(sip_max_udp_size); + sys_config->set_sip_max_tcp_size(sip_max_tcp_size); + + // Ring tones + sys_config->set_play_ringtone(playRingtoneCheckBox->isChecked()); + if (sys_config->get_play_ringtone()) { + if (defaultRingtoneRadioButton->isOn()) { + sys_config->set_ringtone_file(""); + } else { + sys_config->set_ringtone_file(ringtoneLineEdit-> + text().stripWhiteSpace().ascii()); + } + } else { + sys_config->set_ringtone_file(""); + } + + sys_config->set_play_ringback(playRingbackCheckBox->isChecked()); + if (sys_config->get_play_ringback()) { + if (defaultRingbackRadioButton->isOn()) { + sys_config->set_ringback_file(""); + } else { + sys_config->set_ringback_file(ringbackLineEdit-> + text().stripWhiteSpace().ascii()); + } + } else { + sys_config->set_ringback_file(""); + } + + // Address book settings + sys_config->set_ab_lookup_name(abLookupNameCheckBox->isChecked()); + sys_config->set_ab_override_display(abOverrideDisplayCheckBox->isChecked()); + sys_config->set_ab_lookup_photo(abLookupPhotoCheckBox->isChecked()); + + // Save user config + string error_msg; + if (!sys_config->write_config(error_msg)) { + // Failed to write config file + ((t_gui *)ui)->cb_show_msg(this, error_msg, MSG_CRITICAL); + return; + } + + accept(); +} + +void SysSettingsForm::show() +{ + populate(); + QDialog::show(); +} + +int SysSettingsForm::exec() +{ + populate(); + return QDialog::exec(); +} + +void SysSettingsForm::chooseRingtone() +{ + QString file = Q3FileDialog::getOpenFileName( + ((t_gui *)ui)->get_last_file_browse_path(), + tr("Ring tones", "Description of .wav files in file dialog").append(" (*.wav)"), this, "ring tone file dialog", + tr("Choose ring tone")); + if (!file.isEmpty()) { + ringtoneLineEdit->setText(file); + ((t_gui *)ui)->set_last_file_browse_path(QFileInfo(file).dirPath(true)); + } +} + +void SysSettingsForm::chooseRingback() +{ + QString file = Q3FileDialog::getOpenFileName( + ((t_gui *)ui)->get_last_file_browse_path(), + tr("Ring back tones", "Description of .wav files in file dialog").append(" (*.wav)"), this, "ring back file dialog", + tr("Choose ring back tone")); + if (!file.isEmpty()) { + ringbackLineEdit->setText(file); + ((t_gui *)ui)->set_last_file_browse_path(QFileInfo(file).dirPath(true)); + } +} + +void SysSettingsForm::devRingtoneSelected(int idx) { + bool b = (idx == idxOtherPlaybackDevAlsa || idx == idxOtherPlaybackDevOss); + otherRingtoneTextLabel->setEnabled(b); + otherRingtoneLineEdit->setEnabled(b); +} + +void SysSettingsForm::devSpeakerSelected(int idx) { + bool b = (idx == idxOtherPlaybackDevAlsa || idx == idxOtherPlaybackDevOss); + otherSpeakerTextLabel->setEnabled(b); + otherSpeakerLineEdit->setEnabled(b); +} + +void SysSettingsForm::devMicSelected(int idx) { + bool b = (idx == idxOtherCaptureDevAlsa || idx == idxOtherCaptureDevOss); + otherMicTextLabel->setEnabled(b); + otherMicLineEdit->setEnabled(b); +} + +void SysSettingsForm::playRingToneCheckBoxToggles(bool on) { + if (on) { + ringtoneLineEdit->setEnabled(customRingtoneRadioButton->isChecked()); + } else { + ringtoneLineEdit->setEnabled(false); + } +} + +void SysSettingsForm::playRingBackToneCheckBoxToggles(bool on) { + if (on) { + ringbackLineEdit->setEnabled(customRingbackRadioButton->isChecked()); + } else { + ringbackLineEdit->setEnabled(false); + } +} diff --git a/src/gui/syssettingsform.h b/src/gui/syssettingsform.h new file mode 100644 index 0000000..5412219 --- /dev/null +++ b/src/gui/syssettingsform.h @@ -0,0 +1,53 @@ +#ifndef SYSSETTINGSFORM_H +#define SYSSETTINGSFORM_H + +#include "sys_settings.h" +#include +#include "ui_syssettingsform.h" + +class SysSettingsForm : public QDialog, public Ui::SysSettingsForm +{ + Q_OBJECT + +public: + SysSettingsForm(QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WindowFlags fl = 0); + ~SysSettingsForm(); + + virtual string comboItem2audio_dev( QString item, QLineEdit * qleOther, bool playback ); + +public slots: + virtual void showCategory( int index ); + virtual void populateComboBox( QComboBox * cb, const QString & s ); + virtual void populate(); + virtual void validate(); + virtual void show(); + virtual int exec(); + virtual void chooseRingtone(); + virtual void chooseRingback(); + virtual void devRingtoneSelected( int idx ); + virtual void devSpeakerSelected( int idx ); + virtual void devMicSelected( int idx ); + virtual void playRingToneCheckBoxToggles( bool on ); + virtual void playRingBackToneCheckBoxToggles( bool on ); + +signals: + void sipUdpPortChanged(); + void rtpPortChanged(); + +protected slots: + virtual void languageChange(); + +private: + int idxOtherCaptureDevOss; + int idxOtherCaptureDevAlsa; + int idxOtherPlaybackDevOss; + int idxOtherPlaybackDevAlsa; + list list_audio_playback_dev; + list list_audio_capture_dev; + + void init(); + +}; + + +#endif diff --git a/src/gui/syssettingsform.ui b/src/gui/syssettingsform.ui index bfe8807..2af1e4d 100644 --- a/src/gui/syssettingsform.ui +++ b/src/gui/syssettingsform.ui @@ -35,7 +35,7 @@ General - twinkle32.png + :/icons/images/twinkle32.png @@ -43,7 +43,7 @@ Audio - kmix.png + :/icons/images/kmix.png @@ -51,7 +51,7 @@ Ring tones - knotify.png + :/icons/images/knotify.png @@ -59,7 +59,7 @@ Address book - kontact_contacts32.png + :/icons/images/kontact_contacts32.png @@ -67,7 +67,7 @@ Network - network.png + :/icons/images/network.png @@ -75,7 +75,7 @@ Log - log.png + :/icons/images/log.png @@ -1221,7 +1221,7 @@ If before answering a call, the microphone or speaker appears to be invalid, a w - fileopen.png + :/icons/images/fileopen.png Select ring tone file. @@ -1320,7 +1320,7 @@ Depending on your SIP provider the network might provide ring back tone or an an - fileopen.png + :/icons/images/fileopen.png Select ring back tone file. diff --git a/src/gui/syssettingsform.ui.h b/src/gui/syssettingsform.ui.h deleted file mode 100644 index e454dce..0000000 --- a/src/gui/syssettingsform.ui.h +++ /dev/null @@ -1,491 +0,0 @@ -//Added by qt3to4: -#include -/**************************************************************************** -** ui.h extension file, included from the uic-generated form implementation. -** -** If you want to add, delete, or rename functions or slots, use -** Qt Designer to update this file, preserving your code. -** -** You should not define a constructor or destructor in this file. -** Instead, write your code in functions called init() and destroy(). -** These will automatically be called by the form's constructor and -** destructor. -*****************************************************************************/ -/* - Copyright (C) 2005-2009 Michel de Boer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -// Indices of categories in the category list box -#define idxCatGeneral 0 -#define idxCatAudio 1 -#define idxCatRingtones 2 -#define idxCatAddressBook 3 -#define idxCatNetwork 4 -#define idxCatLog 5 - -void SysSettingsForm::init() -{ - // Set toolbutton icons for disabled options. - QIcon i; - i = openRingtoneToolButton->iconSet(); - i.setPixmap(qPixmapFromMimeSource("fileopen-disabled.png"), - QIcon::Automatic, QIcon::Disabled); - openRingtoneToolButton->setIconSet(i); - i = openRingbackToolButton->iconSet(); - i.setPixmap(qPixmapFromMimeSource("fileopen-disabled.png"), - QIcon::Automatic, QIcon::Disabled); - openRingbackToolButton->setIconSet(i); - - QRegExp rxNumber("[0-9]+"); - maxUdpSizeLineEdit->setValidator(new QRegExpValidator(rxNumber, this)); - maxTcpSizeLineEdit->setValidator(new QRegExpValidator(rxNumber, this)); -} - -void SysSettingsForm::showCategory( int index ) -{ - if (index == idxCatGeneral) { - settingsWidgetStack->raiseWidget(pageGeneral); - } else if (index == idxCatAudio) { - settingsWidgetStack->raiseWidget(pageAudio); - } else if (index == idxCatRingtones) { - settingsWidgetStack->raiseWidget(pageRingtones); - } else if (index == idxCatAddressBook) { - settingsWidgetStack->raiseWidget(pageAddressBook); - } else if (index == idxCatNetwork) { - settingsWidgetStack->raiseWidget(pageNetwork); - } else if (index == idxCatLog) { - settingsWidgetStack->raiseWidget(pageLog); - } -} - -string SysSettingsForm::comboItem2audio_dev(QString item, QLineEdit *qleOther, bool playback) -{ - if (item == QString("ALSA: ") + DEV_OTHER) { - if (qleOther->text().isEmpty()) return ""; - return (QString(PFX_ALSA) + qleOther->text()).ascii(); - } - - if (item == QString("OSS: ") + DEV_OTHER) { - if (qleOther->text().isEmpty()) return ""; - return (QString(PFX_OSS) + qleOther->text()).ascii(); - } - - list &list_audio_dev = (playback ? - list_audio_playback_dev : list_audio_capture_dev); - - for (list::iterator i = list_audio_dev.begin(); - i != list_audio_dev.end(); i++) - { - if (i->get_description() == item.ascii()) { - return i->get_settings_value(); - } - } - - return ""; -} - -void SysSettingsForm::populateComboBox(QComboBox *cb, const QString &s) -{ - for (int i = 0; i < cb->count(); i++) { - if (cb->text(i) == s) { - cb->setCurrentItem(i); - return; - } - } -} - -void SysSettingsForm::populate() -{ - QString msg; - int idx; - - // Select the Audio category - categoryListBox->setSelected(idxCatGeneral, true); - settingsWidgetStack->raiseWidget(pageGeneral); - - // Set focus on first field - categoryListBox->setFocus(); - - // Audio settings - list_audio_playback_dev = sys_config->get_audio_devices(true); - list_audio_capture_dev = sys_config->get_audio_devices(false); - ringtoneComboBox->clear(); - speakerComboBox->clear(); - micComboBox->clear(); - bool devRingtoneFound = false; - bool devSpeakerFound = false; - bool devMicFound = false; - - // Playback devices - idx = 0; - for (list::iterator i = list_audio_playback_dev.begin(); - i != list_audio_playback_dev.end(); i++, idx++) { - string item = i->get_description(); - ringtoneComboBox->insertItem(QString(item.c_str())); - speakerComboBox->insertItem(QString(item.c_str())); - - // Select audio device - if (sys_config->get_dev_ringtone().device == i->device) { - ringtoneComboBox->setCurrentItem(idx); - otherRingtoneLineEdit->clear(); - devRingtoneFound = true; - } - if (sys_config->get_dev_speaker().device == i->device) { - speakerComboBox->setCurrentItem(idx); - otherSpeakerLineEdit->clear(); - devSpeakerFound = true; - } - - // Determine index for other non-standard device - if (i->device == DEV_OTHER) { - if (i->type == t_audio_device::ALSA) { - idxOtherPlaybackDevAlsa = idx; - } else { - idxOtherPlaybackDevOss = idx; - } - } - } - - // Check for non-standard audio devices - if (!devRingtoneFound) { - t_audio_device dev = sys_config->get_dev_ringtone(); - otherRingtoneLineEdit->setText(dev.device.c_str()); - ringtoneComboBox->setCurrentItem( - (dev.type == t_audio_device::ALSA ? idxOtherPlaybackDevAlsa : idxOtherPlaybackDevOss)); - } - if (!devSpeakerFound) { - t_audio_device dev = sys_config->get_dev_speaker(); - otherSpeakerLineEdit->setText(dev.device.c_str()); - speakerComboBox->setCurrentItem( - (dev.type == t_audio_device::ALSA ? idxOtherPlaybackDevAlsa : idxOtherPlaybackDevOss)); - } - - // Capture device - idx = 0; - for (list::iterator i = list_audio_capture_dev.begin(); - i != list_audio_capture_dev.end(); i++, idx++) { - string item = i->get_description(); - micComboBox->insertItem(QString(item.c_str())); - - // Select audio device - if (sys_config->get_dev_mic().device == i->device) { - micComboBox->setCurrentItem(idx); - otherMicLineEdit->clear(); - devMicFound = true; - } - - // Determine index for other non-standard device - if (i->device == DEV_OTHER) { - if (i->type == t_audio_device::ALSA) { - idxOtherCaptureDevAlsa = idx; - } else { - idxOtherCaptureDevOss = idx; - } - } - } - - // Check for non-standard audio devices - if (!devMicFound) { - t_audio_device dev = sys_config->get_dev_mic(); - otherMicLineEdit->setText(dev.device.c_str()); - micComboBox->setCurrentItem( - (dev.type == t_audio_device::ALSA ? idxOtherCaptureDevAlsa : idxOtherCaptureDevOss)); - } - - // Enable/disable line edit for non-standard device - devRingtoneSelected(ringtoneComboBox->currentItem()); - devSpeakerSelected(speakerComboBox->currentItem()); - devMicSelected(micComboBox->currentItem()); - - validateAudioCheckBox->setChecked(sys_config->get_validate_audio_dev()); - - populateComboBox(ossFragmentComboBox, - QString::number(sys_config->get_oss_fragment_size())); - populateComboBox(alsaPlayPeriodComboBox, - QString::number(sys_config->get_alsa_play_period_size())); - populateComboBox(alsaCapturePeriodComboBox, - QString::number(sys_config->get_alsa_capture_period_size())); - - // Log settings - logMaxSizeSpinBox->setValue(sys_config->get_log_max_size()); - logDebugCheckBox->setChecked(sys_config->get_log_show_debug()); - logSipCheckBox->setChecked(sys_config->get_log_show_sip()); - logStunCheckBox->setChecked(sys_config->get_log_show_stun()); - logMemoryCheckBox->setChecked(sys_config->get_log_show_memory()); - - // General settings - guiUseSystrayCheckBox->setChecked(sys_config->get_gui_use_systray()); - guiHideCheckBox->setChecked(sys_config->get_gui_hide_on_close()); - guiHideCheckBox->setEnabled(sys_config->get_gui_use_systray()); - - // Call history - histSizeSpinBox->setValue(sys_config->get_ch_max_size()); - - // Auto show on incoming call - autoShowCheckBox->setChecked(sys_config->get_gui_auto_show_incoming()); - autoShowTimeoutSpinBox->setValue(sys_config->get_gui_auto_show_timeout()); - - // Services - callWaitingCheckBox->setChecked(sys_config->get_call_waiting()); - hangupBothCheckBox->setChecked(sys_config->get_hangup_both_3way()); - - // Startup settings - startHiddenCheckBox->setChecked(sys_config->get_start_hidden()); - - QStringList profiles; - if (!SelectProfileForm::getUserProfiles(profiles, msg)) { - ((t_gui *)ui)->cb_show_msg(this, msg.ascii(), MSG_CRITICAL); - } - profileListView->clear(); - for (QStringList::Iterator i = profiles.begin(); i != profiles.end(); i++) { - // Strip off the .cfg suffix - QString profile = *i; - profile.truncate(profile.length() - 4); - Q3CheckListItem *item = new Q3CheckListItem(profileListView, - profile, Q3CheckListItem::CheckBox); - item->setPixmap(0, qPixmapFromMimeSource("penguin-small.png")); - - list l = sys_config->get_start_user_profiles(); - if (std::find(l.begin(), l.end(), profile.ascii()) != l.end()) - { - item->setOn(true); - } - } - - // Web browser command - browserLineEdit->setText(sys_config->get_gui_browser_cmd().c_str()); - - // Network settings - sipUdpPortSpinBox->setValue(sys_config->get_config_sip_port()); - rtpPortSpinBox->setValue(sys_config->get_rtp_port()); - - maxUdpSizeLineEdit->setText(QString::number(sys_config->get_sip_max_udp_size())); - maxTcpSizeLineEdit->setText(QString::number(sys_config->get_sip_max_tcp_size())); - - // Ring tone settings - playRingtoneCheckBox->setChecked(sys_config->get_play_ringtone()); - defaultRingtoneRadioButton->setChecked(sys_config->get_ringtone_file().empty()); - customRingtoneRadioButton->setChecked(!sys_config->get_ringtone_file().empty()); - ringtoneLineEdit->setText(sys_config->get_ringtone_file().c_str()); - defaultRingtoneRadioButton->setEnabled(sys_config->get_play_ringtone()); - customRingtoneRadioButton->setEnabled(sys_config->get_play_ringtone()); - ringtoneLineEdit->setEnabled(!sys_config->get_ringtone_file().empty()); - openRingtoneToolButton->setEnabled(!sys_config->get_ringtone_file().empty()); - - playRingbackCheckBox->setChecked(sys_config->get_play_ringback()); - defaultRingbackRadioButton->setChecked(sys_config->get_ringback_file().empty()); - customRingbackRadioButton->setChecked(!sys_config->get_ringback_file().empty()); - ringbackLineEdit->setText(sys_config->get_ringback_file().c_str()); - defaultRingbackRadioButton->setEnabled(sys_config->get_play_ringback()); - customRingbackRadioButton->setEnabled(sys_config->get_play_ringback()); - ringbackLineEdit->setEnabled(!sys_config->get_ringback_file().empty()); - openRingbackToolButton->setEnabled(!sys_config->get_ringback_file().empty()); - - // Address book settings - abLookupNameCheckBox->setChecked(sys_config->get_ab_lookup_name()); - abOverrideDisplayCheckBox->setChecked(sys_config->get_ab_override_display()); - abOverrideDisplayCheckBox->setEnabled(sys_config->get_ab_lookup_name()); - abLookupPhotoCheckBox->setChecked(sys_config->get_ab_lookup_photo()); -} - -void SysSettingsForm::validate() -{ - bool conversion_ok = false; - unsigned short sip_max_udp_size = maxUdpSizeLineEdit->text().toUShort(&conversion_ok); - if (!conversion_ok) sip_max_udp_size = sys_config->get_sip_max_udp_size(); - - unsigned long sip_max_tcp_size = maxTcpSizeLineEdit->text().toULong(&conversion_ok); - if (!conversion_ok) sip_max_tcp_size = sys_config->get_sip_max_tcp_size(); - - // Audio - string dev; - dev = comboItem2audio_dev(ringtoneComboBox->currentText(), otherRingtoneLineEdit, true); - if (dev != "") sys_config->set_dev_ringtone(sys_config->audio_device(dev)); - dev = comboItem2audio_dev(speakerComboBox->currentText(), otherSpeakerLineEdit, true); - if (dev != "") sys_config->set_dev_speaker(sys_config->audio_device(dev)); - dev = comboItem2audio_dev(micComboBox->currentText(), otherMicLineEdit, false); - if (dev != "") sys_config->set_dev_mic(sys_config->audio_device(dev)); - - sys_config->set_validate_audio_dev(validateAudioCheckBox->isChecked()); - - sys_config->set_oss_fragment_size( - ossFragmentComboBox->currentText().toInt()); - sys_config->set_alsa_play_period_size( - alsaPlayPeriodComboBox->currentText().toInt()); - sys_config->set_alsa_capture_period_size( - alsaCapturePeriodComboBox->currentText().toInt()); - - // Log - sys_config->set_log_max_size(logMaxSizeSpinBox->value()); - sys_config->set_log_show_debug(logDebugCheckBox->isChecked()); - sys_config->set_log_show_sip(logSipCheckBox->isChecked()); - sys_config->set_log_show_stun(logStunCheckBox->isChecked()); - sys_config->set_log_show_memory(logMemoryCheckBox->isChecked()); - - // General - sys_config->set_gui_use_systray(guiUseSystrayCheckBox->isChecked()); - sys_config->set_gui_hide_on_close(guiHideCheckBox->isChecked()); - - // Auto show on incoming call - sys_config->set_gui_auto_show_incoming(autoShowCheckBox->isChecked()); - sys_config->set_gui_auto_show_timeout(autoShowTimeoutSpinBox->value()); - - // Call history - sys_config->set_ch_max_size(histSizeSpinBox->value()); - - // Services - sys_config->set_call_waiting(callWaitingCheckBox->isChecked()); - sys_config->set_hangup_both_3way(hangupBothCheckBox->isChecked()); - - // Startup - sys_config->set_start_hidden(startHiddenCheckBox->isChecked() && - guiUseSystrayCheckBox->isChecked()); - - list start_user_profiles; - Q3ListViewItemIterator i(profileListView, Q3ListViewItemIterator::Checked); - while (i.current()) { - Q3CheckListItem *item = (Q3CheckListItem *)i.current(); - start_user_profiles.push_back(item->text().ascii()); - i++; - } - sys_config->set_start_user_profiles(start_user_profiles); - - // Web browser command - sys_config->set_gui_browser_cmd(browserLineEdit->text().stripWhiteSpace().ascii()); - - // Network - if (sys_config->get_config_sip_port() != sipUdpPortSpinBox->value()) { - sys_config->set_config_sip_port(sipUdpPortSpinBox->value()); - emit sipUdpPortChanged(); - } - if (sys_config->get_rtp_port() != rtpPortSpinBox->value()) { - sys_config->set_rtp_port(rtpPortSpinBox->value()); - emit rtpPortChanged(); - } - sys_config->set_sip_max_udp_size(sip_max_udp_size); - sys_config->set_sip_max_tcp_size(sip_max_tcp_size); - - // Ring tones - sys_config->set_play_ringtone(playRingtoneCheckBox->isChecked()); - if (sys_config->get_play_ringtone()) { - if (defaultRingtoneRadioButton->isOn()) { - sys_config->set_ringtone_file(""); - } else { - sys_config->set_ringtone_file(ringtoneLineEdit-> - text().stripWhiteSpace().ascii()); - } - } else { - sys_config->set_ringtone_file(""); - } - - sys_config->set_play_ringback(playRingbackCheckBox->isChecked()); - if (sys_config->get_play_ringback()) { - if (defaultRingbackRadioButton->isOn()) { - sys_config->set_ringback_file(""); - } else { - sys_config->set_ringback_file(ringbackLineEdit-> - text().stripWhiteSpace().ascii()); - } - } else { - sys_config->set_ringback_file(""); - } - - // Address book settings - sys_config->set_ab_lookup_name(abLookupNameCheckBox->isChecked()); - sys_config->set_ab_override_display(abOverrideDisplayCheckBox->isChecked()); - sys_config->set_ab_lookup_photo(abLookupPhotoCheckBox->isChecked()); - - // Save user config - string error_msg; - if (!sys_config->write_config(error_msg)) { - // Failed to write config file - ((t_gui *)ui)->cb_show_msg(this, error_msg, MSG_CRITICAL); - return; - } - - accept(); -} - -void SysSettingsForm::show() -{ - populate(); - QDialog::show(); -} - -int SysSettingsForm::exec() -{ - populate(); - return QDialog::exec(); -} - -void SysSettingsForm::chooseRingtone() -{ - QString file = Q3FileDialog::getOpenFileName( - ((t_gui *)ui)->get_last_file_browse_path(), - tr("Ring tones", "Description of .wav files in file dialog").append(" (*.wav)"), this, "ring tone file dialog", - tr("Choose ring tone")); - if (!file.isEmpty()) { - ringtoneLineEdit->setText(file); - ((t_gui *)ui)->set_last_file_browse_path(QFileInfo(file).dirPath(true)); - } -} - -void SysSettingsForm::chooseRingback() -{ - QString file = Q3FileDialog::getOpenFileName( - ((t_gui *)ui)->get_last_file_browse_path(), - tr("Ring back tones", "Description of .wav files in file dialog").append(" (*.wav)"), this, "ring back file dialog", - tr("Choose ring back tone")); - if (!file.isEmpty()) { - ringbackLineEdit->setText(file); - ((t_gui *)ui)->set_last_file_browse_path(QFileInfo(file).dirPath(true)); - } -} - -void SysSettingsForm::devRingtoneSelected(int idx) { - bool b = (idx == idxOtherPlaybackDevAlsa || idx == idxOtherPlaybackDevOss); - otherRingtoneTextLabel->setEnabled(b); - otherRingtoneLineEdit->setEnabled(b); -} - -void SysSettingsForm::devSpeakerSelected(int idx) { - bool b = (idx == idxOtherPlaybackDevAlsa || idx == idxOtherPlaybackDevOss); - otherSpeakerTextLabel->setEnabled(b); - otherSpeakerLineEdit->setEnabled(b); -} - -void SysSettingsForm::devMicSelected(int idx) { - bool b = (idx == idxOtherCaptureDevAlsa || idx == idxOtherCaptureDevOss); - otherMicTextLabel->setEnabled(b); - otherMicLineEdit->setEnabled(b); -} - -void SysSettingsForm::playRingToneCheckBoxToggles(bool on) { - if (on) { - ringtoneLineEdit->setEnabled(customRingtoneRadioButton->isChecked()); - } else { - ringtoneLineEdit->setEnabled(false); - } -} - -void SysSettingsForm::playRingBackToneCheckBoxToggles(bool on) { - if (on) { - ringbackLineEdit->setEnabled(customRingbackRadioButton->isChecked()); - } else { - ringbackLineEdit->setEnabled(false); - } -} diff --git a/src/gui/termcapform.cpp b/src/gui/termcapform.cpp new file mode 100644 index 0000000..f1413c5 --- /dev/null +++ b/src/gui/termcapform.cpp @@ -0,0 +1,135 @@ +#include "termcapform.h" + +/* + Copyright (C) 2005-2009 Michel de Boer + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include +#include +#include + +#include "gui.h" +#include "audits/memman.h" +#include "termcapform.h" +/* + * Constructs a TermCapForm as a child of 'parent', with the + * name 'name' and widget flags set to 'f'. + * + * The dialog will by default be modeless, unless you set 'modal' to + * true to construct a modal dialog. + */ +TermCapForm::TermCapForm(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl) + : QDialog(parent, name, modal, fl) +{ + setupUi(this); + + init(); +} + +/* + * Destroys the object and frees any allocated resources + */ +TermCapForm::~TermCapForm() +{ + destroy(); + // no need to delete child widgets, Qt does it all for us +} + +/* + * Sets the strings of the subwidgets using the current + * language. + */ +void TermCapForm::languageChange() +{ + retranslateUi(this); +} + + +void TermCapForm::init() +{ + getAddressForm = 0; + + // Set toolbutton icons for disabled options. + setDisabledIcon(addressToolButton, ":/icons/images/kontact_contacts-disabled.png"); +} + +void TermCapForm::show(t_user *user_config, const QString &dest) +{ + ((t_gui *)ui)->fill_user_combo(fromComboBox); + + // Select from user + if (user_config) { + for (int i = 0; i < fromComboBox->count(); i++) { + if (fromComboBox->text(i) == + user_config->get_profile_name().c_str()) + { + fromComboBox->setCurrentItem(i); + break; + } + } + } + + partyLineEdit->setText(dest); + QDialog::show(); +} + +void TermCapForm::destroy() +{ + if (getAddressForm) { + MEMMAN_DELETE(getAddressForm); + delete getAddressForm; + } +} + +void TermCapForm::validate() +{ + string display, dest_str; + t_user *from_user = phone->ref_user_profile( + fromComboBox->currentText().ascii()); + + ui->expand_destination(from_user, + partyLineEdit->text().stripWhiteSpace().ascii(), + display, dest_str); + t_url dest(dest_str); + + if (dest.is_valid()) { + emit destination(from_user, dest); + accept(); + } else { + partyLineEdit->selectAll(); + } +} + +void TermCapForm::showAddressBook() +{ + if (!getAddressForm) { + getAddressForm = new GetAddressForm( + this, "select address", true); + MEMMAN_NEW(getAddressForm); + } + + connect(getAddressForm, + SIGNAL(address(const QString &)), + this, SLOT(selectedAddress(const QString &))); + + getAddressForm->show(); +} + +void TermCapForm::selectedAddress(const QString &address) +{ + partyLineEdit->setText(address); +} diff --git a/src/gui/termcapform.h b/src/gui/termcapform.h new file mode 100644 index 0000000..3cc53df --- /dev/null +++ b/src/gui/termcapform.h @@ -0,0 +1,40 @@ +#ifndef TERMCAPFORM_H +#define TERMCAPFORM_H +#include "ui_termcapform.h" +#include "getaddressform.h" +#include "phone.h" +#include "sockets/url.h" +#include "user.h" + +class t_phone; +extern t_phone *phone; + +class TermCapForm : public QDialog, public Ui::TermCapForm +{ + Q_OBJECT + +public: + TermCapForm(QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WindowFlags fl = 0); + ~TermCapForm(); + +public slots: + virtual void show( t_user * user_config, const QString & dest ); + virtual void validate(); + virtual void showAddressBook(); + virtual void selectedAddress( const QString & address ); + +signals: + void destination(t_user *, const t_url &); + +protected slots: + virtual void languageChange(); + +private: + GetAddressForm *getAddressForm; + + void init(); + void destroy(); + +}; + +#endif diff --git a/src/gui/termcapform.ui b/src/gui/termcapform.ui index e0740f7..adaf134 100644 --- a/src/gui/termcapform.ui +++ b/src/gui/termcapform.ui @@ -92,7 +92,7 @@ F10 - kontact_contacts.png + :/icons/images/kontact_contacts.png Address book diff --git a/src/gui/termcapform.ui.h b/src/gui/termcapform.ui.h deleted file mode 100644 index e04af11..0000000 --- a/src/gui/termcapform.ui.h +++ /dev/null @@ -1,101 +0,0 @@ -/**************************************************************************** -** ui.h extension file, included from the uic-generated form implementation. -** -** If you wish to add, delete or rename functions or slots use -** Qt Designer which will update this file, preserving your code. Create an -** init() function in place of a constructor, and a destroy() function in -** place of a destructor. -*****************************************************************************/ -/* - Copyright (C) 2005-2009 Michel de Boer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - - -void TermCapForm::init() -{ - getAddressForm = 0; - - // Set toolbutton icons for disabled options. - setDisabledIcon(addressToolButton, "kontact_contacts-disabled.png"); -} - -void TermCapForm::show(t_user *user_config, const QString &dest) -{ - ((t_gui *)ui)->fill_user_combo(fromComboBox); - - // Select from user - if (user_config) { - for (int i = 0; i < fromComboBox->count(); i++) { - if (fromComboBox->text(i) == - user_config->get_profile_name().c_str()) - { - fromComboBox->setCurrentItem(i); - break; - } - } - } - - partyLineEdit->setText(dest); - QDialog::show(); -} - -void TermCapForm::destroy() -{ - if (getAddressForm) { - MEMMAN_DELETE(getAddressForm); - delete getAddressForm; - } -} - -void TermCapForm::validate() -{ - string display, dest_str; - t_user *from_user = phone->ref_user_profile( - fromComboBox->currentText().ascii()); - - ui->expand_destination(from_user, - partyLineEdit->text().stripWhiteSpace().ascii(), - display, dest_str); - t_url dest(dest_str); - - if (dest.is_valid()) { - emit destination(from_user, dest); - accept(); - } else { - partyLineEdit->selectAll(); - } -} - -void TermCapForm::showAddressBook() -{ - if (!getAddressForm) { - getAddressForm = new GetAddressForm( - this, "select address", true); - MEMMAN_NEW(getAddressForm); - } - - connect(getAddressForm, - SIGNAL(address(const QString &)), - this, SLOT(selectedAddress(const QString &))); - - getAddressForm->show(); -} - -void TermCapForm::selectedAddress(const QString &address) -{ - partyLineEdit->setText(address); -} diff --git a/src/gui/transferform.cpp b/src/gui/transferform.cpp new file mode 100644 index 0000000..6394c37 --- /dev/null +++ b/src/gui/transferform.cpp @@ -0,0 +1,229 @@ +//Added by qt3to4: +#include +#include +#include +#include +#include +#include "gui.h" +#include "audits/memman.h" +#include "transferform.h" +/* + * Constructs a TransferForm as a child of 'parent', with the + * name 'name' and widget flags set to 'f'. + * + * The dialog will by default be modeless, unless you set 'modal' to + * true to construct a modal dialog. + */ +TransferForm::TransferForm(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl) + : QDialog(parent, name, modal, fl) +{ + setupUi(this); + + init(); +} + +/* + * Destroys the object and frees any allocated resources + */ +TransferForm::~TransferForm() +{ + destroy(); + // no need to delete child widgets, Qt does it all for us +} + +/* + * Sets the strings of the subwidgets using the current + * language. + */ +void TransferForm::languageChange() +{ + retranslateUi(this); +} + + +/* + Copyright (C) 2005-2009 Michel de Boer + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +void TransferForm::init() +{ + getAddressForm = 0; + + // Set toolbutton icons for disabled options. + QIcon i; + i = addressToolButton->iconSet(); + i.setPixmap(QPixmap(":/icons/images/kontact_contacts-disabled.png"), + QIcon::Automatic, QIcon::Disabled); + addressToolButton->setIconSet(i); +} + +void TransferForm::destroy() +{ + if (getAddressForm) { + MEMMAN_DELETE(getAddressForm); + delete getAddressForm; + } +} + +void TransferForm::initTransferOptions() +{ + // Show possible transfer type options + // Basic transfer is always possible. + // If a line is idle, then a transfer with consultation is possible. + // The line will be seized, so an incoming call cannot occupy it. + // If both lines are busy, then the active line can be transferred + // to the other line. + unsigned short idle_line; + if (phone->get_idle_line(idle_line)) { + consult_line = (int)idle_line; + phone->pub_seize(consult_line); + consultRadioButton->show(); + consultRadioButton->setChecked(true); + otherLineRadioButton->hide(); + } else { + consult_line = -1; + consultRadioButton->hide(); + otherLineRadioButton->show(); + otherLineRadioButton->setChecked(true); + } +} + +void TransferForm::show(t_user *user) +{ + user_config = user; + initTransferOptions(); + QDialog::show(); +} + +void TransferForm::show(t_user *user, const string &dest, t_transfer_type transfer_type) +{ + user_config = user; + initTransferOptions(); + toLineEdit->setText(dest.c_str()); + + switch (transfer_type) { + case TRANSFER_CONSULT: + consultRadioButton->setChecked(true); + break; + case TRANSFER_OTHER_LINE: + otherLineRadioButton->setChecked(true); + break; + default: + basicRadioButton->setChecked(true); + break; + } + + QDialog::show(); +} + +void TransferForm::hide() +{ + if (consult_line > -1) { + phone->pub_unseize(consult_line); + } + + QDialog::hide(); +} + +void TransferForm::reject() +{ + if (user_config->get_referrer_hold()) { + ((t_gui *)ui)->action_retrieve(); + } + + if (consult_line > -1) { + phone->pub_unseize(consult_line); + } + + QDialog::reject(); +} + +void TransferForm::validate() +{ + t_display_url dest; + ui->expand_destination(user_config, toLineEdit->text().stripWhiteSpace().ascii(), dest); + + t_transfer_type transfer_type; + if (consultRadioButton->isOn()) { + transfer_type = TRANSFER_CONSULT; + } else if (otherLineRadioButton->isOn()) { + transfer_type = TRANSFER_OTHER_LINE; + } else { + transfer_type = TRANSFER_BASIC; + } + + + if (transfer_type == TRANSFER_OTHER_LINE || dest.is_valid()) { + if (consult_line > -1) { + phone->pub_unseize(consult_line); + } + emit destination(dest, transfer_type); + accept(); + } else { + toLineEdit->selectAll(); + } +} + +void TransferForm::closeEvent(QCloseEvent *) +{ + reject(); +} + +void TransferForm::showAddressBook() +{ + if (!getAddressForm) { + getAddressForm = new GetAddressForm( + this, "select address", true); + MEMMAN_NEW(getAddressForm); + } + + connect(getAddressForm, + SIGNAL(address(const QString &)), + this, SLOT(selectedAddress(const QString &))); + + getAddressForm->show(); +} + +void TransferForm::selectedAddress(const QString &address) +{ + toLineEdit->setText(address); +} + +void TransferForm::setOtherLineAddress(bool on) +{ + if (on) { + previousAddress = toLineEdit->text(); + unsigned short active_line = phone->get_active_line(); + unsigned short other_line = (active_line == 0 ? 1 : 0); + QString address = ui->format_sip_address(user_config, + phone->get_remote_display(other_line), + phone->get_remote_uri(other_line)).c_str(); + toLineEdit->setText(address); + toLineEdit->setEnabled(false); + toLabel->setEnabled(false); +#ifdef HAVE_KDE + addressToolButton->setEnabled(false); +#endif + } else { + toLineEdit->setText(previousAddress); + toLineEdit->setEnabled(true); + toLabel->setEnabled(true); +#ifdef HAVE_KDE + addressToolButton->setEnabled(true); +#endif + } +} diff --git a/src/gui/transferform.h b/src/gui/transferform.h new file mode 100644 index 0000000..65477d8 --- /dev/null +++ b/src/gui/transferform.h @@ -0,0 +1,52 @@ +#ifndef TRANSFERFORM_H +#define TRANSFERFORM_H +class t_phone; +extern t_phone *phone; + +#include "getaddressform.h" +#include "phone.h" +#include "protocol.h" +#include +#include "sockets/url.h" +#include "user.h" +#include "ui_transferform.h" + +class TransferForm : public QDialog, public Ui::TransferForm +{ + Q_OBJECT + +public: + TransferForm(QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WindowFlags fl = 0); + ~TransferForm(); + +public slots: + virtual void initTransferOptions(); + virtual void show( t_user * user ); + virtual void show( t_user * user, const string & dest, t_transfer_type transfer_type ); + virtual void hide(); + virtual void reject(); + virtual void validate(); + virtual void closeEvent( QCloseEvent * ); + virtual void showAddressBook(); + virtual void selectedAddress( const QString & address ); + virtual void setOtherLineAddress( bool on ); + +signals: + void destination(const t_display_url&, t_transfer_type); + +protected slots: + virtual void languageChange(); + +private: + int consult_line; + t_user *user_config; + GetAddressForm *getAddressForm; + QString previousAddress; + + void init(); + void destroy(); + +}; + + +#endif diff --git a/src/gui/transferform.ui b/src/gui/transferform.ui index b712cc3..04b02ba 100644 --- a/src/gui/transferform.ui +++ b/src/gui/transferform.ui @@ -55,7 +55,7 @@ F10 - kontact_contacts.png + :/icons/images/kontact_contacts.png Address book diff --git a/src/gui/transferform.ui.h b/src/gui/transferform.ui.h deleted file mode 100644 index be4f465..0000000 --- a/src/gui/transferform.ui.h +++ /dev/null @@ -1,198 +0,0 @@ -//Added by qt3to4: -#include -#include -/**************************************************************************** -** ui.h extension file, included from the uic-generated form implementation. -** -** If you wish to add, delete or rename functions or slots use -** Qt Designer which will update this file, preserving your code. Create an -** init() function in place of a constructor, and a destroy() function in -** place of a destructor. -*****************************************************************************/ - -/* - Copyright (C) 2005-2009 Michel de Boer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -void TransferForm::init() -{ - getAddressForm = 0; - - // Set toolbutton icons for disabled options. - QIcon i; - i = addressToolButton->iconSet(); - i.setPixmap(qPixmapFromMimeSource("kontact_contacts-disabled.png"), - QIcon::Automatic, QIcon::Disabled); - addressToolButton->setIconSet(i); -} - -void TransferForm::destroy() -{ - if (getAddressForm) { - MEMMAN_DELETE(getAddressForm); - delete getAddressForm; - } -} - -void TransferForm::initTransferOptions() -{ - // Show possible transfer type options - // Basic transfer is always possible. - // If a line is idle, then a transfer with consultation is possible. - // The line will be seized, so an incoming call cannot occupy it. - // If both lines are busy, then the active line can be transferred - // to the other line. - unsigned short idle_line; - if (phone->get_idle_line(idle_line)) { - consult_line = (int)idle_line; - phone->pub_seize(consult_line); - consultRadioButton->show(); - consultRadioButton->setChecked(true); - otherLineRadioButton->hide(); - } else { - consult_line = -1; - consultRadioButton->hide(); - otherLineRadioButton->show(); - otherLineRadioButton->setChecked(true); - } -} - -void TransferForm::show(t_user *user) -{ - user_config = user; - initTransferOptions(); - QDialog::show(); -} - -void TransferForm::show(t_user *user, const string &dest, t_transfer_type transfer_type) -{ - user_config = user; - initTransferOptions(); - toLineEdit->setText(dest.c_str()); - - switch (transfer_type) { - case TRANSFER_CONSULT: - consultRadioButton->setChecked(true); - break; - case TRANSFER_OTHER_LINE: - otherLineRadioButton->setChecked(true); - break; - default: - basicRadioButton->setChecked(true); - break; - } - - QDialog::show(); -} - -void TransferForm::hide() -{ - if (consult_line > -1) { - phone->pub_unseize(consult_line); - } - - QDialog::hide(); -} - -void TransferForm::reject() -{ - if (user_config->get_referrer_hold()) { - ((t_gui *)ui)->action_retrieve(); - } - - if (consult_line > -1) { - phone->pub_unseize(consult_line); - } - - QDialog::reject(); -} - -void TransferForm::validate() -{ - t_display_url dest; - ui->expand_destination(user_config, toLineEdit->text().stripWhiteSpace().ascii(), dest); - - t_transfer_type transfer_type; - if (consultRadioButton->isOn()) { - transfer_type = TRANSFER_CONSULT; - } else if (otherLineRadioButton->isOn()) { - transfer_type = TRANSFER_OTHER_LINE; - } else { - transfer_type = TRANSFER_BASIC; - } - - - if (transfer_type == TRANSFER_OTHER_LINE || dest.is_valid()) { - if (consult_line > -1) { - phone->pub_unseize(consult_line); - } - emit destination(dest, transfer_type); - accept(); - } else { - toLineEdit->selectAll(); - } -} - -void TransferForm::closeEvent(QCloseEvent *) -{ - reject(); -} - -void TransferForm::showAddressBook() -{ - if (!getAddressForm) { - getAddressForm = new GetAddressForm( - this, "select address", true); - MEMMAN_NEW(getAddressForm); - } - - connect(getAddressForm, - SIGNAL(address(const QString &)), - this, SLOT(selectedAddress(const QString &))); - - getAddressForm->show(); -} - -void TransferForm::selectedAddress(const QString &address) -{ - toLineEdit->setText(address); -} - -void TransferForm::setOtherLineAddress(bool on) -{ - if (on) { - previousAddress = toLineEdit->text(); - unsigned short active_line = phone->get_active_line(); - unsigned short other_line = (active_line == 0 ? 1 : 0); - QString address = ui->format_sip_address(user_config, - phone->get_remote_display(other_line), - phone->get_remote_uri(other_line)).c_str(); - toLineEdit->setText(address); - toLineEdit->setEnabled(false); - toLabel->setEnabled(false); -#ifdef HAVE_KDE - addressToolButton->setEnabled(false); -#endif - } else { - toLineEdit->setText(previousAddress); - toLineEdit->setEnabled(true); - toLabel->setEnabled(true); -#ifdef HAVE_KDE - addressToolButton->setEnabled(true); -#endif - } -} diff --git a/src/gui/twinklesystray.cpp b/src/gui/twinklesystray.cpp deleted file mode 100644 index d2873da..0000000 --- a/src/gui/twinklesystray.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - Copyright (C) 2005-2009 Michel de Boer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -#include "twinklesystray.h" -#include "audits/memman.h" - -t_twinkle_sys_tray::t_twinkle_sys_tray(QWidget *pParent, const char *pszName) : -#ifdef HAVE_KDE - KSystemTray(pParent, pszName) -#else - FreeDeskSysTray(pParent, pszName) -#endif -{} - -t_twinkle_sys_tray::~t_twinkle_sys_tray() -{} - -void t_twinkle_sys_tray::dock() -{ -#ifndef HAVE_KDE - FreeDeskSysTray::dock(); -#endif -} diff --git a/src/gui/twinklesystray.h b/src/gui/twinklesystray.h deleted file mode 100644 index de69c20..0000000 --- a/src/gui/twinklesystray.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - Copyright (C) 2005-2009 Michel de Boer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -#ifndef _TWINKLESYSTRAY_H -#define _TWINKLESYSTRAY_H - -#include "twinkle_config.h" - -#ifdef HAVE_KDE -#include -#include -#else -#include "freedesksystray.h" -#endif - -#include "q3popupmenu.h" -#include "qwidget.h" - -#ifdef HAVE_KDE -class t_twinkle_sys_tray : public KSystemTray { -#else -class t_twinkle_sys_tray : public FreeDeskSysTray { -#endif - -public: - t_twinkle_sys_tray(QWidget *pParent = 0, const char *pszName = 0); - ~t_twinkle_sys_tray(); - - void dock(); -}; - -#endif diff --git a/src/gui/userprofileform.cpp b/src/gui/userprofileform.cpp new file mode 100644 index 0000000..062053f --- /dev/null +++ b/src/gui/userprofileform.cpp @@ -0,0 +1,1507 @@ +//Added by qt3to4: +#include +#include + +/* + Copyright (C) 2005-2009 Michel de Boer + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include +#include +#include +#include +#include +#include +#include "sdp/sdp.h" +#include +#include "protocol.h" +#include +#include "gui.h" +#include +#include +#include +#include "twinkle_config.h" +#include +#include "numberconversionform.h" +#include "util.h" +#include "userprofileform.h" + + +// Indices of categories in the category list box +#define idxCatUser 0 +#define idxCatSipServer 1 +#define idxCatVoiceMail 2 +#define idxCatIM 3 +#define idxCatPresence 4 +#define idxCatRtpAudio 5 +#define idxCatSipProtocol 6 +#define idxCatNat 7 +#define idxCatAddrFmt 8 +#define idxCatTimers 9 +#define idxCatRingTones 10 +#define idxCatScripts 11 +#define idxCatSecurity 12 + +// Indices of call hold variants in the call hold variant list box +#define idxHoldRfc2543 0 +#define idxHoldRfc3264 1 + +// Indices of SIP extension support types in the list box +#define idxExtDisabled 0 +#define idxExtSupported 1 +#define idxExtRequired 2 +#define idxExtPreferred 3 + +// Indices of RTP audio tabs +#define idxRtpCodecs 0 +#define idxRtpPreprocessing 1 +#define idxRtpIlbc 2 +#define idxRtpSpeex 3 +#define idxRtpDtmf 4 + +// Codec labels +#define labelCodecG711a "G.711 A-law" +#define labelCodecG711u "G.711 u-law" +#define labelCodecGSM "GSM" +#define labelCodecSpeexNb "speex-nb (8 kHz)" +#define labelCodecSpeexWb "speex-wb (16 kHz)" +#define labelCodecSpeexUwb "speex-uwb (32 kHz)" +#define labelCodecIlbc "iLBC" +#define labelCodecG726_16 "G.726 16 kbps" +#define labelCodecG726_24 "G.726 24 kbps" +#define labelCodecG726_32 "G.726 32 kbps" +#define labelCodecG726_40 "G.726 40 kbps" + +// Indices of iLBC modes +#define idxIlbcMode20 0 +#define idxIlbcMode30 1 + +// Indices of G.726 packing modes +#define idxG726PackRfc3551 0 +#define idxG726PackAal2 1 + +// Indices of DTMF transport modes in the DTMF transport list box +#define idxDtmfAuto 0 +#define idxDtmfRfc2833 1 +#define idxDtmfInband 2 +#define idxDtmfInfo 3 + +// Columns in the number conversion list view +#define colExpr 0 +#define colReplace 1 + +// MWI type indices +#define idxMWIUnsollicited 0 +#define idxMWISollicited 1 + +// SIP transport protocol indices +#define idxSipTransportAuto 0 +#define idxSipTransportUDP 1 +#define idxSipTransportTCP 2 + +/* + * Constructs a UserProfileForm as a child of 'parent', with the + * name 'name' and widget flags set to 'f'. + * + * The dialog will by default be modeless, unless you set 'modal' to + * true to construct a modal dialog. + */ +UserProfileForm::UserProfileForm(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl) + : QDialog(parent, name, modal, fl) +{ + setupUi(this); + + init(); +} + +/* + * Destroys the object and frees any allocated resources + */ +UserProfileForm::~UserProfileForm() +{ + // no need to delete child widgets, Qt does it all for us +} + +/* + * Sets the strings of the subwidgets using the current + * language. + */ +void UserProfileForm::languageChange() +{ + retranslateUi(this); +} + + +void UserProfileForm::init() +{ + QRegExp rxNoSpace("\\S*"); + QRegExp rxNoAtSign("[^@]*"); + QRegExp rxQvalue("(0\\.[0-9]{0,3})|(1\\.0{0,3})"); + QRegExp rxAkaOpValue("[a-zA-Z0-9]{0,32}"); + QRegExp rxAkaAmfValue("[a-zA-Z0-9]{0,4}"); + + // Set validators + // USER + domainLineEdit->setValidator(new QRegExpValidator(rxNoSpace, this)); + authAkaOpLineEdit->setValidator(new QRegExpValidator(rxAkaOpValue, this)); + authAkaAmfLineEdit->setValidator(new QRegExpValidator(rxAkaAmfValue, this)); + + // SIP SERVER + registrarLineEdit->setValidator(new QRegExpValidator(rxNoSpace, this)); + regQvalueLineEdit->setValidator(new QRegExpValidator(rxQvalue, this)); + proxyLineEdit->setValidator(new QRegExpValidator(rxNoSpace, this)); + + // Voice mail + mwiServerLineEdit->setValidator(new QRegExpValidator(rxNoSpace, this)); + + // NAT + publicIPLineEdit->setValidator(new QRegExpValidator(rxNoSpace, this)); + + // Address format + testConversionLineEdit->setValidator(new QRegExpValidator(rxNoAtSign, this)); + +#ifndef HAVE_SPEEX + // Speex & (Speex) Preprocessing + speexGroupBox->hide(); + preprocessingGroupBox->hide(); + rtpAudioTabWidget->setTabEnabled(rtpAudioTabWidget->page(idxRtpSpeex), false); + rtpAudioTabWidget->setTabEnabled(rtpAudioTabWidget->page(idxRtpPreprocessing), false); +#endif +#ifndef HAVE_ILBC + // iLBC + ilbcGroupBox->hide(); + rtpAudioTabWidget->setTabEnabled(rtpAudioTabWidget->page(idxRtpIlbc), false); +#endif +#ifndef HAVE_ZRTP + // Zrtp + zrtpEnabledCheckBox->setEnabled(false); + zrtpSettingsGroupBox->hide(); +#endif + + // Set toolbutton icons for disabled options. + QIcon i; + i = openRingtoneToolButton->iconSet(); + i.setPixmap(QPixmap(":/icons/images/fileopen-disabled.png"), + QIcon::Automatic, QIcon::Disabled); + openRingtoneToolButton->setIconSet(i); + openRingbackToolButton->setIconSet(i); + openIncomingCallScriptToolButton->setIconSet(i); +} + +void UserProfileForm::showCategory( int index ) +{ + if (index == idxCatUser) { + settingsWidgetStack->raiseWidget(pageUser); + } else if (index == idxCatSipServer) { + settingsWidgetStack->raiseWidget(pageSipServer); + } else if (index == idxCatVoiceMail) { + settingsWidgetStack->raiseWidget(pageVoiceMail); + } else if (index == idxCatIM) { + settingsWidgetStack->raiseWidget(pageIM); + } else if (index == idxCatPresence) { + settingsWidgetStack->raiseWidget(pagePresence); + } else if (index == idxCatRtpAudio) { + settingsWidgetStack->raiseWidget(pageRtpAudio); + } else if (index == idxCatSipProtocol) { + settingsWidgetStack->raiseWidget(pageSipProtocol); + } else if (index == idxCatNat) { + settingsWidgetStack->raiseWidget(pageNat); + } else if (index == idxCatAddrFmt) { + settingsWidgetStack->raiseWidget(pageAddressFormat); + } else if (index == idxCatTimers) { + settingsWidgetStack->raiseWidget(pageTimers); + } else if (index == idxCatRingTones) { + settingsWidgetStack->raiseWidget(pageRingTones); + } else if (index == idxCatScripts) { + settingsWidgetStack->raiseWidget(pageScripts); + } else if (index == idxCatSecurity) { + settingsWidgetStack->raiseWidget(pageSecurity); + } +} + +// Convert a label to a codec +t_audio_codec UserProfileForm::label2codec(const QString &label) { + if (label == labelCodecG711a) { + return CODEC_G711_ALAW; + } else if (label == labelCodecG711u) { + return CODEC_G711_ULAW; + } else if (label == labelCodecGSM) { + return CODEC_GSM; + } else if (label == labelCodecSpeexNb) { + return CODEC_SPEEX_NB; + } else if (label == labelCodecSpeexWb) { + return CODEC_SPEEX_WB; + } else if (label == labelCodecSpeexUwb) { + return CODEC_SPEEX_UWB; + } else if (label == labelCodecIlbc) { + return CODEC_ILBC; + } else if (label == labelCodecG726_16) { + return CODEC_G726_16; + } else if (label == labelCodecG726_24) { + return CODEC_G726_24; + } else if (label == labelCodecG726_32) { + return CODEC_G726_32; + } else if (label == labelCodecG726_40) { + return CODEC_G726_40; + } + return CODEC_NULL; +} + +// Convert a codec to a label +QString UserProfileForm::codec2label(t_audio_codec &codec) { + switch (codec) { + case CODEC_G711_ALAW: + return labelCodecG711a; + case CODEC_G711_ULAW: + return labelCodecG711u; + case CODEC_GSM: + return labelCodecGSM; + case CODEC_SPEEX_NB: + return labelCodecSpeexNb; + case CODEC_SPEEX_WB: + return labelCodecSpeexWb; + case CODEC_SPEEX_UWB: + return labelCodecSpeexUwb; + case CODEC_ILBC: + return labelCodecIlbc; + case CODEC_G726_16: + return labelCodecG726_16; + case CODEC_G726_24: + return labelCodecG726_24; + case CODEC_G726_32: + return labelCodecG726_32; + case CODEC_G726_40: + return labelCodecG726_40; + default: + return ""; + } +} + +// Convert t_ext_support to an index in the SIP extension combo box +int UserProfileForm::ext_support2indexComboItem(t_ext_support ext) { + switch(ext) { + case EXT_DISABLED: + return idxExtDisabled; + case EXT_SUPPORTED: + return idxExtSupported; + case EXT_REQUIRED: + return idxExtRequired; + case EXT_PREFERRED: + return idxExtPreferred; + default: + return idxExtDisabled; + } + + return idxExtDisabled; +} + +t_ext_support UserProfileForm::indexComboItem2ext_support(int index) { + switch(index) { + case idxExtDisabled: + return EXT_DISABLED; + case idxExtSupported: + return EXT_SUPPORTED; + case idxExtRequired: + return EXT_REQUIRED; + case idxExtPreferred: + return EXT_PREFERRED; + } + + return EXT_DISABLED; +} + +// Populate the form +void UserProfileForm::populate() +{ + QString s; + + // Set user profile name in the titlebar + s = PRODUCT_NAME; + s.append(" - ").append(tr("User profile:")).append(" "); + s.append(current_profile->get_profile_name().c_str()); + setCaption(s); + + // Select the User category + categoryListBox->setSelected(idxCatUser, true); + settingsWidgetStack->raiseWidget(pageUser); + + // Set focus on first field + displayLineEdit->setFocus(); + + // Set the values of the current_profile object in the form + // USER + displayLineEdit->setText(current_profile->get_display(false).c_str()); + usernameLineEdit->setText(current_profile->get_name().c_str()); + domainLineEdit->setText(current_profile->get_domain().c_str()); + organizationLineEdit->setText(current_profile->get_organization().c_str()); + authRealmLineEdit->setText(current_profile->get_auth_realm().c_str()); + authNameLineEdit->setText(current_profile->get_auth_name().c_str()); + authPasswordLineEdit->setText(current_profile->get_auth_pass().c_str()); + + uint8 aka_op[AKA_OPLEN]; + current_profile->get_auth_aka_op(aka_op); + authAkaOpLineEdit->setText(binary2hex(aka_op, AKA_OPLEN).c_str()); + + uint8 aka_amf[AKA_AMFLEN]; + current_profile->get_auth_aka_amf(aka_amf); + authAkaAmfLineEdit->setText(binary2hex(aka_amf, AKA_AMFLEN).c_str()); + + // SIP SERVER + registrarLineEdit->setText(current_profile->get_registrar().encode_noscheme().c_str()); + expirySpinBox->setValue(current_profile->get_registration_time()); + regAtStartupCheckBox->setChecked(current_profile->get_register_at_startup()); + regAddQvalueCheckBox->setChecked(current_profile->get_reg_add_qvalue()); + regQvalueLineEdit->setEnabled(current_profile->get_reg_add_qvalue()); + regQvalueLineEdit->setText(float2str(current_profile->get_reg_qvalue(), 3).c_str()); + useProxyCheckBox->setChecked(current_profile->get_use_outbound_proxy()); + proxyTextLabel->setEnabled(current_profile->get_use_outbound_proxy()); + proxyLineEdit->setEnabled(current_profile->get_use_outbound_proxy()); + if (current_profile->get_use_outbound_proxy()) { + proxyLineEdit->setText(current_profile-> + get_outbound_proxy().encode_noscheme().c_str()); + } else { + proxyLineEdit->clear(); + } + allRequestsCheckBox->setChecked(current_profile->get_all_requests_to_proxy()); + allRequestsCheckBox->setEnabled(current_profile->get_use_outbound_proxy()); + proxyNonResolvableCheckBox->setChecked(current_profile->get_non_resolvable_to_proxy()); + proxyNonResolvableCheckBox->setEnabled(current_profile->get_use_outbound_proxy()); + + // VOICE MAIL + vmAddressLineEdit->setText(current_profile->get_mwi_vm_address().c_str()); + if (current_profile->get_mwi_sollicited()) { + mwiTypeComboBox->setCurrentItem(idxMWISollicited); + mwiSollicitedGroupBox->setEnabled(true); + } else { + mwiTypeComboBox->setCurrentItem(idxMWIUnsollicited); + mwiSollicitedGroupBox->setEnabled(false); + } + mwiUserLineEdit->setText(current_profile->get_mwi_user().c_str()); + mwiServerLineEdit->setText(current_profile-> + get_mwi_server().encode_noscheme().c_str()); + mwiViaProxyCheckBox->setChecked(current_profile->get_mwi_via_proxy()); + mwiDurationSpinBox->setValue(current_profile->get_mwi_subscription_time()); + + // INSTANT MESSAGE + imMaxSessionsSpinBox->setValue(current_profile->get_im_max_sessions()); + isComposingCheckBox->setChecked(current_profile->get_im_send_iscomposing()); + + // PRESENCE + presPublishCheckBox->setChecked(current_profile->get_pres_publish_startup()); + presPublishTimeSpinBox->setValue(current_profile->get_pres_publication_time()); + presSubscribeTimeSpinBox->setValue(current_profile->get_pres_subscription_time()); + + // RTP AUDIO + // Codecs + QStringList allCodecs; + allCodecs.append(labelCodecG711a); + allCodecs.append(labelCodecG711u); + allCodecs.append(labelCodecGSM); +#ifdef HAVE_SPEEX + allCodecs.append(labelCodecSpeexNb); + allCodecs.append(labelCodecSpeexWb); + allCodecs.append(labelCodecSpeexUwb); +#endif +#ifdef HAVE_ILBC + allCodecs.append(labelCodecIlbc); +#endif + allCodecs.append(labelCodecG726_16); + allCodecs.append(labelCodecG726_24); + allCodecs.append(labelCodecG726_32); + allCodecs.append(labelCodecG726_40); + activeCodecListBox->clear(); + list audio_codecs = current_profile->get_codecs(); + for (list::iterator i = audio_codecs.begin(); i != audio_codecs.end(); i++) + { + activeCodecListBox->insertItem(codec2label(*i)); + allCodecs.remove(codec2label(*i)); + } + availCodecListBox->clear(); + if (!allCodecs.empty()) availCodecListBox->insertStringList(allCodecs); + + // G.711/G.726 ptime + ptimeSpinBox->setValue(current_profile->get_ptime()); + + // Codec preference + inFarEndCodecPrefCheckBox->setChecked(current_profile->get_in_obey_far_end_codec_pref()); + outFarEndCodecPrefCheckBox->setChecked(current_profile->get_out_obey_far_end_codec_pref()); + + // Speex preprocessing and AEC + spxDspVadCheckBox->setChecked(current_profile->get_speex_dsp_vad()); + spxDspAgcCheckBox->setChecked(current_profile->get_speex_dsp_agc()); + spxDspAecCheckBox->setChecked(current_profile->get_speex_dsp_aec()); + spxDspNrdCheckBox->setChecked(current_profile->get_speex_dsp_nrd()); + spxDspAgcLevelSpinBox->setValue(current_profile->get_speex_dsp_agc_level()); + spxDspAgcLevelTextLabel->setEnabled(current_profile->get_speex_dsp_agc()); + spxDspAgcLevelSpinBox->setEnabled(current_profile->get_speex_dsp_agc()); + + // Speex ([en/de]coding) + spxVbrCheckBox->setChecked(current_profile->get_speex_bit_rate_type() == BIT_RATE_VBR); + spxDtxCheckBox->setChecked(current_profile->get_speex_dtx()); + spxPenhCheckBox->setChecked(current_profile->get_speex_penh()); + spxQualitySpinBox->setValue(current_profile->get_speex_quality()); + spxComplexitySpinBox->setValue(current_profile->get_speex_complexity()); + spxNbPayloadSpinBox->setValue(current_profile->get_speex_nb_payload_type()); + spxWbPayloadSpinBox->setValue(current_profile->get_speex_wb_payload_type()); + spxUwbPayloadSpinBox->setValue(current_profile->get_speex_uwb_payload_type()); + + // iLBC + ilbcPayloadSpinBox->setValue(current_profile->get_ilbc_payload_type()); + + if (current_profile->get_ilbc_mode() == 20) { + ilbcPayloadSizeComboBox->setCurrentItem(idxIlbcMode20); + } else { + ilbcPayloadSizeComboBox->setCurrentItem(idxIlbcMode30); + } + + // G.726 + g72616PayloadSpinBox->setValue(current_profile->get_g726_16_payload_type()); + g72624PayloadSpinBox->setValue(current_profile->get_g726_24_payload_type()); + g72632PayloadSpinBox->setValue(current_profile->get_g726_32_payload_type()); + g72640PayloadSpinBox->setValue(current_profile->get_g726_40_payload_type()); + + if (current_profile->get_g726_packing() == G726_PACK_RFC3551) { + g726PackComboBox->setCurrentItem(idxG726PackRfc3551); + } else { + g726PackComboBox->setCurrentItem(idxG726PackAal2); + } + + // DTMF + switch (current_profile->get_dtmf_transport()) { + case DTMF_RFC2833: + dtmfTransportComboBox->setCurrentItem(idxDtmfRfc2833); + break; + case DTMF_INBAND: + dtmfTransportComboBox->setCurrentItem(idxDtmfInband); + break; + case DTMF_INFO: + dtmfTransportComboBox->setCurrentItem(idxDtmfInfo); + break; + default: + dtmfTransportComboBox->setCurrentItem(idxDtmfAuto); + break; + } + + dtmfPayloadTypeSpinBox->setValue(current_profile->get_dtmf_payload_type()); + dtmfDurationSpinBox->setValue(current_profile->get_dtmf_duration()); + dtmfPauseSpinBox->setValue(current_profile->get_dtmf_pause()); + dtmfVolumeSpinBox->setValue(-(current_profile->get_dtmf_volume())); + + // SIP PROTOCOL + switch (current_profile->get_hold_variant()) { + case HOLD_RFC2543: + holdVariantComboBox->setCurrentItem(idxHoldRfc2543); + break; + default: + holdVariantComboBox->setCurrentItem(idxHoldRfc3264); + break; + } + + maxForwardsCheckBox->setChecked(current_profile->get_check_max_forwards()); + missingContactCheckBox->setChecked(current_profile->get_allow_missing_contact_reg()); + regTimeCheckBox->setChecked(current_profile->get_registration_time_in_contact()); + compactHeadersCheckBox->setChecked(current_profile->get_compact_headers()); + multiValuesListCheckBox->setChecked( + current_profile->get_encode_multi_values_as_list()); + useDomainInContactCheckBox->setChecked( + current_profile->get_use_domain_in_contact()); + allowSdpChangeCheckBox->setChecked(current_profile->get_allow_sdp_change()); + allowRedirectionCheckBox->setChecked(current_profile->get_allow_redirection()); + askUserRedirectCheckBox->setEnabled(current_profile->get_allow_redirection()); + askUserRedirectCheckBox->setChecked(current_profile->get_ask_user_to_redirect()); + maxRedirectTextLabel->setEnabled(current_profile->get_allow_redirection()); + maxRedirectSpinBox->setEnabled(current_profile->get_allow_redirection()); + maxRedirectSpinBox->setValue(current_profile->get_max_redirections()); + ext100relComboBox->setCurrentItem( + ext_support2indexComboItem(current_profile->get_ext_100rel())); + extReplacesCheckBox->setChecked(current_profile->get_ext_replaces()); + allowReferCheckBox->setChecked(current_profile->get_allow_refer()); + askUserReferCheckBox->setEnabled(current_profile->get_allow_refer()); + askUserReferCheckBox->setChecked(current_profile->get_ask_user_to_refer()); + refereeHoldCheckBox->setEnabled(current_profile->get_allow_refer()); + refereeHoldCheckBox->setChecked(current_profile->get_referee_hold()); + referrerHoldCheckBox->setChecked(current_profile->get_referrer_hold()); + refreshReferSubCheckBox->setChecked(current_profile->get_auto_refresh_refer_sub()); + referAorCheckBox->setChecked(current_profile->get_attended_refer_to_aor()); + transferConsultInprogCheckBox->setChecked( + current_profile->get_allow_transfer_consultation_inprog()); + pPreferredIdCheckBox->setChecked(current_profile->get_send_p_preferred_id()); + + // Transport/NAT + switch (current_profile->get_sip_transport()) { + case SIP_TRANS_UDP: + sipTransportComboBox->setCurrentItem(idxSipTransportUDP); + break; + case SIP_TRANS_TCP: + sipTransportComboBox->setCurrentItem(idxSipTransportTCP); + break; + default: + sipTransportComboBox->setCurrentItem(idxSipTransportAuto); + break; + } + + udpThresholdSpinBox->setValue(current_profile->get_sip_transport_udp_threshold()); + udpThresholdTextLabel->setEnabled(current_profile->get_sip_transport() == SIP_TRANS_AUTO); + udpThresholdSpinBox->setEnabled(current_profile->get_sip_transport() == SIP_TRANS_AUTO); + + if (current_profile->get_use_nat_public_ip()) { + natStaticRadioButton->setChecked(true); + } else if (current_profile->get_use_stun()) { + natStunRadioButton->setChecked(true); + } else { + natNoneRadioButton->setChecked(true); + } + + publicIPTextLabel->setEnabled(current_profile->get_use_nat_public_ip()); + publicIPLineEdit->setEnabled(current_profile->get_use_nat_public_ip()); + publicIPLineEdit->setText(current_profile->get_nat_public_ip().c_str()); + stunServerTextLabel->setEnabled(current_profile->get_use_stun()); + stunServerLineEdit->setEnabled(current_profile->get_use_stun()); + stunServerLineEdit->setText(current_profile->get_stun_server(). + encode_noscheme().c_str()); + persistentTcpCheckBox->setChecked(current_profile->get_persistent_tcp()); + persistentTcpCheckBox->setEnabled(current_profile->get_sip_transport() == SIP_TRANS_TCP); + natKeepaliveCheckBox->setChecked(current_profile->get_enable_nat_keepalive()); + natKeepaliveCheckBox->setDisabled(current_profile->get_use_stun()); + + // ADDRESS FORMAT + displayTelUserCheckBox->setChecked(current_profile->get_display_useronly_phone()); + numericalUserIsTelCheckBox->setChecked( + current_profile->get_numerical_user_is_phone()); + removeSpecialCheckBox->setChecked( + current_profile->get_remove_special_phone_symbols()); + specialLineEdit->setText(current_profile->get_special_phone_symbols().c_str()); + useTelUriCheckBox->setChecked(current_profile->get_use_tel_uri_for_phone()); + + conversionListView->clear(); + conversionListView->setSorting(-1); + list conversions = current_profile->get_number_conversions(); + for (list::reverse_iterator i = conversions.rbegin(); i != conversions.rend(); i++) + { + new Q3ListViewItem(conversionListView, i->re.str().c_str(), i->fmt.c_str()); + } + + // TIMERS + tmrNoanswerSpinBox->setValue(current_profile->get_timer_noanswer()); + tmrNatKeepaliveSpinBox->setValue(current_profile->get_timer_nat_keepalive()); + + // RING TONES + ringtoneLineEdit->setText(current_profile->get_ringtone_file().c_str()); + ringbackLineEdit->setText(current_profile->get_ringback_file().c_str()); + + // SCRIPTS + incomingCallScriptLineEdit->setText(current_profile->get_script_incoming_call().c_str()); + inCallAnsweredLineEdit->setText(current_profile->get_script_in_call_answered().c_str()); + inCallFailedLineEdit->setText(current_profile->get_script_in_call_failed().c_str()); + outCallLineEdit->setText(current_profile->get_script_outgoing_call().c_str()); + outCallAnsweredLineEdit->setText(current_profile->get_script_out_call_answered().c_str()); + outCallFailedLineEdit->setText(current_profile->get_script_out_call_failed().c_str()); + localReleaseLineEdit->setText(current_profile->get_script_local_release().c_str()); + remoteReleaseLineEdit->setText(current_profile->get_script_remote_release().c_str()); + + // Security + zrtpEnabledCheckBox->setChecked(current_profile->get_zrtp_enabled()); + zrtpSettingsGroupBox->setEnabled(current_profile->get_zrtp_enabled()); + zrtpSendIfSupportedCheckBox->setChecked(current_profile->get_zrtp_send_if_supported()); + zrtpSdpCheckBox->setChecked(current_profile->get_zrtp_sdp()); + zrtpGoClearWarningCheckBox->setChecked(current_profile->get_zrtp_goclear_warning()); +} + +void UserProfileForm::initProfileList(list profiles, QString show_profile_name) +{ + profile_list = profiles; + + // Initialize user profile combo box + current_profile_idx = -1; + profileComboBox->clear(); + + t_user *show_profile = NULL; + int show_idx = 0; + int idx = 0; + for (list::iterator i = profile_list.begin(); i != profile_list.end(); i++) { + profileComboBox->insertItem((*i)->get_profile_name().c_str()); + if (show_profile_name == (*i)->get_profile_name().c_str()) { + show_idx = idx; + show_profile = *i; + } + idx++; + } + + profileComboBox->setEnabled(profile_list.size() > 1); + current_profile_idx = show_idx; + + if (show_profile == NULL) { + current_profile = profile_list.front(); + } else { + current_profile = show_profile; + } + profileComboBox->setCurrentItem(current_profile_idx); +} + +// Show the form +void UserProfileForm::show(list profiles, QString show_profile) +{ + map_last_cat.clear(); + initProfileList(profiles, show_profile); + populate(); + + // Show form + QDialog::show(); +} + +// Modal execution +int UserProfileForm::exec(list profiles, QString show_profile) +{ + map_last_cat.clear(); + initProfileList(profiles, show_profile); + populate(); + return QDialog::exec(); +} + +bool UserProfileForm::check_dynamic_payload(QSpinBox *spb, + Q3ValueList &checked_list) +{ + if (checked_list.contains(spb->value())) { + categoryListBox->setSelected(idxCatRtpAudio, true); + settingsWidgetStack->raiseWidget(pageRtpAudio); + QString msg = tr("Dynamic payload type %1 is used more than once.").arg(spb->value()); + ((t_gui *)ui)->cb_show_msg(this, msg.ascii(), MSG_CRITICAL); + spb->setFocus(); + return false; + } + + checked_list.append(spb->value()); + return true; +} + +list UserProfileForm::get_number_conversions() +{ + list conversions; + Q3ListViewItemIterator it(conversionListView); + while (it.current()) { + Q3ListViewItem *item = it.current(); + t_number_conversion c; + + try { + c.re.assign(item->text(colExpr).ascii()); + c.fmt = item->text(colReplace).ascii(); + conversions.push_back(c); + } catch (boost::bad_expression) { + // Should never happen as validity has been + // checked already. Just being defensive here. + } + + ++it; + } + + return conversions; +} + +bool UserProfileForm::validateValues() +{ + QString s; + + // Validity check user page + // SIP username is mandatory + if (usernameLineEdit->text().isEmpty()) { + categoryListBox->setSelected(idxCatUser, true); + settingsWidgetStack->raiseWidget(pageUser); + ((t_gui *)ui)->cb_show_msg(this, tr("You must fill in a user name for your SIP account.").ascii(), + MSG_CRITICAL); + usernameLineEdit->setFocus(); + return false; + } + + // SIP user domain is mandatory + if (domainLineEdit->text().isEmpty()) { + categoryListBox->setSelected(idxCatUser, true); + settingsWidgetStack->raiseWidget(pageUser); + ((t_gui *)ui)->cb_show_msg(this, tr( + "You must fill in a domain name for your SIP account.\n" + "This could be the hostname or IP address of your PC " + "if you want direct PC to PC dialing.").ascii(), + MSG_CRITICAL); + domainLineEdit->setFocus(); + return false; + } + + // Check validity of domain + s = USER_SCHEME; + s.append(':').append(domainLineEdit->text()); + t_url u_domain(s.ascii()); + if (!u_domain.is_valid() || u_domain.get_user() != "") { + categoryListBox->setSelected(idxCatUser, true); + settingsWidgetStack->raiseWidget(pageUser); + ((t_gui *)ui)->cb_show_msg(this, tr("Invalid domain.").ascii(), MSG_CRITICAL); + domainLineEdit->setFocus(); + return false; + } + + // Check validity of user + s = USER_SCHEME; + s.append(':').append(usernameLineEdit->text()).append('@'); + s.append(domainLineEdit->text()); + t_url u_user_domain(s.ascii()); + if (!u_user_domain.is_valid()) { + categoryListBox->setSelected(idxCatUser, true); + settingsWidgetStack->raiseWidget(pageUser); + ((t_gui *)ui)->cb_show_msg(this, tr("Invalid user name.").ascii(), MSG_CRITICAL); + usernameLineEdit->setFocus(); + return false; + } + + // Registrar + if (!registrarLineEdit->text().isEmpty()) { + s = USER_SCHEME; + s.append(':').append(registrarLineEdit->text()); + t_url u(s.ascii()); + if (!u.is_valid() || u.get_user() != "") { + categoryListBox->setSelected(idxCatSipServer, true); + settingsWidgetStack->raiseWidget(pageSipServer); + ((t_gui *)ui)->cb_show_msg(this, tr("Invalid value for registrar.").ascii(), + MSG_CRITICAL); + registrarLineEdit->setFocus(); + registrarLineEdit->selectAll(); + return false; + } + } + + // Outbound proxy + if (useProxyCheckBox->isChecked()) { + s = USER_SCHEME; + s.append(':').append(proxyLineEdit->text()); + t_url u(s.ascii()); + if (!u.is_valid() || u.get_user() != "") { + categoryListBox->setSelected(idxCatSipServer, true); + settingsWidgetStack->raiseWidget(pageSipServer); + ((t_gui *)ui)->cb_show_msg(this, tr("Invalid value for outbound proxy.").ascii(), + MSG_CRITICAL); + proxyLineEdit->setFocus(); + proxyLineEdit->selectAll(); + return false; + } + } + + + // Validity check voice mail page + if (mwiTypeComboBox->currentItem() == idxMWISollicited) { + // Mailbox user name is mandatory + if (mwiUserLineEdit->text().isEmpty()) { + categoryListBox->setSelected(idxCatVoiceMail, true); + settingsWidgetStack->raiseWidget(pageVoiceMail); + ((t_gui *)ui)->cb_show_msg(this, + tr("You must fill in a mailbox user name.").ascii(), + MSG_CRITICAL); + mwiUserLineEdit->setFocus(); + return false; + } + + // Mailbox server is mandatory + if (mwiServerLineEdit->text().isEmpty()) { + categoryListBox->setSelected(idxCatVoiceMail, true); + settingsWidgetStack->raiseWidget(pageVoiceMail); + ((t_gui *)ui)->cb_show_msg(this, + tr("You must fill in a mailbox server").ascii(), + MSG_CRITICAL); + mwiServerLineEdit->setFocus(); + return false; + } + + // Check validity of mailbox server + s = USER_SCHEME; + s.append(':').append(mwiServerLineEdit->text()); + t_url u_server(s.ascii()); + if (!u_server.is_valid() || u_server.get_user() != "") { + categoryListBox->setSelected(idxCatVoiceMail, true); + settingsWidgetStack->raiseWidget(pageVoiceMail); + ((t_gui *)ui)->cb_show_msg(this, tr("Invalid mailbox server.").ascii(), + MSG_CRITICAL); + mwiServerLineEdit->setFocus(); + return false; + } + + // Check validity of mailbox user name + s = USER_SCHEME; + s.append(':').append(mwiUserLineEdit->text()).append('@'); + s.append(mwiServerLineEdit->text()); + t_url u_user_server(s.ascii()); + if (!u_user_server.is_valid()) { + categoryListBox->setSelected(idxCatVoiceMail, true); + settingsWidgetStack->raiseWidget(pageVoiceMail); + ((t_gui *)ui)->cb_show_msg(this, tr("Invalid mailbox user name.").ascii(), + MSG_CRITICAL); + mwiUserLineEdit->setFocus(); + return false; + } + } + + // NAT public IP + if (natStaticRadioButton->isChecked()) { + if (publicIPLineEdit->text().isEmpty()){ + categoryListBox->setSelected(idxCatNat, true); + settingsWidgetStack->raiseWidget(pageNat); + ((t_gui *)ui)->cb_show_msg(this, tr("Value for public IP address missing.").ascii(), + MSG_CRITICAL); + publicIPLineEdit->setFocus(); + return false; + } + } + + // Check for double RTP dynamic payload types + Q3ValueList checked_types; + if (!check_dynamic_payload(spxNbPayloadSpinBox, checked_types) || + !check_dynamic_payload(spxWbPayloadSpinBox, checked_types) || + !check_dynamic_payload(spxUwbPayloadSpinBox, checked_types)) + { + rtpAudioTabWidget->showPage(tabSpeex); + return false; + } + + if (!check_dynamic_payload(ilbcPayloadSpinBox, checked_types)) { + rtpAudioTabWidget->showPage(tabIlbc); + return false; + } + + if (!check_dynamic_payload(g72616PayloadSpinBox, checked_types) || + !check_dynamic_payload(g72624PayloadSpinBox, checked_types) || + !check_dynamic_payload(g72632PayloadSpinBox, checked_types) || + !check_dynamic_payload(g72640PayloadSpinBox, checked_types)) { + rtpAudioTabWidget->showPage(tabG726); + return false; + } + + if (!check_dynamic_payload(dtmfPayloadTypeSpinBox, checked_types)) { + rtpAudioTabWidget->showPage(tabDtmf); + return false; + } + + // STUN server + if (natStunRadioButton->isChecked()) { + s = "stun:"; + s.append(stunServerLineEdit->text()); + t_url u(s.ascii()); + if (!u.is_valid() || u.get_user() != "") { + categoryListBox->setSelected(idxCatNat, true); + settingsWidgetStack->raiseWidget(pageNat); + ((t_gui *)ui)->cb_show_msg(this, tr("Invalid value for STUN server.").ascii(), + MSG_CRITICAL); + stunServerLineEdit->setFocus(); + stunServerLineEdit->selectAll(); + return false; + } + } + + // Clear outbound proxy if not used + if (!useProxyCheckBox->isChecked()) { + proxyLineEdit->clear(); + } + + // Clear sollicited MWI settings if unsollicited MWI is used + if (mwiTypeComboBox->currentItem() == idxMWIUnsollicited) { + t_user user_default; + mwiUserLineEdit->clear(); + mwiServerLineEdit->clear(); + mwiViaProxyCheckBox->setChecked(user_default.get_mwi_via_proxy()); + mwiDurationSpinBox->setValue(user_default.get_mwi_subscription_time()); + } + + // Clear NAT public IP if not used + if (!natStaticRadioButton->isChecked()) { + publicIPLineEdit->clear(); + } + + // Clear STUN server if not used + if (!natStunRadioButton->isChecked()) { + stunServerLineEdit->clear(); + } + + // Set all values in the current_profile object + // USER + if (current_profile->get_name() != usernameLineEdit->text().ascii() || + current_profile->get_display(false) != displayLineEdit->text().ascii() || + current_profile->get_domain() != domainLineEdit->text().ascii()) + { + current_profile->set_display(displayLineEdit->text().ascii()); + current_profile->set_name(usernameLineEdit->text().ascii()); + current_profile->set_domain (domainLineEdit->text().ascii()); + emit sipUserChanged(current_profile); + } + + current_profile->set_organization(organizationLineEdit->text().ascii()); + + uint8 new_aka_op[AKA_OPLEN]; + uint8 new_aka_amf[AKA_AMFLEN]; + uint8 current_aka_op[AKA_OPLEN]; + uint8 current_aka_amf[AKA_AMFLEN]; + + hex2binary(padleft(authAkaOpLineEdit->text().ascii(), '0', 32), new_aka_op); + hex2binary(padleft(authAkaAmfLineEdit->text().ascii(), '0', 4), new_aka_amf); + current_profile->get_auth_aka_op(current_aka_op); + current_profile->get_auth_aka_amf(current_aka_amf); + + if (current_profile->get_auth_realm() != authRealmLineEdit->text().ascii() || + current_profile->get_auth_name() != authNameLineEdit->text().ascii() || + current_profile->get_auth_pass() != authPasswordLineEdit->text().ascii() || + memcmp(current_aka_op, new_aka_op, AKA_OPLEN) != 0 || + memcmp(current_aka_amf, new_aka_amf, AKA_AMFLEN) != 0) + { + emit authCredentialsChanged(current_profile, + current_profile->get_auth_realm()); + + current_profile->set_auth_realm(authRealmLineEdit->text().ascii()); + current_profile->set_auth_name(authNameLineEdit->text().ascii()); + current_profile->set_auth_pass(authPasswordLineEdit->text().ascii()); + current_profile->set_auth_aka_op(new_aka_op); + current_profile->set_auth_aka_amf(new_aka_amf); + } + + // SIP SERVER + current_profile->set_use_registrar(!registrarLineEdit->text().isEmpty()); + s = USER_SCHEME; + s.append(':').append(registrarLineEdit->text()); + current_profile->set_registrar(t_url(s.ascii())); + current_profile->set_registration_time(expirySpinBox->value()); + current_profile->set_register_at_startup(regAtStartupCheckBox->isChecked()); + current_profile->set_reg_add_qvalue(regAddQvalueCheckBox->isChecked()); + current_profile->set_reg_qvalue(atof(regQvalueLineEdit->text().ascii())); + + current_profile->set_use_outbound_proxy(useProxyCheckBox->isChecked()); + s = USER_SCHEME; + s.append(':').append(proxyLineEdit->text()); + current_profile->set_outbound_proxy(t_url(s.ascii())); + current_profile->set_all_requests_to_proxy(allRequestsCheckBox->isChecked()); + current_profile->set_non_resolvable_to_proxy( + proxyNonResolvableCheckBox->isChecked()); + + // VOICE MAIL + current_profile->set_mwi_vm_address(vmAddressLineEdit->text().ascii()); + + bool mustTriggerMWISubscribe = false; + bool mwiSollicited = (mwiTypeComboBox->currentItem() == idxMWISollicited); + if (mwiSollicited) { + if (!current_profile->get_mwi_sollicited()) { + // Sollicited MWI now enabled. Subscribe after all MWI + // settings have been changed. + mustTriggerMWISubscribe = true; + } else { + s = USER_SCHEME; + s.append(':').append(mwiServerLineEdit->text()); + if (mwiUserLineEdit->text().ascii() != current_profile->get_mwi_user() || + t_url(s.ascii()) != current_profile->get_mwi_server() || + mwiViaProxyCheckBox->isChecked() != current_profile->get_mwi_via_proxy()) + { + // Sollicited MWI settings changed. Trigger unsubscribe + // of current MWI subscription. + emit mwiChangeUnsubscribe(current_profile); + + // Subscribe after the settings have been changed. + mustTriggerMWISubscribe = true; + } + } + } else { + if (current_profile->get_mwi_sollicited()) { + // MWI type changes to unsollicited. Trigger unsubscribe of + // current MWI subscription. + emit mwiChangeUnsubscribe(current_profile); + } + } + + current_profile->set_mwi_sollicited(mwiSollicited); + current_profile->set_mwi_user(mwiUserLineEdit->text().ascii()); + s = USER_SCHEME; + s.append(':').append(mwiServerLineEdit->text()); + current_profile->set_mwi_server(t_url(s.ascii())); + current_profile->set_mwi_via_proxy(mwiViaProxyCheckBox->isChecked()); + current_profile->set_mwi_subscription_time(mwiDurationSpinBox->value()); + + if (mustTriggerMWISubscribe) { + emit mwiChangeSubscribe(current_profile); + } + + // INSTANT MESSAGE + current_profile->set_im_max_sessions(imMaxSessionsSpinBox->value()); + current_profile->set_im_send_iscomposing(isComposingCheckBox->isChecked()); + + // PRESENCE + current_profile->set_pres_publish_startup(presPublishCheckBox->isChecked()); + current_profile->set_pres_publication_time(presPublishTimeSpinBox->value()); + current_profile->set_pres_subscription_time(presSubscribeTimeSpinBox->value()); + + // RTP AUDIO + // Codecs + list audio_codecs; + for (size_t i = 0; i < activeCodecListBox->count(); i++) { + audio_codecs.push_back(label2codec(activeCodecListBox->text(i))); + } + current_profile->set_codecs(audio_codecs); + + // G.711/G.726 ptime + current_profile->set_ptime(ptimeSpinBox->value()); + + // Codec preference + current_profile->set_in_obey_far_end_codec_pref(inFarEndCodecPrefCheckBox->isChecked()); + current_profile->set_out_obey_far_end_codec_pref(outFarEndCodecPrefCheckBox->isChecked()); + + // Speex preprocessing & AEC + current_profile->set_speex_dsp_vad(spxDspVadCheckBox->isChecked()); + current_profile->set_speex_dsp_agc(spxDspAgcCheckBox->isChecked()); + current_profile->set_speex_dsp_aec(spxDspAecCheckBox->isChecked()); + current_profile->set_speex_dsp_nrd(spxDspNrdCheckBox->isChecked()); + current_profile->set_speex_dsp_agc_level(spxDspAgcLevelSpinBox->value()); + + // Speex ([en/de]coding) + current_profile->set_speex_bit_rate_type((spxVbrCheckBox->isChecked() ? BIT_RATE_VBR : BIT_RATE_CBR)); + current_profile->set_speex_dtx(spxDtxCheckBox->isChecked()); + current_profile->set_speex_penh(spxPenhCheckBox->isChecked()); + current_profile->set_speex_quality(spxQualitySpinBox->value()); + current_profile->set_speex_complexity(spxComplexitySpinBox->value()); + current_profile->set_speex_nb_payload_type(spxNbPayloadSpinBox->value()); + current_profile->set_speex_wb_payload_type(spxWbPayloadSpinBox->value()); + current_profile->set_speex_uwb_payload_type(spxUwbPayloadSpinBox->value()); + + // iLBC + current_profile->set_ilbc_payload_type(ilbcPayloadSpinBox->value()); + switch (ilbcPayloadSizeComboBox->currentItem()) { + case idxIlbcMode20: + current_profile->set_ilbc_mode(20); + break; + default: + current_profile->set_ilbc_mode(30); + break; + } + + // G726 + current_profile->set_g726_16_payload_type(g72616PayloadSpinBox->value()); + current_profile->set_g726_24_payload_type(g72624PayloadSpinBox->value()); + current_profile->set_g726_32_payload_type(g72632PayloadSpinBox->value()); + current_profile->set_g726_40_payload_type(g72640PayloadSpinBox->value()); + + switch (g726PackComboBox->currentItem()) { + case idxG726PackRfc3551: + current_profile->set_g726_packing(G726_PACK_RFC3551); + break; + default: + current_profile->set_g726_packing(G726_PACK_AAL2); + break; + } + + // DTMF + switch (dtmfTransportComboBox->currentItem()) { + case idxDtmfRfc2833: + current_profile->set_dtmf_transport(DTMF_RFC2833); + break; + case idxDtmfInband: + current_profile->set_dtmf_transport(DTMF_INBAND); + break; + case idxDtmfInfo: + current_profile->set_dtmf_transport(DTMF_INFO); + break; + default: + current_profile->set_dtmf_transport(DTMF_AUTO); + break; + } + + current_profile->set_dtmf_payload_type(dtmfPayloadTypeSpinBox->value()); + current_profile->set_dtmf_duration(dtmfDurationSpinBox->value()); + current_profile->set_dtmf_pause(dtmfPauseSpinBox->value()); + current_profile->set_dtmf_volume(-(dtmfVolumeSpinBox->value())); + + // SIP PROTOCOL + switch (holdVariantComboBox->currentItem()) { + case idxHoldRfc2543: + current_profile->set_hold_variant(HOLD_RFC2543); + break; + default: + current_profile->set_hold_variant(HOLD_RFC3264); + break; + } + + current_profile->set_check_max_forwards(maxForwardsCheckBox->isChecked()); + current_profile->set_allow_missing_contact_reg(missingContactCheckBox->isChecked()); + current_profile->set_registration_time_in_contact(regTimeCheckBox->isChecked()); + current_profile->set_compact_headers(compactHeadersCheckBox->isChecked()); + current_profile->set_encode_multi_values_as_list( + multiValuesListCheckBox->isChecked()); + current_profile->set_use_domain_in_contact( + useDomainInContactCheckBox->isChecked()); + current_profile->set_allow_sdp_change(allowSdpChangeCheckBox->isChecked()); + current_profile->set_allow_redirection(allowRedirectionCheckBox->isChecked()); + current_profile->set_ask_user_to_redirect(askUserRedirectCheckBox->isChecked()); + current_profile->set_max_redirections(maxRedirectSpinBox->value()); + current_profile->set_ext_100rel(indexComboItem2ext_support( + ext100relComboBox->currentItem())); + current_profile->set_ext_replaces(extReplacesCheckBox->isChecked()); + current_profile->set_allow_refer(allowReferCheckBox->isChecked()); + current_profile->set_ask_user_to_refer(askUserReferCheckBox->isChecked()); + current_profile->set_referee_hold(refereeHoldCheckBox->isChecked()); + current_profile->set_referrer_hold(referrerHoldCheckBox->isChecked()); + current_profile->set_auto_refresh_refer_sub(refreshReferSubCheckBox->isChecked()); + current_profile->set_attended_refer_to_aor(referAorCheckBox->isChecked()); + current_profile->set_allow_transfer_consultation_inprog( + transferConsultInprogCheckBox->isChecked()); + current_profile->set_send_p_preferred_id(pPreferredIdCheckBox->isChecked()); + + // Transport/NAT + switch (sipTransportComboBox->currentItem()) { + case idxSipTransportUDP: + current_profile->set_sip_transport(SIP_TRANS_UDP); + break; + case idxSipTransportTCP: + current_profile->set_sip_transport(SIP_TRANS_TCP); + break; + default: + current_profile->set_sip_transport(SIP_TRANS_AUTO); + break; + } + + current_profile->set_sip_transport_udp_threshold(udpThresholdSpinBox->value()); + + current_profile->set_use_nat_public_ip(natStaticRadioButton->isChecked()); + current_profile->set_nat_public_ip(publicIPLineEdit->text().ascii()); + current_profile->set_use_stun(natStunRadioButton->isChecked()); + + if (current_profile->get_stun_server().encode_noscheme() != stunServerLineEdit->text().ascii() || + current_profile->get_enable_nat_keepalive() != natKeepaliveCheckBox->isChecked()) + { + s = "stun:"; + s.append(stunServerLineEdit->text()); + current_profile->set_stun_server(t_url(s.ascii())); + current_profile->set_enable_nat_keepalive(natKeepaliveCheckBox->isChecked()); + emit stunServerChanged(current_profile); + } + + current_profile->set_persistent_tcp(persistentTcpCheckBox->isChecked()); + + // ADDRESS FORMAT + current_profile->set_display_useronly_phone( + displayTelUserCheckBox->isChecked()); + current_profile->set_numerical_user_is_phone( + numericalUserIsTelCheckBox->isChecked()); + current_profile->set_remove_special_phone_symbols( + removeSpecialCheckBox->isChecked()); + current_profile->set_special_phone_symbols( + specialLineEdit->text().stripWhiteSpace().ascii()); + current_profile->set_number_conversions(get_number_conversions()); + current_profile->set_use_tel_uri_for_phone(useTelUriCheckBox->isChecked()); + + // TIMERS + current_profile->set_timer_noanswer(tmrNoanswerSpinBox->value()); + current_profile->set_timer_nat_keepalive(tmrNatKeepaliveSpinBox->value()); + + // RING TONES + current_profile->set_ringtone_file(ringtoneLineEdit->text().stripWhiteSpace().ascii()); + current_profile->set_ringback_file(ringbackLineEdit->text().stripWhiteSpace().ascii()); + + // SCRIPTS + current_profile->set_script_incoming_call(incomingCallScriptLineEdit-> + text().stripWhiteSpace().ascii()); + current_profile->set_script_in_call_answered(inCallAnsweredLineEdit-> + text().stripWhiteSpace().ascii()); + current_profile->set_script_in_call_failed(inCallFailedLineEdit-> + text().stripWhiteSpace().ascii()); + current_profile->set_script_outgoing_call(outCallLineEdit-> + text().stripWhiteSpace().ascii()); + current_profile->set_script_out_call_answered(outCallAnsweredLineEdit-> + text().stripWhiteSpace().ascii()); + current_profile->set_script_out_call_failed(outCallFailedLineEdit-> + text().stripWhiteSpace().ascii()); + current_profile->set_script_local_release(localReleaseLineEdit-> + text().stripWhiteSpace().ascii()); + current_profile->set_script_remote_release(remoteReleaseLineEdit-> + text().stripWhiteSpace().ascii()); + + // Security + current_profile->set_zrtp_enabled(zrtpEnabledCheckBox->isChecked()); + current_profile->set_zrtp_send_if_supported(zrtpSendIfSupportedCheckBox->isChecked()); + current_profile->set_zrtp_sdp(zrtpSdpCheckBox->isChecked()); + current_profile->set_zrtp_goclear_warning(zrtpGoClearWarningCheckBox->isChecked()); + + // Save user config + string error_msg; + if (!current_profile->write_config(current_profile->get_filename(), error_msg)) { + // Failed to write config file + ((t_gui *)ui)->cb_show_msg(this, error_msg, MSG_CRITICAL); + return false; + } + + return true; +} + +void UserProfileForm::validate() { + if (validateValues()) { + emit success(); + accept(); + } +} + +// User wants to change to another profile +void UserProfileForm::changeProfile(const QString &profileName) { + if (current_profile_idx == -1) { + // Initializing combo box + return; + } + + // Make the current profile permanent. + if (!validateValues()) { + // Current values are not valid. + // Do not change to the new profile. + profileComboBox->setCurrentItem(current_profile_idx); + return; + } + + // Store the current viewed category + map_last_cat[current_profile] = categoryListBox->index(categoryListBox->selectedItem()); + + // Change to new profile. + for (list::iterator i = profile_list.begin(); i != profile_list.end(); i++) { + if ((*i)->get_profile_name() == profileName.ascii()) { + current_profile = *i; + break; + } + } + + current_profile_idx = profileComboBox->currentItem(); + populate(); + + // Restore last viewed category + int idxCat = map_last_cat[current_profile]; + categoryListBox->setSelected(idxCat, true); + showCategory(idxCat); +} + +void UserProfileForm::chooseFile(QLineEdit *qle, const QString &filter, const QString &caption) +{ + QString file = Q3FileDialog::getOpenFileName( + ((t_gui *)ui)->get_last_file_browse_path(), + filter, this, "open file dialog", + caption); + if (!file.isEmpty()) { + qle->setText(file); + ((t_gui *)ui)->set_last_file_browse_path(QFileInfo(file).dirPath(true)); + } +} + +void UserProfileForm::chooseRingtone() +{ + chooseFile(ringtoneLineEdit, tr("Ring tones", "Description of .wav files in file dialog").append(" (*.wav)"), tr("Choose ring tone")); +} + +void UserProfileForm::chooseRingback() +{ + chooseFile(ringbackLineEdit, tr("Ring back tones", "Description of .wav files in file dialog").append(" (*.wav)"), "Choose ring back tone"); +} + +void UserProfileForm::chooseIncomingCallScript() +{ + chooseFile(incomingCallScriptLineEdit, tr("All files").append(" (*)"), tr("Choose incoming call script")); +} + +void UserProfileForm::chooseInCallAnsweredScript() +{ + chooseFile(inCallAnsweredLineEdit, tr("All files").append(" (*)"), tr("Choose incoming call answered script")); +} + +void UserProfileForm::chooseInCallFailedScript() +{ + chooseFile(inCallFailedLineEdit, tr("All files").append(" (*)"), tr("Choose incoming call failed script")); +} + +void UserProfileForm::chooseOutgoingCallScript() +{ + chooseFile(outCallLineEdit, tr("All files").append(" (*)"), tr("Choose outgoing call script")); +} + +void UserProfileForm::chooseOutCallAnsweredScript() +{ + chooseFile(outCallAnsweredLineEdit, tr("All files").append(" (*)"), tr("Choose outgoing call answered script")); +} + +void UserProfileForm::chooseOutCallFailedScript() +{ + chooseFile(outCallFailedLineEdit, tr("All files").append(" (*)"), tr("Choose outgoing call failed script")); +} + +void UserProfileForm::chooseLocalReleaseScript() +{ + chooseFile(localReleaseLineEdit, tr("All files").append(" (*)"), tr("Choose local release script")); +} + +void UserProfileForm::chooseRemoteReleaseScript() +{ + chooseFile(remoteReleaseLineEdit, tr("All files").append(" (*)"), tr("Choose remote release script")); +} + +void UserProfileForm::addCodec() { + for (size_t i = 0; i < availCodecListBox->count(); i++) { + if (availCodecListBox->isSelected(i)) { + activeCodecListBox->insertItem(availCodecListBox->text(i)); + activeCodecListBox->setSelected( + activeCodecListBox->count() - 1, true); + availCodecListBox->removeItem(i); + return; + } + } +} + +void UserProfileForm::removeCodec() { + for (size_t i = 0; i < activeCodecListBox->count(); i++) { + if (activeCodecListBox->isSelected(i)) { + availCodecListBox->insertItem(activeCodecListBox->text(i)); + availCodecListBox->setSelected( + availCodecListBox->count() - 1, true); + activeCodecListBox->removeItem(i); + return; + } + } +} + +void UserProfileForm::upCodec() { + Q3ListBoxItem *lbi = activeCodecListBox->selectedItem(); + if (!lbi) return; + + int idx = activeCodecListBox->index(lbi); + if (idx == 0) return; + + QString label = lbi->text(); + activeCodecListBox->removeItem(idx); + activeCodecListBox->insertItem(label, idx - 1); + activeCodecListBox->setSelected(idx - 1, true); +} + +void UserProfileForm::downCodec() { + Q3ListBoxItem *lbi = activeCodecListBox->selectedItem(); + if (!lbi) return; + + size_t idx = activeCodecListBox->index(lbi); + if (idx == activeCodecListBox->count() - 1) return; + + QString label = lbi->text(); + activeCodecListBox->removeItem(idx); + activeCodecListBox->insertItem(label, idx + 1); + activeCodecListBox->setSelected(idx + 1, true); +} + +void UserProfileForm::upConversion() { + Q3ListViewItem *lvi = conversionListView->selectedItem(); + if (!lvi) return; + + Q3ListViewItem *above = lvi->itemAbove(); + if (!above) return; + + Q3ListViewItem *newAbove = above->itemAbove(); + + if (newAbove) { + lvi->moveItem(newAbove); + } else { + above->moveItem(lvi); + } + + lvi->setSelected(true); +} + +void UserProfileForm::downConversion() { + Q3ListViewItem *lvi = conversionListView->selectedItem(); + if (!lvi) return; + + Q3ListViewItem *below = lvi->itemBelow(); + if (!below) return; + + lvi->moveItem(below); + lvi->setSelected(true); +} + +void UserProfileForm::addConversion() { + QString expr; + QString replace; + + NumberConversionForm f; + if (f.exec(expr, replace) == QDialog::Accepted) { + Q3ListViewItem *last = conversionListView->lastItem(); + if (last) { + new Q3ListViewItem(conversionListView, last, expr, replace); + } else { + new Q3ListViewItem(conversionListView, expr, replace); + } + } +} + +void UserProfileForm::editConversion() { + Q3ListViewItem *lvi = conversionListView->selectedItem(); + if (!lvi) return; + + QString expr = lvi->text(colExpr); + QString replace = lvi->text(colReplace); + + NumberConversionForm f; + if (f.exec(expr, replace) == QDialog::Accepted) { + lvi->setText(colExpr, expr); + lvi->setText(colReplace, replace); + } +} + +void UserProfileForm::removeConversion() { + Q3ListViewItem *lvi = conversionListView->selectedItem(); + if (!lvi) return; + delete lvi; +} + +void UserProfileForm::testConversion() { + QString number = testConversionLineEdit->text(); + if (number.isEmpty()) return; + + bool remove_special_phone_symbols = removeSpecialCheckBox->isChecked(); + QString special_phone_symbols = specialLineEdit->text(); + + number = remove_white_space(number.ascii()).c_str(); + + // Remove special symbols + if (remove_special_phone_symbols && + looks_like_phone(number.ascii(), special_phone_symbols.ascii())) + { + number = remove_symbols( + number.ascii(), special_phone_symbols.ascii()).c_str(); + } + + QString msg = tr("%1 converts to %2") + .arg(number) + .arg(current_profile->convert_number(number.ascii(), get_number_conversions()).c_str()); + + ((t_gui *)ui)->cb_show_msg(this, msg.ascii(), MSG_INFO); +} + +void UserProfileForm::changeMWIType(int idxMWIType) { + if (idxMWIType == idxMWISollicited) { + mwiSollicitedGroupBox->setEnabled(true); + + // Set defaults + if (mwiUserLineEdit->text().isEmpty()) { + mwiUserLineEdit->setText(usernameLineEdit->text()); + } + if (mwiServerLineEdit->text().isEmpty()) { + mwiServerLineEdit->setText(domainLineEdit->text()); + mwiViaProxyCheckBox->setChecked(useProxyCheckBox->isChecked()); + } + } else { + mwiSollicitedGroupBox->setEnabled(false); + } +} + +void UserProfileForm::changeSipTransportProtocol(int idx) { + udpThresholdTextLabel->setEnabled(idx == idxSipTransportAuto); + udpThresholdSpinBox->setEnabled(idx == idxSipTransportAuto); + persistentTcpCheckBox->setEnabled(idx == idxSipTransportTCP); +} diff --git a/src/gui/userprofileform.h b/src/gui/userprofileform.h new file mode 100644 index 0000000..b339210 --- /dev/null +++ b/src/gui/userprofileform.h @@ -0,0 +1,79 @@ +#ifndef USERPROFILEFORM_H +#define USERPROFILEFORM_H +#include +#include +#include "Qt3Support/Q3ValueList" +#include "user.h" +#include "ui_userprofileform.h" + +class UserProfileForm : public QDialog, public Ui::UserProfileForm +{ + Q_OBJECT + +public: + UserProfileForm(QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WindowFlags fl = 0); + ~UserProfileForm(); + + virtual t_audio_codec label2codec( const QString & label ); + virtual QString codec2label( t_audio_codec & codec ); + virtual int ext_support2indexComboItem( t_ext_support ext ); + virtual t_ext_support indexComboItem2ext_support( int index ); + virtual int exec( list profiles, QString show_profile ); + virtual bool check_dynamic_payload( QSpinBox * spb, Q3ValueList & checked_list ); + virtual list get_number_conversions(); + virtual bool validateValues(); + +public slots: + virtual void showCategory( int index ); + virtual void populate(); + virtual void initProfileList( list profiles, QString show_profile_name ); + virtual void show( list profiles, QString show_profile ); + virtual void validate(); + virtual void changeProfile( const QString & profileName ); + virtual void chooseFile( QLineEdit * qle, const QString & filter, const QString & caption ); + virtual void chooseRingtone(); + virtual void chooseRingback(); + virtual void chooseIncomingCallScript(); + virtual void chooseInCallAnsweredScript(); + virtual void chooseInCallFailedScript(); + virtual void chooseOutgoingCallScript(); + virtual void chooseOutCallAnsweredScript(); + virtual void chooseOutCallFailedScript(); + virtual void chooseLocalReleaseScript(); + virtual void chooseRemoteReleaseScript(); + virtual void addCodec(); + virtual void removeCodec(); + virtual void upCodec(); + virtual void downCodec(); + virtual void upConversion(); + virtual void downConversion(); + virtual void addConversion(); + virtual void editConversion(); + virtual void removeConversion(); + virtual void testConversion(); + virtual void changeMWIType( int idxMWIType ); + virtual void changeSipTransportProtocol( int idx ); + +signals: + void stunServerChanged(t_user *); + void authCredentialsChanged(t_user *, const string &); + void sipUserChanged(t_user *); + void success(); + void mwiChangeUnsubscribe(t_user *); + void mwiChangeSubscribe(t_user *); + +protected slots: + virtual void languageChange(); + +private: + map map_last_cat; + t_user *current_profile; + int current_profile_idx; + list profile_list; + + void init(); + +}; + + +#endif diff --git a/src/gui/userprofileform.ui b/src/gui/userprofileform.ui index 4758dcc..5e28b38 100644 --- a/src/gui/userprofileform.ui +++ b/src/gui/userprofileform.ui @@ -73,7 +73,7 @@ User - penguin.png + :/icons/images/penguin.png @@ -81,7 +81,7 @@ SIP server - package_network.png + :/icons/images/package_network.png @@ -89,7 +89,7 @@ Voice mail - mwi_none.png + :/icons/images/mwi_none.png @@ -97,7 +97,7 @@ Instant message - message32.png + :/icons/images/message32.png @@ -105,7 +105,7 @@ Presence - presence.png + :/icons/images/presence.png @@ -113,7 +113,7 @@ RTP audio - kmix.png + :/icons/images/kmix.png @@ -121,7 +121,7 @@ SIP protocol - package_system.png + :/icons/images/package_system.png @@ -129,7 +129,7 @@ Transport/NAT - yast_babelfish.png + :/icons/images/yast_babelfish.png @@ -137,7 +137,7 @@ Address format - yast_PhoneTTOffhook.png + :/icons/images/yast_PhoneTTOffhook.png @@ -145,7 +145,7 @@ Timers - clock.png + :/icons/images/clock.png @@ -153,7 +153,7 @@ Ring tones - knotify.png + :/icons/images/knotify.png @@ -161,7 +161,7 @@ Scripts - edit.png + :/icons/images/edit.png @@ -169,7 +169,7 @@ Security - encrypted32.png + :/icons/images/encrypted32.png @@ -991,7 +991,7 @@ If you disable this option, then the first codec from the active codecs that is - 1rightarrow.png + :/icons/images/1rightarrow.png Move a codec from the list of available codecs to the list of active codecs. @@ -1004,7 +1004,7 @@ If you disable this option, then the first codec from the active codecs that is - 1leftarrow.png + :/icons/images/1leftarrow.png Move a codec from the list of active codecs to the list of available codecs. @@ -1074,7 +1074,7 @@ If you disable this option, then the first codec from the active codecs that is - 1uparrow.png + :/icons/images/1uparrow.png Move a codec upwards in the list of active codecs, i.e. increase its preference of use. @@ -1087,7 +1087,7 @@ If you disable this option, then the first codec from the active codecs that is - 1downarrow.png + :/icons/images/1downarrow.png Move a codec downwards in the list of active codecs, i.e. decrease its preference of use. @@ -3172,7 +3172,7 @@ Match expression = 0[0-9]* , Replace = 9$&<br> - 1uparrow.png + :/icons/images/1uparrow.png Move the selected number conversion rule upwards in the list. @@ -3185,7 +3185,7 @@ Match expression = 0[0-9]* , Replace = 9$&<br> - 1downarrow.png + :/icons/images/1downarrow.png Move the selected number conversion rule downwards in the list. @@ -3526,7 +3526,7 @@ Match expression = 0[0-9]* , Replace = 9$&<br> - fileopen.png + :/icons/images/fileopen.png Select ring back tone file. @@ -3542,7 +3542,7 @@ Match expression = 0[0-9]* , Replace = 9$&<br> - fileopen.png + :/icons/images/fileopen.png Select ring tone file. @@ -3671,7 +3671,7 @@ The values of all SIP headers of the outgoing SIP BYE request are passed in envi - fileopen.png + :/icons/images/fileopen.png Select script file. @@ -3687,7 +3687,7 @@ The values of all SIP headers of the outgoing SIP BYE request are passed in envi - fileopen.png + :/icons/images/fileopen.png Select script file. @@ -3703,7 +3703,7 @@ The values of all SIP headers of the outgoing SIP BYE request are passed in envi - fileopen.png + :/icons/images/fileopen.png Select script file. @@ -3734,7 +3734,7 @@ The values of all SIP headers of the outgoing SIP failure response are passed in - fileopen.png + :/icons/images/fileopen.png Select script file. @@ -3765,7 +3765,7 @@ The values of all SIP headers of the incoming SIP BYE request are passed in envi - fileopen.png + :/icons/images/fileopen.png Select script file. @@ -3882,7 +3882,7 @@ The values of all SIP headers of the outgoing 200 OK are passed in environment v - fileopen.png + :/icons/images/fileopen.png Select script file. @@ -3967,7 +3967,7 @@ The values of all SIP headers of the outgoing INVITE are passed in environment v - fileopen.png + :/icons/images/fileopen.png Select script file. @@ -4009,7 +4009,7 @@ The values of all SIP headers of the outgoing INVITE are passed in environment v - fileopen.png + :/icons/images/fileopen.png Select script file. diff --git a/src/gui/userprofileform.ui.h b/src/gui/userprofileform.ui.h deleted file mode 100644 index 007ea01..0000000 --- a/src/gui/userprofileform.ui.h +++ /dev/null @@ -1,1461 +0,0 @@ -//Added by qt3to4: -#include -#include -/**************************************************************************** -** ui.h extension file, included from the uic-generated form implementation. -** -** If you wish to add, delete or rename functions or slots use -** Qt Designer which will update this file, preserving your code. Create an -** init() function in place of a constructor, and a destroy() function in -** place of a destructor. -*****************************************************************************/ -/* - Copyright (C) 2005-2009 Michel de Boer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - - -// Indices of categories in the category list box -#define idxCatUser 0 -#define idxCatSipServer 1 -#define idxCatVoiceMail 2 -#define idxCatIM 3 -#define idxCatPresence 4 -#define idxCatRtpAudio 5 -#define idxCatSipProtocol 6 -#define idxCatNat 7 -#define idxCatAddrFmt 8 -#define idxCatTimers 9 -#define idxCatRingTones 10 -#define idxCatScripts 11 -#define idxCatSecurity 12 - -// Indices of call hold variants in the call hold variant list box -#define idxHoldRfc2543 0 -#define idxHoldRfc3264 1 - -// Indices of SIP extension support types in the list box -#define idxExtDisabled 0 -#define idxExtSupported 1 -#define idxExtRequired 2 -#define idxExtPreferred 3 - -// Indices of RTP audio tabs -#define idxRtpCodecs 0 -#define idxRtpPreprocessing 1 -#define idxRtpIlbc 2 -#define idxRtpSpeex 3 -#define idxRtpDtmf 4 - -// Codec labels -#define labelCodecG711a "G.711 A-law" -#define labelCodecG711u "G.711 u-law" -#define labelCodecGSM "GSM" -#define labelCodecSpeexNb "speex-nb (8 kHz)" -#define labelCodecSpeexWb "speex-wb (16 kHz)" -#define labelCodecSpeexUwb "speex-uwb (32 kHz)" -#define labelCodecIlbc "iLBC" -#define labelCodecG726_16 "G.726 16 kbps" -#define labelCodecG726_24 "G.726 24 kbps" -#define labelCodecG726_32 "G.726 32 kbps" -#define labelCodecG726_40 "G.726 40 kbps" - -// Indices of iLBC modes -#define idxIlbcMode20 0 -#define idxIlbcMode30 1 - -// Indices of G.726 packing modes -#define idxG726PackRfc3551 0 -#define idxG726PackAal2 1 - -// Indices of DTMF transport modes in the DTMF transport list box -#define idxDtmfAuto 0 -#define idxDtmfRfc2833 1 -#define idxDtmfInband 2 -#define idxDtmfInfo 3 - -// Columns in the number conversion list view -#define colExpr 0 -#define colReplace 1 - -// MWI type indices -#define idxMWIUnsollicited 0 -#define idxMWISollicited 1 - -// SIP transport protocol indices -#define idxSipTransportAuto 0 -#define idxSipTransportUDP 1 -#define idxSipTransportTCP 2 - -void UserProfileForm::init() -{ - QRegExp rxNoSpace("\\S*"); - QRegExp rxNoAtSign("[^@]*"); - QRegExp rxQvalue("(0\\.[0-9]{0,3})|(1\\.0{0,3})"); - QRegExp rxAkaOpValue("[a-zA-Z0-9]{0,32}"); - QRegExp rxAkaAmfValue("[a-zA-Z0-9]{0,4}"); - - // Set validators - // USER - domainLineEdit->setValidator(new QRegExpValidator(rxNoSpace, this)); - authAkaOpLineEdit->setValidator(new QRegExpValidator(rxAkaOpValue, this)); - authAkaAmfLineEdit->setValidator(new QRegExpValidator(rxAkaAmfValue, this)); - - // SIP SERVER - registrarLineEdit->setValidator(new QRegExpValidator(rxNoSpace, this)); - regQvalueLineEdit->setValidator(new QRegExpValidator(rxQvalue, this)); - proxyLineEdit->setValidator(new QRegExpValidator(rxNoSpace, this)); - - // Voice mail - mwiServerLineEdit->setValidator(new QRegExpValidator(rxNoSpace, this)); - - // NAT - publicIPLineEdit->setValidator(new QRegExpValidator(rxNoSpace, this)); - - // Address format - testConversionLineEdit->setValidator(new QRegExpValidator(rxNoAtSign, this)); - -#ifndef HAVE_SPEEX - // Speex & (Speex) Preprocessing - speexGroupBox->hide(); - preprocessingGroupBox->hide(); - rtpAudioTabWidget->setTabEnabled(rtpAudioTabWidget->page(idxRtpSpeex), false); - rtpAudioTabWidget->setTabEnabled(rtpAudioTabWidget->page(idxRtpPreprocessing), false); -#endif -#ifndef HAVE_ILBC - // iLBC - ilbcGroupBox->hide(); - rtpAudioTabWidget->setTabEnabled(rtpAudioTabWidget->page(idxRtpIlbc), false); -#endif -#ifndef HAVE_ZRTP - // Zrtp - zrtpEnabledCheckBox->setEnabled(false); - zrtpSettingsGroupBox->hide(); -#endif - - // Set toolbutton icons for disabled options. - QIcon i; - i = openRingtoneToolButton->iconSet(); - i.setPixmap(qPixmapFromMimeSource("fileopen-disabled.png"), - QIcon::Automatic, QIcon::Disabled); - openRingtoneToolButton->setIconSet(i); - openRingbackToolButton->setIconSet(i); - openIncomingCallScriptToolButton->setIconSet(i); -} - -void UserProfileForm::showCategory( int index ) -{ - if (index == idxCatUser) { - settingsWidgetStack->raiseWidget(pageUser); - } else if (index == idxCatSipServer) { - settingsWidgetStack->raiseWidget(pageSipServer); - } else if (index == idxCatVoiceMail) { - settingsWidgetStack->raiseWidget(pageVoiceMail); - } else if (index == idxCatIM) { - settingsWidgetStack->raiseWidget(pageIM); - } else if (index == idxCatPresence) { - settingsWidgetStack->raiseWidget(pagePresence); - } else if (index == idxCatRtpAudio) { - settingsWidgetStack->raiseWidget(pageRtpAudio); - } else if (index == idxCatSipProtocol) { - settingsWidgetStack->raiseWidget(pageSipProtocol); - } else if (index == idxCatNat) { - settingsWidgetStack->raiseWidget(pageNat); - } else if (index == idxCatAddrFmt) { - settingsWidgetStack->raiseWidget(pageAddressFormat); - } else if (index == idxCatTimers) { - settingsWidgetStack->raiseWidget(pageTimers); - } else if (index == idxCatRingTones) { - settingsWidgetStack->raiseWidget(pageRingTones); - } else if (index == idxCatScripts) { - settingsWidgetStack->raiseWidget(pageScripts); - } else if (index == idxCatSecurity) { - settingsWidgetStack->raiseWidget(pageSecurity); - } -} - -// Convert a label to a codec -t_audio_codec UserProfileForm::label2codec(const QString &label) { - if (label == labelCodecG711a) { - return CODEC_G711_ALAW; - } else if (label == labelCodecG711u) { - return CODEC_G711_ULAW; - } else if (label == labelCodecGSM) { - return CODEC_GSM; - } else if (label == labelCodecSpeexNb) { - return CODEC_SPEEX_NB; - } else if (label == labelCodecSpeexWb) { - return CODEC_SPEEX_WB; - } else if (label == labelCodecSpeexUwb) { - return CODEC_SPEEX_UWB; - } else if (label == labelCodecIlbc) { - return CODEC_ILBC; - } else if (label == labelCodecG726_16) { - return CODEC_G726_16; - } else if (label == labelCodecG726_24) { - return CODEC_G726_24; - } else if (label == labelCodecG726_32) { - return CODEC_G726_32; - } else if (label == labelCodecG726_40) { - return CODEC_G726_40; - } - return CODEC_NULL; -} - -// Convert a codec to a label -QString UserProfileForm::codec2label(t_audio_codec &codec) { - switch (codec) { - case CODEC_G711_ALAW: - return labelCodecG711a; - case CODEC_G711_ULAW: - return labelCodecG711u; - case CODEC_GSM: - return labelCodecGSM; - case CODEC_SPEEX_NB: - return labelCodecSpeexNb; - case CODEC_SPEEX_WB: - return labelCodecSpeexWb; - case CODEC_SPEEX_UWB: - return labelCodecSpeexUwb; - case CODEC_ILBC: - return labelCodecIlbc; - case CODEC_G726_16: - return labelCodecG726_16; - case CODEC_G726_24: - return labelCodecG726_24; - case CODEC_G726_32: - return labelCodecG726_32; - case CODEC_G726_40: - return labelCodecG726_40; - default: - return ""; - } -} - -// Convert t_ext_support to an index in the SIP extension combo box -int UserProfileForm::ext_support2indexComboItem(t_ext_support ext) { - switch(ext) { - case EXT_DISABLED: - return idxExtDisabled; - case EXT_SUPPORTED: - return idxExtSupported; - case EXT_REQUIRED: - return idxExtRequired; - case EXT_PREFERRED: - return idxExtPreferred; - default: - return idxExtDisabled; - } - - return idxExtDisabled; -} - -t_ext_support UserProfileForm::indexComboItem2ext_support(int index) { - switch(index) { - case idxExtDisabled: - return EXT_DISABLED; - case idxExtSupported: - return EXT_SUPPORTED; - case idxExtRequired: - return EXT_REQUIRED; - case idxExtPreferred: - return EXT_PREFERRED; - } - - return EXT_DISABLED; -} - -// Populate the form -void UserProfileForm::populate() -{ - QString s; - - // Set user profile name in the titlebar - s = PRODUCT_NAME; - s.append(" - ").append(tr("User profile:")).append(" "); - s.append(current_profile->get_profile_name().c_str()); - setCaption(s); - - // Select the User category - categoryListBox->setSelected(idxCatUser, true); - settingsWidgetStack->raiseWidget(pageUser); - - // Set focus on first field - displayLineEdit->setFocus(); - - // Set the values of the current_profile object in the form - // USER - displayLineEdit->setText(current_profile->get_display(false).c_str()); - usernameLineEdit->setText(current_profile->get_name().c_str()); - domainLineEdit->setText(current_profile->get_domain().c_str()); - organizationLineEdit->setText(current_profile->get_organization().c_str()); - authRealmLineEdit->setText(current_profile->get_auth_realm().c_str()); - authNameLineEdit->setText(current_profile->get_auth_name().c_str()); - authPasswordLineEdit->setText(current_profile->get_auth_pass().c_str()); - - uint8 aka_op[AKA_OPLEN]; - current_profile->get_auth_aka_op(aka_op); - authAkaOpLineEdit->setText(binary2hex(aka_op, AKA_OPLEN).c_str()); - - uint8 aka_amf[AKA_AMFLEN]; - current_profile->get_auth_aka_amf(aka_amf); - authAkaAmfLineEdit->setText(binary2hex(aka_amf, AKA_AMFLEN).c_str()); - - // SIP SERVER - registrarLineEdit->setText(current_profile->get_registrar().encode_noscheme().c_str()); - expirySpinBox->setValue(current_profile->get_registration_time()); - regAtStartupCheckBox->setChecked(current_profile->get_register_at_startup()); - regAddQvalueCheckBox->setChecked(current_profile->get_reg_add_qvalue()); - regQvalueLineEdit->setEnabled(current_profile->get_reg_add_qvalue()); - regQvalueLineEdit->setText(float2str(current_profile->get_reg_qvalue(), 3).c_str()); - useProxyCheckBox->setChecked(current_profile->get_use_outbound_proxy()); - proxyTextLabel->setEnabled(current_profile->get_use_outbound_proxy()); - proxyLineEdit->setEnabled(current_profile->get_use_outbound_proxy()); - if (current_profile->get_use_outbound_proxy()) { - proxyLineEdit->setText(current_profile-> - get_outbound_proxy().encode_noscheme().c_str()); - } else { - proxyLineEdit->clear(); - } - allRequestsCheckBox->setChecked(current_profile->get_all_requests_to_proxy()); - allRequestsCheckBox->setEnabled(current_profile->get_use_outbound_proxy()); - proxyNonResolvableCheckBox->setChecked(current_profile->get_non_resolvable_to_proxy()); - proxyNonResolvableCheckBox->setEnabled(current_profile->get_use_outbound_proxy()); - - // VOICE MAIL - vmAddressLineEdit->setText(current_profile->get_mwi_vm_address().c_str()); - if (current_profile->get_mwi_sollicited()) { - mwiTypeComboBox->setCurrentItem(idxMWISollicited); - mwiSollicitedGroupBox->setEnabled(true); - } else { - mwiTypeComboBox->setCurrentItem(idxMWIUnsollicited); - mwiSollicitedGroupBox->setEnabled(false); - } - mwiUserLineEdit->setText(current_profile->get_mwi_user().c_str()); - mwiServerLineEdit->setText(current_profile-> - get_mwi_server().encode_noscheme().c_str()); - mwiViaProxyCheckBox->setChecked(current_profile->get_mwi_via_proxy()); - mwiDurationSpinBox->setValue(current_profile->get_mwi_subscription_time()); - - // INSTANT MESSAGE - imMaxSessionsSpinBox->setValue(current_profile->get_im_max_sessions()); - isComposingCheckBox->setChecked(current_profile->get_im_send_iscomposing()); - - // PRESENCE - presPublishCheckBox->setChecked(current_profile->get_pres_publish_startup()); - presPublishTimeSpinBox->setValue(current_profile->get_pres_publication_time()); - presSubscribeTimeSpinBox->setValue(current_profile->get_pres_subscription_time()); - - // RTP AUDIO - // Codecs - QStringList allCodecs; - allCodecs.append(labelCodecG711a); - allCodecs.append(labelCodecG711u); - allCodecs.append(labelCodecGSM); -#ifdef HAVE_SPEEX - allCodecs.append(labelCodecSpeexNb); - allCodecs.append(labelCodecSpeexWb); - allCodecs.append(labelCodecSpeexUwb); -#endif -#ifdef HAVE_ILBC - allCodecs.append(labelCodecIlbc); -#endif - allCodecs.append(labelCodecG726_16); - allCodecs.append(labelCodecG726_24); - allCodecs.append(labelCodecG726_32); - allCodecs.append(labelCodecG726_40); - activeCodecListBox->clear(); - list audio_codecs = current_profile->get_codecs(); - for (list::iterator i = audio_codecs.begin(); i != audio_codecs.end(); i++) - { - activeCodecListBox->insertItem(codec2label(*i)); - allCodecs.remove(codec2label(*i)); - } - availCodecListBox->clear(); - if (!allCodecs.empty()) availCodecListBox->insertStringList(allCodecs); - - // G.711/G.726 ptime - ptimeSpinBox->setValue(current_profile->get_ptime()); - - // Codec preference - inFarEndCodecPrefCheckBox->setChecked(current_profile->get_in_obey_far_end_codec_pref()); - outFarEndCodecPrefCheckBox->setChecked(current_profile->get_out_obey_far_end_codec_pref()); - - // Speex preprocessing and AEC - spxDspVadCheckBox->setChecked(current_profile->get_speex_dsp_vad()); - spxDspAgcCheckBox->setChecked(current_profile->get_speex_dsp_agc()); - spxDspAecCheckBox->setChecked(current_profile->get_speex_dsp_aec()); - spxDspNrdCheckBox->setChecked(current_profile->get_speex_dsp_nrd()); - spxDspAgcLevelSpinBox->setValue(current_profile->get_speex_dsp_agc_level()); - spxDspAgcLevelTextLabel->setEnabled(current_profile->get_speex_dsp_agc()); - spxDspAgcLevelSpinBox->setEnabled(current_profile->get_speex_dsp_agc()); - - // Speex ([en/de]coding) - spxVbrCheckBox->setChecked(current_profile->get_speex_bit_rate_type() == BIT_RATE_VBR); - spxDtxCheckBox->setChecked(current_profile->get_speex_dtx()); - spxPenhCheckBox->setChecked(current_profile->get_speex_penh()); - spxQualitySpinBox->setValue(current_profile->get_speex_quality()); - spxComplexitySpinBox->setValue(current_profile->get_speex_complexity()); - spxNbPayloadSpinBox->setValue(current_profile->get_speex_nb_payload_type()); - spxWbPayloadSpinBox->setValue(current_profile->get_speex_wb_payload_type()); - spxUwbPayloadSpinBox->setValue(current_profile->get_speex_uwb_payload_type()); - - // iLBC - ilbcPayloadSpinBox->setValue(current_profile->get_ilbc_payload_type()); - - if (current_profile->get_ilbc_mode() == 20) { - ilbcPayloadSizeComboBox->setCurrentItem(idxIlbcMode20); - } else { - ilbcPayloadSizeComboBox->setCurrentItem(idxIlbcMode30); - } - - // G.726 - g72616PayloadSpinBox->setValue(current_profile->get_g726_16_payload_type()); - g72624PayloadSpinBox->setValue(current_profile->get_g726_24_payload_type()); - g72632PayloadSpinBox->setValue(current_profile->get_g726_32_payload_type()); - g72640PayloadSpinBox->setValue(current_profile->get_g726_40_payload_type()); - - if (current_profile->get_g726_packing() == G726_PACK_RFC3551) { - g726PackComboBox->setCurrentItem(idxG726PackRfc3551); - } else { - g726PackComboBox->setCurrentItem(idxG726PackAal2); - } - - // DTMF - switch (current_profile->get_dtmf_transport()) { - case DTMF_RFC2833: - dtmfTransportComboBox->setCurrentItem(idxDtmfRfc2833); - break; - case DTMF_INBAND: - dtmfTransportComboBox->setCurrentItem(idxDtmfInband); - break; - case DTMF_INFO: - dtmfTransportComboBox->setCurrentItem(idxDtmfInfo); - break; - default: - dtmfTransportComboBox->setCurrentItem(idxDtmfAuto); - break; - } - - dtmfPayloadTypeSpinBox->setValue(current_profile->get_dtmf_payload_type()); - dtmfDurationSpinBox->setValue(current_profile->get_dtmf_duration()); - dtmfPauseSpinBox->setValue(current_profile->get_dtmf_pause()); - dtmfVolumeSpinBox->setValue(-(current_profile->get_dtmf_volume())); - - // SIP PROTOCOL - switch (current_profile->get_hold_variant()) { - case HOLD_RFC2543: - holdVariantComboBox->setCurrentItem(idxHoldRfc2543); - break; - default: - holdVariantComboBox->setCurrentItem(idxHoldRfc3264); - break; - } - - maxForwardsCheckBox->setChecked(current_profile->get_check_max_forwards()); - missingContactCheckBox->setChecked(current_profile->get_allow_missing_contact_reg()); - regTimeCheckBox->setChecked(current_profile->get_registration_time_in_contact()); - compactHeadersCheckBox->setChecked(current_profile->get_compact_headers()); - multiValuesListCheckBox->setChecked( - current_profile->get_encode_multi_values_as_list()); - useDomainInContactCheckBox->setChecked( - current_profile->get_use_domain_in_contact()); - allowSdpChangeCheckBox->setChecked(current_profile->get_allow_sdp_change()); - allowRedirectionCheckBox->setChecked(current_profile->get_allow_redirection()); - askUserRedirectCheckBox->setEnabled(current_profile->get_allow_redirection()); - askUserRedirectCheckBox->setChecked(current_profile->get_ask_user_to_redirect()); - maxRedirectTextLabel->setEnabled(current_profile->get_allow_redirection()); - maxRedirectSpinBox->setEnabled(current_profile->get_allow_redirection()); - maxRedirectSpinBox->setValue(current_profile->get_max_redirections()); - ext100relComboBox->setCurrentItem( - ext_support2indexComboItem(current_profile->get_ext_100rel())); - extReplacesCheckBox->setChecked(current_profile->get_ext_replaces()); - allowReferCheckBox->setChecked(current_profile->get_allow_refer()); - askUserReferCheckBox->setEnabled(current_profile->get_allow_refer()); - askUserReferCheckBox->setChecked(current_profile->get_ask_user_to_refer()); - refereeHoldCheckBox->setEnabled(current_profile->get_allow_refer()); - refereeHoldCheckBox->setChecked(current_profile->get_referee_hold()); - referrerHoldCheckBox->setChecked(current_profile->get_referrer_hold()); - refreshReferSubCheckBox->setChecked(current_profile->get_auto_refresh_refer_sub()); - referAorCheckBox->setChecked(current_profile->get_attended_refer_to_aor()); - transferConsultInprogCheckBox->setChecked( - current_profile->get_allow_transfer_consultation_inprog()); - pPreferredIdCheckBox->setChecked(current_profile->get_send_p_preferred_id()); - - // Transport/NAT - switch (current_profile->get_sip_transport()) { - case SIP_TRANS_UDP: - sipTransportComboBox->setCurrentItem(idxSipTransportUDP); - break; - case SIP_TRANS_TCP: - sipTransportComboBox->setCurrentItem(idxSipTransportTCP); - break; - default: - sipTransportComboBox->setCurrentItem(idxSipTransportAuto); - break; - } - - udpThresholdSpinBox->setValue(current_profile->get_sip_transport_udp_threshold()); - udpThresholdTextLabel->setEnabled(current_profile->get_sip_transport() == SIP_TRANS_AUTO); - udpThresholdSpinBox->setEnabled(current_profile->get_sip_transport() == SIP_TRANS_AUTO); - - if (current_profile->get_use_nat_public_ip()) { - natStaticRadioButton->setChecked(true); - } else if (current_profile->get_use_stun()) { - natStunRadioButton->setChecked(true); - } else { - natNoneRadioButton->setChecked(true); - } - - publicIPTextLabel->setEnabled(current_profile->get_use_nat_public_ip()); - publicIPLineEdit->setEnabled(current_profile->get_use_nat_public_ip()); - publicIPLineEdit->setText(current_profile->get_nat_public_ip().c_str()); - stunServerTextLabel->setEnabled(current_profile->get_use_stun()); - stunServerLineEdit->setEnabled(current_profile->get_use_stun()); - stunServerLineEdit->setText(current_profile->get_stun_server(). - encode_noscheme().c_str()); - persistentTcpCheckBox->setChecked(current_profile->get_persistent_tcp()); - persistentTcpCheckBox->setEnabled(current_profile->get_sip_transport() == SIP_TRANS_TCP); - natKeepaliveCheckBox->setChecked(current_profile->get_enable_nat_keepalive()); - natKeepaliveCheckBox->setDisabled(current_profile->get_use_stun()); - - // ADDRESS FORMAT - displayTelUserCheckBox->setChecked(current_profile->get_display_useronly_phone()); - numericalUserIsTelCheckBox->setChecked( - current_profile->get_numerical_user_is_phone()); - removeSpecialCheckBox->setChecked( - current_profile->get_remove_special_phone_symbols()); - specialLineEdit->setText(current_profile->get_special_phone_symbols().c_str()); - useTelUriCheckBox->setChecked(current_profile->get_use_tel_uri_for_phone()); - - conversionListView->clear(); - conversionListView->setSorting(-1); - list conversions = current_profile->get_number_conversions(); - for (list::reverse_iterator i = conversions.rbegin(); i != conversions.rend(); i++) - { - new Q3ListViewItem(conversionListView, i->re.str().c_str(), i->fmt.c_str()); - } - - // TIMERS - tmrNoanswerSpinBox->setValue(current_profile->get_timer_noanswer()); - tmrNatKeepaliveSpinBox->setValue(current_profile->get_timer_nat_keepalive()); - - // RING TONES - ringtoneLineEdit->setText(current_profile->get_ringtone_file().c_str()); - ringbackLineEdit->setText(current_profile->get_ringback_file().c_str()); - - // SCRIPTS - incomingCallScriptLineEdit->setText(current_profile->get_script_incoming_call().c_str()); - inCallAnsweredLineEdit->setText(current_profile->get_script_in_call_answered().c_str()); - inCallFailedLineEdit->setText(current_profile->get_script_in_call_failed().c_str()); - outCallLineEdit->setText(current_profile->get_script_outgoing_call().c_str()); - outCallAnsweredLineEdit->setText(current_profile->get_script_out_call_answered().c_str()); - outCallFailedLineEdit->setText(current_profile->get_script_out_call_failed().c_str()); - localReleaseLineEdit->setText(current_profile->get_script_local_release().c_str()); - remoteReleaseLineEdit->setText(current_profile->get_script_remote_release().c_str()); - - // Security - zrtpEnabledCheckBox->setChecked(current_profile->get_zrtp_enabled()); - zrtpSettingsGroupBox->setEnabled(current_profile->get_zrtp_enabled()); - zrtpSendIfSupportedCheckBox->setChecked(current_profile->get_zrtp_send_if_supported()); - zrtpSdpCheckBox->setChecked(current_profile->get_zrtp_sdp()); - zrtpGoClearWarningCheckBox->setChecked(current_profile->get_zrtp_goclear_warning()); -} - -void UserProfileForm::initProfileList(list profiles, QString show_profile_name) -{ - profile_list = profiles; - - // Initialize user profile combo box - current_profile_idx = -1; - profileComboBox->clear(); - - t_user *show_profile = NULL; - int show_idx = 0; - int idx = 0; - for (list::iterator i = profile_list.begin(); i != profile_list.end(); i++) { - profileComboBox->insertItem((*i)->get_profile_name().c_str()); - if (show_profile_name == (*i)->get_profile_name().c_str()) { - show_idx = idx; - show_profile = *i; - } - idx++; - } - - profileComboBox->setEnabled(profile_list.size() > 1); - current_profile_idx = show_idx; - - if (show_profile == NULL) { - current_profile = profile_list.front(); - } else { - current_profile = show_profile; - } - profileComboBox->setCurrentItem(current_profile_idx); -} - -// Show the form -void UserProfileForm::show(list profiles, QString show_profile) -{ - map_last_cat.clear(); - initProfileList(profiles, show_profile); - populate(); - - // Show form - QDialog::show(); -} - -// Modal execution -int UserProfileForm::exec(list profiles, QString show_profile) -{ - map_last_cat.clear(); - initProfileList(profiles, show_profile); - populate(); - return QDialog::exec(); -} - -bool UserProfileForm::check_dynamic_payload(QSpinBox *spb, - Q3ValueList &checked_list) -{ - if (checked_list.contains(spb->value())) { - categoryListBox->setSelected(idxCatRtpAudio, true); - settingsWidgetStack->raiseWidget(pageRtpAudio); - QString msg = tr("Dynamic payload type %1 is used more than once.").arg(spb->value()); - ((t_gui *)ui)->cb_show_msg(this, msg.ascii(), MSG_CRITICAL); - spb->setFocus(); - return false; - } - - checked_list.append(spb->value()); - return true; -} - -list UserProfileForm::get_number_conversions() -{ - list conversions; - Q3ListViewItemIterator it(conversionListView); - while (it.current()) { - Q3ListViewItem *item = it.current(); - t_number_conversion c; - - try { - c.re.assign(item->text(colExpr).ascii()); - c.fmt = item->text(colReplace).ascii(); - conversions.push_back(c); - } catch (boost::bad_expression) { - // Should never happen as validity has been - // checked already. Just being defensive here. - } - - ++it; - } - - return conversions; -} - -bool UserProfileForm::validateValues() -{ - QString s; - - // Validity check user page - // SIP username is mandatory - if (usernameLineEdit->text().isEmpty()) { - categoryListBox->setSelected(idxCatUser, true); - settingsWidgetStack->raiseWidget(pageUser); - ((t_gui *)ui)->cb_show_msg(this, tr("You must fill in a user name for your SIP account.").ascii(), - MSG_CRITICAL); - usernameLineEdit->setFocus(); - return false; - } - - // SIP user domain is mandatory - if (domainLineEdit->text().isEmpty()) { - categoryListBox->setSelected(idxCatUser, true); - settingsWidgetStack->raiseWidget(pageUser); - ((t_gui *)ui)->cb_show_msg(this, tr( - "You must fill in a domain name for your SIP account.\n" - "This could be the hostname or IP address of your PC " - "if you want direct PC to PC dialing.").ascii(), - MSG_CRITICAL); - domainLineEdit->setFocus(); - return false; - } - - // Check validity of domain - s = USER_SCHEME; - s.append(':').append(domainLineEdit->text()); - t_url u_domain(s.ascii()); - if (!u_domain.is_valid() || u_domain.get_user() != "") { - categoryListBox->setSelected(idxCatUser, true); - settingsWidgetStack->raiseWidget(pageUser); - ((t_gui *)ui)->cb_show_msg(this, tr("Invalid domain.").ascii(), MSG_CRITICAL); - domainLineEdit->setFocus(); - return false; - } - - // Check validity of user - s = USER_SCHEME; - s.append(':').append(usernameLineEdit->text()).append('@'); - s.append(domainLineEdit->text()); - t_url u_user_domain(s.ascii()); - if (!u_user_domain.is_valid()) { - categoryListBox->setSelected(idxCatUser, true); - settingsWidgetStack->raiseWidget(pageUser); - ((t_gui *)ui)->cb_show_msg(this, tr("Invalid user name.").ascii(), MSG_CRITICAL); - usernameLineEdit->setFocus(); - return false; - } - - // Registrar - if (!registrarLineEdit->text().isEmpty()) { - s = USER_SCHEME; - s.append(':').append(registrarLineEdit->text()); - t_url u(s.ascii()); - if (!u.is_valid() || u.get_user() != "") { - categoryListBox->setSelected(idxCatSipServer, true); - settingsWidgetStack->raiseWidget(pageSipServer); - ((t_gui *)ui)->cb_show_msg(this, tr("Invalid value for registrar.").ascii(), - MSG_CRITICAL); - registrarLineEdit->setFocus(); - registrarLineEdit->selectAll(); - return false; - } - } - - // Outbound proxy - if (useProxyCheckBox->isChecked()) { - s = USER_SCHEME; - s.append(':').append(proxyLineEdit->text()); - t_url u(s.ascii()); - if (!u.is_valid() || u.get_user() != "") { - categoryListBox->setSelected(idxCatSipServer, true); - settingsWidgetStack->raiseWidget(pageSipServer); - ((t_gui *)ui)->cb_show_msg(this, tr("Invalid value for outbound proxy.").ascii(), - MSG_CRITICAL); - proxyLineEdit->setFocus(); - proxyLineEdit->selectAll(); - return false; - } - } - - - // Validity check voice mail page - if (mwiTypeComboBox->currentItem() == idxMWISollicited) { - // Mailbox user name is mandatory - if (mwiUserLineEdit->text().isEmpty()) { - categoryListBox->setSelected(idxCatVoiceMail, true); - settingsWidgetStack->raiseWidget(pageVoiceMail); - ((t_gui *)ui)->cb_show_msg(this, - tr("You must fill in a mailbox user name.").ascii(), - MSG_CRITICAL); - mwiUserLineEdit->setFocus(); - return false; - } - - // Mailbox server is mandatory - if (mwiServerLineEdit->text().isEmpty()) { - categoryListBox->setSelected(idxCatVoiceMail, true); - settingsWidgetStack->raiseWidget(pageVoiceMail); - ((t_gui *)ui)->cb_show_msg(this, - tr("You must fill in a mailbox server").ascii(), - MSG_CRITICAL); - mwiServerLineEdit->setFocus(); - return false; - } - - // Check validity of mailbox server - s = USER_SCHEME; - s.append(':').append(mwiServerLineEdit->text()); - t_url u_server(s.ascii()); - if (!u_server.is_valid() || u_server.get_user() != "") { - categoryListBox->setSelected(idxCatVoiceMail, true); - settingsWidgetStack->raiseWidget(pageVoiceMail); - ((t_gui *)ui)->cb_show_msg(this, tr("Invalid mailbox server.").ascii(), - MSG_CRITICAL); - mwiServerLineEdit->setFocus(); - return false; - } - - // Check validity of mailbox user name - s = USER_SCHEME; - s.append(':').append(mwiUserLineEdit->text()).append('@'); - s.append(mwiServerLineEdit->text()); - t_url u_user_server(s.ascii()); - if (!u_user_server.is_valid()) { - categoryListBox->setSelected(idxCatVoiceMail, true); - settingsWidgetStack->raiseWidget(pageVoiceMail); - ((t_gui *)ui)->cb_show_msg(this, tr("Invalid mailbox user name.").ascii(), - MSG_CRITICAL); - mwiUserLineEdit->setFocus(); - return false; - } - } - - // NAT public IP - if (natStaticRadioButton->isChecked()) { - if (publicIPLineEdit->text().isEmpty()){ - categoryListBox->setSelected(idxCatNat, true); - settingsWidgetStack->raiseWidget(pageNat); - ((t_gui *)ui)->cb_show_msg(this, tr("Value for public IP address missing.").ascii(), - MSG_CRITICAL); - publicIPLineEdit->setFocus(); - return false; - } - } - - // Check for double RTP dynamic payload types - Q3ValueList checked_types; - if (!check_dynamic_payload(spxNbPayloadSpinBox, checked_types) || - !check_dynamic_payload(spxWbPayloadSpinBox, checked_types) || - !check_dynamic_payload(spxUwbPayloadSpinBox, checked_types)) - { - rtpAudioTabWidget->showPage(tabSpeex); - return false; - } - - if (!check_dynamic_payload(ilbcPayloadSpinBox, checked_types)) { - rtpAudioTabWidget->showPage(tabIlbc); - return false; - } - - if (!check_dynamic_payload(g72616PayloadSpinBox, checked_types) || - !check_dynamic_payload(g72624PayloadSpinBox, checked_types) || - !check_dynamic_payload(g72632PayloadSpinBox, checked_types) || - !check_dynamic_payload(g72640PayloadSpinBox, checked_types)) { - rtpAudioTabWidget->showPage(tabG726); - return false; - } - - if (!check_dynamic_payload(dtmfPayloadTypeSpinBox, checked_types)) { - rtpAudioTabWidget->showPage(tabDtmf); - return false; - } - - // STUN server - if (natStunRadioButton->isChecked()) { - s = "stun:"; - s.append(stunServerLineEdit->text()); - t_url u(s.ascii()); - if (!u.is_valid() || u.get_user() != "") { - categoryListBox->setSelected(idxCatNat, true); - settingsWidgetStack->raiseWidget(pageNat); - ((t_gui *)ui)->cb_show_msg(this, tr("Invalid value for STUN server.").ascii(), - MSG_CRITICAL); - stunServerLineEdit->setFocus(); - stunServerLineEdit->selectAll(); - return false; - } - } - - // Clear outbound proxy if not used - if (!useProxyCheckBox->isChecked()) { - proxyLineEdit->clear(); - } - - // Clear sollicited MWI settings if unsollicited MWI is used - if (mwiTypeComboBox->currentItem() == idxMWIUnsollicited) { - t_user user_default; - mwiUserLineEdit->clear(); - mwiServerLineEdit->clear(); - mwiViaProxyCheckBox->setChecked(user_default.get_mwi_via_proxy()); - mwiDurationSpinBox->setValue(user_default.get_mwi_subscription_time()); - } - - // Clear NAT public IP if not used - if (!natStaticRadioButton->isChecked()) { - publicIPLineEdit->clear(); - } - - // Clear STUN server if not used - if (!natStunRadioButton->isChecked()) { - stunServerLineEdit->clear(); - } - - // Set all values in the current_profile object - // USER - if (current_profile->get_name() != usernameLineEdit->text().ascii() || - current_profile->get_display(false) != displayLineEdit->text().ascii() || - current_profile->get_domain() != domainLineEdit->text().ascii()) - { - current_profile->set_display(displayLineEdit->text().ascii()); - current_profile->set_name(usernameLineEdit->text().ascii()); - current_profile->set_domain (domainLineEdit->text().ascii()); - emit sipUserChanged(current_profile); - } - - current_profile->set_organization(organizationLineEdit->text().ascii()); - - uint8 new_aka_op[AKA_OPLEN]; - uint8 new_aka_amf[AKA_AMFLEN]; - uint8 current_aka_op[AKA_OPLEN]; - uint8 current_aka_amf[AKA_AMFLEN]; - - hex2binary(padleft(authAkaOpLineEdit->text().ascii(), '0', 32), new_aka_op); - hex2binary(padleft(authAkaAmfLineEdit->text().ascii(), '0', 4), new_aka_amf); - current_profile->get_auth_aka_op(current_aka_op); - current_profile->get_auth_aka_amf(current_aka_amf); - - if (current_profile->get_auth_realm() != authRealmLineEdit->text().ascii() || - current_profile->get_auth_name() != authNameLineEdit->text().ascii() || - current_profile->get_auth_pass() != authPasswordLineEdit->text().ascii() || - memcmp(current_aka_op, new_aka_op, AKA_OPLEN) != 0 || - memcmp(current_aka_amf, new_aka_amf, AKA_AMFLEN) != 0) - { - emit authCredentialsChanged(current_profile, - current_profile->get_auth_realm()); - - current_profile->set_auth_realm(authRealmLineEdit->text().ascii()); - current_profile->set_auth_name(authNameLineEdit->text().ascii()); - current_profile->set_auth_pass(authPasswordLineEdit->text().ascii()); - current_profile->set_auth_aka_op(new_aka_op); - current_profile->set_auth_aka_amf(new_aka_amf); - } - - // SIP SERVER - current_profile->set_use_registrar(!registrarLineEdit->text().isEmpty()); - s = USER_SCHEME; - s.append(':').append(registrarLineEdit->text()); - current_profile->set_registrar(t_url(s.ascii())); - current_profile->set_registration_time(expirySpinBox->value()); - current_profile->set_register_at_startup(regAtStartupCheckBox->isChecked()); - current_profile->set_reg_add_qvalue(regAddQvalueCheckBox->isChecked()); - current_profile->set_reg_qvalue(atof(regQvalueLineEdit->text().ascii())); - - current_profile->set_use_outbound_proxy(useProxyCheckBox->isChecked()); - s = USER_SCHEME; - s.append(':').append(proxyLineEdit->text()); - current_profile->set_outbound_proxy(t_url(s.ascii())); - current_profile->set_all_requests_to_proxy(allRequestsCheckBox->isChecked()); - current_profile->set_non_resolvable_to_proxy( - proxyNonResolvableCheckBox->isChecked()); - - // VOICE MAIL - current_profile->set_mwi_vm_address(vmAddressLineEdit->text().ascii()); - - bool mustTriggerMWISubscribe = false; - bool mwiSollicited = (mwiTypeComboBox->currentItem() == idxMWISollicited); - if (mwiSollicited) { - if (!current_profile->get_mwi_sollicited()) { - // Sollicited MWI now enabled. Subscribe after all MWI - // settings have been changed. - mustTriggerMWISubscribe = true; - } else { - s = USER_SCHEME; - s.append(':').append(mwiServerLineEdit->text()); - if (mwiUserLineEdit->text().ascii() != current_profile->get_mwi_user() || - t_url(s.ascii()) != current_profile->get_mwi_server() || - mwiViaProxyCheckBox->isChecked() != current_profile->get_mwi_via_proxy()) - { - // Sollicited MWI settings changed. Trigger unsubscribe - // of current MWI subscription. - emit mwiChangeUnsubscribe(current_profile); - - // Subscribe after the settings have been changed. - mustTriggerMWISubscribe = true; - } - } - } else { - if (current_profile->get_mwi_sollicited()) { - // MWI type changes to unsollicited. Trigger unsubscribe of - // current MWI subscription. - emit mwiChangeUnsubscribe(current_profile); - } - } - - current_profile->set_mwi_sollicited(mwiSollicited); - current_profile->set_mwi_user(mwiUserLineEdit->text().ascii()); - s = USER_SCHEME; - s.append(':').append(mwiServerLineEdit->text()); - current_profile->set_mwi_server(t_url(s.ascii())); - current_profile->set_mwi_via_proxy(mwiViaProxyCheckBox->isChecked()); - current_profile->set_mwi_subscription_time(mwiDurationSpinBox->value()); - - if (mustTriggerMWISubscribe) { - emit mwiChangeSubscribe(current_profile); - } - - // INSTANT MESSAGE - current_profile->set_im_max_sessions(imMaxSessionsSpinBox->value()); - current_profile->set_im_send_iscomposing(isComposingCheckBox->isChecked()); - - // PRESENCE - current_profile->set_pres_publish_startup(presPublishCheckBox->isChecked()); - current_profile->set_pres_publication_time(presPublishTimeSpinBox->value()); - current_profile->set_pres_subscription_time(presSubscribeTimeSpinBox->value()); - - // RTP AUDIO - // Codecs - list audio_codecs; - for (size_t i = 0; i < activeCodecListBox->count(); i++) { - audio_codecs.push_back(label2codec(activeCodecListBox->text(i))); - } - current_profile->set_codecs(audio_codecs); - - // G.711/G.726 ptime - current_profile->set_ptime(ptimeSpinBox->value()); - - // Codec preference - current_profile->set_in_obey_far_end_codec_pref(inFarEndCodecPrefCheckBox->isChecked()); - current_profile->set_out_obey_far_end_codec_pref(outFarEndCodecPrefCheckBox->isChecked()); - - // Speex preprocessing & AEC - current_profile->set_speex_dsp_vad(spxDspVadCheckBox->isChecked()); - current_profile->set_speex_dsp_agc(spxDspAgcCheckBox->isChecked()); - current_profile->set_speex_dsp_aec(spxDspAecCheckBox->isChecked()); - current_profile->set_speex_dsp_nrd(spxDspNrdCheckBox->isChecked()); - current_profile->set_speex_dsp_agc_level(spxDspAgcLevelSpinBox->value()); - - // Speex ([en/de]coding) - current_profile->set_speex_bit_rate_type((spxVbrCheckBox->isChecked() ? BIT_RATE_VBR : BIT_RATE_CBR)); - current_profile->set_speex_dtx(spxDtxCheckBox->isChecked()); - current_profile->set_speex_penh(spxPenhCheckBox->isChecked()); - current_profile->set_speex_quality(spxQualitySpinBox->value()); - current_profile->set_speex_complexity(spxComplexitySpinBox->value()); - current_profile->set_speex_nb_payload_type(spxNbPayloadSpinBox->value()); - current_profile->set_speex_wb_payload_type(spxWbPayloadSpinBox->value()); - current_profile->set_speex_uwb_payload_type(spxUwbPayloadSpinBox->value()); - - // iLBC - current_profile->set_ilbc_payload_type(ilbcPayloadSpinBox->value()); - switch (ilbcPayloadSizeComboBox->currentItem()) { - case idxIlbcMode20: - current_profile->set_ilbc_mode(20); - break; - default: - current_profile->set_ilbc_mode(30); - break; - } - - // G726 - current_profile->set_g726_16_payload_type(g72616PayloadSpinBox->value()); - current_profile->set_g726_24_payload_type(g72624PayloadSpinBox->value()); - current_profile->set_g726_32_payload_type(g72632PayloadSpinBox->value()); - current_profile->set_g726_40_payload_type(g72640PayloadSpinBox->value()); - - switch (g726PackComboBox->currentItem()) { - case idxG726PackRfc3551: - current_profile->set_g726_packing(G726_PACK_RFC3551); - break; - default: - current_profile->set_g726_packing(G726_PACK_AAL2); - break; - } - - // DTMF - switch (dtmfTransportComboBox->currentItem()) { - case idxDtmfRfc2833: - current_profile->set_dtmf_transport(DTMF_RFC2833); - break; - case idxDtmfInband: - current_profile->set_dtmf_transport(DTMF_INBAND); - break; - case idxDtmfInfo: - current_profile->set_dtmf_transport(DTMF_INFO); - break; - default: - current_profile->set_dtmf_transport(DTMF_AUTO); - break; - } - - current_profile->set_dtmf_payload_type(dtmfPayloadTypeSpinBox->value()); - current_profile->set_dtmf_duration(dtmfDurationSpinBox->value()); - current_profile->set_dtmf_pause(dtmfPauseSpinBox->value()); - current_profile->set_dtmf_volume(-(dtmfVolumeSpinBox->value())); - - // SIP PROTOCOL - switch (holdVariantComboBox->currentItem()) { - case idxHoldRfc2543: - current_profile->set_hold_variant(HOLD_RFC2543); - break; - default: - current_profile->set_hold_variant(HOLD_RFC3264); - break; - } - - current_profile->set_check_max_forwards(maxForwardsCheckBox->isChecked()); - current_profile->set_allow_missing_contact_reg(missingContactCheckBox->isChecked()); - current_profile->set_registration_time_in_contact(regTimeCheckBox->isChecked()); - current_profile->set_compact_headers(compactHeadersCheckBox->isChecked()); - current_profile->set_encode_multi_values_as_list( - multiValuesListCheckBox->isChecked()); - current_profile->set_use_domain_in_contact( - useDomainInContactCheckBox->isChecked()); - current_profile->set_allow_sdp_change(allowSdpChangeCheckBox->isChecked()); - current_profile->set_allow_redirection(allowRedirectionCheckBox->isChecked()); - current_profile->set_ask_user_to_redirect(askUserRedirectCheckBox->isChecked()); - current_profile->set_max_redirections(maxRedirectSpinBox->value()); - current_profile->set_ext_100rel(indexComboItem2ext_support( - ext100relComboBox->currentItem())); - current_profile->set_ext_replaces(extReplacesCheckBox->isChecked()); - current_profile->set_allow_refer(allowReferCheckBox->isChecked()); - current_profile->set_ask_user_to_refer(askUserReferCheckBox->isChecked()); - current_profile->set_referee_hold(refereeHoldCheckBox->isChecked()); - current_profile->set_referrer_hold(referrerHoldCheckBox->isChecked()); - current_profile->set_auto_refresh_refer_sub(refreshReferSubCheckBox->isChecked()); - current_profile->set_attended_refer_to_aor(referAorCheckBox->isChecked()); - current_profile->set_allow_transfer_consultation_inprog( - transferConsultInprogCheckBox->isChecked()); - current_profile->set_send_p_preferred_id(pPreferredIdCheckBox->isChecked()); - - // Transport/NAT - switch (sipTransportComboBox->currentItem()) { - case idxSipTransportUDP: - current_profile->set_sip_transport(SIP_TRANS_UDP); - break; - case idxSipTransportTCP: - current_profile->set_sip_transport(SIP_TRANS_TCP); - break; - default: - current_profile->set_sip_transport(SIP_TRANS_AUTO); - break; - } - - current_profile->set_sip_transport_udp_threshold(udpThresholdSpinBox->value()); - - current_profile->set_use_nat_public_ip(natStaticRadioButton->isChecked()); - current_profile->set_nat_public_ip(publicIPLineEdit->text().ascii()); - current_profile->set_use_stun(natStunRadioButton->isChecked()); - - if (current_profile->get_stun_server().encode_noscheme() != stunServerLineEdit->text().ascii() || - current_profile->get_enable_nat_keepalive() != natKeepaliveCheckBox->isChecked()) - { - s = "stun:"; - s.append(stunServerLineEdit->text()); - current_profile->set_stun_server(t_url(s.ascii())); - current_profile->set_enable_nat_keepalive(natKeepaliveCheckBox->isChecked()); - emit stunServerChanged(current_profile); - } - - current_profile->set_persistent_tcp(persistentTcpCheckBox->isChecked()); - - // ADDRESS FORMAT - current_profile->set_display_useronly_phone( - displayTelUserCheckBox->isChecked()); - current_profile->set_numerical_user_is_phone( - numericalUserIsTelCheckBox->isChecked()); - current_profile->set_remove_special_phone_symbols( - removeSpecialCheckBox->isChecked()); - current_profile->set_special_phone_symbols( - specialLineEdit->text().stripWhiteSpace().ascii()); - current_profile->set_number_conversions(get_number_conversions()); - current_profile->set_use_tel_uri_for_phone(useTelUriCheckBox->isChecked()); - - // TIMERS - current_profile->set_timer_noanswer(tmrNoanswerSpinBox->value()); - current_profile->set_timer_nat_keepalive(tmrNatKeepaliveSpinBox->value()); - - // RING TONES - current_profile->set_ringtone_file(ringtoneLineEdit->text().stripWhiteSpace().ascii()); - current_profile->set_ringback_file(ringbackLineEdit->text().stripWhiteSpace().ascii()); - - // SCRIPTS - current_profile->set_script_incoming_call(incomingCallScriptLineEdit-> - text().stripWhiteSpace().ascii()); - current_profile->set_script_in_call_answered(inCallAnsweredLineEdit-> - text().stripWhiteSpace().ascii()); - current_profile->set_script_in_call_failed(inCallFailedLineEdit-> - text().stripWhiteSpace().ascii()); - current_profile->set_script_outgoing_call(outCallLineEdit-> - text().stripWhiteSpace().ascii()); - current_profile->set_script_out_call_answered(outCallAnsweredLineEdit-> - text().stripWhiteSpace().ascii()); - current_profile->set_script_out_call_failed(outCallFailedLineEdit-> - text().stripWhiteSpace().ascii()); - current_profile->set_script_local_release(localReleaseLineEdit-> - text().stripWhiteSpace().ascii()); - current_profile->set_script_remote_release(remoteReleaseLineEdit-> - text().stripWhiteSpace().ascii()); - - // Security - current_profile->set_zrtp_enabled(zrtpEnabledCheckBox->isChecked()); - current_profile->set_zrtp_send_if_supported(zrtpSendIfSupportedCheckBox->isChecked()); - current_profile->set_zrtp_sdp(zrtpSdpCheckBox->isChecked()); - current_profile->set_zrtp_goclear_warning(zrtpGoClearWarningCheckBox->isChecked()); - - // Save user config - string error_msg; - if (!current_profile->write_config(current_profile->get_filename(), error_msg)) { - // Failed to write config file - ((t_gui *)ui)->cb_show_msg(this, error_msg, MSG_CRITICAL); - return false; - } - - return true; -} - -void UserProfileForm::validate() { - if (validateValues()) { - emit success(); - accept(); - } -} - -// User wants to change to another profile -void UserProfileForm::changeProfile(const QString &profileName) { - if (current_profile_idx == -1) { - // Initializing combo box - return; - } - - // Make the current profile permanent. - if (!validateValues()) { - // Current values are not valid. - // Do not change to the new profile. - profileComboBox->setCurrentItem(current_profile_idx); - return; - } - - // Store the current viewed category - map_last_cat[current_profile] = categoryListBox->index(categoryListBox->selectedItem()); - - // Change to new profile. - for (list::iterator i = profile_list.begin(); i != profile_list.end(); i++) { - if ((*i)->get_profile_name() == profileName.ascii()) { - current_profile = *i; - break; - } - } - - current_profile_idx = profileComboBox->currentItem(); - populate(); - - // Restore last viewed category - int idxCat = map_last_cat[current_profile]; - categoryListBox->setSelected(idxCat, true); - showCategory(idxCat); -} - -void UserProfileForm::chooseFile(QLineEdit *qle, const QString &filter, const QString &caption) -{ - QString file = Q3FileDialog::getOpenFileName( - ((t_gui *)ui)->get_last_file_browse_path(), - filter, this, "open file dialog", - caption); - if (!file.isEmpty()) { - qle->setText(file); - ((t_gui *)ui)->set_last_file_browse_path(QFileInfo(file).dirPath(true)); - } -} - -void UserProfileForm::chooseRingtone() -{ - chooseFile(ringtoneLineEdit, tr("Ring tones", "Description of .wav files in file dialog").append(" (*.wav)"), tr("Choose ring tone")); -} - -void UserProfileForm::chooseRingback() -{ - chooseFile(ringbackLineEdit, tr("Ring back tones", "Description of .wav files in file dialog").append(" (*.wav)"), "Choose ring back tone"); -} - -void UserProfileForm::chooseIncomingCallScript() -{ - chooseFile(incomingCallScriptLineEdit, tr("All files").append(" (*)"), tr("Choose incoming call script")); -} - -void UserProfileForm::chooseInCallAnsweredScript() -{ - chooseFile(inCallAnsweredLineEdit, tr("All files").append(" (*)"), tr("Choose incoming call answered script")); -} - -void UserProfileForm::chooseInCallFailedScript() -{ - chooseFile(inCallFailedLineEdit, tr("All files").append(" (*)"), tr("Choose incoming call failed script")); -} - -void UserProfileForm::chooseOutgoingCallScript() -{ - chooseFile(outCallLineEdit, tr("All files").append(" (*)"), tr("Choose outgoing call script")); -} - -void UserProfileForm::chooseOutCallAnsweredScript() -{ - chooseFile(outCallAnsweredLineEdit, tr("All files").append(" (*)"), tr("Choose outgoing call answered script")); -} - -void UserProfileForm::chooseOutCallFailedScript() -{ - chooseFile(outCallFailedLineEdit, tr("All files").append(" (*)"), tr("Choose outgoing call failed script")); -} - -void UserProfileForm::chooseLocalReleaseScript() -{ - chooseFile(localReleaseLineEdit, tr("All files").append(" (*)"), tr("Choose local release script")); -} - -void UserProfileForm::chooseRemoteReleaseScript() -{ - chooseFile(remoteReleaseLineEdit, tr("All files").append(" (*)"), tr("Choose remote release script")); -} - -void UserProfileForm::addCodec() { - for (size_t i = 0; i < availCodecListBox->count(); i++) { - if (availCodecListBox->isSelected(i)) { - activeCodecListBox->insertItem(availCodecListBox->text(i)); - activeCodecListBox->setSelected( - activeCodecListBox->count() - 1, true); - availCodecListBox->removeItem(i); - return; - } - } -} - -void UserProfileForm::removeCodec() { - for (size_t i = 0; i < activeCodecListBox->count(); i++) { - if (activeCodecListBox->isSelected(i)) { - availCodecListBox->insertItem(activeCodecListBox->text(i)); - availCodecListBox->setSelected( - availCodecListBox->count() - 1, true); - activeCodecListBox->removeItem(i); - return; - } - } -} - -void UserProfileForm::upCodec() { - Q3ListBoxItem *lbi = activeCodecListBox->selectedItem(); - if (!lbi) return; - - int idx = activeCodecListBox->index(lbi); - if (idx == 0) return; - - QString label = lbi->text(); - activeCodecListBox->removeItem(idx); - activeCodecListBox->insertItem(label, idx - 1); - activeCodecListBox->setSelected(idx - 1, true); -} - -void UserProfileForm::downCodec() { - Q3ListBoxItem *lbi = activeCodecListBox->selectedItem(); - if (!lbi) return; - - size_t idx = activeCodecListBox->index(lbi); - if (idx == activeCodecListBox->count() - 1) return; - - QString label = lbi->text(); - activeCodecListBox->removeItem(idx); - activeCodecListBox->insertItem(label, idx + 1); - activeCodecListBox->setSelected(idx + 1, true); -} - -void UserProfileForm::upConversion() { - Q3ListViewItem *lvi = conversionListView->selectedItem(); - if (!lvi) return; - - Q3ListViewItem *above = lvi->itemAbove(); - if (!above) return; - - Q3ListViewItem *newAbove = above->itemAbove(); - - if (newAbove) { - lvi->moveItem(newAbove); - } else { - above->moveItem(lvi); - } - - lvi->setSelected(true); -} - -void UserProfileForm::downConversion() { - Q3ListViewItem *lvi = conversionListView->selectedItem(); - if (!lvi) return; - - Q3ListViewItem *below = lvi->itemBelow(); - if (!below) return; - - lvi->moveItem(below); - lvi->setSelected(true); -} - -void UserProfileForm::addConversion() { - QString expr; - QString replace; - - NumberConversionForm f; - if (f.exec(expr, replace) == QDialog::Accepted) { - Q3ListViewItem *last = conversionListView->lastItem(); - if (last) { - new Q3ListViewItem(conversionListView, last, expr, replace); - } else { - new Q3ListViewItem(conversionListView, expr, replace); - } - } -} - -void UserProfileForm::editConversion() { - Q3ListViewItem *lvi = conversionListView->selectedItem(); - if (!lvi) return; - - QString expr = lvi->text(colExpr); - QString replace = lvi->text(colReplace); - - NumberConversionForm f; - if (f.exec(expr, replace) == QDialog::Accepted) { - lvi->setText(colExpr, expr); - lvi->setText(colReplace, replace); - } -} - -void UserProfileForm::removeConversion() { - Q3ListViewItem *lvi = conversionListView->selectedItem(); - if (!lvi) return; - delete lvi; -} - -void UserProfileForm::testConversion() { - QString number = testConversionLineEdit->text(); - if (number.isEmpty()) return; - - bool remove_special_phone_symbols = removeSpecialCheckBox->isChecked(); - QString special_phone_symbols = specialLineEdit->text(); - - number = remove_white_space(number.ascii()).c_str(); - - // Remove special symbols - if (remove_special_phone_symbols && - looks_like_phone(number.ascii(), special_phone_symbols.ascii())) - { - number = remove_symbols( - number.ascii(), special_phone_symbols.ascii()).c_str(); - } - - QString msg = tr("%1 converts to %2") - .arg(number) - .arg(current_profile->convert_number(number.ascii(), get_number_conversions()).c_str()); - - ((t_gui *)ui)->cb_show_msg(this, msg.ascii(), MSG_INFO); -} - -void UserProfileForm::changeMWIType(int idxMWIType) { - if (idxMWIType == idxMWISollicited) { - mwiSollicitedGroupBox->setEnabled(true); - - // Set defaults - if (mwiUserLineEdit->text().isEmpty()) { - mwiUserLineEdit->setText(usernameLineEdit->text()); - } - if (mwiServerLineEdit->text().isEmpty()) { - mwiServerLineEdit->setText(domainLineEdit->text()); - mwiViaProxyCheckBox->setChecked(useProxyCheckBox->isChecked()); - } - } else { - mwiSollicitedGroupBox->setEnabled(false); - } -} - -void UserProfileForm::changeSipTransportProtocol(int idx) { - udpThresholdTextLabel->setEnabled(idx == idxSipTransportAuto); - udpThresholdSpinBox->setEnabled(idx == idxSipTransportAuto); - persistentTcpCheckBox->setEnabled(idx == idxSipTransportTCP); -} diff --git a/src/gui/wizardform.cpp b/src/gui/wizardform.cpp new file mode 100644 index 0000000..6ed7d5d --- /dev/null +++ b/src/gui/wizardform.cpp @@ -0,0 +1,297 @@ +//Added by qt3to4: +#include + +/* + Copyright (C) 2005-2009 Michel de Boer + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include +#include +#include +#include +#include +#include "gui.h" +#include +#include "wizardform.h" + +#define PROV_NONE QT_TRANSLATE_NOOP("WizardForm", "None (direct IP to IP calls)") +#define PROV_OTHER QT_TRANSLATE_NOOP("WizardForm", "Other") + +struct t_provider { + QString domain; + QString sip_proxy; + QString stun_server; +}; + +/* + * Constructs a WizardForm as a child of 'parent', with the + * name 'name' and widget flags set to 'f'. + * + * The dialog will by default be modeless, unless you set 'modal' to + * true to construct a modal dialog. + */ +WizardForm::WizardForm(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl) + : QDialog(parent, name, modal, fl) +{ + setupUi(this); + + init(); +} + +/* + * Destroys the object and frees any allocated resources + */ +WizardForm::~WizardForm() +{ + // no need to delete child widgets, Qt does it all for us +} + +/* + * Sets the strings of the subwidgets using the current + * language. + */ +void WizardForm::languageChange() +{ + retranslateUi(this); +} + + +void WizardForm::init() +{ + QRegExp rxNoSpace("\\S*"); + + // Set validators + usernameLineEdit->setValidator(new QRegExpValidator(rxNoSpace, this)); + domainLineEdit->setValidator(new QRegExpValidator(rxNoSpace, this)); + authNameLineEdit->setValidator(new QRegExpValidator(rxNoSpace, this)); + proxyLineEdit->setValidator(new QRegExpValidator(rxNoSpace, this)); + + initProviders(); + serviceProviderComboBox->setCurrentItem(serviceProviderComboBox->count() - 1); + update(tr(PROV_OTHER)); +} + +void WizardForm::initProviders() +{ + serviceProviderComboBox->clear(); + serviceProviderComboBox->insertItem(tr(PROV_NONE)); + + QString fname = sys_config->get_dir_share().c_str(); + fname.append("/").append(FILE_PROVIDERS); + QFile providersFile(fname); + if (providersFile.open(QIODevice::ReadOnly)) { + Q3TextStream providersStream(&providersFile); + QString entry; + while ((entry = providersStream.readLine()) != QString::null) { + // Skip comment + if (entry[0] == '#') continue; + + QStringList l = QStringList::split(";", entry, true); + + // Skip invalid lines + if (l.size() != 4) continue; + + t_provider p; + p.domain = l[1]; + p.sip_proxy = l[2]; + p.stun_server = l[3]; + mapProviders[l[0]] = p; + + serviceProviderComboBox->insertItem(l[0]); + } + providersFile.close(); + } + + serviceProviderComboBox->insertItem(tr(PROV_OTHER)); +} + +int WizardForm::exec(t_user *user) +{ + user_config = user; + + // Set user profile name in the titlebar + QString s = PRODUCT_NAME; + s.append(" - ").append(tr("User profile wizard:")).append(" "); + s.append(user_config->get_profile_name().c_str()); + setCaption(s); + + return QDialog::exec(); +} + +void WizardForm::show(t_user *user) +{ + user_config = user; + + // Set user profile name in the titlebar + QString s = PRODUCT_NAME; + s.append(" - ").append(tr("User profile wizard:")).append(" "); + s.append(user_config->get_profile_name().c_str()); + setCaption(s); + + QDialog::show(); +} + +void WizardForm::update(const QString &item) +{ + // Disable/Enable controls + if (item == tr(PROV_NONE)) { + suggestAuthName = false; + authNameTextLabel->setEnabled(false); + authNameLineEdit->setEnabled(false); + authPasswordTextLabel->setEnabled(false); + authPasswordLineEdit->setEnabled(false); + proxyTextLabel->setEnabled(false); + proxyLineEdit->setEnabled(false); + stunServerTextLabel->setEnabled(false); + stunServerLineEdit->setEnabled(false); + } else { + if (usernameLineEdit->text() == authNameLineEdit->text()) { + suggestAuthName = true; + } else { + suggestAuthName = false; + } + + authNameTextLabel->setEnabled(true); + authNameLineEdit->setEnabled(true); + authPasswordTextLabel->setEnabled(true); + authPasswordLineEdit->setEnabled(true); + proxyTextLabel->setEnabled(true); + proxyLineEdit->setEnabled(true); + stunServerTextLabel->setEnabled(true); + stunServerLineEdit->setEnabled(true); + } + + // Set values + if (item == tr(PROV_NONE)) { + domainLineEdit->clear(); + authNameLineEdit->clear(); + authPasswordLineEdit->clear(); + proxyLineEdit->clear(); + stunServerLineEdit->clear(); + } else if (item == tr(PROV_OTHER)) { + domainLineEdit->clear(); + stunServerLineEdit->clear(); + proxyLineEdit->clear(); + } else { + t_provider p = mapProviders[item]; + domainLineEdit->setText(p.domain); + proxyLineEdit->setText(p.sip_proxy); + stunServerLineEdit->setText(p.stun_server); + } +} + +void WizardForm::updateAuthName(const QString &s) +{ + if (suggestAuthName) { + authNameLineEdit->setText(s); + } +} + +void WizardForm::disableSuggestAuthName() +{ + suggestAuthName = false; +} + +void WizardForm::validate() +{ + QString s; + + // Validity check user page + // SIP username is mandatory + if (usernameLineEdit->text().isEmpty()) { + ((t_gui *)ui)->cb_show_msg(this, tr("You must fill in a user name for your SIP account.").ascii(), + MSG_CRITICAL); + usernameLineEdit->setFocus(); + return; + } + + // SIP user domain is mandatory + if (domainLineEdit->text().isEmpty()) { + ((t_gui *)ui)->cb_show_msg(this, tr( + "You must fill in a domain name for your SIP account.\n" + "This could be the hostname or IP address of your PC " + "if you want direct PC to PC dialing.").ascii(), + MSG_CRITICAL); + domainLineEdit->setFocus(); + return; + } + + // SIP proxy + if (proxyLineEdit->text() != "") { + s = USER_SCHEME; + s.append(':').append(proxyLineEdit->text()); + t_url u(s.ascii()); + if (!u.is_valid() || u.get_user() != "") { + ((t_gui *)ui)->cb_show_msg(this, tr("Invalid value for SIP proxy.").ascii(), + MSG_CRITICAL); + proxyLineEdit->setFocus(); + proxyLineEdit->selectAll(); + return; + } + } + + // Register and publish presence at startup + if (serviceProviderComboBox->currentText() == tr(PROV_NONE)) { + user_config->set_register_at_startup(false); + user_config->set_pres_publish_startup(false); + } + + // STUN server + if (stunServerLineEdit->text() != "") { + s = "stun:"; + s.append(stunServerLineEdit->text()); + t_url u(s.ascii()); + if (!u.is_valid() || u.get_user() != "") { + ((t_gui *)ui)->cb_show_msg(this, tr("Invalid value for STUN server.").ascii(), + MSG_CRITICAL); + stunServerLineEdit->setFocus(); + stunServerLineEdit->selectAll(); + return; + } + } + + // Set all values in the user_config object + // USER + user_config->set_display(displayLineEdit->text().ascii()); + user_config->set_name(usernameLineEdit->text().ascii()); + user_config->set_domain(domainLineEdit->text().ascii()); + user_config->set_auth_name(authNameLineEdit->text().ascii()); + user_config->set_auth_pass(authPasswordLineEdit->text().ascii()); + + // SIP SERVER + user_config->set_use_outbound_proxy(!proxyLineEdit->text().isEmpty()); + s = USER_SCHEME; + s.append(':').append(proxyLineEdit->text()); + user_config->set_outbound_proxy(t_url(s.ascii())); + + // NAT + user_config->set_use_stun(!stunServerLineEdit->text().isEmpty()); + s = "stun:"; + s.append(stunServerLineEdit->text()); + user_config->set_stun_server(t_url(s.ascii())); + + // Save user config + string error_msg; + if (!user_config->write_config(user_config->get_filename(), error_msg)) { + // Failed to write config file + ((t_gui *)ui)->cb_show_msg(this, error_msg, MSG_CRITICAL); + return; + } + + emit success(); + accept(); +} diff --git a/src/gui/wizardform.h b/src/gui/wizardform.h new file mode 100644 index 0000000..9332d3f --- /dev/null +++ b/src/gui/wizardform.h @@ -0,0 +1,44 @@ +#ifndef WIZARDFORM_H +#define WIZARDFORM_H + +struct t_provider; + +#include +#include "user.h" +#include "ui_wizardform.h" + +class WizardForm : public QDialog, public Ui::WizardForm +{ + Q_OBJECT + +public: + WizardForm(QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WindowFlags fl = 0); + ~WizardForm(); + + virtual void show( t_user * user ); + +public slots: + virtual void initProviders(); + virtual int exec( t_user * user ); + virtual void update( const QString & item ); + virtual void updateAuthName( const QString & s ); + virtual void disableSuggestAuthName(); + virtual void validate(); + +signals: + void success(); + +protected slots: + virtual void languageChange(); + +private: + bool suggestAuthName; + std::map mapProviders; + t_user *user_config; + + void init(); + +}; + + +#endif diff --git a/src/gui/wizardform.ui.h b/src/gui/wizardform.ui.h deleted file mode 100644 index e7bf798..0000000 --- a/src/gui/wizardform.ui.h +++ /dev/null @@ -1,265 +0,0 @@ -//Added by qt3to4: -#include -/**************************************************************************** -** ui.h extension file, included from the uic-generated form implementation. -** -** If you want to add, delete, or rename functions or slots, use -** Qt Designer to update this file, preserving your code. -** -** You should not define a constructor or destructor in this file. -** Instead, write your code in functions called init() and destroy(). -** These will automatically be called by the form's constructor and -** destructor. -*****************************************************************************/ -/* - Copyright (C) 2005-2009 Michel de Boer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -#define PROV_NONE QT_TRANSLATE_NOOP("WizardForm", "None (direct IP to IP calls)") -#define PROV_OTHER QT_TRANSLATE_NOOP("WizardForm", "Other") - -struct t_provider { - QString domain; - QString sip_proxy; - QString stun_server; -}; - -void WizardForm::init() -{ - QRegExp rxNoSpace("\\S*"); - - // Set validators - usernameLineEdit->setValidator(new QRegExpValidator(rxNoSpace, this)); - domainLineEdit->setValidator(new QRegExpValidator(rxNoSpace, this)); - authNameLineEdit->setValidator(new QRegExpValidator(rxNoSpace, this)); - proxyLineEdit->setValidator(new QRegExpValidator(rxNoSpace, this)); - - initProviders(); - serviceProviderComboBox->setCurrentItem(serviceProviderComboBox->count() - 1); - update(tr(PROV_OTHER)); -} - -void WizardForm::initProviders() -{ - serviceProviderComboBox->clear(); - serviceProviderComboBox->insertItem(tr(PROV_NONE)); - - QString fname = sys_config->get_dir_share().c_str(); - fname.append("/").append(FILE_PROVIDERS); - QFile providersFile(fname); - if (providersFile.open(QIODevice::ReadOnly)) { - Q3TextStream providersStream(&providersFile); - QString entry; - while ((entry = providersStream.readLine()) != QString::null) { - // Skip comment - if (entry[0] == '#') continue; - - QStringList l = QStringList::split(";", entry, true); - - // Skip invalid lines - if (l.size() != 4) continue; - - t_provider p; - p.domain = l[1]; - p.sip_proxy = l[2]; - p.stun_server = l[3]; - mapProviders[l[0]] = p; - - serviceProviderComboBox->insertItem(l[0]); - } - providersFile.close(); - } - - serviceProviderComboBox->insertItem(tr(PROV_OTHER)); -} - -int WizardForm::exec(t_user *user) -{ - user_config = user; - - // Set user profile name in the titlebar - QString s = PRODUCT_NAME; - s.append(" - ").append(tr("User profile wizard:")).append(" "); - s.append(user_config->get_profile_name().c_str()); - setCaption(s); - - return QDialog::exec(); -} - -void WizardForm::show(t_user *user) -{ - user_config = user; - - // Set user profile name in the titlebar - QString s = PRODUCT_NAME; - s.append(" - ").append(tr("User profile wizard:")).append(" "); - s.append(user_config->get_profile_name().c_str()); - setCaption(s); - - QDialog::show(); -} - -void WizardForm::update(const QString &item) -{ - // Disable/Enable controls - if (item == tr(PROV_NONE)) { - suggestAuthName = false; - authNameTextLabel->setEnabled(false); - authNameLineEdit->setEnabled(false); - authPasswordTextLabel->setEnabled(false); - authPasswordLineEdit->setEnabled(false); - proxyTextLabel->setEnabled(false); - proxyLineEdit->setEnabled(false); - stunServerTextLabel->setEnabled(false); - stunServerLineEdit->setEnabled(false); - } else { - if (usernameLineEdit->text() == authNameLineEdit->text()) { - suggestAuthName = true; - } else { - suggestAuthName = false; - } - - authNameTextLabel->setEnabled(true); - authNameLineEdit->setEnabled(true); - authPasswordTextLabel->setEnabled(true); - authPasswordLineEdit->setEnabled(true); - proxyTextLabel->setEnabled(true); - proxyLineEdit->setEnabled(true); - stunServerTextLabel->setEnabled(true); - stunServerLineEdit->setEnabled(true); - } - - // Set values - if (item == tr(PROV_NONE)) { - domainLineEdit->clear(); - authNameLineEdit->clear(); - authPasswordLineEdit->clear(); - proxyLineEdit->clear(); - stunServerLineEdit->clear(); - } else if (item == tr(PROV_OTHER)) { - domainLineEdit->clear(); - stunServerLineEdit->clear(); - proxyLineEdit->clear(); - } else { - t_provider p = mapProviders[item]; - domainLineEdit->setText(p.domain); - proxyLineEdit->setText(p.sip_proxy); - stunServerLineEdit->setText(p.stun_server); - } -} - -void WizardForm::updateAuthName(const QString &s) -{ - if (suggestAuthName) { - authNameLineEdit->setText(s); - } -} - -void WizardForm::disableSuggestAuthName() -{ - suggestAuthName = false; -} - -void WizardForm::validate() -{ - QString s; - - // Validity check user page - // SIP username is mandatory - if (usernameLineEdit->text().isEmpty()) { - ((t_gui *)ui)->cb_show_msg(this, tr("You must fill in a user name for your SIP account.").ascii(), - MSG_CRITICAL); - usernameLineEdit->setFocus(); - return; - } - - // SIP user domain is mandatory - if (domainLineEdit->text().isEmpty()) { - ((t_gui *)ui)->cb_show_msg(this, tr( - "You must fill in a domain name for your SIP account.\n" - "This could be the hostname or IP address of your PC " - "if you want direct PC to PC dialing.").ascii(), - MSG_CRITICAL); - domainLineEdit->setFocus(); - return; - } - - // SIP proxy - if (proxyLineEdit->text() != "") { - s = USER_SCHEME; - s.append(':').append(proxyLineEdit->text()); - t_url u(s.ascii()); - if (!u.is_valid() || u.get_user() != "") { - ((t_gui *)ui)->cb_show_msg(this, tr("Invalid value for SIP proxy.").ascii(), - MSG_CRITICAL); - proxyLineEdit->setFocus(); - proxyLineEdit->selectAll(); - return; - } - } - - // Register and publish presence at startup - if (serviceProviderComboBox->currentText() == tr(PROV_NONE)) { - user_config->set_register_at_startup(false); - user_config->set_pres_publish_startup(false); - } - - // STUN server - if (stunServerLineEdit->text() != "") { - s = "stun:"; - s.append(stunServerLineEdit->text()); - t_url u(s.ascii()); - if (!u.is_valid() || u.get_user() != "") { - ((t_gui *)ui)->cb_show_msg(this, tr("Invalid value for STUN server.").ascii(), - MSG_CRITICAL); - stunServerLineEdit->setFocus(); - stunServerLineEdit->selectAll(); - return; - } - } - - // Set all values in the user_config object - // USER - user_config->set_display(displayLineEdit->text().ascii()); - user_config->set_name(usernameLineEdit->text().ascii()); - user_config->set_domain(domainLineEdit->text().ascii()); - user_config->set_auth_name(authNameLineEdit->text().ascii()); - user_config->set_auth_pass(authPasswordLineEdit->text().ascii()); - - // SIP SERVER - user_config->set_use_outbound_proxy(!proxyLineEdit->text().isEmpty()); - s = USER_SCHEME; - s.append(':').append(proxyLineEdit->text()); - user_config->set_outbound_proxy(t_url(s.ascii())); - - // NAT - user_config->set_use_stun(!stunServerLineEdit->text().isEmpty()); - s = "stun:"; - s.append(stunServerLineEdit->text()); - user_config->set_stun_server(t_url(s.ascii())); - - // Save user config - string error_msg; - if (!user_config->write_config(user_config->get_filename(), error_msg)) { - // Failed to write config file - ((t_gui *)ui)->cb_show_msg(this, error_msg, MSG_CRITICAL); - return; - } - - emit success(); - accept(); -} -- cgit v1.2.3