3 @author: Sudheer K. <scifi.guy@hotmail.com>
4 @license: GNU General Public License
7 #include "configwindow.h"
8 #include "ui_configwindow.h"
9 #include "gconfutility.h"
10 #include "dbusutility.h"
12 #include <QMessageBox>
14 ConfigWindow::ConfigWindow(QWidget *parent) :
16 ui(new Ui::ConfigWindow)
19 gconfUtility = new GConfUtility();
23 ConfigWindow::~ConfigWindow()
30 void ConfigWindow::changeEvent(QEvent *e)
32 QMainWindow::changeEvent(e);
34 case QEvent::LanguageChange:
35 ui->retranslateUi(this);
42 void ConfigWindow::closeEvent(QCloseEvent *e)
44 if (verifyConfigData()){
45 qDebug() << "Verification successful. Saving data to gconf";
54 void ConfigWindow::on_actionSave_triggered()
56 if (verifyConfigData()){
57 qDebug() << "Verification successful. Saving data to gconf";
63 void ConfigWindow::on_actionReset_triggered()
65 ui->checkBoxIntlCallRedirEnabled->setChecked(false);
66 ui->lineEditCallingCardNumber->clear();
67 ui->lineEditCountryCodesToExclude->clear();
68 ui->comboBoxDTMFFormat->clear();
69 ui->comboBoxDTMFSuffix->clear();
70 ui->spinBoxDTMFDelay->setValue(1);
73 void ConfigWindow::loadValues(){
75 bool isRoutingEnabled = gconfUtility->getGconfValueBoolean("routing_enabled");
76 QString strCallingCardNumber = gconfUtility->getGconfValueString("calling_card_number");
77 QString strNumbersToExclude = gconfUtility->getGconfValueString("numbers_to_exclude");
78 QString strDTMFFormat = gconfUtility->getGconfValueString("dtmf_format");
79 QString strDTMFSuffix = gconfUtility->getGconfValueString("dtmf_suffix");
80 int intDTMFDelay = gconfUtility->getGconfValueInteger("dtmf_delay");
82 ui->checkBoxIntlCallRedirEnabled->setChecked(isRoutingEnabled);
83 ui->lineEditCallingCardNumber->setText(strCallingCardNumber);
84 ui->lineEditCountryCodesToExclude->setText(strNumbersToExclude);
85 int intIndex = ui->comboBoxDTMFFormat->findText(strDTMFFormat);
86 ui->comboBoxDTMFFormat->setCurrentIndex(intIndex);
87 intIndex = ui->comboBoxDTMFSuffix->findText(strDTMFSuffix);
88 ui->comboBoxDTMFSuffix->setCurrentIndex(intIndex);
89 ui->spinBoxDTMFDelay->setValue(intDTMFDelay);
91 //Accept numbers only for Calling Card Number field
92 ui->lineEditCallingCardNumber->setValidator(new QRegExpValidator( QRegExp( "^-?\\d\\d*$"), this));
94 qDebug() << "Values loaded from GConf";
98 bool ConfigWindow::verifyConfigData(){
99 //Verify whether user-input matches application requirements
100 bool isRoutingEnabled = ui->checkBoxIntlCallRedirEnabled->isChecked();
101 QString strCallingCardNumber = ui->lineEditCallingCardNumber->text();
102 QString strNumbersToExclude = ui->lineEditCountryCodesToExclude->text();
105 QString strMessage = QString("");
107 if (isRoutingEnabled){
108 //Call Routing is checked. Now validate other values
109 if (strCallingCardNumber.isEmpty()){
110 strMessage.append("Enter a calling card number\n");
111 ui->lineEditCallingCardNumber->setFocus();
114 if (strCallingCardNumber.startsWith("+")||strCallingCardNumber.startsWith("00")){
115 strMessage.append("Calling card number must be a local number. \nPlease remove the international dialing code.\n");
116 ui->lineEditCallingCardNumber->setFocus();
121 if (!strMessage.isEmpty()){
122 QMessageBox::warning(this,"Invalid Data",strMessage);
130 void ConfigWindow::saveConfigData(){
132 bool isRoutingEnabled = ui->checkBoxIntlCallRedirEnabled->isChecked();
133 QString strCallingCardNumber = ui->lineEditCallingCardNumber->text();
134 QString strNumbersToExclude = ui->lineEditCountryCodesToExclude->text();
136 QString strDTMFFormat = ui->comboBoxDTMFFormat->currentText();
137 QString strDTMFSuffix = ui->comboBoxDTMFSuffix->currentText();
138 int intDTMFDelay = ui->spinBoxDTMFDelay->value();
141 gconfUtility->setGconfValueBoolean("routing_enabled",isRoutingEnabled);
143 if (!strCallingCardNumber.isEmpty()){
144 gconfUtility->setGconfValueString("calling_card_number",strCallingCardNumber);
147 if (!strNumbersToExclude.isEmpty()){
148 strNumbersToExclude = strNumbersToExclude.remove(" ");
149 strNumbersToExclude = strNumbersToExclude.remove("\t");
150 strNumbersToExclude = strNumbersToExclude.replace("\n",",");
153 gconfUtility->setGconfValueString("numbers_to_exclude",strNumbersToExclude);
154 gconfUtility->setGconfValueInteger("dtmf_delay",intDTMFDelay);
155 gconfUtility->setGconfValueString("dtmf_format",strDTMFFormat);
156 gconfUtility->setGconfValueString("dtmf_suffix",strDTMFSuffix);
158 DbusUtility dbusUtility = DbusUtility();
160 qDebug() << "Settings updated";
161 dbusUtility.displayNotification("VICaR: Settings Updated.");
163 if (isRoutingEnabled){
164 qDebug() << "Enable call routing immediately";
165 dbusUtility.sendSignal(APPLICATION_DBUS_PATH,APPLICATION_DBUS_INTERFACE,"startOutgoingCallMonitor");
168 qDebug() << "Disable call routing immediately";
169 dbusUtility.sendSignal(APPLICATION_DBUS_PATH,APPLICATION_DBUS_INTERFACE,"stopOutgoingCallMonitor");