00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "TaskManager.pan"
00013 #include "TaskManagerAppUi.h"
00014 #include "TaskManagerAppView.h"
00015 #include "TaskManager.hrh"
00016 #include "TaskManagerEngine.h"
00017 #include "TaskManagerConnForm.h"
00018 #include "TaskManagerConnInfo.h"
00019
00020 #include <avkon.rsg>
00021 #include <eikapp.h>
00022
00023
00024 _LIT(KSettingsFile, "socketsettings.txt");
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 void CTaskManagerAppUi::ConstructL()
00035 {
00036
00037 BaseConstructL(EAknEnableSkin);
00038
00039
00040 iAppView = CTaskManagerAppView::NewL(ClientRect(), *this);
00041
00042
00043 iAppView->SetMopParent(this);
00044
00045
00046 AddToStackL(iAppView);
00047
00048
00049 iEngine = CTaskManagerEngine::NewL(*iAppView);
00050
00051 #ifdef __SERIES60_30__
00052
00053 User::LeaveIfError( iEikonEnv->FsSession().CreatePrivatePath( EDriveC ) );
00054 User::LeaveIfError( iEikonEnv->FsSession().SetSessionToPrivate( EDriveC ) );
00055
00056 #else
00057
00058 #ifndef __WINS__ // don't save settings to z-drive in emulator
00059 TFileName appFullName = Application()->AppFullName();
00060 TParsePtr appPath(appFullName);
00061 iSettingsFile = appPath.DriveAndPath();
00062 #endif //__WINS__
00063 #endif
00064
00065 iSettingsFile.Append(KSettingsFile);
00066
00067
00068 InternalizeConnInfoL();
00069
00070
00071
00072
00073 if (CTaskManagerConnForm::RunDlgLD( iConnectionInfo ))
00074 {
00075 iEngine->SetConnectionSettings(iConnectionInfo.ServerAddress(),
00076 iConnectionInfo.Port(),
00077 iConnectionInfo.Username(),
00078 iConnectionInfo.Password());
00079 TUint32 iap;
00080 #ifdef __SERIES60_30__
00081
00082 iConnectionInfo.SetIap(iap);
00083 iEngine->SetIap(iap);
00084 iEngine->FetchTasksL();
00085
00086 #else
00087
00088
00089
00090 if (iAppView->QueryIapL(iap, iConnectionInfo.Iap()))
00091 {
00092 iConnectionInfo.SetIap(iap);
00093 iEngine->SetIap(iap);
00094 iEngine->FetchTasksL();
00095 }
00096 #endif
00097
00098
00099 ExternalizeConnInfoL();
00100 }
00101 iEngine->SetAutomaticUpdateL(ETrue);
00102 }
00103
00104
00105
00106
00107
00108
00109
00110 CTaskManagerAppUi::~CTaskManagerAppUi()
00111 {
00112 if (iAppView)
00113 {
00114 RemoveFromStack(iAppView);
00115 delete iAppView;
00116 iAppView = NULL;
00117 }
00118 delete iEngine;
00119 }
00120
00121
00122
00123
00124
00125
00126 void CTaskManagerAppUi::HandleCommandL(TInt aCommand)
00127 {
00128 switch(aCommand)
00129 {
00130 case EEikCmdExit:
00131 case EAknSoftkeyExit:
00132 Exit();
00133 break;
00134
00135 case ETaskManagerConnectionSettingsCommand:
00136 {
00137 iUiBusy = ETrue;
00138 iEngine->SetAutomaticUpdateL(EFalse);
00139
00140
00141 if (CTaskManagerConnForm::RunDlgLD( iConnectionInfo ))
00142 {
00143 TUint32 iap;
00144
00145 if (!iEngine->IapSet())
00146 {
00147 if (iAppView->QueryIapL(iap, iConnectionInfo.Iap()))
00148 {
00149 iConnectionInfo.SetIap(iap);
00150 iEngine->SetIap(iap);
00151 }
00152 }
00153
00154 iEngine->SetConnectionSettings(iConnectionInfo.ServerAddress(),
00155 iConnectionInfo.Port(),
00156 iConnectionInfo.Username(),
00157 iConnectionInfo.Password());
00158
00159
00160 ExternalizeConnInfoL();
00161 }
00162
00163 iUiBusy = EFalse;
00164 SetAutomaticUpdateL();
00165 }
00166 break;
00167
00168 case ETaskManagerLoadTasksCommand:
00169 iEngine->FetchTasksL();
00170 break;
00171
00172 case EAknSoftkeyCancel:
00173 iEngine->CancelTransaction();
00174 break;
00175
00176 default:
00177 Panic(ETaskManagerBasicUi);
00178 break;
00179 }
00180 }
00181
00182
00183
00184
00185
00186
00187
00188 void CTaskManagerAppUi::HandleForegroundEventL(TBool aForeground)
00189 {
00190 CAknAppUi::HandleForegroundEventL(aForeground);
00191
00192
00193
00194 if (aForeground)
00195 {
00196 SetAutomaticUpdateL();
00197 }
00198
00199
00200 else
00201 {
00202 iEngine->SetAutomaticUpdateL(EFalse);
00203 }
00204 }
00205
00206
00207
00208
00209
00210
00211 CTaskManagerEngine& CTaskManagerAppUi::Model()
00212 {
00213 return *iEngine;
00214 }
00215
00216
00217
00218
00219
00220
00221
00222 void CTaskManagerAppUi::ShowConnectingCbaL(const TBool& aShow)
00223 {
00224 if (aShow)
00225 {
00226 Cba()->SetCommandSetL(R_AVKON_SOFTKEYS_CANCEL);
00227 }
00228 else
00229 {
00230 Cba()->SetCommandSetL(R_AVKON_SOFTKEYS_OPTIONS_EXIT);
00231 }
00232 Cba()->DrawNow();
00233 }
00234
00235
00236
00237
00238
00239
00240 void CTaskManagerAppUi::InternalizeConnInfoL()
00241 {
00242 RFs& fs = CCoeEnv::Static()->FsSession();
00243 RFileReadStream readStream;
00244 TInt error = readStream.Open(fs, iSettingsFile, EFileRead);
00245 readStream.PushL();
00246 TInt internalizationError = KErrNone;
00247
00248 if (error == KErrNone)
00249 {
00250 TRAP(internalizationError, iConnectionInfo.InternalizeL(readStream);)
00251 }
00252 readStream.Pop();
00253 readStream.Release();
00254
00255
00256 if (internalizationError != KErrNone)
00257 {
00258 User::LeaveIfError(fs.Delete(iSettingsFile));
00259 }
00260
00261 }
00262
00263
00264
00265
00266
00267
00268 void CTaskManagerAppUi::ExternalizeConnInfoL()
00269 {
00270 RFs& fs = CCoeEnv::Static()->FsSession();
00271 RFileWriteStream writeStream;
00272 TInt error = writeStream.Open(fs, iSettingsFile, EFileWrite);
00273
00274 if (error != KErrNone)
00275 {
00276 User::LeaveIfError(writeStream.Create(fs, iSettingsFile, EFileWrite));
00277 }
00278 writeStream.PushL();
00279 writeStream << iConnectionInfo;
00280 writeStream.CommitL();
00281 writeStream.Pop();
00282 writeStream.Release();
00283 }
00284
00285
00286
00287
00288
00289
00290
00291 void CTaskManagerAppUi::SetViewBusyL(const TBool& aBusy)
00292 {
00293 iViewBusy = aBusy;
00294 if (aBusy)
00295 {
00296 iEngine->SetAutomaticUpdateL(EFalse);
00297 }
00298 else
00299 {
00300 SetAutomaticUpdateL();
00301 }
00302 }
00303
00304
00305
00306
00307
00308
00309
00310 void CTaskManagerAppUi::SetAutomaticUpdateL()
00311 {
00312 if (!iViewBusy && !iUiBusy)
00313 {
00314 iEngine->SetAutomaticUpdateL(ETrue);
00315 }
00316 }
00317
00318