Commit e41417c7 authored by llea's avatar llea

Configuration tree setup and config-directory creation in user's home directory

parent 0a68e201
......@@ -34,6 +34,8 @@ OBJS = \
audiortp.o \
CDataFile.o \
configuration.o \
configitem.o \
configurationtree.o \
dtmf.o \
dtmfgenerator.o \
g711.o \
......
/*
* Copyright (C) 2004 Savoir-Faire Linux inc.
* Author: Laurielle Lea <laurielle.lea@savoirfairelinux.com>
*
* This 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,
* or (at your option) any later version.
*
* This 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 dpkg; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <qapplication.h>
#include "audiocodec.h"
#include "configuration.h"
#include "g711.h"
#include <string>
#ifdef CCXX_NAMESPACES
using namespace std;
#endif
AudioCodec::AudioCodec (void) {
// Init array handleCodecs
#if 0
handleCodecs[0] = matchPayloadCodec(
Config::gets(QString("Audio/Codecs.codec1")));
handleCodecs[1] = matchPayloadCodec(
......@@ -17,13 +41,19 @@ AudioCodec::AudioCodec (void) {
Config::gets(QString("Audio/Codecs.codec4")));
handleCodecs[4] = matchPayloadCodec(
Config::gets(QString("Audio/Codecs.codec5")));
#endif
handleCodecs[0] = matchPayloadCodec(Config::gets("Audio", "Codecs.codec1"));
handleCodecs[1] = matchPayloadCodec(Config::gets("Audio", "Codecs.codec2"));
handleCodecs[2] = matchPayloadCodec(Config::gets("Audio", "Codecs.codec3"));
handleCodecs[3] = matchPayloadCodec(Config::gets("Audio", "Codecs.codec4"));
handleCodecs[4] = matchPayloadCodec(Config::gets("Audio", "Codecs.codec5"));
}
AudioCodec::~AudioCodec (void) {
}
int
AudioCodec::matchPayloadCodec (QString codecname) {
AudioCodec::matchPayloadCodec (std::string codecname) {
if (codecname == CODEC_ALAW) {
return PAYLOAD_CODEC_ALAW;
} else if (codecname == CODEC_ULAW) {
......
......@@ -20,7 +20,10 @@
#ifndef __CODEC_AUDIO_H__
#define __CODEC_AUDIO_H__
#include <qstring.h>
#include <string.h>
#ifdef CCXX_NAMESPACES
using namespace std;
#endif
typedef enum {
PAYLOAD_CODEC_ULAW = 0,
......@@ -29,13 +32,18 @@ typedef enum {
PAYLOAD_CODEC_ILBC = 97,
PAYLOAD_CODEC_SPEEX = 110
} codecType;
/*
#define CODEC_ALAW QString("G711a")
#define CODEC_ULAW QString("G711u")
#define CODEC_GSM QString("GSM")
#define CODEC_ILBC QString("iLBC")
#define CODEC_SPEEX QString("SPEEX")
*/
#define CODEC_ALAW std::string("G711a")
#define CODEC_ULAW std::string("G711u")
#define CODEC_GSM std::string("GSM")
#define CODEC_ILBC std::string("iLBC")
#define CODEC_SPEEX std::string("SPEEX")
#define NB_CODECS 5
......@@ -49,7 +57,7 @@ public:
void noSupportedCodec (void);
static int codecDecode (int, short *, unsigned char *, unsigned int);
static int codecEncode (int, unsigned char *, short *, unsigned int);
int matchPayloadCodec (QString);
int matchPayloadCodec (std::string);
char * rtpmapPayload (int);
private:
......
......@@ -34,19 +34,21 @@
#include "sip.h"
#include "../stund/stun.h"
#include <string>
#ifdef CCXX_NAMESPACES
using namespace ost;
using namespace std;
#endif
////////////////////////////////////////////////////////////////////////////////
// AudioRtp
////////////////////////////////////////////////////////////////////////////////
AudioRtp::AudioRtp (SIP *sip, Manager *manager) {
QString svr;
string svr;
this->sip = sip;
this->manager = manager;
RTXThread = NULL;
#if 0
if (!manager->useStun()) {
if (Config::gets("Signalisations/SIP.sipproxy")) {
svr = Config::gets("Signalisations/SIP.sipproxy");
......@@ -54,6 +56,14 @@ AudioRtp::AudioRtp (SIP *sip, Manager *manager) {
} else {
svr = Config::gets("Signalisations/SIP.hostPart");
}
#endif
if (!manager->useStun()) {
if (Config::gets("Signalisations", "SIP.sipproxy") == NULL) {
svr = Config::gets("Signalisations", "SIP.sipproxy");
}
} else {
svr = Config::gets("Signalisations", "SIP.hostPart");
}
}
AudioRtp::~AudioRtp (void) {
......
//
// (c) 2004 Jerome Oufella <jerome.oufella@savoirfairelinux.com>
// (c) 2004 Savoir-faire Linux inc.
// Author: Jerome Oufella <jerome.oufella@savoirfairelinux.com>
//
//
#include <cc++/string.h>
......@@ -40,6 +40,7 @@ ConfigItem::~ConfigItem (void) {
String*
ConfigItem::getValueByKey (const char *keyName) {
assert (_key != NULL);
if (*_key == keyName) {
return _value;
} else if (_next) {
......
//
// (c) 2004 Jerome Oufella <jerome.oufella@savoirfairelinux.com>
// (c) 2004 Savoir-faire Linux inc.
// Author: Jerome Oufella <jerome.oufella@savoirfairelinux.com>
//
//
#ifndef __CONFIG_ITEM_H__
......
......@@ -21,8 +21,11 @@
#include <qsettings.h>
#include "configuration.h"
#include "configurationtree.h"
static ConfigurationTree *globalConfigTree = NULL;
#if 0
QString
Config::gets (QString key) {
return Config::get (key, QString(""));
......@@ -77,5 +80,95 @@ Config::set (QString key, bool val) {
settings.writeEntry (QString(CFG_PFX) + QString("/") + key, val);
return val;
}
#endif
string
Config::gets (const char *section, const char *key) {
return Config::get (section, key, "");
}
string
Config::get (const char *section, const char *key, const char *defval) {
char *value = tree()->getValue (section, key);
if (value == NULL) {
tree()->setValue(section, key, defval);
return string(defval);
} else {
return string(value);
}
}
char *
Config::getschar (const char *section, const char *key) {
return Config::getchar (section, key, "");
}
char *
Config::getchar (const char *section, const char *key, const char *defval) {
char *value = tree()->getValue (section, key);
if (value == NULL) {
tree()->setValue(section, key, defval);
return (char*)defval;
} else {
return value;
}
}
bool
Config::getb (const char *section, const char *key) {
return (bool)Config::get (section, key, 0);
}
int
Config::geti (const char *section, const char *key) {
return Config::get (section, key, 0);
}
int
Config::get (const char *section, const char * key, int defval) {
char *value = tree()->getValue(section, key);
if (value == NULL) {
tree()->setValue(section, key, defval);
return defval;
} else {
return atoi(value);
}
}
string
Config::set (const char *section, const char *key, const char *val) {
tree()->setValue(section, key, val);
return string(val);
}
char *
Config::setchar (const char *section, const char *key, const char *val) {
tree()->setValue(section, key, val);
return (char*)val;
}
int
Config::set (const char *section, const char *key, int val) {
tree()->setValue(section, key, val);
return val;
}
bool
Config::set (const char *section, const char *key, bool val) {
tree()->setValue(section, key, (int)val);
return val;
}
void
Config::setTree (ConfigurationTree *t) {
globalConfigTree = t;
}
ConfigurationTree*
Config::tree(void) {
return globalConfigTree;
}
// EOF
......@@ -26,13 +26,18 @@
#include "global.h"
#define CFG_PFX PROGNAME
#include <string>
#ifdef CCXX_NAMESPACES
using namespace std;
#endif
class ConfigurationTree;
class Config {
public:
Config (void) {};
~Config (void) {};
#if 0
static QString gets (QString);
static QString get (QString, QString);
static QString set (QString, QString);
......@@ -44,6 +49,24 @@ public:
static bool getb (QString);
static bool get (QString, bool);
static bool set (QString, bool);
#endif
static std::string gets (const char*, const char*);
static char* getschar (const char*, const char*);
static int geti (const char*, const char*);
static bool getb (const char*, const char*);
static std::string get (const char*, const char*, const char*);
static char* getchar (const char*, const char*, const char*);
static int get (const char*, const char*, int);
static bool get (const char*, const char*, bool);
static int set (const char*, const char*, int);
static bool set (const char*, const char*, bool);
static std::string set (const char*, const char*, const char*);
static char* setchar (const char*, const char*, const char*);
static void setTree (ConfigurationTree *);
static ConfigurationTree* tree (void);
};
#endif // __CONFIG_H__
......@@ -10,7 +10,6 @@
** destructor.
*****************************************************************************/
#include <qdir.h>
#include <qsettings.h>
#include <qstringlist.h>
#include "configuration.h"
......@@ -19,10 +18,10 @@
#include "skin.h"
#include "qtGUImainwindow.h"
void ConfigurationPanel::init()
{
// For reading settings at application startup
QSettings settings;
// List skin choice from "skins" directory
QDir dir(Skin::getPath(QString(SKINDIR)));
......@@ -41,66 +40,38 @@ void ConfigurationPanel::init()
}
// For signalisations tab
fullName->setText(
Config::get(QString("Signalisations/SIP.fullName"), QString("")));
userPart->setText(
Config::get(QString("Signalisations/SIP.userPart"), QString("")));
username->setText(
Config::get(QString("Signalisations/SIP.username"), QString("")));
password->setText(
Config::get(QString("Signalisations/SIP.password"), QString("")));
hostPart->setText(
Config::get(QString("Signalisations/SIP.hostPart"), QString("")));
sipproxy->setText(
Config::get(QString("Signalisations/SIP.sipproxy"), QString("")));
playTones->setChecked(
Config::get(QString("Signalisations/DTMF.playTones"), true));
pulseLength->setValue(
Config::get(QString("Signalisations/DTMF.pulseLength"), 250));
sendDTMFas->setCurrentItem(
Config::get(QString("Signalisations/DTMF.sendDTMFas"), 1));
STUNserver->setText(
Config::get(QString("Signalisations/STUN.STUNserver"),
QString("stun.fwdnet.net:3478")));
useStunYes->setChecked(
Config::get(QString("Signalisations/STUN.useStunYes"), false));
useStunNo->setChecked(
Config::get(QString("Signalisations/STUN.useStunNo"), true));
// For signalisations tab
fullName->setText(QString(Config::getchar("Signalisations", "SIP.fullName", "")));
userPart->setText(QString(Config::getchar("Signalisations", "SIP.userPart", "")));
username->setText(QString(Config::getchar("Signalisations", "SIP.username", "")));
password->setText(QString(Config::getchar("Signalisations", "SIP.password", "")));
hostPart->setText(QString(Config::getchar("Signalisations", "SIP.hostPart", "")));
sipproxy->setText(QString(Config::getchar("Signalisations", "SIP.sipproxy", "")));
playTones->setChecked(Config::get("Signalisations", "DTMF.playTones", (int)true));
pulseLength->setValue(Config::get("Signalisations", "DTMF.pulseLength", 250));
sendDTMFas->setCurrentItem(Config::get("Signalisations", "DTMF.sendDTMFas",1));
// For audio tab
ossButton->setChecked(
Config::get(QString("Audio/Drivers.driverOSS"), true));
alsaButton->setChecked(
Config::get(QString("Audio/Drivers.driverALSA"), false));
codec1->setCurrentText(
Config::get(QString("Audio/Codecs.codec1"), QString("G711u")));
codec2->setCurrentText(
Config::get(QString("Audio/Codecs.codec2"), QString("G711a")));
codec3->setCurrentText(
Config::get(QString("Audio/Codecs.codec3"), QString("GSM")));
codec4->setCurrentText(
Config::get(QString("Audio/Codecs.codec4"), QString("iLBC")));
codec5->setCurrentText(
Config::get(QString("Audio/Codecs.codec5"), QString("SPEEX")));
ossButton->setChecked(Config::get("Audio", "Drivers.driverOSS", (int)true));
alsaButton->setChecked(Config::get("Audio", "Drivers.driverALSA", (int)false));
codec1->setCurrentText(QString(Config::getchar("Audio", "Codecs.codec1", "G711u")));
codec2->setCurrentText(QString(Config::getchar("Audio", "Codecs.codec2", "G711a")));
codec3->setCurrentText(QString(Config::getchar("Audio", "Codecs.codec3", "GSM")));
codec4->setCurrentText(QString(Config::getchar("Audio", "Codecs.codec4", "iLBC")));
codec5->setCurrentText(QString(Config::getchar("Audio", "Codecs.codec5", "SPEEX")));
// For preferences tab
SkinChoice->setCurrentText(
Config::get(QString("Preferences/Themes.skinChoice"), QString("metal")));
confirmationToQuit->setChecked(
Config::get(QString("Preferences/Options.confirmQuit"), true));
zoneToneChoice->setCurrentText(
Config::get(QString("Preferences/Options.zoneToneChoice"),
QString("North America")));
checkedTray->setChecked(
Config::get(QString("Preferences/Options.checkedTray"), false));
autoregister->setChecked(
Config::get(QString("Preferences/Options.autoregister"), true));
voicemailNumber->setText(
Config::get(QString("Preferences/Themes.voicemailNumber"), QString("888")));
SkinChoice->setCurrentText(QString(Config::getchar(
"Preferences", "Themes.skinChoice", "metal")));
confirmationToQuit->setChecked(Config::get(
"Preferences", "Options.confirmQuit", (int)true));
zoneToneChoice->setCurrentText(QString(Config::getchar(
"Preferences", "Options.zoneToneChoice", "North America")));
checkedTray->setChecked(Config::get(
"Preferences", "Options.checkedTray", (int)false));
autoregister->setChecked(Config::get(
"Preferences", "Options.autoregister", (int)true));
// Init tab view order
Tab_Signalisations->show();
Tab_Audio->hide();
......@@ -132,41 +103,38 @@ voicemailNumber->setText(
// For saving settings at application 'save'
void ConfigurationPanel::saveSlot()
{
QSettings settings;
Config::set("Signalisations/SIP.fullName", fullName->text());
Config::set("Signalisations/SIP.userPart", userPart->text());
Config::set("Signalisations/SIP.username", username->text());
Config::set("Signalisations/SIP.password", password->text());
Config::set("Signalisations/SIP.hostPart", hostPart->text());
Config::set("Signalisations/SIP.sipproxy", sipproxy->text());
Config::set("Signalisations/DTMF.pulseLength", pulseLength->value());
Config::set("Signalisations/DTMF.playTones", playTones->isChecked());
Config::set("Signalisations/DTMF.sendDTMFas", sendDTMFas->currentItem());
Config::set("Signalisations/STUN.STUNserver", STUNserver->text());
Config::set("Signalisations/STUN.useStunYes", useStunYes->isChecked());
Config::set("Signalisations/STUN.useStunNo", useStunNo->isChecked());
Config::set("Signalisations", "SIP.fullName", fullName->text());
Config::set("Signalisations", "SIP.userPart", userPart->text());
Config::set("Signalisations", "SIP.username", username->text());
Config::set("Signalisations", "SIP.password", password->text());
Config::set("Signalisations", "SIP.hostPart", hostPart->text());
Config::set("Signalisations", "SIP.sipproxy", sipproxy->text());
Config::set("Signalisations", "DTMF.pulseLength", pulseLength->value());
Config::set("Signalisations", "DTMF.playTones", playTones->isChecked());
Config::set("Signalisations", "DTMF.sendDTMFas" , sendDTMFas->currentItem());
Config::set("Audio/Drivers.driverOSS", ossButton->isChecked());
Config::set("Audio/Drivers.driverALSA", alsaButton->isChecked());
Config::set("Audio", "Drivers.driverOSS", ossButton->isChecked());
Config::set("Audio", "Drivers.driverALSA", alsaButton->isChecked());
Config::set("Audio/Codecs.codec1", codec1->currentText());
Config::set("Audio/Codecs.codec2", codec2->currentText());
Config::set("Audio/Codecs.codec3", codec3->currentText());
Config::set("Audio/Codecs.codec4", codec4->currentText());
Config::set("Audio/Codecs.codec5", codec5->currentText());
Config::set("Audio", "Codecs.codec1", codec1->currentText());
Config::set("Audio", "Codecs.codec2", codec2->currentText());
Config::set("Audio", "Codecs.codec3", codec3->currentText());
Config::set("Audio", "Codecs.codec4", codec4->currentText());
Config::set("Audio", "Codecs.codec5", codec5->currentText());
Config::set("Preferences/Themes.skinChoice", SkinChoice->currentText());
Config::set("Preferences/Options.zoneToneChoice", zoneToneChoice->currentText());
Config::set("Preferences/Options.confirmQuit", confirmationToQuit->isChecked());
Config::set("Preferences/Options.checkedTray", checkedTray->isChecked());
Config::set("Preferences/Options.autoregister", autoregister->isChecked());
Config::set("Preferences/Options.voicemailNumber", voicemailNumber->text());
Config::set("Preferences", "Themes.skinChoice", SkinChoice->currentText());
Config::set("Preferences", "Options.zoneToneChoice",
zoneToneChoice->currentText());
Config::set("Preferences", "Options.confirmQuit",
confirmationToQuit->isChecked());
Config::set("Preferences", "Options.checkedTray", checkedTray->isChecked());
Config::set("Preferences", "Options.autoregister",autoregister->isChecked());
QMessageBox::information(this, "Save settings",
"You must restart SFLPhone",
QMessageBox::Yes);
accept();
}
// Handle tab view according to current item of listbox
......
/****************************************************************************
** Form implementation generated from reading ui file 'configurationpanel.ui'
**
** Created: Thu Jan 6 16:49:19 2005
** Created: Mon Jan 10 17:49:58 2005
** by: The User Interface Compiler ($Id$)
**
** WARNING! All changes made in this file will be lost!
......
/****************************************************************************
** Form interface generated from reading ui file 'configurationpanel.ui'
**
** Created: Thu Jan 6 16:49:19 2005
** Created: Mon Jan 10 17:49:57 2005
** by: The User Interface Compiler ($Id$)
**
** WARNING! All changes made in this file will be lost!
......
//
// (c) 2004 Jerome Oufella <jerome.oufella@savoirfairelinux.com>
// (c) 2004 Savoir-faire Linux inc.
// Author: Jerome Oufella <jerome.oufella@savoirfairelinux.com>
//
//
#include <iostream>
#include <fstream>
#include <string>
#include "configitem.h"
#include "configurationtree.h"
......@@ -19,7 +19,7 @@ ConfigurationTree::ConfigurationTree (void) {
// Construct with file name, and load from this file
ConfigurationTree::ConfigurationTree (const char *fileName) {
createFromFile (fileName);
populateFromFile (fileName);
}
// Destructor
......@@ -31,8 +31,9 @@ ConfigurationTree::~ConfigurationTree (void) {
// Create the tree from an existing ini file
int
ConfigurationTree::createFromFile (const char *fileName) {
ConfigurationTree::populateFromFile (const char *fileName) {
if (fileName == NULL) {
printf("filename est NULL\n");
return 0;
}
......@@ -43,32 +44,34 @@ ConfigurationTree::createFromFile (const char *fileName) {
cout << "Error opening file";
return 0;
}
char line[128];
bzero (line, 128);
const char* section;
const char* section = NULL;
const char* key;
const char* val;
String s;
while (!file.eof()) {
// Read the file line by line
file.getline (line, 128 - 1);
String* str = new String(line);
if (*str[0] == '[') {
// If the line is a section
section = (str->token("]", 1)).data();
if (section != NULL) {
_head->setValue(section);
}
} else if (*str != NULL){
s = str->token("[",1);
s.trim("]");
section = s.data();
} else if (*str != NULL) {
// If the line is "key=value"
key = (str->token("=", 0)).data();
val = (str->token("=", String(key).length() + 2)).data();
if (key != NULL and val != NULL) {
String k = str->token("=", 0);
key = k.data();
String v = str->token("=", 0);
val = v.data();
if (String(key).length() > 0 and String(val).length() > 0) {
setValue(section, key, val);
}
}
}
delete str;
}
......@@ -98,6 +101,19 @@ ConfigurationTree::saveToFile (const char *fileName) {
return 1;
}
// set [section]/key to int value
#define TMPBUFSIZE 32
int
ConfigurationTree::setValue (const char *section, const char