diff --git a/backends/skype/skype.cpp b/backends/skype/skype.cpp index 9f054efe395a764857494c427e410eb67b8e0b8c..78c1aad314692883030f11319b2326bb6a4b2861 100644 --- a/backends/skype/skype.cpp +++ b/backends/skype/skype.cpp @@ -20,6 +20,7 @@ #include "skype.h" #include "skypeplugin.h" +#include "skypedb.h" #include "transport/config.h" #include "transport/logging.h" @@ -95,9 +96,9 @@ void Skype::login() { return; } - std::string db_path = createSkypeDirectory(); + m_db = createSkypeDirectory(); - bool spawned = spawnSkype(db_path); + bool spawned = spawnSkype(m_db); if (!spawned) { m_np->handleDisconnected(m_user, pbnetwork::CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE, "Error spawning the Skype instance."); return; @@ -229,51 +230,55 @@ bool Skype::loadSkypeBuddies() { } } - std::string friends = send_command("GET AUTH_CONTACTS_PROFILES"); + // Try to load skype buddies from database, if it fails + // fallback to old method. + if (!SkypeDB::loadBuddies(m_np, m_db, m_user, group_map)) { + std::string friends = send_command("GET AUTH_CONTACTS_PROFILES"); - char **full_friends_list = g_strsplit((strchr(friends.c_str(), ' ')+1), ";", 0); - if (full_friends_list && full_friends_list[0]) - { - //in the format of: username;full name;phone;office phone;mobile phone; - // online status;friendly name;voicemail;mood - // (comma-seperated lines, usernames can have comma's) - - for (int i=0; full_friends_list[i] && full_friends_list[i+1] && *full_friends_list[i] != '\0'; i+=8) + char **full_friends_list = g_strsplit((strchr(friends.c_str(), ' ')+1), ";", 0); + if (full_friends_list && full_friends_list[0]) { - std::string buddy = full_friends_list[i]; + //in the format of: username;full name;phone;office phone;mobile phone; + // online status;friendly name;voicemail;mood + // (comma-seperated lines, usernames can have comma's) - if (buddy[0] == ',') { - buddy.erase(buddy.begin()); - } + for (int i=0; full_friends_list[i] && full_friends_list[i+1] && *full_friends_list[i] != '\0'; i+=8) + { + std::string buddy = full_friends_list[i]; - if (buddy.rfind(",") != std::string::npos) { - buddy = buddy.substr(buddy.rfind(",")); - } + if (buddy[0] == ',') { + buddy.erase(buddy.begin()); + } - if (buddy[0] == ',') { - buddy.erase(buddy.begin()); - } + if (buddy.rfind(",") != std::string::npos) { + buddy = buddy.substr(buddy.rfind(",")); + } - LOG4CXX_INFO(logger, "Got buddy " << buddy); - std::string st = full_friends_list[i + 5]; + if (buddy[0] == ',') { + buddy.erase(buddy.begin()); + } - pbnetwork::StatusType status = getStatus(st); + LOG4CXX_INFO(logger, "Got buddy " << buddy); + std::string st = full_friends_list[i + 5]; - std::string alias = full_friends_list[i + 6]; + pbnetwork::StatusType status = getStatus(st); - std::string mood_text = ""; - if (full_friends_list[i + 8] && *full_friends_list[i + 8] != '\0' && *full_friends_list[i + 8] != ',') { - mood_text = full_friends_list[i + 8]; - } + std::string alias = full_friends_list[i + 6]; - std::vector groups; - if (group_map.find(buddy) != group_map.end()) { - groups.push_back(group_map[buddy]); + std::string mood_text = ""; + if (full_friends_list[i + 8] && *full_friends_list[i + 8] != '\0' && *full_friends_list[i + 8] != ',') { + mood_text = full_friends_list[i + 8]; + } + + std::vector groups; + if (group_map.find(buddy) != group_map.end()) { + groups.push_back(group_map[buddy]); + } + m_np->handleBuddyChanged(m_user, buddy, alias, groups, status, mood_text); } - m_np->handleBuddyChanged(m_user, buddy, alias, groups, status, mood_text); } + g_strfreev(full_friends_list); } - g_strfreev(full_friends_list); send_command("SET AUTOAWAY OFF"); send_command("SET USERSTATUS ONLINE");