/*
 * Update current progress
 */
void XYPenPlotterController::setProgress(int progress)
{
    if(progress > 100)
        emit progressUpdate(100);
    else
        emit progressUpdate(progress);
}
void GoogleDocumentService::listDocuments()
{
    authToken = docAuthToken;
    QString url;
    switch (m_type) {
    case OnlineDocument::WORDS:
        url = "https://docs.google.com/feeds/default/private/full/-/document";
        break;
    case OnlineDocument::STAGE:
        url = "https://docs.google.com/feeds/default/private/full/-/presentation";
        break;
    case OnlineDocument::SHEETS:
        url = "https://docs.google.com/feeds/default/private/full/-/spreadsheet";
        break;
    }

    QNetworkRequest requestHeader(QUrl(url.toUtf8()));
    requestHeader.setRawHeader("Host", "docs.google.com");
    requestHeader.setRawHeader("User-Agent", "Calligra");
    requestHeader.setRawHeader("GData-Version", "3.0");
    requestHeader.setRawHeader("Content-Type", "application/atom+xml");
    requestHeader.setRawHeader("Authorization", authToken.toUtf8());

    networkManager.get(requestHeader);
    emit progressUpdate("Successfully authenticated!!! Retreiving document list...");
}
예제 #3
0
void FileNetworkTask::startFileServerTask(const QString& link)
{
    createFileServerTask(link);

    connect(fileserver_task_, SIGNAL(progressUpdate(qint64, qint64)),
            this, SLOT(onFileServerTaskProgressUpdate(qint64, qint64)));
    connect(fileserver_task_, SIGNAL(nameUpdate(QString)),
            this, SLOT(onFileServerTaskNameUpdate(QString)));
    connect(fileserver_task_, SIGNAL(finished(bool)),
            this, SLOT(onFileServerTaskFinished(bool)));
    connect(fileserver_task_, SIGNAL(retried(int)),
            this, SIGNAL(retried(int)));

    if (!worker_thread_) {
        worker_thread_ = new QThread;
        worker_thread_->start();
    }

    if (type() == Download) {
        // From now on the this task would run in the worker thread
        fileserver_task_->moveToThread(worker_thread_);
        QMetaObject::invokeMethod(fileserver_task_, "start");
    } else {
        // ReliablePostFileTask is a bit complicated and it would manage the
        // thread-affinity itself.
        fileserver_task_->start();
    }
}
예제 #4
0
//加载声音
void PreLoad::loadEffect(ValueVector effectFiles){
	for (unsigned int i = 0; i != effectFiles.size(); ++i){
		Value v = effectFiles.at(i);
		SimpleAudioEngine::getInstance()->preloadEffect(v.asString().c_str());
		progressUpdate();
	}

}
예제 #5
0
//加载背景音乐
void PreLoad::loadMusic(ValueVector musicFiles){
	for (unsigned int i = 0; i != musicFiles.size(); ++i){
		Value v = musicFiles.at(i);
		SimpleAudioEngine::getInstance()->preloadBackgroundMusic(v.asString().c_str());
		progressUpdate();
	}

}
예제 #6
0
void cryptfiles::cryptFile( const char * s,const char * d,const char * k,unsigned long l,bool encrypt )
{
	using function_t = std::function< int( int ) > ;

	function_t foo = [ this ]( int e ){ emit progressUpdate( e ) ; return 0 ; } ;

	auto f = reinterpret_cast< void * >( &foo ) ;

	auto u = []( int e,void * f )
	{
		auto function = reinterpret_cast< function_t * >( f ) ;

		return ( *function )( e ) ;
	} ;

	auto r = Task::await( [ & ]{

		auto r = u_int32_t( l ) ;

		if( encrypt ){

			return lxqt_wallet_create_encrypted_file( k,r,s,d,u,f ) ;
		}else{
			return lxqt_wallet_create_decrypted_file( k,r,s,d,u,f ) ;
		}
	} ) ;

	if( r == lxqt_wallet_wrong_password ){

		this->taskFinished( cryptfiles::wrongKey ) ;

	}else if( r == lxqt_wallet_no_error ){

		if( m_ui->progressBar->value() == 100 ){

			utility::changePathOwner( d ) ;

			if( encrypt ){

				this->taskFinished( cryptfiles::encryptSuccess ) ;
			}else{
				this->taskFinished( cryptfiles::decryptSuccess ) ;
			}
		}else{
			this->taskFinished( cryptfiles::quit ) ;
		}
	}else{
		/*
		 * we shouldnt get here and we return a bogus return value for lack of better
		 * alternative
		 */
		this->taskFinished( cryptfiles::openMapperReadFail ) ;
	}
}
예제 #7
0
AutoUpdatePage::AutoUpdatePage(SetupWizard *wizard, QWidget *parent) :
    AbstractWizardPage(wizard, parent),
    ui(new Ui::AutoUpdatePage), m_isUpdating(false)
{
    ui->setupUi(this);
    ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
    Q_ASSERT(pm);
    UploaderGadgetFactory *uploader    = pm->getObject<UploaderGadgetFactory>();
    Q_ASSERT(uploader);
    connect(ui->startUpdate, SIGNAL(clicked()), this, SLOT(disableButtons()));
    connect(ui->startUpdate, SIGNAL(clicked()), this, SLOT(autoUpdate()));
    connect(uploader, SIGNAL(progressUpdate(uploader::ProgressStep, QVariant)), this, SLOT(updateStatus(uploader::ProgressStep, QVariant)));
}
예제 #8
0
//加载精灵表单
void PreLoad::loadSpriteSheets(ValueVector spriteSheets){
	//该函数会加载与plist文件名称相同但后缀名为png的纹理图片
	//把该plist的所有spriteFrame信息读取出来,在之后的代码中可以通过
	//Sprite::createWithSpriteFrameName(const std::string& spriteFrameName)函数
	//获取对应的精灵帧
	for (unsigned int i = 0; i != spriteSheets.size(); ++i){
		Value v = spriteSheets.at(i);
		SpriteFrameCache::getInstance()->addSpriteFramesWithFile(v.asString().c_str());
		progressUpdate();
	}


}
예제 #9
0
void GetFileTask::sendRequest()
{
    QNetworkRequest request(url_);
    reply_ = getQNAM()->get(request);

    connect(reply_, SIGNAL(sslErrors(const QList<QSslError>&)),
            this, SLOT(onSslErrors(const QList<QSslError>&)));

    connect(reply_, SIGNAL(readyRead()), this, SLOT(httpReadyRead()));
    connect(reply_, SIGNAL(downloadProgress(qint64, qint64)),
            this, SIGNAL(progressUpdate(qint64, qint64)));
    connect(reply_, SIGNAL(finished()), this, SLOT(httpRequestFinished()));
}
예제 #10
0
/**
 * This member function may be called in two places:
 * 1. when task is first started
 * 2. when the request is redirected
 */
void PostFileTask::sendRequest()
{
    QHttpMultiPart *multipart = new QHttpMultiPart(QHttpMultiPart::FormDataType, this);
    // parent_dir param
    QHttpPart parentdir_part, file_part;
    if (use_upload_) {
        parentdir_part.setHeader(QNetworkRequest::ContentDispositionHeader,
                                 kParentDirParam);
        parentdir_part.setBody(parent_dir_.toUtf8());
    } else {
        parentdir_part.setHeader(QNetworkRequest::ContentDispositionHeader,
                                 kTargetFileParam);
        parentdir_part.setBody(::pathJoin(parent_dir_, name_).toUtf8());
    }
    multipart->append(parentdir_part);

    // relative_path param
    if (!relative_path_.isEmpty()) {
        QHttpPart part;
        part.setHeader(QNetworkRequest::ContentDispositionHeader,
                       kRelativePathParam);
        part.setBody(relative_path_.toUtf8());
        multipart->append(part);
    }

    // "file" param
    file_part.setHeader(QNetworkRequest::ContentDispositionHeader,
                        QString(kFileParamTemplate).arg(name_).toUtf8());
    file_part.setHeader(QNetworkRequest::ContentTypeHeader,
                        kContentTypeApplicationOctetStream);
    file_part.setBodyDevice(file_);

    multipart->append(file_part);

    QNetworkRequest request(url_);
    request.setRawHeader("Content-Type",
                         "multipart/form-data; boundary=" + multipart->boundary());
    if (!network_mgr_) {
        static QNetworkAccessManager *manager = new QNetworkAccessManager(qApp);
        network_mgr_ = manager;
        NetworkManager::instance()->addWatch(network_mgr_);
    }
    reply_ = network_mgr_->post(request, multipart);
    connect(reply_, SIGNAL(sslErrors(const QList<QSslError>&)),
            this, SLOT(onSslErrors(const QList<QSslError>&)));
    connect(reply_, SIGNAL(finished()), this, SLOT(httpRequestFinished()));
    connect(reply_, SIGNAL(uploadProgress(qint64,qint64)),
            this, SIGNAL(progressUpdate(qint64, qint64)));
}
예제 #11
0
void LoginWindow::loginService()
{
    if (m_authDialog->saveUserDetails->isChecked()) {
        saveUserDetails();
    }

    if (0 == m_authDialog->comboBox->currentIndex()) {
        gdoc = new GoogleDocumentService(m_type);
        showProgressIndicator(true);
        m_authDialog->headerLabel->setText("Signing in...");
        gdoc->clientLogin(m_authDialog->userEdit->text(), m_authDialog->passwordEdit->text());
        connect(gdoc, SIGNAL(userAuthenticated(bool, QString)), this, SLOT(authenticated(bool, QString)));
        connect(gdoc, SIGNAL(progressUpdate(QString)), this, SLOT(updateProgress(QString)));
        connect(gdoc, SIGNAL(showingDocumentList()), this, SLOT(accept()));
    }
예제 #12
0
void csPdfSearch::processSearch()
{
  if( !_running ) {
    return;
  }

  if( _cancel ) {
    _running = false;
    emit canceled();
    return;
  }

  int blockSize = 0;
  if(        !isBlocksFinished() ) {
    // Do CSPDF_SEARCH_BLOCKSIZE's Work...
    blockSize = CSPDF_SEARCH_BLOCKSIZE;
    _cntBlocks++;
  } else if(  isBlocksFinished()  &&  !isRemainFinished() ) {
    // Do _numRemain's Work...
    blockSize = _numRemain;
    _cntRemain += _numRemain;
  }

  if( blockSize != 0 ) {
    const csPdfSearchResults results =
        searchPages(_doc.textPages(_cntIndex, blockSize),
                    _needles, _cs, _context);
    if( !results.isEmpty() ) {
      emit found(results);
    }
    _cntIndex += blockSize;
    _cntDone  += blockSize;
    progressUpdate();
  }

  if( isFinished()  &&  _startIndex != 0  &&  _wrap ) {
    initialize(0, _startIndex);
    _startIndex = 0;
  }

  if( !isFinished() ) {
    QMetaObject::invokeMethod(this, "processSearch", Qt::QueuedConnection);
  } else {
    _running = false;
    emit finished();
  }
}
예제 #13
0
void AsyncIO::startCopy()
{
    //same file, no need to copy
    if(existingFilePath.compare(newFilePath) == 0)
    {
        emit finished();
        return;
    }

    //load both files
    QFile existingFile(existingFilePath);
    QFile newFile(newFilePath);
    bool openExisting = existingFile.open( QIODevice::ReadOnly );
    bool openNew = newFile.open( QIODevice::WriteOnly );

    //if either file fails to open exit
    if(!openExisting || !openNew) {
        emit error("Failed to open file");
        return;
    }

    double existingFileSize = existingFile.size();
    double bytesCopied = 0;

    //copy contents
    uint BUFFER_SIZE = 16000;
    char* buffer = new char[BUFFER_SIZE];
    while(!existingFile.atEnd())
    {
        qint64 len = existingFile.read( buffer, BUFFER_SIZE );
        newFile.write( buffer, len );
        bytesCopied += BUFFER_SIZE;

        int copyProgress = (bytesCopied / existingFileSize) * 100;
        if(copyProgress!=progress)
        {
            progress = copyProgress;
            emit progressUpdate(progress);
        }
    }

    //deallocate buffer
    delete[] buffer;
    buffer = NULL;
    emit finished();
    return;
}
예제 #14
0
void Test::advanceTest() {
    if (state_ == question) {
        state_ = answer;
        playFlipAnimation();
    }
    else if (state_ == answer && currentSequenceIndex_ < shuffledSequence_.length()-1) {
        currentSequenceIndex_++;
        state_ = question;
        currentCard_ = testDeck_->deck_[ shuffledSequence_[currentSequenceIndex_] ];
        playFlipAnimation();
    }
    else {
        emit testFinished();
    }

    emit progressUpdate();
}
예제 #15
0
void FileNetworkTask::startFileServerTask(const QString& link)
{
    createFileServerTask(link);

    connect(fileserver_task_, SIGNAL(progressUpdate(qint64, qint64)),
            this, SLOT(onFileServerTaskProgressUpdate(qint64, qint64)));
    connect(fileserver_task_, SIGNAL(finished(bool)),
            this, SLOT(onFileServerTaskFinished(bool)));

    if (!worker_thread_) {
        worker_thread_ = new QThread;
        worker_thread_->start();
    }
    // From now on the transfer task would run in the worker thread
    fileserver_task_->moveToThread(worker_thread_);
    QMetaObject::invokeMethod(fileserver_task_, "start");
}
예제 #16
0
void GetFileTask::sendRequest()
{
    QNetworkRequest request(url_);
    if (!network_mgr_) {
        static QNetworkAccessManager *manager = new QNetworkAccessManager(qApp);
        network_mgr_ = manager;
        NetworkManager::instance()->addWatch(network_mgr_);
    }
    reply_ = network_mgr_->get(request);

    connect(reply_, SIGNAL(sslErrors(const QList<QSslError>&)),
            this, SLOT(onSslErrors(const QList<QSslError>&)));

    connect(reply_, SIGNAL(readyRead()), this, SLOT(httpReadyRead()));
    connect(reply_, SIGNAL(downloadProgress(qint64, qint64)),
            this, SIGNAL(progressUpdate(qint64, qint64)));
    connect(reply_, SIGNAL(finished()), this, SLOT(httpRequestFinished()));
}
예제 #17
0
boost::shared_ptr<PointCloud> CloudList::loadFile(QString filename) {
    if(!QFileInfo(filename).exists())
        return nullptr;

    boost::shared_ptr<PointCloud> pc;
    pc.reset(new PointCloud());
    pc->moveToThread(QApplication::instance()->thread());

    connect(pc.get(), SIGNAL(progress(int)), this, SIGNAL(progressUpdate(int)));
    pc->load_ptx(filename.toLocal8Bit().constData());
    emit progressUpdate(0);
    disconnect(pc.get(), SIGNAL(progress(int)), this, SIGNAL(progressUpdate(int)));

    emit startNonDetJob();
    addCloud(pc);
    emit endNonDetJob();
    emit listModified();
    return pc;
}
예제 #18
0
bool csPdfSearch::start(const csPDFiumDocument& doc, const QStringList& needles,
                        const int startIndex, const Qt::MatchFlags flags,
                        const int context)
{
  if( _running  ||
      doc.isEmpty()  ||  doc.pageCount() < 1  ||
      needles.isEmpty()  ||
      startIndex < 0  ||  startIndex >= doc.pageCount()  ||
      context < 0 ) {
    return false;
  }

  _doc     = doc;
  _needles = needles;
  _context = context;
  _cs      = flags.testFlag(Qt::MatchCaseSensitive)
      ? Qt::CaseSensitive
      : Qt::CaseInsensitive;
  _wrap    = flags.testFlag(Qt::MatchWrap);
  _cancel  = false;

  if( _wrap ) {
    _numToDo = _doc.pageCount();
  } else {
    _numToDo = _doc.pageCount() - startIndex;
  }
  _cntDone = 0;
  _lastProgress = -1;
  progressUpdate();

  initialize(startIndex, _doc.pageCount());
  _running = true;
  QMetaObject::invokeMethod(this, "processSearch", Qt::QueuedConnection);
  emit started();

  return true;
}
void GoogleDocumentService::handleNetworkData(QNetworkReply *networkReply)
{
    if (!networkReply->error()) {
        if (!loggedin) {
            QString text(networkReply->readAll());
            text = text.right(text.length() - text.indexOf("Auth=") - 5);
            authToken = QString("GoogleLogin auth=") + text.left(text.indexOf("\n"));
            if(authToken.length() > 20) {
                if(!haveDocAuthToken) {
                    docAuthToken = authToken;
                    haveDocAuthToken = true;
                    qDebug() << "Received Doc token = " << docAuthToken;
                    clientLogin(this->username, this->password);
                    return;
                }
                spreadAuthToken = authToken;
                authToken = "";
                loggedin = true;
                qDebug() << "Received Spreadsheet token = " << spreadAuthToken;
                listDocuments();
                emit userAuthenticated(loggedin, "");
            }
        }
        else if (waitingForDoc) {
            QByteArray data = networkReply->readAll();
            QFile file(QDir::tempPath() + QLatin1Char('/') + documentList->currentDocument());
            file.open(QIODevice::ReadWrite);
            file.write(data);
            file.close();
            qDebug() << "Received Document!!!!! " << file.fileName();
            emit receivedDocument(file.fileName());
            waitingForDoc = false;
            showDocumentListWindow(false);
        }
        else {
            QByteArray bytAry = networkReply->readAll();
//            qDebug() << bytAry;

//            xmlInput.setData(networkReply->readAll());
            xmlInput.setData(bytAry);
            qDebug() << "Part received.........";
            if (newInformation) {
                emit progressUpdate("Parsing document list...");
                newInformation = xmlReader.parse(&xmlInput, true);
                qDebug() << "New Information = " << newInformation;
//                newInformation = false;
                getDocument();
            }
        }
    } else {
        QString errorString(networkReply->readAll());
        qDebug() << "Error occurred !!!!  " << errorString;
        errorString = errorString.right(errorString.length() - errorString.indexOf("Error=") - 6);
        if (!loggedin) {
            emit userAuthenticated(loggedin, errorString);
        } else {
            QMessageBox msgBox(QMessageBox::Information, i18n("Online Document Services"),
                               "Error occurred !!!!  " + errorString);
            msgBox.exec();
        }
    }
}
CryptTask::status CryptTask::encrypt()
{
	QFile fd_4( m_source ) ;

	if( !fd_4.open( QIODevice::ReadOnly ) ){
		return CryptTask::OpenSourceFail ;
	}

	QFile fd_1( m_dest ) ;

	if( !fd_1.open( QIODevice::WriteOnly ) ){
		return CryptTask::OpenDestinationFail ;
	}

	const int SIZE = 512 ;
	char buffer[ SIZE ] ;

	qint64 size = fd_4.size() ;
	qint64 source_size = size ;
	int i = 0 ;
	int j = -1 ;

	emit titleUpdate( tr( "Creating Encrypted Container File" ) ) ;

	while( size % SIZE != 0 ){
		size++ ;
	}
	size += SIZE ;

	memset( buffer,0,SIZE ) ;

	emit progressUpdate( 0 ) ;

	if( !fd_1.resize( size ) ){
		for( qint64 size_1 = 0 ; size_1 < size ; size_1 += SIZE ){

			if( m_status == CryptTask::quit ){
				return CryptTask::quit ;
			}else{
				i = ( int )( size_1 * 100 / size ) ;
				if( i > j ){
					emit progressUpdate( i ) ;
				}
				j = i ;

				fd_1.write( buffer,SIZE ) ;
				fd_1.flush() ;
			}
		}

		emit progressUpdate( 100 ) ;
	}

	fd_1.close() ;

	if( this->openMapper( m_dest ) != CryptTask::success ){
		return CryptTask::openMapperFail ;
	}

	QFile fd_2( m_mapperPath ) ;
	if( !fd_2.open(QIODevice::WriteOnly ) ){
		return CryptTask::openMapperWriteFail ;
	}

	QString s = QString::number( source_size ) ;

	fd_2.write( s.toLatin1(),s.size() ) ;

	fd_2.putChar( '\0' ) ;

	char bff[ 100 ] ;

	QFile fd_3( QString( "/dev/urandom" ) ) ;
	fd_3.open( QIODevice::ReadOnly ) ;
	fd_3.read( bff,100 ) ;
	fd_3.close() ;

	fd_2.seek( 100 ) ;

	fd_2.write( bff,100 ) ;
	fd_2.write( bff,100 ) ;

	char version[ 32 ] = { 0 };
	strcpy( version,"1.0" ) ;

	fd_2.write( version,32 ) ;

	char md5Data[ 32 ] ;

	this->calculateMd5( m_source,md5Data ) ;

	fd_2.write( md5Data,32 ) ;

	fd_2.flush() ;

	fd_2.seek( SIZE ) ;

	j = -1 ;

	emit titleUpdate( tr( "Copying Data To The Container File" ) ) ;

	emit progressUpdate( 0 ) ;

	for( qint64 size_1 = 0 ; size_1 < size ; size_1 += SIZE ){

		if( m_status == CryptTask::quit ){
			return CryptTask::quit ;
		}
		i = ( int )( size_1 * 100 / size ) ;
		if( i > j ){
			emit progressUpdate( i ) ;
		}
		j = i ;
		fd_4.read( buffer,SIZE ) ;
		fd_2.write( buffer,SIZE ) ;
		fd_2.flush() ;
	}

	fd_2.close() ;

	emit progressUpdate( 100 ) ;

	return CryptTask::success ;
}
예제 #21
0
void FileNetworkTask::onFileServerTaskProgressUpdate(qint64 transferred, qint64 total)
{
    progress_.transferred = transferred;
    progress_.total = total;
    emit progressUpdate(transferred, total);
}
예제 #22
0
파일: akujobs.cpp 프로젝트: alediaferia/aku
void AkuHelper::onProgressUpdate(double current, double total)
{
    emit progressUpdate(current, total);
}
예제 #23
0
void ExtractWorker::process()
{
    QFile sourceFile(sourceName);
    QFile targetFile(destName);
    QString home = QDir::homePath();
    bool sourceopen = sourceFile.open(QIODevice::ReadOnly);
    int sourceFileDescriptor = sourceFile.handle();
    FILE* source = fdopen(sourceFileDescriptor, "rb");
    bool targetopen = targetFile.open(QIODevice::WriteOnly);
    int targetFileDescriptor = targetFile.handle();
    FILE* dest = fdopen(targetFileDescriptor, "wb");

    int ret;
    unsigned have;
    unsigned written = 0;
    z_stream strm;
    unsigned char in[CHUNKSIZE];
    unsigned char out[CHUNKSIZE];
    strm.zalloc = Z_NULL;
    strm.zfree = Z_NULL;
    strm.opaque = Z_NULL;
    strm.avail_in = 0;
    strm.next_in = Z_NULL;
    ret = inflateInit2(&strm,  47);
    if (ret != Z_OK)
    {
        emit error();
        return;
    }

    do
    {
        strm.avail_in = fread(in, 1, CHUNKSIZE, source);

        if (ferror(source))
        {
            (void)inflateEnd(&strm);
            emit error();
            return;
        }
        if (strm.avail_in == 0)
            break;
        strm.next_in = in;

        do
        {
            strm.avail_out = CHUNKSIZE;
            strm.next_out = out;
            ret = inflate(&strm, Z_NO_FLUSH);
            assert(ret != Z_STREAM_ERROR);  /* state not clobbered */
            switch (ret) {
            case Z_NEED_DICT:
                ret = Z_DATA_ERROR;     /* and fall through */
            case Z_DATA_ERROR:
            case Z_MEM_ERROR:
                (void)inflateEnd(&strm);
                emit error();
                return;
         }
            have = CHUNKSIZE - strm.avail_out;
            written += have;

            emit progressUpdate(written);
            if (fwrite(out, 1, have, dest) != have || ferror(dest))
            {
                (void)inflateEnd(&strm);
                emit error();
                return;
            }
         }
        while (strm.avail_out == 0);
    }
    while (ret != Z_STREAM_END);

    (void)inflateEnd(&strm);
    if (ret == Z_STREAM_END)
        emit finished();
    else
        emit error();
}
예제 #24
0
QWidget * QCamQHY5::buildGUI(QWidget * parent) {
   QWidget* remoteCTRL=QCam::buildGUI(parent);
   QCamVGroupBox* settingsBox=new QCamVGroupBox(QString("Settings"),remoteCTRL);

   QCamHBox* filtersBox=new QCamHBox(settingsBox);
   // denoise
   denoiseBox=new QCheckBox("Horizontal bands filtering",filtersBox);

   // read denoise settings
   if(settings.haveKey("QHY5_BANDS_FILTER")&&(strcasecmp(settings.getKey("QHY5_BANDS_FILTER"),"yes")==0)) {
      denoise_=TRUE;
      denoiseBox->setChecked(TRUE);
   } else {
      denoise_=FALSE;
      denoiseBox->setChecked(FALSE);
   }

   // gain
   gainSlider=new QCamSlider("Gain",false,settingsBox,0,81,false,false);
   gainSlider->setValue(gainG1_);

   gainSliderG1=new QCamSlider("Gain Green 1",false,settingsBox,0,81,false,false);
   gainSliderG1->setValue(gainG1_);

   gainSliderG2=new QCamSlider("Gain Green 2",false,settingsBox,0,81,false,false);
   gainSliderG2->setValue(gainG2_);

   gainSliderR=new QCamSlider("Gain Red",false,settingsBox,0,81,false,false);
   gainSliderR->setValue(gainR_);

   gainSliderB=new QCamSlider("Gain Blue",false,settingsBox,0,81,false,false);
   gainSliderB->setValue(gainB_);

   // no finished at this time, so hidden
   gainSliderG1->hide();
   gainSliderG2->hide();
   gainSliderR->hide();
   gainSliderB->hide();

   // exposure
   QCamHBox* exposureBox=new QCamHBox(settingsBox);
   QLabel* label1=new QLabel(QString("Exposure"),exposureBox);
   exposureSlider=new QSlider(Qt::Horizontal,exposureBox);
   exposureSlider->setMinimum(0);
   exposureSlider->setMaximum(QHY5_EXPOSURE_TABLE_SIZE-1);
   exposureSlider->setValue(getExposureIndex(frameExposure_));
   exposureSlider->setTickPosition(QSlider::TicksBelow);
   exposureSlider->setTickInterval(1);
   exposureValue=new QLabel(exposureBox);
   exposureValue->setMinimumWidth(80);
   // update value
   int transferTime=1558*(height_+26)/PIXEL_RATE;
   if(transferTime>frameExposure_) {
      exposureValue->setText(QString().sprintf("%2i fps (max)",(int)(1.0/(float)transferTime*1000)));
   } else {
      if(frameExposure_<1000)
         exposureValue->setText(QString().sprintf("%2i fps",(int)(1.0/(float)frameExposure_*1000)));
      else
         exposureValue->setText(QString().sprintf("%2.1f s",((float)frameExposure_/1000)));
   }
   // if exposure > 1000ms, read the frame and start a new one
   // count the usb transfer time. Rate is 24M pixels / second
   shootMode_=(frameExposure_<1000);
   int poseTime=frameExposure_-(1558*(height_+26)/PIXEL_RATE);
   if(poseTime<0) poseTime=0;
   camera->stop();
   camera->shoot(poseTime,shootMode_);
   shooting_=TRUE;

   // progress bar
   QCamHBox* progressBox=new QCamHBox(settingsBox);
   QLabel* label3=new QLabel(QString("Progress"),progressBox);
   progressBar=new QProgressBar(progressBox);
   if(frameExposure_>(3*PROGRESS_TIME)) {
      progressBar->setEnabled(true);
      progressBar->setMinimum(0);
      progressBar->setMaximum((int)((float)(frameExposure_+30)/PROGRESS_TIME));
      progress_=0;
   } else {
      progressBar->setEnabled(false);
   }

   // tooltips
   denoiseBox->setToolTip(tr("Denoise the horizontal bands using the edge black pixels"));
   gainSlider->setToolTip(tr("Camera's gain, non linear, 0 to 81 , 5 means x1 (patterns after 52)"));
   exposureSlider->setToolTip(tr("Camera's exposure, may be limited by the frame sizes"));
   exposureValue->setToolTip(tr("Exposure time (not a real fps, not very accurate for high rates)"));

   // connections
   connect(denoiseBox,SIGNAL(toggled(bool)),this,SLOT(denoiseChange(bool)));
   connect(gainSlider,SIGNAL(valueChange(int)),this,SLOT(changeGain(int)));
   connect(gainSlider,SIGNAL(sliderReleased()),this,SLOT(setGain()));
   connect(gainSliderG1,SIGNAL(valueChange(int)),this,SLOT(changeGainG1(int)));
   connect(gainSliderG1,SIGNAL(sliderReleased()),this,SLOT(setGain()));
   connect(gainSliderG2,SIGNAL(valueChange(int)),this,SLOT(changeGainG2(int)));
   connect(gainSliderG2,SIGNAL(sliderReleased()),this,SLOT(setGain()));
   connect(gainSliderR,SIGNAL(valueChange(int)),this,SLOT(changeGainR(int)));
   connect(gainSliderR,SIGNAL(sliderReleased()),this,SLOT(setGain()));
   connect(gainSliderB,SIGNAL(valueChange(int)),this,SLOT(changeGainB(int)));
   connect(gainSliderB,SIGNAL(sliderReleased()),this,SLOT(setGain()));

   connect(exposureSlider,SIGNAL(valueChanged(int)),this,SLOT(changeExposure(int)));
   connect(exposureSlider,SIGNAL(sliderReleased()),this,SLOT(setExposure()));

   cerr << "QHY5 ready..." << endl;

   // set the first timer shot
   timer_=new QTimer(this);
   connect(timer_,SIGNAL(timeout()),this,SLOT(updateFrame()));
   timer_->setSingleShot(true);
   timer_->start(frameExposure_);
   // progress timer
   progressTimer_=new QTimer(this);
   progressTimer_->start(PROGRESS_TIME);
   connect(progressTimer_,SIGNAL(timeout()),this,SLOT(progressUpdate()));

   return remoteCTRL;
}
CryptTask::status CryptTask::decrypt()
{
	if( utility::pathExists( m_dest ) ){
		return CryptTask::destinationFileExists ;
	}
	QFile fd_1( m_mapperPath ) ;
	if( !fd_1.open( QIODevice::ReadOnly ) ){
		return CryptTask::openMapperReadFail ;
	}
	const int SIZE = 512 ;
	char buffer[SIZE] ;

	fd_1.read( buffer,SIZE ) ;

	if( memcmp( buffer + 100,buffer + 200,100 ) != 0 ){
		return CryptTask::wrongKey ;
	}

	char version[ 32 ] ;
	memcpy( version,buffer + 300,32 ) ;
	char md5sum[ 32 ] ;
	memcpy( md5sum,buffer + 332,32 ) ;

	qint64 size = atoll( buffer ) ;
	qint64 len ;
	qint64 i = 0;
	int j = 0;
	int k = -1 ;

	QFile fd_2( m_dest ) ;
	if( !fd_2.open( QIODevice::WriteOnly ) ){
		return CryptTask::createFileFail ;
	}

	emit titleUpdate( tr( "Copying Data From The Container File" ) ) ;

	if( size <= SIZE ){
		fd_1.read( buffer,size ) ;
		fd_2.write( buffer,size ) ;
		fd_2.flush() ;
	}else{
		len = size / SIZE ;

		for( i = 0 ; i < len ; i++ ){

			if( m_status == CryptTask::quit ){
				return CryptTask::quit ;
			}
			j = ( int )( i * 100 / len ) ;

			if( j > k ){
				emit progressUpdate( j ) ;
			}
			k = j ;

			fd_1.read( buffer,SIZE ) ;
			fd_2.write( buffer,SIZE ) ;
			fd_2.flush() ;
		}

		len = size - ( i * SIZE ) ;

		fd_1.read( buffer,len ) ;
		fd_2.write( buffer,len ) ;
		fd_2.flush() ;
	}

	emit progressUpdate( 100 ) ;

	char md5Data[ 32 ] ;

	char version_1[ 32 ] = { '\0' };
	strcpy( version_1,"1.0" ) ;

	if( memcmp( version,version_1,32 ) == 0 ){
		/*
		 * we are decrypting a volume using new format that embed md5 checksum of the data
		 */
		this->calculateMd5( m_dest,md5Data ) ;

		if( memcmp( md5sum,md5Data,32 ) != 0 ){
			return CryptTask::md5Fail ;
		}else{
			return CryptTask::md5Pass ;
		}
	}else{
		return CryptTask::md5Pass ;
	}
}