CMimeItem::CMimeItem(const char *mime) { fMime.SetTo(mime); memset(fIcon, B_TRANSPARENT_8_BIT, 256); memset(fIconSelected, B_TRANSPARENT_8_BIT, 256); BBitmap bm(BRect(0, 0, 15, 15), B_COLOR_8_BIT); if (fMime.GetIcon(&bm, B_MINI_ICON) != B_OK) { try { char p[PATH_MAX]; if (find_directory(B_SYSTEM_TEMP_DIRECTORY, 0, true, p, PATH_MAX) == B_OK) { BDirectory tmpdir; FailOSErr(tmpdir.SetTo(p)); time_t t; time(&t); sprintf(p, "tmp.pe_is_looking_for_a_mime_icon:%ld", t); BFile f; FailOSErr(tmpdir.CreateFile(p, &f)); BNodeInfo ni; FailOSErr(ni.SetTo(&f)); FailOSErr(ni.SetType(mime)); FailOSErr(ni.GetTrackerIcon(&bm, B_MINI_ICON)); } } catch (HErr& e) { } } for (int i = 0; i < 16; i++) { unsigned char *ba = (unsigned char *)((unsigned char *)bm.Bits() + bm.BytesPerRow() * i); memcpy(fIcon + i * 16, ba, 16); for (int j = 0; j < 16; j++) if (ba[j] < 255) fIconSelected[j + i * 16] = gSelectedMap[ba[j]]; } } /* CMimeItem::CMimeItem */
void BootPromptWindow::_PopulateKeymaps() { // Disable sending the selection message while we change the selection. fKeymapsListView->SetSelectionMessage(NULL); // Clean the list view first while (BListItem* item = fKeymapsListView->RemoveItem( fKeymapsListView->CountItems() - 1)) { delete item; } // Get the name of the current keymap, so we can mark the correct entry // in the list view. BString currentKeymapName; entry_ref ref; if (_GetCurrentKeymapRef(ref) == B_OK) { BNode node(&ref); node.ReadAttrString("keymap:name", ¤tKeymapName); } // TODO: common keymaps! BPath path; if (find_directory(B_SYSTEM_DATA_DIRECTORY, &path) != B_OK || path.Append("Keymaps") != B_OK) { return; } // Populate the list BDirectory directory; if (directory.SetTo(path.Path()) == B_OK) { while (directory.GetNextRef(&ref) == B_OK) { fKeymapsListView->AddItem(new KeymapListItem(ref)); if (currentKeymapName == ref.name) fKeymapsListView->Select(fKeymapsListView->CountItems() - 1); } } fKeymapsListView->ScrollToSelection(); // Re-enable sending the selection message. fKeymapsListView->SetSelectionMessage( new BMessage(MSG_KEYMAP_SELECTED)); }
/*! Save the screenshot to the file with the specified filename and type. Note that any existing file with the same filename will be overwritten without warning. */ status_t Utility::Save(BBitmap** screenshot, const char* fileName, uint32 imageType) const { BString fileNameString(fileName); // Generate a default filename when none is given if (fileNameString.Compare("") == 0) { BPath homePath; if (find_directory(B_USER_DIRECTORY, &homePath) != B_OK) return B_ERROR; BEntry entry; int32 index = 1; BString extension = GetFileNameExtension(imageType); do { fileNameString.SetTo(homePath.Path()); fileNameString << "/" << B_TRANSLATE(sDefaultFileNameBase) << index++ << extension; entry.SetTo(fileNameString.String()); } while (entry.Exists()); } // Create the file BFile file(fileNameString, B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY); if (file.InitCheck() != B_OK) return B_ERROR; // Write the screenshot bitmap to the file BBitmapStream stream(*screenshot); BTranslatorRoster* roster = BTranslatorRoster::Default(); roster->Translate(&stream, NULL, NULL, &file, imageType, B_TRANSLATOR_BITMAP); *screenshot = NULL; // Set the file MIME attribute BNodeInfo nodeInfo(&file); if (nodeInfo.InitCheck() != B_OK) return B_ERROR; nodeInfo.SetType(_GetMimeString(imageType)); return B_OK; }
void AddPrinterDialog::_FillMenu(BMenu* menu, const char* path, uint32 what) { for (uint32 i = 0; i < sizeof(gAddonDirs) / sizeof(directory_which); i++) { BPath addonPath; if (find_directory(gAddonDirs[i], &addonPath) != B_OK) continue; if (addonPath.Append(path) != B_OK) continue; BDirectory dir(addonPath.Path()); if (dir.InitCheck() != B_OK) continue; BEntry entry; while (dir.GetNextEntry(&entry, true) == B_OK) { if (!entry.IsFile()) continue; BNode node(&entry); if (node.InitCheck() != B_OK) continue; BNodeInfo info(&node); if (info.InitCheck() != B_OK) continue; char type[B_MIME_TYPE_LENGTH + 1]; info.GetType(type); BMimeType entryType(type); // filter non executable entries (like "transport" subfolder...) if (entryType == B_APP_MIME_TYPE) { BPath transportPath; if (entry.GetPath(&transportPath) != B_OK) continue; BMessage* msg = new BMessage(what); msg->AddString("name", transportPath.Leaf()); menu->AddItem(new BMenuItem(transportPath.Leaf(), msg)); } } } }
void TBarWindow::MenusBeginning() { BPath path; entry_ref ref; find_directory (B_USER_DESKBAR_DIRECTORY, &path); get_ref_for_path(path.Path(), &ref); BEntry entry(&ref, true); if (entry.InitCheck() == B_OK && entry.IsDirectory()) { // need the entry_ref to the actual item entry.GetRef(&ref); // set the nav directory to the deskbar folder sDeskbarMenu->SetNavDir(&ref); } else if (!entry.Exists()) { // the deskbar folder does not exist // create one now BDirectory dir; if (entry.GetParent(&dir) == B_OK) { BDirectory deskbarDir; dir.CreateDirectory("deskbar", &deskbarDir); if (deskbarDir.GetEntry(&entry) == B_OK && entry.GetRef(&ref) == B_OK) sDeskbarMenu->SetNavDir(&ref); } } else { // this really should never happen TRESPASS(); return; } sDeskbarMenu->NeedsToRebuild(); sDeskbarMenu->ResetTargets(); fBarView->SetEventMask(0); // This works around a BeOS bug - the menu is quit with every // B_MOUSE_DOWN the window receives. // // Is this bug still here? I commented this line out and didn't // notice anything different BWindow::MenusBeginning(); }
status_t WinampSkinThemesAddon::CLSkinPath(BPath *to) { char buffer[B_FILE_NAME_LENGTH+1]; BPath CLSPath; buffer[B_FILE_NAME_LENGTH] = '\0'; if (find_directory(B_USER_SETTINGS_DIRECTORY, &CLSPath) < B_OK) return B_ERROR; CLSPath.Append(CL_SETTINGS_NAME); BFile CLSettings(CLSPath.Path(), B_READ_ONLY); if (CLSettings.InitCheck() < B_OK) return CLSettings.InitCheck(); ssize_t got = CLSettings.ReadAt(0x150LL, buffer, B_FILE_NAME_LENGTH); if (got < B_FILE_NAME_LENGTH) return EIO; to->SetTo(buffer); return B_OK; }
char * BeCheckersWindow::File(const char *fileName) { char *f; BPath p; find_directory(B_USER_DIRECTORY, &p); BString path; path.SetTo(p.Path()).Append("/").Append(APP_SGP); create_directory(path.String(), 0777); p.SetTo(path.String()); if(p.Path() != NULL) { f = new char[strlen(p.Path()) + strlen(fileName) + 6] = {'\0'}; sprintf(f, "%s%s%s%s", p.Path(), "/", fileName, APP_XTN); // Thanks, Charlie. } return(p.Path() == NULL ? NULL : f); }
void SerialApp::LoadSettings() { BPath path; find_directory(B_USER_SETTINGS_DIRECTORY, &path); path.Append("SerialConnect"); BFile file(path.Path(), B_READ_ONLY); BMessage message(kMsgSettings); if (message.Unflatten(&file) != B_OK) { message.AddInt32("parity", fSerialPort.ParityMode()); message.AddInt32("databits", fSerialPort.DataBits()); message.AddInt32("stopbits", fSerialPort.StopBits()); message.AddInt32("baudrate", fSerialPort.DataRate()); message.AddInt32("flowcontrol", fSerialPort.FlowControl()); } be_app->PostMessage(&message); fWindow->PostMessage(&message); }
void MediaReplicant::_Launch(const char* prettyName, const char* signature, directory_which base, const char* fileName) { BPath path; status_t status = find_directory(base, &path); if (status == B_OK) path.Append(fileName); // launch the application if (_LaunchBySignature(signature) != B_OK && _LaunchByPath(path.Path()) != B_OK) { BString message = B_TRANSLATE("Couldn't launch "); message << prettyName; (new BAlert(B_TRANSLATE("desklink"), message.String(), B_TRANSLATE("OK")))->Go(); } }
/** called when replicated from NSBaseView::Instantiate() */ int gui_init_replicant(int argc, char** argv) { nserror ret; BPath options; struct gui_table beos_gui_table = { &beos_browser_table, beos_window_table, beos_download_table, &beos_clipboard_table, &beos_fetch_table }; if (find_directory(B_USER_SETTINGS_DIRECTORY, &options, true) == B_OK) { options.Append("x-vnd.NetSurf"); } /* initialise logging. Not fatal if it fails but not much we * can do about it either. */ nslog_init(nslog_stream_configure, &argc, argv); // FIXME: use options as readonly for replicants /* user options setup */ ret = nsoption_init(set_defaults, &nsoptions, &nsoptions_default); if (ret != NSERROR_OK) { // FIXME: must not die when in replicant! die("Options failed to initialise"); } nsoption_read(options.Path(), NULL); nsoption_commandline(&argc, argv, NULL); /* common initialisation */ BPath messages = get_messages_path(); ret = netsurf_init(messages.Path(), &beos_gui_table); if (ret != NSERROR_OK) { // FIXME: must not die when in replicant! die("NetSurf failed to initialise"); } gui_init(argc, argv); return 0; }
MediaWindow::~MediaWindow() { _EmptyNodeLists(); _ClearParamView(); char buffer[512]; BRect rect = Frame(); PRINT_OBJECT(rect); snprintf(buffer, 512, "# MediaPrefs Settings\n rect = %i,%i,%i,%i\n", int(rect.left), int(rect.top), int(rect.right), int(rect.bottom)); BPath path; if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) { path.Append(SETTINGS_FILE); BFile file(path.Path(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE); if (file.InitCheck() == B_OK) file.Write(buffer, strlen(buffer)); } }
bool ShowImageSettings::OpenSettingsFile(BFile* file, bool forReading) { status_t st; BPath path; uint32 openMode; st = find_directory(B_USER_SETTINGS_DIRECTORY, &path); if (st != B_OK) return false; path.Append("ShowImage_settings"); if (forReading) { openMode = B_READ_ONLY; } else { openMode = B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE; } st = file->SetTo(path.Path(), openMode); return st == B_OK; }
SeebaerApp::~SeebaerApp(void) { BPath path; BFile setting; find_directory(B_USER_SETTINGS_DIRECTORY, &path); path.Append("TimeCop_settings"); setting.SetTo(path.Path(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE); setting.Write(&rectWoWin, sizeof(rectWoWin)); setting.Write(&rectMoWin, sizeof(rectMoWin)); setting.Write(&rectDownWin, sizeof(rectDownWin)); setting.Write(&rectDayWin, sizeof(rectDayWin)); setting.Write(&rectLogWin, sizeof(rectLogWin)); setting.Write(&rectAvRunWin, sizeof(rectAvRunWin)); setting.Write(&rectEndlDayWin, sizeof(rectEndlDayWin)); setting.Write(&rectEndlWeekWin, sizeof(rectEndlWeekWin)); setting.Unset(); delete file; }
/* static */ status_t PrefHandler::GetDefaultPath(BPath& path) { status_t status; status = find_directory(B_USER_SETTINGS_DIRECTORY, &path, true); if (status != B_OK) return status; status = path.Append("Terminal"); if (status != B_OK) return status; // Just create the directory. Harmless if already there status = create_directory(path.Path(), 0755); if (status != B_OK) return status; return path.Append("Default"); }
BPoint TimeSettings::LeftTop() const { BPath path; BPoint leftTop(-1000.0, -1000.0); if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) { path.Append(fSettingsFile.String()); BFile file(path.Path(), B_READ_ONLY); if (file.InitCheck() == B_OK) { BPoint tmp; if (file.Read(&tmp, sizeof(BPoint)) == sizeof(BPoint)) leftTop = tmp; } } return leftTop; }
// copies the path to the settings directory into "buffer", which must be // of at least size MAXPATHLEN. // returns buffer on success, NULL on failure. char *GetConfigDir(char *buffer) { // -32: reserve rooms for strcat()'s. meow! if (find_directory(B_USER_SETTINGS_DIRECTORY, 0, true, buffer, MAXPATHLEN-32) == B_OK) { int len = strlen(buffer); if (len && buffer[len-1] != '/') strcat(buffer, "/"); strcat(buffer, "Sisong/"); mkdir(buffer, S_IRUSR | S_IWUSR); return buffer; } // failure buffer[0] = 0; return NULL; }
/** called when replicated from NSBaseView::Instantiate() */ int gui_init_replicant(int argc, char** argv) { setbuf(stderr, NULL); BPath options; if (find_directory(B_USER_SETTINGS_DIRECTORY, &options, true) == B_OK) { options.Append("x-vnd.NetSurf"); } const char* messages = "/boot/apps/netsurf/res/en/Messages"; /* initialise netsurf */ netsurf_init(&argc, &argv, options.Path(), messages); gui_init(argc, argv); gui_init2(argc, argv); return 0; }
void Settings::SaveSettings() { PRINT(("Settings::SaveWindow()\n")); BPath path; find_directory(B_USER_SETTINGS_DIRECTORY, &path); path.Append(COMPANY); path.Append(APPLICATION); create_directory(path.Path(), 0755); path.Append(SETTINGS); BMessage archive; Archive(&archive, false); BFile settings(path.Path(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE); if (settings.InitCheck() == B_OK) { archive.Flatten(&settings); } }
void ProtocolHandler::LoadPasswords() { //find settings dir BPath passwordPath; find_directory(B_USER_SETTINGS_DIRECTORY, &passwordPath); //append Bme path and Cache path passwordPath.Append(K_BME_SETTINGS_PATH); passwordPath.Append(K_CACHE_PATH); //loop through Bme Cache path and find all login names with saved passwords BDirectory cacheDir(passwordPath.Path()); int32 entryNum = cacheDir.CountEntries(); //compose list of loginNames with passwords for (int32 i = 0; i < entryNum;i++) { BEntry entry; cacheDir.GetNextEntry(&entry); //only open if it is a file!!! if (entry.IsFile()) { BFile settingsFile(&entry, B_READ_ONLY); //data is stored as BMessages BMessage message; message.Unflatten(&settingsFile); //see if password is stored in message BString password; BMessage userMessage; if (message.FindMessage("user",&userMessage) == B_OK) { if (userMessage.FindString("User::password",&password) == B_OK) { BString loginName; if (userMessage.FindString("Contact::passport" ,&loginName) == B_OK) { Login login = {loginName,password}; m_passwords.push_back(login); } } } } } }
/**** constructeur ****/ CPreferenceFile::CPreferenceFile(const char *fileName,const char *basePath,const char *extendedPath) : BMessage(C_PREFERENCE_MSG) { BPath path; BEntry settingPathEntry; // par defaut on a pas reussi _state = B_ERROR; // trouver si le repertoire Settings existe if(find_directory(B_USER_SETTINGS_DIRECTORY,&path)!=B_OK) path.SetTo("/boot/home/config/settings"); // verifier si le repertoire MeTOS existe // sinon le creer _filePath = path.Path(); _filePath << "/" << basePath; settingPathEntry.SetTo(_filePath.String()); if(!(settingPathEntry.Exists())) create_directory(_filePath.String(),00777); // on est dans un sous repertoire if(extendedPath!=NULL) { BString extendedPathString; extendedPathString = extendedPath; if(extendedPathString.Length()>0) { _filePath << "/"; _filePath << extendedPath; settingPathEntry.SetTo(_filePath.String()); if(!(settingPathEntry.Exists())) create_directory(_filePath.String(),00777); } } _filePath << "/"; _filePath << fileName; _filePath << ".prefs"; _state = B_OK; }
status_t FolderShaper::CreateSettingsFile () { status_t status; BPath p; if ((status = find_directory(B_USER_SETTINGS_DIRECTORY, &p)) == B_OK) if ((status = p.SetTo(p.Path(),"Kirilla/FolderShaper/settings")) == B_OK) { status = m_settings_file-> SetTo(p.Path(), B_READ_WRITE | B_CREATE_FILE); if (status == B_OK || status == B_FILE_EXISTS) return B_OK; else return status; } else return status; else return status; }
void NotificationWindow::SaveAppFilters() { BPath path; if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) return; path.Append(kSettingsDirectory); path.Append(kFiltersSettings); BMessage settings; BFile file(path.Path(), B_WRITE_ONLY); appfilter_t::iterator fIt; for (fIt = fAppFilters.begin(); fIt != fAppFilters.end(); fIt++) settings.AddFlat("app_usage", fIt->second); settings.Flatten(&file); }
status_t GetSettingsDir(BDirectory &dir, BPath &path) { //BPath path; status_t err; // TODO: build list from text files err = find_directory(B_USER_SETTINGS_DIRECTORY, &path, true); if (err < B_OK) return err; dir.SetTo(path.Path()); if (!dir.Contains("pe")) dir.CreateDirectory("pe", NULL); path.Append("pe"); dir.SetTo(path.Path()); if (!dir.Contains("HeaderTemplates")) dir.CreateDirectory("HeaderTemplates", NULL); path.Append("HeaderTemplates"); dir.SetTo(path.Path()); return B_OK; }
status_t Snapshot::MakeDefaultSettings (void) { // snapshot folder status_t status = B_OK; status = find_directory(B_USER_DIRECTORY, & m_snapshot_dir_path, true); if (status != B_OK) return status; status = m_snapshot_dir_path.Append("Snapshots"); if (status != B_OK) return status; // Other defaults // ... return B_OK; }
void LoadPrefs(void) { // Construct prefs path find_directory(B_USER_SETTINGS_DIRECTORY, &prefs_path, true); prefs_path.Append(PREFS_FILE_NAME); // Read preferences from settings file FILE *f = fopen(prefs_path.Path(), "r"); if (f != NULL) { // Prefs file found, load settings LoadPrefsFromStream(f); fclose(f); } else { // No prefs file, save defaults SavePrefs(); } }
void MediaReplicant::_SaveSettings() { BPath path; if (find_directory(B_USER_SETTINGS_DIRECTORY, &path, false) < B_OK) return; path.Append(kSettingsFile); BFile settings(path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE); if (settings.InitCheck() < B_OK) return; BMessage msg('CNFG'); msg.AddInt32("volwhich", fVolumeWhich); msg.AddBool("dontbeep", fDontBeep); ssize_t size = 0; msg.Flatten(&settings, &size); }
/** * Check that ~/.netsurf/ exists, and if it doesn't, create it. */ static void check_homedir(void) { status_t err; BPath path; err = find_directory(B_USER_SETTINGS_DIRECTORY, &path, true); if (err < B_OK) { /* we really can't continue without a home directory. */ LOG(("Can't find user settings directory - nowhere to store state!")); die("NetSurf needs to find the user settings directory in order to run.\n"); } path.Append("NetSurf"); err = create_directory(path.Path(), 0644); if (err < B_OK) { LOG(("Unable to create %s", path.Path())); die("NetSurf could not create its settings directory.\n"); } }
status_t AutoConfig::LoadProviderInfo(const BString &provider, provider_info* info) { BPath path; status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path); if (status != B_OK) return status; path.Append(INFO_DIR); BDirectory infoDir(path.Path()); BFile infoFile(&infoDir, provider.String(), B_READ_ONLY); if (infoFile.InitCheck() != B_OK) return B_ENTRY_NOT_FOUND; info->provider = provider; if (ReadProviderInfo(&infoFile, info) == true) return B_OK; return B_ERROR; }
/*! \brief Gets the next add-on directory path. \param path Pointer to a BPath to be set to the found directory. \param index Pointer to an index into the kAddOnDirs array indicating which add-on dir shall be retrieved next. \param subdir Name of the subdirectory (in the "disk_scanner" subdirectory of the add-on directory) \a directory shall be set to. \return - \c B_OK: Everything went fine. - \c B_ENTRY_NOT_FOUND: End of directory list. - other error codes */ status_t BDiskDeviceRoster::_GetNextAddOnDir(BPath *path, int32 *index, const char *subdir) { status_t error = (*index < kAddOnDirCount ? B_OK : B_ENTRY_NOT_FOUND); // get the add-on dir path if (error == B_OK) { error = find_directory(kAddOnDirs[*index], path); (*index)++; } // construct the subdirectory path if (error == B_OK) { error = path->Append("disk_scanner"); if (error == B_OK) error = path->Append(subdir); } if (error == B_OK) printf(" next add-on dir: `%s'\n", path->Path()); return error; }
status_t CDDBData::Save() { // This uses the default R5 path BPath path; if (find_directory(B_USER_DIRECTORY, &path, true) != B_OK) return B_ERROR; path.Append("cd"); create_directory(path.Path(), 0755); BString filename(path.Path()); filename << "/" << Artist() << " - " << Album(); if (filename.Compare("Artist")==0) filename << "." << DiscID(); return Save(filename.String()); }