bool QtlMovieCleanupSubtitles::start() { // Do not start twice. if (!QtlMovieAction::start()) { return false; } debug(tr("Starting subtitle file cleanup")); debug(tr("Input file: %1").arg(_inputFile.fileName())); debug(tr("Output file: %1").arg(_outputFile.fileName())); // Open the input file. if (!_inputFile.open(QFile::ReadOnly)) { emitCompleted(false, tr("Error opening %1").arg(_inputFile.fileName())); return true; // true = started (and completed as well in that case). } // Create the output file. if (!_outputFile.open(QFile::WriteOnly)) { _inputFile.close(); emitCompleted(false, tr("Error creating %1").arg(_outputFile.fileName())); return true; // true = started (and completed as well in that case). } // Start immediate timer, a way to read continuously packets but return periodically to the event loop. _timerId = startTimer(0); // Do not report progress more often that every 1% of the file size or 1 kB. _totalSize = _inputFile.size(); _reportInterval = qMax(Q_INT64_C(1024), _totalSize / 100); _nextReport = _reportInterval; // Will read packets later. return true; }
bool QtlMovieDeleteAction::start() { // Do not start twice. if (!QtlMovieAction::start()) { return false; } // Delete all files. bool success = true; foreach (const QString& file, _files) { const QFileInfo info(file); line(tr("Deleting %1").arg(file)); if ((info.isDir() && !QDir(file).removeRecursively()) || (info.isFile() && !QFile(file).remove())) { success = false; line(tr("Error deleting %1").arg(file), QColor(Qt::red)); } } // Report action completion. emitCompleted(success); // Always return true from start(), which means successfully started. // Failure in execution of the action was reported by emitCompleted(). return true; }
void QtlMovieCleanupSubtitles::timerEvent(QTimerEvent* event) { // This handler is invoked for all timer, make sure it is ours. if (event == 0 || _timerId < 0 || event->timerId() != _timerId) { // Not our poll timer, invoke superclass. QtlMovieAction::timerEvent(event); return; } // Read a chunk of the input file. char buffer[QTL_FILE_CHUNK]; const qint64 inCount = _inputFile.read(buffer, sizeof(buffer)); if (inCount < 0) { // File error. emitCompleted(false, tr("Error reading %1").arg(_inputFile.fileName())); } else if (inCount == 0) { // End of file. emitCompleted(true); } else { // Count total input bytes. _readSize += inCount; // Cleanup the buffer, remove nul bytes. char* wr = buffer; for (const char* rd = buffer; rd < buffer + inCount; ++rd) { if (*rd != 0) { *wr++ = *rd; } } const qint64 outCount = wr - buffer; // Write the clean buffer to output file. if (_outputFile.write(buffer, outCount) < outCount) { emitCompleted(false, tr("Error writing %1").arg(_outputFile.fileName())); } else if (_readSize >= _nextReport) { // Report progress in the file. emitProgress(int(_readSize), int(_totalSize)); _nextReport += _reportInterval; } } }
void QtlMovieCleanupSubtitles::abort() { // Declare the completion with error status but no message. emitCompleted(false); }
void SingleJobPrompt::jobResult(KJob *job) { Q_ASSERT(job == m_job); // check for errors first if(m_job->isDismissed()) { emit completed(true, QString()); } else if(m_job->error() != BackendNoError) { // TODO: figure out how to handle errors gracefully. // FIXME; should we use KMessage here instead of KMessageBox ? KMessageBox::error( 0, m_job->errorMessage() ); emit completed(false, QString()); } else { switch(m_job->type()) { case BackendJob::TypeUnlockCollection: case BackendJob::TypeLockCollection: case BackendJob::TypeDeleteCollection: case BackendJob::TypeChangeAuthenticationCollection: case BackendJob::TypeDeleteItem: case BackendJob::TypeLockItem: case BackendJob::TypeUnlockItem: case BackendJob::TypeChangeAuthenticationItem: { BooleanResultJob *brj = qobject_cast<BooleanResultJob*>(m_job); Q_ASSERT(brj); emitCompleted(false, QVariant(brj->result())); } break; case BackendJob::TypeCreateCollectionMaster: { CreateCollectionMasterJob *ccmj = qobject_cast<CreateCollectionMasterJob*>(m_job); Q_ASSERT(ccmj); QDBusObjectPath result("/"); if(ccmj->collection()) { BackendCollection *coll = ccmj->collection(); result.setPath(serviceObjectPath().path() + QStringLiteral( "/collection/" ) + coll->id()); } emitCompleted(false, qVariantFromValue(result)); } break; case BackendJob::TypeCreateCollection: { CreateCollectionJob *ccj = qobject_cast<CreateCollectionJob*>(m_job); Q_ASSERT(ccj); QDBusObjectPath result("/"); if(ccj->collection()) { BackendCollection *coll = ccj->collection(); result.setPath(serviceObjectPath().path() + QStringLiteral( "/collection/" ) + coll->id()); } emitCompleted(false, qVariantFromValue(result)); } break; case BackendJob::TypeCreateItem: { CreateItemJob *cij = qobject_cast<CreateItemJob*>(m_job); Q_ASSERT(cij); QDBusObjectPath result("/"); if(cij->item()) { BackendItem *item = cij->item(); result.setPath(serviceObjectPath().path() + QStringLiteral( "/collection/" ) + cij->collection()->id() + QChar::fromLatin1( '/' ) + item->id()); } emitCompleted(false, qVariantFromValue(result)); } break; default: // should not happen! Q_ASSERT(false); } } deleteLater(); }