Exemplo n.º 1
0
/** \brief Get a suitable icon for the file.
 * This should retrieve a suitable icon for the file to display and return
 * an Image pointer to it.
 *
 * \param pcNode The item from the remote view that needs an icon.
 * \param bSmall If true, the icon should be 24x24. Otherwise it should be 48x48.
 *
 * \todo Ask the registrar for a suitable icon, based on the file extension.
 * \todo Add basic file/dir icons as resources, and fall back to them if the icon file is missing.
 */
Image* RemoteIconView::GetNodeImage( RemoteNode* pcNode, bool bSmall )
{
	File* pcFile;
	/* Todo: ask the Registrar for suitable icon */
	/* Looks like with current RegistrarManager class, either have to parse the list of registered types, or create a 'fake' temp file and query registrar about that instead */
	if( pcNode->m_bIsDir ) {
		/* TODO: fall back to resource if file isn't present */
		pcFile = new File( "/system/icons/folder.png" );
	} else {
		pcFile = new File( "/system/icons/file.png" );
	}
	BitmapImage* pcImage = new BitmapImage( pcFile );
	
	if( bSmall ) {
		if( pcImage && pcImage->GetSize() != Point( 24,24 ) )
			pcImage->SetSize( Point( 24,24 ) );
	} else {
		if( pcImage && pcImage->GetSize() != Point( 48,48 ) )
			pcImage->SetSize( Point( 48,48 ) );
	}
	return( pcImage );
}
Exemplo n.º 2
0
/** \brief DragSelection callback.
 * Handles the results of a drag selection.
 */
void RemoteIconView::DragSelection( Point cStartPoint )
{
	/* Most of this is adapted from IconDirectoryView::DragSelection */
	
	if( m_pcServer == NULL )
	{
		DEBUG( "DragSelection with m_pcServer== NULL\n" );
		return;
	}
	
	String zBase = m_pcServer->GetServerAddress();
	Message cMsg( 1234 );	/* Message code isn't important */
	
	/* Add all selected icons to the message, and find the icon under the mouse. */
	int nCount = 0;
	int nLastSelected = -1;
	Point cIconPos = Point( 0,0 );
	for( uint i = 0; i < GetIconCount(); i++ ) {
		if( GetIconSelected( i ) ) {
			RemoteIconData* pcData = (RemoteIconData*)GetIconData( i );
//			DEBUG( "   %s\n", pcData->m_cNode.m_zPath.c_str() );
			cMsg.AddString( "remote-file/path", pcData->m_cNode.m_zPath );
			cMsg.AddString( "server", zBase );
			cMsg.AddBool( "is_dir", pcData->m_cNode.m_bIsDir );
			
			if( Rect( GetIconPosition( i ), GetIconPosition( i ) + GetIconSize() ).DoIntersect( cStartPoint ) ) {
				cIconPos = GetIconPosition( i );
			}
			
			nLastSelected = i;
			nCount++;
		}
	}
	if( nCount == 0 ) return;
	
	/* Create a drag&drop icon */
	Bitmap cBitmap( (int)GetIconSize().x + 1, (int)GetIconSize().y + 1, CS_RGB32, Bitmap::ACCEPT_VIEWS | Bitmap::SHARE_FRAMEBUFFER );
	View* pcView = new View( Rect( Point(0,0), GetIconSize() ), "temp" );
	cBitmap.AddChild( pcView );
	
	Image* pcIcon = NULL;
	String zLabel;
	if( nCount == 1 ) {
		/* Only one file selected; use its icon */
		zLabel = GetIconString( nLastSelected, 0 );
		pcIcon = GetIconImage( nLastSelected );
	} else {
		/* Multiple files selected; use dir icon */
		zLabel.Format( "%i items", nCount );	/* TODO: localise the string */
		/* TODO: Fall back to resource if file isn't present */
		File* pcFile = new File( "/system/icons/folder.png" );
		BitmapImage* pcBitmapImage = new BitmapImage( pcFile );
		Point cSize = (GetView() == VIEW_LIST || GetView() == VIEW_DETAILS ? Point( 24,24 ) : Point( 48,48 ));
		if( pcBitmapImage->GetSize() != cSize ) pcBitmapImage->SetSize( cSize );
		pcIcon = pcBitmapImage;
	}
	if( pcIcon ) {
		RenderIcon( zLabel, pcIcon, pcView, Point(0,0) );
	}
	cBitmap.Sync();
	if( nCount != 1 ) delete( pcIcon );
	
	BeginDrag( &cMsg, cStartPoint - cIconPos, &cBitmap );
}