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 IconView::Update() { delete fIcon; fIcon = NULL; Invalidate(); // this will actually trigger a redraw *after* we updated the icon below BBitmap* icon = NULL; if (fHasRef) { BFile file(&fRef, B_READ_ONLY); if (file.InitCheck() != B_OK) return; BNodeInfo info; if (info.SetTo(&file) != B_OK) return; icon = Icon::AllocateBitmap(fIconSize); if (icon != NULL && info.GetTrackerIcon(icon, (icon_size)fIconSize) != B_OK) { delete icon; return; } } else if (fHasType) { icon = Icon::AllocateBitmap(fIconSize); if (icon != NULL && icon_for_type(fType, *icon, (icon_size)fIconSize, &fSource) != B_OK) { delete icon; return; } } else if (fIconData) { icon = Icon::AllocateBitmap(fIconSize); if (fIconData->GetIcon(icon) != B_OK) { delete icon; icon = NULL; } } fIcon = icon; }
void SpringLoadedFolderAddUniqueTypeToList(entry_ref* ref, BObjectList<BString>* typeslist) { if (!ref || !typeslist) return; // get the mime type for the current ref BNodeInfo nodeinfo; BNode node(ref); if (node.InitCheck() != B_OK) return; nodeinfo.SetTo(&node); char mimestr[B_MIME_TYPE_LENGTH]; // add it to the list if (nodeinfo.GetType(mimestr) == B_OK && strlen(mimestr) > 0) { // if this is a symlink, add symlink to the list (below) // resolve the symlink, add the resolved type // to the list if (strcmp(B_LINK_MIMETYPE, mimestr) == 0) { BEntry entry(ref, true); if (entry.InitCheck() == B_OK) { entry_ref resolvedRef; if (entry.GetRef(&resolvedRef) == B_OK) SpringLoadedFolderAddUniqueTypeToList(&resolvedRef, typeslist); } } // scan the current list, don't add dups bool unique = true; int32 count = typeslist->CountItems(); for (int32 index = 0 ; index < count ; index++) { if (typeslist->ItemAt(index)->Compare(mimestr) == 0) { unique = false; break; } } if (unique) typeslist->AddItem(new BString(mimestr)); } }
void PProjectWindow::OpenItem() { PEntryItem *gi; gi = dynamic_cast<PEntryItem*>(fList->ItemAt(fList->CurrentSelection())); if (gi) { try { BNode node; FailOSErr(node.SetTo(&gi->Ref())); BNodeInfo info; FailOSErr(info.SetTo(&node)); char mime[B_MIME_TYPE_LENGTH]; CProjectFile* subProject = dynamic_cast<CProjectFile*>(gi->ModelItem()); if (subProject) { if (!subProject->HasBeenParsed()) { subProject->Read(); if (subProject->HasBeenParsed()) { list<CProjectItem*>::const_iterator iter; for( iter = subProject->begin(); iter != subProject->end(); ++iter) { AddItemsToList( *iter, gi); } } } } else if (info.GetType(mime) || strncmp(mime, "text/", 5)) OpenInTracker(gi->Ref()); else gApp->OpenWindow(gi->Ref()); } catch (HErr& e) { e.DoError(); gApp->OpenWindow(gi->Ref()); } } } /* PProjectWindow::OpenItem */
// ----------------------------------------------------------------------- RHTML_text_view - MessageReceived - void RHTMLtextview::MessageReceived(BMessage *msg) { switch (msg->what) { case 'PPOP': { Window()->Lock(); if (pushmenu) { int32 c,d; GetSelection(&c,&d); pushmenu=false; if (mode==1) fTagMenu->Start(ConvertToScreen(PointAt(c)),c,R_TAG_MENU,tags); if (mode==2) fTagMenu->Start(ConvertToScreen(PointAt(c)),c,R_PARAM_MENU,tags,BString(buf1)); if (mode==3) fTagMenu->Start(ConvertToScreen(PointAt(c)),c,R_VALUE_MENU,tags,BString(buf1),BString(buf2)); } Window()->Unlock(); fTimer->EndTimer(); } break; case 'TIMR': { Window()->Lock(); UpdateParamMenu(); fTarget->fNumView->UpdateNum(); Window()->Unlock(); fUpdateTimer->EndTimer(); } break; case 'PTFC': { int32 c,d; BString oldstring; msg->FindInt32("sel1",&c); msg->FindInt32("sel2",&d); msg->FindString("oldstring",&oldstring); BString *newtext = new BString(Text()); fFileTypes->SetFontAndColor(&oldstring, newtext,0,c,d); delete newtext; } break; case 'CWFC': { int32 c,d; GetSelection(&c,&d); BString *newtext = new BString(Text()); fFileTypes->SetFontAndColor(newtext, newtext, 0, c); delete newtext; } break; case 'VALE': { msg->FindString("tag",&buf1); msg->FindString("param",&buf2); pushmenu=true; mode=3; fTimer->StartTimer(fOptions->ReakcioIdoTM); } break; case 'UPPM': { if (fUpdateTimer->IsActive()) fUpdateTimer->ResetTimer(); else fUpdateTimer->StartTimer(fOptions->ReakcioIdo); } break; default: { if (msg->WasDropped()) { int32 num; uint32 type; char* name; BPoint aPoint; BPoint point; entry_ref ref; status_t err; msg->FindPoint("_drop_point_", &aPoint); point = aPoint; this->ConvertFromScreen(&point); const int32 offset = OffsetAt(point); if (msg->GetInfo(B_REF_TYPE, 0, &name, &type, &num) == B_NO_ERROR && num >= 1) { // - File for(int32 i = 0; i < num; i++) { BEntry entry; BPath path; BFile fFile; BNodeInfo fNodeInfo; entry_ref ref; char fFileType[B_MIME_TYPE_LENGTH]; if(msg->FindRef("refs", i, &ref) != B_NO_ERROR) { continue; } if ((err=entry.SetTo(&ref)) == B_OK) { entry.GetPath(&path); } fFile.SetTo(&ref,B_READ_ONLY); fNodeInfo.SetTo(&fFile); fNodeInfo.GetType(fFileType); DropFile(path.Path(), fFileType, offset); } } } else { BTextView::MessageReceived(msg); } } break; } }
status_t HModuleRoster::HandleRequest( RequestPB *pb ) { BEntry entry; BNode node; BNodeInfo info; char mimeType[128], vmimeType[128]; status_t status = B_OK; int32 parentCount = 0; BPath absPath, resourcePath( "/" ); resourcePath.Append( pb->brURI->path ); pb->resourcePath = &resourcePath; pb->mimeType = mimeType; // fix for "hostname//" request crash // wade majors <[email protected] - Mar-09-2001 if (resourcePath.Path() == NULL) { resourcePath.SetTo("null"); pb->resourcePath = &resourcePath; } // VResource *vres = NULL; // ***** // Look for "real" resource // ***** do { // Small optimization... if not done, the path normalizer will // be tickled when a resource does not exit if( (resourcePath.Path())[1] == 0 ) { status = B_ERROR; break; } absPath.SetTo( pb->webDirectory->Path(), resourcePath.Path()+1 ); if( (entry.SetTo( absPath.Path(), true ) == B_OK)&&(node.SetTo( &entry ) == B_OK) &&(info.SetTo( &node ) == B_OK) ) { const char *resMIME; // Cheap hack for directories without a MIME type if(info.GetType( mimeType ) != B_OK) strcpy( mimeType, "application/x-vnd.Be-directory" ); if( (resMIME = pb->vresources->MatchVRes( pb->brURI->path, true, &vres )) ) strcpy( vmimeType, resMIME ); else strcpy( vmimeType, mimeType ); break; } parentCount++; }while( (status = resourcePath.GetParent( &resourcePath )) == B_OK ); entry.Unset(); if( node.InitCheck() ) node.Unset(); // ***** // Look for Virtual Resource if no "real" resource was found. // ***** if( (status != B_OK)||((parentCount != 0)&&(strcmp(mimeType, "application/x-vnd.Be-directory") == 0)) ) { const char *resMIME; if( (resMIME = pb->vresources->MatchVRes( pb->brURI->path, false, &vres )) ) { strcpy( vmimeType, resMIME ); strcpy( mimeType, resMIME ); } else { HTTPResponse response; response.SetHTMLMessage( 404 ); // Not Found pb->request->SendReply( &response ); return B_ERROR; } } // ***** // Find handler module for resource // ***** HModule *module, *prefModule = NULL; int32 priority, highestPriority = 0; for( int32 i=0; (module = (HModule *)moduleList.ItemAt(i)); i++ ) { if( module->CanHandleResource( vmimeType, pb->request->GetMethod(), &priority )&& (priority > highestPriority) ) { highestPriority = priority; prefModule = module; } } // ***** // Setup PB // ***** pb->HandleRequest = HModuleRoster::HandleRequest; pb->Logprintf = log_printf; pb->moduleList = &moduleList; if( vres ) { pb->authenticate = vres->Authenticate(); pb->extras = &vres->extras; } else pb->extras = NULL; // ***** // Invoke Handler Module to handle the request // ***** if( highestPriority > 0 ) { status = prefModule->HandleRequest( pb ); return status; } else // No handler found... send error { HTTPResponse response; response.SetHTMLMessage( 501 ); // Not Implemented pb->request->SendReply( &response ); return B_ERROR; } return B_OK; }