File indexing completed on 2025-01-05 03:54:17
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2005-10-28 0007 * Description : scan item controller - stop operations. 0008 * 0009 * SPDX-FileCopyrightText: 2005-2006 by Tom Albers <tomalbers at kde dot nl> 0010 * SPDX-FileCopyrightText: 2006-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0011 * SPDX-FileCopyrightText: 2007-2013 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> 0012 * 0013 * SPDX-License-Identifier: GPL-2.0-or-later 0014 * 0015 * ============================================================ */ 0016 0017 #include "scancontroller_p.h" 0018 0019 namespace Digikam 0020 { 0021 0022 void ScanController::slotCancelPressed() 0023 { 0024 abortInitialization(); 0025 cancelCompleteScan(); 0026 } 0027 0028 void ScanController::abortInitialization() 0029 { 0030 QMutexLocker lock(&d->mutex); 0031 d->needsInitialization = false; 0032 d->continueInitialization = false; 0033 } 0034 0035 void ScanController::cancelCompleteScan() 0036 { 0037 QMutexLocker lock(&d->mutex); 0038 d->needsCompleteScan = false; 0039 d->continueScan = false; 0040 Q_EMIT completeScanCanceled(); 0041 } 0042 0043 void ScanController::cancelAllAndSuspendCollectionScan() 0044 { 0045 QMutexLocker lock(&d->mutex); 0046 0047 d->needsInitialization = false; 0048 d->continueInitialization = false; 0049 0050 d->needsCompleteScan = false; 0051 d->continueScan = false; 0052 0053 d->scanTasks.clear(); 0054 d->continuePartialScan = false; 0055 0056 d->relaxedTimer->stop(); 0057 0058 // like suspendCollectionScan 0059 d->scanSuspended++; 0060 0061 while (!d->idle) 0062 { 0063 d->condVar.wait(&d->mutex, 20); 0064 } 0065 } 0066 0067 void ScanController::suspendCollectionScan() 0068 { 0069 QMutexLocker lock(&d->mutex); 0070 d->scanSuspended++; 0071 } 0072 0073 /// implementing InitializationObserver 0074 void ScanController::finishedSchemaUpdate(UpdateResult result) 0075 { 0076 // not from main thread 0077 0078 switch (result) 0079 { 0080 case InitializationObserver::UpdateSuccess: 0081 d->advice = Success; 0082 break; 0083 0084 case InitializationObserver::UpdateError: 0085 d->advice = ContinueWithoutDatabase; 0086 break; 0087 0088 case InitializationObserver::UpdateErrorMustAbort: 0089 d->advice = AbortImmediately; 0090 break; 0091 } 0092 } 0093 0094 void ScanController::finishFileMetadataWrite(const ItemInfo& info, bool changed) 0095 { 0096 QFileInfo fi(info.filePath()); 0097 d->hints->recordHint(ItemMetadataAdjustmentHint(info.id(), 0098 changed ? ItemMetadataAdjustmentHint::MetadataEditingFinished : 0099 ItemMetadataAdjustmentHint::MetadataEditingAborted, 0100 fi.lastModified(), 0101 fi.size())); 0102 0103 scanFileDirectlyNormal(info); 0104 } 0105 0106 void ScanController::shutDown() 0107 { 0108 if (!isRunning()) 0109 { 0110 return; 0111 } 0112 0113 d->running = false; 0114 d->continueInitialization = false; 0115 d->continueScan = false; 0116 d->continuePartialScan = false; 0117 0118 { 0119 QMutexLocker lock(&d->mutex); 0120 d->condVar.wakeAll(); 0121 } 0122 0123 wait(); 0124 } 0125 0126 void ScanController::slotRelaxedScanning() 0127 { 0128 qCDebug(DIGIKAM_DATABASE_LOG) << "Starting scan!"; 0129 d->externalTimer->stop(); 0130 d->relaxedTimer->stop(); 0131 0132 QMutexLocker lock(&d->mutex); 0133 d->condVar.wakeAll(); 0134 } 0135 0136 } // namespace Digikam