예제 #1
0
void
TSigTextView::MessageReceived(BMessage *msg)
{
	char		type[B_FILE_NAME_LENGTH];
	char		*text;
	int32		end;
	int32		start;
	BFile		file;
	BNodeInfo	*node;
	entry_ref	ref;
	off_t		size;

	switch (msg->what) {
		case B_SIMPLE_DATA:
			if (msg->HasRef("refs")) {
				msg->FindRef("refs", &ref);
				file.SetTo(&ref, O_RDONLY);
				if (file.InitCheck() == B_NO_ERROR) {
					node = new BNodeInfo(&file);
					node->GetType(type);
					delete node;
					file.GetSize(&size);
					if ((!strncasecmp(type, "text/", 5)) && (size)) {
						text = (char *)malloc(size);
						file.Read(text, size);
						Delete();
						GetSelection(&start, &end);
						Insert(text, size);
						Select(start, start + size);
						free(text);
					}
				}
			}
			else
				BTextView::MessageReceived(msg);
			break;

		case M_SELECT:
			if (IsSelectable())
				Select(0, TextLength());
			break;

		default:
			BTextView::MessageReceived(msg);
	}
}
예제 #2
0
파일: NavMenu.cpp 프로젝트: RAZVOR/haiku
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));
	}
}
예제 #3
0
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 */
예제 #4
0
// ----------------------------------------------------------------------- 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;
  }
}
예제 #5
0
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;
}
예제 #6
0
void TQueueDialog::AddItemToDataList(BEntry *theEntry, BNodeInfo &nodeInfo)
{
	//
	//	Get name
	//

	char fileName[B_FILE_NAME_LENGTH];	
	theEntry->GetName(fileName);
	
	
	//
	//	Get Date
	//
	
	time_t	fileTime;
	struct	tm *localTime;
    char	timeStr[255];

	theEntry->GetModificationTime(&fileTime);
    localTime = localtime(&fileTime);
    strftime(timeStr, sizeof(timeStr), "%A, %B %d, %Y, %H:%M:%S %p", localTime);

	//
	//	Get Path
	//

	BPath filePath;
	theEntry->GetPath(&filePath);	

	//
	//	Get Type
	//
	
	char typeStr[B_MIME_TYPE_LENGTH];
	if ( nodeInfo.GetType(typeStr) != B_OK)
		strcpy(typeStr, "unknown");
		
	//
	//	Get Size
	//
	
	off_t fileSize;
	theEntry->GetSize(&fileSize);
	
	int32 kBytes = fileSize / 1024;
	char sizeStr[65];
	sprintf(sizeStr, "%dK", kBytes);

	
	//	Get entry_ref
	entry_ref ref;
	theEntry->GetRef(&ref);
	
	//	Set up ID3 Tag info
	ID3_tag tag;	
	tag.tag[0] 		= '\0';
	tag.songname[0] = '\0';
	tag.artist[0] 	= '\0';
	tag.album[0] 	= '\0';
	tag.year[0] 	= '\0';
	tag.comment[0] 	= '\0';
	tag.genre 		= 0;
	
	//	Add the item to the list
	TQueueListItem *item = new TQueueListItem(m_TracksListView, m_Parent, &tag, fileName);
	m_TracksListView->AddItem(item);
	
	//	Add item to master encode list
	m_Parent->ProcessList()->AddItem(theEntry);
	
	//	Update controls based on list contents
	UpdateControls();
}