Beispiel #1
0
bool 
Model::Mimeset(bool force)
{
	BString oldType = MimeType();
	ModelNodeLazyOpener opener(this);
	BPath path;
	GetPath(&path);
	if (force) {
		if (opener.OpenNode(true) != B_OK)
			return false;

		Node()->RemoveAttr(kAttrMIMEType);
		update_mime_info(path.Path(), 0, 1, 1);
	} else
		update_mime_info(path.Path(), 0, 1, 0);

	AttrChanged(0);

	return !oldType.ICompare(MimeType());
}
Beispiel #2
0
bool
Model::Mimeset(bool force)
{
	BString oldType = MimeType();
	BPath path;
	GetPath(&path);

	update_mime_info(path.Path(), 0, 1, force ? 2 : 0);
	ModelNodeLazyOpener opener(this);
	opener.OpenNode();
	AttrChanged(NULL);

	return !oldType.ICompare(MimeType());
}
Beispiel #3
0
bool
IsTypeMatch(const BMessage &test, const entry_ref &ref)
{
	BString value;
	if (test.FindString("value",&value) != B_OK)
	{
		debugger("Couldn't get value in IsTypeMatch");
		return false;
	}

//if (value == "image/")
//	debugger("");
	
	BString compare;
	if (test.FindString("mode",&compare) != B_OK)
	{
		debugger("Couldn't get mode in IsTypeMatch");
		return false;
	}
	
	BString string;
	attr_info info;
	BNode node(&ref);
	if (node.InitCheck() != B_OK)
		return false;
	
	if (node.GetAttrInfo("BEOS:TYPE",&info) != B_OK)
	{
		BPath path(&ref);
		if (update_mime_info(path.Path(),0,1,0) != B_OK)
			return false;
	}
	
	if (node.ReadAttrString("BEOS:TYPE",&string) != B_OK)
		return false;
	
	
	bool result = StringCompare(value,string.String(),compare.String(),true);
	
	printf("\tType test: %s %s %s - %s\n",ref.name,compare.String(),value.String(),
								result ? "MATCH" : "NO MATCH");
	
	return result;
}
Beispiel #4
0
void
App::OpenFile(entry_ref ref, int32 line, int32 column)
{
	if (!ref.name)
		return;
	
	BNode node(&ref);
	BString type;
	if (node.ReadAttrString("BEOS:TYPE",&type) != B_OK)
	{
		update_mime_info(BPath(&ref).Path(),0,0,1);
		node.ReadAttrString("BEOS:TYPE",&type);
	}
	
	if (type.CountChars() > 0)
	{
		if (type == PROJECT_MIME_TYPE || type.FindFirst("text/") != 0)
		{
			STRACE(2,("Launching text or project file in roster...\n"));
			be_roster->Launch(&ref);
			return;
		}
	}
	else
	{
		BString extension = BPath(&ref).Path();
		int32 pos = extension.FindLast(".");
		if (pos >= 0)
		{
			extension = extension.String() + pos;
			if (extension.ICompare(".cpp") != 0 &&
				extension.ICompare(".h") != 0 &&
				extension.ICompare(".hpp") != 0 &&
				extension.ICompare(".c") != 0)
			{
				return;
			}
		}
	}
	
	
	BMessage* msg = new BMessage(B_REFS_RECEIVED);
	msg->AddRef("refs",&ref);
	if (line >= 0)
		msg->AddInt32("be:line",line);
	if (column >= 0)
		msg->AddInt32("be:column",column);
	STRACE(2,("Paladin Launching File Ref: %s:%i:%i\n",ref.name,line,column));
	
	/*
	  ANTI-PATTERN - this code left here for future developers' reference
	  Using the below method launches the app, and then be_roster sends
	  ANOTHER B_REFS_REVEIVED of its own, causing the file to be opened twice,
	  or once at the wrong location (i.e. without a line number).
	be_roster->Launch(&ref,msg);
	*/
	
	/*
	entry_ref appRef;
	be_roster->FindApp(&ref,&appRef);
	app_info appInfo;
	be_roster->GetAppInfo(&appRef,&appInfo);
	BMessenger messenger(appInfo.signature);
	messenger.SendMessage(msg,(BHandler*)NULL,B_INFINITE_TIMEOUT);
	// The above results in nothing happening unless the app is ALREADY running
	*/
	
	// Final effort - use the text_search tracker messenger mechanism
	BMessenger target("application/x-vnd.Be-TRAK");
	target.SendMessage(msg);
}
Beispiel #5
0
int32 DCCReceive::Transfer(void* arg)
{
	BMessenger msgr(reinterpret_cast<DCCReceive*>(arg));
	struct sockaddr_in address;
	BLooper* looper(NULL);

	int32 dccSock(-1);

	if ((dccSock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
		UpdateStatus(msgr, S_DCC_ESTABLISH_ERROR);
		return B_ERROR;
	}

	BMessage reply;

	if (msgr.SendMessage(M_DCC_GET_CONNECT_DATA, &reply) == B_ERROR) return B_ERROR;

	memset(&address, 0, sizeof(sockaddr_in));
	address.sin_family = AF_INET;
	address.sin_port = htons(atoi(reply.FindString("port")));
	address.sin_addr.s_addr = htonl(strtoul(reply.FindString("ip"), 0, 10));

	UpdateStatus(msgr, S_DCC_CONNECT_TO_SENDER);
	if (connect(dccSock, (sockaddr*)&address, sizeof(address)) < 0) {
		UpdateStatus(msgr, S_DCC_ESTABLISH_ERROR);
		close(dccSock);
		return B_ERROR;
	}

	BPath path(reply.FindString("name"));
	BString buffer;
	off_t file_size(0);

	buffer << S_DCC_RECV1 << path.Leaf() << S_DCC_RECV2 << reply.FindString("nick") << ".";

	UpdateStatus(msgr, buffer.String());

	BFile file;

	if (msgr.IsValid()) {
		if (reply.FindBool("resume")) {
			if (file.SetTo(reply.FindString("name"), B_WRITE_ONLY | B_OPEN_AT_END) == B_NO_ERROR &&
				file.GetSize(&file_size) == B_NO_ERROR && file_size > 0LL)
				UpdateBar(msgr, file_size, 0, 0, true);
			else
				file_size = 0LL;
		} else {
			file.SetTo(reply.FindString("name"), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
		}
	}

	uint32 bytes_received(file_size);
	uint32 size(atol(reply.FindString("size")));
	uint32 cps(0);

	if (file.InitCheck() == B_NO_ERROR) {
		bigtime_t last(system_time()), now;
		char inBuffer[8196];
		bigtime_t start = system_time();

		while ((msgr.Target(&looper) != NULL) && bytes_received < size) {
			int readSize;
			if ((readSize = recv(dccSock, inBuffer, 8196, 0)) < 0) break;

			file.Write(inBuffer, readSize);
			bytes_received += readSize;
			BMessage msg(M_DCC_UPDATE_TRANSFERRED);
			msg.AddInt32("transferred", bytes_received);
			msgr.SendMessage(&msg);

			uint32 feed_back(htonl(bytes_received));
			send(dccSock, &feed_back, sizeof(uint32), 0);

			now = system_time();
			bool hit(false);

			if (now - last > 500000) {
				cps = (int)ceil((bytes_received - file_size) / ((now - start) / 1000000.0));
				BMessage updmsg(M_DCC_UPDATE_AVERAGE);
				updmsg.AddInt32("average", cps);
				msgr.SendMessage(&updmsg);
				last = now;
				hit = true;
			}

			DCCConnect::UpdateBar(msgr, readSize, cps, bytes_received, hit);
		}
	}

	if (msgr.IsValid()) {
		BMessage msg(M_DCC_STOP_BUTTON);
		msgr.SendMessage(&msg);
	}

	if (dccSock > 0) {
		close(dccSock);
	}

	if (file.InitCheck() == B_OK) {
		file.Unset();
		update_mime_info(reply.FindString("name"), 0, 0, 1);
	}
	return 0;
}
Beispiel #6
0
void
App::OpenFile(entry_ref ref, int32 line)
{
	if (!ref.name)
		return;
	
	BNode node(&ref);
	BString type;
	if (node.ReadAttrString("BEOS:TYPE",&type) != B_OK)
	{
		update_mime_info(BPath(&ref).Path(),0,0,1);
		node.ReadAttrString("BEOS:TYPE",&type);
	}
	
	if (type.CountChars() > 0)
	{
		if (type == PROJECT_MIME_TYPE || type.FindFirst("text/") != 0)
		{
			be_roster->Launch(&ref);
			return;
		}
	}
	else
	{
		BString extension = BPath(&ref).Path();
		int32 pos = extension.FindLast(".");
		if (pos >= 0)
		{
			extension = extension.String() + pos;
			if (extension.ICompare(".cpp") != 0 &&
				extension.ICompare(".h") != 0 &&
				extension.ICompare(".hpp") != 0 &&
				extension.ICompare(".c") != 0)
			{
				return;
			}
		}
	}
	
//	BMessage msg(B_REFS_RECEIVED);
	BMessage msg(PALEDIT_OPEN_FILE);
	msg.AddRef("refs",&ref);
	if (line >= 0)
		msg.AddInt32("line",line);
	
	if (be_roster->IsRunning(EDITOR_SIGNATURE))
	{
		BMessenger msgr(EDITOR_SIGNATURE);
		msgr.SendMessage(&msg);
	}
	else
	{
		DPath path(gAppPath.GetFolder());
		path.Append("PalEdit");
		
		entry_ref launchref;
		BEntry(path.GetFullPath()).GetRef(&launchref);
		
		if (be_roster->Launch(&launchref,&msg) != B_OK &&
			be_roster->Launch(EDITOR_SIGNATURE,&msg) != B_OK)
			be_roster->Launch(&ref);
	}
}
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);
}
Beispiel #8
0
nsresult nsIconChannel::MakeInputStream(nsIInputStream** _retval, PRBool nonBlocking)
{
  nsXPIDLCString contentType;
  nsCAutoString filePath;
  nsCAutoString fileExtension;
  nsCOMPtr<nsIFile> localFile; // File we want an icon for
  PRUint32 desiredImageSize;
  nsresult rv = ExtractIconInfoFromUrl(getter_AddRefs(localFile), &desiredImageSize, contentType, fileExtension);
  NS_ENSURE_SUCCESS(rv, rv);

  PRUint32 iconSize = 16;
  if (desiredImageSize > 16)
    iconSize = 32;

  PRUint32 alphaBytesPerRow = (iconSize / 8);
  if (iconSize % 32 != 0)
    alphaBytesPerRow = ((iconSize / 32) + 1) * 4;
    
  PRBool fileExists = PR_FALSE;
  if (localFile)
  {
    localFile->GetNativePath(filePath);
    localFile->Exists(&fileExists);
  }
  
  // Get the native icon.
  // 1) If it is for an actual local file, BNodeInfo::GetTrackerIcon.
  // 2) If the local file does not exist, use the content type 
  //    and BMimeType::GetIcon
  BBitmap nativeIcon(BRect(0, 0, iconSize - 1, iconSize - 1), B_CMAP8);
  if (!nativeIcon.IsValid())
    return NS_ERROR_OUT_OF_MEMORY;

  PRBool gotBitmap = PR_FALSE;
  if (fileExists)
  {
    BNode localNode(filePath.get());
    // BeOS doesn't MIME type foreign files immediately - 
    // If there is no type attribute then we can force an identify
    if (localNode.ReadAttr("BEOS:TYPE", B_STRING_TYPE, 0, NULL, 0) != B_OK)
    	update_mime_info(filePath.get(), 0, 1, 1);

    BNodeInfo localNodeInfo(&localNode);
    if (iconSize == 16)
    {
      if (localNodeInfo.GetTrackerIcon(&nativeIcon, B_MINI_ICON) == B_OK)
        gotBitmap = PR_TRUE;
    }
    else
    {
      if (localNodeInfo.GetTrackerIcon(&nativeIcon, B_LARGE_ICON) == B_OK)
        gotBitmap = PR_TRUE;
    }
  }

  // If we haven't got a bitmap yet, use the content type
  if (!gotBitmap)    
  {
    // If no content type specified, use mozilla's mime service to guess a mime type
    if (contentType.IsEmpty())
    {
      nsCOMPtr<nsIMIMEService> mimeService (do_GetService("@mozilla.org/mime;1", &rv));
      if (NS_SUCCEEDED(rv))
        mimeService->GetTypeFromExtension(fileExtension, contentType);
      // If unrecognised extension - set to generic file
      if (contentType.IsEmpty())
        contentType = "application/octet-stream";
    }
    // Create BeOS-Native MIME type info - if unheard of, set to generic file
    BMimeType mimeType(contentType.get());
    if (!mimeType.IsInstalled())
    	mimeType.SetTo("application/octet-stream");
    if (iconSize == 16)
    {
      if (mimeType.GetIcon(&nativeIcon, B_MINI_ICON) == B_OK)
        gotBitmap = PR_TRUE;
    }
    else
    {
      if (mimeType.GetIcon(&nativeIcon, B_LARGE_ICON) == B_OK)
        gotBitmap = PR_TRUE;
    }
  }
  
  if (!gotBitmap)
    return NS_ERROR_NOT_AVAILABLE;

  BScreen mainScreen(B_MAIN_SCREEN_ID);
  if (!mainScreen.IsValid())
    return NS_ERROR_NOT_AVAILABLE;

  // Got a bitmap and color space info - convert data to mozilla's icon format
  PRUint32 iconLength = 2 + iconSize * iconSize * 4;
  uint8 *buffer = new uint8[iconLength];
  if (!buffer)
    return NS_ERROR_OUT_OF_MEMORY;

  uint8* destByte = buffer;
  *(destByte++) = iconSize;
  *(destByte++) = iconSize;

  // RGB data
  uint8* sourceByte = (uint8*)nativeIcon.Bits();
  for(PRUint32 iconRow = 0; iconRow < iconSize; iconRow++)
  {
    sourceByte = (uint8*)nativeIcon.Bits() + nativeIcon.BytesPerRow() * iconRow;
    for(PRUint32 iconCol = 0; iconCol < iconSize; iconCol++)
    {
      if (*sourceByte != B_TRANSPARENT_MAGIC_CMAP8)
      {
        rgb_color colorVal = mainScreen.ColorForIndex(*sourceByte);
#ifdef IS_LITTLE_ENDIAN
        *(destByte++) = colorVal.blue;
        *(destByte++) = colorVal.green;
        *(destByte++) = colorVal.red;
        *(destByte++) = uint8(255);
#else
        *(destByte++) = uint8(255);
        *(destByte++) = colorVal.red;
        *(destByte++) = colorVal.green;
        *(destByte++) = colorVal.blue;
#endif
      }
      else
      {
        *destByte++ = 0;
        *destByte++ = 0;
        *destByte++ = 0;
        *destByte++ = 0;
      }
      // original code had a conditional here:
      // if (iconCol < iconSize - 1) 
      // Leaving this comment in case complications arise later
      sourceByte++;
    }
  }

  NS_ASSERTION(buffer + iconLength == destByte, "size miscalculation");
  
  // Now, create a pipe and stuff our data into it
  nsCOMPtr<nsIInputStream> inStream;
  nsCOMPtr<nsIOutputStream> outStream;
  rv = NS_NewPipe(getter_AddRefs(inStream), getter_AddRefs(outStream),
                  iconLength, iconLength, nonBlocking);
  if (NS_SUCCEEDED(rv))
  {
    PRUint32 written;
    rv = outStream->Write((char*)buffer, iconLength, &written);
    if (NS_SUCCEEDED(rv))
      NS_ADDREF(*_retval = inStream);
  }
  delete [] buffer;
  
  return rv;
}