void Renamer::RenameList(BList* FileList) { fNumberOfItems = FileList->CountItems(); FileListItem* ListItem; for (int32 i = 0; i < fNumberOfItems; i++) { ListItem = (FileListItem*)FileList->ItemAt(i); ListItem->SetNewName(""); } }
void Renamer_Extension::RenameList(BList* FileList) { Renamer::RenameList(FileList); const bool replaceold = bool(fReplaceOldCheckBox->Value()); const int32 upperlower = fLowerCase->Value() == B_CONTROL_ON; FileListItem* ListItem; BMessage msg; const char* ExtensionString; BString Extension, NewName; int OldExtStart; for (int32 i = 0; i < fNumberOfItems; i++) { ListItem = (FileListItem*)FileList->ItemAt(i); if (BMimeType((char*)&ListItem->fMimeType).GetFileExtensions(&msg) == B_OK) { for (int32 j = 0; (msg.FindString("extensions", j, &ExtensionString) == B_OK); j++) { if (strlen(ExtensionString) < MAX_EXTENSION_LENGTH) { Extension = ExtensionString; Extension.Prepend("."); if (upperlower) Extension.ToLower(); else Extension.ToUpper(); NewName = ListItem->fName; if ((replaceold) && ((OldExtStart = NewName.FindLast(".")) > 0)) { ListItem->SetNewName(NewName .Truncate(OldExtStart).Append(Extension)); } else ListItem->SetNewName(NewName.Append(Extension)); break; } } } } };
void Renamer_Remove::RenameList(BList* FileList) { Renamer::RenameList(FileList); bool FromRight1 = bool(fDirection1->Menu() ->IndexOf(fDirection1->Menu()->FindMarked())); bool FromRight2 = bool(fDirection2->Menu() ->IndexOf(fDirection2->Menu()->FindMarked())); FileListItem* ListItem; BString ResultString, Part2; int EndPart1, StartPart2; int32 Position1 = fPosition1->Value(); int32 Position2 = fPosition2->Value(); int32 positionMaxValue = 0; int32 UTF_LengthOfFilename, LengthOfFilename; for (int i = 0; i < fNumberOfItems; i++) { ListItem = (FileListItem* )FileList->ItemAt(i); UTF_LengthOfFilename = LengthOfFilename = ListItem->fName.Length(); if (LengthOfFilename > positionMaxValue) positionMaxValue = LengthOfFilename; char* tempStr = new char[UTF_LengthOfFilename + 1]; convert_from_utf8(B_ISO1_CONVERSION, ListItem->fName.String(), &UTF_LengthOfFilename, tempStr, &LengthOfFilename, 0); tempStr[LengthOfFilename] = 0; if (FromRight1) { EndPart1 = (LengthOfFilename >= Position1) ? LengthOfFilename - Position1 : 0; } else { EndPart1 = (LengthOfFilename >= Position1) ? Position1 : LengthOfFilename; } if (FromRight2) { StartPart2 = (LengthOfFilename >= Position2) ? LengthOfFilename - Position2 : 0; } else { StartPart2 = (LengthOfFilename >= Position2) ? Position2 : LengthOfFilename; } if (StartPart2 < EndPart1) std::swap(StartPart2, EndPart1); ResultString.SetTo(tempStr, EndPart1); BString(tempStr).CopyInto(Part2, StartPart2, LengthOfFilename - StartPart2); ResultString.Append(Part2); LengthOfFilename = ResultString.Length(); UTF_LengthOfFilename = LengthOfFilename* 2; char* utf_String = new char[UTF_LengthOfFilename + 1]; convert_to_utf8(B_ISO1_CONVERSION, ResultString.String(), &LengthOfFilename, utf_String, &UTF_LengthOfFilename, 0); utf_String[UTF_LengthOfFilename] = 0; ListItem->SetNewName(utf_String); } fPosition1->SetMaxValue(positionMaxValue); fPosition2->SetMaxValue(positionMaxValue); }
void PecoApp::DoIt() { if (NothingToDo()) return; FileListItem *ListItem; BAlert *myAlert = new BAlert(NULL, MESSAGE_REALLY_DOIT, STR_CONTINUE, STR_CANCEL); if (myAlert->Go() == 1) return; for (int32 i = 0; (ListItem = (FileListItem *)fListView->ItemAt(i)) != NULL; i++ ) { if (ListItem->fErrorStatus == 1 ) { BAlert *myAlert = new BAlert(NULL, MESSAGE_WILL_HAVE_PROBS, STR_CONTINUE, STR_CANCEL); if (myAlert->Go() == 1) return; break; } } bool noerror = true, nomoreerrors=false, canceled=false; fWindow->Lock(); fStatusBar->SetText(STATUS_RENAMING); fStatusBar->SetMaxValue(fList->CountItems()); BButton *okButton = (BButton *)fWindow->FindView("DoIt"); okButton->SetEnabled(false); BTextControl* pfadView = (BTextControl *)fWindow->FindView("pfadView"); BString Pfad(pfadView->Text()); fWindow->Unlock(); BString AlterName, NeuerName; BEntry Datei; for (int32 i = 0; (ListItem = (FileListItem *)fListView->ItemAt(i)) != NULL; i++ ) { fWindow->Lock(); fStatusBar->Update(1); fWindow->Unlock(); if (canceled) { ListItem->fErrorStatus=0; continue; } if (ListItem->fNewName.String() != "" ) { AlterName = Pfad; AlterName.Append("/").Append(ListItem->fName); NeuerName = Pfad; NeuerName.Append("/").Append(ListItem->fNewName); Datei.SetTo(AlterName.String()); if ( Datei.Rename(NeuerName.String()) != B_OK ) { ListItem->fErrorStatus=1; fWindow->Lock(); fListView->InvalidateItem(i); fWindow->Unlock(); if (!nomoreerrors) { noerror = false; BString ErrorMessage(MESSAGE_HAVE_PROBLEM); ErrorMessage.ReplaceFirst("%1", ListItem->fName.String()); ErrorMessage.ReplaceFirst("%2", ListItem->fNewName.String()); BAlert *myAlert = new BAlert(NULL, ErrorMessage.String(), STR_CANCEL, STR_CONTINUE, STR_CONTINUE_WO_MSG, B_WIDTH_AS_USUAL, B_WARNING_ALERT); int32 result = myAlert->Go(); if (result == 0) { canceled = true; continue; } if (result == 2) nomoreerrors = true; } } else { fWindow->Lock(); ListItem->SetName(ListItem->fNewName); ListItem->SetNewName(""); fListView->InvalidateItem(i); fWindow->Unlock(); } } } // NoRenamer(); fWindow->Lock(); fStatusBar->Reset(STATUS_STATUS); fWindow->Unlock(); if (noerror) MakeList(); else { fStatusBar->SetText(STATUS_DIDIT_BAD); BAlert *myAlert = new BAlert(NULL, MESSAGE_MARKED_FILES, STR_OK); myAlert->Go(); } }