void pawsBuddyWindow::ChangeAlias(const csString & name, const csString &oldAlias, const csString & newAlias) { // Check for duplicates if (!IsUniqueAlias(newAlias)) { psSystemMessage err(0, MSG_ERROR, "%s '%s' %s", PawsManager::GetSingleton().Translate("Buddy with the name").GetData(), newAlias.GetDataSafe(), PawsManager::GetSingleton().Translate("already exists.").GetData()); err.FireEvent(); return; } bool found = false; // Find the old alias in both lists and replace with the new alias. size_t loc = offlineBuddies.Find(oldAlias); if (loc != csArrayItemNotFound) { found = true; offlineBuddies.DeleteIndex(loc); offlineBuddies.Push(newAlias); } loc = onlineBuddies.Find(oldAlias); if (loc != csArrayItemNotFound) { found = true; onlineBuddies.DeleteIndex(loc); onlineBuddies.Push(newAlias); } if (!found) { // Old alias not found, perhaps the buddy was removed from the list psSystemMessage err(0, MSG_ERROR, "%s '%s' %s", PawsManager::GetSingleton().Translate("Buddy with the name").GetData(), name.GetDataSafe(), PawsManager::GetSingleton().Translate("cannot be found. Perhaps it was removed.").GetData()); err.FireEvent(); return; } // Add/replace in the aliases table and save it. aliases.PutUnique(name, newAlias); SaveAliases(psengine->GetMainPlayerName()); // Update the listbox FillBuddyList(); }
bool VisionApp::SaveSettings(void) { BAutolock saveLock(const_cast<BLocker*>(&fSettingsLock)); if (!saveLock.IsLocked()) return false; SaveAliases(); if ((fVisionSettings->Save() == B_OK) && fDebugSettings) { printf(":SETTINGS: saved to file\n"); return true; } return false; }
void pawsBuddyWindow::OnStringEntered(const char* name, int /*param*/, const char* value) { if (!value || !strlen(value)) { if (!strcmp(name, "EditBuddy")) editBuddy.Clear(); return; } if (!strcmp(name,"AddBuddy")) { // Is the new buddy name unique? if (!IsUniqueAlias(value)) { psSystemMessage err(0, MSG_ERROR, "%s '%s' %s", PawsManager::GetSingleton().Translate("Buddy with the name").GetData(),value, PawsManager::GetSingleton().Translate("already exists.").GetData()); err.FireEvent(); return; } csString command; command.Format("/buddy %s add", value); psengine->GetCmdHandler()->Execute(command); } else if (!strcmp(name,"RemoveBuddy")) { csString command; command.Format("/buddy %s remove", value); psengine->GetCmdHandler()->Execute(command); currentBuddy.Clear(); if (editBuddy.Compare(value)) { // Removing the buddy that is being edited editBuddy.Clear(); } // Remove from the alias list. It may fail on the server, but we don't have enough // information to remove the alias when the buddy was actually removed. if (aliases.DeleteAll(value)) SaveAliases(psengine->GetMainPlayerName()); } else if (!strcmp(name, "EditBuddy")) { // It might be that the player removed the buddy from the list before clicking OK if (editBuddy.IsEmpty()) { psSystemMessage err(0, MSG_ERROR, "%s '%s' %s", PawsManager::GetSingleton().Translate("Buddy with the new name").GetData(), value, PawsManager::GetSingleton().Translate("cannot be found. Perhaps it was removed.").GetData()); err.FireEvent(); return; } csString alias = GetAlias(editBuddy); ChangeAlias(editBuddy, alias, value); editBuddy.Clear(); } else { csString command; command.Format("/tell %s %s", name, value ); psengine->GetCmdHandler()->Execute(command, false); } }