diff --git a/src/CDataFile.cpp b/src/CDataFile.cpp deleted file mode 100644 index e5946e73b4bdcfba76e64a9a1f4ed14cdae07411..0000000000000000000000000000000000000000 --- a/src/CDataFile.cpp +++ /dev/null @@ -1,823 +0,0 @@ -// -// CDataFile Class Implementation -// -// The purpose of this class is to provide a simple, full featured means to -// store persistent data to a text file. It uses a simple key/value paradigm -// to achieve this. The class can read/write to standard Windows .ini files, -// and yet does not rely on any windows specific calls. It should work as -// well in a linux environment (with some minor adjustments) as it does in -// a Windows one. -// -// Written July, 2002 by Gary McNickle <gary#sunstorm.net> -// If you use this class in your application, credit would be appreciated. -// - -// -// CDataFile -// The purpose of this class is to provide the means to easily store key/value -// pairs in a config file, seperated by independant sections. Sections may not -// have duplicate keys, although two or more sections can have the same key. -// Simple support for comments is included. Each key, and each section may have -// it's own multiline comment. -// -// An example might look like this; -// -// [UserSettings] -// Name=Joe User -// Date of Birth=12/25/01 -// -// ; -// ; Settings unique to this server -// ; -// [ServerSettings] -// Port=1200 -// IP_Address=127.0.0.1 -// MachineName=ADMIN -// - -#include <vector> -#include <string> -#include <ctype.h> -#include <stdio.h> -#include <stdarg.h> -#include <fstream.h> -#include <float.h> - -#include <iostream.h> - -#ifdef WIN32 -#include <windows.h> -#endif - -#include "CDataFile.h" - -// Compatibility Defines //////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////// -#ifdef WIN32 - #define snprintf _snprintf - #define vsnprintf _vsnprintf -#endif - - -// CDataFile -// Our default contstructor. If it can load the file, it will do so and populate -// the section list with the values from the file. -CDataFile::CDataFile(t_Str szFileName) -{ - m_bDirty = false; - m_szFileName = szFileName; - m_Flags = (AUTOCREATE_SECTIONS | AUTOCREATE_KEYS); - m_Sections.push_back( *(new t_Section) ); - - Load(m_szFileName); -} - -CDataFile::CDataFile() -{ - Clear(); - m_Flags = (AUTOCREATE_SECTIONS | AUTOCREATE_KEYS); - m_Sections.push_back( *(new t_Section) ); -} - -// ~CDataFile -// Saves the file if any values have changed since the last save. -CDataFile::~CDataFile() -{ - if ( m_bDirty ) - Save(); -} - -// Clear -// Resets the member variables to their defaults -void CDataFile::Clear() -{ - m_bDirty = false; - m_szFileName = t_Str(""); - m_Sections.clear(); -} - -// SetFileName -// Set's the m_szFileName member variable. For use when creating the CDataFile -// object by hand (-vs- loading it from a file -void CDataFile::SetFileName(t_Str szFileName) -{ - if (m_szFileName.size() != 0 && CompareNoCase(szFileName, m_szFileName) != 0) - { - m_bDirty = true; - - Report(E_WARN, "[CDataFile::SetFileName] The filename has changed from <%s> to <%s>.", - m_szFileName.c_str(), szFileName.c_str()); - } - - m_szFileName = szFileName; -} - -// Load -// Attempts to load in the text file. If successful it will populate the -// Section list with the key/value pairs found in the file. Note that comments -// are saved so that they can be rewritten to the file later. -bool CDataFile::Load(t_Str szFileName) -{ - // We dont want to create a new file here. If it doesn't exist, just - // return false and report the failure. - fstream File(szFileName.c_str(), ios::in /* | ios::nocreate */ ); - - if ( File.is_open() ) - { - bool bDone = false; - bool bAutoKey = (m_Flags & AUTOCREATE_KEYS) == AUTOCREATE_KEYS; - bool bAutoSec = (m_Flags & AUTOCREATE_SECTIONS) == AUTOCREATE_SECTIONS; - - t_Str szLine; - t_Str szComment; - char buffer[MAX_BUFFER_LEN]; - t_Section* pSection = GetSection(""); - - // These need to be set, we'll restore the original values later. - m_Flags |= AUTOCREATE_KEYS; - m_Flags |= AUTOCREATE_SECTIONS; - - while ( !bDone ) - { - memset(buffer, 0, MAX_BUFFER_LEN); - File.getline(buffer, MAX_BUFFER_LEN); - - szLine = buffer; - Trim(szLine); - - bDone = ( File.eof() || File.bad() || File.fail() ); - - if ( szLine.find_first_of(CommentIndicators) == 0 ) - { - szComment += "\n"; - szComment += szLine; - } - else - if ( szLine.find_first_of('[') == 0 ) // new section - { - szLine.erase( 0, 1 ); - szLine.erase( szLine.find_last_of(']'), 1 ); - - CreateSection(szLine, szComment); - pSection = GetSection(szLine); - szComment = t_Str(""); - } - else - if ( szLine.size() > 0 ) // we have a key, add this key/value pair - { - t_Str szKey = GetNextWord(szLine); - t_Str szValue = szLine; - - if ( szKey.size() > 0 && szValue.size() > 0 ) - { - SetValue(szKey, szValue, szComment, pSection->szName); - szComment = t_Str(""); - } - } - } - - // Restore the original flag values. - if ( !bAutoKey ) - m_Flags &= ~AUTOCREATE_KEYS; - - if ( !bAutoSec ) - m_Flags &= ~AUTOCREATE_SECTIONS; - } - else - { - Report(E_INFO, "[CDataFile::Load] Unable to open file. Does it exist?"); - return false; - } - - File.close(); - - return true; -} - - -// Save -// Attempts to save the Section list and keys to the file. Note that if Load -// was never called (the CDataFile object was created manually), then you -// must set the m_szFileName variable before calling save. -bool CDataFile::Save() -{ - if ( KeyCount() == 0 && SectionCount() == 0 ) - { - // no point in saving - Report(E_INFO, "[CDataFile::Save] Nothing to save."); - return false; - } - - if ( m_szFileName.size() == 0 ) - { - Report(E_ERROR, "[CDataFile::Save] No filename has been set."); - return false; - } - - fstream File(m_szFileName.c_str(), ios::out|ios::trunc); - - if ( File.is_open() ) - { - SectionItor s_pos; - KeyItor k_pos; - t_Section Section; - t_Key Key; - - for (s_pos = m_Sections.begin(); s_pos != m_Sections.end(); s_pos++) - { - Section = (*s_pos); - bool bWroteComment = false; - - if ( Section.szComment.size() > 0 ) - { - bWroteComment = true; - WriteLn(File, "\n%s", CommentStr(Section.szComment).c_str()); - } - - if ( Section.szName.size() > 0 ) - { - WriteLn(File, "%s[%s]", - bWroteComment ? "" : "\n", - Section.szName.c_str()); - } - - for (k_pos = Section.Keys.begin(); k_pos != Section.Keys.end(); k_pos++) - { - Key = (*k_pos); - - if ( Key.szKey.size() > 0 && Key.szValue.size() > 0 ) - { - WriteLn(File, "%s%s%s%s%c%s", - Key.szComment.size() > 0 ? "\n" : "", - CommentStr(Key.szComment).c_str(), - Key.szComment.size() > 0 ? "\n" : "", - Key.szKey.c_str(), - EqualIndicators[0], - Key.szValue.c_str()); - } - } - } - - } - else - { - Report(E_ERROR, "[CDataFile::Save] Unable to save file."); - return false; - } - - m_bDirty = false; - - File.flush(); - File.close(); - - return true; -} - -// SetKeyComment -// Set the comment of a given key. Returns true if the key is not found. -bool CDataFile::SetKeyComment(t_Str szKey, t_Str szComment, t_Str szSection) -{ - KeyItor k_pos; - t_Section* pSection; - - if ( (pSection = GetSection(szSection)) == NULL ) - return false; - - for (k_pos = pSection->Keys.begin(); k_pos != pSection->Keys.end(); k_pos++) - { - if ( CompareNoCase( (*k_pos).szKey, szKey ) == 0 ) - { - (*k_pos).szComment = szComment; - m_bDirty = true; - return true; - } - } - - return false; - -} - -// SetSectionComment -// Set the comment for a given section. Returns false if the section -// was not found. -bool CDataFile::SetSectionComment(t_Str szSection, t_Str szComment) -{ - SectionItor s_pos; - - for (s_pos = m_Sections.begin(); s_pos != m_Sections.end(); s_pos++) - { - if ( CompareNoCase( (*s_pos).szName, szSection ) == 0 ) - { - (*s_pos).szComment = szComment; - m_bDirty = true; - return true; - } - } - - return false; -} - - -// SetValue -// Given a key, a value and a section, this function will attempt to locate the -// Key within the given section, and if it finds it, change the keys value to -// the new value. If it does not locate the key, it will create a new key with -// the proper value and place it in the section requested. -bool CDataFile::SetValue(t_Str szKey, t_Str szValue, t_Str szComment, t_Str szSection) -{ - t_Key* pKey = GetKey(szKey, szSection); - t_Section* pSection = GetSection(szSection); - - if (pSection == NULL) - { - if ( !(m_Flags & AUTOCREATE_SECTIONS) || !CreateSection(szSection,"")) - return false; - - pSection = GetSection(szSection); - } - - // Sanity check... - if ( pSection == NULL ) - return false; - - // if the key does not exist in that section, and the value passed - // is not t_Str("") then add the new key. - if ( pKey == NULL && szValue.size() > 0 && (m_Flags & AUTOCREATE_KEYS)) - { - pKey = new t_Key; - - pKey->szKey = szKey; - pKey->szValue = szValue; - pKey->szComment = szComment; - - m_bDirty = true; - - pSection->Keys.push_back(*pKey); - - return true; - } - - if ( pKey != NULL ) - { - pKey->szValue = szValue; - pKey->szComment = szComment; - - m_bDirty = true; - - return true; - } - - return false; -} - -// SetFloat -// Passes the given float to SetValue as a string -bool CDataFile::SetFloat(t_Str szKey, float fValue, t_Str szComment, t_Str szSection) -{ - char szStr[64]; - - snprintf(szStr, 64, "%f", fValue); - - return SetValue(szKey, szStr, szComment, szSection); -} - -// SetInt -// Passes the given int to SetValue as a string -bool CDataFile::SetInt(t_Str szKey, int nValue, t_Str szComment, t_Str szSection) -{ - char szStr[64]; - - snprintf(szStr, 64, "%d", nValue); - - return SetValue(szKey, szStr, szComment, szSection); - -} - -// SetBool -// Passes the given bool to SetValue as a string -bool CDataFile::SetBool(t_Str szKey, bool bValue, t_Str szComment, t_Str szSection) -{ - t_Str szValue = bValue ? "True" : "False"; - - return SetValue(szKey, szValue, szComment, szSection); -} - -// GetValue -// Returns the key value as a t_Str object. A return value of -// t_Str("") indicates that the key could not be found. -t_Str CDataFile::GetValue(t_Str szKey, t_Str szSection) -{ - t_Key* pKey = GetKey(szKey, szSection); - - return (pKey == NULL) ? t_Str("") : pKey->szValue; -} - -// GetString -// Returns the key value as a t_Str object. A return value of -// t_Str("") indicates that the key could not be found. -t_Str CDataFile::GetString(t_Str szKey, t_Str szSection) -{ - return GetValue(szKey, szSection); -} - -// GetFloat -// Returns the key value as a float type. Returns FLT_MIN if the key is -// not found. -float CDataFile::GetFloat(t_Str szKey, t_Str szSection) -{ - t_Str szValue = GetValue(szKey, szSection); - - if ( szValue.size() == 0 ) - return FLT_MIN; - - return (float)atof( szValue.c_str() ); -} - -// GetInt -// Returns the key value as an integer type. Returns INT_MIN if the key is -// not found. -int CDataFile::GetInt(t_Str szKey, t_Str szSection) -{ - t_Str szValue = GetValue(szKey, szSection); - - if ( szValue.size() == 0 ) - return INT_MIN; - - return atoi( szValue.c_str() ); -} - -// GetBool -// Returns the key value as a bool type. Returns false if the key is -// not found. -bool CDataFile::GetBool(t_Str szKey, t_Str szSection) -{ - bool bValue = false; - t_Str szValue = GetValue(szKey, szSection); - - if ( szValue.find("1") == 0 - || CompareNoCase(szValue, "true") - || CompareNoCase(szValue, "yes") ) - { - bValue = true; - } - - return bValue; -} - -// DeleteSection -// Delete a specific section. Returns false if the section cannot be -// found or true when sucessfully deleted. -bool CDataFile::DeleteSection(t_Str szSection) -{ - SectionItor s_pos; - - for (s_pos = m_Sections.begin(); s_pos != m_Sections.end(); s_pos++) - { - if ( CompareNoCase( (*s_pos).szName, szSection ) == 0 ) - { - m_Sections.erase(s_pos); - return true; - } - } - - return false; -} - -// DeleteKey -// Delete a specific key in a specific section. Returns false if the key -// cannot be found or true when sucessfully deleted. -bool CDataFile::DeleteKey(t_Str szKey, t_Str szFromSection) -{ - KeyItor k_pos; - t_Section* pSection; - - if ( (pSection = GetSection(szFromSection)) == NULL ) - return false; - - for (k_pos = pSection->Keys.begin(); k_pos != pSection->Keys.end(); k_pos++) - { - if ( CompareNoCase( (*k_pos).szKey, szKey ) == 0 ) - { - pSection->Keys.erase(k_pos); - return true; - } - } - - return false; -} - -// CreateKey -// Given a key, a value and a section, this function will attempt to locate the -// Key within the given section, and if it finds it, change the keys value to -// the new value. If it does not locate the key, it will create a new key with -// the proper value and place it in the section requested. -bool CDataFile::CreateKey(t_Str szKey, t_Str szValue, t_Str szComment, t_Str szSection) -{ - bool bAutoKey = (m_Flags & AUTOCREATE_KEYS) == AUTOCREATE_KEYS; - bool bReturn = false; - - m_Flags |= AUTOCREATE_KEYS; - - bReturn = SetValue(szKey, szValue, szComment, szSection); - - if ( !bAutoKey ) - m_Flags &= ~AUTOCREATE_KEYS; - - return bReturn; -} - - -// CreateSection -// Given a section name, this function first checks to see if the given section -// allready exists in the list or not, if not, it creates the new section and -// assigns it the comment given in szComment. The function returns true if -// sucessfully created, or false otherwise. -bool CDataFile::CreateSection(t_Str szSection, t_Str szComment) -{ - t_Section* pSection = GetSection(szSection); - - if ( pSection ) - { - Report(E_INFO, "[CDataFile::CreateSection] Section <%s> allready exists. Aborting.", szSection.c_str()); - return false; - } - - pSection = new t_Section; - - pSection->szName = szSection; - pSection->szComment = szComment; - m_Sections.push_back(*pSection); - m_bDirty = true; - - return true; -} - -// CreateSection -// Given a section name, this function first checks to see if the given section -// allready exists in the list or not, if not, it creates the new section and -// assigns it the comment given in szComment. The function returns true if -// sucessfully created, or false otherwise. This version accpets a KeyList -// and sets up the newly created Section with the keys in the list. -bool CDataFile::CreateSection(t_Str szSection, t_Str szComment, KeyList Keys) -{ - if ( !CreateSection(szSection, szComment) ) - return false; - - t_Section* pSection = GetSection(szSection); - - if ( !pSection ) - return false; - - KeyItor k_pos; - - pSection->szName = szSection; - for (k_pos = Keys.begin(); k_pos != Keys.end(); k_pos++) - { - t_Key* pKey = new t_Key; - pKey->szComment = (*k_pos).szComment; - pKey->szKey = (*k_pos).szKey; - pKey->szValue = (*k_pos).szValue; - - pSection->Keys.push_back(*pKey); - } - - m_Sections.push_back(*pSection); - m_bDirty = true; - - return true; -} - -// SectionCount -// Simply returns the number of sections in the list. -int CDataFile::SectionCount() -{ - return m_Sections.size(); -} - -// KeyCount -// Returns the total number of keys contained within all the sections. -int CDataFile::KeyCount() -{ - int nCounter = 0; - SectionItor s_pos; - - for (s_pos = m_Sections.begin(); s_pos != m_Sections.end(); s_pos++) - nCounter += (*s_pos).Keys.size(); - - return nCounter; -} - - -// Protected Member Functions /////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////// - -// GetKey -// Given a key and section name, looks up the key and if found, returns a -// pointer to that key, otherwise returns NULL. -t_Key* CDataFile::GetKey(t_Str szKey, t_Str szSection) -{ - KeyItor k_pos; - t_Section* pSection; - - // Since our default section has a name value of t_Str("") this should - // always return a valid section, wether or not it has any keys in it is - // another matter. - if ( (pSection = GetSection(szSection)) == NULL ) - return NULL; - - for (k_pos = pSection->Keys.begin(); k_pos != pSection->Keys.end(); k_pos++) - { - if ( CompareNoCase( (*k_pos).szKey, szKey ) == 0 ) - return (t_Key*)&(*k_pos); - } - - return NULL; -} - -// GetSection -// Given a section name, locates that section in the list and returns a pointer -// to it. If the section was not found, returns NULL -t_Section* CDataFile::GetSection(t_Str szSection) -{ - SectionItor s_pos; - - for (s_pos = m_Sections.begin(); s_pos != m_Sections.end(); s_pos++) - { - if ( CompareNoCase( (*s_pos).szName, szSection ) == 0 ) - return (t_Section*)&(*s_pos); - } - - return NULL; -} - - -t_Str CDataFile::CommentStr(t_Str szComment) -{ - t_Str szNewStr = t_Str(""); - - Trim(szComment); - - if ( szComment.size() == 0 ) - return szComment; - - if ( szComment.find_first_of(CommentIndicators) != 0 ) - { - szNewStr = CommentIndicators[0]; - szNewStr += " "; - } - - szNewStr += szComment; - - return szNewStr; -} - - - -// Utility Functions //////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////// - -// GetNextWord -// Given a key +delimiter+ value string, pulls the key name from the string, -// deletes the delimiter and alters the original string to contain the -// remainder. Returns the key -t_Str GetNextWord(t_Str& CommandLine) -{ - int nPos = CommandLine.find_first_of(EqualIndicators); - t_Str sWord = t_Str(""); - - if ( nPos > -1 ) - { - sWord = CommandLine.substr(0, nPos); - CommandLine.erase(0, nPos+1); - } - else - { - sWord = CommandLine; - CommandLine = t_Str(""); - } - - Trim(sWord); - return sWord; -} - - -// CompareNoCase -// it's amazing what features std::string lacks. This function simply -// does a lowercase compare against the two strings, returning 0 if they -// match. -int CompareNoCase(t_Str str1, t_Str str2) -{ -#ifdef WIN32 - return stricmp(str1.c_str(), str2.c_str()); -#else - return strcasecmp(str1.c_str(), str2.c_str()); -#endif -} - -// Trim -// Trims whitespace from both sides of a string. -void Trim(t_Str& szStr) -{ - t_Str szTrimChars = WhiteSpace; - - szTrimChars += EqualIndicators; - int nPos, rPos; - - // trim left - nPos = szStr.find_first_not_of(szTrimChars); - - if ( nPos > 0 ) - szStr.erase(0, nPos); - - // trim right and return - nPos = szStr.find_last_not_of(szTrimChars); - rPos = szStr.find_last_of(szTrimChars); - - if ( rPos > nPos && rPos > -1) - szStr.erase(rPos, szStr.size()-rPos); -} - -// WriteLn -// Writes the formatted output to the file stream, returning the number of -// bytes written. -int WriteLn(fstream& stream, char* fmt, ...) -{ - char buf[MAX_BUFFER_LEN]; - int nLength; - t_Str szMsg; - - memset(buf, 0, MAX_BUFFER_LEN); - va_list args; - - va_start (args, fmt); - nLength = vsnprintf(buf, MAX_BUFFER_LEN, fmt, args); - va_end (args); - - - if ( buf[nLength] != '\n' && buf[nLength] != '\r' ) - buf[nLength++] = '\n'; - - - stream.write(buf, nLength); - - return nLength; -} - -// Report -// A simple reporting function. Outputs the report messages to stdout -// This is a dumb'd down version of a simmilar function of mine, so if -// it looks like it should do more than it does, that's why... -void Report(e_DebugLevel DebugLevel, char *fmt, ...) -{ - char buf[MAX_BUFFER_LEN]; - int nLength; - t_Str szMsg; - - va_list args; - - memset(buf, 0, MAX_BUFFER_LEN); - - va_start (args, fmt); - nLength = vsnprintf(buf, MAX_BUFFER_LEN, fmt, args); - va_end (args); - - - if ( buf[nLength] != '\n' && buf[nLength] != '\r' ) - buf[nLength++] = '\n'; - - - switch ( DebugLevel ) - { - case E_DEBUG: - szMsg = "<debug> "; - break; - case E_INFO: - szMsg = "<info> "; - break; - case E_WARN: - szMsg = "<warn> "; - break; - case E_ERROR: - szMsg = "<error> "; - break; - case E_FATAL: - szMsg = "<fatal> "; - break; - case E_CRITICAL: - szMsg = "<critical> "; - break; - } - - - szMsg += buf; - - -#ifdef WIN32 - OutputDebugString(szMsg.c_str()); -#endif - - printf(szMsg.c_str()); - -} - -// EOF diff --git a/src/CDataFile.h b/src/CDataFile.h deleted file mode 100644 index 84f09e7be0df741942496f7565c102e134610ce6..0000000000000000000000000000000000000000 --- a/src/CDataFile.h +++ /dev/null @@ -1,274 +0,0 @@ -// -// CDataFile Class Implementation -// -// The purpose of this class is to provide a simple, full featured means to -// store persistent data to a text file. It uses a simple key/value paradigm -// to achieve this. The class can read/write to standard Windows .ini files, -// and yet does not rely on any windows specific calls. It should work as -// well in a linux environment (with some minor adjustments) as it does in -// a Windows one. -// -// Written July, 2002 by Gary McNickle <gary#sunstorm.net> -// If you use this class in your application, credit would be appreciated. -// - -#ifndef __CDATAFILE_H__ -#define __CDATAFILE_H__ - -#include <vector> -#include <fstream.h> -#include <string> - -// Globally defined structures, defines, & types -////////////////////////////////////////////////////////////////////////////////// - -// AUTOCREATE_SECTIONS -// When set, this define will cause SetValue() to create a new section, if -// the requested section does not allready exist. -#define AUTOCREATE_SECTIONS (1L<<1) - -// AUOTCREATE_KEYS -// When set, this define causes SetValue() to create a new key, if the -// requested key does not allready exist. -#define AUTOCREATE_KEYS (1L<<2) - -// MAX_BUFFER_LEN -// Used simply as a max size of some internal buffers. Determines the maximum -// length of a line that will be read from or written to the file or the -// report output. -#define MAX_BUFFER_LEN 512 - - -// eDebugLevel -// Used by our Report function to classify levels of reporting and severity -// of report. -enum e_DebugLevel -{ - // detailed programmatic informational messages used as an aid in - // troubleshooting problems by programmers - E_DEBUG = 0, - // brief informative messages to use as an aid in troubleshooting - // problems by production support and programmers - E_INFO, - // messages intended to notify help desk, production support and - // programmers of possible issues with respect to the running application - E_WARN, - // messages that detail a programmatic error, these are typically - // messages intended for help desk, production support, programmers and - // occasionally users - E_ERROR, - // severe messages that are programmatic violations that will usually - // result in application failure. These messages are intended for help - // desk, production support, programmers and possibly users - E_FATAL, - // notice that all processing should be stopped immediately after the - // log is written. - E_CRITICAL -}; - - -typedef std::string t_Str; - -// CommentIndicators -// This constant contains the characters that we check for to determine if a -// line is a comment or not. Note that the first character in this constant is -// the one used when writing comments to disk (if the comment does not allready -// contain an indicator) -const t_Str CommentIndicators = t_Str(";#"); - -// EqualIndicators -// This constant contains the characters that we check against to determine if -// a line contains an assignment ( key = value ) -// Note that changing these from their defaults ("=:") WILL affect the -// ability of CDataFile to read/write to .ini files. Also, note that the -// first character in this constant is the one that is used when writing the -// values to the file. (EqualIndicators[0]) -const t_Str EqualIndicators = t_Str("=:"); - -// WhiteSpace -// This constant contains the characters that the Trim() function removes from -// the head and tail of strings. -const t_Str WhiteSpace = t_Str(" \t\n\r"); - -// st_key -// This structure stores the definition of a key. A key is a named identifier -// that is associated with a value. It may or may not have a comment. All comments -// must PRECEDE the key on the line in the config file. -typedef struct st_key -{ - t_Str szKey; - t_Str szValue; - t_Str szComment; - - st_key() - { - szKey = t_Str(""); - szValue = t_Str(""); - szComment = t_Str(""); - } - -} t_Key; - -typedef std::vector<t_Key> KeyList; -typedef KeyList::iterator KeyItor; - -// st_section -// This structure stores the definition of a section. A section contains any number -// of keys (see st_keys), and may or may not have a comment. Like keys, all -// comments must precede the section. -typedef struct st_section -{ - t_Str szName; - t_Str szComment; - KeyList Keys; - - st_section() - { - szName = t_Str(""); - szComment = t_Str(""); - Keys.clear(); - } - -} t_Section; - -typedef std::vector<t_Section> SectionList; -typedef SectionList::iterator SectionItor; - - - -/// General Purpose Utility Functions /////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////// -void Report(e_DebugLevel DebugLevel, char *fmt, ...); -t_Str GetNextWord(t_Str& CommandLine); -int CompareNoCase(t_Str str1, t_Str str2); -void Trim(t_Str& szStr); -int WriteLn(fstream& stream, char* fmt, ...); - - -/// Class Definitions /////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////// - - -// CDataFile -class CDataFile -{ -// Methods -public: - // Constructors & Destructors - ///////////////////////////////////////////////////////////////// - CDataFile(); - CDataFile(t_Str szFileName); - virtual ~CDataFile(); - - // File handling methods - ///////////////////////////////////////////////////////////////// - bool Load(t_Str szFileName); - bool Save(); - - // Data handling methods - ///////////////////////////////////////////////////////////////// - - // GetValue: Our default access method. Returns the raw t_Str value - // Note that this returns keys specific to the given section only. - t_Str GetValue(t_Str szKey, t_Str szSection = t_Str("")); - // GetString: Returns the value as a t_Str - t_Str GetString(t_Str szKey, t_Str szSection = t_Str("")); - // GetFloat: Return the value as a float - float GetFloat(t_Str szKey, t_Str szSection = t_Str("")); - // GetInt: Return the value as an int - int GetInt(t_Str szKey, t_Str szSection = t_Str("")); - // GetBool: Return the value as a bool - bool GetBool(t_Str szKey, t_Str szSection = t_Str("")); - - // SetValue: Sets the value of a given key. Will create the - // key if it is not found and AUTOCREATE_KEYS is active. - bool SetValue(t_Str szKey, t_Str szValue, - t_Str szComment = t_Str(""), t_Str szSection = t_Str("")); - - // SetFloat: Sets the value of a given key. Will create the - // key if it is not found and AUTOCREATE_KEYS is active. - bool SetFloat(t_Str szKey, float fValue, - t_Str szComment = t_Str(""), t_Str szSection = t_Str("")); - - // SetInt: Sets the value of a given key. Will create the - // key if it is not found and AUTOCREATE_KEYS is active. - bool SetInt(t_Str szKey, int nValue, - t_Str szComment = t_Str(""), t_Str szSection = t_Str("")); - - // SetBool: Sets the value of a given key. Will create the - // key if it is not found and AUTOCREATE_KEYS is active. - bool SetBool(t_Str szKey, bool bValue, - t_Str szComment = t_Str(""), t_Str szSection = t_Str("")); - - // Sets the comment for a given key. - bool SetKeyComment(t_Str szKey, t_Str szComment, t_Str szSection = t_Str("")); - - // Sets the comment for a given section - bool SetSectionComment(t_Str szSection, t_Str szComment); - - // DeleteKey: Deletes a given key from a specific section - bool DeleteKey(t_Str szKey, t_Str szFromSection = t_Str("")); - - // DeleteSection: Deletes a given section. - bool DeleteSection(t_Str szSection); - - // Key/Section handling methods - ///////////////////////////////////////////////////////////////// - - // CreateKey: Creates a new key in the requested section. The - // Section will be created if it does not exist and the - // AUTOCREATE_SECTIONS bit is set. - bool CreateKey(t_Str szKey, t_Str szValue, - t_Str szComment = t_Str(""), t_Str szSection = t_Str("")); - // CreateSection: Creates the new section if it does not allready - // exist. Section is created with no keys. - bool CreateSection(t_Str szSection, t_Str szComment = t_Str("")); - // CreateSection: Creates the new section if it does not allready - // exist, and copies the keys passed into it into the new section. - bool CreateSection(t_Str szSection, t_Str szComment, KeyList Keys); - - // Utility Methods - ///////////////////////////////////////////////////////////////// - // SectionCount: Returns the number of valid sections in the database. - int SectionCount(); - // KeyCount: Returns the total number of keys, across all sections. - int KeyCount(); - // Clear: Initializes the member variables to their default states - void Clear(); - // SetFileName: For use when creating the object by hand - // initializes the file name so that it can be later saved. - void SetFileName(t_Str szFileName); - // CommentStr - // Parses a string into a proper comment token/comment. - t_Str CommentStr(t_Str szComment); - - -protected: - // Note: I've tried to insulate the end user from the internal - // data structures as much as possible. This is by design. Doing - // so has caused some performance issues (multiple calls to a - // GetSection() function that would otherwise not be necessary,etc). - // But, I believe that doing so will provide a safer, more stable - // environment. You'll notice that nothing returns a reference, - // to modify the data values, you have to call member functions. - // think carefully before changing this. - - // GetKey: Returns the requested key (if found) from the requested - // Section. Returns NULL otherwise. - t_Key* GetKey(t_Str szKey, t_Str szSection); - // GetSection: Returns the requested section (if found), NULL otherwise. - t_Section* GetSection(t_Str szSection); - - -// Data -public: - long m_Flags; // Our settings flags. - -protected: - SectionList m_Sections; // Our list of sections - t_Str m_szFileName; // The filename to write to - bool m_bDirty; // Tracks whether or not data has changed. -}; - - -#endif diff --git a/src/Makefile b/src/Makefile index 6ca501035bd8d7c04b1cc517c79fea13fbc61f3f..b60a385ae894a4ceec8ee318cb4b18bc3c8c4c8b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -32,7 +32,6 @@ OBJS = \ audiodrivers.o \ audiodriversoss.o \ audiortp.o \ - CDataFile.o \ configuration.o \ configitem.o \ configurationtree.o \ @@ -44,6 +43,7 @@ OBJS = \ mydisplay.o \ numerickeypadtools.o \ phoneline.o \ + point.o \ qjlistboxpixmap.o \ sip.o \ sipcall.o \ diff --git a/src/audiocodec.cpp b/src/audiocodec.cpp index 4764e83ab28b8fcd2fa68a969fc833ad05beb808..118dc4247324a983c5888907f7d54d579a321cd7 100644 --- a/src/audiocodec.cpp +++ b/src/audiocodec.cpp @@ -39,7 +39,7 @@ AudioCodec::~AudioCodec (void) { } int -AudioCodec::matchPayloadCodec (std::string codecname) { +AudioCodec::matchPayloadCodec (string codecname) { if (codecname == CODEC_ALAW) { return PAYLOAD_CODEC_ALAW; } else if (codecname == CODEC_ULAW) { diff --git a/src/audiocodec.h b/src/audiocodec.h index 79ddb18b26a15abaa8de3641cc5c391a69691527..815dfab68d639e208585a345d1b5e1ab03195a8e 100644 --- a/src/audiocodec.h +++ b/src/audiocodec.h @@ -20,7 +20,7 @@ #ifndef __CODEC_AUDIO_H__ #define __CODEC_AUDIO_H__ -#include <string.h> +#include <string> using namespace std; typedef enum { @@ -31,11 +31,11 @@ typedef enum { PAYLOAD_CODEC_SPEEX = 110 } codecType; -#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 CODEC_ALAW string("G711a") +#define CODEC_ULAW string("G711u") +#define CODEC_GSM string("GSM") +#define CODEC_ILBC string("iLBC") +#define CODEC_SPEEX string("SPEEX") #define NB_CODECS 5 @@ -49,7 +49,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 (std::string); + int matchPayloadCodec (string); char * rtpmapPayload (int); private: diff --git a/src/audiortp.cpp b/src/audiortp.cpp index a07487d6ecf12b6d4a3abfe004539ffc4649c182..0e07c8b9866d2809c1937591060307c2e9b0e720 100644 --- a/src/audiortp.cpp +++ b/src/audiortp.cpp @@ -69,7 +69,6 @@ AudioRtp::createNewSession (SipCall *ca) { } RTXThread = new AudioRtpRTX (ca, manager->audiodriver, manager, symetric); - qDebug("-- START SOUND --"); if (RTXThread->start() != 0) { return -1; } @@ -86,6 +85,7 @@ AudioRtp::closeRtpSession (SipCall *ca) { if (RTXThread != NULL) { // Wait for them...and delete. //RTXThread->join(); + qDebug("DELETED"); delete RTXThread; RTXThread = NULL; } diff --git a/src/configurationpanelui.cpp b/src/configurationpanelui.cpp index 7f54afff74b766faca53b826045454c74fe64a51..a27f2add39029ebeb0fa2f4a99787fb1cb36ac57 100644 --- a/src/configurationpanelui.cpp +++ b/src/configurationpanelui.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** Form implementation generated from reading ui file 'configurationpanel.ui' ** -** Created: Mon Jan 24 17:46:09 2005 +** Created: Wed Jan 26 14:28:43 2005 ** by: The User Interface Compiler ($Id$) ** ** WARNING! All changes made in this file will be lost! diff --git a/src/configurationpanelui.h b/src/configurationpanelui.h index df69df351d361f624c05fc970f830351a11cbd23..2f71ee25c8ed6af1c642cc93865c0233464a70b2 100644 --- a/src/configurationpanelui.h +++ b/src/configurationpanelui.h @@ -1,7 +1,7 @@ /**************************************************************************** ** Form interface generated from reading ui file 'configurationpanel.ui' ** -** Created: Mon Jan 24 17:46:09 2005 +** Created: Wed Jan 26 14:28:43 2005 ** by: The User Interface Compiler ($Id$) ** ** WARNING! All changes made in this file will be lost! diff --git a/src/configurationtree.cpp b/src/configurationtree.cpp index 722e76cc2cd1dadafde8211dd241c766bc9d1a8e..91ff2c10cd902d6edb3f4a81515656f7a109c467 100644 --- a/src/configurationtree.cpp +++ b/src/configurationtree.cpp @@ -63,8 +63,8 @@ ConfigurationTree::populateFromFile (const char *fileName) { s.trim("]"); section = s.data(); - } else if (*str != NULL) { - // If the line is "key=value" + } else if (*str != NULL and *str[0] != '#') { + // If the line is "key=value" and doesn't begin with '#'(comments) String k = str->token("=", 0); key = k.data(); String v = str->token("=", 0); diff --git a/src/mydisplay.h b/src/mydisplay.h index 4bcf8afaa5c0e575453976aa5c7ca69cd22502af..f7d3430f220700a86dadd67f38b3e8b5fd2002da 100644 --- a/src/mydisplay.h +++ b/src/mydisplay.h @@ -27,7 +27,6 @@ #include <qthread.h> #include <qwidget.h> -#include "CDataFile.h" #include "global.h" #define FREE_STATUS QObject::tr("Welcome to SFLPhone") @@ -83,8 +82,6 @@ private: MyDisplayThread *animationThread; QtGUIMainWindow *qtgui; - CDataFile ExistingDF; // Configuration file - void initGraphics (void); void initText (void); void renderText (QPainter &, QFontMetrics &, QString &); diff --git a/src/numerickeypad.cpp b/src/numerickeypad.cpp index 3081b3e80f03cd196f545d141a657ef215ef2665..c98ce62a2cf9432490d2a9c836ce793ce84e53de 100644 --- a/src/numerickeypad.cpp +++ b/src/numerickeypad.cpp @@ -19,7 +19,6 @@ #include <qapplication.h> -#include "CDataFile.h" #include "jpushbutton.h" #include "numerickeypad.h" #include "qtGUImainwindow.h" @@ -44,12 +43,10 @@ NumericKeypad::NumericKeypad (QWidget *parent, const char *name, WFlags f) // Calculate just one time the transparency mask bit to bit transparencyMask (); - CDataFile ExistingDF; QString skinfilename(Skin::getPath(QString(SKINDIR), QtGUIMainWindow::setPathSkin(), QString(FILE_INI))); - ExistingDF.SetFileName(skinfilename); - ExistingDF.Load(skinfilename); + pt = new Point(skinfilename); // Buttons initialisation key0 = new JPushButton(this, NULL, DTMF_0); @@ -67,32 +64,19 @@ NumericKeypad::NumericKeypad (QWidget *parent, const char *name, WFlags f) keyClose = new JPushButton(this, NULL, DTMF_CLOSE); // Buttons position - key0->move (ExistingDF.GetInt("dtmf_0_x","Positions"), - ExistingDF.GetInt("dtmf_0_y","Positions")); - key1->move (ExistingDF.GetInt("dtmf_1_x","Positions"), - ExistingDF.GetInt("dtmf_1_y","Positions")); - key2->move (ExistingDF.GetInt("dtmf_2_x","Positions"), - ExistingDF.GetInt("dtmf_2_y","Positions")); - key3->move (ExistingDF.GetInt("dtmf_3_x","Positions"), - ExistingDF.GetInt("dtmf_3_y","Positions")); - key4->move (ExistingDF.GetInt("dtmf_4_x","Positions"), - ExistingDF.GetInt("dtmf_4_y","Positions")); - key5->move (ExistingDF.GetInt("dtmf_5_x","Positions"), - ExistingDF.GetInt("dtmf_5_y","Positions")); - key6->move (ExistingDF.GetInt("dtmf_6_x","Positions"), - ExistingDF.GetInt("dtmf_6_y","Positions")); - key7->move (ExistingDF.GetInt("dtmf_7_x","Positions"), - ExistingDF.GetInt("dtmf_7_y","Positions")); - key8->move (ExistingDF.GetInt("dtmf_8_x","Positions"), - ExistingDF.GetInt("dtmf_8_y","Positions")); - key9->move (ExistingDF.GetInt("dtmf_9_x","Positions"), - ExistingDF.GetInt("dtmf_9_y","Positions")); - keyStar->move (ExistingDF.GetInt("dtmf_star_x","Positions"), - ExistingDF.GetInt("dtmf_star_y","Positions")); - keyHash->move (ExistingDF.GetInt("dtmf_pound_x","Positions"), - ExistingDF.GetInt("dtmf_pound_y","Positions")); - keyClose->move (ExistingDF.GetInt("dtmf_close_x","Positions"), - ExistingDF.GetInt("dtmf_close_y","Positions")); + key0->move (pt->getX(DTMF_0), pt->getY(DTMF_0)); + key1->move (pt->getX(DTMF_1), pt->getY(DTMF_1)); + key2->move (pt->getX(DTMF_2), pt->getY(DTMF_2)); + key3->move (pt->getX(DTMF_3), pt->getY(DTMF_3)); + key4->move (pt->getX(DTMF_4), pt->getY(DTMF_4)); + key5->move (pt->getX(DTMF_5), pt->getY(DTMF_5)); + key6->move (pt->getX(DTMF_6), pt->getY(DTMF_6)); + key7->move (pt->getX(DTMF_7), pt->getY(DTMF_7)); + key8->move (pt->getX(DTMF_8), pt->getY(DTMF_8)); + key9->move (pt->getX(DTMF_9), pt->getY(DTMF_9)); + keyStar->move (pt->getX(DTMF_STAR), pt->getY(DTMF_STAR)); + keyHash->move (pt->getX(DTMF_POUND), pt->getY(DTMF_POUND)); + keyClose->move (pt->getX(DTMF_CLOSE), pt->getY(DTMF_CLOSE)); } NumericKeypad::~NumericKeypad (void) { @@ -109,6 +93,7 @@ NumericKeypad::~NumericKeypad (void) { delete keyStar; delete keyHash; delete keyClose; + delete pt; } void diff --git a/src/numerickeypad.h b/src/numerickeypad.h index 455301c8b8b94aee0400d4bf2f60b85a46fca66a..9b4c083b074aa8b8b74666997a6d65d312e6dd78 100644 --- a/src/numerickeypad.h +++ b/src/numerickeypad.h @@ -21,6 +21,7 @@ #define __NUMERIC_KEYPAD_H__ #include "jpushbutton.h" +#include "point.h" #include "transqwidget.h" class NumericKeypad : public TransQWidget { @@ -30,7 +31,6 @@ public: NumericKeypad (QWidget* = 0, const char* = 0,WFlags = 0); ~NumericKeypad (void); - JPushButton *key0; JPushButton *key1; JPushButton *key2; @@ -46,7 +46,7 @@ public: JPushButton *keyClose; private: -// QPoint position; + Point *pt; TransQWidget* mainWindow; void keyPressEvent (QKeyEvent*); }; diff --git a/src/phonebookui.cpp b/src/phonebookui.cpp index 3eeff6ebfdb7f23bbb4cda4ef9df16860a9fecba..7c633679a58b0ea960bf3ec6c7cf7ecf58001d74 100644 --- a/src/phonebookui.cpp +++ b/src/phonebookui.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** Form implementation generated from reading ui file 'phonebook.ui' ** -** Created: Mon Jan 24 17:46:08 2005 +** Created: Wed Jan 26 14:28:43 2005 ** by: The User Interface Compiler ($Id$) ** ** WARNING! All changes made in this file will be lost! diff --git a/src/phonebookui.h b/src/phonebookui.h index 301cdadd499f8bb4316e181f71ff532c50bf8821..ef1712d02ce9b2adc88e43514fcc5f10264995ec 100644 --- a/src/phonebookui.h +++ b/src/phonebookui.h @@ -1,7 +1,7 @@ /**************************************************************************** ** Form interface generated from reading ui file 'phonebook.ui' ** -** Created: Mon Jan 24 17:46:08 2005 +** Created: Wed Jan 26 14:28:43 2005 ** by: The User Interface Compiler ($Id$) ** ** WARNING! All changes made in this file will be lost! diff --git a/src/point.cpp b/src/point.cpp new file mode 100644 index 0000000000000000000000000000000000000000..12f0d0008b0cf321943d76cbbb8ea067d4a22bf5 --- /dev/null +++ b/src/point.cpp @@ -0,0 +1,79 @@ +/** + * Copyright (C) 2004-2005 Savoir-Faire Linux inc. + * Author: Laurielle Lea <laurielle.lea@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 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., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "configurationtree.h" +#include "point.h" + +#include <string> +using namespace std; + +/** + * Create a config-tree from file 'filename' + */ +Point::Point (const char* filename) { + skinConfigTree = new ConfigurationTree(); + skinConfigTree->populateFromFile (filename); +} + +Point::~Point (void) { + delete skinConfigTree; +} + +/** + * Return the x-value of 'key' + */ +int +Point::getX (const char* key) { + char * value = skinConfigTree->getValue(NULL, key); + string tmp(value); + int index = tmp.find(','); + int toto = atoi((tmp.substr(0, index)).data()); + return toto; +} + +/** + * Return the y-value of 'key' + */ +int +Point::getY (const char* key) { + char * value = skinConfigTree->getValue(NULL, key); + string tmp(value); + int index1, index2; + + index1 = tmp.find(','); + if (tmp.find('-') == string::npos) { + // If string tmp doesn't contain '-' + return atoi((tmp.substr(index1 + 1, tmp.length() - index1)).data()); + } else { + // If string tmp contains '-', it looks like 'y-variation' + index2 = tmp.find('-'); + return atoi((tmp.substr(index1 + 1, index2 - index1)).data()); + } +} + +/** + * Return the variation-value of 'key' (for volume) + */ +int +Point::getVariation (const char* key) { + char * value = skinConfigTree->getValue(NULL, key); + string tmp(value); + int index = tmp.find('-'); + return atoi((tmp.substr(index + 1, tmp.length() - index)).data()); +} diff --git a/src/point.h b/src/point.h new file mode 100644 index 0000000000000000000000000000000000000000..2b0a21030954de84f6bd28fb208d6f256502e080 --- /dev/null +++ b/src/point.h @@ -0,0 +1,38 @@ +/** + * Copyright (C) 2004-2005 Savoir-Faire Linux inc. + * Author: Laurielle Lea <laurielle.lea@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 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., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#ifndef __POINT_H__ +#define __POINT_H__ + +class ConfigurationTree; + +class Point { +public: + Point (const char*); + ~Point (void); + + int getX (const char*); + int getY (const char*); + int getVariation (const char*); + +private: + ConfigurationTree* skinConfigTree; +}; + +#endif // __POINT_H__ diff --git a/src/qtGUImainwindow.cpp b/src/qtGUImainwindow.cpp index 8806ff414b007253cfd516d8dd30ca7e2b14a333..b02fdeb83fa8098c34adb8fb5c9d471bbc3aae56 100644 --- a/src/qtGUImainwindow.cpp +++ b/src/qtGUImainwindow.cpp @@ -46,6 +46,7 @@ #include "jpushbutton.h" #include "manager.h" #include "numerickeypadtools.h" +#include "point.h" #include "skin.h" #include "qtGUImainwindow.h" @@ -115,8 +116,7 @@ QtGUIMainWindow::QtGUIMainWindow (QWidget *parent, const char *name, WFlags f, // Load file configuration skin QString skinfilename(Skin::getPath(QString(SKINDIR), setPathSkin(), QString(FILE_INI))); - ExistingDF.SetFileName(skinfilename); - ExistingDF.Load(skinfilename); + this->pt = new Point(skinfilename.ascii()); // Initialisations this->initButtons(); @@ -343,17 +343,17 @@ QtGUIMainWindow::setPathSkin (void) { void QtGUIMainWindow::initButtons (void) { // Buttons initialisation - phoneKey_msg= new JPushButton(this, NULL, "voicemail"); - phoneKey_transf = new JPushButton(this, NULL, "transfer"); - phoneKey_conf = new JPushButton(this, NULL, "conference"); - reduce_button = new JPushButton(this, NULL, "minimize"); - quit_button = new JPushButton(this, NULL, "close"); - addr_book_button = new JPushButton(this, NULL, "directory"); - configuration_button = new JPushButton(this, NULL, "setup"); - hangup_button = new JPushButton(this, NULL, "hangup"); - dial_button = new JPushButton(this, NULL, "ok"); - mute_button = new JPushButton(this, NULL, "mute"); - dtmf_button = new JPushButton(this, NULL, "dtmf"); + phoneKey_msg= new JPushButton(this, NULL, VOICEMAIL); + phoneKey_transf = new JPushButton(this, NULL, TRANSFER); + phoneKey_conf = new JPushButton(this, NULL, CONFERENCE); + reduce_button = new JPushButton(this, NULL, MINIMIZE); + quit_button = new JPushButton(this, NULL, CLOSE); + addr_book_button = new JPushButton(this, NULL, DIRECTORY); + configuration_button = new JPushButton(this, NULL, SETUP); + hangup_button = new JPushButton(this, NULL, HANGUP); + dial_button = new JPushButton(this, NULL, CONNECT); + mute_button = new JPushButton(this, NULL, MUTE); + dtmf_button = new JPushButton(this, NULL, DTMF_SHOW); // Set tooltip buttons QToolTip::add(reduce_button, tr("Minimize window")); @@ -369,41 +369,18 @@ QtGUIMainWindow::initButtons (void) { QToolTip::add(dtmf_button, tr("Show DTMF keypad")); // Buttons position - phoneKey_msg->move ( - ExistingDF.GetInt("msg_x","Positions"), - ExistingDF.GetInt("msg_y","Positions")); - phoneKey_transf->move ( - ExistingDF.GetInt("transf_x","Positions"), - ExistingDF.GetInt("transf_y","Positions")); - phoneKey_conf->move ( - ExistingDF.GetInt("conf_x","Positions"), - ExistingDF.GetInt("conf_y","Positions")); - reduce_button->move ( - ExistingDF.GetInt("reduce_x","Positions"), - ExistingDF.GetInt("reduce_y","Positions")); - addr_book_button->move ( - ExistingDF.GetInt("addr_book_x","Positions"), - ExistingDF.GetInt("addr_book_y","Positions")); - quit_button->move ( - ExistingDF.GetInt("quit_x","Positions"), - ExistingDF.GetInt("quit_y","Positions")); - configuration_button->move ( - ExistingDF.GetInt("configuration_x","Positions"), - ExistingDF.GetInt("configuration_y","Positions")); - hangup_button->move ( - ExistingDF.GetInt("hangup_x","Positions"), - ExistingDF.GetInt("hangup_y","Positions")); - dial_button->move ( - ExistingDF.GetInt("dial_x","Positions"), - ExistingDF.GetInt("dial_y","Positions")); - mute_button->move ( - ExistingDF.GetInt("mute_x","Positions"), - ExistingDF.GetInt("mute_y","Positions")); - dtmf_button->move ( - ExistingDF.GetInt("dtmf_x","Positions"), - ExistingDF.GetInt("dtmf_y","Positions")); - - + phoneKey_msg->move (pt->getX(VOICEMAIL), pt->getY(VOICEMAIL)); + phoneKey_transf->move (pt->getX(TRANSFER), pt->getY(TRANSFER)); + phoneKey_conf->move (pt->getX(CONFERENCE), pt->getY(CONFERENCE)); + reduce_button->move (pt->getX(MINIMIZE), pt->getY(MINIMIZE)); + addr_book_button->move (pt->getX(DIRECTORY), pt->getY(DIRECTORY)); + quit_button->move (pt->getX(CLOSE), pt->getY(CLOSE)); + configuration_button->move (pt->getX(SETUP), pt->getY(SETUP)); + hangup_button->move (pt->getX(HANGUP), pt->getY(HANGUP)); + dial_button->move (pt->getX(CONNECT), pt->getY(CONNECT)); + mute_button->move (pt->getX(MUTE), pt->getY(MUTE)); + dtmf_button->move (pt->getX(DTMF_SHOW), pt->getY(DTMF_SHOW)); + // Loop for line buttons //Initialisation, set no focus, set geometry, set palette, pixmap for (int j = 0; j < NUMBER_OF_LINES; j++) { @@ -412,20 +389,14 @@ QtGUIMainWindow::initButtons (void) { lnum = "l" + lnum.setNum (j + 1); callmanager->phLines[j]->setButton(new JPushButton( this, NULL, lnum.ascii())); - callmanager->phLines[j]->button()->move ( - ExistingDF.GetInt(lnum + "_x","Positions"), - ExistingDF.GetInt(lnum + "_y","Positions")); + callmanager->phLines[j]->button()->move (pt->getX(lnum),pt->getY(lnum)); } // Set pixmaps volume TODO:change to thing like slider - vol_mic = new JPushButton(this, NULL, "volume"); - vol_mic->move( - ExistingDF.GetInt("vol_mic_x","Positions"), - ExistingDF.GetInt("vol_mic_y","Positions")); - vol_spkr = new JPushButton(this, NULL, "volume"); - vol_spkr->move( - ExistingDF.GetInt("vol_spkr_x","Positions"), - ExistingDF.GetInt("vol_spkr_y","Positions")); + vol_mic = new JPushButton(this, NULL, VOLUME); + vol_spkr = new JPushButton(this, NULL, VOLUME); + vol_mic->move(pt->getX(VOL_MIC), pt->getY(VOL_MIC)); + vol_spkr->move(pt->getX(VOL_SPKR), pt->getY(VOL_SPKR)); } /** @@ -502,8 +473,7 @@ QtGUIMainWindow::dialTone (bool var) { void QtGUIMainWindow::setMainLCD (void) { // Screen initialisation - this->lcd->move (ExistingDF.GetInt("display_x","Positions"), - ExistingDF.GetInt("display_y","Positions")); + this->lcd->move (pt->getX(SCREEN), pt->getY(SCREEN)); } void @@ -531,7 +501,7 @@ QtGUIMainWindow::toggleLine (int num_line) { busyNum = numLineBusy(); if (callmanager->isNotUsedLine(currentLineNumber) and busyNum == -1) { - qDebug("GUI: PREMIERE LIGNE occupee %d", currentLineNumber); + qDebug("GUI: FIRST LINE IN USED %d", currentLineNumber); lcd->setStatus("Enter Phone Number:"); chosenLine = currentLineNumber; if (!noChoose) { @@ -546,7 +516,7 @@ QtGUIMainWindow::toggleLine (int num_line) { // Occurs when newly off-hook line replaces another one. if (busyNum != currentLineNumber && busyNum != -1) { if (callmanager->isNotUsedLine(currentLineNumber)) { - qDebug("GUI: Prend nouvelle ligne %d", currentLineNumber); + qDebug("GUI: Line %d replaces another one", currentLineNumber); lcd->clear(QString("Enter Phone Number:")); chosenLine = currentLineNumber; lcd->inFunction = false; @@ -576,7 +546,7 @@ QtGUIMainWindow::toggleLine (int num_line) { // Answer new call if (callmanager->isRingingLine(currentLineNumber) and callmanager->phLines[currentLineNumber]->getStateLine() != ONHOLD){ - qDebug("GUI: -- Nouvel appel repondu %d --", currentLineNumber); + qDebug("GUI: -- New answered call %d --", currentLineNumber); callmanager->actionHandle (currentLineNumber, ANSWER_CALL); callmanager->phLines[currentLineNumber]->setState(BUSY); callmanager->phLines[currentLineNumber]->setStateLine(BUSY); diff --git a/src/qtGUImainwindow.h b/src/qtGUImainwindow.h index 56938a50291b440e052fe7293e0f54a9384a8512..e4e7bbb44f3146e9775361f21647d6d8c4e563bd 100644 --- a/src/qtGUImainwindow.h +++ b/src/qtGUImainwindow.h @@ -31,7 +31,6 @@ #include <qthread.h> #include <qwidget.h> -#include "CDataFile.h" #include "configuration.h" #include "configurationpanelui.h" #include "dtmf.h" @@ -40,6 +39,7 @@ #include "mydisplay.h" #include "numerickeypad.h" #include "phonebookui.h" +#include "point.h" #include "skin.h" #include "sip.h" #include "transqwidget.h" @@ -186,13 +186,14 @@ protected: void keyPressEvent (QKeyEvent *); private: + // Configuration skin file + Point *pt; + // To construct ring rect pixmap QImage imageRing; QImage imageNoRing; QPixmap TabMsgPixmap[NUMBER_OF_STATES]; - // Configuration file - CDataFile ExistingDF; int modeType; DTMF *key; short *buf; diff --git a/src/sip.cpp b/src/sip.cpp index 5fdfabec6f06efd04f344d0b7c642b031ce18408..722bef8e3620fa78451909f2183940d61074eab2 100644 --- a/src/sip.cpp +++ b/src/sip.cpp @@ -507,7 +507,7 @@ SIP::outgoingInvite (void) { } to = (char*)qto.data(); - qDebug ("From: <%s>", from); + qDebug ("From: %s", from); qDebug ("To: <%s>", to); // If no SIP proxy setting @@ -583,7 +583,6 @@ SIP::manageActions (int usedLine, int action) { // Get local port snprintf (tmpbuf, 63, "%d", call[usedLine]->getLocalAudioPort()); - qDebug("getLocalAudioPort = %d",call[usedLine]->getLocalAudioPort()); eXosip_lock(); i = eXosip_answer_call(call[usedLine]->did, 200, tmpbuf); @@ -602,7 +601,7 @@ SIP::manageActions (int usedLine, int action) { qDebug("CLOSE_CALL: cid = %d et did = %d", call[usedLine]->cid, call[usedLine]->did); - qDebug("JE RACCROCHE CALL 0x%d, usedline = %d", call[usedLine], usedLine); + call[usedLine]->usehold = false; // Release SIP stack. eXosip_lock(); i = eXosip_terminate_call (call[usedLine]->cid, call[usedLine]->did); @@ -624,22 +623,17 @@ SIP::manageActions (int usedLine, int action) { case ONHOLD_CALL: call[usedLine]->usehold = true; - qDebug("ON HOLD CALL 0x%d, usedLine = %d", call[usedLine], usedLine); - eXosip_lock(); i = eXosip_on_hold_call(call[usedLine]->did); eXosip_unlock(); // Disable audio - //call[usedLine]->enable_audio = -1; - //callmanager->closeSound(call[usedLine]); call[usedLine]->closedCall(); break; // IP-Phone user is parking peer OFF HOLD case OFFHOLD_CALL: call[usedLine]->usehold = true; - qDebug("OFF HOLD CALL 0x%d, usedLine = %d", call[usedLine], usedLine); eXosip_lock(); i = eXosip_off_hold_call(call[usedLine]->did, NULL, 0); eXosip_unlock(); @@ -774,8 +768,10 @@ SIP::getEvent (void) { or !call[theline]->usehold) { if (!callmanager->transferedCall()) { - // Associate an audio port with a call - call[theline]->setLocalAudioPort(local_port); + if (!call[theline]->usehold) { + // Associate an audio port with a call + call[theline]->setLocalAudioPort(local_port); + } // Answer call[theline]->answeredCall(event); @@ -913,6 +909,7 @@ SIP::getEvent (void) { qDebug("<- (%i %i) BYE from: %s", event->cid, event->did, event->remote_uri); + call[theline]->usehold = false; theline = findLineNumber(event); if (!callmanager->phLines[theline]->getbInProgress()) { // if (!callmanager->getCallInProgress()) { @@ -942,7 +939,6 @@ SIP::getEvent (void) { qDebug("<- (%i %i) INVITE (On Hold) from: %s", event->cid, event->did, event->remote_uri); theline = findLineNumber(event); - //callmanager->closeSound(call[theline]); call[theline]->closedCall(); call[theline]->onholdCall(event); break; diff --git a/src/skin.h b/src/skin.h index 0aba0011da7b1ee0b1ef99af2fe5157420a2e638..278980beb9ef6e4c7dcdebdae0dc0e284d019d1e 100644 --- a/src/skin.h +++ b/src/skin.h @@ -28,33 +28,11 @@ extern "C" { #define PIXMAP_PHONE "main.png" #define PIXMAP_KEYPAD "dtmf_main.png" -#define PIXMAP_DIGIT0 "0.png" -#define PIXMAP_DIGIT1 "1.png" -#define PIXMAP_DIGIT2 "2.png" -#define PIXMAP_DIGIT3 "3.png" -#define PIXMAP_DIGIT4 "4.png" -#define PIXMAP_DIGIT5 "5.png" -#define PIXMAP_DIGIT6 "6.png" -#define PIXMAP_DIGIT7 "7.png" -#define PIXMAP_DIGIT8 "8.png" -#define PIXMAP_DIGIT9 "9.png" -#define PIXMAP_DIGIT_STAR "star.png" -#define PIXMAP_DIGIT_HASH "hash.png" -/* -#define PIXMAP_ADDRBOOK "directory.png" -#define PIXMAP_CONFERENCE "conference.png" -#define PIXMAP_TRANSFER "transfer.png" -#define PIXMAP_QUIT "close.png" -#define PIXMAP_REDUCE "minimize.png" -#define PIXMAP_CONFIGURATION "setup.png" -#define PIXMAP_HANGUP "hangup.png" -#define PIXMAP_DIAL "dial.png" -#define PIXMAP_MUTE "mute.png" -#define PIXMAP_IS_RINGING "ring.png" -#define PIXMAP_NO_RINGING "no_ring.png" -*/ #define PIXMAP_SCREEN "screen_main.png" #define PIXMAP_OVERSCREEN "overscreen.png" + +#define PIXMAP_IS_RINGING "ring.png" +#define PIXMAP_NO_RINGING "no_ring.png" #define PIXMAP_MESSAGE_ON "voicemail_on.png" #define PIXMAP_MESSAGE_OFF "voicemail_off.png" #define PIXMAP_LINE0_OFF "l1_off.png" @@ -70,6 +48,29 @@ extern "C" { #define PIXMAP_LINE4_BUSY "l5_on.png" #define PIXMAP_LINE5_BUSY "l6_on.png" +#define LINE1 "l1" +#define LINE2 "l2" +#define LINE3 "l3" +#define LINE4 "l4" +#define LINE5 "l5" +#define LINE6 "l6" + +#define VOICEMAIL "voicemail" +#define DIRECTORY "directory" +#define CONFERENCE "conference" +#define TRANSFER "transfer" +#define CLOSE "close" +#define MINIMIZE "minimize" +#define SETUP "setup" +#define HANGUP "hangup" +#define CONNECT "ok" +#define MUTE "mute" +#define DTMF_SHOW "dtmf" +#define VOLUME "volume" +#define VOL_MIC "vol_mic" +#define VOL_SPKR "vol_spkr" +#define SCREEN "screen" + #define DTMF_0 "dtmf_0" #define DTMF_1 "dtmf_1" #define DTMF_2 "dtmf_2" diff --git a/src/url_inputui.cpp b/src/url_inputui.cpp index 99fbd3f6fb9e2c7ecc1f3b6c694e6d7196a6e466..5c2b80e919c3d741b93cc6d0661bbaccf4c863ac 100644 --- a/src/url_inputui.cpp +++ b/src/url_inputui.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** Form implementation generated from reading ui file 'url_input.ui' ** -** Created: Mon Jan 24 17:46:09 2005 +** Created: Wed Jan 26 14:28:43 2005 ** by: The User Interface Compiler ($Id$) ** ** WARNING! All changes made in this file will be lost! diff --git a/src/url_inputui.h b/src/url_inputui.h index c6e1c2fc6fb38f793790f8abb532fd4af7090a76..2ac86de828c1dc8563c99dbb6030d3031f441ed4 100644 --- a/src/url_inputui.h +++ b/src/url_inputui.h @@ -1,7 +1,7 @@ /**************************************************************************** ** Form interface generated from reading ui file 'url_input.ui' ** -** Created: Mon Jan 24 17:46:09 2005 +** Created: Wed Jan 26 14:28:43 2005 ** by: The User Interface Compiler ($Id$) ** ** WARNING! All changes made in this file will be lost!