void repo::gui::RepoWorkerProjectSettings::run() { int jobsCount = 1; int jobsDone = 0; emit progressRangeChanged(0, 0); // undetermined (moving) progress bar try { if (!cancelled && !mongo.reconnect()) std::cerr << tr("Connection failed").toStdString() << std::endl; else { mongo.reauthenticate(); //------------------------------------------------------------------ // Execute command (such as drop or update setting) if any if (command.isOk()) mongo.runCommand(database, command); emit progressValueChanged(jobsDone++); jobsCount += mongo.countItemsInCollection(database, REPO_COLLECTION_SETTINGS); emit progressRangeChanged(jobsDone, jobsCount); //------------------------------------------------------------------ // Get project settings std::auto_ptr<mongo::DBClientCursor> cursor; std::list<std::string> fields; // projection, emtpy at the moment unsigned long long skip = 0; do { for (; !cancelled && cursor.get() && cursor->more(); ++skip) { core::RepoProjectSettings projectSettings(cursor->nextSafe()); emit projectSettingsFetched(projectSettings.copy()); emit progressValueChanged(jobsDone++); } if (!cancelled) cursor = mongo.listAllTailable( database, REPO_COLLECTION_SETTINGS, fields, "", -1, skip); } while (!cancelled && cursor.get() && cursor->more()); } } catch(std::exception e) { std::cerr << e.what() << std::endl; } //-------------------------------------------------------------------------- emit progressValueChanged(jobsCount); emit RepoWorkerAbstract::finished(); }
void CoreConnection::setProgressValue(int value) { if (_progressValue != value) { _progressValue = value; emit progressValueChanged(value); } }
void FutureWatcher::customEvent(QEvent* event) { if(_futureInterface) { OVITO_ASSERT(static_cast<CallOutEvent*>(event)->_source == _futureInterface.get()); if(event->type() == (QEvent::Type)CallOutEvent::Started) Q_EMIT started(); else if(event->type() == (QEvent::Type)CallOutEvent::Finished) { _finished = true; Q_EMIT finished(); } else if(event->type() == (QEvent::Type)CallOutEvent::Canceled) Q_EMIT canceled(); else if(event->type() == (QEvent::Type)CallOutEvent::ResultReady) { if(!_futureInterface->isCanceled()) { Q_EMIT resultReady(); } } else if(event->type() == (QEvent::Type)CallOutEvent::ProgressValue) { if(!_futureInterface->isCanceled()) Q_EMIT progressValueChanged(static_cast<CallOutEvent*>(event)->_value); } else if(event->type() == (QEvent::Type)CallOutEvent::ProgressText) { if(!_futureInterface->isCanceled()) Q_EMIT progressTextChanged(static_cast<CallOutEvent*>(event)->_text); } else if(event->type() == (QEvent::Type)CallOutEvent::ProgressRange) { Q_EMIT progressRangeChanged(static_cast<CallOutEvent*>(event)->_value); } } QObject::customEvent(event); }
//! [1] void DownloadManager::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) { // Update the properties with the new progress values m_progressTotal = bytesTotal; m_progressValue = bytesReceived; emit progressTotalChanged(); emit progressValueChanged(); // Calculate the download speed ... double speed = bytesReceived * 1000.0 / m_downloadTime.elapsed(); QString unit; if (speed < 1024) { unit = "bytes/sec"; } else if (speed < 1024 * 1024) { speed /= 1024; unit = "kB/s"; } else { speed /= 1024 * 1024; unit = "MB/s"; } // ... and update the progress message. m_progressMessage = QString("%1 %2").arg(speed, 3, 'f', 1).arg(unit); emit progressMessageChanged(); }
void CLSValueEditor::setProgressValue(double newValue) { if (progressValue_ != newValue) { progressValue_ = newValue; updateValueLabel(); emit progressValueChanged(progressValue_); } }
void TaskDispatcher::runTasksSingleThreadImpl(QList<Task>& tasks) { int progress = 0; for (QList<Task>::iterator it = tasks.begin(); it != tasks.end(); ++ it) { it->run(); emit progressValueChanged(++progress); } tasks.clear(); emit finished(); return; }
void AdBlockDownloader::onDownloadProgress(qint64 bytesreceived, qint64 bytestotal) { if(!this->_downloading) { this->_downloading = true; emit downloadingChanged(); } this->_progressvalue = bytesreceived; if(this->_progresstotal != bytestotal) { this->_progresstotal = bytestotal; emit progressTotalChanged(); } emit progressValueChanged(); }
//! [2] void DownloadManager::downloadFinished() { // Reset the progress information when the download has finished m_progressTotal = 0; m_progressValue = 0; m_progressMessage.clear(); emit progressValueChanged(); emit progressTotalChanged(); emit progressMessageChanged(); // Close the file where the data have been written m_output.close(); // Add a status or error message if (m_currentDownload->error()) { addErrorMessage(QString("Failed: %1").arg(m_currentDownload->errorString())); } else if (m_currentDownload->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 302) { m_output.remove(); QUrl redirecturl = m_currentDownload->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl(); if(redirecturl.isValid() && (redirecturl != m_currentDownload->url())) /* Avoid Fake/Redirect Loop */ { downloadUrl(redirecturl.toString()); } } else { addStatusMessage("Succeeded."); ++m_downloadedCount; } /** * We can't call 'delete m_currentDownload' here, because this method might have been invoked directly as result of a signal * emission of the network reply object. */ m_currentDownload->deleteLater(); m_currentDownload = 0; emit activeDownloadsChanged(); basename = ""; // Trigger the execution of the next job startNextDownload(); }
void MeshGenerator::run() { if (!m_cube || !m_mesh) { qDebug() << "No mesh or cube set - nothing to find isosurface of..."; return; } // Mark the mesh as being worked on and clear it m_mesh->setStable(false); m_mesh->clear(); m_vertices.reserve(m_dim.x()*m_dim.y()*m_dim.z()*3); m_normals.reserve(m_dim.x()*m_dim.y()*m_dim.z()*3); if (!m_cube->lock()->tryLockForRead()) { qDebug() << "Cannot get a read lock..."; } // Now to march the cube for(int i = 0; i < m_dim.x()-1; ++i) { for(int j = 0; j < m_dim.y()-1; ++j) { for(int k = 0; k < m_dim.z()-1; ++k) { marchingCube(Vector3i(i, j, k)); } } if (m_vertices.capacity() < m_vertices.size() + m_dim.y()*m_dim.x()*3) { m_vertices.reserve(m_vertices.capacity()*2); m_normals.reserve(m_normals.capacity()*2); } emit progressValueChanged(i); } m_cube->lock()->unlock(); // Copy the data across m_mesh->setVertices(m_vertices); m_mesh->setNormals(m_normals); m_mesh->setStable(true); // Now we are done give all that memory back m_vertices.resize(0); m_normals.resize(0); }
void LVRReconstructViaMarchingCubesDialog::setProgressValue(int v) { Q_EMIT(progressValueChanged(v)); }
Object* ObjectSaveLoader::loadFromFile( QString strFilename ) { // ---- test before opening ---- if ( !isFileExists( strFilename ) ) { m_error = PencilError( PCL_ERROR_FILE_NOT_EXIST ); return NULL; } QString strMainXMLFilePath = strFilename; QStringList zippedFileList = JlCompress::getFileList( strFilename ); // -- Test file format: new zipped pclx or old pcl ? bool bIsOldPencilFile = zippedFileList.empty(); if ( !bIsOldPencilFile ) { strMainXMLFilePath = extractZipToTempFolder( strFilename ); qDebug() << "Recognized New zipped Pencil File Format !"; } else { qDebug() << "Recognized Old Pencil File Format !"; } // -- test before opening QScopedPointer<QFile> file( new QFile( strMainXMLFilePath ) ); if ( !file->open( QFile::ReadOnly ) ) { //m_strLastErrorMessage = tr("Cannot open file."); m_error = PencilError( PCL_ERROR_FILE_CANNOT_OPEN ); cleanUpTempFolder(); return NULL; } QDomDocument xmlDoc; if ( !xmlDoc.setContent( file.data() ) ) { //m_strLastErrorMessage = tr("This file is not a valid XML document."); m_error = PencilError( PCL_ERROR_INVALID_XML_FILE ); cleanUpTempFolder(); return NULL; } QDomDocumentType type = xmlDoc.doctype(); if ( type.name() != "PencilDocument" && type.name() != "MyObject" ) { //m_strLastErrorMessage = tr("This file is not a Pencil2D document."); m_error = PencilError( PCL_ERROR_INVALID_PENCIL_FILE ); cleanUpTempFolder(); return NULL; // this is not a Pencil document } Object* pObject = new Object(); QString strDataLayersDirPath; if ( bIsOldPencilFile ) { // ex. aaa.pcl => aaa.pcl.data strDataLayersDirPath = strMainXMLFilePath + "." + PFF_LAYERS_DIR; } else { QDir workingDir = QFileInfo( strMainXMLFilePath ).dir(); // get the parent folder workingDir.cd( PFF_LAYERS_DIR ); strDataLayersDirPath = workingDir.absolutePath(); } Object* newObject = pObject; if ( !newObject->loadPalette( strDataLayersDirPath ) ) { newObject->loadDefaultPalette(); } // ------- reads the XML file ------- bool ok = true; int prog = 0; QDomElement docElem = xmlDoc.documentElement(); if ( docElem.isNull() ) { return NULL; } if ( docElem.tagName() == "document" ) { qDebug( "Object Loader: start." ); QDomNode tag = docElem.firstChild(); while ( !tag.isNull() ) { QDomElement element = tag.toElement(); // try to convert the node to an element. if ( !element.isNull() ) { prog += std::min( prog + 10, 100 ); //progress.setValue(prog); emit progressValueChanged( prog ); if ( element.tagName() == "editor" ) { qDebug( " Load editor" ); //loadDomElement( element ); } else if ( element.tagName() == "object" ) { qDebug( " Load object" ); ok = newObject->loadDomElement( element, strDataLayersDirPath ); qDebug() << " dataDir:" << strDataLayersDirPath; } } tag = tag.nextSibling(); } } else { if ( docElem.tagName() == "object" || docElem.tagName() == "MyOject" ) // old Pencil format (<=0.4.3) { ok = newObject->loadDomElement( docElem, strFilename ); } } if ( ok ) { /* if (!openingTheOLDWAY) { removePFFTmpDirectory( tmpFilePath ); // --removes temporary decompression directory } */ } else { return NULL; } return pObject; }
void HttpRequest::updateDataReadProgress(qint64 bytesRead, qint64 totalBytes) { emit progressRangeChanged(0, totalBytes); emit progressValueChanged(bytesRead); }
/* * Paste files to destination */ void Worker::pasteFiles(bool cut) { buildFileList(); QList<QString> directoryList; QDir sourceDir(m_clipboardDir); QTime startTime = QTime::currentTime(); emit progressTextChanged(QString("Copying files...")); // Create a list of directories to be created for (int i=0; i < m_directoryList.count(); i++) { QString sourcePath = m_directoryList.at(i); QString newDirPath = QString("%1/%2").arg(m_destination, sourceDir.relativeFilePath(sourcePath)); qDebug() << sourcePath.toLatin1() << " > " << newDirPath.toLatin1(); directoryList.append(newDirPath); } emit progressTextChanged("Creating directories..."); qDebug() << "FILES"; // Create a list of files to be copied for (int i=0; i < m_fileList.count(); i++) { QString sourcePath = m_fileList.at(i); QString newFilePath = QString("%1/%2").arg(m_destination, sourceDir.relativeFilePath(sourcePath)); qDebug() << sourcePath.toLatin1() << " > " << newFilePath.toLatin1(); m_fileMap.insert(sourcePath, newFilePath); } // First, create the directories for (int i = 0; i < directoryList.count(); i++) { QString newDir = directoryList.at(i); QDir dir(newDir); // If the directory already exists, skip it if (dir.exists()) continue; bool success = dir.mkdir(newDir); if (!success) directoryErrorMap.insert(newDir, DirCreateError); } // If any of the directories couldn't be created, abort the process if (directoryErrorMap.count() > 0) { emit progressTextChanged("Directories couldn't be created."); emit fileOperationFinished(); // Abort the process quit(); } // Now, copy the files int fileCount = 0; QMapIterator<QString, QString> i(m_fileMap); while (i.hasNext()) { i.next(); fileCount++; QString sourceFilePath = i.key(); QString newFilePath = i.value(); QFile sourceFile(sourceFilePath); // Report the progress, but only every 50 milliseconds to prevent the UI thread // from being flooded with signals if (QTime::currentTime().msecsTo(startTime) <= -50) { startTime = QTime::currentTime(); emit progressTextChanged(QString("Copying files (%1 of %2)...").arg(QString("%1").arg(fileCount), QString("%1").arg(m_fileMap.count()))); emit currentEntryChanged(sourceFile.fileName()); double progress = (double)(fileCount) / (double)m_fileMap.count(); emit progressValueChanged(progress); } // Copy the file bool success = sourceFile.copy(sourceFilePath, newFilePath); if (!success) fileErrorMap.insert(newFilePath, sourceFile.error()); } // If we don't have to cut files we are done if (!cut) { if (fileErrorMap.count() == 0 && directoryErrorMap.count() == 0) emit progressTextChanged("All files were copied successfully."); else emit progressTextChanged("All files couldn't be copied successfully."); emit fileOperationFinished(); // Done, time to self-destruct quit(); } else { fileCount = 0; if (fileErrorMap.count() == 0 && directoryErrorMap.count() == 0) { // We copied all files successfully, so delete the old ones now i.toFront(); while (i.hasNext()) { i.next(); fileCount++; QString sourceFilePath = i.key(); QFile sourceFile(sourceFilePath); // Report the progress, but only every 50 milliseconds to prevent the UI thread // from being flooded with signals if (QTime::currentTime().msecsTo(startTime) <= -50) { startTime = QTime::currentTime(); emit progressTextChanged(QString("Deleting old files (%1 of %2)...").arg(QString("%1").arg(fileCount), QString("%1").arg(m_fileMap.count()))); emit currentEntryChanged(sourceFile.fileName()); double progress = (double)(fileCount) / (double)m_fileMap.count(); emit progressValueChanged(progress); } // Delete the file bool success = sourceFile.remove(); if (!success) fileErrorMap.insert(sourceFilePath, sourceFile.error()); } emit progressTextChanged(QString("Deleting old directories...")); emit progressValueChanged(-1); // Then delete the directories for (int i=m_directoryList.count()-1; i >= 0; i--) { QString sourcePath = m_directoryList.at(i); QDir dir(sourcePath); // If it doesn't exist, it was most likely removed earlier if (!dir.exists()) continue; bool success = dir.rmdir(sourcePath); if (!success) directoryErrorMap.insert(sourcePath, DirDeleteError); } // Check if files were copied and deleted successfully if (fileErrorMap.count() == 0 && directoryErrorMap.count() == 0) emit progressTextChanged("All of the files were cut and pasted successfully."); else emit progressTextChanged("All of the files couldn't be cut and pasted successfully."); emit fileOperationFinished(); // Done, time to self-destruct quit(); } else { // All files couldn't be copied, so delete the new copied files to revert the process i.toFront(); while (i.hasNext()) { i.next(); fileCount++; QString newFilePath = i.value(); QFile newFile(newFilePath); // Report the progress, but only every 50 milliseconds to prevent the UI thread // from being flooded with signals if (QTime::currentTime().msecsTo(startTime) <= -50) { startTime = QTime::currentTime(); emit progressTextChanged(QString("Failed to copy all files, deleting copied files (%1 of %2)...").arg(QString("%1").arg(fileCount), QString("%1").arg(m_fileMap.count()))); emit currentEntryChanged(newFile.fileName()); double progress = (double)(fileCount) / (double)m_fileMap.count(); emit progressValueChanged(progress); } // Delete the file newFile.remove(); } emit progressTextChanged(QString("Failed to copy all files, deleting created directories...")); emit progressValueChanged(-1); // Delete the directories for (int i=directoryList.count()-1; i >= 0; i--) { QString newDir = directoryList.at(i); QDir dir(newDir); // If the directory already exists, skip it if (dir.exists()) continue; bool success = dir.rmdir(newDir); if (!success) directoryErrorMap.insert(newDir, DirDeleteError); } emit progressTextChanged("All files couldn't be copied successfully."); emit fileOperationFinished(); } } }
/* * Delete files in the clipboard */ void Worker::deleteFiles() { buildFileList(); emit progressTextChanged(QString("Deleting files...")); QTime startTime = QTime::currentTime(); // Start deleting files for (int i=0; i < m_fileList.count(); i++) { QString fullPath = m_fileList.at(i); QFile file(fullPath); // Report the progress if (QTime::currentTime().msecsTo(startTime) <= -50) { startTime = QTime::currentTime(); emit progressTextChanged(QString("Deleting files (%1 of %2)...").arg(QString("%1").arg(i+1), QString("%1").arg(m_fileList.count()))); emit currentEntryChanged(file.fileName()); double progress = (double)(i + 1) / (double)m_fileList.count(); emit progressValueChanged(progress); } file.open(QIODevice::WriteOnly); // Remove the file bool success = file.remove(); if (!success) fileErrorMap.insert(fullPath, file.error()); } // And then delete directories // Reverse order so that the subdirectories are deleted first for (int i=m_directoryList.count()-1; i >= 0; i--) { QString fullPath = m_directoryList.at(i); QDir dir(fullPath); // If it doesn't exist, it was most likely removed earlier if (!dir.exists()) continue; bool success = dir.rmdir(fullPath); if (!success) directoryErrorMap.insert(fullPath, DirDeleteError); if (QTime::currentTime().msecsTo(startTime) <= -50) { startTime = QTime::currentTime(); emit progressTextChanged(QString("Deleting directories...")); emit currentEntryChanged(dir.dirName()); emit progressValueChanged(-1); } } // We are done if (fileErrorMap.count() == 0 && directoryErrorMap.count() == 0) emit progressTextChanged("All files were deleted successfully."); else emit progressTextChanged("All files couldn't be deleted successfully."); emit fileOperationFinished(); // Done, time to self-destruct quit(); }