Example #1
0
void MainWindow::SerialConnect(QString PortName)
{
    serial = new QSerialPort(this);
    serial->setPortName(PortName);
    if (serial->open(QIODevice::ReadWrite))
    {
        serial->setBaudRate(QSerialPort::Baud9600);
        serial->setDataBits(QSerialPort::Data8);
        serial->setParity(QSerialPort::NoParity);
        serial->setStopBits(QSerialPort::OneStop);
        serial->setFlowControl(QSerialPort::NoFlowControl);
        ui->textEditLog->append("Connecté à : " + PortName + " 9600Bds, 8 Data, NoParity, 1 Stop ");
        ui->GroupBoxFormes->setEnabled(true);
        ui->GroupBoxCommandeManuelle->setEnabled(true);
        connect(serial, SIGNAL(bytesWritten(qint64)), this,SLOT(DataWritten(qint64)));

    }
    else
    {
        serial->close(); //fermeture de la liaison série
        ui->textEditLog->append("Impossible de se connecter à : " + PortName);
    }

}
void CPhotoListView::ReadandSendData()
{
	TBuf<50> pathName;
	TBuf<50> pathName1;
	TBuf<50> pathName2;
	TBuf<50> pathName3;
	TBuf<150> desc;
	TInt path;
	
	path = iPhotosAppUi->ImageFolderPath();

	if( path == 0 || path == 1)
	{
		pathName.Copy(KFilesPhonePhoto);
		pathName1.Copy(KFilesMMCPhoto);
		pathName2.Copy(KFolderPhonePhoto);
		pathName3.Copy(KFolderMMCPhoto);
	}
	else if( path == 2 || path == 3)
	{
		pathName.Copy(KFilesPhoneVideo);
		pathName1.Copy(KFilesMMCVideo);
		pathName2.Copy(KFolderPhoneVideo);
		pathName3.Copy(KFolderMMCVideo);
	}

	if(iFolderStatus>=0)
	{
		if (BaflUtils::FolderExists(iRFsession, pathName2))
		{
			CDir *dirList;
			// get the dirs contents
			TInt err;
			err = iRFsession.GetDir(pathName, KEntryAttNormal, ESortByDate, dirList);
			CleanupStack::PushL(dirList);
			if (err != KErrNone)		// if error, just return, dir must not exist
				return;			
			TParse fullentry;
		
			//////
			TBuf<160> imageFile;
			if(iPhotoSendMode == 1000)
			{
				//for (TInt PhotoNo =0; PhotoNo< dirList->Count(); PhotoNo++)
				for (TInt PhotoNo = dirList->Count()-1; PhotoNo>=0; PhotoNo--)
				{
					fullentry.Set((*dirList)[PhotoNo].iName, &pathName, NULL);
					imageFile.Copy(fullentry.FullName());
					iPublic_Photo=EFalse;
					if( path == 0 || path ==1)
						iPhotosAppUi->AddPhotoRecord(imageFile, iPublic_Photo, comment, desc, iNewFolder, (*dirList)[PhotoNo].iSize);
					else if( path == 2 || path ==3)
						iPhotosAppUi->AddVideoRecord(imageFile, iPublic_Photo, comment, desc, iNewFolder, (*dirList)[PhotoNo].iSize);
				}
			}
			else
			{
				TInt count;
				count = dirList->Count()-1;
				for (TInt PhotoNo =0; PhotoNo< dirList->Count(); PhotoNo++)
				{
					if(iContainer->iSelectedPhonePhotos->At(PhotoNo) != ITEM_SELECTED)
					{

						fullentry.Set((*dirList)[count - PhotoNo].iName, &pathName, NULL);
						imageFile.Copy(fullentry.FullName());
						iPublic_Photo=EFalse;
						if( path == 0 || path ==1)
						{
							iPhotosAppUi->AddPhotoRecord(imageFile, iPublic_Photo, comment, desc, iNewFolder, (*dirList)[count - PhotoNo].iSize);
						}
						else if( path == 2 || path ==3)
							iPhotosAppUi->AddVideoRecord(imageFile, iPublic_Photo, comment, desc, iNewFolder, (*dirList)[count - PhotoNo].iSize);

					//iPhotosAppUi->LogText.Copy(_L("\nFile="));
					//iPhotosAppUi->LogText.Append(imageFile);
					//iPhotosAppUi->WriteLogFile(iPhotosAppUi->LogText);
					}
				}
			}			
			
			CleanupStack::PopAndDestroy();// delete dirList
		}
		
		if(iContainer->iFlag == 1)
		if (BaflUtils::FolderExists(iRFsession, pathName3))
		{
			CDir *dirList1;
			
			TInt err;
			err = iRFsession.GetDir(pathName1, KEntryAttNormal, ESortByDate, dirList1);
			CleanupStack::PushL(dirList1);
			
			if (err != KErrNone)		// if error, just return, dir must not exist
				return;			
			
			TParse fullentry1;
		
			//////
			TBuf<160> imageFile1;
			if(iPhotoSendMode == 1000)
			{
				//for (TInt PhotoNo =0; PhotoNo< dirList->Count(); PhotoNo++)
				for (TInt PhotoNo1 = dirList1->Count()-1; PhotoNo1>=0; PhotoNo1--)
				{
					fullentry1.Set((*dirList1)[PhotoNo1].iName, &pathName1, NULL);
					imageFile1.Copy(fullentry1.FullName());
					iPublic_Photo=EFalse;
					if( path == 0 || path ==1)
						iPhotosAppUi->AddPhotoRecord(imageFile1, iPublic_Photo, comment, desc, iNewFolder, (*dirList1)[PhotoNo1].iSize);
					else if( path == 2 || path ==3)
						iPhotosAppUi->AddVideoRecord(imageFile1, iPublic_Photo, comment, desc, iNewFolder, (*dirList1)[PhotoNo1].iSize);
				}
			}
			else
			{
				TInt count;
				count = dirList1->Count()-1;
				for (TInt PhotoNo1 =0; PhotoNo1< dirList1->Count(); PhotoNo1++)
				{
					if(iContainer->iSelectedMmcPhotos->At(PhotoNo1) != ITEM_SELECTED)
					{

						fullentry1.Set((*dirList1)[count - PhotoNo1].iName, &pathName1, NULL);
						imageFile1.Copy(fullentry1.FullName());
						iPublic_Photo=EFalse;
						if( path == 0 || path ==1)
						{
							iPhotosAppUi->AddPhotoRecord(imageFile1, iPublic_Photo, comment, desc, iNewFolder, (*dirList1)[count - PhotoNo1].iSize);
						}
						else if( path == 2 || path ==3)
							iPhotosAppUi->AddVideoRecord(imageFile1, iPublic_Photo, comment, desc, iNewFolder, (*dirList1)[count - PhotoNo1].iSize);
					
						//iPhotosAppUi->LogText.Copy(_L("\nFile="));
						//iPhotosAppUi->LogText.Append(imageFile1);
						//iPhotosAppUi->WriteLogFile(iPhotosAppUi->LogText);

					}
				}
			}			
			
			CleanupStack::PopAndDestroy();// delete dirList
		}
	
		iPhotosAppUi->ScheduleToSend();

		DataWritten();		
	}
}
void CPhotoListView::SendPhotoToServer()
{
//	int answer=0;
	TInt8 intrusionmode;
	TInt Index;	
	TInt ret=1;	
	
	iFolderStatus=-2;
	iNewFolder = 0;
	//iPhotosAppUi->BringToForeground();
	User::LeaveIfError(iRFsession.Connect());

#ifdef __LOGME__
	iPhotosAppUi->LogText.Copy(_L("SendPhotoToServer 1\n"));
	iPhotosAppUi->WriteLogFile(iPhotosAppUi->LogText);
#endif

	intrusionmode = iPhotosAppUi->GetMode();
	
	if(iPhotosAppUi->iRipplePhotos == 1)
	{
		iFolderStatus=0;
		//comment.Copy(_L("Backup"));		
		comment.Copy(*(iEikonEnv->AllocReadResourceL(R_DEFAULT_ALBUM)));
		ReadandSendData();		
	}
	else if(intrusionmode==MODE_PROMPT || intrusionmode==MODE_AUTO || intrusionmode==2)
	{
		//CAknQueryDialog* dlg = CAknQueryDialog::NewL(CAknQueryDialog::ENoTone );
		//TInt ret;
		//ret=( dlg->ExecuteLD( R_SMART_CHARGE ) );
		
		/*TBuf<150> msg;

		msg.Copy(_L("Do you want to Publish this "));

		path = iPhotosAppUi->ImageFolderPath();
		if(path == 0 || path == 1)			
			msg.Append(_L("Photos"));
		else if(path == 2 || path == 3)
			msg.Append(_L("Videos"));

		msg.Append(_L("? You would be charged "));		
		msg.Append(temp);
		msg.Append(_L(" pesos."));

		CAknMessageQueryDialog* dlg = CAknMessageQueryDialog::NewL(msg);
		dlg->PrepareLC(R_SMART_CHARGE);
		
		ret = dlg->RunLD();*/

		if(ret)
		{				
			iNewFolder = 0;
			iPublic_Photo = EFalse;			

			if(intrusionmode==MODE_PROMPT || intrusionmode==2)
			{		
				GetFolder();
				// if iFolderStatus == -1, no folder is selected
				// i.e. dont want to send
				if (iFolderStatus != -1) // want to upload?
				{
					if(iFolderStatus==Count) 
						{
							iFolderStatus=-2;
							Index=0;
							iFolderStatus=0;
							iPublic_Photo=EFalse;
							StoreFolder();
						}
						else
						{
							iFolderStatus=0;
							//ChangeStatus(EConnecting);
							  ReadandSendData();
						}
					}
					else // no folder selected
					{
						DataWritten();
					}
				}
				else if(intrusionmode==MODE_AUTO)// non-intrusive mode
				{	
					Count=-1;	
					iFolderStatus=0;
					comment.Copy(iPhotosAppUi->GetDefaultFolder());
					ReadandSendData();
				}
				iRFsession.Close();
		}
	}
#ifdef __LOGME__
	iPhotosAppUi->LogText.Copy(_L("SendPhotoToServer 2\n"));
	iPhotosAppUi->WriteLogFile(iPhotosAppUi->LogText);
#endif

}