creator/src/enginewrapper.cpp
branchRCL_3
changeset 22 fad26422216a
parent 21 b3cee849fa46
child 23 f8280f3bfeb7
equal deleted inserted replaced
21:b3cee849fa46 22:fad26422216a
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <hbprogressdialog.h>
       
    20 #include <hbmessagebox.h>
       
    21 #include <hblabel.h>
       
    22 
       
    23 #include <QString>
       
    24 #include <QDate>
       
    25 
       
    26 #include <e32std.h>
       
    27 #include <e32base.h>
       
    28 
       
    29 #include "creator.hrh" // for command ids
       
    30 #include "notifications.h"
       
    31 #include "enginewrapper.h"
       
    32 #include "engine.h"
       
    33 #include "mainview.h"
       
    34 
       
    35 
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 
       
    39 EngineWrapper::EngineWrapper()
       
    40 : iEngine(0), iProgressDialog(0)
       
    41 {
       
    42 }
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 
       
    46 EngineWrapper::~EngineWrapper()
       
    47 {
       
    48     if (iEngine != 0) {
       
    49         delete iEngine;
       
    50     }
       
    51     if (iProgressDialog != 0) {
       
    52         delete iProgressDialog;
       
    53     }
       
    54 }
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 
       
    58 bool EngineWrapper::init()
       
    59 {
       
    60     TRAPD(err, iEngine = CCreatorEngine::NewL(this));
       
    61     if(err != KErrNone) {
       
    62         return false;
       
    63     }
       
    64     else {
       
    65         return true;
       
    66     }
       
    67 }
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 
       
    71 QList<MemoryDetails> EngineWrapper::GetMemoryDetailsList()
       
    72 	{
       
    73 	RPointerArray<TMemoryDetails> tMemDetList = iEngine->GetMemoryDetailsList();
       
    74 	QList<MemoryDetails> memDetList;
       
    75 	MemoryDetails memDet;
       
    76 		for(int i=0; i<tMemDetList.Count(); i++)
       
    77 			{
       
    78 			TMemoryDetails* temp = tMemDetList.operator [](i);
       
    79 			QString free = QString::fromUtf16(tMemDetList.operator [](i)->iFree.Ptr(), tMemDetList.operator [](i)->iFree.Length());//QString((QChar*) temp->iFree.Ptr(), temp->iFree.Length());
       
    80 			QString size = QString::fromUtf16(tMemDetList.operator [](i)->iSize.Ptr(), tMemDetList.operator [](i)->iSize.Length());//QString((QChar*) temp->iSize.Ptr(), temp->iSize.Length());
       
    81 			QString driveLetter = QString::fromUtf8((const char*) &tMemDetList.operator [](i)->iDriveLetter, (int) sizeof(char) );//QString((QChar*) &temp->iDriveLetter, (int) sizeof( char ) );
       
    82 			memDet.mFree = free; //QString((QChar*)tMemDetList[i]->iFree.Ptr(), tMemDetList[i]->iFree.Length());
       
    83 			memDet.mSize = size; //QString((QChar*) tMemDetList[i]->iSize.Ptr(), tMemDetList[i]->iSize.Length());
       
    84 			memDet.mDriveLetter = driveLetter;
       
    85 			
       
    86 			//memDetList[i].mDriveLetter = QString::fromUtf8( (char *) &tMemDetList[i]->iDriveLetter, (int) sizeof( char ) );
       
    87 			memDetList.append( memDet );
       
    88 			}
       
    89 	return memDetList;
       
    90 	}
       
    91 
       
    92 MemoryDetails EngineWrapper::GetMemoryDetails()
       
    93 {
       
    94 	
       
    95     TMemoryDetails tMemoryDetails = iEngine->GetMemoryDetails();
       
    96     MemoryDetails memoryDetails;
       
    97 
       
    98     // Convert TMemoryDetails to MemoryDetails 
       
    99 	memoryDetails.mRamFree  = QString((QChar*)tMemoryDetails.iRamFree.Ptr(), tMemoryDetails.iRamFree.Length());
       
   100 	memoryDetails.mRamSize  = QString((QChar*)tMemoryDetails.iRamSize.Ptr(), tMemoryDetails.iRamSize.Length());
       
   101 
       
   102 	return memoryDetails;
       
   103 }
       
   104 
       
   105 
       
   106 // ---------------------------------------------------------------------------
       
   107 
       
   108 void EngineWrapper::ShowErrorMessage(const TDesC& aErrorMessage)
       
   109 {
       
   110     QString errorMessage((QChar*)aErrorMessage.Ptr(),aErrorMessage.Length());
       
   111     Notifications::error(errorMessage);
       
   112  
       
   113 }
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 
       
   117 void EngineWrapper::ShowNote(const TDesC& aNoteMessage, TInt /*aResourceId*/)
       
   118 {
       
   119     QString note((QChar*)aNoteMessage.Ptr(),aNoteMessage.Length());
       
   120     Notifications::showGlobalNote(note, HbMessageBox::MessageTypeInformation, HbPopup::ConfirmationNoteTimeout);
       
   121 }
       
   122 
       
   123 // ---------------------------------------------------------------------------
       
   124 
       
   125 void EngineWrapper::ShowProgressBar(const TDesC& aPrompt, int aMax)
       
   126 {
       
   127 	QString text((QChar*)aPrompt.Ptr(), aPrompt.Length());
       
   128 	if(iProgressDialog){
       
   129         delete iProgressDialog;
       
   130         iProgressDialog = NULL;
       
   131 	}
       
   132     iProgressDialog = Notifications::showProgressBar(text, aMax);
       
   133 	connect(iProgressDialog, SIGNAL(cancelled()), this, SLOT(ProgressDialogCancelled()));
       
   134 }
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 
       
   138 void EngineWrapper::IncrementProgressbarValue()
       
   139 {
       
   140     if(iProgressDialog)
       
   141         iProgressDialog->setProgressValue(iProgressDialog->progressValue() + 1);
       
   142 }
       
   143 
       
   144 // ---------------------------------------------------------------------------
       
   145 
       
   146 void EngineWrapper::CloseProgressbar()
       
   147 {
       
   148     if(iProgressDialog){
       
   149         disconnect(iProgressDialog, SIGNAL(cancelled()), this, SLOT(ProgressDialogCancelled()));
       
   150         delete iProgressDialog;
       
   151         iProgressDialog = NULL;
       
   152     }
       
   153 }
       
   154 
       
   155 // ---------------------------------------------------------------------------
       
   156 
       
   157 TBool EngineWrapper::EntriesQueryDialog(TInt* aNumberOfEntries, const TDesC& aPrompt, TBool aAcceptsZero, MUIObserver* observer, int userData)
       
   158     {
       
   159 	QString text((QChar*)aPrompt.Ptr(), aPrompt.Length());
       
   160 	TBool success(EFalse);
       
   161     try{
       
   162         CreatorInputDialog::launch(text, aNumberOfEntries, aAcceptsZero ? true : false, observer, userData);
       
   163         success = ETrue;
       
   164     }
       
   165     catch (std::exception& e)
       
   166         {
       
   167         Notifications::error( QString("exception: ")+e.what() );
       
   168         }
       
   169 	return success;
       
   170     }
       
   171 	
       
   172 // ---------------------------------------------------------------------------	
       
   173 
       
   174 TBool EngineWrapper::TimeQueryDialog(TTime* aTime, const TDesC& aPrompt, MUIObserver* observer, int userData)
       
   175     {
       
   176     QString text((QChar*)aPrompt.Ptr(), aPrompt.Length());
       
   177     TBool success(EFalse);
       
   178     try{
       
   179         CreatorDateTimeDialog::launch(text, aTime, observer, userData); 
       
   180         success = ETrue;
       
   181     }
       
   182     catch (std::exception& e)
       
   183         {
       
   184         Notifications::error( QString("exception: ")+e.what() );
       
   185         }
       
   186     return success;
       
   187     }
       
   188 
       
   189 TBool EngineWrapper::YesNoQueryDialog(const TDesC& aPrompt, MUIObserver* observer, int userData)
       
   190 {
       
   191 	QString text((QChar*)aPrompt.Ptr(), aPrompt.Length());
       
   192 	TBool success(EFalse);
       
   193     try{
       
   194         CreatorYesNoDialog::launch(text, "", observer, userData);	
       
   195         success = ETrue;
       
   196     }
       
   197     catch (std::exception& e)
       
   198         {
       
   199         Notifications::error( QString("exception: ")+e.what() );
       
   200         }
       
   201     return success;
       
   202 }
       
   203  
       
   204 // ---------------------------------------------------------------------------	
       
   205 
       
   206 bool EngineWrapper::ExecuteOptionsMenuCommand(int commandId)
       
   207 {
       
   208 	TInt err = KErrNone;
       
   209 	if (commandId == ECmdCreateFromFile) {
       
   210 		TRAP(err, iEngine->RunScriptL());
       
   211 	}
       
   212 	else if (commandId == ECmdSelectRandomDataFile) {
       
   213 		TBool ret = EFalse;
       
   214 		TRAP(err, ret = iEngine->GetRandomDataL());
       
   215 		if ( err != KErrNone || ret == EFalse ) {
       
   216 			Notifications::error("Error in getting random data.");
       
   217 			return false;
       
   218 		}		
       
   219 	}
       
   220     else {
       
   221 		TRAP(err, iEngine->ExecuteOptionsMenuCommandL(commandId));
       
   222 	}
       
   223 	// error handling
       
   224     if(err != KErrNone) {
       
   225         return false;
       
   226     }
       
   227     else {
       
   228         return true;
       
   229     }
       
   230 }
       
   231 
       
   232 // ---------------------------------------------------------------------------	
       
   233 
       
   234 TBool EngineWrapper::PopupListDialog(const TDesC& aPrompt, const CDesCArray* aFileNameArray, TInt* aIndex, MUIObserver* aObserver, TInt aUserData) 
       
   235 {
       
   236 	QString text((QChar*)aPrompt.Ptr(), aPrompt.Length());
       
   237 	QStringList itemList;
       
   238 
       
   239 	for (int i = 0; i < aFileNameArray->Count(); i++) {
       
   240 		itemList.append(QString::fromUtf16(
       
   241 				  aFileNameArray->MdcaPoint(i).Ptr(),
       
   242 				  aFileNameArray->MdcaPoint(i).Length()));
       
   243 	}
       
   244 	TBool success(EFalse);
       
   245     try{
       
   246         CreatorSelectionDialog::launch(text, itemList, aIndex, aObserver, aUserData);
       
   247 	    success = ETrue;
       
   248     }
       
   249     catch (std::exception& e)
       
   250         {
       
   251         Notifications::error( QString("exception: ")+e.what() );
       
   252         }
       
   253     return success;
       
   254 }
       
   255 
       
   256 // ---------------------------------------------------------------------------	
       
   257 
       
   258 TBool EngineWrapper::DirectoryQueryDialog(const TDesC& aPrompt, TDes& aDirectory, MUIObserver* aObserver, TInt aUserData)
       
   259 {
       
   260 	QString text((QChar*)aPrompt.Ptr(), aPrompt.Length());
       
   261 	TBool success(EFalse);
       
   262     try{
       
   263         CreatorInputDialog::launch(text, aDirectory, aObserver, aUserData);
       
   264         success = ETrue;
       
   265     }
       
   266     catch (std::exception& e)
       
   267         {
       
   268         Notifications::error( QString("exception: ")+e.what() );
       
   269         }
       
   270     return success;
       
   271 }
       
   272 
       
   273 
       
   274 // ---------------------------------------------------------------------------
       
   275 
       
   276 void EngineWrapper::ProgressDialogCancelled()
       
   277 {
       
   278 	CloseProgressbar();
       
   279 	TRAPD(err, iEngine->ProgressDialogCancelledL());
       
   280 	// error handling
       
   281     if(err != KErrNone) {
       
   282         Notifications::error("Error in operation cancel.");
       
   283     }	
       
   284 }
       
   285 
       
   286 // ---------------------------------------------------------------------------
       
   287 
       
   288 TBool EngineWrapper::ListQueryDialog(const TDesC& aPrompt, TListQueryId aId, TInt* aIndex, MUIObserver* aObserver, TInt aUserData)
       
   289 {
       
   290 	bool ret = false;
       
   291 	QString text((QChar*)aPrompt.Ptr(), aPrompt.Length());
       
   292 	QStringList itemList;
       
   293 	
       
   294 	switch (aId) {
       
   295 		case R_CONTACT_CREATION_TYPE_QUERY: {
       
   296 			itemList << "Default fields" << "Define...";
       
   297 			break;
       
   298 		}
       
   299 		case R_GROUP_CREATION_TYPE_QUERY: {
       
   300 			itemList << "Random" << "Define...";
       
   301 			break;
       
   302 		}
       
   303 		case R_MESSAGE_TYPE_QUERY: {
       
   304 			itemList << "SMS" << "MMS" << "AMS" << "Email" << "Smart Message" << "IR Message" << "BT Message";
       
   305 			break;
       
   306 		}
       
   307 		case R_FOLDER_TYPE_QUERY: {
       
   308 			itemList << "Inbox" << "Drafts" << "Outbox" << "Sent";
       
   309 			break;
       
   310 		}
       
   311 		case R_UNREAD_QUERY: {
       
   312 			itemList << "Read" << "New";
       
   313 			break;
       
   314 		}
       
   315 		case R_ATTACHMENT_MULTI_SELECTION_QUERY: {
       
   316 			Notifications::error("Not supported resource id."); 
       
   317 			break;
       
   318 		}
       
   319 		case R_AMS_ATTACHMENT_SINGLE_SELECTION_QUERY: {
       
   320 			itemList << "AMR 20kB";
       
   321 			break;
       
   322 		}
       
   323 		case R_ATTACHMENT_SINGLE_SELECTION_QUERY: {
       
   324 			itemList << "JPEG 25kB" << "JPEG 300kB" << "JPEG 500kB" << "PNG 15kB" << "GIF 2kB" << "RNG 1kB" 
       
   325 			<< "MIDI 10kB" << "WAVE 20kB" << "AMR 20kB" << "Excel 15kB" << "Word 20kB" << "PowerPoint 40kB" 
       
   326 			<< "Text 10kB" << "Text 70kB" << "3GPP 70kB" << "MP3 250kB" << "AAC 100kB" << "RM 95kB";
       
   327 			break;
       
   328 		}
       
   329 		default: {
       
   330 			Notifications::error("Error in resource id.");
       
   331 			return ret;
       
   332 		}
       
   333 	}
       
   334 	TBool success(EFalse);
       
   335     try{
       
   336         CreatorSelectionDialog::launch(text, itemList, aIndex, aObserver, aUserData);
       
   337         success = ETrue;
       
   338     }
       
   339     catch (std::exception& e)
       
   340         {
       
   341         Notifications::error( QString("exception: ")+e.what() );
       
   342         }
       
   343     return success;
       
   344 }
       
   345 
       
   346 TBool EngineWrapper::ListQueryDialog(const TDesC& aPrompt, TListQueryId aId, CArrayFixFlat<TInt>* aSelectedItems, MUIObserver* aObserver, TInt aUserData)
       
   347 {
       
   348     TBool success(EFalse);
       
   349 	QStringList itemList;
       
   350 	QString text((QChar*)aPrompt.Ptr(), aPrompt.Length());
       
   351 	if (aId == R_ATTACHMENT_MULTI_SELECTION_QUERY) {
       
   352        itemList << "None" << "JPEG 25kB" << "JPEG 300kB" << "JPEG 500kB" << "PNG 15kB" << "GIF 2kB" << "RNG 1kB" 
       
   353            << "MIDI 10kB" << "WAVE 20kB" << "AMR 20kB" << "Excel 15kB" << "Word 20kB" << "PowerPoint 40kB" 
       
   354            << "Text 10kB" << "Text 70kB" << "3GPP 70kB" << "MP3 250kB" << "AAC 100kB" << "RM 95kB";
       
   355 	}
       
   356 	else{
       
   357         Notifications::error("Error in resource id.");
       
   358         return EFalse;
       
   359     }
       
   360 	
       
   361     try{
       
   362         CreatorSelectionDialog::launch(text, itemList, aSelectedItems, aObserver, aUserData);
       
   363         success = ETrue;
       
   364     }
       
   365     catch (std::exception& e)
       
   366         {
       
   367         Notifications::error( QString("exception: ")+e.what() );
       
   368         }
       
   369     return success;
       
   370 }
       
   371 
       
   372 void EngineWrapper::CloseCreatorApp()
       
   373 {
       
   374 	MainView::closeApp();
       
   375 }