creator/src/enginewrapper.cpp
changeset 19 4b22a598b890
parent 17 4f2773374eff
child 23 c9bf25a20c9f
equal deleted inserted replaced
17:4f2773374eff 19:4b22a598b890
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 #include <hbprogressdialog.h>
    19 #include <hbprogressdialog.h>
    20 #include <hbmessagebox.h>
    20 #include <hbmessagebox.h>
    21 
    21 #include <hblabel.h>
    22 #include <hbpopup.h>
       
    23 
    22 
    24 #include <QString>
    23 #include <QString>
    25 #include <QDate>
    24 #include <QDate>
    26 
    25 
    27 #include <e32std.h>
    26 #include <e32std.h>
   104  
   103  
   105 }
   104 }
   106 
   105 
   107 // ---------------------------------------------------------------------------
   106 // ---------------------------------------------------------------------------
   108 
   107 
   109 void EngineWrapper::ShowNote(const TDesC& aNoteMessage, TInt aResourceId)
   108 void EngineWrapper::ShowNote(const TDesC& aNoteMessage, TInt /*aResourceId*/)
   110 {
   109 {
   111     QString note((QChar*)aNoteMessage.Ptr(),aNoteMessage.Length());
   110     QString note((QChar*)aNoteMessage.Ptr(),aNoteMessage.Length());
   112     Notifications::showGlobalNote(note, HbMessageBox::MessageTypeInformation, HbPopup::ConfirmationNoteTimeout);
   111     Notifications::showGlobalNote(note, HbMessageBox::MessageTypeInformation, HbPopup::ConfirmationNoteTimeout);
   113 }
   112 }
   114 
   113 
   130 
   129 
   131 // ---------------------------------------------------------------------------
   130 // ---------------------------------------------------------------------------
   132 
   131 
   133 void EngineWrapper::CloseProgressbar()
   132 void EngineWrapper::CloseProgressbar()
   134 {
   133 {
   135     delete iProgressDialog;
   134     if(iProgressDialog){
   136     iProgressDialog = 0;
   135         delete iProgressDialog;
   137 }
   136         iProgressDialog = 0;
   138 
   137     }
   139 // ---------------------------------------------------------------------------
   138 }
   140 
   139 
   141 TBool EngineWrapper::EntriesQueryDialog(TInt& aNumberOfEntries, const TDesC& aPrompt, TBool aAcceptsZero)
   140 // ---------------------------------------------------------------------------
       
   141 
       
   142 TBool EngineWrapper::EntriesQueryDialog(TInt* aNumberOfEntries, const TDesC& aPrompt, TBool aAcceptsZero, MUIObserver* observer, int userData)
   142     {
   143     {
   143 	QString text((QChar*)aPrompt.Ptr(), aPrompt.Length());
   144 	QString text((QChar*)aPrompt.Ptr(), aPrompt.Length());
   144     bool err = Notifications::entriesQueryDialog(aNumberOfEntries, text, aAcceptsZero);
   145 	TBool success(EFalse);
   145 	return err;
   146     try{
       
   147         CreatorInputDialog::launch(text, aNumberOfEntries, aAcceptsZero ? true : false, observer, userData);
       
   148         success = ETrue;
       
   149     }
       
   150     catch (std::exception& e)
       
   151         {
       
   152         Notifications::error( QString("exception: ")+e.what() );
       
   153         }
       
   154 	return success;
   146     }
   155     }
   147 	
   156 	
   148 // ---------------------------------------------------------------------------	
   157 // ---------------------------------------------------------------------------	
   149 
   158 
   150 TBool EngineWrapper::TimeQueryDialog(TTime aTime, const TDesC& aPrompt)
   159 TBool EngineWrapper::TimeQueryDialog(TTime* aTime, const TDesC& aPrompt, MUIObserver* observer, int userData)
   151     {
   160     {
   152     // TTime to QDate
   161     QString text((QChar*)aPrompt.Ptr(), aPrompt.Length());
   153     TBuf<20> timeString;
   162     TBool success(EFalse);
   154     _LIT(KDateString,"%D%M%Y%/0%1%/1%2%/2%3%/3");
   163     try{
   155     TRAP_IGNORE( aTime.FormatL(timeString, KDateString) );
   164         CreatorDateTimeDialog::launch(text, aTime, observer, userData); 
   156     QString temp = QString::fromUtf16(timeString.Ptr(), timeString.Length());
   165         success = ETrue;
   157     temp.replace(QChar('/'), QChar('-'));
   166     }
   158     QDate date = QDate::fromString(temp, "dd-MM-yyyy");
   167     catch (std::exception& e)
   159 
   168         {
   160 	QString text((QChar*)aPrompt.Ptr(), aPrompt.Length());
   169         Notifications::error( QString("exception: ")+e.what() );
   161     bool err = Notifications::timeQueryDialog(date, text);
   170         }
   162 	return err;
   171     return success;
   163     }
   172     }
   164 
   173 
   165 TBool EngineWrapper::YesNoQueryDialog(const TDesC& aPrompt)
   174 TBool EngineWrapper::YesNoQueryDialog(const TDesC& aPrompt, MUIObserver* observer, int userData)
   166 {
   175 {
   167 	QString text((QChar*)aPrompt.Ptr(), aPrompt.Length());
   176 	QString text((QChar*)aPrompt.Ptr(), aPrompt.Length());
   168     return Notifications::yesNoQueryDialog(text);	
   177 	TBool success(EFalse);
       
   178     try{
       
   179         CreatorYesNoDialog::launch(text, "", observer, userData);	
       
   180         success = ETrue;
       
   181     }
       
   182     catch (std::exception& e)
       
   183         {
       
   184         Notifications::error( QString("exception: ")+e.what() );
       
   185         }
       
   186     return success;
   169 }
   187 }
   170  
   188  
   171 // ---------------------------------------------------------------------------	
   189 // ---------------------------------------------------------------------------	
   172 
   190 
   173 bool EngineWrapper::ExecuteOptionsMenuCommand(int commandId)
   191 bool EngineWrapper::ExecuteOptionsMenuCommand(int commandId)
   175 	TInt err = KErrNone;
   193 	TInt err = KErrNone;
   176 	if (commandId == ECmdCreateFromFile) {
   194 	if (commandId == ECmdCreateFromFile) {
   177 		TRAP(err, iEngine->RunScriptL());
   195 		TRAP(err, iEngine->RunScriptL());
   178 	}
   196 	}
   179 	else if (commandId == ECmdSelectRandomDataFile) {
   197 	else if (commandId == ECmdSelectRandomDataFile) {
   180 		TFileName filename;
       
   181 		TBool ret = EFalse;
   198 		TBool ret = EFalse;
   182 		TRAP(err, ret = iEngine->GetRandomDataFilenameL(filename));
   199 		TRAP(err, ret = iEngine->GetRandomDataL());
   183 		if (err != KErrNone) {
   200 		if ( err != KErrNone || ret == EFalse ) {
   184 			Notifications::error("Error in getting random data.");
   201 			Notifications::error("Error in getting random data.");
   185 			return false;
   202 			return false;
   186 		}		
   203 		}		
   187 		if (ret == true) {
       
   188 			TRAP(err, iEngine->GetRandomDataFromFileL(filename));
       
   189 		}
       
   190 	}
   204 	}
   191     else {
   205     else {
   192 		TRAP(err, iEngine->ExecuteOptionsMenuCommandL(commandId));
   206 		TRAP(err, iEngine->ExecuteOptionsMenuCommandL(commandId));
   193 	}
   207 	}
   194 	// error handling
   208 	// error handling
   200     }
   214     }
   201 }
   215 }
   202 
   216 
   203 // ---------------------------------------------------------------------------	
   217 // ---------------------------------------------------------------------------	
   204 
   218 
   205 bool EngineWrapper::PopupListDialog(const TDesC& aPrompt, CDesCArray* aFileNameArray, TInt& aIndex) 
   219 TBool EngineWrapper::PopupListDialog(const TDesC& aPrompt, const CDesCArray* aFileNameArray, TInt* aIndex, MUIObserver* aObserver, TInt aUserData) 
   206 {
   220 {
   207 	QString text((QChar*)aPrompt.Ptr(), aPrompt.Length());
   221 	QString text((QChar*)aPrompt.Ptr(), aPrompt.Length());
   208 	QStringList itemList;
   222 	QStringList itemList;
   209 
   223 
   210 	for (int i = 0; i < aFileNameArray->Count(); i++) {
   224 	for (int i = 0; i < aFileNameArray->Count(); i++) {
   211 		itemList.append(QString::fromUtf16(
   225 		itemList.append(QString::fromUtf16(
   212 				  aFileNameArray->MdcaPoint(i).Ptr(),
   226 				  aFileNameArray->MdcaPoint(i).Ptr(),
   213 				  aFileNameArray->MdcaPoint(i).Length()));
   227 				  aFileNameArray->MdcaPoint(i).Length()));
   214 	}
   228 	}
   215 	// TODO: HbSelectionDialog handle close & user choice
   229 	// TODO: HbSelectionDialog handle close & user choice
   216 	Notifications::popupListDialog(text, itemList, HbAbstractItemView::SingleSelection);
   230 	TBool success(EFalse);
   217 	return false;
   231     try{
       
   232         CreatorSelectionDialog::launch(text, itemList, aIndex, aObserver, aUserData);
       
   233 	    success = ETrue;
       
   234     }
       
   235     catch (std::exception& e)
       
   236         {
       
   237         Notifications::error( QString("exception: ")+e.what() );
       
   238         }
       
   239     return success;
   218 }
   240 }
   219 
   241 
   220 // ---------------------------------------------------------------------------	
   242 // ---------------------------------------------------------------------------	
   221 
   243 
   222 bool EngineWrapper::DirectoryQueryDialog(const TDesC& aPrompt, TFileName& aDirectory)
   244 bool EngineWrapper::DirectoryQueryDialog(const TDesC& aPrompt, TFileName& aDirectory)
   244     }	
   266     }	
   245 }
   267 }
   246 
   268 
   247 // ---------------------------------------------------------------------------
   269 // ---------------------------------------------------------------------------
   248 
   270 
   249 bool EngineWrapper::ListQueryDialog(const TDesC& aPrompt, TListQueryId aId, TInt& aIndex)
   271 TBool EngineWrapper::ListQueryDialog(const TDesC& aPrompt, TListQueryId aId, TInt* aIndex, MUIObserver* aObserver, TInt aUserData)
   250 {
   272 {
   251 	bool ret = false;
   273 	bool ret = false;
   252 	QString text((QChar*)aPrompt.Ptr(), aPrompt.Length());
   274 	QString text((QChar*)aPrompt.Ptr(), aPrompt.Length());
   253 	QStringList itemList;
   275 	QStringList itemList;
   254 	
   276 	
   291 			Notifications::error("Error in resource id.");
   313 			Notifications::error("Error in resource id.");
   292 			return ret;
   314 			return ret;
   293 		}
   315 		}
   294 	}
   316 	}
   295     // TODO: HbSelectionDialog handle close & user choice
   317     // TODO: HbSelectionDialog handle close & user choice
   296     Notifications::popupListDialog(text, itemList, HbAbstractItemView::SingleSelection);
   318 	TBool success(EFalse);
   297     return false;
   319     try{
   298 
   320         CreatorSelectionDialog::launch(text, itemList, aIndex, aObserver, aUserData);
   299 }
   321         success = ETrue;
   300 
   322     }
   301 bool EngineWrapper::ListQueryDialog(const TDesC& aPrompt, TListQueryId aId, CArrayFixFlat<TInt>* aIndexes)
   323     catch (std::exception& e)
   302 {
   324         {
   303 	bool ret = false;
   325         Notifications::error( QString("exception: ")+e.what() );
   304 	QString text((QChar*)aPrompt.Ptr(), aPrompt.Length());
   326         }
       
   327     return success;
       
   328 }
       
   329 
       
   330 TBool EngineWrapper::ListQueryDialog(const TDesC& aPrompt, TListQueryId aId, CArrayFixFlat<TInt>* aSelectedItems, MUIObserver* aObserver, TInt aUserData)
       
   331 {
       
   332     TBool success(EFalse);
   305 	QStringList itemList;
   333 	QStringList itemList;
   306 	QList<int> indexes;
   334 	QString text((QChar*)aPrompt.Ptr(), aPrompt.Length());
   307 	if (aId == R_ATTACHMENT_MULTI_SELECTION_QUERY) {
   335 	if (aId == R_ATTACHMENT_MULTI_SELECTION_QUERY) {
   308 		itemList << "None" << "JPEG 25kB" << "JPEG 300kB" << "JPEG 500kB" << "PNG 15kB" << "GIF 2kB" << "RNG 1kB" 
   336        itemList << "None" << "JPEG 25kB" << "JPEG 300kB" << "JPEG 500kB" << "PNG 15kB" << "GIF 2kB" << "RNG 1kB" 
   309 			<< "MIDI 10kB" << "WAVE 20kB" << "AMR 20kB" << "Excel 15kB" << "Word 20kB" << "PowerPoint 40kB" 
   337            << "MIDI 10kB" << "WAVE 20kB" << "AMR 20kB" << "Excel 15kB" << "Word 20kB" << "PowerPoint 40kB" 
   310 			<< "Text 10kB" << "Text 70kB" << "3GPP 70kB" << "MP3 250kB" << "AAC 100kB" << "RM 95kB";
   338            << "Text 10kB" << "Text 70kB" << "3GPP 70kB" << "MP3 250kB" << "AAC 100kB" << "RM 95kB";
   311 
   339 	}
   312 		//ret = Notifications::popupListDialog(text, itemList, indexes);
   340 	else{
   313 		// TODO: HbSelectionDialog handle close & user choice
   341         Notifications::error("Error in resource id.");
   314 		Notifications::popupListDialog(text, itemList, HbAbstractItemView::MultiSelection);
   342         return EFalse;
   315 
   343     }
   316 		if (ret == true) {
   344 	
   317 			aIndexes->Reset();
   345     try{
   318 			for (int i = 0; i < indexes.count(); i++) {
   346         CreatorSelectionDialog::launch(text, itemList, aSelectedItems, aObserver, aUserData);
   319 				aIndexes->AppendL(indexes.at(i));
   347         success = ETrue;
   320 			}
   348     }
   321 		}
   349     catch (std::exception& e)
   322 	}
   350         {
   323 	return ret;			
   351         Notifications::error( QString("exception: ")+e.what() );
       
   352         }
       
   353     return success;
   324 }
   354 }
   325 
   355 
   326 void EngineWrapper::CloseCreatorApp()
   356 void EngineWrapper::CloseCreatorApp()
   327 {
   357 {
   328 	MainView::closeApp();
   358 	MainView::closeApp();