File indexing completed on 2025-01-19 03:55:48
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2012-02-05 0007 * Description : file action manager task list 0008 * 0009 * SPDX-FileCopyrightText: 2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #include "fileactionimageinfolist.h" 0016 0017 // Qt includes 0018 0019 #include <QtGlobal> 0020 0021 // Local includes 0022 0023 #include "digikam_debug.h" 0024 0025 namespace Digikam 0026 { 0027 0028 void TwoProgressItemsContainer::scheduleOnProgressItem(QAtomicPointer<ProgressItem>& ptr, 0029 int total, 0030 const QString& action, 0031 FileActionProgressItemCreator* const creator) 0032 { 0033 if (total <= 0) 0034 { 0035 return; 0036 } 0037 0038 if (!ptr) 0039 { 0040 ProgressItem* const item = creator->createProgressItem(action); 0041 0042 if (ptr.testAndSetOrdered(nullptr, item)) 0043 { 0044 creator->addProgressItem(item); 0045 } 0046 else 0047 { 0048 delete item; 0049 } 0050 } 0051 0052 ptr.loadRelaxed()->incTotalItems(total); 0053 } 0054 0055 void TwoProgressItemsContainer::advance(QAtomicPointer<ProgressItem>& ptr, int n) 0056 { 0057 if (ptr && ptr.loadRelaxed()->advance(n)) 0058 { 0059 ProgressItem* const item = ptr; 0060 0061 if (item && ptr.testAndSetOrdered(item, nullptr)) 0062 { 0063 item->setComplete(); 0064 } 0065 } 0066 } 0067 0068 FileActionProgressItemContainer::FileActionProgressItemContainer() 0069 { 0070 } 0071 0072 void FileActionProgressItemContainer::schedulingForDB(int numberOfInfos, 0073 const QString& action, 0074 FileActionProgressItemCreator* const creator) 0075 { 0076 scheduleOnProgressItem(firstItem, numberOfInfos, action, creator); 0077 } 0078 0079 void FileActionProgressItemContainer::dbProcessed(int numberOfInfos) 0080 { 0081 advance(firstItem, numberOfInfos); 0082 } 0083 0084 void FileActionProgressItemContainer::dbFinished() 0085 { 0086 /* 0087 checkFinish(firstItem); 0088 */ 0089 } 0090 0091 void FileActionProgressItemContainer::schedulingForWrite(int numberOfInfos, 0092 const QString& action, 0093 FileActionProgressItemCreator* const creator) 0094 { 0095 scheduleOnProgressItem(secondItem, numberOfInfos, action, creator); 0096 0097 if (secondItem) 0098 { 0099 connect(secondItem, SIGNAL(progressItemCompleted(ProgressItem*)), 0100 this, SIGNAL(signalWrittingDone())); 0101 } 0102 } 0103 0104 void FileActionProgressItemContainer::written(int numberOfInfos) 0105 { 0106 advance(secondItem, numberOfInfos); 0107 } 0108 0109 void FileActionProgressItemContainer::finishedWriting() 0110 { 0111 /* 0112 checkFinish(secondItem); 0113 */ 0114 } 0115 0116 FileActionItemInfoList FileActionItemInfoList::create(const QList<ItemInfo>& infos) 0117 { 0118 FileActionItemInfoList list; 0119 list = FileActionItemInfoList(infos); 0120 list.container = new FileActionProgressItemContainer; 0121 0122 return list; 0123 } 0124 0125 FileActionItemInfoList FileActionItemInfoList::continueTask(const QList<ItemInfo>& infos, 0126 FileActionProgressItemContainer* const container) 0127 { 0128 FileActionItemInfoList list; 0129 list = FileActionItemInfoList(infos); 0130 list.container = container; 0131 0132 return list; 0133 } 0134 0135 } // namespace Digikam 0136 0137 #include "moc_fileactionimageinfolist.cpp"