std::map<std::string, Status*> Status::GetAllStatusses() { if (s_allStatusses.size() == 0) { IImageManager* imageManager = PlatformSpecific::GetImageManager(); //otherwise open status XML file typedef vector<XMLNode*>::const_iterator SI; vector<XMLNode*> statusNodes = BmeClient::GetPreferences()->GetIconPrefs()->GetStatusNodes(); for (SI s = statusNodes.begin(); s != statusNodes.end(); ++s) { XMLNode* statusNode = *s; if (statusNode->Name() == "status") { vector<XMLNode*> children = statusNode->Children(); Status* status = new Status(); for (SI c = children.begin(); c != children.end(); ++c) { XMLNode* statusChild = *c; if (statusChild->Name() == "icon") { std::string iconPath = statusChild->StringValue(); IPath* iconFullPath = PlatformSpecific::GetPathManager()->GetIconPrefsPath()->Append(iconPath); Image* statusIcon = imageManager->GetImageFromFile(iconFullPath->ToString()); status->AddIcon(statusIcon); delete iconFullPath; } else if (statusChild->Name() == "message") { status->SetStatusName(statusChild->StringValue()); } else if (statusChild->Name() == "protocol") { status->SetAbbreviation(statusChild->StringValue()); } else if (statusChild->Name() == "visible") { bool userChoice = atoi(statusChild->StringValue().c_str()); status->SetUserChoice(userChoice); } else if (statusChild->Name() == "color") { } } s_allStatusses[status->GetAbbreviation()] = (status); } } delete imageManager; } return s_allStatusses; }
status_t LoadStatusses(BPath statFilePath) { status_t error = B_OK; //open file BFile statFile(statFilePath.Path(), B_READ_ONLY); error = statFile.InitCheck(); if (error != B_ERROR) { StringList *tokenList = new StringList(); //read line off_t fileSize; if (statFile.GetSize(&fileSize) == B_OK) { ssize_t bytesRead = 0; BString* token = new BString(""); bool newToken = false; do { char c[2]; bytesRead += statFile.Read(c,1); c[1] = '\0'; if (c[0] == '\t' || c[0] == '\n') { //clear token if (!newToken) { //add token to list tokenList->AddItem(token); token = new BString(""); newToken = true; } } else { token->Append(c); newToken = false; } } while (bytesRead < fileSize); } int32 startIndex = -1; int32 endIndex = -1; for (int32 i = 0; i < tokenList->CountItems(); i++) { if ((*tokenList)[i].ICompare("<status>") == 0) startIndex = i; else if ((*tokenList)[i].ICompare("</status>") == 0) { endIndex = i; break; } } if (startIndex != -1 && endIndex != -1) { //start past the <status> tag startIndex++; for (int32 i = startIndex; i < endIndex; i++) { int32 lastLineIndex = i + 4; if (lastLineIndex < endIndex) { //parse lines BString bitmapString = (*tokenList)[i]; BString statusName = (*tokenList)[i+1]; BString abbreviation = (*tokenList)[i+2]; bool userChoice = atoi((*tokenList)[i+3].String()); BString colourString = (*tokenList)[i+4]; i += 4; //construct bitmap path BPath bitmapPath; statFilePath.GetParent(&bitmapPath); bitmapPath.Append(bitmapString.String()); BBitmap *icon = BTranslationUtils::GetBitmap(bitmapPath.Path()); //construct status object Status *status = FindStatus(abbreviation); if (status != NULL) { status->AddIcon(icon); } else { //remove brackets from colourString colourString.RemoveAll("{"); colourString.RemoveAll("}"); int32 colours[4]; int32 startIndex = 0; for (int i = 0; i < 4; i++) { int32 commaIndex = colourString.FindFirst(",",startIndex); if (commaIndex != B_ERROR) { BString colourValue; colourString.CopyInto(colourValue,startIndex, commaIndex-startIndex); colours[i] = atoi(colourValue.String()); startIndex = commaIndex + 1; } else if (i < 3) { BString colourValue; colourString.CopyInto(colourValue, startIndex, colourString.CountChars() - startIndex); colours[i] = atoi(colourValue.String()); } else if (i == 3) { colours[i] = 255; } } //construct status colour rgb_color statusColour; statusColour.red = colours[0]; statusColour.green = colours[1]; statusColour.blue = colours[2]; statusColour.alpha = colours[3]; //construct new status object Status *status = new Status(statusName,abbreviation, icon, userChoice, statusColour); statLock.Lock(); statusses[abbreviation] = status; statLock.Unlock(); } } } } StringList::deleteStrings(tokenList); delete tokenList; } else { error = B_ERROR; } return error; }