⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dfb_wzm.cpp

📁 带DirectFB界面的FTP客户端
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	}
}

int DFBDisplay::EvtFunction( DFBWindowEvent &evt )
{
	if( evt.key_symbol == DIKS_F1 )
	{
		if( fileflg )
			sprintf( buf, "help" );
		else
			sprintf( buf, "list" );
			
		return 1;
	}
	
	if( evt.key_symbol == DIKS_F2 && fileflg )
	{
		char buffer[MAXNUM];
		int pos;
		char *p = buf;		
		
		flag = false;
		AcceptCmd( "Please Input New Name:", buffer, true );
		buf = p;
		flag = true;
		if( !strcmp( buffer, "quit" ) || !strcmp( buffer, "exit" ))
		{
			sprintf( buf, "list" );
			page = 0;
		}
		else
		{
			if( evt.window_id == lid )
				sprintf( buf, "lren %s %s", lstrs[llines-1].c_str(), buffer );
			else
			{
				try
				{
					pos = strs[lines-1].find_last_of( " ", strs[lines-1].length() );
					sprintf( buf, "rena %s %s", strs[lines-1].substr( pos+1, -1 ).c_str(), buffer );
				}
				catch( ... )
				{
					ERR( "rename to [%s] error!", buffer );	
					sprintf( buf, "list");
					page = 0;
				}
			}
	    }
		
		return 2;
	}
	
	if( evt.key_symbol == DIKS_F3 && fileflg )
	{		
		if( evt.window_id == lid )
		{
			struct stat mode;
		
			if( stat( lstrs[llines-1].c_str(), &mode ) < 0 )
			{
				sprintf( buf, "lcwd" );	
				return 3;
			}
			if( S_ISDIR( mode.st_mode ) )
				sprintf( buf, "lrmd %s", lstrs[llines-1].c_str());
			else
				sprintf( buf, "ldel %s", lstrs[llines-1].c_str());
		}
		else
		{
			int pos;
			
			try
			{
				pos = strs[lines-1].find_last_of( " ", strs[lines-1].length() );
				if( !strs[lines-1].compare( 0, 1, "d" ) )
					sprintf( buf, "srmd %s", strs[lines-1].substr( pos+1, -1 ).c_str());
				else
					sprintf( buf, "dele %s", strs[lines-1].substr( pos+1, -1 ).c_str());
			}
			catch( ... )
			{
				ERR( "this line [%s] error!", strs[lines-1].c_str() );	
				sprintf( buf, "list" );
			}
		}
		
		return 3;
	}
	
	if( evt.key_symbol == DIKS_F4 && fileflg )
	{
		int pos;
		
		if( evt.window_id == lid )
		{
			struct stat mode;
		
			if( stat( lstrs[llines-1].c_str(), &mode ) < 0 )
			{
				sprintf( buf, "lcwd" );	
				return 3;
			}
			if( S_ISDIR( mode.st_mode ) )
				sprintf( buf, "lcwd %s", lstrs[llines-1].c_str());
			else
				sprintf( buf, "lsiz %s", lstrs[llines-1].c_str());
		}
		else
		{
			try
			{
				pos = strs[lines-1].find_last_of( " ", strs[lines-1].length() );
				if( !strs[lines-1].compare( 0, 1, "d" ) )
					sprintf( buf, "scwd %s", strs[lines-1].substr( pos+1, -1 ).c_str());
				else
					sprintf( buf, "size %s", strs[lines-1].substr( pos+1, -1 ).c_str());
			}
			catch( ... )
			{
				ERR( "this line [%s] error!", strs[lines-1].c_str() );	
				sprintf( buf, "list" );
			}
		}
		
		return 4;
	}
	
	if( evt.key_symbol == DIKS_F5 && fileflg )
	{
		sprintf( buf, "type" );
		
		return 5;
	}
	
	if( evt.key_symbol == DIKS_F6 && fileflg )
	{
		sprintf( buf, "mode" );
		
		return 5;
	}
	
	if( evt.key_symbol == DIKS_F7 && fileflg )
	{
		char buffer[MAXNUM];
		char *p = buf;		
		
		flag = false;
		AcceptCmd( "Please Input Dir Name:", buffer, true );
		buf = p;
		flag = true;
		if( !strcmp( buffer, "quit" ) || !strcmp( buffer, "exit" ))
		{
			sprintf( buf, "list" );
			page = 0;
		}
		else
		{
			if( evt.window_id == lid )
				sprintf( buf, "lmkd %s", buffer );
			else
				sprintf( buf, "smkd %s", buffer );
	    }
		
		return 7;
	}
	
	if( evt.key_symbol == DIKS_F8 && fileflg )
	{
		int pos;
		
		if( evt.window_id == lid )
			sprintf( buf, "lmdt %s", lstrs[llines-1].c_str());
		else
		{
			try
			{
				pos = strs[lines-1].find_last_of( " ", strs[lines-1].length() );
				sprintf( buf, "mdtm %s", strs[lines-1].substr( pos+1, -1 ).c_str());
			}
			catch( ... )
			{
				ERR( "this line [%s] error!", strs[lines-1].c_str() );	
				sprintf( buf, "list" );
			}
		}
		
		return 4;
	}   
	
	return 0;	
}

int DFBDisplay::InputEvent( const bool &flg )
{
	int num=0;
	DFBWindowEvent evt;      
	
	memset( buf, 0, MAXNUM );	
	while (1) 
	{
		events->WaitForEvent( events );
		while (events->GetEvent( events, DFB_EVENT(&evt) ) == DFB_OK) 
		{    
			 if( evt.type == DWET_KEYDOWN ) 
			 {
			 	if ( DFB_KEY_TYPE( evt.key_symbol ) == DIKT_SPECIAL && flag )
				{
					if( EvtSpecial( evt ) )
						return strlen( buf );
				}
			 	if ( DFB_KEY_TYPE( evt.key_symbol ) == DIKT_UNICODE )
				{
					if( EvtUnicode( evt, num, flg ) )
						return num;
				}
				if ( DFB_KEY_TYPE( evt.key_symbol ) == DIKT_FUNCTION && flag )
				{
					if( EvtFunction( evt ) )
						return strlen( buf );
				}
				
			}
			if( evt.type == DWET_BUTTONDOWN && flag ) 
			{
				if( EvtCousor( evt ) )
					return strlen( buf );
			}
			if( evt.type == DWET_WHEEL && flag ) 
				EvtWheel( evt );
		}
     }
     
     return num;	
}

int DFBDisplay::AcceptCmd( const string &pro, char *ret, const bool &flg )
{
	prompt = pro;
	
	if( DrawCmd( prompt.c_str() ) )
		ERR( "输出[%s]到CMD失败!", prompt.c_str() );
		
	if( ret != NULL )
	{
		buf = ret;
		return InputEvent( flg );	
	}
	return 0;
}

int DFBDisplay::DrawFile( const char *file, int start, const bool &flg )
{
	ifstream fs;
	char buffer[MAXNUM];
	bool nowhite = false;
	
	nums = 0;
	page = start;
	start *= 19;
	fileflg = flg;
	
	if( fileflg )
	{
		windowr->MoveTo( windowr, linewidth, fontheigh+5 );
		windowr->Resize( windowr, linewidth, winheight );
		windowl->SetOpacity(windowl, 0xff );
	}
	else
	{
		windowr->MoveTo( windowr, 0, fontheigh + 5 );
		windowr->Resize( windowr, linewidth*2, winheight );
		windowl->SetOpacity(windowl, 0x00 );
		Exchange(true);
	}
	
	surfacer->Clear( surfacer, 0xff, 0xff, 0xff, 0xff );
	if( file == NULL || strlen(file) <= 0 )
	{
		fs.open( TEMPFILE );
		tmpfile = "";
	}
	else
	{
		fs.open( file );
		tmpfile = file;
	}
		
	while(  fs.good() && nums<19 )
	{
		fs.getline( buffer, MAXNUM );
		if( start-- > 0 )
			continue;
		cleartail( buffer );
		strs[nums] = buffer;
		if( strs[nums].empty() && fileflg )
			continue;
		nums++;
		if( fileflg )
		{
			try
			{
				int pos;
				
				pos = strs[nums-1].find_last_of( ' ', strs[nums-1].length() );
				sprintf( buffer, "%s%s", strs[nums-1].substr(0,4).c_str(), 
										  strs[nums-1].substr( pos, -1 ).c_str());
			}
			catch( ... )
			{
				ERR("%s","the error data:",buffer);
				nums--;
				continue;
			}
			strs[nums-1] = buffer;
		}
		if( nums == lines )
			nowhite = true;
		DrawLine( strs[nums-1].c_str(), nums, nowhite );
		nowhite = false;
	}
	
	fs.close();
	
	if( nums >= 19 )
	{
		nums = 19;
		next = true;
	}
	else
		next = false;
		
	flag = true;	
	surfacer->Flip( surfacer, NULL,  DSFLIP_NONE );
	
	return 0;	
}

DFBDisplay::DFBDisplay( int argc, char **argv )
{
	 int screen_width,screen_height;
	 
	 DFBDisplayLayerConfig layer_config;
	 
	 DFBCHECK(DirectFBInit( &argc, &argv ));
     DFBCHECK(DirectFBCreate( &dfb ));
     
	 DFBCHECK(dfb->GetDisplayLayer( dfb, DLID_PRIMARY, &layer ));
	 layer->SetCooperativeLevel( layer, DLSCL_ADMINISTRATIVE );
	 layer->GetConfiguration( layer, &layer_config );
	 layer->EnableCursor ( layer, 1 );	 
	 layer->SetBackgroundColor ( layer, 0x66, 0x66, 0x66, 0x66 );
	 layer->SetBackgroundMode( layer, DLBM_COLOR  );
	 screen_width = layer_config.width;
     screen_height = layer_config.height;
     layer->WarpCursor( layer, screen_width/4, screen_height/2 );

	 {
     	DFBFontDescription     fdsc;
     	int i;
     	
     	i = DFDESC_HEIGHT|DFDESC_WIDTH;
     	memcpy(&fdsc.flags, &i,4);
     	fdsc.height = screen_width / 30;
     	fdsc.width = screen_width / 30;
     	fontheigh = fdsc.height + 2;
	 	DFBCHECK(dfb->CreateFont( dfb, FONTFILE, &fdsc, &font_normal ));
	 }

	 {
	 	DFBWindowDescription desc;
	 	int i;
	 	
	 	i = DWDESC_POSX|DWDESC_POSY|DWDESC_WIDTH|DWDESC_HEIGHT|DWDESC_CAPS;
	 	memcpy(&desc.flags, &i, 4);
        desc.posx   = 0;
        desc.posy   = screen_height - fontheigh - 5;
        desc.width  = screen_width;
        desc.height = fontheigh + 5;
        desc.caps   = DWCAPS_ALPHACHANNEL;
	 	DFBCHECK(layer->CreateWindow( layer, &desc, &windowd ) );
     }
     
     {
	 	DFBWindowDescription desc;
	 	int i;
	 	
	 	i = DWDESC_POSX|DWDESC_POSY|DWDESC_WIDTH|DWDESC_HEIGHT|DWDESC_CAPS;
	 	memcpy(&desc.flags, &i, 4);
        desc.posx   = 0;
        desc.posy   = 0;
        desc.width  = screen_width;
        desc.height = fontheigh + 5;
        desc.caps   = DWCAPS_ALPHACHANNEL;
	 	DFBCHECK(layer->CreateWindow( layer, &desc, &windowu ) );
     }

	 {
	 	DFBWindowDescription desc;
	 	int i;
	 	
	 	i = DWDESC_POSX|DWDESC_POSY|DWDESC_WIDTH|DWDESC_HEIGHT|DWDESC_CAPS;
	 	memcpy(&desc.flags, &i, 4);
        desc.posx   = screen_width / 2 ;
        desc.posy   = fontheigh + 5;
        desc.width  = screen_width/2;
      	linewidth = desc.width;
        desc.height = screen_height - (fontheigh + 5)*2;
        winheight = desc.height;
        desc.caps   = DWCAPS_ALPHACHANNEL;
	 	DFBCHECK(layer->CreateWindow( layer, &desc, &windowr ) );
     }
     
     {
	 	DFBWindowDescription desc;
	 	int i;
	 	
	 	i = DWDESC_POSX|DWDESC_POSY|DWDESC_WIDTH|DWDESC_HEIGHT|DWDESC_CAPS;
	 	memcpy(&desc.flags, &i, 4);
        desc.posx   = 0;
        desc.posy   = fontheigh + 5;
        desc.width  = screen_width / 2 - 5;
        desc.height = screen_height - (fontheigh + 5)*2;
        desc.caps   = DWCAPS_ALPHACHANNEL;
	 	DFBCHECK(layer->CreateWindow( layer, &desc, &windowl ) );
     }

	 windowr->GetSurface( windowr, &surfacer );
     windowr->CreateEventBuffer( windowr, &events );	
	 surfacer->SetFont( surfacer, font_normal );
	 surfacer->Clear( surfacer, 0xff, 0xff, 0xff, 0xff );
	 windowr->SetOpacity( windowr, 0xFF );

	 windowd->GetSurface( windowd, &surfaced );
	 windowd->AttachEventBuffer( windowd, events );
	 surfaced->Clear( surfaced, 0x60, 0xff, 0xff, 0xff );
	 windowd->SetOpacity( windowd, 0xFF );
	 surfaced->SetFont( surfaced, font_normal );
	 surfaced->SetColor( surfaced, 0x60, 0x60, 0x60, 0xFF );
	 
	 windowu->GetSurface( windowu, &surfaceu );
	 windowu->AttachEventBuffer( windowu, events );
	 surfaceu->Clear( surfaceu, 0x60, 0x60, 0xff, 0xff );
	 windowu->SetOpacity( windowu, 0xFF );
	 surfaceu->SetFont( surfaceu, font_normal );
	 surfaceu->SetColor( surfaceu, 0x60, 0x60, 0x60, 0xFF );
	 
	 windowl->GetSurface( windowl, &surfacel );
	 windowl->AttachEventBuffer( windowl, events );
	 surfacel->Clear( surfacel, 0xff, 0xff, 0xff, 0xff );
	 windowl->SetOpacity( windowl, 0xFF );
	 surfacel->SetFont( surfacel, font_normal );
	 surfacel->SetColor( surfacel, 0x60, 0x60, 0x60, 0xFF );
	 windowl->GetID( windowl, &lid );
	 windowl->RequestFocus( windowl );

	 lines = llines = 1;
	 flag = false;
	 nums = lnums = 0;
	 page = lpage = 0;
	 next = lnext = false;
	 tmpfile = "";
	 fileflg = false;
	 serdir = "/";
}

DFBDisplay::~DFBDisplay()
{
	if(font_normal) font_normal->Release( font_normal );
	if(events)      events->Release( events );
    if(surfacer)    surfacer->Release( surfacer );
    if(surfaced)    surfacer->Release( surfaced );
    if(surfaceu)    surfacer->Release( surfaceu );
    if(surfacel)    surfacer->Release( surfacel );
    if(windowr)     windowr->Release( windowr );
    if(windowd)     windowr->Release( windowd );
    if(windowu)     windowr->Release( windowu );
    if(windowl)     windowr->Release( windowl );
    if(layer)       layer->Release( layer );
    if(dfb)         dfb->Release( dfb );	
}

int DFBDisplay::GB2312ToUTF8( char *str )
{
	char *p,*c,*cs;
	iconv_t cd;
	size_t i,j;
	i = strlen(str);
	j = i*3;
	cs = str;

	if( 0 > (cd = iconv_open( "UTF8", "GB2312" )) )
		return 1;
	
	if( NULL == (p = ( char * )calloc( i, 3 )) )
		return 2;
	c=p;
	if( 0 > iconv( cd, &cs, &i, &p, &j ))
		return 3;
	
	iconv_close( cd );
	strcpy( str, c );
	free(c);
	return 0;
}
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -