Skip to content
Snippets Groups Projects
Commit 9ea06051 authored by Jérémy Quentin's avatar Jérémy Quentin
Browse files

[#1756] Implement a kde configuration dialog with kconfig xt and kconfigdialog class

parent 26bf3c24
Branches
Tags
No related merge requests found
...@@ -30,7 +30,6 @@ SET ( KDE4_KABC_LIBS -lkabc ) ...@@ -30,7 +30,6 @@ SET ( KDE4_KABC_LIBS -lkabc )
SET( sflphone_client_kde_SRCS SET( sflphone_client_kde_SRCS
sflphone_kdeview.cpp sflphone_kdeview.cpp
SFLPhone.cpp SFLPhone.cpp
ConfigDialog.cpp
main.cpp main.cpp
sflphone_const.h sflphone_const.h
Account.cpp Account.cpp
......
This diff is collapsed.
/***************************************************************************
* Copyright (C) 2009 by Savoir-Faire Linux *
* Author : Jérémy Quentin *
* jeremy.quentin@savoirfairelinux.com *
* *
* 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 3 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 HEADER_CONFIGDIALOG
#define HEADER_CONFIGDIALOG
#include <QtGui/QTableWidgetItem>
#include <QtGui/QListWidgetItem>
#include <QtCore/QString>
#include <QtGui/QAbstractButton>
#include <QErrorMessage>
#include "ui_ConfigDialog.h"
#include "AccountList.h"
#include "sflphone_kdeview.h"
class sflphone_kdeView;
class ConfigurationDialog : public QDialog, private Ui::ConfigurationDialog
{
Q_OBJECT
private:
static AccountList * accountList;
QErrorMessage * errorWindow;
bool accountsChangedEnableWarning;
public:
//Constructors & Destructors
ConfigurationDialog(sflphone_kdeView * parent);
~ConfigurationDialog();
//Getters
static AccountList * getAccountList();
//Setters
void setPage(int page);
void addAccountToAccountList(Account * account);
void loadAccount(QListWidgetItem * item);
void saveAccount(QListWidgetItem * item);
void loadAccountList();
void saveAccountList();
void loadCodecs();
void saveCodecs();
void loadOptions();
void saveOptions();
//Updates
void updateCodecListCommands();
void updateAccountListCommands();
void updateAccountStates();
private slots:
void changedAccountList();
void connectAccountsChangedSignal();
void disconnectAccountsChangedSignal();
void on_toolButton_codecUp_clicked();
void on_toolButton_codecDown_clicked();
void on_button_accountUp_clicked();
void on_button_accountDown_clicked();
void on_button_accountAdd_clicked();
void on_button_accountRemove_clicked();
void on_edit1_alias_textChanged(const QString & text);
void on_listWidget_accountList_currentItemChanged ( QListWidgetItem * current, QListWidgetItem * previous );
void on_spinBox_SIPPort_valueChanged ( int value );
void on_buttonBoxDialog_clicked(QAbstractButton * button);
void on_tableWidget_codecs_currentCellChanged(int currentRow);
void on_toolButton_accountsApply_clicked();
void on1_accountsChanged();
void on1_parametersChanged();
void on1_errorAlert(int code);
};
#endif
...@@ -32,14 +32,12 @@ ...@@ -32,14 +32,12 @@
#include <KXmlGuiWindow> #include <KXmlGuiWindow>
#include "ui_sflphone_kdeview_base.h" #include "ui_sflphone_kdeview_base.h"
#include "ConfigDialog.h"
#include "CallList.h" #include "CallList.h"
#include "AccountWizard.h" #include "AccountWizard.h"
#include "Contact.h" #include "Contact.h"
#include "sflphone_kdeview.h" #include "sflphone_kdeview.h"
class ConfigurationDialog;
class sflphone_kdeView; class sflphone_kdeView;
class SFLPhone : public KXmlGuiWindow class SFLPhone : public KXmlGuiWindow
......
...@@ -108,7 +108,7 @@ void ConfigurationSkeleton::readConfig() ...@@ -108,7 +108,7 @@ void ConfigurationSkeleton::readConfig()
} }
//codecs settings //codecs settings
// // loadCodecs(); setActiveCodecList(configurationManager.getActiveCodecList());
qDebug() << "configurationManager.getCurrentAudioOutputPlugin() = " << configurationManager.getCurrentAudioOutputPlugin(); qDebug() << "configurationManager.getCurrentAudioOutputPlugin() = " << configurationManager.getCurrentAudioOutputPlugin();
setAlsaPlugin(configurationManager.getCurrentAudioOutputPlugin()); setAlsaPlugin(configurationManager.getCurrentAudioOutputPlugin());
...@@ -227,7 +227,8 @@ void ConfigurationSkeleton::writeConfig() ...@@ -227,7 +227,8 @@ void ConfigurationSkeleton::writeConfig()
configurationManager.setRingtoneChoice(ringtone()); configurationManager.setRingtoneChoice(ringtone());
//codecs settings //codecs settings
// // saveCodecs(); configurationManager.setActiveCodecList(activeCodecList());
//alsa settings //alsa settings
if(prevManager == CONST_ALSA && newManager == EnumInterface::ALSA) if(prevManager == CONST_ALSA && newManager == EnumInterface::ALSA)
......
...@@ -25,20 +25,34 @@ ...@@ -25,20 +25,34 @@
#include "conf/ConfigurationSkeleton.h" #include "conf/ConfigurationSkeleton.h"
#include "conf/ConfigurationDialog.h" #include "conf/ConfigurationDialog.h"
#include "sflphone_const.h"
DlgAudio::DlgAudio(KConfigDialog *parent) DlgAudio::DlgAudio(KConfigDialog *parent)
: QWidget(parent) : QWidget(parent)
{ {
setupUi(this); setupUi(this);
ConfigurationManagerInterface & configurationManager = ConfigurationManagerInterfaceSingleton::getInstance(); ConfigurationManagerInterface & configurationManager = ConfigurationManagerInterfaceSingleton::getInstance();
QStyle * style = QApplication::style();
KUrl url = KUrl(SHARE_INSTALL_PREFIX); KUrl url = KUrl(SHARE_INSTALL_PREFIX);
url.cd("sflphone/ringtones"); url.cd("sflphone/ringtones");
KUrlRequester_ringtone->setUrl(url); KUrlRequester_ringtone->setUrl(url);
KUrlRequester_ringtone->lineEdit()->setObjectName("kcfg_ringtone"); KUrlRequester_ringtone->lineEdit()->setObjectName("kcfg_ringtone");
codecTableHasChanged = false;
toolButton_codecUp->setIcon(style->standardIcon(QStyle::SP_ArrowUp));
toolButton_codecDown->setIcon(style->standardIcon(QStyle::SP_ArrowDown));
tableWidget_codecs->verticalHeader()->hide();
tableWidget_codecs->setSelectionBehavior(QAbstractItemView::SelectRows);
updateAlsaSettings(); updateAlsaSettings();
connect(box_alsaPlugin, SIGNAL(currentIndexChanged(int)), parent, SLOT(updateButtons())); connect(box_alsaPlugin, SIGNAL(currentIndexChanged(int)), parent, SLOT(updateButtons()));
connect(tableWidget_codecs, SIGNAL(itemChanged(QTableWidgetItem *)), this, SLOT(codecTableChanged()));
connect(toolButton_codecUp, SIGNAL(clicked()), this, SLOT(codecTableChanged()));
connect(toolButton_codecDown, SIGNAL(clicked()), this, SLOT(codecTableChanged()));
connect(this, SIGNAL(updateButtons()), parent, SLOT(updateButtons()));
} }
...@@ -49,16 +63,102 @@ DlgAudio::~DlgAudio() ...@@ -49,16 +63,102 @@ DlgAudio::~DlgAudio()
void DlgAudio::updateWidgets() void DlgAudio::updateWidgets()
{ {
// qDebug() << "DlgAudio::updateWidgets"; // qDebug() << "DlgAudio::updateWidgets";
//alsa Plugin
ConfigurationSkeleton * skeleton = ConfigurationSkeleton::self(); ConfigurationSkeleton * skeleton = ConfigurationSkeleton::self();
box_alsaPlugin->setCurrentIndex(box_alsaPlugin->findText(skeleton->alsaPlugin())); box_alsaPlugin->setCurrentIndex(box_alsaPlugin->findText(skeleton->alsaPlugin()));
//codecList
qDebug() << "loadCodecs";
ConfigurationManagerInterface & configurationManager = ConfigurationManagerInterfaceSingleton::getInstance();
QStringList codecList = configurationManager.getCodecList();
QStringList activeCodecList = skeleton->activeCodecList();
#if QT_VERSION >= 0x040500
activeCodecList.removeDuplicates();
#else
for (int i = 0 ; i < activeCodecList.size() ; i++)
{
if(activeCodecList.lastIndexOf(activeCodecList[i]) != i)
{
activeCodecList.removeAt(i);
i--;
}
}
#endif
for (int i=0 ; i<activeCodecList.size() ; i++)
{
if(! codecList.contains(activeCodecList[i]))
{
activeCodecList.removeAt(i);
i--;
}
}
QStringList codecListToDisplay = activeCodecList;
for (int i=0 ; i<codecList.size() ; i++)
{
if(! activeCodecList.contains(codecList[i]))
{
codecListToDisplay << codecList[i];
}
}
qDebug() << "codecList = " << codecList;
qDebug() << "activeCodecList" << activeCodecList;
qDebug() << "codecListToDisplay" << codecListToDisplay;
tableWidget_codecs->setRowCount(0);
for(int i=0 ; i<codecListToDisplay.size() ; i++)
{
bool ok;
qDebug() << codecListToDisplay[i];
QString payloadStr = QString(codecListToDisplay[i]);
int payload = payloadStr.toInt(&ok);
if(!ok)
qDebug() << "The codec's payload sent by the configurationManager is not a number : " << codecListToDisplay[i];
else
{
QStringList details = configurationManager.getCodecDetails(payload);
tableWidget_codecs->insertRow(i);
tableWidget_codecs->setVerticalHeaderItem (i, new QTableWidgetItem());
tableWidget_codecs->verticalHeaderItem (i)->setText(payloadStr);
tableWidget_codecs->setItem(i,0,new QTableWidgetItem(""));
tableWidget_codecs->setItem(i,1,new QTableWidgetItem(details[CODEC_NAME]));
tableWidget_codecs->setItem(i,2,new QTableWidgetItem(details[CODEC_SAMPLE_RATE]));
tableWidget_codecs->setItem(i,3,new QTableWidgetItem(details[CODEC_BIT_RATE]));
tableWidget_codecs->setItem(i,4,new QTableWidgetItem(details[CODEC_BANDWIDTH]));
tableWidget_codecs->item(i,0)->setFlags(Qt::ItemIsSelectable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
tableWidget_codecs->item(i,0)->setCheckState(activeCodecList.contains(codecListToDisplay[i]) ? Qt::Checked : Qt::Unchecked);
tableWidget_codecs->item(i,1)->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled);
tableWidget_codecs->item(i,2)->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled);
tableWidget_codecs->item(i,3)->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled);
tableWidget_codecs->item(i,4)->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled);
qDebug() << "Added to codecs : " << payloadStr << " , " << details[CODEC_NAME];
}
}
tableWidget_codecs->resizeColumnsToContents();
tableWidget_codecs->resizeRowsToContents();
codecTableHasChanged = false;
} }
void DlgAudio::updateSettings() void DlgAudio::updateSettings()
{ {
// qDebug() << "DlgAudio::updateSettings"; // qDebug() << "DlgAudio::updateSettings";
//alsaPlugin
ConfigurationSkeleton * skeleton = ConfigurationSkeleton::self(); ConfigurationSkeleton * skeleton = ConfigurationSkeleton::self();
skeleton->setAlsaPlugin(box_alsaPlugin->currentText()); skeleton->setAlsaPlugin(box_alsaPlugin->currentText());
//codecList
QStringList activeCodecs;
for(int i = 0 ; i < tableWidget_codecs->rowCount() ; i++)
{
if(tableWidget_codecs->item(i,0)->checkState() == Qt::Checked)
{
activeCodecs << tableWidget_codecs->verticalHeaderItem(i)->text();
}
}
qDebug() << "Calling setActiveCodecList with list : " << activeCodecs ;
skeleton->setActiveCodecList(activeCodecs);
codecTableHasChanged = false;
} }
bool DlgAudio::hasChanged() bool DlgAudio::hasChanged()
...@@ -67,7 +167,10 @@ bool DlgAudio::hasChanged() ...@@ -67,7 +167,10 @@ bool DlgAudio::hasChanged()
ConfigurationSkeleton * skeleton = ConfigurationSkeleton::self(); ConfigurationSkeleton * skeleton = ConfigurationSkeleton::self();
qDebug() << "skeleton->alsaPlugin() = " << skeleton->alsaPlugin(); qDebug() << "skeleton->alsaPlugin() = " << skeleton->alsaPlugin();
qDebug() << "box_alsaPlugin->currentText() = " << box_alsaPlugin->currentText(); qDebug() << "box_alsaPlugin->currentText() = " << box_alsaPlugin->currentText();
return (skeleton->interface() == ConfigurationSkeleton::EnumInterface::ALSA && skeleton->alsaPlugin() != box_alsaPlugin->currentText()); bool alsaPluginHasChanged =
skeleton->interface() == ConfigurationSkeleton::EnumInterface::ALSA
&& skeleton->alsaPlugin() != box_alsaPlugin->currentText();
return alsaPluginHasChanged || codecTableHasChanged;
} }
void DlgAudio::updateAlsaSettings() void DlgAudio::updateAlsaSettings()
...@@ -105,4 +208,80 @@ void DlgAudio::updateAlsaSettings() ...@@ -105,4 +208,80 @@ void DlgAudio::updateAlsaSettings()
} }
} }
void DlgAudio::updateCodecListCommands()
{
bool buttonsEnabled[2] = {true,true};
if(! tableWidget_codecs->currentItem())
{
buttonsEnabled[0] = false;
buttonsEnabled[1] = false;
}
else if(tableWidget_codecs->currentRow() == 0)
{
buttonsEnabled[0] = false;
}
else if(tableWidget_codecs->currentRow() == tableWidget_codecs->rowCount() - 1)
{
buttonsEnabled[1] = false;
}
toolButton_codecUp->setEnabled(buttonsEnabled[0]);
toolButton_codecDown->setEnabled(buttonsEnabled[1]);
}
void DlgAudio::on_tableWidget_codecs_currentCellChanged(int currentRow)
{
qDebug() << "on_tableWidget_codecs_currentCellChanged";
int nbCol = tableWidget_codecs->columnCount();
for(int i = 0 ; i < nbCol ; i++)
{
tableWidget_codecs->setRangeSelected(QTableWidgetSelectionRange(currentRow, 0, currentRow, nbCol - 1), true);
}
updateCodecListCommands();
}
void DlgAudio::on_toolButton_codecUp_clicked()
{
qDebug() << "on_toolButton_codecUp_clicked";
int currentCol = tableWidget_codecs->currentColumn();
int currentRow = tableWidget_codecs->currentRow();
int nbCol = tableWidget_codecs->columnCount();
for(int i = 0 ; i < nbCol ; i++)
{
QTableWidgetItem * item1 = tableWidget_codecs->takeItem(currentRow, i);
QTableWidgetItem * item2 = tableWidget_codecs->takeItem(currentRow - 1, i);
tableWidget_codecs->setItem(currentRow - 1, i , item1);
tableWidget_codecs->setItem(currentRow, i , item2);
}
QTableWidgetItem * item1 = tableWidget_codecs->takeVerticalHeaderItem(currentRow);
QTableWidgetItem * item2 = tableWidget_codecs->takeVerticalHeaderItem(currentRow - 1);
tableWidget_codecs->setVerticalHeaderItem(currentRow - 1, item1);
tableWidget_codecs->setVerticalHeaderItem(currentRow, item2);
tableWidget_codecs->setCurrentCell(currentRow - 1, currentCol);
}
void DlgAudio::on_toolButton_codecDown_clicked()
{
qDebug() << "on_toolButton_codecDown_clicked";
int currentCol = tableWidget_codecs->currentColumn();
int currentRow = tableWidget_codecs->currentRow();
int nbCol = tableWidget_codecs->columnCount();
for(int i = 0 ; i < nbCol ; i++)
{
QTableWidgetItem * item1 = tableWidget_codecs->takeItem(currentRow, i);
QTableWidgetItem * item2 = tableWidget_codecs->takeItem(currentRow + 1, i);
tableWidget_codecs->setItem(currentRow + 1, i , item1);
tableWidget_codecs->setItem(currentRow, i , item2);
}
QTableWidgetItem * item1 = tableWidget_codecs->takeVerticalHeaderItem(currentRow);
QTableWidgetItem * item2 = tableWidget_codecs->takeVerticalHeaderItem(currentRow + 1);
tableWidget_codecs->setVerticalHeaderItem(currentRow + 1, item1);
tableWidget_codecs->setVerticalHeaderItem(currentRow, item2);
tableWidget_codecs->setCurrentCell(currentRow + 1, currentCol);
}
void DlgAudio::codecTableChanged()
{
codecTableHasChanged = true;
emit updateButtons();
}
\ No newline at end of file
...@@ -38,11 +38,24 @@ public: ...@@ -38,11 +38,24 @@ public:
~DlgAudio(); ~DlgAudio();
private:
bool codecTableHasChanged;
public slots: public slots:
void updateWidgets(); void updateWidgets();
void updateSettings(); void updateSettings();
bool hasChanged(); bool hasChanged();
void updateAlsaSettings(); void updateAlsaSettings();
private slots:
void updateCodecListCommands();
void on_tableWidget_codecs_currentCellChanged(int currentRow);
void on_toolButton_codecUp_clicked();
void on_toolButton_codecDown_clicked();
void codecTableChanged();
signals:
void updateButtons();
}; };
#endif #endif
...@@ -56,6 +56,9 @@ ...@@ -56,6 +56,9 @@
<entry name="ringtone" type="Path"> <entry name="ringtone" type="Path">
<label>Defines which ringtone is used.</label> <label>Defines which ringtone is used.</label>
</entry> </entry>
<entry name="activeCodecList" type="StringList">
<label>Defines which ALSA plugin to use.</label>
</entry>
<entry name="alsaPlugin" type="String"> <entry name="alsaPlugin" type="String">
<label>Defines which ALSA plugin to use.</label> <label>Defines which ALSA plugin to use.</label>
</entry> </entry>
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include <kaboutdata.h> #include <kaboutdata.h>
#include <klocale.h> #include <klocale.h>
#include "ConfigDialog.h"
#include "SFLPhone.h" #include "SFLPhone.h"
#include "AccountWizard.h" #include "AccountWizard.h"
#include "instance_interface_singleton.h" #include "instance_interface_singleton.h"
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment