void NetworkSetupWindow::_BuildProfilesMenu(BMenu* menu, int32 msg_what) { BMenuItem* item; char current_profile[256] = { 0 }; menu->SetRadioMode(true); BDirectory dir("/boot/common/settings/network/profiles"); if (dir.InitCheck() == B_OK) { BEntry entry; BMessage* msg; dir.Rewind(); while (dir.GetNextEntry(&entry) >= 0) { BPath name; entry.GetPath(&name); if (entry.IsSymLink() && strcmp("current", name.Leaf()) == 0) { BSymLink symlink(&entry); if (symlink.IsAbsolute()) // oh oh, sorry, wrong symlink... continue; symlink.ReadLink(current_profile, sizeof(current_profile)); continue; }; if (!entry.IsDirectory()) continue; msg = new BMessage(msg_what); msg->AddString("path", name.Path()); item = new BMenuItem(name.Leaf(), msg); menu->AddItem(item); } } menu->AddSeparatorItem(); menu->AddItem(new BMenuItem(B_TRANSLATE("New" B_UTF8_ELLIPSIS), new BMessage(kMsgProfileNew))); menu->AddItem(new BMenuItem(B_TRANSLATE("Manage" B_UTF8_ELLIPSIS), new BMessage(kMsgProfileManage))); if (strlen(current_profile)) { item = menu->FindItem(current_profile); if (item) { BString label; label << item->Label(); label << " (current)"; item->SetLabel(label.String()); item->SetMarked(true); } } }
bool SeqNavMenu::AddEntry(BEntry& entry, bool useLeafForLabel) { BPath path; if( entry.GetPath( &path ) != B_OK ) { printf("\tquery returned an entry but couldn't get the path\n"); return false; } const char* label = (useLeafForLabel) ? path.Leaf(): path.Path(); if( !label ) return false; _AmIconMenuItem* item = 0; uint32 tmpEntry; if( entry.IsDirectory() ) { tmpEntry = DIR_ENTRY; SeqNavMenu* nm = new SeqNavMenu( label, mTarget ); if( nm && (item = new _AmIconMenuItem( nm )) ) { nm->SetPath( path.Path() ); } } else { tmpEntry = OTHER_ENTRY; BMessage* msg = new BMessage( B_REFS_RECEIVED ); entry_ref ref; if( msg && (entry.GetRef( &ref ) == B_OK) ) { msg->AddRef( "refs", &ref ); item = new _AmIconMenuItem( label, msg ); } } if( item ) { mItems.push_back( item ); item->SetIcon( GetIcon( entry ) ); if( mFirstEntry == NO_ENTRY ) mFirstEntry = tmpEntry; } return true; }
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 NetworkSetupWindow::MessageReceived(BMessage* msg) { switch (msg->what) { case NEW_PROFILE_MSG: break; case COPY_PROFILE_MSG: break; case DELETE_PROFILE_MSG: { break; } case SELECT_PROFILE_MSG: { BPath name; const char *path; bool is_default; bool is_current; if (msg->FindString("path", &path) != B_OK) break; name.SetTo(path); is_default = (strcmp(name.Leaf(), "default") == 0); is_current = (strcmp(name.Leaf(), "current") == 0); fApplyNowButton->SetEnabled(!is_current); break; } case SHOW_MSG: { if (fAddonView) fAddonView->RemoveSelf(); fAddonView = NULL; if (msg->FindPointer("addon_view", (void **) &fAddonView) != B_OK) break; fPanel->AddChild(fAddonView); fAddonView->ResizeTo(fPanel->Bounds().Width(), fPanel->Bounds().Height()); break; } default: inherited::MessageReceived(msg); } }
void InspectorApp::AddToTranslatorsList(const char *folder, int32 group) { BDirectory dir; if (dir.SetTo(folder) == B_OK) { BEntry ent; while (dir.GetNextEntry(&ent) == B_OK) { BPath path; if (ent.GetPath(&path) == B_OK) flstTranslators.AddItem( new BTranslatorItem(path.Leaf(), path.Path(), group)); } } }
bool DeskbarView::_CreateMenuLinks(BDirectory& directory, BPath& path) { status_t status = directory.SetTo(path.Path()); if (status == B_OK) return true; // Check if the directory has to be created (and do it in this case, // filling it with some standard links). Normally the installer will // create the directory and fill it with links, so normally this doesn't // get used. BEntry entry(path.Path()); if (status != B_ENTRY_NOT_FOUND || entry.GetParent(&directory) < B_OK || directory.CreateDirectory(path.Leaf(), NULL) < B_OK || directory.SetTo(path.Path()) < B_OK) return false; BPath targetPath; find_directory(B_USER_DIRECTORY, &targetPath); targetPath.Append("mail/in"); directory.CreateSymLink("Open Inbox Folder", targetPath.Path(), NULL); targetPath.GetParent(&targetPath); directory.CreateSymLink("Open Mail Folder", targetPath.Path(), NULL); // create the draft query BFile file; if (directory.CreateFile("Open Draft", &file) < B_OK) return true; BString string("MAIL:draft==1"); file.WriteAttrString("_trk/qrystr", &string); string = "E-mail"; file.WriteAttrString("_trk/qryinitmime", &string); BNodeInfo(&file).SetType("application/x-vnd.Be-query"); return true; }
void DialUpView::LoadInterfaces() { fInterfaceMenu->AddSeparatorItem(); fInterfaceMenu->AddItem(new BMenuItem(kLabelCreateNewInterface, new BMessage(kMsgCreateNew))); fDeleterItem = new BMenuItem(kLabelDeleteCurrent, new BMessage(kMsgDeleteCurrent)); fInterfaceMenu->AddItem(fDeleterItem); BDirectory settingsDirectory; BEntry entry; BPath path; GetPPPDirectories(&settingsDirectory, NULL); while(settingsDirectory.GetNextEntry(&entry) == B_OK) { if(entry.IsFile()) { entry.GetPath(&path); AddInterface(path.Leaf(), true); } } }
const char *GetValidName(BEntry *entry) { // given a particular location, this will (1) check to see if said entry // exists and if it does, generates a filename which will work complete with // the full path. The entry is also set to this new, valid path BPath path; entry->GetPath(&path); if(entry->Exists()) { // separate into path and leaf char leafbase[B_FILE_NAME_LENGTH]; char newpath[B_PATH_NAME_LENGTH]; strcpy(leafbase, path.Leaf()); path.GetParent(&path); int32 attempt=1; do { if(attempt>1) sprintf(newpath, "%s/%s copy %ld", path.Path(),leafbase, attempt); else sprintf(newpath, "%s/%s copy", path.Path(),leafbase); entry->SetTo(newpath); attempt++; } while (entry->Exists()); return newpath; } return path.Path(); }
int32 PackageView::ItemExists(PackageItem& item, BPath& path, int32& policy) { int32 choice = P_EXISTS_NONE; switch (policy) { case P_EXISTS_OVERWRITE: choice = P_EXISTS_OVERWRITE; break; case P_EXISTS_SKIP: choice = P_EXISTS_SKIP; break; case P_EXISTS_ASK: case P_EXISTS_NONE: { const char* formatString; switch (item.ItemKind()) { case P_KIND_SCRIPT: formatString = B_TRANSLATE("The script named \'%s\' " "already exists in the given path.\nReplace the script " "with the one from this package or skip it?"); break; case P_KIND_FILE: formatString = B_TRANSLATE("The file named \'%s\' already " "exists in the given path.\nReplace the file with the " "one from this package or skip it?"); break; case P_KIND_DIRECTORY: formatString = B_TRANSLATE("The directory named \'%s\' " "already exists in the given path.\nReplace the " "directory with one from this package or skip it?"); break; case P_KIND_SYM_LINK: formatString = B_TRANSLATE("The symbolic link named \'%s\' " "already exists in the given path.\nReplace the link " "with the one from this package or skip it?"); break; default: formatString = B_TRANSLATE("The item named \'%s\' already " "exists in the given path.\nReplace the item with the " "one from this package or skip it?"); break; } char buffer[512]; snprintf(buffer, sizeof(buffer), formatString, path.Leaf()); BString alertString = buffer; BAlert* alert = new BAlert("file_exists", alertString.String(), B_TRANSLATE("Replace"), B_TRANSLATE("Skip"), B_TRANSLATE("Abort")); alert->SetShortcut(2, B_ESCAPE); choice = alert->Go(); switch (choice) { case 0: choice = P_EXISTS_OVERWRITE; break; case 1: choice = P_EXISTS_SKIP; break; default: return P_EXISTS_ABORT; } if (policy == P_EXISTS_NONE) { // TODO: Maybe add 'No, but ask again' type of choice as well? alertString = B_TRANSLATE("Do you want to remember this " "decision for the rest of this installation?\n"); BString actionString; if (choice == P_EXISTS_OVERWRITE) { alertString << B_TRANSLATE( "All existing files will be replaced?"); actionString = B_TRANSLATE("Replace all"); } else { alertString << B_TRANSLATE( "All existing files will be skipped?"); actionString = B_TRANSLATE("Skip all"); } alert = new BAlert("policy_decision", alertString.String(), actionString.String(), B_TRANSLATE("Ask again")); int32 decision = alert->Go(); if (decision == 0) policy = choice; else policy = P_EXISTS_ASK; } break; } } return choice; }
void ImageView::SetImage(BMessage *pmsg) { // Replace current image with the image // specified in the given BMessage entry_ref ref; if (!pmsg) ref = fcurrentRef; else if (pmsg->FindRef("refs", &ref) != B_OK) // If refs not found, just ignore the message return; StatusCheck chk; try { BFile file(&ref, B_READ_ONLY); chk = file.InitCheck(); BTranslatorRoster roster, *proster; proster = SelectTranslatorRoster(roster); if (!proster) // throw exception chk = B_ERROR; // determine what type the image is translator_info tinfo; BMessage ioExtension; if (ref != fcurrentRef) // if new image, reset to first document fdocumentIndex = 1; chk = ioExtension.AddInt32("/documentIndex", fdocumentIndex); chk = proster->Identify(&file, &ioExtension, &tinfo, 0, NULL, B_TRANSLATOR_BITMAP); // perform the actual translation BBitmapStream outstream; chk = proster->Translate(&file, &tinfo, &ioExtension, &outstream, B_TRANSLATOR_BITMAP); BBitmap *pbitmap = NULL; chk = outstream.DetachBitmap(&pbitmap); delete fpbitmap; fpbitmap = pbitmap; pbitmap = NULL; fcurrentRef = ref; // need to keep the ref around if user wants to switch pages int32 documentCount = 0; if (ioExtension.FindInt32("/documentCount", &documentCount) == B_OK && documentCount > 0) fdocumentCount = documentCount; else fdocumentCount = 1; // Set the name of the Window to reflect the file name BWindow *pwin = Window(); BEntry entry(&ref); BPath path; if (entry.InitCheck() == B_OK) { if (path.SetTo(&entry) == B_OK) pwin->SetTitle(path.Leaf()); else pwin->SetTitle(IMAGEWINDOW_TITLE); } else pwin->SetTitle(IMAGEWINDOW_TITLE); UpdateInfoWindow(path, ioExtension, tinfo, proster); // Resize parent window and set size limits to // reflect the size of the new bitmap float width, height; BMenuBar *pbar = pwin->KeyMenuBar(); width = fpbitmap->Bounds().Width() + B_V_SCROLL_BAR_WIDTH + (BORDER_WIDTH * 2); height = fpbitmap->Bounds().Height() + pbar->Bounds().Height() + B_H_SCROLL_BAR_HEIGHT + (BORDER_HEIGHT * 2) + 1; BScreen *pscreen = new BScreen(pwin); BRect rctscreen = pscreen->Frame(); if (width > rctscreen.Width()) width = rctscreen.Width(); if (height > rctscreen.Height()) height = rctscreen.Height(); pwin->SetSizeLimits(B_V_SCROLL_BAR_WIDTH * 4, width, pbar->Bounds().Height() + (B_H_SCROLL_BAR_HEIGHT * 4) + 1, height); pwin->SetZoomLimits(width, height); AdjustScrollBars(); //pwin->Zoom(); // Perform all of the hard work of resizing the // window while taking into account the size of // the screen, the tab and borders of the window // // HACK: Need to fix case where window un-zooms // when the window is already the correct size // for the current image // repaint view Invalidate(); } catch (StatusNotOKException) { BAlert *palert = new BAlert(NULL, B_TRANSLATE("Sorry, unable to load the image."), B_TRANSLATE("OK")); palert->Go(); } }
/* * Message Handling Function * If it's a node monitor message, * then figure out what to do based on it. * Otherwise, let BApplication handle it. */ void App::MessageReceived(BMessage *msg) { printf("message received:\n"); msg->PrintToStream(); switch(msg->what) { case MY_DELTA_CONST: { printf("Pulling changes from Dropbox\n"); pull_and_apply_deltas(); break; } case B_NODE_MONITOR: { printf("Received Node Monitor Alert\n"); status_t err; int32 opcode; err = msg->FindInt32("opcode",&opcode); if(err == B_OK) { switch(opcode) { case B_ENTRY_CREATED: { printf("CREATED NEW FILE\n"); entry_ref ref; BPath path; const char * name; // unpack the message msg->FindInt32("device",&ref.device); msg->FindInt64("directory",&ref.directory); msg->FindString("name",&name); ref.set_name(name); BEntry new_file = BEntry(&ref); new_file.GetPath(&path); //if we said to ignore a `NEW` msg from the path, then ignore it if(this->ignore_created(&path)) return; this->track_file(&new_file); if(new_file.IsDirectory()) { add_folder_to_dropbox(path.Path()); BDirectory new_dir = BDirectory(&new_file); this->recursive_watch(&new_dir); } else { BString *result = add_file_to_dropbox(path.Path()); BString *real_path = parse_path(result); BString *parent_rev = parse_parent_rev(result); delete result; printf("path:|%s|\nparent_rev:|%s|\n",real_path->String(),parent_rev->String()); BNode node = BNode(&new_file); set_parent_rev(&node,parent_rev); delete parent_rev; BPath new_path = BPath(db_to_local_filepath(real_path->String()).String()); if(strcmp(new_path.Leaf(),path.Leaf()) != 0) { printf("moving %s to %s\n", path.Leaf(), new_path.Leaf()); BEntry entry = BEntry(path.Path()); //entry for local path status_t err = entry.Rename(new_path.Leaf(),true); if(err != B_OK) printf("error moving: %s\n",strerror(err)); } delete real_path; watch_entry(&new_file,B_WATCH_STAT); } break; } case B_ENTRY_MOVED: { printf("MOVED FILE\n"); entry_ref eref; BDirectory from_dir, to_dir; node_ref from_ref,to_ref,nref; BPath path; const char* name; msg->FindInt32("device",&from_ref.device); msg->FindInt32("device",&to_ref.device); msg->FindInt32("device",&eref.device); msg->FindInt32("device",&nref.device); msg->FindInt64("from directory",&from_ref.node); msg->FindInt64("to directory",&to_ref.node); msg->FindInt64("to directory",&eref.directory); msg->FindInt64("node",&nref.node); msg->FindString("name",&name); eref.set_name(name); err = from_dir.SetTo(&from_ref); err = to_dir.SetTo(&to_ref); BEntry dest_entry = BEntry(&eref); BEntry test = BEntry("/boot/home/Dropbox/hi"); BDirectory dropbox_local = BDirectory(local_path_string); bool into_dropbox = dropbox_local.Contains(&dest_entry); int32 index = this->find_nref_in_tracked_files(nref); if((index >= 0) && into_dropbox) { printf("moving within dropbox\n"); BPath *old_path = (BPath*)this->tracked_filepaths.ItemAt(index); BPath new_path; dest_entry.GetPath(&new_path); char *argv[3]; argv[0] = "db_mv.py"; BString opath = local_to_db_filepath(old_path->Path()); BString npath = local_to_db_filepath(new_path.Path()); char not_const_o[opath.CountChars()]; char not_const_n[npath.CountChars()]; strcpy(not_const_o,opath.String()); strcpy(not_const_n,npath.String()); argv[1] = not_const_o; argv[2] = not_const_n; run_python_script(argv,3); old_path->SetTo(&dest_entry); } else if(index >= 0) { printf("moving the file out of dropbox\n"); BPath *old_path = (BPath*)this->tracked_filepaths.ItemAt(index); delete_file_on_dropbox(old_path->Path()); this->tracked_files.RemoveItem(index); this->tracked_filepaths.RemoveItem(index); } else if(into_dropbox) { printf("moving file into dropbox\n"); BPath new_path; dest_entry.GetPath(&new_path); this->track_file(&dest_entry); if(dest_entry.IsDirectory()) { add_folder_to_dropbox(new_path.Path()); BDirectory new_dir = BDirectory(&dest_entry); this->recursive_watch(&new_dir); } else { add_file_to_dropbox(new_path.Path()); watch_entry(&dest_entry,B_WATCH_STAT); } } else { printf("moving unrelated file...?\n"); } break; } case B_ENTRY_REMOVED: { printf("DELETED FILE\n"); node_ref nref; msg->FindInt32("device", &nref.device); msg->FindInt64("node", &nref.node); int32 index = this->find_nref_in_tracked_files(nref); if(index >= 0) { BPath *path = (BPath*)this->tracked_filepaths.ItemAt(index); printf("local file %s deleted\n",path->Path()); if(ignore_removed(path)) return; delete_file_on_dropbox(path->Path()); this->tracked_files.RemoveItem(index); this->tracked_filepaths.RemoveItem(index); } else { printf("could not find deleted file\n"); } break; } case B_STAT_CHANGED: { printf("EDITED FILE\n"); node_ref nref; msg->FindInt32("device", &nref.device); msg->FindInt64("node", &nref.node); int32 index = this->find_nref_in_tracked_files(nref); if(index >= 0) { BPath *path = (BPath*)this->tracked_filepaths.ItemAt(index); if(ignore_edited(path)) return; BNode node = BNode(path->Path()); BString * rev = get_parent_rev(&node); printf("parent_rev:|%s|\n",rev->String()); update_file_in_dropbox(path->Path(),rev->String()); } else { printf("Could not find edited file\n"); } break; } default: { printf("default case opcode...\n"); } } } break; } default: { BApplication::MessageReceived(msg); break; } } }
void BeAccessibleWindow::OpenDatabase(BPath path) { //If a database is already open, close it before opening a new one. if (GlobalSQLMgr->IsOpen()) CloseDatabase(); //Open the given database bool databaseOpened = GlobalSQLMgr->Open(path.Path()); if (databaseOpened) { //Add database to list of recently opened files BeAccessibleApp* myApp = static_cast<BeAccessibleApp*>(be_app); myApp->AddToRecentFiles(new BString(path.Path())); //Create the beaccessible_master table if it's not there if (!GlobalSQLMgr->TableExists("beaccessible_master")) { BString sql = "create table beaccessible_master (name Text, type Text, " "value Text, primary key (name, type));"; GlobalSQLMgr->Execute(sql.String()); } } Lock(); //Change title of window to include database name BString newTitle("BeAccessible : "); newTitle += path.Leaf(); SetTitle(newTitle.String()); //Create tab for Tables (hopefully someday Queries, too!) BRect frame = Bounds(); BRect menuHeight = fMenuBar->Bounds(); frame.top += menuHeight.Height() + 1; frame.InsetBy(10.0, 10.0); const char* tabNames[1] = {"Tables"}; fTabView = new TabView(frame, NULL, tabNames, 1, B_FOLLOW_ALL_SIDES); fTabView->SetViewColor(216,216,216,0); BRect ContentRect = fTabView->GetContentArea(); ContentRect.InsetBy(5,5); fTableTab = new DBTabView(ContentRect, "Table"); BView* tabs[1]; tabs[0] = (BView*)fTableTab; fTabView->AddViews(tabs); fMainView->AddChild(fTabView); //Select the first table as default fTableTab->fListView->Select(0); //Enable certain menu items since there is now a database open EnableMenuItems(); Unlock(); // Save the database's full path to a string fPath->SetTo(path.Path()); }
void TMailApp::ReadyToRun() { // Create needed indices for META:group, META:email, MAIL:draft, // INDEX_SIGNATURE, INDEX_STATUS on the boot volume BVolume volume; BVolumeRoster().GetBootVolume(&volume); fs_create_index(volume.Device(), "META:group", B_STRING_TYPE, 0); fs_create_index(volume.Device(), "META:email", B_STRING_TYPE, 0); fs_create_index(volume.Device(), "MAIL:draft", B_INT32_TYPE, 0); fs_create_index(volume.Device(), INDEX_SIGNATURE, B_STRING_TYPE, 0); fs_create_index(volume.Device(), INDEX_STATUS, B_STRING_TYPE, 0); fs_create_index(volume.Device(), B_MAIL_ATTR_FLAGS, B_INT32_TYPE, 0); // Start people queries fPeopleQueryList.Init("META:email=**"); // Load dictionaries BPath indexDir; BPath dictionaryDir; BPath userDictionaryDir; BPath userIndexDir; BPath dataPath; BPath indexPath; BDirectory directory; BEntry entry; // Locate dictionaries directory find_directory(B_SYSTEM_DATA_DIRECTORY, &indexDir, true); indexDir.Append("spell_check"); dictionaryDir = indexDir; //Locate user dictionary directory find_directory(B_USER_CONFIG_DIRECTORY, &userIndexDir, true); userIndexDir.Append("data/spell_check"); userDictionaryDir = userIndexDir; // Create directory if needed directory.CreateDirectory(userIndexDir.Path(), NULL); // Setup directory paths indexDir.Append(kIndexDirectory); dictionaryDir.Append(kDictDirectory); userIndexDir.Append(kIndexDirectory); userDictionaryDir.Append(kDictDirectory); // Create directories if needed directory.CreateDirectory(indexDir.Path(), NULL); directory.CreateDirectory(dictionaryDir.Path(), NULL); directory.CreateDirectory(userIndexDir.Path(), NULL); directory.CreateDirectory(userDictionaryDir.Path(), NULL); dataPath = dictionaryDir; dataPath.Append("words"); // Only Load if Words Dictionary if (BEntry(kWordsPath).Exists() || BEntry(dataPath.Path()).Exists()) { // If "/boot/optional/goodies/words" exists but there is no // system dictionary, copy words if (!BEntry(dataPath.Path()).Exists() && BEntry(kWordsPath).Exists()) { BFile words(kWordsPath, B_READ_ONLY); BFile copy(dataPath.Path(), B_WRITE_ONLY | B_CREATE_FILE); char buffer[4096]; ssize_t size; while ((size = words.Read( buffer, 4096)) > 0) copy.Write(buffer, size); BNodeInfo(©).SetType("text/plain"); } // Load dictionaries directory.SetTo(dictionaryDir.Path()); BString leafName; gUserDict = -1; while (gDictCount < MAX_DICTIONARIES && directory.GetNextEntry(&entry) != B_ENTRY_NOT_FOUND) { dataPath.SetTo(&entry); indexPath = indexDir; leafName.SetTo(dataPath.Leaf()); leafName.Append(kMetaphone); indexPath.Append(leafName.String()); gWords[gDictCount] = new Words(dataPath.Path(), indexPath.Path(), true); indexPath = indexDir; leafName.SetTo(dataPath.Leaf()); leafName.Append(kExact); indexPath.Append(leafName.String()); gExactWords[gDictCount] = new Words(dataPath.Path(), indexPath.Path(), false); gDictCount++; } // Create user dictionary if it does not exist dataPath = userDictionaryDir; dataPath.Append("user"); if (!BEntry(dataPath.Path()).Exists()) { BFile user(dataPath.Path(), B_WRITE_ONLY | B_CREATE_FILE); BNodeInfo(&user).SetType("text/plain"); } // Load user dictionary if (BEntry(userDictionaryDir.Path()).Exists()) { gUserDictFile = new BFile(dataPath.Path(), B_WRITE_ONLY | B_OPEN_AT_END); gUserDict = gDictCount; indexPath = userIndexDir; leafName.SetTo(dataPath.Leaf()); leafName.Append(kMetaphone); indexPath.Append(leafName.String()); gWords[gDictCount] = new Words(dataPath.Path(), indexPath.Path(), true); indexPath = userIndexDir; leafName.SetTo(dataPath.Leaf()); leafName.Append(kExact); indexPath.Append(leafName.String()); gExactWords[gDictCount] = new Words(dataPath.Path(), indexPath.Path(), false); gDictCount++; } } // Create a new window if starting up without any extra arguments. if (!fPrintHelpAndExit && !fWindowCount) { TMailWindow *window; window = NewWindow(); window->Show(); } }
void ImmersiveVideoWindow::LoadPlugins(void) { image_id addonId; status_t err = B_NO_ERROR; ImmersiveVideoPlugin* aktPlugin=NULL; ImmersiveVideoPlugin* (*NewImmersiveVideoPlugin)(image_id); app_info info; BFile *file; BPath path; BPath *configPath = new BPath(); BPath *pluginPath = new BPath(); BEntry *entry =new BEntry(); find_directory(B_COMMON_SETTINGS_DIRECTORY,pluginPath,false,NULL); pluginPath->Append("Immersive Video/plugins"); /*pfad von der Anwendung besorgen, von der aus ein ImmersiveVideoWindow aufgerufen wurde*/ /* be_app->GetAppInfo(&info); BEntry entry(&info.ref); entry.GetPath(&path); path.GetParent(&path); //in das Unterverzeichniss "Plugins wechseln" path.Append("plugins");*/ BDirectory dir(pluginPath->Path()); printf("Laden der Plugins..\n"); /*config Pfad holen*/ find_directory(B_COMMON_SETTINGS_DIRECTORY,configPath,false,NULL); configPath->Append("Immersive Video/config"); BDirectory configDir(configPath->Path()); /*alle Dateien in diesem Verzeichniss durchlaufen und jede Datei überprüfen ob sie ein gültiges Plugin ist. ?muss ich vorher testen ob der Pfadgültig ist ?*/ while( err == B_NO_ERROR ) { // nächsten Verweis auf eine Datei auslesen err = dir.GetNextEntry(entry, TRUE ); //testen ob es ein gültiger Verweis ist if( entry->InitCheck() != B_NO_ERROR ) { break; } //einen Pfad(+Dateiname) von dem aktuellen Verweis erstellen lassen ->Path if( entry->GetPath(&path) != B_NO_ERROR ) { //printf( "entry.GetPath failed\n" ); } else { //Versuch die über path angegebene Datei als Addon zu laden addonId = load_add_on( path.Path() ); if( addonId < 0 ) { //Wenns schief ging, kein Poblem, dann wars irgendeine andere Datei //printf( "load_add_on( %s ) failed\n", path.Path() ); } else { //wenns geklappt hatt dann kleine Naricht auf stdout printf( "\t%s\t\tloaded\n", path.Leaf()); /*überprüfen ob es ein Addon war, welches unsere Schnittstelle entspricht Schnittstelle heist hier NewImmersiveVideoPlugin und es muss mit dem Protypen (void **)NewImmersiveVideoPlugin gekennzeichnet*/ if( get_image_symbol( addonId, "NewImmersiveVideoPlugin", B_SYMBOL_TYPE_TEXT, (void **)&NewImmersiveVideoPlugin) ) { // wenn wir ein ungülitges Plugin geladen hatten, wieder wegwerfen ;-) //printf( "get_image_symbol( NewImmersiveVideoPlugin ) failed\n" ); unload_add_on(addonId ); } else { //ansonsten von dem geleadenen Plugin mit der addonID ein gültiges Objekt erzeugen aktPlugin = (*NewImmersiveVideoPlugin)( addonId ); if( !aktPlugin ) { printf( "failed to create a new plugin\n" ); } else { file=new BFile(&configDir,aktPlugin->GetName(),B_READ_ONLY); if (file->InitCheck()==B_OK) { //BMessage laden welches alle Einstellungen enhält BMessage *archive=new BMessage(); archive->Unflatten(file); //daraus das Plugin alles bauen lassen, was es benötigt aktPlugin->Init(archive); delete archive; archive=NULL; } else { //wenn keine Configdatei gefunden wurde, wird das Plugin "pur" initialisiert aktPlugin->Init(); } // pluginWindow = new PluginWin(this,aktPlugin); //aktuelles Plugin der Liste (in diesm Fall der Grafischen Liste) als Eintrag hinzufügen listView->AddItem(new PluginItem(aktPlugin)); } } } } } listView->Select(0); }
BPopUpMenu* DeskbarView::_BuildMenu() { BPopUpMenu* menu = new BPopUpMenu(B_EMPTY_STRING, false, false); menu->SetFont(be_plain_font); menu->AddItem(new BMenuItem(MDR_DIALECT_CHOICE ( "Create new message", "N) 新規メッセージ作成")B_UTF8_ELLIPSIS, new BMessage(MD_OPEN_NEW))); menu->AddSeparatorItem(); BMessenger tracker(kTrackerSignature); BNavMenu* navMenu; BMenuItem* item; BMessage* msg; entry_ref ref; BPath path; find_directory(B_USER_SETTINGS_DIRECTORY, &path); path.Append("Mail/Menu Links"); BDirectory directory; if (_CreateMenuLinks(directory, path)) { int32 count = 0; while (directory.GetNextRef(&ref) == B_OK) { count++; path.SetTo(&ref); // the true here dereferences the symlinks all the way :) BEntry entry(&ref, true); // do we want to use the NavMenu, or just an ordinary BMenuItem? // we are using the NavMenu only for directories and queries bool useNavMenu = false; if (entry.InitCheck() == B_OK) { if (entry.IsDirectory()) useNavMenu = true; else if (entry.IsFile()) { // Files should use the BMenuItem unless they are queries char mimeString[B_MIME_TYPE_LENGTH]; BNode node(&entry); BNodeInfo info(&node); if (info.GetType(mimeString) == B_OK && strcmp(mimeString, "application/x-vnd.Be-query") == 0) useNavMenu = true; } // clobber the existing ref only if the symlink derefernces // completely, otherwise we'll stick with what we have entry.GetRef(&ref); } msg = new BMessage(B_REFS_RECEIVED); msg->AddRef("refs", &ref); if (useNavMenu) { item = new BMenuItem(navMenu = new BNavMenu(path.Leaf(), B_REFS_RECEIVED, tracker), msg); navMenu->SetNavDir(&ref); } else item = new BMenuItem(path.Leaf(), msg); menu->AddItem(item); if(entry.InitCheck() != B_OK) item->SetEnabled(false); } if (count > 0) menu->AddSeparatorItem(); } // Hack for R5's buggy Query Notification #ifdef HAIKU_TARGET_PLATFORM_BEOS menu->AddItem(new BMenuItem( MDR_DIALECT_CHOICE("Refresh New Mail Count", "未読メールカウントを更新"), new BMessage(MD_REFRESH_QUERY))); #endif // The New E-mail query if (fNewMessages > 0) { BString string; MDR_DIALECT_CHOICE( string << fNewMessages << " new message" << (fNewMessages != 1 ? "s" : B_EMPTY_STRING), string << fNewMessages << " 通の未読メッセージ"); _GetNewQueryRef(ref); item = new BMenuItem(navMenu = new BNavMenu(string.String(), B_REFS_RECEIVED, BMessenger(kTrackerSignature)), msg = new BMessage(B_REFS_RECEIVED)); msg->AddRef("refs", &ref); navMenu->SetNavDir(&ref); menu->AddItem(item); } else { menu->AddItem(item = new BMenuItem( MDR_DIALECT_CHOICE ("No new messages","未読メッセージなし"), NULL)); item->SetEnabled(false); } BMailAccounts accounts; if (modifiers() & B_SHIFT_KEY) { BMenu *accountMenu = new BMenu( MDR_DIALECT_CHOICE ("Check for mails only","R) メール受信のみ")); BFont font; menu->GetFont(&font); accountMenu->SetFont(&font); for (int32 i = 0; i < accounts.CountAccounts(); i++) { BMailAccountSettings* account = accounts.AccountAt(i); BMessage* message = new BMessage(MD_CHECK_FOR_MAILS); message->AddInt32("account", account->AccountID()); accountMenu->AddItem(new BMenuItem(account->Name(), message)); } if (accounts.CountAccounts() == 0) { item = new BMenuItem("<no accounts>", NULL); item->SetEnabled(false); accountMenu->AddItem(item); } accountMenu->SetTargetForItems(this); menu->AddItem(new BMenuItem(accountMenu, new BMessage(MD_CHECK_FOR_MAILS))); // Not used: // menu->AddItem(new BMenuItem(MDR_DIALECT_CHOICE ( // "Check For Mails Only","メール受信のみ"), new BMessage(MD_CHECK_FOR_MAILS))); menu->AddItem(new BMenuItem( MDR_DIALECT_CHOICE ("Send pending mails", "M) 保留メールを送信"), new BMessage(MD_SEND_MAILS))); } else { menu->AddItem(item = new BMenuItem( MDR_DIALECT_CHOICE ("Check for mail now", "C) メールチェック"), new BMessage(MD_CHECK_SEND_NOW))); if (accounts.CountAccounts() == 0) item->SetEnabled(false); } menu->AddSeparatorItem(); menu->AddItem(new BMenuItem( MDR_DIALECT_CHOICE ("Preferences", "P) メール環境設定") B_UTF8_ELLIPSIS, new BMessage(MD_OPEN_PREFS))); if (modifiers() & B_SHIFT_KEY) { menu->AddItem(new BMenuItem( MDR_DIALECT_CHOICE ("Shutdown mail services", "Q) 終了"), new BMessage(B_QUIT_REQUESTED))); } // Reset Item Targets (only those which aren't already set) for (int32 i = menu->CountItems(); i-- > 0;) { item = menu->ItemAt(i); if (item && (msg = item->Message()) != NULL) { if (msg->what == B_REFS_RECEIVED) item->SetTarget(tracker); else item->SetTarget(this); } } return menu; }
/*********************************************************** * SaveMails ***********************************************************/ void HDaemonApp::SaveMail(const char* all_content, entry_ref* folder_ref, entry_ref *file_ref, bool *is_delete) { fGotMails = true; if(!fHaveNewMails) fHaveNewMails = true; BString header(""),subject(""),to(""),date(""),cc(""),from("") ,priority(""),reply(""),mime(""); Encoding encode; bool is_multipart = false; int32 org_len = strlen(all_content); // Probably deleted with Spam filter if(org_len == 0) { *is_delete = false; return; } // int32 header_len = 0; for(int32 i = 0;i < org_len;i++) { if(strncasecmp(&all_content[i],"Subject:",8) == 0 && all_content[i-1] == '\n') i = GetHeaderParam(subject,all_content,i+8); else if(strncasecmp(&all_content[i],"Date:",5) == 0 && all_content[i-1] == '\n') i = GetHeaderParam(date,all_content,i+5); else if(strncasecmp(&all_content[i],"Cc:",3) == 0 && all_content[i-1] == '\n') i = GetHeaderParam(cc,all_content,i+3); else if(strncasecmp(&all_content[i],"To:",3) == 0 && all_content[i-1] == '\n') i = GetHeaderParam(to,all_content,i+3); else if(strncasecmp(&all_content[i],"From:",5) == 0 && all_content[i-1] == '\n') i = GetHeaderParam(from,all_content,i+5); else if(strncasecmp(&all_content[i],"X-Priority:",11) == 0 && all_content[i-1] == '\n') i = GetHeaderParam(priority,all_content,i+11); else if(strncasecmp(&all_content[i],"Mime-Version:",13) == 0 && all_content[i-1] == '\n') i = GetHeaderParam(mime,all_content,i+13); else if(strncasecmp(&all_content[i],"Reply-To:",9) == 0 && all_content[i-1] == '\n') i = GetHeaderParam(reply,all_content,i+9); else if(all_content[i] == '\r'||all_content[i] == '\n') { if(all_content[i-2] == '\r'||all_content[i-1] == '\n') { header_len = i+2; break; } } } header.Append(all_content,header_len); if(subject.Length() == 0) subject = "Untitled"; if(strstr(header.String(),"Content-Type: multipart")) is_multipart = true; //PRINT(("From:%s\n",from.String())); encode.Mime2UTF8(from); //PRINT(("Decoded From:%s\n",from.String())); encode.Mime2UTF8(to); encode.Mime2UTF8(cc); encode.Mime2UTF8(reply); // convert mime subject to UTF8 encode.Mime2UTF8(subject); // Filter mails BString folder_path; FilterMail(subject.String(), from.String(), to.String(), cc.String(), reply.String(), folder_path); //PRINT(("path:%s\n",folder_path.String() )); // Save to disk BPath path = folder_path.String(); ::create_directory(path.Path(),0777); BDirectory destDir(path.Path()); path.Append(subject.String()); //PRINT(("path:%s\n",path.Path() )); // create the e-mail file BFile file; TrackerUtils().SmartCreateFile(&file,&destDir,path.Leaf(),"_"); // write e-mail attributes file.Write(all_content,strlen(all_content)); file.SetSize(strlen(all_content)); file.WriteAttr(B_MAIL_ATTR_STATUS,B_STRING_TYPE,0,"New",4); file.WriteAttrString(B_MAIL_ATTR_PRIORITY,&priority); file.WriteAttrString(B_MAIL_ATTR_TO,&to); file.WriteAttrString(B_MAIL_ATTR_CC,&cc); file.WriteAttrString(B_MAIL_ATTR_FROM,&from); file.WriteAttrString(B_MAIL_ATTR_SUBJECT,&subject); file.WriteAttrString(B_MAIL_ATTR_REPLY,&reply); file.WriteAttrString(B_MAIL_ATTR_MIME,&mime); file.WriteAttr(B_MAIL_ATTR_ATTACHMENT,B_BOOL_TYPE,0,&is_multipart,sizeof(bool)); int32 content_len = strlen(all_content)-header_len; //PRINT(("header:%d, content%d\n",header_len,content_len)); file.WriteAttr(B_MAIL_ATTR_HEADER,B_INT32_TYPE,0,&header_len,sizeof(int32)); file.WriteAttr(B_MAIL_ATTR_CONTENT,B_INT32_TYPE,0,&content_len,sizeof(int32)); time_t when = MakeTime_t(date.String()); time_t now = time(NULL); float diff = difftime(now,when); switch(fRetrievingType ) { case 0: *is_delete = false; break; case 1: *is_delete = true; break; case 2: *is_delete = ( diff/3600 > fDeleteDays*24)?true:false; break; } file.WriteAttr(B_MAIL_ATTR_WHEN,B_TIME_TYPE,0,&when,sizeof(time_t)); BNodeInfo ninfo(&file); ninfo.SetType("text/x-email"); entry_ref ref; ::get_ref_for_path(path.Path(),&ref); *file_ref = ref; AddNewMail(new BEntry(file_ref)); path.GetParent(&path); ::get_ref_for_path(path.Path(),&ref); *folder_ref =ref; return; }
void MediaConverterApp::_RunConvert() { bigtime_t start = 0; bigtime_t end = 0; int32 audioQuality = 75; int32 videoQuality = 75; if (fWin->Lock()) { char *a; start = strtoimax(fWin->StartDuration(), &a, 0) * 1000; end = strtoimax(fWin->EndDuration(), &a, 0) * 1000; audioQuality = fWin->AudioQuality(); videoQuality = fWin->VideoQuality(); fWin->Unlock(); } int32 srcIndex = 0; BMediaFile *inFile(NULL), *outFile(NULL); BEntry outEntry; entry_ref inRef; entry_ref outRef; BPath path; BString name; while (!fCancel) { if (fWin->Lock()) { status_t r = fWin->GetSourceFileAt(srcIndex, &inFile, &inRef); if (r == B_OK) { media_codec_info* audioCodec; media_codec_info* videoCodec; media_file_format* fileFormat; fWin->GetSelectedFormatInfo(&fileFormat, &audioCodec, &videoCodec); BDirectory directory = fWin->OutputDirectory(); fWin->Unlock(); outEntry = _CreateOutputFile(directory, &inRef, fileFormat); // display file name outEntry.GetPath(&path); name.SetTo(path.Leaf()); if (outEntry.InitCheck() == B_OK) { entry_ref outRef; outEntry.GetRef(&outRef); outFile = new BMediaFile(&outRef, fileFormat); BString tmp( B_TRANSLATE("Output file '%filename' created")); tmp.ReplaceAll("%filename", name); name = tmp; } else { BString tmp(B_TRANSLATE("Error creating '%filename'")); tmp.ReplaceAll("%filename", name); name = tmp; } if (fWin->Lock()) { fWin->SetFileMessage(name.String()); fWin->Unlock(); } if (outFile != NULL) { r = _ConvertFile(inFile, outFile, audioCodec, videoCodec, audioQuality, videoQuality, start, end); // set mime update_mime_info(path.Path(), false, false, false); fWin->Lock(); if (r == B_OK) { fWin->RemoveSourceFile(srcIndex); } else { srcIndex++; BString error( B_TRANSLATE("Error converting '%filename'")); error.ReplaceAll("%filename", inRef.name); fWin->SetStatusMessage(error.String()); } fWin->Unlock(); } } else { fWin->Unlock(); break; } } else { break; } } BMessenger(this).SendMessage(CONVERSION_DONE_MESSAGE); }
/*! \brief Constructor for the ActivityWindow class. * \param[in] data The data to be displayed. * \param[in] target The process to be notified about user's choise. * \param[in] name Name of the Event. * \param[in] category Category of the Event. * \param[in] templateMessage The message to be sent to the target. * If \c NULL is passed, then a new message is constructed * with \c kActivityWindowRepsonceMessage value in \c what. * \param[in] reminder \c true if the window is constructed for a reminder, else * \c false. Actually, it matters only for explanation to user. * Default is \c false (it's not a reminder). * \note A note on memory management: * \c data (the ActionData) belongs to the caller, but it's used only for * initialization of this window. I. e., if the user makes changes to the * data while an ActivityWindow is open, the changes won't be reflected. * However, \c target and \c templateMessage belong to this object. User * shouldn't free them or do anything else. */ ActivityWindow::ActivityWindow( ActivityData* data, BMessenger* target, BString name, Category* category, BMessage* templateMessage, bool reminder ) : BWindow( BRect( 0, 0, 400, 500 ), "Event occurred", B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS ), fTarget( target ), fData( data ), fTemplateMessage( templateMessage ), bIsReminder( reminder ), fLastError( B_OK ), fEventName( name ), fCategory( category ), fTitle( NULL ), fEventNameView( NULL ), fCategoryView( NULL ), fTextScroller( NULL ), fSnoozeTime( NULL ), fNoteText( NULL ), fSnooze( NULL ), fOk( NULL ) { BFont boldFont( be_bold_font ); BFont plainFont( be_plain_font ); BFont font; // For various font-related activities font_height fh; // For setting the height of the Text View with notification text plainFont.GetHeight( &fh ); int numberOfColumnsInLayout = 2; // Sanity check if ( !data || !target ) { /* Panic! */ fLastError = B_BAD_VALUE; return; } if ( ! fData->GetNotification( NULL ) && ! fData->GetSound( NULL ) && ! fData->GetProgram( NULL, NULL ) ) { // Nothing to do! This is not an error! fLastError = B_NO_INIT; return; } BView* background = new BView( Bounds(), "Background view", B_FOLLOW_ALL_SIDES, B_WILL_DRAW ); if ( !background ) { /* Panic! */ fLastError = B_NO_MEMORY; return; } this->AddChild( background ); BGridLayout* gridLayout = new BGridLayout(); if ( !gridLayout ) { /* Panic! */ fLastError = B_NO_MEMORY; return; } background->SetLayout( gridLayout ); background->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) ); gridLayout->SetInsets( 5, 5, 5, 5 ); /*------------------------------------------------- * First line - explaining what's happening here *------------------------------------------------*/ BStringView* exp = new BStringView( BRect( 0, 0, 1, 1 ), "Explanation 1", ( bIsReminder ? "A Reminder has occured!" : "An Event has occured!" ) ); if ( ! exp ) { /* Panic! */ fLastError = B_NO_MEMORY; return; } exp->SetFont( &boldFont ); exp->ResizeToPreferred(); BLayoutItem* layoutItem = gridLayout->AddView( exp, 0, 0, numberOfColumnsInLayout, 1 ); if ( layoutItem ) { layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_CENTER, B_ALIGN_TOP ) ); } /*----------------------------------------------------------------- * Second line - event's name on category's color as background *----------------------------------------------------------------*/ // Create background // Note: the pulse is requested for this Window to receive Pulse notifications. fBackground = new BView( BRect( 0, 0, 1, 1 ), "Background", B_FOLLOW_LEFT_RIGHT | B_FOLLOW_V_CENTER | B_PULSE_NEEDED, B_WILL_DRAW ); if ( !fBackground ) { /* Panic! */ fLastError = B_NO_MEMORY; return; } fBackground->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) ); layoutItem = gridLayout->AddView( fBackground, 0, 1, numberOfColumnsInLayout, 1 ); if ( layoutItem ) { layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_USE_FULL_WIDTH, B_ALIGN_USE_FULL_HEIGHT ) ); } BGroupLayout* bgLayout = new BGroupLayout( B_VERTICAL ); if ( !bgLayout ) { /* Panic! */ fLastError = B_NO_MEMORY; return; } fBackground->SetLayout( bgLayout ); bgLayout->SetInsets( 15, 10, 15, 10 ); fBackground->SetViewColor( fCategory.categoryColor ); BString sb = "Category:\n"; sb << fCategory.categoryName; fBackground->SetToolTip( sb.String() ); // Create Event's name view fTitle = new BStringView( BRect( 0, 0, 1, 1 ), "Event name", fEventName.String(), B_FOLLOW_H_CENTER | B_FOLLOW_V_CENTER ); if ( !fTitle ) { /* Panic! */ fLastError = B_NO_MEMORY; return; } // Use big bold font for Event's name fTitle->SetFont( be_bold_font ); fTitle->GetFont( &font ); font.SetSize( font.Size() + 2 ); fTitle->SetFont( &font, B_FONT_SIZE ); // Add the title and set its tooltip fTitle->ResizeToPreferred(); fTitle->SetToolTip( sb.String() ); bgLayout->AddView( fTitle ); fTitle->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) ); fTitle->SetToolTip( fEventName.String() ); int nextLineInLayout = 2; /*================================================================ * If the notification was set by the user, display it. *================================================================*/ BString tempString; BPath path; float rectHeight = fh.leading + fh.ascent + fh.descent; float rectWidth = this->Bounds().Width() - 10; // Layout insets BSize size( rectWidth, rectHeight ); if ( fData->GetNotification( &tempString ) ) { /*----------------------------------------------------------------- * Line of explanation *----------------------------------------------------------------*/ exp = new BStringView( BRect( 0, 0, 1, 1 ), "Text view explanation", "You set the following notification:" ); if ( !exp ) { /* Panic! */ fLastError = B_NO_MEMORY; return; } exp->ResizeToPreferred(); layoutItem = gridLayout->AddView( exp, 0, nextLineInLayout++, numberOfColumnsInLayout, 1 ); /*----------------------------------------------------------------- * Text view with notification text *----------------------------------------------------------------*/ BRect tempRect( BPoint( 0, 0 ), size ); tempRect.right -= B_V_SCROLL_BAR_WIDTH; fNoteText = new BTextView( tempRect, "Notification text container", tempRect.InsetByCopy( 1, 1 ), B_FOLLOW_ALL_SIDES, B_WILL_DRAW ); if ( !fNoteText ) { /* Panic! */ fLastError = B_NO_MEMORY; return; } fNoteText->MakeEditable( false ); fNoteText->SetText( tempString.String() ); /*----------------------------------------------------------------- * Scroll view to scroll the notification text *----------------------------------------------------------------*/ fTextScroller = new BScrollView( "Notification text scroller", fNoteText, B_FOLLOW_ALL_SIDES, 0, false, true ); if ( !fTextScroller ) { /* Panic! */ fLastError = B_NO_MEMORY; return; } layoutItem = gridLayout->AddView( fTextScroller, 0, nextLineInLayout++, numberOfColumnsInLayout, 1 ); if ( layoutItem ) { // layoutItem->SetExplicitMaxSize( size ); layoutItem->SetExplicitMinSize( size ); layoutItem->SetExplicitPreferredSize( size ); layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_USE_FULL_WIDTH, B_ALIGN_USE_FULL_HEIGHT ) ); } } // <-- end of adding information about the notification /*================================================================ * If user wanted to play a sound file, notify him about it. *================================================================*/ if ( fData->GetSound( &path ) ) { /*----------------------------------------------------------------- * Line of explanation *----------------------------------------------------------------*/ exp = new BStringView( BRect( 0, 0, 1, 1 ), "Sound file explanation", "You wanted to play the file:", B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP ); if ( !exp ) { /* Panic! */ fLastError = B_NO_MEMORY; return; } exp->ResizeToPreferred(); layoutItem = gridLayout->AddView( exp, 0, nextLineInLayout++, numberOfColumnsInLayout, 1 ); if ( layoutItem ) { layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_CENTER, B_ALIGN_MIDDLE ) ); } /*----------------------------------------------------------------- * Display sound file name *----------------------------------------------------------------*/ // What should we display - full path or just the leaf? if ( ( size.width - 10 ) > plainFont.StringWidth( path.Path() ) ) { tempString.SetTo( path.Path() ); } else { tempString.SetTo( path.Leaf() ); } exp = new BStringView( BRect( 0, 0, 1, 1 ), "Sound file name", tempString.String() ); if ( !exp ) { /* Panic! */ fLastError = B_NO_MEMORY; return; } exp->ResizeToPreferred(); layoutItem = gridLayout->AddView( exp, 0, nextLineInLayout++, numberOfColumnsInLayout, 1 ); if ( layoutItem ) { layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_CENTER, B_ALIGN_MIDDLE ) ); } } // <-- end of displaying information about the sound file /*================================================================ * If user wanted to run a program, notify him about it. *================================================================*/ if ( fData->GetProgram( &path, &tempString ) ) { /*----------------------------------------------------------------- * Line of explanation *----------------------------------------------------------------*/ exp = new BStringView( BRect( 0, 0, 1, 1 ), "Program explanation", "You wanted to run a program:" ); if ( !exp ) { /* Panic! */ fLastError = B_NO_MEMORY; return; } exp->ResizeToPreferred(); layoutItem = gridLayout->AddView( exp, 0, nextLineInLayout++, numberOfColumnsInLayout, 1 ); if ( layoutItem ) { layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_CENTER, B_ALIGN_MIDDLE ) ); } /*----------------------------------------------------------------- * Display path to program file *----------------------------------------------------------------*/ // What should we display - full path or just the leaf? exp = new BStringView( BRect( 0, 0, 1, 1 ), "Program file name", ( ( size.width - 10 ) > plainFont.StringWidth( path.Path() ) ) ? path.Path() : path.Leaf() ); if ( !exp ) { /* Panic! */ fLastError = B_NO_MEMORY; return; } exp->ResizeToPreferred(); layoutItem = gridLayout->AddView( exp, 0, nextLineInLayout++, numberOfColumnsInLayout, 1 ); if ( layoutItem ) { layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_CENTER, B_ALIGN_MIDDLE ) ); } /*----------------------------------------------------------------- * Explanation about the program options *----------------------------------------------------------------*/ if ( tempString.Length() > 0 ) { exp = new BStringView( BRect( 0, 0, 1, 1 ), "Program file options explanation", "With the following parameters:" ); if ( !exp ) { /* Panic! */ fLastError = B_NO_MEMORY; return; } exp->ResizeToPreferred(); layoutItem = gridLayout->AddView( exp, 0, nextLineInLayout++, numberOfColumnsInLayout, 1 ); if ( layoutItem ) { layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_CENTER, B_ALIGN_MIDDLE ) ); } /*----------------------------------------------------------------- * Display the program options *----------------------------------------------------------------*/ // What should we display - full path or just the leaf? exp = new BStringView( BRect( 0, 0, 1, 1 ), "Program file options", tempString.String() ); if ( !exp ) { /* Panic! */ fLastError = B_NO_MEMORY; return; } exp->ResizeToPreferred(); layoutItem = gridLayout->AddView( exp, 0, nextLineInLayout++, numberOfColumnsInLayout, 1 ); if ( layoutItem ) { layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_CENTER, B_ALIGN_MIDDLE ) ); } } // <-- end of diplaying CLI options } // <-- end of displaying information about the program to run /*================================================================ * Now it's time to display the Snooze time selector *================================================================*/ TimePreferences* prefs = pref_GetTimePreferences(); if ( prefs ) { prefs->GetDefaultSnoozeTime( ( int* )&fSnoozeHours, ( int* )&fSnoozeMins ); } else { fSnoozeHours = 0; fSnoozeMins = 10; } BMessage* toSend = new BMessage( kSnoozeTimeControlMessage ); if ( ! toSend ) { /* Panic! */ fLastError = B_NO_MEMORY; return; } fSnoozeTime = new GeneralHourMinControl( BRect( 0, 0, 1, 1 ), "Snooze time selector", "Snooze this Activtiy for:", BString( "" ), // No check box toSend ); if ( !fSnoozeTime ) { /* Panic! */ fLastError = B_NO_MEMORY; return; } fSnoozeTime->SetHoursLimit( 23 ); // Max reminder time delay is 23 hours 55 minutes fSnoozeTime->SetMinutesLimit( 55 ); fSnoozeTime->SetCurrentTime( fSnoozeHours, fSnoozeMins ); layoutItem = gridLayout->AddView( fSnoozeTime, 0, nextLineInLayout++, numberOfColumnsInLayout, 1 ); if ( layoutItem ) { layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_CENTER, B_ALIGN_MIDDLE ) ); } /*================================================================ * Snooze button *================================================================*/ toSend = new BMessage( kSnoozeButtonPressed ); if ( !toSend ) { /* Panic! */ fLastError = B_NO_MEMORY; return; } fSnooze = new BButton( BRect( 0, 0, 1, 1 ), "Snooze button", "Snooze", toSend, B_FOLLOW_LEFT | B_FOLLOW_TOP ); if ( !fSnooze ) { /* Panic! */ fLastError = B_NO_MEMORY; return; } fSnooze->ResizeToPreferred(); layoutItem = gridLayout->AddView( fSnooze, 0, nextLineInLayout ); if ( layoutItem ) { layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_LEFT, B_ALIGN_TOP ) ); } /*================================================================ * Ok button *================================================================*/ toSend = new BMessage( kDismissButtonPressed ); if ( !toSend ) { /* Panic! */ fLastError = B_NO_MEMORY; return; } fOk = new BButton( BRect( 0, 0, 1, 1 ), "Dismiss button", "Dismiss", toSend, B_FOLLOW_RIGHT | B_FOLLOW_TOP ); if ( !fOk ) { /* Panic! */ fLastError = B_NO_MEMORY; return; } fSnooze->ResizeToPreferred(); layoutItem = gridLayout->AddView( fOk, 1, nextLineInLayout ); if ( layoutItem ) { layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_RIGHT, B_ALIGN_TOP ) ); } this->CenterOnScreen(); } // <-- end of constructor for ActivityWindow
void NetworkWindow::_ScanAddOns() { BStringList paths; BPathFinder::FindPaths(B_FIND_PATH_ADD_ONS_DIRECTORY, "Network Settings", paths); // Collect add-on paths by name, so that each name will only be // loaded once. typedef std::map<BString, BPath> PathMap; PathMap addOnMap; for (int32 i = 0; i < paths.CountStrings(); i++) { BDirectory directory(paths.StringAt(i)); BEntry entry; while (directory.GetNextEntry(&entry) == B_OK) { BPath path; if (entry.GetPath(&path) != B_OK) continue; if (addOnMap.find(path.Leaf()) == addOnMap.end()) addOnMap.insert(std::pair<BString, BPath>(path.Leaf(), path)); } } for (PathMap::const_iterator addOnIterator = addOnMap.begin(); addOnIterator != addOnMap.end(); addOnIterator++) { const BPath& path = addOnIterator->second; image_id image = load_add_on(path.Path()); if (image < 0) { printf("Failed to load %s addon: %s.\n", path.Path(), strerror(image)); continue; } BNetworkSettingsAddOn* (*instantiateAddOn)(image_id image, BNetworkSettings& settings); status_t status = get_image_symbol(image, "instantiate_network_settings_add_on", B_SYMBOL_TYPE_TEXT, (void**)&instantiateAddOn); if (status != B_OK) { // No "addon instantiate function" symbol found in this addon printf("No symbol \"instantiate_network_settings_add_on\" found " "in %s addon: not a network setup addon!\n", path.Path()); unload_add_on(image); continue; } BNetworkSettingsAddOn* addOn = instantiateAddOn(image, fSettings); if (addOn == NULL) { unload_add_on(image); continue; } fAddOns.AddItem(addOn); // Per interface items ItemMap::const_iterator iterator = fInterfaceItemMap.begin(); for (; iterator != fInterfaceItemMap.end(); iterator++) { const BString& interface = iterator->first; BListItem* interfaceItem = iterator->second; uint32 cookie = 0; while (true) { BNetworkSettingsItem* item = addOn->CreateNextInterfaceItem( cookie, interface.String()); if (item == NULL) break; fSettingsMap[item->ListItem()] = item; fListView->AddUnder(item->ListItem(), interfaceItem); } fListView->SortItemsUnder(interfaceItem, true, NetworkWindow::_CompareListItems); } // Generic items uint32 cookie = 0; while (true) { BNetworkSettingsItem* item = addOn->CreateNextItem(cookie); if (item == NULL) break; fSettingsMap[item->ListItem()] = item; fListView->AddUnder(item->ListItem(), _ListItemFor(item->Type())); } _SortItemsUnder(fServicesItem); _SortItemsUnder(fDialUpItem); _SortItemsUnder(fOtherItem); } fListView->SortItemsUnder(NULL, true, NetworkWindow::_CompareTopLevelListItems); }
void DataTranslationsWindow::MessageReceived(BMessage *message) { switch (message->what) { case kMsgTranslatorInfo: { int32 selected = fTranslatorListView->CurrentSelection(0); if (selected < 0) { // If no translator is selected, show a message explaining // what the config panel is for (new BAlert("Panel Info", "Translation Settings\n\n" "Use this control panel to set values that various\n" "translators use when no other settings are specified\n" "in the application.", "OK"))->Go(); break; } TranslatorItem* item = dynamic_cast<TranslatorItem*>(fTranslatorListView->ItemAt(selected)); if (item != NULL) _ShowInfoAlert(item->ID()); break; } case kMsgSelectedTranslator: { // Update the icon and translator info panel // to match the new selection int32 selected = fTranslatorListView->CurrentSelection(0); if (selected < 0) { // If none selected, clear the old one fIconView->DrawIcon(false); fTranslatorNameView->SetText(""); fRightBox->RemoveChild(fConfigView); break; } TranslatorItem* item = dynamic_cast<TranslatorItem*>(fTranslatorListView->ItemAt(selected)); if (item == NULL) break; _ShowConfigView(item->ID()); const char* name = NULL; const char* info = NULL; int32 version = 0; BPath path; _GetTranslatorInfo(item->ID(), name, info, version, path); fTranslatorNameView->SetText(path.Leaf()); fIconView->SetIcon(path); break; } case B_TRANSLATOR_ADDED: { int32 index = 0, id; while (message->FindInt32("translator_id", index++, &id) == B_OK) { const char* name; const char* info; int32 version; BPath path; if (_GetTranslatorInfo(id, name, info, version, path) == B_OK) fTranslatorListView->AddItem(new TranslatorItem(id, name)); } fTranslatorListView->SortItems(); break; } case B_TRANSLATOR_REMOVED: { int32 index = 0, id; while (message->FindInt32("translator_id", index++, &id) == B_OK) { for (int32 i = 0; i < fTranslatorListView->CountItems(); i++) { TranslatorItem* item = dynamic_cast<TranslatorItem*>(fTranslatorListView->ItemAt(i)); if (item == NULL) continue; if (item->ID() == (translator_id)id) { fTranslatorListView->RemoveItem(i); delete item; break; } } } break; } default: BWindow::MessageReceived(message); break; } }
void PecoApp::RefsReceived ( BMessage* msg ) { entry_ref ref; BPath aPath; BEntry aEntry; off_t size; time_t timer; fWindow->Lock(); BTextControl* pfadView = (BTextControl *)fWindow->FindView("pfadView"); fWindow->Unlock(); //Pfad finden for ( int i=0; msg->FindRef("refs", i, &ref) == B_OK; i++ ) if ( ref.device > 1 ) break; if ( ref.device > 1 ) { New(); fWindow->Lock(); ((PecoApp *)be_app)->fStatusBar->SetText(STATUS_IMPORT); fWindow->Unlock(); aEntry = BEntry(&ref); BPath( &aEntry ).GetParent(&fPfad); fWindow->Lock(); pfadView->SetText( fPfad.Path() ); fWindow->Unlock(); //zählen type_code typeFound; long total = 0; msg->GetInfo("refs", &typeFound, &total); fWindow->Lock(); fStatusBar->SetMaxValue( total ); fWindow->Unlock(); BPath newPath; bool didntshow_msgmultidir = true; for ( int i=0; msg->FindRef("refs", i, &ref) == B_OK; i++ ) { fWindow->Lock(); fStatusBar->Update(1); fWindow->Unlock(); // Laufwerke ausfiltern if ( ref.device == 1 ) continue; // Dateien mit falschem Pfad ausfiltern aEntry = BEntry(&ref); aPath = BPath(&aEntry); BPath( &aEntry ).GetParent(&newPath); if ( (strcmp( fPfad.Path(), newPath.Path() ) != 0 ) ) { if ( didntshow_msgmultidir ) { BAlert* myAlert = new BAlert(NULL, MESSAGE_MULTIDIR, STR_OK); myAlert->Go(); didntshow_msgmultidir = false; } continue; } // Werte auslesen if (aEntry.IsFile()) aEntry.GetSize(&size); else if (aEntry.IsSymLink()) size = -1; else if (aEntry.IsDirectory()) size = -2; else continue; aEntry.GetModificationTime(&timer); fList->AddItem(new FileListItem(aPath.Leaf(), size, timer, &ref)); } fWindow->Lock(); fListView->AddList(fList); float Hoehe = be_plain_font->Size() + 2; if (Hoehe < 18) { BListItem* myListItem; for (int i=0; (myListItem = fListView->ItemAt(i)); i++) myListItem->SetHeight(18); // Zum Updaten: fListView->AddItem(myListItem = new BStringItem("")); fListView->RemoveItem(myListItem); } fStatusBar->Reset(STATUS_STATUS); fStatusBar->SetMaxValue(fList->CountItems()); fWindow->Unlock(); MakeList(); } fWindow->Activate(); UpdateWindowStatus(); }
void SoundPreferencesView::MessageReceived(BMessage *msg) { switch (msg->what) { case B_CANCEL: { uint32 what_was_i = msg->FindInt32("old_what"); if (what_was_i == NEW_MESSAGE_FILE_OPEN) { _old_new_message_item->SetMarked(true); } else if (what_was_i == MESSAGE_FILE_OPEN) { _old_message_item->SetMarked(true); } else if (what_was_i == USER_ONLINE_FILE_OPEN) { _old_user_online_item->SetMarked(true); } else if (what_was_i == USER_OFFLINE_FILE_OPEN) { _old_user_offline_item->SetMarked(true); } else if (what_was_i == ALERT_FILE_OPEN) { _old_alert_item->SetMarked(true); } break; } case JAB_PICK_NEW_MESSAGE_SOUND: { // just open file panel for now entry_ref sounds; get_ref_for_path(AppLocation::Instance()->AbsolutePath("resources/sounds").c_str(), &sounds); _fp = new BFilePanel(B_OPEN_PANEL, new BMessenger(this, Window()), &sounds, 0, false, new BMessage(NEW_MESSAGE_FILE_OPEN)); _fp->Show(); break; } case JAB_NO_NEW_MESSAGE_SOUND: { _old_new_message_item = _new_chat_selection->FindMarked(); SoundSystem::Instance()->SetNewMessageSound("<none>"); break; } case JAB_SELECTED_NEW_MESSAGE_SOUND: { _old_new_message_item = _new_chat_selection->FindMarked(); SoundSystem::Instance()->SetNewMessageSound(dynamic_cast<FileItem *>(_old_new_message_item)->Filename()); break; } case NEW_MESSAGE_FILE_OPEN: { entry_ref file; string filename; msg->FindRef("refs", &file); BEntry ent(&file); BPath path; ent.GetPath(&path); filename = path.Path(); SoundSystem::Instance()->SetNewMessageSound(filename); // add to menu FileItem *new_item = new FileItem(path.Leaf(), path.Path(), new BMessage(JAB_SELECTED_NEW_MESSAGE_SOUND)); _new_chat_selection->AddItem(new_item, 0); new_item->SetMarked(true); new_item->SetTarget(this); _old_new_message_item = _new_chat_selection->FindMarked(); break; } case JAB_PICK_MESSAGE_SOUND: { // just open file panel for now entry_ref sounds; get_ref_for_path(AppLocation::Instance()->AbsolutePath("resources/sounds").c_str(), &sounds); _fp = new BFilePanel(B_OPEN_PANEL, new BMessenger(this, Window()), &sounds, 0, false, new BMessage(MESSAGE_FILE_OPEN)); _fp->Show(); break; } case JAB_NO_MESSAGE_SOUND: { _old_message_item = _message_selection->FindMarked(); SoundSystem::Instance()->SetMessageSound("<none>"); break; } case JAB_SELECTED_MESSAGE_SOUND: { _old_message_item = _message_selection->FindMarked(); SoundSystem::Instance()->SetMessageSound(dynamic_cast<FileItem *>(_old_message_item)->Filename()); break; } case MESSAGE_FILE_OPEN: { entry_ref file; string filename; msg->FindRef("refs", &file); BEntry ent(&file); BPath path; ent.GetPath(&path); filename = path.Path(); SoundSystem::Instance()->SetMessageSound(filename); // add to menu FileItem *new_item = new FileItem(path.Leaf(), path.Path(), new BMessage(JAB_SELECTED_MESSAGE_SOUND)); _message_selection->AddItem(new_item, 0); new_item->SetMarked(true); new_item->SetTarget(this); _old_message_item = _message_selection->FindMarked(); break; } case JAB_PICK_USER_ONLINE_SOUND: { // just open file panel for now entry_ref sounds; get_ref_for_path(AppLocation::Instance()->AbsolutePath("resources/sounds").c_str(), &sounds); _fp = new BFilePanel(B_OPEN_PANEL, new BMessenger(this, Window()), &sounds, 0, false, new BMessage(USER_ONLINE_FILE_OPEN)); _fp->Show(); break; } case JAB_NO_USER_ONLINE_SOUND: { _old_user_online_item = _now_online_selection->FindMarked(); SoundSystem::Instance()->SetUserOnlineSound("<none>"); break; } case JAB_SELECTED_USER_ONLINE_SOUND: { _old_user_online_item = _now_online_selection->FindMarked(); SoundSystem::Instance()->SetUserOnlineSound(dynamic_cast<FileItem *>(_old_user_online_item)->Filename()); break; } case USER_ONLINE_FILE_OPEN: { entry_ref file; string filename; msg->FindRef("refs", &file); BEntry ent(&file); BPath path; ent.GetPath(&path); filename = path.Path(); SoundSystem::Instance()->SetUserOnlineSound(filename); // add to menu FileItem *new_item = new FileItem(path.Leaf(), path.Path(), new BMessage(JAB_SELECTED_USER_ONLINE_SOUND)); _now_online_selection->AddItem(new_item, 0); new_item->SetMarked(true); new_item->SetTarget(this); _old_user_online_item = _now_online_selection->FindMarked(); break; } case JAB_PICK_USER_OFFLINE_SOUND: { // just open file panel for now entry_ref sounds; get_ref_for_path(AppLocation::Instance()->AbsolutePath("resources/sounds").c_str(), &sounds); _fp = new BFilePanel(B_OPEN_PANEL, new BMessenger(this, Window()), &sounds, 0, false, new BMessage(USER_OFFLINE_FILE_OPEN)); _fp->Show(); break; } case JAB_NO_USER_OFFLINE_SOUND: { _old_user_offline_item = _now_offline_selection->FindMarked(); SoundSystem::Instance()->SetUserOfflineSound("<none>"); break; } case JAB_SELECTED_USER_OFFLINE_SOUND: { _old_user_offline_item = _now_offline_selection->FindMarked(); SoundSystem::Instance()->SetUserOfflineSound(dynamic_cast<FileItem *>(_old_user_offline_item)->Filename()); break; } case USER_OFFLINE_FILE_OPEN: { entry_ref file; string filename; msg->FindRef("refs", &file); BEntry ent(&file); BPath path; ent.GetPath(&path); filename = path.Path(); SoundSystem::Instance()->SetUserOfflineSound(filename); // add to menu FileItem *new_item = new FileItem(path.Leaf(), path.Path(), new BMessage(JAB_SELECTED_USER_OFFLINE_SOUND)); _now_offline_selection->AddItem(new_item, 0); new_item->SetMarked(true); new_item->SetTarget(this); _old_user_offline_item = _now_offline_selection->FindMarked(); break; } case JAB_PICK_ALERT_SOUND: { // just open file panel for now entry_ref sounds; get_ref_for_path(AppLocation::Instance()->AbsolutePath("resources/sounds").c_str(), &sounds); _fp = new BFilePanel(B_OPEN_PANEL, new BMessenger(this, Window()), &sounds, 0, false, new BMessage(ALERT_FILE_OPEN)); _fp->Show(); break; } case JAB_NO_ALERT_SOUND: { _old_alert_item = _alert_selection->FindMarked(); SoundSystem::Instance()->SetAlertSound("<none>"); break; } case JAB_SELECTED_ALERT_SOUND: { _old_alert_item = _alert_selection->FindMarked(); SoundSystem::Instance()->SetAlertSound(dynamic_cast<FileItem *>(_old_alert_item)->Filename()); break; } case ALERT_FILE_OPEN: { entry_ref file; string filename; msg->FindRef("refs", &file); BEntry ent(&file); BPath path; ent.GetPath(&path); filename = path.Path(); SoundSystem::Instance()->SetAlertSound(filename); // add to menu FileItem *new_item = new FileItem(path.Leaf(), path.Path(), new BMessage(JAB_SELECTED_ALERT_SOUND)); _alert_selection->AddItem(new_item, 0); new_item->SetMarked(true); new_item->SetTarget(this); _old_alert_item = _alert_selection->FindMarked(); break; } case TEST_NEW_CHAT: { SoundSystem::Instance()->PlayNewMessageSound(); break; } case TEST_MESSAGE: { SoundSystem::Instance()->PlayMessageSound(); break; } case TEST_ONLINE: { SoundSystem::Instance()->PlayUserOnlineSound(); break; } case TEST_OFFLINE: { SoundSystem::Instance()->PlayUserOfflineSound(); break; } case TEST_ALERT: { SoundSystem::Instance()->PlayAlertSound(); break; } } }
nsresult nsOSHelperAppService::SetMIMEInfoForType(const char *aMIMEType, nsMIMEInfoBeOS**_retval) { LOG(("-- nsOSHelperAppService::SetMIMEInfoForType: %s\n",aMIMEType)); nsresult rv = NS_ERROR_FAILURE; nsMIMEInfoBeOS* mimeInfo = new nsMIMEInfoBeOS(aMIMEType); if (mimeInfo) { NS_ADDREF(mimeInfo); BMimeType mimeType(aMIMEType); BMessage data; int32 index = 0; BString strData; LOG((" Adding extensions:\n")); if (mimeType.GetFileExtensions(&data) == B_OK) { while (data.FindString("extensions",index,&strData) == B_OK) { // if the file extension includes the '.' then we don't want to include that when we append // it to the mime info object. if (strData.ByteAt(0) == '.') strData.RemoveFirst("."); mimeInfo->AppendExtension(nsDependentCString(strData.String())); LOG((" %s\n",strData.String())); index++; } } char desc[B_MIME_TYPE_LENGTH + 1]; if (mimeType.GetShortDescription(desc) == B_OK) { mimeInfo->SetDescription(NS_ConvertUTF8toUCS2(desc)); } else { if (mimeType.GetLongDescription(desc) == B_OK) { mimeInfo->SetDescription(NS_ConvertUTF8toUCS2(desc)); } else { mimeInfo->SetDescription(NS_ConvertUTF8toUCS2(aMIMEType)); } } LOG((" Description: %s\n",desc)); //set preferred app and app description char appSig[B_MIME_TYPE_LENGTH + 1]; bool doSave = true; if (mimeType.GetPreferredApp(appSig) == B_OK) { LOG((" Got preferred ap\n")); BMimeType app(appSig); entry_ref ref; BEntry entry; BPath path; if ((app.GetAppHint(&ref) == B_OK) && (entry.SetTo(&ref, false) == B_OK) && (entry.GetPath(&path) == B_OK)) { LOG((" Got our path!\n")); nsCOMPtr<nsIFile> handlerFile; rv = GetFileTokenForPath(NS_ConvertUTF8toUCS2(path.Path()).get(), getter_AddRefs(handlerFile)); if (NS_SUCCEEDED(rv)) { mimeInfo->SetDefaultApplication(handlerFile); mimeInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault); mimeInfo->SetDefaultDescription(NS_ConvertUTF8toUCS2(path.Leaf())); LOG((" Preferred App: %s\n",path.Leaf())); doSave = false; } } } if (doSave) { mimeInfo->SetPreferredAction(nsIMIMEInfo::saveToDisk); LOG((" No Preferred App\n")); } *_retval = mimeInfo; rv = NS_OK; } else rv = NS_ERROR_FAILURE; return rv; }
void NetworkSetupWindow::MessageReceived(BMessage* msg) { switch (msg->what) { case kMsgProfileNew: break; case kMsgProfileSelected: { BPath name; const char *path; bool is_default; bool is_current; if (msg->FindString("path", &path) != B_OK) break; name.SetTo(path); is_default = (strcmp(name.Leaf(), "default") == 0); is_current = (strcmp(name.Leaf(), "current") == 0); fApplyButton->SetEnabled(!is_current); break; } case kMsgRevert: { for (int addonIndex = 0; addonIndex < fAddonCount; addonIndex++) { NetworkSetupAddOn* addon = fNetworkAddOnMap[addonIndex]; addon->Revert(); } break; } case kMsgApply: { for (int addonIndex = 0; addonIndex < fAddonCount; addonIndex++) { NetworkSetupAddOn* addon = fNetworkAddOnMap[addonIndex]; addon->Save(); } break; } case kMsgAddonShow: { if (fAddonView) fAddonView->RemoveSelf(); fAddonView = NULL; if (msg->FindPointer("addon_view", (void **) &fAddonView) != B_OK) break; fPanel->AddChild(fAddonView); fAddonView->ResizeTo(fPanel->Bounds().Width(), fPanel->Bounds().Height()); break; } default: inherited::MessageReceived(msg); } }
PrefWindow::PrefWindow() : BWindow( BRect(100, 100, 500, 300), "StrokeIt Settings", B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, 0 ) { main_save_file.SetTo(""); trainer_save_file.SetTo(""); ///////////////////////////////////////////////////////////////// // Read the settings SettingsFile s("strokeit", "strokeit"); s.Load(); if (!s.FindString("strokefile", &main_save_file)==B_OK) { main_save_file.SetTo("(none)"); } s.FindBool("help", &help_value); s.FindInt32("scale", &scale_value); ///////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////// // Set up the tabview BRect r = Bounds(); _view = new BTabView(r, "pref_tabview"); r = _view->Bounds(); r.InsetBy(5,5); r.bottom -= _view->TabHeight(); tab1 = new BTab(); PrefView* tab1_view = new PrefView(r); _view->AddTab(tab1_view, tab1); tab1->SetLabel("Main"); tab2 = new BTab(); PrefView* tab2_view = new PrefView(r); _view->AddTab(tab2_view, tab2); tab2->SetLabel("Trainer"); AddChild(_view); ///////////////////////////////////////////////////////////////// //_btn = new BButton( // BRect(3, 25, 45, 53), // "TestBtn", // "Test", // new BMessage('tstB'), // 0 //); //tab1_view->AddChild(_btn); ///////////////////////////////////////////////////////////////// // Set up the trainer view stroke_view = new PrefStrokeView(5, 5); tab2_view->AddChild( stroke_view ); traineroutput.SetTo(""); trainer_output = new BTextControl(BRect(160, 3, 350, 30), "trainerInput", "stroke", "", new BMessage('trnO') ); trainer_output->SetEnabled(false); trainer_output->SetDivider( 60 ); tab2_view->AddChild( trainer_output ); trainer_input = new BTextControl(BRect(160, 35, 350, 60), "trainerInput", "translation", "", new BMessage('trnI') ); //trainer_input->SetEnabled(false); trainer_input->SetDivider( 60 ); tab2_view->AddChild( trainer_input ); trainer_button_save = new BButton(BRect(160, 65, 280, 95), "trainerSaveBtn", "Save to active file", new BMessage('svTf')); //trainer_button->SetEnabled(false); tab2_view->AddChild( trainer_button_save ); trainer_button_saveto = new BButton(BRect(160, 100, 280, 130), "trainerSaveToBtn", "Save to selected file", new BMessage('sTsf')); //trainer_button->SetEnabled(false); tab2_view->AddChild( trainer_button_saveto ); ///////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////// // Set up the Main view help_setting = new BCheckBox(BRect(3, 35, 77, 55), "helpSeting", "Bubble help", new BMessage('chHp')); tab1_view->AddChild(help_setting); help_setting->SetValue(help_value); scale_setting = new BSlider(BRect(3, 105, 157, 185), "scaleSlider", "Scale:", new BMessage('stSc'), 1, 4 ); //, B_TRIANGLE_THUMB); scale_setting->SetHashMarks(B_HASH_MARKS_TOP); tab1_view->AddChild(scale_setting); cout << "scale value is " << scale_value << endl; scale_setting->SetValue( scaleToSlider(scale_value) ); scale_setting->SetModificationMessage( new BMessage('ScMv') ); cout << "we picked " << scale_setting->Value() << " as a good match" << endl; scale_setting->SetLimitLabels("smallest", "largest"); setSliderLabel(); ///////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////// // Set up the pop-up menus... BPopUpMenu* file_list_menu = new BPopUpMenu(""); //Main : for file selection BPopUpMenu* trainer_file_list_menu = new BPopUpMenu(""); //Trainer: for "save stroke into"... BPath settingspath; //set up the file list if ((find_directory(B_USER_SETTINGS_DIRECTORY, &settingspath))==B_OK) { //found path to settings... cout << "The path to the settings is... " << settingspath.Path() << endl; if (settingspath.Append("strokeit/strokes") == B_OK) settings_dir = new BDirectory( settingspath.Path() ); else return; BEntry entry; BPath file; while (settings_dir->GetNextEntry(&entry)==B_OK) { file.SetTo(&entry); cout << file.Path() << endl; BMessage* tmp = new BMessage('mnuF'); tmp->AddString( "path", file.Path() ); tmp->AddString( "filename", file.Leaf() ); BMenuItem* mnu = new BMenuItem(file.Leaf(), tmp); file_list_menu->AddItem( mnu ); BMessage* tmp2 = new BMessage('mnF2'); tmp2->AddString( "path", file.Path() ); tmp2->AddString( "filename", file.Leaf() ); BMenuItem* mnu2 = new BMenuItem(file.Leaf(), tmp2); trainer_file_list_menu->AddItem( mnu2 ); if ( main_save_file.Compare( file.Leaf() )==0 ) { cout << "bing!!" << endl; mnu->SetMarked(true); mnu2->SetMarked(true); } trainer_save_file.SetTo( main_save_file.String() ); } } ///////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////// // Set up the file_list = new BMenuField(BRect(3, 3, 300, 28), "mnufldFileLst", "Stroke File", file_list_menu); file_list->SetDivider(60); tab1_view->AddChild(file_list); trainer_file_list = new BMenuField(BRect(290, 100, 457, 128), "mnufldTrainerFLst", "", trainer_file_list_menu); trainer_file_list->SetDivider(1); tab2_view->AddChild(trainer_file_list); ///////////////////////////////////////////////////////////////// }