7 #include <aknmessagequerydialog.h>
10 #include "LogNull.hpp"
12 #include "ServerPtr.hpp"
13 #include "SymbianNetwork.hpp"
14 #include "AuthNone.hpp"
15 #include "AuthToken.hpp"
16 #include "Exceptions.hpp"
17 #include "resource/dftpd.hrh"
24 class FtpAppView
: public CCoeControl
27 FtpAppView( const TRect
& aRect
);
28 virtual ~FtpAppView() {}
30 void Draw( const TRect
& aRect
) const { m_view
->Draw( aRect
); };
31 virtual void SizeChanged() { m_view
->SetRect( Rect() ); }
33 void Log( const std::string
& text
);
38 FtpAppView::FtpAppView( const TRect
& aRect
)
42 m_view
= new CEikEdwin
;
43 m_view
->SetContainerWindowL( *this );
44 m_view
->ConstructL( EEikEdwinDisplayOnly
| EEikEdwinNoAutoSelection
);
50 void FtpAppView::Log( const std::string
& _text
)
52 std::string text
= _text
+ '\f';
54 TPtrC8
ptr( reinterpret_cast<const TUint8
*>( text
.c_str() ) );
59 m_view
->Text()->InsertL( m_view
->Text()->DocumentLength(), log
);
60 m_view
->HandleTextChangedL();
61 m_view
->SetCursorPosL( m_view
->Text()->DocumentLength(), EFalse
);
62 m_view
->NotifyNewFormatL();
67 class FtpAppUi
: public CAknAppUi
, public CActive
, public Log
70 FtpAppUi() : CActive( EPriorityStandard
), iAppView( NULL
), m_starter( NULL
), m_authenticationEnabled( true ) { g_log
= this; }
75 void HandleCommandL( TInt aCommand
);
76 void HandleResourceChangeL( TInt aType
);
78 static TBool
StartL( TAny
* aThis
);
84 void Print( const std::string
& text
);
94 bool m_authenticationEnabled
;
111 void FtpAppUi::ConstructL()
113 BaseConstructL( EAknEnableSkin
);
114 iAppView
= new FtpAppView( ClientRect() );
116 CActiveScheduler::Add( this );
118 m_starter
= CIdle::NewL( CActive::EPriorityLow
);
119 m_starter
->Start( TCallBack( StartL
, this ) );
122 void FtpAppUi::HandleCommandL( TInt aCommand
)
127 case EAknSoftkeyExit
:
134 if( !m_authenticationEnabled
)
136 g_log
->Print( "Enabling authentication" );
137 m_auth
.reset( new AuthToken
);
138 m_server
->SetAuth( m_auth
);
139 m_authenticationEnabled
= true;
141 ((AuthToken
*)m_auth
.get())->GenerateToken();
145 case EDisableAuthentication
:
146 if( m_authenticationEnabled
&& m_server
)
148 g_log
->Print( "Authentication disabled" );
149 m_auth
.reset( new AuthNone
);
150 m_server
->SetAuth( m_auth
);
151 m_authenticationEnabled
= false;
157 CAknMessageQueryDialog
* dlg
= new CAknMessageQueryDialog
;
158 dlg
->ExecuteLD( R_DFTPD_ABOUT
);
167 void FtpAppUi::HandleResourceChangeL( TInt aType
)
169 CAknAppUi::HandleResourceChangeL( aType
);
170 if( aType
== KEikDynamicLayoutVariantSwitch
&& iAppView
!= NULL
)
172 iAppView
->SetRect( ClientRect() );
176 TBool
FtpAppUi::StartL( TAny
* aThis
)
178 static_cast<FtpAppUi
*>( aThis
)->StartL();
182 void FtpAppUi::StartL()
188 m_auth
.reset( new AuthToken
);
189 ip
= EstablishConnection();
190 m_server
= Server::Create( m_auth
, ip
);
192 catch( ServerCrash
& e
)
198 CEikStatusPane
* sp
= iEikonEnv
->AppUiFactory()->StatusPane();
199 CAknNavigationControlContainer
* iNaviPane
= (CAknNavigationControlContainer
*)sp
->ControlL( TUid::Uid( EEikStatusPaneUidNavi
) );
201 TPtrC8
ptr( reinterpret_cast<const TUint8
*>( ip
.c_str() ) );
204 naviLabel
.Copy( ptr
);
205 iNaviPane
->PushL( *iNaviPane
->CreateNavigationLabelL( naviLabel
) );
207 m_timer
.CreateLocal();
208 m_timer
.After( iStatus
, 10 );
212 void FtpAppUi::RunL()
218 catch( ServerCrash
& e
)
224 m_timer
.After( iStatus
, 10 );
228 void FtpAppUi::DoCancel()
233 void FtpAppUi::Print( const std::string
& text
)
235 iAppView
->Log( text
);
238 void FtpAppUi::ServerCrashed()
240 CEikStatusPane
* sp
= iEikonEnv
->AppUiFactory()->StatusPane();
241 CAknNavigationControlContainer
* iNaviPane
= (CAknNavigationControlContainer
*)sp
->ControlL( TUid::Uid( EEikStatusPaneUidNavi
) );
243 _LIT( naviLabel
, "Server crashed" );
244 iNaviPane
->PushL( *iNaviPane
->CreateNavigationLabelL( naviLabel
) );
251 class FtpDocument
: public CAknDocument
254 FtpDocument( CEikApplication
& aApp
) : CAknDocument( aApp
) {}
255 CEikAppUi
* CreateAppUiL() { return static_cast<CEikAppUi
*>( new FtpAppUi
); }
260 const TUid FtpUid
= { 0xA0102039 };
262 class FtpApplication
: public CAknApplication
265 TUid
AppDllUid() const { return FtpUid
; }
266 CApaDocument
* CreateDocumentL() { return static_cast<CApaDocument
*>( new FtpDocument( *this ) ); }
271 LOCAL_C CApaApplication
* NewApplication()
273 return new FtpApplication
;
276 GLDEF_C TInt
E32Main()
278 return EikStart::RunApplication( NewApplication
);