Skip to content
Snippets Groups Projects
Commit 7ef995c9 authored by Emmanuel Lepage Vallee's avatar Emmanuel Lepage Vallee
Browse files

Code cleanup

parent f55edc47
No related branches found
No related tags found
No related merge requests found
Showing
with 17 additions and 326 deletions
......@@ -43,14 +43,11 @@ SET( sflphone_client_kde_SRCS
conf/dlgdisplay.cpp
conf/dlgaccounts.cpp
conf/dlgaudio.cpp
#conf/dlgrecord.cpp
conf/dlgaddressbook.cpp
conf/dlghooks.cpp
conf/ConfigurationSkeleton.cpp
Dialpad.cpp
Codec.cpp
#CodecListModel.cpp
#SortableCodecListWidget.cpp
Item.cpp
AccountListModel.cpp
)
......@@ -113,7 +110,6 @@ SET( config_ui_files
conf/dlgdisplaybase.ui
conf/dlgaccountsbase.ui
conf/dlgaudiobase.ui
conf/dlgrecordbase.ui
conf/dlgaddressbookbase.ui
conf/dlghooksbase.ui
)
......
/***************************************************************************
* 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. *
***************************************************************************/
#include "CodecListModel.h"
#include <QtCore/QSize>
#include <QtCore/QDebug>
#include <KLocale>
#include "configurationmanager_interface_singleton.h"
CodecListModel::CodecListModel(QObject *parent)
: QAbstractTableModel(parent)
{
this->codecs = QList<Codec *>();
ConfigurationManagerInterface & configurationManager = ConfigurationManagerInterfaceSingleton::getInstance();
QStringList activeCodecList = configurationManager.getActiveCodecList();
setActiveCodecList(activeCodecList);
}
CodecListModel::~CodecListModel()
{
}
QVariant CodecListModel::data ( const QModelIndex & index, int role) const
{
if (!index.isValid())
return QVariant();
const Codec * codec = codecs[index.row()];
if(index.column() == 1 && role == Qt::DisplayRole)
{
return QVariant(codec->getName());
}
else if(index.column() == 0 && role == Qt::CheckStateRole)
{
return QVariant(codec->isEnabled() ? Qt::Checked : Qt::Unchecked);
}
else if(index.column() == 2 && role == Qt::DisplayRole)
{
return QVariant(codec->getFrequency());
}
else if(index.column() == 3 && role == Qt::DisplayRole)
{
return QVariant(codec->getBitrate());
}
else if(index.column() == 4 && role == Qt::DisplayRole)
{
return QVariant(codec->getBandwidth());
}
return QVariant();
}
int CodecListModel::rowCount(const QModelIndex & /*parent*/) const
{
return codecs.count();
}
int CodecListModel::columnCount(const QModelIndex & /*parent*/) const
{
return 5;
}
QVariant CodecListModel::headerData(int section , Qt::Orientation orientation, int role) const
{
if (section == 0 && orientation == Qt::Horizontal && role == Qt::DisplayRole)
{
return QVariant(i18n(""));
}
else if (section == 1 && orientation == Qt::Horizontal && role == Qt::DisplayRole)
{
return QVariant(i18n("Codec"));
}
else if (section == 2 && orientation == Qt::Horizontal && role == Qt::DisplayRole)
{
return QVariant(i18n("Frequency"));
}
else if (section == 3 && orientation == Qt::Horizontal && role == Qt::DisplayRole)
{
return QVariant(i18n("Bitrate"));
}
else if (section == 4 && orientation == Qt::Horizontal && role == Qt::DisplayRole)
{
return QVariant(i18n("Bandwidth"));
}
return QVariant();
}
Qt::ItemFlags CodecListModel::flags(const QModelIndex & index) const
{
if (index.column() == 0)
{
return QAbstractItemModel::flags(index) | Qt::ItemIsUserCheckable;
}
return QAbstractItemModel::flags(index);
}
bool CodecListModel::setData ( const QModelIndex & index, const QVariant &value, int role)
{
qDebug() << "setData";
if (index.isValid() && index.column() == 0 && role == Qt::CheckStateRole) {
codecs[index.row()]->setEnabled(value.toBool());
emit dataChanged(index, index);
return true;
}
return false;
}
bool CodecListModel::codecUp( int index )
{
if(index > 0 && index <= rowCount())
{
codecs.swap(index - 1, index);
emit dataChanged(this->index(index - 1, 0, QModelIndex()), this->index(index, columnCount(), QModelIndex()));
return true;
}
return false;
}
bool CodecListModel::codecDown( int index )
{
if(index >= 0 && index < rowCount())
{
codecs.swap(index + 1, index);
emit dataChanged(this->index(index, 0, QModelIndex()), this->index(index + 1, columnCount(), QModelIndex()));
return true;
}
return false;
}
QStringList CodecListModel::getActiveCodecList() const
{
QStringList codecList;
for(int i = 0 ; i < rowCount() ; i++)
{
if(codecs[i]->isEnabled())
codecList.append(codecs[i]->getPayload());
}
return codecList;
}
void CodecListModel::setActiveCodecList(const QStringList & activeCodecListToSet)
{
this->codecs = QList<Codec *>();
ConfigurationManagerInterface & configurationManager = ConfigurationManagerInterfaceSingleton::getInstance();
QStringList codecList = configurationManager.getCodecList();
QStringList activeCodecList = activeCodecListToSet;
#if QT_VERSION >= 0x040500
activeCodecList.removeDuplicates();
#else
for (int i = 0 ; i < activeCodecList.size() ; i++)
{
if(activeCodecList.lastIndexOf(activeCodecList[i]) != i || ! codecList.contains(activeCodecList[i]))
{
activeCodecList.removeAt(i);
i--;
}
}
#endif
QStringList codecListToDisplay = activeCodecList;
for (int i=0 ; i<codecList.size() ; i++)
{
if(! activeCodecList.contains(codecList[i]))
{
codecListToDisplay << codecList[i];
}
}
for(int i=0 ; i<codecListToDisplay.size() ; i++)
{
bool ok;
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
{
codecs << new Codec(payload, activeCodecList.contains(codecListToDisplay[i]));
}
}
emit dataChanged(this->index(0, 0, QModelIndex()), this->index(rowCount(), columnCount(), QModelIndex()));
}
/***************************************************************************
* 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 CODECLISTMODEL_H
#define CODECLISTMODEL_H
#include <QAbstractItemModel>
#include "Codec.h"
/**
@author Jérémy Quentin <jeremy.quentin@gmail.com>
*/
class CodecListModel : public QAbstractTableModel
{
Q_OBJECT
private:
QList<Codec *> codecs;
public:
CodecListModel(QObject *parent = 0);
~CodecListModel();
QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const;
int rowCount(const QModelIndex & parent = QModelIndex()) const;
int columnCount(const QModelIndex & parent = QModelIndex()) const;
QVariant headerData(int section , Qt::Orientation orientation, int role) const;
Qt::ItemFlags flags(const QModelIndex & index) const;
virtual bool setData ( const QModelIndex & index, const QVariant &value, int role);
bool codecUp( int index );
bool codecDown( int index );
QStringList getActiveCodecList() const ;
void setActiveCodecList(const QStringList & activeCodecListToSet);
signals:
// void dataChanged(const QModelIndex &, const QModelIndex &);
};
#endif
......@@ -27,7 +27,6 @@
#include "dlgaccounts.h"
#include "dlgaudio.h"
#include "dlgaddressbook.h"
#include "dlgrecord.h"
#include "dlghooks.h"
#include "sflphone_const.h"
......@@ -42,7 +41,6 @@ ConfigurationDialog::ConfigurationDialog(SFLPhoneView *parent)
dlgAccounts = new DlgAccounts(this);
dlgAudio = new DlgAudio(this);
dlgAddressBook = new DlgAddressBook(this);
//dlgRecord = new DlgRecord(this);
dlgHooks = new DlgHooks(this);
addPage( dlgGeneral , i18n("General") , "sflphone-client-kde" );
......@@ -50,7 +48,6 @@ ConfigurationDialog::ConfigurationDialog(SFLPhoneView *parent)
addPage( dlgAccounts , i18n("Accounts") , "personal" );
addPage( dlgAudio , i18n("Audio") , "voicecall" );
addPage( dlgAddressBook , i18n("Address Book") , "x-office-address-book" );
//addPage( dlgRecord , i18n("Recordings") , "media-record" );
addPage( dlgHooks , i18n("Hooks") , "insert-link" );
connect(this, SIGNAL(applyClicked()), this, SLOT(applyCustomSettings()));
......@@ -89,18 +86,16 @@ void ConfigurationDialog::updateButtons()
{
bool changed = hasChanged();
qDebug() << "updateButtons , hasChanged = " << changed;
// if(hasChanged())
// enableButtonApply( true );
enableButtonApply( changed );
}
void ConfigurationDialog::applyCustomSettings()
{
qDebug() << "\napplyCustomSettings";
// if(hasChanged())
// {
if(hasChanged())
{
ConfigurationSkeleton::self()->writeConfig();
// }
}
updateSettings();
updateWidgets();
updateButtons();
......
......@@ -62,7 +62,6 @@ private:
DlgAccounts * dlgAccounts;
DlgAudio * dlgAudio;
DlgAddressBook * dlgAddressBook;
//DlgRecord * dlgRecord;
DlgHooks * dlgHooks;
public:
......
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
......@@ -233,20 +233,18 @@ void DlgAccounts::saveAccount(QListWidgetItem * item)
account->setAccountDetail(TLS_ENABLE,group_security_tls->isChecked()?"true":"false");
account->setAccountDetail(TLS_METHOD, QString::number(combo_security_STRP->currentIndex()));
QStringList test;
//QString test2;
QStringList _codecList;
foreach (QString aCodec, keditlistbox_codec->items()) {
foreach (StringHash _aCodec, codecList) {
if (_aCodec["alias"] == aCodec) {
test << _aCodec["id"];
//test2 += _aCodec["id"] + "/";
_codecList << _aCodec["id"];
}
}
}
ConfigurationManagerInterface & configurationManager = ConfigurationManagerInterfaceSingleton::getInstance();
configurationManager.setActiveCodecList(test, account->getAccountDetail(ACCOUNT_ID));
qDebug() << "Account codec have been saved" << test << account->getAccountDetail(ACCOUNT_ID);
configurationManager.setActiveCodecList(_codecList, account->getAccountDetail(ACCOUNT_ID));
qDebug() << "Account codec have been saved" << _codecList << account->getAccountDetail(ACCOUNT_ID);
}
void DlgAccounts::loadAccount(QListWidgetItem * item)
......@@ -543,7 +541,8 @@ void DlgAccounts::updateWidgets()
accountListHasChanged = false;
}
void DlgAccounts::loadCodecList() {
void DlgAccounts::loadCodecList()
{
ConfigurationManagerInterface & configurationManager = ConfigurationManagerInterfaceSingleton::getInstance();
QStringList codecIdList = configurationManager.getCodecList();
QStringList tmpNameList;
......@@ -574,7 +573,8 @@ void DlgAccounts::loadCodecList() {
}
void DlgAccounts::codecClicked(const QModelIndex & model) {
void DlgAccounts::codecClicked(const QModelIndex & model)
{
foreach (StringHash aCodec, codecList) {
if (aCodec["alias"] == keditlistbox_codec->currentText()) {
label_bandwidth_value->setText(aCodec["bandwidth"]);
......@@ -588,7 +588,8 @@ void DlgAccounts::codecClicked(const QModelIndex & model) {
keditlistbox_codec->addButton()->setEnabled(true);
}
void DlgAccounts::addCodec(QString name) {
void DlgAccounts::addCodec(QString name)
{
if (name.isEmpty()) {
Private_AddCodecDialog* aDialog = new Private_AddCodecDialog(codecList, keditlistbox_codec->items(), this);
aDialog->show();
......@@ -601,7 +602,8 @@ void DlgAccounts::addCodec(QString name) {
}
}
void DlgAccounts::codecChanged() {
void DlgAccounts::codecChanged()
{
if (keditlistbox_codec->items().size() == codecList.size())
keditlistbox_codec->addButton()->setEnabled(false);
else
......
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
/***************************************************************************
* 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. *
***************************************************************************/
#include "dlgrecord.h"
#include <KLineEdit>
DlgRecord::DlgRecord(QWidget *parent)
: QWidget(parent)
{
setupUi(this);
KUrlRequester_destinationFolder->setMode(KFile::Directory|KFile::ExistingOnly|KFile::LocalOnly);
KUrlRequester_destinationFolder->setUrl(KUrl(QDir::home().path()));
KUrlRequester_destinationFolder->lineEdit()->setObjectName("kcfg_destinationFolder");
KUrlRequester_destinationFolder->lineEdit()->setReadOnly(true);
}
DlgRecord::~DlgRecord()
{
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment