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