diff --git a/daemon/src/config/config.cpp b/daemon/src/config/config.cpp index bd3818d857eb3b499585cd96b9de8d19cb3ca02b..ede267907559fa27e38e08d79d5c61039b6a01a7 100644 --- a/daemon/src/config/config.cpp +++ b/daemon/src/config/config.cpp @@ -43,16 +43,7 @@ namespace Conf { ConfigTree::~ConfigTree() -{ - // erase every new ItemMap (by CreateSection) - SectionMap::iterator iter = sections_.begin(); - - while (iter != sections_.end()) { - delete iter->second; - iter->second = NULL; - iter++; - } -} +{} void ConfigTree::addDefaultValue(const std::pair<std::string, std::string>& token, std::string section) { @@ -81,7 +72,7 @@ ConfigTree::createSection(const std::string& section) { // if we doesn't find the item, create it if (sections_.find(section) == sections_.end()) - sections_[section] = new ItemMap; + sections_[section] = ItemMap(); } /** @@ -98,18 +89,13 @@ ConfigTree::removeSection(const std::string& section) } /** Retrieve the sections as an array */ -TokenList +std::list<std::string> ConfigTree::getSections() { - TokenList sections; - - SectionMap::iterator iter = sections_.begin(); + std::list<std::string> sections; - while (iter != sections_.end()) { - // add to token list the: iter->second; + for (SectionMap::iterator iter = sections_.begin(); iter != sections_.end(); ++iter) sections.push_back(iter->first); - iter++; - } return sections; } @@ -125,7 +111,7 @@ ConfigTree::addConfigTreeItem(const std::string& section, const ConfigTreeItem i SectionMap::iterator iter = sections_.find(section); if (iter == sections_.end()) { - sections_[section] = new ItemMap; + sections_[section] = ItemMap(); iter = sections_.find(section); } @@ -133,9 +119,8 @@ ConfigTree::addConfigTreeItem(const std::string& section, const ConfigTreeItem i if (iter != sections_.end()) { std::string name(item.getName()); - if (iter->second->find(name) == iter->second->end()) { - (*(iter->second))[name] = item; - } + if (iter->second.find(name) == iter->second.end()) + iter->second[name] = item; } } @@ -163,17 +148,11 @@ ConfigTree::getConfigTreeItemIntValue(const std::string& section, const std::str bool ConfigTree::getConfigTreeItemBoolValue(const std::string& section, const std::string& itemName) const { - std::string configItem = getConfigTreeItemValue(section, itemName); - - if (configItem == "true") { - return true; - } - - return false; + return getConfigTreeItemValue(section, itemName) == "true"; } bool -ConfigTree::getConfigTreeItemToken(const std::string& section, const std::string& itemName, TokenList& arg) const +ConfigTree::getConfigTreeItemToken(const std::string& section, const std::string& itemName, std::list<std::string>& arg) const { const ConfigTreeItem *item = getConfigTreeItem(section, itemName); @@ -186,8 +165,8 @@ ConfigTree::getConfigTreeItemToken(const std::string& section, const std::string arg.push_back(item->getDefaultValue()); return true; } - - return false; + else + return false; } /** @@ -201,9 +180,9 @@ ConfigTree::getConfigTreeItem(const std::string& section, const std::string& ite if (iter == sections_.end()) return NULL; - ItemMap::const_iterator iterItem = iter->second->find(itemName); + ItemMap::const_iterator iterItem = iter->second.find(itemName); - if (iterItem == iter->second->end()) + if (iterItem == iter->second.end()) return NULL; return & (iterItem->second); @@ -220,18 +199,17 @@ ConfigTree::setConfigTreeItem(const std::string& section, const std::string& itemName, const std::string& value) { - SectionMap::iterator iter = sections_.find(section); if (iter == sections_.end()) { // Not found, create section - sections_[section] = new ItemMap; + sections_[section] = ItemMap(); iter = sections_.find(section); } - ItemMap::iterator iterItem = iter->second->find(itemName); + ItemMap::iterator iterItem = iter->second.find(itemName); - if (iterItem == iter->second->end()) { + if (iterItem == iter->second.end()) { // If not found, search in our default list to find // something that would fit. std::string defaultValue = getDefaultValue(itemName); @@ -240,13 +218,12 @@ ConfigTree::setConfigTreeItem(const std::string& section, } // Use default value if the value is empty. - if (value.empty() == true) { + if (value.empty()) { iterItem->second.setValue(getDefaultValue(itemName)); return true; } iterItem->second.setValue(value); - return true; } @@ -254,7 +231,7 @@ ConfigTree::setConfigTreeItem(const std::string& section, // return false if empty, no config, or enable to open // return true if everything is ok bool -ConfigTree::saveConfigTree(const std::string& fileName) +ConfigTree::saveConfigTree(const std::string& fileName) const { DEBUG("ConfigTree: Save %s", fileName.c_str()); @@ -271,20 +248,12 @@ ConfigTree::saveConfigTree(const std::string& fileName) } // for each section, for each item... - SectionMap::iterator iter = sections_.begin(); - - while (iter != sections_.end()) { + for (SectionMap::const_iterator iter = sections_.begin(); iter != sections_.end(); ++iter) { file << "[" << iter->first << "]" << std::endl; - ItemMap::iterator iterItem = iter->second->begin(); - - while (iterItem != iter->second->end()) { + for (ItemMap::const_iterator iterItem = iter->second.begin(); iterItem != iter->second.end(); ++iterItem) file << iterItem->first << "=" << iterItem->second.getValue() << std::endl; - iterItem++; - } file << std::endl; - - iter++; } file.close(); @@ -335,10 +304,9 @@ ConfigTree::populateFromFile(const std::string& fileName) } std::string line; - - std::string section(""); - std::string key(""); - std::string val(""); + std::string section; + std::string key; + std::string val; std::string::size_type pos; while (!file.eof()) { @@ -371,16 +339,16 @@ ConfigTree::populateFromFile(const std::string& fileName) return 1; } -TokenList -ConfigTreeIterator::begin() +std::list<std::string> +ConfigTreeIterator::begin() const { - TokenList tk; + std::list<std::string> tk; iter_ = tree_->sections_.begin(); - if (iter_!=tree_->sections_.end()) { - iterItem_ = iter_->second->begin(); + if (iter_ != tree_->sections_.end()) { + iterItem_ = iter_->second.begin(); - if (iterItem_!=iter_->second->end()) { + if (iterItem_ != iter_->second.end()) { tk.push_back(iter_->first); tk.push_back(iterItem_->first); tk.push_back(iterItem_->second.getType()); @@ -392,26 +360,26 @@ ConfigTreeIterator::begin() return tk; } -TokenList +std::list<std::string> ConfigTreeIterator::next() { - TokenList tk; + std::list<std::string> tk; // we return tk empty if we are at the end of the list... if (iter_ == tree_->sections_.end()) return tk; - if (iterItem_ != iter_->second->end()) + if (iterItem_ != iter_->second.end()) iterItem_++; - if (iterItem_ == iter_->second->end()) { + if (iterItem_ == iter_->second.end()) { // if we increment, and we are at the end of a section iter_++; if (iter_ != tree_->sections_.end()) { - iterItem_ = iter_->second->begin(); + iterItem_ = iter_->second.begin(); - if (iterItem_ != iter_->second->end()) { + if (iterItem_ != iter_->second.end()) { tk.push_back(iter_->first); tk.push_back(iterItem_->first); tk.push_back(iterItem_->second.getType()); diff --git a/daemon/src/config/config.h b/daemon/src/config/config.h index b91dd819c154dbce27251e7c5a10fc7a895d3be1..aff39f99a759c120a0f00c9411436b84a048ff91 100644 --- a/daemon/src/config/config.h +++ b/daemon/src/config/config.h @@ -47,8 +47,7 @@ static const char * const TRUE_STR = "true"; class ConfigTreeItem; typedef std::map<std::string, ConfigTreeItem> ItemMap; -typedef std::map<std::string, ItemMap*> SectionMap; -typedef std::list<std::string> TokenList; +typedef std::map<std::string, ItemMap> SectionMap; class ConfigTreeItemException { }; @@ -58,25 +57,13 @@ class ConfigTree; class ConfigTreeIterator { public: - /** - * Parsing method - * @return TokenList - */ - TokenList begin(); + std::list<std::string> begin() const; - /** - * Parsing method - * @return TokenList - */ - const TokenList& end() const { + const std::list<std::string> & end() const { return endToken_; } - /** - * Parsing method - * @return TokenList - */ - TokenList next(); + std::list<std::string> next(); private: friend class ConfigTree; @@ -85,9 +72,9 @@ class ConfigTreeIterator { NON_COPYABLE(ConfigTreeIterator); ConfigTree* tree_; - TokenList endToken_; - SectionMap::iterator iter_; - ItemMap::iterator iterItem_; + std::list<std::string> endToken_; + mutable SectionMap::iterator iter_; + mutable ItemMap::iterator iterItem_; }; class ConfigTree { @@ -118,7 +105,7 @@ class ConfigTree { * * @return array Strings of the sections */ - TokenList getSections(); + std::list<std::string> getSections(); void addConfigTreeItem(const std::string& section, const ConfigTreeItem item); /** @@ -149,14 +136,14 @@ class ConfigTree { /** * Flush data to .ini file */ - bool saveConfigTree(const std::string& fileName); + bool saveConfigTree(const std::string& fileName) const; /** * Load data (and fill ConfigTree) from disk */ int populateFromFile(const std::string& fileName); - bool getConfigTreeItemToken(const std::string& section, const std::string& itemName, TokenList& arg) const; + bool getConfigTreeItemToken(const std::string& section, const std::string& itemName, std::list<std::string>& arg) const; private: std::string getDefaultValue(const std::string& key) const; @@ -196,19 +183,19 @@ class ConfigTreeItem { value_ = value; } - const std::string getName() const { + std::string getName() const { return name_; } - const std::string getValue() const { + std::string getValue() const { return value_; } - const std::string getDefaultValue() const { + std::string getDefaultValue() const { return defaultValue_; } - const std::string getType() const { + std::string getType() const { return type_; } diff --git a/daemon/src/dbus/configurationmanager-introspec.xml b/daemon/src/dbus/configurationmanager-introspec.xml index 1964f615fed4702e54ef6704b3a134fe1bd3ccc2..a659f1c5c7f3afa89c61c168d9bb9e55128d5266 100644 --- a/daemon/src/dbus/configurationmanager-introspec.xml +++ b/daemon/src/dbus/configurationmanager-introspec.xml @@ -601,20 +601,10 @@ </arg> </method> - <method name="getHistory" tp:name-for-bindings="getHistory"> - <tp:docstring> - </tp:docstring> - <annotation name="com.trolltech.QtDBus.QtTypeName.Out0" value="MapStringString"/> - <arg type="as" name="entries" direction="out"> - <tp:docstring> - </tp:docstring> - </arg> - </method> - - <method name="getHistorySimple" tp:name-for-bindings="getHistorySimple"> - <annotation name="com.trolltech.QtDBus.QtTypeName.Out0" value="MapIntMapStringString"/> - <!-- Return a Dict of type <int, Dict<string, string> >...a Dict of Dicts --> - <arg type="a{ia{ss}}" name="info" direction="out"/> + <method name="getHistory" tp:name-for-bindings="getHistory"> + <annotation name="com.trolltech.QtDBus.QtTypeName.Out0" value="VectorMapStringString"/> + <!-- Return a List of type Dict<string, string> >...a List of Dicts --> + <arg type="aa{ss}" name="entries" direction="out"/> </method> <method name="setHistory" tp:name-for-bindings="setHistory"> diff --git a/daemon/src/dbus/configurationmanager.cpp b/daemon/src/dbus/configurationmanager.cpp index f337ae439c3f1bf34ebd6958a97eac7ec14d19f0..6947fc62390ebc687cd1e075ef931eefd503e4ab 100644 --- a/daemon/src/dbus/configurationmanager.cpp +++ b/daemon/src/dbus/configurationmanager.cpp @@ -398,12 +398,7 @@ void ConfigurationManager::setAccountsOrder(const std::string& order) Manager::instance().setAccountsOrder(order); } -std::vector<std::string> ConfigurationManager::getHistory() -{ - return Manager::instance().getHistorySerialized(); -} - -std::map<int, std::map<std::string, std::string> > ConfigurationManager::getHistorySimple() +std::vector<std::map<std::string, std::string> > ConfigurationManager::getHistory() { return Manager::instance().getHistory(); } diff --git a/daemon/src/dbus/configurationmanager.h b/daemon/src/dbus/configurationmanager.h index 0f8f46964e94af118aece7b79a3d0a3d28947c43..1e647313bde407bc2f936d93cc190d077f6ff29c 100644 --- a/daemon/src/dbus/configurationmanager.h +++ b/daemon/src/dbus/configurationmanager.h @@ -123,8 +123,7 @@ class ConfigurationManager : std::map<std::string, std::string> getHookSettings(); void setHookSettings(const std::map<std::string, std::string>& settings); - std::vector<std::string> getHistory(); - std::map<int, std::map<std::string, std::string> > getHistorySimple(); + std::vector<std::map<std::string, std::string> > getHistory(); void setHistory(const std::vector<std::string> &entries); std::map<std::string, std::string> getTlsSettings(); diff --git a/daemon/src/history/historyitem.cpp b/daemon/src/history/historyitem.cpp index 180849aef3e4190885770b5512c5cdbc712857b8..5c7466c6c8542913ea873f233dd16d4fe4f12cb5 100644 --- a/daemon/src/history/historyitem.cpp +++ b/daemon/src/history/historyitem.cpp @@ -35,13 +35,15 @@ #include <cstdlib> #include "manager.h" -static const char * const ITEM_SEPARATOR = "|"; +namespace { + const char * const ITEM_SEPARATOR = "|"; +} const char * const HistoryItem::ACCOUNT_ID_KEY = "accountid"; const char * const HistoryItem::CALLID_KEY = "callid"; const char * const HistoryItem::CONFID_KEY = "confid"; -const char * const HistoryItem::NAME_KEY = "name"; -const char * const HistoryItem::NUMBER_KEY = "number"; +const char * const HistoryItem::PEER_NAME_KEY = "peer_name"; +const char * const HistoryItem::PEER_NUMBER_KEY = "peer_number"; const char * const HistoryItem::RECORDING_PATH_KEY = "recordfile"; const char * const HistoryItem::TIME_ADDED_KEY = "timeadded"; const char * const HistoryItem::TIMESTAMP_START_KEY = "timestamp_start"; @@ -58,8 +60,8 @@ HistoryItem::HistoryItem(const std::string ×tampStart, : accountID_(accountID), confID_(confID), callID_(callID), - name_(name), - number_(number), + peerName_(name), + peerNumber_(number), recordingPath_(recording), timeAdded_(timeAdded), timestampStart_(timestampStart), @@ -69,7 +71,7 @@ HistoryItem::HistoryItem(const std::string ×tampStart, HistoryItem::HistoryItem(std::string serialized_form) : - accountID_(), confID_(), callID_(), name_(), number_(), recordingPath_(), + accountID_(), confID_(), callID_(), peerName_(), peerNumber_(), recordingPath_(), timeAdded_(), timestampStart_(), timestampStop_(), state_(MISSED) { @@ -83,13 +85,12 @@ HistoryItem::HistoryItem(std::string serialized_form) : state_ = (HistoryState) atoi(tmp.c_str()); break; case 1: // The number field - number_ = tmp; + peerNumber_ = tmp; break; case 2: // The name field - name_ = tmp; - - if (name_ == "empty") - name_ = ""; + peerName_ = tmp; + if (peerName_ == "empty") + peerName_ = ""; break; case 3: // The start timestamp timestampStart_ = tmp; @@ -119,7 +120,7 @@ HistoryItem::HistoryItem(std::string serialized_form) : } } -bool HistoryItem::save(Conf::ConfigTree **history) +bool HistoryItem::save(Conf::ConfigTree &history) const { std::stringstream section; std::stringstream state; @@ -129,25 +130,25 @@ bool HistoryItem::save(Conf::ConfigTree **history) std::string sectionstr = section.str(); state << state_; - return (*history)->setConfigTreeItem(sectionstr, STATE_KEY, state.str()) - && (*history)->setConfigTreeItem(sectionstr, TIMESTAMP_START_KEY, timestampStart_) - && (*history)->setConfigTreeItem(sectionstr, TIMESTAMP_STOP_KEY, timestampStop_) - && (*history)->setConfigTreeItem(sectionstr, NUMBER_KEY, number_) - && (*history)->setConfigTreeItem(sectionstr, CALLID_KEY, callID_) - && (*history)->setConfigTreeItem(sectionstr, ACCOUNT_ID_KEY, accountID_) - && (*history)->setConfigTreeItem(sectionstr, NAME_KEY, name_) - && (*history)->setConfigTreeItem(sectionstr, RECORDING_PATH_KEY, recordingPath_) - && (*history)->setConfigTreeItem(sectionstr, CONFID_KEY, confID_) - && (*history)->setConfigTreeItem(sectionstr, TIME_ADDED_KEY, timeAdded_); + return history.setConfigTreeItem(sectionstr, STATE_KEY, state.str()) + and history.setConfigTreeItem(sectionstr, TIMESTAMP_START_KEY, timestampStart_) + and history.setConfigTreeItem(sectionstr, TIMESTAMP_STOP_KEY, timestampStop_) + and history.setConfigTreeItem(sectionstr, PEER_NUMBER_KEY, peerNumber_) + and history.setConfigTreeItem(sectionstr, CALLID_KEY, callID_) + and history.setConfigTreeItem(sectionstr, ACCOUNT_ID_KEY, accountID_) + and history.setConfigTreeItem(sectionstr, PEER_NAME_KEY, peerName_) + and history.setConfigTreeItem(sectionstr, RECORDING_PATH_KEY, recordingPath_) + and history.setConfigTreeItem(sectionstr, CONFID_KEY, confID_) + and history.setConfigTreeItem(sectionstr, TIME_ADDED_KEY, timeAdded_); } std::string HistoryItem::serialize() const { // Replace empty string with a valid standard string value - std::string name(name_); + std::string peerName(peerName_); - if (name.empty()) - name = "empty"; + if (peerName.empty()) + peerName = "empty"; // For the account ID, check also if the accountID corresponds to an existing account // ie the account may have been removed @@ -158,7 +159,7 @@ std::string HistoryItem::serialize() const std::stringstream res; // Serialize it - res << state_ << ITEM_SEPARATOR << number_ << ITEM_SEPARATOR << name << ITEM_SEPARATOR << timestampStart_ << ITEM_SEPARATOR << timestampStop_ + res << state_ << ITEM_SEPARATOR << peerNumber_ << ITEM_SEPARATOR << peerName << ITEM_SEPARATOR << timestampStart_ << ITEM_SEPARATOR << timestampStop_ << ITEM_SEPARATOR << callID_ << ITEM_SEPARATOR << accountID << ITEM_SEPARATOR << recordingPath_ << ITEM_SEPARATOR << confID_ << ITEM_SEPARATOR << timeAdded_; return res.str(); @@ -169,10 +170,10 @@ std::map<std::string, std::string> HistoryItem::toMap() const std::map<std::string, std::string> result; // Replace empty string with a valid standard string value - if (name_.empty()) - result[NAME_KEY] = "empty"; + if (peerName_.empty()) + result[PEER_NAME_KEY] = "empty"; else - result[NAME_KEY] = name_; + result[PEER_NAME_KEY] = peerName_; // For the account ID, check also if the accountID corresponds to an existing account // ie the account may have been removed @@ -184,7 +185,7 @@ std::map<std::string, std::string> HistoryItem::toMap() const result[ACCOUNT_ID_KEY] = accountID_; result[STATE_KEY] = state_; - result[NUMBER_KEY] = number_; + result[PEER_NUMBER_KEY] = peerNumber_; result[TIMESTAMP_START_KEY] = timestampStart_; result[TIMESTAMP_STOP_KEY] = timestampStop_; result[CALLID_KEY] = callID_; @@ -200,3 +201,8 @@ bool HistoryItem::valid_account(const std::string &id) const { return Manager::instance().accountExists(id); } + +bool HistoryItem::youngerThan(int otherTime) const +{ + return atoi(timestampStart_.c_str()) >= otherTime; +} diff --git a/daemon/src/history/historyitem.h b/daemon/src/history/historyitem.h index 16b9493bb34fdc17e033f68454763f4ce76c4073..870f03a52a92f033383e2c87f5a8e790567e49e8 100644 --- a/daemon/src/history/historyitem.h +++ b/daemon/src/history/historyitem.h @@ -51,8 +51,8 @@ class HistoryItem { static const char * const ACCOUNT_ID_KEY; static const char * const CONFID_KEY; static const char * const CALLID_KEY; - static const char * const NAME_KEY; - static const char * const NUMBER_KEY; + static const char * const PEER_NAME_KEY; + static const char * const PEER_NUMBER_KEY; static const char * const RECORDING_PATH_KEY; static const char * const TIME_ADDED_KEY; static const char * const TIMESTAMP_START_KEY; @@ -87,7 +87,9 @@ class HistoryItem { return timestampStart_; } - bool save(Conf::ConfigTree **history); + bool youngerThan(int otherTime) const; + + bool save(Conf::ConfigTree &history) const; std::string serialize() const; std::map<std::string, std::string> toMap() const; @@ -116,8 +118,8 @@ class HistoryItem { /* * The information about the callee/caller, depending on the type of call. */ - std::string name_; - std::string number_; + std::string peerName_; + std::string peerNumber_; /** * Path of recording for this call, if it exists diff --git a/daemon/src/history/historymanager.cpp b/daemon/src/history/historymanager.cpp index d83d768fa60c5553dd046d4df83cc36477d5973b..912a5b18bce9c74ce5353d8e8ce88c9c84323186 100644 --- a/daemon/src/history/historymanager.cpp +++ b/daemon/src/history/historymanager.cpp @@ -37,70 +37,79 @@ #include "config/config.h" namespace { - int get_unix_timestamp_equivalent(int days) { + int get_unix_timestamp_equivalent(int days) + { // Number of seconds in one day: 60 x 60 x 24 static const int DAY_UNIX_TIMESTAMP = 86400; return days * DAY_UNIX_TIMESTAMP; } + + int getConfigInt(const std::string& section, const std::string& name, const Conf::ConfigTree &historyList) + { + return historyList.getConfigTreeItemIntValue(section, name); + } + + std::string getConfigString(const std::string& section, const std::string& name, const Conf::ConfigTree &historyList) + { + return historyList.getConfigTreeItemValue(section, name); + } } HistoryManager::HistoryManager() : - history_items_(), history_items_simple_(), history_loaded_(false), history_path_("") + history_items_(), history_loaded_(false), history_path_("") {} -int HistoryManager::load_history(int limit, const std::string &path) +int HistoryManager::loadHistory(int limit, const std::string &path) { - Conf::ConfigTree history_list; - create_history_path(path); - load_history_from_file(&history_list); - return load_history_items_map(&history_list, limit); + Conf::ConfigTree historyList; + createHistoryPath(path); + loadHistoryFromFile(historyList); + return loadHistoryItemsMap(historyList, limit); } -bool HistoryManager::save_history() +bool HistoryManager::saveHistory() { - Conf::ConfigTree history_list; - save_history_items_vector(&history_list); - return save_history_to_file(&history_list); + Conf::ConfigTree historyList; + saveHistoryItemsVector(historyList); + return saveHistoryToFile(historyList); } -bool HistoryManager::load_history_from_file(Conf::ConfigTree *history_list) +bool HistoryManager::loadHistoryFromFile(Conf::ConfigTree &historyList) { - DEBUG("HistoryManager: Load history from file %s", history_path_.c_str()); - - int exist = history_list->populateFromFile(history_path_.c_str()); + int exist = historyList.populateFromFile(history_path_.c_str()); history_loaded_ = (exist == 2) ? false : true; return history_loaded_; } -int HistoryManager::load_history_items_map(Conf::ConfigTree *history_list, int limit) +int HistoryManager::loadHistoryItemsMap(Conf::ConfigTree &historyList, int limit) { using std::string; // We want to save only the items recent enough (ie compared to CONFIG_HISTORY_LIMIT) - // Get the current timestamp - time_t current_timestamp; - time(¤t_timestamp); - int history_limit = get_unix_timestamp_equivalent(limit); + time_t currentTimestamp; + time(¤tTimestamp); + int historyLimit = get_unix_timestamp_equivalent(limit); + int oldestEntryTime = static_cast<int>(currentTimestamp) - historyLimit; - Conf::TokenList sections(history_list->getSections()); + std::list<std::string> sections(historyList.getSections()); int nb_items = 0; - for (Conf::TokenList::iterator iter = sections.begin(); iter != sections.end(); ++iter) { - HistoryState state = static_cast<HistoryState>(getConfigInt(*iter, HistoryItem::STATE_KEY, history_list)); - string timestamp_start(getConfigString(*iter, HistoryItem::TIMESTAMP_START_KEY, history_list)); - string timestamp_stop(getConfigString(*iter, HistoryItem::TIMESTAMP_STOP_KEY, history_list)); - string name(getConfigString(*iter, HistoryItem::NAME_KEY, history_list)); - string number(getConfigString(*iter, HistoryItem::NUMBER_KEY, history_list)); - string callID(getConfigString(*iter, HistoryItem::CALLID_KEY, history_list)); - string accountID(getConfigString(*iter, HistoryItem::ACCOUNT_ID_KEY, history_list)); - string recording_file(getConfigString(*iter, HistoryItem::RECORDING_PATH_KEY, history_list)); - string confID(getConfigString(*iter, HistoryItem::CONFID_KEY, history_list)); - string timeAdded(getConfigString(*iter, HistoryItem::TIME_ADDED_KEY, history_list)); + for (std::list<std::string>::const_iterator iter = sections.begin(); iter != sections.end(); ++iter) { + HistoryState state = static_cast<HistoryState>(getConfigInt(*iter, HistoryItem::STATE_KEY, historyList)); + string timestamp_start(getConfigString(*iter, HistoryItem::TIMESTAMP_START_KEY, historyList)); + string timestamp_stop(getConfigString(*iter, HistoryItem::TIMESTAMP_STOP_KEY, historyList)); + string peerName(getConfigString(*iter, HistoryItem::PEER_NAME_KEY, historyList)); + string peerNumber(getConfigString(*iter, HistoryItem::PEER_NUMBER_KEY, historyList)); + string callID(getConfigString(*iter, HistoryItem::CALLID_KEY, historyList)); + string accountID(getConfigString(*iter, HistoryItem::ACCOUNT_ID_KEY, historyList)); + string recording_file(getConfigString(*iter, HistoryItem::RECORDING_PATH_KEY, historyList)); + string confID(getConfigString(*iter, HistoryItem::CONFID_KEY, historyList)); + string timeAdded(getConfigString(*iter, HistoryItem::TIME_ADDED_KEY, historyList)); // Make a check on the start timestamp to know it is loadable according to CONFIG_HISTORY_LIMIT - if (atoi(timestamp_start.c_str()) >= ((int) current_timestamp - history_limit)) { - HistoryItem item(timestamp_start, state, timestamp_stop, name, number, callID, accountID, recording_file, confID, timeAdded); - add_new_history_entry(item); + HistoryItem item(timestamp_start, state, timestamp_stop, peerName, peerNumber, callID, accountID, recording_file, confID, timeAdded); + if (item.youngerThan(oldestEntryTime)) { + addNewHistoryEntry(item); ++nb_items; } } @@ -109,26 +118,25 @@ int HistoryManager::load_history_items_map(Conf::ConfigTree *history_list, int l } -bool HistoryManager::save_history_to_file(Conf::ConfigTree *history_list) +bool HistoryManager::saveHistoryToFile(const Conf::ConfigTree &historyList) const { DEBUG("HistoryManager: Saving history in XDG directory: %s", history_path_.c_str()); - return history_list->saveConfigTree(history_path_.data()); + return historyList.saveConfigTree(history_path_.data()); } -void HistoryManager::save_history_items_vector(Conf::ConfigTree *history_list) +void HistoryManager::saveHistoryItemsVector(Conf::ConfigTree &historyList) const { - for (std::vector<HistoryItem>::iterator iter = history_items_.begin(); iter != history_items_.end(); ++iter) - if (not iter->save(&history_list)) + for (std::vector<HistoryItem>::const_iterator iter = history_items_.begin(); iter != history_items_.end(); ++iter) + if (not iter->save(historyList)) DEBUG("can't save NULL history item\n"); } -void HistoryManager::add_new_history_entry(const HistoryItem &new_item) +void HistoryManager::addNewHistoryEntry(const HistoryItem &new_item) { history_items_.push_back(new_item); - history_items_simple_[rand()] = new_item; } -void HistoryManager::create_history_path(const std::string &path) +void HistoryManager::createHistoryPath(const std::string &path) { std::string xdg_data = std::string(HOMEDIR) + DIR_SEPARATOR_STR + ".local/share/sflphone"; @@ -150,46 +158,27 @@ void HistoryManager::create_history_path(const std::string &path) } } // Load user's history - set_history_path(userdata + DIR_SEPARATOR_STR + "history"); + setHistoryPath(userdata + DIR_SEPARATOR_STR + "history"); } else - set_history_path(path); -} - - -int -HistoryManager::getConfigInt(const std::string& section, const std::string& name, Conf::ConfigTree *history_list) -{ - return history_list->getConfigTreeItemIntValue(section, name); + setHistoryPath(path); } -std::string -HistoryManager::getConfigString(const std::string& section, const std::string& name, Conf::ConfigTree *history_list) -{ - return history_list->getConfigTreeItemValue(section, name); -} -std::vector<std::string> HistoryManager::get_history_serialized() const -{ - std::vector<std::string> serialized; - for (std::vector<HistoryItem>::const_iterator iter = history_items_.begin(); iter != history_items_.end(); ++iter) - serialized.push_back(iter->serialize()); - - return serialized; -} - -// Convert our map of HistoryItems to a map<int, map<string, string> > -std::map<int, std::map<std::string, std::string> > HistoryManager::get_history_simple() const +std::vector<std::map<std::string, std::string> > HistoryManager::getSerialized() const { using std::map; using std::string; - map<int, map<string, string> > result; - for (map<int, HistoryItem>::const_iterator iter = history_items_simple_.begin(); iter != history_items_simple_.end(); ++iter) - result[iter->first] = iter->second.toMap(); + using std::vector; + + vector<map<string, string> > result; + for (vector<HistoryItem>::const_iterator iter = history_items_.begin(); + iter != history_items_.end(); ++iter) + result.push_back(iter->toMap()); return result; } -int HistoryManager::set_serialized_history(const std::vector<std::string> &history, int limit) +int HistoryManager::setSerializedHistory(const std::vector<std::string> &history, int limit) { history_items_.clear(); @@ -205,7 +194,7 @@ int HistoryManager::set_serialized_history(const std::vector<std::string> &histo int item_timestamp = atoi(new_item.get_timestamp().c_str()); if (item_timestamp >= ((int) current_timestamp - history_limit)) { - add_new_history_entry(new_item); + addNewHistoryEntry(new_item); ++items_added; } } diff --git a/daemon/src/history/historymanager.h b/daemon/src/history/historymanager.h index a9dceeb5415c7429fe63fff06d79692229cc491e..62cae72240cdd94ed3061c4745470ef76a0445ca 100644 --- a/daemon/src/history/historymanager.h +++ b/daemon/src/history/historymanager.h @@ -49,80 +49,70 @@ class HistoryManager { * *@return int The number of history items successfully loaded */ - int load_history(int limit, const std::string &path=""); + int loadHistory(int limit, const std::string &path=""); /** *@return bool True if the history has been successfully saved in the file */ - bool save_history(); + bool saveHistory(); /* * Load the history from a file to the dedicated data structure */ - bool load_history_from_file(Conf::ConfigTree *history_list); + bool loadHistoryFromFile(Conf::ConfigTree &history_list); /* * @return int The number of history items loaded */ - int load_history_items_map(Conf::ConfigTree *history_list, int limit); + int loadHistoryItemsMap(Conf::ConfigTree &history_list, int limit); /* * Inverse method, ie save a data structure containing the history into a file */ - bool save_history_to_file(Conf::ConfigTree *history_list); + bool saveHistoryToFile(const Conf::ConfigTree &history_list) const; - void save_history_items_vector(Conf::ConfigTree *history_list); + void saveHistoryItemsVector(Conf::ConfigTree &history_list) const; /** *@return bool True if the history file has been successfully read */ - bool is_loaded() const { + bool isLoaded() const { return history_loaded_; } - void set_history_path(const std::string &filename) { + void setHistoryPath(const std::string &filename) { history_path_ = filename; } /* *@return int The number of items found in the history file */ - int get_history_size() const { + int numberOfItems() const { return history_items_.size(); } - std::vector<std::string> get_history_serialized() const; - std::map<int, std::map<std::string, std::string> > get_history_simple() const; + std::vector<std::string> getHistorySerialized() const; + std::vector<std::map<std::string, std::string> > getSerialized() const; - int set_serialized_history(const std::vector<std::string> &history, int limit); + int setSerializedHistory(const std::vector<std::string> &history, int limit); private: - int getConfigInt(const std::string& section, const std::string& name, Conf::ConfigTree *history_list); - std::string getConfigString(const std::string& section, const std::string& name, Conf::ConfigTree *history_list); - /* * Set the path to the history file * * @param path A specific file to use; if empty, use the global one */ - void create_history_path(const std::string &path=""); + void createHistoryPath(const std::string &path=""); /* * Add a new history item in the data structure */ - void add_new_history_entry(const HistoryItem &new_item); + void addNewHistoryEntry(const HistoryItem &new_item); /* * Vector containing the history items */ std::vector<HistoryItem> history_items_; - /* - * Map containing the history items - * key=id - * value=HistoryItem - */ - std::map<int, HistoryItem> history_items_simple_; - /* * History has been loaded */ diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp index feeda1f599e91bc3ca9dcdac4d45bcc125a351f1..21bc2fed6a14c602d6601c920a743934939a565a 100644 --- a/daemon/src/managerimpl.cpp +++ b/daemon/src/managerimpl.cpp @@ -76,7 +76,7 @@ ManagerImpl::ManagerImpl() : audiolayerMutex_(), waitingCall_(), waitingCallMutex_(), nbIncomingWaitingCall_(0), path_(), callAccountMap_(), callAccountMapMutex_(), callConfigMap_(), accountMap_(), - mainBuffer_(), conferenceMap_(), history_(new HistoryManager), + mainBuffer_(), conferenceMap_(), history_(), imModule_(new sfl::InstantMessaging) { // initialize random generator for call id @@ -87,7 +87,6 @@ ManagerImpl::ManagerImpl() : ManagerImpl::~ManagerImpl() { delete imModule_; - delete history_; delete audiofile_; } @@ -129,7 +128,7 @@ void ManagerImpl::init(std::string config_file) audioLayerMutexUnlock(); - history_->load_history(preferences.getHistoryLimit()); + history_.loadHistory(preferences.getHistoryLimit()); registerAccounts(); } @@ -2955,20 +2954,15 @@ std::map<std::string, std::string> ManagerImpl::getCallDetails(const std::string return call_details; } -std::vector<std::string> ManagerImpl::getHistorySerialized() const +std::vector<std::map<std::string, std::string> > ManagerImpl::getHistory() const { - return history_->get_history_serialized(); + return history_.getSerialized(); } -std::map<int, std::map<std::string, std::string> > ManagerImpl::getHistory() const +void ManagerImpl::setHistorySerialized(const std::vector<std::string> &history) { - return history_->get_history_simple(); -} - -void ManagerImpl::setHistorySerialized(std::vector<std::string> history) -{ - history_->set_serialized_history(history, preferences.getHistoryLimit());; - history_->save_history(); + history_.setSerializedHistory(history, preferences.getHistoryLimit()); + history_.saveHistory(); } namespace { diff --git a/daemon/src/managerimpl.h b/daemon/src/managerimpl.h index c1530fcd3dc71433f0cd106e7da0a392560babf5..8a93efeed2d21434f3cb975bb8f407d8670009d2 100644 --- a/daemon/src/managerimpl.h +++ b/daemon/src/managerimpl.h @@ -51,6 +51,7 @@ #include "audio/codecs/audiocodecfactory.h" #include "audio/mainbuffer.h" +#include "history/historymanager.h" #include "preferences.h" #include "noncopyable.h" @@ -73,7 +74,6 @@ class VoIPLink; class DNSService; #endif -class HistoryManager; class Account; /** Define a type for a AccountMap container */ @@ -1145,23 +1145,13 @@ class ManagerImpl { */ bool accountExists(const std::string& accountID); - /** - * Get a list of serialized history entries - * @return A list of serialized entry - */ - std::vector<std::string> getHistorySerialized() const; - - /** - * Get a list of serialized history entries - * @return A list of serialized entry - */ - std::map<int, std::map<std::string, std::string> > getHistory() const; + std::vector<std::map<std::string, std::string> > getHistory() const; /** * Set a list of serialized history entries * @param Vector of history entries */ - void setHistorySerialized(std::vector<std::string> history); + void setHistorySerialized(const std::vector<std::string> &history); /** * Get an account pointer * @param accountID account ID to get @@ -1206,8 +1196,9 @@ class ManagerImpl { /** * To handle the persistent history + * TODO: move this to ConfigurationManager */ - HistoryManager * history_; + HistoryManager history_; /** * Instant messaging module, resposible to initiate, format, parse, diff --git a/daemon/test/historytest.cpp b/daemon/test/historytest.cpp index 95a0ecbf6a27f5b2aab6ad605c1f199ddf244bd5..1973a32f8295f2b4492ceae7b470b869129cbceb 100644 --- a/daemon/test/historytest.cpp +++ b/daemon/test/historytest.cpp @@ -68,8 +68,8 @@ void HistoryTest::test_create_history_path() std::string path(HISTORY_SAMPLE); - history->create_history_path(path); - CPPUNIT_ASSERT(!history->is_loaded()); + history->createHistoryPath(path); + CPPUNIT_ASSERT(!history->isLoaded()); CPPUNIT_ASSERT(history->history_path_ == path); } @@ -80,11 +80,11 @@ void HistoryTest::test_load_history_from_file() bool res; Conf::ConfigTree history_list; - history->create_history_path(HISTORY_SAMPLE); - res = history->load_history_from_file(&history_list); + history->createHistoryPath(HISTORY_SAMPLE); + res = history->loadHistoryFromFile(history_list); - CPPUNIT_ASSERT(history->is_loaded()); - CPPUNIT_ASSERT(res == true); + CPPUNIT_ASSERT(history->isLoaded()); + CPPUNIT_ASSERT(res); } void HistoryTest::test_load_history_items_map() @@ -95,12 +95,11 @@ void HistoryTest::test_load_history_items_map() int nb_items; Conf::ConfigTree history_list; - history->set_history_path(HISTORY_SAMPLE); - history->load_history_from_file(&history_list); - nb_items = history->load_history_items_map(&history_list, - HUGE_HISTORY_LIMIT); + history->setHistoryPath(HISTORY_SAMPLE); + history->loadHistoryFromFile(history_list); + nb_items = history->loadHistoryItemsMap(history_list, HUGE_HISTORY_LIMIT); CPPUNIT_ASSERT(nb_items == HISTORY_SAMPLE_SIZE); - CPPUNIT_ASSERT(history->get_history_size() == HISTORY_SAMPLE_SIZE); + CPPUNIT_ASSERT(history->numberOfItems() == HISTORY_SAMPLE_SIZE); } void HistoryTest::test_save_history_items_map() @@ -110,10 +109,10 @@ void HistoryTest::test_save_history_items_map() std::string path; Conf::ConfigTree history_list, history_list2; - history->set_history_path(HISTORY_SAMPLE); - history->load_history_from_file(&history_list); - history->load_history_items_map(&history_list, HUGE_HISTORY_LIMIT); - history->save_history_items_vector(&history_list2); + history->setHistoryPath(HISTORY_SAMPLE); + history->loadHistoryFromFile(history_list); + history->loadHistoryItemsMap(history_list, HUGE_HISTORY_LIMIT); + history->saveHistoryItemsVector(history_list2); } void HistoryTest::test_save_history_to_file() @@ -125,24 +124,22 @@ void HistoryTest::test_save_history_to_file() std::map<std::string, std::string> res; std::map<std::string, std::string>::iterator iter; - history->set_history_path(HISTORY_SAMPLE); - history->load_history_from_file(&history_list); - history->load_history_items_map(&history_list, HUGE_HISTORY_LIMIT); - history->save_history_items_vector(&history_list2); - CPPUNIT_ASSERT(history->save_history_to_file(&history_list2)); + history->setHistoryPath(HISTORY_SAMPLE); + history->loadHistoryFromFile(history_list); + history->loadHistoryItemsMap(history_list, HUGE_HISTORY_LIMIT); + history->saveHistoryItemsVector(history_list2); + CPPUNIT_ASSERT(history->saveHistoryToFile(history_list2)); } void HistoryTest::test_get_history_serialized() { DEBUG("-------------------- HistoryTest::test_get_history_serialized --------------------\n"); - std::vector<std::string> res; std::vector<std::string>::iterator iter; std::string tmp; - CPPUNIT_ASSERT(history->load_history(HUGE_HISTORY_LIMIT, HISTORY_SAMPLE) == HISTORY_SAMPLE_SIZE); - res = history->get_history_serialized(); - CPPUNIT_ASSERT(res.size() == HISTORY_SAMPLE_SIZE); + CPPUNIT_ASSERT(history->loadHistory(HUGE_HISTORY_LIMIT, HISTORY_SAMPLE) == HISTORY_SAMPLE_SIZE); + CPPUNIT_ASSERT(history->getSerialized().size() == HISTORY_SAMPLE_SIZE); // Warning - If you change the history-sample file, you must change the following lines also so that the tests could work @@ -173,14 +170,13 @@ void HistoryTest::test_set_serialized_history() test_vector.push_back("2|136|Emmanuel Milou|747638685|747638765|Account:1239059899||||"); test_vector.push_back("1|5143848557|empty|775354456|775354987|Account:43789459478||||"); - CPPUNIT_ASSERT(history->load_history(HUGE_HISTORY_LIMIT, HISTORY_SAMPLE) == HISTORY_SAMPLE_SIZE); + CPPUNIT_ASSERT(history->loadHistory(HUGE_HISTORY_LIMIT, HISTORY_SAMPLE) == HISTORY_SAMPLE_SIZE); // We use a large history limit to be able to interpret results - CPPUNIT_ASSERT(history->set_serialized_history(test_vector, HUGE_HISTORY_LIMIT) == 3); - CPPUNIT_ASSERT(history->get_history_size() == 3); + CPPUNIT_ASSERT(history->setSerializedHistory(test_vector, HUGE_HISTORY_LIMIT) == 3); + CPPUNIT_ASSERT(history->numberOfItems() == 3); test_vector.clear(); - test_vector = history->get_history_serialized(); - CPPUNIT_ASSERT(test_vector.size() == 3); + CPPUNIT_ASSERT(history->getSerialized().size() == 3); // Check the first tmp = "0|514-276-5468|Savoir-faire Linux|144562000|144562458||empty|||"; @@ -191,8 +187,8 @@ void HistoryTest::test_set_serialized_history() // std::cout << "test vector : " << test_vector[1] << std::endl; // CPPUNIT_ASSERT (Validator::isEqual (tmp, test_vector[1])); - history->save_history_items_vector(&history_list); - CPPUNIT_ASSERT(history->save_history_to_file(&history_list)); + history->saveHistoryItemsVector(history_list); + CPPUNIT_ASSERT(history->saveHistoryToFile(history_list)); } void HistoryTest::test_set_serialized_history_with_limit() @@ -215,19 +211,19 @@ void HistoryTest::test_set_serialized_history_with_limit() test_vector.push_back(current_2.str()); test_vector.push_back(current_3.str()); - CPPUNIT_ASSERT(history->load_history(HUGE_HISTORY_LIMIT, HISTORY_SAMPLE) == HISTORY_SAMPLE_SIZE); + CPPUNIT_ASSERT(history->loadHistory(HUGE_HISTORY_LIMIT, HISTORY_SAMPLE) == HISTORY_SAMPLE_SIZE); // We use different value of history limit // 10 days - the last entry should not be saved - CPPUNIT_ASSERT(history->set_serialized_history(test_vector, 10) == 2); - CPPUNIT_ASSERT(history->get_history_size() == 2); + CPPUNIT_ASSERT(history->setSerializedHistory(test_vector, 10) == 2); + CPPUNIT_ASSERT(history->numberOfItems() == 2); // 4 days - the two last entries should not be saved - CPPUNIT_ASSERT(history->set_serialized_history(test_vector, 4) == 1); - CPPUNIT_ASSERT(history->get_history_size() == 1); + CPPUNIT_ASSERT(history->setSerializedHistory(test_vector, 4) == 1); + CPPUNIT_ASSERT(history->numberOfItems() == 1); // 1 day - no entry should not be saved - CPPUNIT_ASSERT(history->set_serialized_history(test_vector, 1) == 0); - CPPUNIT_ASSERT(history->get_history_size() == 0); + CPPUNIT_ASSERT(history->setSerializedHistory(test_vector, 1) == 0); + CPPUNIT_ASSERT(history->numberOfItems() == 0); } void HistoryTest::tearDown() diff --git a/gnome/src/actions.c b/gnome/src/actions.c index a02a9fe0af88bfeb602c66ac2a935391365b6693..ec777394e959b684364d41d2499d812dee649bec 100644 --- a/gnome/src/actions.c +++ b/gnome/src/actions.c @@ -41,7 +41,6 @@ #include <string.h> #include <sys/types.h> #include <unistd.h> -#include <assert.h> #include <arpa/nameser.h> #include <netinet/in.h> @@ -61,6 +60,7 @@ #include "icons/icon_factory.h" #include "imwindow.h" #include "statusicon.h" +#include "unused.h" #include "widget/imwidget.h" @@ -72,7 +72,7 @@ static gchar ** sflphone_order_history_hash_table(GHashTable *result) gint size = 0; gchar **ordered_list = NULL; - assert(result); + g_assert(result); while (g_hash_table_size(result)) { gpointer key, value; @@ -1075,27 +1075,21 @@ void sflphone_fill_conference_list(void) g_strfreev(conferences); } -void sflphone_fill_history(void) +static void +create_callable_from_entry(gpointer data, gpointer user_data UNUSED) { - gchar **entries, **entries_orig; - entries = entries_orig = dbus_get_history(); - - while (entries && *entries) { - gchar *current_entry = *entries; - /* do something with key and value */ - callable_obj_t *history_call = create_history_entry_from_serialized_form(current_entry); + GHashTable *entry = (GHashTable *) data; + callable_obj_t *history_call = create_history_entry_from_hashtable(entry); - /* Add it and update the GUI */ - calllist_add_call(history_tab, history_call); - entries++; - } - - g_strfreev(entries_orig); + /* Add it and update the GUI */ + calllist_add_call(history_tab, history_call); +} - // fill the treeview with calls +static void fill_treeview_with_calls(void) +{ guint n = calllist_get_size(history_tab); - for (guint i = 0; i < n; i++) { + for (guint i = 0; i < n; ++i) { QueueElement *element = calllist_get_nth(history_tab, i); if (element->type == HIST_CALL) @@ -1103,6 +1097,15 @@ void sflphone_fill_history(void) } } +void sflphone_fill_history(void) +{ + GPtrArray *entries = dbus_get_history(); + if (entries) + g_ptr_array_foreach(entries, create_callable_from_entry, NULL); + + fill_treeview_with_calls(); +} + #if ! (GLIB_CHECK_VERSION(2,28,0)) static void g_slist_free_full(GSList *list, diff --git a/gnome/src/callable_obj.c b/gnome/src/callable_obj.c index d6e3771c481417289596e30dca8bb3b2c77eba3d..65b6f1cb3c23a5aab5f60de8e1fc11ab3620f508 100644 --- a/gnome/src/callable_obj.c +++ b/gnome/src/callable_obj.c @@ -174,73 +174,36 @@ static history_state_t get_history_state_from_id(gchar *indice) return state; } -callable_obj_t *create_history_entry_from_serialized_form(const gchar *entry) +static gconstpointer get_str(GHashTable *entry, gconstpointer key) { - const gchar *peer_name = ""; - const gchar *peer_number = ""; - const gchar *callID = ""; - const gchar *accountID = ""; - const gchar *time_start = ""; - const gchar *time_stop = ""; - const gchar *recordfile = ""; - const gchar *confID = ""; - const gchar *time_added = ""; - history_state_t history_state = MISSED; - - gchar **ptr_orig = g_strsplit(entry, "|", 10); - gchar **ptr; - gint token; - - for (ptr = ptr_orig, token = 0; ptr && token < 10; token++, ptr++) - switch (token) { - case 0: - history_state = get_history_state_from_id(*ptr); - break; - case 1: - peer_number = *ptr; - break; - case 2: - peer_name = *ptr; - break; - case 3: - time_start = *ptr; - break; - case 4: - time_stop = *ptr; - break; - case 5: - callID = *ptr; - break; - case 6: - accountID = *ptr; - break; - case 7: - recordfile = *ptr; - break; - case 8: - confID = *ptr; - break; - case 9: - time_added = *ptr; - break; - default: - break; - } - - if (g_strcasecmp(peer_name, "empty") == 0) - peer_name = ""; + gconstpointer result = g_hash_table_lookup(entry, key); + if (!result || g_strcmp0(result, "empty") == 0) + result = ""; + return result; +} +callable_obj_t *create_history_entry_from_hashtable(GHashTable *entry) +{ + gconstpointer callID = get_str(entry, "callid"); + gconstpointer accountID = get_str(entry, "accountid"); + gconstpointer peer_name = get_str(entry, "peer_name"); + gconstpointer peer_number = get_str(entry, "peer_number"); callable_obj_t *new_call = create_new_call(HISTORY_ENTRY, CALL_STATE_DIALING, callID, accountID, peer_name, peer_number); - new_call->_history_state = history_state; - new_call->_time_start = atoi(time_start); - new_call->_time_stop = atoi(time_stop); - new_call->_recordfile = g_strdup(recordfile); - new_call->_confID = g_strdup(confID); - new_call->_historyConfID = g_strdup(confID); - new_call->_time_added = atoi(time_added); + gconstpointer value = g_hash_table_lookup(entry, "state"); + new_call->_history_state = value ? atoi(value) : MISSED; + value = g_hash_table_lookup(entry, "timestamp_start"); + new_call->_time_start = value ? atoi(value) : 0; + value = g_hash_table_lookup(entry, "timestamp_stop"); + new_call->_time_stop = value ? atoi(value) : 0; + value = g_hash_table_lookup(entry, "recordfile"); + new_call->_recordfile = g_strdup(value); + value = g_hash_table_lookup(entry, "confid"); + new_call->_confID = g_strdup(value); + new_call->_historyConfID = g_strdup(value); + value = g_hash_table_lookup(entry, "timeadded"); + new_call->_time_added = value ? atoi(value) : 0; new_call->_record_is_playing = FALSE; - g_strfreev(ptr_orig); return new_call; } diff --git a/gnome/src/callable_obj.h b/gnome/src/callable_obj.h index 2f81d683e7e372360487cd75e7ecf2201c066702..c81d9c736d83af132d350839ad49201ff6e0e0a9 100644 --- a/gnome/src/callable_obj.h +++ b/gnome/src/callable_obj.h @@ -166,7 +166,7 @@ callable_obj_t *create_new_call (callable_type_t, call_state_t, const gchar* con callable_obj_t *create_new_call_from_details (const gchar *, GHashTable *); -callable_obj_t *create_history_entry_from_serialized_form (const gchar *); +callable_obj_t *create_history_entry_from_hashtable (GHashTable *entry); void call_add_error (callable_obj_t * call, gpointer dialog); diff --git a/gnome/src/contacts/calllist.c b/gnome/src/contacts/calllist.c index 75b0727f8c03104ee93158e47a74a58b8df8ad0c..d1e634e54b67042add8ec9da2914e33e99c9ffb1 100644 --- a/gnome/src/contacts/calllist.c +++ b/gnome/src/contacts/calllist.c @@ -172,7 +172,7 @@ calllist_get_by_state(calltab_t* tab, call_state_t state) } guint -calllist_get_size(calltab_t* tab) +calllist_get_size(const calltab_t* tab) { return g_queue_get_length(tab->callQueue); } diff --git a/gnome/src/contacts/calllist.h b/gnome/src/contacts/calllist.h index 66d793f5627f598d5c792b8a480c0f893b8e94f7..5eb14a722d63dff29bcc95c949668f19e0d3325e 100644 --- a/gnome/src/contacts/calllist.h +++ b/gnome/src/contacts/calllist.h @@ -107,7 +107,7 @@ calllist_get_by_state (calltab_t* tab, call_state_t state); /** Return the number of calls in the list * @return The number of calls in the list */ guint -calllist_get_size (calltab_t* tab); +calllist_get_size (const calltab_t* tab); /** Return the call at the nth position in the list * @param n The position of the call you want diff --git a/gnome/src/dbus/configurationmanager-introspec.xml b/gnome/src/dbus/configurationmanager-introspec.xml index 1964f615fed4702e54ef6704b3a134fe1bd3ccc2..a659f1c5c7f3afa89c61c168d9bb9e55128d5266 100644 --- a/gnome/src/dbus/configurationmanager-introspec.xml +++ b/gnome/src/dbus/configurationmanager-introspec.xml @@ -601,20 +601,10 @@ </arg> </method> - <method name="getHistory" tp:name-for-bindings="getHistory"> - <tp:docstring> - </tp:docstring> - <annotation name="com.trolltech.QtDBus.QtTypeName.Out0" value="MapStringString"/> - <arg type="as" name="entries" direction="out"> - <tp:docstring> - </tp:docstring> - </arg> - </method> - - <method name="getHistorySimple" tp:name-for-bindings="getHistorySimple"> - <annotation name="com.trolltech.QtDBus.QtTypeName.Out0" value="MapIntMapStringString"/> - <!-- Return a Dict of type <int, Dict<string, string> >...a Dict of Dicts --> - <arg type="a{ia{ss}}" name="info" direction="out"/> + <method name="getHistory" tp:name-for-bindings="getHistory"> + <annotation name="com.trolltech.QtDBus.QtTypeName.Out0" value="VectorMapStringString"/> + <!-- Return a List of type Dict<string, string> >...a List of Dicts --> + <arg type="aa{ss}" name="entries" direction="out"/> </method> <method name="setHistory" tp:name-for-bindings="setHistory"> diff --git a/gnome/src/dbus/dbus.c b/gnome/src/dbus/dbus.c index 5c3cbfc55d42b17dac3ec1fc5f0f97af50098cc4..79762c621f8397658c0ff945b7c66675236d8a8d 100644 --- a/gnome/src/dbus/dbus.c +++ b/gnome/src/dbus/dbus.c @@ -1943,17 +1943,17 @@ dbus_set_accounts_order(const gchar* order) } } -gchar ** +GPtrArray * dbus_get_history(void) { GError *error = NULL; - gchar **entries = NULL; + GPtrArray *entries = NULL; org_sflphone_SFLphone_ConfigurationManager_get_history( configurationManagerProxy, &entries, &error); if (error) { - ERROR("Error calling get history: %s", error->message); + ERROR("Error calling get history simple: %s", error->message); g_error_free(error); } diff --git a/gnome/src/dbus/dbus.h b/gnome/src/dbus/dbus.h index 41193d89dc991a2dce2bf5747e03b4feda1dec31..e8c159452c48767be3775ecc9e6b3f3b071411a9 100644 --- a/gnome/src/dbus/dbus.h +++ b/gnome/src/dbus/dbus.h @@ -472,10 +472,10 @@ gchar** dbus_get_conference_list (void); void dbus_set_accounts_order (const gchar* order); /** - * Get a list of serialized hisotry entries - * @return The list of history entries + * Get a the history + * @return The PtrArray of history entries */ -gchar **dbus_get_history (void); +GPtrArray *dbus_get_history(void); /** * Set the history entries into the daemon. The daemon then write teh content