TInt CSendUIAPITest::MsgDataSetSubjectL( TPtrC& aSubject )
   {
   // Print to UI
   _LIT( KSendUIAPITest, "SendUIAPITest" );
   _LIT( KMsgDataSetSubjectL, "In MsgDataSetSubjectL" );
   TestModuleIf().Printf( 0, KSendUIAPITest, KMsgDataSetSubjectL );
   // Print to log file
   iLog->Log( KMsgDataSetSubjectL);
   
   //Create the instance of CMessageData
   CMessageData* messagedata = InitL();
   
   //Set the subject 
   TRAPD(err,messagedata->SetSubjectL(&aSubject));
   if(err == KErrNone)
		{
		return KErrNone;
		}
			
	else
		{
		return err;
		}
 
   }
void CDVToolReaderFrame::onMessage(wxEvent& event)
{
	CMessageEvent& msgEvent = dynamic_cast<CMessageEvent&>(event);

	CMessageData* message = msgEvent.getMessageData();
	wxASSERT(message != NULL);

	wxString msg = message->getMsgText();

	m_message->SetLabel(msg);

	delete message;
}
void CNodeMesh::startSimulation()
{
    CLogInfo log;
    qint8 input_gates = 0;
    // Flag to keep track whether the simulation is started or not.
    bool simulation_started = false;

    // Create the message that will be sent.
    CMessageData *msg =
        static_cast<CMessageData *>(CDataFactory::instance().createData("message"));
    if(msg == nullptr) {
        log.setMsg("Could not create start message.");
        log.setSrc(CLogInfo::ESource::framework);
        log.setStatus(CLogInfo::EStatus::error);
        log.setTime(QDateTime::currentDateTime());
        log.print();

        emit simulationFinished();
        return;
    }
    msg->setMessage("start");
    QSharedPointer<CData> pmsg = QSharedPointer<CData>(msg);

    // Look for nodes without input gates and send them the start message.
    QMap<QString, QSharedPointer<CNode>>::iterator i;
    for(i = m_nodes.begin(); i != m_nodes.end(); ++i) {
        auto node = i.value();
        input_gates = node->inputGatesSize();
       // qDebug().nospace().noquote()
             //   << "Message before";

        if(input_gates == 0) {
            node->processData("", pmsg);
           // qDebug().nospace().noquote()
                  //  << "Message after";
            simulation_started = true;
        }
    }

    if(!simulation_started) {
        log.setMsg("The simulation was not started because"
                   "we could not figure out where to start.");
        log.setSrc(CLogInfo::ESource::framework);
        log.setStatus(CLogInfo::EStatus::warning);
        log.setTime(QDateTime::currentDateTime());
        log.print();

        emit simulationFinished();
    }
}
void CGMSKClientFrame::onMessage(wxEvent& event)
{
	CMessageEvent& msgEvent = dynamic_cast<CMessageEvent&>(event);

	CMessageData* message = msgEvent.getMessageData();
	wxASSERT(message != NULL);

	wxString msg = message->getMsgText();

	m_hrdMessage->SetLabel(msg);
	m_heard->SetItem(0L, 5, msg);

	delete message;
}
void Model::sendsms(QString num)
{
   LS("Model::sendsms =>>");
   if(num.length() > 199)
       return;

   CSendUi* sendAppUi = CSendUi::NewLC();
   CMessageData* message = CMessageData::NewLC();

   TBuf<200> number;
   number.Copy(num.utf16());
   message->AppendToAddressL(number, KNullDesC);

   sendAppUi->CreateAndSendMessageL(KSenduiMtmSmsUid, message, KNullUid, ETrue);

   CleanupStack::PopAndDestroy(2); //sendAppUi & message
   LS("Model::sendsms <<");
}
TInt CSendUIAPITest::MsgDataCompSubjectL( TPtrC& aSubject )
	{
	// Print to UI
	_LIT( KSendUIAPITest, "SendUIAPITest" );
	_LIT( KMsgDataCompSubjectL, "In MsgDataCompSubjectL" );
	TestModuleIf().Printf( 0, KSendUIAPITest, KMsgDataCompSubjectL );
	// Print to log file
	iLog->Log( KMsgDataCompSubjectL);

	//Create the instance of CMessageData
	CMessageData* messagedata = InitL();
	//Get the subject from message data
	TPtrC msgdatasubject = messagedata->Subject();

	//Compare the two subjects
	if(msgdatasubject == aSubject)
		{
		return KErrNone;
		}	
	else
		{
		return KErrGeneral;
		}
	}
void CEmTubeSearchView::HandleCommandL( TInt aCommand )
	{
	TInt which = CurrentToActual();

	switch(aCommand)
		{
		case EMTVSendViaBluetoothCommand:
			{
			CSendUi* sendUi = CSendUi::NewLC();
			CMessageData* mdata = CMessageData::NewLC();
			mdata->AppendAttachmentL( iAppUi->SearchEntries()[ which ]->SavedFileName() );
			sendUi->CreateAndSendMessageL( KSenduiMtmBtUid, mdata );
			CleanupStack::PopAndDestroy( mdata );
			CleanupStack::PopAndDestroy( sendUi );
			}
		break;

		case EMTVSearchViewDownloadCommand:
			{
//			iAppUi->CancelDownloadImageL();
			iContainer->DownloadL( );
			}
		break;

		case EMTVAddToPlaylistCommand:
			{
			RArray<TInt> indices;
			CleanupClosePushL( indices );
			CAknSinglePopupMenuStyleListBox* plist = new(ELeave) CAknSinglePopupMenuStyleListBox;
			CleanupStack::PushL(plist);

		    CAknPopupList* popupList = CAknPopupList::NewL( plist, R_AVKON_SOFTKEYS_MENU_LIST, AknPopupLayouts::EPopupSNotePopupWindow);
		    CleanupStack::PushL(popupList);

		    plist->ConstructL(popupList, CEikListBox::ELeftDownInViewRect);
		    plist->CreateScrollBarFrameL(ETrue);
		    plist->ScrollBarFrame()->SetScrollBarVisibilityL(
		                               CEikScrollBarFrame::EOff,
		                               CEikScrollBarFrame::EAuto);

		    MDesCArray* itemList = plist->Model()->ItemTextArray();
		    CDesCArray* items = (CDesCArray*) itemList;

		    popupList->SetTitleL( KNullDesC() );

		    HBufC* txt = StringLoader::LoadLC( R_PLAYLIST_CREATE_NEW_TXT );
		    indices.Append( -1 );
		    items->AppendL( *txt );
		    CleanupStack::PopAndDestroy( txt );

		    TInt count = iManager->PlaylistsCount();
			for(TInt i=0;i<count;i++)
				{
				CEmTubePlaylist* pl = iManager->Playlist( i );
				if( pl->Editable() )
					{
					indices.Append( i );
			    	items->AppendL( pl->Name() );
					}
			    }

		    TInt popupOk = popupList->ExecuteLD();
		    if(popupOk)
		        {
		        TInt idx = indices[ plist->CurrentItemIndex() ];
				if( idx == -1 )
		        	{
					TBuf<64> name;
					CAknTextQueryDialog* dlg = new(ELeave)CAknTextQueryDialog( name, CAknQueryDialog::ENoTone );
					dlg->SetPredictiveTextInputPermitted( ETrue );
					TInt ret = dlg->ExecuteLD( R_EMTV_ADD_PLAYLIST_DIALOG );
					if( ret )
						{
						iManager->AddPlaylistL( name, CEmTubePlaylist::EPlaylistUserDefined );
						idx = iManager->PlaylistsCount() - 1;
						}
		        	}

				if( idx >= 0 )
					{
					CEmTubePlaylist* pl = iManager->Playlist( idx );
					CVideoEntry* e = iAppUi->SearchEntries()[ which ];
					if( iAppUi->SearchDisplayMode() == CEmTubeAppUi::ESearchDisplaySearchEntries ||
							iAppUi->SearchDisplayMode() == CEmTubeAppUi::ESearchDisplayFavEntries )
						pl->AddEntryL( e->Url(), e->MediaTitle(), CEmTubePlaylistEntry::EPlaylistEntryRemote );
					else
						pl->AddEntryL( e->SavedFileName(), e->MediaTitle(), CEmTubePlaylistEntry::EPlaylistEntryLocal );
					}
		        }
		    CleanupStack::Pop( popupList );
		    CleanupStack::PopAndDestroy( plist );
		    CleanupStack::PopAndDestroy( &indices );
			}
		break;

		case EMTVSearchViewAddToFCommand:
			{
			iContainer->AddCurrentItemToFavsL();
			}
		break;

		case EMTVSearchViewRemoveFromFCommand:
			{
			iContainer->RemoveCurrentItemFromFavsL();
			}
		break;

		case EMTVSearchCommand:
			{
			if( iAppUi->SearchDialogL() )
				{
// TODO: when displaying featured (for example), new search (from menu) - change navi pane text
//				if(no tabs, one plugin)
//					iContainer->SetNaviPaneTextL();

				StartProgressBarL( EFalse );
				}
			}
		break;

		case EMTVSearchViewPlayCommand:
			{
			if( which != KErrNotFound )
				{
				iAppUi->CancelDownloadImageL();
				if( iAppUi->SearchDisplayMode() == CEmTubeAppUi::ESearchDisplaySavedEntries )
					iAppUi->OpenFileL( iAppUi->SearchEntries()[ which ]->SavedFileName(), iAppUi->SearchEntries()[ which ]->MediaTitle() );
				else
					iAppUi->OpenFileL( iAppUi->SearchEntries()[ which ] );
				}
			}
		break;

		case EMTVDeleteClipCommand:
			{
			iContainer->DeleteSavedClipL();
			}
		break;

		case EMTVRenameClipCommand:
			{
			iContainer->RenameSavedClipL();
			}
		break;

		case EMTVShowRelatedCommand:
			{
			if( which != KErrNotFound )
				{
				iAppUi->CancelDownloadImageL();
				CVideoEntry* e = iAppUi->SearchEntries()[ which ];
				iAppUi->SearchString().Copy( e->RelatedUrl() );
				StartProgressBarL( EFalse );
				iAppUi->ClearSearchResults();
				iAppUi->SearchL( ERelatedClips, ERelevance, EPeriodIrrelevant );
				}
			}
		break;

		case EMTVShowUserCommand:
			{
			if( which != KErrNotFound )
				{
				iAppUi->CancelDownloadImageL();
				CVideoEntry* e = iAppUi->SearchEntries()[ which ];
				iAppUi->SearchString().Copy( e->AuthorVideosUrl() );
				StartProgressBarL( EFalse );
				iAppUi->ClearSearchResults();
				iAppUi->SearchL( EUserClips, EUpdated, EPeriodIrrelevant );
				}
			}
		break;

		case EMTVSearchViewDetailsCommand:
			{
			iContainer->ShowToolbar( EFalse );
			CEmTubeDetailsDialog::RunDialogL( iAppUi->SearchEntries()[ which ] );
			iContainer->ShowToolbar( ETrue );
			}
		break;

		case EMTVSearchViewBackCommand:
			{
			iContainer->ClearToolbar();
			iAppUi->CancelDownloadImageL();
			iAppUi->HandleCommandL( EMTVActivateMainViewCommand );
			}
		break;

		case EMTVProgressDialogCancel:
			{
			iAppUi->CancelDownloadImageL();
			if( iAppUi->SearchEntries().Count() )
				iContainer->CancelProgressL();
			else
				iAppUi->HandleCommandL( EMTVActivateMainViewCommand );
			}
		break;

		default:
			{
			iAppUi->HandleCommandL(aCommand);
			}
		break;
		}
	}