WirelessNetworkMenuItem::WirelessNetworkMenuItem(const char* name, int32 signalQuality, int32 authenticationMode, BMessage* message) : BMenuItem(name, message), fQuality(signalQuality) { // Append authentication mode to label BString label = B_TRANSLATE("%name% (%authenticationMode%)"); label.Replace("%name%", name, 1); label.Replace("%authenticationMode%", AuthenticationName(authenticationMode), 1); SetLabel(label.String()); }
void BContactField::_UpdateLabel(field_usage usage, BString& str) { for (int i = 0; gStandardUsages[i].usage != 0; i++) { standardUsagesMap item = gStandardUsages[i]; if (usage == item.usage) { switch (item.stringOp) { case 0: break; case 1: str.Prepend(item.label); break; case 2: str.Append(item.label); break; case 3: if (strlen(item.replaceString) < 1) break; str.Replace(item.replaceString, item.label, 1); break; } } } }
void TranslateEntities(BString &str) { // pointeur vers un caractère '&' int l_Pointer=-1; while ((l_Pointer = str.FindFirst('&',l_Pointer+1)) >= 0) { // recherche du ';' de fin unsigned int l_Pointer2; l_Pointer2 = str.FindFirst(';',l_Pointer); if (l_Pointer2 < 0) return; // s'il n'y a plus de ';' dans la chaîne, on peut arréter de chercher des '&', c'est fini BString l_Entity(str.String()+l_Pointer+1,l_Pointer2-l_Pointer-1); // recherche de l'entité dans la liste déclarée ci-dessus // on procède par dichotomie pour trouver la chaîne unsigned int l_Start = 0; unsigned int l_End = c_NumEntities; unsigned int l_StringIndex; while(l_Start != l_End) { // on regarde ce qu'il y a au milieu l_StringIndex = (l_End+l_Start)/2; int l_Comp = l_Entity.Compare(s_EntityNames[l_StringIndex]); if (l_Comp == 0) { l_Entity.Prepend("&"); l_Entity.Append(";"); str.Replace(l_Entity.String(),s_EntityCharacters[l_StringIndex],1,l_Pointer); break; } if (l_Comp>0) // la chaîne à chercher est après l_Start = ++l_StringIndex; else // la chaîne à chercher est avant l_End = l_StringIndex; } } }
status_t BEmailMessage::RenderTo(BDirectory *dir, BEntry *msg) { time_t currentTime; char numericDateString [40]; struct tm timeFields; BString worker; // Generate a file name for the outgoing message. See also // FolderFilter::ProcessMailMessage which does something similar for // incoming messages. BString name = Subject(); SubjectToThread (name); // Extract the core subject words. if (name.Length() <= 0) name = "No Subject"; if (name[0] == '.') name.Prepend ("_"); // Avoid hidden files, starting with a dot. // Convert the date into a year-month-day fixed digit width format, so that // sorting by file name will give all the messages with the same subject in // order of date. time (¤tTime); localtime_r (¤tTime, &timeFields); sprintf (numericDateString, "%04d%02d%02d%02d%02d%02d", timeFields.tm_year + 1900, timeFields.tm_mon + 1, timeFields.tm_mday, timeFields.tm_hour, timeFields.tm_min, timeFields.tm_sec); name << " " << numericDateString; worker = From(); extract_address_name(worker); name << " " << worker; name.Truncate(222); // reserve space for the uniquer // Get rid of annoying characters which are hard to use in the shell. name.ReplaceAll('/','_'); name.ReplaceAll('\'','_'); name.ReplaceAll('"','_'); name.ReplaceAll('!','_'); name.ReplaceAll('<','_'); name.ReplaceAll('>','_'); while (name.FindFirst(" ") >= 0) // Remove multiple spaces. name.Replace(" " /* Old */, " " /* New */, 1024 /* Count */); int32 uniquer = time(NULL); worker = name; int32 tries = 30; bool exists; while ((exists = dir->Contains(worker.String())) && --tries > 0) { srand(rand()); uniquer += (rand() >> 16) - 16384; worker = name; worker << ' ' << uniquer; } if (exists) printf("could not create mail! (should be: %s)\n", worker.String()); BFile file; status_t status = dir->CreateFile(worker.String(), &file); if (status < B_OK) return status; if (msg != NULL) msg->SetTo(dir,worker.String()); return RenderToRFC822(&file); }
status_t TimeFormat(BString &string, int32 index, FormatSeparator separator, DateOrder order, bool clockIs24Hour) { if (index >= 6) return B_ERROR; BString clockString; BString dateString; if (index <= 1) if (clockIs24Hour) clockString = "%H:%M:%S"; else clockString = "%I:%M:%S %p"; else if (clockIs24Hour) clockString = "%H:%M"; else clockString = "%I:%M %p"; if (index <= 3) { switch (order) { case kYMDFormat: dateString = "%Y %! %d"; break; case kDMYFormat: dateString = "%d %! %Y"; break; case kMDYFormat: // Fall through case kDateFormatEnd: // Fall through default: dateString = "%! %d %Y"; break; } if (index == 0) dateString.Replace('!', 'B', 1); else dateString.Replace('!', 'b', 1); } else { switch (order) { case kYMDFormat: dateString = "%y!%m!%d"; break; case kDMYFormat: dateString = "%d!%m!%y"; break; case kMDYFormat: // Fall through case kDateFormatEnd: // Fall through default: dateString = "%m!%d!%y"; break; } char separatorArray[] = {' ', '-', '/', '\\', '.'}; if (separator == kNoSeparator) dateString.ReplaceAll("!", ""); else dateString.ReplaceAll('!', separatorArray[separator-1]); } if (index == 0) string = "%A, "; else if (index < 3) string = "%a, "; else string = ""; string << dateString; if (index < 5) string << ", " << clockString; return B_OK; }