//! Sorting function for ScreenSaverItems int ModulesView::_CompareScreenSaverItems(const void* left, const void* right) { ScreenSaverItem* leftItem = *(ScreenSaverItem **)left; ScreenSaverItem* rightItem = *(ScreenSaverItem **)right; return strcasecmp(leftItem->Text(), rightItem->Text()); }
void ModulesView::PopulateScreenSaverList() { // Blackness is a built-in screen saver ScreenSaverItem* defaultItem = new ScreenSaverItem(B_TRANSLATE("Blackness"), ""); fScreenSaversListView->AddItem(defaultItem); // Iterate over add-on directories, and add their files to the list view directory_which which[] = { B_USER_NONPACKAGED_ADDONS_DIRECTORY, B_USER_ADDONS_DIRECTORY, B_SYSTEM_NONPACKAGED_ADDONS_DIRECTORY, B_SYSTEM_ADDONS_DIRECTORY, }; ScreenSaverItem* selectedItem = NULL; for (uint32 i = 0; i < sizeof(which) / sizeof(which[0]); i++) { BPath basePath; if (find_directory(which[i], &basePath) != B_OK) continue; else if (basePath.Append("Screen Savers", true) != B_OK) continue; BDirectory dir(basePath.Path()); BEntry entry; while (dir.GetNextEntry(&entry, true) == B_OK) { char name[B_FILE_NAME_LENGTH]; if (entry.GetName(name) != B_OK) continue; BPath path(basePath); if (path.Append(name) != B_OK) continue; ScreenSaverItem* item = new ScreenSaverItem(name, path.Path()); fScreenSaversListView->AddItem(item); if (selectedItem != NULL) continue; if (strcmp(fSettings.ModuleName(), item->Text()) == 0) selectedItem = item; } } fScreenSaversListView->SortItems(_CompareScreenSaverItems); if (selectedItem == NULL) selectedItem = defaultItem; fScreenSaversListView->Select(fScreenSaversListView->IndexOf(selectedItem)); fScreenSaversListView->ScrollToSelection(); }
void ModulesView::PopulateScreenSaverList() { fScreenSaversListView->DeselectAll(); while (ScreenSaverItem* item = (ScreenSaverItem*)fScreenSaversListView->RemoveItem((int32)0)) { delete item; } // Blackness is a built-in screen saver fScreenSaversListView->AddItem( new ScreenSaverItem(B_TRANSLATE("Blackness"), "")); // Iterate over add-on directories, and add their files to the list view directory_which which[] = { B_USER_ADDONS_DIRECTORY, B_COMMON_ADDONS_DIRECTORY, B_SYSTEM_ADDONS_DIRECTORY, }; ScreenSaverItem* selectItem = NULL; for (uint32 i = 0; i < sizeof(which) / sizeof(which[0]); i++) { BPath basePath; find_directory(which[i], &basePath); basePath.Append("Screen Savers", true); BDirectory dir(basePath.Path()); BEntry entry; while (dir.GetNextEntry(&entry, true) == B_OK) { char name[B_FILE_NAME_LENGTH]; if (entry.GetName(name) != B_OK) continue; BPath path = basePath; path.Append(name); ScreenSaverItem* item = new ScreenSaverItem(name, path.Path()); fScreenSaversListView->AddItem(item); if (strcmp(fSettings.ModuleName(), item->Text()) != 0 || (strcmp(fSettings.ModuleName(), "") != 0 && strcmp(item->Text(), B_TRANSLATE("Blackness")) != 0)) { selectItem = item; } } } fScreenSaversListView->SortItems(_CompareScreenSaverItems); fScreenSaversListView->Select(fScreenSaversListView->IndexOf(selectItem)); fScreenSaversListView->ScrollToSelection(); }
void ModulesView::MessageReceived(BMessage* message) { switch (message->what) { case kMsgSaverSelected: { int selection = fScreenSaversListView->CurrentSelection(); if (selection < 0) break; ScreenSaverItem* item = (ScreenSaverItem*)fScreenSaversListView->ItemAt(selection); if (item == NULL) break; if (strcmp(item->Text(), B_TRANSLATE("Blackness")) == 0) fSettings.SetModuleName(""); else fSettings.SetModuleName(item->Text()); SaveState(); _CloseSaver(); _OpenSaver(); fSettings.Save(); break; } case kMsgTestSaver: { SaveState(); fSettings.Save(); _CloseSaver(); be_roster->StartWatching(BMessenger(this, Looper()), B_REQUEST_QUIT); if (be_roster->Launch(SCREEN_BLANKER_SIG, &fSettings.Message(), &fScreenSaverTestTeam) == B_OK) { break; } // Try really hard to launch it. It's very likely that this fails // when we run from the CD, and there is only an incomplete mime // database for example... BPath path; if (find_directory(B_SYSTEM_BIN_DIRECTORY, &path) != B_OK || path.Append("screen_blanker") != B_OK) { path.SetTo("/bin/screen_blanker"); } BEntry entry(path.Path()); entry_ref ref; if (entry.GetRef(&ref) == B_OK) { be_roster->Launch(&ref, &fSettings.Message(), &fScreenSaverTestTeam); } break; } case kMsgAddSaver: fFilePanel->Show(); break; case B_SOME_APP_QUIT: { team_id team; if (message->FindInt32("be:team", &team) == B_OK && team == fScreenSaverTestTeam) { be_roster->StopWatching(this); _OpenSaver(); } break; } default: BView::MessageReceived(message); } }