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